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