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 QGTK3MENU_H
5#define QGTK3MENU_H
6
7#include <QtGui/qpa/qplatformmenu.h>
8
9typedef struct _GtkWidget GtkWidget;
10typedef struct _GtkMenuItem GtkMenuItem;
11typedef struct _GtkCheckMenuItem GtkCheckMenuItem;
12
13QT_BEGIN_NAMESPACE
14
15class QGtk3Menu;
16
17class QGtk3MenuItem: public QPlatformMenuItem
18{
19public:
20 QGtk3MenuItem();
21 ~QGtk3MenuItem();
22
23 bool isInvalid() const;
24
25 GtkWidget *create();
26 GtkWidget *handle() const;
27
28 QString text() const;
29 void setText(const QString &text) override;
30
31 QGtk3Menu *menu() const;
32 void setMenu(QPlatformMenu *menu) override;
33
34 bool isVisible() const;
35 void setVisible(bool visible) override;
36
37 bool isSeparator() const;
38 void setIsSeparator(bool separator) override;
39
40 bool isCheckable() const;
41 void setCheckable(bool checkable) override;
42
43 bool isChecked() const;
44 void setChecked(bool checked) override;
45
46#if QT_CONFIG(shortcut)
47 QKeySequence shortcut() const;
48 void setShortcut(const QKeySequence &shortcut) override;
49#endif
50
51 bool isEnabled() const;
52 void setEnabled(bool enabled) override;
53
54 bool hasExclusiveGroup() const;
55 void setHasExclusiveGroup(bool exclusive) override;
56
57 void setRole(MenuRole role) override { Q_UNUSED(role); }
58 void setFont(const QFont &font) override { Q_UNUSED(font); }
59 void setIcon(const QIcon &icon) override { Q_UNUSED(icon); }
60 void setIconSize(int size) override { Q_UNUSED(size); }
61
62protected:
63 static void onSelect(GtkMenuItem *item, void *data);
64 static void onActivate(GtkMenuItem *item, void *data);
65 static void onToggle(GtkCheckMenuItem *item, void *data);
66
67private:
68 bool m_visible;
69 bool m_separator;
70 bool m_checkable;
71 bool m_checked;
72 bool m_enabled;
73 bool m_exclusive;
74 bool m_underline;
75 bool m_invalid;
76 QGtk3Menu *m_menu;
77 GtkWidget *m_item;
78 QString m_text;
79#if QT_CONFIG(shortcut)
80 QKeySequence m_shortcut;
81#endif
82};
83
84class QGtk3Menu : public QPlatformMenu
85{
86 Q_OBJECT
87
88public:
89 QGtk3Menu();
90 ~QGtk3Menu();
91
92 GtkWidget *handle() const;
93
94 void insertMenuItem(QPlatformMenuItem *item, QPlatformMenuItem *before) override;
95 void removeMenuItem(QPlatformMenuItem *item) override;
96 void syncMenuItem(QPlatformMenuItem *item) override;
97 void syncSeparatorsCollapsible(bool enable) override;
98
99 void setEnabled(bool enabled) override;
100 void setVisible(bool visible) override;
101
102 void setIcon(const QIcon &icon) override { Q_UNUSED(icon); }
103 void setText(const QString &text) override { Q_UNUSED(text); }
104
105 QPoint targetPos() const;
106
107 void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item) override;
108 void dismiss() override;
109
110 QPlatformMenuItem *menuItemAt(int position) const override;
111 QPlatformMenuItem *menuItemForTag(quintptr tag) const override;
112
113 QPlatformMenuItem *createMenuItem() const override;
114 QPlatformMenu *createSubMenu() const override;
115
116protected:
117 static void onShow(GtkWidget *menu, void *data);
118 static void onHide(GtkWidget *menu, void *data);
119
120private:
121 GtkWidget *m_menu;
122 QPoint m_targetPos;
123 QList<QGtk3MenuItem *> m_items;
124};
125
126QT_END_NAMESPACE
127
128#endif // QGTK3MENU_H
129

source code of qtbase/src/plugins/platformthemes/gtk3/qgtk3menu.h