cid#1606940 Check of thread-shared field evades lock acquisition
[LibreOffice.git] / vcl / inc / unx / gtk / gtksalmenu.hxx
blob3172c37656bd851ce10a32c6b0a8d505beccc266
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #pragma once
12 #include <config_dbus.h>
13 #include <config_gio.h>
15 #include <vector>
16 #if ENABLE_GIO
17 #include <gio/gio.h>
18 #endif
20 #include <salmenu.hxx>
21 #include <unx/gtk/gtkframe.hxx>
22 #include <unotools/tempfile.hxx>
23 #include <vcl/idle.hxx>
25 #include <unx/gtk/glomenu.h>
26 #include <unx/gtk/gloactiongroup.h>
28 class MenuItemList;
29 class GtkSalMenuItem;
31 class GtkSalMenu final : public SalMenu
33 private:
34 std::vector< GtkSalMenuItem* > maItems;
35 std::vector<std::pair<sal_uInt16, GtkWidget*>> maExtraButtons;
36 Idle maUpdateMenuBarIdle;
38 bool mbInActivateCallback;
39 bool mbMenuBar;
40 bool mbNeedsUpdate;
41 bool mbReturnFocusToDocument;
42 bool mbAddedGrab;
43 /// Even setting null icon on a menuitem can be expensive, so cache state to avoid that call
44 bool mbHasNullItemIcon = true;
45 GtkWidget* mpMenuBarContainerWidget;
46 std::unique_ptr<utl::TempFileNamed> mxPersonaImage;
47 BitmapEx maPersonaBitmap;
48 GtkWidget* mpMenuAllowShrinkWidget;
49 GtkWidget* mpMenuBarWidget;
50 GtkWidget* mpMenuWidget;
51 GtkCssProvider* mpMenuBarContainerProvider;
52 GtkCssProvider* mpMenuBarProvider;
53 GtkWidget* mpCloseButton;
54 VclPtr<Menu> mpVCLMenu;
55 GtkSalMenu* mpParentSalMenu;
56 GtkSalFrame* mpFrame;
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;
88 void SetMenu( Menu* pMenu ) { mpVCLMenu = pMenu; }
89 Menu* GetMenu() { return mpVCLMenu; }
90 void SetMenuModel(GMenuModel* pMenuModel);
91 unsigned GetItemCount() const { return maItems.size(); }
92 GtkSalMenuItem* GetItemAtPos( unsigned nPos ) { return maItems[ nPos ]; }
93 void SetActionGroup( GActionGroup* pActionGroup ) { mpActionGroup = pActionGroup; }
94 bool IsItemVisible( unsigned nPos );
96 void NativeSetItemText( unsigned nSection, unsigned nItemPos, const OUString& rText, bool bFireEvent = true );
97 void NativeSetItemIcon( unsigned nSection, unsigned nItemPos, const Image& rImage );
98 bool NativeSetItemCommand( unsigned nSection,
99 unsigned nItemPos,
100 sal_uInt16 nId,
101 const gchar* aCommand,
102 MenuItemBits nBits,
103 bool bChecked,
104 bool bIsSubmenu );
105 void NativeSetEnableItem(const OString& sCommand, gboolean bEnable);
106 void NativeCheckItem( unsigned nSection, unsigned nItemPos, MenuItemBits bits, gboolean bCheck );
107 void NativeSetAccelerator( unsigned nSection, unsigned nItemPos, const vcl::KeyCode& rKeyCode, std::u16string_view rKeyName );
109 static void DispatchCommand(const gchar* pMenuCommand);
110 static void Activate(const gchar* pMenuCommand);
111 static void Deactivate(const gchar* pMenuCommand);
112 void EnableUnity(bool bEnable);
113 virtual void ShowMenuBar( bool bVisible ) override;
114 bool PrepUpdate() const;
115 virtual void Update() override; // Update this menu only.
116 // Update full menu hierarchy from this menu.
117 void UpdateFull () { ActivateAllSubmenus(mpVCLMenu); }
118 // Clear ActionGroup and MenuModel from full menu hierarchy
119 void ClearActionGroupAndMenuModel();
120 GtkSalMenu* GetTopLevel();
121 void SetNeedsUpdate();
123 GtkWidget* GetMenuBarWidget() const { return mpMenuBarWidget; }
124 GtkWidget* GetMenuBarContainerWidget() const { return mpMenuBarContainerWidget; }
126 void CreateMenuBarWidget();
127 void DestroyMenuBarWidget();
128 #if !GTK_CHECK_VERSION(4, 0, 0)
129 gboolean SignalKey(GdkEventKey const * pEvent);
130 #endif
131 void ReturnFocus();
133 virtual bool ShowNativePopupMenu(FloatingWindow * pWin, const tools::Rectangle& rRect, FloatWinPopupFlags nFlags) override;
134 virtual void ShowCloseButton(bool bShow) override;
135 virtual bool AddMenuBarButton( const SalMenuButtonItem& rNewItem ) override;
136 virtual void RemoveMenuBarButton( sal_uInt16 nId ) override;
137 virtual tools::Rectangle GetMenuBarButtonRectPixel( sal_uInt16 i_nItemId, SalFrame* i_pReferenceFrame ) override;
138 virtual bool CanGetFocus() const override;
139 virtual bool TakeFocus() override;
140 virtual int GetMenuBarHeight() const override;
141 virtual void ApplyPersona() override;
144 class GtkSalMenuItem final : public SalMenuItem
146 public:
147 GtkSalMenuItem( const SalItemParams* );
148 virtual ~GtkSalMenuItem() override;
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.
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */