How can I check if a GtkWidget exists?

2012-07-20 Thread Frank Cox
How can I check if a GtkWidget exists?

I am planning to create and destroy widgets in a window depending on the user's
selections, but I can't figure out how to determine if a particular widget
already exists in the window so it won't be created twice or receive a
second deletion attempt if it's already gone.

I tried checking GTK_WIDGET_REALIZED but it appears that if the widget has
previously been destroyed then the GTK_WIDGET_REALIZED tries to access it
anyway and gives me an error.

Is there a way to determine if a widget is already in a window without having
to maintain my own table?

-- 
MELVILLE THEATRE ~ Real D 3D Digital Cinema ~ www.melvilletheatre.com
www.creekfm.com - FIFTY THOUSAND WATTS of POW WOW POWER!
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: How can I check if a GtkWidget exists?

2012-07-20 Thread David Nečas
On Fri, Jul 20, 2012 at 12:50:45AM -0600, Frank Cox wrote:
 How can I check if a GtkWidget exists?

By keeping track of it (either when you create and destroy the widgets
or using weak references/weak pointers/destroy callbacks/...).

‘Checking the existence of a widget’ is, essentially, a meaningless
phrase.  If the widget has been destroyed you do not have any means to
*refer* to it.  You cannot ask ‘does this widget exist’ because there is
no way to say ‘this widget’.

Using the pointer to the memory the widget used to occupy for anything
is a programming error.

Yeti

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: How can I check if a GtkWidget exists?

2012-07-20 Thread Miroslav Rajcic

On 7/20/2012 8:50 AM, Frank Cox wrote:

How can I check if a GtkWidget exists?

I am planning to create and destroy widgets in a window depending on the user's
selections, but I can't figure out how to determine if a particular widget
already exists in the window so it won't be created twice or receive a
second deletion attempt if it's already gone.

I tried checking GTK_WIDGET_REALIZED but it appears that if the widget has
previously been destroyed then the GTK_WIDGET_REALIZED tries to access it
anyway and gives me an error.

Is there a way to determine if a widget is already in a window without having
to maintain my own table?


Not sure, but perhaps GTK_IS_WIDGET (widget) macro would help.

Miroslav
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: How can I check if a GtkWidget exists?

2012-07-20 Thread David Nečas
On Fri, Jul 20, 2012 at 10:15:54AM +0200, Miroslav Rajcic wrote:
 Not sure, but perhaps GTK_IS_WIDGET(widget) macro would help.

If you have the pointer to a GObject instance and want to know whether
it is an instance of GtkWidget (including subclasses) then
GTK_IS_WIDGET() is the right thing to use.

But if you use this macro with a random pointer (e.g. one pointing to a
memory location where some GObject might be some time ago) do not expect
anything more useful than a CRITICAL error/crash.

To deal with objects that may or may not exist use one of the several
mechanisms (weak pointers/weak refs/destroy callbacks/...) for keeping
track of the object existence.  And, generally, use these mechanisms to
avoid even the possibility of dangling pointers in your code.

Yeti

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re : How can I check if a GtkWidget exists?

2012-07-20 Thread Nicolas SOUBEIRAN
Have you try g_object_add_weak_ref ? Weak references are used for 
notification when an object is finalized.

Hope this helps.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Re : How can I check if a GtkWidget exists?

2012-07-20 Thread Kevin DeKorte
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 07/20/2012 11:54 AM, Nicolas SOUBEIRAN wrote:
 Have you try g_object_add_weak_ref ? Weak references are used for 
 notification when an object is finalized. Hope this helps.

The GTK_IS_WIDGET macro is useful as well.

Kevin

- -- 
Get my public GnuPG key from
http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0x7D0BD5D1
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlAJnCUACgkQ6w2kMH0L1dECDACffj/EM0QcslT+mA43SQq7oWow
C8AAniwfsDSk13n/RP7friOwX/aUk2qQ
=ESuh
-END PGP SIGNATURE-
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list