Move wxCocoa's wxFontRefData from the header to the implementation file.
[wxWidgets.git] / src / cocoa / font.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        src/cocoa/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 #include "wx/wxprec.h"
13
14 #include "wx/font.h"
15
16 #ifndef WX_PRECOMP
17     #include "wx/string.h"
18     #include "wx/gdicmn.h"
19 #endif
20
21 #include "wx/encinfo.h"
22
23 class WXDLLEXPORT wxFontRefData: public wxGDIRefData
24 {
25     friend class WXDLLIMPEXP_FWD_CORE wxFont;
26 public:
27     wxFontRefData()
28         : m_fontId(0)
29         , m_pointSize(10)
30         , m_family(wxDEFAULT)
31         , m_style(wxNORMAL)
32         , m_weight(wxNORMAL)
33         , m_underlined(FALSE)
34         , m_faceName(wxT("Geneva"))
35         , m_encoding(wxFONTENCODING_DEFAULT)
36     {
37         Init(10, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE,
38              wxT("Geneva"), wxFONTENCODING_DEFAULT);
39     }
40
41     wxFontRefData(const wxFontRefData& data)
42         : wxGDIRefData()
43         , m_fontId(data.m_fontId)
44         , m_pointSize(data.m_pointSize)
45         , m_family(data.m_family)
46         , m_style(data.m_style)
47         , m_weight(data.m_weight)
48         , m_underlined(data.m_underlined)
49         , m_faceName(data.m_faceName)
50         , m_encoding(data.m_encoding)
51     {
52         Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight,
53              data.m_underlined, data.m_faceName, data.m_encoding);
54     }
55
56     wxFontRefData(int size,
57                   int family,
58                   int style,
59                   int weight,
60                   bool underlined,
61                   const wxString& faceName,
62                   wxFontEncoding encoding)
63         : m_fontId(0)
64         , m_pointSize(size)
65         , m_family(family)
66         , m_style(style)
67         , m_weight(weight)
68         , m_underlined(underlined)
69         , m_faceName(faceName)
70         , m_encoding(encoding)
71     {
72         Init(size, family, style, weight, underlined, faceName, encoding);
73     }
74
75     virtual ~wxFontRefData();
76 protected:
77     // common part of all ctors
78     void Init(int size,
79               int family,
80               int style,
81               int weight,
82               bool underlined,
83               const wxString& faceName,
84               wxFontEncoding encoding);
85
86     // font characterstics
87     int            m_fontId;
88     int            m_pointSize;
89     int            m_family;
90     int            m_style;
91     int            m_weight;
92     bool           m_underlined;
93     wxString       m_faceName;
94     wxFontEncoding m_encoding;
95     
96 public:
97 };
98 IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
99
100 void wxFontRefData::Init(int size, int family, int style, int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding)
101 {
102     m_family = family;
103     m_style = style;
104     m_weight = weight;
105     m_underlined = underlined;
106     m_faceName = faceName;
107     m_encoding = encoding;
108 }
109
110 wxFontRefData::~wxFontRefData()
111 {
112     // TODO: delete font data
113 }
114
115 #define M_FONTDATA ((wxFontRefData*)m_refData)
116
117 bool wxFont::Create(const wxNativeFontInfo&)
118 {
119     return false;
120 }
121
122 void wxFont::SetEncoding(wxFontEncoding)
123 {
124 }
125
126 wxFontEncoding wxFont::GetEncoding() const
127 {
128     return wxFontEncoding();
129 }
130
131 int wxFont::GetPointSize() const
132 {
133     return 0;
134 }
135
136 bool wxFont::GetUnderlined() const
137 {
138     if(M_FONTDATA)
139         return M_FONTDATA->m_underlined;
140     else
141         return false;
142 }
143
144 int wxFont::GetStyle() const
145 {
146     return 0;
147 }
148
149 int wxFont::GetFamily() const
150 {
151     return 0;
152 }
153
154 int wxFont::GetWeight() const
155 {
156     return 0;
157 }
158
159 const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
160 {
161     return NULL;
162 }
163
164 void wxGetNativeFontEncoding(wxFontEncoding, wxNativeEncodingInfo*);
165
166 bool wxFont::Create(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding)
167 {
168     UnRef();
169     m_refData = new wxFontRefData;
170
171     M_FONTDATA->m_family = family;
172     M_FONTDATA->m_style = style;
173     M_FONTDATA->m_weight = weight;
174     M_FONTDATA->m_pointSize = pointSize;
175     M_FONTDATA->m_underlined = underlined;
176     M_FONTDATA->m_faceName = faceName;
177
178     RealizeResource();
179
180     return true;
181 }
182
183 wxFont::~wxFont()
184 {
185 }
186
187 bool wxFont::RealizeResource()
188 {
189     // TODO: create the font (if there is a native font object)
190     return false;
191 }
192
193 void wxFont::Unshare()
194 {
195     // Don't change shared data
196     if (!m_refData)
197     {
198         m_refData = new wxFontRefData();
199     }
200     else
201     {
202         wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
203         UnRef();
204         m_refData = ref;
205     }
206 }
207
208 void wxFont::SetPointSize(int pointSize)
209 {
210     Unshare();
211
212     M_FONTDATA->m_pointSize = pointSize;
213
214     RealizeResource();
215 }
216
217 void wxFont::SetFamily(int family)
218 {
219     Unshare();
220
221     M_FONTDATA->m_family = family;
222
223     RealizeResource();
224 }
225
226 void wxFont::SetStyle(int style)
227 {
228     Unshare();
229
230     M_FONTDATA->m_style = style;
231
232     RealizeResource();
233 }
234
235 void wxFont::SetWeight(int weight)
236 {
237     Unshare();
238
239     M_FONTDATA->m_weight = weight;
240
241     RealizeResource();
242 }
243
244 bool wxFont::SetFaceName(const wxString& faceName)
245 {
246     Unshare();
247
248     M_FONTDATA->m_faceName = faceName;
249
250     RealizeResource();
251
252     return wxFontBase::SetFaceName(faceName);
253 }
254
255 void wxFont::SetUnderlined(bool underlined)
256 {
257     Unshare();
258
259     M_FONTDATA->m_underlined = underlined;
260
261     RealizeResource();
262 }
263
264 /* New font system */
265 wxString wxFont::GetFaceName() const
266 {
267     wxString str;
268     if (M_FONTDATA)
269         str = M_FONTDATA->m_faceName ;
270     return str;
271 }
272
273 // vim:sts=4:sw=4:et