]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/window.cpp
Typo fix
[wxWidgets.git] / src / msw / window.cpp
index 23d1786d2b769085ca4e6a300a86da0c3fcb9fba..77589902e52de74badfdc01b09e54c06d7afcf75 100644 (file)
     #endif
 #endif
 
     #endif
 #endif
 
+// ----------------------------------------------------------------------------
+// standard constants not available with all compilers/headers
+// ----------------------------------------------------------------------------
+
 // This didn't appear in mingw until 2.95.2
 #ifndef SIF_TRACKPOS
 #define SIF_TRACKPOS 16
 // This didn't appear in mingw until 2.95.2
 #ifndef SIF_TRACKPOS
 #define SIF_TRACKPOS 16
     #ifndef SPI_GETWHEELSCROLLLINES
         #define SPI_GETWHEELSCROLLLINES 104
     #endif
     #ifndef SPI_GETWHEELSCROLLLINES
         #define SPI_GETWHEELSCROLLLINES 104
     #endif
+#endif // wxUSE_MOUSEWHEEL
+
+#ifndef VK_OEM_1
+    #define VK_OEM_1        0xBA
+    #define VK_OEM_PLUS     0xBB
+    #define VK_OEM_COMMA    0xBC
+    #define VK_OEM_MINUS    0xBD
+    #define VK_OEM_PERIOD   0xBE
+    #define VK_OEM_2        0xBF
+    #define VK_OEM_3        0xC0
+    #define VK_OEM_4        0xDB
+    #define VK_OEM_5        0xDC
+    #define VK_OEM_6        0xDD
+    #define VK_OEM_7        0xDE
 #endif
 
 // ---------------------------------------------------------------------------
 #endif
 
 // ---------------------------------------------------------------------------
@@ -297,6 +315,7 @@ void wxWindowMSW::Init()
     m_oldWndProc = 0;
     m_useCtl3D = FALSE;
     m_mouseInWindow = FALSE;
     m_oldWndProc = 0;
     m_useCtl3D = FALSE;
     m_mouseInWindow = FALSE;
+    m_lastKeydownProcessed = FALSE;
 
     // wxWnd
     m_hMenu = 0;
 
     // wxWnd
     m_hMenu = 0;
@@ -1645,15 +1664,6 @@ void wxWindowMSW::DoSetClientSize(int width, int height)
             break;
         }
 
             break;
         }
 
-        if ( i == 3 )
-        {
-            // how did it happen? maybe OnSize() handler does something really
-            // strange in this class?
-            wxFAIL_MSG( _T("logic error in DoSetClientSize") );
-
-            break;
-        }
-
         int widthClient = width,
             heightClient = height;
 
         int widthClient = width,
             heightClient = height;
 
@@ -2026,10 +2036,18 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
         }
 #endif // 1/0
 
         }
 #endif // 1/0
 
-        if ( ::IsDialogMessage(GetHwnd(), msg) )
+        // we handle VK_ESCAPE ourselves in wxDialog::OnCharHook() and we
+        // shouldn't let IsDialogMessage() get it as it _always_ eats the
+        // message even when there is no cancel button and when the message is
+        // needed by the control itself: in particular, it prevents the tree in
+        // place edit control from being closed with Escape in a dialog
+        if ( msg->message != WM_KEYDOWN || msg->wParam != VK_ESCAPE )
         {
         {
-            // IsDialogMessage() did something...
-            return TRUE;
+            if ( ::IsDialogMessage(GetHwnd(), msg) )
+            {
+                // IsDialogMessage() did something...
+                return TRUE;
+            }
         }
     }
 #endif // __WXUNIVERSAL__
         }
     }
 #endif // __WXUNIVERSAL__
@@ -2472,27 +2490,31 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
 
         case WM_SYSKEYDOWN:
         case WM_KEYDOWN:
 
         case WM_SYSKEYDOWN:
         case WM_KEYDOWN:
-            // If this has been processed by an event handler,
-            // return 0 now (we've handled it).
-            if ( HandleKeyDown((WORD) wParam, lParam) )
-            {
-                processed = TRUE;
-
-                break;
-            }
-
-            // we consider these message "not interesting" to OnChar
-            if ( wParam == VK_SHIFT || wParam == VK_CONTROL )
+            // If this has been processed by an event handler, return 0 now
+            // (we've handled it).
+            m_lastKeydownProcessed = HandleKeyDown((WORD) wParam, lParam);
+            if ( m_lastKeydownProcessed )
             {
                 processed = TRUE;
             {
                 processed = TRUE;
-
                 break;
             }
 
             switch ( wParam )
             {
                 break;
             }
 
             switch ( wParam )
             {
-                // avoid duplicate messages to OnChar for these ASCII keys: they
-                // will be translated by TranslateMessage() and received in WM_CHAR
+                // we consider these message "not interesting" to OnChar, so
+                // just don't do anything more with them
+                case VK_SHIFT:
+                case VK_CONTROL:
+                case VK_MENU:
+                case VK_CAPITAL:
+                case VK_NUMLOCK:
+                case VK_SCROLL:
+                    processed = TRUE;
+                    break;
+
+                // avoid duplicate messages to OnChar for these ASCII keys:
+                // they will be translated by TranslateMessage() and received
+                // in WM_CHAR
                 case VK_ESCAPE:
                 case VK_SPACE:
                 case VK_RETURN:
                 case VK_ESCAPE:
                 case VK_SPACE:
                 case VK_RETURN:
@@ -2500,9 +2522,22 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
                 case VK_TAB:
                 case VK_ADD:
                 case VK_SUBTRACT:
                 case VK_TAB:
                 case VK_ADD:
                 case VK_SUBTRACT:
-                    // but set processed to FALSE, not TRUE to still pass them to
-                    // the control's default window proc - otherwise built-in
-                    // keyboard handling won't work
+                case VK_MULTIPLY:
+                case VK_DIVIDE:
+                case VK_OEM_1:
+                case VK_OEM_2:
+                case VK_OEM_3:
+                case VK_OEM_4:
+                case VK_OEM_5:
+                case VK_OEM_6:
+                case VK_OEM_7:
+                case VK_OEM_PLUS:
+                case VK_OEM_COMMA:
+                case VK_OEM_MINUS:
+                case VK_OEM_PERIOD:
+                    // but set processed to FALSE, not TRUE to still pass them
+                    // to the control's default window proc - otherwise
+                    // built-in keyboard handling won't work
                     processed = FALSE;
 
                     break;
                     processed = FALSE;
 
                     break;
@@ -2521,12 +2556,10 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
                     break;
 #endif // VK_APPS
 
                     break;
 #endif // VK_APPS
 
-                case VK_LEFT:
-                case VK_RIGHT:
-                case VK_DOWN:
-                case VK_UP:
                 default:
                 default:
+                    // do generate a CHAR event
                     processed = HandleChar((WORD)wParam, lParam);
                     processed = HandleChar((WORD)wParam, lParam);
+
             }
             break;
 
             }
             break;
 
@@ -2551,7 +2584,18 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
 
         case WM_SYSCHAR:
         case WM_CHAR: // Always an ASCII character
 
         case WM_SYSCHAR:
         case WM_CHAR: // Always an ASCII character
-            processed = HandleChar((WORD)wParam, lParam, TRUE);
+            if ( m_lastKeydownProcessed )
+            {
+                // The key was handled in the EVT_KEY_DOWN and handling
+                // a key in an EVT_KEY_DOWN handler is meant, by
+                // design, to prevent EVT_CHARs from happening
+                m_lastKeydownProcessed = FALSE;
+                processed = TRUE;
+            }
+            else
+            {
+                processed = HandleChar((WORD)wParam, lParam, TRUE);
+            }
             break;
 
         case WM_HSCROLL:
             break;
 
         case WM_HSCROLL:
@@ -2611,6 +2655,10 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
             processed = HandlePaletteChanged((WXHWND) (HWND) wParam);
             break;
 
             processed = HandlePaletteChanged((WXHWND) (HWND) wParam);
             break;
 
+        case WM_CAPTURECHANGED:
+            processed = HandleCaptureChanged((WXHWND) (HWND) lParam);
+            break;
+
         case WM_QUERYNEWPALETTE:
             processed = HandleQueryNewPalette();
             break;
         case WM_QUERYNEWPALETTE:
             processed = HandleQueryNewPalette();
             break;
@@ -3475,6 +3523,14 @@ bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange)
     return GetEventHandler()->ProcessEvent(event);
 }
 
     return GetEventHandler()->ProcessEvent(event);
 }
 
+bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture)
+{
+    wxMouseCaptureChangedEvent event(GetId(), wxFindWinFromHandle(hWndGainedCapture));
+    event.SetEventObject(this);
+
+    return GetEventHandler()->ProcessEvent(event);
+}
+
 bool wxWindowMSW::HandleQueryNewPalette()
 {
 
 bool wxWindowMSW::HandleQueryNewPalette()
 {
 
@@ -3740,9 +3796,13 @@ bool wxWindowMSW::HandleMove(int x, int y)
     return GetEventHandler()->ProcessEvent(event);
 }
 
     return GetEventHandler()->ProcessEvent(event);
 }
 
-bool wxWindowMSW::HandleSize(int w, int h, WXUINT WXUNUSED(flag))
+bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h),
+                             WXUINT WXUNUSED(flag))
 {
 {
-    wxSizeEvent event(wxSize(w, h), m_windowId);
+    // don't use w and h parameters as they specify the client size while
+    // according to the docs EVT_SIZE handler is supposed to receive the total
+    // size
+    wxSizeEvent event(GetSize(), m_windowId);
     event.SetEventObject(this);
 
     return GetEventHandler()->ProcessEvent(event);
     event.SetEventObject(this);
 
     return GetEventHandler()->ProcessEvent(event);
@@ -4014,7 +4074,8 @@ bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam)
 // HandleChar and HandleKeyDown/Up
 wxKeyEvent wxWindowMSW::CreateKeyEvent(wxEventType evType,
                                        int id,
 // HandleChar and HandleKeyDown/Up
 wxKeyEvent wxWindowMSW::CreateKeyEvent(wxEventType evType,
                                        int id,
-                                       WXLPARAM lParam) const
+                                       WXLPARAM lParam,
+                                       WXWPARAM wParam) const
 {
     wxKeyEvent event(evType);
     event.SetId(GetId());
 {
     wxKeyEvent event(evType);
     event.SetId(GetId());
@@ -4024,6 +4085,8 @@ wxKeyEvent wxWindowMSW::CreateKeyEvent(wxEventType evType,
 
     event.m_eventObject = (wxWindow *)this; // const_cast
     event.m_keyCode = id;
 
     event.m_eventObject = (wxWindow *)this; // const_cast
     event.m_keyCode = id;
+    event.m_rawCode = (wxUint32) wParam;
+    event.m_rawFlags = (wxUint32) lParam;
     event.SetTimestamp(s_currentMsg.time);
 
     // translate the position to client coords
     event.SetTimestamp(s_currentMsg.time);
 
     // translate the position to client coords
@@ -4069,30 +4132,28 @@ bool wxWindowMSW::HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII)
 
                 default:
                     ctrlDown = TRUE;
 
                 default:
                     ctrlDown = TRUE;
-                    id = id + 96;
+                    id = id + 'a' - 1;
             }
         }
     }
             }
         }
     }
-    else if ( (id = wxCharCodeMSWToWX(wParam)) == 0 )
+    else // we're called from WM_KEYDOWN
     {
     {
-        // it's ASCII and will be processed here only when called from
-        // WM_CHAR (i.e. when isASCII = TRUE), don't process it now
-        id = -1;
-    }
-
-    if ( id != -1 )
-    {
-        wxKeyEvent event(CreateKeyEvent(wxEVT_CHAR, id, lParam));
-        if ( ctrlDown )
+        id = wxCharCodeMSWToWX(wParam);
+        if ( id == 0 )
         {
         {
-            event.m_controlDown = TRUE;
+            // it's ASCII and will be processed here only when called from
+            // WM_CHAR (i.e. when isASCII = TRUE), don't process it now
+            return FALSE;
         }
         }
+    }
 
 
-        if ( GetEventHandler()->ProcessEvent(event) )
-            return TRUE;
+    wxKeyEvent event(CreateKeyEvent(wxEVT_CHAR, id, lParam, wParam));
+    if ( ctrlDown )
+    {
+        event.m_controlDown = TRUE;
     }
 
     }
 
-    return FALSE;
+    return GetEventHandler()->ProcessEvent(event);
 }
 
 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam)
 }
 
 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam)
@@ -4107,7 +4168,7 @@ bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam)
 
     if ( id != -1 ) // VZ: does this ever happen (FIXME)?
     {
 
     if ( id != -1 ) // VZ: does this ever happen (FIXME)?
     {
-        wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_DOWN, id, lParam));
+        wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_DOWN, id, lParam, wParam));
         if ( GetEventHandler()->ProcessEvent(event) )
         {
             return TRUE;
         if ( GetEventHandler()->ProcessEvent(event) )
         {
             return TRUE;
@@ -4129,7 +4190,7 @@ bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam)
 
     if ( id != -1 ) // VZ: does this ever happen (FIXME)?
     {
 
     if ( id != -1 ) // VZ: does this ever happen (FIXME)?
     {
-        wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_UP, id, lParam));
+        wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_UP, id, lParam, wParam));
         if ( GetEventHandler()->ProcessEvent(event) )
             return TRUE;
     }
         if ( GetEventHandler()->ProcessEvent(event) )
             return TRUE;
     }
@@ -4230,7 +4291,7 @@ bool wxWindowMSW::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags)
 // ---------------------------------------------------------------------------
 
 bool wxWindowMSW::MSWOnScroll(int orientation, WXWORD wParam,
 // ---------------------------------------------------------------------------
 
 bool wxWindowMSW::MSWOnScroll(int orientation, WXWORD wParam,
-                           WXWORD pos, WXHWND control)
+                              WXWORD pos, WXHWND control)
 {
     if ( control )
     {
 {
     if ( control )
     {
@@ -4358,6 +4419,7 @@ int wxCharCodeMSWToWX(int keySym)
         case VK_CONTROL:    id = WXK_CONTROL; break;
         case VK_MENU :      id = WXK_MENU; break;
         case VK_PAUSE:      id = WXK_PAUSE; break;
         case VK_CONTROL:    id = WXK_CONTROL; break;
         case VK_MENU :      id = WXK_MENU; break;
         case VK_PAUSE:      id = WXK_PAUSE; break;
+        case VK_CAPITAL:    id = WXK_CAPITAL; break;
         case VK_SPACE:      id = WXK_SPACE; break;
         case VK_ESCAPE:     id = WXK_ESCAPE; break;
         case VK_PRIOR:      id = WXK_PRIOR; break;
         case VK_SPACE:      id = WXK_SPACE; break;
         case VK_ESCAPE:     id = WXK_ESCAPE; break;
         case VK_PRIOR:      id = WXK_PRIOR; break;
@@ -4415,6 +4477,19 @@ int wxCharCodeMSWToWX(int keySym)
         case VK_F24:        id = WXK_F24; break;
         case VK_NUMLOCK:    id = WXK_NUMLOCK; break;
         case VK_SCROLL:     id = WXK_SCROLL; break;
         case VK_F24:        id = WXK_F24; break;
         case VK_NUMLOCK:    id = WXK_NUMLOCK; break;
         case VK_SCROLL:     id = WXK_SCROLL; break;
+
+        case VK_OEM_1:      id = ';'; break;
+        case VK_OEM_PLUS:   id = '+'; break;
+        case VK_OEM_COMMA:  id = ','; break;
+        case VK_OEM_MINUS:  id = '-'; break;
+        case VK_OEM_PERIOD: id = '.'; break;
+        case VK_OEM_2:      id = '/'; break;
+        case VK_OEM_3:      id = '~'; break;
+        case VK_OEM_4:      id = '['; break;
+        case VK_OEM_5:      id = '\\'; break;
+        case VK_OEM_6:      id = ']'; break;
+        case VK_OEM_7:      id = '\''; break;
+
         default:
             id = 0;
     }
         default:
             id = 0;
     }
@@ -5158,7 +5233,7 @@ wxPoint wxGetMousePosition()
 {
     POINT pt;
     GetCursorPos( & pt );
 {
     POINT pt;
     GetCursorPos( & pt );
-    
+
     return wxPoint(pt.x, pt.y);
 }
 
     return wxPoint(pt.x, pt.y);
 }