Mercurial > projects > dwt-addons
annotate dwtx/ui/internal/forms/widgets/ObjectSegment.d @ 104:04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 07 Aug 2008 15:01:33 +0200 |
parents | 26c6c9dfd13c |
children |
rev | line source |
---|---|
75 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 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 dwtx.ui.internal.forms.widgets.ObjectSegment; | |
14 | |
15 import dwtx.ui.internal.forms.widgets.ParagraphSegment; | |
16 import dwtx.ui.internal.forms.widgets.Locator; | |
17 import dwtx.ui.internal.forms.widgets.SelectionData; | |
18 | |
19 import dwt.DWT; | |
20 import dwt.graphics.GC; | |
21 import dwt.graphics.Point; | |
22 import dwt.graphics.Rectangle; | |
23 | |
24 import dwt.dwthelper.utils; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
77
diff
changeset
|
25 import dwtx.dwtxhelper.Collection; |
75 | 26 |
27 public abstract class ObjectSegment : ParagraphSegment { | |
28 public static const int TOP = 1; | |
29 | |
30 public static const int MIDDLE = 2; | |
31 | |
32 public static const int BOTTOM = 3; | |
33 | |
34 private int alignment = BOTTOM; | |
35 private bool nowrap=false; | |
36 private Rectangle bounds; | |
37 private String objectId; | |
38 | |
39 public int getVerticalAlignment() { | |
40 return alignment; | |
41 } | |
42 | |
43 void setVerticalAlignment(int alignment) { | |
44 this.alignment = alignment; | |
45 } | |
46 | |
47 public String getObjectId() { | |
48 return objectId; | |
49 } | |
50 | |
51 void setObjectId(String objectId) { | |
52 this.objectId = objectId; | |
53 } | |
54 | |
55 protected abstract Point getObjectSize(Hashtable resourceTable, int wHint); | |
56 | |
57 public bool advanceLocator(GC gc, int wHint, Locator loc, | |
58 Hashtable objectTable, bool computeHeightOnly) { | |
59 Point objectSize = getObjectSize(objectTable, wHint); | |
60 int iwidth = 0; | |
61 int iheight = 0; | |
62 bool newLine = false; | |
63 | |
64 if (objectSize !is null) { | |
65 iwidth = objectSize.x + (isSelectable()?2:0); | |
66 iheight = objectSize.y + (isSelectable()?2:0); | |
67 } | |
68 if (wHint !is DWT.DEFAULT && !nowrap && loc.x + iwidth > wHint) { | |
69 // new line | |
70 if (computeHeightOnly) | |
71 loc.collectHeights(); | |
72 loc.x = loc.indent; | |
73 loc.x += iwidth; | |
74 loc.y += loc.rowHeight; | |
75 loc.width = loc.indent + iwidth; | |
76 loc.rowHeight = iheight; | |
77 loc.leading = 0; | |
78 newLine = true; | |
79 } else { | |
80 loc.x += iwidth; | |
81 loc.width += iwidth; | |
82 loc.rowHeight = Math.max(loc.rowHeight, iheight); | |
83 } | |
84 return newLine; | |
85 } | |
86 | |
87 public bool contains(int x, int y) { | |
77
26c6c9dfd13c
ui.forms compile, just FormTextModel with xml reimpl left todo
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
88 if (bounds is null) |
75 | 89 return false; |
90 return bounds.contains(x, y); | |
91 } | |
92 public bool intersects(Rectangle rect) { | |
77
26c6c9dfd13c
ui.forms compile, just FormTextModel with xml reimpl left todo
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
93 if (bounds is null) |
75 | 94 return false; |
95 return bounds.intersects(rect); | |
96 } | |
97 | |
98 public Rectangle getBounds() { | |
99 return bounds; | |
100 } | |
101 | |
102 public bool isSelectable() { | |
103 return false; | |
104 } | |
105 /** | |
106 * @return Returns the nowrap. | |
107 */ | |
108 public bool isNowrap() { | |
109 return nowrap; | |
110 } | |
111 /** | |
112 * @param nowrap The nowrap to set. | |
113 */ | |
114 public void setNowrap(bool nowrap) { | |
115 this.nowrap = nowrap; | |
116 } | |
117 public void paint(GC gc, bool hover, Hashtable resourceTable, bool selected, SelectionData selData, Rectangle repaintRegion) { | |
118 } | |
119 | |
120 /* (non-Javadoc) | |
121 * @see dwtx.ui.internal.forms.widgets.ParagraphSegment#layout(dwt.graphics.GC, int, dwtx.ui.internal.forms.widgets.Locator, java.util.Hashtable, bool, dwtx.ui.internal.forms.widgets.SelectionData) | |
122 */ | |
123 public void layout(GC gc, int width, Locator loc, Hashtable resourceTable, | |
124 bool selected) { | |
125 Point size = getObjectSize(resourceTable, width); | |
126 | |
127 int objWidth = 0; | |
128 int objHeight = 0; | |
129 if (size !is null) { | |
130 objWidth = size.x + (isSelectable()?2:0); | |
131 objHeight = size.y + (isSelectable()?2:0); | |
132 } else | |
133 return; | |
134 loc.width = objWidth; | |
135 | |
136 if (!nowrap && loc.x + objWidth > width) { | |
137 // new row | |
138 loc.newLine(); | |
139 loc.rowCounter++; | |
140 } | |
141 int ix = loc.x; | |
142 int iy = loc.y; | |
143 | |
77
26c6c9dfd13c
ui.forms compile, just FormTextModel with xml reimpl left todo
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
144 if (alignment is MIDDLE) |
75 | 145 iy = loc.getMiddle(objHeight, false); |
77
26c6c9dfd13c
ui.forms compile, just FormTextModel with xml reimpl left todo
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
146 else if (alignment is BOTTOM) |
75 | 147 iy = loc.getBaseline(objHeight, false); |
148 loc.x += objWidth; | |
149 loc.rowHeight = Math.max(loc.rowHeight, objHeight); | |
150 bounds = new Rectangle(ix, iy, objWidth, objHeight); | |
151 } | |
152 /* (non-Javadoc) | |
153 * @see dwtx.ui.internal.forms.widgets.ParagraphSegment#computeSelection(dwt.graphics.GC, java.util.Hashtable, bool, dwtx.ui.internal.forms.widgets.SelectionData) | |
154 */ | |
155 public void computeSelection(GC gc, Hashtable resourceTable, SelectionData selData) { | |
156 // TODO we should add this to the selection | |
157 // if we want to support rich text | |
158 } | |
159 } |