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