support multiline labels in wxCheckBox (#9495)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54008 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -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:
|
||||
|
||||
|
@@ -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);
|
||||
|
46
include/wx/msw/private/button.h
Normal file
46
include/wx/msw/private/button.h
Normal file
@@ -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_
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user