]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
ca3e85cf | 2 | // Name: src/common/gdicmn.cpp |
c801d85f KB |
3 | // Purpose: Common GDI classes |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
55d99c7a | 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__ | |
670f9935 | 16 | #pragma hdrstop |
c801d85f KB |
17 | #endif |
18 | ||
19 | #include "wx/gdicmn.h" | |
e4db172a WS |
20 | |
21 | #ifndef WX_PRECOMP | |
22 | #include "wx/log.h" | |
f5590243 | 23 | #include "wx/pen.h" |
c64755ed | 24 | #include "wx/brush.h" |
559a723c | 25 | #include "wx/palette.h" |
923d28da | 26 | #include "wx/icon.h" |
c8326d64 | 27 | #include "wx/cursor.h" |
9eddec69 | 28 | #include "wx/settings.h" |
e4db172a WS |
29 | #endif |
30 | ||
e7445ff8 | 31 | #include "wx/colour.h" |
c801d85f | 32 | #include "wx/bitmap.h" |
c801d85f | 33 | #include "wx/font.h" |
c801d85f | 34 | |
e7445ff8 PC |
35 | WXDLLIMPEXP_DATA_CORE(wxBrushList*) wxTheBrushList; |
36 | WXDLLIMPEXP_DATA_CORE(wxFontList*) wxTheFontList; | |
37 | WXDLLIMPEXP_DATA_CORE(wxPenList*) wxThePenList; | |
38 | ||
39 | WXDLLIMPEXP_DATA_CORE(wxColourDatabase*) wxTheColourDatabase; | |
40 | ||
41 | WXDLLIMPEXP_DATA_CORE(wxBitmap) wxNullBitmap; | |
42 | WXDLLIMPEXP_DATA_CORE(wxBrush) wxNullBrush; | |
43 | WXDLLIMPEXP_DATA_CORE(wxColour) wxNullColour; | |
44 | WXDLLIMPEXP_DATA_CORE(wxCursor) wxNullCursor; | |
45 | WXDLLIMPEXP_DATA_CORE(wxFont) wxNullFont; | |
46 | WXDLLIMPEXP_DATA_CORE(wxIcon) wxNullIcon; | |
47 | WXDLLIMPEXP_DATA_CORE(wxPen) wxNullPen; | |
48 | #if wxUSE_PALETTE | |
49 | WXDLLIMPEXP_DATA_CORE(wxPalette) wxNullPalette; | |
46ccb510 JS |
50 | #endif |
51 | ||
e7445ff8 PC |
52 | const wxSize wxDefaultSize(wxDefaultCoord, wxDefaultCoord); |
53 | const wxPoint wxDefaultPosition(wxDefaultCoord, wxDefaultCoord); | |
7266b672 | 54 | |
cb73e600 SC |
55 | #if wxUSE_EXTENDED_RTTI |
56 | ||
57 | // wxPoint | |
58 | ||
59 | template<> void wxStringReadValue(const wxString &s , wxPoint &data ) | |
60 | { | |
5d3e7b52 | 61 | wxSscanf(s, wxT("%d,%d"), &data.x , &data.y ) ; |
cb73e600 SC |
62 | } |
63 | ||
64 | template<> void wxStringWriteValue(wxString &s , const wxPoint &data ) | |
65 | { | |
5d3e7b52 | 66 | s = wxString::Format(wxT("%d,%d"), data.x , data.y ) ; |
cb73e600 SC |
67 | } |
68 | ||
8805dbab | 69 | wxCUSTOM_TYPE_INFO(wxPoint, wxToStringConverter<wxPoint> , wxFromStringConverter<wxPoint>) |
cb73e600 SC |
70 | |
71 | template<> void wxStringReadValue(const wxString &s , wxSize &data ) | |
72 | { | |
5d3e7b52 | 73 | wxSscanf(s, wxT("%d,%d"), &data.x , &data.y ) ; |
cb73e600 SC |
74 | } |
75 | ||
76 | template<> void wxStringWriteValue(wxString &s , const wxSize &data ) | |
77 | { | |
5d3e7b52 | 78 | s = wxString::Format(wxT("%d,%d"), data.x , data.y ) ; |
cb73e600 SC |
79 | } |
80 | ||
8805dbab | 81 | wxCUSTOM_TYPE_INFO(wxSize, wxToStringConverter<wxSize> , wxFromStringConverter<wxSize>) |
cb73e600 SC |
82 | |
83 | #endif | |
84 | ||
d7a7546b | 85 | wxRect::wxRect(const wxPoint& point1, const wxPoint& point2) |
c801d85f | 86 | { |
5d3e7b52 WS |
87 | x = point1.x; |
88 | y = point1.y; | |
89 | width = point2.x - point1.x; | |
90 | height = point2.y - point1.y; | |
8bbe427f | 91 | |
5d3e7b52 WS |
92 | if (width < 0) |
93 | { | |
94 | width = -width; | |
95 | x = point2.x; | |
96 | } | |
97 | width++; | |
8bbe427f | 98 | |
5d3e7b52 WS |
99 | if (height < 0) |
100 | { | |
101 | height = -height; | |
102 | y = point2.y; | |
103 | } | |
104 | height++; | |
c801d85f KB |
105 | } |
106 | ||
a23fd0e1 | 107 | bool wxRect::operator==(const wxRect& rect) const |
c801d85f | 108 | { |
5d3e7b52 WS |
109 | return ((x == rect.x) && |
110 | (y == rect.y) && | |
111 | (width == rect.width) && | |
112 | (height == rect.height)); | |
c801d85f KB |
113 | } |
114 | ||
df83b840 | 115 | wxRect wxRect::operator+(const wxRect& rect) const |
619d0528 | 116 | { |
45816ddd VZ |
117 | int x1 = wxMin(this->x, rect.x); |
118 | int y1 = wxMin(this->y, rect.y); | |
119 | int y2 = wxMax(y+height, rect.height+rect.y); | |
120 | int x2 = wxMax(x+width, rect.width+rect.x); | |
121 | return wxRect(x1, y1, x2-x1, y2-y1); | |
dcb44466 JS |
122 | } |
123 | ||
df83b840 VZ |
124 | wxRect& wxRect::Union(const wxRect& rect) |
125 | { | |
c71ce675 VZ |
126 | // ignore empty rectangles: union with an empty rectangle shouldn't extend |
127 | // this one to (0, 0) | |
128 | if ( !width || !height ) | |
129 | { | |
130 | *this = rect; | |
131 | } | |
132 | else if ( rect.width && rect.height ) | |
df83b840 VZ |
133 | { |
134 | int x1 = wxMin(x, rect.x); | |
135 | int y1 = wxMin(y, rect.y); | |
136 | int y2 = wxMax(y + height, rect.height + rect.y); | |
137 | int x2 = wxMax(x + width, rect.width + rect.x); | |
138 | ||
139 | x = x1; | |
140 | y = y1; | |
141 | width = x2 - x1; | |
142 | height = y2 - y1; | |
143 | } | |
c71ce675 | 144 | //else: we're not empty and rect is empty |
df83b840 VZ |
145 | |
146 | return *this; | |
147 | } | |
148 | ||
1e6feb95 VZ |
149 | wxRect& wxRect::Inflate(wxCoord dx, wxCoord dy) |
150 | { | |
8673a125 VZ |
151 | if (-2*dx>width) |
152 | { | |
153 | // Don't allow deflate to eat more width than we have, | |
154 | // a well-defined rectangle cannot have negative width. | |
155 | x+=width/2; | |
156 | width=0; | |
157 | } | |
158 | else | |
159 | { | |
160 | // The inflate is valid. | |
161 | x-=dx; | |
162 | width+=2*dx; | |
163 | } | |
164 | ||
165 | if (-2*dy>height) | |
166 | { | |
167 | // Don't allow deflate to eat more height than we have, | |
168 | // a well-defined rectangle cannot have negative height. | |
169 | y+=height/2; | |
170 | height=0; | |
171 | } | |
172 | else | |
173 | { | |
174 | // The inflate is valid. | |
175 | y-=dy; | |
176 | height+=2*dy; | |
177 | } | |
1e6feb95 VZ |
178 | |
179 | return *this; | |
180 | } | |
181 | ||
dcb44466 JS |
182 | bool wxRect::Inside(int cx, int cy) const |
183 | { | |
45816ddd VZ |
184 | return ( (cx >= x) && (cy >= y) |
185 | && ((cy - y) < height) | |
186 | && ((cx - x) < width) | |
187 | ); | |
dcb44466 JS |
188 | } |
189 | ||
1e6feb95 VZ |
190 | wxRect& wxRect::Intersect(const wxRect& rect) |
191 | { | |
192 | int x2 = GetRight(), | |
193 | y2 = GetBottom(); | |
194 | ||
195 | if ( x < rect.x ) | |
196 | x = rect.x; | |
197 | if ( y < rect.y ) | |
198 | y = rect.y; | |
199 | if ( x2 > rect.GetRight() ) | |
200 | x2 = rect.GetRight(); | |
201 | if ( y2 > rect.GetBottom() ) | |
202 | y2 = rect.GetBottom(); | |
203 | ||
204 | width = x2 - x + 1; | |
205 | height = y2 - y + 1; | |
206 | ||
207 | if ( width <= 0 || height <= 0 ) | |
208 | { | |
209 | width = | |
210 | height = 0; | |
211 | } | |
212 | ||
213 | return *this; | |
214 | } | |
215 | ||
216 | bool wxRect::Intersects(const wxRect& rect) const | |
217 | { | |
218 | wxRect r = Intersect(rect); | |
219 | ||
220 | // if there is no intersection, both width and height are 0 | |
221 | return r.width != 0; | |
222 | } | |
223 | ||
c50f92d0 VZ |
224 | // ============================================================================ |
225 | // wxColourDatabase | |
226 | // ============================================================================ | |
227 | ||
c50f92d0 VZ |
228 | // ---------------------------------------------------------------------------- |
229 | // wxColourDatabase ctor/dtor | |
230 | // ---------------------------------------------------------------------------- | |
222ed1d6 MB |
231 | |
232 | wxColourDatabase::wxColourDatabase () | |
c801d85f | 233 | { |
c50f92d0 VZ |
234 | // will be created on demand in Initialize() |
235 | m_map = NULL; | |
c801d85f KB |
236 | } |
237 | ||
6a6c0a8b | 238 | wxColourDatabase::~wxColourDatabase () |
c801d85f | 239 | { |
c50f92d0 VZ |
240 | if ( m_map ) |
241 | { | |
242 | WX_CLEAR_HASH_MAP(wxStringToColourHashMap, *m_map); | |
243 | ||
244 | delete m_map; | |
245 | } | |
222ed1d6 | 246 | |
19bf0c69 DW |
247 | #ifdef __WXPM__ |
248 | delete [] m_palTable; | |
249 | #endif | |
c801d85f KB |
250 | } |
251 | ||
252 | // Colour database stuff | |
c50f92d0 | 253 | void wxColourDatabase::Initialize() |
c801d85f | 254 | { |
c50f92d0 VZ |
255 | if ( m_map ) |
256 | { | |
257 | // already initialized | |
258 | return; | |
259 | } | |
260 | ||
261 | m_map = new wxStringToColourHashMap; | |
262 | ||
f6bcfd97 BP |
263 | static const struct wxColourDesc |
264 | { | |
265 | const wxChar *name; | |
5c519b6c | 266 | unsigned char r,g,b; |
f6bcfd97 BP |
267 | } |
268 | wxColourTable[] = | |
269 | { | |
5e2ab1ea | 270 | {wxT("AQUAMARINE"),112, 219, 147}, |
f6bcfd97 BP |
271 | {wxT("BLACK"),0, 0, 0}, |
272 | {wxT("BLUE"), 0, 0, 255}, | |
5e2ab1ea | 273 | {wxT("BLUE VIOLET"), 159, 95, 159}, |
f6bcfd97 | 274 | {wxT("BROWN"), 165, 42, 42}, |
5e2ab1ea VZ |
275 | {wxT("CADET BLUE"), 95, 159, 159}, |
276 | {wxT("CORAL"), 255, 127, 0}, | |
277 | {wxT("CORNFLOWER BLUE"), 66, 66, 111}, | |
f6bcfd97 | 278 | {wxT("CYAN"), 0, 255, 255}, |
5e2ab1ea VZ |
279 | {wxT("DARK GREY"), 47, 47, 47}, // ? |
280 | ||
281 | {wxT("DARK GREEN"), 47, 79, 47}, | |
282 | {wxT("DARK OLIVE GREEN"), 79, 79, 47}, | |
f6bcfd97 | 283 | {wxT("DARK ORCHID"), 153, 50, 204}, |
5e2ab1ea | 284 | {wxT("DARK SLATE BLUE"), 107, 35, 142}, |
f6bcfd97 | 285 | {wxT("DARK SLATE GREY"), 47, 79, 79}, |
5e2ab1ea VZ |
286 | {wxT("DARK TURQUOISE"), 112, 147, 219}, |
287 | {wxT("DIM GREY"), 84, 84, 84}, | |
288 | {wxT("FIREBRICK"), 142, 35, 35}, | |
289 | {wxT("FOREST GREEN"), 35, 142, 35}, | |
290 | {wxT("GOLD"), 204, 127, 50}, | |
291 | {wxT("GOLDENROD"), 219, 219, 112}, | |
292 | {wxT("GREY"), 128, 128, 128}, | |
f6bcfd97 | 293 | {wxT("GREEN"), 0, 255, 0}, |
5e2ab1ea VZ |
294 | {wxT("GREEN YELLOW"), 147, 219, 112}, |
295 | {wxT("INDIAN RED"), 79, 47, 47}, | |
296 | {wxT("KHAKI"), 159, 159, 95}, | |
297 | {wxT("LIGHT BLUE"), 191, 216, 216}, | |
298 | {wxT("LIGHT GREY"), 192, 192, 192}, | |
299 | {wxT("LIGHT STEEL BLUE"), 143, 143, 188}, | |
300 | {wxT("LIME GREEN"), 50, 204, 50}, | |
301 | {wxT("LIGHT MAGENTA"), 255, 0, 255}, | |
f6bcfd97 | 302 | {wxT("MAGENTA"), 255, 0, 255}, |
5e2ab1ea VZ |
303 | {wxT("MAROON"), 142, 35, 107}, |
304 | {wxT("MEDIUM AQUAMARINE"), 50, 204, 153}, | |
305 | {wxT("MEDIUM GREY"), 100, 100, 100}, | |
306 | {wxT("MEDIUM BLUE"), 50, 50, 204}, | |
307 | {wxT("MEDIUM FOREST GREEN"), 107, 142, 35}, | |
308 | {wxT("MEDIUM GOLDENROD"), 234, 234, 173}, | |
309 | {wxT("MEDIUM ORCHID"), 147, 112, 219}, | |
310 | {wxT("MEDIUM SEA GREEN"), 66, 111, 66}, | |
311 | {wxT("MEDIUM SLATE BLUE"), 127, 0, 255}, | |
312 | {wxT("MEDIUM SPRING GREEN"), 127, 255, 0}, | |
313 | {wxT("MEDIUM TURQUOISE"), 112, 219, 219}, | |
314 | {wxT("MEDIUM VIOLET RED"), 219, 112, 147}, | |
315 | {wxT("MIDNIGHT BLUE"), 47, 47, 79}, | |
316 | {wxT("NAVY"), 35, 35, 142}, | |
317 | {wxT("ORANGE"), 204, 50, 50}, | |
318 | {wxT("ORANGE RED"), 255, 0, 127}, | |
319 | {wxT("ORCHID"), 219, 112, 219}, | |
320 | {wxT("PALE GREEN"), 143, 188, 143}, | |
321 | {wxT("PINK"), 188, 143, 234}, | |
322 | {wxT("PLUM"), 234, 173, 234}, | |
323 | {wxT("PURPLE"), 176, 0, 255}, | |
f6bcfd97 | 324 | {wxT("RED"), 255, 0, 0}, |
5e2ab1ea VZ |
325 | {wxT("SALMON"), 111, 66, 66}, |
326 | {wxT("SEA GREEN"), 35, 142, 107}, | |
327 | {wxT("SIENNA"), 142, 107, 35}, | |
328 | {wxT("SKY BLUE"), 50, 153, 204}, | |
329 | {wxT("SLATE BLUE"), 0, 127, 255}, | |
f6bcfd97 | 330 | {wxT("SPRING GREEN"), 0, 255, 127}, |
5e2ab1ea VZ |
331 | {wxT("STEEL BLUE"), 35, 107, 142}, |
332 | {wxT("TAN"), 219, 147, 112}, | |
f6bcfd97 | 333 | {wxT("THISTLE"), 216, 191, 216}, |
5e2ab1ea VZ |
334 | {wxT("TURQUOISE"), 173, 234, 234}, |
335 | {wxT("VIOLET"), 79, 47, 79}, | |
336 | {wxT("VIOLET RED"), 204, 50, 153}, | |
337 | {wxT("WHEAT"), 216, 216, 191}, | |
f6bcfd97 BP |
338 | {wxT("WHITE"), 255, 255, 255}, |
339 | {wxT("YELLOW"), 255, 255, 0}, | |
aad6765c | 340 | {wxT("YELLOW GREEN"), 153, 204, 50} |
f6bcfd97 BP |
341 | }; |
342 | ||
c50f92d0 | 343 | size_t n; |
bf2c4b94 DW |
344 | |
345 | for ( n = 0; n < WXSIZEOF(wxColourTable); n++ ) | |
f6bcfd97 BP |
346 | { |
347 | const wxColourDesc& cc = wxColourTable[n]; | |
c50f92d0 | 348 | (*m_map)[cc.name] = new wxColour(cc.r, cc.g, cc.b); |
f6bcfd97 | 349 | } |
c50f92d0 | 350 | |
19bf0c69 DW |
351 | #ifdef __WXPM__ |
352 | m_palTable = new long[n]; | |
353 | for ( n = 0; n < WXSIZEOF(wxColourTable); n++ ) | |
354 | { | |
355 | const wxColourDesc& cc = wxColourTable[n]; | |
356 | m_palTable[n] = OS2RGB(cc.r,cc.g,cc.b); | |
357 | } | |
358 | m_nSize = n; | |
359 | #endif | |
c801d85f KB |
360 | } |
361 | ||
c50f92d0 VZ |
362 | // ---------------------------------------------------------------------------- |
363 | // wxColourDatabase operations | |
364 | // ---------------------------------------------------------------------------- | |
222ed1d6 | 365 | |
c50f92d0 | 366 | void wxColourDatabase::AddColour(const wxString& name, const wxColour& colour) |
222ed1d6 | 367 | { |
c50f92d0 | 368 | Initialize(); |
222ed1d6 | 369 | |
c50f92d0 VZ |
370 | // canonicalize the colour names before using them as keys: they should be |
371 | // in upper case | |
8f520a56 MB |
372 | wxString colName = name; |
373 | colName.MakeUpper(); | |
c50f92d0 VZ |
374 | |
375 | // ... and we also allow both grey/gray | |
376 | wxString colNameAlt = colName; | |
377 | if ( !colNameAlt.Replace(_T("GRAY"), _T("GREY")) ) | |
378 | { | |
379 | // but in this case it is not necessary so avoid extra search below | |
380 | colNameAlt.clear(); | |
381 | } | |
8f520a56 MB |
382 | |
383 | wxStringToColourHashMap::iterator it = m_map->find(colName); | |
c50f92d0 VZ |
384 | if ( it == m_map->end() && !colNameAlt.empty() ) |
385 | it = m_map->find(colNameAlt); | |
8f520a56 MB |
386 | if ( it != m_map->end() ) |
387 | { | |
c50f92d0 VZ |
388 | *(it->second) = colour; |
389 | } | |
390 | else // new colour | |
391 | { | |
5767e836 | 392 | (*m_map)[colName] = new wxColour(colour); |
8f520a56 | 393 | } |
8f520a56 MB |
394 | } |
395 | ||
c50f92d0 | 396 | wxColour wxColourDatabase::Find(const wxString& colour) const |
c801d85f | 397 | { |
c50f92d0 VZ |
398 | wxColourDatabase * const self = wxConstCast(this, wxColourDatabase); |
399 | self->Initialize(); | |
400 | ||
c50f92d0 | 401 | // make the comparaison case insensitive and also match both grey and gray |
f6bcfd97 BP |
402 | wxString colName = colour; |
403 | colName.MakeUpper(); | |
c50f92d0 VZ |
404 | wxString colNameAlt = colName; |
405 | if ( !colNameAlt.Replace(_T("GRAY"), _T("GREY")) ) | |
406 | colNameAlt.clear(); | |
f6bcfd97 | 407 | |
222ed1d6 | 408 | wxStringToColourHashMap::iterator it = m_map->find(colName); |
c50f92d0 VZ |
409 | if ( it == m_map->end() && !colNameAlt.empty() ) |
410 | it = m_map->find(colNameAlt); | |
222ed1d6 | 411 | if ( it != m_map->end() ) |
c50f92d0 | 412 | return *(it->second); |
34138703 | 413 | |
40989e46 WS |
414 | // we did not find any result in existing colours: |
415 | // we won't use wxString -> wxColour conversion because the | |
416 | // wxColour::Set(const wxString &) function which does that conversion | |
417 | // internally uses this function (wxColourDatabase::Find) and we want | |
418 | // to avoid infinite recursion ! | |
c50f92d0 | 419 | return wxNullColour; |
c801d85f KB |
420 | } |
421 | ||
c50f92d0 | 422 | wxString wxColourDatabase::FindName(const wxColour& colour) const |
c801d85f | 423 | { |
c50f92d0 VZ |
424 | wxColourDatabase * const self = wxConstCast(this, wxColourDatabase); |
425 | self->Initialize(); | |
8bbe427f | 426 | |
222ed1d6 MB |
427 | typedef wxStringToColourHashMap::iterator iterator; |
428 | ||
c50f92d0 | 429 | for ( iterator it = m_map->begin(), en = m_map->end(); it != en; ++it ) |
a23fd0e1 | 430 | { |
c50f92d0 | 431 | if ( *(it->second) == colour ) |
222ed1d6 | 432 | return it->first; |
a23fd0e1 | 433 | } |
c801d85f | 434 | |
222ed1d6 | 435 | return wxEmptyString; |
c801d85f KB |
436 | } |
437 | ||
c50f92d0 VZ |
438 | // ---------------------------------------------------------------------------- |
439 | // deprecated wxColourDatabase methods | |
440 | // ---------------------------------------------------------------------------- | |
441 | ||
ca3e85cf | 442 | #if WXWIN_COMPATIBILITY_2_6 |
c50f92d0 VZ |
443 | wxColour *wxColourDatabase::FindColour(const wxString& name) |
444 | { | |
98de2b68 DS |
445 | // This function is deprecated, use Find() instead. |
446 | // Formerly this function sometimes would return a deletable pointer and | |
447 | // sometimes a non-deletable one (when returning a colour from the database). | |
448 | // Trying to delete the latter anyway results in problems, so probably | |
449 | // nobody ever freed the pointers. Currently it always returns a new | |
450 | // instance, which means there will be memory leaks. | |
451 | wxLogDebug(wxT("wxColourDataBase::FindColour():") | |
452 | wxT(" Please use wxColourDataBase::Find() instead")); | |
453 | ||
492e2a5b VZ |
454 | // using a static variable here is not the most elegant solution but unless |
455 | // we want to make wxStringToColourHashMap public (i.e. move it to the | |
456 | // header) so that we could have a member function returning | |
457 | // wxStringToColourHashMap::iterator, there is really no good way to do it | |
458 | // otherwise | |
459 | // | |
460 | // and knowing that this function is going to disappear in the next release | |
461 | // anyhow I don't want to waste time on this | |
98de2b68 | 462 | |
492e2a5b VZ |
463 | static wxColour s_col; |
464 | ||
465 | s_col = Find(name); | |
466 | if ( !s_col.Ok() ) | |
c50f92d0 VZ |
467 | return NULL; |
468 | ||
98de2b68 | 469 | return new wxColour(s_col); |
c50f92d0 | 470 | } |
ca3e85cf | 471 | #endif // WXWIN_COMPATIBILITY_2_6 |
c50f92d0 VZ |
472 | |
473 | // ============================================================================ | |
474 | // stock objects | |
475 | // ============================================================================ | |
476 | ||
f516d986 VZ |
477 | static wxStockGDI gs_wxStockGDI_instance; |
478 | wxStockGDI* wxStockGDI::ms_instance = &gs_wxStockGDI_instance; | |
479 | wxObject* wxStockGDI::ms_stockObject[ITEMCOUNT]; | |
480 | ||
481 | wxStockGDI::wxStockGDI() | |
7ecb8b06 | 482 | { |
f516d986 | 483 | } |
1c193821 | 484 | |
f516d986 VZ |
485 | wxStockGDI::~wxStockGDI() |
486 | { | |
a3622daa | 487 | } |
c801d85f | 488 | |
f516d986 | 489 | void wxStockGDI::DeleteAll() |
a3622daa | 490 | { |
f516d986 VZ |
491 | for (unsigned i = 0; i < ITEMCOUNT; i++) |
492 | { | |
493 | delete ms_stockObject[i]; | |
494 | ms_stockObject[i] = NULL; | |
495 | } | |
496 | } | |
c801d85f | 497 | |
f516d986 VZ |
498 | const wxBrush* wxStockGDI::GetBrush(Item item) |
499 | { | |
500 | wxBrush* brush = wx_static_cast(wxBrush*, ms_stockObject[item]); | |
501 | if (brush == NULL) | |
502 | { | |
503 | switch (item) | |
504 | { | |
505 | case BRUSH_BLACK: | |
506 | brush = new wxBrush(*GetColour(COLOUR_BLACK), wxSOLID); | |
507 | break; | |
508 | case BRUSH_BLUE: | |
509 | brush = new wxBrush(*GetColour(COLOUR_BLUE), wxSOLID); | |
510 | break; | |
511 | case BRUSH_CYAN: | |
512 | brush = new wxBrush(*GetColour(COLOUR_CYAN), wxSOLID); | |
513 | break; | |
514 | case BRUSH_GREEN: | |
515 | brush = new wxBrush(*GetColour(COLOUR_GREEN), wxSOLID); | |
516 | break; | |
517 | case BRUSH_GREY: | |
518 | brush = new wxBrush(wxColour(wxT("GREY")), wxSOLID); | |
519 | break; | |
520 | case BRUSH_LIGHTGREY: | |
521 | brush = new wxBrush(*GetColour(COLOUR_LIGHTGREY), wxSOLID); | |
522 | break; | |
523 | case BRUSH_MEDIUMGREY: | |
524 | brush = new wxBrush(wxColour(wxT("MEDIUM GREY")), wxSOLID); | |
525 | break; | |
526 | case BRUSH_RED: | |
527 | brush = new wxBrush(*GetColour(COLOUR_RED), wxSOLID); | |
528 | break; | |
529 | case BRUSH_TRANSPARENT: | |
530 | brush = new wxBrush(*GetColour(COLOUR_BLACK), wxTRANSPARENT); | |
531 | break; | |
532 | case BRUSH_WHITE: | |
533 | brush = new wxBrush(*GetColour(COLOUR_WHITE), wxSOLID); | |
534 | break; | |
535 | default: | |
536 | wxFAIL; | |
537 | } | |
538 | ms_stockObject[item] = brush; | |
539 | } | |
540 | return brush; | |
541 | } | |
696e1ea0 | 542 | |
f516d986 VZ |
543 | const wxColour* wxStockGDI::GetColour(Item item) |
544 | { | |
545 | wxColour* colour = wx_static_cast(wxColour*, ms_stockObject[item]); | |
546 | if (colour == NULL) | |
547 | { | |
548 | switch (item) | |
549 | { | |
550 | case COLOUR_BLACK: | |
551 | colour = new wxColour(0, 0, 0); | |
552 | break; | |
553 | case COLOUR_BLUE: | |
554 | colour = new wxColour(0, 0, 255); | |
555 | break; | |
556 | case COLOUR_CYAN: | |
557 | colour = new wxColour(wxT("CYAN")); | |
558 | break; | |
559 | case COLOUR_GREEN: | |
560 | colour = new wxColour(0, 255, 0); | |
561 | break; | |
562 | case COLOUR_LIGHTGREY: | |
563 | colour = new wxColour(wxT("LIGHT GREY")); | |
564 | break; | |
565 | case COLOUR_RED: | |
566 | colour = new wxColour(255, 0, 0); | |
567 | break; | |
568 | case COLOUR_WHITE: | |
569 | colour = new wxColour(255, 255, 255); | |
570 | break; | |
571 | default: | |
572 | wxFAIL; | |
573 | } | |
574 | ms_stockObject[item] = colour; | |
575 | } | |
576 | return colour; | |
577 | } | |
578 | ||
579 | const wxCursor* wxStockGDI::GetCursor(Item item) | |
580 | { | |
581 | wxCursor* cursor = wx_static_cast(wxCursor*, ms_stockObject[item]); | |
582 | if (cursor == NULL) | |
583 | { | |
584 | switch (item) | |
585 | { | |
586 | case CURSOR_CROSS: | |
587 | cursor = new wxCursor(wxCURSOR_CROSS); | |
588 | break; | |
589 | case CURSOR_HOURGLASS: | |
590 | cursor = new wxCursor(wxCURSOR_WAIT); | |
591 | break; | |
592 | case CURSOR_STANDARD: | |
593 | cursor = new wxCursor(wxCURSOR_ARROW); | |
594 | break; | |
595 | default: | |
596 | wxFAIL; | |
597 | } | |
598 | ms_stockObject[item] = cursor; | |
599 | } | |
600 | return cursor; | |
601 | } | |
602 | ||
603 | const wxFont* wxStockGDI::GetFont(Item item) | |
604 | { | |
605 | wxFont* font = wx_static_cast(wxFont*, ms_stockObject[item]); | |
606 | if (font == NULL) | |
607 | { | |
608 | switch (item) | |
609 | { | |
610 | case FONT_ITALIC: | |
611 | font = new wxFont(GetFont(FONT_NORMAL)->GetPointSize(), wxROMAN, wxITALIC, wxNORMAL); | |
612 | break; | |
613 | case FONT_NORMAL: | |
614 | font = new wxFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
615 | break; | |
616 | case FONT_SMALL: | |
617 | font = new wxFont(GetFont(FONT_NORMAL)->GetPointSize() - 2, wxSWISS, wxNORMAL, wxNORMAL); | |
618 | break; | |
619 | case FONT_SWISS: | |
620 | font = new wxFont(GetFont(FONT_NORMAL)->GetPointSize(), wxSWISS, wxNORMAL, wxNORMAL); | |
621 | break; | |
622 | default: | |
623 | wxFAIL; | |
624 | } | |
625 | ms_stockObject[item] = font; | |
626 | } | |
627 | return font; | |
628 | } | |
c801d85f | 629 | |
f516d986 VZ |
630 | const wxPen* wxStockGDI::GetPen(Item item) |
631 | { | |
632 | wxPen* pen = wx_static_cast(wxPen*, ms_stockObject[item]); | |
633 | if (pen == NULL) | |
634 | { | |
635 | switch (item) | |
636 | { | |
637 | case PEN_BLACK: | |
638 | pen = new wxPen(*GetColour(COLOUR_BLACK), 1, wxSOLID); | |
639 | break; | |
640 | case PEN_BLACKDASHED: | |
641 | pen = new wxPen(*GetColour(COLOUR_BLACK), 1, wxSHORT_DASH); | |
642 | break; | |
643 | case PEN_CYAN: | |
644 | pen = new wxPen(*GetColour(COLOUR_CYAN), 1, wxSOLID); | |
645 | break; | |
646 | case PEN_GREEN: | |
647 | pen = new wxPen(*GetColour(COLOUR_GREEN), 1, wxSOLID); | |
648 | break; | |
649 | case PEN_GREY: | |
650 | pen = new wxPen(wxColour(wxT("GREY")), 1, wxSOLID); | |
651 | break; | |
652 | case PEN_LIGHTGREY: | |
653 | pen = new wxPen(*GetColour(COLOUR_LIGHTGREY), 1, wxSOLID); | |
654 | break; | |
655 | case PEN_MEDIUMGREY: | |
656 | pen = new wxPen(wxColour(wxT("MEDIUM GREY")), 1, wxSOLID); | |
657 | break; | |
658 | case PEN_RED: | |
659 | pen = new wxPen(*GetColour(COLOUR_RED), 1, wxSOLID); | |
660 | break; | |
661 | case PEN_TRANSPARENT: | |
662 | pen = new wxPen(*GetColour(COLOUR_BLACK), 1, wxTRANSPARENT); | |
663 | break; | |
664 | case PEN_WHITE: | |
665 | pen = new wxPen(*GetColour(COLOUR_WHITE), 1, wxSOLID); | |
666 | break; | |
667 | default: | |
668 | wxFAIL; | |
669 | } | |
670 | ms_stockObject[item] = pen; | |
671 | } | |
672 | return pen; | |
c801d85f KB |
673 | } |
674 | ||
f516d986 | 675 | void wxInitializeStockLists() |
c801d85f | 676 | { |
f516d986 VZ |
677 | wxTheColourDatabase = new wxColourDatabase; |
678 | ||
679 | wxTheBrushList = new wxBrushList; | |
680 | wxThePenList = new wxPenList; | |
681 | wxTheFontList = new wxFontList; | |
a3622daa VZ |
682 | } |
683 | ||
7ecb8b06 VZ |
684 | void wxDeleteStockLists() |
685 | { | |
5d3e7b52 WS |
686 | wxDELETE(wxTheBrushList); |
687 | wxDELETE(wxThePenList); | |
688 | wxDELETE(wxTheFontList); | |
c801d85f KB |
689 | } |
690 | ||
7ecb8b06 VZ |
691 | // ============================================================================ |
692 | // wxTheXXXList stuff (semi-obsolete) | |
693 | // ============================================================================ | |
694 | ||
1de8d512 | 695 | wxGDIObjListBase::wxGDIObjListBase() |
c801d85f | 696 | { |
c801d85f KB |
697 | } |
698 | ||
1de8d512 | 699 | wxGDIObjListBase::~wxGDIObjListBase() |
c801d85f | 700 | { |
1de8d512 | 701 | for (wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext()) |
c801d85f | 702 | { |
1de8d512 | 703 | delete wx_static_cast(wxObject*, node->GetData()); |
c801d85f KB |
704 | } |
705 | } | |
706 | ||
debe6624 | 707 | wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, int style) |
c801d85f | 708 | { |
1de8d512 | 709 | for (wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext()) |
13b6e335 | 710 | { |
b1d4dd7a | 711 | wxPen *each_pen = (wxPen *) node->GetData (); |
1de8d512 | 712 | if ( |
13b6e335 VZ |
713 | each_pen->GetWidth () == width && |
714 | each_pen->GetStyle () == style && | |
715 | each_pen->GetColour ().Red () == colour.Red () && | |
716 | each_pen->GetColour ().Green () == colour.Green () && | |
717 | each_pen->GetColour ().Blue () == colour.Blue ()) | |
718 | return each_pen; | |
719 | } | |
720 | ||
1de8d512 VZ |
721 | wxPen* pen = NULL; |
722 | wxPen penTmp(colour, width, style); | |
723 | if (penTmp.Ok()) | |
c801d85f | 724 | { |
1de8d512 VZ |
725 | pen = new wxPen(penTmp); |
726 | list.Append(pen); | |
c801d85f | 727 | } |
c801d85f | 728 | |
13b6e335 | 729 | return pen; |
c801d85f KB |
730 | } |
731 | ||
debe6624 | 732 | wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, int style) |
c801d85f | 733 | { |
1de8d512 | 734 | for (wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext()) |
c801d85f | 735 | { |
b1d4dd7a | 736 | wxBrush *each_brush = (wxBrush *) node->GetData (); |
1de8d512 | 737 | if ( |
13b6e335 VZ |
738 | each_brush->GetStyle () == style && |
739 | each_brush->GetColour ().Red () == colour.Red () && | |
740 | each_brush->GetColour ().Green () == colour.Green () && | |
741 | each_brush->GetColour ().Blue () == colour.Blue ()) | |
742 | return each_brush; | |
c801d85f | 743 | } |
6d167489 | 744 | |
1de8d512 VZ |
745 | wxBrush* brush = NULL; |
746 | wxBrush brushTmp(colour, style); | |
747 | if (brushTmp.Ok()) | |
13b6e335 | 748 | { |
1de8d512 VZ |
749 | brush = new wxBrush(brushTmp); |
750 | list.Append(brush); | |
13b6e335 | 751 | } |
6d167489 | 752 | |
13b6e335 | 753 | return brush; |
c801d85f KB |
754 | } |
755 | ||
f6bcfd97 BP |
756 | wxFont *wxFontList::FindOrCreateFont(int pointSize, |
757 | int family, | |
758 | int style, | |
759 | int weight, | |
760 | bool underline, | |
761 | const wxString& facename, | |
762 | wxFontEncoding encoding) | |
c801d85f | 763 | { |
1de8d512 | 764 | wxFont *font; |
222ed1d6 | 765 | wxList::compatibility_iterator node; |
1de8d512 | 766 | for (node = list.GetFirst(); node; node = node->GetNext()) |
c801d85f | 767 | { |
b1d4dd7a | 768 | font = (wxFont *)node->GetData(); |
1de8d512 | 769 | if ( |
f6bcfd97 BP |
770 | font->GetPointSize () == pointSize && |
771 | font->GetStyle () == style && | |
772 | font->GetWeight () == weight && | |
773 | font->GetUnderlined () == underline ) | |
774 | { | |
775 | int fontFamily = font->GetFamily(); | |
776 | ||
619d0528 | 777 | #if defined(__WXGTK__) |
f6bcfd97 BP |
778 | // under GTK the default family is wxSWISS, so looking for a font |
779 | // with wxDEFAULT family should return a wxSWISS one instead of | |
780 | // creating a new one | |
781 | bool same = (fontFamily == family) || | |
782 | (fontFamily == wxSWISS && family == wxDEFAULT); | |
783 | #else // !GTK | |
784 | // VZ: but why elsewhere do we require an exact match? mystery... | |
785 | bool same = fontFamily == family; | |
786 | #endif // GTK/!GTK | |
787 | ||
788 | // empty facename matches anything at all: this is bad because | |
789 | // depending on which fonts are already created, we might get back | |
790 | // a different font if we create it with empty facename, but it is | |
791 | // still better than never matching anything in the cache at all | |
792 | // in this case | |
8d8fbb9d | 793 | if ( same && !facename.empty() ) |
f6bcfd97 BP |
794 | { |
795 | const wxString& fontFace = font->GetFaceName(); | |
796 | ||
797 | // empty facename matches everything | |
798 | same = !fontFace || fontFace == facename; | |
799 | } | |
800 | ||
801 | if ( same && (encoding != wxFONTENCODING_DEFAULT) ) | |
802 | { | |
803 | // have to match the encoding too | |
804 | same = font->GetEncoding() == encoding; | |
805 | } | |
806 | ||
807 | if ( same ) | |
808 | { | |
809 | return font; | |
810 | } | |
811 | } | |
c801d85f | 812 | } |
6d167489 | 813 | |
1de8d512 VZ |
814 | // font not found, create the new one |
815 | font = NULL; | |
816 | wxFont fontTmp(pointSize, family, style, weight, underline, facename, encoding); | |
817 | if (fontTmp.Ok()) | |
f6bcfd97 | 818 | { |
1de8d512 VZ |
819 | font = new wxFont(fontTmp); |
820 | list.Append(font); | |
f6bcfd97 | 821 | } |
6d167489 | 822 | |
f6bcfd97 | 823 | return font; |
c801d85f KB |
824 | } |
825 | ||
1de8d512 VZ |
826 | #if WXWIN_COMPATIBILITY_2_6 |
827 | void wxBrushList::AddBrush(wxBrush*) { } | |
828 | void wxBrushList::RemoveBrush(wxBrush*) { } | |
829 | void wxFontList::AddFont(wxFont*) { } | |
830 | void wxFontList::RemoveFont(wxFont*) { } | |
831 | void wxPenList::AddPen(wxPen*) { } | |
832 | void wxPenList::RemovePen(wxPen*) { } | |
833 | #endif | |
c801d85f | 834 | |
6a6c0a8b JS |
835 | wxSize wxGetDisplaySize() |
836 | { | |
837 | int x, y; | |
838 | wxDisplaySize(& x, & y); | |
839 | return wxSize(x, y); | |
840 | } | |
841 | ||
ec5d7799 RD |
842 | wxRect wxGetClientDisplayRect() |
843 | { | |
844 | int x, y, width, height; | |
845 | wxClientDisplayRect(&x, &y, &width, &height); // call plat-specific version | |
846 | return wxRect(x, y, width, height); | |
847 | } | |
848 | ||
904a68b6 RL |
849 | wxSize wxGetDisplaySizeMM() |
850 | { | |
851 | int x, y; | |
852 | wxDisplaySizeMM(& x, & y); | |
853 | return wxSize(x, y); | |
854 | } | |
855 | ||
8bbe427f VZ |
856 | wxResourceCache::~wxResourceCache () |
857 | { | |
222ed1d6 | 858 | wxList::compatibility_iterator node = GetFirst (); |
f6bcfd97 | 859 | while (node) { |
b1d4dd7a | 860 | wxObject *item = (wxObject *)node->GetData(); |
f6bcfd97 | 861 | delete item; |
a3622daa | 862 | |
b1d4dd7a | 863 | node = node->GetNext (); |
a3622daa | 864 | } |
a3622daa | 865 | } |