]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/font.cpp
Make wxWindow::SetSizeHints() do nothing.
[wxWidgets.git] / src / dfb / font.cpp
CommitLineData
b3c86150
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/dfb/font.cpp
3// Purpose: wxFont implementation
4// Author: Vaclav Slavik
5// Created: 2006-08-08
6// RCS-ID: $Id$
7// Copyright: (c) 2006 REA Elektronik GmbH
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#include "wx/font.h"
27
28#ifndef WX_PRECOMP
29 #include "wx/app.h"
30#endif
31
32#include "wx/fontutil.h"
33#include "wx/dfb/private.h"
34
35// ----------------------------------------------------------------------------
36// wxFontRefData
37// ----------------------------------------------------------------------------
38
39// FIXME: for now, always use single font
52c8d32a 40static wxIDirectFBFontPtr gs_font = NULL;
b3c86150
VS
41static unsigned gs_fontRefCnt = 0;
42
43class wxFontRefData : public wxObjectRefData
44{
45public:
46 wxFontRefData(int size = wxDEFAULT,
47 int family = wxDEFAULT,
48 int style = wxDEFAULT,
49 int weight = wxDEFAULT,
50 bool underlined = false,
51 const wxString& faceName = wxEmptyString,
52 wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
53 {
54 if ( family == wxDEFAULT )
55 family = wxSWISS;
56 if ( style == wxDEFAULT )
57 style = wxNORMAL;
58 if ( weight == wxDEFAULT )
59 weight = wxNORMAL;
60 if ( size == wxDEFAULT )
61 size = 12;
62
63 m_info.family = (wxFontFamily)family;
64 m_info.faceName = faceName;
65 m_info.style = (wxFontStyle)style;
66 m_info.weight = (wxFontWeight)weight;
67 m_info.pointSize = size;
68 m_info.underlined = underlined;
69 m_info.encoding = encoding;
70
71 // FIXME: always use default font for now
72 if ( !gs_font )
73 {
b3c86150
VS
74 DFBFontDescription desc;
75 desc.flags = (DFBFontDescriptionFlags)0;
52c8d32a
VS
76 wxIDirectFBFontPtr f(wxIDirectFB::Get()->CreateFont(NULL, &desc));
77 if ( f )
b3c86150
VS
78 gs_font = f;
79 }
80 if ( gs_font ) // the above may fail
81 {
82 gs_fontRefCnt++;
83 m_font = gs_font;
84 }
85 }
86
87 wxFontRefData(const wxFontRefData& data)
88 {
89 m_info = data.m_info;
90 m_font = data.m_font;
91 }
92
93 ~wxFontRefData()
94 {
95 if ( m_font )
96 {
97 m_font.Reset();
98 // FIXME
99 if ( --gs_fontRefCnt == 0 )
100 gs_font = NULL;
101 }
102 }
103
104 wxNativeFontInfo m_info;
52c8d32a 105 wxIDirectFBFontPtr m_font;
b3c86150
VS
106};
107
108
109// ----------------------------------------------------------------------------
110// wxFont
111// ----------------------------------------------------------------------------
112
113IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
114
115bool wxFont::Create(const wxNativeFontInfo& info)
116{
117 return Create(info.pointSize, info.family, info.style, info.weight,
118 info.underlined, info.faceName, info.encoding);
119}
120
121bool wxFont::Create(int pointSize,
122 int family,
123 int style,
124 int weight,
125 bool underlined,
126 const wxString& face,
127 wxFontEncoding encoding)
128{
129 m_refData = new wxFontRefData(pointSize, family, style, weight,
130 underlined, face, encoding);
131 return true;
132}
133
134wxObjectRefData *wxFont::CreateRefData() const
135{
136 return new wxFontRefData;
137}
138
139wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const
140{
141 return new wxFontRefData(*(wxFontRefData *)data);
142}
143
144
145// ----------------------------------------------------------------------------
146// accessors
147// ----------------------------------------------------------------------------
148
52c8d32a 149wxIDirectFBFontPtr wxFont::GetDirectFBFont() const
b3c86150
VS
150{
151 wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );
152
153 return M_FONTDATA->m_font;
154}
155
156int wxFont::GetPointSize() const
157{
158 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
159
160 return M_FONTDATA->m_info.pointSize;
161}
162
163wxString wxFont::GetFaceName() const
164{
165 wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid font") );
166
167 return M_FONTDATA->m_info.faceName;
168}
169
170int wxFont::GetFamily() const
171{
172 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
173
174 return M_FONTDATA->m_info.family;
175}
176
177int wxFont::GetStyle() const
178{
179 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
180
181 return M_FONTDATA->m_info.style;
182}
183
184int wxFont::GetWeight() const
185{
186 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
187
188 return M_FONTDATA->m_info.weight;
189}
190
191bool wxFont::GetUnderlined() const
192{
193 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
194
195 return M_FONTDATA->m_info.underlined;
196}
197
198
199wxFontEncoding wxFont::GetEncoding() const
200{
201 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
202
203 return M_FONTDATA->m_info.encoding;
204}
205
206bool wxFont::IsFixedWidth() const
207{
208 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
209
210 return true; // FIXME_DFB
211}
212
213const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
214{
215 wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );
216
217 return &(M_FONTDATA->m_info);
218}
219
220// ----------------------------------------------------------------------------
221// change font attributes
222// ----------------------------------------------------------------------------
223
224void wxFont::SetPointSize(int pointSize)
225{
226 AllocExclusive();
227
228 M_FONTDATA->m_info.pointSize = pointSize;
229}
230
231void wxFont::SetFamily(int family)
232{
233 AllocExclusive();
234
235 M_FONTDATA->m_info.family = (wxFontFamily)family;
236}
237
238void wxFont::SetStyle(int style)
239{
240 AllocExclusive();
241
242 M_FONTDATA->m_info.style = (wxFontStyle)style;
243}
244
245void wxFont::SetWeight(int weight)
246{
247 AllocExclusive();
248
249 M_FONTDATA->m_info.weight = (wxFontWeight)weight;
250}
251
252bool wxFont::SetFaceName(const wxString& faceName)
253{
254 AllocExclusive();
255
256 M_FONTDATA->m_info.faceName = faceName;
257
258 return wxFontBase::SetFaceName(faceName);
259}
260
261void wxFont::SetUnderlined(bool underlined)
262{
263 AllocExclusive();
264
265 M_FONTDATA->m_info.underlined = underlined;
266}
267
268void wxFont::SetEncoding(wxFontEncoding encoding)
269{
270 AllocExclusive();
271
272 M_FONTDATA->m_info.encoding = encoding;
273}