qulogic/libgnt

Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
next.minor
2007-10-20, Sadrul Habib Chowdhury
b2b27f700dba
Parents bd9935b376e6
Children cecac099a870
Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
  • +10 -9
    gntmenu.c
  • +26 -1
    gntmenuitem.c
  • +13 -0
    gntmenuitem.h
  • --- a/gntmenu.c Sat Oct 20 05:50:48 2007 +0000
    +++ b/gntmenu.c Sat Oct 20 05:52:52 2007 +0000
    @@ -181,7 +181,15 @@
    static void
    menuitem_activate(GntMenu *menu, GntMenuItem *item)
    {
    - if (item) {
    + if (!item)
    + return;
    +
    + if (gnt_menuitem_activate(item)) {
    + while (menu) {
    + gnt_widget_hide(GNT_WIDGET(menu));
    + menu = menu->parentmenu;
    + }
    + } else {
    if (item->submenu) {
    GntMenu *sub = GNT_MENU(item->submenu);
    menu->submenu = sub;
    @@ -195,12 +203,6 @@
    gnt_widget_set_position(GNT_WIDGET(sub), item->priv.x, item->priv.y);
    GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(sub), GNT_WIDGET_INVISIBLE);
    gnt_widget_draw(GNT_WIDGET(sub));
    - } else if (item->callback) {
    - item->callback(item, item->callbackdata);
    - while (menu) {
    - gnt_widget_hide(GNT_WIDGET(menu));
    - menu = menu->parentmenu;
    - }
    }
    }
    }
    @@ -326,8 +328,7 @@
    GntMenu *menu = GNT_MENU(tree);
    gboolean check = gnt_menuitem_check_get_checked(GNT_MENU_ITEM_CHECK(item));
    gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item), !check);
    - if (item->callback)
    - item->callback(item, item->callbackdata);
    + gnt_menuitem_activate(item);
    while (menu) {
    gnt_widget_hide(GNT_WIDGET(menu));
    menu = menu->parentmenu;
    --- a/gntmenuitem.c Sat Oct 20 05:50:48 2007 +0000
    +++ b/gntmenuitem.c Sat Oct 20 05:52:52 2007 +0000
    @@ -23,6 +23,13 @@
    #include "gntmenu.h"
    #include "gntmenuitem.h"
    +enum
    +{
    + SIG_ACTIVATE,
    + SIGS
    +};
    +static guint signals[SIGS] = { 0 };
    +
    static GObjectClass *parent_class = NULL;
    static void
    @@ -44,10 +51,18 @@
    parent_class = g_type_class_peek_parent(klass);
    obj_class->dispose = gnt_menuitem_destroy;
    +
    + signals[SIG_ACTIVATE] =
    + g_signal_new("activate",
    + G_TYPE_FROM_CLASS(klass),
    + G_SIGNAL_RUN_LAST,
    + 0, NULL, NULL,
    + g_cclosure_marshal_VOID__VOID,
    + G_TYPE_NONE, 0);
    }
    static void
    -gnt_menuitem_init(GTypeInstance *instance, gpointer class)
    +gnt_menuitem_init(GTypeInstance *instance, gpointer klass)
    {
    }
    @@ -131,3 +146,13 @@
    return item->priv.id;
    }
    +gboolean gnt_menuitem_activate(GntMenuItem *item)
    +{
    + g_signal_emit(item, signals[SIG_ACTIVATE], 0);
    + if (item->callback) {
    + item->callback(item, item->callbackdata);
    + return TRUE;
    + }
    + return FALSE;
    +}
    +
    --- a/gntmenuitem.h Sat Oct 20 05:50:48 2007 +0000
    +++ b/gntmenuitem.h Sat Oct 20 05:52:52 2007 +0000
    @@ -168,6 +168,19 @@
    */
    const char * gnt_menuitem_get_id(GntMenuItem *item);
    +/**
    + * Activate a menuitem.
    + * Activating the menuitem will first trigger the 'activate' signal for the
    + * menuitem. Then the callback for the menuitem is triggered, if there is one.
    + *
    + * @param item The menuitem.
    + *
    + * @return Whether the callback for the menuitem was called.
    + *
    + * @since 2.3.0
    + */
    +gboolean gnt_menuitem_activate(GntMenuItem *item);
    +
    G_END_DECLS
    #endif /* GNT_MENUITEM_H */