Mercurial > projects > dwt2
annotate org.eclipse.swt.gtk.linux.x86/src/org/eclipse/swt/custom/StyleRange.d @ 120:536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
===D2===
* added [Try]Immutable/Const/Shared templates to work with differenses in D1/D2 instead of version statements
used these templates to work with strict type storage rules of dmd-2.053
* com.ibm.icu now also compilable with D2, but not tested yet
* small fixes
Snippet288 - shared data is in TLS
===Phobos===
* fixed critical bugs in Phobos implemention
completely incorrect segfault prone fromStringz (Linux's port ruthless killer)
terrible, incorrect StringBuffer realization (StyledText killer)
* fixed small bugs as well
Snippet72 - misprint in the snippet
* implemented missed functionality for Phobos
ByteArrayOutputStream implemented (image loading available)
formatting correctly works for all DWT's cases
As a result, folowing snippets now works with Phobos (Snippet### - what is fixed):
Snippet24, 42, 111, 115, 130, 235, 276 - bad string formatting
Snippet48, 282 - crash on image loading
Snippet163, 189, 211, 213, 217, 218, 222 - crash on copy/cut in StyledText
Snippet244 - hang-up
===Tango===
* few changes for the latest Tango trunc-r5661
* few small performance improvments
===General===
* implMissing-s for only one version changed to implMissingInTango/InPhobos
* incorrect calls to Format in toString-s fixed
* fixed loading \uXXXX characters in ResourceBundle
* added good UTF-8 support for StyledText, TextLayout (Win32) and friends
UTF functions revised and tested. It is now in java.nonstandard.*Utf modules
StyledText and TextLayout (Win32) modules revised for UTF-8 support
* removed small diferences in most identical files in *.swt.* folders
*.swt.internal.image, *.swt.events and *.swt.custom are identical in Win32/Linux32
now 179 of 576 (~31%) files in *.swt.* folders are fully identical
* Win32: snippets now have right subsystem, pretty icons and native system style controls
* small fixes in snippets
Snippet44 - it's not Snippet44
Snippet212 - functions work with different images and offsets arrays
Win32: Snippet282 - crash on close if the button has an image
Snippet293 - setGrayed is commented
and others
Win32: As a result, folowing snippets now works
Snippet68 - color doesn't change
Snippet163, 189, 211, 213, 217, 218, 222 - UTF-8 issues (see above)
Snippet193 - no tabel headers
author | Denis Shelomovskij <verylonglogin.reg@gmail.com> |
---|---|
date | Sat, 09 Jul 2011 15:50:20 +0300 |
parents | c01d033c633a |
children |
rev | line source |
---|---|
25 | 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 import org.eclipse.swt.SWT; | |
18 import org.eclipse.swt.graphics.Color; | |
19 import org.eclipse.swt.graphics.TextStyle; | |
20 import org.eclipse.swt.internal.CloneableCompatibility; | |
21 import org.eclipse.swt.custom.StyleRange; | |
22 import org.eclipse.swt.custom.TextChangedEvent; | |
23 import org.eclipse.swt.custom.TextChangingEvent; | |
24 | |
25 /** | |
26 * <code>StyleRange</code> defines a set of styles for a specified | |
27 * range of text. | |
28 * <p> | |
29 * The hashCode() method in this class uses the values of the public | |
30 * fields to compute the hash value. When storing instances of the | |
31 * class in hashed collections, do not modify these fields after the | |
32 * object has been inserted. | |
33 * </p> | |
34 * | |
35 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
36 */ | |
37 public class StyleRange : TextStyle, CloneableCompatibility { | |
38 | |
39 /** | |
40 * the start offset of the range, zero-based from the document start | |
41 */ | |
42 public int start; | |
43 | |
44 /** | |
45 * the length of the range | |
46 */ | |
47 public int length; | |
48 | |
49 /** | |
50 * the font style of the range. It may be a combination of | |
51 * SWT.NORMAL, SWT.ITALIC or SWT.BOLD | |
52 * | |
53 * Note: the font style is not used if the <code>font</code> attribute | |
54 * is set | |
55 */ | |
56 public int fontStyle = SWT.NORMAL; | |
57 | |
58 /** | |
59 * Create a new style range with no styles | |
60 * | |
61 * @since 3.2 | |
62 */ | |
63 public this() { | |
64 } | |
65 /++ | |
66 + SWT extension for clone implementation | |
67 +/ | |
68 protected this( StyleRange other ){ | |
69 super( other ); | |
70 start = other.start; | |
71 length = other.length; | |
72 fontStyle = other.fontStyle; | |
73 } | |
74 | |
75 /** | |
76 * Create a new style range from an existing text style. | |
77 * | |
78 * @param style the text style to copy | |
79 * | |
80 * @since 3.4 | |
81 */ | |
82 public this(TextStyle style) { | |
83 super(style); | |
84 } | |
85 | |
86 /** | |
87 * Create a new style range. | |
88 * | |
89 * @param start start offset of the style | |
90 * @param length length of the style | |
91 * @param foreground foreground color of the style, null if none | |
92 * @param background background color of the style, null if none | |
93 */ | |
94 public this(int start, int length, Color foreground, Color background) { | |
95 super(null, foreground, background); | |
96 this.start = start; | |
97 this.length = length; | |
98 } | |
99 | |
100 /** | |
101 * Create a new style range. | |
102 * | |
103 * @param start start offset of the style | |
104 * @param length length of the style | |
105 * @param foreground foreground color of the style, null if none | |
106 * @param background background color of the style, null if none | |
107 * @param fontStyle font style of the style, may be SWT.NORMAL, SWT.ITALIC or SWT.BOLD | |
108 */ | |
109 public this(int start, int length, Color foreground, Color background, int fontStyle) { | |
110 this(start, length, foreground, background); | |
111 this.fontStyle = fontStyle; | |
112 } | |
113 | |
114 /** | |
115 * Compares the argument to the receiver, and returns true | |
116 * if they represent the <em>same</em> object using a class | |
117 * specific comparison. | |
118 * | |
119 * @param object the object to compare with this object | |
120 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
121 * | |
122 * @see #hashCode() | |
123 */ | |
26 | 124 public override equals_t opEquals(Object object) { |
25 | 125 if (object is this) return true; |
126 if (auto style = cast(StyleRange) object ) { | |
127 if (start !is style.start) return false; | |
128 if (length !is style.length) return false; | |
129 return similarTo(style); | |
130 } | |
131 return false; | |
132 } | |
133 | |
134 /** | |
135 * Returns an integer hash code for the receiver. Any two | |
136 * objects that return <code>true</code> when passed to | |
137 * <code>equals</code> must return the same value for this | |
138 * method. | |
139 * | |
140 * @return the receiver's hash | |
141 * | |
142 * @see #equals(Object) | |
143 */ | |
144 public override hash_t toHash() { | |
145 return super.toHash() ^ fontStyle; | |
146 } | |
147 bool isVariableHeight() { | |
148 return font !is null || metrics !is null || rise !is 0; | |
149 } | |
150 /** | |
151 * Returns whether or not the receiver is unstyled (i.e., does not have any | |
152 * style attributes specified). | |
153 * | |
154 * @return true if the receiver is unstyled, false otherwise. | |
155 */ | |
156 public bool isUnstyled() { | |
157 if (font !is null) return false; | |
158 if (rise !is 0) return false; | |
159 if (metrics !is null) return false; | |
160 if (foreground !is null) return false; | |
161 if (background !is null) return false; | |
162 if (fontStyle !is SWT.NORMAL) return false; | |
163 if (underline) return false; | |
164 if (strikeout) return false; | |
165 if (borderStyle !is SWT.NONE) return false; | |
166 return true; | |
167 } | |
168 | |
169 /** | |
170 * Compares the specified object to this StyleRange and answer if the two | |
171 * are similar. The object must be an instance of StyleRange and have the | |
172 * same field values for except for start and length. | |
173 * | |
174 * @param style the object to compare with this object | |
175 * @return true if the objects are similar, false otherwise | |
176 */ | |
177 public bool similarTo(StyleRange style) { | |
178 if (!super.opEquals(style)) return false; | |
179 if (fontStyle !is style.fontStyle) return false; | |
180 return true; | |
181 } | |
182 | |
183 /** | |
184 * Returns a new StyleRange with the same values as this StyleRange. | |
185 * | |
186 * @return a shallow copy of this StyleRange | |
187 */ | |
188 public /+override+/ Object clone() { | |
189 return new StyleRange( this ); | |
190 } | |
191 | |
192 /** | |
193 * Returns a string containing a concise, human-readable | |
194 * description of the receiver. | |
195 * | |
196 * @return a string representation of the StyleRange | |
197 */ | |
198 public override String toString() { | |
199 StringBuffer buffer = new StringBuffer(); | |
200 buffer.append("StyleRange {"); | |
201 buffer.append(start); | |
202 buffer.append(", "); | |
203 buffer.append(length); | |
204 buffer.append(", fontStyle="); | |
205 switch (fontStyle) { | |
206 case SWT.BOLD: | |
207 buffer.append("bold"); | |
208 break; | |
209 case SWT.ITALIC: | |
210 buffer.append("italic"); | |
211 break; | |
212 case SWT.BOLD | SWT.ITALIC: | |
213 buffer.append("bold-italic"); | |
214 break; | |
215 default: | |
216 buffer.append("normal"); | |
217 } | |
218 String str = super.toString(); | |
51 | 219 int index = str.indexOf( '{'); |
120
536e43f63c81
Comprehensive update for Win32/Linux32 dmd-2.053/dmd-1.068+Tango-r5661
Denis Shelomovskij <verylonglogin.reg@gmail.com>
parents:
51
diff
changeset
|
220 str = str.substring( index + 1 ); |
25 | 221 if (str.length > 1) buffer.append(", "); |
222 buffer.append(str); | |
223 return buffer.toString(); | |
224 } | |
225 } |