comparison org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/custom/StyleRange.d @ 0:6dd524f61e62

add dwt win and basic java stuff
author Frank Benoit <benoit@tionex.de>
date Mon, 02 Mar 2009 14:44:16 +0100
parents
children 4c0057e71936
comparison
equal deleted inserted replaced
-1:000000000000 0:6dd524f61e62
1 /*******************************************************************************
2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module org.eclipse.swt.custom.StyleRange;
14
15 import java.lang.all;
16
17
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.graphics.Color;
20 import org.eclipse.swt.graphics.TextStyle;
21 import org.eclipse.swt.internal.CloneableCompatibility;
22 import org.eclipse.swt.custom.StyleRange;
23 import org.eclipse.swt.custom.TextChangedEvent;
24 import org.eclipse.swt.custom.TextChangingEvent;
25
26 static import tango.text.Text;
27 alias tango.text.Text.Text!(char) StringBuffer;
28
29 /**
30 * <code>StyleRange</code> defines a set of styles for a specified
31 * range of text.
32 * <p>
33 * The hashCode() method in this class uses the values of the public
34 * fields to compute the hash value. When storing instances of the
35 * class in hashed collections, do not modify these fields after the
36 * object has been inserted.
37 * </p>
38 *
39 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
40 */
41 public class StyleRange : TextStyle, CloneableCompatibility {
42
43 /**
44 * the start offset of the range, zero-based from the document start
45 */
46 public int start;
47
48 /**
49 * the length of the range
50 */
51 public int length;
52
53 /**
54 * the font style of the range. It may be a combination of
55 * SWT.NORMAL, SWT.ITALIC or SWT.BOLD
56 *
57 * Note: the font style is not used if the <code>font</code> attribute
58 * is set
59 */
60 public int fontStyle = SWT.NORMAL;
61
62 /**
63 * Create a new style range with no styles
64 *
65 * @since 3.2
66 */
67 public this() {
68 }
69 /++
70 + SWT extension for clone implementation
71 +/
72 protected this( StyleRange other ){
73 super( other );
74 start = other.start;
75 length = other.length;
76 fontStyle = other.fontStyle;
77 }
78
79 /**
80 * Create a new style range from an existing text style.
81 *
82 * @param style the text style to copy
83 *
84 * @since 3.4
85 */
86 public this(TextStyle style) {
87 super(style);
88 }
89
90 /**
91 * Create a new style range.
92 *
93 * @param start start offset of the style
94 * @param length length of the style
95 * @param foreground foreground color of the style, null if none
96 * @param background background color of the style, null if none
97 */
98 public this(int start, int length, Color foreground, Color background) {
99 super(null, foreground, background);
100 this.start = start;
101 this.length = length;
102 }
103
104 /**
105 * Create a new style range.
106 *
107 * @param start start offset of the style
108 * @param length length of the style
109 * @param foreground foreground color of the style, null if none
110 * @param background background color of the style, null if none
111 * @param fontStyle font style of the style, may be SWT.NORMAL, SWT.ITALIC or SWT.BOLD
112 */
113 public this(int start, int length, Color foreground, Color background, int fontStyle) {
114 this(start, length, foreground, background);
115 this.fontStyle = fontStyle;
116 }
117
118 /**
119 * Compares the argument to the receiver, and returns true
120 * if they represent the <em>same</em> object using a class
121 * specific comparison.
122 *
123 * @param object the object to compare with this object
124 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
125 *
126 * @see #hashCode()
127 */
128 public override int opEquals(Object object) {
129 if (object is this) return true;
130 if (auto style = cast(StyleRange) object ) {
131 if (start !is style.start) return false;
132 if (length !is style.length) return false;
133 return similarTo(style);
134 }
135 return false;
136 }
137
138 /**
139 * Returns an integer hash code for the receiver. Any two
140 * objects that return <code>true</code> when passed to
141 * <code>equals</code> must return the same value for this
142 * method.
143 *
144 * @return the receiver's hash
145 *
146 * @see #equals(Object)
147 */
148 public override hash_t toHash() {
149 return super.toHash() ^ fontStyle;
150 }
151 bool isVariableHeight() {
152 return font !is null || metrics !is null || rise !is 0;
153 }
154 /**
155 * Returns whether or not the receiver is unstyled (i.e., does not have any
156 * style attributes specified).
157 *
158 * @return true if the receiver is unstyled, false otherwise.
159 */
160 public bool isUnstyled() {
161 if (font !is null) return false;
162 if (rise !is 0) return false;
163 if (metrics !is null) return false;
164 if (foreground !is null) return false;
165 if (background !is null) return false;
166 if (fontStyle !is SWT.NORMAL) return false;
167 if (underline) return false;
168 if (strikeout) return false;
169 if (borderStyle !is SWT.NONE) return false;
170 return true;
171 }
172
173 /**
174 * Compares the specified object to this StyleRange and answer if the two
175 * are similar. The object must be an instance of StyleRange and have the
176 * same field values for except for start and length.
177 *
178 * @param style the object to compare with this object
179 * @return true if the objects are similar, false otherwise
180 */
181 public bool similarTo(StyleRange style) {
182 if (!super.opEquals(style)) return false;
183 if (fontStyle !is style.fontStyle) return false;
184 return true;
185 }
186
187 /**
188 * Returns a new StyleRange with the same values as this StyleRange.
189 *
190 * @return a shallow copy of this StyleRange
191 */
192 public /+override+/ Object clone() {
193 return new StyleRange( this );
194 }
195
196 /**
197 * Returns a string containing a concise, human-readable
198 * description of the receiver.
199 *
200 * @return a string representation of the StyleRange
201 */
202 public override String toString() {
203 StringBuffer buffer = new StringBuffer();
204 buffer.append("StyleRange {");
205 buffer.append(start);
206 buffer.append(", ");
207 buffer.append(length);
208 buffer.append(", fontStyle=");
209 switch (fontStyle) {
210 case SWT.BOLD:
211 buffer.append("bold");
212 break;
213 case SWT.ITALIC:
214 buffer.append("italic");
215 break;
216 case SWT.BOLD | SWT.ITALIC:
217 buffer.append("bold-italic");
218 break;
219 default:
220 buffer.append("normal");
221 }
222 String str = super.toString();
223 int index = tango.text.Util.locate( str, '{');
224 if( index is str.length ) index = -1;
225 str = str[ index + 1 .. $ ];
226 if (str.length > 1) buffer.append(", ");
227 buffer.append(str);
228 return buffer.toString();
229 }
230 }