]> git.saurik.com Git - wxWidgets.git/commitdiff
decreased text limit which we consider to be set by user (and not built in the contro...
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 29 Jul 2005 23:01:56 +0000 (23:01 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 29 Jul 2005 23:01:56 +0000 (23:01 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35005 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/textctrl.h
src/msw/textctrl.cpp

index 5d7815f099d1200fcc65e1919642aeb14a780d0b..4b2b906625b4ee6867c2cdb3718e1436841ac987 100644 (file)
@@ -201,6 +201,10 @@ protected:
     // intercept WM_GETDLGCODE
     virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
 
+    // return true if this control has a user-set limit on amount of text (i.e.
+    // the limit is due to a previous call to SetMaxLength() and not built in)
+    bool HasSpaceLimit(unsigned int *len) const;
+
     // call this to increase the size limit (will do nothing if the current
     // limit is big enough)
     //
index bcabaabb7d0cb12d81419a78967082e49a36fd9e..3cb69ee2677c49da33b1b8693cbeaa9dfa8eba9d 100644 (file)
@@ -1560,11 +1560,22 @@ wxString wxTextCtrl::GetLineText(long lineNo) const
 void wxTextCtrl::SetMaxLength(unsigned long len)
 {
 #if wxUSE_RICHEDIT
-    if (IsRich())
-        ::SendMessage(GetHwnd(), EM_EXLIMITTEXT, 0, (LPARAM) (DWORD) len);
+    if ( IsRich() )
+    {
+        ::SendMessage(GetHwnd(), EM_EXLIMITTEXT, 0, len ? len : 0x7fffffff);
+    }
     else
-#endif
-    ::SendMessage(GetHwnd(), EM_LIMITTEXT, len, 0);
+#endif // wxUSE_RICHEDIT
+    {
+        if ( len >= 0xffff )
+        {
+            // this will set it to a platform-dependent maximum (much more
+            // than 64Kb under NT)
+            len = 0;
+        }
+
+        ::SendMessage(GetHwnd(), EM_LIMITTEXT, len, 0);
+    }
 }
 
 // ----------------------------------------------------------------------------
@@ -1894,48 +1905,36 @@ WXHBRUSH wxTextCtrl::MSWControlColor(WXHDC hDC, WXHWND hWnd)
     return wxTextCtrlBase::MSWControlColor(hDC, hWnd);
 }
 
-bool wxTextCtrl::AdjustSpaceLimit()
+bool wxTextCtrl::HasSpaceLimit(unsigned int *len) const
 {
-    unsigned int limit = ::SendMessage(GetHwnd(), EM_GETLIMITTEXT, 0, 0);
-
     // HACK: we try to automatically extend the limit for the amount of text
     //       to allow (interactively) entering more than 64Kb of text under
     //       Win9x but we shouldn't reset the text limit which was previously
     //       set explicitly with SetMaxLength()
     //
-    //       we could solve this by storing the limit we set in wxTextCtrl but
-    //       to save space we prefer to simply test here the actual limit
-    //       value: we consider that SetMaxLength() can only be called for
-    //       values < 32Kb
-    if ( limit < 0x8000 )
-    {
-        // we've got more text than limit set by SetMaxLength()
+    //       Unfortunately there is no EM_GETLIMITTEXTSETBYUSER and so we don't
+    //       know the limit we set (if any). We could solve this by storing the
+    //       limit we set in wxTextCtrl but to save space we prefer to simply
+    //       test here the actual limit value: we consider that SetMaxLength()
+    //       can only be called for small values while EN_MAXTEXT is only sent
+    //       for large values (in practice the default limit seems to be 30000
+    //       but make it smaller just to be on the safe side)
+    *len = ::SendMessage(GetHwnd(), EM_GETLIMITTEXT, 0, 0);
+    return *len < 10001;
+
+}
+
+bool wxTextCtrl::AdjustSpaceLimit()
+{
+    unsigned int limit;
+    if ( HasSpaceLimit(&limit) )
         return false;
-    }
 
     unsigned int len = ::GetWindowTextLength(GetHwnd());
     if ( len >= limit )
     {
-        limit = len + 0x8000;    // 32Kb
-
-#if wxUSE_RICHEDIT
-        if ( IsRich() )
-        {
-            // as a nice side effect, this also allows passing limit > 64Kb
-            ::SendMessage(GetHwnd(), EM_EXLIMITTEXT, 0, limit);
-        }
-        else
-#endif // wxUSE_RICHEDIT
-        {
-            if ( limit > 0xffff )
-            {
-                // this will set it to a platform-dependent maximum (much more
-                // than 64Kb under NT)
-                limit = 0;
-            }
-
-            ::SendMessage(GetHwnd(), EM_LIMITTEXT, limit, 0);
-        }
+        // increment in 32Kb chunks
+        SetMaxLength(len + 0x8000);
     }
 
     // we changed the limit