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