]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/window.cpp
Some but not all compile fixes for typetest (VC++ 1.5); added datetime.cpp
[wxWidgets.git] / src / msw / window.cpp
index eefebd74d7d0dc2a566ca469dc51bfb11e758cc7..7fd94251019f6cde0abe27688cdc8a8378068092 100644 (file)
@@ -74,8 +74,8 @@
 #include "wx/intl.h"
 #include "wx/log.h"
 
 #include "wx/intl.h"
 #include "wx/log.h"
 
-
 #include "wx/textctrl.h"
 #include "wx/textctrl.h"
+#include "wx/notebook.h"
 
 #include <string.h>
 
 
 #include <string.h>
 
     #endif
 #endif
 
     #endif
 #endif
 
-// ---------------------------------------------------------------------------
-// macros
-// ---------------------------------------------------------------------------
-
-// standard macros missing from some compilers headers
-#ifndef GET_X_LPARAM
-    #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
-    #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
-#endif // GET_X_LPARAM
-
 // ---------------------------------------------------------------------------
 // global variables
 // ---------------------------------------------------------------------------
 // ---------------------------------------------------------------------------
 // global variables
 // ---------------------------------------------------------------------------
@@ -141,13 +131,14 @@ wxWindow *wxFindWinFromHandle(WXHWND hWnd);
 // event tables
 // ---------------------------------------------------------------------------
 
 // event tables
 // ---------------------------------------------------------------------------
 
-    IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
+IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
 
 BEGIN_EVENT_TABLE(wxWindow, wxWindowBase)
     EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
     EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
     EVT_INIT_DIALOG(wxWindow::OnInitDialog)
     EVT_IDLE(wxWindow::OnIdle)
 
 BEGIN_EVENT_TABLE(wxWindow, wxWindowBase)
     EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
     EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
     EVT_INIT_DIALOG(wxWindow::OnInitDialog)
     EVT_IDLE(wxWindow::OnIdle)
+    EVT_SET_FOCUS(wxWindow::OnSetFocus)
 END_EVENT_TABLE()
 
 // ===========================================================================
 END_EVENT_TABLE()
 
 // ===========================================================================
@@ -1209,9 +1200,9 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
         return;
     }
 
         return;
     }
 
-    if ( x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
+    if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
         x = currentX;
         x = currentX;
-    if ( y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
+    if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
         y = currentY;
 
     AdjustForParentClientOrigin(x, y, sizeFlags);
         y = currentY;
 
     AdjustForParentClientOrigin(x, y, sizeFlags);
@@ -1469,6 +1460,10 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg)
     {
         // intercept dialog navigation keys
         MSG *msg = (MSG *)pMsg;
     {
         // intercept dialog navigation keys
         MSG *msg = (MSG *)pMsg;
+
+        // here we try to do all the job which ::IsDialogMessage() usually does
+        // internally
+#if 1
         bool bProcess = TRUE;
         if ( msg->message != WM_KEYDOWN )
             bProcess = FALSE;
         bool bProcess = TRUE;
         if ( msg->message != WM_KEYDOWN )
             bProcess = FALSE;
@@ -1586,6 +1581,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;
 
         if ( ::IsDialogMessage(GetHwnd(), msg) )
             return TRUE;
@@ -1841,6 +1866,11 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
            break;
 
         case WM_LBUTTONDOWN:
            break;
 
         case WM_LBUTTONDOWN:
+           // set focus to this window
+           SetFocus();
+
+           // fall through
+
         case WM_LBUTTONUP:
         case WM_LBUTTONDBLCLK:
         case WM_RBUTTONDOWN:
         case WM_LBUTTONUP:
         case WM_LBUTTONDBLCLK:
         case WM_RBUTTONDOWN:
@@ -1950,6 +1980,8 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
                 case VK_RETURN:
                 case VK_BACK:
                 case VK_TAB:
                 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
                     // 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
@@ -2157,7 +2189,7 @@ void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win)
     if ( oldWin && (oldWin != win) )
     {
         wxString str(win->GetClassInfo()->GetClassName());
     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)
     {
     }
     else if (!oldWin)
     {
@@ -2251,6 +2283,17 @@ bool wxWindow::MSWCreate(int id,
     if ( width > -1 ) width1 = width;
     if ( height > -1 ) height1 = height;
 
     if ( width > -1 ) width1 = width;
     if ( height > -1 ) height1 = height;
 
+    // Unfortunately this won't work in WIN16. Unless perhaps
+    // we define WS_EX_CONTROLPARENT ourselves?
+#ifndef __WIN16__
+    // if we have wxTAB_TRAVERSAL style, we want WS_EX_CONTROLPARENT or
+    // IsDialogMessage() won't work for us
+    if ( GetWindowStyleFlag() & wxTAB_TRAVERSAL )
+    {
+        extendedStyle |= WS_EX_CONTROLPARENT;
+    }
+#endif
+
     HWND hParent = (HWND)NULL;
     if ( parent )
         hParent = (HWND) parent->GetHWND();
     HWND hParent = (HWND)NULL;
     if ( parent )
         hParent = (HWND) parent->GetHWND();
@@ -2329,7 +2372,7 @@ bool wxWindow::MSWCreate(int id,
         HWND hWnd = (HWND) node->GetKeyInteger();
         if (hWnd != (HWND) m_hWnd)
         {
         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
         }
     }
 #endif
@@ -2478,6 +2521,33 @@ bool wxWindow::HandleDestroy()
 // activation/focus
 // ---------------------------------------------------------------------------
 
 // activation/focus
 // ---------------------------------------------------------------------------
 
+void wxWindow::OnSetFocus(wxFocusEvent& event)
+{
+    // panel wants to track the window which was the last to have focus in it,
+    // so we want to set ourselves as the window which last had focus
+    //
+    // notice that it's also important to do it upwards the tree becaus
+    // otherwise when the top level panel gets focus, it won't set it back to
+    // us, but to some other sibling
+    wxWindow *win = this;
+    while ( win )
+    {
+        wxWindow *parent = win->GetParent();
+        wxPanel *panel = wxDynamicCast(parent, wxPanel);
+        if ( panel )
+        {
+            panel->SetLastFocus(win);
+        }
+
+        win = parent;
+    }
+
+    wxLogTrace(_T("focus"), _T("%s (0x%08x) gets focus"),
+               GetClassInfo()->GetClassName(), GetHandle());
+
+    event.Skip();
+}
+
 bool wxWindow::HandleActivate(int state,
                               bool WXUNUSED(minimized),
                               WXHWND WXUNUSED(activate))
 bool wxWindow::HandleActivate(int state,
                               bool WXUNUSED(minimized),
                               WXHWND WXUNUSED(activate))
@@ -2500,13 +2570,6 @@ bool wxWindow::HandleSetFocus(WXHWND WXUNUSED(hwnd))
     }
 #endif // wxUSE_CARET
 
     }
 #endif // wxUSE_CARET
 
-    // panel wants to track the window which was the last to have focus in it
-    wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
-    if ( panel )
-    {
-        panel->SetLastFocus(this);
-    }
-
     wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
     event.SetEventObject(this);
 
     wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
     event.SetEventObject(this);
 
@@ -2941,15 +3004,32 @@ bool wxWindow::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
         return popupMenu->MSWCommand(cmd, id);
     }
 
         return popupMenu->MSWCommand(cmd, id);
     }
 
-    // must cast to a signed type before comparing with other ids!
-    wxWindow *win = FindItem((signed short)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);
         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;
 }
 
     return FALSE;
 }
@@ -3335,8 +3415,11 @@ bool wxWindow::MSWOnScroll(int orientation, WXWORD wParam,
         event.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
         break;
 
         event.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
         break;
 
-    case SB_THUMBTRACK:
     case SB_THUMBPOSITION:
     case SB_THUMBPOSITION:
+        event.m_isScrolling = FALSE;
+        /* fall-through */
+
+    case SB_THUMBTRACK:
         event.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
         break;
 
         event.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
         break;
 
@@ -3549,6 +3632,48 @@ wxWindow *wxGetActiveWindow()
     return NULL;
 }
 
     return NULL;
 }
 
+extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd)
+{
+    HWND hwnd = (HWND)hWnd;
+
+    // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
+    // by code in msw/radiobox.cpp), for all the others we just search up the
+    // window hierarchy
+    wxWindow *win = (wxWindow *)NULL;
+    if ( hwnd )
+    {
+        win = wxFindWinFromHandle((WXHWND)hwnd);
+        if ( !win )
+        {
+            // the radiobox pointer is stored in GWL_USERDATA only under Win32
+#ifdef __WIN32__
+            // native radiobuttons return DLGC_RADIOBUTTON here and for any
+            // wxWindow class which overrides WM_GETDLGCODE processing to
+            // do it as well, win would be already non NULL
+            if ( ::SendMessage((HWND)hwnd, WM_GETDLGCODE,
+                               0, 0) & DLGC_RADIOBUTTON )
+            {
+                win = (wxWindow *)::GetWindowLong(hwnd, GWL_USERDATA);
+            }
+            else
+#endif // Win32
+            {
+                // hwnd is not a wxWindow, try its parent next below
+                hwnd = ::GetParent(hwnd);
+            }
+        }
+        //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
+    }
+
+    while ( hwnd && !win )
+    {
+        win = wxFindWinFromHandle((WXHWND)hwnd);
+        hwnd = ::GetParent(hwnd);
+    }
+
+    return win;
+}
+
 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
 // in active frames and dialogs, regardless of where the focus is.
 static HHOOK wxTheKeyboardHook = 0;
 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
 // in active frames and dialogs, regardless of where the focus is.
 static HHOOK wxTheKeyboardHook = 0;
@@ -3564,11 +3689,12 @@ void wxSetKeyboardHook(bool doIt)
         wxTheKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) wxTheKeyboardHookProc, wxGetInstance(),
 
 #if defined(__WIN32__) && !defined(__TWIN32__)
         wxTheKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) wxTheKeyboardHookProc, wxGetInstance(),
 
 #if defined(__WIN32__) && !defined(__TWIN32__)
-            GetCurrentThreadId());
+            GetCurrentThreadId()
         //      (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
 #else
         //      (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
 #else
-            GetCurrentTask());
+            GetCurrentTask()
 #endif
 #endif
+            );
     }
     else
     {
     }
     else
     {