PageRenderTime 52ms CodeModel.GetById 2ms app.highlight 46ms RepoModel.GetById 1ms app.codeStats 0ms

/binding/win32/gdiplusstringformat.d

http://github.com/wilkie/djehuty
D | 297 lines | 232 code | 42 blank | 23 comment | 5 complexity | 882cd2a960b68b55bd8a9d01bfdbca67 MD5 | raw file
  1/*
  2 * gdiplusstringformat.d
  3 *
  4 * This module implements GdiPlusStringFormat.h for D. The original
  5 * copyright info is given below.
  6 *
  7 * Author: Dave Wilkinson
  8 * Originated: November 25th, 2009
  9 *
 10 */
 11
 12module binding.win32.gdiplusstringformat;
 13
 14import binding.win32.windef;
 15import binding.win32.winbase;
 16import binding.win32.winnt;
 17import binding.win32.wingdi;
 18import binding.win32.guiddef;
 19import binding.win32.gdiplusbase;
 20import binding.win32.gdiplustypes;
 21import binding.win32.gdiplusenums;
 22import binding.win32.gdipluspixelformats;
 23import binding.win32.gdiplusgpstubs;
 24import binding.win32.gdiplusmetaheader;
 25import binding.win32.gdipluspixelformats;
 26import binding.win32.gdipluscolor;
 27import binding.win32.gdipluscolormatrix;
 28import binding.win32.gdiplusflat;
 29import binding.win32.gdiplusimaging;
 30import binding.win32.gdiplusbitmap;
 31import binding.win32.gdiplusimageattributes;
 32import binding.win32.gdiplusmatrix;
 33
 34/**************************************************************************\
 35*
 36* Copyright (c) 1998-2001, Microsoft Corp.  All Rights Reserved.
 37*
 38* Module Name:
 39*
 40*   GdiplusStringFormat.h
 41*
 42* Abstract:
 43*
 44*   GDI+ StringFormat class
 45*
 46\**************************************************************************/
 47
 48class StringFormat : GdiplusBase {
 49
 50    this(
 51        in INT     formatFlags = 0,
 52        in LANGID  language = LANG_NEUTRAL) {
 53        nativeFormat = null;
 54        lastError = GdipCreateStringFormat(
 55            formatFlags,
 56            language,
 57            &nativeFormat
 58        );
 59    }
 60
 61    static StringFormat GenericDefault() {
 62		StringFormat genericDefaultStringFormat = new StringFormat();
 63
 64	    genericDefaultStringFormat.lastError =
 65	        GdipStringFormatGetGenericDefault(
 66	            &(genericDefaultStringFormat.nativeFormat)
 67	        );
 68
 69		return genericDefaultStringFormat;
 70	}
 71
 72    static StringFormat GenericTypographic() {
 73    	StringFormat genericTypographicStringFormat = new StringFormat();
 74
 75	    genericTypographicStringFormat.lastError =
 76	        GdipStringFormatGetGenericTypographic(
 77	            &genericTypographicStringFormat.nativeFormat
 78	        );
 79
 80	    return genericTypographicStringFormat;
 81    }
 82
 83    this(in StringFormat format) {
 84        nativeFormat = null;
 85        lastError = GdipCloneStringFormat(
 86            format ? format.nativeFormat : null,
 87            &nativeFormat
 88        );
 89    }
 90
 91    StringFormat Clone() {
 92        GpStringFormat *clonedStringFormat = null;
 93
 94        lastError = GdipCloneStringFormat(
 95            nativeFormat,
 96            &clonedStringFormat
 97        );
 98
 99        if (lastError == Status.Ok)
100            return new StringFormat(clonedStringFormat, lastError);
101        else
102            return null;
103    }
104    
105    alias Clone dup;
106
107    ~this() {
108        GdipDeleteStringFormat(nativeFormat);
109    }
110
111    Status SetFormatFlags(in INT flags) {
112        return SetStatus(GdipSetStringFormatFlags(
113            nativeFormat,
114            flags
115        ));
116    }
117
118    INT GetFormatFlags() {
119        INT flags;
120        SetStatus(GdipGetStringFormatFlags(nativeFormat, &flags));
121        return flags;
122    }
123
124    Status SetAlignment(in StringAlignment _align) {
125        return SetStatus(GdipSetStringFormatAlign(
126            nativeFormat,
127            _align
128        ));
129    }
130
131    StringAlignment GetAlignment() {
132        StringAlignment alignment;
133        SetStatus(GdipGetStringFormatAlign(
134            nativeFormat,
135            &alignment
136        ));
137        return alignment;
138    }
139
140    Status SetLineAlignment(in StringAlignment _align) {
141        return SetStatus(GdipSetStringFormatLineAlign(
142            nativeFormat,
143            _align
144        ));
145    }
146
147    StringAlignment GetLineAlignment() {
148        StringAlignment alignment;
149        SetStatus(GdipGetStringFormatLineAlign(
150            nativeFormat,
151            &alignment
152        ));
153        return alignment;
154    }
155
156    Status SetHotkeyPrefix(in HotkeyPrefix hotkeyPrefix) {
157        return SetStatus(GdipSetStringFormatHotkeyPrefix(
158            nativeFormat,
159            cast(INT)hotkeyPrefix
160        ));
161    }
162
163    HotkeyPrefix GetHotkeyPrefix() {
164        HotkeyPrefix hotkeyPrefix;
165        SetStatus(GdipGetStringFormatHotkeyPrefix(
166            nativeFormat,
167            cast(INT*)&hotkeyPrefix
168        ));
169        return hotkeyPrefix;
170    }
171
172    Status SetTabStops(
173        in REAL    firstTabOffset,
174        in INT     count,
175        in REAL    *tabStops
176    ) {
177        return SetStatus(GdipSetStringFormatTabStops(
178            nativeFormat,
179            firstTabOffset,
180            count,
181            tabStops
182        ));
183    }
184
185    INT GetTabStopCount() {
186        INT count;
187        SetStatus(GdipGetStringFormatTabStopCount(nativeFormat, &count));
188        return count;
189    }
190
191    Status GetTabStops(
192        in INT     count,
193        REAL   *firstTabOffset,
194        REAL   *tabStops
195    ) {
196        return SetStatus(GdipGetStringFormatTabStops(
197            nativeFormat,
198            count,
199            firstTabOffset,
200            tabStops
201        ));
202    }
203
204    Status SetDigitSubstitution(
205        in LANGID                language,
206        in StringDigitSubstitute substitute
207    ) {
208        return SetStatus(GdipSetStringFormatDigitSubstitution(
209            nativeFormat,
210            language,
211            substitute
212        ));
213    }
214
215    LANGID GetDigitSubstitutionLanguage() {
216        LANGID language;
217        SetStatus(GdipGetStringFormatDigitSubstitution(
218            nativeFormat,
219            &language,
220            null
221        ));
222        return language;
223    }
224
225    StringDigitSubstitute GetDigitSubstitutionMethod() {
226        StringDigitSubstitute substitute;
227        SetStatus(GdipGetStringFormatDigitSubstitution(
228            nativeFormat,
229            null,
230            &substitute
231        ));
232        return substitute;
233    }
234
235    Status SetTrimming(in StringTrimming trimming) {
236        return SetStatus(GdipSetStringFormatTrimming(
237            nativeFormat,
238            trimming
239        ));
240    }
241
242    StringTrimming GetTrimming() {
243        StringTrimming trimming;
244        SetStatus(GdipGetStringFormatTrimming(
245            nativeFormat,
246            &trimming
247        ));
248        return trimming;
249    }
250
251    Status SetMeasurableCharacterRanges(
252        in INT                  rangeCount,
253        in CharacterRange[] ranges
254    ) {
255        return SetStatus(GdipSetStringFormatMeasurableCharacterRanges(
256            nativeFormat,
257            rangeCount,
258            ranges.ptr
259        ));
260    }
261
262    INT GetMeasurableCharacterRangeCount() {
263        INT count;
264        SetStatus(GdipGetStringFormatMeasurableCharacterRangeCount(
265            nativeFormat,
266            &count
267        ));
268        return count;
269    }
270
271    Status GetLastStatus() {
272        Status lastStatus = lastError;
273        lastError = Status.Ok;
274
275        return lastStatus;
276    }
277
278protected:
279
280    Status SetStatus(GpStatus newStatus) {
281        if (newStatus == Status.Ok) {
282            return Status.Ok;
283        }
284        else {
285            return lastError = newStatus;
286        }
287    }
288
289    package this(GpStringFormat* clonedStringFormat, Status status) {
290        lastError = status;
291        nativeFormat = clonedStringFormat;
292
293    }
294
295    package GpStringFormat *nativeFormat;
296    package Status  lastError;
297}