]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/window.cpp
added wxListView class: this is going to be a wxListCtrl with human (inter)face
[wxWidgets.git] / src / msw / window.cpp
index 31ef0ea340b6112eedfc706026c82520cce82e78..5b07081f99cfaedefa4c32f5444a4340cbef3ca0 100644 (file)
@@ -84,7 +84,7 @@
 
 #include <string.h>
 
-#if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
+#if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__)) || defined(__CYGWIN10__)
     #include <shellapi.h>
     #include <mmsystem.h>
 #endif
     #include <windowsx.h>
 #endif
 
-#if (!defined(__GNUWIN32_OLD__) && !defined(__TWIN32__)) || defined(__CYGWIN10__)
+#if (!defined(__GNUWIN32_OLD__) && !defined(__TWIN32__) && !defined(__WXMICROWIN__)) || defined(__CYGWIN10__)
     #ifdef __WIN95__
         #include <commctrl.h>
     #endif
-#else // broken compiler
+#elif !defined(__WXMICROWIN__) // broken compiler
     #ifndef __TWIN32__
         #include "wx/msw/gnuwin32/extra.h"
     #endif
@@ -160,14 +160,12 @@ static void TranslateKbdEventToMouse(wxWindowMSW *win,
 static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win);
 
 // check if the mouse is in the window or its child
-static bool IsMouseInWindow(HWND hwnd);
+//static bool IsMouseInWindow(HWND hwnd);
 
 // ---------------------------------------------------------------------------
 // event tables
 // ---------------------------------------------------------------------------
 
-IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
-
 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
 // method
 #ifdef __WXUNIVERSAL__
@@ -423,12 +421,19 @@ void wxWindowMSW::SetFocus()
     HWND hWnd = GetHwnd();
     wxCHECK_RET( hWnd, _T("can't set focus to invalid window") );
 
+#ifndef __WXMICROWIN__
     ::SetLastError(0);
+#endif
 
     if ( !::SetFocus(hWnd) )
     {
         // was there really an error?
+#ifndef __WXMICROWIN__
         DWORD dwRes = ::GetLastError();
+#else
+
+        DWORD dwRes = 0;
+#endif
         if ( dwRes )
         {
             wxLogApiError(_T("SetFocus"), dwRes);
@@ -491,7 +496,19 @@ bool wxWindowMSW::Show(bool show)
 
     if ( show )
     {
+#ifdef __WXMICROWIN__
+        // It seems that MicroWindows brings the _parent_ of the
+        // window to the top, which can be the wrong one.
+
+        // activate (set focus to) specified window
+        ::SetFocus(hWnd);
+
+        // raise top level parent to top of z order
+        ::SetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0,
+                SWP_NOMOVE|SWP_NOSIZE);
+#else
         BringWindowToTop(hWnd);
+#endif
     }
 
     return TRUE;
@@ -503,8 +520,19 @@ void wxWindowMSW::Raise()
 #ifdef __WIN16__
     ::BringWindowToTop(GetHwnd());
 #else // Win32
+#ifdef __WXMICROWIN__
+    // It seems that MicroWindows brings the _parent_ of the
+    // window to the top, which can be the wrong one.
+
+    // activate (set focus to) specified window
+    ::SetFocus(GetHwnd());
+
+    // raise top level parent to top of z order
+    ::SetWindowPos(GetHwnd(), HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
+#else
     ::SetForegroundWindow(GetHwnd());
 #endif
+#endif
 }
 
 // Lower the window to the bottom of the Z order
@@ -742,7 +770,11 @@ int wxWindowMSW::GetScrollPos(int orient) const
     HWND hWnd = GetHwnd();
     if ( hWnd )
     {
+#ifdef __WXMICROWIN__
+        return ::GetScrollPosWX(hWnd, wOrient);
+#else
         return ::GetScrollPos(hWnd, wOrient);
+#endif
     }
     else
         return 0;
@@ -912,6 +944,9 @@ void wxWindowMSW::SubclassWin(WXHWND hWnd)
     wxAssociateWinWithHandle(hwnd, this);
 
     m_oldWndProc = (WXFARPROC) GetWindowLong(hwnd, GWL_WNDPROC);
+
+    wxASSERT( (WXFARPROC) m_oldWndProc != (WXFARPROC) wxWndProc );
+
     SetWindowLong(hwnd, GWL_WNDPROC, (LONG) wxWndProc);
 }
 
@@ -1176,7 +1211,7 @@ void wxWindowMSW::Update()
         wxLogLastError(_T("UpdateWindow"));
     }
 
-#ifdef __WIN32__
+#if defined(__WIN32__) && !defined(__WXMICROWIN__)
     // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
     // handler needs to be really drawn right now
     (void)::GdiFlush();
@@ -1885,9 +1920,11 @@ void wxWindowMSW::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
                               WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd)
 {
+#ifndef __WXMICROWIN__
     *nCtlColor = CTLCOLOR_BTN;
     *hwnd = (WXHWND)lParam;
     *hdc = (WXHDC)wParam;
+#endif
 }
 
 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
@@ -2065,21 +2102,11 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
             }
             break;
 
-#ifdef __WXUNIVERSAL__
+#ifndef __WXMICROWIN__
         case WM_ACTIVATEAPP:
             wxTheApp->SetActive(wParam != 0, FindFocus());
             break;
-
-        case WM_NCHITTEST:
-            // we shouldn't allow the windows which don't want to get focus to
-            // get it
-            if ( !AcceptsFocus() )
-            {
-                rc.result = HTTRANSPARENT;
-                processed = TRUE;
-            }
-            break;
-#endif // __WXUNIVERSAL__
+#endif
 
         case WM_ACTIVATE:
             {
@@ -2127,12 +2154,6 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
 #endif
 
         case WM_LBUTTONDOWN:
-           // set focus to this window
-           if (AcceptsFocus())
-                SetFocus();
-
-           // fall through
-
         case WM_LBUTTONUP:
         case WM_LBUTTONDBLCLK:
         case WM_RBUTTONDOWN:
@@ -2141,12 +2162,70 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
         case WM_MBUTTONDOWN:
         case WM_MBUTTONUP:
         case WM_MBUTTONDBLCLK:
-            processed = HandleMouseEvent(message,
+         {
+                processed = FALSE;
+#ifdef __WXMICROWIN__
+                // MicroWindows seems to ignore the fact that a window is
+                // disabled. So catch mouse events and throw them away if
+                // necessary.
+                wxWindowMSW* win = this;
+                while (win)
+                {
+                    if (!win->IsEnabled())
+                    {
+                        processed = TRUE;
+                        break;
+                    }
+                    win = win->GetParent();
+                    if (win && win->IsTopLevel())
+                        break;
+                }
+#endif // __WXMICROWIN__
+                if (!processed)
+                {
+                    if (message == WM_LBUTTONDOWN && AcceptsFocus())
+                        SetFocus();
+                     processed = HandleMouseEvent(message,
                                          GET_X_LPARAM(lParam),
                                          GET_Y_LPARAM(lParam),
-                                         wParam);
-            break;
+                                                  wParam);
+                }
+                break;
+         }
+
+#ifdef __WXMICROWIN__
+        case WM_NCLBUTTONDOWN:
+        case WM_NCLBUTTONUP:
+        case WM_NCLBUTTONDBLCLK:
+        case WM_NCRBUTTONDOWN:
+        case WM_NCRBUTTONUP:
+        case WM_NCRBUTTONDBLCLK:
+#if 0
+        case WM_NCMBUTTONDOWN:
+        case WM_NCMBUTTONUP:
+        case WM_NCMBUTTONDBLCLK:
+#endif
+            {
+                // MicroWindows seems to ignore the fact that a window
+                // is disabled. So catch mouse events and throw them away if necessary.
+                processed = FALSE;
+                wxWindowMSW* win = this;
+                while (win)
+                {
+                    if (!win->IsEnabled())
+                    {
+                        processed = TRUE;
+                        break;
+                    }
+                    win = win->GetParent();
+                    if (win && win->IsTopLevel())
+                        break;
+                }
+                break;
+            }
+#endif // __WXMICROWIN__
 
+#ifdef MM_JOY1MOVE
         case MM_JOY1MOVE:
         case MM_JOY2MOVE:
         case MM_JOY1ZMOVE:
@@ -2160,6 +2239,7 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
                                             GET_Y_LPARAM(lParam),
                                             wParam);
             break;
+#endif // __WXMICROWIN__
 
         case WM_SYSCOMMAND:
             processed = HandleSysCommand(wParam, lParam);
@@ -2182,6 +2262,7 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
 #endif  // Win95
 
             // for these messages we must return TRUE if process the message
+#ifdef WM_DRAWITEM
         case WM_DRAWITEM:
         case WM_MEASUREITEM:
             {
@@ -2201,6 +2282,7 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
                     rc.result = TRUE;
             }
             break;
+#endif // defined(WM_DRAWITEM)
 
         case WM_GETDLGCODE:
             if ( m_lDlgCode )
@@ -2309,7 +2391,8 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
             break;
 
         // CTLCOLOR messages are sent by children to query the parent for their
-        // colors
+        // colors#ifndef __WXMICROWIN__
+#ifndef __WXMICROWIN__
 #ifdef __WIN32__
         case WM_CTLCOLORMSGBOX:
         case WM_CTLCOLOREDIT:
@@ -2336,6 +2419,7 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
                                            lParam);
             }
             break;
+#endif // !__WXMICROWIN__
 
             // the return value for this message is ignored
         case WM_SYSCOLORCHANGE:
@@ -2399,14 +2483,14 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
             }
             break;
 
-#ifdef __WIN32__
+#if defined(__WIN32__) && defined(WM_HELP)
         case WM_HELP:
             {
                 HELPINFO* info = (HELPINFO*) lParam;
                 // Don't yet process menu help events, just windows
                 if (info->iContextType == HELPINFO_WINDOW)
                 {
-                    wxWindow* subjectOfHelp = this;
+                    wxWindowMSW* subjectOfHelp = this;
                     bool eventProcessed = FALSE;
                     while (subjectOfHelp && !eventProcessed)
                     {
@@ -2447,6 +2531,18 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
             }
             break;
 #endif // __WIN32__
+
+#ifdef __WXUNIVERSAL__
+        case WM_NCHITTEST:
+            // we shouldn't allow the windows which don't want to get focus to
+            // get it
+            if ( !AcceptsFocus() )
+            {
+                rc.result = HTTRANSPARENT;
+                processed = TRUE;
+            }
+            break;
+#endif // __WXUNIVERSAL__
     }
 
     if ( !processed )
@@ -2537,6 +2633,7 @@ void wxWindowMSW::MSWDestroyWindow()
 
 void wxWindowMSW::MSWDetachWindowMenu()
 {
+#ifndef __WXUNIVERSAL__
     if ( m_hMenu )
     {
         wxChar buf[1024];
@@ -2563,6 +2660,7 @@ void wxWindowMSW::MSWDetachWindowMenu()
             }
         }
     }
+#endif
 }
 
 bool wxWindowMSW::MSWCreate(int id,
@@ -2636,6 +2734,7 @@ bool wxWindowMSW::MSWCreate(int id,
 
     wxWndHook = this;
 
+#ifndef __WXMICROWIN__
     if ( dialog_template )
     {
         // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
@@ -2709,8 +2808,10 @@ bool wxWindowMSW::MSWCreate(int id,
         {
             wxLogLastError(wxT("MoveWindow"));
         }
+
     }
     else // creating a normal window, not a dialog
+#endif // !__WXMICROWIN__
     {
         int controlId = 0;
         if ( style & WS_CHILD )
@@ -2781,6 +2882,7 @@ bool wxWindowMSW::MSWCreate(int id,
 // FIXME: VZ: I'm not sure at all that the order of processing is correct
 bool wxWindowMSW::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
 {
+#ifndef __WXMICROWIN__
     LPNMHDR hdr = (LPNMHDR)lParam;
     HWND hWnd = hdr->hwndFrom;
     wxWindow *win = wxFindWinFromHandle((WXHWND)hWnd);
@@ -2806,6 +2908,9 @@ bool wxWindowMSW::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
 
     // finally try this window too (catches toolbar case)
     return MSWOnNotify(idCtrl, lParam, result);
+#else // __WXMICROWIN__
+    return FALSE;
+#endif
 }
 
 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl),
@@ -3006,6 +3111,7 @@ bool wxWindowMSW::HandleInitDialog(WXHWND WXUNUSED(hWndFocus))
 
 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam)
 {
+#ifndef __WXMICROWIN__
     HDROP hFilesInfo = (HDROP) wParam;
     POINT dropPoint;
     DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint);
@@ -3037,12 +3143,16 @@ bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam)
     delete[] files;
 
     return rc;
+#else // __WXMICROWIN__
+    return FALSE;
+#endif
 }
 
 bool wxWindowMSW::HandleSetCursor(WXHWND WXUNUSED(hWnd),
                                   short nHitTest,
                                   int WXUNUSED(mouseMsg))
 {
+#ifndef __WXMICROWIN__
     // the logic is as follows:
     // -1. don't set cursor for non client area, including but not limited to
     //     the title bar, scrollbars, &c
@@ -3119,6 +3229,7 @@ bool wxWindowMSW::HandleSetCursor(WXHWND WXUNUSED(hWnd),
         // cursor set, stop here
         return TRUE;
     }
+#endif // __WXMICROWIN__
 
     // pass up the window chain
     return FALSE;
@@ -3215,6 +3326,7 @@ bool wxWindowMSW::HandleCtlColor(WXHBRUSH *brush,
                               WXWPARAM wParam,
                               WXLPARAM lParam)
 {
+#ifndef __WXMICROWIN__
     WXHBRUSH hBrush = 0;
 
     if ( nCtlColor == CTLCOLOR_DLG )
@@ -3234,6 +3346,9 @@ bool wxWindowMSW::HandleCtlColor(WXHBRUSH *brush,
         *brush = hBrush;
 
     return hBrush != 0;
+#else // __WXMICROWIN__
+    return FALSE;
+#endif
 }
 
 // Define for each class of dialog and control
@@ -3500,7 +3615,7 @@ bool wxWindowMSW::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
 
         return GetEventHandler()->ProcessEvent(event);
     }
-#if wxUSE_SPINCTRL
+#if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
     else
     {
         // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
@@ -3625,7 +3740,7 @@ bool wxWindowMSW::HandleMouseMove(int x, int y, WXUINT flags)
 }
 
 
-bool wxWindow::HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam)
+bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam)
 {
 #if wxUSE_MOUSEWHEEL
     wxMouseEvent event(wxEVT_MOUSEWHEEL);
@@ -3804,6 +3919,7 @@ bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam)
 
 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags)
 {
+#ifdef JOY_BUTTON1
     int change = 0;
     if ( flags & JOY_BUTTON1CHG )
         change = wxJOY_BUTTON1;
@@ -3880,6 +3996,9 @@ bool wxWindowMSW::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags)
     event.SetEventObject(this);
 
     return GetEventHandler()->ProcessEvent(event);
+#else
+    return FALSE;
+#endif
 }
 
 // ---------------------------------------------------------------------------
@@ -4198,7 +4317,7 @@ extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd)
 
             // spin control text buddy window should be mapped to spin ctrl
             // itself so try it too
-#if wxUSE_SPINCTRL
+#if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
             if ( !win )
             {
                 win = wxSpinCtrl::GetSpinForTextCtrl((WXHWND)hwnd);
@@ -4224,6 +4343,8 @@ extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd)
     return win;
 }
 
+#ifndef __WXMICROWIN__
+
 // 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;
@@ -4301,6 +4422,8 @@ wxKeyboardHook(int nCode, WORD wParam, DWORD lParam)
     return (int)CallNextHookEx(wxTheKeyboardHook, nCode, wParam, lParam);
 }
 
+#endif // !__WXMICROWIN__
+
 #ifdef __WXDEBUG__
 const char *wxGetMessageName(int message)
 {