]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
f4da9a94 | 2 | // Name: src/generic/colrdlgg.cpp |
c801d85f KB |
3 | // Purpose: Choice dialogs |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6aa89a22 | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
c801d85f KB |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
1e6feb95 | 16 | #pragma hdrstop |
c801d85f KB |
17 | #endif |
18 | ||
ff654490 | 19 | #if wxUSE_COLOURDLG |
1e6feb95 | 20 | |
c801d85f | 21 | #ifndef WX_PRECOMP |
1e6feb95 VZ |
22 | #include "wx/utils.h" |
23 | #include "wx/intl.h" | |
24 | #include "wx/dialog.h" | |
25 | #include "wx/listbox.h" | |
26 | #include "wx/button.h" | |
27 | #include "wx/stattext.h" | |
28 | #include "wx/layout.h" | |
29 | #include "wx/dcclient.h" | |
1e6feb95 | 30 | #include "wx/sizer.h" |
f4da9a94 | 31 | #include "wx/slider.h" |
4130b487 RR |
32 | #endif |
33 | ||
34 | #if wxUSE_STATLINE | |
35 | #include "wx/statline.h" | |
c801d85f KB |
36 | #endif |
37 | ||
081d8d96 | 38 | #include "wx/colourdata.h" |
c801d85f KB |
39 | #include "wx/generic/colrdlgg.h" |
40 | ||
c801d85f KB |
41 | IMPLEMENT_DYNAMIC_CLASS(wxGenericColourDialog, wxDialog) |
42 | ||
43 | BEGIN_EVENT_TABLE(wxGenericColourDialog, wxDialog) | |
c35414db | 44 | EVT_BUTTON(wxID_ADD_CUSTOM, wxGenericColourDialog::OnAddCustom) |
6bb44116 | 45 | #if wxUSE_SLIDER |
c35414db VZ |
46 | EVT_SLIDER(wxID_RED_SLIDER, wxGenericColourDialog::OnRedSlider) |
47 | EVT_SLIDER(wxID_GREEN_SLIDER, wxGenericColourDialog::OnGreenSlider) | |
48 | EVT_SLIDER(wxID_BLUE_SLIDER, wxGenericColourDialog::OnBlueSlider) | |
6bb44116 | 49 | #endif |
c35414db VZ |
50 | EVT_PAINT(wxGenericColourDialog::OnPaint) |
51 | EVT_MOUSE_EVENTS(wxGenericColourDialog::OnMouseEvent) | |
52 | EVT_CLOSE(wxGenericColourDialog::OnCloseWindow) | |
c801d85f KB |
53 | END_EVENT_TABLE() |
54 | ||
c801d85f KB |
55 | |
56 | /* | |
57 | * Generic wxColourDialog | |
58 | */ | |
59 | ||
61138de0 VZ |
60 | // don't change the number of elements (48) in this array, the code below is |
61 | // hardcoded to use it | |
a243da29 | 62 | static const wxChar *const wxColourDialogNames[] = |
61138de0 VZ |
63 | { |
64 | wxT("ORANGE"), | |
65 | wxT("GOLDENROD"), | |
66 | wxT("WHEAT"), | |
67 | wxT("SPRING GREEN"), | |
68 | wxT("SKY BLUE"), | |
69 | wxT("SLATE BLUE"), | |
70 | wxT("MEDIUM VIOLET RED"), | |
71 | wxT("PURPLE"), | |
72 | ||
73 | wxT("RED"), | |
74 | wxT("YELLOW"), | |
75 | wxT("MEDIUM SPRING GREEN"), | |
76 | wxT("PALE GREEN"), | |
77 | wxT("CYAN"), | |
78 | wxT("LIGHT STEEL BLUE"), | |
79 | wxT("ORCHID"), | |
80 | wxT("LIGHT MAGENTA"), | |
81 | ||
82 | wxT("BROWN"), | |
83 | wxT("YELLOW"), | |
84 | wxT("GREEN"), | |
85 | wxT("CADET BLUE"), | |
86 | wxT("MEDIUM BLUE"), | |
87 | wxT("MAGENTA"), | |
88 | wxT("MAROON"), | |
89 | wxT("ORANGE RED"), | |
90 | ||
91 | wxT("FIREBRICK"), | |
92 | wxT("CORAL"), | |
93 | wxT("FOREST GREEN"), | |
94 | wxT("AQUAMARINE"), | |
95 | wxT("BLUE"), | |
96 | wxT("NAVY"), | |
97 | wxT("THISTLE"), | |
98 | wxT("MEDIUM VIOLET RED"), | |
99 | ||
100 | wxT("INDIAN RED"), | |
101 | wxT("GOLD"), | |
102 | wxT("MEDIUM SEA GREEN"), | |
103 | wxT("MEDIUM BLUE"), | |
104 | wxT("MIDNIGHT BLUE"), | |
105 | wxT("GREY"), | |
106 | wxT("PURPLE"), | |
107 | wxT("KHAKI"), | |
108 | ||
109 | wxT("BLACK"), | |
110 | wxT("MEDIUM FOREST GREEN"), | |
111 | wxT("KHAKI"), | |
112 | wxT("DARK GREY"), | |
113 | wxT("SEA GREEN"), | |
114 | wxT("LIGHT GREY"), | |
115 | wxT("MEDIUM SLATE BLUE"), | |
116 | wxT("WHITE") | |
117 | }; | |
c801d85f | 118 | |
4130b487 | 119 | wxGenericColourDialog::wxGenericColourDialog() |
c801d85f | 120 | { |
66c59e2c VZ |
121 | m_whichKind = 1; |
122 | m_colourSelection = -1; | |
c801d85f KB |
123 | } |
124 | ||
f6bcfd97 BP |
125 | wxGenericColourDialog::wxGenericColourDialog(wxWindow *parent, |
126 | wxColourData *data) | |
c801d85f | 127 | { |
66c59e2c VZ |
128 | m_whichKind = 1; |
129 | m_colourSelection = -1; | |
f4da9a94 | 130 | Create(parent, data); |
c801d85f KB |
131 | } |
132 | ||
4130b487 | 133 | wxGenericColourDialog::~wxGenericColourDialog() |
c801d85f KB |
134 | { |
135 | } | |
136 | ||
74e3313b | 137 | void wxGenericColourDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) |
c801d85f | 138 | { |
f4da9a94 | 139 | EndModal(wxID_CANCEL); |
c801d85f KB |
140 | } |
141 | ||
142 | bool wxGenericColourDialog::Create(wxWindow *parent, wxColourData *data) | |
143 | { | |
cdc48273 | 144 | if ( !wxDialog::Create(GetParentForModalDialog(parent, 0), wxID_ANY, |
2229243b VZ |
145 | _("Choose colour"), |
146 | wxPoint(0, 0), wxSize(900, 900)) ) | |
ca65c044 | 147 | return false; |
c35414db | 148 | |
f6bcfd97 | 149 | if (data) |
66c59e2c | 150 | m_colourData = *data; |
c35414db | 151 | |
f6bcfd97 BP |
152 | InitializeColours(); |
153 | CalculateMeasurements(); | |
154 | CreateWidgets(); | |
155 | ||
ca65c044 | 156 | return true; |
c801d85f KB |
157 | } |
158 | ||
4130b487 | 159 | int wxGenericColourDialog::ShowModal() |
c801d85f | 160 | { |
f4da9a94 | 161 | return wxDialog::ShowModal(); |
c801d85f KB |
162 | } |
163 | ||
164 | ||
165 | // Internal functions | |
166 | void wxGenericColourDialog::OnMouseEvent(wxMouseEvent& event) | |
167 | { | |
168 | if (event.ButtonDown(1)) | |
169 | { | |
170 | int x = (int)event.GetX(); | |
171 | int y = (int)event.GetY(); | |
172 | ||
b1f9d7bf DW |
173 | #ifdef __WXPM__ |
174 | // Handle OS/2's reverse coordinate system and account for the dialog title | |
175 | int nClientHeight; | |
176 | ||
177 | GetClientSize(NULL, &nClientHeight); | |
178 | y = (nClientHeight - y) + 20; | |
179 | #endif | |
66c59e2c VZ |
180 | if ((x >= m_standardColoursRect.x && x <= (m_standardColoursRect.x + m_standardColoursRect.width)) && |
181 | (y >= m_standardColoursRect.y && y <= (m_standardColoursRect.y + m_standardColoursRect.height))) | |
c801d85f | 182 | { |
66c59e2c VZ |
183 | int selX = (int)(x - m_standardColoursRect.x)/(m_smallRectangleSize.x + m_gridSpacing); |
184 | int selY = (int)(y - m_standardColoursRect.y)/(m_smallRectangleSize.y + m_gridSpacing); | |
c801d85f KB |
185 | int ptr = (int)(selX + selY*8); |
186 | OnBasicColourClick(ptr); | |
187 | } | |
66c59e2c VZ |
188 | else if ((x >= m_customColoursRect.x && x <= (m_customColoursRect.x + m_customColoursRect.width)) && |
189 | (y >= m_customColoursRect.y && y <= (m_customColoursRect.y + m_customColoursRect.height))) | |
c801d85f | 190 | { |
66c59e2c VZ |
191 | int selX = (int)(x - m_customColoursRect.x)/(m_smallRectangleSize.x + m_gridSpacing); |
192 | int selY = (int)(y - m_customColoursRect.y)/(m_smallRectangleSize.y + m_gridSpacing); | |
c801d85f KB |
193 | int ptr = (int)(selX + selY*8); |
194 | OnCustomColourClick(ptr); | |
195 | } | |
c10920de VS |
196 | else |
197 | event.Skip(); | |
c801d85f | 198 | } |
c10920de VS |
199 | else |
200 | event.Skip(); | |
c801d85f KB |
201 | } |
202 | ||
4a699e3a | 203 | void wxGenericColourDialog::OnPaint(wxPaintEvent& WXUNUSED(event)) |
c801d85f | 204 | { |
7a893a31 | 205 | wxPaintDC dc(this); |
c801d85f | 206 | |
7a893a31 WS |
207 | PaintBasicColours(dc); |
208 | PaintCustomColours(dc); | |
209 | PaintCustomColour(dc); | |
210 | PaintHighlight(dc, true); | |
c801d85f KB |
211 | } |
212 | ||
4130b487 | 213 | void wxGenericColourDialog::CalculateMeasurements() |
c801d85f | 214 | { |
66c59e2c VZ |
215 | m_smallRectangleSize.x = 18; |
216 | m_smallRectangleSize.y = 14; | |
217 | m_customRectangleSize.x = 40; | |
218 | m_customRectangleSize.y = 40; | |
c801d85f | 219 | |
66c59e2c VZ |
220 | m_gridSpacing = 6; |
221 | m_sectionSpacing = 15; | |
c801d85f | 222 | |
66c59e2c | 223 | m_standardColoursRect.x = 10; |
b1f9d7bf | 224 | #ifdef __WXPM__ |
66c59e2c | 225 | m_standardColoursRect.y = 15 + 20; /* OS/2 needs to account for dialog titlebar */ |
b1f9d7bf | 226 | #else |
66c59e2c | 227 | m_standardColoursRect.y = 15; |
b1f9d7bf | 228 | #endif |
66c59e2c VZ |
229 | m_standardColoursRect.width = (8*m_smallRectangleSize.x) + (7*m_gridSpacing); |
230 | m_standardColoursRect.height = (6*m_smallRectangleSize.y) + (5*m_gridSpacing); | |
231 | ||
232 | m_customColoursRect.x = m_standardColoursRect.x; | |
233 | m_customColoursRect.y = m_standardColoursRect.y + m_standardColoursRect.height + 20; | |
234 | m_customColoursRect.width = (8*m_smallRectangleSize.x) + (7*m_gridSpacing); | |
235 | m_customColoursRect.height = (2*m_smallRectangleSize.y) + (1*m_gridSpacing); | |
236 | ||
237 | m_singleCustomColourRect.x = m_customColoursRect.width + m_customColoursRect.x + m_sectionSpacing; | |
238 | m_singleCustomColourRect.y = 80; | |
239 | m_singleCustomColourRect.width = m_customRectangleSize.x; | |
240 | m_singleCustomColourRect.height = m_customRectangleSize.y; | |
241 | ||
242 | m_okButtonX = 10; | |
243 | m_customButtonX = m_singleCustomColourRect.x ; | |
244 | m_buttonY = m_customColoursRect.y + m_customColoursRect.height + 10; | |
c801d85f KB |
245 | } |
246 | ||
4130b487 | 247 | void wxGenericColourDialog::CreateWidgets() |
c801d85f | 248 | { |
4130b487 | 249 | wxBeginBusyCursor(); |
c801d85f | 250 | |
6bb44116 WS |
251 | wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); |
252 | ||
f79a46f8 | 253 | const int sliderHeight = 160; |
4130b487 | 254 | |
bd9f3519 | 255 | // first sliders |
6bb44116 | 256 | #if wxUSE_SLIDER |
66c59e2c | 257 | const int sliderX = m_singleCustomColourRect.x + m_singleCustomColourRect.width + m_sectionSpacing; |
6bb44116 | 258 | |
66c59e2c | 259 | m_redSlider = new wxSlider(this, wxID_RED_SLIDER, m_colourData.m_dataColour.Red(), 0, 255, |
a3b8b891 | 260 | wxDefaultPosition, wxSize(wxDefaultCoord, sliderHeight), wxSL_VERTICAL|wxSL_LABELS|wxSL_INVERSE); |
66c59e2c | 261 | m_greenSlider = new wxSlider(this, wxID_GREEN_SLIDER, m_colourData.m_dataColour.Green(), 0, 255, |
a3b8b891 | 262 | wxDefaultPosition, wxSize(wxDefaultCoord, sliderHeight), wxSL_VERTICAL|wxSL_LABELS|wxSL_INVERSE); |
66c59e2c | 263 | m_blueSlider = new wxSlider(this, wxID_BLUE_SLIDER, m_colourData.m_dataColour.Blue(), 0, 255, |
a3b8b891 | 264 | wxDefaultPosition, wxSize(wxDefaultCoord, sliderHeight), wxSL_VERTICAL|wxSL_LABELS|wxSL_INVERSE); |
f79a46f8 WS |
265 | |
266 | wxBoxSizer *sliderSizer = new wxBoxSizer( wxHORIZONTAL ); | |
267 | ||
bd9f3519 | 268 | sliderSizer->Add(sliderX, sliderHeight ); |
4130b487 | 269 | |
bd9f3519 VZ |
270 | wxSizerFlags flagsRight; |
271 | flagsRight.Align(wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL).DoubleBorder(); | |
272 | ||
66c59e2c VZ |
273 | sliderSizer->Add(m_redSlider, flagsRight); |
274 | sliderSizer->Add(m_greenSlider,flagsRight); | |
275 | sliderSizer->Add(m_blueSlider,flagsRight); | |
bd9f3519 VZ |
276 | |
277 | topSizer->Add(sliderSizer, wxSizerFlags().Centre().DoubleBorder()); | |
6bb44116 | 278 | #else |
bd9f3519 | 279 | topSizer->Add(1, sliderHeight, wxSizerFlags(1).Centre().TripleBorder()); |
6bb44116 | 280 | #endif // wxUSE_SLIDER |
6c34d0ed | 281 | |
bd9f3519 VZ |
282 | // then the custom button |
283 | topSizer->Add(new wxButton(this, wxID_ADD_CUSTOM, | |
284 | _("Add to custom colours") ), | |
285 | wxSizerFlags().DoubleHorzBorder()); | |
c35414db | 286 | |
bd9f3519 VZ |
287 | // then the standard buttons |
288 | wxSizer *buttonsizer = CreateSeparatedButtonSizer(wxOK | wxCANCEL); | |
289 | if ( buttonsizer ) | |
290 | { | |
291 | topSizer->Add(buttonsizer, wxSizerFlags().Expand().DoubleBorder()); | |
292 | } | |
c801d85f | 293 | |
ca65c044 | 294 | SetAutoLayout( true ); |
f79a46f8 | 295 | SetSizer( topSizer ); |
6c34d0ed | 296 | |
f79a46f8 WS |
297 | topSizer->SetSizeHints( this ); |
298 | topSizer->Fit( this ); | |
c801d85f | 299 | |
4130b487 | 300 | Centre( wxBOTH ); |
c801d85f | 301 | |
4130b487 | 302 | wxEndBusyCursor(); |
c801d85f KB |
303 | } |
304 | ||
305 | void wxGenericColourDialog::InitializeColours(void) | |
306 | { | |
a4ba2eec | 307 | size_t i; |
ea8a9699 | 308 | |
61138de0 | 309 | for (i = 0; i < WXSIZEOF(wxColourDialogNames); i++) |
ea8a9699 | 310 | { |
564a150b | 311 | wxColour col = wxTheColourDatabase->Find(wxColourDialogNames[i]); |
a1b806b9 | 312 | if (col.IsOk()) |
66c59e2c | 313 | m_standardColours[i].Set(col.Red(), col.Green(), col.Blue()); |
ea8a9699 | 314 | else |
66c59e2c | 315 | m_standardColours[i].Set(0, 0, 0); |
ea8a9699 | 316 | } |
c801d85f | 317 | |
66c59e2c | 318 | for (i = 0; i < WXSIZEOF(m_customColours); i++) |
ea8a9699 | 319 | { |
66c59e2c | 320 | wxColour c = m_colourData.GetCustomColour(i); |
a1b806b9 | 321 | if (c.IsOk()) |
66c59e2c | 322 | m_customColours[i] = m_colourData.GetCustomColour(i); |
a2b99ff5 | 323 | else |
66c59e2c | 324 | m_customColours[i] = wxColour(255, 255, 255); |
ea8a9699 | 325 | } |
c801d85f | 326 | |
66c59e2c | 327 | wxColour curr = m_colourData.GetColour(); |
a1b806b9 | 328 | if ( curr.IsOk() ) |
ea8a9699 | 329 | { |
66c59e2c | 330 | bool m_initColourFound = false; |
ea8a9699 | 331 | |
61138de0 | 332 | for (i = 0; i < WXSIZEOF(wxColourDialogNames); i++) |
ea8a9699 | 333 | { |
66c59e2c | 334 | if ( m_standardColours[i] == curr && !m_initColourFound ) |
ea8a9699 | 335 | { |
66c59e2c VZ |
336 | m_whichKind = 1; |
337 | m_colourSelection = i; | |
338 | m_initColourFound = true; | |
ea8a9699 VZ |
339 | break; |
340 | } | |
341 | } | |
66c59e2c | 342 | if ( !m_initColourFound ) |
ea8a9699 | 343 | { |
66c59e2c | 344 | for ( i = 0; i < WXSIZEOF(m_customColours); i++ ) |
ea8a9699 | 345 | { |
66c59e2c | 346 | if ( m_customColours[i] == curr ) |
ea8a9699 | 347 | { |
66c59e2c VZ |
348 | m_whichKind = 2; |
349 | m_colourSelection = i; | |
ea8a9699 VZ |
350 | break; |
351 | } | |
352 | } | |
353 | } | |
66c59e2c | 354 | m_colourData.m_dataColour.Set( curr.Red(), curr.Green(), curr.Blue() ); |
ea8a9699 VZ |
355 | } |
356 | else | |
357 | { | |
66c59e2c VZ |
358 | m_whichKind = 1; |
359 | m_colourSelection = 0; | |
360 | m_colourData.m_dataColour.Set( 0, 0, 0 ); | |
ea8a9699 | 361 | } |
c801d85f KB |
362 | } |
363 | ||
364 | void wxGenericColourDialog::PaintBasicColours(wxDC& dc) | |
365 | { | |
f4da9a94 WS |
366 | int i; |
367 | for (i = 0; i < 6; i++) | |
c801d85f | 368 | { |
f4da9a94 WS |
369 | int j; |
370 | for (j = 0; j < 8; j++) | |
371 | { | |
372 | int ptr = i*8 + j; | |
c35414db | 373 | |
66c59e2c VZ |
374 | int x = (j*(m_smallRectangleSize.x+m_gridSpacing) + m_standardColoursRect.x); |
375 | int y = (i*(m_smallRectangleSize.y+m_gridSpacing) + m_standardColoursRect.y); | |
c801d85f | 376 | |
f4da9a94 | 377 | dc.SetPen(*wxBLACK_PEN); |
a243da29 | 378 | wxBrush brush(m_standardColours[ptr]); |
f4da9a94 | 379 | dc.SetBrush(brush); |
c801d85f | 380 | |
66c59e2c | 381 | dc.DrawRectangle( x, y, m_smallRectangleSize.x, m_smallRectangleSize.y); |
f4da9a94 | 382 | } |
c801d85f | 383 | } |
c801d85f KB |
384 | } |
385 | ||
386 | void wxGenericColourDialog::PaintCustomColours(wxDC& dc) | |
387 | { | |
c801d85f KB |
388 | int i; |
389 | for (i = 0; i < 2; i++) | |
390 | { | |
391 | int j; | |
392 | for (j = 0; j < 8; j++) | |
393 | { | |
394 | int ptr = i*8 + j; | |
c35414db | 395 | |
66c59e2c VZ |
396 | int x = (j*(m_smallRectangleSize.x+m_gridSpacing)) + m_customColoursRect.x; |
397 | int y = (i*(m_smallRectangleSize.y+m_gridSpacing)) + m_customColoursRect.y; | |
c801d85f KB |
398 | |
399 | dc.SetPen(*wxBLACK_PEN); | |
400 | ||
a243da29 | 401 | wxBrush brush(m_customColours[ptr]); |
c801d85f KB |
402 | dc.SetBrush(brush); |
403 | ||
66c59e2c | 404 | dc.DrawRectangle( x, y, m_smallRectangleSize.x, m_smallRectangleSize.y); |
c801d85f KB |
405 | } |
406 | } | |
c801d85f KB |
407 | } |
408 | ||
409 | void wxGenericColourDialog::PaintHighlight(wxDC& dc, bool draw) | |
410 | { | |
66c59e2c | 411 | if ( m_colourSelection < 0 ) |
ea8a9699 VZ |
412 | return; |
413 | ||
c801d85f KB |
414 | // Number of pixels bigger than the standard rectangle size |
415 | // for drawing a highlight | |
416 | int deltaX = 2; | |
417 | int deltaY = 2; | |
418 | ||
66c59e2c | 419 | if (m_whichKind == 1) |
c801d85f KB |
420 | { |
421 | // Standard colours | |
66c59e2c VZ |
422 | int y = (int)(m_colourSelection / 8); |
423 | int x = (int)(m_colourSelection - (y*8)); | |
c801d85f | 424 | |
66c59e2c VZ |
425 | x = (x*(m_smallRectangleSize.x + m_gridSpacing) + m_standardColoursRect.x) - deltaX; |
426 | y = (y*(m_smallRectangleSize.y + m_gridSpacing) + m_standardColoursRect.y) - deltaY; | |
c801d85f KB |
427 | |
428 | if (draw) | |
429 | dc.SetPen(*wxBLACK_PEN); | |
430 | else | |
431 | dc.SetPen(*wxLIGHT_GREY_PEN); | |
432 | ||
433 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
66c59e2c | 434 | dc.DrawRectangle( x, y, (m_smallRectangleSize.x + (2*deltaX)), (m_smallRectangleSize.y + (2*deltaY))); |
c801d85f KB |
435 | } |
436 | else | |
437 | { | |
438 | // User-defined colours | |
66c59e2c VZ |
439 | int y = (int)(m_colourSelection / 8); |
440 | int x = (int)(m_colourSelection - (y*8)); | |
c801d85f | 441 | |
66c59e2c VZ |
442 | x = (x*(m_smallRectangleSize.x + m_gridSpacing) + m_customColoursRect.x) - deltaX; |
443 | y = (y*(m_smallRectangleSize.y + m_gridSpacing) + m_customColoursRect.y) - deltaY; | |
c801d85f KB |
444 | |
445 | if (draw) | |
446 | dc.SetPen(*wxBLACK_PEN); | |
447 | else | |
448 | dc.SetPen(*wxLIGHT_GREY_PEN); | |
c35414db | 449 | |
c801d85f | 450 | dc.SetBrush(*wxTRANSPARENT_BRUSH); |
66c59e2c | 451 | dc.DrawRectangle( x, y, (m_smallRectangleSize.x + (2*deltaX)), (m_smallRectangleSize.y + (2*deltaY))); |
c801d85f | 452 | } |
c801d85f KB |
453 | } |
454 | ||
455 | void wxGenericColourDialog::PaintCustomColour(wxDC& dc) | |
456 | { | |
f4da9a94 | 457 | dc.SetPen(*wxBLACK_PEN); |
c801d85f | 458 | |
a243da29 | 459 | wxBrush *brush = new wxBrush(m_colourData.m_dataColour); |
f4da9a94 | 460 | dc.SetBrush(*brush); |
c801d85f | 461 | |
66c59e2c VZ |
462 | dc.DrawRectangle( m_singleCustomColourRect.x, m_singleCustomColourRect.y, |
463 | m_customRectangleSize.x, m_customRectangleSize.y); | |
c801d85f | 464 | |
f4da9a94 WS |
465 | dc.SetBrush(wxNullBrush); |
466 | delete brush; | |
c801d85f KB |
467 | } |
468 | ||
469 | void wxGenericColourDialog::OnBasicColourClick(int which) | |
470 | { | |
ca65c044 | 471 | wxClientDC dc(this); |
c801d85f | 472 | |
ca65c044 | 473 | PaintHighlight(dc, false); |
66c59e2c VZ |
474 | m_whichKind = 1; |
475 | m_colourSelection = which; | |
2997ca30 | 476 | |
6bb44116 | 477 | #if wxUSE_SLIDER |
66c59e2c VZ |
478 | m_redSlider->SetValue( m_standardColours[m_colourSelection].Red() ); |
479 | m_greenSlider->SetValue( m_standardColours[m_colourSelection].Green() ); | |
480 | m_blueSlider->SetValue( m_standardColours[m_colourSelection].Blue() ); | |
6bb44116 | 481 | #endif // wxUSE_SLIDER |
2997ca30 | 482 | |
66c59e2c VZ |
483 | m_colourData.m_dataColour.Set(m_standardColours[m_colourSelection].Red(), |
484 | m_standardColours[m_colourSelection].Green(), | |
485 | m_standardColours[m_colourSelection].Blue()); | |
c801d85f | 486 | |
ca65c044 WS |
487 | PaintCustomColour(dc); |
488 | PaintHighlight(dc, true); | |
c801d85f KB |
489 | } |
490 | ||
491 | void wxGenericColourDialog::OnCustomColourClick(int which) | |
492 | { | |
ca65c044 WS |
493 | wxClientDC dc(this); |
494 | PaintHighlight(dc, false); | |
66c59e2c VZ |
495 | m_whichKind = 2; |
496 | m_colourSelection = which; | |
2997ca30 | 497 | |
6bb44116 | 498 | #if wxUSE_SLIDER |
66c59e2c VZ |
499 | m_redSlider->SetValue( m_customColours[m_colourSelection].Red() ); |
500 | m_greenSlider->SetValue( m_customColours[m_colourSelection].Green() ); | |
501 | m_blueSlider->SetValue( m_customColours[m_colourSelection].Blue() ); | |
6bb44116 | 502 | #endif // wxUSE_SLIDER |
2997ca30 | 503 | |
66c59e2c VZ |
504 | m_colourData.m_dataColour.Set(m_customColours[m_colourSelection].Red(), |
505 | m_customColours[m_colourSelection].Green(), | |
506 | m_customColours[m_colourSelection].Blue()); | |
2997ca30 | 507 | |
ca65c044 WS |
508 | PaintCustomColour(dc); |
509 | PaintHighlight(dc, true); | |
c801d85f KB |
510 | } |
511 | ||
512 | /* | |
513 | void wxGenericColourDialog::OnOk(void) | |
514 | { | |
ca65c044 | 515 | Show(false); |
c801d85f KB |
516 | } |
517 | ||
518 | void wxGenericColourDialog::OnCancel(void) | |
519 | { | |
ca65c044 WS |
520 | colourDialogCancelled = true; |
521 | Show(false); | |
c801d85f KB |
522 | } |
523 | */ | |
524 | ||
525 | void wxGenericColourDialog::OnAddCustom(wxCommandEvent& WXUNUSED(event)) | |
526 | { | |
527 | wxClientDC dc(this); | |
66c59e2c | 528 | if (m_whichKind != 2) |
c801d85f | 529 | { |
ca65c044 | 530 | PaintHighlight(dc, false); |
66c59e2c VZ |
531 | m_whichKind = 2; |
532 | m_colourSelection = 0; | |
ca65c044 | 533 | PaintHighlight(dc, true); |
c801d85f KB |
534 | } |
535 | ||
66c59e2c VZ |
536 | m_customColours[m_colourSelection].Set(m_colourData.m_dataColour.Red(), |
537 | m_colourData.m_dataColour.Green(), | |
538 | m_colourData.m_dataColour.Blue()); | |
2997ca30 | 539 | |
66c59e2c | 540 | m_colourData.SetCustomColour(m_colourSelection, m_customColours[m_colourSelection]); |
c35414db | 541 | |
c801d85f KB |
542 | PaintCustomColours(dc); |
543 | } | |
544 | ||
6bb44116 WS |
545 | #if wxUSE_SLIDER |
546 | ||
c801d85f KB |
547 | void wxGenericColourDialog::OnRedSlider(wxCommandEvent& WXUNUSED(event)) |
548 | { | |
66c59e2c | 549 | if (!m_redSlider) |
c801d85f | 550 | return; |
c35414db | 551 | |
c801d85f | 552 | wxClientDC dc(this); |
66c59e2c | 553 | m_colourData.m_dataColour.Set((unsigned char)m_redSlider->GetValue(), m_colourData.m_dataColour.Green(), m_colourData.m_dataColour.Blue()); |
c801d85f KB |
554 | PaintCustomColour(dc); |
555 | } | |
556 | ||
557 | void wxGenericColourDialog::OnGreenSlider(wxCommandEvent& WXUNUSED(event)) | |
558 | { | |
66c59e2c | 559 | if (!m_greenSlider) |
c801d85f KB |
560 | return; |
561 | ||
562 | wxClientDC dc(this); | |
66c59e2c | 563 | m_colourData.m_dataColour.Set(m_colourData.m_dataColour.Red(), (unsigned char)m_greenSlider->GetValue(), m_colourData.m_dataColour.Blue()); |
c801d85f KB |
564 | PaintCustomColour(dc); |
565 | } | |
566 | ||
567 | void wxGenericColourDialog::OnBlueSlider(wxCommandEvent& WXUNUSED(event)) | |
568 | { | |
66c59e2c | 569 | if (!m_blueSlider) |
c801d85f KB |
570 | return; |
571 | ||
572 | wxClientDC dc(this); | |
66c59e2c | 573 | m_colourData.m_dataColour.Set(m_colourData.m_dataColour.Red(), m_colourData.m_dataColour.Green(), (unsigned char)m_blueSlider->GetValue()); |
c801d85f KB |
574 | PaintCustomColour(dc); |
575 | } | |
576 | ||
6bb44116 WS |
577 | #endif // wxUSE_SLIDER |
578 | ||
ff654490 | 579 | #endif // wxUSE_COLOURDLG |