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