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