From 12348ea833bf731a0a977cd201d6804c6f3af221 Mon Sep 17 00:00:00 2001
From: Joerg Bornemann <joerg.bornemann@trolltech.com>
Date: Thu, 7 May 2009 14:54:05 +0200
Subject: handle the back soft key on Windows mobile SmartPhones

We must tell the system that we want to intercept the back key on
Windows mobile. Each toplevel widget that needs correct back key
behaviour needs to have a menu bar. Why? Ask Microsoft...

Task-number: 248846
Reviewed-by: thartman
---
 src/gui/kernel/qapplication_win.cpp | 15 +++++++++++++++
 src/gui/widgets/qmenu_wince.cpp     | 16 +++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp
index 065e7ff..f14ad6f 100644
--- a/src/gui/kernel/qapplication_win.cpp
+++ b/src/gui/kernel/qapplication_win.cpp
@@ -1725,6 +1725,21 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam
             // fall-through intended
         case WM_KEYUP:
         case WM_SYSKEYUP:
+#if Q_OS_WINCE_WM
+        case WM_HOTKEY:
+            if(HIWORD(msg.lParam) == VK_TBACK) {
+                const bool hotKeyDown = !(LOWORD(msg.lParam) & MOD_KEYUP);
+                msg.lParam = 0x69 << 16;
+                msg.wParam = VK_BACK;
+                if (hotKeyDown) {
+                    msg.message = WM_KEYDOWN;
+                    qt_keymapper_private()->updateKeyMap(msg);
+                } else {
+                    msg.message = WM_KEYUP;
+                }
+            }
+            // fall-through intended
+#endif
         case WM_IME_CHAR:
         case WM_IME_KEYDOWN:
         case WM_CHAR: {
diff --git a/src/gui/widgets/qmenu_wince.cpp b/src/gui/widgets/qmenu_wince.cpp
index ea58d46..847a623 100644
--- a/src/gui/widgets/qmenu_wince.cpp
+++ b/src/gui/widgets/qmenu_wince.cpp
@@ -58,6 +58,9 @@
 
 #include <QtCore/qlibrary.h>
 #include <commctrl.h>
+#if Q_OS_WINCE_WM
+#   include <windowsm.h>
+#endif
 
 #include "qguifunctions_wince.h"
 
@@ -71,6 +74,12 @@
 #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
 
@@ -204,8 +213,13 @@ static HWND qt_wce_create_menubar(HWND parentHandle, HINSTANCE resourceHandle, i
         mbi.dwFlags = flags;
         mbi.nToolBarId = toolbarID;
 
-        if (ptrCreateMenuBar(&mbi))
+        if (ptrCreateMenuBar(&mbi)) {
+            // 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);
             return mbi.hwndMB;
+        }
     }
     return 0;
 }
-- 
cgit v0.12