1 /*
2 Copyright (C) 2011-2021, Dirk Krause
3 SPDX-License-Identifier: BSD-3-Clause
4 */
5 
6 /*
7 	WARNING: This file was generated by the dkct program (see
8 	http://dktools.sourceforge.net/ for details).
9 	Changes you make here will be lost if dkct is run again!
10 	You should modify the original source and run dkct on it.
11 	Original source: Dk4WxColourView.cpt
12 */
13 
14 /**	@file Dk4WxColourView.h Header file for the Dk4WxColourView module.
15 */
16 
17 #ifndef DK4WXCOLOURVIEW_H_INCLUDED
18 /** Avoid multiple inclusions. */
19 #define DK4WXCOLOURVIEW_H_INCLUDED 1
20 
21 
22 
23 #ifndef DK4CONF_H_INCLUDED
24 #if DK4_BUILDING_DKTOOLS4
25 #include "dk4conf.h"
26 #else
27 #include <dktools-4/dk4conf.h>
28 #endif
29 #endif
30 
31 #ifndef DK4TYPES_H_INCLUDED
32 #if DK4_BUILDING_DKTOOLS4
33 #include <libdk4base/dk4types.h>
34 #else
35 #include <dktools-4/dk4types.h>
36 #endif
37 #endif
38 
39 #include <wx/wxprec.h>
40 #ifdef __BORLANDC__
41 #pragma hdrstop
42 #endif
43 #ifndef WX_PRECOMP
44 #include <wx/wx.h>
45 #endif
46 
47 #ifndef	DK4WXAPPLICATIONHELPER_H_INCLUDED
48 #if DK4_BUILDING_DKTOOLS4
49 #include <libdk4wx/Dk4WxApplicationHelper.h>
50 #else
51 #include <dktools-4/Dk4WxApplicationHelper.h>
52 #endif
53 #endif
54 
55 #if	wxCHECK_VERSION(3,0,0)
56 
57 /**	Event generated if the colour was changed.
58 */
59 wxDECLARE_EVENT(wxEVT_DK4_COLOUR_VIEW_EVENT, wxCommandEvent);
60 
61 #else
62 
63 /**	Event generated if the colour was changed.
64 */
65 BEGIN_DECLARE_EVENT_TYPES()
66 DECLARE_EVENT_TYPE(wxEVT_DK4_COLOUR_VIEW_EVENT, -1)
END_DECLARE_EVENT_TYPES()67 END_DECLARE_EVENT_TYPES()
68 
69 #endif
70 
71 /**	Show color setting, show colour chooser on mouse click.
72 */
73 class Dk4WxColourView : public wxControl
74 {
75 
76   /**	Declare class as dynamic.
77   */
78 #if	wxCHECK_VERSION(3,0,0)
79   wxDECLARE_DYNAMIC_CLASS(Dk4WxColourView);
80 #else
81   DECLARE_DYNAMIC_CLASS(Dk4WxColourView)
82 #endif
83 
84   /**	Event table for control.
85   */
86 #if	wxCHECK_VERSION(3,0,0)
87   wxDECLARE_EVENT_TABLE();
88 #else
89   DECLARE_EVENT_TABLE()
90 #endif
91 
92   protected:
93 
94     /**	Parent window.
95     */
96     wxWindow				*pParentWindow;
97 
98     /**	Application helper, used to position color chooser dialog.
99     */
100     Dk4WxApplicationHelper	*pHelper;
101 
102     /**	Class name, used in constructor and Create().
103     */
104     static wxChar const		 Dk4WxColourViewName[];
105 
106 	/**	ID to use in generated events.
107 	*/
108 	wxWindowID				 m_wxid;
109 
110     /**	Height.
111     */
112     int						 w;
113 
114     /**	Width.
115     */
116     int						 h;
117 
118     /**	Red component of color to show.
119     */
120     int						 r;
121 
122     /**	Green component of color to show.
123     */
124     int						 g;
125 
126     /**	Blue component of color to show.
127     */
128     int						 b;
129 
130     /**	Previous x position of color chooser dialog.
131     */
132     int						 ccdx;
133 
134     /**	Previous y position of color chooser dialog.
135     */
136     int						 ccdy;
137 
138 	/**	Previous x position of color palette dialog.
139 	*/
140 	int						 cpdx;
141 
142 	/**	Previous x position of color palette dialog.
143 	*/
144 	int						 cpdy;
145 
146 	/**	Activity flag, allow to choose a color.
147 	*/
148 	bool					 bActive;
149 
150 	/**	Flag: Prefer platte over normal view.
151 	*/
152 	bool					 bPalettePreferred;
153 
154 	/**	Flag: Set position for colour chooser.
155 	*/
156 	bool					 bPlaceColourChooser;
157 
158 	/**	Flag: Show active/inactive state.
159 	*/
160 	bool					 bMarkActiveInactive;
161 
162 	/**	Flag: Show colour chooser with a border.
163 	*/
164 	bool					 bWithBorder;
165 
166   protected:
167 
168 	/**	Send event for changed colour.
169 	*/
170 	void
171 	SendColourViewEvent(void);
172 
173 	/**	Place colour chooser dialog.
174 		@param	dlg	Dialog to place.
175 		@param	x	Saved x coordinate or -1.
176 		@param	y	Saved y coordinate or -1.
177 	*/
178 	void
179 	PlaceColourChooser(wxWindow & dlg, int x, int y);
180 
181 	/**	Run the system colour chooser.
182 	*/
183 	void
184 	RunSystemColourChooser(void);
185 
186 	/**	Run the palette based colour chooser.
187 	*/
188 	void
189 	RunPaletteColourChooser(void);
190 
191   public:
192 
193     /**	Default constructor.
194     */
195     Dk4WxColourView();
196 
197     /**	Constructor.
198     	@param	pParent		Parent window.
199 		@param	wxid		Window ID.
200 		@param	appHelper	Application helper.
201 		@param	red	Red 	component of color to show.
202 		@param	green		Green component of color to show.
203 		@param	blue		Blue component of color to show.
204 		@param	pos			Object position.
205 		@param	size		Object minimum size.
206 		@param	style		Style for control.
207 		@param	name		Class name.
208     */
209     Dk4WxColourView(
210       wxWindow					*pParent,
211       wxWindowID				 wxid,
212       Dk4WxApplicationHelper	*appHelper,
213       int						 red,
214       int						 green,
215       int						 blue,
216       wxPoint const &			 pos	= wxDefaultPosition,
217       wxSize  const &			 size	= wxDefaultSize,
218       long						 style	= wxBORDER_NONE,
219       wxChar const				*name	= Dk4WxColourViewName
220     );
221 
222     /**	Create object after using default constructor.
223     	@param	pParent		Parent window.
224 		@param	wxid		Window ID.
225 		@param	appHelper	Application helper.
226 		@param	red	Red 	component of color to show.
227 		@param	green		Green component of color to show.
228 		@param	blue		Blue component of color to show.
229 		@param	pos			Object position.
230 		@param	size		Object minimum size.
231 		@param	style		Style for control.
232 		@param	name		Class name.
233 		@return	true on success, false on error.
234     */
235     bool
236     Create(
237       wxWindow					*pParent,
238       wxWindowID				 wxid,
239       Dk4WxApplicationHelper	*appHelper,
240       int						 red	= 255,
241       int						 green	= 255,
242       int						 blue	= 255,
243       wxPoint const &			 pos	= wxDefaultPosition,
244       wxSize  const &			 size	= wxDefaultSize,
245       long						 style	= wxBORDER_NONE,
246       wxChar const				*name	= Dk4WxColourViewName
247     );
248 
249     /**	Find minimum size.
250     */
251     wxSize DoGetBestSize() const;
252 
253     /**	Get red component of current color.
254     	@return	Red.
255     */
256     int
257     Red() const;
258 
259     /**	Get green component of current color.
260     	@return	Green.
261     */
262     int
263     Green() const;
264 
265     /**	Get blue component of current color.
266     	@return	Blue.
267     */
268     int
269     Blue() const;
270 
271     /**	Set new current color.
272     	@param	red		Red.
273 		@param	green	Green.
274 		@param	blue	Blue.
275     */
276     void
277     SetRGB(int red, int green, int blue);
278 
279 	/**	Set activity flag.
280 	*/
281 	void
282 	SetActive(bool b);
283 
284 	/**	Set palette as preferred method to choose a color.
285 	*/
286 	void
287 	SetPalettePreferred(bool b = true);
288 
289 	/**	Set whether to place the colour chooser near the colour view.
290 		@param	b	New flag value.
291 	*/
292 	void
293 	SetPlaceColourChooser(bool b = true);
294 
295 	/**	Set whether to indicate active/inactive state.
296 		@param	b	new flag value.
297 	*/
298 	void
299 	SetMarkActiveInactive(bool b = true);
300 
301 	/**	Set up border for colour chooser.
302 		@param	b	Flag for border.
303 	*/
304 	void
305 	SetColourChooserWithBorder(bool b = true);
306 
307     /**	Handler for erase event.
308     	@param	event	Event to process.
309     */
310     void
311     OnErase(wxEraseEvent & event);
312 
313     /**	Handler for paint event.
314     	@param	event	Event to process.
315     */
316     void
317     OnPaint(wxPaintEvent & event);
318 
319     /**	Handler for mouse click event.
320     	@param	event	Event to process.
321     */
322     void
323     OnLeftMouseButtonDown(wxMouseEvent & event);
324 
325 	/**	Handler for right mouse click event.
326 		@param	event	Event to process.
327 	*/
328 	void
329 	OnRightMouseButtonDown(wxMouseEvent & event);
330 
331 };
332 
333 
334 
335 /* vim: set ai sw=4 ts=4 : */
336 
337 #endif
338