Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwindowsmenu.h
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QWINDOWSMENU_H
5#define QWINDOWSMENU_H
6
7#include "qtwindowsglobal.h"
8
9#include <qpa/qplatformmenu.h>
10
11#include <QtCore/qlist.h>
12
14
15class QDebug;
16
17class QWindowsMenu;
18class QWindowsMenuBar;
19class QWindowsWindow;
20
22{
24public:
25 explicit QWindowsMenuItem(QWindowsMenu *parentMenu = nullptr);
26 ~QWindowsMenuItem() override;
27
28 void setText(const QString &text) override;
29 void setIcon(const QIcon &icon) override;
30 void setMenu(QPlatformMenu *menu) override;
31 void setVisible(bool isVisible) override;
32 void setIsSeparator(bool isSeparator) override;
33 void setFont(const QFont &) override {}
34 void setRole(MenuRole) override {}
35 void setCheckable(bool checkable) override;
36 void setChecked(bool isChecked) override;
37#ifndef QT_NO_SHORTCUT
38 void setShortcut(const QKeySequence& shortcut) override;
39#endif
40 void setEnabled(bool enabled) override;
41 void setIconSize(int size) override;
42
43 const QWindowsMenu *parentMenu() const { return m_parentMenu; }
44 QWindowsMenu *parentMenu() { return m_parentMenu; }
45 HMENU parentMenuHandle() const;
46 QWindowsMenu *subMenu() const { return m_subMenu; }
47 UINT_PTR id() const { return m_id; }
48 void setId(uint id) { m_id = id; }
49 UINT state() const;
50 QString text() const { return m_text; }
51 QString nativeText() const;
52 bool isVisible() const { return m_visible; }
53
54 void insertIntoMenu(QWindowsMenu *menuItem, bool append, int index);
55 bool removeFromMenu();
56
57#ifndef QT_NO_DEBUG_STREAM
58 void formatDebug(QDebug &d) const;
59#endif
60
61private:
62 void updateBitmap();
63 void freeBitmap();
64 void updateText();
65 void insertIntoMenuHelper(QWindowsMenu *menu, bool append, int index);
66
67 QWindowsMenu *m_parentMenu = nullptr;
68 QWindowsMenu *m_subMenu = nullptr;
69 UINT_PTR m_id; // Windows Id sent as wParam with WM_COMMAND or submenu handle.
70 QString m_text;
71 QIcon m_icon;
72 HBITMAP m_hbitmap = nullptr;
73 int m_iconSize = 0;
74 bool m_separator = false;
75 bool m_visible = true;
76 bool m_checkable = false;
77 bool m_checked = false;
78 bool m_enabled = true;
79 QKeySequence m_shortcut;
80};
81
83{
85public:
86 using MenuItems = QList<QWindowsMenuItem *>;
87
90
91 void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) override;
92 void removeMenuItem(QPlatformMenuItem *menuItem) override;
93 void syncMenuItem(QPlatformMenuItem *) override {}
94 void syncSeparatorsCollapsible(bool) override {}
95
96 void setText(const QString &text) override;
97 void setIcon(const QIcon &icon) override;
98 void setEnabled(bool enabled) override;
99 bool isEnabled() const override { return m_enabled; }
100 void setVisible(bool visible) override;
101
102 QPlatformMenuItem *menuItemAt(int position) const override;
104
105 QPlatformMenuItem *createMenuItem() const override;
106 QPlatformMenu *createSubMenu() const override;
107
108 HMENU menuHandle() const { return m_hMenu; }
109 UINT_PTR id() const { return reinterpret_cast<UINT_PTR>(m_hMenu); }
110 QString text() const { return m_text; }
111 const MenuItems &menuItems() const { return m_menuItems; }
112 QWindowsMenuItem *itemForSubMenu(const QWindowsMenu *subMenu) const;
113
114 const QWindowsMenuBar *parentMenuBar() const { return m_parentMenuBar; }
115 HMENU parentMenuBarHandle() const;
116 const QWindowsMenu *parentMenu() const { return m_parentMenu; }
119 HMENU parentMenuHandle() const;
120 HMENU parentHandle() const;
121 bool isVisible() const { return m_visible; }
122 void insertIntoMenuBar(QWindowsMenuBar *bar, bool append, int index);
123 bool removeFromParent();
124
125#ifndef QT_NO_DEBUG_STREAM
126 void formatDebug(QDebug &d) const;
127#endif
128
129protected:
130 explicit QWindowsMenu(QWindowsMenu *parentMenu, HMENU menu);
131
132private:
133 QWindowsMenuBar *m_parentMenuBar = nullptr;
134 QWindowsMenu *m_parentMenu = nullptr;
135 MenuItems m_menuItems;
136 HMENU m_hMenu = nullptr;
137 QString m_text;
138 QIcon m_icon;
139 bool m_visible = true;
140 bool m_enabled = true;
141};
142
144{
146public:
148
149 static bool notifyTriggered(uint id);
150 static bool notifyAboutToShow(HMENU hmenu);
151
152 void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item) override;
153 void dismiss() override {}
154
155 bool trackPopupMenu(HWND windowHandle, int x, int y);
156};
157
159{
161public:
162 using Menus = QList<QWindowsMenu *>;
163
165 ~QWindowsMenuBar() override;
166
167 void insertMenu(QPlatformMenu *menu, QPlatformMenu *before) override;
168 void removeMenu(QPlatformMenu *menu) override;
169 void syncMenu(QPlatformMenu *) override {}
170 void handleReparent(QWindow *newParentWindow) override;
171
172 QPlatformMenu *menuForTag(quintptr tag) const override;
173 QPlatformMenu *createMenu() const override;
174
175 HMENU menuBarHandle() const { return m_hMenuBar; }
176 const Menus &menus() const { return m_menus; }
177 bool notifyTriggered(uint id);
178 bool notifyAboutToShow(HMENU hmenu);
180 void redraw() const;
181
183
184 static QWindowsMenuBar *menuBarOf(const QWindow *notYetCreatedWindow);
185
186#ifndef QT_NO_DEBUG_STREAM
187 void formatDebug(QDebug &d) const;
188#endif
189
190private:
191 QWindowsWindow *platformWindow() const;
192 void removeFromWindow();
193
194 Menus m_menus;
195 HMENU m_hMenuBar = nullptr;
196};
197
198#ifndef QT_NO_DEBUG_STREAM
202#endif // !QT_NO_DEBUG_STREAM
203
205
206#endif // QWINDOWSMENU_H
\inmodule QtCore
\reentrant
Definition qfont.h:22
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
The QKeySequence class encapsulates a key sequence as used by shortcuts.
bool removeOne(const AT &t)
Definition qlist.h:598
virtual quintptr tag() const
\inmodule QtCore\reentrant
Definition qrect.h:30
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtGui
Definition qwindow.h:63
Windows native menu bar.
static QWindowsMenuBar * menuBarOf(const QWindow *notYetCreatedWindow)
void formatDebug(QDebug &d) const
void syncMenu(QPlatformMenu *) override
const Menus & menus() const
void removeMenu(QPlatformMenu *menu) override
void insertMenu(QPlatformMenu *menu, QPlatformMenu *before) override
void notifyRemoved(QWindowsMenu *menu)
QList< QWindowsMenu * > Menus
bool notifyAboutToShow(HMENU hmenu)
void install(QWindowsWindow *window)
HMENU menuBarHandle() const
~QWindowsMenuBar() override
QPlatformMenu * menuForTag(quintptr tag) const override
bool notifyTriggered(uint id)
void handleReparent(QWindow *newParentWindow) override
QPlatformMenu * createMenu() const override
void redraw() const
void setChecked(bool isChecked) override
void setCheckable(bool checkable) override
void insertIntoMenu(QWindowsMenu *menuItem, bool append, int index)
UINT state() const
QString text() const
void setIconSize(int size) override
void formatDebug(QDebug &d) const
void setRole(MenuRole) override
void setIsSeparator(bool isSeparator) override
QString nativeText() const
~QWindowsMenuItem() override
void setIcon(const QIcon &icon) override
void setMenu(QPlatformMenu *menu) override
void setId(uint id)
UINT_PTR id() const
void setShortcut(const QKeySequence &shortcut) override
void setText(const QString &text) override
bool isVisible() const
QWindowsMenuItem(QWindowsMenu *parentMenu=nullptr)
void setEnabled(bool enabled) override
void setVisible(bool isVisible) override
const QWindowsMenu * parentMenu() const
HMENU parentMenuHandle() const
QWindowsMenu * subMenu() const
QWindowsMenu * parentMenu()
void setFont(const QFont &) override
HMENU parentMenuBarHandle() const
void setText(const QString &text) override
QString text() const
void syncSeparatorsCollapsible(bool) override
UINT_PTR id() const
HMENU parentHandle() const
void setEnabled(bool enabled) override
void syncMenuItem(QPlatformMenuItem *) override
const QWindowsMenu * parentMenu() const
void notifyRemoved(QWindowsMenuItem *item)
QPlatformMenu * createSubMenu() const override
void removeMenuItem(QPlatformMenuItem *menuItem) override
bool isEnabled() const override
bool isVisible() const
QPlatformMenuItem * createMenuItem() const override
const MenuItems & menuItems() const
void formatDebug(QDebug &d) const
HMENU menuHandle() const
QPlatformMenuItem * menuItemAt(int position) const override
void setVisible(bool visible) override
void setIcon(const QIcon &icon) override
HMENU parentMenuHandle() const
QPlatformMenuItem * menuItemForTag(quintptr tag) const override
void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) override
QWindowsMenuItem * itemForSubMenu(const QWindowsMenu *subMenu) const
bool removeFromParent()
void setAsItemSubMenu(QWindowsMenuItem *item)
const QWindowsMenuBar * parentMenuBar() const
QList< QWindowsMenuItem * > MenuItems
void insertIntoMenuBar(QWindowsMenuBar *bar, bool append, int index)
static bool notifyAboutToShow(HMENU hmenu)
static bool notifyTriggered(uint id)
void dismiss() override
void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item) override
bool trackPopupMenu(HWND windowHandle, int x, int y)
Raster or OpenGL Window.
list append(new Employee("Blackpool", "Stephen"))
Combined button and popup list for selecting options.
AudioChannelLayoutTag tag
static bool isSeparator(char c)
Definition qhsts.cpp:280
GLint GLint GLint GLint GLint x
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint y
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_OBJECT
size_t quintptr
Definition qtypes.h:167
unsigned int uint
Definition qtypes.h:34
QDebug operator<<(QDebug d, const QPlatformMenuItem *)
QGraphicsItem * item
aWidget window() -> setWindowTitle("New Window Title")
[2]
QMenu menu
[5]