00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifdef HAVE_CONFIG_H
00031 # include <config.h>
00032 #endif
00033
00034 #ifdef _MSC_VER
00035 #pragma warning(disable: 4786)
00036 #endif
00037
00038 #include "ColorPickerControl.h"
00039
00040 #include <wx/wx.h>
00041 #include <wx/colordlg.h>
00042
00043
00044
00045
00046
00047
00048 BEGIN_EVENT_TABLE(ColorPickerControl, wxControl)
00049 EVT_PAINT(ColorPickerControl::OnPaint)
00050 EVT_LEFT_UP(ColorPickerControl::OnLeftUp)
00051 END_EVENT_TABLE()
00052
00053 IMPLEMENT_DYNAMIC_CLASS(ColorPickerControl, wxControl);
00054
00055
00056
00057
00058
00059
00060 ColorPickerControl::ColorPickerControl()
00061 {
00062 }
00063
00064
00065
00066
00067
00068
00069 ColorPickerControl::ColorPickerControl(wxWindow* parent, wxWindowID id, wxPoint pt, wxSize sz)
00070 {
00071 Create(parent, id, pt, sz, wxSUNKEN_BORDER | wxTAB_TRAVERSAL);
00072
00073 m_clrSelection.Set(0, 0, 0);
00074 }
00075
00076
00077
00078
00079
00080
00081 void ColorPickerControl::OnPaint(wxPaintEvent& event)
00082 {
00083 wxPaintDC dc(this);
00084 wxRect rect;
00085 wxBrush brOld;
00086 wxPen penOld;
00087
00088 if (IsEnabled())
00089 {
00090 wxBrush brThis(m_clrSelection, wxSOLID);
00091 wxPen penThis(m_clrSelection, 1, wxSOLID);
00092
00093 rect = GetClientRect();
00094
00095 brOld = dc.GetBrush();
00096 dc.SetBrush(brThis);
00097
00098 penOld = dc.GetPen();
00099 dc.SetPen(penThis);
00100
00101 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
00102 }
00103 else
00104 {
00105 wxBrush brThis(*wxWHITE, wxSOLID);
00106 wxPen penThis(*wxWHITE, 1, wxSOLID);
00107 wxPen penRedLine(*wxRED, 2, wxSOLID);
00108
00109 rect = GetClientRect();
00110
00111 brOld = dc.GetBrush();
00112 dc.SetBrush(brThis);
00113
00114 penOld = dc.GetPen();
00115 dc.SetPen(penThis);
00116
00117 dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
00118
00119 dc.SetPen(penRedLine);
00120 dc.DrawLine(0, 0, rect.width, rect.height);
00121 }
00122
00123 dc.SetBrush(brOld);
00124 dc.SetPen(penOld);
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 void ColorPickerControl::OnLeftUp(wxMouseEvent& event)
00138 {
00139 wxColourDialog dlgColor(this);
00140
00141 dlgColor.GetColourData().SetColour(m_clrSelection);
00142
00143 if (dlgColor.ShowModal() == wxID_OK)
00144 {
00145 m_clrSelection = dlgColor.GetColourData().GetColour();
00146
00147 Refresh();
00148
00149 wxCommandEvent ev(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
00150
00151 GetParent()->AddPendingEvent(ev);
00152 }
00153 }
00154
00155
00156
00157
00158
00159
00160
00161 void ColorPickerControl::SetColor(wxColour clrColor)
00162 {
00163 m_clrSelection = clrColor;
00164
00165 Refresh();
00166 }
00167
00168
00169
00170
00171
00172
00173 wxColour ColorPickerControl::GetColor()
00174 {
00175 return m_clrSelection;
00176 }