Allow setting icons for submenus

This commit is contained in:
Mikael Magnusson 2010-04-16 17:58:20 +02:00 committed by Dana Jansens
parent 6ad5f085fa
commit 588aa0790a
3 changed files with 32 additions and 9 deletions

View file

@ -326,6 +326,8 @@ static void parse_menu(xmlNodePtr node, gpointer data)
ObMenuParseState *state = data;
gchar *name = NULL, *title = NULL, *script = NULL;
ObMenu *menu;
ObMenuEntry *e;
gchar *icon;
if (!obt_xml_attr_string(node, "id", &name))
goto parse_menu_fail;
@ -349,8 +351,20 @@ static void parse_menu(xmlNodePtr node, gpointer data)
}
}
if (state->parent)
menu_add_submenu(state->parent, -1, name);
if (state->parent) {
e = menu_add_submenu(state->parent, -1, name);
if (config_menu_show_icons &&
obt_xml_attr_string(node, "icon", &icon))
{
e->data.submenu.icon = RrImageNewFromName(ob_rr_icons, icon);
if (e->data.submenu.icon)
e->data.submenu.icon_alpha = 0xff;
g_free(icon);
}
}
parse_menu_fail:
g_free(name);
@ -534,6 +548,7 @@ void menu_entry_unref(ObMenuEntry *self)
}
break;
case OB_MENU_ENTRY_TYPE_SUBMENU:
RrImageUnref(self->data.submenu.icon);
g_free(self->data.submenu.name);
break;
case OB_MENU_ENTRY_TYPE_SEPARATOR:

View file

@ -103,6 +103,10 @@ typedef enum
} ObMenuEntryType;
struct _ObNormalMenuEntry {
/* Icon stuff. If you set this, make sure you RrImageRef() it too. */
RrImage *icon;
gint icon_alpha;
gchar *label;
/*! The shortcut key that would be used to activate this menu entry */
gunichar shortcut;
@ -117,10 +121,6 @@ struct _ObNormalMenuEntry {
/* List of ObActions */
GSList *actions;
/* Icon stuff. If you set this, make sure you RrImageRef() it too. */
RrImage *icon;
gint icon_alpha;
/* Mask icon */
RrPixmapMask *mask;
RrColor *mask_normal_color;
@ -132,8 +132,13 @@ struct _ObNormalMenuEntry {
};
struct _ObSubmenuMenuEntry {
/* Icon stuff. If you set this, make sure you RrImageRef() it too. */
RrImage *icon;
gint icon_alpha;
gchar *name;
ObMenu *submenu;
guint show_from;
};

View file

@ -181,7 +181,8 @@ static ObMenuEntryFrame* menu_entry_frame_new(ObMenuEntry *entry,
self->text = createWindow(self->window, 0, NULL);
g_hash_table_insert(menu_frame_map, &self->window, self);
g_hash_table_insert(menu_frame_map, &self->text, self);
if (entry->type == OB_MENU_ENTRY_TYPE_NORMAL) {
if ((entry->type == OB_MENU_ENTRY_TYPE_NORMAL) ||
(entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)) {
self->icon = createWindow(self->window, 0, NULL);
g_hash_table_insert(menu_frame_map, &self->icon, self);
}
@ -209,7 +210,8 @@ static void menu_entry_frame_free(ObMenuEntryFrame *self)
XDestroyWindow(obt_display, self->window);
g_hash_table_remove(menu_frame_map, &self->text);
g_hash_table_remove(menu_frame_map, &self->window);
if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) {
if ((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) ||
(self->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)) {
XDestroyWindow(obt_display, self->icon);
g_hash_table_remove(menu_frame_map, &self->icon);
}
@ -522,7 +524,8 @@ static void menu_entry_frame_render(ObMenuEntryFrame *self)
g_assert_not_reached();
}
if (self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
if (((self->entry->type == OB_MENU_ENTRY_TYPE_NORMAL) ||
(self->entry->type == OB_MENU_ENTRY_TYPE_SUBMENU)) &&
self->entry->data.normal.icon)
{
RrAppearance *clear;