]>
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 and Markus Holzem | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "gdicmn.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #include "wx/event.h" | |
24 | #include "wx/gdicmn.h" | |
25 | #include "wx/brush.h" | |
26 | #include "wx/pen.h" | |
27 | #include "wx/bitmap.h" | |
28 | #include "wx/icon.h" | |
29 | #include "wx/cursor.h" | |
30 | #include "wx/font.h" | |
31 | #include "wx/palette.h" | |
32 | #include "wx/app.h" | |
33 | #include "wx/dc.h" | |
34 | #include "wx/utils.h" | |
35 | ||
36 | #include "wx/log.h" | |
37 | #include <string.h> | |
38 | ||
39 | #ifdef __WXMSW__ | |
40 | #include <windows.h> | |
41 | #endif | |
42 | ||
43 | #ifdef __WXMOTIF__ | |
44 | #ifdef __VMS__ | |
45 | #pragma message disable nosimpint | |
46 | #endif | |
47 | #include <Xm/Xm.h> | |
48 | #ifdef __VMS__ | |
49 | #pragma message enable nosimpint | |
50 | #endif | |
51 | #endif | |
52 | ||
53 | IMPLEMENT_CLASS(wxColourDatabase, wxList) | |
54 | IMPLEMENT_DYNAMIC_CLASS(wxFontList, wxList) | |
55 | IMPLEMENT_DYNAMIC_CLASS(wxPenList, wxList) | |
56 | IMPLEMENT_DYNAMIC_CLASS(wxBrushList, wxList) | |
57 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapList, wxList) | |
58 | IMPLEMENT_DYNAMIC_CLASS(wxResourceCache, wxList) | |
59 | ||
60 | IMPLEMENT_ABSTRACT_CLASS(wxDCBase, wxObject) | |
61 | ||
62 | wxRect::wxRect(const wxPoint& topLeft, const wxPoint& bottomRight) | |
63 | { | |
64 | x = topLeft.x; | |
65 | y = topLeft.y; | |
66 | width = bottomRight.x - topLeft.x; | |
67 | height = bottomRight.y - topLeft.y; | |
68 | ||
69 | if (width < 0) | |
70 | { | |
71 | width = -width; | |
72 | x -= width; | |
73 | } | |
74 | ||
75 | if (height < 0) | |
76 | { | |
77 | height = -height; | |
78 | y -= height; | |
79 | } | |
80 | } | |
81 | ||
82 | wxRect::wxRect(const wxPoint& point, const wxSize& size) | |
83 | { | |
84 | x = point.x; y = point.y; | |
85 | width = size.x; height = size.y; | |
86 | } | |
87 | ||
88 | bool wxRect::operator==(const wxRect& rect) const | |
89 | { | |
90 | return ((x == rect.x) && | |
91 | (y == rect.y) && | |
92 | (width == rect.width) && | |
93 | (height == rect.height)); | |
94 | } | |
95 | ||
96 | wxRect& wxRect::operator += (const wxRect& rect) | |
97 | { | |
98 | *this = (*this + rect); | |
99 | return ( *this ) ; | |
100 | } | |
101 | ||
102 | wxRect wxRect::operator + (const wxRect& rect) const | |
103 | { | |
104 | int x1 = wxMin(this->x, rect.x); | |
105 | int y1 = wxMin(this->y, rect.y); | |
106 | int y2 = wxMax(y+height, rect.height+rect.y); | |
107 | int x2 = wxMax(x+width, rect.width+rect.x); | |
108 | return wxRect(x1, y1, x2-x1, y2-y1); | |
109 | } | |
110 | ||
111 | bool wxRect::Inside(int cx, int cy) const | |
112 | { | |
113 | return ( (cx >= x) && (cy >= y) | |
114 | && ((cy - y) < height) | |
115 | && ((cx - x) < width) | |
116 | ); | |
117 | } | |
118 | ||
119 | wxColourDatabase::wxColourDatabase (int type) : wxList (type) | |
120 | { | |
121 | } | |
122 | ||
123 | wxColourDatabase::~wxColourDatabase () | |
124 | { | |
125 | // Cleanup Colour allocated in Initialize() | |
126 | wxNode *node = First (); | |
127 | while (node) | |
128 | { | |
129 | wxColour *col = (wxColour *) node->Data (); | |
130 | wxNode *next = node->Next (); | |
131 | delete col; | |
132 | node = next; | |
133 | } | |
134 | } | |
135 | ||
136 | // Colour database stuff | |
137 | void wxColourDatabase::Initialize () | |
138 | { | |
139 | // Don't initialize for X: colours are found | |
140 | // in FindColour below. | |
141 | // Added: Not all | |
142 | ||
143 | struct cdef { | |
144 | wxChar *name; | |
145 | int r,g,b; | |
146 | }; | |
147 | cdef cc; | |
148 | static cdef table[]={ | |
149 | ||
150 | // #ifdef __WXMSW__ | |
151 | {wxT("AQUAMARINE"),112, 219, 147}, | |
152 | {wxT("BLACK"),0, 0, 0}, | |
153 | {wxT("BLUE"), 0, 0, 255}, | |
154 | {wxT("BLUE VIOLET"), 159, 95, 159}, | |
155 | {wxT("BROWN"), 165, 42, 42}, | |
156 | {wxT("CADET BLUE"), 95, 159, 159}, | |
157 | {wxT("CORAL"), 255, 127, 0}, | |
158 | {wxT("CORNFLOWER BLUE"), 66, 66, 111}, | |
159 | {wxT("CYAN"), 0, 255, 255}, | |
160 | {wxT("DARK GREY"), 47, 47, 47}, // ? | |
161 | ||
162 | {wxT("DARK GREEN"), 47, 79, 47}, | |
163 | {wxT("DARK OLIVE GREEN"), 79, 79, 47}, | |
164 | {wxT("DARK ORCHID"), 153, 50, 204}, | |
165 | {wxT("DARK SLATE BLUE"), 107, 35, 142}, | |
166 | {wxT("DARK SLATE GREY"), 47, 79, 79}, | |
167 | {wxT("DARK TURQUOISE"), 112, 147, 219}, | |
168 | {wxT("DIM GREY"), 84, 84, 84}, | |
169 | {wxT("FIREBRICK"), 142, 35, 35}, | |
170 | {wxT("FOREST GREEN"), 35, 142, 35}, | |
171 | {wxT("GOLD"), 204, 127, 50}, | |
172 | {wxT("GOLDENROD"), 219, 219, 112}, | |
173 | {wxT("GREY"), 128, 128, 128}, | |
174 | {wxT("GREEN"), 0, 255, 0}, | |
175 | {wxT("GREEN YELLOW"), 147, 219, 112}, | |
176 | {wxT("INDIAN RED"), 79, 47, 47}, | |
177 | {wxT("KHAKI"), 159, 159, 95}, | |
178 | {wxT("LIGHT BLUE"), 191, 216, 216}, | |
179 | {wxT("LIGHT GREY"), 192, 192, 192}, | |
180 | {wxT("LIGHT STEEL BLUE"), 143, 143, 188}, | |
181 | {wxT("LIME GREEN"), 50, 204, 50}, | |
182 | {wxT("LIGHT MAGENTA"), 255, 0, 255}, | |
183 | {wxT("MAGENTA"), 255, 0, 255}, | |
184 | {wxT("MAROON"), 142, 35, 107}, | |
185 | {wxT("MEDIUM AQUAMARINE"), 50, 204, 153}, | |
186 | {wxT("MEDIUM GREY"), 100, 100, 100}, | |
187 | {wxT("MEDIUM BLUE"), 50, 50, 204}, | |
188 | {wxT("MEDIUM FOREST GREEN"), 107, 142, 35}, | |
189 | {wxT("MEDIUM GOLDENROD"), 234, 234, 173}, | |
190 | {wxT("MEDIUM ORCHID"), 147, 112, 219}, | |
191 | {wxT("MEDIUM SEA GREEN"), 66, 111, 66}, | |
192 | {wxT("MEDIUM SLATE BLUE"), 127, 0, 255}, | |
193 | {wxT("MEDIUM SPRING GREEN"), 127, 255, 0}, | |
194 | {wxT("MEDIUM TURQUOISE"), 112, 219, 219}, | |
195 | {wxT("MEDIUM VIOLET RED"), 219, 112, 147}, | |
196 | {wxT("MIDNIGHT BLUE"), 47, 47, 79}, | |
197 | {wxT("NAVY"), 35, 35, 142}, | |
198 | {wxT("ORANGE"), 204, 50, 50}, | |
199 | {wxT("ORANGE RED"), 255, 0, 127}, | |
200 | {wxT("ORCHID"), 219, 112, 219}, | |
201 | {wxT("PALE GREEN"), 143, 188, 143}, | |
202 | {wxT("PINK"), 188, 143, 234}, | |
203 | {wxT("PLUM"), 234, 173, 234}, | |
204 | {wxT("PURPLE"), 176, 0, 255}, | |
205 | {wxT("RED"), 255, 0, 0}, | |
206 | {wxT("SALMON"), 111, 66, 66}, | |
207 | {wxT("SEA GREEN"), 35, 142, 107}, | |
208 | {wxT("SIENNA"), 142, 107, 35}, | |
209 | {wxT("SKY BLUE"), 50, 153, 204}, | |
210 | {wxT("SLATE BLUE"), 0, 127, 255}, | |
211 | {wxT("SPRING GREEN"), 0, 255, 127}, | |
212 | {wxT("STEEL BLUE"), 35, 107, 142}, | |
213 | {wxT("TAN"), 219, 147, 112}, | |
214 | {wxT("THISTLE"), 216, 191, 216}, | |
215 | {wxT("TURQUOISE"), 173, 234, 234}, | |
216 | {wxT("VIOLET"), 79, 47, 79}, | |
217 | {wxT("VIOLET RED"), 204, 50, 153}, | |
218 | {wxT("WHEAT"), 216, 216, 191}, | |
219 | {wxT("WHITE"), 255, 255, 255}, | |
220 | {wxT("YELLOW"), 255, 255, 0}, | |
221 | {wxT("YELLOW GREEN"), 153, 204, 50}, | |
222 | // #endif | |
223 | ||
224 | #if defined(__WXGTK__) || defined(__X__) | |
225 | {wxT("MEDIUM GOLDENROD"), 234, 234, 173}, | |
226 | {wxT("MEDIUM FOREST GREEN"), 107, 142, 35}, | |
227 | {wxT("LIGHT MAGENTA"), 255, 0, 255}, | |
228 | {wxT("MEDIUM GREY"), 100, 100, 100}, | |
229 | #endif | |
230 | ||
231 | {0,0,0,0} | |
232 | }; | |
233 | int i; | |
234 | for (i=0;cc=table[i],cc.name!=0;i++) | |
235 | { | |
236 | Append(cc.name,new wxColour(cc.r,cc.g,cc.b)); | |
237 | } | |
238 | ||
239 | } | |
240 | ||
241 | /* | |
242 | * Changed by Ian Brown, July 1994. | |
243 | * | |
244 | * When running under X, the Colour Database starts off empty. The X server | |
245 | * is queried for the colour first time after which it is entered into the | |
246 | * database. This allows our client to use the server colour database which | |
247 | * is hopefully gamma corrected for the display being used. | |
248 | */ | |
249 | ||
250 | wxColour *wxColourDatabase::FindColour(const wxString& colour) | |
251 | { | |
252 | // VZ: make the comparaison case insensitive | |
253 | wxString str = colour; | |
254 | str.MakeUpper(); | |
255 | ||
256 | wxNode *node = Find(str); | |
257 | if (node) | |
258 | return (wxColour *)node->Data(); | |
259 | ||
260 | #ifdef __WXMSW__ | |
261 | else return NULL; | |
262 | #endif | |
263 | #ifdef __WXPM__ | |
264 | else return NULL; | |
265 | #endif | |
266 | ||
267 | // TODO for other implementations. This should really go into | |
268 | // platform-specific directories. | |
269 | #ifdef __WXMAC__ | |
270 | else return NULL; | |
271 | #endif | |
272 | #ifdef __WXSTUBS__ | |
273 | else return NULL; | |
274 | #endif | |
275 | ||
276 | #ifdef __WXGTK__ | |
277 | else { | |
278 | wxColour *col = new wxColour( colour ); | |
279 | ||
280 | if (!(col->Ok())) { | |
281 | delete col; | |
282 | return (wxColour *) NULL; | |
283 | } | |
284 | Append( colour, col ); | |
285 | return col; | |
286 | } | |
287 | #endif | |
288 | ||
289 | #ifdef __X__ | |
290 | else { | |
291 | XColor xcolour; | |
292 | ||
293 | #ifdef __WXMOTIF__ | |
294 | Display *display = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()) ; | |
295 | #endif | |
296 | #ifdef __XVIEW__ | |
297 | Xv_Screen screen = xv_get(xview_server, SERVER_NTH_SCREEN, 0); | |
298 | Xv_opaque root_window = xv_get(screen, XV_ROOT); | |
299 | Display *display = (Display *)xv_get(root_window, XV_DISPLAY); | |
300 | #endif | |
301 | ||
302 | /* MATTHEW: [4] Use wxGetMainColormap */ | |
303 | if (!XParseColor(display, (Colormap) wxTheApp->GetMainColormap((WXDisplay*) display), colour,&xcolour)) | |
304 | return NULL; | |
305 | ||
306 | unsigned char r = (unsigned char)(xcolour.red >> 8); | |
307 | unsigned char g = (unsigned char)(xcolour.green >> 8); | |
308 | unsigned char b = (unsigned char)(xcolour.blue >> 8); | |
309 | ||
310 | wxColour *col = new wxColour(r, g, b); | |
311 | Append(colour, col); | |
312 | ||
313 | return col; | |
314 | } | |
315 | #endif | |
316 | } | |
317 | ||
318 | wxString wxColourDatabase::FindName (const wxColour& colour) const | |
319 | { | |
320 | wxString name; | |
321 | ||
322 | unsigned char red = colour.Red (); | |
323 | unsigned char green = colour.Green (); | |
324 | unsigned char blue = colour.Blue (); | |
325 | ||
326 | for (wxNode * node = First (); node; node = node->Next ()) | |
327 | { | |
328 | wxColour *col = (wxColour *) node->Data (); | |
329 | ||
330 | if (col->Red () == red && col->Green () == green && col->Blue () == blue) | |
331 | { | |
332 | const wxChar *found = node->GetKeyString(); | |
333 | if ( found ) | |
334 | { | |
335 | name = found; | |
336 | ||
337 | break; | |
338 | } | |
339 | } | |
340 | } | |
341 | ||
342 | return name; | |
343 | } | |
344 | ||
345 | void wxInitializeStockLists () { | |
346 | wxTheBrushList = new wxBrushList; | |
347 | wxThePenList = new wxPenList; | |
348 | wxTheFontList = new wxFontList; | |
349 | wxTheBitmapList = new wxBitmapList; | |
350 | } | |
351 | ||
352 | void wxInitializeStockObjects () | |
353 | { | |
354 | #ifdef __WXMOTIF__ | |
355 | #endif | |
356 | #ifdef __X__ | |
357 | // TODO | |
358 | // wxFontPool = new XFontPool; | |
359 | #endif | |
360 | ||
361 | // why under MSW fonts shouldn't have the standard system size? | |
362 | #ifdef __WXMSW__ | |
363 | static const int sizeFont = 10; | |
364 | #else | |
365 | static const int sizeFont = 12; | |
366 | #endif | |
367 | ||
368 | wxNORMAL_FONT = new wxFont (sizeFont, wxMODERN, wxNORMAL, wxNORMAL); | |
369 | wxSMALL_FONT = new wxFont (sizeFont - 2, wxSWISS, wxNORMAL, wxNORMAL); | |
370 | wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL); | |
371 | wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL); | |
372 | ||
373 | wxRED_PEN = new wxPen ("RED", 1, wxSOLID); | |
374 | wxCYAN_PEN = new wxPen ("CYAN", 1, wxSOLID); | |
375 | wxGREEN_PEN = new wxPen ("GREEN", 1, wxSOLID); | |
376 | wxBLACK_PEN = new wxPen ("BLACK", 1, wxSOLID); | |
377 | wxWHITE_PEN = new wxPen ("WHITE", 1, wxSOLID); | |
378 | wxTRANSPARENT_PEN = new wxPen ("BLACK", 1, wxTRANSPARENT); | |
379 | wxBLACK_DASHED_PEN = new wxPen ("BLACK", 1, wxSHORT_DASH); | |
380 | wxGREY_PEN = new wxPen ("GREY", 1, wxSOLID); | |
381 | wxMEDIUM_GREY_PEN = new wxPen ("MEDIUM GREY", 1, wxSOLID); | |
382 | wxLIGHT_GREY_PEN = new wxPen ("LIGHT GREY", 1, wxSOLID); | |
383 | ||
384 | wxBLUE_BRUSH = new wxBrush ("BLUE", wxSOLID); | |
385 | wxGREEN_BRUSH = new wxBrush ("GREEN", wxSOLID); | |
386 | wxWHITE_BRUSH = new wxBrush ("WHITE", wxSOLID); | |
387 | wxBLACK_BRUSH = new wxBrush ("BLACK", wxSOLID); | |
388 | wxTRANSPARENT_BRUSH = new wxBrush ("BLACK", wxTRANSPARENT); | |
389 | wxCYAN_BRUSH = new wxBrush ("CYAN", wxSOLID); | |
390 | wxRED_BRUSH = new wxBrush ("RED", wxSOLID); | |
391 | wxGREY_BRUSH = new wxBrush ("GREY", wxSOLID); | |
392 | wxMEDIUM_GREY_BRUSH = new wxBrush ("MEDIUM GREY", wxSOLID); | |
393 | wxLIGHT_GREY_BRUSH = new wxBrush ("LIGHT GREY", wxSOLID); | |
394 | ||
395 | wxBLACK = new wxColour ("BLACK"); | |
396 | wxWHITE = new wxColour ("WHITE"); | |
397 | wxRED = new wxColour ("RED"); | |
398 | wxBLUE = new wxColour ("BLUE"); | |
399 | wxGREEN = new wxColour ("GREEN"); | |
400 | wxCYAN = new wxColour ("CYAN"); | |
401 | wxLIGHT_GREY = new wxColour ("LIGHT GREY"); | |
402 | ||
403 | wxSTANDARD_CURSOR = new wxCursor (wxCURSOR_ARROW); | |
404 | wxHOURGLASS_CURSOR = new wxCursor (wxCURSOR_WAIT); | |
405 | wxCROSS_CURSOR = new wxCursor (wxCURSOR_CROSS); | |
406 | } | |
407 | ||
408 | void wxDeleteStockObjects () | |
409 | { | |
410 | wxDELETE(wxNORMAL_FONT); | |
411 | wxDELETE(wxSMALL_FONT); | |
412 | wxDELETE(wxITALIC_FONT); | |
413 | wxDELETE(wxSWISS_FONT); | |
414 | ||
415 | wxDELETE(wxRED_PEN); | |
416 | wxDELETE(wxCYAN_PEN); | |
417 | wxDELETE(wxGREEN_PEN); | |
418 | wxDELETE(wxBLACK_PEN); | |
419 | wxDELETE(wxWHITE_PEN); | |
420 | wxDELETE(wxTRANSPARENT_PEN); | |
421 | wxDELETE(wxBLACK_DASHED_PEN); | |
422 | wxDELETE(wxGREY_PEN); | |
423 | wxDELETE(wxMEDIUM_GREY_PEN); | |
424 | wxDELETE(wxLIGHT_GREY_PEN); | |
425 | ||
426 | wxDELETE(wxBLUE_BRUSH); | |
427 | wxDELETE(wxGREEN_BRUSH); | |
428 | wxDELETE(wxWHITE_BRUSH); | |
429 | wxDELETE(wxBLACK_BRUSH); | |
430 | wxDELETE(wxTRANSPARENT_BRUSH); | |
431 | wxDELETE(wxCYAN_BRUSH); | |
432 | wxDELETE(wxRED_BRUSH); | |
433 | wxDELETE(wxGREY_BRUSH); | |
434 | wxDELETE(wxMEDIUM_GREY_BRUSH); | |
435 | wxDELETE(wxLIGHT_GREY_BRUSH); | |
436 | ||
437 | wxDELETE(wxBLACK); | |
438 | wxDELETE(wxWHITE); | |
439 | wxDELETE(wxRED); | |
440 | wxDELETE(wxBLUE); | |
441 | wxDELETE(wxGREEN); | |
442 | wxDELETE(wxCYAN); | |
443 | wxDELETE(wxLIGHT_GREY); | |
444 | ||
445 | wxDELETE(wxSTANDARD_CURSOR); | |
446 | wxDELETE(wxHOURGLASS_CURSOR); | |
447 | wxDELETE(wxCROSS_CURSOR); | |
448 | } | |
449 | ||
450 | void wxDeleteStockLists() { | |
451 | wxDELETE(wxTheBrushList); | |
452 | wxDELETE(wxThePenList); | |
453 | wxDELETE(wxTheFontList); | |
454 | wxDELETE(wxTheBitmapList); | |
455 | } | |
456 | ||
457 | wxBitmapList::wxBitmapList () | |
458 | { | |
459 | } | |
460 | ||
461 | wxBitmapList::~wxBitmapList () | |
462 | { | |
463 | wxNode *node = First (); | |
464 | while (node) | |
465 | { | |
466 | wxBitmap *bitmap = (wxBitmap *) node->Data (); | |
467 | wxNode *next = node->Next (); | |
468 | if (bitmap->GetVisible()) | |
469 | delete bitmap; | |
470 | node = next; | |
471 | } | |
472 | } | |
473 | ||
474 | // Pen and Brush lists | |
475 | wxPenList::~wxPenList () | |
476 | { | |
477 | wxNode *node = First (); | |
478 | while (node) | |
479 | { | |
480 | wxPen *pen = (wxPen *) node->Data (); | |
481 | wxNode *next = node->Next (); | |
482 | if (pen->GetVisible()) | |
483 | delete pen; | |
484 | node = next; | |
485 | } | |
486 | } | |
487 | ||
488 | void wxPenList::AddPen (wxPen * pen) | |
489 | { | |
490 | Append (pen); | |
491 | } | |
492 | ||
493 | void wxPenList::RemovePen (wxPen * pen) | |
494 | { | |
495 | DeleteObject (pen); | |
496 | } | |
497 | ||
498 | wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, int style) | |
499 | { | |
500 | for (wxNode * node = First (); node; node = node->Next ()) | |
501 | { | |
502 | wxPen *each_pen = (wxPen *) node->Data (); | |
503 | if (each_pen && | |
504 | each_pen->GetVisible() && | |
505 | each_pen->GetWidth () == width && | |
506 | each_pen->GetStyle () == style && | |
507 | each_pen->GetColour ().Red () == colour.Red () && | |
508 | each_pen->GetColour ().Green () == colour.Green () && | |
509 | each_pen->GetColour ().Blue () == colour.Blue ()) | |
510 | return each_pen; | |
511 | } | |
512 | wxPen *pen = new wxPen (colour, width, style); | |
513 | ||
514 | // Yes, we can return a pointer to this in a later FindOrCreatePen call, | |
515 | // because we created it within FindOrCreatePen. Safeguards against | |
516 | // returning a pointer to an automatic variable and hanging on to it | |
517 | // (dangling pointer). | |
518 | pen->SetVisible(TRUE); | |
519 | ||
520 | return pen; | |
521 | } | |
522 | ||
523 | wxBrushList::~wxBrushList () | |
524 | { | |
525 | wxNode *node = First (); | |
526 | while (node) | |
527 | { | |
528 | wxBrush *brush = (wxBrush *) node->Data (); | |
529 | wxNode *next = node->Next (); | |
530 | if (brush->GetVisible()) | |
531 | delete brush; | |
532 | node = next; | |
533 | } | |
534 | } | |
535 | ||
536 | void wxBrushList::AddBrush (wxBrush * brush) | |
537 | { | |
538 | Append (brush); | |
539 | } | |
540 | ||
541 | wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, int style) | |
542 | { | |
543 | for (wxNode * node = First (); node; node = node->Next ()) | |
544 | { | |
545 | wxBrush *each_brush = (wxBrush *) node->Data (); | |
546 | if (each_brush && | |
547 | each_brush->GetVisible() && | |
548 | each_brush->GetStyle () == style && | |
549 | each_brush->GetColour ().Red () == colour.Red () && | |
550 | each_brush->GetColour ().Green () == colour.Green () && | |
551 | each_brush->GetColour ().Blue () == colour.Blue ()) | |
552 | return each_brush; | |
553 | } | |
554 | ||
555 | // Yes, we can return a pointer to this in a later FindOrCreateBrush call, | |
556 | // because we created it within FindOrCreateBrush. Safeguards against | |
557 | // returning a pointer to an automatic variable and hanging on to it | |
558 | // (dangling pointer). | |
559 | wxBrush *brush = new wxBrush (colour, style); | |
560 | ||
561 | brush->SetVisible(TRUE); | |
562 | ||
563 | return brush; | |
564 | } | |
565 | ||
566 | void wxBrushList::RemoveBrush (wxBrush * brush) | |
567 | { | |
568 | DeleteObject (brush); | |
569 | } | |
570 | ||
571 | wxFontList::~wxFontList () | |
572 | { | |
573 | wxNode *node = First (); | |
574 | while (node) | |
575 | { | |
576 | // Only delete objects that are 'visible', i.e. | |
577 | // that have been created using FindOrCreate..., | |
578 | // where the pointers are expected to be shared | |
579 | // (and therefore not deleted by any one part of an app). | |
580 | wxFont *font = (wxFont *) node->Data (); | |
581 | wxNode *next = node->Next (); | |
582 | if (font->GetVisible()) | |
583 | delete font; | |
584 | node = next; | |
585 | } | |
586 | } | |
587 | ||
588 | void wxFontList::AddFont (wxFont * font) | |
589 | { | |
590 | Append (font); | |
591 | } | |
592 | ||
593 | void wxFontList::RemoveFont (wxFont * font) | |
594 | { | |
595 | DeleteObject (font); | |
596 | } | |
597 | ||
598 | wxFont *wxFontList:: | |
599 | FindOrCreateFont (int PointSize, int FamilyOrFontId, int Style, int Weight, bool underline, const wxString& Face, wxFontEncoding encoding) | |
600 | { | |
601 | for (wxNode * node = First (); node; node = node->Next ()) | |
602 | { | |
603 | wxFont *each_font = (wxFont *) node->Data (); | |
604 | if (each_font && | |
605 | each_font->GetVisible() && | |
606 | each_font->Ok() && | |
607 | each_font->GetPointSize () == PointSize && | |
608 | each_font->GetStyle () == Style && | |
609 | each_font->GetWeight () == Weight && | |
610 | each_font->GetUnderlined () == underline && | |
611 | #if defined(__WXGTK__) | |
612 | (each_font->GetFamily() == FamilyOrFontId || | |
613 | (each_font->GetFamily() == wxSWISS && FamilyOrFontId == wxDEFAULT)) && | |
614 | #else | |
615 | each_font->GetFamily() == FamilyOrFontId && | |
616 | #endif | |
617 | ((each_font->GetFaceName() == wxT("")) || each_font->GetFaceName() == Face) && | |
618 | (encoding == wxFONTENCODING_DEFAULT || each_font->GetEncoding() == encoding)) | |
619 | return each_font; | |
620 | } | |
621 | wxFont *font = new wxFont (PointSize, FamilyOrFontId, Style, Weight, underline, Face, encoding); | |
622 | ||
623 | font->SetVisible(TRUE); | |
624 | ||
625 | return font; | |
626 | } | |
627 | ||
628 | void wxBitmapList::AddBitmap(wxBitmap *bitmap) | |
629 | { | |
630 | Append(bitmap); | |
631 | } | |
632 | ||
633 | void wxBitmapList::RemoveBitmap(wxBitmap *bitmap) | |
634 | { | |
635 | DeleteObject(bitmap); | |
636 | } | |
637 | ||
638 | wxSize wxGetDisplaySize() | |
639 | { | |
640 | int x, y; | |
641 | wxDisplaySize(& x, & y); | |
642 | return wxSize(x, y); | |
643 | } | |
644 | ||
645 | wxResourceCache::~wxResourceCache () | |
646 | { | |
647 | wxNode *node = First (); | |
648 | while (node) { | |
649 | wxGDIObject *item = (wxGDIObject *)node->Data(); | |
650 | if (item->IsKindOf(CLASSINFO(wxBrush))) { | |
651 | wxBrush *brush = (wxBrush *)item; | |
652 | delete brush; | |
653 | } | |
654 | ||
655 | if (item->IsKindOf(CLASSINFO(wxFont))) { | |
656 | wxFont *font = (wxFont *)item; | |
657 | delete font; | |
658 | } | |
659 | ||
660 | if (item->IsKindOf(CLASSINFO(wxBitmap))) { | |
661 | wxBitmap *bitmap = (wxBitmap *)item; | |
662 | delete bitmap; | |
663 | } | |
664 | ||
665 | if (item->IsKindOf(CLASSINFO(wxColour))) { | |
666 | wxColour *colour = (wxColour *)item; | |
667 | delete colour; | |
668 | } | |
669 | ||
670 | wxNode *next = node->Next (); | |
671 | node = next; | |
672 | } | |
673 | } | |
674 |