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