LibreOffice Module vcl (master) 1
gtksalmenu.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10#ifndef INCLUDED_VCL_INC_UNX_GTK_GTKSALMENU_HXX
11#define INCLUDED_VCL_INC_UNX_GTK_GTKSALMENU_HXX
12
13#include <config_dbus.h>
14#include <config_gio.h>
15
16#include <vector>
17#if ENABLE_GIO
18#include <gio/gio.h>
19#endif
20
21#include <salmenu.hxx>
22#include <unx/gtk/gtkframe.hxx>
23#include <unotools/tempfile.hxx>
24#include <vcl/idle.hxx>
25
26#include <unx/gtk/glomenu.h>
28
29class MenuItemList;
30class GtkSalMenuItem;
31
32class GtkSalMenu final : public SalMenu
33{
34private:
35 std::vector< GtkSalMenuItem* > maItems;
36 std::vector<std::pair<sal_uInt16, GtkWidget*>> maExtraButtons;
38
45 bool mbHasNullItemIcon = true;
47 std::unique_ptr<utl::TempFile> mxPersonaImage;
53 GtkCssProvider* mpMenuBarProvider;
58
59 // GMenuModel and GActionGroup attributes
60 GMenuModel* mpMenuModel;
61 GActionGroup* mpActionGroup;
62
63 void ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries);
64 void ActivateAllSubmenus(Menu* pMenuBar);
65
66 DECL_LINK(MenuBarHierarchyChangeHandler, Timer*, void);
67
68 static GtkWidget* AddButton(GtkWidget *pImage);
69
70public:
71 GtkSalMenu( bool bMenuBar );
72 virtual ~GtkSalMenu() override;
73
74 virtual bool HasNativeMenuBar() override;
75 virtual void ShowMenuBar(bool bVisible) override;
76
77 virtual void InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ) override;
78 virtual void RemoveItem( unsigned nPos ) override;
79 virtual void SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos ) override;
80 virtual void SetFrame( const SalFrame* pFrame ) override;
81 const GtkSalFrame* GetFrame() const;
82 virtual void CheckItem( unsigned nPos, bool bCheck ) override;
83 virtual void EnableItem( unsigned nPos, bool bEnable ) override;
84 virtual void ShowItem( unsigned nPos, bool bShow ) override;
85 virtual void SetItemText( unsigned nPos, SalMenuItem* pSalMenuItem, const OUString& rText ) override;
86 virtual void SetItemImage( unsigned nPos, SalMenuItem* pSalMenuItem, const Image& rImage) override;
87 virtual void SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const vcl::KeyCode& rKeyCode, const OUString& rKeyName ) override;
88 virtual void GetSystemMenuData( SystemMenuData* pData ) override;
89
90 void SetMenu( Menu* pMenu ) { mpVCLMenu = pMenu; }
91 Menu* GetMenu() { return mpVCLMenu; }
92 void SetMenuModel(GMenuModel* pMenuModel);
93 unsigned GetItemCount() const { return maItems.size(); }
94 GtkSalMenuItem* GetItemAtPos( unsigned nPos ) { return maItems[ nPos ]; }
95 void SetActionGroup( GActionGroup* pActionGroup ) { mpActionGroup = pActionGroup; }
96 bool IsItemVisible( unsigned nPos );
97
98 void NativeSetItemText( unsigned nSection, unsigned nItemPos, const OUString& rText );
99 void NativeSetItemIcon( unsigned nSection, unsigned nItemPos, const Image& rImage );
100 bool NativeSetItemCommand( unsigned nSection,
101 unsigned nItemPos,
102 sal_uInt16 nId,
103 const gchar* aCommand,
104 MenuItemBits nBits,
105 bool bChecked,
106 bool bIsSubmenu );
107 void NativeSetEnableItem( gchar const * aCommand, gboolean bEnable );
108 void NativeCheckItem( unsigned nSection, unsigned nItemPos, MenuItemBits bits, gboolean bCheck );
109 void NativeSetAccelerator( unsigned nSection, unsigned nItemPos, const vcl::KeyCode& rKeyCode, std::u16string_view rKeyName );
110
111 static void DispatchCommand(const gchar* pMenuCommand);
112 static void Activate(const gchar* pMenuCommand);
113 static void Deactivate(const gchar* pMenuCommand);
114 void EnableUnity(bool bEnable);
115 bool PrepUpdate() const;
116 virtual void Update() override; // Update this menu only.
117 // Update full menu hierarchy from this menu.
119 // Clear ActionGroup and MenuModel from full menu hierarchy
123
126
129#if !GTK_CHECK_VERSION(4, 0, 0)
130 gboolean SignalKey(GdkEventKey const * pEvent);
131#endif
133
134 virtual bool ShowNativePopupMenu(FloatingWindow * pWin, const tools::Rectangle& rRect, FloatWinPopupFlags nFlags) override;
135 virtual void ShowCloseButton(bool bShow) override;
136 virtual bool AddMenuBarButton( const SalMenuButtonItem& rNewItem ) override;
137 virtual void RemoveMenuBarButton( sal_uInt16 nId ) override;
138 virtual tools::Rectangle GetMenuBarButtonRectPixel( sal_uInt16 i_nItemId, SalFrame* i_pReferenceFrame ) override;
139 virtual bool CanGetFocus() const override;
140 virtual bool TakeFocus() override;
141 virtual void ApplyPersona() override;
142};
143
144class GtkSalMenuItem final : public SalMenuItem
145{
146public:
148 virtual ~GtkSalMenuItem() override;
149
150 GtkSalMenu* mpParentMenu; // The menu into which this menu item is inserted
151 GtkSalMenu* mpSubMenu; // Submenu of this item (if defined)
152 MenuItemType mnType; // Item type
153 sal_uInt16 mnId; // Item ID
154 bool mbVisible; // Item visibility.
155};
156
157#endif // INCLUDED_VCL_INC_UNX_GTK_GTKSALMENU_HXX
158
159/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 mnId
Definition: gtksalmenu.hxx:153
GtkSalMenu * mpSubMenu
Definition: gtksalmenu.hxx:151
virtual ~GtkSalMenuItem() override
MenuItemType mnType
Definition: gtksalmenu.hxx:152
GtkSalMenu * mpParentMenu
Definition: gtksalmenu.hxx:150
GtkSalMenuItem(const SalItemParams *)
void ActivateAllSubmenus(Menu *pMenuBar)
virtual void CheckItem(unsigned nPos, bool bCheck) override
void ClearActionGroupAndMenuModel()
GtkSalMenu * mpParentSalMenu
Definition: gtksalmenu.hxx:56
GtkWidget * mpMenuWidget
Definition: gtksalmenu.hxx:51
virtual bool ShowNativePopupMenu(FloatingWindow *pWin, const tools::Rectangle &rRect, FloatWinPopupFlags nFlags) override
unsigned GetItemCount() const
Definition: gtksalmenu.hxx:93
virtual void EnableItem(unsigned nPos, bool bEnable) override
virtual void SetAccelerator(unsigned nPos, SalMenuItem *pSalMenuItem, const vcl::KeyCode &rKeyCode, const OUString &rKeyName) override
bool mbInActivateCallback
Definition: gtksalmenu.hxx:39
static void DispatchCommand(const gchar *pMenuCommand)
std::vector< GtkSalMenuItem * > maItems
Definition: gtksalmenu.hxx:35
GtkWidget * mpCloseButton
Definition: gtksalmenu.hxx:54
void NativeCheckItem(unsigned nSection, unsigned nItemPos, MenuItemBits bits, gboolean bCheck)
virtual void ApplyPersona() override
BitmapEx maPersonaBitmap
Definition: gtksalmenu.hxx:48
virtual bool AddMenuBarButton(const SalMenuButtonItem &rNewItem) override
GActionGroup * mpActionGroup
Definition: gtksalmenu.hxx:61
VclPtr< Menu > mpVCLMenu
Definition: gtksalmenu.hxx:55
virtual void ShowMenuBar(bool bVisible) override
Change visibility of the native menu bar.
virtual void RemoveMenuBarButton(sal_uInt16 nId) override
void NativeSetItemText(unsigned nSection, unsigned nItemPos, const OUString &rText)
void NativeSetAccelerator(unsigned nSection, unsigned nItemPos, const vcl::KeyCode &rKeyCode, std::u16string_view rKeyName)
virtual void InsertItem(SalMenuItem *pSalMenuItem, unsigned nPos) override
void SetActionGroup(GActionGroup *pActionGroup)
Definition: gtksalmenu.hxx:95
virtual void SetFrame(const SalFrame *pFrame) override
virtual void ShowItem(unsigned nPos, bool bShow) override
static void Deactivate(const gchar *pMenuCommand)
GtkSalMenuItem * GetItemAtPos(unsigned nPos)
Definition: gtksalmenu.hxx:94
Idle maUpdateMenuBarIdle
Definition: gtksalmenu.hxx:37
virtual bool CanGetFocus() const override
bool mbReturnFocusToDocument
Definition: gtksalmenu.hxx:42
static GtkWidget * AddButton(GtkWidget *pImage)
virtual void RemoveItem(unsigned nPos) override
GtkSalFrame * mpFrame
Definition: gtksalmenu.hxx:57
void EnableUnity(bool bEnable)
bool IsItemVisible(unsigned nPos)
bool NativeSetItemCommand(unsigned nSection, unsigned nItemPos, sal_uInt16 nId, const gchar *aCommand, MenuItemBits nBits, bool bChecked, bool bIsSubmenu)
void DestroyMenuBarWidget()
GtkSalMenu(bool bMenuBar)
bool mbHasNullItemIcon
Even setting null icon on a menuitem can be expensive, so cache state to avoid that call.
Definition: gtksalmenu.hxx:45
virtual bool TakeFocus() override
void UpdateFull()
Definition: gtksalmenu.hxx:118
GMenuModel * mpMenuModel
Definition: gtksalmenu.hxx:60
virtual bool HasNativeMenuBar() override
Return true, if the implementation supports a native menu bar (or wants to suppress LO's menu bar,...
void ReturnFocus()
virtual void SetItemText(unsigned nPos, SalMenuItem *pSalMenuItem, const OUString &rText) override
bool PrepUpdate() const
void SetMenu(Menu *pMenu)
Definition: gtksalmenu.hxx:90
bool mbAddedGrab
Definition: gtksalmenu.hxx:43
void CreateMenuBarWidget()
std::vector< std::pair< sal_uInt16, GtkWidget * > > maExtraButtons
Definition: gtksalmenu.hxx:36
virtual void Update() override
const GtkSalFrame * GetFrame() const
GtkCssProvider * mpMenuBarProvider
Definition: gtksalmenu.hxx:53
GtkSalMenu * GetTopLevel()
void SetMenuModel(GMenuModel *pMenuModel)
void NativeSetItemIcon(unsigned nSection, unsigned nItemPos, const Image &rImage)
GtkCssProvider * mpMenuBarContainerProvider
Definition: gtksalmenu.hxx:52
virtual void SetItemImage(unsigned nPos, SalMenuItem *pSalMenuItem, const Image &rImage) override
void SetNeedsUpdate()
virtual void GetSystemMenuData(SystemMenuData *pData) override
virtual void ShowCloseButton(bool bShow) override
void ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries)
bool mbMenuBar
Definition: gtksalmenu.hxx:40
virtual ~GtkSalMenu() override
GtkWidget * mpMenuAllowShrinkWidget
Definition: gtksalmenu.hxx:49
std::unique_ptr< utl::TempFile > mxPersonaImage
Definition: gtksalmenu.hxx:47
GtkWidget * mpMenuBarWidget
Definition: gtksalmenu.hxx:50
DECL_LINK(MenuBarHierarchyChangeHandler, Timer *, void)
bool mbNeedsUpdate
Definition: gtksalmenu.hxx:41
static void Activate(const gchar *pMenuCommand)
gboolean SignalKey(GdkEventKey const *pEvent)
GtkWidget * GetMenuBarWidget() const
Definition: gtksalmenu.hxx:124
Menu * GetMenu()
Definition: gtksalmenu.hxx:91
GtkWidget * mpMenuBarContainerWidget
Definition: gtksalmenu.hxx:46
GtkWidget * GetMenuBarContainerWidget() const
Definition: gtksalmenu.hxx:125
virtual void SetSubMenu(SalMenuItem *pSalMenuItem, SalMenu *pSubMenu, unsigned nPos) override
virtual tools::Rectangle GetMenuBarButtonRectPixel(sal_uInt16 i_nItemId, SalFrame *i_pReferenceFrame) override
void NativeSetEnableItem(gchar const *aCommand, gboolean bEnable)
An idle is a timer to be scheduled immediately.
Definition: idle.hxx:35
Definition: image.hxx:40
Definition: menu.hxx:116
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:115
Definition: timer.hxx:27
struct _GtkWidget GtkWidget
sal_uInt16 nPos
MenuItemType
Definition: vclenum.hxx:30
MenuItemBits
Definition: vclenum.hxx:33
FloatWinPopupFlags
Definition: vclenum.hxx:330