dialog question



Dear all:
This is my first mail here, and my English is not good(I come from Taiwan),
so if you can't understant my words, please forgive me and tell me. Thanks.

My question is every program need to ask user a question to decide what to
do next. For instance, ask for a file name to open, ask for yes or no, like
this:

GtkWidget* window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
//.. initial the window and other widget

// ask for a file name to open
// the fileDialog's argument is the parent window
char* fileName=fileDialog(window);

// be sure
BOOLEAN result=areYouSure("open the file?", window);
if (result) {
    // open the file...
}

To do this, I write a function named "areYouSure" to ask for yes or no. It
worked well, but when I used this function in another thread, it generated
error message like this: the main loop already active in another thread.
What happened? and how can I modify this function? The function list as
below:

void areYouSure_ok(GtkWidget* b_ok, gpointer d)
{
    void** data=(void**)d;
    BOOLEAN* b=(BOOLEAN*)(data[0]);
    GtkWidget* dialog=(GtkWidget*)(data[1]);

    *b=TRUE;
    gtk_widget_destroy(dialog);
    gtk_main_quit();
}
void areYouSure_cancel(GtkWidget* b_ok, gpointer d)
{
    void** data=(void**)d;
    BOOLEAN* b=(BOOLEAN*)(data[0]);
    GtkWidget* dialog=(GtkWidget*)(data[1]);

    *b=FALSE;
    gtk_widget_destroy(dialog);
    gtk_main_quit();
}
BOOLEAN areYouSure(char* str,GtkWidget* parent)
{
    BOOLEAN result;

    GtkWidget* dialog;
    GtkWidget* l_message;
    GtkWidget* b_ok;
    GtkWidget* b_cancel;

    dialog=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_modal(GTK_WINDOW(dialog),TRUE);
    gtk_window_set_transient_for(GTK_WINDOW(dialog),GTK_WINDOW(parent));
    gtk_container_set_border_width(GTK_CONTAINER(dialog),3);

gtk_signal_connect(GTK_OBJECT(dialog),"delete_event",GTK_SIGNAL_FUNC(gtk_tru
e),NULL);

    void* data[2];
    data[0]=&result;
    data[1]=dialog;

    l_message=gtk_label_new(str);
    b_ok     =gtk_button_new_with_label("Yes");
    b_cancel =gtk_button_new_with_label("No");

gtk_signal_connect(GTK_OBJECT(b_ok),"clicked",GTK_SIGNAL_FUNC(areYouSure_ok)
,data);

gtk_signal_connect(GTK_OBJECT(b_cancel),"clicked",GTK_SIGNAL_FUNC(areYouSure
_cancel),data);

    gtk_widget_show(l_message);
    gtk_widget_show(b_ok);
    gtk_widget_show(b_cancel);

    GtkWidget* box1=gtk_hbox_new(FALSE,0);
    gtk_box_pack_start(GTK_BOX(box1),b_ok,TRUE,TRUE,5);
    gtk_box_pack_start(GTK_BOX(box1),b_cancel,TRUE,TRUE,5);
    gtk_widget_show(box1);
    GtkWidget* hseparator=gtk_hseparator_new();
    gtk_widget_show(hseparator);
    GtkWidget* box2=gtk_vbox_new(FALSE,0);
    gtk_box_pack_start(GTK_BOX(box2),l_message,TRUE,TRUE,5);
    gtk_box_pack_start(GTK_BOX(box2),hseparator,TRUE,TRUE,5);
    gtk_box_pack_start(GTK_BOX(box2),box1,TRUE,TRUE,5);
    gtk_widget_show(box2);
    gtk_container_add(GTK_CONTAINER(dialog),box2);
    gtk_widget_show(dialog);

    gtk_main();
    return result;
}


==========================================================
 PC home 電子信箱,申請請至: http://www.pchome.com.tw
 PC home Online 網路家庭:會員第?,台灣最大的入口網站
==========================================================




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