19
19
#include "ctl/ctlColourPicker.h"
22
void ctlColourPicker::Create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size)
22
void ctlColourPicker::Create(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size)
25
m_title = _("Choose the colour");
27
// Create the wxBitmapButton
28
((wxBitmapButton *)this)->Create(parent, id, wxNullBitmap, pos, size);
30
// Set the handler for a click
31
Connect(id, wxEVT_LEFT_DOWN, wxMouseEventHandler(ctlColourPicker::DoProcessLeftClick) );
25
m_title = _("Choose the colour");
27
// Create the wxBitmapButton
28
((wxBitmapButton *)this)->Create(parent, id, wxNullBitmap, pos, size);
30
// Set the handler for a click
31
Connect(id, wxEVT_LEFT_DOWN, wxMouseEventHandler(ctlColourPicker::DoProcessLeftClick) );
35
void ctlColourPicker::DoProcessLeftClick(wxMouseEvent& event)
35
void ctlColourPicker::DoProcessLeftClick(wxMouseEvent &event)
39
// If there is an initial colour, set it for wxColourDialog
40
if (m_colour_clr.IsOk())
41
clrData.SetColour(m_colour_clr);
43
// Declare the new dialog
44
wxColourDialog dialog(this, &clrData);
47
dialog.SetTitle(m_title);
50
if (dialog.ShowModal() == wxID_OK)
52
clrData = dialog.GetColourData();
39
// Initialise custom colours
40
for (int index = 0; index < 16; index++)
41
clrData.SetCustomColour(index, settings->GetCustomColour(index));
43
// If there is an initial colour, set it for wxColourDialog
44
if (m_colour_clr.IsOk())
45
clrData.SetColour(m_colour_clr);
47
// Declare the new dialog
48
wxColourDialog dialog(this, &clrData);
51
dialog.SetTitle(m_title);
54
if (dialog.ShowModal() == wxID_OK)
56
clrData = dialog.GetColourData();
53
57
SetColour(clrData.GetColour());
59
// Store custom colours
60
for (int index = 0; index < 16; index++)
61
settings->SetCustomColour(index, clrData.GetCustomColour(index).GetAsString(wxC2S_HTML_SYNTAX));
58
66
void ctlColourPicker::UpdateColour()
60
if (!m_colour_clr.IsOk())
63
SetBitmapLabel(empty);
67
wxSize sz = GetSize();
68
sz.x -= 2*GetMarginX();
69
sz.y -= 2*GetMarginY();
77
wxBitmap bmp(sz.x, sz.y);
80
dc.SetBrush(wxBrush(m_colour_clr));
81
dc.DrawRectangle(topleft,sz);
83
((wxBitmapButton *)this)->SetBitmapLabel(bmp);
68
if (!m_colour_clr.IsOk())
71
SetBitmapLabel(empty);
75
wxSize sz = GetSize();
76
sz.x -= 2 * GetMarginX();
77
sz.y -= 2 * GetMarginY();
84
wxBitmap bmp(sz.x, sz.y);
87
dc.SetBrush(wxBrush(m_colour_clr));
88
dc.DrawRectangle(topleft, sz);
90
((wxBitmapButton *)this)->SetBitmapLabel(bmp);
86
93
wxColour ctlColourPicker::GetColour()
91
98
wxString ctlColourPicker::GetColourString()
93
if (!m_colour_clr.IsOk())
100
if (!m_colour_clr.IsOk())
101
return wxEmptyString;
95
102
return m_colour_clr.GetAsString();
98
void ctlColourPicker::SetColour(const wxColour& colour)
105
void ctlColourPicker::SetColour(const wxColour &colour)
100
107
m_colour_clr = colour;
104
void ctlColourPicker::SetColour(const wxString& colour)
111
void ctlColourPicker::SetColour(const wxString &colour)
106
113
m_colour_clr = wxColour(colour);
110
void ctlColourPicker::SetTitle(const wxString& title)
117
void ctlColourPicker::SetTitle(const wxString &title)