1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this 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 have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | //Native menubars are only supported for Windows Mobile not the standard SDK/generic WinCE
|
---|
43 | #ifdef Q_WS_WINCE
|
---|
44 | #include "qmenu.h"
|
---|
45 | #include "qt_windows.h"
|
---|
46 | #include "qapplication.h"
|
---|
47 | #include "qmainwindow.h"
|
---|
48 | #include "qtoolbar.h"
|
---|
49 | #include "qevent.h"
|
---|
50 | #include "qstyle.h"
|
---|
51 | #include "qdebug.h"
|
---|
52 | #include "qwidgetaction.h"
|
---|
53 | #include <private/qapplication_p.h>
|
---|
54 | #include <private/qmenu_p.h>
|
---|
55 | #include <private/qmenubar_p.h>
|
---|
56 |
|
---|
57 | #include "qmenu_wince_resource_p.h"
|
---|
58 |
|
---|
59 | #include <QtCore/qlibrary.h>
|
---|
60 | #include <commctrl.h>
|
---|
61 | #if Q_OS_WINCE_WM
|
---|
62 | # include <windowsm.h>
|
---|
63 | #endif
|
---|
64 |
|
---|
65 | #include "qguifunctions_wince.h"
|
---|
66 |
|
---|
67 | #ifndef QT_NO_MENUBAR
|
---|
68 |
|
---|
69 | #ifndef SHCMBF_EMPTYBAR
|
---|
70 | #define SHCMBF_EMPTYBAR 0x0001
|
---|
71 | #endif
|
---|
72 |
|
---|
73 | #ifndef SHCMBM_GETSUBMENU
|
---|
74 | #define SHCMBM_GETSUBMENU (WM_USER + 401)
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | #ifdef Q_OS_WINCE_WM
|
---|
78 | # define SHMBOF_NODEFAULT 0x00000001
|
---|
79 | # define SHMBOF_NOTIFY 0x00000002
|
---|
80 | # define SHCMBM_OVERRIDEKEY (WM_USER + 0x193)
|
---|
81 | #endif
|
---|
82 |
|
---|
83 | extern bool qt_wince_is_smartphone();//defined in qguifunctions_wce.cpp
|
---|
84 | extern bool qt_wince_is_pocket_pc(); //defined in qguifunctions_wce.cpp
|
---|
85 |
|
---|
86 | QT_BEGIN_NAMESPACE
|
---|
87 |
|
---|
88 | static uint qt_wce_menu_static_cmd_id = 200;
|
---|
89 | static QList<QMenuBar*> nativeMenuBars;
|
---|
90 |
|
---|
91 | struct qt_SHMENUBARINFO
|
---|
92 | {
|
---|
93 | DWORD cbSize;
|
---|
94 | HWND hwndParent;
|
---|
95 | DWORD dwFlags;
|
---|
96 | UINT nToolBarId;
|
---|
97 | HINSTANCE hInstRes;
|
---|
98 | int nBmpId;
|
---|
99 | int cBmpImages;
|
---|
100 | HWND hwndMB;
|
---|
101 | COLORREF clrBk;
|
---|
102 | };
|
---|
103 |
|
---|
104 | typedef BOOL (WINAPI *AygCreateMenuBar)(qt_SHMENUBARINFO*);
|
---|
105 | typedef HRESULT (WINAPI *AygEnableSoftKey)(HWND,UINT,BOOL,BOOL);
|
---|
106 |
|
---|
107 | static bool aygResolved = false;
|
---|
108 | static AygCreateMenuBar ptrCreateMenuBar = 0;
|
---|
109 | static AygEnableSoftKey ptrEnableSoftKey = 0;
|
---|
110 |
|
---|
111 | static void resolveAygLibs()
|
---|
112 | {
|
---|
113 | if (!aygResolved) {
|
---|
114 | aygResolved = true;
|
---|
115 | QLibrary aygLib(QLatin1String("aygshell"));
|
---|
116 | if (!aygLib.load())
|
---|
117 | return;
|
---|
118 | ptrCreateMenuBar = (AygCreateMenuBar) aygLib.resolve("SHCreateMenuBar");
|
---|
119 | ptrEnableSoftKey = (AygEnableSoftKey) aygLib.resolve("SHEnableSoftkey");
|
---|
120 | }
|
---|
121 | }
|
---|
122 |
|
---|
123 | static void qt_wce_enable_soft_key(HWND handle, uint command)
|
---|
124 | {
|
---|
125 | resolveAygLibs();
|
---|
126 | if (ptrEnableSoftKey)
|
---|
127 | ptrEnableSoftKey(handle, command, false, true);
|
---|
128 | }
|
---|
129 |
|
---|
130 | static void qt_wce_disable_soft_key(HWND handle, uint command)
|
---|
131 | {
|
---|
132 | resolveAygLibs();
|
---|
133 | if (ptrEnableSoftKey)
|
---|
134 | ptrEnableSoftKey(handle, command, false, false);
|
---|
135 | }
|
---|
136 |
|
---|
137 | static void qt_wce_delete_action_list(QList<QWceMenuAction*> *list)
|
---|
138 | {
|
---|
139 | for(QList<QWceMenuAction*>::Iterator it = list->begin(); it != list->end(); ++it) {
|
---|
140 | QWceMenuAction *action = (*it);
|
---|
141 | delete action;
|
---|
142 | action = 0;
|
---|
143 | }
|
---|
144 | list->clear();
|
---|
145 | }
|
---|
146 |
|
---|
147 | //search for first QuitRole in QMenuBar
|
---|
148 | static QAction* qt_wce_get_quit_action(QList<QAction *> actionItems)
|
---|
149 | {
|
---|
150 | QAction *returnAction = 0;
|
---|
151 | for (int i = 0; i < actionItems.size(); ++i) {
|
---|
152 | QAction *action = actionItems.at(i);
|
---|
153 | if (action->menuRole() == QAction::QuitRole)
|
---|
154 | returnAction = action;
|
---|
155 | else
|
---|
156 | if (action->menu())
|
---|
157 | returnAction = qt_wce_get_quit_action(action->menu()->actions());
|
---|
158 | if (returnAction)
|
---|
159 | return returnAction; //return first action found
|
---|
160 | }
|
---|
161 | return 0; //nothing found;
|
---|
162 | }
|
---|
163 |
|
---|
164 | static QAction* qt_wce_get_quit_action(QList<QWceMenuAction*> actionItems)
|
---|
165 | {
|
---|
166 | for (int i = 0; i < actionItems.size(); ++i) {
|
---|
167 | if (actionItems.at(i)->action->menuRole() == QAction::QuitRole)
|
---|
168 | return actionItems.at(i)->action;
|
---|
169 | else if (actionItems.at(i)->action->menu()) {
|
---|
170 | QAction *returnAction = qt_wce_get_quit_action(actionItems.at(i)->action->menu()->actions());
|
---|
171 | if (returnAction)
|
---|
172 | return returnAction;
|
---|
173 | }
|
---|
174 | }
|
---|
175 | return 0;
|
---|
176 | }
|
---|
177 |
|
---|
178 | static HMODULE qt_wce_get_module_handle()
|
---|
179 | {
|
---|
180 | HMODULE module = 0; //handle to resources
|
---|
181 | if (!(module = GetModuleHandle(L"QtGui4"))) //release dynamic
|
---|
182 | if (!(module = GetModuleHandle(L"QtGuid4"))) //debug dynamic
|
---|
183 | module = (HINSTANCE)qWinAppInst(); //static
|
---|
184 | Q_ASSERT_X(module, "qt_wce_get_module_handle()", "cannot get handle to module?");
|
---|
185 | return module;
|
---|
186 | }
|
---|
187 |
|
---|
188 | static void qt_wce_change_command(HWND menuHandle, int item, int command)
|
---|
189 | {
|
---|
190 | TBBUTTONINFOA tbbi;
|
---|
191 | memset(&tbbi,0,sizeof(tbbi));
|
---|
192 | tbbi.cbSize = sizeof(tbbi);
|
---|
193 | tbbi.dwMask = TBIF_COMMAND;
|
---|
194 | tbbi.idCommand = command;
|
---|
195 | SendMessage(menuHandle, TB_SETBUTTONINFO, item, (LPARAM)&tbbi);
|
---|
196 | }
|
---|
197 |
|
---|
198 | static void qt_wce_rename_menu_item(HWND menuHandle, int item, const QString &newText)
|
---|
199 | {
|
---|
200 | TBBUTTONINFOA tbbi;
|
---|
201 | memset(&tbbi,0,sizeof(tbbi));
|
---|
202 | tbbi.cbSize = sizeof(tbbi);
|
---|
203 | tbbi.dwMask = TBIF_TEXT;
|
---|
204 | QString text = newText;
|
---|
205 | text.remove(QChar::fromLatin1('&'));
|
---|
206 | tbbi.pszText = (LPSTR) text.utf16();
|
---|
207 | SendMessage(menuHandle, TB_SETBUTTONINFO, item, (LPARAM)&tbbi);
|
---|
208 | }
|
---|
209 |
|
---|
210 | static HWND qt_wce_create_menubar(HWND parentHandle, HINSTANCE resourceHandle, int toolbarID, int flags = 0)
|
---|
211 | {
|
---|
212 | resolveAygLibs();
|
---|
213 |
|
---|
214 | if (ptrCreateMenuBar) {
|
---|
215 | qt_SHMENUBARINFO mbi;
|
---|
216 | memset(&mbi, 0, sizeof(qt_SHMENUBARINFO));
|
---|
217 | mbi.cbSize = sizeof(qt_SHMENUBARINFO);
|
---|
218 | mbi.hwndParent = parentHandle;
|
---|
219 | mbi.hInstRes = resourceHandle;
|
---|
220 | mbi.dwFlags = flags;
|
---|
221 | mbi.nToolBarId = toolbarID;
|
---|
222 |
|
---|
223 | if (ptrCreateMenuBar(&mbi)) {
|
---|
224 | #ifdef Q_OS_WINCE_WM
|
---|
225 | // Tell the menu bar that we want to override hot key behaviour.
|
---|
226 | LPARAM lparam = MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
|
---|
227 | SHMBOF_NODEFAULT | SHMBOF_NOTIFY);
|
---|
228 | SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK, lparam);
|
---|
229 | #endif
|
---|
230 | return mbi.hwndMB;
|
---|
231 | }
|
---|
232 | }
|
---|
233 | return 0;
|
---|
234 | }
|
---|
235 |
|
---|
236 | static void qt_wce_insert_action(HMENU menu, QWceMenuAction *action)
|
---|
237 | {
|
---|
238 | Q_ASSERT_X(menu, "AppendMenu", "menu is 0");
|
---|
239 | if (action->action->isVisible()) {
|
---|
240 | int flags;
|
---|
241 | action->action->isEnabled() ? flags = MF_ENABLED : flags = MF_GRAYED;
|
---|
242 |
|
---|
243 | QString text = action->action->iconText();
|
---|
244 | text.remove(QChar::fromLatin1('&'));
|
---|
245 | if (action->action->isSeparator()) {
|
---|
246 | AppendMenu (menu, MF_SEPARATOR , 0, 0);
|
---|
247 | }
|
---|
248 | else if (action->action->menu()) {
|
---|
249 | text.remove(QChar::fromLatin1('&'));
|
---|
250 | AppendMenu (menu, MF_STRING | flags | MF_POPUP,
|
---|
251 | (UINT) action->action->menu()->wceMenu(), reinterpret_cast<const wchar_t *> (text.utf16()));
|
---|
252 | }
|
---|
253 | else {
|
---|
254 | AppendMenu (menu, MF_STRING | flags, action->command, reinterpret_cast<const wchar_t *> (text.utf16()));
|
---|
255 | }
|
---|
256 | if (action->action->isCheckable())
|
---|
257 | if (action->action->isChecked())
|
---|
258 | CheckMenuItem(menu, action->command, MF_BYCOMMAND | MF_CHECKED);
|
---|
259 | else
|
---|
260 | CheckMenuItem(menu, action->command, MF_BYCOMMAND | MF_UNCHECKED);
|
---|
261 | }
|
---|
262 | }
|
---|
263 |
|
---|
264 | // Removes all items from the menu without destroying the handles.
|
---|
265 | static void qt_wce_clear_menu(HMENU hMenu)
|
---|
266 | {
|
---|
267 | while (RemoveMenu(hMenu, 0, MF_BYPOSITION));
|
---|
268 | }
|
---|
269 |
|
---|
270 | /*!
|
---|
271 | \internal
|
---|
272 |
|
---|
273 | This function refreshes the native Windows CE menu.
|
---|
274 | */
|
---|
275 |
|
---|
276 | void QMenuBar::wceRefresh()
|
---|
277 | {
|
---|
278 | for (int i = 0; i < nativeMenuBars.size(); ++i)
|
---|
279 | nativeMenuBars.at(i)->d_func()->wceRefresh();
|
---|
280 | }
|
---|
281 |
|
---|
282 | void QMenuBarPrivate::wceRefresh()
|
---|
283 | {
|
---|
284 | DrawMenuBar(wce_menubar->menubarHandle);
|
---|
285 | }
|
---|
286 |
|
---|
287 | /*!
|
---|
288 | \internal
|
---|
289 |
|
---|
290 | This function sends native Windows CE commands to Qt menus.
|
---|
291 | */
|
---|
292 |
|
---|
293 | QAction* QMenu::wceCommands(uint command)
|
---|
294 | {
|
---|
295 | Q_D(QMenu);
|
---|
296 | return d->wceCommands(command);
|
---|
297 | }
|
---|
298 |
|
---|
299 | /*!
|
---|
300 | \internal
|
---|
301 |
|
---|
302 | This function sends native Windows CE commands to Qt menu bars
|
---|
303 | and all their child menus.
|
---|
304 | */
|
---|
305 |
|
---|
306 | void QMenuBar::wceCommands(uint command)
|
---|
307 | {
|
---|
308 | const HWND hwndActiveWindow = GetActiveWindow();
|
---|
309 | for (int i = 0; i < nativeMenuBars.size(); ++i) {
|
---|
310 | QMenuBarPrivate* nativeMenuBar = nativeMenuBars.at(i)->d_func();
|
---|
311 | if (hwndActiveWindow == nativeMenuBar->wce_menubar->parentWindowHandle)
|
---|
312 | nativeMenuBar->wceCommands(command);
|
---|
313 | }
|
---|
314 | }
|
---|
315 |
|
---|
316 | bool QMenuBarPrivate::wceEmitSignals(QList<QWceMenuAction*> actions, uint command)
|
---|
317 | {
|
---|
318 | QAction *foundAction = 0;
|
---|
319 | for (int i = 0; i < actions.size(); ++i) {
|
---|
320 | QWceMenuAction *action = actions.at(i);
|
---|
321 | if (action->action->menu()) {
|
---|
322 | foundAction = action->action->menu()->wceCommands(command);
|
---|
323 | if (foundAction)
|
---|
324 | break;
|
---|
325 | }
|
---|
326 | else if (action->command == command) {
|
---|
327 | action->action->activate(QAction::Trigger);
|
---|
328 | return true;
|
---|
329 | }
|
---|
330 | }
|
---|
331 | if (foundAction) {
|
---|
332 | emit q_func()->triggered(foundAction);
|
---|
333 | return true;
|
---|
334 | }
|
---|
335 | return false;
|
---|
336 | }
|
---|
337 |
|
---|
338 | void QMenuBarPrivate::wceCommands(uint command)
|
---|
339 | {
|
---|
340 | if (wceClassicMenu) {
|
---|
341 | for (int i = 0; i < wce_menubar->actionItemsClassic.size(); ++i)
|
---|
342 | wceEmitSignals(wce_menubar->actionItemsClassic.at(i), command);
|
---|
343 | } else {
|
---|
344 | if (wceEmitSignals(wce_menubar->actionItems, command)) {
|
---|
345 | return;
|
---|
346 | }
|
---|
347 | else if (wce_menubar->leftButtonIsMenu) {//check if command is on the left quick button
|
---|
348 | wceEmitSignals(wce_menubar->actionItemsLeftButton, command);
|
---|
349 | }
|
---|
350 | else if ((wce_menubar->leftButtonAction) && (command == wce_menubar->leftButtonCommand)) {
|
---|
351 | emit q_func()->triggered(wce_menubar->leftButtonAction);
|
---|
352 | wce_menubar->leftButtonAction->activate(QAction::Trigger);
|
---|
353 | }
|
---|
354 | }
|
---|
355 | }
|
---|
356 |
|
---|
357 | QAction *QMenuPrivate::wceCommands(uint command)
|
---|
358 | {
|
---|
359 | QAction *foundAction = 0;
|
---|
360 | for (int i = 0; i < wce_menu->actionItems.size(); ++i) {
|
---|
361 | if (foundAction)
|
---|
362 | break;
|
---|
363 | QWceMenuAction *action = wce_menu->actionItems.at(i);
|
---|
364 | if (action->action->menu()) {
|
---|
365 | foundAction = action->action->menu()->d_func()->wceCommands(command);
|
---|
366 | }
|
---|
367 | else if (action->command == command) {
|
---|
368 | activateAction(action->action, QAction::Trigger);
|
---|
369 | return action->action;
|
---|
370 | }
|
---|
371 | }
|
---|
372 | if (foundAction)
|
---|
373 | emit q_func()->triggered(foundAction);
|
---|
374 | return foundAction;
|
---|
375 | }
|
---|
376 |
|
---|
377 | void QMenuBarPrivate::wceCreateMenuBar(QWidget *parent)
|
---|
378 | {
|
---|
379 | Q_Q(QMenuBar);
|
---|
380 | wce_menubar = new QWceMenuBarPrivate(this);
|
---|
381 |
|
---|
382 | wce_menubar->parentWindowHandle = parent ? parent->winId() : q->winId();
|
---|
383 | wce_menubar->leftButtonAction = defaultAction;
|
---|
384 |
|
---|
385 | wce_menubar->menubarHandle = qt_wce_create_menubar(wce_menubar->parentWindowHandle, (HINSTANCE)qWinAppInst(), 0, SHCMBF_EMPTYBAR);
|
---|
386 | Q_ASSERT_X(wce_menubar->menubarHandle, "wceCreateMenuBar", "cannot create empty menu bar");
|
---|
387 | DrawMenuBar(wce_menubar->menubarHandle);
|
---|
388 | nativeMenuBars.append(q);
|
---|
389 | wceClassicMenu = (!qt_wince_is_smartphone() && !qt_wince_is_pocket_pc());
|
---|
390 | }
|
---|
391 |
|
---|
392 | void QMenuBarPrivate::wceDestroyMenuBar()
|
---|
393 | {
|
---|
394 | Q_Q(QMenuBar);
|
---|
395 | int index = nativeMenuBars.indexOf(q);
|
---|
396 | nativeMenuBars.removeAt(index);
|
---|
397 | if (wce_menubar) {
|
---|
398 | delete wce_menubar;
|
---|
399 | wce_menubar = 0;
|
---|
400 | }
|
---|
401 | }
|
---|
402 |
|
---|
403 | QMenuBarPrivate::QWceMenuBarPrivate::QWceMenuBarPrivate(QMenuBarPrivate *menubar)
|
---|
404 | : menubarHandle(0), menuHandle(0), leftButtonMenuHandle(0),
|
---|
405 | leftButtonAction(0), leftButtonIsMenu(false), d(menubar)
|
---|
406 | {
|
---|
407 | }
|
---|
408 |
|
---|
409 | QMenuBarPrivate::QWceMenuBarPrivate::~QWceMenuBarPrivate()
|
---|
410 | {
|
---|
411 | if (menubarHandle)
|
---|
412 | DestroyWindow(menubarHandle);
|
---|
413 | qt_wce_delete_action_list(&actionItems);
|
---|
414 | qt_wce_delete_action_list(&actionItemsLeftButton);
|
---|
415 |
|
---|
416 | for (int i=0; i<actionItemsClassic.size(); ++i)
|
---|
417 | if (!actionItemsClassic.value(i).empty())
|
---|
418 | qt_wce_delete_action_list(&actionItemsClassic[i]);
|
---|
419 | actionItemsClassic.clear();
|
---|
420 |
|
---|
421 | menubarHandle = 0;
|
---|
422 | menuHandle = 0;
|
---|
423 | leftButtonMenuHandle = 0;
|
---|
424 | leftButtonCommand = 0;
|
---|
425 | QMenuBar::wceRefresh();
|
---|
426 | }
|
---|
427 |
|
---|
428 | QMenuPrivate::QWceMenuPrivate::QWceMenuPrivate()
|
---|
429 | : menuHandle(0)
|
---|
430 | {
|
---|
431 | }
|
---|
432 |
|
---|
433 | QMenuPrivate::QWceMenuPrivate::~QWceMenuPrivate()
|
---|
434 | {
|
---|
435 | qt_wce_delete_action_list(&actionItems);
|
---|
436 | if (menuHandle)
|
---|
437 | DestroyMenu(menuHandle);
|
---|
438 | }
|
---|
439 |
|
---|
440 | void QMenuPrivate::QWceMenuPrivate::addAction(QAction *a, QWceMenuAction *before)
|
---|
441 | {
|
---|
442 | QWceMenuAction *action = new QWceMenuAction;
|
---|
443 | action->action = a;
|
---|
444 | action->command = qt_wce_menu_static_cmd_id++;
|
---|
445 | addAction(action, before);
|
---|
446 | }
|
---|
447 |
|
---|
448 | void QMenuPrivate::QWceMenuPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before)
|
---|
449 | {
|
---|
450 | if (!action)
|
---|
451 | return;
|
---|
452 | int before_index = actionItems.indexOf(before);
|
---|
453 | if (before_index < 0) {
|
---|
454 | before = 0;
|
---|
455 | before_index = actionItems.size();
|
---|
456 | }
|
---|
457 | actionItems.insert(before_index, action);
|
---|
458 | rebuild();
|
---|
459 | }
|
---|
460 |
|
---|
461 | /*!
|
---|
462 | \internal
|
---|
463 |
|
---|
464 | This function will return the HMENU used to create the native
|
---|
465 | Windows CE menu bar bindings.
|
---|
466 | */
|
---|
467 |
|
---|
468 | HMENU QMenu::wceMenu()
|
---|
469 | {
|
---|
470 | return d_func()->wceMenu();
|
---|
471 | }
|
---|
472 |
|
---|
473 | HMENU QMenuPrivate::wceMenu()
|
---|
474 | {
|
---|
475 | if (!wce_menu)
|
---|
476 | wce_menu = new QWceMenuPrivate;
|
---|
477 | if (!wce_menu->menuHandle)
|
---|
478 | wce_menu->rebuild();
|
---|
479 | return wce_menu->menuHandle;
|
---|
480 | }
|
---|
481 |
|
---|
482 | void QMenuPrivate::QWceMenuPrivate::rebuild()
|
---|
483 | {
|
---|
484 | if (!menuHandle)
|
---|
485 | menuHandle = CreatePopupMenu();
|
---|
486 | else
|
---|
487 | qt_wce_clear_menu(menuHandle);
|
---|
488 |
|
---|
489 | for (int i = 0; i < actionItems.size(); ++i) {
|
---|
490 | QWceMenuAction *action = actionItems.at(i);
|
---|
491 | action->menuHandle = menuHandle;
|
---|
492 | qt_wce_insert_action(menuHandle, action);
|
---|
493 | }
|
---|
494 | QMenuBar::wceRefresh();
|
---|
495 | }
|
---|
496 |
|
---|
497 | void QMenuPrivate::QWceMenuPrivate::syncAction(QWceMenuAction *)
|
---|
498 | {
|
---|
499 | rebuild();
|
---|
500 | }
|
---|
501 |
|
---|
502 | void QMenuPrivate::QWceMenuPrivate::removeAction(QWceMenuAction *action)
|
---|
503 | {
|
---|
504 | actionItems.removeAll(action);
|
---|
505 | delete action;
|
---|
506 | rebuild();
|
---|
507 | }
|
---|
508 |
|
---|
509 | void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QAction *a, QWceMenuAction *before)
|
---|
510 | {
|
---|
511 | QWceMenuAction *action = new QWceMenuAction;
|
---|
512 | action->action = a;
|
---|
513 | action->command = qt_wce_menu_static_cmd_id++;
|
---|
514 | addAction(action, before);
|
---|
515 | }
|
---|
516 |
|
---|
517 | void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before)
|
---|
518 | {
|
---|
519 | if (!action)
|
---|
520 | return;
|
---|
521 | int before_index = actionItems.indexOf(before);
|
---|
522 | if (before_index < 0) {
|
---|
523 | before = 0;
|
---|
524 | before_index = actionItems.size();
|
---|
525 | }
|
---|
526 | actionItems.insert(before_index, action);
|
---|
527 | rebuild();
|
---|
528 | }
|
---|
529 |
|
---|
530 | void QMenuBarPrivate::QWceMenuBarPrivate::syncAction(QWceMenuAction*)
|
---|
531 | {
|
---|
532 | QMenuBar::wceRefresh();
|
---|
533 | rebuild();
|
---|
534 | }
|
---|
535 |
|
---|
536 | void QMenuBarPrivate::QWceMenuBarPrivate::removeAction(QWceMenuAction *action)
|
---|
537 | {
|
---|
538 | actionItems.removeAll(action);
|
---|
539 | delete action;
|
---|
540 | rebuild();
|
---|
541 | }
|
---|
542 |
|
---|
543 | void QMenuBarPrivate::_q_updateDefaultAction()
|
---|
544 | {
|
---|
545 | if (wce_menubar)
|
---|
546 | wce_menubar->rebuild();
|
---|
547 | }
|
---|
548 |
|
---|
549 | void QMenuBarPrivate::QWceMenuBarPrivate::rebuild()
|
---|
550 | {
|
---|
551 | d->q_func()->resize(0,0);
|
---|
552 | parentWindowHandle = d->q_func()->parentWidget() ? d->q_func()->parentWidget()->winId() : d->q_func()->winId();
|
---|
553 | if (d->wceClassicMenu) {
|
---|
554 | QList<QAction*> actions = d->actions;
|
---|
555 | int maxEntries;
|
---|
556 | int resourceHandle;
|
---|
557 | if (actions.size() < 5) {
|
---|
558 | maxEntries = 4;
|
---|
559 | resourceHandle = IDR_MAIN_MENU3;
|
---|
560 | } else if (actions.size() < 7) {
|
---|
561 | maxEntries = 6;
|
---|
562 | resourceHandle = IDR_MAIN_MENU4;
|
---|
563 | }
|
---|
564 | else {
|
---|
565 | maxEntries = 8;
|
---|
566 | resourceHandle = IDR_MAIN_MENU5;
|
---|
567 | }
|
---|
568 | Q_ASSERT_X(menubarHandle, "rebuild !created", "menubar already deleted");
|
---|
569 | qt_wce_clear_menu(menuHandle);
|
---|
570 | DestroyWindow(menubarHandle);
|
---|
571 | menubarHandle = qt_wce_create_menubar(parentWindowHandle, qt_wce_get_module_handle(), resourceHandle);
|
---|
572 | Q_ASSERT_X(menubarHandle, "rebuild classic menu", "cannot create menubar from resource");
|
---|
573 | DrawMenuBar(menubarHandle);
|
---|
574 | QList<int> menu_ids;
|
---|
575 | QList<int> item_ids;
|
---|
576 | menu_ids << IDM_MENU1 << IDM_MENU2 << IDM_MENU3 << IDM_MENU4 << IDM_MENU5 << IDM_MENU6 << IDM_MENU7 << IDM_MENU8;
|
---|
577 | item_ids << IDM_ITEM1 << IDM_ITEM2 << IDM_ITEM3 << IDM_ITEM4 << IDM_ITEM5 << IDM_ITEM6 << IDM_ITEM7 << IDM_ITEM8;
|
---|
578 |
|
---|
579 | for (int i = 0; i < actionItemsClassic.size(); ++i)
|
---|
580 | if (!actionItemsClassic.value(i).empty())
|
---|
581 | qt_wce_delete_action_list(&actionItemsClassic[i]);
|
---|
582 | actionItemsClassic.clear();
|
---|
583 |
|
---|
584 | for (int i = 0; i < actions.size(); ++i) {
|
---|
585 | qt_wce_rename_menu_item(menubarHandle, menu_ids.at(i), actions.at(i)->text());
|
---|
586 | QList<QAction *> subActions = actions.at(i)->menu()->actions();
|
---|
587 | HMENU subMenuHandle = (HMENU) SendMessage(menubarHandle, SHCMBM_GETSUBMENU,0 , menu_ids.at(i));
|
---|
588 | DeleteMenu(subMenuHandle, item_ids.at(i), MF_BYCOMMAND);
|
---|
589 | for (int c = 0; c < subActions.size(); ++c) {
|
---|
590 | QList<QWceMenuAction*> list;
|
---|
591 | actionItemsClassic.append(list);
|
---|
592 | QWceMenuAction *action = new QWceMenuAction;
|
---|
593 | action->action = subActions.at(c);
|
---|
594 | action->command = qt_wce_menu_static_cmd_id++;
|
---|
595 | action->menuHandle = subMenuHandle;
|
---|
596 | actionItemsClassic.last().append(action);
|
---|
597 | qt_wce_insert_action(subMenuHandle, action);
|
---|
598 | }
|
---|
599 | }
|
---|
600 | for (int i = actions.size();i<maxEntries;++i) {
|
---|
601 | qt_wce_rename_menu_item(menubarHandle, menu_ids.at(i), QString());
|
---|
602 | qt_wce_disable_soft_key(menubarHandle, menu_ids.at(i));
|
---|
603 | }
|
---|
604 | } else {
|
---|
605 | leftButtonAction = d->defaultAction;
|
---|
606 | if (!leftButtonAction)
|
---|
607 | leftButtonAction = qt_wce_get_quit_action(actionItems);
|
---|
608 |
|
---|
609 | leftButtonIsMenu = (leftButtonAction && leftButtonAction->menu());
|
---|
610 | Q_ASSERT_X(menubarHandle, "rebuild !created", "menubar already deleted");
|
---|
611 | qt_wce_clear_menu(menuHandle);
|
---|
612 | DestroyWindow(menubarHandle);
|
---|
613 | if (leftButtonIsMenu) {
|
---|
614 | menubarHandle = qt_wce_create_menubar(parentWindowHandle, qt_wce_get_module_handle(), IDR_MAIN_MENU2);
|
---|
615 | Q_ASSERT_X(menubarHandle, "rebuild !created left menubar", "cannot create menubar from resource");
|
---|
616 | menuHandle = (HMENU) SendMessage(menubarHandle, SHCMBM_GETSUBMENU,0,IDM_MENU);
|
---|
617 | Q_ASSERT_X(menuHandle, "rebuild !created", "IDM_MENU not found - invalid resource?");
|
---|
618 | DeleteMenu(menuHandle, IDM_ABOUT, MF_BYCOMMAND);
|
---|
619 | leftButtonMenuHandle = (HMENU) SendMessage(menubarHandle, SHCMBM_GETSUBMENU,0,IDM_LEFTMENU);
|
---|
620 | Q_ASSERT_X(leftButtonMenuHandle, "rebuild !created", "IDM_LEFTMENU not found - invalid resource?");
|
---|
621 | DeleteMenu(leftButtonMenuHandle, IDM_VIEW, MF_BYCOMMAND);
|
---|
622 | } else {
|
---|
623 | menubarHandle = qt_wce_create_menubar(parentWindowHandle, qt_wce_get_module_handle(), IDR_MAIN_MENU);
|
---|
624 | Q_ASSERT_X(menubarHandle, "rebuild !created no left menubar", "cannot create menubar from resource");
|
---|
625 | menuHandle = (HMENU) SendMessage(menubarHandle, SHCMBM_GETSUBMENU,0,IDM_MENU);
|
---|
626 | Q_ASSERT_X(menuHandle, "rebuild !created", "IDM_MENU not found - invalid resource?");
|
---|
627 | DeleteMenu(menuHandle, IDM_ABOUT, MF_BYCOMMAND);
|
---|
628 | leftButtonMenuHandle = 0;
|
---|
629 | leftButtonCommand = qt_wce_menu_static_cmd_id++;
|
---|
630 | qt_wce_change_command(menubarHandle, IDM_EXIT, leftButtonCommand);
|
---|
631 | }
|
---|
632 |
|
---|
633 | if (actionItems.size() == 0) {
|
---|
634 | qt_wce_rename_menu_item(menubarHandle, IDM_MENU, QLatin1String(""));
|
---|
635 | qt_wce_disable_soft_key(menubarHandle, IDM_MENU);
|
---|
636 | }
|
---|
637 | for (int i = 0; i < actionItems.size(); ++i) {
|
---|
638 | QWceMenuAction *action = actionItems.at(i);
|
---|
639 | action->menuHandle = menuHandle;
|
---|
640 | qt_wce_insert_action(menuHandle, action);
|
---|
641 | }
|
---|
642 | if (!leftButtonIsMenu) {
|
---|
643 | if (leftButtonAction) {
|
---|
644 | qt_wce_rename_menu_item(menubarHandle, leftButtonCommand, leftButtonAction->text());
|
---|
645 | qt_wce_enable_soft_key(menubarHandle, leftButtonCommand);
|
---|
646 | } else {
|
---|
647 | qt_wce_rename_menu_item(menubarHandle, leftButtonCommand, QLatin1String(""));
|
---|
648 | qt_wce_disable_soft_key(menubarHandle, leftButtonCommand);
|
---|
649 | }
|
---|
650 | } else {
|
---|
651 | qt_wce_rename_menu_item(menubarHandle, IDM_LEFTMENU, leftButtonAction->text());
|
---|
652 | QList<QAction *> actions = leftButtonAction->menu()->actions();
|
---|
653 | qt_wce_delete_action_list(&actionItemsLeftButton);
|
---|
654 | for (int i=0; i<actions.size(); ++i) {
|
---|
655 | QWceMenuAction *action = new QWceMenuAction;
|
---|
656 | action->action = actions.at(i);
|
---|
657 | action->command = qt_wce_menu_static_cmd_id++;
|
---|
658 | action->menuHandle = leftButtonMenuHandle;
|
---|
659 | actionItemsLeftButton.append(action);
|
---|
660 | qt_wce_insert_action(leftButtonMenuHandle, action);
|
---|
661 | }
|
---|
662 | }
|
---|
663 | }
|
---|
664 | DrawMenuBar(menubarHandle);
|
---|
665 | }
|
---|
666 |
|
---|
667 | QT_END_NAMESPACE
|
---|
668 |
|
---|
669 | #endif //QT_NO_MENUBAR
|
---|
670 | #endif //Q_WS_WINCE
|
---|