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 QMENUBAR_P_H
|
---|
43 | #define QMENUBAR_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 | #ifndef QMAC_Q3MENUBAR_CPP_FILE
|
---|
57 | #include "QtGui/qstyleoption.h"
|
---|
58 | #include <private/qmenu_p.h> // Mac needs what in this file!
|
---|
59 |
|
---|
60 | #ifdef Q_OS_WINCE
|
---|
61 | #include "qguifunctions_wince.h"
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | QT_BEGIN_NAMESPACE
|
---|
65 |
|
---|
66 | #ifndef QT_NO_MENUBAR
|
---|
67 | class QMenuBarExtension;
|
---|
68 | class QMenuBarPrivate : public QWidgetPrivate
|
---|
69 | {
|
---|
70 | Q_DECLARE_PUBLIC(QMenuBar)
|
---|
71 | public:
|
---|
72 | QMenuBarPrivate() : itemsDirty(0), itemsWidth(0), itemsStart(-1), currentAction(0), mouseDown(0),
|
---|
73 | closePopupMode(0), defaultPopDown(1), popupState(0), keyboardState(0), altPressed(0)
|
---|
74 | #ifdef Q_WS_MAC
|
---|
75 | , mac_menubar(0)
|
---|
76 | #endif
|
---|
77 |
|
---|
78 | #ifdef Q_OS_WINCE
|
---|
79 | , wce_menubar(0), wceClassicMenu(false)
|
---|
80 | #endif
|
---|
81 | { }
|
---|
82 | ~QMenuBarPrivate()
|
---|
83 | {
|
---|
84 | #ifdef Q_WS_MAC
|
---|
85 | delete mac_menubar;
|
---|
86 | #endif
|
---|
87 | #ifdef Q_OS_WINCE
|
---|
88 | delete wce_menubar;
|
---|
89 | #endif
|
---|
90 | }
|
---|
91 |
|
---|
92 | void init();
|
---|
93 | QStyleOptionMenuItem getStyleOption(const QAction *action) const;
|
---|
94 |
|
---|
95 | //item calculations
|
---|
96 | uint itemsDirty : 1;
|
---|
97 | int itemsWidth, itemsStart;
|
---|
98 |
|
---|
99 | QVector<int> shortcutIndexMap;
|
---|
100 | mutable QMap<QAction*, QRect> actionRects;
|
---|
101 | mutable QList<QAction*> actionList;
|
---|
102 | void calcActionRects(int max_width, int start, QMap<QAction*, QRect> &actionRects, QList<QAction*> &actionList) const;
|
---|
103 | QRect actionRect(QAction *) const;
|
---|
104 | void updateGeometries();
|
---|
105 |
|
---|
106 | //selection
|
---|
107 | QPointer<QAction>currentAction;
|
---|
108 | uint mouseDown : 1, closePopupMode : 1, defaultPopDown;
|
---|
109 | QAction *actionAt(QPoint p) const;
|
---|
110 | void setCurrentAction(QAction *, bool =false, bool =false);
|
---|
111 | void popupAction(QAction *, bool);
|
---|
112 |
|
---|
113 | //active popup state
|
---|
114 | uint popupState : 1;
|
---|
115 | QPointer<QMenu> activeMenu;
|
---|
116 |
|
---|
117 | //keyboard mode for keyboard navigation
|
---|
118 | void setKeyboardMode(bool);
|
---|
119 | uint keyboardState : 1, altPressed : 1;
|
---|
120 | QPointer<QWidget> keyboardFocusWidget;
|
---|
121 |
|
---|
122 | //firing of events
|
---|
123 | void activateAction(QAction *, QAction::ActionEvent);
|
---|
124 |
|
---|
125 | void _q_actionTriggered();
|
---|
126 | void _q_actionHovered();
|
---|
127 | void _q_internalShortcutActivated(int);
|
---|
128 | void _q_updateLayout();
|
---|
129 |
|
---|
130 | #ifdef Q_OS_WINCE
|
---|
131 | void _q_updateDefaultAction();
|
---|
132 | #endif
|
---|
133 |
|
---|
134 | //extra widgets in the menubar
|
---|
135 | QPointer<QWidget> leftWidget, rightWidget;
|
---|
136 | QMenuBarExtension *extension;
|
---|
137 | bool isVisible(QAction *action);
|
---|
138 |
|
---|
139 | //menu fading/scrolling effects
|
---|
140 | bool doChildEffects;
|
---|
141 |
|
---|
142 | QRect menuRect(bool) const;
|
---|
143 |
|
---|
144 | // reparenting
|
---|
145 | void handleReparent();
|
---|
146 | QWidget *oldParent;
|
---|
147 | QWidget *oldWindow;
|
---|
148 |
|
---|
149 | QList<QAction*> hiddenActions;
|
---|
150 | //default action
|
---|
151 | QPointer<QAction> defaultAction;
|
---|
152 |
|
---|
153 | QBasicTimer autoReleaseTimer;
|
---|
154 | #ifdef QT3_SUPPORT
|
---|
155 | bool doAutoResize;
|
---|
156 | #endif
|
---|
157 | #ifdef Q_WS_MAC
|
---|
158 | //mac menubar binding
|
---|
159 | struct QMacMenuBarPrivate {
|
---|
160 | QList<QMacMenuAction*> actionItems;
|
---|
161 | OSMenuRef menu, apple_menu;
|
---|
162 | QMacMenuBarPrivate();
|
---|
163 | ~QMacMenuBarPrivate();
|
---|
164 |
|
---|
165 | void addAction(QAction *, QMacMenuAction* =0);
|
---|
166 | void addAction(QMacMenuAction *, QMacMenuAction* =0);
|
---|
167 | void syncAction(QMacMenuAction *);
|
---|
168 | inline void syncAction(QAction *a) { syncAction(findAction(a)); }
|
---|
169 | void removeAction(QMacMenuAction *);
|
---|
170 | inline void removeAction(QAction *a) { removeAction(findAction(a)); }
|
---|
171 | inline QMacMenuAction *findAction(QAction *a) {
|
---|
172 | for(int i = 0; i < actionItems.size(); i++) {
|
---|
173 | QMacMenuAction *act = actionItems[i];
|
---|
174 | if(a == act->action)
|
---|
175 | return act;
|
---|
176 | }
|
---|
177 | return 0;
|
---|
178 | }
|
---|
179 | } *mac_menubar;
|
---|
180 | void macCreateMenuBar(QWidget *);
|
---|
181 | void macDestroyMenuBar();
|
---|
182 | OSMenuRef macMenu();
|
---|
183 | #endif
|
---|
184 | #ifdef Q_OS_WINCE
|
---|
185 | void wceCreateMenuBar(QWidget *);
|
---|
186 | void wceDestroyMenuBar();
|
---|
187 | struct QWceMenuBarPrivate {
|
---|
188 | QList<QWceMenuAction*> actionItems;
|
---|
189 | QList<QWceMenuAction*> actionItemsLeftButton;
|
---|
190 | QList<QList<QWceMenuAction*>> actionItemsClassic;
|
---|
191 | HMENU menuHandle;
|
---|
192 | HMENU leftButtonMenuHandle;
|
---|
193 | HWND menubarHandle;
|
---|
194 | HWND parentWindowHandle;
|
---|
195 | bool leftButtonIsMenu;
|
---|
196 | QPointer<QAction> leftButtonAction;
|
---|
197 | QMenuBarPrivate *d;
|
---|
198 | int leftButtonCommand;
|
---|
199 |
|
---|
200 | QWceMenuBarPrivate(QMenuBarPrivate *menubar);
|
---|
201 | ~QWceMenuBarPrivate();
|
---|
202 | void addAction(QAction *, QWceMenuAction* =0);
|
---|
203 | void addAction(QWceMenuAction *, QWceMenuAction* =0);
|
---|
204 | void syncAction(QWceMenuAction *);
|
---|
205 | inline void syncAction(QAction *a) { syncAction(findAction(a)); }
|
---|
206 | void removeAction(QWceMenuAction *);
|
---|
207 | void rebuild();
|
---|
208 | inline void removeAction(QAction *a) { removeAction(findAction(a)); }
|
---|
209 | inline QWceMenuAction *findAction(QAction *a) {
|
---|
210 | for(int i = 0; i < actionItems.size(); i++) {
|
---|
211 | QWceMenuAction *act = actionItems[i];
|
---|
212 | if(a == act->action)
|
---|
213 | return act;
|
---|
214 | }
|
---|
215 | return 0;
|
---|
216 | }
|
---|
217 | } *wce_menubar;
|
---|
218 | bool wceClassicMenu;
|
---|
219 | void wceCommands(uint command);
|
---|
220 | void wceRefresh();
|
---|
221 | bool wceEmitSignals(QList<QWceMenuAction*> actions, uint command);
|
---|
222 | #endif
|
---|
223 | };
|
---|
224 | #endif
|
---|
225 |
|
---|
226 | #endif // QT_NO_MENUBAR
|
---|
227 |
|
---|
228 | QT_END_NAMESPACE
|
---|
229 |
|
---|
230 | #endif // QMENUBAR_P_H
|
---|