]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/window.cpp
(run-time) fix for !wxUSE_IPC build
[wxWidgets.git] / src / msw / window.cpp
index cb7ceddbda28516b8c27de3bb05388411a8acaeb..ec39a8be1d37c814c329040582eff6ac716d9178 100644 (file)
@@ -74,8 +74,8 @@
 #include "wx/intl.h"
 #include "wx/log.h"
 
-
 #include "wx/textctrl.h"
+#include "wx/notebook.h"
 
 #include <string.h>
 
@@ -119,7 +119,7 @@ extern MSG s_currentMsg;
 
 wxMenu *wxCurrentPopupMenu = NULL;
 extern wxList WXDLLEXPORT wxPendingDelete;
-extern wxChar wxCanvasClassName[];
+extern const wxChar *wxCanvasClassName;
 
 // ---------------------------------------------------------------------------
 // private functions
@@ -141,9 +141,7 @@ wxWindow *wxFindWinFromHandle(WXHWND hWnd);
 // event tables
 // ---------------------------------------------------------------------------
 
-#if !USE_SHARED_LIBRARY
     IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
-#endif
 
 BEGIN_EVENT_TABLE(wxWindow, wxWindowBase)
     EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
@@ -163,6 +161,17 @@ END_EVENT_TABLE()
 // Find an item given the MS Windows id
 wxWindow *wxWindow::FindItem(long id) const
 {
+    wxControl *item = wxDynamicCast(this, wxControl);
+    if ( item )
+    {
+        // i it we or one of our "internal" children?
+        if ( item->GetId() == id ||
+             (item->GetSubcontrols().Index(id) != wxNOT_FOUND) )
+        {
+            return item;
+        }
+    }
+
     wxWindowList::Node *current = GetChildren().GetFirst();
     while (current)
     {
@@ -172,19 +181,6 @@ wxWindow *wxWindow::FindItem(long id) const
         if ( wnd )
             return wnd;
 
-        if ( childWin->IsKindOf(CLASSINFO(wxControl)) )
-        {
-            wxControl *item = (wxControl *)childWin;
-            if ( item->GetId() == id )
-                return item;
-            else
-            {
-                // In case it's a 'virtual' control (e.g. radiobox)
-                if ( item->GetSubcontrols().Member((wxObject *)id) )
-                    return item;
-            }
-        }
-
         current = current->GetNext();
     }
 
@@ -1213,9 +1209,9 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
         return;
     }
 
-    if ( x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
+    if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
         x = currentX;
-    if ( y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
+    if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
         y = currentY;
 
     AdjustForParentClientOrigin(x, y, sizeFlags);
@@ -1473,6 +1469,10 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg)
     {
         // intercept dialog navigation keys
         MSG *msg = (MSG *)pMsg;
+
+        // here we try to do all the job which ::IsDialogMessage() usually does
+        // internally
+#if 0
         bool bProcess = TRUE;
         if ( msg->message != WM_KEYDOWN )
             bProcess = FALSE;
@@ -1590,6 +1590,36 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg)
                 }
             }
         }
+#else
+        // let ::IsDialogMessage() do almost everything and handle just the
+        // things it doesn't here: Ctrl-TAB for switching notebook pages
+        if ( msg->message == WM_KEYDOWN )
+        {
+            // don't process system keys here
+            if ( !(HIWORD(msg->lParam) & KF_ALTDOWN) )
+            {
+                if ( (msg->wParam == VK_TAB) &&
+                     (::GetKeyState(VK_CONTROL) & 0x100) != 0 )
+                {
+                    // find the first notebook parent and change its page
+                    wxWindow *win = this;
+                    wxNotebook *nbook = NULL;
+                    while ( win && !nbook )
+                    {
+                        nbook = wxDynamicCast(win, wxNotebook);
+                        win = win->GetParent();
+                    }
+
+                    if ( nbook )
+                    {
+                        bool forward = !(::GetKeyState(VK_SHIFT) & 0x100);
+
+                        nbook->AdvanceSelection(forward);
+                    }
+                }
+            }
+        }
+#endif // 0
 
         if ( ::IsDialogMessage(GetHwnd(), msg) )
             return TRUE;
@@ -1841,9 +1871,15 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
                 short y = HIWORD(lParam);
 
                 processed = HandleMouseMove(x, y, wParam);
-                break;
-            }
+           }
+           break;
+
         case WM_LBUTTONDOWN:
+           // set focus to this window
+           SetFocus();
+
+           // fall through
+
         case WM_LBUTTONUP:
         case WM_LBUTTONDBLCLK:
         case WM_RBUTTONDOWN:
@@ -1953,6 +1989,8 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
                 case VK_RETURN:
                 case VK_BACK:
                 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
@@ -2160,7 +2198,7 @@ void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win)
     if ( oldWin && (oldWin != win) )
     {
         wxString str(win->GetClassInfo()->GetClassName());
-        wxLogError("Bug! Found existing HWND %X for new window of class %s", (int) hWnd, (const char*) str);
+        wxLogError(wxT("Bug! Found existing HWND %X for new window of class %s"), (int) hWnd, (const wxChar*) str);
     }
     else if (!oldWin)
     {
@@ -2332,7 +2370,7 @@ bool wxWindow::MSWCreate(int id,
         HWND hWnd = (HWND) node->GetKeyInteger();
         if (hWnd != (HWND) m_hWnd)
         {
-            wxLogError("A second HWND association is being added for the same window!");
+            wxLogError(wxT("A second HWND association is being added for the same window!"));
         }
     }
 #endif
@@ -2673,10 +2711,9 @@ bool wxWindow::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct)
     {
         return ((wxControl *)item)->MSWOnDraw(itemStruct);
     }
-    else
-#endif
-        return FALSE;
+#endif // USE_OWNER_DRAWN
 
+    return FALSE;
 }
 
 bool wxWindow::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
@@ -2945,14 +2982,32 @@ bool wxWindow::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
         return popupMenu->MSWCommand(cmd, id);
     }
 
-    wxWindow *win = FindItem(id);
-    if ( !win )
+    wxWindow *win;
+    if ( cmd == 0 || cmd == 1 ) // menu or accel - use id
+    {
+        // must cast to a signed type before comparing with other ids!
+        win = FindItem((signed short)id);
+    }
+    else
     {
+        // find it from HWND - this works even with the broken programs using
+        // the same ids for different controls
         win = wxFindWinFromHandle(control);
     }
 
     if ( win )
         return win->MSWCommand(cmd, id);
+    else
+    {
+        // If no child window, it may be an accelerator, e.g. for
+        // a popup menu command.
+
+        wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED);
+        event.SetEventObject(this);
+        event.SetId(id);
+        event.SetInt(id);
+        return ProcessEvent(event);
+    }
 
     return FALSE;
 }
@@ -3338,8 +3393,11 @@ bool wxWindow::MSWOnScroll(int orientation, WXWORD wParam,
         event.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
         break;
 
-    case SB_THUMBTRACK:
     case SB_THUMBPOSITION:
+        event.m_isScrolling = FALSE;
+        /* fall-through */
+
+    case SB_THUMBTRACK:
         event.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
         break;