]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/window.cpp
Added support for delayed deactivation of windows (for MDI)
[wxWidgets.git] / src / msw / window.cpp
index 1da351142c9f5579df63cff931be33fe5a7c25be..9c8a049a45272eaaff7c77371822b8bb4fb1f77b 100644 (file)
@@ -60,6 +60,7 @@
 
 #if wxUSE_ACCESSIBILITY
     #include "wx/access.h"
+    #include <ole2.h>
     #include <oleacc.h>
     #ifndef WM_GETOBJECT
         #define WM_GETOBJECT 0x003D
     #include <windowsx.h>
 #endif
 
-#if (!defined(__GNUWIN32_OLD__) && !defined(__TWIN32__) && !defined(__WXMICROWIN__)) || defined(__CYGWIN10__)
+#if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__)) || defined(__CYGWIN10__)
     #ifdef __WIN95__
         #include <commctrl.h>
     #endif
 #elif !defined(__WXMICROWIN__) // broken compiler
-    #ifndef __TWIN32__
-        #include "wx/msw/gnuwin32/extra.h"
-    #endif
+    #include "wx/msw/gnuwin32/extra.h"
+#endif
+
+#if defined(__GNUG__)
+#include "wx/msw/missing.h"
 #endif
 
 // ----------------------------------------------------------------------------
 
 #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_7        0xDE
 #endif
 
+#ifndef VK_OEM_COMMA
+    #define VK_OEM_PLUS     0xBB
+    #define VK_OEM_COMMA    0xBC
+    #define VK_OEM_MINUS    0xBD
+    #define VK_OEM_PERIOD   0xBE
+#endif
+
 // ---------------------------------------------------------------------------
 // global variables
 // ---------------------------------------------------------------------------
@@ -211,15 +217,13 @@ static inline void wxBringWindowToTop(HWND hwnd)
 
     // activate (set focus to) specified window
     ::SetFocus(hwnd);
+#endif
 
     // raise top level parent to top of z order
-    ::SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
-#else // !__WXMICROWIN__
-    if ( !::BringWindowToTop(hwnd) )
+    if (!::SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE))
     {
-        wxLogLastError(_T("BringWindowToTop"));
+        wxLogLastError(_T("SetWindowPos"));
     }
-#endif // __WXMICROWIN__/!__WXMICROWIN__
 }
 
 // ---------------------------------------------------------------------------
@@ -577,7 +581,7 @@ bool wxWindowMSW::Show(bool show)
     int cshow = show ? SW_SHOW : SW_HIDE;
     ::ShowWindow(hWnd, cshow);
 
-    if ( show )
+    if ( show && IsTopLevel() )
     {
         wxBringWindowToTop(hWnd);
     }
@@ -697,7 +701,7 @@ void wxWindowMSW::MSWDeviceToLogical (float *x, float *y) const
 // ---------------------------------------------------------------------------
 
 // convert wxHORIZONTAL/wxVERTICAL to SB_HORZ/SB_VERT
-static inline wxDirToWinStyle(int orient)
+static inline int wxDirToWinStyle(int orient)
 {
     return orient == wxHORIZONTAL ? SB_HORZ : SB_VERT;
 }
@@ -1024,6 +1028,12 @@ WXDWORD wxWindowMSW::MSWGetStyle(long flags, WXDWORD *exstyle) const
     if ( flags & wxCLIP_SIBLINGS )
         style |= WS_CLIPSIBLINGS;
 
+    if ( flags & wxVSCROLL )
+        style |= WS_VSCROLL;
+
+    if ( flags & wxHSCROLL )
+        style |= WS_HSCROLL;
+
     wxBorder border = (wxBorder)(flags & wxBORDER_MASK);
     
     // Check if we want to automatically give it a sunken style.
@@ -1032,7 +1042,9 @@ WXDWORD wxWindowMSW::MSWGetStyle(long flags, WXDWORD *exstyle) const
     // Windows XP. Instead we get the appropriate style for the theme.
 
     if (border == wxBORDER_DEFAULT && wxTheApp->GetAuto3D() && 
-        GetParent() && GetParent()->IsKindOf(CLASSINFO(wxPanel)) &&
+        IsKindOf(CLASSINFO(wxControl)) &&
+        GetParent() && (GetParent()->IsKindOf(CLASSINFO(wxPanel)) ||
+                        GetParent()->IsKindOf(CLASSINFO(wxDialog))) &&
         ((GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS))
     {
         border = (wxBorder)((flags & wxBORDER_MASK) | wxBORDER_SUNKEN);
@@ -1066,7 +1078,7 @@ WXDWORD wxWindowMSW::MSWGetStyle(long flags, WXDWORD *exstyle) const
                 break;
 
             case wxBORDER_RAISED:
-                *exstyle |= WS_EX_WINDOWEDGE;
+                *exstyle |= WS_EX_DLGMODALFRAME;
                 break;
 
             case wxBORDER_SUNKEN:
@@ -2180,6 +2192,24 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
             processed = HandleMove(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
             break;
 
+        case WM_MOVING:
+                       {
+                               LPRECT pRect = (LPRECT)lParam;
+                               wxRect rc;
+                               rc.SetLeft(pRect->left);
+                               rc.SetTop(pRect->top);
+                               rc.SetRight(pRect->right);
+                               rc.SetBottom(pRect->bottom);
+                               processed = HandleMoving(rc);
+                               if (processed) {
+                                       pRect->left = rc.GetLeft();
+                                       pRect->top = rc.GetTop();
+                                       pRect->right = rc.GetRight();
+                                       pRect->bottom = rc.GetBottom();
+                               }
+                       }
+            break;
+
         case WM_SIZE:
             switch ( wParam )
             {
@@ -2208,6 +2238,24 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
             }
             break;
 
+        case WM_SIZING:
+            {
+                LPRECT pRect = (LPRECT)lParam;
+                wxRect rc;
+                rc.SetLeft(pRect->left);
+                rc.SetTop(pRect->top);
+                rc.SetRight(pRect->right);
+                rc.SetBottom(pRect->bottom);
+                processed = HandleSizing(rc);
+                if (processed) {
+                    pRect->left = rc.GetLeft();
+                    pRect->top = rc.GetTop();
+                    pRect->right = rc.GetRight();
+                    pRect->bottom = rc.GetBottom();
+                }
+            }
+            break;
+
 #ifndef __WXMICROWIN__
         case WM_ACTIVATEAPP:
             wxTheApp->SetActive(wParam != 0, FindFocus());
@@ -3389,16 +3437,21 @@ bool wxWindowMSW::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct)
     }
 #endif // wxUSE_MENUS_NATIVE
 
+#endif // USE_OWNER_DRAWN
+
 #if wxUSE_CONTROLS
+
     wxWindow *item = FindItem(id);
+#if wxUSE_OWNER_DRAWN
     if ( item && item->IsKindOf(CLASSINFO(wxControl)) )
-    {
         return ((wxControl *)item)->MSWOnDraw(itemStruct);
-    }
-#endif // wxUSE_CONTROLS
-
+#else
+    if ( item && item->IsKindOf(CLASSINFO(wxButton)) )
+        return ((wxButton *)item)->MSWOnDraw(itemStruct);
 #endif // USE_OWNER_DRAWN
 
+#endif // wxUSE_CONTROLS
+
     return FALSE;
 }
 
@@ -3691,6 +3744,9 @@ extern wxCOLORMAP *wxGetStdColourMap()
 
 bool wxWindowMSW::HandlePaint()
 {
+//    if (GetExtraStyle() & wxWS_EX_THEMED_BACKGROUND)
+//        return FALSE;
+    
 #ifdef __WIN32__
     HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
     if ( !hRegion )
@@ -3743,6 +3799,29 @@ bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc)
     if ( ::IsIconic(GetHwnd()) )
         return TRUE;
 
+#if 0
+    if (GetParent() && GetParent()->GetExtraStyle() & wxWS_EX_THEMED_BACKGROUND)
+    {
+        return FALSE;
+    }
+
+    if (GetExtraStyle() & wxWS_EX_THEMED_BACKGROUND)
+    {
+        if (wxUxThemeEngine::Get())
+        {
+            WXHTHEME hTheme = wxUxThemeEngine::Get()->m_pfnOpenThemeData(GetHWND(), L"TAB");
+            if (hTheme)
+            {
+                WXURECT rect;
+                ::GetClientRect((HWND) GetHWND(), (RECT*) & rect);
+                wxUxThemeEngine::Get()->m_pfnDrawThemeBackground(hTheme, hdc, 10 /* TABP_BODY */, 0, &rect, &rect);
+                wxUxThemeEngine::Get()->m_pfnCloseThemeData(hTheme);
+                return TRUE;
+            }
+        }
+    }
+#endif
+    
     wxDCTemp dc(hdc);
 
     dc.SetHDC(hdc);
@@ -3810,6 +3889,17 @@ bool wxWindowMSW::HandleMove(int x, int y)
     return GetEventHandler()->ProcessEvent(event);
 }
 
+bool wxWindowMSW::HandleMoving(wxRect& rect)
+{
+    wxMoveEvent event(rect, m_windowId);
+    event.SetEventObject(this);
+    
+    bool rc = GetEventHandler()->ProcessEvent(event);
+    if (rc)
+        rect = event.GetRect();
+    return rc;
+}
+
 bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h),
                              WXUINT WXUNUSED(flag))
 {
@@ -3822,6 +3912,17 @@ bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h),
     return GetEventHandler()->ProcessEvent(event);
 }
 
+bool wxWindowMSW::HandleSizing(wxRect& rect)
+{
+    wxSizeEvent event(rect, m_windowId);
+    event.SetEventObject(this);
+    
+    bool rc = GetEventHandler()->ProcessEvent(event);
+    if (rc)
+        rect = event.GetRect();
+    return rc;
+}
+
 bool wxWindowMSW::HandleGetMinMaxInfo(void *mmInfo)
 {
     MINMAXINFO *info = (MINMAXINFO *)mmInfo;
@@ -3961,7 +4062,10 @@ void wxWindowMSW::InitMouseEvent(wxMouseEvent& event,
     event.m_leftDown = (flags & MK_LBUTTON) != 0;
     event.m_middleDown = (flags & MK_MBUTTON) != 0;
     event.m_rightDown = (flags & MK_RBUTTON) != 0;
-    event.m_altDown = (::GetKeyState(VK_MENU) & 0x80000000) != 0;
+ //   event.m_altDown = (::GetKeyState(VK_MENU) & 0x80000000) != 0;
+    // Returns different negative values on WinME and WinNT,
+    // so simply test for negative value.
+    event.m_altDown = ::GetKeyState(VK_MENU) < 0;
 
     event.SetTimestamp(s_currentMsg.time);
     event.m_eventObject = this;
@@ -4816,7 +4920,7 @@ void wxSetKeyboardHook(bool doIt)
         wxTheKeyboardHookProc = MakeProcInstance((FARPROC) wxKeyboardHook, wxGetInstance());
         wxTheKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) wxTheKeyboardHookProc, wxGetInstance(),
 
-#if defined(__WIN32__) && !defined(__TWIN32__)
+#if defined(__WIN32__)
             GetCurrentThreadId()
         //      (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
 #else