Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
5#ifndef QWINDOWSMENU_H
6#define QWINDOWSMENU_H
7
9
10#include <qpa/qplatformmenu.h>
11
12#include <QtCore/qlist.h>
13
15
16class QDebug;
17
18class QWindowsMenu;
19class QWindowsMenuBar;
20class QWindowsWindow;
21
23{
25public:
26 explicit QWindowsMenuItem(QWindowsMenu *parentMenu = nullptr);
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#if QT_CONFIG(shortcut)
82#endif
83};
84
86{
88public:
90
92 ~QWindowsMenu();
93
94 void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) override;
95 void removeMenuItem(QPlatformMenuItem *menuItem) override;
96 void syncMenuItem(QPlatformMenuItem *) override {}
98
99 void setText(const QString &text) override;
100 void setIcon(const QIcon &icon) override;
101 void setEnabled(bool enabled) override;
102 bool isEnabled() const override { return m_enabled; }
103 void setVisible(bool visible) override;
104
105 QPlatformMenuItem *menuItemAt(int position) const override;
106 QPlatformMenuItem *menuItemForTag(quintptr tag) const override;
107
108 QPlatformMenuItem *createMenuItem() const override;
109 QPlatformMenu *createSubMenu() const override;
110
111 HMENU menuHandle() const { return m_hMenu; }
112 UINT_PTR id() const { return reinterpret_cast<UINT_PTR>(m_hMenu); }
113 QString text() const { return m_text; }
114 const MenuItems &menuItems() const { return m_menuItems; }
115 QWindowsMenuItem *itemForSubMenu(const QWindowsMenu *subMenu) const;
116
117 const QWindowsMenuBar *parentMenuBar() const { return m_parentMenuBar; }
119 const QWindowsMenu *parentMenu() const { return m_parentMenu; }
121 void notifyRemoved(QWindowsMenuItem *item) { m_menuItems.removeOne(item); }
122 HMENU parentMenuHandle() const;
123 HMENU parentHandle() const;
124 bool isVisible() const { return m_visible; }
125 void insertIntoMenuBar(QWindowsMenuBar *bar, bool append, int index);
126 bool removeFromParent();
127
128#ifndef QT_NO_DEBUG_STREAM
129 void formatDebug(QDebug &d) const;
130#endif
131
132protected:
133 explicit QWindowsMenu(QWindowsMenu *parentMenu, HMENU menu);
134
135private:
136 QWindowsMenuBar *m_parentMenuBar = nullptr;
137 QWindowsMenu *m_parentMenu = nullptr;
138 MenuItems m_menuItems;
139 HMENU m_hMenu = nullptr;
140 QString m_text;
141 QIcon m_icon;
142 bool m_visible = true;
143 bool m_enabled = true;
144};
145
147{
149public:
151
152 static bool notifyTriggered(uint id);
153 static bool notifyAboutToShow(HMENU hmenu);
154
155 void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item) override;
157
158 bool trackPopupMenu(HWND windowHandle, int x, int y);
159};
160
162{
164public:
166
169
170 void insertMenu(QPlatformMenu *menu, QPlatformMenu *before) override;
171 void removeMenu(QPlatformMenu *menu) override;
172 void syncMenu(QPlatformMenu *) override {}
173 void handleReparent(QWindow *newParentWindow) override;
174
175 QPlatformMenu *menuForTag(quintptr tag) const override;
176 QPlatformMenu *createMenu() const override;
177
178 HMENU menuBarHandle() const { return m_hMenuBar; }
179 const Menus &menus() const { return m_menus; }
180 bool notifyTriggered(uint id);
181 bool notifyAboutToShow(HMENU hmenu);
182 void notifyRemoved(QWindowsMenu *menu) { m_menus.removeOne(menu); }
183 void redraw() const;
184
185 void install(QWindowsWindow *window);
186
187 static QWindowsMenuBar *menuBarOf(const QWindow *notYetCreatedWindow);
188
189#ifndef QT_NO_DEBUG_STREAM
190 void formatDebug(QDebug &d) const;
191#endif
192
193private:
194 QWindowsWindow *platformWindow() const;
195 void removeFromWindow();
196
197 Menus m_menus;
198 HMENU m_hMenuBar = nullptr;
199};
200
201#ifndef QT_NO_DEBUG_STREAM
202QDebug operator<<(QDebug d, const QPlatformMenuItem *);
203QDebug operator<<(QDebug d, const QPlatformMenu *);
204QDebug operator<<(QDebug d, const QPlatformMenuBar *);
205#endif // !QT_NO_DEBUG_STREAM
206
207QT_END_NAMESPACE
208
209#endif // QWINDOWSMENU_H
\inmodule QtCore\reentrant
Definition qpoint.h:30
Singleton container for all relevant information.
QSharedPointer< QWindowCreationContext > windowCreationContext() const
QWindowsScreenManager & screenManager()
QWindowsWindow * findClosestPlatformWindow(HWND) const
QWindow * findWindow(HWND) const
bool asyncExpose() const
void addWindow(HWND, QWindowsWindow *w)
static bool systemParametersInfoForScreen(unsigned action, unsigned param, void *out, const QPlatformScreen *screen=nullptr)
static bool setProcessDpiAwareness(QtWindows::DpiAwareness dpiAwareness)
HDC displayContext() const
QWindowsTabletSupport * tabletSupport() const
static bool systemParametersInfoForWindow(unsigned action, unsigned param, void *out, const QPlatformWindow *win=nullptr)
static void setTabletAbsoluteRange(int a)
QWindowsWindow * findPlatformWindowAt(HWND parent, const QPoint &screenPoint, unsigned cwex_flags) const
bool initTouch(unsigned integrationOptions)
HWND createDummyWindow(const QString &classNameIn, const wchar_t *windowName, WNDPROC wndProc=nullptr, DWORD style=WS_OVERLAPPED)
Convenience to create a non-visible, message-only dummy window for example used as clipboard watcher ...
void setAsyncExpose(bool value)
QSharedPointer< QWindowCreationContext > setWindowCreationContext(const QSharedPointer< QWindowCreationContext > &ctx)
bool windowsProc(HWND hwnd, UINT message, QtWindows::WindowsEventType et, WPARAM wParam, LPARAM lParam, LRESULT *result, QWindowsWindow **platformWindowPtr)
Main windows procedure registered for windows.
unsigned systemInfo() const
static QtWindows::DpiAwareness processDpiAwareness()
QWindowsWindow * findPlatformWindow(HWND) const
QWindow * keyGrabber() const
QWindowsWindow * findPlatformWindow(const QWindowsMenuBar *mb) const
QWindow * windowUnderMouse() const
QPlatformKeyMapper * keyMapper() const
bool useRTLExtensions() const
static bool systemParametersInfo(unsigned action, unsigned param, void *out, unsigned dpi=0)
QWindowsMimeRegistry & mimeConverter() const
static bool isSessionLocked()
int screenDepth() const
bool initPowerNotificationHandler()
HandleBaseWindowHash & windows()
static QWindowsContext * instance()
void setDetectAltGrModifier(bool a)
Platform cursor implementation.
static bool hasOverrideCursor()
static void enforceOverrideCursor()
Windows Input context implementation.
static void setWindowsImeEnabled(QWindowsWindow *platformWindow, bool enabled)
static QWindowsIntegration * instance()
Translates Windows keys to QWindowSystemInterface events.
bool translateKeyEvent(QWindow *widget, HWND hwnd, const MSG &msg, LRESULT *result)
To be called from the window procedure.
bool detectAltGrModifier() const
void setUseRTLExtensions(bool e)
QWindow * keyGrabber() const
Qt::KeyboardModifiers queryKeyboardModifiers() const override
bool useRTLExtensions() const
void setKeyGrabber(QWindow *w)
void setDetectAltGrModifier(bool a)
QList< QKeyCombination > possibleKeyCombinations(const QKeyEvent *e) const override
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)
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
QWindowsMenu(QWindowsMenu *parentMenu, HMENU menu)
void insertIntoMenuBar(QWindowsMenuBar *bar, bool append, int index)
Manages the list of QWindowsMimeConverter instances.
QWindow * windowUnderMouse() const
static QPointingDevicePtr createTouchDevice(bool mouseEmulation)
QWindowsPointerHandler()=default
static Qt::MouseButtons queryMouseButtons()
const QPointingDevicePtr & touchDevice() const
bool translatePointerEvent(QWindow *window, HWND hwnd, QtWindows::WindowsEventType et, MSG msg, LRESULT *result)
bool translateMouseEvent(QWindow *window, HWND hwnd, QtWindows::WindowsEventType et, MSG msg, LRESULT *result)
void setTouchDevice(const QPointingDevicePtr &d)
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)
Manages a list of QWindowsScreen.
Tablet support for Windows.
static QWindowsTheme * instance()
Raster or OpenGL Window.
void alertWindow(int durationMs=0)
bool testFlag(unsigned f) const
void setFlag(unsigned f) const
void clearFlag(unsigned f) const
static void settingsChanged()
static const char * embeddedNativeParentHandleProperty
QWindowsMenuBar * menuBar() const
bool frameStrutEventsEnabled() const override
Reimplement this method to return whether frame strut events are enabled.
@ WithinSetParent
Automatic mouse capture on button press.
void handleCompositionSettingsChanged()
Combined button and popup list for selecting options.
WindowsEventType
Enumerations for WM_XX events.
@ PointerActivateWindowEvent
@ InputMethodEndCompositionEvent
@ ShowEventOnParentRestoring
@ InputMethodCompositionEvent
@ InputMethodOpenCandidateWindowEvent
@ MouseActivateWindowEvent
@ DpiChangedAfterParentEvent
@ InputMethodStartCompositionEvent
@ CompositionSettingsChanged
@ InputMethodCloseCandidateWindowEvent
@ AccessibleObjectFromWindowRequest
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
#define WM_TOUCH
#define DPI_AWARENESS_CONTEXT_UNAWARE
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
#define DPI_AWARENESS_CONTEXT_SYSTEM_AWARE
#define DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED
static bool isTopLevel(HWND hwnd)
#define LANG_SYRIAC
static RECT rectFromNcCalcSize(UINT message, WPARAM wParam, LPARAM lParam, int n)
static bool enableNonClientDpiScaling(HWND hwnd)
static bool isInputMessage(UINT m)
static DPI_AWARENESS_CONTEXT qtDpiAwarenessToDpiAwarenessContext(QtWindows::DpiAwareness dpiAwareness)
static bool isMinimized(HWND hwnd)
static QMargins marginsFromRects(const RECT &frame, const RECT &client)
static bool useRTL_Extensions()
static bool sessionManagerInteractionBlocked()
static QWindowsInputContext * windowsInputContext()
static QtWindows::DpiAwareness dpiAwarenessContextToQtDpiAwareness(DPI_AWARENESS_CONTEXT context)
static QByteArray nativeEventType()
static bool isEmptyRect(const RECT &rect)
static bool findPlatformWindowHelper(const POINT &screenPoint, unsigned cwexFlags, const QWindowsContext *context, HWND *hwnd, QWindowsWindow **result)
Find a child window at a screen point.
WindowsNativeModifiers
@ ScrollLock
@ ExtendedKey
@ ShiftRight
@ LockAny
@ AltLeft
@ ShiftLeft
@ MetaRight
@ MetaLeft
@ MetaAny
@ AltRight
@ ControlLeft
@ ControlRight
@ CapsLock
@ NumLock
@ ShiftAny
@ ControlAny
quint32 qtKey[NumQtKeys]
static const size_t NumQtKeys
const HRESULT m_oleInitializeResult
QWindowsKeyMapper m_keyMapper
QWindowsWindowClassRegistry m_windowClassRegistry
QWindowsPointerHandler m_pointerHandler
QUniqueHDCHandle m_displayContext
QWindowsScreenManager m_screenManager
QWindowsMimeRegistry m_mimeConverter
QWindowsContext::HandleBaseWindowHash m_windows
QSharedPointer< QWindowCreationContext > m_creationContext