1 /*
2 Copyright (C) 2015-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: Dk4WxControl.cpt
12 */
13 
14 #ifndef DK4WXCONTROL_H_INCLUDED
15 /** Avoid multiple inclusions. */
16 #define DK4WXCONTROL_H_INCLUDED 1
17 
18 
19 /**	@file	Dk4WxControl.h	Triple-buffered control.
20 */
21 
22 #ifndef DK4CONF_H_INCLUDED
23 #if DK4_BUILDING_DKTOOLS4
24 #include "dk4conf.h"
25 #else
26 #include <dktools-4/dk4conf.h>
27 #endif
28 #endif
29 
30 #ifndef DK4TYPES_H_INCLUDED
31 #if DK4_BUILDING_DKTOOLS4
32 #include <libdk4base/dk4types.h>
33 #else
34 #include <dktools-4/dk4types.h>
35 #endif
36 #endif
37 
38 #ifndef WX_WXPREC_H_INCLUDED
39 #include <wx/wxprec.h>
40 #define	WX_WXPREC_H_INCLUDED 1
41 #endif
42 #ifdef __BORLANDC__
43 #pragma hdrstop
44 #endif
45 #ifndef WX_PRECOMP
46 #ifndef WX_WX_H_INCLUDED
47 #include <wx/wx.h>
48 #define	WX_WX_H_INCLUDED 1
49 #endif
50 #endif
51 
52 
53 
54 /**	Base class for user-defined controls.
55 	Like double-buffering we write the windows contents
56 	to an image and finally transfer the entire image
57 	to the device context.
58 	Additionally we keep the image between the paint events
59 	and rebuild the image only if necessary (data to show
60 	has changed).
61 
62 	When the frame containing your view becomes invisible
63 	(frame iconized or hidden) you should use the ReleaseBuffer()
64 	method to decrease the memory footprint of the program.
65 
66 	In your derived class, call the Dk4WxControl constructors from
67 	the constructors.
68 	From Create() call Dk4WxControl::Create().
69 
70 	You should also use wxDECLARE_DYNAMIC_CLASS() and;
71 	wxIMPLEMENT_DYNAMIC_CLASS().
72 */
73 class Dk4WxControl : public wxControl
74 {
75   private:
76 
77     /**	For RTTI.
78     */
79 #if	wxCHECK_VERSION(3,0,0)
80     wxDECLARE_DYNAMIC_CLASS(Dk4WxControl);
81 #else
82     DECLARE_DYNAMIC_CLASS(Dk4WxControl)
83 #endif
84 
85     /**	Event table.
86     */
87 #if	wxCHECK_VERSION(3,0,0)
88     wxDECLARE_EVENT_TABLE();
89 #else
90     DECLARE_EVENT_TABLE()
91 #endif
92 
93   protected:
94 
95     /**	Class name.
96     */
97     static const wxChar	Dk4WxControlName[];
98 
99     /**	Protection against simultaneous access.
100     */
101     wxCriticalSection	csProtect;
102 
103     /**	Bitmap to cache contents.
104     */
105     wxBitmap		*pBitmap;
106 
107     /**	Bitmap width.
108     */
109     int			iBmWidth;
110 
111     /**	Bitmap height.
112     */
113     int			iBmHeight;
114 
115     /**	Flag: Must update contents.
116     */
117     bool		bUpdate;
118 
119   protected:
120 
121     /**	Overwrite this method to do the real drawing.
122 	@param	pdc		Device context to draw to.
123 	@param	event		Paint event to draw for.
124 	@param	buffered	Flag: Operating on memory DC.
125 	@param	clWidth		Client area width.
126 	@param	clHeight	Client area height.
127     */
128     virtual
129     void
130     PaintOperation(
131       wxDC &		pdc,
132       wxPaintEvent &	event,
133       bool		buffered,
134       int		clWidth,
135       int		clHeight
136     );
137 
138     /**	Internal paint operation.
139 	@param	pdc		Device context to draw to.
140 	@param	event		Paint event to draw for.
141 	@param	buffered	Flag: Operating on memory DC.
142 	@param	clWidth		Client area width.
143 	@param	clHeight	Client area height.
144     */
145     void
146     InternalPaint(
147       wxDC &		pdc,
148       wxPaintEvent &	event,
149       bool		buffered,
150       int		clWidth,
151       int		clHeight
152     );
153 
154   public:
155 
156     /**	Default constructor.
157     */
158     Dk4WxControl();
159 
160     /**	Useful constructor.
161 	@param	parent		Parent window.
162 	@param	wid		Window ID.
163 	@param	pos		Position.
164 	@param	size		Size.
165 	@param	style		Style.
166 	@param	validator	Validator.
167 	@param	name		Type name.
168     */
169     Dk4WxControl(
170       wxWindow			*parent,
171       wxWindowID		 wid		= wxID_ANY,
172       const wxPoint &		 pos		= wxDefaultPosition,
173       const wxSize &		 size		= wxDefaultSize,
174       long			 style		= 0L,
175       const wxValidator &	 validator	= wxDefaultValidator,
176       const wxChar		*name		= Dk4WxControlName
177     );
178 
179     /**	Create window after using default constructor.
180 	@param	parent		Parent window.
181 	@param	wid		Window ID.
182 	@param	pos		Position.
183 	@param	size		Size.
184 	@param	style		Style.
185 	@param	validator	Validator.
186 	@param	name		Type name.
187     */
188     bool
189     Create(
190       wxWindow			*parent,
191       wxWindowID		 wid		= wxID_ANY,
192       const wxPoint &		 pos		= wxDefaultPosition,
193       const wxSize &		 size		= wxDefaultSize,
194       long			 style		= 0L,
195       const wxValidator &	 validator	= wxDefaultValidator,
196       const wxChar		*name		= Dk4WxControlName
197     );
198 
199     /**	Destructor.
200     */
201     ~Dk4WxControl();
202 
203     /**	Mark update necessarity.
204     */
205     void
206     SetUpdate(bool flag = true);
207 
208     /**	Handler for erase background event.
209 	@param	event	Event to process.
210     */
211     void
212     OnErase(wxEraseEvent & event);
213 
214     /**	Handler for paint event.
215 	@param	event	Event to process.
216     */
217     void
218     OnPaint(wxPaintEvent & event);
219 
220     /**	Release buffer when frame is iconized or hidden.
221     */
222     void
223     ReleaseBuffer(void);
224 };
225 
226 
227 
228 
229 #endif
230