Reactos
1/*
2 * GdiPlusStringFormat.h
3 *
4 * Windows GDI+
5 *
6 * This file is part of the w32api package.
7 *
8 * THIS SOFTWARE IS NOT COPYRIGHTED
9 *
10 * This source code is offered for use in the public domain. You may
11 * use, modify or distribute it freely.
12 *
13 * This code is distributed in the hope that it will be useful but
14 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
15 * DISCLAIMED. This includes but is not limited to warranties of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 */
18
19#ifndef _GDIPLUSSTRINGFORMAT_H
20#define _GDIPLUSSTRINGFORMAT_H
21
22class StringFormat : public GdiplusBase
23{
24 public:
25 StringFormat(INT formatFlags = 0, LANGID language = LANG_NEUTRAL) : nativeFormat(NULL)
26 {
27 lastStatus = DllExports::GdipCreateStringFormat(formatFlags, language, &nativeFormat);
28 }
29
30 StringFormat(const StringFormat *format) : nativeFormat(NULL)
31 {
32 lastStatus = DllExports::GdipCloneStringFormat(format ? format->nativeFormat : NULL, &nativeFormat);
33 }
34
35 StringFormat *
36 Clone() const
37 {
38 GpStringFormat *cloneFormat = NULL;
39
40 lastStatus = DllExports::GdipCloneStringFormat(nativeFormat, &cloneFormat);
41 if (lastStatus != Ok)
42 return NULL;
43
44 StringFormat *newFormat = new StringFormat(cloneFormat, lastStatus);
45 if (!newFormat)
46 DllExports::GdipDeleteStringFormat(cloneFormat);
47 return newFormat;
48 }
49
50 ~StringFormat()
51 {
52 DllExports::GdipDeleteStringFormat(nativeFormat);
53 }
54
55 static const StringFormat *
56 GenericDefault()
57 {
58 return NULL; // FIXME
59 }
60
61 static const StringFormat *
62 GenericTypographic()
63 {
64 return NULL; // FIXME
65 }
66
67 StringAlignment
68 GetAlignment() const
69 {
70 StringAlignment alignment;
71 SetStatus(DllExports::GdipGetStringFormatAlign(nativeFormat, &alignment));
72 return alignment;
73 }
74
75 LANGID
76 GetDigitSubstitutionLanguage() const
77 {
78 LANGID language;
79 SetStatus(DllExports::GdipGetStringFormatDigitSubstitution(nativeFormat, &language, NULL));
80 return language;
81 }
82
83 StringDigitSubstitute
84 GetDigitSubstitutionMethod() const
85 {
86 StringDigitSubstitute substitute;
87 SetStatus(DllExports::GdipGetStringFormatDigitSubstitution(nativeFormat, NULL, &substitute));
88 return substitute;
89 }
90
91 INT
92 GetFormatFlags() const
93 {
94 INT flags;
95 SetStatus(DllExports::GdipGetStringFormatFlags(nativeFormat, &flags));
96 return flags;
97 }
98
99 HotkeyPrefix
100 GetHotkeyPrefix() const
101 {
102 HotkeyPrefix hotkeyPrefix;
103 SetStatus(DllExports::GdipGetStringFormatHotkeyPrefix(nativeFormat, reinterpret_cast<INT *>(&hotkeyPrefix)));
104 return hotkeyPrefix;
105 }
106
107 Status
108 GetLastStatus() const
109 {
110 return lastStatus;
111 }
112
113 StringAlignment
114 GetLineAlignment() const
115 {
116 StringAlignment alignment;
117 SetStatus(DllExports::GdipGetStringFormatLineAlign(nativeFormat, &alignment));
118 return alignment;
119 }
120
121 INT
122 GetMeasurableCharacterRangeCount() const
123 {
124 INT count;
125 SetStatus(DllExports::GdipGetStringFormatMeasurableCharacterRangeCount(nativeFormat, &count));
126 return count;
127 }
128
129 INT
130 GetTabStopCount() const
131 {
132 INT count;
133 SetStatus(DllExports::GdipGetStringFormatTabStopCount(nativeFormat, &count));
134 return count;
135 }
136
137 Status
138 GetTabStops(INT count, REAL *firstTabOffset, REAL *tabStops) const
139 {
140 return SetStatus(DllExports::GdipGetStringFormatTabStops(nativeFormat, count, firstTabOffset, tabStops));
141 }
142
143 StringTrimming
144 GetTrimming() const
145 {
146 StringTrimming trimming;
147 SetStatus(DllExports::GdipGetStringFormatTrimming(nativeFormat, &trimming));
148 return trimming;
149 }
150
151 Status
152 SetAlignment(StringAlignment align)
153 {
154 return SetStatus(DllExports::GdipSetStringFormatAlign(nativeFormat, align));
155 }
156
157 Status
158 SetDigitSubstitution(LANGID language, StringDigitSubstitute substitute)
159 {
160 return SetStatus(DllExports::GdipSetStringFormatDigitSubstitution(nativeFormat, language, substitute));
161 }
162
163 Status
164 SetFormatFlags(INT flags)
165 {
166 return SetStatus(DllExports::GdipSetStringFormatFlags(nativeFormat, flags));
167 }
168
169 Status
170 SetHotkeyPrefix(HotkeyPrefix hotkeyPrefix)
171 {
172 return SetStatus(DllExports::GdipSetStringFormatHotkeyPrefix(nativeFormat, INT(hotkeyPrefix)));
173 }
174
175 Status
176 SetLineAlignment(StringAlignment align)
177 {
178 return SetStatus(DllExports::GdipSetStringFormatLineAlign(nativeFormat, align));
179 }
180
181 Status
182 SetMeasurableCharacterRanges(INT rangeCount, const CharacterRange *ranges)
183 {
184 return SetStatus(DllExports::GdipSetStringFormatMeasurableCharacterRanges(nativeFormat, rangeCount, ranges));
185 }
186
187 Status
188 SetTabStops(REAL firstTabOffset, INT count, const REAL *tabStops)
189 {
190 return SetStatus(DllExports::GdipSetStringFormatTabStops(nativeFormat, firstTabOffset, count, tabStops));
191 }
192
193 Status
194 SetTrimming(StringTrimming trimming)
195 {
196 return SetStatus(DllExports::GdipSetStringFormatTrimming(nativeFormat, trimming));
197 }
198
199 protected:
200 GpStringFormat *nativeFormat;
201 mutable Status lastStatus;
202
203 StringFormat(GpStringFormat *format, Status status) : nativeFormat(format), lastStatus(status)
204 {
205 }
206
207 Status
208 SetStatus(Status status) const
209 {
210 if (status != Ok)
211 lastStatus = status;
212 return status;
213 }
214
215 // get native
216 friend inline GpStringFormat *&
217 getNat(const StringFormat *sf)
218 {
219 return const_cast<StringFormat *>(sf)->nativeFormat;
220 }
221};
222
223#endif /* _GDIPLUSSTRINGFORMAT_H */