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;
|
|
25
|
|
26 public abstract class ObjectSegment : ParagraphSegment {
|
|
27 public static const int TOP = 1;
|
|
28
|
|
29 public static const int MIDDLE = 2;
|
|
30
|
|
31 public static const int BOTTOM = 3;
|
|
32
|
|
33 private int alignment = BOTTOM;
|
|
34 private bool nowrap=false;
|
|
35 private Rectangle bounds;
|
|
36 private String objectId;
|
|
37
|
|
38 public int getVerticalAlignment() {
|
|
39 return alignment;
|
|
40 }
|
|
41
|
|
42 void setVerticalAlignment(int alignment) {
|
|
43 this.alignment = alignment;
|
|
44 }
|
|
45
|
|
46 public String getObjectId() {
|
|
47 return objectId;
|
|
48 }
|
|
49
|
|
50 void setObjectId(String objectId) {
|
|
51 this.objectId = objectId;
|
|
52 }
|
|
53
|
|
54 protected abstract Point getObjectSize(Hashtable resourceTable, int wHint);
|
|
55
|
|
56 public bool advanceLocator(GC gc, int wHint, Locator loc,
|
|
57 Hashtable objectTable, bool computeHeightOnly) {
|
|
58 Point objectSize = getObjectSize(objectTable, wHint);
|
|
59 int iwidth = 0;
|
|
60 int iheight = 0;
|
|
61 bool newLine = false;
|
|
62
|
|
63 if (objectSize !is null) {
|
|
64 iwidth = objectSize.x + (isSelectable()?2:0);
|
|
65 iheight = objectSize.y + (isSelectable()?2:0);
|
|
66 }
|
|
67 if (wHint !is DWT.DEFAULT && !nowrap && loc.x + iwidth > wHint) {
|
|
68 // new line
|
|
69 if (computeHeightOnly)
|
|
70 loc.collectHeights();
|
|
71 loc.x = loc.indent;
|
|
72 loc.x += iwidth;
|
|
73 loc.y += loc.rowHeight;
|
|
74 loc.width = loc.indent + iwidth;
|
|
75 loc.rowHeight = iheight;
|
|
76 loc.leading = 0;
|
|
77 newLine = true;
|
|
78 } else {
|
|
79 loc.x += iwidth;
|
|
80 loc.width += iwidth;
|
|
81 loc.rowHeight = Math.max(loc.rowHeight, iheight);
|
|
82 }
|
|
83 return newLine;
|
|
84 }
|
|
85
|
|
86 public bool contains(int x, int y) {
|
|
87 if (boundsisnull)
|
|
88 return false;
|
|
89 return bounds.contains(x, y);
|
|
90 }
|
|
91 public bool intersects(Rectangle rect) {
|
|
92 if (boundsisnull)
|
|
93 return false;
|
|
94 return bounds.intersects(rect);
|
|
95 }
|
|
96
|
|
97 public Rectangle getBounds() {
|
|
98 return bounds;
|
|
99 }
|
|
100
|
|
101 public bool isSelectable() {
|
|
102 return false;
|
|
103 }
|
|
104 /**
|
|
105 * @return Returns the nowrap.
|
|
106 */
|
|
107 public bool isNowrap() {
|
|
108 return nowrap;
|
|
109 }
|
|
110 /**
|
|
111 * @param nowrap The nowrap to set.
|
|
112 */
|
|
113 public void setNowrap(bool nowrap) {
|
|
114 this.nowrap = nowrap;
|
|
115 }
|
|
116 public void paint(GC gc, bool hover, Hashtable resourceTable, bool selected, SelectionData selData, Rectangle repaintRegion) {
|
|
117 }
|
|
118
|
|
119 /* (non-Javadoc)
|
|
120 * @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)
|
|
121 */
|
|
122 public void layout(GC gc, int width, Locator loc, Hashtable resourceTable,
|
|
123 bool selected) {
|
|
124 Point size = getObjectSize(resourceTable, width);
|
|
125
|
|
126 int objWidth = 0;
|
|
127 int objHeight = 0;
|
|
128 if (size !is null) {
|
|
129 objWidth = size.x + (isSelectable()?2:0);
|
|
130 objHeight = size.y + (isSelectable()?2:0);
|
|
131 } else
|
|
132 return;
|
|
133 loc.width = objWidth;
|
|
134
|
|
135 if (!nowrap && loc.x + objWidth > width) {
|
|
136 // new row
|
|
137 loc.newLine();
|
|
138 loc.rowCounter++;
|
|
139 }
|
|
140 int ix = loc.x;
|
|
141 int iy = loc.y;
|
|
142
|
|
143 if (alignmentisMIDDLE)
|
|
144 iy = loc.getMiddle(objHeight, false);
|
|
145 else if (alignmentisBOTTOM)
|
|
146 iy = loc.getBaseline(objHeight, false);
|
|
147 loc.x += objWidth;
|
|
148 loc.rowHeight = Math.max(loc.rowHeight, objHeight);
|
|
149 bounds = new Rectangle(ix, iy, objWidth, objHeight);
|
|
150 }
|
|
151 /* (non-Javadoc)
|
|
152 * @see dwtx.ui.internal.forms.widgets.ParagraphSegment#computeSelection(dwt.graphics.GC, java.util.Hashtable, bool, dwtx.ui.internal.forms.widgets.SelectionData)
|
|
153 */
|
|
154 public void computeSelection(GC gc, Hashtable resourceTable, SelectionData selData) {
|
|
155 // TODO we should add this to the selection
|
|
156 // if we want to support rich text
|
|
157 }
|
|
158 }
|