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