]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/gdicmn.cpp
fixes for page positioning for notebooks with wxNB_MULTILINE style (closes bugs 70909...
[wxWidgets.git] / src / common / gdicmn.cpp
... / ...
CommitLineData
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
72template<> void wxStringReadValue(const wxString &s , wxPoint &data )
73{
74 wxSscanf(s, wxT("%d,%d"), &data.x , &data.y ) ;
75}
76
77template<> void wxStringWriteValue(wxString &s , const wxPoint &data )
78{
79 s = wxString::Format(wxT("%d,%d"), data.x , data.y ) ;
80}
81
82wxCUSTOM_TYPE_INFO(wxPoint, wxToStringConverter<wxPoint> , wxFromStringConverter<wxPoint>)
83
84template<> void wxStringReadValue(const wxString &s , wxSize &data )
85{
86 wxSscanf(s, wxT("%d,%d"), &data.x , &data.y ) ;
87}
88
89template<> void wxStringWriteValue(wxString &s , const wxSize &data )
90{
91 s = wxString::Format(wxT("%d,%d"), data.x , data.y ) ;
92}
93
94wxCUSTOM_TYPE_INFO(wxSize, wxToStringConverter<wxSize> , wxFromStringConverter<wxSize>)
95
96#endif
97
98IMPLEMENT_ABSTRACT_CLASS(wxDCBase, wxObject)
99
100wxRect::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
122wxRect::wxRect(const wxPoint& point, const wxSize& size)
123{
124 x = point.x; y = point.y;
125 width = size.x; height = size.y;
126}
127
128bool 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
136wxRect& wxRect::operator += (const wxRect& rect)
137{
138 *this = (*this + rect);
139 return ( *this ) ;
140}
141
142wxRect 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
151wxRect& 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
174bool 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
182wxRect& 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
208bool 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// ============================================================================
217// wxColourDatabase
218// ============================================================================
219
220WX_DECLARE_STRING_HASH_MAP( wxColour *, wxStringToColourHashMap );
221
222// ----------------------------------------------------------------------------
223// wxColourDatabase ctor/dtor
224// ----------------------------------------------------------------------------
225
226wxColourDatabase::wxColourDatabase ()
227{
228 // will be created on demand in Initialize()
229 m_map = NULL;
230}
231
232wxColourDatabase::~wxColourDatabase ()
233{
234 if ( m_map )
235 {
236 WX_CLEAR_HASH_MAP(wxStringToColourHashMap, *m_map);
237
238 delete m_map;
239 }
240
241#ifdef __WXPM__
242 delete [] m_palTable;
243#endif
244}
245
246// Colour database stuff
247void wxColourDatabase::Initialize()
248{
249 if ( m_map )
250 {
251 // already initialized
252 return;
253 }
254
255 m_map = new wxStringToColourHashMap;
256
257 static const struct wxColourDesc
258 {
259 const wxChar *name;
260 int r,g,b;
261 }
262 wxColourTable[] =
263 {
264 {wxT("AQUAMARINE"),112, 219, 147},
265 {wxT("BLACK"),0, 0, 0},
266 {wxT("BLUE"), 0, 0, 255},
267 {wxT("BLUE VIOLET"), 159, 95, 159},
268 {wxT("BROWN"), 165, 42, 42},
269 {wxT("CADET BLUE"), 95, 159, 159},
270 {wxT("CORAL"), 255, 127, 0},
271 {wxT("CORNFLOWER BLUE"), 66, 66, 111},
272 {wxT("CYAN"), 0, 255, 255},
273 {wxT("DARK GREY"), 47, 47, 47}, // ?
274
275 {wxT("DARK GREEN"), 47, 79, 47},
276 {wxT("DARK OLIVE GREEN"), 79, 79, 47},
277 {wxT("DARK ORCHID"), 153, 50, 204},
278 {wxT("DARK SLATE BLUE"), 107, 35, 142},
279 {wxT("DARK SLATE GREY"), 47, 79, 79},
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},
287 {wxT("GREEN"), 0, 255, 0},
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},
296 {wxT("MAGENTA"), 255, 0, 255},
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},
318 {wxT("RED"), 255, 0, 0},
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},
324 {wxT("SPRING GREEN"), 0, 255, 127},
325 {wxT("STEEL BLUE"), 35, 107, 142},
326 {wxT("TAN"), 219, 147, 112},
327 {wxT("THISTLE"), 216, 191, 216},
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},
332 {wxT("WHITE"), 255, 255, 255},
333 {wxT("YELLOW"), 255, 255, 0},
334 {wxT("YELLOW GREEN"), 153, 204, 50}
335 };
336
337 size_t n;
338
339 for ( n = 0; n < WXSIZEOF(wxColourTable); n++ )
340 {
341 const wxColourDesc& cc = wxColourTable[n];
342 (*m_map)[cc.name] = new wxColour(cc.r, cc.g, cc.b);
343 }
344
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
354}
355
356// ----------------------------------------------------------------------------
357// wxColourDatabase operations
358// ----------------------------------------------------------------------------
359
360void wxColourDatabase::AddColour(const wxString& name, const wxColour& colour)
361{
362 Initialize();
363
364 // canonicalize the colour names before using them as keys: they should be
365 // in upper case
366 wxString colName = name;
367 colName.MakeUpper();
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 }
376
377 wxStringToColourHashMap::iterator it = m_map->find(colName);
378 if ( it == m_map->end() && !colNameAlt.empty() )
379 it = m_map->find(colNameAlt);
380 if ( it != m_map->end() )
381 {
382 *(it->second) = colour;
383 }
384 else // new colour
385 {
386 (*m_map)[name] = new wxColour(colour);
387 }
388}
389
390wxColour wxColourDatabase::Find(const wxString& colour) const
391{
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
398 wxString colName = colour;
399 colName.MakeUpper();
400 wxString colNameAlt = colName;
401 if ( !colNameAlt.Replace(_T("GRAY"), _T("GREY")) )
402 colNameAlt.clear();
403
404 wxStringToColourHashMap::iterator it = m_map->find(colName);
405 if ( it == m_map->end() && !colNameAlt.empty() )
406 it = m_map->find(colNameAlt);
407 if ( it != m_map->end() )
408 return *(it->second);
409
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);
413
414 if ( col.Ok() )
415 {
416 // cache it
417 self->AddColour(colour, col);
418 }
419
420 return col;
421#elif defined(__X__)
422 // TODO: move this to wxColour::CreateByName()
423 XColor xcolour;
424
425#ifdef __WXMOTIF__
426 Display *display = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()) ;
427#endif
428#ifdef __WXX11__
429 Display* display = (Display*) wxGetDisplay();
430#endif
431 /* MATTHEW: [4] Use wxGetMainColormap */
432 if (!XParseColor(display, (Colormap) wxTheApp->GetMainColormap((WXDisplay*) display), colour.ToAscii() ,&xcolour))
433 return NULL;
434
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
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);
443#endif
444
445 wxColour col(r, g, b);
446 AddColour(colour, col);
447
448 return col;
449#else // other platform
450 return wxNullColour;
451#endif // platforms
452}
453
454wxString wxColourDatabase::FindName(const wxColour& colour) const
455{
456 wxColourDatabase * const self = wxConstCast(this, wxColourDatabase);
457 self->Initialize();
458
459 typedef wxStringToColourHashMap::iterator iterator;
460
461 for ( iterator it = m_map->begin(), en = m_map->end(); it != en; ++it )
462 {
463 if ( *(it->second) == colour )
464 return it->first;
465 }
466
467 return wxEmptyString;
468}
469
470// ----------------------------------------------------------------------------
471// deprecated wxColourDatabase methods
472// ----------------------------------------------------------------------------
473
474wxColour *wxColourDatabase::FindColour(const wxString& name)
475{
476 // This function is deprecated, use Find() instead.
477 // Formerly this function sometimes would return a deletable pointer and
478 // sometimes a non-deletable one (when returning a colour from the database).
479 // Trying to delete the latter anyway results in problems, so probably
480 // nobody ever freed the pointers. Currently it always returns a new
481 // instance, which means there will be memory leaks.
482 wxLogDebug(wxT("wxColourDataBase::FindColour():")
483 wxT(" Please use wxColourDataBase::Find() instead"));
484
485 // using a static variable here is not the most elegant solution but unless
486 // we want to make wxStringToColourHashMap public (i.e. move it to the
487 // header) so that we could have a member function returning
488 // wxStringToColourHashMap::iterator, there is really no good way to do it
489 // otherwise
490 //
491 // and knowing that this function is going to disappear in the next release
492 // anyhow I don't want to waste time on this
493
494 static wxColour s_col;
495
496 s_col = Find(name);
497 if ( !s_col.Ok() )
498 return NULL;
499
500 return new wxColour(s_col);
501}
502
503// ============================================================================
504// stock objects
505// ============================================================================
506
507void wxInitializeStockLists()
508{
509 wxTheColourDatabase = new wxColourDatabase;
510
511 wxTheBrushList = new wxBrushList;
512 wxThePenList = new wxPenList;
513 wxTheFontList = new wxFontList;
514 wxTheBitmapList = new wxBitmapList;
515}
516
517void wxInitializeStockObjects ()
518{
519#ifdef __WXMOTIF__
520#endif
521#ifdef __X__
522 // TODO
523 // wxFontPool = new XFontPool;
524#endif
525
526 // why under MSW fonts shouldn't have the standard system size?
527/*
528#ifdef __WXMSW__
529 static const int sizeFont = 10;
530#else
531#endif
532*/
533#if defined(__WXMAC__)
534 int sizeFont = 12;
535
536 Str255 fontName ;
537 SInt16 fontSize ;
538 Style fontStyle ;
539
540 GetThemeFont(kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
541 sizeFont = fontSize ;
542 wxNORMAL_FONT = new wxFont (fontSize, wxMODERN, wxNORMAL, wxNORMAL , false , wxMacMakeStringFromPascal(fontName) );
543#elif defined(__WXPM__)
544 static const int sizeFont = 12;
545#else
546 wxNORMAL_FONT = new wxFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
547 static const int sizeFont = wxNORMAL_FONT->GetPointSize();
548#endif
549
550#if defined(__WXPM__)
551 /*
552 // Basic OS/2 has a fairly limited number of fonts and these are as good
553 // as I can do to get something that looks halfway "wx" normal
554 */
555 wxNORMAL_FONT = new wxFont (sizeFont, wxMODERN, wxNORMAL, wxBOLD);
556 wxSMALL_FONT = new wxFont (sizeFont - 4, wxSWISS, wxNORMAL, wxNORMAL); /* Helv */
557 wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL);
558 wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL); /* Helv */
559#elif defined(__WXMAC__)
560 wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL); /* Helv */
561 wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL);
562 GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
563 wxSMALL_FONT = new wxFont (fontSize, wxSWISS, wxNORMAL, wxNORMAL , false , wxMacMakeStringFromPascal( fontName ) );
564#else
565 wxSMALL_FONT = new wxFont (sizeFont - 2, wxSWISS, wxNORMAL, wxNORMAL);
566 wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL);
567 wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL);
568#endif
569
570 wxRED_PEN = new wxPen (wxT("RED"), 1, wxSOLID);
571 wxCYAN_PEN = new wxPen (wxT("CYAN"), 1, wxSOLID);
572 wxGREEN_PEN = new wxPen (wxT("GREEN"), 1, wxSOLID);
573 wxBLACK_PEN = new wxPen (wxT("BLACK"), 1, wxSOLID);
574 wxWHITE_PEN = new wxPen (wxT("WHITE"), 1, wxSOLID);
575 wxTRANSPARENT_PEN = new wxPen (wxT("BLACK"), 1, wxTRANSPARENT);
576 wxBLACK_DASHED_PEN = new wxPen (wxT("BLACK"), 1, wxSHORT_DASH);
577 wxGREY_PEN = new wxPen (wxT("GREY"), 1, wxSOLID);
578 wxMEDIUM_GREY_PEN = new wxPen (wxT("MEDIUM GREY"), 1, wxSOLID);
579 wxLIGHT_GREY_PEN = new wxPen (wxT("LIGHT GREY"), 1, wxSOLID);
580
581 wxBLUE_BRUSH = new wxBrush (wxT("BLUE"), wxSOLID);
582 wxGREEN_BRUSH = new wxBrush (wxT("GREEN"), wxSOLID);
583 wxWHITE_BRUSH = new wxBrush (wxT("WHITE"), wxSOLID);
584 wxBLACK_BRUSH = new wxBrush (wxT("BLACK"), wxSOLID);
585 wxTRANSPARENT_BRUSH = new wxBrush (wxT("BLACK"), wxTRANSPARENT);
586 wxCYAN_BRUSH = new wxBrush (wxT("CYAN"), wxSOLID);
587 wxRED_BRUSH = new wxBrush (wxT("RED"), wxSOLID);
588 wxGREY_BRUSH = new wxBrush (wxT("GREY"), wxSOLID);
589 wxMEDIUM_GREY_BRUSH = new wxBrush (wxT("MEDIUM GREY"), wxSOLID);
590 wxLIGHT_GREY_BRUSH = new wxBrush (wxT("LIGHT GREY"), wxSOLID);
591
592 wxBLACK = new wxColour (wxT("BLACK"));
593 wxWHITE = new wxColour (wxT("WHITE"));
594 wxRED = new wxColour (wxT("RED"));
595 wxBLUE = new wxColour (wxT("BLUE"));
596 wxGREEN = new wxColour (wxT("GREEN"));
597 wxCYAN = new wxColour (wxT("CYAN"));
598 wxLIGHT_GREY = new wxColour (wxT("LIGHT GREY"));
599
600 wxSTANDARD_CURSOR = new wxCursor (wxCURSOR_ARROW);
601 wxHOURGLASS_CURSOR = new wxCursor (wxCURSOR_WAIT);
602 wxCROSS_CURSOR = new wxCursor (wxCURSOR_CROSS);
603}
604
605void wxDeleteStockObjects ()
606{
607 wxDELETE(wxNORMAL_FONT);
608 wxDELETE(wxSMALL_FONT);
609 wxDELETE(wxITALIC_FONT);
610 wxDELETE(wxSWISS_FONT);
611
612 wxDELETE(wxRED_PEN);
613 wxDELETE(wxCYAN_PEN);
614 wxDELETE(wxGREEN_PEN);
615 wxDELETE(wxBLACK_PEN);
616 wxDELETE(wxWHITE_PEN);
617 wxDELETE(wxTRANSPARENT_PEN);
618 wxDELETE(wxBLACK_DASHED_PEN);
619 wxDELETE(wxGREY_PEN);
620 wxDELETE(wxMEDIUM_GREY_PEN);
621 wxDELETE(wxLIGHT_GREY_PEN);
622
623 wxDELETE(wxBLUE_BRUSH);
624 wxDELETE(wxGREEN_BRUSH);
625 wxDELETE(wxWHITE_BRUSH);
626 wxDELETE(wxBLACK_BRUSH);
627 wxDELETE(wxTRANSPARENT_BRUSH);
628 wxDELETE(wxCYAN_BRUSH);
629 wxDELETE(wxRED_BRUSH);
630 wxDELETE(wxGREY_BRUSH);
631 wxDELETE(wxMEDIUM_GREY_BRUSH);
632 wxDELETE(wxLIGHT_GREY_BRUSH);
633
634 wxDELETE(wxBLACK);
635 wxDELETE(wxWHITE);
636 wxDELETE(wxRED);
637 wxDELETE(wxBLUE);
638 wxDELETE(wxGREEN);
639 wxDELETE(wxCYAN);
640 wxDELETE(wxLIGHT_GREY);
641
642 wxDELETE(wxSTANDARD_CURSOR);
643 wxDELETE(wxHOURGLASS_CURSOR);
644 wxDELETE(wxCROSS_CURSOR);
645}
646
647void wxDeleteStockLists()
648{
649 wxDELETE(wxTheBrushList);
650 wxDELETE(wxThePenList);
651 wxDELETE(wxTheFontList);
652 wxDELETE(wxTheBitmapList);
653}
654
655// ============================================================================
656// wxTheXXXList stuff (semi-obsolete)
657// ============================================================================
658
659wxBitmapList::wxBitmapList()
660{
661}
662
663wxBitmapList::~wxBitmapList ()
664{
665 wxList::compatibility_iterator node = GetFirst ();
666 while (node)
667 {
668 wxBitmap *bitmap = (wxBitmap *) node->GetData ();
669 wxList::compatibility_iterator next = node->GetNext ();
670 if (bitmap->GetVisible())
671 delete bitmap;
672 node = next;
673 }
674}
675
676// Pen and Brush lists
677wxPenList::~wxPenList ()
678{
679 wxList::compatibility_iterator node = GetFirst ();
680 while (node)
681 {
682 wxPen *pen = (wxPen *) node->GetData ();
683 wxList::compatibility_iterator next = node->GetNext ();
684 if (pen->GetVisible())
685 delete pen;
686 node = next;
687 }
688}
689
690void wxPenList::AddPen (wxPen * pen)
691{
692 Append (pen);
693}
694
695void wxPenList::RemovePen (wxPen * pen)
696{
697 DeleteObject (pen);
698}
699
700wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, int style)
701{
702 for (wxList::compatibility_iterator node = GetFirst (); node; node = node->GetNext ())
703 {
704 wxPen *each_pen = (wxPen *) node->GetData ();
705 if (each_pen &&
706 each_pen->GetVisible() &&
707 each_pen->GetWidth () == width &&
708 each_pen->GetStyle () == style &&
709 each_pen->GetColour ().Red () == colour.Red () &&
710 each_pen->GetColour ().Green () == colour.Green () &&
711 each_pen->GetColour ().Blue () == colour.Blue ())
712 return each_pen;
713 }
714
715 wxPen *pen = new wxPen (colour, width, style);
716 if ( !pen->Ok() )
717 {
718 // don't save the invalid pens in the list
719 delete pen;
720
721 return NULL;
722 }
723
724 AddPen(pen);
725
726 // we'll delete it ourselves later
727 pen->SetVisible(TRUE);
728
729 return pen;
730}
731
732wxBrushList::~wxBrushList ()
733{
734 wxList::compatibility_iterator node = GetFirst ();
735 while (node)
736 {
737 wxBrush *brush = (wxBrush *) node->GetData ();
738 wxList::compatibility_iterator next = node->GetNext ();
739 if (brush && brush->GetVisible())
740 delete brush;
741 node = next;
742 }
743}
744
745void wxBrushList::AddBrush (wxBrush * brush)
746{
747 Append (brush);
748}
749
750wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, int style)
751{
752 for (wxList::compatibility_iterator node = GetFirst (); node; node = node->GetNext ())
753 {
754 wxBrush *each_brush = (wxBrush *) node->GetData ();
755 if (each_brush &&
756 each_brush->GetVisible() &&
757 each_brush->GetStyle () == style &&
758 each_brush->GetColour ().Red () == colour.Red () &&
759 each_brush->GetColour ().Green () == colour.Green () &&
760 each_brush->GetColour ().Blue () == colour.Blue ())
761 return each_brush;
762 }
763
764 wxBrush *brush = new wxBrush (colour, style);
765
766 if ( !brush->Ok() )
767 {
768 // don't put the brushes we failed to create into the list
769 delete brush;
770
771 return NULL;
772 }
773
774 AddBrush(brush);
775
776 // we'll delete it ourselves later
777 brush->SetVisible(TRUE);
778
779 return brush;
780}
781
782void wxBrushList::RemoveBrush (wxBrush * brush)
783{
784 DeleteObject (brush);
785}
786
787wxFontList::~wxFontList ()
788{
789 wxList::compatibility_iterator node = GetFirst ();
790 while (node)
791 {
792 // Only delete objects that are 'visible', i.e.
793 // that have been created using FindOrCreate...,
794 // where the pointers are expected to be shared
795 // (and therefore not deleted by any one part of an app).
796 wxFont *font = (wxFont *) node->GetData ();
797 wxList::compatibility_iterator next = node->GetNext ();
798 if (font->GetVisible())
799 delete font;
800 node = next;
801 }
802}
803
804void wxFontList::AddFont (wxFont * font)
805{
806 Append (font);
807}
808
809void wxFontList::RemoveFont (wxFont * font)
810{
811 DeleteObject (font);
812}
813
814wxFont *wxFontList::FindOrCreateFont(int pointSize,
815 int family,
816 int style,
817 int weight,
818 bool underline,
819 const wxString& facename,
820 wxFontEncoding encoding)
821{
822 wxFont *font = (wxFont *)NULL;
823 wxList::compatibility_iterator node;
824 for ( node = GetFirst(); node; node = node->GetNext() )
825 {
826 font = (wxFont *)node->GetData();
827 if ( font->GetVisible() &&
828 font->Ok() &&
829 font->GetPointSize () == pointSize &&
830 font->GetStyle () == style &&
831 font->GetWeight () == weight &&
832 font->GetUnderlined () == underline )
833 {
834 int fontFamily = font->GetFamily();
835
836#if defined(__WXGTK__)
837 // under GTK the default family is wxSWISS, so looking for a font
838 // with wxDEFAULT family should return a wxSWISS one instead of
839 // creating a new one
840 bool same = (fontFamily == family) ||
841 (fontFamily == wxSWISS && family == wxDEFAULT);
842#else // !GTK
843 // VZ: but why elsewhere do we require an exact match? mystery...
844 bool same = fontFamily == family;
845#endif // GTK/!GTK
846
847 // empty facename matches anything at all: this is bad because
848 // depending on which fonts are already created, we might get back
849 // a different font if we create it with empty facename, but it is
850 // still better than never matching anything in the cache at all
851 // in this case
852 if ( same && !!facename )
853 {
854 const wxString& fontFace = font->GetFaceName();
855
856 // empty facename matches everything
857 same = !fontFace || fontFace == facename;
858 }
859
860 if ( same && (encoding != wxFONTENCODING_DEFAULT) )
861 {
862 // have to match the encoding too
863 same = font->GetEncoding() == encoding;
864 }
865
866 if ( same )
867 {
868 return font;
869 }
870 }
871 }
872
873 if ( !node )
874 {
875 // font not found, create the new one
876 font = new wxFont(pointSize, family, style, weight,
877 underline, facename, encoding);
878
879 AddFont(font);
880
881 // and mark it as being cacheable
882 font->SetVisible(TRUE);
883 }
884
885 return font;
886}
887
888void wxBitmapList::AddBitmap(wxBitmap *bitmap)
889{
890 Append(bitmap);
891}
892
893void wxBitmapList::RemoveBitmap(wxBitmap *bitmap)
894{
895 DeleteObject(bitmap);
896}
897
898wxSize wxGetDisplaySize()
899{
900 int x, y;
901 wxDisplaySize(& x, & y);
902 return wxSize(x, y);
903}
904
905wxRect wxGetClientDisplayRect()
906{
907 int x, y, width, height;
908 wxClientDisplayRect(&x, &y, &width, &height); // call plat-specific version
909 return wxRect(x, y, width, height);
910}
911
912wxSize wxGetDisplaySizeMM()
913{
914 int x, y;
915 wxDisplaySizeMM(& x, & y);
916 return wxSize(x, y);
917}
918
919wxResourceCache::~wxResourceCache ()
920{
921 wxList::compatibility_iterator node = GetFirst ();
922 while (node) {
923 wxObject *item = (wxObject *)node->GetData();
924 delete item;
925
926 node = node->GetNext ();
927 }
928}
929