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>
27 #include <unx/gtk/gloactiongroup.h>
28 
29 class MenuItemList;
30 class GtkSalMenuItem;
31 
32 class GtkSalMenu : public SalMenu
33 {
34 private:
35  std::vector< GtkSalMenuItem* > maItems;
37 
39  bool const mbMenuBar;
44  bool mbHasNullItemIcon = true;
46  std::unique_ptr<utl::TempFile> mxPersonaImage;
49  GtkWidget* mpMenuBarWidget;
50  GtkCssProvider* mpMenuBarContainerProvider;
51  GtkCssProvider* mpMenuBarProvider;
52  GtkWidget* mpCloseButton;
56 
57  // GMenuModel and GActionGroup attributes
58  GMenuModel* mpMenuModel;
59  GActionGroup* mpActionGroup;
60 
61  void ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries);
62  void ActivateAllSubmenus(Menu* pMenuBar);
63 
64  DECL_LINK(MenuBarHierarchyChangeHandler, Timer*, void);
65 
66 public:
67  GtkSalMenu( bool bMenuBar );
68  virtual ~GtkSalMenu() override;
69 
70  virtual bool VisibleMenuBar() override; // must return TRUE to actually DISPLAY native menu bars
71  // otherwise only menu messages are processed (eg, OLE on Windows)
72 
73  virtual void InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos ) override;
74  virtual void RemoveItem( unsigned nPos ) override;
75  virtual void SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos ) override;
76  virtual void SetFrame( const SalFrame* pFrame ) override;
77  const GtkSalFrame* GetFrame() const;
78  virtual void CheckItem( unsigned nPos, bool bCheck ) override;
79  virtual void EnableItem( unsigned nPos, bool bEnable ) override;
80  virtual void ShowItem( unsigned nPos, bool bShow ) override;
81  virtual void SetItemText( unsigned nPos, SalMenuItem* pSalMenuItem, const OUString& rText ) override;
82  virtual void SetItemImage( unsigned nPos, SalMenuItem* pSalMenuItem, const Image& rImage) override;
83  virtual void SetAccelerator( unsigned nPos, SalMenuItem* pSalMenuItem, const vcl::KeyCode& rKeyCode, const OUString& rKeyName ) override;
84  virtual void GetSystemMenuData( SystemMenuData* pData ) override;
85 
86  void SetMenu( Menu* pMenu ) { mpVCLMenu = pMenu; }
87  Menu* GetMenu() { return mpVCLMenu; }
88  void SetMenuModel(GMenuModel* pMenuModel);
89  unsigned GetItemCount() const { return maItems.size(); }
90  GtkSalMenuItem* GetItemAtPos( unsigned nPos ) { return maItems[ nPos ]; }
91  void SetActionGroup( GActionGroup* pActionGroup ) { mpActionGroup = pActionGroup; }
92  bool IsItemVisible( unsigned nPos );
93 
94  void NativeSetItemText( unsigned nSection, unsigned nItemPos, const OUString& rText );
95  void NativeSetItemIcon( unsigned nSection, unsigned nItemPos, const Image& rImage );
96  bool NativeSetItemCommand( unsigned nSection,
97  unsigned nItemPos,
98  sal_uInt16 nId,
99  const gchar* aCommand,
100  MenuItemBits nBits,
101  bool bChecked,
102  bool bIsSubmenu );
103  void NativeSetEnableItem( gchar const * aCommand, gboolean bEnable );
104  void NativeCheckItem( unsigned nSection, unsigned nItemPos, MenuItemBits bits, gboolean bCheck );
105  void NativeSetAccelerator( unsigned nSection, unsigned nItemPos, const vcl::KeyCode& rKeyCode, const OUString& rKeyName );
106 
107  static void DispatchCommand(const gchar* pMenuCommand);
108  static void Activate(const gchar* pMenuCommand);
109  static void Deactivate(const gchar* pMenuCommand);
110  void EnableUnity(bool bEnable);
111  virtual void ShowMenuBar( bool bVisible ) override;
112  bool PrepUpdate();
113  virtual void Update() override; // Update this menu only.
114  // Update full menu hierarchy from this menu.
115  void UpdateFull () { ActivateAllSubmenus(mpVCLMenu); Update(); }
116  // Clear ActionGroup and MenuModel from full menu hierarchy
119  void SetNeedsUpdate();
120 
122 
123  void CreateMenuBarWidget();
124  void DestroyMenuBarWidget();
125  gboolean SignalKey(GdkEventKey const * pEvent);
126  void ReturnFocus();
127 
128  virtual bool ShowNativePopupMenu(FloatingWindow * pWin, const tools::Rectangle& rRect, FloatWinPopupFlags nFlags) override;
129  virtual void ShowCloseButton(bool bShow) override;
130  virtual bool CanGetFocus() const override;
131  virtual bool TakeFocus() override;
132  virtual int GetMenuBarHeight() const override;
133  virtual void ApplyPersona() override;
134 };
135 
137 {
138 public:
139  GtkSalMenuItem( const SalItemParams* );
140  virtual ~GtkSalMenuItem() override;
141 
142  GtkSalMenu* mpParentMenu; // The menu into which this menu item is inserted
143  GtkSalMenu* mpSubMenu; // Submenu of this item (if defined)
144  MenuItemType const mnType; // Item type
145  sal_uInt16 const mnId; // Item ID
146  bool mbVisible; // Item visibility.
147 };
148 
149 #endif // INCLUDED_VCL_INC_UNX_GTK_GTKSALMENU_HXX
150 
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetItemText(unsigned nPos, SalMenuItem *pSalMenuItem, const OUString &rText) override
MenuItemType
Definition: vclenum.hxx:30
bool mbAddedGrab
Definition: gtksalmenu.hxx:42
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:55
virtual void EnableItem(unsigned nPos, bool bEnable) override
GtkWidget * mpMenuBarContainerWidget
Definition: gtksalmenu.hxx:45
BitmapEx maPersonaBitmap
Definition: gtksalmenu.hxx:47
bool mbHasNullItemIcon
Even setting null icon on a menuitem can be expensive, so cache state to avoid that call...
Definition: gtksalmenu.hxx:44
void ReturnFocus()
bool const mbMenuBar
Definition: gtksalmenu.hxx:39
Idle maUpdateMenuBarIdle
Definition: gtksalmenu.hxx:36
virtual void SetItemImage(unsigned nPos, SalMenuItem *pSalMenuItem, const Image &rImage) override
GtkCssProvider * mpMenuBarProvider
Definition: gtksalmenu.hxx:51
bool mbInActivateCallback
Definition: gtksalmenu.hxx:38
void SetMenuModel(GMenuModel *pMenuModel)
static void Activate(const gchar *pMenuCommand)
GtkCssProvider * mpMenuBarContainerProvider
Definition: gtksalmenu.hxx:50
virtual bool ShowNativePopupMenu(FloatingWindow *pWin, const tools::Rectangle &rRect, FloatWinPopupFlags nFlags) override
GtkWidget * mpMenuBarWidget
Definition: gtksalmenu.hxx:49
MenuItemBits
Definition: vclenum.hxx:32
static void DispatchCommand(const gchar *pMenuCommand)
GtkWidget * GetMenuBarContainerWidget() const
Definition: gtksalmenu.hxx:121
virtual void Update() override
unsigned GetItemCount() const
Definition: gtksalmenu.hxx:89
DECL_LINK(MenuBarHierarchyChangeHandler, Timer *, void)
VclPtr< Menu > mpVCLMenu
Definition: gtksalmenu.hxx:53
void NativeSetAccelerator(unsigned nSection, unsigned nItemPos, const vcl::KeyCode &rKeyCode, const OUString &rKeyName)
virtual ~GtkSalMenuItem() override
GtkWidget * mpCloseButton
Definition: gtksalmenu.hxx:52
bool IsItemVisible(unsigned nPos)
void SetActionGroup(GActionGroup *pActionGroup)
Definition: gtksalmenu.hxx:91
void UpdateFull()
Definition: gtksalmenu.hxx:115
gboolean SignalKey(GdkEventKey const *pEvent)
sal_uInt16 const mnId
Definition: gtksalmenu.hxx:145
bool mbReturnFocusToDocument
Definition: gtksalmenu.hxx:41
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
bool PrepUpdate()
void ActivateAllSubmenus(Menu *pMenuBar)
void NativeSetEnableItem(gchar const *aCommand, gboolean bEnable)
virtual void ShowCloseButton(bool bShow) override
GtkSalMenu * mpParentMenu
Definition: gtksalmenu.hxx:142
virtual void SetSubMenu(SalMenuItem *pSalMenuItem, SalMenu *pSubMenu, unsigned nPos) override
GtkSalMenu * GetTopLevel()
FloatWinPopupFlags
Definition: floatwin.hxx:31
MenuItemType const mnType
Definition: gtksalmenu.hxx:144
bool mbNeedsUpdate
Definition: gtksalmenu.hxx:40
void SetMenu(Menu *pMenu)
Definition: gtksalmenu.hxx:86
virtual bool TakeFocus() override
virtual void ShowItem(unsigned nPos, bool bShow) override
GtkSalMenu * mpParentSalMenu
Definition: gtksalmenu.hxx:54
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:112
Definition: menu.hxx:121
void NativeCheckItem(unsigned nSection, unsigned nItemPos, MenuItemBits bits, gboolean bCheck)
std::unique_ptr< utl::TempFile > mxPersonaImage
Definition: gtksalmenu.hxx:46
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:40
virtual void ApplyPersona() override
GtkSalMenu * mpSubMenu
Definition: gtksalmenu.hxx:143
virtual ~GtkSalMenu() override
GtkWidget * mpMenuAllowShrinkWidget
Definition: gtksalmenu.hxx:48
GActionGroup * mpActionGroup
Definition: gtksalmenu.hxx:59
virtual int GetMenuBarHeight() const override
void SetNeedsUpdate()
Definition: timer.hxx:26
virtual void InsertItem(SalMenuItem *pSalMenuItem, unsigned nPos) override
Menu * GetMenu()
Definition: gtksalmenu.hxx:87
An idle is a timer to be scheduled immediately.
Definition: idle.hxx:30
virtual bool CanGetFocus() const override
GtkSalMenuItem * GetItemAtPos(unsigned nPos)
Definition: gtksalmenu.hxx:90
virtual void GetSystemMenuData(SystemMenuData *pData) override
GMenuModel * mpMenuModel
Definition: gtksalmenu.hxx:58
static void Deactivate(const gchar *pMenuCommand)
virtual bool VisibleMenuBar() override
void CreateMenuBarWidget()
void ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries)