Refactor: create src/univ/anybutton.cpp.

Extract and pull the common functions from wxButton and wxToggleButton to
wxAnyButton in wxUniv too.

Also make wxToggleButton inherit from wxToggleButtonBase correctly

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77759 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-09-23 17:38:47 +00:00
parent 16601713a4
commit 43c99ef613
12 changed files with 497 additions and 386 deletions

View File

@@ -17,10 +17,13 @@
#if wxUSE_TOGGLEBTN
#include "wx/tglbtn.h"
#include "wx/univ/renderer.h"
#include "wx/univ/colschem.h"
#include "wx/univ/theme.h"
wxDEFINE_EVENT( wxEVT_TOGGLEBUTTON, wxCommandEvent );
IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxButton)
IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxToggleButtonBase)
wxToggleButton::wxToggleButton()
{
@@ -28,34 +31,55 @@ wxToggleButton::wxToggleButton()
}
wxToggleButton::wxToggleButton(wxWindow *parent,
wxWindowID id,
const wxBitmap& bitmap,
const wxString& label,
const wxPoint& pos,
const wxSize& size,
long style,
const wxValidator& validator,
const wxString& name)
{
Init();
Create(parent, id, bitmap, label, pos, size, style, validator, name);
}
wxToggleButton::wxToggleButton(wxWindow *parent,
wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size,
long style,
const wxValidator& validator,
const wxString& name)
wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size,
long style,
const wxValidator& validator,
const wxString& name)
{
Init();
Create(parent, id, label, pos, size, style, validator, name);
}
wxToggleButton::~wxToggleButton()
bool wxToggleButton::Create(wxWindow *parent,
wxWindowID id,
const wxString& lbl,
const wxPoint& pos,
const wxSize& size, long style,
const wxValidator& validator,
const wxString& name)
{
wxString label(lbl);
if (label.empty() && wxIsStockID(id))
label = wxGetStockLabel(id);
long ctrl_style = style & ~wxBU_ALIGN_MASK;
ctrl_style = ctrl_style & ~wxALIGN_MASK;
if((style & wxBU_RIGHT) == wxBU_RIGHT)
ctrl_style |= wxALIGN_RIGHT;
else if((style & wxBU_LEFT) == wxBU_LEFT)
ctrl_style |= wxALIGN_LEFT;
else
ctrl_style |= wxALIGN_CENTRE_HORIZONTAL;
if((style & wxBU_TOP) == wxBU_TOP)
ctrl_style |= wxALIGN_TOP;
else if((style & wxBU_BOTTOM) == wxBU_BOTTOM)
ctrl_style |= wxALIGN_BOTTOM;
else
ctrl_style |= wxALIGN_CENTRE_VERTICAL;
if ( !wxToggleButtonBase::Create(parent, id, pos, size, ctrl_style, validator, name) )
{
wxFAIL_MSG(wxT("wxToggleButton creation failed"));
return false;
}
SetLabel(label);
CreateInputHandler(wxINP_HANDLER_BUTTON);
return true;
}
void wxToggleButton::Init()