RE: Newbie question: gtk_widget_destroy()



Hi Lucia,

How can I destroy a window, without destroying the main window?  

For example, in a file selection widget, when the Cancel 
button is pressed I 
connect like this:
g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(file_widget)->can
cel_button), 
"clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), 
G_OBJECT(file_widget));

Maybe you should use g_signal_connect_swapped:
   g_signal_connect_swapped (GTK_OBJECT (GTK_FILE_SELECTION
(file_selector)->ok_button),
                             "clicked",
                             G_CALLBACK (gtk_widget_destroy), 
                             (gpointer) file_selector); 

like in in the example #1 on
http://developer.gnome.org/doc/API/2.0/gtk/GtkFileSelection.html

You can also use gtk_dialog_run. This shows a modal file selection
dialog and you don't have to connect anything. (see below)

Regards,

Gregor


-----
#include <string>
using namespace std;

/*
 * helper function:
 * 'filename': the selected filename if user hit OK.
 * 'title'   : the title to be displayed
 * returns true if the user hit OK otherwise false.
 */
bool
select_file (string* filename, const string& title)
{
    //http://developer.gnome.org/doc/API/2.0/gtk/GtkFileSelection.html

    GtkDialog *file_select;
    file_select = (GtkDialog*)gtk_file_selection_new (title.c_str());

    bool result = false;

 
//http://developer.gnome.org/doc/API/2.0/gtk/GtkDialog.html#gtk-dialog-r
esponse
    if (GTK_RESPONSE_OK == gtk_dialog_run(file_select))
    {
        *filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION
(file_select));
        result = true;
    }

    gtk_widget_destroy ((GtkWidget*)file_select);

    return result;
}
----

example:
---------
 string result;
 if (select_file(&result, "Select a funny file."))
 {
    // result contains the filename
 }
 else
 {
   // user hit Cancel.
 }
-----




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