#ifndef _WX_MSW_PRIVATE_BUTTON_H_
#define _WX_MSW_PRIVATE_BUTTON_H_
+// define some standard button constants which may be missing in the headers
+#ifndef BS_PUSHLIKE
+ #define BS_PUSHLIKE 0x00001000L
+#endif
+
+#ifndef BST_UNCHECKED
+ #define BST_UNCHECKED 0x0000
+#endif
+
+#ifndef BST_CHECKED
+ #define BST_CHECKED 0x0001
+#endif
+
+#ifndef BST_INDETERMINATE
+ #define BST_INDETERMINATE 0x0002
+#endif
+
+#ifndef DT_HIDEPREFIX
+ #define DT_HIDEPREFIX 0x00100000
+#endif
+
namespace wxMSWButton
{
::SetWindowLong(hwnd, GWL_STYLE, styleNew);
}
+// common implementation of wxButton and wxToggleButton::DoGetBestSize()
+inline wxSize ComputeBestSize(wxControl *btn)
+{
+ wxClientDC dc(btn);
+
+ wxCoord wBtn,
+ hBtn;
+ dc.GetMultiLineTextExtent(btn->GetLabelText(), &wBtn, &hBtn);
+
+ // FIXME: this is pure guesswork, need to retrieve the real button margins
+ wBtn += 3*btn->GetCharWidth();
+ hBtn = 11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(hBtn)/10;
+
+ // all buttons have at least the standard size unless the user explicitly
+ // wants them to be of smaller size and used wxBU_EXACTFIT style when
+ // creating the button
+ if ( !btn->HasFlag(wxBU_EXACTFIT) )
+ {
+ wxSize sz = wxButton::GetDefaultSize();
+ if ( wBtn < sz.x )
+ wBtn = sz.x;
+ if ( hBtn < sz.y )
+ hBtn = sz.y;
+ }
+
+ wxSize best(wBtn, hBtn);
+ btn->CacheBestSize(best);
+ return best;
+}
+
} // namespace wxMSWButton
#endif // _WX_MSW_PRIVATE_BUTTON_H_
IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
#endif
-// this macro tries to adjust the default button height to a reasonable value
-// using the char height as the base
-#define BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cy) (11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)/10)
-
// ============================================================================
// implementation
// ============================================================================
wxSize wxButton::DoGetBestSize() const
{
- wxClientDC dc(wx_const_cast(wxButton *, this));
- dc.SetFont(GetFont());
-
- wxCoord wBtn,
- hBtn;
- dc.GetMultiLineTextExtent(GetLabelText(), &wBtn, &hBtn);
-
- // add a margin -- the button is wider than just its label
- wBtn += 3*GetCharWidth();
- hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hBtn);
-
- // all buttons have at least the standard size unless the user explicitly
- // wants them to be of smaller size and used wxBU_EXACTFIT style when
- // creating the button
- if ( !HasFlag(wxBU_EXACTFIT) )
- {
- wxSize sz = GetDefaultSize();
- if (wBtn > sz.x)
- sz.x = wBtn;
- if (hBtn > sz.y)
- sz.y = hBtn;
-
- return sz;
- }
-
- wxSize best(wBtn, hBtn);
- CacheBestSize(best);
- return best;
+ return wxMSWButton::ComputeBestSize(wx_const_cast(wxButton *, this));
}
/* static */
#endif // WX_PRECOMP
#include "wx/msw/private.h"
+#include "wx/msw/private/button.h"
// ----------------------------------------------------------------------------
// macros
IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
-#define BUTTON_HEIGHT_FROM_CHAR_HEIGHT(cy) (11*EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy)/10)
-
// ============================================================================
// implementation
// ============================================================================
// wxToggleButton
// ----------------------------------------------------------------------------
-bool wxToggleButton::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
-{
- wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
- event.SetInt(GetValue());
- event.SetEventObject(this);
- ProcessCommand(event);
- return true;
-}
-
// Single check box item
-bool wxToggleButton::Create(wxWindow *parent, wxWindowID id,
+bool wxToggleButton::Create(wxWindow *parent,
+ wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size, long style,
if ( !CreateControl(parent, id, pos, size, style, validator, name) )
return false;
- if ( !MSWCreateControl(wxT("BUTTON"), label, pos, size) )
- return false;
-
- return true;
+ // if the label contains several lines we must explicitly tell the button
+ // about it or it wouldn't draw it correctly ("\n"s would just appear as
+ // black boxes)
+ //
+ // 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
+ WXDWORD exstyle;
+ WXDWORD msStyle = MSWGetStyle(style, &exstyle);
+ msStyle |= wxMSWButton::GetMultilineStyle(label);
+
+ return MSWCreateControl(_T("BUTTON"), msStyle, pos, size, label, exstyle);
}
WXDWORD wxToggleButton::MSWGetStyle(long style, WXDWORD *exstyle) const
{
WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
-#ifndef BS_PUSHLIKE
-#define BS_PUSHLIKE 0x00001000L
-#endif
-
msStyle |= BS_AUTOCHECKBOX | BS_PUSHLIKE | WS_TABSTOP;
- if(style & wxBU_LEFT)
+ if ( style & wxBU_LEFT )
msStyle |= BS_LEFT;
- if(style & wxBU_RIGHT)
+ if ( style & wxBU_RIGHT )
msStyle |= BS_RIGHT;
- if(style & wxBU_TOP)
+ if ( style & wxBU_TOP )
msStyle |= BS_TOP;
- if(style & wxBU_BOTTOM)
+ if ( style & wxBU_BOTTOM )
msStyle |= BS_BOTTOM;
return msStyle;
wxSize wxToggleButton::DoGetBestSize() const
{
- wxString label = wxGetWindowText(GetHWND());
- int wBtn;
- GetTextExtent(GetLabelText(label), &wBtn, NULL);
-
- int wChar, hChar;
- wxGetCharSize(GetHWND(), &wChar, &hChar, GetFont());
-
- // add a margin - the button is wider than just its label
- wBtn += 3*wChar;
-
- // the button height is proportional to the height of the font used
- int hBtn = BUTTON_HEIGHT_FROM_CHAR_HEIGHT(hChar);
-
-#if wxUSE_BUTTON
- // make all buttons of at least standard size unless wxBU_EXACTFIT is given
- if ( !HasFlag(wxBU_EXACTFIT) )
- {
- const wxSize szMin = wxButton::GetDefaultSize();
- if ( wBtn < szMin.x )
- wBtn = szMin.x;
- if ( hBtn < szMin.y )
- hBtn = szMin.y;
- }
-#endif // wxUSE_BUTTON
-
- wxSize sz(wBtn, hBtn);
-
- CacheBestSize(sz);
- return sz;
+ return wxMSWButton::ComputeBestSize(wx_const_cast(wxToggleButton *, this));
+}
+
+void wxToggleButton::SetLabel(const wxString& label)
+{
+ wxMSWButton::UpdateMultilineStyle(GetHwnd(), label);
+
+ wxToggleButtonBase::SetLabel(label);
}
void wxToggleButton::SetValue(bool val)
::SendMessage(GetHwnd(), BM_SETCHECK, val, 0);
}
-#ifndef BST_CHECKED
-#define BST_CHECKED 0x0001
-#endif
-
bool wxToggleButton::GetValue() const
{
-#ifdef __WIN32__
- return (::SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) == BST_CHECKED);
-#else
- return ((0x001 & ::SendMessage(GetHwnd(), BM_GETCHECK, 0, 0)) == 0x001);
-#endif
+ return ::SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) == BST_CHECKED;
}
-void wxToggleButton::Command(wxCommandEvent & event)
+void wxToggleButton::Command(wxCommandEvent& event)
{
- SetValue((event.GetInt() != 0));
- ProcessCommand(event);
+ SetValue(event.GetInt() != 0);
+ ProcessCommand(event);
+}
+
+bool wxToggleButton::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
+{
+ wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
+ event.SetInt(GetValue());
+ event.SetEventObject(this);
+ ProcessCommand(event);
+ return true;
}
#endif // wxUSE_TOGGLEBTN