]>
Commit | Line | Data |
---|---|---|
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
13 | #pragma implementation "gdicmn.h" | |
14 | #endif | |
15 | ||
16 | #ifdef __VMS | |
17 | #define XtDisplay XTDISPLAY | |
18 | #endif | |
19 | ||
20 | // For compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #include "wx/event.h" | |
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" | |
36 | #include "wx/app.h" | |
37 | #include "wx/dc.h" | |
38 | #include "wx/utils.h" | |
39 | #include "wx/settings.h" | |
40 | #include "wx/hashmap.h" | |
41 | ||
42 | #include "wx/log.h" | |
43 | #include <string.h> | |
44 | ||
45 | #if defined(__WXMSW__) && !defined(__PALMOS__) | |
46 | #include "wx/msw/wrapwin.h" | |
47 | #endif | |
48 | ||
49 | #ifdef __WXMOTIF__ | |
50 | #ifdef __VMS__ | |
51 | #pragma message disable nosimpint | |
52 | #endif | |
53 | #include <Xm/Xm.h> | |
54 | #ifdef __VMS__ | |
55 | #pragma message enable nosimpint | |
56 | #endif | |
57 | #endif | |
58 | ||
59 | #ifdef __WXX11__ | |
60 | #include "X11/Xlib.h" | |
61 | #endif | |
62 | ||
63 | #ifdef __WXMAC__ | |
64 | #include "wx/mac/private.h" | |
65 | #include "wx/mac/uma.h" | |
66 | #endif | |
67 | ||
68 | #if wxUSE_EXTENDED_RTTI | |
69 | ||
70 | // wxPoint | |
71 | ||
72 | template<> void wxStringReadValue(const wxString &s , wxPoint &data ) | |
73 | { | |
74 | wxSscanf(s, wxT("%d,%d"), &data.x , &data.y ) ; | |
75 | } | |
76 | ||
77 | template<> void wxStringWriteValue(wxString &s , const wxPoint &data ) | |
78 | { | |
79 | s = wxString::Format(wxT("%d,%d"), data.x , data.y ) ; | |
80 | } | |
81 | ||
82 | wxCUSTOM_TYPE_INFO(wxPoint, wxToStringConverter<wxPoint> , wxFromStringConverter<wxPoint>) | |
83 | ||
84 | template<> void wxStringReadValue(const wxString &s , wxSize &data ) | |
85 | { | |
86 | wxSscanf(s, wxT("%d,%d"), &data.x , &data.y ) ; | |
87 | } | |
88 | ||
89 | template<> void wxStringWriteValue(wxString &s , const wxSize &data ) | |
90 | { | |
91 | s = wxString::Format(wxT("%d,%d"), data.x , data.y ) ; | |
92 | } | |
93 | ||
94 | wxCUSTOM_TYPE_INFO(wxSize, wxToStringConverter<wxSize> , wxFromStringConverter<wxSize>) | |
95 | ||
96 | #endif | |
97 | ||
98 | IMPLEMENT_ABSTRACT_CLASS(wxDCBase, wxObject) | |
99 | ||
100 | wxRect::wxRect(const wxPoint& point1, const wxPoint& point2) | |
101 | { | |
102 | x = point1.x; | |
103 | y = point1.y; | |
104 | width = point2.x - point1.x; | |
105 | height = point2.y - point1.y; | |
106 | ||
107 | if (width < 0) | |
108 | { | |
109 | width = -width; | |
110 | x = point2.x; | |
111 | } | |
112 | width++; | |
113 | ||
114 | if (height < 0) | |
115 | { | |
116 | height = -height; | |
117 | y = point2.y; | |
118 | } | |
119 | height++; | |
120 | } | |
121 | ||
122 | bool wxRect::operator==(const wxRect& rect) const | |
123 | { | |
124 | return ((x == rect.x) && | |
125 | (y == rect.y) && | |
126 | (width == rect.width) && | |
127 | (height == rect.height)); | |
128 | } | |
129 | ||
130 | wxRect wxRect::operator+(const wxRect& rect) const | |
131 | { | |
132 | int x1 = wxMin(this->x, rect.x); | |
133 | int y1 = wxMin(this->y, rect.y); | |
134 | int y2 = wxMax(y+height, rect.height+rect.y); | |
135 | int x2 = wxMax(x+width, rect.width+rect.x); | |
136 | return wxRect(x1, y1, x2-x1, y2-y1); | |
137 | } | |
138 | ||
139 | wxRect& wxRect::Union(const wxRect& rect) | |
140 | { | |
141 | // ignore empty rectangles | |
142 | if ( rect.width && rect.height ) | |
143 | { | |
144 | int x1 = wxMin(x, rect.x); | |
145 | int y1 = wxMin(y, rect.y); | |
146 | int y2 = wxMax(y + height, rect.height + rect.y); | |
147 | int x2 = wxMax(x + width, rect.width + rect.x); | |
148 | ||
149 | x = x1; | |
150 | y = y1; | |
151 | width = x2 - x1; | |
152 | height = y2 - y1; | |
153 | } | |
154 | ||
155 | return *this; | |
156 | } | |
157 | ||
158 | wxRect& wxRect::Inflate(wxCoord dx, wxCoord dy) | |
159 | { | |
160 | x -= dx; | |
161 | y -= dy; | |
162 | width += 2*dx; | |
163 | height += 2*dy; | |
164 | ||
165 | // check that we didn't make the rectangle invalid by accident (you almost | |
166 | // never want to have negative coords and never want negative size) | |
167 | if ( x < 0 ) | |
168 | x = 0; | |
169 | if ( y < 0 ) | |
170 | y = 0; | |
171 | ||
172 | // what else can we do? | |
173 | if ( width < 0 ) | |
174 | width = 0; | |
175 | if ( height < 0 ) | |
176 | height = 0; | |
177 | ||
178 | return *this; | |
179 | } | |
180 | ||
181 | bool wxRect::Inside(int cx, int cy) const | |
182 | { | |
183 | return ( (cx >= x) && (cy >= y) | |
184 | && ((cy - y) < height) | |
185 | && ((cx - x) < width) | |
186 | ); | |
187 | } | |
188 | ||
189 | wxRect& wxRect::Intersect(const wxRect& rect) | |
190 | { | |
191 | int x2 = GetRight(), | |
192 | y2 = GetBottom(); | |
193 | ||
194 | if ( x < rect.x ) | |
195 | x = rect.x; | |
196 | if ( y < rect.y ) | |
197 | y = rect.y; | |
198 | if ( x2 > rect.GetRight() ) | |
199 | x2 = rect.GetRight(); | |
200 | if ( y2 > rect.GetBottom() ) | |
201 | y2 = rect.GetBottom(); | |
202 | ||
203 | width = x2 - x + 1; | |
204 | height = y2 - y + 1; | |
205 | ||
206 | if ( width <= 0 || height <= 0 ) | |
207 | { | |
208 | width = | |
209 | height = 0; | |
210 | } | |
211 | ||
212 | return *this; | |
213 | } | |
214 | ||
215 | bool wxRect::Intersects(const wxRect& rect) const | |
216 | { | |
217 | wxRect r = Intersect(rect); | |
218 | ||
219 | // if there is no intersection, both width and height are 0 | |
220 | return r.width != 0; | |
221 | } | |
222 | ||
223 | // ============================================================================ | |
224 | // wxColourDatabase | |
225 | // ============================================================================ | |
226 | ||
227 | // ---------------------------------------------------------------------------- | |
228 | // wxColourDatabase ctor/dtor | |
229 | // ---------------------------------------------------------------------------- | |
230 | ||
231 | wxColourDatabase::wxColourDatabase () | |
232 | { | |
233 | // will be created on demand in Initialize() | |
234 | m_map = NULL; | |
235 | } | |
236 | ||
237 | wxColourDatabase::~wxColourDatabase () | |
238 | { | |
239 | if ( m_map ) | |
240 | { | |
241 | WX_CLEAR_HASH_MAP(wxStringToColourHashMap, *m_map); | |
242 | ||
243 | delete m_map; | |
244 | } | |
245 | ||
246 | #ifdef __WXPM__ | |
247 | delete [] m_palTable; | |
248 | #endif | |
249 | } | |
250 | ||
251 | // Colour database stuff | |
252 | void wxColourDatabase::Initialize() | |
253 | { | |
254 | if ( m_map ) | |
255 | { | |
256 | // already initialized | |
257 | return; | |
258 | } | |
259 | ||
260 | m_map = new wxStringToColourHashMap; | |
261 | ||
262 | static const struct wxColourDesc | |
263 | { | |
264 | const wxChar *name; | |
265 | unsigned char r,g,b; | |
266 | } | |
267 | wxColourTable[] = | |
268 | { | |
269 | {wxT("AQUAMARINE"),112, 219, 147}, | |
270 | {wxT("BLACK"),0, 0, 0}, | |
271 | {wxT("BLUE"), 0, 0, 255}, | |
272 | {wxT("BLUE VIOLET"), 159, 95, 159}, | |
273 | {wxT("BROWN"), 165, 42, 42}, | |
274 | {wxT("CADET BLUE"), 95, 159, 159}, | |
275 | {wxT("CORAL"), 255, 127, 0}, | |
276 | {wxT("CORNFLOWER BLUE"), 66, 66, 111}, | |
277 | {wxT("CYAN"), 0, 255, 255}, | |
278 | {wxT("DARK GREY"), 47, 47, 47}, // ? | |
279 | ||
280 | {wxT("DARK GREEN"), 47, 79, 47}, | |
281 | {wxT("DARK OLIVE GREEN"), 79, 79, 47}, | |
282 | {wxT("DARK ORCHID"), 153, 50, 204}, | |
283 | {wxT("DARK SLATE BLUE"), 107, 35, 142}, | |
284 | {wxT("DARK SLATE GREY"), 47, 79, 79}, | |
285 | {wxT("DARK TURQUOISE"), 112, 147, 219}, | |
286 | {wxT("DIM GREY"), 84, 84, 84}, | |
287 | {wxT("FIREBRICK"), 142, 35, 35}, | |
288 | {wxT("FOREST GREEN"), 35, 142, 35}, | |
289 | {wxT("GOLD"), 204, 127, 50}, | |
290 | {wxT("GOLDENROD"), 219, 219, 112}, | |
291 | {wxT("GREY"), 128, 128, 128}, | |
292 | {wxT("GREEN"), 0, 255, 0}, | |
293 | {wxT("GREEN YELLOW"), 147, 219, 112}, | |
294 | {wxT("INDIAN RED"), 79, 47, 47}, | |
295 | {wxT("KHAKI"), 159, 159, 95}, | |
296 | {wxT("LIGHT BLUE"), 191, 216, 216}, | |
297 | {wxT("LIGHT GREY"), 192, 192, 192}, | |
298 | {wxT("LIGHT STEEL BLUE"), 143, 143, 188}, | |
299 | {wxT("LIME GREEN"), 50, 204, 50}, | |
300 | {wxT("LIGHT MAGENTA"), 255, 0, 255}, | |
301 | {wxT("MAGENTA"), 255, 0, 255}, | |
302 | {wxT("MAROON"), 142, 35, 107}, | |
303 | {wxT("MEDIUM AQUAMARINE"), 50, 204, 153}, | |
304 | {wxT("MEDIUM GREY"), 100, 100, 100}, | |
305 | {wxT("MEDIUM BLUE"), 50, 50, 204}, | |
306 | {wxT("MEDIUM FOREST GREEN"), 107, 142, 35}, | |
307 | {wxT("MEDIUM GOLDENROD"), 234, 234, 173}, | |
308 | {wxT("MEDIUM ORCHID"), 147, 112, 219}, | |
309 | {wxT("MEDIUM SEA GREEN"), 66, 111, 66}, | |
310 | {wxT("MEDIUM SLATE BLUE"), 127, 0, 255}, | |
311 | {wxT("MEDIUM SPRING GREEN"), 127, 255, 0}, | |
312 | {wxT("MEDIUM TURQUOISE"), 112, 219, 219}, | |
313 | {wxT("MEDIUM VIOLET RED"), 219, 112, 147}, | |
314 | {wxT("MIDNIGHT BLUE"), 47, 47, 79}, | |
315 | {wxT("NAVY"), 35, 35, 142}, | |
316 | {wxT("ORANGE"), 204, 50, 50}, | |
317 | {wxT("ORANGE RED"), 255, 0, 127}, | |
318 | {wxT("ORCHID"), 219, 112, 219}, | |
319 | {wxT("PALE GREEN"), 143, 188, 143}, | |
320 | {wxT("PINK"), 188, 143, 234}, | |
321 | {wxT("PLUM"), 234, 173, 234}, | |
322 | {wxT("PURPLE"), 176, 0, 255}, | |
323 | {wxT("RED"), 255, 0, 0}, | |
324 | {wxT("SALMON"), 111, 66, 66}, | |
325 | {wxT("SEA GREEN"), 35, 142, 107}, | |
326 | {wxT("SIENNA"), 142, 107, 35}, | |
327 | {wxT("SKY BLUE"), 50, 153, 204}, | |
328 | {wxT("SLATE BLUE"), 0, 127, 255}, | |
329 | {wxT("SPRING GREEN"), 0, 255, 127}, | |
330 | {wxT("STEEL BLUE"), 35, 107, 142}, | |
331 | {wxT("TAN"), 219, 147, 112}, | |
332 | {wxT("THISTLE"), 216, 191, 216}, | |
333 | {wxT("TURQUOISE"), 173, 234, 234}, | |
334 | {wxT("VIOLET"), 79, 47, 79}, | |
335 | {wxT("VIOLET RED"), 204, 50, 153}, | |
336 | {wxT("WHEAT"), 216, 216, 191}, | |
337 | {wxT("WHITE"), 255, 255, 255}, | |
338 | {wxT("YELLOW"), 255, 255, 0}, | |
339 | {wxT("YELLOW GREEN"), 153, 204, 50} | |
340 | }; | |
341 | ||
342 | size_t n; | |
343 | ||
344 | for ( n = 0; n < WXSIZEOF(wxColourTable); n++ ) | |
345 | { | |
346 | const wxColourDesc& cc = wxColourTable[n]; | |
347 | (*m_map)[cc.name] = new wxColour(cc.r, cc.g, cc.b); | |
348 | } | |
349 | ||
350 | #ifdef __WXPM__ | |
351 | m_palTable = new long[n]; | |
352 | for ( n = 0; n < WXSIZEOF(wxColourTable); n++ ) | |
353 | { | |
354 | const wxColourDesc& cc = wxColourTable[n]; | |
355 | m_palTable[n] = OS2RGB(cc.r,cc.g,cc.b); | |
356 | } | |
357 | m_nSize = n; | |
358 | #endif | |
359 | } | |
360 | ||
361 | // ---------------------------------------------------------------------------- | |
362 | // wxColourDatabase operations | |
363 | // ---------------------------------------------------------------------------- | |
364 | ||
365 | void wxColourDatabase::AddColour(const wxString& name, const wxColour& colour) | |
366 | { | |
367 | Initialize(); | |
368 | ||
369 | // canonicalize the colour names before using them as keys: they should be | |
370 | // in upper case | |
371 | wxString colName = name; | |
372 | colName.MakeUpper(); | |
373 | ||
374 | // ... and we also allow both grey/gray | |
375 | wxString colNameAlt = colName; | |
376 | if ( !colNameAlt.Replace(_T("GRAY"), _T("GREY")) ) | |
377 | { | |
378 | // but in this case it is not necessary so avoid extra search below | |
379 | colNameAlt.clear(); | |
380 | } | |
381 | ||
382 | wxStringToColourHashMap::iterator it = m_map->find(colName); | |
383 | if ( it == m_map->end() && !colNameAlt.empty() ) | |
384 | it = m_map->find(colNameAlt); | |
385 | if ( it != m_map->end() ) | |
386 | { | |
387 | *(it->second) = colour; | |
388 | } | |
389 | else // new colour | |
390 | { | |
391 | (*m_map)[colName] = new wxColour(colour); | |
392 | } | |
393 | } | |
394 | ||
395 | wxColour wxColourDatabase::Find(const wxString& colour) const | |
396 | { | |
397 | wxColourDatabase * const self = wxConstCast(this, wxColourDatabase); | |
398 | self->Initialize(); | |
399 | ||
400 | // first look among the existing colours | |
401 | ||
402 | // make the comparaison case insensitive and also match both grey and gray | |
403 | wxString colName = colour; | |
404 | colName.MakeUpper(); | |
405 | wxString colNameAlt = colName; | |
406 | if ( !colNameAlt.Replace(_T("GRAY"), _T("GREY")) ) | |
407 | colNameAlt.clear(); | |
408 | ||
409 | wxStringToColourHashMap::iterator it = m_map->find(colName); | |
410 | if ( it == m_map->end() && !colNameAlt.empty() ) | |
411 | it = m_map->find(colNameAlt); | |
412 | if ( it != m_map->end() ) | |
413 | return *(it->second); | |
414 | ||
415 | // if we didn't find it, query the system, maybe it knows about it | |
416 | #if defined(__WXGTK__) || defined(__X__) | |
417 | wxColour col = wxColour::CreateByName(colour); | |
418 | ||
419 | if ( col.Ok() ) | |
420 | { | |
421 | // cache it | |
422 | self->AddColour(colour, col); | |
423 | } | |
424 | ||
425 | return col; | |
426 | #elif defined(__X__) | |
427 | // TODO: move this to wxColour::CreateByName() | |
428 | XColor xcolour; | |
429 | ||
430 | #ifdef __WXMOTIF__ | |
431 | Display *display = XtDisplay((Widget) wxTheApp->GetTopLevelWidget()) ; | |
432 | #endif | |
433 | #ifdef __WXX11__ | |
434 | Display* display = (Display*) wxGetDisplay(); | |
435 | #endif | |
436 | /* MATTHEW: [4] Use wxGetMainColormap */ | |
437 | if (!XParseColor(display, (Colormap) wxTheApp->GetMainColormap((WXDisplay*) display), colour.ToAscii() ,&xcolour)) | |
438 | return NULL; | |
439 | ||
440 | #if wxUSE_NANOX | |
441 | unsigned char r = (unsigned char)(xcolour.red); | |
442 | unsigned char g = (unsigned char)(xcolour.green); | |
443 | unsigned char b = (unsigned char)(xcolour.blue); | |
444 | #else | |
445 | unsigned char r = (unsigned char)(xcolour.red >> 8); | |
446 | unsigned char g = (unsigned char)(xcolour.green >> 8); | |
447 | unsigned char b = (unsigned char)(xcolour.blue >> 8); | |
448 | #endif | |
449 | ||
450 | wxColour col(r, g, b); | |
451 | AddColour(colour, col); | |
452 | ||
453 | return col; | |
454 | #else // other platform | |
455 | return wxNullColour; | |
456 | #endif // platforms | |
457 | } | |
458 | ||
459 | wxString wxColourDatabase::FindName(const wxColour& colour) const | |
460 | { | |
461 | wxColourDatabase * const self = wxConstCast(this, wxColourDatabase); | |
462 | self->Initialize(); | |
463 | ||
464 | typedef wxStringToColourHashMap::iterator iterator; | |
465 | ||
466 | for ( iterator it = m_map->begin(), en = m_map->end(); it != en; ++it ) | |
467 | { | |
468 | if ( *(it->second) == colour ) | |
469 | return it->first; | |
470 | } | |
471 | ||
472 | return wxEmptyString; | |
473 | } | |
474 | ||
475 | // ---------------------------------------------------------------------------- | |
476 | // deprecated wxColourDatabase methods | |
477 | // ---------------------------------------------------------------------------- | |
478 | ||
479 | wxColour *wxColourDatabase::FindColour(const wxString& name) | |
480 | { | |
481 | // This function is deprecated, use Find() instead. | |
482 | // Formerly this function sometimes would return a deletable pointer and | |
483 | // sometimes a non-deletable one (when returning a colour from the database). | |
484 | // Trying to delete the latter anyway results in problems, so probably | |
485 | // nobody ever freed the pointers. Currently it always returns a new | |
486 | // instance, which means there will be memory leaks. | |
487 | wxLogDebug(wxT("wxColourDataBase::FindColour():") | |
488 | wxT(" Please use wxColourDataBase::Find() instead")); | |
489 | ||
490 | // using a static variable here is not the most elegant solution but unless | |
491 | // we want to make wxStringToColourHashMap public (i.e. move it to the | |
492 | // header) so that we could have a member function returning | |
493 | // wxStringToColourHashMap::iterator, there is really no good way to do it | |
494 | // otherwise | |
495 | // | |
496 | // and knowing that this function is going to disappear in the next release | |
497 | // anyhow I don't want to waste time on this | |
498 | ||
499 | static wxColour s_col; | |
500 | ||
501 | s_col = Find(name); | |
502 | if ( !s_col.Ok() ) | |
503 | return NULL; | |
504 | ||
505 | return new wxColour(s_col); | |
506 | } | |
507 | ||
508 | // ============================================================================ | |
509 | // stock objects | |
510 | // ============================================================================ | |
511 | ||
512 | void wxInitializeStockLists() | |
513 | { | |
514 | wxTheColourDatabase = new wxColourDatabase; | |
515 | ||
516 | wxTheBrushList = new wxBrushList; | |
517 | wxThePenList = new wxPenList; | |
518 | wxTheFontList = new wxFontList; | |
519 | wxTheBitmapList = new wxBitmapList; | |
520 | } | |
521 | ||
522 | void wxInitializeStockObjects () | |
523 | { | |
524 | #ifdef __WXMOTIF__ | |
525 | #endif | |
526 | #ifdef __X__ | |
527 | // TODO | |
528 | // wxFontPool = new XFontPool; | |
529 | #endif | |
530 | ||
531 | // why under MSW fonts shouldn't have the standard system size? | |
532 | /* | |
533 | #ifdef __WXMSW__ | |
534 | static const int sizeFont = 10; | |
535 | #else | |
536 | #endif | |
537 | */ | |
538 | #if defined(__WXMAC__) | |
539 | // retrieve size of system font for all stock fonts | |
540 | int sizeFont = 12; | |
541 | ||
542 | Str255 fontName ; | |
543 | SInt16 fontSize ; | |
544 | Style fontStyle ; | |
545 | ||
546 | GetThemeFont(kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; | |
547 | sizeFont = fontSize ; | |
548 | #ifdef __WXMAC_CLASSIC__ | |
549 | wxNORMAL_FONT = new wxFont (fontSize, wxMODERN, wxNORMAL, wxNORMAL , false , wxMacMakeStringFromPascal(fontName) ); | |
550 | #else | |
551 | wxNORMAL_FONT = new wxFont () ; | |
552 | wxNORMAL_FONT->MacCreateThemeFont( kThemeSystemFont ); | |
553 | #endif | |
554 | #elif defined(__WXPM__) | |
555 | static const int sizeFont = 12; | |
556 | #else | |
557 | wxNORMAL_FONT = new wxFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
558 | static const int sizeFont = wxNORMAL_FONT->GetPointSize(); | |
559 | #endif | |
560 | ||
561 | #if defined(__WXPM__) | |
562 | /* | |
563 | // Basic OS/2 has a fairly limited number of fonts and these are as good | |
564 | // as I can do to get something that looks halfway "wx" normal | |
565 | */ | |
566 | wxNORMAL_FONT = new wxFont (sizeFont, wxMODERN, wxNORMAL, wxBOLD); | |
567 | wxSMALL_FONT = new wxFont (sizeFont - 4, wxSWISS, wxNORMAL, wxNORMAL); /* Helv */ | |
568 | wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL); | |
569 | wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL); /* Helv */ | |
570 | #elif defined(__WXMAC__) | |
571 | wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL); /* Helv */ | |
572 | wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL); | |
573 | #ifdef __WXMAC_CLASSIC__ | |
574 | GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; | |
575 | wxSMALL_FONT = new wxFont (fontSize, wxSWISS, wxNORMAL, wxNORMAL , false , wxMacMakeStringFromPascal( fontName ) ); | |
576 | #else | |
577 | wxSMALL_FONT = new wxFont () ; | |
578 | wxSMALL_FONT->MacCreateThemeFont( kThemeSmallSystemFont ); | |
579 | #endif | |
580 | #else | |
581 | wxSMALL_FONT = new wxFont (sizeFont - 2, wxSWISS, wxNORMAL, wxNORMAL); | |
582 | wxITALIC_FONT = new wxFont (sizeFont, wxROMAN, wxITALIC, wxNORMAL); | |
583 | wxSWISS_FONT = new wxFont (sizeFont, wxSWISS, wxNORMAL, wxNORMAL); | |
584 | #endif | |
585 | ||
586 | wxRED_PEN = new wxPen (wxT("RED"), 1, wxSOLID); | |
587 | wxCYAN_PEN = new wxPen (wxT("CYAN"), 1, wxSOLID); | |
588 | wxGREEN_PEN = new wxPen (wxT("GREEN"), 1, wxSOLID); | |
589 | wxBLACK_PEN = new wxPen (wxT("BLACK"), 1, wxSOLID); | |
590 | wxWHITE_PEN = new wxPen (wxT("WHITE"), 1, wxSOLID); | |
591 | wxTRANSPARENT_PEN = new wxPen (wxT("BLACK"), 1, wxTRANSPARENT); | |
592 | wxBLACK_DASHED_PEN = new wxPen (wxT("BLACK"), 1, wxSHORT_DASH); | |
593 | wxGREY_PEN = new wxPen (wxT("GREY"), 1, wxSOLID); | |
594 | wxMEDIUM_GREY_PEN = new wxPen (wxT("MEDIUM GREY"), 1, wxSOLID); | |
595 | wxLIGHT_GREY_PEN = new wxPen (wxT("LIGHT GREY"), 1, wxSOLID); | |
596 | ||
597 | wxBLUE_BRUSH = new wxBrush (wxT("BLUE"), wxSOLID); | |
598 | wxGREEN_BRUSH = new wxBrush (wxT("GREEN"), wxSOLID); | |
599 | wxWHITE_BRUSH = new wxBrush (wxT("WHITE"), wxSOLID); | |
600 | wxBLACK_BRUSH = new wxBrush (wxT("BLACK"), wxSOLID); | |
601 | wxTRANSPARENT_BRUSH = new wxBrush (wxT("BLACK"), wxTRANSPARENT); | |
602 | wxCYAN_BRUSH = new wxBrush (wxT("CYAN"), wxSOLID); | |
603 | wxRED_BRUSH = new wxBrush (wxT("RED"), wxSOLID); | |
604 | wxGREY_BRUSH = new wxBrush (wxT("GREY"), wxSOLID); | |
605 | wxMEDIUM_GREY_BRUSH = new wxBrush (wxT("MEDIUM GREY"), wxSOLID); | |
606 | wxLIGHT_GREY_BRUSH = new wxBrush (wxT("LIGHT GREY"), wxSOLID); | |
607 | ||
608 | wxBLACK = new wxColour (wxT("BLACK")); | |
609 | wxWHITE = new wxColour (wxT("WHITE")); | |
610 | wxRED = new wxColour (wxT("RED")); | |
611 | wxBLUE = new wxColour (wxT("BLUE")); | |
612 | wxGREEN = new wxColour (wxT("GREEN")); | |
613 | wxCYAN = new wxColour (wxT("CYAN")); | |
614 | wxLIGHT_GREY = new wxColour (wxT("LIGHT GREY")); | |
615 | ||
616 | wxSTANDARD_CURSOR = new wxCursor (wxCURSOR_ARROW); | |
617 | wxHOURGLASS_CURSOR = new wxCursor (wxCURSOR_WAIT); | |
618 | wxCROSS_CURSOR = new wxCursor (wxCURSOR_CROSS); | |
619 | } | |
620 | ||
621 | void wxDeleteStockObjects () | |
622 | { | |
623 | wxDELETE(wxNORMAL_FONT); | |
624 | wxDELETE(wxSMALL_FONT); | |
625 | wxDELETE(wxITALIC_FONT); | |
626 | wxDELETE(wxSWISS_FONT); | |
627 | ||
628 | wxDELETE(wxRED_PEN); | |
629 | wxDELETE(wxCYAN_PEN); | |
630 | wxDELETE(wxGREEN_PEN); | |
631 | wxDELETE(wxBLACK_PEN); | |
632 | wxDELETE(wxWHITE_PEN); | |
633 | wxDELETE(wxTRANSPARENT_PEN); | |
634 | wxDELETE(wxBLACK_DASHED_PEN); | |
635 | wxDELETE(wxGREY_PEN); | |
636 | wxDELETE(wxMEDIUM_GREY_PEN); | |
637 | wxDELETE(wxLIGHT_GREY_PEN); | |
638 | ||
639 | wxDELETE(wxBLUE_BRUSH); | |
640 | wxDELETE(wxGREEN_BRUSH); | |
641 | wxDELETE(wxWHITE_BRUSH); | |
642 | wxDELETE(wxBLACK_BRUSH); | |
643 | wxDELETE(wxTRANSPARENT_BRUSH); | |
644 | wxDELETE(wxCYAN_BRUSH); | |
645 | wxDELETE(wxRED_BRUSH); | |
646 | wxDELETE(wxGREY_BRUSH); | |
647 | wxDELETE(wxMEDIUM_GREY_BRUSH); | |
648 | wxDELETE(wxLIGHT_GREY_BRUSH); | |
649 | ||
650 | wxDELETE(wxBLACK); | |
651 | wxDELETE(wxWHITE); | |
652 | wxDELETE(wxRED); | |
653 | wxDELETE(wxBLUE); | |
654 | wxDELETE(wxGREEN); | |
655 | wxDELETE(wxCYAN); | |
656 | wxDELETE(wxLIGHT_GREY); | |
657 | ||
658 | wxDELETE(wxSTANDARD_CURSOR); | |
659 | wxDELETE(wxHOURGLASS_CURSOR); | |
660 | wxDELETE(wxCROSS_CURSOR); | |
661 | } | |
662 | ||
663 | void wxDeleteStockLists() | |
664 | { | |
665 | wxDELETE(wxTheBrushList); | |
666 | wxDELETE(wxThePenList); | |
667 | wxDELETE(wxTheFontList); | |
668 | wxDELETE(wxTheBitmapList); | |
669 | } | |
670 | ||
671 | // ============================================================================ | |
672 | // wxTheXXXList stuff (semi-obsolete) | |
673 | // ============================================================================ | |
674 | ||
675 | wxBitmapList::~wxBitmapList () | |
676 | { | |
677 | wxList::compatibility_iterator node = GetFirst (); | |
678 | while (node) | |
679 | { | |
680 | wxBitmap *bitmap = (wxBitmap *) node->GetData (); | |
681 | wxList::compatibility_iterator next = node->GetNext (); | |
682 | if (bitmap->GetVisible()) | |
683 | delete bitmap; | |
684 | node = next; | |
685 | } | |
686 | } | |
687 | ||
688 | // Pen and Brush lists | |
689 | wxPenList::~wxPenList () | |
690 | { | |
691 | wxList::compatibility_iterator node = GetFirst (); | |
692 | while (node) | |
693 | { | |
694 | wxPen *pen = (wxPen *) node->GetData (); | |
695 | wxList::compatibility_iterator next = node->GetNext (); | |
696 | if (pen->GetVisible()) | |
697 | delete pen; | |
698 | node = next; | |
699 | } | |
700 | } | |
701 | ||
702 | void wxPenList::AddPen (wxPen * pen) | |
703 | { | |
704 | Append (pen); | |
705 | } | |
706 | ||
707 | void wxPenList::RemovePen (wxPen * pen) | |
708 | { | |
709 | DeleteObject (pen); | |
710 | } | |
711 | ||
712 | wxPen *wxPenList::FindOrCreatePen (const wxColour& colour, int width, int style) | |
713 | { | |
714 | for (wxList::compatibility_iterator node = GetFirst (); node; node = node->GetNext ()) | |
715 | { | |
716 | wxPen *each_pen = (wxPen *) node->GetData (); | |
717 | if (each_pen && | |
718 | each_pen->GetVisible() && | |
719 | each_pen->GetWidth () == width && | |
720 | each_pen->GetStyle () == style && | |
721 | each_pen->GetColour ().Red () == colour.Red () && | |
722 | each_pen->GetColour ().Green () == colour.Green () && | |
723 | each_pen->GetColour ().Blue () == colour.Blue ()) | |
724 | return each_pen; | |
725 | } | |
726 | ||
727 | wxPen *pen = new wxPen (colour, width, style); | |
728 | if ( !pen->Ok() ) | |
729 | { | |
730 | // don't save the invalid pens in the list | |
731 | delete pen; | |
732 | ||
733 | return NULL; | |
734 | } | |
735 | ||
736 | AddPen(pen); | |
737 | ||
738 | // we'll delete it ourselves later | |
739 | pen->SetVisible(true); | |
740 | ||
741 | return pen; | |
742 | } | |
743 | ||
744 | wxBrushList::~wxBrushList () | |
745 | { | |
746 | wxList::compatibility_iterator node = GetFirst (); | |
747 | while (node) | |
748 | { | |
749 | wxBrush *brush = (wxBrush *) node->GetData (); | |
750 | wxList::compatibility_iterator next = node->GetNext (); | |
751 | if (brush && brush->GetVisible()) | |
752 | delete brush; | |
753 | node = next; | |
754 | } | |
755 | } | |
756 | ||
757 | void wxBrushList::AddBrush (wxBrush * brush) | |
758 | { | |
759 | Append (brush); | |
760 | } | |
761 | ||
762 | wxBrush *wxBrushList::FindOrCreateBrush (const wxColour& colour, int style) | |
763 | { | |
764 | for (wxList::compatibility_iterator node = GetFirst (); node; node = node->GetNext ()) | |
765 | { | |
766 | wxBrush *each_brush = (wxBrush *) node->GetData (); | |
767 | if (each_brush && | |
768 | each_brush->GetVisible() && | |
769 | each_brush->GetStyle () == style && | |
770 | each_brush->GetColour ().Red () == colour.Red () && | |
771 | each_brush->GetColour ().Green () == colour.Green () && | |
772 | each_brush->GetColour ().Blue () == colour.Blue ()) | |
773 | return each_brush; | |
774 | } | |
775 | ||
776 | wxBrush *brush = new wxBrush (colour, style); | |
777 | ||
778 | if ( !brush->Ok() ) | |
779 | { | |
780 | // don't put the brushes we failed to create into the list | |
781 | delete brush; | |
782 | ||
783 | return NULL; | |
784 | } | |
785 | ||
786 | AddBrush(brush); | |
787 | ||
788 | // we'll delete it ourselves later | |
789 | brush->SetVisible(true); | |
790 | ||
791 | return brush; | |
792 | } | |
793 | ||
794 | void wxBrushList::RemoveBrush (wxBrush * brush) | |
795 | { | |
796 | DeleteObject (brush); | |
797 | } | |
798 | ||
799 | wxFontList::~wxFontList () | |
800 | { | |
801 | wxList::compatibility_iterator node = GetFirst (); | |
802 | while (node) | |
803 | { | |
804 | // Only delete objects that are 'visible', i.e. | |
805 | // that have been created using FindOrCreate..., | |
806 | // where the pointers are expected to be shared | |
807 | // (and therefore not deleted by any one part of an app). | |
808 | wxFont *font = (wxFont *) node->GetData (); | |
809 | wxList::compatibility_iterator next = node->GetNext (); | |
810 | if (font->GetVisible()) | |
811 | delete font; | |
812 | node = next; | |
813 | } | |
814 | } | |
815 | ||
816 | void wxFontList::AddFont (wxFont * font) | |
817 | { | |
818 | Append (font); | |
819 | } | |
820 | ||
821 | void wxFontList::RemoveFont (wxFont * font) | |
822 | { | |
823 | DeleteObject (font); | |
824 | } | |
825 | ||
826 | wxFont *wxFontList::FindOrCreateFont(int pointSize, | |
827 | int family, | |
828 | int style, | |
829 | int weight, | |
830 | bool underline, | |
831 | const wxString& facename, | |
832 | wxFontEncoding encoding) | |
833 | { | |
834 | wxFont *font = (wxFont *)NULL; | |
835 | wxList::compatibility_iterator node; | |
836 | for ( node = GetFirst(); node; node = node->GetNext() ) | |
837 | { | |
838 | font = (wxFont *)node->GetData(); | |
839 | if ( font->GetVisible() && | |
840 | font->Ok() && | |
841 | font->GetPointSize () == pointSize && | |
842 | font->GetStyle () == style && | |
843 | font->GetWeight () == weight && | |
844 | font->GetUnderlined () == underline ) | |
845 | { | |
846 | int fontFamily = font->GetFamily(); | |
847 | ||
848 | #if defined(__WXGTK__) | |
849 | // under GTK the default family is wxSWISS, so looking for a font | |
850 | // with wxDEFAULT family should return a wxSWISS one instead of | |
851 | // creating a new one | |
852 | bool same = (fontFamily == family) || | |
853 | (fontFamily == wxSWISS && family == wxDEFAULT); | |
854 | #else // !GTK | |
855 | // VZ: but why elsewhere do we require an exact match? mystery... | |
856 | bool same = fontFamily == family; | |
857 | #endif // GTK/!GTK | |
858 | ||
859 | // empty facename matches anything at all: this is bad because | |
860 | // depending on which fonts are already created, we might get back | |
861 | // a different font if we create it with empty facename, but it is | |
862 | // still better than never matching anything in the cache at all | |
863 | // in this case | |
864 | if ( same && !facename.empty() ) | |
865 | { | |
866 | const wxString& fontFace = font->GetFaceName(); | |
867 | ||
868 | // empty facename matches everything | |
869 | same = !fontFace || fontFace == facename; | |
870 | } | |
871 | ||
872 | if ( same && (encoding != wxFONTENCODING_DEFAULT) ) | |
873 | { | |
874 | // have to match the encoding too | |
875 | same = font->GetEncoding() == encoding; | |
876 | } | |
877 | ||
878 | if ( same ) | |
879 | { | |
880 | return font; | |
881 | } | |
882 | } | |
883 | } | |
884 | ||
885 | if ( !node ) | |
886 | { | |
887 | // font not found, create the new one | |
888 | font = new wxFont(pointSize, family, style, weight, | |
889 | underline, facename, encoding); | |
890 | ||
891 | AddFont(font); | |
892 | ||
893 | // and mark it as being cacheable | |
894 | font->SetVisible(true); | |
895 | } | |
896 | ||
897 | return font; | |
898 | } | |
899 | ||
900 | void wxBitmapList::AddBitmap(wxBitmap *bitmap) | |
901 | { | |
902 | Append(bitmap); | |
903 | } | |
904 | ||
905 | void wxBitmapList::RemoveBitmap(wxBitmap *bitmap) | |
906 | { | |
907 | DeleteObject(bitmap); | |
908 | } | |
909 | ||
910 | wxSize wxGetDisplaySize() | |
911 | { | |
912 | int x, y; | |
913 | wxDisplaySize(& x, & y); | |
914 | return wxSize(x, y); | |
915 | } | |
916 | ||
917 | wxRect wxGetClientDisplayRect() | |
918 | { | |
919 | int x, y, width, height; | |
920 | wxClientDisplayRect(&x, &y, &width, &height); // call plat-specific version | |
921 | return wxRect(x, y, width, height); | |
922 | } | |
923 | ||
924 | wxSize wxGetDisplaySizeMM() | |
925 | { | |
926 | int x, y; | |
927 | wxDisplaySizeMM(& x, & y); | |
928 | return wxSize(x, y); | |
929 | } | |
930 | ||
931 | wxResourceCache::~wxResourceCache () | |
932 | { | |
933 | wxList::compatibility_iterator node = GetFirst (); | |
934 | while (node) { | |
935 | wxObject *item = (wxObject *)node->GetData(); | |
936 | delete item; | |
937 | ||
938 | node = node->GetNext (); | |
939 | } | |
940 | } | |
941 |