]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/font.cpp
disallow creation of wxDC objects and made wxDC an ABC; use wxDCTemp instead of wxDC...
[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
27#ifndef WX_PRECOMP
28 #include "wx/setup.h"
29 #include "wx/list.h"
30 #include "wx/utils.h"
31 #include "wx/app.h"
32 #include "wx/font.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
44wxBEGIN_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 )
52wxEND_ENUM( wxFontFamily )
53
54wxBEGIN_ENUM( wxFontStyle )
55 wxENUM_MEMBER( wxNORMAL )
56 wxENUM_MEMBER( wxITALIC )
57 wxENUM_MEMBER( wxSLANT )
58wxEND_ENUM( wxFontStyle )
59
60wxBEGIN_ENUM( wxFontWeight )
61 wxENUM_MEMBER( wxNORMAL )
62 wxENUM_MEMBER( wxLIGHT )
63 wxENUM_MEMBER( wxBOLD )
64wxEND_ENUM( wxFontWeight )
65
66IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI(wxFont, wxGDIObject,"wx/font.h")
67
68wxBEGIN_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"))
76wxEND_PROPERTIES_TABLE()
77
78wxCONSTRUCTOR_6( wxFont , int , Size , int , Family , int , Style , int , Weight , bool , Underlined , wxString , Face )
79
80wxBEGIN_HANDLERS_TABLE(wxFont)
81wxEND_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
96class WXDLLEXPORT wxFontRefData: public wxGDIRefData
97{
98public:
99 // constructors
100 wxFontRefData()
101 {
4055ed82
WS
102 Init(-1, wxSize(0, 0), false, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
103 wxFONTWEIGHT_NORMAL, false, wxEmptyString,
ffecfa5a
JS
104 wxFONTENCODING_DEFAULT);
105 }
106
107 wxFontRefData(int size,
108 const wxSize& pixelSize,
109 bool sizeUsingPixels,
110 int family,
111 int style,
112 int 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;
4055ed82 217 m_sizeUsingPixels = false;
ffecfa5a
JS
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;
4055ed82 230 m_sizeUsingPixels = true;
ffecfa5a
JS
231 }
232 }
233
234 void SetFamily(int family)
235 {
236 m_family = family;
237 }
238
239 void SetStyle(int style)
240 {
241 if ( m_nativeFontInfoOk )
242 m_nativeFontInfo.SetStyle((wxFontStyle)style);
243 else
244 m_style = style;
245 }
246
247 void SetWeight(int weight)
248 {
249 if ( m_nativeFontInfoOk )
250 m_nativeFontInfo.SetWeight((wxFontWeight)weight);
251 else
252 m_weight = weight;
253 }
254
255 void 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
285protected:
286 // common part of all ctors
287 void Init(int size,
288 const wxSize& pixelSize,
289 bool sizeUsingPixels,
290 int family,
291 int style,
292 int 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 int m_family;
304 int m_style;
305 int 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// ============================================================================
319// implementation
320// ============================================================================
321
322// ----------------------------------------------------------------------------
323// wxFontRefData
324// ----------------------------------------------------------------------------
325
326void wxFontRefData::Init(int pointSize,
327 const wxSize& pixelSize,
328 bool sizeUsingPixels,
329 int family,
330 int style,
331 int weight,
332 bool underlined,
333 const wxString& faceName,
334 wxFontEncoding encoding)
335{
336}
337
338void wxFontRefData::Init(const wxNativeFontInfo& info, WXHFONT hFont)
339{
340}
341
342wxFontRefData::~wxFontRefData()
343{
344}
345
346bool wxFontRefData::Alloc(wxFont *font)
347{
348 return false;
349}
350
351void wxFontRefData::Free()
352{
353}
354
355// ----------------------------------------------------------------------------
356// wxNativeFontInfo
357// ----------------------------------------------------------------------------
358
359void wxNativeFontInfo::SetPixelSize(const wxSize& pixelSize)
360{
361}
362
363// ----------------------------------------------------------------------------
364// wxFont
365// ----------------------------------------------------------------------------
366
367void wxFont::Init()
368{
369}
370
371bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont)
372{
373 return false;
374}
375
376wxFont::wxFont(const wxString& fontdesc)
377{
378}
379
380/* Constructor for a font. Note that the real construction is done
381 * in wxDC::SetFont, when information is available about scaling etc.
382 */
383bool wxFont::DoCreate(int pointSize,
384 const wxSize& pixelSize,
385 bool sizeUsingPixels,
386 int family,
387 int style,
388 int weight,
389 bool underlined,
390 const wxString& faceName,
391 wxFontEncoding encoding)
392{
4055ed82 393 return false;
ffecfa5a
JS
394}
395
396wxFont::~wxFont()
397{
398}
399
400// ----------------------------------------------------------------------------
401// real implementation
402// ----------------------------------------------------------------------------
403
404bool wxFont::RealizeResource()
405{
4055ed82 406 return false;
ffecfa5a
JS
407}
408
409bool wxFont::FreeResource(bool WXUNUSED(force))
410{
411 return false;
412}
413
414WXHANDLE wxFont::GetResourceHandle() const
415{
416 return (WXHANDLE)0;
417}
418
ffecfa5a
JS
419bool wxFont::IsFree() const
420{
421 return false;
422}
423
424void wxFont::Unshare()
425{
426}
427
428// ----------------------------------------------------------------------------
429// change font attribute: we recreate font when doing it
430// ----------------------------------------------------------------------------
431
432void wxFont::SetPointSize(int pointSize)
433{
434}
435
436void wxFont::SetPixelSize(const wxSize& pixelSize)
437{
438}
439
440void wxFont::SetFamily(int family)
441{
442}
443
444void wxFont::SetStyle(int style)
445{
446}
447
448void wxFont::SetWeight(int weight)
449{
450}
451
452void wxFont::SetFaceName(const wxString& faceName)
453{
454}
455
456void wxFont::SetUnderlined(bool underlined)
457{
458}
459
460void wxFont::SetEncoding(wxFontEncoding encoding)
461{
462}
463
464void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
465{
466}
467
468// ----------------------------------------------------------------------------
469// accessors
470// ----------------------------------------------------------------------------
471
472int wxFont::GetPointSize() const
473{
474 return 0;
475}
476
477wxSize wxFont::GetPixelSize() const
478{
479 return wxSize(0,0);
480}
481
482bool wxFont::IsUsingSizeInPixels() const
483{
484 return false;
485}
486
487int wxFont::GetFamily() const
488{
489 return wxFONTFAMILY_ROMAN;
490}
491
492int wxFont::GetStyle() const
493{
494 return wxFONTSTYLE_NORMAL;
495}
496
497int wxFont::GetWeight() const
498{
499 return wxFONTWEIGHT_NORMAL;
500}
501
502bool wxFont::GetUnderlined() const
503{
504 return false;
505}
506
507wxString wxFont::GetFaceName() const
508{
509 return wxEmptyString;
510}
511
512wxFontEncoding wxFont::GetEncoding() const
513{
514 return wxFONTENCODING_SYSTEM;
515}
516
517const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
518{
519 return NULL;
520}
521
522bool wxFont::IsFixedWidth() const
523{
524 return false;
525}
526