2006-05-31 19:57:54 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/clrpicker.h
|
|
|
|
// Purpose: wxColourPickerCtrl base header
|
|
|
|
// Author: Francesco Montorsi (based on Vadim Zeitlin's code)
|
|
|
|
// Modified by:
|
|
|
|
// Created: 14/4/2006
|
|
|
|
// Copyright: (c) Vadim Zeitlin, Francesco Montorsi
|
|
|
|
// Licence: wxWindows Licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_CLRPICKER_H_BASE_
|
|
|
|
#define _WX_CLRPICKER_H_BASE_
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
|
|
|
|
#if wxUSE_COLOURPICKERCTRL
|
|
|
|
|
|
|
|
#include "wx/pickerbase.h"
|
|
|
|
|
|
|
|
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxColourPickerEvent;
|
2006-05-31 19:57:54 -04:00
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
extern WXDLLIMPEXP_DATA_CORE(const char) wxColourPickerWidgetNameStr[];
|
|
|
|
extern WXDLLIMPEXP_DATA_CORE(const char) wxColourPickerCtrlNameStr[];
|
2006-05-31 19:57:54 -04:00
|
|
|
|
2007-11-05 17:31:24 -05:00
|
|
|
// show the colour in HTML form (#AABBCC) as colour button label
|
|
|
|
#define wxCLRBTN_SHOW_LABEL 100
|
|
|
|
|
|
|
|
// the default style
|
|
|
|
#define wxCLRBTN_DEFAULT_STYLE (wxCLRBTN_SHOW_LABEL)
|
|
|
|
|
|
|
|
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxColourPickerWidgetBase: a generic abstract interface which must be
|
|
|
|
// implemented by controls used by wxColourPickerCtrl
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_CORE wxColourPickerWidgetBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxColourPickerWidgetBase() { m_colour = *wxBLACK; }
|
|
|
|
virtual ~wxColourPickerWidgetBase() {}
|
|
|
|
|
|
|
|
wxColour GetColour() const
|
|
|
|
{ return m_colour; }
|
|
|
|
virtual void SetColour(const wxColour &col)
|
|
|
|
{ m_colour = col; UpdateColour(); }
|
|
|
|
virtual void SetColour(const wxString &col)
|
|
|
|
{ m_colour.Set(col); UpdateColour(); }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual void UpdateColour() = 0;
|
|
|
|
|
|
|
|
// the current colour (may be invalid if none)
|
|
|
|
wxColour m_colour;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Styles which must be supported by all controls implementing wxColourPickerWidgetBase
|
|
|
|
// NB: these styles must be defined to carefully-chosen values to
|
|
|
|
// avoid conflicts with wxButton's styles
|
|
|
|
|
|
|
|
// show the colour in HTML form (#AABBCC) as colour button label
|
|
|
|
// (instead of no label at all)
|
|
|
|
// NOTE: this style is supported just by wxColourButtonGeneric and
|
|
|
|
// thus is not exposed in wxColourPickerCtrl
|
|
|
|
#define wxCLRP_SHOW_LABEL 0x0008
|
2015-11-11 11:32:21 -05:00
|
|
|
#define wxCLRP_SHOW_ALPHA 0x0010
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
// map platform-dependent controls which implement the wxColourPickerWidgetBase
|
|
|
|
// under the name "wxColourPickerWidget".
|
|
|
|
// NOTE: wxColourPickerCtrl allocates a wxColourPickerWidget and relies on the
|
|
|
|
// fact that all classes being mapped as wxColourPickerWidget have the
|
|
|
|
// same prototype for their contructor (and also explains why we use
|
|
|
|
// define instead of a typedef)
|
2006-07-17 11:02:35 -04:00
|
|
|
// since GTK > 2.4, there is GtkColorButton
|
2007-11-05 17:31:24 -05:00
|
|
|
#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
|
2006-05-31 19:57:54 -04:00
|
|
|
#include "wx/gtk/clrpicker.h"
|
|
|
|
#define wxColourPickerWidget wxColourButton
|
2014-08-23 21:50:11 -04:00
|
|
|
#elif defined(__WXQT__) && !defined(__WXUNIVERSAL__)
|
|
|
|
#include "wx/qt/clrpicker.h"
|
2006-05-31 19:57:54 -04:00
|
|
|
#else
|
|
|
|
#include "wx/generic/clrpickerg.h"
|
|
|
|
#define wxColourPickerWidget wxGenericColourButton
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxColourPickerCtrl: platform-independent class which embeds a
|
|
|
|
// platform-dependent wxColourPickerWidget and, if wxCLRP_USE_TEXTCTRL style is
|
|
|
|
// used, a textctrl next to it.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2006-06-02 08:00:30 -04:00
|
|
|
#define wxCLRP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
|
2006-05-31 19:57:54 -04:00
|
|
|
#define wxCLRP_DEFAULT_STYLE 0
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_CORE wxColourPickerCtrl : public wxPickerBase
|
|
|
|
{
|
|
|
|
public:
|
2012-09-09 09:35:57 -04:00
|
|
|
wxColourPickerCtrl() {}
|
2006-05-31 19:57:54 -04:00
|
|
|
virtual ~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);
|
|
|
|
|
|
|
|
|
|
|
|
public: // public API
|
|
|
|
|
|
|
|
// get the colour chosen
|
|
|
|
wxColour GetColour() const
|
|
|
|
{ return ((wxColourPickerWidget *)m_picker)->GetColour(); }
|
|
|
|
|
|
|
|
// set currently displayed color
|
|
|
|
void SetColour(const wxColour& col);
|
|
|
|
|
|
|
|
// set colour using RGB(r,g,b) syntax or considering given text as a colour name;
|
|
|
|
// returns true if the given text was successfully recognized.
|
|
|
|
bool SetColour(const wxString& text);
|
|
|
|
|
|
|
|
|
|
|
|
public: // internal functions
|
|
|
|
|
|
|
|
// update the button colour to match the text control contents
|
2014-03-29 20:02:23 -04:00
|
|
|
void UpdatePickerFromTextCtrl() wxOVERRIDE;
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
// update the text control to match the button's colour
|
2014-03-29 20:02:23 -04:00
|
|
|
void UpdateTextCtrlFromPicker() wxOVERRIDE;
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
// event handler for our picker
|
|
|
|
void OnColourChange(wxColourPickerEvent &);
|
|
|
|
|
2006-06-03 15:20:23 -04:00
|
|
|
protected:
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual long GetPickerStyle(long style) const wxOVERRIDE
|
2015-11-11 11:32:21 -05:00
|
|
|
{ return (style & (wxCLRP_SHOW_LABEL | wxCLRP_SHOW_ALPHA)); }
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
private:
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(wxColourPickerCtrl);
|
2006-05-31 19:57:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxColourPickerEvent: used by wxColourPickerCtrl only
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2013-04-25 06:11:03 -04:00
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COLOURPICKER_CHANGED, wxColourPickerEvent );
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
class WXDLLIMPEXP_CORE wxColourPickerEvent : public wxCommandEvent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxColourPickerEvent() {}
|
|
|
|
wxColourPickerEvent(wxObject *generator, int id, const wxColour &col)
|
2013-04-25 06:11:03 -04:00
|
|
|
: wxCommandEvent(wxEVT_COLOURPICKER_CHANGED, id),
|
2006-05-31 19:57:54 -04:00
|
|
|
m_colour(col)
|
|
|
|
{
|
|
|
|
SetEventObject(generator);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxColour GetColour() const { return m_colour; }
|
|
|
|
void SetColour(const wxColour &c) { m_colour = c; }
|
|
|
|
|
2006-06-08 14:27:44 -04:00
|
|
|
|
|
|
|
// default copy ctor, assignment operator and dtor are ok
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxEvent *Clone() const wxOVERRIDE { return new wxColourPickerEvent(*this); }
|
2006-06-08 14:27:44 -04:00
|
|
|
|
2006-05-31 19:57:54 -04:00
|
|
|
private:
|
|
|
|
wxColour m_colour;
|
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxColourPickerEvent);
|
2006-05-31 19:57:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event types and macros
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
typedef void (wxEvtHandler::*wxColourPickerEventFunction)(wxColourPickerEvent&);
|
|
|
|
|
|
|
|
#define wxColourPickerEventHandler(func) \
|
2009-01-12 09:26:13 -05:00
|
|
|
wxEVENT_HANDLER_CAST(wxColourPickerEventFunction, func)
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
#define EVT_COLOURPICKER_CHANGED(id, fn) \
|
2013-04-25 06:11:03 -04:00
|
|
|
wx__DECLARE_EVT1(wxEVT_COLOURPICKER_CHANGED, id, wxColourPickerEventHandler(fn))
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
|
2013-04-25 06:11:03 -04:00
|
|
|
// old wxEVT_COMMAND_* constant
|
|
|
|
#define wxEVT_COMMAND_COLOURPICKER_CHANGED wxEVT_COLOURPICKER_CHANGED
|
|
|
|
|
2006-05-31 19:57:54 -04:00
|
|
|
#endif // wxUSE_COLOURPICKERCTRL
|
|
|
|
|
|
|
|
#endif // _WX_CLRPICKER_H_BASE_
|
|
|
|
|