]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/window.cpp
Decided that not doing methods for keyboard commands was not worth the
[wxWidgets.git] / src / msw / window.cpp
index d58cf40d7eb20966f1818b5bdbc0983a5f0e7818..9a4db982419fbb4a887d8535ee54821949316811 100644 (file)
@@ -431,6 +431,7 @@ void wxWindowMSW::Init()
     m_lastKeydownProcessed = false;
 
     m_childrenDisabled = NULL;
+    m_frozenness = 0;
 
     // wxWnd
     m_hMenu = 0;
@@ -1294,16 +1295,24 @@ static inline void SendSetRedraw(HWND hwnd, bool on)
 
 void wxWindowMSW::Freeze()
 {
-    SendSetRedraw(GetHwnd(), false);
+    if ( !m_frozenness++ )
+    {
+        SendSetRedraw(GetHwnd(), false);
+    }
 }
 
 void wxWindowMSW::Thaw()
 {
-    SendSetRedraw(GetHwnd(), true);
+    wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") );
+
+    if ( !--m_frozenness )
+    {
+        SendSetRedraw(GetHwnd(), true);
 
-    // we need to refresh everything or otherwise he invalidated area is not
-    // repainted
-    Refresh();
+        // we need to refresh everything or otherwise he invalidated area is not
+        // repainted
+        Refresh();
+    }
 }
 
 void wxWindowMSW::Refresh(bool eraseBack, const wxRect *rect)
@@ -2984,8 +2993,6 @@ bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint& pos,
 {
     // yes, those are just some arbitrary hardcoded numbers
     static const int DEFAULT_Y = 200;
-    static const int DEFAULT_W = 400;
-    static const int DEFAULT_H = 250;
 
     bool nonDefault = false;
 
@@ -3023,36 +3030,31 @@ bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint& pos,
           this and ignore any attempts to change the window size to the size it
           already has - so no WM_SIZE would be sent.
      */
-    if ( size.x == -1 )
-    {
-        // we don't use CW_USEDEFAULT here for several reasons:
-        //
-        //  1. it results in huge frames on modern screens (1000*800 is not
-        //     uncommon on my 1280*1024 screen) which is way too big for a half
-        //     empty frame of most of wxWindows samples for example)
-        //
-        //  2. it is buggy for frames with wxFRAME_TOOL_WINDOW style for which
-        //     the default is for whatever reason 8*8 which breaks client <->
-        //     window size calculations (it would be nice if it didn't, but it
-        //     does and the simplest way to fix it seemed to change the broken
-        //     default size anyhow)
-        //
-        //  3. there is just no advantage in doing it: with x and y it is
-        //     possible that [future versions of] Windows position the new top
-        //     level window in some smart way which we can't do, but we can
-        //     guess a reasonably good size for a new window just as well
-        //     ourselves
-        w = DEFAULT_W;
-        h = DEFAULT_H;
-    }
-    else
-    {
-        // and, again as above, we can't set the height to CW_USEDEFAULT here
-        w = size.x;
-        h = size.y == -1 ? DEFAULT_H  : size.y;
 
+    
+    // we don't use CW_USEDEFAULT here for several reasons:
+    //
+    //  1. it results in huge frames on modern screens (1000*800 is not
+    //     uncommon on my 1280*1024 screen) which is way too big for a half
+    //     empty frame of most of wxWindows samples for example)
+    //
+    //  2. it is buggy for frames with wxFRAME_TOOL_WINDOW style for which
+    //     the default is for whatever reason 8*8 which breaks client <->
+    //     window size calculations (it would be nice if it didn't, but it
+    //     does and the simplest way to fix it seemed to change the broken
+    //     default size anyhow)
+    //
+    //  3. there is just no advantage in doing it: with x and y it is
+    //     possible that [future versions of] Windows position the new top
+    //     level window in some smart way which we can't do, but we can
+    //     guess a reasonably good size for a new window just as well
+    //     ourselves
+    if ( size.x == -1 || size.y == -1)
+    {
         nonDefault = true;
     }
+    w = WidthDefault(size.x);
+    h = HeightDefault(size.y);
 
     AdjustForParentClientOrigin(x, y);
 
@@ -3200,7 +3202,8 @@ bool wxWindowMSW::HandleTooltipNotify(WXUINT code,
     // we need to handle it as well, otherwise no tooltips will be shown in
     // this case
 #ifndef __WXWINCE__
-    if ( !(code == (WXUINT) TTN_NEEDTEXTA || code == (WXUINT) TTN_NEEDTEXTW) || ttip.empty() )
+    if ( !(code == (WXUINT) TTN_NEEDTEXTA || code == (WXUINT) TTN_NEEDTEXTW)
+            || ttip.empty() )
     {
         // not a tooltip message or no tooltip to show anyhow
         return false;
@@ -3209,41 +3212,58 @@ bool wxWindowMSW::HandleTooltipNotify(WXUINT code,
 
     LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
 
+    // We don't want to use the szText buffer because it has a limit of 80
+    // bytes and this is not enough, especially for Unicode build where it
+    // limits the tooltip string length to only 40 characters
+    //
+    // The best would be, of course, to not impose any length limitations at
+    // all but then the buffer would have to be dynamic and someone would have
+    // to free it and we don't have the tooltip owner object here any more, so
+    // for now use our own static buffer with a higher fixed max length.
+    //
+    // Note that using a static buffer should not be a problem as only a single
+    // tooltip can be shown at the same time anyhow.
 #if !wxUSE_UNICODE
-    if ( code == (WXUINT) TTN_NEEDTEXTA )
-    {
-        // we pass just the pointer as we store the string internally anyhow
-        ttText->lpszText = (char *)ttip.c_str();
-    }
-    else // TTN_NEEDTEXTW
-#endif // !Unicode
+    if ( code == (WXUINT) TTN_NEEDTEXTW )
     {
-#if wxUSE_UNICODE
-        // in Unicode mode this is just what we need
-        ttText->lpszText = (wxChar *)ttip.c_str();
-#else // !Unicode
-        // Convert tooltip from multi byte to Unicode.
-
-        // We don't want to use the szText buffer because it has a limit of 80
-        // bytes, for now use our own static buffer with a higher fixed max
-        // length.
-        // Preferably a dynamic buffer should be used, but who frees the buffer?
+        // We need to convert tooltip from multi byte to Unicode on the fly.
+        static wchar_t buf[513];
 
-        static const int MAX_LENGTH = 512;
-        static wchar_t buf[MAX_LENGTH+1];
-
-        ttText->lpszText = (LPSTR) buf;
-
-        // Truncate tooltip length if needed
-        size_t tipLength = wxMin(ttip.Len(), MAX_LENGTH);
+        // Truncate tooltip length if needed as otherwise we might not have
+        // enough space for it in the buffer and MultiByteToWideChar() would
+        // return an error
+        size_t tipLength = wxMin(ttip.Len(), WXSIZEOF(buf) - 1);
 
         // Convert to WideChar without adding the NULL character. The NULL
         // character is added afterwards (this is more efficient).
-        ::MultiByteToWideChar(CP_ACP, 0, ttip, tipLength, buf, MAX_LENGTH);
-
-        buf[tipLength] = '\0';
+        int len = ::MultiByteToWideChar
+                    (
+                        CP_ACP,
+                        0,                      // no flags
+                        ttip,
+                        tipLength,
+                        buf,
+                        WXSIZEOF(buf) - 1
+                    );
+
+        if ( !len )
+        {
+            wxLogLastError(_T("MultiByteToWideChar()"));
+        }
 
-#endif // Unicode/!Unicode
+        buf[len] = L'\0';
+        ttText->lpszText = (LPSTR) buf;
+    }
+    else // TTN_NEEDTEXTA
+#endif // !wxUSE_UNICODE
+    {
+        // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
+        // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
+        // to copy the string we have into the buffer
+        static wxChar buf[513];
+        wxStrncpy(buf, ttip.c_str(), WXSIZEOF(buf) - 1);
+        buf[WXSIZEOF(buf) - 1] = _T('\0');
+        ttText->lpszText = buf;
     }
 
     return true;