Re: [gtk-list] closing windows



On Mon, 28 Jun 1999 14:24:17 -0400, Alexandre Sagala wrote:
> I have a problem I have a main window and  a another window that pops-up
> ( call it wondow2) on top when the user clicks a button. In window2 I
> have  a ok button and a cancel button . To kill the window when cnacle
> is clicked I do a
> 
> 
> gtk_signal_connect_object (GTK_OBJECT (button2),
> "clicked",GTK_SIGNAL_FUNC (gtk_widget_destroy),GTK_OBJECT (window));
> 
> and it works but for the ok button on the click event I call up a
> function to check if all the info entered is ok but I wnt to kill the
> window and the same fucniton how can I do that????????????

Don't call gtk_widget_destroy(), but one of your own callback functions.
Something like:

  void my_ok_button_handler(GtkWidget *widget, gpointer data)
  {
    /* get the window pointer */
    GtkWidget *window = (GtkWidget *)data;

    /* do some sanity checks */
    assert(widget != NULL);
    assert(window != NULL);

    /* code to check the input fields */

    /* destroy window */  
    gtk_widget_destroy(window);
  }


  gtk_signal_connect(GTK_OBJECT(ok_button), "clicked",
                     GTK_SIGNAL_FUNC(my_ok_button_handler), window);


Maybe you'd better not destroy the window, but just simply hide it with 
gtk_widget_hide(window). The next time you want to show the window again,
you don't have to build it but you simply do gtk_widget_show(window). Code
looks more or less like:

  void popup_window()
  {
    static GtkWidget *window = NULL;

    if(window == NULL)
      {
         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
         /* buildup rest of window, but don't yet show it! */

         /* connect the OK button callback function */
         gtk_signal_connect(GTK_OBJECT(ok_button), "clicked",
                           GTK_SIGNAL_FUNC(my_ok_button_handler), window);
      }

    gtk_widget_show(window);
  }

Use gtk_widget_hide() instead of gtk_widget_destroy() in
my_ok_button_handler(). Oh, and of course don't call gtk_widget_destroy()
in the cancel button callback.


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2785859  Fax: +31-15-2781843  Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/




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