summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@nokia.com>2010-03-10 09:21:53 (GMT)
committerJoerg Bornemann <joerg.bornemann@nokia.com>2010-03-10 09:46:24 (GMT)
commit5342a81075f3efa17fd4c495411b2c2bd2a369d1 (patch)
tree362b4fbaeca631d67d34e9ebf96c9f9deb86e79a /src
parent389930090c938d3aeaae7f23bf6a07aeeaed9edf (diff)
downloadQt-5342a81075f3efa17fd4c495411b2c2bd2a369d1.zip
Qt-5342a81075f3efa17fd4c495411b2c2bd2a369d1.tar.gz
Qt-5342a81075f3efa17fd4c495411b2c2bd2a369d1.tar.bz2
fix menu handling on Windows CE
Don't recreate the menu handles on every rebuild. Now, we clear the menu before rebuilding. Also, we have to clear the menu before destroying the menu bar handle. Otherwise, DestroyWindow kills our menu handles. Task-number: QTBUG-8754 Reviewed-by: thartman
Diffstat (limited to 'src')
-rw-r--r--src/gui/widgets/qmenu_p.h2
-rw-r--r--src/gui/widgets/qmenu_wince.cpp24
2 files changed, 19 insertions, 7 deletions
diff --git a/src/gui/widgets/qmenu_p.h b/src/gui/widgets/qmenu_p.h
index aaed6b1..495872c 100644
--- a/src/gui/widgets/qmenu_p.h
+++ b/src/gui/widgets/qmenu_p.h
@@ -347,7 +347,7 @@ public:
void syncAction(QWceMenuAction *);
inline void syncAction(QAction *a) { syncAction(findAction(a)); }
void removeAction(QWceMenuAction *);
- void rebuild(bool reCreate = false);
+ void rebuild();
inline void removeAction(QAction *a) { removeAction(findAction(a)); }
inline QWceMenuAction *findAction(QAction *a) {
for(int i = 0; i < actionItems.size(); i++) {
diff --git a/src/gui/widgets/qmenu_wince.cpp b/src/gui/widgets/qmenu_wince.cpp
index edef466..1577f0a 100644
--- a/src/gui/widgets/qmenu_wince.cpp
+++ b/src/gui/widgets/qmenu_wince.cpp
@@ -253,6 +253,12 @@ static void qt_wce_insert_action(HMENU menu, QWceMenuAction *action, bool create
}
}
+// 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
@@ -403,7 +409,8 @@ QMenuPrivate::QWceMenuPrivate::QWceMenuPrivate() {
QMenuPrivate::QWceMenuPrivate::~QWceMenuPrivate() {
qt_wce_delete_action_list(&actionItems);
- menuHandle = 0;
+ if (menuHandle)
+ DestroyMenu(menuHandle);
}
void QMenuPrivate::QWceMenuPrivate::addAction(QAction *a, QWceMenuAction *before) {
@@ -438,14 +445,17 @@ HMENU QMenuPrivate::wceMenu(bool create) {
if (!wce_menu)
wce_menu = new QWceMenuPrivate;
if (!wce_menu->menuHandle || create)
- wce_menu->rebuild(create);
+ wce_menu->rebuild();
return wce_menu->menuHandle;
}
-void QMenuPrivate::QWceMenuPrivate::rebuild(bool reCreate) {
- if (menuHandle && !reCreate)
- DestroyMenu(menuHandle);
- menuHandle = CreatePopupMenu();
+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;
@@ -521,6 +531,7 @@ void QMenuBarPrivate::QWceMenuBarPrivate::rebuild() {
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");
@@ -562,6 +573,7 @@ void QMenuBarPrivate::QWceMenuBarPrivate::rebuild() {
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);