destroying is not freeing, is it?



hello list,

(please cc me, i am not subscribed)

this strange question struck me when a tried to do this:
a have a regular menu, which opens some windows (wow).
these windows must be unique, by which i mean, only one
instance of one particular window is allowed.

hiding/showing the window is not possible, because some
buttons and widgets in the window change according to some
conditions, so it is easier to construct the window every
time the menu-item is selected.

except when the user selects the *same* menu-item, i.e. the
window is already showed.  then i want the existing window
be raised.  i think this is sensible, and many apps do this
(the editor example in glade but using show/hide).

when closing the window, i destroy it.  so when selecting
a menu-item a needed to make sure a window of this menu
item does not exist already.

so first i thought, destoryed widget's pointer will be
null ;-) not true.  than i thought ok, the pointer is
not null but perhaps junk, so i checked if the
pointer is an object (GTK_IS_OBJECT()) and it is!

so i looked in the .h file, and saw that objects have
a destroyed bit.  so i tried the way you see down there.
i would like to ask, is this a correct approach?

GtkWidget *window = NULL;

/* relevant part of itemfactory */
        { "Add/Box", NULL, on_add_box, 0, NULL },

/* the callback */
void
on_add_box(data)
        gpointer data;
{
        if (window && !GTK_OBJECT_DESTROYED(window)) {
                gdk_window_raise(window->window);
        } else
                create_add_box_window(data);
}

static void 
create_tyc_kruhova_window(data)
        gpointer data;          
{
        if (data) {
                /* ... */
        } else {
                /* ... */
        }

        return window;
}

-f
(gtk, glib 1.2.10)
-- 
girls just wanna have fun...  guys just wanna have girls.



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