Re: Dialog destruction signals.
- From: Count Zero <countzero cyberdeck org>
- To: gtk-list redhat com
- Subject: Re: Dialog destruction signals.
- Date: 14 Jun 2000 07:41:08 CDT
Farooq Mela was overheared mumbling something about this on Wed, 14 Jun 2000
00:19:59 -0700 (PDT)
> /* gtk_signal_connect(GTK_OBJECT(dialog),
> "delete_event",
> GTK_SIGNAL_FUNC(on_dialog_delete), dialog); */
on_dialog_delete will get "dialog" as "widget" so no need to pass it as data...
> gtk_signal_connect(GTK_OBJECT(dialog), "destroy",
> GTK_SIGNAL_FUNC(on_dialog_delete), dialog);
Same here...
> static gint
> on_dialog_delete(GtkWidget *widget, gpointer data)
> {
> GtkWidget *dialog;
> struct file_info *fi;
> int answer;
Again, widget == dialog... so no need to do GtkWidget *dialog or:
> dialog = data;
This line either...
> fi = gtk_object_get_data(GTK_OBJECT(dialog),
> "file_info");
fi = gtk_object_get_data(GTK_OBJECT(widget), "file_info");
> if(!fi->changed) {
> gtk_widget_destroy(dialog);
Problem here... you are doing this in the "delete_event" signal...
If you return FALSE, gtk is going to do gtk_widget_destroy() for you anyway, so
that will now FAIL if you destroy it... so, don't destroy here, just return
FALSE (Meaning, "Gtk, I did some stuff, but I didn't completely deal with the
"delete_event" signal, you go ahead and do your stuff too")
> return FALSE;
> }
>
> fi->changed = 0;
>
> answer = yesnocancel_dialog("This file has
> changed.\nDo you wish to save changes?",
> fi->filename, TRUE);
I assume yesnocancel_dialog() is modal?
> if(answer == 0) {
> gtk_widget_destroy(dialog);
bad, just return FALSE
> } else if(answer == 1) {
> on_file_save(widget, data);
> gtk_widget_destroy(dialog);
Again, just return FALSE
> } else {
> return TRUE;
Good, now your widget won't get destroyed...
> }
> return FALSE;
Good, now your widget WILL get destroyed....
> }
>
> /* -- END CODE -- */
>
> The problem is that the "delete_event" and "destroy"
> signals do not seem to be doing what they are supposed
> to. The delete_event signal, according to
> documentation, should be emitted before the destroy
> signal, and the emission of the destroy signal should
> be dependant upon the return value of the signal
> handler associated with the delete_event signal.
It does... problem is, you have already destroyed the widget and then you
return FALSE telling Gtk to try to destroy the widget too....
> In my
> program, connecting to the delete_event signal causes
> an assertation failure (caused by the call to
> `gtk_object_get_data' above) and then a segfault:
>
> Gtk-WARNING **: invalid unclassed pointer in cast to
> `GtkObject'
>
> Gtk-CRITICAL **: file gtkobject.c: line 1080
> (gtk_object_get_data): assertion `GTK_IS_OBJECT
> (object)' failed.
> Segmentation fault (core dumped)
>
> This obviously leads me to believe that the object was
> deconstructed and destroyed _before_ the signal
> handler for delete_event was called.
No, you destroyed the widget _before_ Gtk's signal handler for "delete_event"
was called.
> However,
> connecting to the "destroy" signal causes no such
> assertation failure. However, when connecting to the
> `destroy' signal, the dialog appears to be destroyed,
> before the dialog box from the `yesnocancel_dialog'
> function appears. But in reality it is only hidden,
> because the contents of the GtkText in that dialog can
> be saved from the signal handler!
"Destroy" is an informative signal. Gtk is saying "I am destroying this
widget, heres a last chance for you do do some stuff" But no matter what you
do, the widget will still be destroyed.
> This behaviour is really confusing me; it seems to be
> inconsistent with the way the `destroy' and
> `delete_event' signals work. Could this perhaps be
> caused by that fact that the dialog created is a
> GTK_WINDOW_DIALOG and not a GTK_WINDOW_TOPLEVEL?
No... windows are windows... the GTK_WINDOW_DIALOG and GTK_WINDOW_TOPLEVEL just
set some Window Manager hints so that they MAY look different (different border
styles, etc) but other than that, there is no difference...
> My second question is, how can I set the icon for my
> application? I.E., if the application is minimized,
> the icon I have set for the application appears rather
> than the default icon as set by the window manager?
GtkWidget *window;
GdkPixmap *pixmap;
GdkBitmap *mask;
GdkColormap *colormap;
window = gtk_window_new();
colormap = gtk_widget_get_colormap(window);
pixmap = gdk_pixmap_colormap_create_from_xpm(NULL, colormap, &mask, NULL,
"filename.xpm");
gdk_window_set_icon(window->window, NULL, pixmap, mask);
gdk_pixmap_unref(pixmap);
gdk_bitmap_unref(mask);
Of course, what icon gets displayed when a program is minimized is 100% up to
the Window Manager... We can only ASK that our icon gets displayed... What
actually happens will be WM and user preference dependant...
> Regards,
>
> Farooq
>
Your welcome,
-Count Zero
--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GIT/CM d--(+) s+: a- C++++ UL++++$ P+++ L+++>++++ E--- W+++(--) N+ o? K?
w---(++) O M->-- !V PS+++ PE Y+ PGP t+@ 5? X+ R++ tv-- b+++ DI? D++
G e h r- y+
------END GEEK CODE BLOCK------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]