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 /** @file Dk4WxControl.cpp The Dk4WxControl module.
15 */
16
17
18 #include "dk4conf.h"
19 #include <libdk4wx/Dk4WxControl.h>
20
21
22
23
24
25
26
27 const wxChar Dk4WxControl::Dk4WxControlName[] = { wxT("Dk4WxControl") };
28
29
30 #if wxCHECK_VERSION(3,0,0)
31 wxIMPLEMENT_DYNAMIC_CLASS(Dk4WxControl, wxControl);
32 #else
IMPLEMENT_DYNAMIC_CLASS(Dk4WxControl,wxControl)33 IMPLEMENT_DYNAMIC_CLASS(Dk4WxControl, wxControl)
34 #endif
35
36
37 #if wxCHECK_VERSION(3,0,0)
38 wxBEGIN_EVENT_TABLE(Dk4WxControl,wxControl)
39 #else
40 BEGIN_EVENT_TABLE(Dk4WxControl,wxControl)
41 #endif
42 EVT_ERASE_BACKGROUND(Dk4WxControl::OnErase)
43 EVT_PAINT(Dk4WxControl::OnPaint)
44 #if wxCHECK_VERSION(3,0,0)
45 wxEND_EVENT_TABLE()
46 #else
47 END_EVENT_TABLE()
48 #endif
49
50
51
52 Dk4WxControl::Dk4WxControl()
53 : wxControl()
54 {
55
56 pBitmap = NULL;
57 iBmWidth = -1;
58 iBmHeight = -1;
59 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
60
61 }
62
63
64
65 bool
Create(wxWindow * parent,wxWindowID wid,const wxPoint & pos,const wxSize & size,long style,const wxValidator & validator,const wxChar * name)66 Dk4WxControl::Create(
67 wxWindow *parent,
68 wxWindowID wid,
69 const wxPoint & pos,
70 const wxSize & size,
71 long style,
72 const wxValidator & validator,
73 const wxChar *name
74 )
75 {
76 bool back;
77
78 back = wxControl::Create(
79 parent, wid, pos, size, style, validator, name
80 );
81 pBitmap = NULL;
82 iBmWidth = -1;
83 iBmHeight = -1;
84 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
85
86 return back;
87 }
88
89
90
Dk4WxControl(wxWindow * parent,wxWindowID wid,const wxPoint & pos,const wxSize & size,long style,const wxValidator & validator,const wxChar * name)91 Dk4WxControl::Dk4WxControl(
92 wxWindow *parent,
93 wxWindowID wid,
94 const wxPoint & pos,
95 const wxSize & size,
96 long style,
97 const wxValidator & validator,
98 const wxChar *name
99 )
100 : wxControl( parent, wid, pos, size, style, validator, wxString(name))
101 {
102
103 pBitmap = NULL;
104 iBmWidth = -1;
105 iBmHeight = -1;
106 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
107
108 }
109
110
111
~Dk4WxControl()112 Dk4WxControl::~Dk4WxControl()
113 {
114
115 {
116 wxCriticalSectionLocker lock(csProtect);
117 if (NULL != pBitmap) { delete(pBitmap); }
118 pBitmap = NULL;
119 iBmWidth = -1;
120 iBmHeight = -1;
121 }
122
123 }
124
125
126
127 void
OnErase(wxEraseEvent & WXUNUSED (event))128 Dk4WxControl::OnErase(wxEraseEvent & WXUNUSED(event))
129 {
130
131
132 }
133
134
135
136 void
PaintOperation(wxDC & pdc,wxPaintEvent & WXUNUSED (event),bool WXUNUSED (buffered),int clWidth,int clHeight)137 Dk4WxControl::PaintOperation(
138 wxDC & pdc,
139 wxPaintEvent & WXUNUSED(event),
140 bool WXUNUSED(buffered),
141 int clWidth,
142 int clHeight
143 )
144 {
145 pdc.SetBrush(*wxWHITE_BRUSH);
146 pdc.DrawRectangle(0, 0, clWidth, clHeight);
147 }
148
149
150
151 void
InternalPaint(wxDC & pdc,wxPaintEvent & event,bool buffered,int clWidth,int clHeight)152 Dk4WxControl::InternalPaint(
153 wxDC & pdc,
154 wxPaintEvent & event,
155 bool buffered,
156 int clWidth,
157 int clHeight
158 )
159 {
160 /* Save current DC settings.
161 */
162 wxBrush const br = pdc.GetBrush();
163 wxBrush const bg = pdc.GetBackground();
164 wxFont const fn = pdc.GetFont();
165 wxPen const pn = pdc.GetPen();
166 wxColour const tbg = pdc.GetTextBackground();
167 wxColour const tfg = pdc.GetTextForeground();
168 int bgm = pdc.GetBackgroundMode();
169
170 /* Do the real pain operation.
171 */
172 PaintOperation(pdc, event, buffered, clWidth, clHeight);
173 /* Restore DC settings from start.
174 */
175 pdc.SetBackgroundMode(bgm);
176 pdc.SetTextForeground(tfg);
177 pdc.SetTextBackground(tbg);
178 pdc.SetPen(pn);
179 pdc.SetFont(fn);
180 pdc.SetBackground(bg);
181 pdc.SetBrush(br);
182
183 }
184
185
186
187 void
OnPaint(wxPaintEvent & event)188 Dk4WxControl::OnPaint(wxPaintEvent & event)
189 {
190 wxPaintDC paintDC(this);
191 int w = 0;
192 int h = 0;
193 bool mustDraw = false;
194 bool done = false;
195
196 {
197 wxCriticalSectionLocker lock(csProtect);
198 wxSize sz = GetClientSize();
199 mustDraw = bUpdate;
200 #if VERSION_BEFORE_20150821
201 w = iBmWidth;
202 h = iBmHeight;
203 #endif
204 if (NULL != pBitmap) {
205 if ((iBmWidth != sz.x) || (iBmHeight != sz.y)) {
206 delete(pBitmap);
207 pBitmap = NULL;
208 }
209 }
210 w = iBmWidth = sz.x;
211 h = iBmHeight = sz.y;
212 if (NULL == pBitmap) {
213 pBitmap = new wxBitmap(iBmWidth, iBmHeight);
214 mustDraw = true;
215 }
216 if (NULL != pBitmap) {
217 if (mustDraw) {
218 wxMemoryDC memDC;
219 memDC.SelectObject(*pBitmap);
220 InternalPaint(memDC, event, true, w, h);
221 memDC.SelectObject(wxNullBitmap);
222 bUpdate = false;
223 }
224 paintDC.DrawBitmap(*pBitmap, 0, 0, false);
225 done = true;
226 }
227 }
228 if (!(done)) {
229 InternalPaint(paintDC, event, false, w, h);
230 }
231
232 }
233
234
235
236 void
SetUpdate(bool flag)237 Dk4WxControl::SetUpdate(bool flag)
238 {
239
240 if (flag) {
241 wxCriticalSectionLocker lock(csProtect);
242 bUpdate = true;
243 }
244
245 }
246
247
248
249 void
ReleaseBuffer(void)250 Dk4WxControl::ReleaseBuffer(void)
251 {
252 {
253 wxCriticalSectionLocker lock(csProtect);
254 if (NULL != pBitmap) {
255 delete(pBitmap);
256 pBitmap = NULL;
257 }
258 }
259 }
260
261