[Xfc-dev] xfc questions

Jeff Franks jcfranks at tpg.com.au
Sat Aug 20 12:08:35 CEST 2005


Xavier Otazu wrote:

>> [snip]
>
>I do not define the label on Glade, and as you tell, it works fine and the 
>button does not allocate space for this label. But in some places of my 
>code I need to change button image.
>
>In the xfc-4.3/docs/reference/html/classXfc_1_1Gtk_1_1Button.html#z601_11 
>html file of documentation of void Xfc::Gtk::Button::set_image (Widget & 
>image) function, you tell :
>
>void Xfc::Gtk::Button::set_image (Widget &image)
>
>Set the image of the button to the given widget.
>
>Parameters:
>     	image 	The Image you want the button to display.
>
>For this method to work the button label must be set first.
>  
>
This is true, but it is GtkButton that requires the label to be set, not 
XFC.  In the gtk_button_constructor_child() function in gtkbutton.c is 
this line of code:

if (button->label_text == NULL)
    return;

It is this line of code that stops the image being changed if the label 
text is not set.

When you use a GtkButton you create a blank button and add your own 
widget, such as a Gtk::Image, or you create a text button, or you create 
a stock image button. When you create a stock image button it is 
supposed to display text  and/or icon depending on the current theme's 
button icon/text setting. That is why you observe the behaviour you 
describe. What you want is an empty button that you add a stock 
Gtk::Image too. Glade does this for you.

When you select the stock id from the 'Stock Button' combo box list in 
the property editor, Glade creates a stock button with image and label. 
If the label text field is blank GTK wont create the label initially but 
as you can see from the above lines of code the constrcutor function 
will abort if the label text is NULL. When you select a stock id from 
the icon combo box list in the property editor, Glade creates an empty 
button and adds to it a GtkImage child widget. If you look at the .glade 
file you will see this. The answer to you problem is to select your 
stock id from the icon list and then set the image on the  Gtk::Image, 
not the Gtk::Button.

>
>
>I tried not to set the label prior to calling the set_image() function, 
>but the image on the button does not change. I have to call the 
>set_label() function to change the image of an already existing Button.
>
>  
>
Xavier,

Attached is a modifed xfcapp which correctly does what you are trying to do.

Jeff.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: xfcapp.tar.gz
Type: application/x-gzip
Size: 1482 bytes
Desc: not available
URL: <http://mail.xfce.org/pipermail/xfc-dev/attachments/20050820/d4a02029/attachment.bin>


More information about the Xfc-dev mailing list