summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets/qmenu_wince.cpp
blob: b0c6c1bd126a86806fc844a490a8517d6bf79a35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

//Native menubars are only supported for Windows Mobile not the standard SDK/generic WinCE
#ifdef Q_WS_WINCE
#include "qmenu.h"
#include "qt_windows.h"
#include "qapplication.h"
#include "qmainwindow.h"
#include "qtoolbar.h"
#include "qevent.h"
#include "qstyle.h"
#include "qdebug.h"
#include "qwidgetaction.h"
#include <private/qapplication_p.h>
#include <private/qmenu_p.h>
#include <private/qmenubar_p.h>

#include "qmenu_wince_resource_p.h"

#include <QtCore/qlibrary.h>
#include <commctrl.h>
#if Q_OS_WINCE_WM
#   include <windowsm.h>
#endif

#include "qguifunctions_wince.h"

#ifndef QT_NO_MENUBAR

#ifndef SHCMBF_EMPTYBAR
#define SHCMBF_EMPTYBAR 0x0001
#endif

#ifndef SHCMBM_GETSUBMENU
#define SHCMBM_GETSUBMENU (WM_USER + 401)
#endif

#ifdef Q_OS_WINCE_WM
#   define SHMBOF_NODEFAULT 0x00000001
#   define SHMBOF_NOTIFY    0x00000002
#   define SHCMBM_OVERRIDEKEY (WM_USER + 0x193)
#endif

extern bool qt_wince_is_smartphone();//defined in qguifunctions_wce.cpp
extern bool qt_wince_is_pocket_pc(); //defined in qguifunctions_wce.cpp

QT_BEGIN_NAMESPACE

static uint qt_wce_menu_static_cmd_id = 200;
static QList<QMenuBar*> nativeMenuBars;

struct qt_SHMENUBARINFO
{
    DWORD     cbSize;
    HWND      hwndParent;
    DWORD     dwFlags;
    UINT      nToolBarId;
    HINSTANCE hInstRes;
    int       nBmpId;
    int       cBmpImages;
    HWND      hwndMB;
    COLORREF  clrBk;
};

typedef BOOL (WINAPI *AygCreateMenuBar)(qt_SHMENUBARINFO*);
typedef HRESULT (WINAPI *AygEnableSoftKey)(HWND,UINT,BOOL,BOOL);

static bool aygResolved = false;
static AygCreateMenuBar ptrCreateMenuBar = 0;
static AygEnableSoftKey ptrEnableSoftKey = 0;

static void resolveAygLibs()
{
    if (!aygResolved) {
        aygResolved = true;
        QLibrary aygLib(QLatin1String("aygshell"));
        ptrCreateMenuBar = (AygCreateMenuBar) aygLib.resolve("SHCreateMenuBar");
        ptrEnableSoftKey = (AygEnableSoftKey) aygLib.resolve("SHEnableSoftkey");
    }
}

static void qt_wce_enable_soft_key(HWND handle, uint command) 
{
    resolveAygLibs();
    if (ptrEnableSoftKey)
        ptrEnableSoftKey(handle, command, false, true);
}

static void qt_wce_disable_soft_key(HWND handle, uint command) 
{
    resolveAygLibs();
    if (ptrEnableSoftKey)
        ptrEnableSoftKey(handle, command, false, false);
}

static void qt_wce_delete_action_list(QList<QWceMenuAction*> *list)
{
    for(QList<QWceMenuAction*>::Iterator it = list->begin(); it != list->end(); ++it) {
        QWceMenuAction *action = (*it);
        delete action;
        action = 0;
    }
    list->clear();
}

//search for first QuitRole in QMenuBar
static QAction* qt_wce_get_quit_action(QList<QAction *> actionItems)
{
    QAction *returnAction = 0;
    for (int i = 0; i < actionItems.size(); ++i) {
        QAction *action = actionItems.at(i);
        if (action->menuRole() == QAction::QuitRole)
            returnAction = action;
        else 
            if (action->menu())
                returnAction = qt_wce_get_quit_action(action->menu()->actions());
        if (returnAction)
            return returnAction; //return first action found
    }
    return 0; //nothing found;
}

static QAction* qt_wce_get_quit_action(QList<QWceMenuAction*> actionItems)
{
    for (int i = 0; i < actionItems.size(); ++i) {
        if (actionItems.at(i)->action->menuRole() == QAction::QuitRole)
            return actionItems.at(i)->action;
        else if (actionItems.at(i)->action->menu()) {
            QAction *returnAction = qt_wce_get_quit_action(actionItems.at(i)->action->menu()->actions());
            if (returnAction)
                return returnAction;
        }
    }
    return 0;
}

static HMODULE qt_wce_get_module_handle()
{
    HMODULE module =  0; //handle to resources
    if (!(module = GetModuleHandle(L"QtGui4"))) //release dynamic
        if (!(module = GetModuleHandle(L"QtGuid4"))) //debug dynamic
            module = (HINSTANCE)qWinAppInst(); //static
    Q_ASSERT_X(module, "qt_wce_get_module_handle()", "cannot get handle to module?");
    return module;
}

static void qt_wce_change_command(HWND menuHandle, int item, int command)
{
TBBUTTONINFOA tbbi;
    memset(&tbbi,0,sizeof(tbbi));
    tbbi.cbSize = sizeof(tbbi);
    tbbi.dwMask = TBIF_COMMAND;
    tbbi.idCommand = command;
    SendMessage(menuHandle, TB_SETBUTTONINFO, item, (LPARAM)&tbbi);
}

static void qt_wce_rename_menu_item(HWND menuHandle, int item, const QString &newText)
{
    TBBUTTONINFOA tbbi;
    memset(&tbbi,0,sizeof(tbbi));
    tbbi.cbSize = sizeof(tbbi);
    tbbi.dwMask = TBIF_TEXT;
    QString text = newText;
    text.remove(QChar::fromLatin1('&'));
    tbbi.pszText = (LPSTR) text.utf16();
    SendMessage(menuHandle, TB_SETBUTTONINFO, item, (LPARAM)&tbbi);
}

static HWND qt_wce_create_menubar(HWND parentHandle, HINSTANCE resourceHandle, int toolbarID, int flags = 0)
{
    resolveAygLibs();

    if (ptrCreateMenuBar) {
        qt_SHMENUBARINFO mbi;
        memset(&mbi, 0, sizeof(qt_SHMENUBARINFO));
        mbi.cbSize     = sizeof(qt_SHMENUBARINFO);
        mbi.hwndParent = parentHandle;
        mbi.hInstRes   = resourceHandle;
        mbi.dwFlags = flags;
        mbi.nToolBarId = toolbarID;

        if (ptrCreateMenuBar(&mbi)) {
#ifdef Q_OS_WINCE_WM
            // Tell the menu bar that we want to override hot key behaviour.
            LPARAM lparam = MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
                                       SHMBOF_NODEFAULT | SHMBOF_NOTIFY);
            SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK, lparam);
#endif
            return mbi.hwndMB;
        }
    }
    return 0;
}

static void qt_wce_insert_action(HMENU menu, QWceMenuAction *action)
{
    Q_ASSERT_X(menu, "AppendMenu", "menu is 0");
    if (action->action->isVisible()) {
        int flags;
        action->action->isEnabled() ? flags = MF_ENABLED : flags = MF_GRAYED;

        QString text = action->action->iconText();
        text.remove(QChar::fromLatin1('&'));
        if (action->action->isSeparator()) {
            AppendMenu (menu, MF_SEPARATOR , 0, 0);
        }
        else if (action->action->menu()) {
            text.remove(QChar::fromLatin1('&'));
            AppendMenu (menu, MF_STRING | flags | MF_POPUP,
            (UINT) action->action->menu()->wceMenu(), reinterpret_cast<const wchar_t *> (text.utf16()));
        }
        else {
            AppendMenu (menu, MF_STRING | flags, action->command, reinterpret_cast<const wchar_t *> (text.utf16()));
        }
        if (action->action->isCheckable())
            if (action->action->isChecked())
                CheckMenuItem(menu, action->command, MF_BYCOMMAND | MF_CHECKED);
            else 
                CheckMenuItem(menu, action->command, MF_BYCOMMAND | MF_UNCHECKED);
    }
}

// Removes all items from the menu without destroying the handles.
static void qt_wce_clear_menu(HMENU hMenu)
{
    while (RemoveMenu(hMenu, 0, MF_BYPOSITION));
}

/*!
    \internal 
    
    This function refreshes the native Windows CE menu.
*/

void QMenuBar::wceRefresh()
{
    for (int i = 0; i < nativeMenuBars.size(); ++i)
        nativeMenuBars.at(i)->d_func()->wceRefresh();
}

void QMenuBarPrivate::wceRefresh()
{
    DrawMenuBar(wce_menubar->menubarHandle);
}

/*!
    \internal 
    
    This function sends native Windows CE commands to Qt menus.
*/

QAction* QMenu::wceCommands(uint command)
{
    Q_D(QMenu);
    return d->wceCommands(command);
}

/*!
    \internal 
    
    This function sends native Windows CE commands to Qt menu bars
    and all their child menus.
*/

void QMenuBar::wceCommands(uint command)
{
    const HWND hwndActiveWindow = GetActiveWindow();
    for (int i = 0; i < nativeMenuBars.size(); ++i) {
        QMenuBarPrivate* nativeMenuBar = nativeMenuBars.at(i)->d_func();
        if (hwndActiveWindow == nativeMenuBar->wce_menubar->parentWindowHandle)
            nativeMenuBar->wceCommands(command);
    }
}

bool QMenuBarPrivate::wceEmitSignals(QList<QWceMenuAction*> actions, uint command)
{
    QAction *foundAction = 0;
    for (int i = 0; i < actions.size(); ++i) {
        QWceMenuAction *action = actions.at(i);
        if (action->action->menu()) {
            foundAction = action->action->menu()->wceCommands(command);
            if (foundAction)
                break;
        }
        else if (action->command == command) {
            action->action->activate(QAction::Trigger);
            return true;
        }
    }
    if (foundAction) {
        emit q_func()->triggered(foundAction);
        return true;
    }
    return false;
}

void QMenuBarPrivate::wceCommands(uint command)
{
    if (wceClassicMenu) {
        for (int i = 0; i < wce_menubar->actionItemsClassic.size(); ++i)
            wceEmitSignals(wce_menubar->actionItemsClassic.at(i), command);
    } else {
        if (wceEmitSignals(wce_menubar->actionItems, command)) {
            return;
        }
        else if (wce_menubar->leftButtonIsMenu) {//check if command is on the left quick button
            wceEmitSignals(wce_menubar->actionItemsLeftButton, command);
        }
        else if ((wce_menubar->leftButtonAction) && (command == wce_menubar->leftButtonCommand)) {
            emit q_func()->triggered(wce_menubar->leftButtonAction);
            wce_menubar->leftButtonAction->activate(QAction::Trigger);
        }
    }
}

QAction *QMenuPrivate::wceCommands(uint command)
{
    QAction *foundAction = 0;
    for (int i  = 0; i < wce_menu->actionItems.size(); ++i) {
        if (foundAction)
            break;
        QWceMenuAction *action = wce_menu->actionItems.at(i);
        if (action->action->menu()) {
            foundAction = action->action->menu()->d_func()->wceCommands(command);
        }
        else if (action->command == command) {
            activateAction(action->action, QAction::Trigger);
            return action->action;
        }
    }
    if (foundAction)
        emit q_func()->triggered(foundAction);
    return foundAction;
}

void QMenuBarPrivate::wceCreateMenuBar(QWidget *parent)
{
    Q_Q(QMenuBar);
    wce_menubar = new QWceMenuBarPrivate(this);

    wce_menubar->parentWindowHandle = parent ? parent->winId() : q->winId();
    wce_menubar->leftButtonAction = defaultAction;

    wce_menubar->menubarHandle = qt_wce_create_menubar(wce_menubar->parentWindowHandle, (HINSTANCE)qWinAppInst(), 0, SHCMBF_EMPTYBAR);
    Q_ASSERT_X(wce_menubar->menubarHandle, "wceCreateMenuBar", "cannot create empty menu bar");
    DrawMenuBar(wce_menubar->menubarHandle);
    nativeMenuBars.append(q);
    wceClassicMenu = (!qt_wince_is_smartphone() && !qt_wince_is_pocket_pc());
}

void QMenuBarPrivate::wceDestroyMenuBar()
{
    Q_Q(QMenuBar);
    int index = nativeMenuBars.indexOf(q);
    nativeMenuBars.removeAt(index);
    if (wce_menubar) {
        delete wce_menubar;
        wce_menubar = 0;
    }
}

QMenuBarPrivate::QWceMenuBarPrivate::QWceMenuBarPrivate(QMenuBarPrivate *menubar)
:   menubarHandle(0), menuHandle(0), leftButtonMenuHandle(0),
    leftButtonAction(0), leftButtonIsMenu(false), d(menubar)
{
}

QMenuBarPrivate::QWceMenuBarPrivate::~QWceMenuBarPrivate()
{
    if (menubarHandle)
        DestroyWindow(menubarHandle);
    qt_wce_delete_action_list(&actionItems);
    qt_wce_delete_action_list(&actionItemsLeftButton);

    for (int i=0; i<actionItemsClassic.size(); ++i)
        if (!actionItemsClassic.value(i).empty())
            qt_wce_delete_action_list(&actionItemsClassic[i]);
    actionItemsClassic.clear();

    menubarHandle = 0;
    menuHandle = 0;
    leftButtonMenuHandle = 0;
    leftButtonCommand = 0;
    QMenuBar::wceRefresh();
}

QMenuPrivate::QWceMenuPrivate::QWceMenuPrivate()
:   menuHandle(0)
{
}

QMenuPrivate::QWceMenuPrivate::~QWceMenuPrivate()
{
    qt_wce_delete_action_list(&actionItems);
    if (menuHandle)
        DestroyMenu(menuHandle);
}

void QMenuPrivate::QWceMenuPrivate::addAction(QAction *a, QWceMenuAction *before)
{
    QWceMenuAction *action = new QWceMenuAction;
    action->action = a;
    action->command = qt_wce_menu_static_cmd_id++;
    addAction(action, before);
}

void QMenuPrivate::QWceMenuPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before)
{
    if (!action)
        return;
    int before_index = actionItems.indexOf(before);
    if (before_index < 0) {
        before = 0;
        before_index = actionItems.size();
    }
    actionItems.insert(before_index, action);
    rebuild();
}

/*!
    \internal
    
    This function will return the HMENU used to create the native
    Windows CE menu bar bindings.
*/

HMENU QMenu::wceMenu()
{
    return d_func()->wceMenu();
}

HMENU QMenuPrivate::wceMenu()
{
    if (!wce_menu)
        wce_menu = new QWceMenuPrivate;
    if (!wce_menu->menuHandle)
        wce_menu->rebuild();
    return wce_menu->menuHandle;
}

void QMenuPrivate::QWceMenuPrivate::rebuild()
{
    if (!menuHandle)
        menuHandle = CreatePopupMenu();
    else
        qt_wce_clear_menu(menuHandle);

    for (int i = 0; i < actionItems.size(); ++i) {
        QWceMenuAction *action = actionItems.at(i);
        action->menuHandle = menuHandle;
        qt_wce_insert_action(menuHandle, action);
    }
    QMenuBar::wceRefresh();
}

void QMenuPrivate::QWceMenuPrivate::syncAction(QWceMenuAction *)
{
    rebuild();
}

void QMenuPrivate::QWceMenuPrivate::removeAction(QWceMenuAction *action)
{
    actionItems.removeAll(action);
    delete action;
    rebuild();
}

void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QAction *a, QAction *before)
{
    QWceMenuAction *action = new QWceMenuAction;
    action->action = a;
    action->command = qt_wce_menu_static_cmd_id++;
    addAction(action, findAction(before));
}

void QMenuBarPrivate::QWceMenuBarPrivate::addAction(QWceMenuAction *action, QWceMenuAction *before)
{
    if (!action)
        return;
    int before_index = actionItems.indexOf(before);
    if (before_index < 0) {
        before = 0;
        before_index = actionItems.size();
    }
    actionItems.insert(before_index, action);
    rebuild();
}

void QMenuBarPrivate::QWceMenuBarPrivate::syncAction(QWceMenuAction*)
{
    QMenuBar::wceRefresh();
    rebuild();
}

void QMenuBarPrivate::QWceMenuBarPrivate::removeAction(QWceMenuAction *action)
{
    actionItems.removeAll(action);
    delete action;
    rebuild();
}

void QMenuBarPrivate::_q_updateDefaultAction()
{
    if (wce_menubar)
        wce_menubar->rebuild();
}

void QMenuBarPrivate::QWceMenuBarPrivate::rebuild()
{
    d->q_func()->resize(0,0);
    parentWindowHandle = d->q_func()->parentWidget() ? d->q_func()->parentWidget()->winId() : d->q_func()->winId();
    if (d->wceClassicMenu) {
        QList<QAction*> actions = d->actions;
        int maxEntries;
        int resourceHandle;
        if (actions.size() < 5) {
            maxEntries = 4;
            resourceHandle = IDR_MAIN_MENU3;
        } else if (actions.size() < 7) {
            maxEntries = 6;
            resourceHandle = IDR_MAIN_MENU4;
        }
        else {
          maxEntries = 8;
          resourceHandle = IDR_MAIN_MENU5;
        }
        Q_ASSERT_X(menubarHandle, "rebuild !created", "menubar already deleted");
        qt_wce_clear_menu(menuHandle);
        DestroyWindow(menubarHandle);
        menubarHandle = qt_wce_create_menubar(parentWindowHandle, qt_wce_get_module_handle(), resourceHandle);
        Q_ASSERT_X(menubarHandle, "rebuild classic menu", "cannot create menubar from resource");
        DrawMenuBar(menubarHandle);
        QList<int> menu_ids;
        QList<int> item_ids;
        menu_ids << IDM_MENU1 << IDM_MENU2 << IDM_MENU3 << IDM_MENU4 << IDM_MENU5 << IDM_MENU6 << IDM_MENU7 << IDM_MENU8;
        item_ids << IDM_ITEM1 << IDM_ITEM2 << IDM_ITEM3 << IDM_ITEM4 << IDM_ITEM5 << IDM_ITEM6 << IDM_ITEM7 << IDM_ITEM8;

        for (int i = 0; i < actionItemsClassic.size(); ++i)
          if (!actionItemsClassic.value(i).empty())
            qt_wce_delete_action_list(&actionItemsClassic[i]);
        actionItemsClassic.clear();

        for (int i = 0; i < actions.size(); ++i) {
            qt_wce_rename_menu_item(menubarHandle, menu_ids.at(i), actions.at(i)->text());
            QList<QAction *> subActions = actions.at(i)->menu()->actions();
            HMENU subMenuHandle = (HMENU) SendMessage(menubarHandle, SHCMBM_GETSUBMENU,0 , menu_ids.at(i));
            DeleteMenu(subMenuHandle, item_ids.at(i), MF_BYCOMMAND);
            for (int c = 0; c < subActions.size(); ++c) {
                QList<QWceMenuAction*> list;
                actionItemsClassic.append(list);
                QWceMenuAction *action = new QWceMenuAction;
                action->action = subActions.at(c);
                action->command = qt_wce_menu_static_cmd_id++;
                action->menuHandle = subMenuHandle;
                actionItemsClassic.last().append(action);
                qt_wce_insert_action(subMenuHandle, action);
            }
        }
        for (int i = actions.size();i<maxEntries;++i) {
            qt_wce_rename_menu_item(menubarHandle, menu_ids.at(i), QString());
            qt_wce_disable_soft_key(menubarHandle, menu_ids.at(i));
        }
    } else {
        leftButtonAction = d->defaultAction;
        if (!leftButtonAction)
            leftButtonAction = qt_wce_get_quit_action(actionItems);

        leftButtonIsMenu = (leftButtonAction && leftButtonAction->menu());
        Q_ASSERT_X(menubarHandle, "rebuild !created", "menubar already deleted");
        qt_wce_clear_menu(menuHandle);
        DestroyWindow(menubarHandle);
        if (leftButtonIsMenu) {
            menubarHandle = qt_wce_create_menubar(parentWindowHandle, qt_wce_get_module_handle(), IDR_MAIN_MENU2);
            Q_ASSERT_X(menubarHandle, "rebuild !created left menubar", "cannot create menubar from resource");
            menuHandle = (HMENU) SendMessage(menubarHandle, SHCMBM_GETSUBMENU,0,IDM_MENU);
            Q_ASSERT_X(menuHandle, "rebuild !created", "IDM_MENU not found - invalid resource?");
            DeleteMenu(menuHandle, IDM_ABOUT, MF_BYCOMMAND);
            leftButtonMenuHandle = (HMENU) SendMessage(menubarHandle, SHCMBM_GETSUBMENU,0,IDM_LEFTMENU);
            Q_ASSERT_X(leftButtonMenuHandle, "rebuild !created", "IDM_LEFTMENU not found - invalid resource?");
            DeleteMenu(leftButtonMenuHandle, IDM_VIEW, MF_BYCOMMAND);
        } else {
            menubarHandle = qt_wce_create_menubar(parentWindowHandle, qt_wce_get_module_handle(), IDR_MAIN_MENU);
            Q_ASSERT_X(menubarHandle, "rebuild !created no left menubar", "cannot create menubar from resource");
            menuHandle = (HMENU) SendMessage(menubarHandle, SHCMBM_GETSUBMENU,0,IDM_MENU);
            Q_ASSERT_X(menuHandle, "rebuild !created", "IDM_MENU not found - invalid resource?");
            DeleteMenu(menuHandle, IDM_ABOUT, MF_BYCOMMAND);
            leftButtonMenuHandle = 0;
            leftButtonCommand = qt_wce_menu_static_cmd_id++;
            qt_wce_change_command(menubarHandle, IDM_EXIT, leftButtonCommand);
        }

        if (actionItems.size() == 0) {
            qt_wce_rename_menu_item(menubarHandle, IDM_MENU, QLatin1String(""));
            qt_wce_disable_soft_key(menubarHandle, IDM_MENU);
        }
        for (int i = 0; i < actionItems.size(); ++i) {
            QWceMenuAction *action = actionItems.at(i);
            action->menuHandle = menuHandle;
            qt_wce_insert_action(menuHandle, action);
        }
        if (!leftButtonIsMenu) {
            if (leftButtonAction) {
                qt_wce_rename_menu_item(menubarHandle, leftButtonCommand, leftButtonAction->text());
                qt_wce_enable_soft_key(menubarHandle, leftButtonCommand);
            } else {
                qt_wce_rename_menu_item(menubarHandle, leftButtonCommand, QLatin1String(""));           
                qt_wce_disable_soft_key(menubarHandle, leftButtonCommand);
            }
        } else {
            qt_wce_rename_menu_item(menubarHandle, IDM_LEFTMENU, leftButtonAction->text());
            QList<QAction *> actions = leftButtonAction->menu()->actions();
            qt_wce_delete_action_list(&actionItemsLeftButton);
            for (int i=0; i<actions.size(); ++i) {
                QWceMenuAction *action = new QWceMenuAction;
                action->action = actions.at(i);
                action->command = qt_wce_menu_static_cmd_id++;
                action->menuHandle = leftButtonMenuHandle;
                actionItemsLeftButton.append(action);
                qt_wce_insert_action(leftButtonMenuHandle, action);
            }
        }
    }
    DrawMenuBar(menubarHandle);
}

QT_END_NAMESPACE

#endif //QT_NO_MENUBAR
#endif //Q_WS_WINCE