include: Add STORAGE_HOTPLUG_INFO structure.
[wine.git] / dlls / gdiplus / stringformat.c
blobb220dfc27765059036250900c905a71de00dcba8
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 const GpStringFormat default_drawstring_format =
38 LANG_NEUTRAL,
39 LANG_NEUTRAL,
40 StringAlignmentNear,
41 StringTrimmingCharacter,
42 HotkeyPrefixNone,
43 StringAlignmentNear,
44 StringDigitSubstituteUser,
46 0.0,
47 NULL,
48 NULL,
50 FALSE
53 static GpStringFormat generic_default_format;
54 static GpStringFormat generic_typographic_format;
56 void init_generic_string_formats(void)
58 memcpy(&generic_default_format, &default_drawstring_format, sizeof(generic_default_format));
60 memcpy(&generic_typographic_format, &default_drawstring_format, sizeof(generic_typographic_format));
61 generic_typographic_format.attr = StringFormatFlagsNoFitBlackBox | StringFormatFlagsLineLimit |
62 StringFormatFlagsNoClip;
63 generic_typographic_format.trimming = StringTrimmingNone;
64 generic_typographic_format.generic_typographic = TRUE;
67 void free_generic_string_formats(void)
69 free(generic_default_format.character_ranges);
70 free(generic_default_format.tabs);
72 free(generic_typographic_format.character_ranges);
73 free(generic_typographic_format.tabs);
76 GpStatus WINGDIPAPI GdipCreateStringFormat(INT attr, LANGID lang,
77 GpStringFormat **format)
79 TRACE("(%i, %x, %p)\n", attr, lang, format);
81 if(!format)
82 return InvalidParameter;
84 *format = calloc(1, sizeof(GpStringFormat));
85 if(!*format) return OutOfMemory;
87 (*format)->attr = attr;
88 (*format)->lang = lang;
89 (*format)->digitlang = LANG_NEUTRAL;
90 (*format)->trimming = StringTrimmingCharacter;
91 (*format)->digitsub = StringDigitSubstituteUser;
92 (*format)->character_ranges = NULL;
93 (*format)->range_count = 0;
94 (*format)->generic_typographic = FALSE;
95 /* tabstops */
96 (*format)->tabcount = 0;
97 (*format)->firsttab = 0.0;
98 (*format)->tabs = NULL;
100 TRACE("<-- %p\n", *format);
102 return Ok;
105 GpStatus WINGDIPAPI GdipDeleteStringFormat(GpStringFormat *format)
107 if(!format)
108 return InvalidParameter;
110 if (format == &generic_default_format || format == &generic_typographic_format)
111 return Ok;
113 free(format->character_ranges);
114 free(format->tabs);
115 free(format);
117 return Ok;
120 GpStatus WINGDIPAPI GdipStringFormatGetGenericDefault(GpStringFormat **format)
122 if (!format)
123 return InvalidParameter;
125 *format = &generic_default_format;
127 return Ok;
130 GpStatus WINGDIPAPI GdipGetStringFormatAlign(GpStringFormat *format,
131 StringAlignment *align)
133 if(!format || !align)
134 return InvalidParameter;
136 *align = format->align;
138 return Ok;
141 GpStatus WINGDIPAPI GdipGetStringFormatDigitSubstitution(GDIPCONST GpStringFormat *format,
142 LANGID *language, StringDigitSubstitute *substitute)
144 if(!format)
145 return InvalidParameter;
147 if(language) *language = format->digitlang;
148 if(substitute) *substitute = format->digitsub;
150 return Ok;
153 GpStatus WINGDIPAPI GdipGetStringFormatFlags(GDIPCONST GpStringFormat* format,
154 INT* flags)
156 if (!(format && flags))
157 return InvalidParameter;
159 *flags = format->attr;
161 return Ok;
164 GpStatus WINGDIPAPI GdipGetStringFormatHotkeyPrefix(GDIPCONST GpStringFormat
165 *format, INT *hkpx)
167 if(!format || !hkpx)
168 return InvalidParameter;
170 *hkpx = (INT)format->hkprefix;
172 return Ok;
175 GpStatus WINGDIPAPI GdipGetStringFormatLineAlign(GpStringFormat *format,
176 StringAlignment *align)
178 if(!format || !align)
179 return InvalidParameter;
181 *align = format->line_align;
183 return Ok;
186 GpStatus WINGDIPAPI GdipGetStringFormatMeasurableCharacterRangeCount(
187 GDIPCONST GpStringFormat *format, INT *count)
189 if (!(format && count))
190 return InvalidParameter;
192 TRACE("%p %p\n", format, count);
194 *count = format->range_count;
196 return Ok;
199 GpStatus WINGDIPAPI GdipGetStringFormatTabStopCount(GDIPCONST GpStringFormat *format,
200 INT *count)
202 if(!format || !count)
203 return InvalidParameter;
205 *count = format->tabcount;
207 return Ok;
210 GpStatus WINGDIPAPI GdipGetStringFormatTabStops(GDIPCONST GpStringFormat *format, INT count,
211 REAL *firsttab, REAL *tabs)
213 if(!format || !firsttab || !tabs)
214 return InvalidParameter;
216 /* native simply crashes on count < 0 */
217 if(count != 0)
218 memcpy(tabs, format->tabs, sizeof(REAL)*count);
220 *firsttab = format->firsttab;
222 return Ok;
225 GpStatus WINGDIPAPI GdipGetStringFormatTrimming(GpStringFormat *format,
226 StringTrimming *trimming)
228 if(!format || !trimming)
229 return InvalidParameter;
231 *trimming = format->trimming;
233 return Ok;
236 GpStatus WINGDIPAPI GdipSetStringFormatAlign(GpStringFormat *format,
237 StringAlignment align)
239 TRACE("(%p, %i)\n", format, align);
241 if(!format)
242 return InvalidParameter;
244 format->align = align;
246 return Ok;
249 /*FIXME: digit substitution actually not implemented, get/set only */
250 GpStatus WINGDIPAPI GdipSetStringFormatDigitSubstitution(GpStringFormat *format,
251 LANGID language, StringDigitSubstitute substitute)
253 TRACE("(%p, %x, %i)\n", format, language, substitute);
255 if(!format)
256 return InvalidParameter;
258 format->digitlang = language;
259 format->digitsub = substitute;
261 return Ok;
264 GpStatus WINGDIPAPI GdipSetStringFormatHotkeyPrefix(GpStringFormat *format,
265 INT hkpx)
267 TRACE("(%p, %i)\n", format, hkpx);
269 if(!format || hkpx < 0 || hkpx > 2)
270 return InvalidParameter;
272 format->hkprefix = (HotkeyPrefix) hkpx;
274 return Ok;
277 GpStatus WINGDIPAPI GdipSetStringFormatLineAlign(GpStringFormat *format,
278 StringAlignment align)
280 TRACE("(%p, %i)\n", format, align);
282 if(!format)
283 return InvalidParameter;
285 format->line_align = align;
287 return Ok;
290 GpStatus WINGDIPAPI GdipSetStringFormatMeasurableCharacterRanges(
291 GpStringFormat *format, INT rangeCount, GDIPCONST CharacterRange *ranges)
293 CharacterRange *new_ranges;
295 if (!(format && ranges))
296 return InvalidParameter;
298 TRACE("%p, %d, %p\n", format, rangeCount, ranges);
300 new_ranges = malloc(rangeCount * sizeof(CharacterRange));
301 if (!new_ranges)
302 return OutOfMemory;
304 free(format->character_ranges);
305 format->character_ranges = new_ranges;
306 memcpy(format->character_ranges, ranges, sizeof(CharacterRange) * rangeCount);
307 format->range_count = rangeCount;
309 return Ok;
312 GpStatus WINGDIPAPI GdipSetStringFormatTabStops(GpStringFormat *format, REAL firsttab,
313 INT count, GDIPCONST REAL *tabs)
315 TRACE("(%p, %0.2f, %i, %p)\n", format, firsttab, count, tabs);
317 if(!format || !tabs)
318 return InvalidParameter;
320 if(count > 0){
321 if(firsttab < 0.0) return NotImplemented;
322 if(format->tabcount < count){
323 REAL *ptr;
324 ptr = realloc(format->tabs, sizeof(REAL) * count);
325 if(!ptr)
326 return OutOfMemory;
327 format->tabs = ptr;
329 format->firsttab = firsttab;
330 format->tabcount = count;
331 memcpy(format->tabs, tabs, sizeof(REAL)*count);
334 return Ok;
337 GpStatus WINGDIPAPI GdipSetStringFormatTrimming(GpStringFormat *format,
338 StringTrimming trimming)
340 TRACE("(%p, %i)\n", format, trimming);
342 if(!format)
343 return InvalidParameter;
345 format->trimming = trimming;
347 return Ok;
350 GpStatus WINGDIPAPI GdipSetStringFormatFlags(GpStringFormat *format, INT flags)
352 TRACE("(%p, %x)\n", format, flags);
354 if(!format)
355 return InvalidParameter;
357 format->attr = flags;
359 return Ok;
362 GpStatus WINGDIPAPI GdipCloneStringFormat(GDIPCONST GpStringFormat *format, GpStringFormat **newFormat)
364 if(!format || !newFormat)
365 return InvalidParameter;
367 *newFormat = malloc(sizeof(GpStringFormat));
368 if(!*newFormat) return OutOfMemory;
370 **newFormat = *format;
372 if(format->tabcount > 0){
373 (*newFormat)->tabs = malloc(sizeof(REAL) * format->tabcount);
374 if(!(*newFormat)->tabs){
375 free(*newFormat);
376 return OutOfMemory;
378 memcpy((*newFormat)->tabs, format->tabs, sizeof(REAL) * format->tabcount);
380 else
381 (*newFormat)->tabs = NULL;
383 if(format->range_count > 0){
384 (*newFormat)->character_ranges = malloc(sizeof(CharacterRange) * format->range_count);
385 if(!(*newFormat)->character_ranges){
386 free((*newFormat)->tabs);
387 free(*newFormat);
388 return OutOfMemory;
390 memcpy((*newFormat)->character_ranges, format->character_ranges,
391 sizeof(CharacterRange) * format->range_count);
393 else
394 (*newFormat)->character_ranges = NULL;
396 TRACE("%p %p\n",format,newFormat);
398 return Ok;
401 GpStatus WINGDIPAPI GdipStringFormatGetGenericTypographic(GpStringFormat **format)
403 if(!format)
404 return InvalidParameter;
406 *format = &generic_typographic_format;
408 TRACE("%p => %p\n", format, *format);
410 return Ok;