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