]> git.saurik.com Git - wxWidgets.git/commitdiff
Explicitly set margins for single line text controls in wxMSW.
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 4 Dec 2012 00:39:37 +0000 (00:39 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 4 Dec 2012 00:39:37 +0000 (00:39 +0000)
The margin used by them was inconsistent and depended on the initial size the
control was created with for some reason. Call EM_SETMARGINS explicitly to
ensure consistent appearance in all cases.

Closes #2438.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73126 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/textctrl.cpp

index 4245b581258ad8b6941504df73b4fcb3061bdec1..fcdb1ab1110f1daf3d2f83ada7bcaf5bb4aa62ee 100644 (file)
@@ -499,7 +499,23 @@ bool wxTextCtrl::MSWCreateText(const wxString& value,
     SetWindowPos(GetHwnd(), NULL, 0, 0, 0, 0,
                 SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
                 SWP_FRAMECHANGED);
-#endif
+
+    if ( IsSingleLine() )
+    {
+        // If we don't set the margins explicitly, their size depends on the
+        // control initial size, see #2438. So explicitly set them to something
+        // consistent. And for this we have 2 candidates: EC_USEFONTINFO (which
+        // sets the left margin to 3 pixels, at least under Windows 7) or 0. We
+        // use the former because it looks like it was meant to be used as the
+        // default (what else would it be there for?) and 0 looks bad in
+        // classic mode, i.e. without themes. Also, the margin can be reset to
+        // 0 easily by calling SetMargins() explicitly but setting it to the
+        // default value is not currently supported.
+        ::SendMessage(GetHwnd(), EM_SETMARGINS,
+                      EC_LEFTMARGIN | EC_RIGHTMARGIN,
+                      MAKELPARAM(EC_USEFONTINFO, EC_USEFONTINFO));
+    }
+#endif // !__WXWINCE__
 
     return true;
 }