Mercurial > projects > dwt-addons
comparison dwtx/draw2d/text/BlockBox.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.BlockBox; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 | |
17 import dwtx.draw2d.geometry.Rectangle; | |
18 import dwtx.draw2d.text.CompositeBox; | |
19 import dwtx.draw2d.text.BlockFlow; | |
20 import dwtx.draw2d.text.LineRoot; | |
21 import dwtx.draw2d.text.FlowBox; | |
22 | |
23 /** | |
24 * A CompositeBox suitable for containing multiple LineBox fragments. | |
25 * @author hudsonr | |
26 * @since 2.1 | |
27 */ | |
28 public class BlockBox | |
29 : CompositeBox | |
30 { | |
31 | |
32 int height; | |
33 private int y; | |
34 BlockFlow owner; | |
35 | |
36 this(BlockFlow owner) { | |
37 this.owner = owner; | |
38 } | |
39 | |
40 /** | |
41 * @see CompositeBox#add(FlowBox) | |
42 */ | |
43 public void add(FlowBox box) { | |
44 width = Math.max(width, box.getWidth()); | |
45 height = Math.max(height, box.getBaseline() + box.getDescent()); | |
46 } | |
47 | |
48 /** | |
49 * @see FlowBox#containsPoint(int, int) | |
50 */ | |
51 public bool containsPoint(int x, int y) { | |
52 return true; | |
53 } | |
54 | |
55 /** | |
56 * @see FlowBox#getAscent() | |
57 */ | |
58 public int getAscent() { | |
59 return 0; | |
60 } | |
61 | |
62 /** | |
63 * @see FlowBox#getBaseline() | |
64 */ | |
65 public int getBaseline() { | |
66 return y; | |
67 } | |
68 | |
69 int getBottomMargin() { | |
70 return owner.getBottomMargin(); | |
71 } | |
72 | |
73 /** | |
74 * @see FlowBox#getDescent() | |
75 */ | |
76 public int getDescent() { | |
77 return height; | |
78 } | |
79 | |
80 /** | |
81 * @return Returns the height. | |
82 */ | |
83 public int getHeight() { | |
84 return height; | |
85 } | |
86 | |
87 LineRoot getLineRoot() { | |
88 return null; | |
89 } | |
90 | |
91 int getTopMargin() { | |
92 return owner.getTopMargin(); | |
93 } | |
94 | |
95 /** | |
96 * Sets the height. | |
97 * @param h The height | |
98 */ | |
99 public void setHeight(int h) { | |
100 height = h; | |
101 } | |
102 | |
103 /** | |
104 * @see CompositeBox#setLineTop(int) | |
105 */ | |
106 public void setLineTop(int y) { | |
107 this.y = y; | |
108 } | |
109 | |
110 Rectangle toRectangle() { | |
111 return new Rectangle(getX(), y, Math.max(getWidth(), recommendedWidth), height); | |
112 } | |
113 | |
114 } |