GTK and the modal window



Hi all.

I'm working at a project with GTK+ 1.2.8 and linux pthread.

I need to put on the screen a modal dialog box.
The modal dialogbox is put on the screen by a function thrown by a thread outside the gtk_main loop.
This function have to stop until the user answers to dialogbox because the return value of the function is 
use like code answer.

I made my dialogbox coding a new GTK object with GOB 1.0.0.
The new dialogbox object is named GtkMsgBox.
It implemented the function "gtk_msgbox_do_modal" to start the modal dialogbox and "gtk_msgbox_end_modal" to 
stop.
Inside gtk_msgbox_do_modal I show the dialogbox, I save the current gtk_main_level value and start a new 
gtk_main.
Inside gtk_msgbox_end_modal I hide the dialogbox and stop the gtk_main loop with gtk_main_quit if and only if 
the current gtk_main_level is greater than the gtk_main_level saved.

I report some piece of code.


/* Inside threadUserAnswer */

void *threadUserAnswer(void *param)
{

        ...
        /* Show the dialogbox and wait for answer.
         * The thread is stopped until sisFnMex returns.
         * sisFnMex is a function-pointer assigned to int userMessageBox(void) function
         * implemented in the main.c source.
         */
        ans = sisFnMex();
        ...
}



/* Inside main.c
 * g_msgBox is the global GtkWidget pointer to the GtkMsgBox used to put messages.
 * g_msgBox is global in main.c
 */

int userMessageBox(void)
{
        gtk_msgbox_do_modal(GTK_MSGBOX(g_msgBox));
        return 0;
}




The modal dialogbox can be closed by another thread (created with pthread_create).

void *dlgBoxCloser(void *param)
{
        ...
        /* sisCloseDialog is a function-pointer to the function that close the dialogbox declared in tha 
main.c.
         */
        sisCloseDialog();
}



Inside main.c
void closeMessageBox(void)
{
        gtk_msgbox_end_modal(GTK_MSGBOX(g_msgBox));
}


Now I start the program.
The message box is on the screen because the threadUserAnswer thread does this.
The mouse pointer is on the message box.
Now the dlgBoxCloser thread try to close the message box. GLib prints on the screen the follow warning 
message:

GLib-WARNING **: g_main_iterate(): main loop already active in another thread

and the program is in loop. The mouse pointer is on the dialog box.
Now I move off the dialogbox the pointer and GLib stop to put the message, the function userMessageBox return 
but the 
gtk_main loop is locked.

Why this happens?

Thank to all.

        Mauro



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]