1%%	options
2
3copyright owner	=	Dirk Krause
4copyright year	=	2018-xxxx
5SPDX-License-Identifier:	BSD-3-Clause
6
7%%	wx-gui
8
9type			=	dialog
10contents		=	mainSizerHorizontal
11
12[wxBoxSizer mainSizerHorizontal]
13direction		=	horizontal
14contents		=	$space(10)
15contents		=	mainSizerVertical
16contents		=	$space(10)
17
18[wxBoxSizer mainSizerVertical]
19direction		=	vertical
20contents		=	$space(10)
21contents		=	choiceBookInput
22contents		=	$space(10)
23contents		=	resultSizerHexadecimal
24contents		=	resultSizerDecimal
25contents		=	$space(5)
26contents		=	colourViewResult
27contents		=	$space(10)
28contents		=	buttonsDialog		centered-x
29contents		=	$space(10)
30
31[wxChoicebook choiceBookInput]
32id				=	ID_CHOICEBOOK
33contents		=	panelFig
34contents		=	panelHtmlNamed
35contents		=	panelHtml216
36tip				=	lTexts[1]
37
38[wxPanel panelFig]
39text			=	lTexts[26]
40contents		=	figSizerHorizontal
41
42[wxBoxSizer figSizerHorizontal]
43direction		=	horizontal
44contents		=	$stretch(5)
45contents		=	figSizerVertical
46contents		=	$stretch(5)
47
48[wxBoxSizer figSizerVertical]
49direction		=	vertical
50contents		=	$stretch(5)
51contents		=	figButtonRow0
52contents		=	$space(5)
53contents		=	figButtonRow1
54contents		=	$space(5)
55contents		=	figButtonRow2
56contents		=	$space(5)
57contents		=	figButtonRow3
58contents		=	$space(10)
59contents		=	figShaderLabelSizer
60contents		=	$space(5)
61contents		=	figShaderSlider
62contents		=	$stretch(5)
63
64[wxBoxSizer figButtonRow0]
65direction		=	horizontal
66contents		=	b00
67contents		=	$space(5)
68contents		=	b01
69contents		=	$space(5)
70contents		=	b02
71contents		=	$space(5)
72contents		=	b03
73contents		=	$space(5)
74contents		=	b04
75contents		=	$space(5)
76contents		=	b05
77contents		=	$space(5)
78contents		=	b06
79contents		=	$space(5)
80contents		=	b07
81
82[wxBoxSizer figButtonRow1]
83direction		=	horizontal
84contents		=	b08
85contents		=	$space(5)
86contents		=	b09
87contents		=	$space(5)
88contents		=	b10
89contents		=	$space(5)
90contents		=	b11
91contents		=	$space(5)
92contents		=	b12
93contents		=	$space(5)
94contents		=	b13
95contents		=	$space(5)
96contents		=	b14
97contents		=	$space(5)
98contents		=	b15
99
100[wxBoxSizer figButtonRow2]
101direction		=	horizontal
102contents		=	b16
103contents		=	$space(5)
104contents		=	b17
105contents		=	$space(5)
106contents		=	b18
107contents		=	$space(5)
108contents		=	b19
109contents		=	$space(5)
110contents		=	b20
111contents		=	$space(5)
112contents		=	b21
113contents		=	$space(5)
114contents		=	b22
115contents		=	$space(5)
116contents		=	b23
117
118[wxBoxSizer figButtonRow3]
119direction		=	horizontal
120contents		=	b24
121contents		=	$space(5)
122contents		=	b25
123contents		=	$space(5)
124contents		=	b26
125contents		=	$space(5)
126contents		=	b27
127contents		=	$space(5)
128contents		=	b28
129contents		=	$space(5)
130contents		=	b29
131contents		=	$space(5)
132contents		=	b30
133contents		=	$space(5)
134contents		=	b31
135
136[Dk4WxColourPaletteItem b00]
137constructor		=	this, pAppHelper, 0, 0, 0
138tip				=	lTexts[2]
139
140[Dk4WxColourPaletteItem b01]
141constructor		=	this, pAppHelper, 0,   0, 255
142tip				=	lTexts[2]
143
144[Dk4WxColourPaletteItem b02]
145constructor		=	this, pAppHelper, 0, 255,   0
146tip				=	lTexts[2]
147
148[Dk4WxColourPaletteItem b03]
149constructor		=	this, pAppHelper, 0, 255, 255
150tip				=	lTexts[2]
151
152[Dk4WxColourPaletteItem b04]
153constructor		=	this, pAppHelper, 255,   0,   0
154tip				=	lTexts[2]
155
156[Dk4WxColourPaletteItem b05]
157constructor		=	this, pAppHelper, 255,   0, 255
158tip				=	lTexts[2]
159
160[Dk4WxColourPaletteItem b06]
161constructor		=	this, pAppHelper, 255, 255,   0
162tip				=	lTexts[2]
163
164[Dk4WxColourPaletteItem b07]
165constructor		=	this, pAppHelper, 255, 255, 255
166tip				=	lTexts[2]
167
168[Dk4WxColourPaletteItem b08]
169constructor		=	this, pAppHelper, 0,   0, 143
170tip				=	lTexts[2]
171
172[Dk4WxColourPaletteItem b09]
173constructor		=	this, pAppHelper, 0,   0, 176
174tip				=	lTexts[2]
175
176[Dk4WxColourPaletteItem b10]
177constructor		=	this, pAppHelper, 0,   0, 209
178tip				=	lTexts[2]
179
180[Dk4WxColourPaletteItem b11]
181constructor		=	this, pAppHelper, 135, 207, 255
182tip				=	lTexts[2]
183
184[Dk4WxColourPaletteItem b12]
185constructor		=	this, pAppHelper, 0, 143,   0
186tip				=	lTexts[2]
187
188[Dk4WxColourPaletteItem b13]
189constructor		=	this, pAppHelper, 0, 176,   0
190tip				=	lTexts[2]
191
192[Dk4WxColourPaletteItem b14]
193constructor		=	this, pAppHelper, 0, 209,   0
194tip				=	lTexts[2]
195
196[Dk4WxColourPaletteItem b15]
197constructor		=	this, pAppHelper, 0, 143, 143
198tip				=	lTexts[2]
199
200[Dk4WxColourPaletteItem b16]
201constructor		=	this, pAppHelper, 0, 176, 176
202tip				=	lTexts[2]
203
204[Dk4WxColourPaletteItem b17]
205constructor		=	this, pAppHelper, 0, 209, 209
206tip				=	lTexts[2]
207
208[Dk4WxColourPaletteItem b18]
209constructor		=	this, pAppHelper, 143,   0,   0
210tip				=	lTexts[2]
211
212[Dk4WxColourPaletteItem b19]
213constructor		=	this, pAppHelper, 176,   0,   0
214tip				=	lTexts[2]
215
216[Dk4WxColourPaletteItem b20]
217constructor		=	this, pAppHelper, 209,   0,   0
218tip				=	lTexts[2]
219
220[Dk4WxColourPaletteItem b21]
221constructor		=	this, pAppHelper, 143,   0, 143
222tip				=	lTexts[2]
223
224[Dk4WxColourPaletteItem b22]
225constructor		=	this, pAppHelper, 176,   0, 176
226tip				=	lTexts[2]
227
228[Dk4WxColourPaletteItem b23]
229constructor		=	this, pAppHelper, 209,   0, 209
230tip				=	lTexts[2]
231
232[Dk4WxColourPaletteItem b24]
233constructor		=	this, pAppHelper, 127,  48,   0
234tip				=	lTexts[2]
235
236[Dk4WxColourPaletteItem b25]
237constructor		=	this, pAppHelper, 160,  63,   0
238tip				=	lTexts[2]
239
240[Dk4WxColourPaletteItem b26]
241constructor		=	this, pAppHelper, 191,  97,   0
242tip				=	lTexts[2]
243
244[Dk4WxColourPaletteItem b27]
245constructor		=	this, pAppHelper, 255, 127, 127
246tip				=	lTexts[2]
247
248[Dk4WxColourPaletteItem b28]
249constructor		=	this, pAppHelper, 255, 160, 160
250tip				=	lTexts[2]
251
252[Dk4WxColourPaletteItem b29]
253constructor		=	this, pAppHelper, 255, 191, 191
254tip				=	lTexts[2]
255
256[Dk4WxColourPaletteItem b30]
257constructor		=	this, pAppHelper, 255, 224, 224
258tip				=	lTexts[2]
259
260[Dk4WxColourPaletteItem b31]
261constructor		=	this, pAppHelper, 255, 214,   0
262tip				=	lTexts[2]
263
264[wxBoxSizer figShaderLabelSizer]
265direction		=	horizontal
266contents		=	$stretch(10)
267contents		=	figShaderLabelText
268contents		=	$stretch(10)
269grow			=	yes
270
271[wxStaticText figShaderLabelText]
272text			=	lTexts[4]
273text style		=	centered
274tip				=	lTexts[6]
275
276[wxSlider figShaderSlider]
277id				=	ID_SLIDER_SHADE
278direction		=	horizontal
279range			=	-20 20
280value			=	0
281grow			=	yes
282tip				=	lTexts[7]
283
284[wxPanel panelHtmlNamed]
285text			=	lTexts[27]
286contents		=	htmlNamedSizerHorizontal
287
288[wxBoxSizer htmlNamedSizerHorizontal]
289direction		=	horizontal
290contents		=	$space(5)
291contents		=	htmlNamedSizerVertical
292contents		=	$space(5)
293
294[wxBoxSizer htmlNamedSizerVertical]
295contents		=	$space(5)
296contents		=	listHtmlNames
297contents		=	$space(5)
298
299[wxListBox listHtmlNames]
300# constructor		=	wxDefaultPosition, wxDefaultSize, saHtmlNames, wxLB_SINGLE
301id				=	ID_HTML_NAMED_LIST
302choices			=	saHtmlNames
303size			=	200 200
304tip				=	lTexts[8]
305
306[wxPanel panelHtml216]
307text			=	lTexts[28]
308contents		=	html216SizerHorizontal
309
310[wxBoxSizer html216SizerHorizontal]
311direction		=	horizontal
312contents		=	$space(5)
313contents		=	html216SizerVertical
314contents		=	$space(5)
315
316[wxBoxSizer html216SizerVertical]
317direction		=	vertical
318contents		=	$space(250,5)
319contents		=	labelHtml216Red
320contents		=	sliderHtml216Red
321contents		=	$space(5)
322contents		=	labelHtml216Green
323contents		=	sliderHtml216Green
324contents		=	$space(5)
325contents		=	labelHtml216Blue
326contents		=	sliderHtml216Blue
327contents		=	$space(5)
328
329[wxStaticText labelHtml216Red]
330text			=	lTexts[9]
331
332[wxSlider sliderHtml216Red]
333id				=	ID_SLIDER_RED
334range			=	0 5
335value			=	0
336direction		=	horizontal
337grow			=	yes
338tip				=	lTexts[12]
339
340[wxStaticText labelHtml216Green]
341text			=	lTexts[10]
342
343[wxSlider sliderHtml216Green]
344id				=	ID_SLIDER_GREEN
345range			=	0 5
346value			=	0
347direction		=	horizontal
348grow			=	yes
349tip				=	lTexts[13]
350
351[wxStaticText labelHtml216Blue]
352text			=	lTexts[11]
353
354[wxSlider sliderHtml216Blue]
355id				=	ID_SLIDER_BLUE
356range			=	0 5
357value			=	0
358direction		=	horizontal
359grow			=	yes
360tip				=	lTexts[14]
361
362[wxBoxSizer resultSizerHexadecimal]
363direction		=	horizontal
364grow			=	yes
365contents		=	hexRed
366contents		=	$stretch(10)
367contents		=	hexGreen
368contents		=	$stretch(10)
369contents		=	hexBlue
370
371[wxBoxSizer resultSizerDecimal]
372direction		=	horizontal
373grow			=	yes
374contents		=	decRed
375contents		=	$stretch(10)
376contents		=	decGreen
377contents		=	$stretch(10)
378contents		=	decBlue
379
380[wxStaticText hexRed]
381text			=	not_localized_texts[0]
382tip				=	lTexts[17]
383
384[wxStaticText hexGreen]
385text			=	not_localized_texts[0]
386text style		=	centered
387tip				=	lTexts[18]
388
389[wxStaticText hexBlue]
390text			=	not_localized_texts[0]
391text style		=	right
392tip				=	lTexts[19]
393
394[wxStaticText decRed]
395text			=	not_localized_texts[1]
396tip				=	lTexts[20]
397
398[wxStaticText decGreen]
399text			=	not_localized_texts[1]
400text style		=	centered
401tip				=	lTexts[21]
402
403[wxStaticText decBlue]
404text			=	not_localized_texts[1]
405text style		=	right
406tip				=	lTexts[22]
407
408[Dk4WxColourView colourViewResult]
409constructor		=	pAppHelp, r, g, b
410tip				=	lTexts[23]
411grow			=	yes
412minimum size	=	50 50
413
414[wxStdDialogButtonSizer buttonsDialog]
415contents		=	buttonOK
416contents		=	buttonCancel
417
418[wxButton buttonOK]
419id				=	wxID_OK
420text			=	lTexts[24]
421tip				=	lTexts[25]
422
423[wxButton buttonCancel]
424id				=	wxID_CANCEL
425text			=	lTexts[15]
426tip				=	lTexts[16]
427
428
429%%	header start
430
431#ifndef DK4CONF_H_INCLUDED
432#if DK4_BUILDING_DKTOOLS4
433#include "dk4conf.h"
434#else
435#include <dktools-4/dk4conf.h>
436#endif
437#endif
438
439#ifndef WX_WXPREC_H_INCLUDED
440#include <wx/wxprec.h>
441#define	WX_WXPREC_H_INCLUDED 1
442#endif
443
444#ifdef __BORLANDC__
445#pragma hdrstop
446#endif
447
448#ifndef WX_PRECOMP
449#ifndef WX_WX_H_INCLUDED
450#include <wx/wx.h>
451#define	WX_WX_H_INCLUDED 1
452#endif
453#endif
454
455#ifndef WX_GBSIZER_H_INCLUDED
456#include <wx/gbsizer.h>
457#define	WX_GBSIZER_H_INCLUDED 1
458#endif
459
460#ifndef	WX_BOOKCTRL_H_INCLUDED
461#include <wx/bookctrl.h>
462#define	WX_BOOKCTRL_H_INCLUDED 1
463#endif
464
465#ifndef	WX_CHOICEBK_H_INCLUDED
466#include <wx/choicebk.h>
467#define	WX_CHOICEBK_H_INCLUDED 1
468#endif
469
470#ifndef	WX_STATBOX_H_INCLUDED
471#include <wx/statbox.h>
472#define	WX_STATBOX_H_INCLUDED 1
473#endif
474
475#ifndef DK4WXAPPLICTIONHELPER_H_INCLUDED
476#if DK4_BUILDING_DKTOOLS4
477#include <libdk4wx/Dk4WxApplicationHelper.h>
478#else
479#include <dktools-4/Dk4WxApplicationHelper.h>
480#endif
481#endif
482
483#ifndef	DK4WXCOLOURVIEW_H_INCLUDED
484#if DK4_BUILDING_DKTOOLS4
485#include <libdk4wx/Dk4WxColourView.h>
486#else
487#include <dktools-4/Dk4WxColourView.h>
488#endif
489#endif
490
491%%	class start
492
493/**	Color palette allowing to choose between predefined colours.
494*/
495class Dk4WxColourPalette : public wxDialog
496{
497	/**	Item in a colour palette.
498	*/
499	class Dk4WxColourPaletteItem : public wxControl
500	{
501		/**	Class is dynamic.
502		*/
503#if	wxCHECK_VERSION(3,0,0)
504		wxDECLARE_DYNAMIC_CLASS(Dk4WxColourPaletteItem);
505#else
506		DECLARE_DYNAMIC_CLASS(Dk4WxColourPaletteItem)
507#endif
508
509		/**	Event table for control.
510		*/
511#if wxCHECK_VERSION(3,0,0)
512		wxDECLARE_EVENT_TABLE();
513#else
514		DECLARE_EVENT_TABLE()
515#endif
516
517	protected:
518
519		/**	Parent dialog we have to notify about color change.
520		*/
521		Dk4WxColourPalette		*pParentWindow;
522
523		/**	Application helper.
524		*/
525		Dk4WxApplicationHelper	*pAppHelp;
526
527		/**	Class name, used in constructor and Create().
528		*/
529		static wxChar const		 Dk4WxColourPaletteItemName[];
530
531		/**	Height.
532		*/
533		int						 w;
534
535		/**	Width.
536		*/
537		int						 h;
538
539		/**	Red component of color to show.
540		*/
541		int						 r;
542
543		/**	Green component of color to show.
544		*/
545		int						 g;
546
547		/**	Blue component of color to show.
548		*/
549		int						 b;
550
551	public:
552
553		/**	Default constructor.
554		*/
555		Dk4WxColourPaletteItem();
556
557		/**	Constructor.
558			@param	pParent		Parent window.
559			@param	wxid		Window ID.
560			@param	appHelper	Application helper.
561			@param	red	Red 	component of color to show.
562			@param	green		Green component of color to show.
563			@param	blue		Blue component of color to show.
564			@param	pos			Object position.
565			@param	size		Object minimum size.
566			@param	style		Style for control.
567			@param	name		Class name.
568		*/
569		Dk4WxColourPaletteItem(
570			wxWindow				*pParent,
571			wxWindowID				 wxid,
572			Dk4WxColourPalette		*pal,
573			Dk4WxApplicationHelper	*appHelper,
574			int						 red,
575			int						 green,
576			int						 blue,
577			wxPoint const &			 pos	= wxDefaultPosition,
578			wxSize  const &			 size	= wxDefaultSize,
579			long					 style	= wxBORDER_NONE,
580			wxChar const			*name	= Dk4WxColourPaletteItemName
581		);
582
583		/**	Create object after using default constructor.
584			@param	pParent		Parent window.
585			@param	wxid		Window ID.
586			@param	appHelper	Application helper.
587			@param	red	Red 	component of color to show.
588			@param	green		Green component of color to show.
589			@param	blue		Blue component of color to show.
590			@param	pos			Object position.
591			@param	size		Object minimum size.
592			@param	style		Style for control.
593			@param	name		Class name.
594			@return	true on success, false on error.
595		*/
596		bool
597		Create(
598			wxWindow				*pParent,
599			wxWindowID				 wxid,
600			Dk4WxColourPalette		*pal,
601			Dk4WxApplicationHelper	*appHelper,
602			int						 red	= 255,
603			int						 green	= 255,
604			int						 blue	= 255,
605			wxPoint const &			 pos	= wxDefaultPosition,
606			wxSize  const &			 size	= wxDefaultSize,
607			long					 style	= wxBORDER_NONE,
608			wxChar const			*name	= Dk4WxColourPaletteItemName
609		);
610
611		/**	Find minimum size.
612		*/
613		wxSize
614		DoGetBestSize() const;
615
616		/**	Handler for erase event.
617			@param	event	Event to process.
618		*/
619		void
620		OnErase(wxEraseEvent & event);
621
622		/**	Handler for paint event.
623			@param	event	Event to process.
624		*/
625		void
626		OnPaint(wxPaintEvent & event);
627
628		/**	Handler for mouse click event.
629			@param	event	Event to process.
630		*/
631		void
632		OnLeftMouseButtonDown(wxMouseEvent & event);
633
634	};
635
636private:
637
638	/**	Events we have to respond to.
639	*/
640#if	wxCHECK_VERSION(3,0,0)
641	wxDECLARE_EVENT_TABLE();
642#else
643	DECLARE_EVENT_TABLE()
644#endif
645
646protected:
647
648	/**	Red colour for text labels.
649	*/
650	wxColour				 colourRed;
651
652	/**	Green colour for text labels.
653	*/
654	wxColour				 colourGreen;
655
656	/**	Blue colour for text labels.
657	*/
658	wxColour				 colourBlue;
659
660	/**	Application helper.
661	*/
662	Dk4WxApplicationHelper	*pAppHelp;
663
664	/**	Localized texts.
665	*/
666	wxChar const * const	*localizedTexts;
667
668	/**	Shade slider value -20 to 20.
669	*/
670	int						 slvshade;
671
672	/**	Red slider value 0 to 5.
673	*/
674	int						 slvred;
675
676	/**	Green slider value 0 to 5.
677	*/
678	int						 slvgreen;
679
680	/**	Blue slider value 0 to 5.
681	*/
682	int						 slvblue;
683
684	/**	Index of selected list item.
685	*/
686	int						 listSelection;
687
688	/**	Base red component, not shaded.
689	*/
690	int						 rb;
691
692	/**	Base green component, not shaded.
693	*/
694	int						 gb;
695
696	/**	Base blue component, not shaded.
697	*/
698	int						 bb;
699
700	/**	Result red component.
701	*/
702	int						 r;
703
704	/**	Result green component.
705	*/
706	int						 g;
707
708	/**	Result blue component.
709	*/
710	int						 b;
711
712	/**	Flag: Already in correction process.
713	*/
714	bool					 bIsCorrecting;
715
716%%	class end
717
718protected:
719
720	/**	Correct shade label.
721	*/
722	void
723	CorrectShadeLabel(void);
724
725	/**	Shade a color.
726		@param	val	Original value.
727		@return	Shaded color value.
728	*/
729	int
730	ShadeColour(int val);
731
732	/**	Correct appearance after using controls.
733		@param	reason	Which control was used.
734	*/
735	void
736	CorrectGui(int reason);
737
738	/**	Set the R, G, B text labels for the r, g, b variables.
739	*/
740	void
741	SetRgbTextLabels(void);
742
743	/**	Find RGB slider value next to a given color value.
744	*/
745	int
746	FindSliderValue(int colval);
747
748	/**	Find slider values next to the r, g, b variables.
749	*/
750	void
751	FindRgbSliderValues(void);
752
753	/**	Find list box entry next to the r, g, b variables.
754	*/
755	void
756	FindListBoxEntry(void);
757
758public:
759
760	/**	Our IDs.
761	*/
762	enum {
763
764		/**	ID of choicebook change.
765		*/
766		ID_CHOICEBOOK	=	((wxID_HIGHEST) + 1) ,
767
768		/**	ID of XFig shade slider.
769		*/
770		ID_SLIDER_SHADE ,
771
772		/**	ID of HTML named colors list control.
773		*/
774		ID_HTML_NAMED_LIST ,
775
776		/**	ID of HTML 216 red slider.
777		*/
778		ID_SLIDER_RED ,
779
780		/**	ID of HTML 216 green slider.
781		*/
782		ID_SLIDER_GREEN ,
783
784		/**	ID of HTML 216 blue slider.
785		*/
786		ID_SLIDER_BLUE
787	};
788
789	/**	Reasons for GUI corrections.
790	*/
791	enum {
792							/**	New page selected in choice book.
793							*/
794		REASON_CHOICEBOOK	= 0 ,
795
796							/**	Base colors changed.
797							*/
798		REASON_BASE_COLOR ,
799
800							/**	Shade slider changed.
801							*/
802		REASON_SHADE_SLIDER ,
803
804							/**	List selection changed.
805							*/
806		REASON_LIST_SELECT ,
807
808							/**	RGB slider changed.
809							*/
810		REASON_RGB_SLIDER
811	};
812
813	/**	Default constructor.
814	*/
815	Dk4WxColourPalette();
816
817	/**	Real constructor.
818		@param	pParent		Parent window.
819		@param	pAppHelper	Application helper.
820		@param	red			Initial red component.
821		@param	green		Initial green component.
822		@param	blue		Initial blue component.
823		@param	withborder	Flag: Show border around dialog box.
824	*/
825	Dk4WxColourPalette(
826		wxWindow				*pParent,
827		Dk4WxApplicationHelper	*pAppHelper,
828		int						 red,
829		int						 green,
830		int						 blue,
831		bool					 withborder = true
832	);
833
834	/**	Handler for OK button.
835		@param	event	Event to respond to, unused.
836	*/
837	void
838	OnOK(wxCommandEvent & event);
839
840	/**	Handler for Cancel button.
841		@param	event	Event to respond to, unused.
842	*/
843	void
844	OnCancel(wxCommandEvent & event);
845
846	/**	Handler for shade slider events.
847		@param	event	Event to respond to, unused.
848	*/
849	void
850	OnShadeSlider(wxCommandEvent & event);
851
852	/**	Handler for RGB slider events.
853		@param	event	Event to respond to, unused.
854	*/
855	void
856	OnRgbSlider(wxCommandEvent & event);
857
858#if	wxCHECK_VERSION(3,0,0)
859	/**	Handler for changed choicebook page.
860		@param	event	Event to respond to, unused
861	*/
862	void
863	OnChoicebookChanged(wxBookCtrlEvent & event);
864#else
865	/**	Handler for changed choicebook page.
866		@param	event	Event to respond to, unused
867	*/
868	void
869	OnChoicebookChanged(wxChoicebookEvent & event);
870#endif
871
872	/**	Handler for changed selection on list box.
873		@param	event	Event to respond to, unused.
874	*/
875	void
876	OnListBoxChanged(wxCommandEvent & event);
877
878	/**	Retrieve red component.
879		@return	Red value.
880	*/
881	int
882	Red(void) const;
883
884	/**	Retrieve green component.
885		@return	Green value.
886	*/
887	int
888	Green(void) const;
889
890	/**	Retrieve blue component.
891		@return	Blue value.
892	*/
893	int
894	Blue(void) const;
895
896	/**	React on Dk4WxColourPaletteItem click.
897		@param	red		New base red component.
898		@param	green	New base green component.
899		@param	blue	New base blue component.
900	*/
901	void
902	SetBaseRGB(int red, int green, int blue);
903
904	/**	Construct a dialog style value.
905		@param	bBorder	Flag: Draw border.
906		@param	bTitle	Flag: Title bar on dialog.
907	*/
908	static
909	int
910	GetDialogStyle(bool bBorder = true, bool bTitle = true);
911
912};
913
914
915%%	header end
916
917%%	module start
918
919#include <libdk4wx/Dk4WxColourPalette.h>
920
921#ifndef WX_CONFIG_H_INCLUDED
922#include <wx/config.h>
923#define	WX_CONFIG_H_INCLUDED 1
924#endif
925
926#ifndef WX_ARRSTR_H_INCLUDED
927#include <wx/arrstr.h>
928#define	WX_ARRSTR_H_INCLUDED 1
929#endif
930
931#ifndef	WX_DCBUFFER_H_INCLUDED
932#include <wx/dcbuffer.h>
933#define	WX_DCBUFFER_H_INCLUDED 1
934#endif
935
936
937
938$!trace-include
939
940
941
942/**	HTML named color type.
943*/
944typedef struct {
945	const wxChar	*name;		/**< Color name. */
946	unsigned long	 rgb;		/**< 16*R+8*G+B. */
947} html_color_t;
948
949
950
951/**	The named HTML colors.
952*/
953static const html_color_t html_colors[] = {
954	{ wxT("AliceBlue"),				0xF0F8FFUL },
955	{ wxT("AntiqueWhite"),			0xFAEBD7UL },
956	{ wxT("Aqua"),					0x00FFFFUL },
957	{ wxT("Aquamarine"),			0x7FFFD4UL },
958	{ wxT("Azure"),					0xF0FFFFUL },
959	{ wxT("Beige"),					0xF5F5DCUL },
960	{ wxT("Bisque"),				0xFFE4C4UL },
961	{ wxT("Black"),					0x000000UL },
962	{ wxT("BlanchedAlmond"),		0xFFEBCDUL },
963	{ wxT("Blue"),					0x0000FFUL },
964	{ wxT("BlueViolet"),			0x8A2BE2UL },
965	{ wxT("Brown"),					0xA52A2AUL },
966	{ wxT("BurlyWood"),				0xDEB887UL },
967	{ wxT("CadetBlue"),				0x5F9EA0UL },
968	{ wxT("Chartreuse"),			0x7FFF00UL },
969	{ wxT("Chocolate"),				0xD2691EUL },
970	{ wxT("Coral"),					0xFF7F50UL },
971	{ wxT("CornflowerBlue"),		0x6495EDUL },
972	{ wxT("Cornsilk"),				0xFFF8DCUL },
973	{ wxT("Crimson"),				0xDC143CUL },
974	{ wxT("Cyan"),					0x00FFFFUL },
975	{ wxT("DarkBlue"),				0x00008BUL },
976	{ wxT("DarkCyan"),				0x008B8BUL },
977	{ wxT("DarkGoldenRod"),			0xB8860BUL },
978	{ wxT("DarkGray"),				0xA9A9A9UL },
979	{ wxT("DarkGrey"),				0xA9A9A9UL },
980	{ wxT("DarkGreen"),				0x006400UL },
981	{ wxT("DarkKhaki"),				0xBDB76BUL },
982	{ wxT("DarkMagenta"),			0x8B008BUL },
983	{ wxT("DarkOliveGreen"),		0x556B2FUL },
984	{ wxT("DarkOrange"),			0xFF8C00UL },
985	{ wxT("DarkOrchid"),			0x9932CCUL },
986	{ wxT("DarkRed"),				0x8B0000UL },
987	{ wxT("DarkSalmon"),			0xE9967AUL },
988	{ wxT("DarkSeaGreen"),			0x8FBC8FUL },
989	{ wxT("DarkSlateBlue"),			0x483D8BUL },
990	{ wxT("DarkSlateGray"),			0x2F4F4FUL },
991	{ wxT("DarkSlateGrey"),			0x2F4F4FUL },
992	{ wxT("DarkTurquoise"),			0x00CED1UL },
993	{ wxT("DarkViolet"),			0x9400D3UL },
994	{ wxT("DeepPink"),				0xFF1493UL },
995	{ wxT("DeepSkyBlue"),			0x00BFFFUL },
996	{ wxT("DimGray"),				0x696969UL },
997	{ wxT("DimGrey"),				0x696969UL },
998	{ wxT("DodgerBlue"),			0x1E90FFUL },
999	{ wxT("FireBrick"),				0xB22222UL },
1000	{ wxT("FloralWhite"),			0xFFFAF0UL },
1001	{ wxT("ForestGreen"),			0x228B22UL },
1002	{ wxT("Fuchsia"),				0xFF00FFUL },
1003	{ wxT("Gainsboro"),				0xDCDCDCUL },
1004	{ wxT("GhostWhite"),			0xF8F8FFUL },
1005	{ wxT("Gold"),					0xFFD700UL },
1006	{ wxT("GoldenRod"),				0xDAA520UL },
1007	{ wxT("Gray"),					0x808080UL },
1008	{ wxT("Grey"),					0x808080UL },
1009	{ wxT("Green"),					0x008000UL },
1010	{ wxT("GreenYellow"),			0xADFF2FUL },
1011	{ wxT("HoneyDew"),				0xF0FFF0UL },
1012	{ wxT("HotPink"),				0xFF69B4UL },
1013	{ wxT("IndianRed"),				0xCD5C5CUL },
1014	{ wxT("Indigo"),				0x4B0082UL },
1015	{ wxT("Ivory"),					0xFFFFF0UL },
1016	{ wxT("Khaki"),					0xF0E68CUL },
1017	{ wxT("Lavender"),				0xE6E6FAUL },
1018	{ wxT("LavenderBlush"),			0xFFF0F5UL },
1019	{ wxT("LawnGreen"),				0x7CFC00UL },
1020	{ wxT("LemonChiffon"),			0xFFFACDUL },
1021	{ wxT("LightBlue"),				0xADD8E6UL },
1022	{ wxT("LightCoral"),			0xF08080UL },
1023	{ wxT("LightCyan"),				0xE0FFFFUL },
1024	{ wxT("LightGoldenRodYellow"),	0xFAFAD2UL },
1025	{ wxT("LightGray"),				0xD3D3D3UL },
1026	{ wxT("LightGrey"),				0xD3D3D3UL },
1027	{ wxT("LightGreen"),			0x90EE90UL },
1028	{ wxT("LightPink"),				0xFFB6C1UL },
1029	{ wxT("LightSalmon"),			0xFFA07AUL },
1030	{ wxT("LightSeaGreen"),			0x20B2AAUL },
1031	{ wxT("LightSkyBlue"),			0x87CEFAUL },
1032	{ wxT("LightSlateGray"),		0x778899UL },
1033	{ wxT("LightSlateGrey"),		0x778899UL },
1034	{ wxT("LightSteelBlue"),		0xB0C4DEUL },
1035	{ wxT("LightYellow"),			0xFFFFE0UL },
1036	{ wxT("Lime"),					0x00FF00UL },
1037	{ wxT("LimeGreen"),				0x32CD32UL },
1038	{ wxT("Linen"),					0xFAF0E6UL },
1039	{ wxT("Magenta"),				0xFF00FFUL },
1040	{ wxT("Maroon"),				0x800000UL },
1041	{ wxT("MediumAquaMarine"),		0x66CDAAUL },
1042	{ wxT("MediumBlue"),			0x0000CDUL },
1043	{ wxT("MediumOrchid"),			0xBA55D3UL },
1044	{ wxT("MediumPurple"),			0x9370DBUL },
1045	{ wxT("MediumSeaGreen"),		0x3CB371UL },
1046	{ wxT("MediumSlateBlue"),		0x7B68EEUL },
1047	{ wxT("MediumSpringGreen"),		0x00FA9AUL },
1048	{ wxT("MediumTurquoise"),		0x48D1CCUL },
1049	{ wxT("MediumVioletRed"),		0xC71585UL },
1050	{ wxT("MidnightBlue"),			0x191970UL },
1051	{ wxT("MintCream"),				0xF5FFFAUL },
1052	{ wxT("MistyRose"),				0xFFE4E1UL },
1053	{ wxT("Moccasin"),				0xFFE4B5UL },
1054	{ wxT("NavajoWhite"),			0xFFDEADUL },
1055	{ wxT("Navy"),					0x000080UL },
1056	{ wxT("OldLace"),				0xFDF5E6UL },
1057	{ wxT("Olive"),					0x808000UL },
1058	{ wxT("OliveDrab"),				0x6B8E23UL },
1059	{ wxT("Orange"),				0xFFA500UL },
1060	{ wxT("OrangeRed"),				0xFF4500UL },
1061	{ wxT("Orchid"),				0xDA70D6UL },
1062	{ wxT("PaleGoldenRod"),			0xEEE8AAUL },
1063	{ wxT("PaleGreen"),				0x98FB98UL },
1064	{ wxT("PaleTurquoise"),			0xAFEEEEUL },
1065	{ wxT("PaleVioletRed"),			0xDB7093UL },
1066	{ wxT("PapayaWhip"),			0xFFEFD5UL },
1067	{ wxT("PeachPuff"),				0xFFDAB9UL },
1068	{ wxT("Peru"),					0xCD853FUL },
1069	{ wxT("Pink"),					0xFFC0CBUL },
1070	{ wxT("Plum"),					0xDDA0DDUL },
1071	{ wxT("PowderBlue"),			0xB0E0E6UL },
1072	{ wxT("Purple"),				0x800080UL },
1073	{ wxT("RebeccaPurple"),			0x663399UL },
1074	{ wxT("Red"),					0xFF0000UL },
1075	{ wxT("RosyBrown"),				0xBC8F8FUL },
1076	{ wxT("RoyalBlue"),				0x4169E1UL },
1077	{ wxT("SaddleBrown"),			0x8B4513UL },
1078	{ wxT("Salmon"),				0xFA8072UL },
1079	{ wxT("SandyBrown"),			0xF4A460UL },
1080	{ wxT("SeaGreen"),				0x2E8B57UL },
1081	{ wxT("SeaShell"),				0xFFF5EEUL },
1082	{ wxT("Sienna"),				0xA0522DUL },
1083	{ wxT("Silver"),				0xC0C0C0UL },
1084	{ wxT("SkyBlue"),				0x87CEEBUL },
1085	{ wxT("SlateBlue"),				0x6A5ACDUL },
1086	{ wxT("SlateGray"),				0x708090UL },
1087	{ wxT("SlateGrey"),				0x708090UL },
1088	{ wxT("Snow"),					0xFFFAFAUL },
1089	{ wxT("SpringGreen"),			0x00FF7FUL },
1090	{ wxT("SteelBlue"),				0x4682B4UL },
1091	{ wxT("Tan"),					0xD2B48CUL },
1092	{ wxT("Teal"),					0x008080UL },
1093	{ wxT("Thistle"),				0xD8BFD8UL },
1094	{ wxT("Tomato"),				0xFF6347UL },
1095	{ wxT("Turquoise"),				0x40E0D0UL },
1096	{ wxT("Violet"),				0xEE82EEUL },
1097	{ wxT("Wheat"),					0xF5DEB3UL },
1098	{ wxT("White"),					0xFFFFFFUL },
1099	{ wxT("WhiteSmoke"),			0xF5F5F5UL },
1100	{ wxT("Yellow"),				0xFFFF00UL },
1101	{ wxT("YellowGreen"),			0x9ACD32UL }
1102};
1103
1104
1105
1106/**	Number of elements in the html_colors array.
1107*/
1108static const size_t sz_html_colors =
1109sizeof(html_colors)/sizeof(html_color_t);
1110
1111
1112
1113/**	Window type name.
1114*/
1115wxChar const
1116Dk4WxColourPalette::Dk4WxColourPaletteItem::Dk4WxColourPaletteItemName[] = {
1117	wxT("Dk4WxColourPaletteItem")
1118} ;
1119
1120
1121
1122#if	wxCHECK_VERSION(3,0,0)
1123wxBEGIN_EVENT_TABLE(Dk4WxColourPalette::Dk4WxColourPaletteItem,wxControl)
1124#else
1125BEGIN_EVENT_TABLE(Dk4WxColourPalette::Dk4WxColourPaletteItem,wxControl)
1126#endif
1127  EVT_ERASE_BACKGROUND(Dk4WxColourPalette::Dk4WxColourPaletteItem::OnErase)
1128  EVT_PAINT(Dk4WxColourPalette::Dk4WxColourPaletteItem::OnPaint)
1129  EVT_LEFT_DOWN(Dk4WxColourPalette::Dk4WxColourPaletteItem::OnLeftMouseButtonDown)
1130#if	wxCHECK_VERSION(3,0,0)
1131wxEND_EVENT_TABLE()
1132#else
1133END_EVENT_TABLE()
1134#endif
1135
1136
1137#if	wxCHECK_VERSION(3,0,0)
1138wxIMPLEMENT_DYNAMIC_CLASS(Dk4WxColourPalette::Dk4WxColourPaletteItem,wxControl);
1139#else
1140IMPLEMENT_DYNAMIC_CLASS(Dk4WxColourPalette::Dk4WxColourPaletteItem,wxControl)
1141#endif
1142
1143
1144
1145#if	wxCHECK_VERSION(3,0,0)
1146wxBEGIN_EVENT_TABLE(Dk4WxColourPalette,wxDialog)
1147#else
1148BEGIN_EVENT_TABLE(Dk4WxColourPalette,wxDialog)
1149#endif
1150	EVT_BUTTON(\
1151		wxID_OK,\
1152		Dk4WxColourPalette::OnOK\
1153	)
1154	EVT_BUTTON(\
1155		wxID_CANCEL,\
1156		Dk4WxColourPalette::OnCancel\
1157	)
1158	EVT_SLIDER(\
1159		Dk4WxColourPalette::ID_SLIDER_SHADE,\
1160		Dk4WxColourPalette::OnShadeSlider\
1161	)
1162	EVT_SLIDER(\
1163		Dk4WxColourPalette::ID_SLIDER_RED,\
1164		Dk4WxColourPalette::OnRgbSlider\
1165	)
1166	EVT_SLIDER(\
1167		Dk4WxColourPalette::ID_SLIDER_GREEN,\
1168		Dk4WxColourPalette::OnRgbSlider\
1169	)
1170	EVT_SLIDER(\
1171		Dk4WxColourPalette::ID_SLIDER_BLUE,\
1172		Dk4WxColourPalette::OnRgbSlider\
1173	)
1174	EVT_CHOICEBOOK_PAGE_CHANGED(\
1175		Dk4WxColourPalette::ID_CHOICEBOOK,\
1176		Dk4WxColourPalette::OnChoicebookChanged\
1177	)
1178	EVT_LISTBOX(\
1179		Dk4WxColourPalette::ID_HTML_NAMED_LIST,\
1180		Dk4WxColourPalette::OnListBoxChanged\
1181	)
1182#if	wxCHECK_VERSION(3,0,0)
1183wxEND_EVENT_TABLE()
1184#else
1185END_EVENT_TABLE()
1186#endif
1187
1188
1189
1190/**	Text fragments, replaced by localized versions if found.
1191*/
1192static const wxChar * const	message_texts[] = {
1193$!string-table	macro=wxT
1194#
1195#	  0		Window title
1196#
1197Colour palettes
1198#
1199#	  1		Tip for choice book
1200#
1201Choose palette type
1202#
1203#	  2		Tip for palette item
1204#
1205Click palette item to choose color
1206#
1207#	  3-7	Special shading levels
1208#
1209black
1210pure
1211white
1212Shading level
1213Modify shading (mix towards black or white)
1214#
1215#	   8	Tip for list
1216#
1217Select item to choose color
1218#
1219#	 9-11	Labels for RGB sliders
1220#
1221Red
1222Green
1223Blue
1224#
1225#	12-14	Tips for RGB sliders
1226#
1227Modify red color component
1228Modify green color component
1229Modify blue color component
1230#
1231#	15-16	Initial label value
1232#
1233Cancel
1234Leave dialog, skip settings
1235#
1236#	17-19	Tips for labels
1237#
1238Red color component value, hexadecimal 00...FF
1239Green color component value, hexadecimal 00...FF
1240Blue color component value, hexadecimal 00...FF
1241#
1242#	20-22	Tips for labels
1243#
1244Red color component value, decimal 0...255
1245Green color component value, decimal 0...255
1246Blue color component value, decimal 0...255
1247#
1248#	 23		Tip for result colour view
1249#
1250Result color
1251#
1252#	24-25	Button texts and tips
1253#
1254OK
1255Apply settings
1256#
1257#	26-28	Palette types
1258#
1259XFig
1260HTML
1261WEB 216
1262#
1263#
1264#
1265$!end
1266};
1267
1268
1269static const wxChar * const	not_localized_texts[] = {
1270$!string-table	macro=wxT
1271#
1272#	0-1		Initial label texts for numeric fields
1273#
1274FF
1275255
1276#
1277#	2-4		Format strings
1278#
1279%+02d %%
1280%03d
1281%02X
1282$!end
1283};
1284
1285
1286
1287/**	String table file name.
1288*/
1289static const dkChar sttfilename[]  = { dkT("dk4colpal.str") };
1290
1291
1292
1293/**	Color component values corresponding to the RGB slider settings.
1294*/
1295static const int rgbSliderValues[] = {
1296	0, 0x0033, 0x0066, 0x0099, 0x00CC, 0x00FF
1297};
1298
1299
1300
1301Dk4WxColourPalette::Dk4WxColourPalette()
1302{
1303	pAppHelp = NULL;
1304	slvshade = 0;
1305	rb = gb = bb = r = g = b = 255;
1306	slvred = slvgreen = slvblue = 5;
1307	listSelection = 0;
1308	bIsCorrecting = false;
1309}
1310
1311
1312
1313%%	constructor start
1314
1315Dk4WxColourPalette::Dk4WxColourPalette(
1316	wxWindow				*pParent,
1317	Dk4WxApplicationHelper	*pAppHelper,
1318	int						 red,
1319	int						 green,
1320	int						 blue,
1321	bool					 withborder
1322)
1323: wxDialog(
1324	pParent, wxID_ANY,
1325	wxT("Colour palette"),
1326	wxDefaultPosition, wxDefaultSize,
1327	Dk4WxColourPalette::GetDialogStyle(false, withborder)
1328),
1329colourRed(127, 0, 0),
1330colourGreen(0, 127, 0),
1331colourBlue(0, 0, 127)
1332{
1333  wxArrayString			 saHtmlNames;
1334  wxChar const * const	*lTexts;
1335  size_t				 i;
1336  $? "+ Dk4WxColourPalette::Dk4WxColourPalette"
1337  $? ". red   = %d", red
1338  $? ". green = %d", green
1339  $? ". blue  = %d", blue
1340
1341  localizedTexts = lTexts =
1342  pAppHelper->GetStringTable(sttfilename, message_texts);
1343  if (NULL == localizedTexts) {
1344    localizedTexts = lTexts = message_texts;
1345  }
1346  pAppHelp = pAppHelper;
1347  slvshade = 0;
1348  rb = r = red;
1349  gb = g = green;
1350  bb = b = blue;
1351  slvred = slvgreen = slvblue = 5;
1352  listSelection = 0;
1353  bIsCorrecting = false;
1354  for (i = 0; i < sz_html_colors; i++) {
1355    saHtmlNames.Add(html_colors[i].name);
1356  }
1357%%	constructor end
1358  if (dkctGUILayoutOK) {
1359    colourViewResult->SetActive(false);
1360	colourViewResult->SetMarkActiveInactive(false);
1361	decRed->SetForegroundColour(colourRed);
1362	decGreen->SetForegroundColour(colourGreen);
1363	decBlue->SetForegroundColour(colourBlue);
1364	hexRed->SetForegroundColour(colourRed);
1365	hexGreen->SetForegroundColour(colourGreen);
1366	hexBlue->SetForegroundColour(colourBlue);
1367	SetRgbTextLabels();
1368	FindRgbSliderValues();
1369	FindListBoxEntry();
1370	SetTitle(lTexts[0]);
1371	wxSize	minsize = GetMinSize();
1372	SetMaxSize(minsize);
1373  }
1374  $? "- Dk4WxColourPalette::Dk4WxColourPalette"
1375}
1376
1377%%	module end
1378
1379
1380void
1381Dk4WxColourPalette::OnOK(wxCommandEvent & WXUNUSED(event))
1382{
1383	if(IsModal()) {
1384		EndModal(wxID_OK);
1385	}
1386	else {
1387		SetReturnCode(wxID_OK);
1388		Show(false);
1389	}
1390}
1391
1392
1393
1394void
1395Dk4WxColourPalette::OnCancel(wxCommandEvent & WXUNUSED(event))
1396{
1397	if(IsModal()) {
1398		EndModal(wxID_CANCEL);
1399	}
1400	else {
1401		SetReturnCode(wxID_CANCEL);
1402		Show(false);
1403	}
1404}
1405
1406
1407
1408#if	wxCHECK_VERSION(3,0,0)
1409void
1410Dk4WxColourPalette::OnChoicebookChanged(wxBookCtrlEvent & event)
1411#else
1412void
1413Dk4WxColourPalette::OnChoicebookChanged(wxChoicebookEvent & event)
1414#endif
1415{
1416	int		pn;
1417	$? "+ Dk4WxColourPalette::OnChoicebookChanged"
1418	pn = event.GetSelection();
1419	if (1 == pn) {
1420		if (wxNOT_FOUND != listSelection) {
1421			listHtmlNames->SetSelection(listSelection);
1422		}
1423	}
1424	$? "- Dk4WxColourPalette::OnChoicebookChanged"
1425}
1426
1427
1428
1429int
1430Dk4WxColourPalette::ShadeColour(int val)
1431{
1432	int		back;
1433
1434	back = val;
1435	if (0 < slvshade) {
1436		back = (((20 - slvshade) * val) + (slvshade * 255)) / 20;
1437	}
1438	else {
1439		if (0 > slvshade) {
1440			back = (val * (20 + slvshade)) / 20;
1441		}
1442	}
1443	return back;
1444}
1445
1446
1447
1448void
1449Dk4WxColourPalette::CorrectShadeLabel(void)
1450{
1451	wxString	lstr;
1452
1453	switch (slvshade) {
1454		case -20 : {
1455			figShaderLabelText->SetLabel(localizedTexts[3]);
1456		} break;
1457		case   0 : {
1458			figShaderLabelText->SetLabel(localizedTexts[4]);
1459		} break;
1460		case  20 : {
1461			figShaderLabelText->SetLabel(localizedTexts[5]);
1462		} break;
1463		default : {
1464			lstr.Printf(not_localized_texts[2], (5*slvshade));
1465			figShaderLabelText->SetLabel(lstr);
1466		} break;
1467	}
1468}
1469
1470
1471
1472void
1473Dk4WxColourPalette::SetBaseRGB(int red, int green, int blue)
1474{
1475	$? "+ Dk4WxColourPalette::SetBaseRGB"
1476	rb = red; gb = green; bb = blue;
1477	CorrectGui(REASON_BASE_COLOR);
1478	$? "- Dk4WxColourPalette::SetBaseRGB"
1479}
1480
1481
1482
1483void
1484Dk4WxColourPalette::OnShadeSlider(wxCommandEvent & WXUNUSED(event))
1485{
1486	$? "+ Dk4WxColourPalette::OnShadeSlider"
1487	if (!(bIsCorrecting)) {
1488		slvshade = figShaderSlider->GetValue();
1489		CorrectGui(REASON_SHADE_SLIDER);
1490	}
1491	$? "- Dk4WxColourPalette::OnShadeSlider"
1492}
1493
1494
1495
1496void
1497Dk4WxColourPalette::OnListBoxChanged(wxCommandEvent & WXUNUSED(event))
1498{
1499	int				in;
1500	unsigned long	ul;
1501	$? "+ Dk4WxColourPalette::OnListBoxChanged"
1502	if (!(bIsCorrecting)) {
1503		listSelection = in = listHtmlNames->GetSelection();
1504		if ((0 <= in) && (wxNOT_FOUND != in)) {
1505			ul = html_colors[in].rgb;
1506			r = rb = (int)((ul >> 16) & 0x000000FFUL);
1507			g = gb = (int)((ul >>  8) & 0x000000FFUL);
1508			b = bb = (int)( ul        & 0x000000FFUL);
1509			CorrectGui(REASON_LIST_SELECT);
1510		}
1511	}
1512	$? "- Dk4WxColourPalette::OnListBoxChanged"
1513}
1514
1515
1516
1517void
1518Dk4WxColourPalette::OnRgbSlider(wxCommandEvent & WXUNUSED(event))
1519{
1520	$? "+ Dk4WxColourPalette::OnRgbSlider"
1521	if (!(bIsCorrecting)) {
1522		rb = r = rgbSliderValues[sliderHtml216Red->GetValue()];
1523		gb = g = rgbSliderValues[sliderHtml216Green->GetValue()];
1524		bb = b = rgbSliderValues[sliderHtml216Blue->GetValue()];
1525		CorrectGui(REASON_RGB_SLIDER);
1526	}
1527	$? "- Dk4WxColourPalette::OnRgbSlider"
1528}
1529
1530
1531
1532int
1533Dk4WxColourPalette::FindSliderValue(int colval)
1534{
1535	long	 mindiff	= 0L;
1536	long	 curdiff;
1537	int		 back		= 0;
1538	int		 i;
1539	for (i = 0; i < 6; i++) {
1540		curdiff = labs(colval - rgbSliderValues[i]);
1541		if ((0 == i) || (curdiff < mindiff)) {
1542			back = i;
1543			mindiff = curdiff;
1544		}
1545	}
1546	return back;
1547}
1548
1549
1550
1551void
1552Dk4WxColourPalette::FindRgbSliderValues(void)
1553{
1554	int sl;
1555	sl = FindSliderValue(r);
1556	slvred = sl;
1557	sliderHtml216Red->SetValue(sl);
1558	sl = FindSliderValue(g);
1559	slvgreen = sl;
1560	sliderHtml216Green->SetValue(sl);
1561	sl = FindSliderValue(b);
1562	slvblue = sl;
1563	sliderHtml216Blue->SetValue(sl);
1564}
1565
1566
1567
1568void
1569Dk4WxColourPalette::FindListBoxEntry(void)
1570{
1571	size_t			i;
1572	size_t			mini;
1573	unsigned long	ul;
1574	unsigned long	curdiff;
1575	unsigned long	mindiff;
1576	unsigned long	r0;
1577	unsigned long	g0;
1578	unsigned long	b0;
1579
1580	mindiff = 0UL; mini = 0;
1581	for (i = 0; i < sz_html_colors; i++) {
1582		ul = html_colors[i].rgb;
1583		r0 = (ul >> 16) & 0x000000FFUL;
1584		g0 = (ul >>  8) & 0x000000FFUL;
1585		b0 = ul         & 0x000000FFUL;
1586		r0 = labs((long)r0 - (long)r);
1587		g0 = labs((long)g0 - (long)g);
1588		b0 = labs((long)b0 - (long)b);
1589		r0 = r0 * r0;
1590		g0 = g0 * g0;
1591		b0 = b0 * b0;
1592		curdiff = r0 + g0 + b0;
1593		if ((0 == i) || (curdiff < mindiff)) {
1594			mindiff = curdiff;
1595			mini = i;
1596		}
1597	}
1598	/*
1599		Cast not dangerous as sz_html_colors is limited.
1600	*/
1601	listSelection = (int)mini;
1602	listHtmlNames->SetSelection((int)mini);
1603}
1604
1605
1606
1607void
1608Dk4WxColourPalette::SetRgbTextLabels(void)
1609{
1610	wxString valstr;
1611
1612	valstr.Printf(not_localized_texts[3], r);
1613	decRed->SetLabel(valstr);
1614	valstr.Printf(not_localized_texts[3], g);
1615	decGreen->SetLabel(valstr);
1616	valstr.Printf(not_localized_texts[3], b);
1617	decBlue->SetLabel(valstr);
1618	valstr.Printf(not_localized_texts[4], r);
1619	hexRed->SetLabel(valstr);
1620	valstr.Printf(not_localized_texts[4], g);
1621	hexGreen->SetLabel(valstr);
1622	valstr.Printf(not_localized_texts[4], b);
1623	hexBlue->SetLabel(valstr);
1624}
1625
1626
1627
1628void
1629Dk4WxColourPalette::CorrectGui(int reason)
1630{
1631	$? "+ Dk4WxColourPalette::CorrectGui"
1632	if(!(bIsCorrecting)) {		$? ". not yet correcting"
1633		/*
1634			Mark correction in progress
1635		*/
1636		bIsCorrecting = true;
1637		/*
1638			Apply the changes
1639		*/
1640		switch (reason) {
1641			case REASON_CHOICEBOOK : {
1642			} break;
1643			case REASON_BASE_COLOR : {		$? ". base color"
1644				r = ShadeColour(rb);
1645				g = ShadeColour(gb);
1646				b = ShadeColour(bb);
1647				FindListBoxEntry();
1648				FindRgbSliderValues();
1649			} break;
1650			case REASON_SHADE_SLIDER : {	$? ". shade slider"
1651				r = ShadeColour(rb);
1652				g = ShadeColour(gb);
1653				b = ShadeColour(bb);
1654				FindListBoxEntry();
1655				FindRgbSliderValues();
1656				CorrectShadeLabel();
1657			} break;
1658			case REASON_LIST_SELECT : {		$? ". list selection"
1659				FindRgbSliderValues();
1660				slvshade = 0;
1661				figShaderSlider->SetValue(0);
1662				CorrectShadeLabel();
1663			} break;
1664			case REASON_RGB_SLIDER : {		$? ". rgb slider"
1665				FindListBoxEntry();
1666				slvshade = 0;
1667				figShaderSlider->SetValue(0);
1668				CorrectShadeLabel();
1669			} break;
1670		}
1671		/*
1672			Mark correction as done
1673		*/
1674		bIsCorrecting = false;
1675		/*
1676			Update result color viewer and dialog window
1677		*/
1678		SetRgbTextLabels();
1679		colourViewResult->SetRGB(r, g, b);
1680		Refresh();
1681		Update();
1682	}
1683	$? "- Dk4WxColourPalette::CorrectGui"
1684}
1685
1686
1687
1688int
1689Dk4WxColourPalette::Red(void) const
1690{
1691	return r;
1692}
1693
1694
1695
1696int
1697Dk4WxColourPalette::Green(void) const
1698{
1699	return g;
1700}
1701
1702
1703
1704int
1705Dk4WxColourPalette::Blue(void) const
1706{
1707	return b;
1708}
1709
1710
1711
1712Dk4WxColourPalette::Dk4WxColourPaletteItem::Dk4WxColourPaletteItem()
1713{
1714	pParentWindow = NULL;
1715	pAppHelp = NULL;
1716	w = h = -1;
1717	r = g = b = 255;
1718}
1719
1720
1721
1722Dk4WxColourPalette::Dk4WxColourPaletteItem::Dk4WxColourPaletteItem(
1723	wxWindow				*pParent,
1724	wxWindowID				 wxid,
1725	Dk4WxColourPalette		*pal,
1726	Dk4WxApplicationHelper	*appHelper,
1727	int						 red,
1728	int						 green,
1729	int						 blue,
1730	wxPoint const &			 pos,
1731	wxSize  const &			 size,
1732	long					 style,
1733	wxChar const			*name
1734)
1735: wxControl(
1736	pParent, wxid, pos, size, style, wxDefaultValidator,
1737	wxString(name)
1738)
1739{
1740
1741	pParentWindow = pal;
1742	pAppHelp = appHelper;
1743	w = h = -1;
1744	r = red;
1745	g = green;
1746	b = blue;
1747}
1748
1749
1750
1751bool
1752Dk4WxColourPalette::Dk4WxColourPaletteItem::Create(
1753	wxWindow				*pParent,
1754	wxWindowID				 wxid,
1755	Dk4WxColourPalette		*pal,
1756	Dk4WxApplicationHelper	*appHelper,
1757	int						 red,
1758	int						 green,
1759	int						 blue,
1760	wxPoint const &			 pos,
1761	wxSize  const &			 size,
1762	long					 style,
1763	wxChar const			*name
1764)
1765{
1766	bool back = wxControl::Create(
1767		pParent, wxid, pos, size, style, wxDefaultValidator,
1768		wxString(name)
1769	);
1770	pParentWindow = pal;
1771	pAppHelp = appHelper;
1772	w = h = -1;
1773	r = red;
1774	g = green;
1775	b = blue;
1776	return back;
1777}
1778
1779
1780
1781wxSize
1782Dk4WxColourPalette::Dk4WxColourPaletteItem::DoGetBestSize() const
1783{
1784	wxSize back(((-1 < w) ? w : 25), ((-1 < h) ? h : 25));
1785	return back;
1786}
1787
1788
1789
1790void
1791Dk4WxColourPalette::Dk4WxColourPaletteItem::OnErase(wxEraseEvent & WXUNUSED(event))
1792{
1793
1794}
1795
1796
1797
1798void
1799Dk4WxColourPalette::Dk4WxColourPaletteItem::OnPaint(wxPaintEvent & WXUNUSED(event))
1800{
1801	wxBufferedPaintDC	useDC(this);
1802	wxSize				sz		= GetClientSize();
1803	wxColour			mycolor(
1804		(unsigned char)r,
1805		(unsigned char)g,
1806		(unsigned char)b
1807	);
1808#if	wxCHECK_VERSION(3,0,0)
1809	wxBrush				myBrush(mycolor, wxBRUSHSTYLE_SOLID);
1810#else
1811	wxBrush				myBrush(mycolor, wxSOLID);
1812#endif
1813	const wxBrush		oldBrus	= useDC.GetBrush();
1814	useDC.SetBrush(myBrush);
1815	useDC.DrawRectangle(0, 0, sz.GetWidth(), sz.GetHeight());
1816	useDC.SetBrush(wxNullBrush);
1817}
1818
1819
1820
1821void
1822Dk4WxColourPalette::Dk4WxColourPaletteItem::OnLeftMouseButtonDown(
1823	wxMouseEvent & WXUNUSED(event)
1824)
1825{
1826	if (NULL != pParentWindow) {
1827		pParentWindow->SetBaseRGB(r, g, b);
1828	}
1829}
1830
1831
1832
1833int
1834Dk4WxColourPalette::GetDialogStyle(bool bBorder, bool bTitle)
1835{
1836	int		 back = wxDEFAULT_DIALOG_STYLE;
1837
1838	back &= (~(wxCLOSE_BOX));
1839	back &= (~(wxSYSTEM_MENU));
1840	if (!(bBorder)) {
1841		back &= (~(wxRESIZE_BORDER));
1842	}
1843	if (!(bTitle)) {
1844		back &= (~(wxCAPTION));
1845	}
1846	return back;
1847}
1848
1849
1850
1851
1852
1853/* vim: set ai sw=4 ts=4 : */
1854
1855