Mercurial > projects > dwt-win
annotate dwt/custom/Bullet.d @ 315:349b8c12e243
Sync dwt/custom with dwt-linux
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 07 Oct 2008 16:18:26 +0200 |
parents | fd9c62a2998e |
children |
rev | line source |
---|---|
315
349b8c12e243
Sync dwt/custom with dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
1 /******************************************************************************* |
246 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
155 | 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 dwt.custom.Bullet; | |
14 | |
315
349b8c12e243
Sync dwt/custom with dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
15 import dwt.dwthelper.utils; |
349b8c12e243
Sync dwt/custom with dwt-linux
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
16 |
155 | 17 import dwt.DWT; |
18 import dwt.custom.StyleRange; | |
19 import dwt.custom.ST; | |
20 import dwt.dwthelper.System; | |
21 | |
22 /** | |
23 * Instances of this class represent bullets in the <code>StyledText</code>. | |
24 * <p> | |
25 * The hashCode() method in this class uses the values of the public | |
26 * fields to compute the hash value. When storing instances of the | |
27 * class in hashed collections, do not modify these fields after the | |
28 * object has been inserted. | |
29 * </p> | |
30 * <p> | |
31 * Application code does <em>not</em> need to explicitly release the | |
32 * resources managed by each instance when those instances are no longer | |
33 * required, and thus no <code>dispose()</code> method is provided. | |
34 * </p> | |
35 * | |
36 * @see StyledText#setLineBullet(int, int, Bullet) | |
246 | 37 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
155 | 38 * |
39 * @since 3.2 | |
40 */ | |
41 public class Bullet { | |
246 | 42 /** |
43 * The bullet type. Possible values are: | |
44 * <ul> | |
45 * <li><code>ST.BULLET_DOT</code></li> | |
46 * <li><code>ST.BULLET_NUMBER</code></li> | |
47 * <li><code>ST.BULLET_LETTER_LOWER</code></li> | |
48 * <li><code>ST.BULLET_LETTER_UPPER</code></li> | |
49 * <li><code>ST.BULLET_TEXT</code></li> | |
50 * <li><code>ST.BULLET_CUSTOM</code></li> | |
51 * </ul> | |
52 */ | |
155 | 53 public int type; |
246 | 54 |
55 /** | |
56 * The bullet style. | |
57 */ | |
155 | 58 public StyleRange style; |
246 | 59 |
60 /** | |
61 * The bullet text. | |
62 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
155
diff
changeset
|
63 public String text; |
246 | 64 |
155 | 65 int[] linesIndices; |
66 int count; | |
67 | |
68 /** | |
246 | 69 * Create a new bullet with the specified style, and type <code>ST.BULLET_DOT</code>. |
155 | 70 * The style must have a glyph metrics set. |
71 * | |
72 * @param style the style | |
73 * | |
74 * @exception IllegalArgumentException <ul> | |
75 * <li>ERROR_NULL_ARGUMENT when the style or the glyph metrics are null</li> | |
76 * </ul> | |
77 */ | |
78 public this(StyleRange style) { | |
79 this(ST.BULLET_DOT, style); | |
80 } | |
81 /** | |
82 * Create a new bullet the specified style and type. | |
83 * The style must have a glyph metrics set. | |
84 * | |
246 | 85 * @param type the bullet type |
155 | 86 * @param style the style |
87 * | |
88 * @exception IllegalArgumentException <ul> | |
89 * <li>ERROR_NULL_ARGUMENT when the style or the glyph metrics are null</li> | |
90 * </ul> | |
91 */ | |
92 public this(int type, StyleRange style) { | |
93 if (style is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
94 if (style.metrics is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
95 this.type = type; | |
96 this.style = style; | |
97 } | |
98 void addIndices (int startLine, int lineCount) { | |
99 if (linesIndices is null) { | |
100 linesIndices = new int[lineCount]; | |
101 count = lineCount; | |
102 for (int i = 0; i < lineCount; i++) linesIndices[i] = startLine + i; | |
103 } else { | |
104 int modifyStart = 0; | |
105 while (modifyStart < count) { | |
106 if (startLine <= linesIndices[modifyStart]) break; | |
107 modifyStart++; | |
108 } | |
109 int modifyEnd = modifyStart; | |
110 while (modifyEnd < count) { | |
111 if (startLine + lineCount <= linesIndices[modifyEnd]) break; | |
112 modifyEnd++; | |
113 } | |
114 int newSize = modifyStart + lineCount + count - modifyEnd; | |
115 if (newSize > linesIndices.length) { | |
116 int[] newLinesIndices = new int[newSize]; | |
117 System.arraycopy(linesIndices, 0, newLinesIndices, 0, count); | |
118 linesIndices = newLinesIndices; | |
119 } | |
120 System.arraycopy(linesIndices, modifyEnd, linesIndices, modifyStart + lineCount, count - modifyEnd); | |
121 for (int i = 0; i < lineCount; i++) linesIndices[modifyStart + i] = startLine + i; | |
122 count = newSize; | |
123 } | |
124 } | |
125 int indexOf (int lineIndex) { | |
126 for (int i = 0; i < count; i++) { | |
127 if (linesIndices[i] is lineIndex) return i; | |
128 } | |
129 return -1; | |
130 } | |
131 public override hash_t toHash() { | |
132 return style.toHash() ^ type; | |
133 } | |
134 int[] removeIndices (int startLine, int replaceLineCount, int newLineCount, bool update) { | |
135 if (count is 0) return null; | |
136 if (startLine > linesIndices[count - 1]) return null; | |
137 int endLine = startLine + replaceLineCount; | |
138 int delta = newLineCount - replaceLineCount; | |
139 for (int i = 0; i < count; i++) { | |
140 int index = linesIndices[i]; | |
141 if (startLine <= index) { | |
142 int j = i; | |
143 while (j < count) { | |
144 if (linesIndices[j] >= endLine) break; | |
145 j++; | |
146 } | |
147 if (update) { | |
148 for (int k = j; k < count; k++) linesIndices[k] += delta; | |
149 } | |
150 int[] redrawLines = new int[count - j]; | |
151 System.arraycopy(linesIndices, j, redrawLines, 0, count - j); | |
152 System.arraycopy(linesIndices, j, linesIndices, i, count - j); | |
153 count -= (j - i); | |
154 return redrawLines; | |
155 } | |
156 } | |
157 for (int i = 0; i < count; i++) linesIndices[i] += delta; | |
158 return null; | |
159 } | |
160 int size() { | |
161 return count; | |
162 } | |
163 } |