]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/font.cpp
changed layout hints to proper determining aqua layout presence before
[wxWidgets.git] / src / mac / carbon / font.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: font.cpp
3 // Purpose: wxFont class
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "font.h"
14 #endif
15
16 #include "wx/defs.h"
17 #include "wx/string.h"
18 #include "wx/font.h"
19 #include "wx/fontutil.h"
20 #include "wx/gdicmn.h"
21 #include "wx/utils.h"
22
23 #include "wx/fontutil.h"
24
25 #if !USE_SHARED_LIBRARIES
26 IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
27 #endif
28
29 // ============================================================================
30 // implementation
31 // ============================================================================
32
33 // ----------------------------------------------------------------------------
34 // wxFontRefData
35 // ----------------------------------------------------------------------------
36
37 void wxFontRefData::Init(int pointSize,
38 int family,
39 int style,
40 int weight,
41 bool underlined,
42 const wxString& faceName,
43 wxFontEncoding encoding)
44 {
45 m_style = style;
46 m_pointSize = pointSize;
47 m_family = family;
48 m_style = style;
49 m_weight = weight;
50 m_underlined = underlined;
51 m_faceName = faceName;
52 m_encoding = encoding;
53
54 m_macFontNum = 0 ;
55 m_macFontSize = 0;
56 m_macFontStyle = 0;
57 m_fontId = 0;
58 }
59
60 wxFontRefData::~wxFontRefData()
61 {
62 }
63
64 void wxFontRefData::MacFindFont()
65 {
66 if( m_faceName == "" )
67 {
68 switch( m_family )
69 {
70 case wxDEFAULT :
71 m_macFontNum = ::GetAppFont() ;
72 break ;
73 case wxDECORATIVE :
74 ::GetFNum( "\pTimes" , &m_macFontNum) ;
75 break ;
76 case wxROMAN :
77 ::GetFNum( "\pTimes" , &m_macFontNum) ;
78 break ;
79 case wxSCRIPT :
80 ::GetFNum( "\pTimes" , &m_macFontNum) ;
81 break ;
82 case wxSWISS :
83 ::GetFNum( "\pGeneva" , &m_macFontNum) ;
84 break ;
85 case wxMODERN :
86 ::GetFNum( "\pMonaco" , &m_macFontNum) ;
87 break ;
88 }
89 }
90 else
91 {
92 if ( m_faceName == "systemfont" )
93 m_macFontNum = ::GetSysFont() ;
94 else if ( m_faceName == "applicationfont" )
95 m_macFontNum = ::GetAppFont() ;
96 else
97 {
98 #if TARGET_CARBON
99 c2pstrcpy( (StringPtr) wxBuffer, m_faceName ) ;
100 #else
101 strcpy( (char *) wxBuffer, m_faceName ) ;
102 c2pstr( (char *) wxBuffer ) ;
103 #endif
104 ::GetFNum( (StringPtr) wxBuffer, &m_macFontNum);
105 }
106 }
107
108 m_macFontStyle = 0;
109 if (m_weight == wxBOLD)
110 m_macFontStyle |= bold;
111 if (m_style == wxITALIC || m_style == wxSLANT)
112 m_macFontStyle |= italic;
113 if (m_underlined)
114 m_macFontStyle |= underline;
115 m_macFontSize = m_pointSize ;
116 }
117
118 // ----------------------------------------------------------------------------
119 // wxFont
120 // ----------------------------------------------------------------------------
121
122 void wxFont::Init()
123 {
124 }
125
126 bool wxFont::Create(const wxNativeFontInfo& info)
127 {
128 return Create(info.pointSize, info.family, info.style, info.weight,
129 info.underlined, info.faceName, info.encoding);
130 }
131
132 wxFont::wxFont(const wxString& fontdesc)
133 {
134 wxNativeFontInfo info;
135 if ( info.FromString(fontdesc) )
136 (void)Create(info);
137 }
138
139 bool wxFont::Create(int pointSize,
140 int family,
141 int style,
142 int weight,
143 bool underlined,
144 const wxString& faceName,
145 wxFontEncoding encoding)
146 {
147 UnRef();
148 m_refData = new wxFontRefData(pointSize, family, style, weight,
149 underlined, faceName, encoding);
150
151 RealizeResource();
152
153 return TRUE;
154 }
155
156 wxFont::~wxFont()
157 {
158 }
159
160 bool wxFont::RealizeResource()
161 {
162 M_FONTDATA->MacFindFont() ;
163 return TRUE;
164 }
165
166 void wxFont::SetEncoding(wxFontEncoding encoding)
167 {
168 Unshare();
169
170 M_FONTDATA->m_encoding = encoding;
171
172 RealizeResource();
173 }
174
175 void wxFont::Unshare()
176 {
177 // Don't change shared data
178 if (!m_refData)
179 {
180 m_refData = new wxFontRefData();
181 }
182 else
183 {
184 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
185 UnRef();
186 m_refData = ref;
187 }
188 }
189
190 void wxFont::SetPointSize(int pointSize)
191 {
192 Unshare();
193
194 M_FONTDATA->m_pointSize = pointSize;
195
196 RealizeResource();
197 }
198
199 void wxFont::SetFamily(int family)
200 {
201 Unshare();
202
203 M_FONTDATA->m_family = family;
204
205 RealizeResource();
206 }
207
208 void wxFont::SetStyle(int style)
209 {
210 Unshare();
211
212 M_FONTDATA->m_style = style;
213
214 RealizeResource();
215 }
216
217 void wxFont::SetWeight(int weight)
218 {
219 Unshare();
220
221 M_FONTDATA->m_weight = weight;
222
223 RealizeResource();
224 }
225
226 void wxFont::SetFaceName(const wxString& faceName)
227 {
228 Unshare();
229
230 M_FONTDATA->m_faceName = faceName;
231
232 RealizeResource();
233 }
234
235 void wxFont::SetUnderlined(bool underlined)
236 {
237 Unshare();
238
239 M_FONTDATA->m_underlined = underlined;
240
241 RealizeResource();
242 }
243
244 // ----------------------------------------------------------------------------
245 // accessors
246 // ----------------------------------------------------------------------------
247
248 int wxFont::GetPointSize() const
249 {
250 return M_FONTDATA->m_pointSize;
251 }
252
253 int wxFont::GetFamily() const
254 {
255 return M_FONTDATA->m_family;
256 }
257
258 int wxFont::GetStyle() const
259 {
260 return M_FONTDATA->m_style;
261 }
262
263 int wxFont::GetWeight() const
264 {
265 return M_FONTDATA->m_weight;
266 }
267
268 bool wxFont::GetUnderlined() const
269 {
270 return M_FONTDATA->m_underlined;
271 }
272
273 wxString wxFont::GetFaceName() const
274 {
275 wxString str;
276 if ( M_FONTDATA )
277 str = M_FONTDATA->m_faceName ;
278 return str;
279 }
280
281 wxFontEncoding wxFont::GetEncoding() const
282 {
283 return M_FONTDATA->m_encoding;
284 }
285