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