1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the plugins of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QGTK3MENU_H
41#define QGTK3MENU_H
42
43#include <QtGui/qpa/qplatformmenu.h>
44
45typedef struct _GtkWidget GtkWidget;
46typedef struct _GtkMenuItem GtkMenuItem;
47typedef struct _GtkCheckMenuItem GtkCheckMenuItem;
48
49QT_BEGIN_NAMESPACE
50
51class QGtk3Menu;
52
53class QGtk3MenuItem: public QPlatformMenuItem
54{
55public:
56 QGtk3MenuItem();
57 ~QGtk3MenuItem();
58
59 bool isInvalid() const;
60
61 GtkWidget *create();
62 GtkWidget *handle() const;
63
64 QString text() const;
65 void setText(const QString &text) override;
66
67 QGtk3Menu *menu() const;
68 void setMenu(QPlatformMenu *menu) override;
69
70 bool isVisible() const;
71 void setVisible(bool visible) override;
72
73 bool isSeparator() const;
74 void setIsSeparator(bool separator) override;
75
76 bool isCheckable() const;
77 void setCheckable(bool checkable) override;
78
79 bool isChecked() const;
80 void setChecked(bool checked) override;
81
82#if QT_CONFIG(shortcut)
83 QKeySequence shortcut() const;
84 void setShortcut(const QKeySequence &shortcut) override;
85#endif
86
87 bool isEnabled() const;
88 void setEnabled(bool enabled) override;
89
90 bool hasExclusiveGroup() const;
91 void setHasExclusiveGroup(bool exclusive) override;
92
93 void setRole(MenuRole role) override { Q_UNUSED(role); }
94 void setFont(const QFont &font) override { Q_UNUSED(font); }
95 void setIcon(const QIcon &icon) override { Q_UNUSED(icon); }
96 void setIconSize(int size) override { Q_UNUSED(size); }
97
98protected:
99 static void onSelect(GtkMenuItem *item, void *data);
100 static void onActivate(GtkMenuItem *item, void *data);
101 static void onToggle(GtkCheckMenuItem *item, void *data);
102
103private:
104 bool m_visible;
105 bool m_separator;
106 bool m_checkable;
107 bool m_checked;
108 bool m_enabled;
109 bool m_exclusive;
110 bool m_underline;
111 bool m_invalid;
112 QGtk3Menu *m_menu;
113 GtkWidget *m_item;
114 QString m_text;
115#if QT_CONFIG(shortcut)
116 QKeySequence m_shortcut;
117#endif
118};
119
120class QGtk3Menu : public QPlatformMenu
121{
122 Q_OBJECT
123
124public:
125 QGtk3Menu();
126 ~QGtk3Menu();
127
128 GtkWidget *handle() const;
129
130 void insertMenuItem(QPlatformMenuItem *item, QPlatformMenuItem *before) override;
131 void removeMenuItem(QPlatformMenuItem *item) override;
132 void syncMenuItem(QPlatformMenuItem *item) override;
133 void syncSeparatorsCollapsible(bool enable) override;
134
135 void setEnabled(bool enabled) override;
136 void setVisible(bool visible) override;
137
138 void setIcon(const QIcon &icon) override { Q_UNUSED(icon); }
139 void setText(const QString &text) override { Q_UNUSED(text); }
140
141 QPoint targetPos() const;
142
143 void showPopup(const QWindow *parentWindow, const QRect &targetRect, const QPlatformMenuItem *item) override;
144 void dismiss() override;
145
146 QPlatformMenuItem *menuItemAt(int position) const override;
147 QPlatformMenuItem *menuItemForTag(quintptr tag) const override;
148
149 QPlatformMenuItem *createMenuItem() const override;
150 QPlatformMenu *createSubMenu() const override;
151
152protected:
153 static void onShow(GtkWidget *menu, void *data);
154 static void onHide(GtkWidget *menu, void *data);
155
156private:
157 GtkWidget *m_menu;
158 QPoint m_targetPos;
159 QList<QGtk3MenuItem *> m_items;
160};
161
162QT_END_NAMESPACE
163
164#endif // QGTK3MENU_H
165