Re: Signals and marshaling



Your 'Quit' should be tied to your destroy
callback rather than your delete-event. 
If you are exiting within the delete-event
and not processing the destroy, then it
won't work :-).  
The delete_event callback does
whatever processing to ensure the user
really wants to close the app, then returns a 
FALSE.  This causes a destroy signal - I usually 
have a simple destroy callback which does gtk_main_quit():

void bye( GtkWidget *widget, gpointer user_data)
 {
   printf("Quitting now\n");
   /* And anything else I might need */
   gtk_main_quit();
 }

and is connected to both the destroy signal
and the activate of a 'Quit' menu item:

  gtk_signal_connect( GTK_OBJECT(quit_item), "activate", bye, NULL );
  gtk_signal_connect( GTK_OBJECT(top_widget), "delete-event", 
                     GTK_SIGNAL_FUNC(delete_handler), NULL );
  gtk_signal_connect( GTK_OBJECT(top_widget), "destroy", bye, NULL );


HTH,
Seems like this is in the tutorial
Donna
----- Original Message ----- 
From: Dmitry Ponomaryov <eagleowl comail ru>
To: <gtk-app-devel-list gnome org>
Sent: Wednesday, January 24, 2001 6:52 AM
Subject: Signals and marshaling



Another question:
I want that 'Quit' menu item close my application. But I already define
callback for "delete_event". So put call to this call back into 'Quit'
menu-item callback:

void
menu_close_cb( GtkWidget* widget,
   gpointer   data )
{
delete_event_cb( NULL, NULL );
}

But this is ugly (am I right?) - I decide to make the following:
'Quit' menu item should emit "delete_event", which will be traped
by application and so "delete_event_cb" will be called automaticly
(self-acting). So:

void
menu_close_cb( GtkWidget* widget,
   gpointer   data )
{
/* Parameter 'data' is main_window widget.  */
gtk_signal_emit_by_name( GTK_OBJECT(data), "delete_event" );

file://delete_event_cb( NULL, NULL );
}

But this dump core :-[ - something wrong with signal priorities?
[one signal called during another].

So to avoid core dump I define my marshaller and call back for menu
item:

gtk_signal_connect_full( GTK_OBJECT(close_item),
"activate",
NULL, /* No call-back function at all! */
(GtkCallbackMarshal)(delete_event_marshal_NONE__NONE),
GTK_WIDGET(main_window),
NULL,
FALSE,
GTK_RUN_FIRST );


void gcp_delete_event_marshal_NONE__NONE(GtkObject *object,
    gpointer   data,
    guint      n_args,
    GtkArg    *args)
{
gtk_signal_emit_by_name( GTK_OBJECT(data), "delete_event" );
}


But this core dump too!!!

How can I transform emition of one signal to emition of other signal?
 [or call one signal from another?]

PS. Does "gtk_signal_emit_stop_by_name" stops propagation only for
    for current signal with given name (and NOT all signals with given
    name [may be in future])? If I am right may be I should use
"gtk_signal_emit_stop_by_name"
    to stop one signal propagation and after that emit another signal?
    Something like:
    (I haven't try the following example yet)

void
menu_close_cb( GtkWidget* widget,
   gpointer   data )
{
/* Stop current signal propagation.  */
gtk_signal_emit_stop_by_name( GTK_OBJECT(widget) /* menu item */,
"activate" );

/* Parameter 'data' is main_window widget.  */
gtk_signal_emit_by_name( GTK_OBJECT(data), "delete_event" );

file://delete_event_cb( NULL, NULL );
}

---
Dmitry Ponomaryov


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list






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