1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QMENU_P_H
|
---|
43 | #define QMENU_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists purely as an
|
---|
50 | // implementation detail. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #include "QtGui/qmenubar.h"
|
---|
57 | #include "QtGui/qstyleoption.h"
|
---|
58 | #include "QtCore/qdatetime.h"
|
---|
59 | #include "QtCore/qmap.h"
|
---|
60 | #include "QtCore/qhash.h"
|
---|
61 | #include "QtCore/qbasictimer.h"
|
---|
62 | #include "private/qwidget_p.h"
|
---|
63 |
|
---|
64 | QT_BEGIN_NAMESPACE
|
---|
65 |
|
---|
66 | #ifndef QT_NO_MENU
|
---|
67 |
|
---|
68 | class QTornOffMenu;
|
---|
69 | class QEventLoop;
|
---|
70 |
|
---|
71 | #ifdef Q_WS_MAC
|
---|
72 | # ifdef __OBJC__
|
---|
73 | QT_END_NAMESPACE
|
---|
74 | @class NSMenuItem;
|
---|
75 | QT_BEGIN_NAMESPACE
|
---|
76 | # else
|
---|
77 | typedef void NSMenuItem;
|
---|
78 | # endif //__OBJC__
|
---|
79 | struct QMacMenuAction {
|
---|
80 | QMacMenuAction()
|
---|
81 | #ifndef QT_MAC_USE_COCOA
|
---|
82 | : command(0)
|
---|
83 | #else
|
---|
84 | : menuItem(0)
|
---|
85 | #endif
|
---|
86 | , ignore_accel(0), merged(0), menu(0)
|
---|
87 | {
|
---|
88 | }
|
---|
89 | ~QMacMenuAction();
|
---|
90 | #ifndef QT_MAC_USE_COCOA
|
---|
91 | uint command;
|
---|
92 | #else
|
---|
93 | NSMenuItem *menuItem;
|
---|
94 | #endif
|
---|
95 | uchar ignore_accel : 1;
|
---|
96 | uchar merged : 1;
|
---|
97 | QPointer<QAction> action;
|
---|
98 | OSMenuRef menu;
|
---|
99 | };
|
---|
100 |
|
---|
101 | struct QMenuMergeItem
|
---|
102 | {
|
---|
103 | #ifndef QT_MAC_USE_COCOA
|
---|
104 | inline QMenuMergeItem(MenuCommand c, QMacMenuAction *a) : command(c), action(a) { }
|
---|
105 | MenuCommand command;
|
---|
106 | #else
|
---|
107 | inline QMenuMergeItem(NSMenuItem *c, QMacMenuAction *a) : menuItem(c), action(a) { }
|
---|
108 | NSMenuItem *menuItem;
|
---|
109 | #endif
|
---|
110 | QMacMenuAction *action;
|
---|
111 | };
|
---|
112 | typedef QList<QMenuMergeItem> QMenuMergeList;
|
---|
113 | #endif
|
---|
114 |
|
---|
115 | #ifdef Q_OS_WINCE
|
---|
116 | struct QWceMenuAction {
|
---|
117 | uint command;
|
---|
118 | QPointer<QAction> action;
|
---|
119 | HMENU menuHandle;
|
---|
120 | QWceMenuAction() : menuHandle(0), command(0) {}
|
---|
121 | };
|
---|
122 | #endif
|
---|
123 |
|
---|
124 | class QMenuPrivate : public QWidgetPrivate
|
---|
125 | {
|
---|
126 | Q_DECLARE_PUBLIC(QMenu)
|
---|
127 | public:
|
---|
128 | QMenuPrivate() : itemsDirty(0), maxIconWidth(0), tabWidth(0), ncols(0),
|
---|
129 | collapsibleSeparators(true), hasHadMouse(0), aboutToHide(0), motions(0),
|
---|
130 | currentAction(0), scroll(0), eventLoop(0), tearoff(0), tornoff(0), tearoffHighlighted(0),
|
---|
131 | hasCheckableItems(0), sloppyAction(0)
|
---|
132 | #ifdef Q_WS_MAC
|
---|
133 | ,mac_menu(0)
|
---|
134 | #endif
|
---|
135 | #if defined(Q_OS_WINCE) && !defined(QT_NO_MENUBAR)
|
---|
136 | ,wce_menu(0)
|
---|
137 | #endif
|
---|
138 | #ifdef QT3_SUPPORT
|
---|
139 | ,emitHighlighted(false)
|
---|
140 | #endif
|
---|
141 | { }
|
---|
142 | ~QMenuPrivate()
|
---|
143 | {
|
---|
144 | delete scroll;
|
---|
145 | #ifdef Q_WS_MAC
|
---|
146 | delete mac_menu;
|
---|
147 | #endif
|
---|
148 | #if defined(Q_OS_WINCE) && !defined(QT_NO_MENUBAR)
|
---|
149 | delete wce_menu;
|
---|
150 | #endif
|
---|
151 | }
|
---|
152 | void init();
|
---|
153 |
|
---|
154 | //item calculations
|
---|
155 | mutable uint itemsDirty : 1;
|
---|
156 | mutable uint maxIconWidth, tabWidth;
|
---|
157 | QRect actionRect(QAction *) const;
|
---|
158 | mutable QMap<QAction*, QRect> actionRects;
|
---|
159 | mutable QList<QAction*> actionList;
|
---|
160 | mutable QHash<QAction *, QWidget *> widgetItems;
|
---|
161 | void calcActionRects(QMap<QAction*, QRect> &actionRects, QList<QAction*> &actionList) const;
|
---|
162 | void updateActions();
|
---|
163 | QRect popupGeometry(int screen=-1) const;
|
---|
164 | QList<QAction *> filterActions(const QList<QAction *> &actions) const;
|
---|
165 | uint ncols : 4; //4 bits is probably plenty
|
---|
166 | uint collapsibleSeparators : 1;
|
---|
167 |
|
---|
168 | uint activationRecursionGuard : 1;
|
---|
169 |
|
---|
170 | //selection
|
---|
171 | static QPointer<QMenu> mouseDown;
|
---|
172 | QPoint mousePopupPos;
|
---|
173 | uint hasHadMouse : 1;
|
---|
174 | uint aboutToHide : 1;
|
---|
175 | int motions;
|
---|
176 | QAction *currentAction;
|
---|
177 | static QBasicTimer menuDelayTimer;
|
---|
178 | enum SelectionReason {
|
---|
179 | SelectedFromKeyboard,
|
---|
180 | SelectedFromElsewhere
|
---|
181 | };
|
---|
182 | QAction *actionAt(QPoint p) const;
|
---|
183 | void setFirstActionActive();
|
---|
184 | void setCurrentAction(QAction *, int popup = -1, SelectionReason reason = SelectedFromElsewhere, bool activateFirst = false);
|
---|
185 | void popupAction(QAction *, int, bool);
|
---|
186 | void setSyncAction();
|
---|
187 |
|
---|
|
---|