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