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