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