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