GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Sep 16, 2014 7:30 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Access to buttons created via gtk_dialog_new_with_buttons()
PostPosted: Thu Nov 15, 2007 3:50 pm 
Offline
Familiar Face

Joined: Wed Oct 03, 2007 12:28 pm
Posts: 25
Location: Virginia (Northern)
I would like to access a dialog button that is created via gtk_dialog_new_with_buttons() in order to set its sensitivity property. As an example, there are times in my program during a runtime operation that I want the user to be able to 'Cancel', but not be able to press 'Ok'. After the operation is complete, then I desire the to have the opposite conditions... 'Cancel' deactivated, and 'Ok' active.

So... something like this...
Code:
dialog =
     gtk_dialog_new_with_buttons
       (
          "Dialog Title...",
          parent,
          GTK_DIALOG_DESTROY_WITH_PARENT,
          GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
          GTK_STOCK_OK, GTK_RESPONSE_OK,
          NULL
       );

/* This next function I fabricated... to illustrate what I am inquiring about... */
ok_button = gtk_get_dialog_stock_button( dialog, GTK_STOCK_OK );

/* Then I want to be able to control the particular buttons sensitivity */
gtk_widget_set_sensitive( ok_button, FALSE );


Perhaps I am just being stubborn and just need to accept that I need to initially create the dialog without any buttons... and then add them manually [presumably using gtk_dialiog_add_button() ]. That method, would of course, allow me to reference them directly. I would just like to know if this is actually necessary or are the buttons created via the very convenient function gtk_dialog_new_with_buttons() accessible?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 17, 2007 4:16 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
The buttons are packed into GTK_DIALOG(dialog)->action_area where dialog is your dialog. The action_area is a GtkHButtonBox.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject: Access to buttons created via gtk_dialog_new_with_buttons()
PostPosted: Sun Nov 18, 2007 4:45 pm 
Offline
Familiar Face

Joined: Wed Oct 03, 2007 12:28 pm
Posts: 25
Location: Virginia (Northern)
Is there a way to access the GtkButton* representing the button widget built in this manner?

I was able to accomplish this as follows, but am still curious whether the button widgets created via gtk_dialog_new_with_button() can be accessed...
Code:
   dialog =
     gtk_dialog_new_with_buttons
       (
          "Dialog Title...",
          parent,
          GTK_DIALOG_DESTROY_WITH_PARENT,
          NULL   /* NOTE: buttons were not specified */
       );

   /*
    * Now create the dialog buttons so that I can retain access to control
    * thesensitivity
    */
   cancel_btn =
     gtk_dialog_add_button( (GtkDialog*)dialog,
                            GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL );
   ok_btn =
     gtk_dialog_add_button( (GtkDialog*)dialog,
                             GTK_STOCK_OK, GTK_RESPONSE_OK );


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 18, 2007 7:14 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
dialog->action_area is a GtkHButtonBox, derived from GtkButtonBox, derived from GtkContainer. Therefore, you could use gtk_container_xx functions such as gtk_container_foreach() and gtk_container_get_children() which returns a GSList of the children. Then you can iterate through the buttons and set/unset their sensitivity.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject: Access to buttons created via gtk_dialog_new_with_buttons()
PostPosted: Mon Nov 19, 2007 1:24 pm 
Offline
Familiar Face

Joined: Wed Oct 03, 2007 12:28 pm
Posts: 25
Location: Virginia (Northern)
Oh, ok, I get it... great thanks for the tip!

:D


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


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