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