ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

stringformat.c
Go to the documentation of this file.
00001 /*
00002  *
00003  * Copyright (C) 2007 Google (Evan Stade)
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00018  */
00019 
00020 #include <stdarg.h>
00021 
00022 #include "windef.h"
00023 #include "winbase.h"
00024 #include "wingdi.h"
00025 #include "winnls.h"
00026 
00027 #include "objbase.h"
00028 
00029 #include "gdiplus.h"
00030 #include "gdiplus_private.h"
00031 #include "wine/debug.h"
00032 
00033 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
00034 
00035 GpStatus WINGDIPAPI GdipCreateStringFormat(INT attr, LANGID lang,
00036     GpStringFormat **format)
00037 {
00038     TRACE("(%i, %x, %p)\n", attr, lang, format);
00039 
00040     if(!format)
00041         return InvalidParameter;
00042 
00043     *format = GdipAlloc(sizeof(GpStringFormat));
00044     if(!*format)   return OutOfMemory;
00045 
00046     (*format)->attr = attr;
00047     (*format)->lang = lang;
00048     (*format)->digitlang = LANG_NEUTRAL;
00049     (*format)->trimming = StringTrimmingCharacter;
00050     (*format)->digitsub = StringDigitSubstituteUser;
00051     (*format)->character_ranges = NULL;
00052     (*format)->range_count = 0;
00053     /* tabstops */
00054     (*format)->tabcount = 0;
00055     (*format)->firsttab = 0.0;
00056     (*format)->tabs = NULL;
00057 
00058     TRACE("<-- %p\n", *format);
00059 
00060     return Ok;
00061 }
00062 
00063 GpStatus WINGDIPAPI GdipDeleteStringFormat(GpStringFormat *format)
00064 {
00065     if(!format)
00066         return InvalidParameter;
00067 
00068     GdipFree(format->character_ranges);
00069     GdipFree(format->tabs);
00070     GdipFree(format);
00071 
00072     return Ok;
00073 }
00074 
00075 GpStatus WINGDIPAPI GdipStringFormatGetGenericDefault(GpStringFormat **format)
00076 {
00077     GpStatus stat;
00078 
00079     if (!format)
00080         return InvalidParameter;
00081 
00082     stat = GdipCreateStringFormat(0, LANG_NEUTRAL, format);
00083     if(stat != Ok)
00084         return stat;
00085 
00086     (*format)->align     = StringAlignmentNear;
00087     (*format)->vertalign = StringAlignmentNear;
00088 
00089     return Ok;
00090 }
00091 
00092 GpStatus WINGDIPAPI GdipGetStringFormatAlign(GpStringFormat *format,
00093     StringAlignment *align)
00094 {
00095     if(!format || !align)
00096         return InvalidParameter;
00097 
00098     *align = format->align;
00099 
00100     return Ok;
00101 }
00102 
00103 GpStatus WINGDIPAPI GdipGetStringFormatDigitSubstitution(GDIPCONST GpStringFormat *format,
00104     LANGID *language, StringDigitSubstitute *substitute)
00105 {
00106     if(!format)
00107         return InvalidParameter;
00108 
00109     if(language)    *language   = format->digitlang;
00110     if(substitute)  *substitute = format->digitsub;
00111 
00112     return Ok;
00113 }
00114 
00115 GpStatus WINGDIPAPI GdipGetStringFormatFlags(GDIPCONST GpStringFormat* format,
00116         INT* flags)
00117 {
00118     if (!(format && flags))
00119         return InvalidParameter;
00120 
00121     *flags = format->attr;
00122 
00123     return Ok;
00124 }
00125 
00126 GpStatus WINGDIPAPI GdipGetStringFormatHotkeyPrefix(GDIPCONST GpStringFormat
00127     *format, INT *hkpx)
00128 {
00129     if(!format || !hkpx)
00130         return InvalidParameter;
00131 
00132     *hkpx = (INT)format->hkprefix;
00133 
00134     return Ok;
00135 }
00136 
00137 GpStatus WINGDIPAPI GdipGetStringFormatLineAlign(GpStringFormat *format,
00138     StringAlignment *align)
00139 {
00140     if(!format || !align)
00141         return InvalidParameter;
00142 
00143     *align = format->vertalign;
00144 
00145     return Ok;
00146 }
00147 
00148 GpStatus WINGDIPAPI GdipGetStringFormatMeasurableCharacterRangeCount(
00149     GDIPCONST GpStringFormat *format, INT *count)
00150 {
00151     if (!(format && count))
00152         return InvalidParameter;
00153 
00154     TRACE("%p %p\n", format, count);
00155 
00156     *count = format->range_count;
00157 
00158     return Ok;
00159 }
00160 
00161 GpStatus WINGDIPAPI GdipGetStringFormatTabStopCount(GDIPCONST GpStringFormat *format,
00162     INT *count)
00163 {
00164     if(!format || !count)
00165         return InvalidParameter;
00166 
00167     *count = format->tabcount;
00168 
00169     return Ok;
00170 }
00171 
00172 GpStatus WINGDIPAPI GdipGetStringFormatTabStops(GDIPCONST GpStringFormat *format, INT count,
00173     REAL *firsttab, REAL *tabs)
00174 {
00175     if(!format || !firsttab || !tabs)
00176         return InvalidParameter;
00177 
00178     /* native simply crashes on count < 0 */
00179     if(count != 0)
00180         memcpy(tabs, format->tabs, sizeof(REAL)*count);
00181 
00182     *firsttab = format->firsttab;
00183 
00184     return Ok;
00185 }
00186 
00187 GpStatus WINGDIPAPI GdipGetStringFormatTrimming(GpStringFormat *format,
00188     StringTrimming *trimming)
00189 {
00190     if(!format || !trimming)
00191         return InvalidParameter;
00192 
00193     *trimming = format->trimming;
00194 
00195     return Ok;
00196 }
00197 
00198 GpStatus WINGDIPAPI GdipSetStringFormatAlign(GpStringFormat *format,
00199     StringAlignment align)
00200 {
00201     TRACE("(%p, %i)\n", format, align);
00202 
00203     if(!format)
00204         return InvalidParameter;
00205 
00206     format->align = align;
00207 
00208     return Ok;
00209 }
00210 
00211 /*FIXME: digit substitution actually not implemented, get/set only */
00212 GpStatus WINGDIPAPI GdipSetStringFormatDigitSubstitution(GpStringFormat *format,
00213     LANGID language, StringDigitSubstitute substitute)
00214 {
00215     TRACE("(%p, %x, %i)\n", format, language, substitute);
00216 
00217     if(!format)
00218         return InvalidParameter;
00219 
00220     format->digitlang = language;
00221     format->digitsub  = substitute;
00222 
00223     return Ok;
00224 }
00225 
00226 GpStatus WINGDIPAPI GdipSetStringFormatHotkeyPrefix(GpStringFormat *format,
00227     INT hkpx)
00228 {
00229     TRACE("(%p, %i)\n", format, hkpx);
00230 
00231     if(!format || hkpx < 0 || hkpx > 2)
00232         return InvalidParameter;
00233 
00234     format->hkprefix = (HotkeyPrefix) hkpx;
00235 
00236     return Ok;
00237 }
00238 
00239 GpStatus WINGDIPAPI GdipSetStringFormatLineAlign(GpStringFormat *format,
00240     StringAlignment align)
00241 {
00242     TRACE("(%p, %i)\n", format, align);
00243 
00244     if(!format)
00245         return InvalidParameter;
00246 
00247     format->vertalign = align;
00248 
00249     return Ok;
00250 }
00251 
00252 GpStatus WINGDIPAPI GdipSetStringFormatMeasurableCharacterRanges(
00253     GpStringFormat *format, INT rangeCount, GDIPCONST CharacterRange *ranges)
00254 {
00255     CharacterRange *new_ranges;
00256 
00257     if (!(format && ranges))
00258         return InvalidParameter;
00259 
00260     TRACE("%p, %d, %p\n", format, rangeCount, ranges);
00261 
00262     new_ranges = GdipAlloc(rangeCount * sizeof(CharacterRange));
00263     if (!new_ranges)
00264         return OutOfMemory;
00265 
00266     GdipFree(format->character_ranges);
00267     format->character_ranges = new_ranges;
00268     memcpy(format->character_ranges, ranges, sizeof(CharacterRange) * rangeCount);
00269     format->range_count = rangeCount;
00270 
00271     return Ok;
00272 }
00273 
00274 GpStatus WINGDIPAPI GdipSetStringFormatTabStops(GpStringFormat *format, REAL firsttab,
00275     INT count, GDIPCONST REAL *tabs)
00276 {
00277     TRACE("(%p, %0.2f, %i, %p)\n", format, firsttab, count, tabs);
00278 
00279     if(!format || !tabs)
00280         return InvalidParameter;
00281 
00282     if(count > 0){
00283         if(firsttab < 0.0)  return NotImplemented;
00284         /* first time allocation */
00285         if(format->tabcount == 0){
00286             format->tabs = GdipAlloc(sizeof(REAL)*count);
00287             if(!format->tabs)
00288                 return OutOfMemory;
00289         }
00290         /* reallocation */
00291         if((format->tabcount < count) && (format->tabcount > 0)){
00292             REAL *ptr;
00293             ptr = HeapReAlloc(GetProcessHeap(), 0, format->tabs, sizeof(REAL)*count);
00294             if(!ptr)
00295                 return OutOfMemory;
00296             format->tabs = ptr;
00297         }
00298         format->firsttab = firsttab;
00299         format->tabcount = count;
00300         memcpy(format->tabs, tabs, sizeof(REAL)*count);
00301     }
00302 
00303     return Ok;
00304 }
00305 
00306 GpStatus WINGDIPAPI GdipSetStringFormatTrimming(GpStringFormat *format,
00307     StringTrimming trimming)
00308 {
00309     TRACE("(%p, %i)\n", format, trimming);
00310 
00311     if(!format)
00312         return InvalidParameter;
00313 
00314     format->trimming = trimming;
00315 
00316     return Ok;
00317 }
00318 
00319 GpStatus WINGDIPAPI GdipSetStringFormatFlags(GpStringFormat *format, INT flags)
00320 {
00321     TRACE("(%p, %x)\n", format, flags);
00322 
00323     if(!format)
00324         return InvalidParameter;
00325 
00326     format->attr = flags;
00327 
00328     return Ok;
00329 }
00330 
00331 GpStatus WINGDIPAPI GdipCloneStringFormat(GDIPCONST GpStringFormat *format, GpStringFormat **newFormat)
00332 {
00333     if(!format || !newFormat)
00334         return InvalidParameter;
00335 
00336     *newFormat = GdipAlloc(sizeof(GpStringFormat));
00337     if(!*newFormat)    return OutOfMemory;
00338 
00339     **newFormat = *format;
00340 
00341     if(format->tabcount > 0){
00342         (*newFormat)->tabs = GdipAlloc(sizeof(REAL) * format->tabcount);
00343         if(!(*newFormat)->tabs){
00344             GdipFree(*newFormat);
00345             return OutOfMemory;
00346         }
00347         memcpy((*newFormat)->tabs, format->tabs, sizeof(REAL) * format->tabcount);
00348     }
00349     else
00350         (*newFormat)->tabs = NULL;
00351 
00352     if(format->range_count > 0){
00353         (*newFormat)->character_ranges = GdipAlloc(sizeof(CharacterRange) * format->range_count);
00354         if(!(*newFormat)->character_ranges){
00355             GdipFree((*newFormat)->tabs);
00356             GdipFree(*newFormat);
00357             return OutOfMemory;
00358         }
00359         memcpy((*newFormat)->character_ranges, format->character_ranges,
00360                sizeof(CharacterRange) * format->range_count);
00361     }
00362     else
00363         (*newFormat)->character_ranges = NULL;
00364 
00365     TRACE("%p %p\n",format,newFormat);
00366 
00367     return Ok;
00368 }
00369 
00370 GpStatus WINGDIPAPI GdipStringFormatGetGenericTypographic(GpStringFormat **format)
00371 {
00372     GpStatus stat;
00373 
00374     if(!format)
00375         return InvalidParameter;
00376 
00377     stat = GdipCreateStringFormat(StringFormatFlagsNoFitBlackBox |
00378                                   StringFormatFlagsLineLimit |
00379                                   StringFormatFlagsNoClip, LANG_NEUTRAL, format);
00380     if(stat != Ok)
00381         return stat;
00382 
00383     (*format)->digitlang = LANG_NEUTRAL;
00384     (*format)->digitsub  = StringDigitSubstituteUser;
00385     (*format)->trimming  = StringTrimmingNone;
00386     (*format)->hkprefix  = HotkeyPrefixNone;
00387     (*format)->align     = StringAlignmentNear;
00388     (*format)->vertalign = StringAlignmentNear;
00389 
00390     return Ok;
00391 }

Generated on Mon May 28 2012 04:23:27 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.