1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #ifndef INCLUDED_VCL_INC_UNX_GTK_GTKSALMENU_HXX
11 #define INCLUDED_VCL_INC_UNX_GTK_GTKSALMENU_HXX
13 #include <config_dbus.h>
14 #include <config_gio.h>
21 #include <salmenu.hxx>
22 #include <unx/gtk/gtkframe.hxx>
23 #include <vcl/idle.hxx>
25 #if ENABLE_DBUS && ENABLE_GIO && \
26 (GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION >= 36)
27 # define ENABLE_GMENU_INTEGRATION
28 # include <unx/gtk/glomenu.h>
29 # include <unx/gtk/gloactiongroup.h>
31 # if !(GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION >= 32)
32 typedef void GMenuModel
;
34 # if !(GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION >= 28)
35 typedef void GActionGroup
;
42 class GtkSalMenu
: public SalMenu
45 std::vector
< GtkSalMenuItem
* > maItems
;
46 Idle maUpdateMenuBarIdle
;
48 bool mbInActivateCallback
;
51 bool mbReturnFocusToDocument
;
53 GtkWidget
* mpMenuBarContainerWidget
;
54 GtkWidget
* mpMenuBarWidget
;
55 GtkWidget
* mpCloseButton
;
56 VclPtr
<Menu
> mpVCLMenu
;
57 GtkSalMenu
* mpParentSalMenu
;
60 // GMenuModel and GActionGroup attributes
61 GMenuModel
* mpMenuModel
;
62 GActionGroup
* mpActionGroup
;
64 void ImplUpdate(bool bRecurse
, bool bRemoveDisabledEntries
);
65 void ActivateAllSubmenus(Menu
* pMenuBar
);
67 DECL_LINK(MenuBarHierarchyChangeHandler
, Timer
*, void);
70 GtkSalMenu( bool bMenuBar
);
71 virtual ~GtkSalMenu() override
;
73 virtual bool VisibleMenuBar() override
; // must return TRUE to actually DISPLAY native menu bars
74 // otherwise only menu messages are processed (eg, OLE on Windows)
76 virtual void InsertItem( SalMenuItem
* pSalMenuItem
, unsigned nPos
) override
;
77 virtual void RemoveItem( unsigned nPos
) override
;
78 virtual void SetSubMenu( SalMenuItem
* pSalMenuItem
, SalMenu
* pSubMenu
, unsigned nPos
) override
;
79 virtual void SetFrame( const SalFrame
* pFrame
) override
;
80 const GtkSalFrame
* GetFrame() const;
81 virtual void CheckItem( unsigned nPos
, bool bCheck
) override
;
82 virtual void EnableItem( unsigned nPos
, bool bEnable
) override
;
83 virtual void ShowItem( unsigned nPos
, bool bShow
) override
;
84 virtual void SetItemText( unsigned nPos
, SalMenuItem
* pSalMenuItem
, const OUString
& rText
) override
;
85 virtual void SetItemImage( unsigned nPos
, SalMenuItem
* pSalMenuItem
, const Image
& rImage
) override
;
86 virtual void SetAccelerator( unsigned nPos
, SalMenuItem
* pSalMenuItem
, const vcl::KeyCode
& rKeyCode
, const OUString
& rKeyName
) override
;
87 virtual void GetSystemMenuData( SystemMenuData
* pData
) override
;
89 void SetMenu( Menu
* pMenu
) { mpVCLMenu
= pMenu
; }
90 Menu
* GetMenu() { return mpVCLMenu
; }
91 void SetMenuModel(GMenuModel
* pMenuModel
);
92 unsigned GetItemCount() { return maItems
.size(); }
93 GtkSalMenuItem
* GetItemAtPos( unsigned nPos
) { return maItems
[ nPos
]; }
94 void SetActionGroup( GActionGroup
* pActionGroup
) { mpActionGroup
= pActionGroup
; }
95 bool IsItemVisible( unsigned nPos
);
97 void NativeSetItemText( unsigned nSection
, unsigned nItemPos
, const OUString
& rText
);
98 void NativeSetItemIcon( unsigned nSection
, unsigned nItemPos
, const Image
& rImage
);
99 bool NativeSetItemCommand( unsigned nSection
,
102 const gchar
* aCommand
,
106 void NativeSetEnableItem( gchar
* aCommand
, gboolean bEnable
);
107 void NativeCheckItem( unsigned nSection
, unsigned nItemPos
, MenuItemBits bits
, gboolean bCheck
);
108 void NativeSetAccelerator( unsigned nSection
, unsigned nItemPos
, const vcl::KeyCode
& rKeyCode
, const OUString
& rKeyName
);
110 static void DispatchCommand(const gchar
* pMenuCommand
);
111 static void Activate(const gchar
* pMenuCommand
);
112 static void Deactivate(const gchar
* pMenuCommand
);
113 void EnableUnity(bool bEnable
);
114 virtual void ShowMenuBar( bool bVisible
) override
;
116 virtual void Update() override
; // Update this menu only.
117 // Update full menu hierarchy from this menu.
118 void UpdateFull () { ActivateAllSubmenus(mpVCLMenu
); Update(); }
119 // Clear ActionGroup and MenuModel from full menu hierarchy
120 void ClearActionGroupAndMenuModel();
121 GtkSalMenu
* GetTopLevel();
122 void SetNeedsUpdate();
124 void CreateMenuBarWidget();
125 void DestroyMenuBarWidget();
126 gboolean
SignalKey(GdkEventKey
* pEvent
);
129 virtual bool ShowNativePopupMenu(FloatingWindow
* pWin
, const tools::Rectangle
& rRect
, FloatWinPopupFlags nFlags
) override
;
130 virtual void ShowCloseButton(bool bShow
) override
;
131 virtual bool CanGetFocus() const override
;
132 virtual bool TakeFocus() override
;
135 class GtkSalMenuItem
: public SalMenuItem
138 GtkSalMenuItem( const SalItemParams
* );
139 virtual ~GtkSalMenuItem() override
;
141 sal_uInt16 mnId
; // Item ID
142 MenuItemType mnType
; // Item type
143 bool mbVisible
; // Item visibility.
144 GtkSalMenu
* mpParentMenu
; // The menu into which this menu item is inserted
145 GtkSalMenu
* mpSubMenu
; // Submenu of this item (if defined)
148 #endif // INCLUDED_VCL_INC_UNX_GTK_GTKSALMENU_HXX
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */