GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sat Oct 25, 2014 10:51 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: gtk2 non modal dialog differentiated responses
PostPosted: Wed Feb 05, 2014 3:31 pm 
Offline
Familiar Face

Joined: Fri Oct 26, 2012 10:49 am
Posts: 37
I have a non-modal dialog with 2 buttons->OK and Cancel
I use "g_signal_connect_swapped " execute a function when the user clicks one of the button or closes the dialog.
I can I know which button has been clicked?
It is a NON-MODAL Dialog, that mean, I cannot use the command
Code:
response = gtk_dialog_run()

Tanks a lot for your help in advance
MBoerner

Code:

dialog = gtk_message_dialog_new (main_application_window,
                                  GTK_DIALOG_DESTROY_WITH_PARENT,
                                  GTK_MESSAGE_ERROR,
                                  GTK_BUTTONS_OK_CANCEL,
                                  "Error loading file '%s': %s",
                                  filename, g_strerror (errno));

/* Destroy the dialog when the user responds to it (e.g. clicks a button) */
g_signal_connect_swapped (dialog, "response",  G_CALLBACK (cb_on_response), dialog);
gtk_widget_show_all(dialog);


Code:

static gboolean  cb_on_response(GtkWidget *widget, gpointer data)
{
   (void) widget;
   (void) data;

switch
{
user has klicked CANCEL-> do this
user has klicked OK-> do that
}

return FALSE;
}




Top
 Profile  
 
 Post subject: Re: gtk2 non modal dialog differentiated responses
PostPosted: Thu Feb 06, 2014 11:09 am 
Offline
Familiar Face

Joined: Fri Oct 26, 2012 10:49 am
Posts: 37
I found it for myself.
Maybe somebody else needs it:
In the callback function cb_on_close_non_modal , the response is given by the parameter GtkResponseType response

just write:
Code:
g_signal_connect_swapped(nm_local.info_dialog, "response", G_CALLBACK (cb_on_close_non_modal), NULL);
gtk_widget_show_all(nm_local.info_dialog);


Code:
static gboolean  cb_on_close_non_modal(GtkWidget *widget, GtkResponseType response , gpointer data)
{
   switch (response)
   {
   case GTK_RESPONSE_OK:
      printf("OK\n");
      break;
   case GTK_RESPONSE_CANCEL:
      printf("CANCEL\n");
      break;
   }


return FALSE;
}


and it works.


Top
 Profile  
 
 Post subject: Re: gtk2 non modal dialog differentiated responses
PostPosted: Sun Feb 09, 2014 7:25 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 764
Location: UK
Hi your use of the "response" signal is slightly incorrect.

Your code should read more like the following. Note the changes to the call-back function. It does not return any value, the first argument is of type GtkDialog * and the second argument is of type gint.

Code:
g_signal_connect(nm_local.info_dialog, "response", G_CALLBACK (cb_on_close_non_modal), NULL);
gtk_widget_show_all(nm_local.info_dialog);


Code:
static void cb_on_close_non_modal(GtkDialog *widget, gint response , gpointer data)
{
   switch (response)
   {
   case GTK_RESPONSE_OK:
      printf("OK\n");
      break;
   case GTK_RESPONSE_CANCEL:
      printf("CANCEL\n");
      break;
   }
}

_________________
E.


Top
 Profile  
 
 Post subject: Re: gtk2 non modal dialog differentiated responses
PostPosted: Mon Feb 10, 2014 6:33 am 
Offline
Familiar Face

Joined: Fri Oct 26, 2012 10:49 am
Posts: 37
OK, Thank you, I changed it!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group