Qt 6.x
The Qt SDK
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#include <QtCore/qpair.h>
13
15
16class QDebug;
17
18class QWindowsMenu;
19class QWindowsMenuBar;
20class QWindowsWindow;
21
23{
25public:
26 explicit QWindowsMenuItem(QWindowsMenu *parentMenu = nullptr);
27 ~QWindowsMenuItem() override;
28
29 void setText(const QString &text) override;
30 void setIcon(const QIcon &icon) override;
31 void setMenu(QPlatformMenu *menu) override;
32 void setVisible(bool isVisible) override;
33 void setIsSeparator(bool isSeparator) override;
34 void setFont(const QFont &) override {}
35 void setRole(MenuRole) override {}
36 void setCheckable(bool checkable) override;
37 void setChecked(bool isChecked) override;
38#ifndef QT_NO_SHORTCUT
39 void setShortcut(const QKeySequence& shortcut) override;
40#endif
41 void setEnabled(bool enabled) override;
42 void setIconSize(int size) override;
43
44 const QWindowsMenu *parentMenu() const { return m_parentMenu; }
45 QWindowsMenu *parentMenu() { return m_parentMenu; }
46 HMENU parentMenuHandle() const;
47 QWindowsMenu *subMenu() const { return m_subMenu; }
48 UINT_PTR id() const { return m_id; }
49 void setId(uint id) { m_id = id; }
50 UINT state() const;
51 QString text() const { return m_text; }
52 QString nativeText() const;
53 bool isVisible() const { return m_visible; }
54
55 void insertIntoMenu(QWindowsMenu *menuItem, bool append, int index);
56 bool removeFromMenu();
57
58#ifndef QT_NO_DEBUG_STREAM
59 void formatDebug(QDebug &d) const;
60#endif
61
62private:
63 void updateBitmap();
64 void freeBitmap();
65 void updateText();
66 void insertIntoMenuHelper(QWindowsMenu *menu, bool append, int index);
67
68 QWindowsMenu *m_parentMenu = nullptr;
69 QWindowsMenu *m_subMenu = nullptr;
70 UINT_PTR m_id; // Windows Id sent as wParam with WM_COMMAND or submenu handle.
71 QString m_text;
72 QIcon m_icon;
73 HBITMAP m_hbitmap = nullptr;
74 int m_iconSize = 0;
75 bool m_separator = false;
76 bool m_visible = true;
77 bool m_checkable = false;
78 bool m_checked = false;
79 bool m_enabled = true;
80 QKeySequence m_shortcut;
81};
82
84{
86public:
88
91
92 void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) override;
93 void removeMenuItem(QPlatformMenuItem *menuItem) override;
94 void syncMenuItem(QPlatformMenuItem *) override {}
95 void syncSeparatorsCollapsible(bool) override {}
96
97 void setText(const QString &text) override;
98 void setIcon(const QIcon &icon) override;
99 void setEnabled(bool enabled) override;
100 bool isEnabled() const override { return m_enabled; }
101 void setVisible(bool visible) override;
102
103 QPlatformMenuItem *menuItemAt(int position) const override;
105
106 QPlatformMenuItem *createMenuItem() const override;
107 QPlatformMenu *createSubMenu() const override;
108
109 HMENU menuHandle() const { return m_hMenu; }
110 UINT_PTR id() const { return reinterpret_cast<UINT_PTR>(m_hMenu); }
111 QString text() const { return m_text; }
112 const MenuItems &menuItems() const { return m_menuItems; }
113 QWindowsMenuItem *itemForSubMenu(const QWindowsMenu *subMenu) const;
114
115 const QWindowsMenuBar *parentMenuBar() const { return m_parentMenuBar; }
116 HMENU parentMenuBarHandle() const;
117 const QWindowsMenu *parentMenu() const { return m_parentMenu; }
120 HMENU parentMenuHandle() const;
121 HMENU parentHandle() const;
122 bool isVisible() const { return m_visible; }
123 void insertIntoMenuBar(QWindowsMenuBar *bar, bool append, int index);
124 bool removeFromParent();
125
126#ifndef QT_NO_DEBUG_STREAM
127 void formatDebug(QDebug &d) const;
128#endif
129
130protected:
131 explicit QWindowsMenu(QWindowsMenu *parentMenu, HMENU menu);
132
133private:
134 QWindowsMenuBar *m_parentMenuBar = nullptr;
135 QWindowsMenu *m_parentMenu = nullptr;
136 MenuItems m_menuItems;
137 HMENU m_hMenu = nullptr;
138 QString m_text;
139 QIcon m_icon;
140 bool m_visible = true;
141 bool m_enabled = true;
142};
143
145{
147public:
149
150 static bool notifyTriggered(uint id);
151 static bool notifyAboutToShow(HMENU hmenu);
152
153 void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item) override;
154 void dismiss() override {}
155
156 bool trackPopupMenu(HWND windowHandle, int x, int y);
157};
158
160{
162public:
164
166 ~QWindowsMenuBar() override;
167
168 void insertMenu(QPlatformMenu *menu, QPlatformMenu *before) override;
169 void removeMenu(QPlatformMenu *menu) override;
170 void syncMenu(QPlatformMenu *) override {}
171 void handleReparent(QWindow *newParentWindow) override;
172
173 QPlatformMenu *menuForTag(quintptr tag) const override;
174 QPlatformMenu *createMenu() const override;
175
176 HMENU menuBarHandle() const { return m_hMenuBar; }
177 const Menus &menus() const { return m_menus; }
178 bool notifyTriggered(uint id);
179 bool notifyAboutToShow(HMENU hmenu);
181 void redraw() const;
182
184
185 static QWindowsMenuBar *menuBarOf(const QWindow *notYetCreatedWindow);
186
187#ifndef QT_NO_DEBUG_STREAM
188 void formatDebug(QDebug &d) const;
189#endif
190
191private:
192 QWindowsWindow *platformWindow() const;
193 void removeFromWindow();
194
195 Menus m_menus;
196 HMENU m_hMenuBar = nullptr;
197};
198
199#ifndef QT_NO_DEBUG_STREAM
203#endif // !QT_NO_DEBUG_STREAM
204
206
207#endif // QWINDOWSMENU_H
\inmodule QtCore
\reentrant
Definition qfont.h:20
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:581
virtual quintptr tag() const
\inmodule QtCore\reentrant
Definition qrect.h:30
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\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
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:278
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:72
unsigned int uint
Definition qtypes.h:29
QDebug operator<<(QDebug d, const QPlatformMenuItem *)
QGraphicsItem * item
aWidget window() -> setWindowTitle("New Window Title")
[2]
QMenu menu
[5]