>________________________________
> From: Roger Davis <r...@soest.hawaii.edu>
>To: Lance Dillon <riffraff...@yahoo.com> 
>Cc: "gtk-app-devel-list@gnome.org" <gtk-app-devel-list@gnome.org> 
>Sent: Thursday, March 8, 2012 2:07 AM
>Subject: Re: modifiable dialog button labels?
> 
>
>
>On Wed, 7 Mar 2012, Lance Dillon wrote:
>
>> you can use gtk_get_action_area() to get the GtkBox that that is the action
>> area, that itself contains the buttons.  I believe you can then get all the
>> child widgets, which would be the GtkButtons.
>> 
>> The  docs for GtkDialog describes it some, but doesn't talk about getting the
>> buttons.  I think you would have to go to the page for GtkBox for how to get
>> the children.
>
>Hi Lance,
>
>The GtkDialog documentation tells only how to access the action area, not its 
>children. Searching around I see a gtk_container_get_children() which 
>presumably returns a list of GtkWidget pointers. Is there a way I can look at 
>a widget pointer and detrmine the widget's type, i.e., figure out whether or 
>not it's a button? I see references to a gtk_widget_get_type() on the web, but 
>no good examples of how it's used, and it appears to be not present at all in 
>my own GTK release's GtkWidget documentation. There also seem to be some 
>related type discovery functions in the gobject library such as g_type(), 
>etc., but so far I have not found any useful examples of how I might use them 
>to figure out if any particular widget pointer is a button or not.
>
>Thanks,
>
>Roger
>
>You would then use g_type_is_a() (possibly), perhaps with G_TYPE_FROM_INSTANCE 
>and g_type_from_name():

GList *g,*g1;
g1=g=gtk_container_get_children(GTK_CONTAINER(gtk_dialog_get_action_area(dialogbox)));

while(g1);

if (g_type_is_a(G_TYPE_FROM_INSTANCE(g1->data),g_type_from_name("GtkButton"))) {
  /* do something with button */
  g1=g_list_next(g1);
}

g_list_free(g);



You can of course create the dialog without buttons with gtk_dialog_new(), then 
add buttons manually with gtk_dialog_add_button(), and save the return value 
which is the widget, then change the labels on the buttons  when you need to.  
That may be easier than the above:

GtkWidget *d;
d=gtk_dialog_new();
GtkButton *b1,*b2;
b1=gtk_dialog_add_button(GTK_DIALOG(d),"Wine",1);
b2=gtk_dialog_add_button(GTK_DIALOG(d),"Beer",2);

Then do your gtk_dialog_run() later.  Then when you need to change the values, 
you can just do gtk_button_set_label(b1,"Dog"); gtk_button_set_label(b2,"Cat"), 
then reshow your dialog and gtk_dialog_run() again.
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to