LibreOffice Module vcl (master) 1
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
8 */
13#include <config_dbus.h>
14#include <config_gio.h>
16#include <vector>
18#include <gio/gio.h>
21#include <salmenu.hxx>
22#include <unx/gtk/gtkframe.hxx>
23#include <unotools/tempfile.hxx>
24#include <vcl/idle.hxx>
26#include <unx/gtk/glomenu.h>
29class MenuItemList;
30class GtkSalMenuItem;
32class GtkSalMenu final : public SalMenu
35 std::vector< GtkSalMenuItem* > maItems;
36 std::vector<std::pair<sal_uInt16, GtkWidget*>> maExtraButtons;
45 bool mbHasNullItemIcon = true;
47 std::unique_ptr<utl::TempFileNamed> mxPersonaImage;
53 GtkCssProvider* mpMenuBarProvider;
59 // GMenuModel and GActionGroup attributes
60 GMenuModel* mpMenuModel;
61 GActionGroup* mpActionGroup;
63 void ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries);
64 void ActivateAllSubmenus(Menu* pMenuBar);
66 DECL_LINK(MenuBarHierarchyChangeHandler, Timer*, void);
68 static GtkWidget* AddButton(GtkWidget *pImage);
71 GtkSalMenu( bool bMenuBar );
72 virtual ~GtkSalMenu() override;
74 virtual bool VisibleMenuBar() override; // must return TRUE to actually DISPLAY native menu bars
75 // otherwise only menu messages are processed (eg, OLE on Windows)
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;
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 );
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 );
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 virtual void ShowMenuBar( bool bVisible ) override;
116 bool PrepUpdate() const;
117 virtual void Update() override; // Update this menu only.
118 // Update full menu hierarchy from this menu.
120 // Clear ActionGroup and MenuModel from full menu hierarchy
130#if !GTK_CHECK_VERSION(4, 0, 0)
131 gboolean SignalKey(GdkEventKey const * pEvent);
135 virtual bool ShowNativePopupMenu(FloatingWindow * pWin, const tools::Rectangle& rRect, FloatWinPopupFlags nFlags) override;
136 virtual void ShowCloseButton(bool bShow) override;
137 virtual bool AddMenuBarButton( const SalMenuButtonItem& rNewItem ) override;
138 virtual void RemoveMenuBarButton( sal_uInt16 nId ) override;
139 virtual tools::Rectangle GetMenuBarButtonRectPixel( sal_uInt16 i_nItemId, SalFrame* i_pReferenceFrame ) override;
140 virtual bool CanGetFocus() const override;
141 virtual bool TakeFocus() override;
142 virtual int GetMenuBarHeight() const override;
143 virtual void ApplyPersona() override;
146class GtkSalMenuItem final : public SalMenuItem
150 virtual ~GtkSalMenuItem() override;
152 GtkSalMenu* mpParentMenu; // The menu into which this menu item is inserted
153 GtkSalMenu* mpSubMenu; // Submenu of this item (if defined)
154 MenuItemType mnType; // Item type
155 sal_uInt16 mnId; // Item ID
156 bool mbVisible; // Item visibility.
161/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 mnId
Definition: gtksalmenu.hxx:155
GtkSalMenu * mpSubMenu
Definition: gtksalmenu.hxx:153
virtual ~GtkSalMenuItem() override
MenuItemType mnType
Definition: gtksalmenu.hxx:154
GtkSalMenu * mpParentMenu
Definition: gtksalmenu.hxx:152
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 int GetMenuBarHeight() const override
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
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
std::unique_ptr< utl::TempFileNamed > mxPersonaImage
Definition: gtksalmenu.hxx:47
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:119
GMenuModel * mpMenuModel
Definition: gtksalmenu.hxx:60
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
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:125
Menu * GetMenu()
Definition: gtksalmenu.hxx:91
virtual bool VisibleMenuBar() override
GtkWidget * mpMenuBarContainerWidget
Definition: gtksalmenu.hxx:46
GtkWidget * GetMenuBarContainerWidget() const
Definition: gtksalmenu.hxx:126
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
Definition: vclenum.hxx:30
Definition: vclenum.hxx:33
Definition: vclenum.hxx:323