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