Mercurial > projects > dwt-addons
comparison dwtx/draw2d/text/FlowBox.d @ 98:95307ad235d9
Added Draw2d code, still work in progress
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 03 Aug 2008 00:52:14 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
96:b492ba44e44d | 98:95307ad235d9 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2005 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.draw2d.text.FlowBox; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 import dwtx.draw2d.text.LineRoot; | |
17 | |
18 /** | |
19 * A Geometric object for representing a region on a line of Text. This class adds the | |
20 * notion of a baseline to {@link dwtx.draw2d.geometry.Rectangle}. <i>Ascent</i> is | |
21 * the distance above the baseline. <i>Descent</i> is the distance below the baseline. | |
22 * <P> | |
23 * This class should not be treated as a <code>Rectangle</code> by clients. It is | |
24 * important to use getters when available for lazy calculation of values. | |
25 * | |
26 * @author hudsonr | |
27 * @since 2.1 | |
28 */ | |
29 public abstract class FlowBox { | |
30 | |
31 int width; | |
32 | |
33 /** | |
34 * The x location | |
35 */ | |
36 private int x; | |
37 | |
38 /** | |
39 * This method must be called on a block that is completely positioned and committed. | |
40 * @param x X | |
41 * @param y Y | |
42 * @return <code>true</code> if the FlowBox contains the point | |
43 */ | |
44 public abstract bool containsPoint(int x, int y); | |
45 | |
46 /** | |
47 * Returns the amount of line content in pixels which is above the baseline. Ascent and | |
48 * descent are used to space consecutive lines apart. Certain types of line content, such | |
49 * as borders, extend beyond the ascent and descent. | |
50 * @return the <i>descent</i> in pixels below the baseline | |
51 */ | |
52 public abstract int getAscent(); | |
53 | |
54 /** | |
55 * Returns y coordinate for the box's baseline. | |
56 * @return the baseline location | |
57 * @since 3.1 | |
58 */ | |
59 public abstract int getBaseline(); | |
60 | |
61 /** | |
62 * Returns the amount of line content in pixels which is below the baseline. | |
63 * @return the <i>descent</i> in pixels | |
64 * @see #getAscent() | |
65 */ | |
66 public abstract int getDescent(); | |
67 | |
68 /** | |
69 * Returns the root LineBox in which this box is placed. The root line is interesting | |
70 * when painting selection or hit testing. All boxes in a line should render selection at | |
71 * the same top and bottom location. | |
72 * @return the line root. | |
73 * @since 3.1 | |
74 */ | |
75 abstract LineRoot getLineRoot(); | |
76 | |
77 /** | |
78 * Returns the outer ascent of this box. The outer ascent is the ascent above the | |
79 * baseline including the border size and margin. This is used when adding content into a | |
80 * LineBox. The linebox's own border must be drawn around the children. | |
81 */ | |
82 int getOuterAscent() { | |
83 return getAscent(); | |
84 } | |
85 | |
86 /** | |
87 * Returns the outer descent of this box. The outer descent is the space below the | |
88 * baseline including the border size and margin. This is used when adding content into a | |
89 * LineBox. The linebox's own border must be drawn around the children. | |
90 */ | |
91 int getOuterDescent() { | |
92 return getDescent(); | |
93 } | |
94 | |
95 int getAscentWithBorder() { | |
96 throw new RuntimeException("Not valid on this box type"); //$NON-NLS-1$ | |
97 } | |
98 | |
99 int getDescentWithBorder() { | |
100 throw new RuntimeException("Not valid on this box type"); //$NON-NLS-1$ | |
101 } | |
102 | |
103 /** | |
104 * Returns the width of the box. | |
105 * @return the box's width | |
106 */ | |
107 public int getWidth() { | |
108 return width; | |
109 } | |
110 | |
111 /** | |
112 * Returns the X coordinate of the box. | |
113 * @return the x coordinate | |
114 * @since 3.1 | |
115 */ | |
116 public int getX() { | |
117 return x; | |
118 } | |
119 | |
120 /** | |
121 * Returns <code>true</code> if any of the children are bi-directional. Default | |
122 * implementation returns false. | |
123 * | |
124 * @return <code>true</code> if the box is bi-directional | |
125 * @since 3.1 | |
126 */ | |
127 public bool requiresBidi() { | |
128 return false; | |
129 } | |
130 | |
131 /** | |
132 * Sets the line root. | |
133 * @param root the line root | |
134 * @since 3.1 | |
135 */ | |
136 void setLineRoot(LineRoot root) { | |
137 } | |
138 | |
139 /** | |
140 * Sets the width of the box. | |
141 * @param width the new width | |
142 * @since 3.1 | |
143 */ | |
144 public void setWidth(int width) { | |
145 this.width = width; | |
146 } | |
147 | |
148 /** | |
149 * Sets the x coordinate for this box. | |
150 * @param x the x coordinate | |
151 * @since 3.1 | |
152 */ | |
153 public void setX(int x) { | |
154 this.x = x; | |
155 } | |
156 | |
157 } |