Re: child windows creation control



Hi,

Ignacio <inodal teleline es> writes:

> I have some buttons connected with the "clicked" signal to a different
> callback for each button.
> Each callback creates a different window. Since now, I've used this
> approximation to control that the child widgets are created only once,
> and not as many times as the button is clicked:
> 
> 
> /* Declaring local variables */
> static GtkWidget *window = NULL;
> ...
> 
> /* Return if window already exists */
> if ( window )
> {
>         gdk_window_raise(GTK_WIDGET(window)->window);
>         return;
> }
> 
> /* Creating window */
> window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
> ...
> 
> [Note: i've set window == NULL in the destroy callbacks]
> 
> The problem is I don't like this approximation, because it forces me to
> have a 9 "static Gtkwidgets*" declared. (I have 9 buttons with 9
> different callbacks).
> 
> Is there any other way to control this problem?

you could attach the window pointer as object data to your buttons.
Then the code would become something like this:

  window = gtk_object_get_data (GTK_OBJECT (button), "window");

  if (window)
    {
      gdk_window_raise (GTK_WIDGET(window)->window);
      return;
    }

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_object_set_data (GTK_OBJECT (button), "window", window);
 
  ...



Salut, Sven



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