qulogic/libgnt

Merged in default (pull request #45)

2019-04-26, Gary Kramlich
2e237235d055
Merged in default (pull request #45)

Hide GntMenu internals

Approved-by: Gary Kramlich
  • +2 -1
    gntmain.c
  • +45 -0
    gntmenu.c
  • +2 -38
    gntmenu.h
  • +39 -0
    gntmenuprivate.h
  • +4 -3
    gntwindow.c
  • +2 -1
    gntwm.c
  • --- a/gntmain.c Wed Apr 24 03:44:25 2019 -0400
    +++ b/gntmain.c Fri Apr 26 03:42:29 2019 +0000
    @@ -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 Wed Apr 24 03:44:25 2019 -0400
    +++ b/gntmenu.c Fri Apr 26 03:42:29 2019 +0000
    @@ -29,6 +29,20 @@
    #include <ctype.h>
    #include <string.h>
    +struct _GntMenu
    +{
    + GntTree parent;
    + GntMenuType type;
    +
    + GList *list;
    + guint selected;
    +
    + /* This will keep track of its immediate submenu which is visible so
    + * that keystrokes can be passed to it. */
    + GntMenu *submenu;
    + GntMenu *parentmenu;
    +};
    +
    enum
    {
    SIGS = 1,
    @@ -551,3 +565,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;
    +}
    --- a/gntmenu.h Wed Apr 24 03:44:25 2019 -0400
    +++ b/gntmenu.h Fri Apr 26 03:42:29 2019 +0000
    @@ -35,15 +35,9 @@
    #include "gntcolors.h"
    #include "gntkeys.h"
    -#define GNT_TYPE_MENU (gnt_menu_get_type())
    -#define GNT_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_MENU, GntMenu))
    -#define GNT_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_MENU, GntMenuClass))
    -#define GNT_IS_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_MENU))
    -#define GNT_IS_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_MENU))
    -#define GNT_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_MENU, GntMenuClass))
    +#define GNT_TYPE_MENU gnt_menu_get_type()
    typedef struct _GntMenu GntMenu;
    -typedef struct _GntMenuClass GntMenuClass;
    #include "gntmenuitem.h"
    @@ -62,36 +56,6 @@
    GNT_MENU_POPUP,
    } GntMenuType;
    -/**
    - * GntMenu:
    - *
    - * Access to any fields is deprecated. See inline comments for replacements.
    - */
    -struct _GntMenu
    -{
    - GntTree parent;
    - GntMenuType GNTSEAL(type);
    -
    - GList *GNTSEAL(list);
    - guint GNTSEAL(selected);
    -
    - /* This will keep track of its immediate submenu which is visible so that
    - * keystrokes can be passed to it. */
    - GntMenu *GNTSEAL(submenu);
    - GntMenu *GNTSEAL(parentmenu);
    -};
    -
    -struct _GntMenuClass
    -{
    - GntTreeClass parent;
    -
    - /*< private >*/
    - void (*gnt_reserved1)(void);
    - void (*gnt_reserved2)(void);
    - void (*gnt_reserved3)(void);
    - void (*gnt_reserved4)(void);
    -};
    -
    G_BEGIN_DECLS
    /**
    @@ -99,7 +63,7 @@
    *
    * Returns: The GType for GntMenu.
    */
    -GType gnt_menu_get_type(void);
    +G_DECLARE_FINAL_TYPE(GntMenu, gnt_menu, GNT, MENU, GntTree)
    /**
    * gnt_menu_new:
    --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/gntmenuprivate.h Fri Apr 26 03:42:29 2019 +0000
    @@ -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 Wed Apr 24 03:44:25 2019 -0400
    +++ b/gntwindow.c Fri Apr 26 03:42:29 2019 +0000
    @@ -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 Wed Apr 24 03:44:25 2019 -0400
    +++ b/gntwm.c Fri Apr 26 03:42:29 2019 +0000
    @@ -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();