Merge branch 'master' of github.com:tgiphil/mono
[mono.git] / mcs / class / System.Drawing / System.Drawing / StringFormat.jvm.cs
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)
10 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 //
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.
31 //
32 using System;
33 using System.Drawing.Text;
34
35 namespace System.Drawing {
36         /// <summary>
37         /// Summary description for StringFormat.
38         /// </summary>
39         public sealed class StringFormat : MarshalByRefObject, IDisposable, ICloneable {
40                 
41                 
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;
50                 
51                 private float _firstTabOffset;
52                 private float [] _tabStops;\r
53 \r
54                 private bool _genericTypeographic = false;
55                 
56                 #region Constructors
57
58                 public StringFormat() : this(0, 0) {                                       
59                 }
60                 
61                 public StringFormat(StringFormatFlags options) : this(options,0) {
62                 }
63                 
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;
72                 }
73                 
74                 public StringFormat (StringFormat source) {
75                         if (source == null)
76                                 throw new ArgumentNullException("format");
77
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;
85                 }
86
87
88                 #endregion
89
90                 #region IDisposable
91
92                 public void Dispose() { 
93                 }
94
95                 #endregion
96
97                 #region Public properties
98
99                 public StringAlignment Alignment {
100                         get {
101                                 return _alignment;
102                         }
103
104                         set {
105                                 _alignment = value;
106                         }
107                 }
108
109                 public StringAlignment LineAlignment {
110                         get {
111                                 return _lineAlignment;
112                         }
113                         set {
114                                 _lineAlignment = value;
115                         }
116                 }
117
118                 [MonoTODO]
119                 public StringFormatFlags FormatFlags {
120                         get {                           
121                                 return _flags;
122                         }
123
124                         set {
125                                 _flags = value;
126                         }
127                 }
128
129                 [MonoTODO]
130                 public HotkeyPrefix HotkeyPrefix {
131                         get {                           
132                                 return _hotkeyPrefix;
133                         }
134
135                         set {
136                                 _hotkeyPrefix = value;
137                         }
138                 }
139
140                 [MonoTODO]
141                 public StringTrimming Trimming {
142                         get {
143                                 return _trimming;
144                         }
145
146                         set {
147                                 _trimming = value;
148                         }
149                 }
150
151                 public int DigitSubstitutionLanguage {
152                         get {
153                                 return _digitSubstituteLanguage;
154                         }
155                 }
156
157                 public StringDigitSubstitute DigitSubstitutionMethod {
158                         get {
159                                 return _digitSubstituteMethod;     
160                         }
161                 }
162
163
164                 #endregion
165
166                 #region static properties
167
168                 public static StringFormat GenericDefault {
169                         get {
170                                 StringFormat genericDefault = new StringFormat();
171                                 return genericDefault;
172                         }
173                 }
174                 
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;\r
183                                 genericTypographic._genericTypeographic = true;
184                                 return genericTypographic;
185                         }
186                 }
187
188                 #endregion
189
190                 #region internal accessors
191                 internal bool NoWrap {\r
192                         get {\r
193                                 return (FormatFlags & StringFormatFlags.NoWrap) != 0;\r
194                         }\r
195                 }\r
196 \r
197                 internal bool IsVertical {\r
198                         get {\r
199                                 return (FormatFlags & StringFormatFlags.DirectionVertical) != 0;\r
200                         }\r
201                 }\r
202 \r
203                 internal bool MeasureTrailingSpaces {\r
204                         get {\r
205                                 return (FormatFlags & StringFormatFlags.MeasureTrailingSpaces) != 0;\r
206                         }\r
207                 }\r
208 \r
209                 internal bool LineLimit {\r
210                         get {\r
211                                 return (FormatFlags & StringFormatFlags.LineLimit) != 0;\r
212                         }\r
213                 }\r
214 \r
215                 internal bool NoClip {\r
216                         get {\r
217                                 return (FormatFlags & StringFormatFlags.NoClip) != 0;\r
218                         }\r
219                 }
220
221                 internal bool IsRightToLeft {\r
222                         get {\r
223                                 return (FormatFlags & StringFormatFlags.DirectionRightToLeft) != 0;\r
224                         }\r
225                 }
226                 
227                 internal CharacterRange [] CharRanges {
228                         get {
229                                 return _charRanges;
230                         }
231                 }\r
232 \r
233                 internal bool IsGenericTypographic\r
234                 {\r
235                         get {\r
236                                 return _genericTypeographic;\r
237                         }\r
238                 }
239                 #endregion
240
241                 #region public methods
242
243                 public void SetMeasurableCharacterRanges (CharacterRange [] range) {
244                         _charRanges = range != null ? (CharacterRange [])range.Clone() : null;
245                 }
246         
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;
254                 }
255
256                 public override string ToString() {
257                         return "[StringFormat, FormatFlags=" + this.FormatFlags.ToString() + "]";
258                 }
259                 
260                 public void SetTabStops(float firstTabOffset, float[] tabStops) {
261 //                      _firstTabOffset = firstTabOffset;
262 //                      _tabStops = tabStops != null ? (float[])tabStops.Clone() : null;
263                         throw new NotImplementedException();
264                 }
265
266                 public void SetDigitSubstitution(int language,  StringDigitSubstitute substitute) {
267 //                      _digitSubstituteMethod = substitute;
268 //                      _digitSubstituteLanguage = language;
269                         throw new NotImplementedException();
270                 }
271
272                 [MonoTODO]
273                 public float[] GetTabStops(out float firstTabOffset) {
274                         firstTabOffset = _firstTabOffset;
275                         return _tabStops != null ? (float[])_tabStops.Clone() : null;
276                 }
277
278                 #endregion
279         }
280 }