[Glade-users] Holding the pointer of window



Axel,

I think you need a combination of lookup_widget and the get/set_data stuff.
 Here's how I've referenced the main window (I use this code to put status
notes in the status bar) from a secondary, non-child, window.

In callbacks.c declare a static variable that's just a string;

gchar *MainWindowKey = "MainWindowKey";

In the function that creates the child window:

GtkWidget *mainwindow;

secondwindow = create_secondwindow();  /* this is the function I'm assuming
glade created to make the second window */

mainwindow = lookup_widget(GTK_WIDGET(button (or menuitem or whatever)),
"main window");   
gtk_object_set_data(GTK_OBJECT(secondwindow), MainWindowKey, mainwindow);

Now, you have the mainwindow referenced in the second window's 'object
data' through the static variable MainWindowKey.

When you need to reference the main window from the second window, you have
to do somewhat the reverse from above:

declare 
GtkWidget *buttonparent;  /* or any item parent, I'm assuming you are
clicking a button on the second window */
GtkWidget *main_window;

add:
  buttonparent = gtk_widget_get_toplevel(GTK_WIDGET(button));
  main_window = gtk_object_get_data(GTK_OBJECT(buttonparent),
MainWindowKey);

and there you have it, a reference back to the main window.  Hope this
helps.  Good idea to look at the example editor code that comes with the
glade tarball, there is an example of this in there too, I believe.

Rikke

On 2001.10.17 12:54 Axel Rueweler wrote:
On Wed, Oct 17, 2001 at 04:27:23PM -0200, Flavio Alberto Lopes Soares
wrote:
Use a function supplied by Glade in file support.c : lookup_widget, the
1st parameter is the parent widget and 2nd parameter is a string with
the name of your child widget, the return is a GtkWidget pointer to
your
child widget and you can manipulate this widget.
I know that function. But from where can I get the pointer of the main
window?
E.g.: I have got a mainwindow with an entrybox. Now I start over a button
a snd. window with another entry(created with glade, as well). When I
press 
a button in that dialog, the text of that snd. entry has to be set in the

first.
But from where can I get the pointer to the main window to use 
lookup_widget?

mfg
 axel

_______________________________________________
Glade-users maillist  -  Glade-users ximian com
http://lists.ximian.com/mailman/listinfo/glade-users






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