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 -*- */
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
8  */
13 #include <config_dbus.h>
14 #include <config_gio.h>
16 #include <vector>
18 #include <gio/gio.h>
19 #endif
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>
27 #include <unx/gtk/gloactiongroup.h>
29 class MenuItemList;
30 class GtkSalMenuItem;
32 class GtkSalMenu : public SalMenu
33 {
34 private:
35  std::vector< GtkSalMenuItem* > maItems;
36  std::vector<std::pair<sal_uInt16, GtkWidget*>> maExtraButtons;
40  bool mbMenuBar;
45  bool mbHasNullItemIcon = true;
47  std::unique_ptr<utl::TempFile> mxPersonaImage;
50  GtkWidget* mpMenuBarWidget;
51  GtkCssProvider* mpMenuBarContainerProvider;
52  GtkCssProvider* mpMenuBarProvider;
53  GtkWidget* mpCloseButton;
58  // GMenuModel and GActionGroup attributes
59  GMenuModel* mpMenuModel;
60  GActionGroup* mpActionGroup;
62  void ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries);
63  void ActivateAllSubmenus(Menu* pMenuBar);
65  DECL_LINK(MenuBarHierarchyChangeHandler, Timer*, void);
67  static GtkWidget* AddButton(GtkWidget *pImage);
69 public:
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() const { 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,
100  unsigned nItemPos,
101  sal_uInt16 nId,
102  const gchar* aCommand,
103  MenuItemBits nBits,
104  bool bChecked,
105  bool bIsSubmenu );
106  void NativeSetEnableItem( gchar const * 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, std::u16string_view 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;
115  bool PrepUpdate();
116  virtual void Update() override; // Update this menu only.
117  // Update full menu hierarchy from this menu.
118  void UpdateFull () { ActivateAllSubmenus(mpVCLMenu); }
119  // Clear ActionGroup and MenuModel from full menu hierarchy
122  void SetNeedsUpdate();
126  void CreateMenuBarWidget();
127  void DestroyMenuBarWidget();
128  gboolean SignalKey(GdkEventKey const * pEvent);
129  void ReturnFocus();
131  virtual bool ShowNativePopupMenu(FloatingWindow * pWin, const tools::Rectangle& rRect, FloatWinPopupFlags nFlags) override;
132  virtual void ShowCloseButton(bool bShow) override;
133  virtual bool AddMenuBarButton( const SalMenuButtonItem& rNewItem ) override;
134  virtual void RemoveMenuBarButton( sal_uInt16 nId ) override;
135  virtual tools::Rectangle GetMenuBarButtonRectPixel( sal_uInt16 i_nItemId, SalFrame* i_pReferenceFrame ) override;
136  virtual bool CanGetFocus() const override;
137  virtual bool TakeFocus() override;
138  virtual int GetMenuBarHeight() const override;
139  virtual void ApplyPersona() override;
140 };
143 {
144 public:
145  GtkSalMenuItem( const SalItemParams* );
146  virtual ~GtkSalMenuItem() override;
148  GtkSalMenu* mpParentMenu; // The menu into which this menu item is inserted
149  GtkSalMenu* mpSubMenu; // Submenu of this item (if defined)
150  MenuItemType mnType; // Item type
151  sal_uInt16 mnId; // Item ID
152  bool mbVisible; // Item visibility.
153 };
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetItemText(unsigned nPos, SalMenuItem *pSalMenuItem, const OUString &rText) override
Definition: vclenum.hxx:30
bool mbAddedGrab
Definition: gtksalmenu.hxx:43
virtual void RemoveItem(unsigned nPos) override
std::vector< GtkSalMenuItem * > maItems
Definition: gtksalmenu.hxx:35
GtkSalMenu(bool bMenuBar)
virtual void CheckItem(unsigned nPos, bool bCheck) override
GtkSalFrame * mpFrame
Definition: gtksalmenu.hxx:56
virtual void EnableItem(unsigned nPos, bool bEnable) override
GtkWidget * mpMenuBarContainerWidget
Definition: gtksalmenu.hxx:46
virtual tools::Rectangle GetMenuBarButtonRectPixel(sal_uInt16 i_nItemId, SalFrame *i_pReferenceFrame) override
BitmapEx maPersonaBitmap
Definition: gtksalmenu.hxx:48
bool mbHasNullItemIcon
Even setting null icon on a menuitem can be expensive, so cache state to avoid that call...
Definition: gtksalmenu.hxx:45
void ReturnFocus()
Idle maUpdateMenuBarIdle
Definition: gtksalmenu.hxx:37
virtual void SetItemImage(unsigned nPos, SalMenuItem *pSalMenuItem, const Image &rImage) override
GtkCssProvider * mpMenuBarProvider
Definition: gtksalmenu.hxx:52
bool mbInActivateCallback
Definition: gtksalmenu.hxx:39
void SetMenuModel(GMenuModel *pMenuModel)
static void Activate(const gchar *pMenuCommand)
GtkCssProvider * mpMenuBarContainerProvider
Definition: gtksalmenu.hxx:51
void NativeSetAccelerator(unsigned nSection, unsigned nItemPos, const vcl::KeyCode &rKeyCode, std::u16string_view rKeyName)
Definition: vclenum.hxx:369
virtual bool ShowNativePopupMenu(FloatingWindow *pWin, const tools::Rectangle &rRect, FloatWinPopupFlags nFlags) override
GtkWidget * mpMenuBarWidget
Definition: gtksalmenu.hxx:50
Definition: vclenum.hxx:32
static void DispatchCommand(const gchar *pMenuCommand)
GtkWidget * GetMenuBarContainerWidget() const
Definition: gtksalmenu.hxx:124
virtual void Update() override
unsigned GetItemCount() const
Definition: gtksalmenu.hxx:92
DECL_LINK(MenuBarHierarchyChangeHandler, Timer *, void)
VclPtr< Menu > mpVCLMenu
Definition: gtksalmenu.hxx:54
virtual ~GtkSalMenuItem() override
GtkWidget * mpCloseButton
Definition: gtksalmenu.hxx:53
bool IsItemVisible(unsigned nPos)
void SetActionGroup(GActionGroup *pActionGroup)
Definition: gtksalmenu.hxx:94
void UpdateFull()
Definition: gtksalmenu.hxx:118
gboolean SignalKey(GdkEventKey const *pEvent)
bool mbReturnFocusToDocument
Definition: gtksalmenu.hxx:42
virtual void SetFrame(const SalFrame *pFrame) override
void EnableUnity(bool bEnable)
bool NativeSetItemCommand(unsigned nSection, unsigned nItemPos, sal_uInt16 nId, const gchar *aCommand, MenuItemBits nBits, bool bChecked, bool bIsSubmenu)
void DestroyMenuBarWidget()
void NativeSetItemText(unsigned nSection, unsigned nItemPos, const OUString &rText)
virtual void ShowMenuBar(bool bVisible) override
MenuItemType mnType
Definition: gtksalmenu.hxx:150
sal_uInt16 mnId
Definition: gtksalmenu.hxx:151
bool PrepUpdate()
bool mbMenuBar
Definition: gtksalmenu.hxx:40
void ActivateAllSubmenus(Menu *pMenuBar)
void NativeSetEnableItem(gchar const *aCommand, gboolean bEnable)
virtual void ShowCloseButton(bool bShow) override
GtkSalMenu * mpParentMenu
Definition: gtksalmenu.hxx:148
virtual void SetSubMenu(SalMenuItem *pSalMenuItem, SalMenu *pSubMenu, unsigned nPos) override
GtkSalMenu * GetTopLevel()
bool mbNeedsUpdate
Definition: gtksalmenu.hxx:41
void SetMenu(Menu *pMenu)
Definition: gtksalmenu.hxx:89
virtual bool TakeFocus() override
virtual void ShowItem(unsigned nPos, bool bShow) override
GtkSalMenu * mpParentSalMenu
Definition: gtksalmenu.hxx:55
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:112
Definition: menu.hxx:123
void NativeCheckItem(unsigned nSection, unsigned nItemPos, MenuItemBits bits, gboolean bCheck)
std::unique_ptr< utl::TempFile > mxPersonaImage
Definition: gtksalmenu.hxx:47
void ClearActionGroupAndMenuModel()
GtkSalMenuItem(const SalItemParams *)
virtual void SetAccelerator(unsigned nPos, SalMenuItem *pSalMenuItem, const vcl::KeyCode &rKeyCode, const OUString &rKeyName) override
void NativeSetItemIcon(unsigned nSection, unsigned nItemPos, const Image &rImage)
const GtkSalFrame * GetFrame() const
Definition: image.hxx:39
virtual void ApplyPersona() override
GtkSalMenu * mpSubMenu
Definition: gtksalmenu.hxx:149
virtual ~GtkSalMenu() override
GtkWidget * mpMenuAllowShrinkWidget
Definition: gtksalmenu.hxx:49
GActionGroup * mpActionGroup
Definition: gtksalmenu.hxx:60
virtual int GetMenuBarHeight() const override
void SetNeedsUpdate()
Definition: timer.hxx:26
virtual void InsertItem(SalMenuItem *pSalMenuItem, unsigned nPos) override
Menu * GetMenu()
Definition: gtksalmenu.hxx:90
virtual void RemoveMenuBarButton(sal_uInt16 nId) override
std::vector< std::pair< sal_uInt16, GtkWidget * > > maExtraButtons
Definition: gtksalmenu.hxx:36
static GtkWidget * AddButton(GtkWidget *pImage)
An idle is a timer to be scheduled immediately.
Definition: idle.hxx:34
virtual bool AddMenuBarButton(const SalMenuButtonItem &rNewItem) override
virtual bool CanGetFocus() const override
GtkSalMenuItem * GetItemAtPos(unsigned nPos)
Definition: gtksalmenu.hxx:93
virtual void GetSystemMenuData(SystemMenuData *pData) override
GMenuModel * mpMenuModel
Definition: gtksalmenu.hxx:59
static void Deactivate(const gchar *pMenuCommand)
virtual bool VisibleMenuBar() override
void CreateMenuBarWidget()
void ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries)