]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/window.cpp
set string length to 0 in AllocBeforeWrite() just to be tidy (replaces patch 1123226)
[wxWidgets.git] / src / msw / window.cpp
index 0597f96da22a822fe9f209fe42cf55a34f172a09..0cf5f9959cb7b9f2289a8145f9989c30590bf900 100644 (file)
@@ -54,6 +54,7 @@
 #endif
 
 #include "wx/module.h"
+#include "wx/sysopt.h"
 
 #if wxUSE_DRAG_AND_DROP
     #include "wx/dnd.h"
@@ -305,9 +306,9 @@ wxBEGIN_PROPERTIES_TABLE(wxWindow)
     wxPROPERTY( Shown , bool , Show , IsShown , wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
 #if 0
     // possible property candidates (not in xrc) or not valid in all subclasses
-    wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxT("") )
+    wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxEmptyString )
     wxPROPERTY( Font , wxFont , SetFont , GetWindowFont  , )
-    wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxT("") )
+    wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxEmptyString )
     // MaxHeight, Width , MinHeight , Width
     // TODO switch label to control and title to toplevels
 
@@ -1145,8 +1146,10 @@ WXDWORD wxWindowMSW::MSWGetStyle(long flags, WXDWORD *exstyle) const
 
     // using this flag results in very significant reduction in flicker,
     // especially with controls inside the static boxes (as the interior of the
-    // box is not redrawn twice)
-    style |= WS_CLIPCHILDREN;
+    // box is not redrawn twice).
+    // wxCLIP_CHILDREN support is for compatibility with old applications only.
+    if ((!wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children")) == 1) || (flags & wxCLIP_CHILDREN))
+        style |= WS_CLIPCHILDREN;
 
     // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
     // don't support overlapping windows and it only makes sense for them and,
@@ -1499,9 +1502,10 @@ void wxWindowMSW::DoMoveWindow(int x, int y, int width, int height)
     if (height < 0)
         height = 0;
 
-    // if our parent had prepared a defer window handle for us, use it
+    // if our parent had prepared a defer window handle for us, use it (unless
+    // we are a top level window)
     wxWindowMSW *parent = GetParent();
-    HDWP hdwp = parent ? (HDWP)parent->m_hDWP : NULL;
+    HDWP hdwp = (parent && !IsTopLevel()) ? (HDWP)parent->m_hDWP : NULL;
     if ( hdwp )
     {
         hdwp = ::DeferWindowPos(hdwp, GetHwnd(), NULL,
@@ -1650,13 +1654,6 @@ void wxWindowMSW::DoSetClientSize(int width, int height)
     }
 }
 
-// For implementation purposes - sometimes decorations make the client area
-// smaller
-wxPoint wxWindowMSW::GetClientAreaOrigin() const
-{
-    return wxPoint(0, 0);
-}
-
 // ---------------------------------------------------------------------------
 // text metrics
 // ---------------------------------------------------------------------------
@@ -1831,7 +1828,8 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
             }
 
             bool bForward = true,
-                 bWindowChange = false;
+                 bWindowChange = false,
+                 bFromTab = false;
 
             // should we process this message specially?
             bool bProcess = true;
@@ -1845,6 +1843,7 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
                         // Ctrl-Tab cycles thru notebook pages
                         bWindowChange = bCtrlDown;
                         bForward = !bShiftDown;
+                        bFromTab = true;
                     }
                     break;
 
@@ -1969,6 +1968,7 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
                 wxNavigationKeyEvent event;
                 event.SetDirection(bForward);
                 event.SetWindowChange(bWindowChange);
+                event.SetFromTab(bFromTab);
                 event.SetEventObject(this);
 
                 if ( GetEventHandler()->ProcessEvent(event) )
@@ -2229,49 +2229,6 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
             (void)HandleDestroy();
             break;
 
-#ifndef __SMARTPHONE__ // or wxWinCE in general ?
-        case WM_WINDOWPOSCHANGING:
-            {
-                WINDOWPOS *wp = wx_reinterpret_cast(WINDOWPOS *, lParam);
-
-                if ( wp->flags & SWP_NOSIZE )
-                    break;
-
-                // when we resize this window, its children are probably going
-                // to be repositioned as well, prepare to use DeferWindowPos()
-                // for them
-                const int numChildren = GetChildren().GetCount();
-                if ( numChildren > 1 )
-                {
-                    m_hDWP = (WXHANDLE)::BeginDeferWindowPos(numChildren);
-                    if ( !m_hDWP )
-                    {
-                        wxLogLastError(_T("BeginDeferWindowPos"));
-                    }
-                }
-            }
-            break;
-
-        case WM_WINDOWPOSCHANGED:
-            // first let DefWindowProc() handle the message: it will generate
-            // WM_MOVE and WM_SIZE as needed
-            processed = MSWDefWindowProc(message, wParam, lParam) == 0;
-
-            // then change the positions of all child windows at once
-            if ( m_hDWP )
-            {
-                HDWP hDWP = (HDWP)m_hDWP;
-                m_hDWP = NULL;
-
-                // put all child controls in place at once now
-                if ( !::EndDeferWindowPos(hDWP) )
-                {
-                    wxLogLastError(_T("EndDeferWindowPos"));
-                }
-            }
-            break;
-#endif // __SMARTPHONE__
-
         case WM_SIZE:
             processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
             break;
@@ -2281,7 +2238,6 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
             break;
 
 #if !defined(__WXWINCE__)
-        // TODO: move those in WM_WINDOWPOSCHANGING case above
         case WM_MOVING:
             {
                 LPRECT pRect = (LPRECT)lParam;
@@ -2358,23 +2314,26 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
                 break;
             }
 
-#ifndef __WXWINCE__
-        case WM_PRINT:
+#ifdef WM_PRINT
+        case WM_PRINTCLIENT:
+            if ( GetParent() &&
+                    GetParent()->MSWPrintChild(this, wParam, lParam) )
             {
-#if wxUSE_LISTCTRL
-                // Don't call the wx handlers in this case
-                if ( wxIsKindOf(this, wxListCtrl) )
-                    break;
-#endif
+                processed = true;
+            }
+            break;
 
+        case WM_PRINT:
+            {
                 if ( lParam & PRF_ERASEBKGND )
                     HandleEraseBkgnd((WXHDC)(HDC)wParam);
 
                 wxPaintDCEx dc((wxWindow *)this, (WXHDC)wParam);
+
                 processed = HandlePaint();
             }
             break;
-#endif
+#endif // WM_PRINT
 
         case WM_CLOSE:
 #ifdef __WXUNIVERSAL__
@@ -2829,7 +2788,7 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
                         wxHelpEvent helpEvent(wxEVT_HELP,
                                               subjectOfHelp->GetId(),
 #ifdef __WXWINCE__
-                                              wxPoint(0, 0)
+                                              wxPoint(0,0)
 #else
                                               wxPoint(info->MousePos.x, info->MousePos.y)
 #endif
@@ -3082,42 +3041,22 @@ bool wxWindowMSW::MSWCreate(const wxChar *wclass,
     // do create the window
     wxWindowCreationHook hook(this);
 
-    // VZ: anyone care to explain why this is done for CE?
-#ifdef __WXWINCE__
-    if (extendedStyle == 0)
-    {
-        m_hWnd = (WXHWND)::CreateWindow
-            (
-            className,
-            title ? title : wxEmptyString,
-            style,
-            x, y, w, h,
-            (HWND)MSWGetParent(),
-            (HMENU)controlId,
-            wxGetInstance(),
-            NULL                        // no extra data
-            );
-    }
-    else
-#endif // __WXWINCE__
-    {
-        m_hWnd = (WXHWND)::CreateWindowEx
-            (
-            extendedStyle,
-            className,
-            title ? title : wxEmptyString,
-            style,
-            x, y, w, h,
-            (HWND)MSWGetParent(),
-            (HMENU)controlId,
-            wxGetInstance(),
-            NULL                        // no extra data
-            );
-    }
+    m_hWnd = (WXHWND)::CreateWindowEx
+                       (
+                        extendedStyle,
+                        className,
+                        title ? title : m_windowName.c_str(),
+                        style,
+                        x, y, w, h,
+                        (HWND)MSWGetParent(),
+                        (HMENU)controlId,
+                        wxGetInstance(),
+                        NULL                        // no extra data
+                       );
 
     if ( !m_hWnd )
     {
-        wxLogSysError(_("Can't create window of class %s"), wclass);
+        wxLogSysError(_("Can't create window of class %s"), className.c_str());
 
         return false;
     }
@@ -4108,6 +4047,14 @@ WXHBRUSH wxWindowMSW::MSWGetBgBrush(WXHDC hDC)
     return 0;
 }
 
+bool
+wxWindowMSW::MSWPrintChild(wxWindow * WXUNUSED(win),
+                           WXWPARAM WXUNUSED(wParam),
+                           WXLPARAM WXUNUSED(lParam))
+{
+    return false;
+}
+
 // ---------------------------------------------------------------------------
 // moving and resizing
 // ---------------------------------------------------------------------------
@@ -4150,8 +4097,20 @@ bool wxWindowMSW::HandleMoving(wxRect& rect)
 
 bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h), WXUINT wParam)
 {
-    bool processed = false;
+    // when we resize this window, its children are probably going to be
+    // repositioned as well, prepare to use DeferWindowPos() for them
+    const int numChildren = GetChildren().GetCount();
+    if ( numChildren > 1 )
+    {
+        m_hDWP = (WXHANDLE)::BeginDeferWindowPos(numChildren);
+        if ( !m_hDWP )
+        {
+            wxLogLastError(_T("BeginDeferWindowPos"));
+        }
+    }
 
+    // update this window size
+    bool processed = false;
     switch ( wParam )
     {
         default:
@@ -4181,6 +4140,23 @@ bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h), WXUINT wParam)
             processed = GetEventHandler()->ProcessEvent(event);
     }
 
+    // and finally change the positions of all child windows at once
+    if ( m_hDWP )
+    {
+        // reset m_hDWP to NULL so that child windows don't try to use our
+        // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
+        // happen anyhow normally but who knows what weird flow of control we
+        // may have depending on what the users EVT_SIZE handler does...)
+        HDWP hDWP = (HDWP)m_hDWP;
+        m_hDWP = NULL;
+
+        // do put all child controls in place at once
+        if ( !::EndDeferWindowPos(hDWP) )
+        {
+            wxLogLastError(_T("EndDeferWindowPos"));
+        }
+    }
+
     return processed;
 }
 
@@ -4978,7 +4954,7 @@ int wxCharCodeMSWToWX(int keySym, WXLPARAM lParam)
         case VK_CLEAR:      id = WXK_CLEAR; break;
         case VK_SHIFT:      id = WXK_SHIFT; break;
         case VK_CONTROL:    id = WXK_CONTROL; break;
-        case VK_MENU :      id = WXK_MENU; break;
+        case VK_MENU :      id = WXK_ALT; break;
         case VK_PAUSE:      id = WXK_PAUSE; break;
         case VK_CAPITAL:    id = WXK_CAPITAL; break;
         case VK_SPACE:      id = WXK_SPACE; break;
@@ -5084,7 +5060,6 @@ WXWORD wxCharCodeWXToMSW(int id, bool *isVirtual)
     case WXK_SHIFT:     keySym = VK_SHIFT; break;
     case WXK_CONTROL:   keySym = VK_CONTROL; break;
     case WXK_ALT:       keySym = VK_MENU; break;
-    case WXK_MENU :     keySym = VK_MENU; break;
     case WXK_PAUSE:     keySym = VK_PAUSE; break;
     case WXK_CAPITAL:   keySym = VK_CAPITAL; break;
     case WXK_PRIOR:     keySym = VK_PRIOR; break;