Re: using gnome stock-items in GTK+
- From: John Cupitt <jcupitt gmail com>
- To: edward hage <edha xs4all nl>
- Cc: gtk-list gnome org
- Subject: Re: using gnome stock-items in GTK+
- Date: Sun, 19 Sep 2004 12:49:39 +0100
On Sun, 19 Sep 2004 12:27:56 +0200, edward hage <edha xs4all nl> wrote:
> Another question; is there a how-to to create stock-items from scratch (adding png-files
> and labels yourself). I found the API to be quit complicated.
Here's the code I ended up with after some fiddling and looking at the
GIMP sources:
static void
main_file_for_stock( GtkIconFactory *icon_factory,
const char *stock, const char *file )
{
GtkIconSource *icon_source;
GtkIconSet *icon_set;
char buf[FILENAME_MAX];
char buf2[FILENAME_MAX];
im_snprintf( buf2, FILENAME_MAX,
"$VIPSHOME/share/$PACKAGE/data/%s", file );
expand_variables( buf2, buf );
nativize_path( buf );
icon_source = gtk_icon_source_new();
gtk_icon_source_set_filename( icon_source, buf );
icon_set = gtk_icon_set_new();
gtk_icon_set_add_source( icon_set, icon_source );
gtk_icon_source_free( icon_source );
gtk_icon_factory_add( icon_factory, stock, icon_set );
gtk_icon_set_unref( icon_set );
}
then in startup:
static const GtkStockItem stock_item[] = {
/* Can be (eg.)
*
* { GTK_STOCK_COPY, N_("_Copy"), GDK_CONTROL_MASK, 'c', GETTEXT_PACKAGE },
*
*/
{ STOCK_PAINTBRUSH, N_( "Pen" ),
0, 0, GETTEXT_PACKAGE },
{ STOCK_LINE, N_( "Line" ),
0, 0, GETTEXT_PACKAGE },
etc.
};
gtk_stock_add_static( stock_item, IM_NUMBER( stock_item ) );
main_icon_factory = gtk_icon_factory_new();
main_file_for_stock( main_icon_factory,
STOCK_PAINTBRUSH, "stock-tool-ink-22.png" );
main_file_for_stock( main_icon_factory,
STOCK_LINE, "stock-tool-path-22.png" );
etc.
gtk_icon_factory_add_default( main_icon_factory );
g_object_unref( main_icon_factory );
Then you can use STOCK_LINE like any other stock item (if I've not
forgotten anything).
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]