]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/palmos/font.cpp
don't overwrite the existing local file if we failed to open it but it does exist
[wxWidgets.git] / src / palmos / font.cpp
... / ...
CommitLineData
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
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 {
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 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;
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(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 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
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#define M_FONTDATA ((wxFontRefData*)m_refData)
319
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
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{
391 return false;
392}
393
394wxFont::~wxFont()
395{
396}
397
398// ----------------------------------------------------------------------------
399// real implementation
400// ----------------------------------------------------------------------------
401
402bool wxFont::RealizeResource()
403{
404 return false;
405}
406
407bool wxFont::FreeResource(bool WXUNUSED(force))
408{
409 return false;
410}
411
412WXHANDLE wxFont::GetResourceHandle() const
413{
414 return (WXHANDLE)0;
415}
416
417bool wxFont::IsFree() const
418{
419 return false;
420}
421
422void wxFont::Unshare()
423{
424}
425
426// ----------------------------------------------------------------------------
427// change font attribute: we recreate font when doing it
428// ----------------------------------------------------------------------------
429
430void wxFont::SetPointSize(int pointSize)
431{
432}
433
434void wxFont::SetPixelSize(const wxSize& pixelSize)
435{
436}
437
438void wxFont::SetFamily(int family)
439{
440}
441
442void wxFont::SetStyle(int style)
443{
444}
445
446void wxFont::SetWeight(int weight)
447{
448}
449
450bool wxFont::SetFaceName(const wxString& faceName)
451{
452 return true;
453}
454
455void wxFont::SetUnderlined(bool underlined)
456{
457}
458
459void wxFont::SetEncoding(wxFontEncoding encoding)
460{
461}
462
463void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
464{
465}
466
467// ----------------------------------------------------------------------------
468// accessors
469// ----------------------------------------------------------------------------
470
471int wxFont::GetPointSize() const
472{
473 return 0;
474}
475
476wxSize wxFont::GetPixelSize() const
477{
478 return wxSize(0,0);
479}
480
481bool wxFont::IsUsingSizeInPixels() const
482{
483 return false;
484}
485
486int wxFont::GetFamily() const
487{
488 return wxFONTFAMILY_ROMAN;
489}
490
491int wxFont::GetStyle() const
492{
493 return wxFONTSTYLE_NORMAL;
494}
495
496int wxFont::GetWeight() const
497{
498 return wxFONTWEIGHT_NORMAL;
499}
500
501bool wxFont::GetUnderlined() const
502{
503 return false;
504}
505
506wxString wxFont::GetFaceName() const
507{
508 return wxEmptyString;
509}
510
511wxFontEncoding wxFont::GetEncoding() const
512{
513 return wxFONTENCODING_SYSTEM;
514}
515
516const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
517{
518 return NULL;
519}
520
521bool wxFont::IsFixedWidth() const
522{
523 return false;
524}