]>
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 | ||
4dff3400 JJ |
16 | #ifdef __VMS |
17 | #define XtDisplay XTDISPLAY | |
18 | #endif | |
19 | ||
c801d85f KB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
2432b92d | 27 | #include "wx/event.h" |
c801d85f KB |
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" | |
46ccb510 | 36 | #include "wx/app.h" |
b0e0d661 | 37 | #include "wx/dc.h" |
b93d0c64 | 38 | #include "wx/utils.h" |
c801d85f | 39 | |
cb38104e | 40 | #include "wx/log.h" |
c801d85f KB |
41 | #include <string.h> |
42 | ||
2049ba38 | 43 | #ifdef __WXMSW__ |
c801d85f KB |
44 | #include <windows.h> |
45 | #endif | |
46 | ||
46ccb510 | 47 | #ifdef __WXMOTIF__ |
338dd992 JJ |
48 | #ifdef __VMS__ |
49 | #pragma message disable nosimpint | |
50 | #endif | |
46ccb510 | 51 | #include <Xm/Xm.h> |
338dd992 JJ |
52 | #ifdef __VMS__ |
53 | #pragma message enable nosimpint | |
54 | #endif | |
46ccb510 JS |
55 | #endif |
56 | ||
45816ddd VZ |
57 | IMPLEMENT_CLASS(wxColourDatabase, wxList) |
58 | IMPLEMENT_DYNAMIC_CLASS(wxFontList, wxList) | |
59 | IMPLEMENT_DYNAMIC_CLASS(wxPenList, wxList) | |
60 | IMPLEMENT_DYNAMIC_CLASS(wxBrushList, wxList) | |
61 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapList, wxList) | |
62 | IMPLEMENT_DYNAMIC_CLASS(wxResourceCache, wxList) | |
a23fd0e1 | 63 | |
45816ddd | 64 | IMPLEMENT_ABSTRACT_CLASS(wxDCBase, wxObject) |
c801d85f | 65 | |
c801d85f KB |
66 | wxRect::wxRect(const wxPoint& topLeft, const wxPoint& bottomRight) |
67 | { | |
68 | x = topLeft.x; | |
69 | y = topLeft.y; | |
736b80cd JS |
70 | width = bottomRight.x - topLeft.x + 1; |
71 | height = bottomRight.y - topLeft.y + 1; | |
8bbe427f | 72 | |
c801d85f KB |
73 | if (width < 0) |
74 | { | |
75 | width = -width; | |
76 | x -= width; | |
77 | } | |
8bbe427f | 78 | |
c801d85f KB |
79 | if (height < 0) |
80 | { | |
81 | height = -height; | |
3e418ffc | 82 | y -= height; |
c801d85f KB |
83 | } |
84 | } | |
85 | ||
86 | wxRect::wxRect(const wxPoint& point, const wxSize& size) | |
87 | { | |
88 | x = point.x; y = point.y; | |
89 | width = size.x; height = size.y; | |
90 | } | |
91 | ||
a23fd0e1 | 92 | bool wxRect::operator==(const wxRect& rect) const |
c801d85f KB |
93 | { |
94 | return ((x == rect.x) && | |
95 | (y == rect.y) && | |
96 | (width == rect.width) && | |
97 | (height == rect.height)); | |
98 | } | |
99 | ||
45816ddd | 100 | wxRect& wxRect::operator += (const wxRect& rect) |
619d0528 | 101 | { |
45816ddd VZ |
102 | *this = (*this + rect); |
103 | return ( *this ) ; | |
dcb44466 JS |
104 | } |
105 | ||
106 | wxRect wxRect::operator + (const wxRect& rect) const | |
619d0528 | 107 | { |
45816ddd VZ |
108 | int x1 = wxMin(this->x, rect.x); |
109 | int y1 = wxMin(this->y, rect.y); | |
110 | int y2 = wxMax(y+height, rect.height+rect.y); | |
111 | int x2 = wxMax(x+width, rect.width+rect.x); | |
112 | return wxRect(x1, y1, x2-x1, y2-y1); | |
dcb44466 JS |
113 | } |
114 | ||
115 | bool wxRect::Inside(int cx, int cy) const | |
116 | { | |
45816ddd VZ |
117 | return ( (cx >= x) && (cy >= y) |
118 | && ((cy - y) < height) | |
119 | && ((cx - x) < width) | |
120 | ); | |
dcb44466 JS |
121 | } |
122 | ||
a23fd0e1 | 123 | wxColourDatabase::wxColourDatabase (int type) : wxList (type) |
c801d85f KB |
124 | { |
125 | } | |
126 | ||
6a6c0a8b | 127 | wxColourDatabase::~wxColourDatabase () |
c801d85f KB |
128 | { |
129 | // Cleanup Colour allocated in Initialize() | |
130 | wxNode *node = First (); | |
131 | while (node) | |
132 | { | |
133 | wxColour *col = (wxColour *) node->Data (); | |
134 | wxNode *next = node->Next (); | |
135 | delete col; | |
136 | node = next; | |
137 | } | |
138 | } | |
139 | ||
140 | // Colour database stuff | |
6a6c0a8b | 141 | void wxColourDatabase::Initialize () |
c801d85f | 142 | { |
f6bcfd97 BP |
143 | static const struct wxColourDesc |
144 | { | |
145 | const wxChar *name; | |
146 | int r,g,b; | |
147 | } | |
148 | wxColourTable[] = | |
149 | { | |
150 | {wxT("AQUAMARINE"),112, 219, 147}, | |
151 | {wxT("BLACK"),0, 0, 0}, | |
152 | {wxT("BLUE"), 0, 0, 255}, | |
153 | {wxT("BLUE VIOLET"), 159, 95, 159}, | |
154 | {wxT("BROWN"), 165, 42, 42}, | |
155 | {wxT("CADET BLUE"), 95, 159, 159}, | |
156 | {wxT("CORAL"), 255, 127, 0}, | |
157 | {wxT("CORNFLOWER BLUE"), 66, 66, 111}, | |
158 | {wxT("CYAN"), 0, 255, 255}, | |
159 | {wxT("DARK GREY"), 47, 47, 47}, // ? | |
160 | ||
161 | {wxT("DARK GREEN"), 47, 79, 47}, | |
162 | {wxT("DARK OLIVE GREEN"), 79, 79, 47}, | |
163 | {wxT("DARK ORCHID"), 153, 50, 204}, | |
164 | {wxT("DARK SLATE BLUE"), 107, 35, 142}, | |
165 | {wxT("DARK SLATE GREY"), 47, 79, 79}, | |
166 | {wxT("DARK TURQUOISE"), 112, 147, 219}, | |
167 | {wxT("DIM GREY"), 84, 84, 84}, | |
168 | {wxT("FIREBRICK"), 142, 35, 35}, | |
169 | {wxT("FOREST GREEN"), 35, 142, 35}, | |
170 | {wxT("GOLD"), 204, 127, 50}, | |
171 | {wxT("GOLDENROD"), 219, 219, 112}, | |
172 | {wxT("GREY"), 128, 128, 128}, | |
173 | {wxT("GREEN"), 0, 255, 0}, | |
174 | {wxT("GREEN YELLOW"), 147, 219, 112}, | |
175 | {wxT("INDIAN RED"), 79, 47, 47}, | |
176 | {wxT("KHAKI"), 159, 159, 95}, | |
177 | {wxT("LIGHT BLUE"), 191, 216, 216}, | |
178 | {wxT("LIGHT GREY"), 192, 192, 192}, | |
179 | {wxT("LIGHT STEEL BLUE"), 143, 143, 188}, | |
180 | {wxT("LIME GREEN"), 50, 204, 50}, | |
181 | {wxT("LIGHT MAGENTA"), 255, 0, 255}, | |
182 | {wxT("MAGENTA"), 255, 0, 255}, | |
183 | {wxT("MAROON"), 142, 35, 107}, | |
184 | {wxT("MEDIUM AQUAMARINE"), 50, 204, 153}, | |
185 | {wxT("MEDIUM GREY"), 100, 100, 100}, | |
186 | {wxT("MEDIUM BLUE"), 50, 50, 204}, | |
187 | {wxT("MEDIUM FOREST GREEN"), 107, 142, 35}, | |
188 | {wxT("MEDIUM GOLDENROD"), 234, 234, 173}, | |
189 | {wxT("MEDIUM ORCHID"), 147, 112, 219}, | |
190 | {wxT("MEDIUM SEA GREEN"), 66, 111, 66}, | |
191 | {wxT("MEDIUM SLATE BLUE"), 127, 0, 255}, | |
192 | {wxT("MEDIUM SPRING GREEN"), 127, 255, 0}, | |
193 | {wxT("MEDIUM TURQUOISE"), 112, 219, 219}, | |
194 | {wxT("MEDIUM VIOLET RED"), 219, 112, 147}, | |
195 | {wxT("MIDNIGHT BLUE"), 47, 47, 79}, | |
196 | {wxT("NAVY"), 35, 35, 142}, | |
197 | {wxT("ORANGE"), 204, 50, 50}, | |
198 | {wxT("ORANGE RED"), 255, 0, 127}, | |
199 | {wxT("ORCHID"), 219, 112, 219}, | |
200 | {wxT("PALE GREEN"), 143, 188, 143}, | |
201 | {wxT("PINK"), 188, 143, 234}, | |
202 | {wxT("PLUM"), 234, 173, 234}, | |
203 | {wxT("PURPLE"), 176, 0, 255}, | |
204 | {wxT("RED"), 255, 0, 0}, | |
205 | {wxT("SALMON"), 111, 66, 66}, | |
206 | {wxT("SEA GREEN"), 35, 142, 107}, | |
207 | {wxT("SIENNA"), 142, 107, 35}, | |
208 | {wxT("SKY BLUE"), 50, 153, 204}, | |
209 | {wxT("SLATE BLUE"), 0, 127, 255}, | |
210 | {wxT("SPRING GREEN"), 0, 255, 127}, | |
211 | {wxT("STEEL BLUE"), 35, 107, 142}, | |
212 | {wxT("TAN"), 219, 147, 112}, | |
213 | {wxT("THISTLE"), 216, 191, 216}, | |
214 | {wxT("TURQUOISE"), 173, 234, 234}, | |
215 | {wxT("VIOLET"), 79, 47, 79}, | |
216 | {wxT("VIOLET RED"), 204, 50, 153}, | |
217 | {wxT("WHEAT"), 216, 216, 191}, | |
218 | {wxT("WHITE"), 255, 255, 255}, | |
219 | {wxT("YELLOW"), 255, 255, 0}, | |
220 | {wxT("YELLOW GREEN"), 153, 204, 50}, | |
221 | {wxT("MEDIUM GOLDENROD"), 234, 234, 173}, | |
222 | {wxT("MEDIUM FOREST GREEN"), 107, 142, 35}, | |
223 | {wxT("LIGHT MAGENTA"), 255, 0, 255}, | |
224 | {wxT("MEDIUM GREY"), 100, 100, 100}, | |
225 | }; | |
226 | ||
227 | for ( size_t n = 0; n < WXSIZEOF(wxColourTable); n++ ) | |
228 | { | |
229 | const wxColourDesc& cc = wxColourTable[n]; | |
230 | Append(cc.name, new wxColour(cc.r,cc.g,cc.b)); | |
231 | } | |
c801d85f KB |
232 | } |
233 | ||
234 | /* | |
235 | * Changed by Ian Brown, July 1994. | |
236 | * | |
237 | * When running under X, the Colour Database starts off empty. The X server | |
238 | * is queried for the colour first time after which it is entered into the | |
239 | * database. This allows our client to use the server colour database which | |
240 | * is hopefully gamma corrected for the display being used. | |
241 | */ | |
242 | ||
243 | wxColour *wxColourDatabase::FindColour(const wxString& colour) | |
244 | { | |
f6bcfd97 BP |
245 | // VZ: make the comparaison case insensitive and also match both grey and |
246 | // gray | |
247 | wxString colName = colour; | |
248 | colName.MakeUpper(); | |
249 | wxString colName2 = colName; | |
250 | if ( !colName2.Replace(_T("GRAY"), _T("GREY")) ) | |
251 | colName2.clear(); | |
252 | ||
253 | wxNode *node = First(); | |
254 | while ( node ) | |
255 | { | |
256 | const wxChar *key = node->GetKeyString(); | |
257 | if ( colName == key || colName2 == key ) | |
258 | { | |
259 | return (wxColour *)node->Data(); | |
260 | } | |
1c4a764c | 261 | |
f6bcfd97 BP |
262 | node = node->Next(); |
263 | } | |
8bbe427f | 264 | |
2049ba38 | 265 | #ifdef __WXMSW__ |
f6bcfd97 | 266 | return NULL; |
c801d85f | 267 | #endif |
913df6f2 | 268 | #ifdef __WXPM__ |
f6bcfd97 | 269 | return NULL; |
913df6f2 | 270 | #endif |
c801d85f | 271 | |
34138703 JS |
272 | // TODO for other implementations. This should really go into |
273 | // platform-specific directories. | |
169935ad | 274 | #ifdef __WXMAC__ |
f6bcfd97 | 275 | return NULL; |
169935ad | 276 | #endif |
34138703 | 277 | #ifdef __WXSTUBS__ |
f6bcfd97 | 278 | return NULL; |
34138703 JS |
279 | #endif |
280 | ||
2049ba38 | 281 | #ifdef __WXGTK__ |
f6bcfd97 | 282 | wxColour *col = new wxColour( colour ); |
8bbe427f | 283 | |
f6bcfd97 | 284 | if (!(col->Ok())) { |
c801d85f | 285 | delete col; |
c67daf87 | 286 | return (wxColour *) NULL; |
c801d85f | 287 | } |
f6bcfd97 BP |
288 | Append( colour, col ); |
289 | return col; | |
c801d85f KB |
290 | #endif |
291 | ||
292 | #ifdef __X__ | |
c801d85f KB |
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; | |
f6bcfd97 | 316 | #endif // __X__ |
c801d85f KB |
317 | } |
318 | ||
319 | wxString wxColourDatabase::FindName (const wxColour& colour) const | |
320 | { | |
a23fd0e1 | 321 | wxString name; |
8bbe427f | 322 | |
a23fd0e1 VZ |
323 | unsigned char red = colour.Red (); |
324 | unsigned char green = colour.Green (); | |
325 | unsigned char blue = colour.Blue (); | |
8bbe427f | 326 | |
a23fd0e1 VZ |
327 | for (wxNode * node = First (); node; node = node->Next ()) |
328 | { | |
329 | wxColour *col = (wxColour *) node->Data (); | |
330 | ||
331 | if (col->Red () == red && col->Green () == green && col->Blue () == blue) | |
8bbe427f | 332 | { |
a23fd0e1 VZ |
333 | const wxChar *found = node->GetKeyString(); |
334 | if ( found ) | |
335 | { | |
336 | name = found; | |
337 | ||
338 | break; | |
339 | } | |
8bbe427f | 340 | } |
a23fd0e1 | 341 | } |
c801d85f | 342 | |
a23fd0e1 | 343 | return name; |
c801d85f KB |
344 | } |
345 | ||
a3622daa | 346 | void wxInitializeStockLists () { |
c801d85f KB |
347 | wxTheBrushList = new wxBrushList; |
348 | wxThePenList = new wxPenList; | |
349 | wxTheFontList = new wxFontList; | |
350 | wxTheBitmapList = new wxBitmapList; | |
a3622daa | 351 | } |
c801d85f | 352 | |
a3622daa VZ |
353 | void wxInitializeStockObjects () |
354 | { | |
2049ba38 | 355 | #ifdef __WXMOTIF__ |
c801d85f KB |
356 | #endif |
357 | #ifdef __X__ | |
46ccb510 JS |
358 | // TODO |
359 | // wxFontPool = new XFontPool; | |
c801d85f KB |
360 | #endif |
361 | ||
696e1ea0 VZ |
362 | // why under MSW fonts shouldn't have the standard system size? |
363 | #ifdef __WXMSW__ | |
364 | static const int sizeFont = 10; | |
365 | #else | |
366 | static const int sizeFont = 12; | |
367 | #endif | |
368 | ||
369 | wxNORMAL_FONT = new wxFont (sizeFont, wxMODERN, wxNORMAL, wxNORMAL); | |
370 | wxSMALL_FONT = new wxFont (sizeFont - 2, wxSWISS, wxNORMAL, wxNORMAL); | |
371 | wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL); | |
372 | wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL); | |
c801d85f KB |
373 | |
374 | wxRED_PEN = new wxPen ("RED", 1, wxSOLID); | |
375 | wxCYAN_PEN = new wxPen ("CYAN", 1, wxSOLID); | |
376 | wxGREEN_PEN = new wxPen ("GREEN", 1, wxSOLID); | |
377 | wxBLACK_PEN = new wxPen ("BLACK", 1, wxSOLID); | |
378 | wxWHITE_PEN = new wxPen ("WHITE", 1, wxSOLID); | |
379 | wxTRANSPARENT_PEN = new wxPen ("BLACK", 1, wxTRANSPARENT); | |
380 | wxBLACK_DASHED_PEN = new wxPen ("BLACK", 1, wxSHORT_DASH); | |
381 | wxGREY_PEN = new wxPen ("GREY", 1, wxSOLID); | |
382 | wxMEDIUM_GREY_PEN = new wxPen ("MEDIUM GREY", 1, wxSOLID); | |
383 | wxLIGHT_GREY_PEN = new wxPen ("LIGHT GREY", 1, wxSOLID); | |
384 | ||
385 | wxBLUE_BRUSH = new wxBrush ("BLUE", wxSOLID); | |
386 | wxGREEN_BRUSH = new wxBrush ("GREEN", wxSOLID); | |
387 | wxWHITE_BRUSH = new wxBrush ("WHITE", wxSOLID); | |
388 | wxBLACK_BRUSH = new wxBrush ("BLACK", wxSOLID); | |
389 | wxTRANSPARENT_BRUSH = new wxBrush ("BLACK", wxTRANSPARENT); | |
390 | wxCYAN_BRUSH = new wxBrush ("CYAN", wxSOLID); | |
391 | wxRED_BRUSH = new wxBrush ("RED", wxSOLID); | |
392 | wxGREY_BRUSH = new wxBrush ("GREY", wxSOLID); | |
393 | wxMEDIUM_GREY_BRUSH = new wxBrush ("MEDIUM GREY", wxSOLID); | |
394 | wxLIGHT_GREY_BRUSH = new wxBrush ("LIGHT GREY", wxSOLID); | |
395 | ||
396 | wxBLACK = new wxColour ("BLACK"); | |
397 | wxWHITE = new wxColour ("WHITE"); | |
398 | wxRED = new wxColour ("RED"); | |
399 | wxBLUE = new wxColour ("BLUE"); | |
400 | wxGREEN = new wxColour ("GREEN"); | |
401 | wxCYAN = new wxColour ("CYAN"); | |
402 | wxLIGHT_GREY = new wxColour ("LIGHT GREY"); | |
403 | ||
404 | wxSTANDARD_CURSOR = new wxCursor (wxCURSOR_ARROW); | |
405 | wxHOURGLASS_CURSOR = new wxCursor (wxCURSOR_WAIT); | |
406 | wxCROSS_CURSOR = new wxCursor (wxCURSOR_CROSS); | |
407 | } | |
408 | ||
8bbe427f | 409 | void wxDeleteStockObjects () |
c801d85f | 410 | { |
a3622daa VZ |
411 | wxDELETE(wxNORMAL_FONT); |
412 | wxDELETE(wxSMALL_FONT); | |
413 | wxDELETE(wxITALIC_FONT); | |
414 | wxDELETE(wxSWISS_FONT); | |
415 | ||
416 | wxDELETE(wxRED_PEN); | |
417 | wxDELETE(wxCYAN_PEN); | |
418 | wxDELETE(wxGREEN_PEN); | |
419 | wxDELETE(wxBLACK_PEN); | |
420 | wxDELETE(wxWHITE_PEN); | |
421 | wxDELETE(wxTRANSPARENT_PEN); | |
422 | wxDELETE(wxBLACK_DASHED_PEN); | |
423 | wxDELETE(wxGREY_PEN); | |
424 | wxDELETE(wxMEDIUM_GREY_PEN); | |
425 | wxDELETE(wxLIGHT_GREY_PEN); | |
426 | ||
427 | wxDELETE(wxBLUE_BRUSH); | |
428 | wxDELETE(wxGREEN_BRUSH); | |
429 | wxDELETE(wxWHITE_BRUSH); | |
430 | wxDELETE(wxBLACK_BRUSH); | |
431 | wxDELETE(wxTRANSPARENT_BRUSH); | |
432 | wxDELETE(wxCYAN_BRUSH); | |
433 | wxDELETE(wxRED_BRUSH); | |
434 | wxDELETE(wxGREY_BRUSH); | |
435 | wxDELETE(wxMEDIUM_GREY_BRUSH); | |
436 | wxDELETE(wxLIGHT_GREY_BRUSH); | |
437 | ||
438 | wxDELETE(wxBLACK); | |
439 | wxDELETE(wxWHITE); | |
440 | wxDELETE(wxRED); | |
441 | wxDELETE(wxBLUE); | |
442 | wxDELETE(wxGREEN); | |
443 | wxDELETE(wxCYAN); | |
444 | wxDELETE(wxLIGHT_GREY); | |
445 | ||
446 | wxDELETE(wxSTANDARD_CURSOR); | |
447 | wxDELETE(wxHOURGLASS_CURSOR); | |
448 | wxDELETE(wxCROSS_CURSOR); | |
449 | } | |
450 | ||
451 | void wxDeleteStockLists() { | |
452 | wxDELETE(wxTheBrushList); | |
453 | wxDELETE(wxThePenList); | |
454 | wxDELETE(wxTheFontList); | |
455 | wxDELETE(wxTheBitmapList); | |
c801d85f KB |
456 | } |
457 | ||
6a6c0a8b | 458 | wxBitmapList::wxBitmapList () |
c801d85f KB |
459 | { |
460 | } | |
461 | ||
6a6c0a8b | 462 | wxBitmapList::~wxBitmapList () |
c801d85f KB |
463 | { |
464 | wxNode *node = First (); | |
465 | while (node) | |
466 | { | |
467 | wxBitmap *bitmap = (wxBitmap *) node->Data (); | |
468 | wxNode *next = node->Next (); | |
4c444f19 JS |
469 | if (bitmap->GetVisible()) |
470 | delete bitmap; | |
c801d85f KB |
471 | node = next; |
472 | } | |
473 | } | |
474 | ||
475 | // Pen and Brush lists | |
6a6c0a8b | 476 | wxPenList::~wxPenList () |
c801d85f KB |
477 | { |
478 | wxNode *node = First (); | |
479 | while (node) | |
480 | { | |
481 | wxPen *pen = (wxPen *) node->Data (); | |
482 | wxNode *next = node->Next (); | |
4c444f19 JS |
483 | if (pen->GetVisible()) |
484 | delete pen; | |
c801d85f KB |
485 | node = next; |
486 | } | |
487 | } | |
488 | ||
489 | void wxPenList::AddPen (wxPen * pen) | |
490 | { | |
491 | Append (pen); | |
492 | } | |
493 | ||
494 | void wxPenList::RemovePen (wxPen * pen) | |
495 | { | |
496 | DeleteObject (pen); | |
497 | } | |
498 | ||
debe6624 | 499 | wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, int style) |
c801d85f KB |
500 | { |
501 | for (wxNode * node = First (); node; node = node->Next ()) | |
502 | { | |
503 | wxPen *each_pen = (wxPen *) node->Data (); | |
6d167489 VZ |
504 | if (each_pen && |
505 | each_pen->GetVisible() && | |
8bbe427f VZ |
506 | each_pen->GetWidth () == width && |
507 | each_pen->GetStyle () == style && | |
508 | each_pen->GetColour ().Red () == colour.Red () && | |
509 | each_pen->GetColour ().Green () == colour.Green () && | |
510 | each_pen->GetColour ().Blue () == colour.Blue ()) | |
511 | return each_pen; | |
c801d85f KB |
512 | } |
513 | wxPen *pen = new wxPen (colour, width, style); | |
514 | ||
515 | // Yes, we can return a pointer to this in a later FindOrCreatePen call, | |
516 | // because we created it within FindOrCreatePen. Safeguards against | |
517 | // returning a pointer to an automatic variable and hanging on to it | |
518 | // (dangling pointer). | |
519 | pen->SetVisible(TRUE); | |
6d167489 | 520 | |
c801d85f KB |
521 | return pen; |
522 | } | |
523 | ||
6a6c0a8b | 524 | wxBrushList::~wxBrushList () |
c801d85f KB |
525 | { |
526 | wxNode *node = First (); | |
527 | while (node) | |
528 | { | |
529 | wxBrush *brush = (wxBrush *) node->Data (); | |
530 | wxNode *next = node->Next (); | |
4c444f19 JS |
531 | if (brush->GetVisible()) |
532 | delete brush; | |
c801d85f KB |
533 | node = next; |
534 | } | |
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 | ||
f6bcfd97 BP |
599 | wxFont *wxFontList::FindOrCreateFont(int pointSize, |
600 | int family, | |
601 | int style, | |
602 | int weight, | |
603 | bool underline, | |
604 | const wxString& facename, | |
605 | wxFontEncoding encoding) | |
c801d85f | 606 | { |
f6bcfd97 BP |
607 | wxFont *font = (wxFont *)NULL; |
608 | wxNode *node; | |
609 | for ( node = First(); node; node = node->Next() ) | |
c801d85f | 610 | { |
f6bcfd97 BP |
611 | font = (wxFont *)node->Data(); |
612 | if ( font->GetVisible() && | |
613 | font->Ok() && | |
614 | font->GetPointSize () == pointSize && | |
615 | font->GetStyle () == style && | |
616 | font->GetWeight () == weight && | |
617 | font->GetUnderlined () == underline ) | |
618 | { | |
619 | int fontFamily = font->GetFamily(); | |
620 | ||
619d0528 | 621 | #if defined(__WXGTK__) |
f6bcfd97 BP |
622 | // under GTK the default family is wxSWISS, so looking for a font |
623 | // with wxDEFAULT family should return a wxSWISS one instead of | |
624 | // creating a new one | |
625 | bool same = (fontFamily == family) || | |
626 | (fontFamily == wxSWISS && family == wxDEFAULT); | |
627 | #else // !GTK | |
628 | // VZ: but why elsewhere do we require an exact match? mystery... | |
629 | bool same = fontFamily == family; | |
630 | #endif // GTK/!GTK | |
631 | ||
632 | // empty facename matches anything at all: this is bad because | |
633 | // depending on which fonts are already created, we might get back | |
634 | // a different font if we create it with empty facename, but it is | |
635 | // still better than never matching anything in the cache at all | |
636 | // in this case | |
637 | if ( same && !!facename ) | |
638 | { | |
639 | const wxString& fontFace = font->GetFaceName(); | |
640 | ||
641 | // empty facename matches everything | |
642 | same = !fontFace || fontFace == facename; | |
643 | } | |
644 | ||
645 | if ( same && (encoding != wxFONTENCODING_DEFAULT) ) | |
646 | { | |
647 | // have to match the encoding too | |
648 | same = font->GetEncoding() == encoding; | |
649 | } | |
650 | ||
651 | if ( same ) | |
652 | { | |
653 | return font; | |
654 | } | |
655 | } | |
c801d85f | 656 | } |
6d167489 | 657 | |
f6bcfd97 BP |
658 | if ( !node ) |
659 | { | |
660 | // font not found, create the new one | |
661 | font = new wxFont(pointSize, family, style, weight, | |
662 | underline, facename, encoding); | |
663 | ||
664 | // and mark it as being cacheable | |
665 | font->SetVisible(TRUE); | |
666 | } | |
6d167489 | 667 | |
f6bcfd97 | 668 | return font; |
c801d85f KB |
669 | } |
670 | ||
671 | void wxBitmapList::AddBitmap(wxBitmap *bitmap) | |
8bbe427f VZ |
672 | { |
673 | Append(bitmap); | |
674 | } | |
675 | ||
c801d85f | 676 | void wxBitmapList::RemoveBitmap(wxBitmap *bitmap) |
8bbe427f VZ |
677 | { |
678 | DeleteObject(bitmap); | |
679 | } | |
c801d85f | 680 | |
6a6c0a8b JS |
681 | wxSize wxGetDisplaySize() |
682 | { | |
683 | int x, y; | |
684 | wxDisplaySize(& x, & y); | |
685 | return wxSize(x, y); | |
686 | } | |
687 | ||
8bbe427f VZ |
688 | wxResourceCache::~wxResourceCache () |
689 | { | |
f6bcfd97 BP |
690 | wxNode *node = First (); |
691 | while (node) { | |
692 | wxObject *item = (wxObject *)node->Data(); | |
693 | delete item; | |
a3622daa | 694 | |
f6bcfd97 | 695 | node = node->Next (); |
a3622daa | 696 | } |
a3622daa VZ |
697 | } |
698 |