1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
12 #include <salmenu.hxx>
14 #include <QtCore/QObject>
28 * Qt5Menu can represent
29 * (1) the top-level menu of a menubar, in which case 'mbMenuBar' is true and
30 * 'mpQMenuBar' refers to the corresponding QMenuBar
31 * (2) another kind of menu (like a PopupMenu), in which case the corresponding QMenu
32 * object is instantiated and owned by this Qt5Menu (held in 'mpOwnedQMenu').
33 * (3) a "submenu" in an existing menu (like (1)), in which case the corresponding
34 * QMenu object is owned by the corresponding Qt5MenuItem.
36 * For (2) and (3), member 'mpQMenu' points to the corresponding QMenu object.
38 class Qt5Menu
: public QObject
, public SalMenu
42 std::vector
<Qt5MenuItem
*> maItems
;
43 VclPtr
<Menu
> mpVCLMenu
;
44 Qt5Menu
* mpParentSalMenu
;
48 // self-created QMenu that this Qt5Menu represents, if applicable (s. comment for class)
49 std::unique_ptr
<QMenu
> mpOwnedQMenu
;
50 // pointer to QMenu owned by the corresponding Qt5MenuItem or self (-> mpOwnedQMenu)
52 QPushButton
* mpCloseButton
;
53 QMetaObject::Connection maCloseButtonConnection
;
55 void DoFullMenuUpdate(Menu
* pMenuBar
);
56 static void NativeItemText(OUString
& rItemText
);
58 void InsertMenuItem(Qt5MenuItem
* pSalMenuItem
, unsigned nPos
);
60 void ReinitializeActionGroup(unsigned nPos
);
61 void ResetAllActionGroups();
62 void UpdateActionGroupItem(const Qt5MenuItem
* pSalMenuItem
);
65 Qt5Menu(bool bMenuBar
);
67 virtual bool VisibleMenuBar() override
; // must return TRUE to actually DISPLAY native menu bars
69 virtual void InsertItem(SalMenuItem
* pSalMenuItem
, unsigned nPos
) override
;
70 virtual void RemoveItem(unsigned nPos
) override
;
71 virtual void SetSubMenu(SalMenuItem
* pSalMenuItem
, SalMenu
* pSubMenu
, unsigned nPos
) override
;
72 virtual void SetFrame(const SalFrame
* pFrame
) override
;
73 const Qt5Frame
* GetFrame() const;
74 virtual void ShowMenuBar(bool bVisible
) override
;
75 virtual bool ShowNativePopupMenu(FloatingWindow
* pWin
, const tools::Rectangle
& rRect
,
76 FloatWinPopupFlags nFlags
) override
;
77 Qt5Menu
* GetTopLevel();
78 virtual void SetItemBits(unsigned nPos
, MenuItemBits nBits
) override
;
79 virtual void CheckItem(unsigned nPos
, bool bCheck
) override
;
80 virtual void EnableItem(unsigned nPos
, bool bEnable
) override
;
81 virtual void ShowItem(unsigned nPos
, bool bShow
) override
;
82 virtual void SetItemText(unsigned nPos
, SalMenuItem
* pSalMenuItem
,
83 const OUString
& rText
) override
;
84 virtual void SetItemImage(unsigned nPos
, SalMenuItem
* pSalMenuItem
,
85 const Image
& rImage
) override
;
86 virtual void SetAccelerator(unsigned nPos
, SalMenuItem
* pSalMenuItem
,
87 const vcl::KeyCode
& rKeyCode
, const OUString
& rKeyName
) override
;
88 virtual void GetSystemMenuData(SystemMenuData
* pData
) override
;
89 virtual void ShowCloseButton(bool bShow
) override
;
91 void SetMenu(Menu
* pMenu
) { mpVCLMenu
= pMenu
; }
92 Menu
* GetMenu() { return mpVCLMenu
; }
93 unsigned GetItemCount() const { return maItems
.size(); }
94 Qt5MenuItem
* GetItemAtPos(unsigned nPos
) { return maItems
[nPos
]; }
97 static void slotMenuTriggered(Qt5MenuItem
* pQItem
);
98 static void slotMenuAboutToShow(Qt5MenuItem
* pQItem
);
99 static void slotMenuAboutToHide(Qt5MenuItem
* pQItem
);
100 void slotCloseDocument();
103 class Qt5MenuItem
: public SalMenuItem
106 Qt5MenuItem(const SalItemParams
*);
108 QAction
* getAction() const;
110 Qt5Menu
* mpParentMenu
; // The menu into which this menu item is inserted
111 Qt5Menu
* mpSubMenu
; // Submenu of this item (if defined)
112 std::unique_ptr
<QAction
> mpAction
; // action corresponding to this item
113 std::unique_ptr
<QMenu
> mpMenu
; // menu corresponding to this item
114 std::shared_ptr
<QActionGroup
> mpActionGroup
; // empty if it's a separator element
115 sal_uInt16 mnId
; // Item ID
116 MenuItemType mnType
; // Item type
117 bool mbVisible
; // Item visibility.
118 bool mbEnabled
; // Item active.
119 Image maImage
; // Item image
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */