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