]> git.saurik.com Git - wxWidgets.git/commitdiff
support multiline labels in wxCheckBox (#9495)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Jun 2008 01:54:44 +0000 (01:54 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Jun 2008 01:54:44 +0000 (01:54 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54008 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/msw/checkbox.h
include/wx/msw/private/button.h [new file with mode: 0644]
src/msw/button.cpp
src/msw/checkbox.cpp

index 3656438378caa2098a80b9407900a249848aeb88..a16acebb9f00337b1a8cc85a5e50f6ffefbe97f6 100644 (file)
@@ -393,6 +393,7 @@ wxMSW:
 - Show resize gripper on resizeable dialogs (Kolya Kosenko)
 - Implement support for display enumeration under WinCE (Vince Harron)
 - Use different Win32 class names in different wx instances (Thomas Hauk)
+- Support multiline labels for wxCheckBox.
 
 wxX11:
 
index dfdcf427188f872043eb4c4d012ebd51ce3fdd0c..275fed537bbbe3bb4daad16e5747852aec82f2e5 100644 (file)
@@ -42,6 +42,8 @@ public:
     virtual bool GetValue() const;
 
     // override some base class virtuals
+    virtual void SetLabel(const wxString& label);
+
     virtual bool MSWCommand(WXUINT param, WXWORD id);
     virtual void Command(wxCommandEvent& event);
     virtual bool SetForegroundColour(const wxColour& colour);
diff --git a/include/wx/msw/private/button.h b/include/wx/msw/private/button.h
new file mode 100644 (file)
index 0000000..ac6393d
--- /dev/null
@@ -0,0 +1,46 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        msw/private/button.h
+// Purpose:     helper functions used with native BUTTON control
+// Author:      Vadim Zeitlin
+// Created:     2008-06-07
+// RCS-ID:      $Id$
+// Copyright:   (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
+// Licence:     wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_MSW_PRIVATE_BUTTON_H_
+#define _WX_MSW_PRIVATE_BUTTON_H_
+
+namespace wxMSWButton
+{
+
+// returns BS_MULTILINE if the label contains new lines or 0 otherwise
+inline int GetMultilineStyle(const wxString& label)
+{
+    return label.find(_T('\n')) == wxString::npos ? 0 : BS_MULTILINE;
+}
+
+// update the style of the specified HWND to include or exclude BS_MULTILINE
+// depending on whether the label contains the new lines
+inline void UpdateMultilineStyle(HWND hwnd, const wxString& label)
+{
+    // update BS_MULTILINE style depending on the new label (resetting it
+    // doesn't seem to do anything very useful but it shouldn't hurt and we do
+    // have to set it whenever the label becomes multi line as otherwise it
+    // wouldn't be shown correctly as we don't use BS_MULTILINE when creating
+    // the control unless it already has new lines in its label)
+    long styleOld = ::GetWindowLong(hwnd, GWL_STYLE),
+         styleNew;
+    if ( label.find(_T('\n')) != wxString::npos )
+        styleNew = styleOld | BS_MULTILINE;
+    else
+        styleNew = styleOld & ~BS_MULTILINE;
+
+    if ( styleNew != styleOld )
+        ::SetWindowLong(hwnd, GWL_STYLE, styleNew);
+}
+
+} // namespace wxMSWButton
+
+#endif // _WX_MSW_PRIVATE_BUTTON_H_
+
index 9ccd939cc16f17233e46eb52ed8e5e77c9962318..b342fbc0b25712e49ebefd7104da1fd3c3af0908 100644 (file)
@@ -40,8 +40,8 @@
 #endif
 
 #include "wx/stockitem.h"
-#include "wx/tokenzr.h"
 #include "wx/msw/private.h"
+#include "wx/msw/private/button.h"
 
 #if wxUSE_UXTHEME
     #include "wx/msw/uxtheme.h"
@@ -183,10 +183,7 @@ bool wxButton::Create(wxWindow *parent,
     //
     // NB: we do it here and not in MSWGetStyle() because we need the label
     //     value and the label is not set yet when MSWGetStyle() is called
-    if ( label.find(_T('\n')) != wxString::npos )
-    {
-        msStyle |= BS_MULTILINE;
-    }
+    msStyle |= wxMSWButton::GetMultilineStyle(label);
 
     return MSWCreateControl(_T("BUTTON"), msStyle, pos, size, label, exstyle);
 }
@@ -238,19 +235,7 @@ WXDWORD wxButton::MSWGetStyle(long style, WXDWORD *exstyle) const
 
 void wxButton::SetLabel(const wxString& label)
 {
-    // update BS_MULTILINE style depending on the new label (resetting it
-    // doesn't seem to do anything very useful but it shouldn't hurt and we do
-    // have to set it whenever the label becomes multi line as otherwise it
-    // wouldn't be shown correctly)
-    long styleOld = ::GetWindowLong(GetHwnd(), GWL_STYLE),
-         styleNew;
-    if ( label.find(_T('\n')) != wxString::npos )
-        styleNew = styleOld | BS_MULTILINE;
-    else
-        styleNew = styleOld & ~BS_MULTILINE;
-
-    if ( styleNew != styleOld )
-        ::SetWindowLong(GetHwnd(), GWL_STYLE, styleNew);
+    wxMSWButton::UpdateMultilineStyle(GetHwnd(), label);
 
     wxButtonBase::SetLabel(label);
 }
index 02a5a495c55ee59123880ba62abfc1d3febcba0c..44645f3b726bd0875bc52d51b10a75ac3cbaf9c8 100644 (file)
@@ -35,8 +35,9 @@
 #endif
 
 #include "wx/msw/dc.h"          // for wxDCTemp
-#include "wx/msw/uxtheme.h"
 #include "wx/renderer.h"
+#include "wx/msw/uxtheme.h"
+#include "wx/msw/private/button.h"
 
 // ----------------------------------------------------------------------------
 // constants
@@ -188,6 +189,8 @@ bool wxCheckBox::Create(wxWindow *parent,
         msStyle |= BS_LEFTTEXT | BS_RIGHT;
     }
 
+    msStyle |= wxMSWButton::GetMultilineStyle(label);
+
     return MSWCreateControl(wxT("BUTTON"), msStyle, pos, size, label, 0);
 }
 
@@ -212,7 +215,9 @@ wxSize wxCheckBox::DoGetBestSize() const
     int wCheckbox, hCheckbox;
     if ( !str.empty() )
     {
-        GetTextExtent(GetLabelText(str), &wCheckbox, &hCheckbox);
+        wxClientDC dc(wx_const_cast(wxCheckBox *, this));
+        dc.SetFont(GetFont());
+        dc.GetMultiLineTextExtent(GetLabelText(str), &wCheckbox, &hCheckbox);
         wCheckbox += s_checkSize + GetCharWidth();
 
         if ( hCheckbox < s_checkSize )
@@ -236,6 +241,13 @@ wxSize wxCheckBox::DoGetBestSize() const
 // wxCheckBox operations
 // ----------------------------------------------------------------------------
 
+void wxCheckBox::SetLabel(const wxString& label)
+{
+    wxMSWButton::UpdateMultilineStyle(GetHwnd(), label);
+
+    wxCheckBoxBase::SetLabel(label);
+}
+
 void wxCheckBox::SetValue(bool val)
 {
     Set3StateValue(val ? wxCHK_CHECKED : wxCHK_UNCHECKED);