I did finally manage to create something that
seems to work.
I basically copied
Create() from
wxColourPickerCtrl:: and
wxGenericColourButton::, changing only what I needed. I tried invoking the respective canonical
Create() functions, and then undoing/redoing some of what they were doing, but that almost seemed like more work and more of a mess than just copying what they were doing without actually invoking them.
I'd at least like your advice about how to do this better.
Code: Select all
class _wxGenericColourButton : public wxGenericColourButton {
public:
_wxGenericColourButton() {}
_wxGenericColourButton( wxWindow *parent,
wxWindowID id,
const wxColour& col = *wxBLACK,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxCLRBTN_DEFAULT_STYLE,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxColourPickerWidgetNameStr )
{
Create(parent,id,col,pos,size,style,validator,name);
}
bool Create( wxWindow *parent,
wxWindowID id,
const wxColour& col = *wxBLACK,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxCLRBTN_DEFAULT_STYLE,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxColourPickerWidgetNameStr )
{
// Generally taken from wxGenericColourButton::Create() [clrpickerg.cpp:44]
// Make the bitmap smaller by default. Enlarging the button should work fine.
m_bitmap = wxBitmap(13, 13);
// create this button
if (!wxBitmapButton::Create( parent, id, m_bitmap, pos,
size, style | wxBU_AUTODRAW, validator, name ))
{
wxFAIL_MSG( wxT("wxGenericColourButton creation failed") );
return false;
}
// and handle user clicks on it
Connect(GetId(), wxEVT_BUTTON,
wxCommandEventHandler(wxGenericColourButton::OnButtonClick),
NULL, this);
m_colour = col;
UpdateColour();
InitColourData();
return true;
}
};
class _wxColourPickerCtrl : public wxColourPickerCtrl {
public:
_wxColourPickerCtrl() {}
_wxColourPickerCtrl( wxWindow *parent, wxWindowID id,
const wxColour& col = *wxBLACK, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = wxCLRP_DEFAULT_STYLE,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxColourPickerCtrlNameStr)
{
Create(parent, id, col, pos, size, style, validator, name);
}
bool Create( wxWindow *parent, wxWindowID id,
const wxColour& col = *wxBLACK,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxCLRP_DEFAULT_STYLE,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxColourPickerCtrlNameStr)
{
// This code is generally taken from: wxColourPickerCtrl::Create() [clrpickercmn.cpp:51]
if (!wxPickerBase::CreateBase(parent, id, col.GetAsString(), pos, size,
style, validator, name))
return false;
// Use our "enhanced" _wxGenericColourButton instead of the one with hardcoded,
// undesirable behavior.
m_picker = new _wxGenericColourButton(this, wxID_ANY, col,
wxDefaultPosition, wxDefaultSize,
GetPickerStyle(style));
wxPickerBase::PostCreation();
m_picker->Connect(wxEVT_COLOURPICKER_CHANGED,
wxColourPickerEventHandler(wxColourPickerCtrl::OnColourChange),
NULL, this);
return true;
}
};
Thanks for your help!