[yast-commit] r59867 - in /trunk/gtk: ChangeLog src/YGUtils.cc src/YGUtils.h src/ygtkwizard.c
Author: rpmcruz Date: Tue Dec 1 04:30:59 2009 New Revision: 59867 URL: http://svn.opensuse.org/viewcvs/yast?rev=59867&view=rev Log: * src/YGUtils.h/cc & src/ygtkwizard.c: map stock icons to menu items (try autoyast). Modified: trunk/gtk/ChangeLog trunk/gtk/src/YGUtils.cc trunk/gtk/src/YGUtils.h trunk/gtk/src/ygtkwizard.c Modified: trunk/gtk/ChangeLog URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/ChangeLog?rev=59867&r1=59866&r2=59867&view=diff ============================================================================== --- trunk/gtk/ChangeLog (original) +++ trunk/gtk/ChangeLog Tue Dec 1 04:30:59 2009 @@ -11,6 +11,9 @@ * src/YGPackageSelector.cc: partial bug fix for 548437: honor a couple of the flags. + * src/YGUtils.h/cc & src/ygtkwizard.c: map stock icons + to menu items (try autoyast). + 2009-11-26 Ricardo Cruz <rpmcruz@alunos.dcc.fc.up.pt> * src/YGPackageSelector.cc: added support for Modified: trunk/gtk/src/YGUtils.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGUtils.cc?rev=59867&r1=59866&r2=59867&view=diff ============================================================================== --- trunk/gtk/src/YGUtils.cc (original) +++ trunk/gtk/src/YGUtils.cc Tue Dec 1 04:30:59 2009 @@ -573,8 +573,7 @@ str.erase (str.size()-1, 1); } -const char *YGUtils::setStockIcon (GtkWidget *button, const std::string &label, - const char *fallbackIcon) +const char *YGUtils::mapStockIcon (const std::string &label) { static bool firstTime = true; static std::map <std::string, std::string> stockMap; if (firstTime) { @@ -591,6 +590,8 @@ _id = GTK_STOCK_GO_FORWARD; else if (!strcmp (id, GTK_STOCK_MEDIA_PREVIOUS) || !strcmp (id, GTK_STOCK_MEDIA_REWIND)) _id = GTK_STOCK_GO_BACK; + else if (!strcmp (id, GTK_STOCK_MEDIA_RECORD)) + _id = GTK_STOCK_SAVE; stockMap[cutUnderline (item.label)] = _id; } // some may not have a stock item because they can't be set on a label @@ -612,6 +613,7 @@ stockMap [_("Down")] = GTK_STOCK_GO_DOWN; stockMap [_("Enable")] = GTK_STOCK_YES; stockMap [_("Disable")] = GTK_STOCK_NO; + stockMap [_("Exit")] = GTK_STOCK_QUIT; } std::string id = cutUnderline (label); @@ -621,17 +623,21 @@ std::map <std::string, std::string>::const_iterator it; it = stockMap.find (id); - bool foundIcon = it != stockMap.end(); - const char *icon = NULL; - if (foundIcon) - icon = it->second.c_str(); - else if (id.size() < 22) + if (it != stockMap.end()) + return it->second.c_str(); + return NULL; +} + +const char *YGUtils::setStockIcon (GtkWidget *button, const std::string &label, + const char *fallbackIcon) +{ + const char *icon = mapStockIcon (label); + if (!icon && label.size() < 22) icon = fallbackIcon; if (icon) { if (gtk_style_lookup_icon_set (button->style, icon)) { // we want to use GtkImage stock mode so it honors sensitive GtkWidget *image = gtk_image_new_from_stock (icon, GTK_ICON_SIZE_BUTTON); - gtk_widget_show (image); gtk_button_set_image (GTK_BUTTON (button), image); } } @@ -640,10 +646,9 @@ if (image) gtk_widget_hide (image); } - return foundIcon ? icon : NULL; + return icon; } - /* * construct a help string by dropping the title, and mentioning * the first sentence for a dialog sub-title @@ -712,6 +717,9 @@ return g_string_free (str, FALSE); } +const char *ygutils_mapStockIcon (const char *label) +{ return YGUtils::mapStockIcon (label); } + const char *ygutils_setStockIcon (GtkWidget *button, const char *label, const char *fallback) { return YGUtils::setStockIcon (button, label, fallback); } Modified: trunk/gtk/src/YGUtils.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/YGUtils.h?rev=59867&r1=59866&r2=59867&view=diff ============================================================================== --- trunk/gtk/src/YGUtils.h (original) +++ trunk/gtk/src/YGUtils.h Tue Dec 1 04:30:59 2009 @@ -49,6 +49,7 @@ GdkPixbuf *setOpacity (const GdkPixbuf *src, int opacity, bool touchAlpha); /* Tries to make sense out of the string, applying some stock icon to the button. */ + const char *mapStockIcon (const std::string &label); const char *setStockIcon (GtkWidget *button, const std::string &label, const char *fallbackIcon); }; @@ -60,6 +61,7 @@ void ygutils_scrollAdj (GtkAdjustment *vadj, gboolean top); + const char *ygutils_mapStockIcon (const char *label); const char *ygutils_setStockIcon (GtkWidget *button, const char *label, const char *fallbackIcon); Modified: trunk/gtk/src/ygtkwizard.c URL: http://svn.opensuse.org/viewcvs/yast/trunk/gtk/src/ygtkwizard.c?rev=59867&r1=59866&r2=59867&view=diff ============================================================================== --- trunk/gtk/src/ygtkwizard.c (original) +++ trunk/gtk/src/ygtkwizard.c Tue Dec 1 04:30:59 2009 @@ -27,6 +27,7 @@ // YGUtils bridge extern void ygutils_setWidgetFont (GtkWidget *widget, PangoStyle style, PangoWeight weight, double scale); +extern const char *ygutils_mapStockIcon (const char *label); extern const char *ygutils_setStockIcon (GtkWidget *button, const char *label, const char *fallbackIcon); extern GdkPixbuf *ygutils_setOpacity (const GdkPixbuf *src, int opacity, gboolean alpha); @@ -942,7 +943,15 @@ if (!parent) return FALSE; - GtkWidget *entry = gtk_menu_item_new_with_mnemonic (text); + GtkWidget *entry; + const char *icon = ygutils_mapStockIcon (text); + if (icon) { + GtkWidget *image = gtk_image_new_from_stock (icon, GTK_ICON_SIZE_MENU); + entry = gtk_image_menu_item_new_with_mnemonic (text); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (entry), image); + } + else + entry = gtk_menu_item_new_with_mnemonic (text); gtk_menu_shell_append (GTK_MENU_SHELL (parent), entry); gtk_widget_show (entry); -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
rpmcruz@svn.opensuse.org