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