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