libgnt/libgnt

Add private accessors to some GntMenu internals.

2019-04-24, Elliott Sales de Andrade
0f4ef296f3f9
Parents 49842f6491e1
Children 50e4271f8b4a
Add private accessors to some GntMenu internals.
  • +2 -1
    gntmain.c
  • +31 -0
    gntmenu.c
  • +39 -0
    gntmenuprivate.h
  • +4 -3
    gntwindow.c
  • +2 -1
    gntwm.c
  • --- a/gntmain.c Thu Apr 25 03:42:09 2019 -0400
    +++ b/gntmain.c Wed Apr 24 01:05:07 2019 -0400
    @@ -50,6 +50,7 @@
    #include "gntwindow.h"
    #include "gntwm.h"
    +#include "gntmenuprivate.h"
    #include "gntwsprivate.h"
    #include <panel.h>
    @@ -497,7 +498,7 @@
    do {
    gnt_widget_hide(GNT_WIDGET(wm->menu));
    if (wm->menu)
    - wm->menu = wm->menu->parentmenu;
    + wm->menu = gnt_menu_get_parent_menu(wm->menu);
    } while (wm->menu);
    }
    --- a/gntmenu.c Thu Apr 25 03:42:09 2019 -0400
    +++ b/gntmenu.c Wed Apr 24 01:05:07 2019 -0400
    @@ -527,3 +527,34 @@
    return item;
    }
    +/* Internal. */
    +GntMenuType
    +gnt_menu_get_menutype(GntMenu *menu)
    +{
    + g_return_val_if_fail(GNT_IS_MENU(menu), 0);
    + return menu->type;
    +}
    +
    +/* Internal. */
    +GntMenuItem *
    +gnt_menu_get_selected_item(GntMenu *menu)
    +{
    + g_return_val_if_fail(GNT_IS_MENU(menu), NULL);
    + return g_list_nth_data(menu->list, menu->selected);
    +}
    +
    +/* Internal. */
    +GntMenu *
    +gnt_menu_get_parent_menu(GntMenu *menu)
    +{
    + g_return_val_if_fail(GNT_IS_MENU(menu), NULL);
    + return menu->parentmenu;
    +}
    +
    +/* Internal. */
    +GntMenu *
    +gnt_menu_get_submenu(GntMenu *menu)
    +{
    + g_return_val_if_fail(GNT_IS_MENU(menu), NULL);
    + return menu->submenu;
    +}
    --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/gntmenuprivate.h Wed Apr 24 01:05:07 2019 -0400
    @@ -0,0 +1,39 @@
    +/*
    + * GNT - The GLib Ncurses Toolkit
    + *
    + * GNT is the legal property of its developers, whose names are too numerous
    + * to list here. Please refer to the COPYRIGHT file distributed with this
    + * source distribution.
    + *
    + * This library is free software; you can redistribute it and/or modify
    + * it under the terms of the GNU General Public License as published by
    + * the Free Software Foundation; either version 2 of the License, or
    + * (at your option) any later version.
    + *
    + * This program is distributed in the hope that it will be useful,
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    + * GNU General Public License for more details.
    + *
    + * You should have received a copy of the GNU General Public License along with
    + * this program; if not, write to the Free Software Foundation, Inc.,
    + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    + */
    +
    +#ifndef GNT_MENU_PRIVATE_H
    +#define GNT_MENU_PRIVATE_H
    +
    +#include "gnt.h"
    +#include "gntmenu.h"
    +
    +G_BEGIN_DECLS
    +
    +/* Private access to some internals. Contact us if you need these. */
    +GntMenuType gnt_menu_get_menutype(GntMenu *menu);
    +GntMenuItem *gnt_menu_get_selected_item(GntMenu *menu);
    +GntMenu *gnt_menu_get_parent_menu(GntMenu *menu);
    +GntMenu *gnt_menu_get_submenu(GntMenu *menu);
    +
    +G_END_DECLS
    +
    +#endif /* GNT_MENU_PRIVATE_H */
    --- a/gntwindow.c Thu Apr 25 03:42:09 2019 -0400
    +++ b/gntwindow.c Wed Apr 24 01:05:07 2019 -0400
    @@ -24,6 +24,8 @@
    #include "gntstyle.h"
    #include "gntwindow.h"
    +#include "gntmenuprivate.h"
    +
    #include <string.h>
    typedef struct
    @@ -56,9 +58,8 @@
    GntMenu *menu = priv->menu;
    gnt_screen_menu_show(menu);
    - if (menu->type == GNT_MENU_TOPLEVEL) {
    - GntMenuItem *item;
    - item = g_list_nth_data(menu->list, menu->selected);
    + if (gnt_menu_get_menutype(menu) == GNT_MENU_TOPLEVEL) {
    + GntMenuItem *item = gnt_menu_get_selected_item(menu);
    if (item && gnt_menuitem_get_submenu(item)) {
    gnt_widget_activate(GNT_WIDGET(menu));
    }
    --- a/gntwm.c Thu Apr 25 03:42:09 2019 -0400
    +++ b/gntwm.c Wed Apr 24 01:05:07 2019 -0400
    @@ -60,6 +60,7 @@
    #include "gntutils.h"
    #include "gntwindow.h"
    +#include "gntmenuprivate.h"
    #include "gntwsprivate.h"
    #define IDLE_CHECK_INTERVAL 5 /* 5 seconds */
    @@ -237,7 +238,7 @@
    GntNode *node = g_hash_table_lookup(wm->nodes, top);
    if (node)
    top_panel(node->panel);
    - top = top->submenu;
    + top = gnt_menu_get_submenu(top);
    }
    }
    work_around_for_ncurses_bug();