2010-04-07 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.Drawing / System.Drawing / StringFormat.jvm.cs
blobe8e829dc03799680bace190cbc22ec45fe470e86
1 //
2 // System.Drawing.StringFormat.cs
3 //
4 // Authors:
5 // Dennis Hayes (dennish@Raytek.com)
6 // Miguel de Icaza (miguel@ximian.com)
7 // Jordi Mas i Hernandez (jordi@ximian.com)
8 //
9 // Copyright (C) 2002 Ximian, Inc (http://www.ximian.com)
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System;
33 using System.Drawing.Text;
35 namespace System.Drawing {
36 /// <summary>
37 /// Summary description for StringFormat.
38 /// </summary>
39 public sealed class StringFormat : MarshalByRefObject, IDisposable, ICloneable {
42 private CharacterRange [] _charRanges;
43 private StringAlignment _alignment;
44 private StringAlignment _lineAlignment;
45 private HotkeyPrefix _hotkeyPrefix;
46 private StringFormatFlags _flags;
47 private StringDigitSubstitute _digitSubstituteMethod;
48 private int _digitSubstituteLanguage;
49 private StringTrimming _trimming;
51 private float _firstTabOffset;
52 private float [] _tabStops;
54 private bool _genericTypeographic = false;
56 #region Constructors
58 public StringFormat() : this(0, 0) {
61 public StringFormat(StringFormatFlags options) : this(options,0) {
64 public StringFormat(StringFormatFlags options, int lang) {
65 _alignment = StringAlignment.Near;
66 _digitSubstituteLanguage = lang;
67 _digitSubstituteMethod = StringDigitSubstitute.User;
68 _flags = options;
69 _hotkeyPrefix = HotkeyPrefix.None;
70 _lineAlignment = StringAlignment.Near;
71 _trimming = StringTrimming.Character;
74 public StringFormat (StringFormat source) {
75 if (source == null)
76 throw new ArgumentNullException("format");
78 _alignment = source.LineAlignment;
79 _digitSubstituteLanguage = source.DigitSubstitutionLanguage;
80 _digitSubstituteMethod = source.DigitSubstitutionMethod;
81 _flags = source.FormatFlags;
82 _hotkeyPrefix = source.HotkeyPrefix;
83 _lineAlignment = source.LineAlignment;
84 _trimming = source.Trimming;
88 #endregion
90 #region IDisposable
92 public void Dispose() {
95 #endregion
97 #region Public properties
99 public StringAlignment Alignment {
100 get {
101 return _alignment;
104 set {
105 _alignment = value;
109 public StringAlignment LineAlignment {
110 get {
111 return _lineAlignment;
113 set {
114 _lineAlignment = value;
118 [MonoTODO]
119 public StringFormatFlags FormatFlags {
120 get {
121 return _flags;
124 set {
125 _flags = value;
129 [MonoTODO]
130 public HotkeyPrefix HotkeyPrefix {
131 get {
132 return _hotkeyPrefix;
135 set {
136 _hotkeyPrefix = value;
140 [MonoTODO]
141 public StringTrimming Trimming {
142 get {
143 return _trimming;
146 set {
147 _trimming = value;
151 public int DigitSubstitutionLanguage {
152 get {
153 return _digitSubstituteLanguage;
157 public StringDigitSubstitute DigitSubstitutionMethod {
158 get {
159 return _digitSubstituteMethod;
164 #endregion
166 #region static properties
168 public static StringFormat GenericDefault {
169 get {
170 StringFormat genericDefault = new StringFormat();
171 return genericDefault;
175 public static StringFormat GenericTypographic {
176 get {
177 StringFormat genericTypographic = new StringFormat(
178 StringFormatFlags.FitBlackBox |
179 StringFormatFlags.LineLimit |
180 StringFormatFlags.NoClip,
181 0 );
182 genericTypographic.Trimming = StringTrimming.None;
183 genericTypographic._genericTypeographic = true;
184 return genericTypographic;
188 #endregion
190 #region internal accessors
191 internal bool NoWrap {
192 get {
193 return (FormatFlags & StringFormatFlags.NoWrap) != 0;
197 internal bool IsVertical {
198 get {
199 return (FormatFlags & StringFormatFlags.DirectionVertical) != 0;
203 internal bool MeasureTrailingSpaces {
204 get {
205 return (FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0;
209 internal bool LineLimit {
210 get {
211 return (FormatFlags & StringFormatFlags.LineLimit) != 0;
215 internal bool NoClip {
216 get {
217 return (FormatFlags & StringFormatFlags.NoClip) != 0;
221 internal bool IsRightToLeft {
222 get {
223 return (FormatFlags & StringFormatFlags.DirectionRightToLeft) != 0;
227 internal CharacterRange [] CharRanges {
228 get {
229 return _charRanges;
233 internal bool IsGenericTypographic
235 get {
236 return _genericTypeographic;
239 #endregion
241 #region public methods
243 public void SetMeasurableCharacterRanges (CharacterRange [] range) {
244 _charRanges = range != null ? (CharacterRange [])range.Clone() : null;
247 public object Clone() {
248 StringFormat copy = (StringFormat)MemberwiseClone();
249 if (_charRanges != null)
250 copy._charRanges = (CharacterRange [])_charRanges.Clone();
251 if (_tabStops != null)
252 copy._tabStops = (float[])_tabStops.Clone();
253 return copy;
256 public override string ToString() {
257 return "[StringFormat, FormatFlags=" + this.FormatFlags.ToString() + "]";
260 public void SetTabStops(float firstTabOffset, float[] tabStops) {
261 // _firstTabOffset = firstTabOffset;
262 // _tabStops = tabStops != null ? (float[])tabStops.Clone() : null;
263 throw new NotImplementedException();
266 public void SetDigitSubstitution(int language, StringDigitSubstitute substitute) {
267 // _digitSubstituteMethod = substitute;
268 // _digitSubstituteLanguage = language;
269 throw new NotImplementedException();
272 [MonoTODO]
273 public float[] GetTabStops(out float firstTabOffset) {
274 firstTabOffset = _firstTabOffset;
275 return _tabStops != null ? (float[])_tabStops.Clone() : null;
278 #endregion