Merge branch 'col-dialog-current'
Add events for current colour change in wxColourDialog and wxColourPickerCtrl. See https://github.com/wxWidgets/wxWidgets/pull/1301
This commit is contained in:
@@ -159,13 +159,15 @@ private:
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COLOURPICKER_CHANGED, wxColourPickerEvent );
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COLOURPICKER_CHANGED, wxColourPickerEvent );
|
||||||
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COLOURPICKER_CURRENT_CHANGED, wxColourPickerEvent );
|
||||||
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COLOURPICKER_DIALOG_CANCELLED, wxColourPickerEvent );
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxColourPickerEvent : public wxCommandEvent
|
class WXDLLIMPEXP_CORE wxColourPickerEvent : public wxCommandEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxColourPickerEvent() {}
|
wxColourPickerEvent() {}
|
||||||
wxColourPickerEvent(wxObject *generator, int id, const wxColour &col)
|
wxColourPickerEvent(wxObject *generator, int id, const wxColour &col, wxEventType commandType = wxEVT_COLOURPICKER_CHANGED)
|
||||||
: wxCommandEvent(wxEVT_COLOURPICKER_CHANGED, id),
|
: wxCommandEvent(commandType, id),
|
||||||
m_colour(col)
|
m_colour(col)
|
||||||
{
|
{
|
||||||
SetEventObject(generator);
|
SetEventObject(generator);
|
||||||
@@ -196,6 +198,11 @@ typedef void (wxEvtHandler::*wxColourPickerEventFunction)(wxColourPickerEvent&);
|
|||||||
#define EVT_COLOURPICKER_CHANGED(id, fn) \
|
#define EVT_COLOURPICKER_CHANGED(id, fn) \
|
||||||
wx__DECLARE_EVT1(wxEVT_COLOURPICKER_CHANGED, id, wxColourPickerEventHandler(fn))
|
wx__DECLARE_EVT1(wxEVT_COLOURPICKER_CHANGED, id, wxColourPickerEventHandler(fn))
|
||||||
|
|
||||||
|
#define EVT_COLOURPICKER_CURRENT_CHANGED(id, fn) \
|
||||||
|
wx__DECLARE_EVT1(wxEVT_COLOURPICKER_CURRENT_CHANGED, id, wxColourPickerEventHandler(fn))
|
||||||
|
|
||||||
|
#define EVT_COLOURPICKER_DIALOG_CANCELLED(id, fn) \
|
||||||
|
wx__DECLARE_EVT1(wxEVT_COLOURPICKER_DIALOG_CANCELLED, id, wxColourPickerEventHandler(fn))
|
||||||
|
|
||||||
// old wxEVT_COMMAND_* constant
|
// old wxEVT_COMMAND_* constant
|
||||||
#define wxEVT_COMMAND_COLOURPICKER_CHANGED wxEVT_COLOURPICKER_CHANGED
|
#define wxEVT_COMMAND_COLOURPICKER_CHANGED wxEVT_COLOURPICKER_CHANGED
|
||||||
|
@@ -31,6 +31,52 @@
|
|||||||
#define wxColourDialog wxGenericColourDialog
|
#define wxColourDialog wxGenericColourDialog
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Under some platforms (currently only wxMSW) wxColourDialog can send events
|
||||||
|
// of this type while it is shown.
|
||||||
|
//
|
||||||
|
// Notice that this class is almost identical to wxColourPickerEvent but it
|
||||||
|
// doesn't really sense to reuse the same class for both controls.
|
||||||
|
class WXDLLIMPEXP_CORE wxColourDialogEvent : public wxCommandEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxColourDialogEvent()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
wxColourDialogEvent(wxEventType evtType,
|
||||||
|
wxColourDialog* dialog,
|
||||||
|
const wxColour& colour)
|
||||||
|
: wxCommandEvent(evtType, dialog->GetId()),
|
||||||
|
m_colour(colour)
|
||||||
|
{
|
||||||
|
SetEventObject(dialog);
|
||||||
|
}
|
||||||
|
|
||||||
|
// default copy ctor and dtor are ok
|
||||||
|
|
||||||
|
wxColour GetColour() const { return m_colour; }
|
||||||
|
void SetColour(const wxColour& colour) { m_colour = colour; }
|
||||||
|
|
||||||
|
virtual wxEvent *Clone() const wxOVERRIDE
|
||||||
|
{
|
||||||
|
return new wxColourDialogEvent(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxColour m_colour;
|
||||||
|
|
||||||
|
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxColourDialogEvent);
|
||||||
|
};
|
||||||
|
|
||||||
|
wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CORE, wxEVT_COLOUR_CHANGED, wxColourDialogEvent);
|
||||||
|
|
||||||
|
#define wxColourDialogEventHandler(func) \
|
||||||
|
wxEVENT_HANDLER_CAST(wxColourDialogEventFunction, func)
|
||||||
|
|
||||||
|
#define EVT_COLOUR_CHANGED(id, fn) \
|
||||||
|
wx__DECLARE_EVT1(wxEVT_COLOUR_CHANGED, id, wxColourDialogEventHandler(fn))
|
||||||
|
|
||||||
|
|
||||||
// get the colour from user and return it
|
// get the colour from user and return it
|
||||||
WXDLLIMPEXP_CORE wxColour wxGetColourFromUser(wxWindow *parent = NULL,
|
WXDLLIMPEXP_CORE wxColour wxGetColourFromUser(wxWindow *parent = NULL,
|
||||||
const wxColour& colInit = wxNullColour,
|
const wxColour& colInit = wxNullColour,
|
||||||
|
@@ -15,6 +15,8 @@
|
|||||||
#include "wx/bmpbuttn.h"
|
#include "wx/bmpbuttn.h"
|
||||||
#include "wx/colourdata.h"
|
#include "wx/colourdata.h"
|
||||||
|
|
||||||
|
class wxColourDialogEvent;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxGenericColourButton: a button which brings up a wxColourDialog
|
// wxGenericColourButton: a button which brings up a wxColourDialog
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -75,6 +77,8 @@ protected:
|
|||||||
static wxColourData ms_data;
|
static wxColourData ms_data;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void OnColourChanged(wxColourDialogEvent& event);
|
||||||
|
|
||||||
wxDECLARE_DYNAMIC_CLASS(wxGenericColourButton);
|
wxDECLARE_DYNAMIC_CLASS(wxGenericColourButton);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -44,6 +44,9 @@ public:
|
|||||||
// called from the hook procedure on WM_INITDIALOG reception
|
// called from the hook procedure on WM_INITDIALOG reception
|
||||||
virtual void MSWOnInitDone(WXHWND hDlg);
|
virtual void MSWOnInitDone(WXHWND hDlg);
|
||||||
|
|
||||||
|
// called from the hook procedure
|
||||||
|
void MSWCheckIfCurrentChanged(WXCOLORREF currentCol);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// common part of all ctors
|
// common part of all ctors
|
||||||
void Init();
|
void Init();
|
||||||
@@ -57,6 +60,9 @@ protected:
|
|||||||
wxColourData m_colourData;
|
wxColourData m_colourData;
|
||||||
wxString m_title;
|
wxString m_title;
|
||||||
|
|
||||||
|
// Currently selected colour, used while the dialog is being shown.
|
||||||
|
WXCOLORREF m_currentCol;
|
||||||
|
|
||||||
// indicates that the dialog should be centered in this direction if non 0
|
// indicates that the dialog should be centered in this direction if non 0
|
||||||
// (set by DoCentre(), used by MSWOnInitDone())
|
// (set by DoCentre(), used by MSWOnInitDone())
|
||||||
int m_centreDir;
|
int m_centreDir;
|
||||||
|
@@ -44,7 +44,20 @@ wxEventType wxEVT_COLOURPICKER_CHANGED;
|
|||||||
The user changed the colour selected in the control either using the
|
The user changed the colour selected in the control either using the
|
||||||
button or using text control (see @c wxCLRP_USE_TEXTCTRL; note that
|
button or using text control (see @c wxCLRP_USE_TEXTCTRL; note that
|
||||||
in this case the event is fired only if the user’s input is valid,
|
in this case the event is fired only if the user’s input is valid,
|
||||||
i.e. recognizable).
|
i.e. recognizable). When using a popup dialog for changing the
|
||||||
|
colour, this event is sent only when the changes in the dialog are
|
||||||
|
accepted by the user, unlike @c EVT_COLOURPICKER_CURRENT_CHANGED.
|
||||||
|
@event{EVT_COLOURPICKER_CURRENT_CHANGED(id, func)}
|
||||||
|
The user changed the currently selected colour in the dialog
|
||||||
|
associated with the control. This event is sent immediately when the
|
||||||
|
selection changes and you must also handle @c EVT_COLOUR_CANCELLED
|
||||||
|
to revert to the previously selected colour if the selection ends up
|
||||||
|
not being accepted. This event is new since wxWidgets 3.1.3 and
|
||||||
|
currently is only implemented in wxMSW.
|
||||||
|
@event{EVT_COLOURPICKER_DIALOG_CANCELLED(id, func)}
|
||||||
|
The user cancelled the colour dialog associated with the control,
|
||||||
|
i.e. closed it without accepting the selection. This event is new
|
||||||
|
since wxWidgets 3.1.3 and currently is only implemented in wxMSW.
|
||||||
@endEventTable
|
@endEventTable
|
||||||
|
|
||||||
@library{wxcore}
|
@library{wxcore}
|
||||||
@@ -124,6 +137,15 @@ public:
|
|||||||
@beginEventTable{wxColourPickerEvent}
|
@beginEventTable{wxColourPickerEvent}
|
||||||
@event{EVT_COLOURPICKER_CHANGED(id, func)}
|
@event{EVT_COLOURPICKER_CHANGED(id, func)}
|
||||||
Generated whenever the selected colour changes.
|
Generated whenever the selected colour changes.
|
||||||
|
@event{EVT_COLOURPICKER_CURRENT_CHANGED(id, func)}
|
||||||
|
Generated whenever the currently selected colour in the dialog shown
|
||||||
|
by the picker changes. This event is new since wxWidgets 3.1.3 and
|
||||||
|
currently is only implemented in wxMSW.
|
||||||
|
@event{EVT_COLOURPICKER_DIALOG_CANCELLED(id, func)}
|
||||||
|
Generated when the user cancels the colour dialog associated with
|
||||||
|
the control, i.e. closes it without accepting the selection. This
|
||||||
|
event is new since wxWidgets 3.1.3 and currently is only implemented
|
||||||
|
in wxMSW.
|
||||||
@endEventTable
|
@endEventTable
|
||||||
|
|
||||||
@library{wxcore}
|
@library{wxcore}
|
||||||
|
@@ -10,11 +10,46 @@
|
|||||||
|
|
||||||
This class represents the colour chooser dialog.
|
This class represents the colour chooser dialog.
|
||||||
|
|
||||||
|
Starting from wxWidgets 3.1.3 and currently in the MSW port only, this
|
||||||
|
dialog generates wxEVT_COLOUR_CHANGED events while it is being shown, i.e.
|
||||||
|
from inside its ShowModal() method, that notify the program about the
|
||||||
|
change of the currently selected colour and allow it to e.g. preview the
|
||||||
|
effect of selecting this colour. Note that if you react to this event, you
|
||||||
|
should also correctly revert to the previously selected colour if the
|
||||||
|
dialog is cancelled by the user.
|
||||||
|
|
||||||
|
Example of using this class with dynamic feedback for the selected colour:
|
||||||
|
@code
|
||||||
|
// Some function for redrawing using the given colour. Ideally, it
|
||||||
|
// shouldn't do anything if the colour is the same as the one used
|
||||||
|
// before.
|
||||||
|
void Redraw(const wxColour& colour);
|
||||||
|
|
||||||
|
wxColourData data;
|
||||||
|
data.SetColour(initialColourToUse);
|
||||||
|
wxColourData dlg(this, &data);
|
||||||
|
dlg.Bind(wxEVT_COLOUR_CHANGED, [](wxColourDialogEvent& event) {
|
||||||
|
Redraw(event.GetColour());
|
||||||
|
});
|
||||||
|
if ( dlg.ShowModal() == wxID_OK ) {
|
||||||
|
// Colour did change.
|
||||||
|
} else {
|
||||||
|
// Colour didn't change.
|
||||||
|
}
|
||||||
|
|
||||||
|
// This call is unnecessary under platforms generating
|
||||||
|
// wxEVT_COLOUR_CHANGED if the dialog was accepted and unnecessary
|
||||||
|
// under the platforms not generating this event if it was cancelled,
|
||||||
|
// so we could check for the different cases explicitly to avoid it,
|
||||||
|
// but it's simpler to just always call it.
|
||||||
|
Redraw(data.GetColour());
|
||||||
|
@endcode
|
||||||
|
|
||||||
@library{wxcore}
|
@library{wxcore}
|
||||||
@category{cmndlg}
|
@category{cmndlg}
|
||||||
|
|
||||||
@see @ref overview_cmndlg_colour, wxColour, wxColourData,
|
@see @ref overview_cmndlg_colour, wxColour, wxColourData,
|
||||||
wxGetColourFromUser()
|
wxColourDialogEvent, wxGetColourFromUser()
|
||||||
*/
|
*/
|
||||||
class wxColourDialog : public wxDialog
|
class wxColourDialog : public wxDialog
|
||||||
{
|
{
|
||||||
@@ -55,7 +90,30 @@ public:
|
|||||||
virtual int ShowModal();
|
virtual int ShowModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
This event class is used for the events generated by wxColourDialog.
|
||||||
|
|
||||||
|
@beginEventTable{wxColourPickerEvent}
|
||||||
|
@event{EVT_COLOUR_CHANGED(id, func)}
|
||||||
|
Generated whenever the currently selected colour in the dialog
|
||||||
|
changes. This event is currently only implemented in wxMSW.
|
||||||
|
@endEventTable
|
||||||
|
|
||||||
|
@library{wxcore}
|
||||||
|
@category{events}
|
||||||
|
|
||||||
|
@see wxColourDialog
|
||||||
|
|
||||||
|
@since 3.1.3
|
||||||
|
*/
|
||||||
|
class wxColourDialogEvent : public wxCommandEvent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
Retrieve the colour the user has just selected.
|
||||||
|
*/
|
||||||
|
wxColour GetColour() const;
|
||||||
|
};
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Global functions/macros
|
// Global functions/macros
|
||||||
|
@@ -734,20 +734,35 @@ MyFrame::~MyFrame()
|
|||||||
|
|
||||||
#if wxUSE_COLOURDLG
|
#if wxUSE_COLOURDLG
|
||||||
|
|
||||||
|
void MyFrame::DoApplyColour(const wxColour& colour)
|
||||||
|
{
|
||||||
|
if ( colour == m_canvas->GetBackgroundColour() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_canvas->SetBackgroundColour(colour);
|
||||||
|
m_canvas->ClearBackground();
|
||||||
|
m_canvas->Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnColourChanged(wxColourDialogEvent& event)
|
||||||
|
{
|
||||||
|
DoApplyColour(event.GetColour());
|
||||||
|
}
|
||||||
|
|
||||||
void MyFrame::ChooseColour(wxCommandEvent& event)
|
void MyFrame::ChooseColour(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
m_clrData.SetColour(m_canvas->GetBackgroundColour());
|
m_clrData.SetColour(m_canvas->GetBackgroundColour());
|
||||||
m_clrData.SetChooseAlpha(event.GetId() == DIALOGS_CHOOSE_COLOUR_ALPHA);
|
m_clrData.SetChooseAlpha(event.GetId() == DIALOGS_CHOOSE_COLOUR_ALPHA);
|
||||||
|
|
||||||
wxColourDialog dialog(this, &m_clrData);
|
wxColourDialog dialog(this, &m_clrData);
|
||||||
|
dialog.Bind(wxEVT_COLOUR_CHANGED, &MyFrame::OnColourChanged, this);
|
||||||
dialog.SetTitle("Please choose the background colour");
|
dialog.SetTitle("Please choose the background colour");
|
||||||
if ( dialog.ShowModal() == wxID_OK )
|
if ( dialog.ShowModal() == wxID_OK )
|
||||||
{
|
{
|
||||||
m_clrData = dialog.GetColourData();
|
m_clrData = dialog.GetColourData();
|
||||||
m_canvas->SetBackgroundColour(m_clrData.GetColour());
|
|
||||||
m_canvas->ClearBackground();
|
|
||||||
m_canvas->Refresh();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DoApplyColour(m_clrData.GetColour());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::GetColour(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::GetColour(wxCommandEvent& WXUNUSED(event))
|
||||||
|
@@ -506,6 +506,11 @@ public:
|
|||||||
void OnExit(wxCommandEvent& event);
|
void OnExit(wxCommandEvent& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#if wxUSE_COLOURDLG
|
||||||
|
void OnColourChanged(wxColourDialogEvent& event);
|
||||||
|
void DoApplyColour(const wxColour& colour);
|
||||||
|
#endif // wxUSE_COLOURDLG
|
||||||
|
|
||||||
#if wxUSE_DIRDLG
|
#if wxUSE_DIRDLG
|
||||||
void DoDirChoose(int style);
|
void DoDirChoose(int style);
|
||||||
#endif // wxUSE_DIRDLG
|
#endif // wxUSE_DIRDLG
|
||||||
|
@@ -83,6 +83,9 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
void OnColourChange(wxColourPickerEvent &ev);
|
void OnColourChange(wxColourPickerEvent &ev);
|
||||||
|
void OnColourCurrentChanged(wxColourPickerEvent &ev);
|
||||||
|
void OnColourDialogCancelled(wxColourPickerEvent &ev);
|
||||||
|
|
||||||
void OnCheckBox(wxCommandEvent &ev);
|
void OnCheckBox(wxCommandEvent &ev);
|
||||||
void OnButtonReset(wxCommandEvent &ev);
|
void OnButtonReset(wxCommandEvent &ev);
|
||||||
|
|
||||||
@@ -111,6 +114,8 @@ wxBEGIN_EVENT_TABLE(ColourPickerWidgetsPage, WidgetsPage)
|
|||||||
EVT_BUTTON(PickerPage_Reset, ColourPickerWidgetsPage::OnButtonReset)
|
EVT_BUTTON(PickerPage_Reset, ColourPickerWidgetsPage::OnButtonReset)
|
||||||
|
|
||||||
EVT_COLOURPICKER_CHANGED(PickerPage_Colour, ColourPickerWidgetsPage::OnColourChange)
|
EVT_COLOURPICKER_CHANGED(PickerPage_Colour, ColourPickerWidgetsPage::OnColourChange)
|
||||||
|
EVT_COLOURPICKER_CURRENT_CHANGED(PickerPage_Colour, ColourPickerWidgetsPage::OnColourCurrentChanged)
|
||||||
|
EVT_COLOURPICKER_DIALOG_CANCELLED(PickerPage_Colour, ColourPickerWidgetsPage::OnColourDialogCancelled)
|
||||||
|
|
||||||
EVT_CHECKBOX(wxID_ANY, ColourPickerWidgetsPage::OnCheckBox)
|
EVT_CHECKBOX(wxID_ANY, ColourPickerWidgetsPage::OnCheckBox)
|
||||||
wxEND_EVENT_TABLE()
|
wxEND_EVENT_TABLE()
|
||||||
@@ -221,6 +226,18 @@ void ColourPickerWidgetsPage::OnColourChange(wxColourPickerEvent& event)
|
|||||||
event.GetColour().GetAsString(wxC2S_CSS_SYNTAX));
|
event.GetColour().GetAsString(wxC2S_CSS_SYNTAX));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ColourPickerWidgetsPage::OnColourCurrentChanged(wxColourPickerEvent& event)
|
||||||
|
{
|
||||||
|
wxLogMessage("The currently selected colour changed to '%s'",
|
||||||
|
event.GetColour().GetAsString(wxC2S_CSS_SYNTAX));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ColourPickerWidgetsPage::OnColourDialogCancelled(wxColourPickerEvent& event)
|
||||||
|
{
|
||||||
|
wxLogMessage("Colour selection dialog cancelled, current colour is '%s'",
|
||||||
|
event.GetColour().GetAsString(wxC2S_CSS_SYNTAX));
|
||||||
|
}
|
||||||
|
|
||||||
void ColourPickerWidgetsPage::OnCheckBox(wxCommandEvent &event)
|
void ColourPickerWidgetsPage::OnCheckBox(wxCommandEvent &event)
|
||||||
{
|
{
|
||||||
if (event.GetEventObject() == m_chkColourTextCtrl ||
|
if (event.GetEventObject() == m_chkColourTextCtrl ||
|
||||||
|
@@ -39,6 +39,9 @@ const char wxColourPickerWidgetNameStr[] = "colourpickerwidget";
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
wxDEFINE_EVENT(wxEVT_COLOURPICKER_CHANGED, wxColourPickerEvent);
|
wxDEFINE_EVENT(wxEVT_COLOURPICKER_CHANGED, wxColourPickerEvent);
|
||||||
|
wxDEFINE_EVENT(wxEVT_COLOURPICKER_CURRENT_CHANGED, wxColourPickerEvent);
|
||||||
|
wxDEFINE_EVENT(wxEVT_COLOURPICKER_DIALOG_CANCELLED, wxColourPickerEvent);
|
||||||
|
|
||||||
wxIMPLEMENT_DYNAMIC_CLASS(wxColourPickerCtrl, wxPickerBase);
|
wxIMPLEMENT_DYNAMIC_CLASS(wxColourPickerCtrl, wxPickerBase);
|
||||||
wxIMPLEMENT_DYNAMIC_CLASS(wxColourPickerEvent, wxEvent);
|
wxIMPLEMENT_DYNAMIC_CLASS(wxColourPickerEvent, wxEvent);
|
||||||
|
|
||||||
@@ -129,10 +132,7 @@ void wxColourPickerCtrl::OnColourChange(wxColourPickerEvent &ev)
|
|||||||
{
|
{
|
||||||
UpdateTextCtrlFromPicker();
|
UpdateTextCtrlFromPicker();
|
||||||
|
|
||||||
// the wxColourPickerWidget sent us a colour-change notification.
|
ev.Skip();
|
||||||
// forward this event to our parent
|
|
||||||
wxColourPickerEvent event(this, GetId(), ev.GetColour());
|
|
||||||
GetEventHandler()->ProcessEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_COLOURPICKERCTRL
|
#endif // wxUSE_COLOURPICKERCTRL
|
||||||
|
@@ -129,6 +129,10 @@ bool wxColourData::FromString(const wxString& str)
|
|||||||
|
|
||||||
#include "wx/colordlg.h"
|
#include "wx/colordlg.h"
|
||||||
|
|
||||||
|
wxIMPLEMENT_DYNAMIC_CLASS(wxColourDialogEvent, wxCommandEvent);
|
||||||
|
|
||||||
|
wxDEFINE_EVENT(wxEVT_COLOUR_CHANGED, wxColourDialogEvent);
|
||||||
|
|
||||||
wxColour wxGetColourFromUser(wxWindow *parent,
|
wxColour wxGetColourFromUser(wxWindow *parent,
|
||||||
const wxColour& colInit,
|
const wxColour& colInit,
|
||||||
const wxString& caption,
|
const wxString& caption,
|
||||||
|
@@ -86,15 +86,36 @@ void wxGenericColourButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev))
|
|||||||
|
|
||||||
// create the colour dialog and display it
|
// create the colour dialog and display it
|
||||||
wxColourDialog dlg(this, &ms_data);
|
wxColourDialog dlg(this, &ms_data);
|
||||||
|
dlg.Bind(wxEVT_COLOUR_CHANGED, &wxGenericColourButton::OnColourChanged, this);
|
||||||
|
|
||||||
|
wxEventType eventType;
|
||||||
if (dlg.ShowModal() == wxID_OK)
|
if (dlg.ShowModal() == wxID_OK)
|
||||||
{
|
{
|
||||||
ms_data = dlg.GetColourData();
|
ms_data = dlg.GetColourData();
|
||||||
SetColour(ms_data.GetColour());
|
SetColour(ms_data.GetColour());
|
||||||
|
|
||||||
// fire an event
|
eventType = wxEVT_COLOURPICKER_CHANGED;
|
||||||
wxColourPickerEvent event(this, GetId(), m_colour);
|
|
||||||
GetEventHandler()->ProcessEvent(event);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
eventType = wxEVT_COLOURPICKER_DIALOG_CANCELLED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fire the corresponding event: note that we want it to appear as
|
||||||
|
// originating from our parent, which is the user-visible window, and not
|
||||||
|
// this button itself, which is just an implementation detail.
|
||||||
|
wxWindow* const parent = GetParent();
|
||||||
|
wxColourPickerEvent event(parent, parent->GetId(), m_colour, eventType);
|
||||||
|
|
||||||
|
ProcessWindowEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGenericColourButton::OnColourChanged(wxColourDialogEvent& ev)
|
||||||
|
{
|
||||||
|
wxWindow* const parent = GetParent();
|
||||||
|
wxColourPickerEvent event(parent, parent->GetId(), ev.GetColour(),
|
||||||
|
wxEVT_COLOURPICKER_CURRENT_CHANGED);
|
||||||
|
parent->ProcessWindowEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGenericColourButton::UpdateColour()
|
void wxGenericColourButton::UpdateColour()
|
||||||
|
@@ -50,8 +50,11 @@ static void gtk_clrbutton_setcolor_callback(GtkColorButton *widget,
|
|||||||
#endif
|
#endif
|
||||||
p->GTKSetColour(gdkColor);
|
p->GTKSetColour(gdkColor);
|
||||||
|
|
||||||
// fire the colour-changed event
|
// Fire the corresponding event: note that we want it to appear as
|
||||||
wxColourPickerEvent event(p, p->GetId(), p->GetColour());
|
// originating from our parent, which is the user-visible window, and not
|
||||||
|
// this button itself, which is just an implementation detail.
|
||||||
|
wxWindow* const parent = p->GetParent();
|
||||||
|
wxColourPickerEvent event(parent, parent->GetId(), p->GetColour());
|
||||||
p->HandleWindowEvent(event);
|
p->HandleWindowEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,8 @@
|
|||||||
#include "wx/math.h"
|
#include "wx/math.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "wx/scopeguard.h"
|
||||||
|
|
||||||
#include "wx/msw/private.h"
|
#include "wx/msw/private.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -51,6 +53,9 @@
|
|||||||
// and "Define Custom Colors" extension not shown
|
// and "Define Custom Colors" extension not shown
|
||||||
static wxRect gs_rectDialog(0, 0, 222, 324);
|
static wxRect gs_rectDialog(0, 0, 222, 324);
|
||||||
|
|
||||||
|
// The dialog currently being shown or null.
|
||||||
|
static wxColourDialog* gs_activeDialog = NULL;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxWin macros
|
// wxWin macros
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -61,6 +66,53 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog);
|
|||||||
// implementation
|
// implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
|
#ifndef COLORBOXES
|
||||||
|
#define COLORBOXES 64
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Undocumented property storing the COLORINFO struct in the standard dialog.
|
||||||
|
#ifndef COLORPROP
|
||||||
|
#define COLORPROP (LPCTSTR) 0xA000L
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
// The private and undocumented Windows structure used by the standard dialog.
|
||||||
|
// See https://social.msdn.microsoft.com/Forums/en-US/c5fcfd9f-6b27-4848-bb9d-94bec105eabd/get-the-current-clicked-color-from-choosecolor-dialog?forum=windowsgeneraldevelopmentissues
|
||||||
|
struct COLORINFO
|
||||||
|
{
|
||||||
|
UINT ApiType;
|
||||||
|
LPCHOOSECOLOR pCC;
|
||||||
|
HANDLE hLocal;
|
||||||
|
HANDLE hDialog;
|
||||||
|
HPALETTE hPal;
|
||||||
|
DWORD currentRGB;
|
||||||
|
WORD currentHue;
|
||||||
|
WORD currentSat;
|
||||||
|
WORD currentLum;
|
||||||
|
WORD nHueWidth;
|
||||||
|
WORD nSatHeight;
|
||||||
|
WORD nLumHeight;
|
||||||
|
WORD nCurMix;
|
||||||
|
WORD nCurDsp;
|
||||||
|
WORD nCurBox;
|
||||||
|
WORD nHuePos;
|
||||||
|
WORD nSatPos;
|
||||||
|
WORD nLumPos;
|
||||||
|
RECT rOriginal;
|
||||||
|
RECT rRainbow;
|
||||||
|
RECT rLumScroll;
|
||||||
|
RECT rLumPaint;
|
||||||
|
RECT rCurrentColor;
|
||||||
|
RECT rNearestPure;
|
||||||
|
RECT rColorSamples;
|
||||||
|
BOOL bFoldOut;
|
||||||
|
DWORD rgbBoxColor[COLORBOXES];
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// colour dialog hook proc
|
// colour dialog hook proc
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -69,19 +121,30 @@ UINT_PTR CALLBACK
|
|||||||
wxColourDialogHookProc(HWND hwnd,
|
wxColourDialogHookProc(HWND hwnd,
|
||||||
UINT uiMsg,
|
UINT uiMsg,
|
||||||
WPARAM WXUNUSED(wParam),
|
WPARAM WXUNUSED(wParam),
|
||||||
LPARAM lParam)
|
LPARAM WXUNUSED(lParam))
|
||||||
{
|
{
|
||||||
if ( uiMsg == WM_INITDIALOG )
|
switch ( uiMsg )
|
||||||
{
|
{
|
||||||
CHOOSECOLOR *pCC = (CHOOSECOLOR *)lParam;
|
case WM_INITDIALOG:
|
||||||
wxColourDialog * const
|
{
|
||||||
dialog = reinterpret_cast<wxColourDialog *>(pCC->lCustData);
|
const wxString title = gs_activeDialog->GetTitle();
|
||||||
|
|
||||||
const wxString title = dialog->GetTitle();
|
|
||||||
if ( !title.empty() )
|
if ( !title.empty() )
|
||||||
::SetWindowText(hwnd, title.t_str());
|
::SetWindowText(hwnd, title.t_str());
|
||||||
|
|
||||||
dialog->MSWOnInitDone((WXHWND)hwnd);
|
gs_activeDialog->MSWOnInitDone((WXHWND)hwnd);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Check if the currently selected colour changed.
|
||||||
|
//
|
||||||
|
// Doing it for all messages might be an overkill, we probably
|
||||||
|
// could only do it for keyboard/mouse ones.
|
||||||
|
if ( const COLORINFO* pCI = (COLORINFO*)::GetProp(hwnd, COLORPROP) )
|
||||||
|
{
|
||||||
|
gs_activeDialog->MSWCheckIfCurrentChanged(pCI->currentRGB);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -135,9 +198,11 @@ int wxColourDialog::ShowModal()
|
|||||||
custColours[i] = RGB(255,255,255);
|
custColours[i] = RGB(255,255,255);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_currentCol = wxColourToRGB(m_colourData.GetColour());
|
||||||
|
|
||||||
chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR);
|
chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR);
|
||||||
chooseColorStruct.hwndOwner = hWndParent;
|
chooseColorStruct.hwndOwner = hWndParent;
|
||||||
chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.GetColour());
|
chooseColorStruct.rgbResult = m_currentCol;
|
||||||
chooseColorStruct.lpCustColors = custColours;
|
chooseColorStruct.lpCustColors = custColours;
|
||||||
|
|
||||||
chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK;
|
chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK;
|
||||||
@@ -147,6 +212,10 @@ int wxColourDialog::ShowModal()
|
|||||||
if ( m_colourData.GetChooseFull() )
|
if ( m_colourData.GetChooseFull() )
|
||||||
chooseColorStruct.Flags |= CC_FULLOPEN;
|
chooseColorStruct.Flags |= CC_FULLOPEN;
|
||||||
|
|
||||||
|
// Set the global pointer for the duration of the modal dialog life-time.
|
||||||
|
gs_activeDialog = this;
|
||||||
|
wxON_BLOCK_EXIT_NULL(gs_activeDialog);
|
||||||
|
|
||||||
// do show the modal dialog
|
// do show the modal dialog
|
||||||
if ( !::ChooseColor(&chooseColorStruct) )
|
if ( !::ChooseColor(&chooseColorStruct) )
|
||||||
{
|
{
|
||||||
@@ -274,4 +343,15 @@ void wxColourDialog::MSWOnInitDone(WXHWND hDlg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxColourDialog::MSWCheckIfCurrentChanged(WXCOLORREF currentCol)
|
||||||
|
{
|
||||||
|
if ( currentCol == m_currentCol )
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_currentCol = currentCol;
|
||||||
|
|
||||||
|
wxColourDialogEvent event(wxEVT_COLOUR_CHANGED, this, wxRGBToColour(currentCol));
|
||||||
|
ProcessWindowEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // wxUSE_COLOURDLG
|
#endif // wxUSE_COLOURDLG
|
||||||
|
Reference in New Issue
Block a user