msvcrt/tests: Remove a space before a '\n'.
[wine/gsoc-2012-control.git] / dlls / gdiplus / stringformat.c
blob201201a866f5730a803d55c7d7c438e4e70510ce
1 /*
3 * Copyright (C) 2007 Google (Evan Stade)
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "wingdi.h"
25 #include "winnls.h"
27 #include "objbase.h"
29 #include "gdiplus.h"
30 #include "gdiplus_private.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
35 GpStatus WINGDIPAPI GdipCreateStringFormat(INT attr, LANGID lang,
36 GpStringFormat **format)
38 if(!format)
39 return InvalidParameter;
41 *format = GdipAlloc(sizeof(GpStringFormat));
42 if(!*format) return OutOfMemory;
44 (*format)->attr = attr;
45 (*format)->lang = lang;
46 (*format)->digitlang = LANG_NEUTRAL;
47 (*format)->trimming = StringTrimmingCharacter;
48 (*format)->digitsub = StringDigitSubstituteUser;
49 /* tabstops */
50 (*format)->tabcount = 0;
51 (*format)->firsttab = 0.0;
52 (*format)->tabs = NULL;
54 return Ok;
57 GpStatus WINGDIPAPI GdipDeleteStringFormat(GpStringFormat *format)
59 if(!format)
60 return InvalidParameter;
62 GdipFree(format->tabs);
63 GdipFree(format);
65 return Ok;
68 GpStatus WINGDIPAPI GdipStringFormatGetGenericDefault(GpStringFormat **format)
70 GpStatus stat;
72 if (!format)
73 return InvalidParameter;
75 stat = GdipCreateStringFormat(0, LANG_NEUTRAL, format);
76 if(stat != Ok)
77 return stat;
79 (*format)->align = StringAlignmentNear;
80 (*format)->vertalign = StringAlignmentNear;
82 return Ok;
85 GpStatus WINGDIPAPI GdipGetStringFormatAlign(GpStringFormat *format,
86 StringAlignment *align)
88 if(!format || !align)
89 return InvalidParameter;
91 *align = format->align;
93 return Ok;
96 GpStatus WINGDIPAPI GdipGetStringFormatDigitSubstitution(GDIPCONST GpStringFormat *format,
97 LANGID *language, StringDigitSubstitute *substitute)
99 if(!format)
100 return InvalidParameter;
102 if(language) *language = format->digitlang;
103 if(substitute) *substitute = format->digitsub;
105 return Ok;
108 GpStatus WINGDIPAPI GdipGetStringFormatFlags(GDIPCONST GpStringFormat* format,
109 INT* flags)
111 if (!(format && flags))
112 return InvalidParameter;
114 *flags = format->attr;
116 return Ok;
119 GpStatus WINGDIPAPI GdipGetStringFormatHotkeyPrefix(GDIPCONST GpStringFormat
120 *format, INT *hkpx)
122 if(!format || !hkpx)
123 return InvalidParameter;
125 *hkpx = (INT)format->hkprefix;
127 return Ok;
130 GpStatus WINGDIPAPI GdipGetStringFormatLineAlign(GpStringFormat *format,
131 StringAlignment *align)
133 if(!format || !align)
134 return InvalidParameter;
136 *align = format->vertalign;
138 return Ok;
141 GpStatus WINGDIPAPI GdipGetStringFormatMeasurableCharacterRangeCount(
142 GDIPCONST GpStringFormat* format, INT* count)
144 if (!(format && count))
145 return InvalidParameter;
147 FIXME("stub: %p %p\n", format, count);
149 return NotImplemented;
152 GpStatus WINGDIPAPI GdipGetStringFormatTabStopCount(GDIPCONST GpStringFormat *format,
153 INT *count)
155 if(!format || !count)
156 return InvalidParameter;
158 *count = format->tabcount;
160 return Ok;
163 GpStatus WINGDIPAPI GdipGetStringFormatTabStops(GDIPCONST GpStringFormat *format, INT count,
164 REAL *firsttab, REAL *tabs)
166 if(!format || !firsttab || !tabs)
167 return InvalidParameter;
169 /* native simply crashes on count < 0 */
170 if(count != 0)
171 memcpy(tabs, format->tabs, sizeof(REAL)*count);
173 *firsttab = format->firsttab;
175 return Ok;
178 GpStatus WINGDIPAPI GdipGetStringFormatTrimming(GpStringFormat *format,
179 StringTrimming *trimming)
181 if(!format || !trimming)
182 return InvalidParameter;
184 *trimming = format->trimming;
186 return Ok;
189 GpStatus WINGDIPAPI GdipSetStringFormatAlign(GpStringFormat *format,
190 StringAlignment align)
192 if(!format)
193 return InvalidParameter;
195 format->align = align;
197 return Ok;
200 /*FIXME: digit substitution actually not implemented, get/set only */
201 GpStatus WINGDIPAPI GdipSetStringFormatDigitSubstitution(GpStringFormat *format,
202 LANGID language, StringDigitSubstitute substitute)
204 if(!format)
205 return InvalidParameter;
207 format->digitlang = language;
208 format->digitsub = substitute;
210 return Ok;
213 GpStatus WINGDIPAPI GdipSetStringFormatHotkeyPrefix(GpStringFormat *format,
214 INT hkpx)
216 if(!format || hkpx < 0 || hkpx > 2)
217 return InvalidParameter;
219 format->hkprefix = (HotkeyPrefix) hkpx;
221 return Ok;
224 GpStatus WINGDIPAPI GdipSetStringFormatLineAlign(GpStringFormat *format,
225 StringAlignment align)
227 if(!format)
228 return InvalidParameter;
230 format->vertalign = align;
232 return Ok;
235 GpStatus WINGDIPAPI GdipSetStringFormatMeasurableCharacterRanges(GpStringFormat*
236 format, INT rangeCount, GDIPCONST CharacterRange* ranges)
238 if (!(format && rangeCount && ranges))
239 return InvalidParameter;
241 FIXME("stub: %p, %d, %p\n", format, rangeCount, ranges);
243 return NotImplemented;
246 GpStatus WINGDIPAPI GdipSetStringFormatTabStops(GpStringFormat *format, REAL firsttab,
247 INT count, GDIPCONST REAL *tabs)
249 if(!format || !tabs)
250 return InvalidParameter;
252 if(count > 0){
253 if(firsttab < 0.0) return NotImplemented;
254 /* first time allocation */
255 if(format->tabcount == 0){
256 format->tabs = GdipAlloc(sizeof(REAL)*count);
257 if(!format->tabs)
258 return OutOfMemory;
260 /* reallocation */
261 if((format->tabcount < count) && (format->tabcount > 0)){
262 REAL *ptr;
263 ptr = HeapReAlloc(GetProcessHeap(), 0, format->tabs, sizeof(REAL)*count);
264 if(!ptr)
265 return OutOfMemory;
266 format->tabs = ptr;
268 format->firsttab = firsttab;
269 format->tabcount = count;
270 memcpy(format->tabs, tabs, sizeof(REAL)*count);
273 return Ok;
276 GpStatus WINGDIPAPI GdipSetStringFormatTrimming(GpStringFormat *format,
277 StringTrimming trimming)
279 if(!format)
280 return InvalidParameter;
282 format->trimming = trimming;
284 return Ok;
287 GpStatus WINGDIPAPI GdipSetStringFormatFlags(GDIPCONST GpStringFormat *format, INT flags)
289 FIXME("format (%p) flags (%d)\n", format, flags);
291 return Ok;
294 GpStatus WINGDIPAPI GdipCloneStringFormat(GDIPCONST GpStringFormat *format, GpStringFormat **newFormat)
296 if(!format || !newFormat)
297 return InvalidParameter;
299 *newFormat = GdipAlloc(sizeof(GpStringFormat));
300 if(!*newFormat) return OutOfMemory;
302 **newFormat = *format;
304 if(format->tabcount > 0){
305 (*newFormat)->tabs = GdipAlloc(sizeof(REAL) * format->tabcount);
306 if(!(*newFormat)->tabs){
307 GdipFree(*newFormat);
308 return OutOfMemory;
310 memcpy((*newFormat)->tabs, format->tabs, sizeof(REAL) * format->tabcount);
312 else
313 (*newFormat)->tabs = NULL;
315 TRACE("%p %p\n",format,newFormat);
317 return Ok;
320 GpStatus WINGDIPAPI GdipStringFormatGetGenericTypographic(GpStringFormat **format)
322 GpStatus stat;
324 if(!format)
325 return InvalidParameter;
327 stat = GdipCreateStringFormat(StringFormatFlagsNoFitBlackBox |
328 StringFormatFlagsLineLimit |
329 StringFormatFlagsNoClip, LANG_NEUTRAL, format);
330 if(stat != Ok)
331 return stat;
333 (*format)->digitlang = LANG_NEUTRAL;
334 (*format)->digitsub = StringDigitSubstituteUser;
335 (*format)->trimming = StringTrimmingNone;
336 (*format)->hkprefix = HotkeyPrefixNone;
337 (*format)->align = StringAlignmentNear;
338 (*format)->vertalign = StringAlignmentNear;
340 return Ok;