// Created: 08.02.01
// RCS-ID: $Id$
// Copyright: (c) 2000 Johnny C. Norris II
-// License: wxWindows licence
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// ============================================================================
// macros
// ----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
-DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
+wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON, wxCommandEvent );
// ============================================================================
// implementation
// ============================================================================
+//-----------------------------------------------------------------------------
+// wxBitmapToggleButton
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxBitmapToggleButton, wxToggleButton)
+
+bool wxBitmapToggleButton::Create( wxWindow *parent, wxWindowID id,
+ const wxBitmap& label,const wxPoint& pos, const wxSize& size, long style,
+ const wxValidator& validator, const wxString& name )
+{
+ if (!wxToggleButton::Create( parent, id, wxEmptyString, pos, size, style, validator, name ))
+ return false;
+
+ SetBitmap(label);
+
+ if (size.x == -1 || size.y == -1)
+ {
+ wxSize new_size = GetBestSize();
+ if (size.x != -1)
+ new_size.x = size.x;
+ if (size.y != -1)
+ new_size.y = size.y;
+ SetSize( new_size );
+ }
+
+ return true;
+}
+
+
// ----------------------------------------------------------------------------
// wxToggleButton
// ----------------------------------------------------------------------------
+IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
+
+void wxToggleButton::Init()
+{
+ m_state = false;
+}
+
// Single check box item
bool wxToggleButton::Create(wxWindow *parent,
wxWindowID id,
const wxValidator& validator,
const wxString& name)
{
+ Init();
+
if ( !CreateControl(parent, id, pos, size, style, validator, name) )
return false;
WXDWORD msStyle = MSWGetStyle(style, &exstyle);
msStyle |= wxMSWButton::GetMultilineStyle(label);
- return MSWCreateControl(_T("BUTTON"), msStyle, pos, size, label, exstyle);
+ return MSWCreateControl(wxT("BUTTON"), msStyle, pos, size, label, exstyle);
}
WXDWORD wxToggleButton::MSWGetStyle(long style, WXDWORD *exstyle) const
return msStyle;
}
-wxSize wxToggleButton::DoGetBestSize() const
-{
- 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);
+ m_state = val;
+ if ( IsOwnerDrawn() )
+ {
+ Refresh();
+ }
+ else
+ {
+ ::SendMessage(GetHwnd(), BM_SETCHECK, val, 0);
+ }
}
bool wxToggleButton::GetValue() const
{
- return ::SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) == BST_CHECKED;
+ if ( IsOwnerDrawn() )
+ {
+ return m_state;
+ }
+ else
+ {
+ return ::SendMessage(GetHwnd(), BM_GETCHECK, 0, 0) == BST_CHECKED;
+ }
}
void wxToggleButton::Command(wxCommandEvent& event)
ProcessCommand(event);
}
-bool wxToggleButton::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
+bool wxToggleButton::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
{
- wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId);
+ if ( param != BN_CLICKED && param != BN_DBLCLK )
+ return false;
+
+ // first update the value so that user event handler gets the new
+ // toggle button value
+
+ // ownerdrawn buttons don't manage their state themselves unlike usual
+ // auto checkboxes so do it ourselves in any case
+ m_state = !m_state;
+
+ wxCommandEvent event(wxEVT_TOGGLEBUTTON, m_windowId);
event.SetInt(GetValue());
event.SetEventObject(this);
ProcessCommand(event);
return true;
}
+wxAnyButton::State wxToggleButton::GetNormalState() const
+{
+ if ( GetValue() )
+ return State_Pressed;
+ else
+ return State_Normal;
+}
+
#endif // wxUSE_TOGGLEBTN