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
4#ifndef QWINDOWSMENU_H
5#define QWINDOWSMENU_H
6
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);
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#if QT_CONFIG(shortcut)
81#endif
82};
83
85{
87public:
89
91 ~QWindowsMenu();
92
93 void insertMenuItem(QPlatformMenuItem *menuItem, QPlatformMenuItem *before) override;
94 void removeMenuItem(QPlatformMenuItem *menuItem) override;
95 void syncMenuItem(QPlatformMenuItem *) override {}
97
98 void setText(const QString &text) override;
99 void setIcon(const QIcon &icon) override;
100 void setEnabled(bool enabled) override;
101 bool isEnabled() const override { return m_enabled; }
102 void setVisible(bool visible) override;
103
104 QPlatformMenuItem *menuItemAt(int position) const override;
105 QPlatformMenuItem *menuItemForTag(quintptr tag) const override;
106
107 QPlatformMenuItem *createMenuItem() const override;
108 QPlatformMenu *createSubMenu() const override;
109
110 HMENU menuHandle() const { return m_hMenu; }
111 UINT_PTR id() const { return reinterpret_cast<UINT_PTR>(m_hMenu); }
112 QString text() const { return m_text; }
113 const MenuItems &menuItems() const { return m_menuItems; }
114 QWindowsMenuItem *itemForSubMenu(const QWindowsMenu *subMenu) const;
115
116 const QWindowsMenuBar *parentMenuBar() const { return m_parentMenuBar; }
118 const QWindowsMenu *parentMenu() const { return m_parentMenu; }
120 void notifyRemoved(QWindowsMenuItem *item) { m_menuItems.removeOne(item); }
121 HMENU parentMenuHandle() const;
122 HMENU parentHandle() const;
123 bool isVisible() const { return m_visible; }
124 void insertIntoMenuBar(QWindowsMenuBar *bar, bool append, int index);
125 bool removeFromParent();
126
127#ifndef QT_NO_DEBUG_STREAM
128 void formatDebug(QDebug &d) const;
129#endif
130
131protected:
132 explicit QWindowsMenu(QWindowsMenu *parentMenu, HMENU menu);
133
134private:
135 QWindowsMenuBar *m_parentMenuBar = nullptr;
136 QWindowsMenu *m_parentMenu = nullptr;
137 MenuItems m_menuItems;
138 HMENU m_hMenu = nullptr;
139 QString m_text;
140 QIcon m_icon;
141 bool m_visible = true;
142 bool m_enabled = true;
143};
144
146{
148public:
150
151 static bool notifyTriggered(uint id);
152 static bool notifyAboutToShow(HMENU hmenu);
153
154 void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item) override;
156
157 bool trackPopupMenu(HWND windowHandle, int x, int y);
158};
159
161{
163public:
165
168
169 void insertMenu(QPlatformMenu *menu, QPlatformMenu *before) override;
170 void removeMenu(QPlatformMenu *menu) override;
171 void syncMenu(QPlatformMenu *) override {}
172 void handleReparent(QWindow *newParentWindow) override;
173
174 QPlatformMenu *menuForTag(quintptr tag) const override;
175 QPlatformMenu *createMenu() const override;
176
177 HMENU menuBarHandle() const { return m_hMenuBar; }
178 const Menus &menus() const { return m_menus; }
179 bool notifyTriggered(uint id);
180 bool notifyAboutToShow(HMENU hmenu);
181 void notifyRemoved(QWindowsMenu *menu) { m_menus.removeOne(menu); }
182 void redraw() const;
183
184 void install(QWindowsWindow *window);
185
186 static QWindowsMenuBar *menuBarOf(const QWindow *notYetCreatedWindow);
187
188#ifndef QT_NO_DEBUG_STREAM
189 void formatDebug(QDebug &d) const;
190#endif
191
192private:
193 QWindowsWindow *platformWindow() const;
194 void removeFromWindow();
195
196 Menus m_menus;
197 HMENU m_hMenuBar = nullptr;
198};
199
200#ifndef QT_NO_DEBUG_STREAM
201QDebug operator<<(QDebug d, const QPlatformMenuItem *);
202QDebug operator<<(QDebug d, const QPlatformMenu *);
203QDebug operator<<(QDebug d, const QPlatformMenuBar *);
204#endif // !QT_NO_DEBUG_STREAM
205
206QT_END_NAMESPACE
207
208#endif // QWINDOWSMENU_H
\inmodule QtCore\reentrant
Definition qpoint.h:29
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()
QString registerWindowClass(QString cname, WNDPROC proc, unsigned style=0, HBRUSH brush=nullptr, bool icon=false)
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)
void checkForScreenChanged(ScreenChangeMode mode=FromGeometryChange)
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()
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
QWindowsPointerHandler m_pointerHandler
QSet< QString > m_registeredWindowClassNames
QWindowsScreenManager m_screenManager
QWindowsMimeRegistry m_mimeConverter
QWindowsContext::HandleBaseWindowHash m_windows
QSharedPointer< QWindowCreationContext > m_creationContext