]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/font.cpp
wxUSE_PROPGRID is now recognized by source and header files
[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
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
85ab460e 255 bool SetFaceName(const wxString& faceName)
ffecfa5a
JS
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
68c95704
VS
318#define M_FONTDATA ((wxFontRefData*)m_refData)
319
ffecfa5a
JS
320// ============================================================================
321// implementation
322// ============================================================================
323
324// ----------------------------------------------------------------------------
325// wxFontRefData
326// ----------------------------------------------------------------------------
327
328void wxFontRefData::Init(int pointSize,
329 const wxSize& pixelSize,
330 bool sizeUsingPixels,
331 int family,
332 int style,
333 int weight,
334 bool underlined,
335 const wxString& faceName,
336 wxFontEncoding encoding)
337{
338}
339
340void wxFontRefData::Init(const wxNativeFontInfo& info, WXHFONT hFont)
341{
342}
343
344wxFontRefData::~wxFontRefData()
345{
346}
347
348bool wxFontRefData::Alloc(wxFont *font)
349{
350 return false;
351}
352
353void wxFontRefData::Free()
354{
355}
356
357// ----------------------------------------------------------------------------
358// wxNativeFontInfo
359// ----------------------------------------------------------------------------
360
361void wxNativeFontInfo::SetPixelSize(const wxSize& pixelSize)
362{
363}
364
365// ----------------------------------------------------------------------------
366// wxFont
367// ----------------------------------------------------------------------------
368
ffecfa5a
JS
369bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont)
370{
371 return false;
372}
373
374wxFont::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 */
381bool wxFont::DoCreate(int pointSize,
382 const wxSize& pixelSize,
383 bool sizeUsingPixels,
384 int family,
385 int style,
386 int weight,
387 bool underlined,
388 const wxString& faceName,
389 wxFontEncoding encoding)
390{
4055ed82 391 return false;
ffecfa5a
JS
392}
393
394wxFont::~wxFont()
395{
396}
397
398// ----------------------------------------------------------------------------
399// real implementation
400// ----------------------------------------------------------------------------
6afc1b46
VZ
401wxGDIRefData *wxFont::CreateGDIRefData() const
402{
403 return new wxFontRefData();
404}
405
406wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const
407{
408 return new wxFontRefData(*wx_static_cast(const wxFontRefData *, data));
409}
ffecfa5a
JS
410
411bool wxFont::RealizeResource()
412{
4055ed82 413 return false;
ffecfa5a
JS
414}
415
416bool wxFont::FreeResource(bool WXUNUSED(force))
417{
418 return false;
419}
420
421WXHANDLE wxFont::GetResourceHandle() const
422{
423 return (WXHANDLE)0;
424}
425
ffecfa5a
JS
426bool wxFont::IsFree() const
427{
428 return false;
429}
430
ffecfa5a
JS
431// ----------------------------------------------------------------------------
432// change font attribute: we recreate font when doing it
433// ----------------------------------------------------------------------------
434
435void wxFont::SetPointSize(int pointSize)
436{
437}
438
439void wxFont::SetPixelSize(const wxSize& pixelSize)
440{
441}
442
443void wxFont::SetFamily(int family)
444{
445}
446
447void wxFont::SetStyle(int style)
448{
449}
450
451void wxFont::SetWeight(int weight)
452{
453}
454
85ab460e 455bool wxFont::SetFaceName(const wxString& faceName)
ffecfa5a 456{
85ab460e 457 return true;
ffecfa5a
JS
458}
459
460void wxFont::SetUnderlined(bool underlined)
461{
462}
463
464void wxFont::SetEncoding(wxFontEncoding encoding)
465{
466}
467
468void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
469{
470}
471
472// ----------------------------------------------------------------------------
473// accessors
474// ----------------------------------------------------------------------------
475
476int wxFont::GetPointSize() const
477{
478 return 0;
479}
480
481wxSize wxFont::GetPixelSize() const
482{
483 return wxSize(0,0);
484}
485
486bool wxFont::IsUsingSizeInPixels() const
487{
488 return false;
489}
490
491int wxFont::GetFamily() const
492{
493 return wxFONTFAMILY_ROMAN;
494}
495
496int wxFont::GetStyle() const
497{
498 return wxFONTSTYLE_NORMAL;
499}
500
501int wxFont::GetWeight() const
502{
503 return wxFONTWEIGHT_NORMAL;
504}
505
506bool wxFont::GetUnderlined() const
507{
508 return false;
509}
510
511wxString wxFont::GetFaceName() const
512{
513 return wxEmptyString;
514}
515
516wxFontEncoding wxFont::GetEncoding() const
517{
518 return wxFONTENCODING_SYSTEM;
519}
520
521const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
522{
523 return NULL;
524}
525
6afc1b46
VZ
526wxString 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
535wxString 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
ffecfa5a
JS
544bool wxFont::IsFixedWidth() const
545{
546 return false;
547}