X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4ce7b1e43fdf835a77a78765fe73de707b89e85f..005659f0ffe0b280c3f800a5706b93fe9b78276e:/src/common/clrpickercmn.cpp?ds=inline diff --git a/src/common/clrpickercmn.cpp b/src/common/clrpickercmn.cpp index 412eaadc7b..9420551b5a 100644 --- a/src/common/clrpickercmn.cpp +++ b/src/common/clrpickercmn.cpp @@ -28,13 +28,18 @@ #include "wx/clrpicker.h" +#ifndef WX_PRECOMP + #include "wx/textctrl.h" +#endif +const char wxColourPickerCtrlNameStr[] = "colourpicker"; +const char wxColourPickerWidgetNameStr[] = "colourpickerwidget"; // ============================================================================ // implementation // ============================================================================ -DEFINE_EVENT_TYPE(wxEVT_COMMAND_COLOURPICKER_CHANGED) +wxDEFINE_EVENT(wxEVT_COMMAND_COLOURPICKER_CHANGED, wxColourPickerEvent); IMPLEMENT_DYNAMIC_CLASS(wxColourPickerCtrl, wxPickerBase) IMPLEMENT_DYNAMIC_CLASS(wxColourPickerEvent, wxEvent) @@ -56,8 +61,13 @@ bool wxColourPickerCtrl::Create( wxWindow *parent, wxWindowID id, // we are not interested to the ID of our picker as we connect // to its "changed" event dynamically... - m_picker = new wxColourPickerWidget(this, wxID_ANY, col, wxPoint(40,0), wxSize(30,-1), + m_picker = new wxColourPickerWidget(this, wxID_ANY, col, + wxDefaultPosition, wxDefaultSize, GetPickerStyle(style)); + + // complete sizer creation + wxPickerBase::PostCreation(); + m_picker->Connect(wxEVT_COMMAND_COLOURPICKER_CHANGED, wxColourPickerEventHandler(wxColourPickerCtrl::OnColourChange), NULL, this); @@ -74,7 +84,7 @@ void wxColourPickerCtrl::SetColour(const wxColour &col) bool wxColourPickerCtrl::SetColour(const wxString &text) { wxColour col(text); // smart wxString->wxColour conversion - if ( !col.Ok() ) + if ( !col.IsOk() ) return false; M_PICKER->SetColour(col); UpdateTextCtrlFromPicker(); @@ -86,16 +96,9 @@ void wxColourPickerCtrl::UpdatePickerFromTextCtrl() { wxASSERT(m_text); - if (m_bIgnoreNextTextCtrlUpdate) - { - // ignore this update - m_bIgnoreNextTextCtrlUpdate = false; - return; - } - // wxString -> wxColour conversion wxColour col(m_text->GetValue()); - if ( !col.Ok() ) + if ( !col.IsOk() ) return; // invalid user input if (M_PICKER->GetColour() != col) @@ -113,11 +116,9 @@ void wxColourPickerCtrl::UpdateTextCtrlFromPicker() if (!m_text) return; // no textctrl to update - // NOTE: this SetValue() will generate an unwanted wxEVT_COMMAND_TEXT_UPDATED - // which will trigger a unneeded UpdateFromTextCtrl(); thus before using - // SetValue() we set the m_bIgnoreNextTextCtrlUpdate flag... - m_bIgnoreNextTextCtrlUpdate = true; - m_text->SetValue(M_PICKER->GetColour().GetAsString()); + // Take care to use ChangeValue() here and not SetValue() to avoid + // infinite recursion. + m_text->ChangeValue(M_PICKER->GetColour().GetAsString()); }