|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
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 static void qt_wce_disable_soft_key(HWND handle, uint command) |
|
130 { |
|
131 resolveAygLibs(); |
|
132 if (ptrEnableSoftKey) |
|
133 ptrEnableSoftKey(handle, command, false, false); |
|
134 } |
|
135 |
|
136 static void qt_wce_delete_action_list(QList<QWceMenuAction*> *list) { |
|
137 for(QList<QWceMenuAction*>::Iterator it = list->begin(); it != list->end(); ++it) { |
|
138 QWceMenuAction *action = (*it); |
|
139 delete action; |
|
140 action = 0; |
|
141 } |
|
142 list->clear(); |
|
143 } |
|
144 |
|
145 //search for first QuitRole in QMenuBar |
|
146 static QAction* qt_wce_get_quit_action(QList<QAction *> actionItems) { |
|
147 QAction *returnAction = 0; |
|
148 for (int i = 0; i < actionItems.size(); ++i) { |
|
149 QAction *action = actionItems.at(i); |
|
150 if (action->menuRole() == QAction::QuitRole) |
|
151 returnAction = action; |
|
152 else |
|
153 if (action->menu()) |
|
154 returnAction = qt_wce_get_quit_action(action->menu()->actions()); |
|
155 if (returnAction) |
|
156 return returnAction; //return first action found |
|
157 } |
|
158 return 0; //nothing found; |
|
159 } |
|
160 |
|
161 static QAction* qt_wce_get_quit_action(QList<QWceMenuAction*> actionItems) { |
|
162 for (int i = 0; i < actionItems.size(); ++i) { |
|
163 if (actionItems.at(i)->action->menuRole() == QAction::QuitRole) |
|
164 return actionItems.at(i)->action; |
|
165 else if (actionItems.at(i)->action->menu()) { |
|
166 QAction *returnAction = qt_wce_get_quit_action(actionItems.at(i)->action->menu()->actions()); |
|
167 if (returnAction) |
|
168 return returnAction; |
|
169 } |
|
170 } |
|
171 return 0; |
|
172 } |
|
173 |
|
174 static HMODULE qt_wce_get_module_handle() { |
|
175 HMODULE module = 0; //handle to resources |
|
176 if (!(module = GetModuleHandle(L"QtGui4"))) //release dynamic |
|
177 if (!(module = GetModuleHandle(L"QtGuid4"))) //debug dynamic |
|
178 module = (HINSTANCE)qWinAppInst(); //static |
|
179 Q_ASSERT_X(module, "qt_wce_get_module_handle()", "cannot get handle to module?"); |
|
180 return module; |
|
181 } |
|
182 |
|
183 static void qt_wce_change_command(HWND menuHandle, int item, int command) { |
|
184 TBBUTTONINFOA tbbi; |
|
185 memset(&tbbi,0,sizeof(tbbi)); |
|
186 tbbi.cbSize = sizeof(tbbi); |
|
187 tbbi.dwMask = TBIF_COMMAND; |
|
188 tbbi.idCommand = command; |
|
189 SendMessage(menuHandle, TB_SETBUTTONINFO, item, (LPARAM)&tbbi); |
|
190 } |
|
191 |
|
192 static void qt_wce_rename_menu_item(HWND menuHandle, int item, const QString &newText) { |
|
193 TBBUTTONINFOA tbbi; |
|
194 memset(&tbbi,0,sizeof(tbbi)); |
|
195 tbbi.cbSize = sizeof(tbbi); |
|
196 tbbi.dwMask = TBIF_TEXT; |
|
197 QString text = newText; |
|
198 text.remove(QChar::fromLatin1('&')); |
|
199 tbbi.pszText = (LPSTR) text.utf16(); |
|
200 SendMessage(menuHandle, TB_SETBUTTONINFO, item, (LPARAM)&tbbi); |
|
201 } |
|
202 |
|
203 static HWND qt_wce_create_menubar(HWND parentHandle, HINSTANCE resourceHandle, int toolbarID, int flags = 0) { |
|
204 resolveAygLibs(); |
|
205 |
|
206 if (ptrCreateMenuBar) { |
|
207 qt_SHMENUBARINFO mbi; |
|
208 memset(&mbi, 0, sizeof(qt_SHMENUBARINFO)); |
|
209 mbi.cbSize = sizeof(qt_SHMENUBARINFO); |
|
210 mbi.hwndParent = parentHandle; |
|
211 mbi.hInstRes = resourceHandle; |
|
212 mbi.dwFlags = flags; |
|
213 mbi.nToolBarId = toolbarID; |
|
214 |
|
215 if (ptrCreateMenuBar(&mbi)) { |
|
216 #ifdef Q_OS_WINCE_WM |
|
217 // Tell the menu bar that we want to override hot key behaviour. |
|
218 LPARAM lparam = MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY, |
|
219 SHMBOF_NODEFAULT | SHMBOF_NOTIFY); |
|
220 SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK, lparam); |
|
221 #endif |
|
222 return mbi.hwndMB; |
|
223 } |
|
224 } |
|
225 return 0; |
|
226 } |
|
227 |
|
228 static void qt_wce_insert_action(HMENU menu, QWceMenuAction *action, bool created) { |
|
229 |
|
230 Q_ASSERT_X(menu, "AppendMenu", "menu is 0"); |
|
231 if (action->action->isVisible()) { |
|
232 int flags; |
|
233 action->action->isEnabled() ? flags = MF_ENABLED : flags = MF_GRAYED; |
|
234 |
|
235 QString text = action->action->iconText(); |
|
236 text.remove(QChar::fromLatin1('&')); |
|
237 if (action->action->isSeparator()) { |
|
238 AppendMenu (menu, MF_SEPARATOR , 0, 0); |
|
239 } |
|
240 else if (action->action->menu()) { |
|
241 text.remove(QChar::fromLatin1('&')); |
|
242 AppendMenu (menu, MF_STRING | flags | MF_POPUP, |
|
243 (UINT) action->action->menu()->wceMenu(created), reinterpret_cast<const wchar_t *> (text.utf16())); |
|
244 } |
|
245 else { |
|
246 AppendMenu (menu, MF_STRING | flags, action->command, reinterpret_cast<const wchar_t *> (text.utf16())); |
|
247 } |
|
248 if (action->action->isCheckable()) |
|
249 if (action->action->isChecked()) |
|
250 CheckMenuItem(menu, action->command, MF_BYCOMMAND | MF_CHECKED); |
|
251 else |
|
252 CheckMenuItem(menu, action->command, MF_BYCOMMAND | MF_UNCHECKED); |
|
253 } |
|
254 } |
|
255 |
|
256 // Removes all items from the menu without destroying the handles. |
|
257 static void qt_wce_clear_menu(HMENU hMenu) |
|
258 { |
|
259 while (RemoveMenu(hMenu, 0, MF_BYPOSITION)); |
|
260 } |
|
261 |
|
262 /*! |
|
263 \internal |
|
264 |
|
265 This function refreshes the native Windows CE menu. |
|
266 */ |
|
267 |
|
268 void QMenuBar::wceRefresh() { |
|
269 for (int i = 0; i < nativeMenuBars.size(); ++i) |
|
270 nativeMenuBars.at(i)->d_func()->wceRefresh(); |
|
271 } |
|
272 |
|
273 void QMenuBarPrivate::wceRefresh() { |
|
274 DrawMenuBar(wce_menubar->menubarHandle); |
|
275 } |
|
276 |
|
277 /*! |
|
278 \internal |
|
279 |
|
280 This function sends native Windows CE commands to Qt menus. |
|
281 */ |
|
282 |
|
283 QAction* QMenu::wceCommands(uint command) { |
|
284 Q_D(QMenu); |
|
285 return d->wceCommands(command); |
|
286 } |
|
287 |
|
288 /*! |
|
289 \internal |
|
290 |
|
291 This function sends native Windows CE commands to Qt menu bars |
|
292 and all their child menus. |
|
293 */ |
|
294 |
|
295 void QMenuBar::wceCommands(uint command, HWND) { |
|
296 for (int i = 0; i < nativeMenuBars.size(); ++i) |
|
297 nativeMenuBars.at(i)->d_func()->wceCommands(command); |
|
298 } |
|
299 |
|
300 bool QMenuBarPrivate::wceEmitSignals(QList<QWceMenuAction*> actions, uint command) { |
|
301 QAction *foundAction = 0; |
|
302 for (int i = 0; i < actions.size(); ++i) { |
|
303 if (foundAction) |
|
304 break; |
|
305 QWceMenuAction *action = actions.at(i); |
|
306 if (action->action->menu()) { |
|
307 foundAction = action->action->menu()->wceCommands(command); |
|
308 } |
|
309 else if (action->command == command) { |
|
310 emit q_func()->triggered(action->action); |
|
311 action->action->activate(QAction::Trigger); |
|
312 return true; |
|
313 } |
|
314 } |
|
315 if (foundAction) { |
|
316 emit q_func()->triggered(foundAction); |
|
317 return true; |
|
318 } |
|
319 return false; |
|
320 } |
|
321 |
|
322 void QMenuBarPrivate::wceCommands(uint command) { |
|
323 if (wceClassicMenu) { |
|
324 for (int i = 0; i < wce_menubar->actionItemsClassic.size(); ++i) |
|
325 wceEmitSignals(wce_menubar->actionItemsClassic.at(i), command); |
|
326 } else { |
|
327 if (wceEmitSignals(wce_menubar->actionItems, command)) { |
|
328 return ; |
|
329 } |
|
330 else if (wce_menubar->leftButtonIsMenu) {//check if command is on the left quick button |
|
331 wceEmitSignals(wce_menubar->actionItemsLeftButton, command); |
|
332 } |
|
333 else if ((wce_menubar->leftButtonAction) && (command == wce_menubar->leftButtonCommand)) { |
|
334 emit q_func()->triggered(wce_menubar->leftButtonAction); |
|
335 wce_menubar->leftButtonAction->activate(QAction::Trigger); |
|
336 } |
|
337 } |
|
338 } |
|
339 |
|
340 QAction *QMenuPrivate::wceCommands(uint command) { |
|
341 QAction *foundAction = 0; |
|
342 for (int i = 0; i < wce_menu->actionItems.size(); ++i) { |
|
343 if (foundAction) |
|
344 break; |
|
345 QWceMenuAction *action = wce_menu->actionItems.at(i); |
|
346 if (action->action->menu()) { |
|
347 foundAction = action->action->menu()->d_func()->wceCommands(command); |
|
348 } |
|
349 else if (action->command == command) { |
|
350 action->action->activate(QAction::Trigger); |
|
351 return action->action; |
|
352 } |
|
353 } |
|
354 if (foundAction) |
|
355 emit q_func()->triggered(foundAction); |
|
356 return foundAction; |
|
357 } |
|
358 |
|
359 void QMenuBarPrivate::wceCreateMenuBar(QWidget *parent) { |
|
360 |
|
361 Q_Q(QMenuBar); |
|
362 wce_menubar = new QWceMenuBarPrivate(this); |
|
363 |
|
364 wce_menubar->parentWindowHandle = parent ? parent->winId() : q->winId(); |
|
365 wce_menubar->leftButtonAction = defaultAction; |
|
366 |
|
367 wce_menubar->menubarHandle = qt_wce_create_menubar(wce_menubar->parentWindowHandle, (HINSTANCE)qWinAppInst(), 0, SHCMBF_EMPTYBAR); |
|
368 Q_ASSERT_X(wce_menubar->menubarHandle, "wceCreateMenuBar", "cannot create empty menu bar"); |
|
369 DrawMenuBar(wce_menubar->menubarHandle); |
|
370 nativeMenuBars.append(q); |
|
371 wceClassicMenu = (!qt_wince_is_smartphone() && !qt_wince_is_pocket_pc()); |
|
372 } |
|
373 |
|
374 void QMenuBarPrivate::wceDestroyMenuBar() { |
|
375 Q_Q(QMenuBar); |
|
376 int index = nativeMenuBars.indexOf(q); |
|
377 nativeMenuBars.removeAt(index); |
|
378 if (wce_menubar) |
|
379 delete wce_menubar; |
|
380 wce_menubar = 0; |
|
381 } |
|
382 |
|
383 QMenuBarPrivate::QWceMenuBarPrivate::QWceMenuBarPrivate(QMenuBarPrivate *menubar) : |
|
384 menubarHandle(0), menuHandle(0),leftButtonMenuHandle(0) , |
|
385 leftButtonAction(0), leftButtonIsMenu(false), d(menubar) { |
|
386 } |
|
387 |
|
388 QMenuBarPrivate::QWceMenuBarPrivate::~QWceMenuBarPrivate() { |
|
389 if (menubarHandle) |
|
390 DestroyWindow(menubarHandle); |
|
391 qt_wce_delete_action_list(&actionItems); |
|
392 qt_wce_delete_action_list(&actionItemsLeftButton); |
|
393 |
|
394 for (int i=0; i<actionItemsClassic.size(); ++i) |
|
395 if (!actionItemsClassic.value(i).empty()) |
|
396 qt_wce_delete_action_list(&actionItemsClassic[i]); |
|
397 actionItemsClassic.clear(); |
|
398 |
|
399 menubarHandle = 0; |
|
400 menuHandle = 0; |
|
401 leftButtonMenuHandle = 0; |
|
402 leftButtonCommand = 0; |
|
403 QMenuBar::wceRefresh(); |
|
404 } |
|
405 |
|
406 QMenuPrivate::QWceMenuPrivate::QWceMenuPrivate() { |
|
407 menuHandle = 0; |
|
408 } |
|
409 |
|
410 QMenuPrivate::QWceMenuPrivate::~QWceMenuPrivate() { |
|
411 qt_wce_delete_action_list(&actionItems); |
|
412 if (menuHandle) |
|
413 DestroyMenu(menuHandle); |
|
414 } |
|
415 |
|
416 void QMenuPrivate::QWceMenuPrivate::addAction(QAction *a, QWceMenuAction *before) { |
|
417 QWceMenuAction *action = new QWceMenuAction; |
|
418 action->action = a; |
|
419 action->command = qt_wce_menu_static_cmd_id++; |
|
420 addAction(action, before); |
|
421 } |
|
422 |
|
423 void QMenuPrivate::QWceMenuPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before) { |
|
424 if (!action) |
|
425 return; |
|
426 int before_index = actionItems.indexOf(before); |
|
427 if (before_index < 0) { |
|
428 before = 0; |
|
429 before_index = actionItems.size(); |
|
430 } |
|
431 actionItems.insert(before_index, action); |
|
432 rebuild(); |
|
433 } |
|
434 |
|
435 /*! |
|
436 \internal |
|
437 |
|
438 This function will return the HMENU used to create the native |
|
439 Windows CE menu bar bindings. |
|
440 */ |
|
441 |
|
442 HMENU QMenu::wceMenu(bool create) { return d_func()->wceMenu(create); } |
|
443 |
|
444 HMENU QMenuPrivate::wceMenu(bool create) { |
|
445 if (!wce_menu) |
|
446 wce_menu = new QWceMenuPrivate; |
|
447 if (!wce_menu->menuHandle || create) |
|
448 wce_menu->rebuild(); |
|
449 return wce_menu->menuHandle; |
|
450 } |
|
451 |
|
452 void QMenuPrivate::QWceMenuPrivate::rebuild() |
|
453 { |
|
454 if (!menuHandle) |
|
455 menuHandle = CreatePopupMenu(); |
|
456 else |
|
457 qt_wce_clear_menu(menuHandle); |
|
458 |
|
459 for (int i = 0; i < actionItems.size(); ++i) { |
|
460 QWceMenuAction *action = actionItems.at(i); |
|
461 action->menuHandle = menuHandle; |
|
462 qt_wce_insert_action(menuHandle, action, true); |
|
463 } |
|
464 QMenuBar::wceRefresh(); |
|
465 } |
|
466 |
|
467 void QMenuPrivate::QWceMenuPrivate::syncAction(QWceMenuAction *) { |
|
468 rebuild(); |
|
469 } |
|
470 |
|
471 void QMenuPrivate::QWceMenuPrivate::removeAction(QWceMenuAction *action) { |
|
472 actionItems.removeAll(action); |
|
473 delete action; |
|
474 action = 0; |
|
475 rebuild(); |
|
476 } |
|
477 |
|
478 void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QAction *a, QWceMenuAction *before) { |
|
479 QWceMenuAction *action = new QWceMenuAction; |
|
480 action->action = a; |
|
481 action->command = qt_wce_menu_static_cmd_id++; |
|
482 addAction(action, before); |
|
483 } |
|
484 |
|
485 void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before) { |
|
486 if (!action) |
|
487 return; |
|
488 int before_index = actionItems.indexOf(before); |
|
489 if (before_index < 0) { |
|
490 before = 0; |
|
491 before_index = actionItems.size(); |
|
492 } |
|
493 actionItems.insert(before_index, action); |
|
494 rebuild(); |
|
495 } |
|
496 |
|
497 void QMenuBarPrivate::QWceMenuBarPrivate::syncAction(QWceMenuAction*) { |
|
498 QMenuBar::wceRefresh(); |
|
499 rebuild(); |
|
500 } |
|
501 |
|
502 void QMenuBarPrivate::QWceMenuBarPrivate::removeAction(QWceMenuAction *action) { |
|
503 actionItems.removeAll(action); |
|
504 delete action; |
|
505 action = 0; |
|
506 rebuild(); |
|
507 } |
|
508 |
|
509 void QMenuBarPrivate::_q_updateDefaultAction() { |
|
510 if (wce_menubar) |
|
511 wce_menubar->rebuild(); |
|
512 } |
|
513 |
|
514 void QMenuBarPrivate::QWceMenuBarPrivate::rebuild() { |
|
515 |
|
516 d->q_func()->resize(0,0); |
|
517 parentWindowHandle = d->q_func()->parentWidget() ? d->q_func()->parentWidget()->winId() : d->q_func()->winId(); |
|
518 if (d->wceClassicMenu) { |
|
519 QList<QAction*> actions = d->actions; |
|
520 int maxEntries; |
|
521 int resourceHandle; |
|
522 if (actions.size() < 5) { |
|
523 maxEntries = 4; |
|
524 resourceHandle = IDR_MAIN_MENU3; |
|
525 } else if (actions.size() < 7) { |
|
526 maxEntries = 6; |
|
527 resourceHandle = IDR_MAIN_MENU4; |
|
528 } |
|
529 else { |
|
530 maxEntries = 8; |
|
531 resourceHandle = IDR_MAIN_MENU5; |
|
532 } |
|
533 Q_ASSERT_X(menubarHandle, "rebuild !created", "menubar already deleted"); |
|
534 qt_wce_clear_menu(menuHandle); |
|
535 DestroyWindow(menubarHandle); |
|
536 menubarHandle = qt_wce_create_menubar(parentWindowHandle, qt_wce_get_module_handle(), resourceHandle); |
|
537 Q_ASSERT_X(menubarHandle, "rebuild classic menu", "cannot create menubar from resource"); |
|
538 DrawMenuBar(menubarHandle); |
|
539 QList<int> menu_ids; |
|
540 QList<int> item_ids; |
|
541 menu_ids << IDM_MENU1 << IDM_MENU2 << IDM_MENU3 << IDM_MENU4 << IDM_MENU5 << IDM_MENU6 << IDM_MENU7 << IDM_MENU8; |
|
542 item_ids << IDM_ITEM1 << IDM_ITEM2 << IDM_ITEM3 << IDM_ITEM4 << IDM_ITEM5 << IDM_ITEM6 << IDM_ITEM7 << IDM_ITEM8; |
|
543 |
|
544 for (int i = 0; i < actionItemsClassic.size(); ++i) |
|
545 if (!actionItemsClassic.value(i).empty()) |
|
546 qt_wce_delete_action_list(&actionItemsClassic[i]); |
|
547 actionItemsClassic.clear(); |
|
548 |
|
549 for (int i = 0; i < actions.size(); ++i) { |
|
550 qt_wce_rename_menu_item(menubarHandle, menu_ids.at(i), actions.at(i)->text()); |
|
551 QList<QAction *> subActions = actions.at(i)->menu()->actions(); |
|
552 HMENU subMenuHandle = (HMENU) SendMessage(menubarHandle, SHCMBM_GETSUBMENU,0 , menu_ids.at(i)); |
|
553 DeleteMenu(subMenuHandle, item_ids.at(i), MF_BYCOMMAND); |
|
554 for (int c = 0; c < subActions.size(); ++c) { |
|
555 QList<QWceMenuAction*> list; |
|
556 actionItemsClassic.append(list); |
|
557 QWceMenuAction *action = new QWceMenuAction; |
|
558 action->action = subActions.at(c); |
|
559 action->command = qt_wce_menu_static_cmd_id++; |
|
560 action->menuHandle = subMenuHandle; |
|
561 actionItemsClassic.last().append(action); |
|
562 qt_wce_insert_action(subMenuHandle, action, true); |
|
563 } |
|
564 } |
|
565 for (int i = actions.size();i<maxEntries;++i) { |
|
566 qt_wce_rename_menu_item(menubarHandle, menu_ids.at(i), QString()); |
|
567 qt_wce_disable_soft_key(menubarHandle, menu_ids.at(i)); |
|
568 } |
|
569 } else { |
|
570 leftButtonAction = d->defaultAction; |
|
571 if (!leftButtonAction) |
|
572 leftButtonAction = qt_wce_get_quit_action(actionItems); |
|
573 |
|
574 leftButtonIsMenu = (leftButtonAction && leftButtonAction->menu()); |
|
575 Q_ASSERT_X(menubarHandle, "rebuild !created", "menubar already deleted"); |
|
576 qt_wce_clear_menu(menuHandle); |
|
577 DestroyWindow(menubarHandle); |
|
578 if (leftButtonIsMenu) { |
|
579 menubarHandle = qt_wce_create_menubar(parentWindowHandle, qt_wce_get_module_handle(), IDR_MAIN_MENU2); |
|
580 Q_ASSERT_X(menubarHandle, "rebuild !created left menubar", "cannot create menubar from resource"); |
|
581 menuHandle = (HMENU) SendMessage(menubarHandle, SHCMBM_GETSUBMENU,0,IDM_MENU); |
|
582 Q_ASSERT_X(menuHandle, "rebuild !created", "IDM_MENU not found - invalid resource?"); |
|
583 DeleteMenu(menuHandle, IDM_ABOUT, MF_BYCOMMAND); |
|
584 leftButtonMenuHandle = (HMENU) SendMessage(menubarHandle, SHCMBM_GETSUBMENU,0,IDM_LEFTMENU); |
|
585 Q_ASSERT_X(leftButtonMenuHandle, "rebuild !created", "IDM_LEFTMENU not found - invalid resource?"); |
|
586 DeleteMenu(leftButtonMenuHandle, IDM_VIEW, MF_BYCOMMAND); |
|
587 } else { |
|
588 menubarHandle = qt_wce_create_menubar(parentWindowHandle, qt_wce_get_module_handle(), IDR_MAIN_MENU); |
|
589 Q_ASSERT_X(menubarHandle, "rebuild !created no left menubar", "cannot create menubar from resource"); |
|
590 menuHandle = (HMENU) SendMessage(menubarHandle, SHCMBM_GETSUBMENU,0,IDM_MENU); |
|
591 Q_ASSERT_X(menuHandle, "rebuild !created", "IDM_MENU not found - invalid resource?"); |
|
592 DeleteMenu(menuHandle, IDM_ABOUT, MF_BYCOMMAND); |
|
593 leftButtonMenuHandle = 0; |
|
594 leftButtonCommand = qt_wce_menu_static_cmd_id++; |
|
595 qt_wce_change_command(menubarHandle, IDM_EXIT, leftButtonCommand); |
|
596 } |
|
597 |
|
598 if (actionItems.size() == 0) { |
|
599 qt_wce_rename_menu_item(menubarHandle, IDM_MENU, QLatin1String("")); |
|
600 qt_wce_disable_soft_key(menubarHandle, IDM_MENU); |
|
601 } |
|
602 for (int i = 0; i < actionItems.size(); ++i) { |
|
603 QWceMenuAction *action = actionItems.at(i); |
|
604 action->menuHandle = menuHandle; |
|
605 qt_wce_insert_action(menuHandle, action, true); |
|
606 } |
|
607 if (!leftButtonIsMenu) { |
|
608 if (leftButtonAction) { |
|
609 qt_wce_rename_menu_item(menubarHandle, leftButtonCommand, leftButtonAction->text()); |
|
610 qt_wce_enable_soft_key(menubarHandle, leftButtonCommand); |
|
611 } else { |
|
612 qt_wce_rename_menu_item(menubarHandle, leftButtonCommand, QLatin1String("")); |
|
613 qt_wce_disable_soft_key(menubarHandle, leftButtonCommand); |
|
614 } |
|
615 } else { |
|
616 qt_wce_rename_menu_item(menubarHandle, IDM_LEFTMENU, leftButtonAction->text()); |
|
617 QList<QAction *> actions = leftButtonAction->menu()->actions(); |
|
618 qt_wce_delete_action_list(&actionItemsLeftButton); |
|
619 for (int i=0; i<actions.size(); ++i) { |
|
620 QWceMenuAction *action = new QWceMenuAction; |
|
621 action->action = actions.at(i); |
|
622 action->command = qt_wce_menu_static_cmd_id++; |
|
623 action->menuHandle = leftButtonMenuHandle; |
|
624 actionItemsLeftButton.append(action); |
|
625 qt_wce_insert_action(leftButtonMenuHandle, action, true); |
|
626 } |
|
627 } |
|
628 } |
|
629 DrawMenuBar(menubarHandle); |
|
630 } |
|
631 |
|
632 QT_END_NAMESPACE |
|
633 |
|
634 #endif //QT_NO_MENUBAR |
|
635 #endif //Q_WS_WINCE |