]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/font.cpp
Fix after removal of PRIOR/NEXT in common headers (duplicates change in GTK2 sources).
[wxWidgets.git] / src / palmos / font.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/font.cpp
3 // Purpose: wxFont class
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by:
6 // Created: 10/14/04
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
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 #ifndef WX_PRECOMP
28 #include "wx/list.h"
29 #include "wx/utils.h"
30 #include "wx/app.h"
31 #include "wx/font.h"
32 #include "wx/log.h"
33 #include "wx/encinfo.h"
34 #endif // WX_PRECOMP
35
36 #include "wx/fontutil.h"
37 #include "wx/fontmap.h"
38
39 #include "wx/tokenzr.h"
40
41 #if wxUSE_EXTENDED_RTTI
42
43 wxBEGIN_ENUM( wxFontFamily )
44 wxENUM_MEMBER( wxDEFAULT )
45 wxENUM_MEMBER( wxDECORATIVE )
46 wxENUM_MEMBER( wxROMAN )
47 wxENUM_MEMBER( wxSCRIPT )
48 wxENUM_MEMBER( wxSWISS )
49 wxENUM_MEMBER( wxMODERN )
50 wxENUM_MEMBER( wxTELETYPE )
51 wxEND_ENUM( wxFontFamily )
52
53 wxBEGIN_ENUM( wxFontStyle )
54 wxENUM_MEMBER( wxNORMAL )
55 wxENUM_MEMBER( wxITALIC )
56 wxENUM_MEMBER( wxSLANT )
57 wxEND_ENUM( wxFontStyle )
58
59 wxBEGIN_ENUM( wxFontWeight )
60 wxENUM_MEMBER( wxNORMAL )
61 wxENUM_MEMBER( wxLIGHT )
62 wxENUM_MEMBER( wxBOLD )
63 wxEND_ENUM( wxFontWeight )
64
65 IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont, wxGDIObject,"wx/font.h")
66
67 wxBEGIN_PROPERTIES_TABLE(wxFont)
68 wxPROPERTY( Size,int, SetPointSize, GetPointSize, 12 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
69 wxPROPERTY( Family, int , SetFamily, GetFamily, (int)wxDEFAULT , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontFamily
70 wxPROPERTY( Style, int , SetStyle, GetStyle, (int)wxNORMAL , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontStyle
71 wxPROPERTY( Weight, int , SetWeight, GetWeight, (int)wxNORMAL , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // wxFontWeight
72 wxPROPERTY( Underlined, bool , SetUnderlined, GetUnderlined, false , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
73 wxPROPERTY( Face, wxString , SetFaceName, GetFaceName, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
74 wxPROPERTY( Encoding, wxFontEncoding , SetEncoding, GetEncoding, wxFONTENCODING_DEFAULT , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
75 wxEND_PROPERTIES_TABLE()
76
77 wxCONSTRUCTOR_6( wxFont , int , Size , int , Family , int , Style , int , Weight , bool , Underlined , wxString , Face )
78
79 wxBEGIN_HANDLERS_TABLE(wxFont)
80 wxEND_HANDLERS_TABLE()
81
82 #else
83 IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
84 #endif
85
86
87 // ----------------------------------------------------------------------------
88 // constants
89 // ----------------------------------------------------------------------------
90
91 // ----------------------------------------------------------------------------
92 // wxFontRefData - the internal description of the font
93 // ----------------------------------------------------------------------------
94
95 class WXDLLEXPORT wxFontRefData: public wxGDIRefData
96 {
97 public:
98 // constructors
99 wxFontRefData()
100 {
101 Init(-1, wxSize(0, 0), false, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
102 wxFONTWEIGHT_NORMAL, false, wxEmptyString,
103 wxFONTENCODING_DEFAULT);
104 }
105
106 wxFontRefData(int size,
107 const wxSize& pixelSize,
108 bool sizeUsingPixels,
109 int family,
110 int style,
111 int weight,
112 bool underlined,
113 const wxString& faceName,
114 wxFontEncoding encoding)
115 {
116 Init(size, pixelSize, sizeUsingPixels, family, style, weight,
117 underlined, faceName, encoding);
118 }
119
120 wxFontRefData(const wxNativeFontInfo& info, WXHFONT hFont = 0)
121 {
122 Init(info, hFont);
123 }
124
125 wxFontRefData(const wxFontRefData& data)
126 {
127 if ( data.m_nativeFontInfoOk )
128 {
129 Init(data.m_nativeFontInfo);
130 }
131 else
132 {
133 Init(data.m_pointSize, data.m_pixelSize, data.m_sizeUsingPixels,
134 data.m_family, data.m_style, data.m_weight,
135 data.m_underlined, data.m_faceName, data.m_encoding);
136 }
137 }
138
139 virtual ~wxFontRefData();
140
141 // operations
142 bool Alloc(wxFont *font);
143
144 void Free();
145
146 // all wxFont accessors
147 int GetPointSize() const
148 {
149 return m_nativeFontInfoOk ? m_nativeFontInfo.GetPointSize()
150 : m_pointSize;
151 }
152
153 wxSize GetPixelSize() const
154 {
155 return m_nativeFontInfoOk ? m_nativeFontInfo.GetPixelSize()
156 : m_pixelSize;
157 }
158
159 bool IsUsingSizeInPixels() const
160 {
161 return m_nativeFontInfoOk ? true : m_sizeUsingPixels;
162 }
163
164 int GetFamily() const
165 {
166 return m_family;
167 }
168
169 int GetStyle() const
170 {
171 return m_nativeFontInfoOk ? m_nativeFontInfo.GetStyle()
172 : m_style;
173 }
174
175 int GetWeight() const
176 {
177 return m_nativeFontInfoOk ? m_nativeFontInfo.GetWeight()
178 : m_weight;
179 }
180
181 bool GetUnderlined() const
182 {
183 return m_nativeFontInfoOk ? m_nativeFontInfo.GetUnderlined()
184 : m_underlined;
185 }
186
187 wxString GetFaceName() const
188 {
189 wxString s;
190 if ( m_nativeFontInfoOk )
191 s = m_nativeFontInfo.GetFaceName();
192 else
193 s = m_faceName;
194
195 return s;
196 }
197
198 wxFontEncoding GetEncoding() const
199 {
200 return m_nativeFontInfoOk ? m_nativeFontInfo.GetEncoding()
201 : m_encoding;
202 }
203
204 WXHFONT GetHFONT() const { return m_hFont; }
205
206 // ... and setters
207 void SetPointSize(int pointSize)
208 {
209 if ( m_nativeFontInfoOk )
210 {
211 m_nativeFontInfo.SetPointSize(pointSize);
212 }
213 else
214 {
215 m_pointSize = pointSize;
216 m_sizeUsingPixels = false;
217 }
218 }
219
220 void SetPixelSize(const wxSize& pixelSize)
221 {
222 if ( m_nativeFontInfoOk )
223 {
224 m_nativeFontInfo.SetPixelSize(pixelSize);
225 }
226 else
227 {
228 m_pixelSize = pixelSize;
229 m_sizeUsingPixels = true;
230 }
231 }
232
233 void SetFamily(int family)
234 {
235 m_family = family;
236 }
237
238 void SetStyle(int style)
239 {
240 if ( m_nativeFontInfoOk )
241 m_nativeFontInfo.SetStyle((wxFontStyle)style);
242 else
243 m_style = style;
244 }
245
246 void SetWeight(int weight)
247 {
248 if ( m_nativeFontInfoOk )
249 m_nativeFontInfo.SetWeight((wxFontWeight)weight);
250 else
251 m_weight = weight;
252 }
253
254 void SetFaceName(const wxString& faceName)
255 {
256 if ( m_nativeFontInfoOk )
257 m_nativeFontInfo.SetFaceName(faceName);
258 else
259 m_faceName = faceName;
260 }
261
262 void SetUnderlined(bool underlined)
263 {
264 if ( m_nativeFontInfoOk )
265 m_nativeFontInfo.SetUnderlined(underlined);
266 else
267 m_underlined = underlined;
268 }
269
270 void SetEncoding(wxFontEncoding encoding)
271 {
272 if ( m_nativeFontInfoOk )
273 m_nativeFontInfo.SetEncoding(encoding);
274 else
275 m_encoding = encoding;
276 }
277
278 // native font info tests
279 bool HasNativeFontInfo() const { return m_nativeFontInfoOk; }
280
281 const wxNativeFontInfo& GetNativeFontInfo() const
282 { return m_nativeFontInfo; }
283
284 protected:
285 // common part of all ctors
286 void Init(int size,
287 const wxSize& pixelSize,
288 bool sizeUsingPixels,
289 int family,
290 int style,
291 int weight,
292 bool underlined,
293 const wxString& faceName,
294 wxFontEncoding encoding);
295
296 void Init(const wxNativeFontInfo& info, WXHFONT hFont = 0);
297
298 // font characterstics
299 int m_pointSize;
300 wxSize m_pixelSize;
301 bool m_sizeUsingPixels;
302 int m_family;
303 int m_style;
304 int m_weight;
305 bool m_underlined;
306 wxString m_faceName;
307 wxFontEncoding m_encoding;
308
309 // Windows font handle
310 WXHFONT m_hFont;
311
312 // Native font info
313 wxNativeFontInfo m_nativeFontInfo;
314 bool m_nativeFontInfoOk;
315 };
316
317 // ============================================================================
318 // implementation
319 // ============================================================================
320
321 // ----------------------------------------------------------------------------
322 // wxFontRefData
323 // ----------------------------------------------------------------------------
324
325 void wxFontRefData::Init(int pointSize,
326 const wxSize& pixelSize,
327 bool sizeUsingPixels,
328 int family,
329 int style,
330 int weight,
331 bool underlined,
332 const wxString& faceName,
333 wxFontEncoding encoding)
334 {
335 }
336
337 void wxFontRefData::Init(const wxNativeFontInfo& info, WXHFONT hFont)
338 {
339 }
340
341 wxFontRefData::~wxFontRefData()
342 {
343 }
344
345 bool wxFontRefData::Alloc(wxFont *font)
346 {
347 return false;
348 }
349
350 void wxFontRefData::Free()
351 {
352 }
353
354 // ----------------------------------------------------------------------------
355 // wxNativeFontInfo
356 // ----------------------------------------------------------------------------
357
358 void wxNativeFontInfo::SetPixelSize(const wxSize& pixelSize)
359 {
360 }
361
362 // ----------------------------------------------------------------------------
363 // wxFont
364 // ----------------------------------------------------------------------------
365
366 bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont)
367 {
368 return false;
369 }
370
371 wxFont::wxFont(const wxString& fontdesc)
372 {
373 }
374
375 /* Constructor for a font. Note that the real construction is done
376 * in wxDC::SetFont, when information is available about scaling etc.
377 */
378 bool wxFont::DoCreate(int pointSize,
379 const wxSize& pixelSize,
380 bool sizeUsingPixels,
381 int family,
382 int style,
383 int weight,
384 bool underlined,
385 const wxString& faceName,
386 wxFontEncoding encoding)
387 {
388 return false;
389 }
390
391 wxFont::~wxFont()
392 {
393 }
394
395 // ----------------------------------------------------------------------------
396 // real implementation
397 // ----------------------------------------------------------------------------
398
399 bool wxFont::RealizeResource()
400 {
401 return false;
402 }
403
404 bool wxFont::FreeResource(bool WXUNUSED(force))
405 {
406 return false;
407 }
408
409 WXHANDLE wxFont::GetResourceHandle() const
410 {
411 return (WXHANDLE)0;
412 }
413
414 bool wxFont::IsFree() const
415 {
416 return false;
417 }
418
419 void wxFont::Unshare()
420 {
421 }
422
423 // ----------------------------------------------------------------------------
424 // change font attribute: we recreate font when doing it
425 // ----------------------------------------------------------------------------
426
427 void wxFont::SetPointSize(int pointSize)
428 {
429 }
430
431 void wxFont::SetPixelSize(const wxSize& pixelSize)
432 {
433 }
434
435 void wxFont::SetFamily(int family)
436 {
437 }
438
439 void wxFont::SetStyle(int style)
440 {
441 }
442
443 void wxFont::SetWeight(int weight)
444 {
445 }
446
447 void wxFont::SetFaceName(const wxString& faceName)
448 {
449 }
450
451 void wxFont::SetUnderlined(bool underlined)
452 {
453 }
454
455 void wxFont::SetEncoding(wxFontEncoding encoding)
456 {
457 }
458
459 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
460 {
461 }
462
463 // ----------------------------------------------------------------------------
464 // accessors
465 // ----------------------------------------------------------------------------
466
467 int wxFont::GetPointSize() const
468 {
469 return 0;
470 }
471
472 wxSize wxFont::GetPixelSize() const
473 {
474 return wxSize(0,0);
475 }
476
477 bool wxFont::IsUsingSizeInPixels() const
478 {
479 return false;
480 }
481
482 int wxFont::GetFamily() const
483 {
484 return wxFONTFAMILY_ROMAN;
485 }
486
487 int wxFont::GetStyle() const
488 {
489 return wxFONTSTYLE_NORMAL;
490 }
491
492 int wxFont::GetWeight() const
493 {
494 return wxFONTWEIGHT_NORMAL;
495 }
496
497 bool wxFont::GetUnderlined() const
498 {
499 return false;
500 }
501
502 wxString wxFont::GetFaceName() const
503 {
504 return wxEmptyString;
505 }
506
507 wxFontEncoding wxFont::GetEncoding() const
508 {
509 return wxFONTENCODING_SYSTEM;
510 }
511
512 const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
513 {
514 return NULL;
515 }
516
517 bool wxFont::IsFixedWidth() const
518 {
519 return false;
520 }