]>
Commit | Line | Data |
---|---|---|
7c78e7c7 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: font.cpp | |
01b2eeec KB |
3 | // Purpose: wxFont class |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
7c78e7c7 RR |
9 | // Licence: wxWindows licence |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "font.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/font.h" | |
7c78e7c7 RR |
17 | |
18 | IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) | |
19 | ||
01b2eeec | 20 | wxFontRefData::wxFontRefData() |
7c78e7c7 | 21 | { |
01b2eeec KB |
22 | m_style = 0; |
23 | m_pointSize = 0; | |
24 | m_family = 0; | |
25 | m_style = 0; | |
26 | m_weight = 0; | |
27 | m_underlined = 0; | |
28 | m_faceName = ""; | |
29 | /* TODO | |
30 | m_hFont = 0; | |
31 | */ | |
32 | } | |
7c78e7c7 | 33 | |
01b2eeec | 34 | wxFontRefData::wxFontRefData(const wxFontRefData& data) |
7c78e7c7 | 35 | { |
01b2eeec KB |
36 | m_style = data.m_style; |
37 | m_pointSize = data.m_pointSize; | |
38 | m_family = data.m_family; | |
39 | m_style = data.m_style; | |
40 | m_weight = data.m_weight; | |
41 | m_underlined = data.m_underlined; | |
42 | m_faceName = data.m_faceName; | |
43 | /* TODO | |
44 | m_hFont = 0; | |
45 | */ | |
46 | } | |
7c78e7c7 | 47 | |
01b2eeec | 48 | wxFontRefData::~wxFontRefData() |
7c78e7c7 | 49 | { |
01b2eeec KB |
50 | // TODO: delete font data |
51 | } | |
7c78e7c7 | 52 | |
01b2eeec | 53 | wxFont::wxFont() |
7c78e7c7 | 54 | { |
01b2eeec KB |
55 | if ( wxTheFontList ) |
56 | wxTheFontList->Append(this); | |
57 | } | |
7c78e7c7 | 58 | |
01b2eeec KB |
59 | wxFont::wxFont(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName) |
60 | { | |
61 | Create(pointSize, family, style, weight, underlined, faceName); | |
7c78e7c7 | 62 | |
01b2eeec KB |
63 | if ( wxTheFontList ) |
64 | wxTheFontList->Append(this); | |
65 | } | |
7c78e7c7 | 66 | |
01b2eeec | 67 | bool wxFont::Create(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName) |
7c78e7c7 | 68 | { |
01b2eeec KB |
69 | UnRef(); |
70 | m_refData = new wxFontRefData; | |
7c78e7c7 | 71 | |
01b2eeec KB |
72 | M_FONTDATA->m_family = family; |
73 | M_FONTDATA->m_style = style; | |
74 | M_FONTDATA->m_weight = weight; | |
75 | M_FONTDATA->m_pointSize = pointSize; | |
76 | M_FONTDATA->m_underlined = underlined; | |
77 | M_FONTDATA->m_faceName = faceName; | |
7c78e7c7 | 78 | |
01b2eeec | 79 | RealizeResource(); |
7c78e7c7 | 80 | |
01b2eeec KB |
81 | return TRUE; |
82 | } | |
7c78e7c7 | 83 | |
01b2eeec | 84 | wxFont::~wxFont() |
7c78e7c7 | 85 | { |
01b2eeec KB |
86 | if (wxTheFontList) |
87 | wxTheFontList->DeleteObject(this); | |
88 | } | |
7c78e7c7 | 89 | |
01b2eeec | 90 | bool wxFont::RealizeResource() |
7c78e7c7 | 91 | { |
01b2eeec KB |
92 | // TODO: create the font (if there is a native font object) |
93 | return FALSE; | |
94 | } | |
7c78e7c7 | 95 | |
01b2eeec | 96 | void wxFont::Unshare() |
7c78e7c7 | 97 | { |
01b2eeec KB |
98 | // Don't change shared data |
99 | if (!m_refData) | |
100 | { | |
101 | m_refData = new wxFontRefData(); | |
102 | } | |
103 | else | |
104 | { | |
105 | wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData); | |
106 | UnRef(); | |
107 | m_refData = ref; | |
108 | } | |
109 | } | |
7c78e7c7 | 110 | |
01b2eeec | 111 | void wxFont::SetPointSize(int pointSize) |
7c78e7c7 | 112 | { |
01b2eeec | 113 | Unshare(); |
7c78e7c7 | 114 | |
01b2eeec | 115 | M_FONTDATA->m_pointSize = pointSize; |
7c78e7c7 | 116 | |
01b2eeec KB |
117 | RealizeResource(); |
118 | } | |
7c78e7c7 | 119 | |
01b2eeec | 120 | void wxFont::SetFamily(int family) |
7c78e7c7 | 121 | { |
01b2eeec KB |
122 | Unshare(); |
123 | ||
124 | M_FONTDATA->m_family = family; | |
7c78e7c7 | 125 | |
01b2eeec KB |
126 | RealizeResource(); |
127 | } | |
128 | ||
129 | void wxFont::SetStyle(int style) | |
7c78e7c7 | 130 | { |
01b2eeec KB |
131 | Unshare(); |
132 | ||
133 | M_FONTDATA->m_style = style; | |
134 | ||
135 | RealizeResource(); | |
136 | } | |
7c78e7c7 | 137 | |
01b2eeec | 138 | void wxFont::SetWeight(int weight) |
7c78e7c7 | 139 | { |
01b2eeec | 140 | Unshare(); |
7c78e7c7 | 141 | |
01b2eeec KB |
142 | M_FONTDATA->m_weight = weight; |
143 | ||
144 | RealizeResource(); | |
145 | } | |
146 | ||
147 | void wxFont::SetFaceName(const wxString& faceName) | |
7c78e7c7 | 148 | { |
01b2eeec KB |
149 | Unshare(); |
150 | ||
151 | M_FONTDATA->m_faceName = faceName; | |
7c78e7c7 | 152 | |
01b2eeec KB |
153 | RealizeResource(); |
154 | } | |
155 | ||
156 | void wxFont::SetUnderlined(bool underlined) | |
7c78e7c7 | 157 | { |
01b2eeec KB |
158 | Unshare(); |
159 | ||
160 | M_FONTDATA->m_underlined = underlined; | |
161 | ||
162 | RealizeResource(); | |
163 | } | |
7c78e7c7 | 164 | |
01b2eeec | 165 | wxString wxFont::GetFamilyString() const |
7c78e7c7 | 166 | { |
01b2eeec KB |
167 | wxString fam(""); |
168 | switch (GetFamily()) | |
169 | { | |
170 | case wxDECORATIVE: | |
171 | fam = "wxDECORATIVE"; | |
172 | break; | |
173 | case wxROMAN: | |
174 | fam = "wxROMAN"; | |
175 | break; | |
176 | case wxSCRIPT: | |
177 | fam = "wxSCRIPT"; | |
178 | break; | |
179 | case wxSWISS: | |
180 | fam = "wxSWISS"; | |
181 | break; | |
182 | case wxMODERN: | |
183 | fam = "wxMODERN"; | |
184 | break; | |
185 | case wxTELETYPE: | |
186 | fam = "wxTELETYPE"; | |
187 | break; | |
188 | default: | |
189 | fam = "wxDEFAULT"; | |
190 | break; | |
191 | } | |
192 | return fam; | |
193 | } | |
194 | ||
195 | /* New font system */ | |
196 | wxString wxFont::GetFaceName() const | |
197 | { | |
198 | wxString str(""); | |
199 | if (M_FONTDATA) | |
200 | str = M_FONTDATA->m_faceName ; | |
201 | return str; | |
202 | } | |
203 | ||
204 | wxString wxFont::GetStyleString() const | |
205 | { | |
206 | wxString styl(""); | |
207 | switch (GetStyle()) | |
208 | { | |
209 | case wxITALIC: | |
210 | styl = "wxITALIC"; | |
211 | break; | |
212 | case wxSLANT: | |
213 | styl = "wxSLANT"; | |
214 | break; | |
215 | default: | |
216 | styl = "wxNORMAL"; | |
217 | break; | |
218 | } | |
219 | return styl; | |
220 | } | |
221 | ||
222 | wxString wxFont::GetWeightString() const | |
223 | { | |
224 | wxString w(""); | |
225 | switch (GetWeight()) | |
226 | { | |
227 | case wxBOLD: | |
228 | w = "wxBOLD"; | |
229 | break; | |
230 | case wxLIGHT: | |
231 | w = "wxLIGHT"; | |
232 | break; | |
233 | default: | |
234 | w = "wxNORMAL"; | |
235 | break; | |
236 | } | |
237 | return w; | |
238 | } | |
239 |