예제 #1
0
void
ACIconFactory::add(const Glib::ustring & theStockId, const Glib::ustring & theIconFile,
                   const Glib::ustring & theLabel)
{
    Glib::RefPtr<Gdk::Pixbuf> myPixbuf = Gdk::Pixbuf::create_from_file(theIconFile);
    Gtk::IconSource myIconSource;
    myIconSource.set_pixbuf(myPixbuf);
    Gtk::IconSet myIconSet;
    myIconSet.add_source( myIconSource );
    Gtk::StockID myStockId(theStockId);
    _myIconFactory->add(myStockId, myIconSet);
    Gtk::Stock::add(Gtk::StockItem(myStockId, theLabel));
}
예제 #2
0
/** \brief Registrate stock icons for this program. */
void
IconLoader::register_stock_items()
{
	Glib::RefPtr<Gtk::IconFactory> factory = Gtk::IconFactory::create();

	int i = 0;
	while (icons[i].file) {
		Gtk::IconSource source;

		try {
			// This throws an exception if the file is not found:
			source.set_pixbuf(Gdk::Pixbuf::create_from_file(icons[i].file));
		}
		catch (const Glib::Exception& ex) {
			std::cout << ex.what() << std::endl;
		}

		source.set_size(Gtk::ICON_SIZE_SMALL_TOOLBAR);
		// Icon may be scaled.
		source.set_size_wildcarded();

		Gtk::IconSet icon_set;
		// More than one source per set is allowed.
		icon_set.add_source(source);

		const Gtk::StockID stock_id(icons[i].id);
		factory->add( stock_id, icon_set);
		Gtk::Stock::add(Gtk::StockItem( stock_id, gettext(icons[i].label)));
		++i;
	}

	// Add factory to list of factories:
	factory->add_default();

	// register 64x64 pixels icon size
	Gtk::IconSize::register_new( icon_size_64x64, 64, 64);
}