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