Mercurial > projects > dwt-addons
comparison dwtx/draw2d/text/LineBox.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.LineBox; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 import dwtx.dwtxhelper.Collection; | |
17 import dwtx.draw2d.text.CompositeBox; | |
18 import dwtx.draw2d.text.FlowBox; | |
19 | |
20 /** | |
21 * @author hudsonr | |
22 * @since 2.1 | |
23 */ | |
24 public abstract class LineBox | |
25 : CompositeBox | |
26 { | |
27 | |
28 /** | |
29 * The maximum ascent of all contained fragments. | |
30 */ | |
31 int contentAscent; | |
32 | |
33 /** | |
34 * The maximum descent of all contained fragments. | |
35 */ | |
36 int contentDescent; | |
37 | |
38 List fragments; | |
39 | |
40 public this(){ | |
41 fragments = new ArrayList(); | |
42 } | |
43 | |
44 /** | |
45 * @see dwtx.draw2d.text.CompositeBox#add(dwtx.draw2d.text.FlowBox) | |
46 */ | |
47 public void add(FlowBox child) { | |
48 fragments.add(child); | |
49 width += child.getWidth(); | |
50 contentAscent = Math.max(contentAscent, child.getOuterAscent()); | |
51 contentDescent = Math.max(contentDescent, child.getOuterDescent()); | |
52 } | |
53 | |
54 /** | |
55 * @see dwtx.draw2d.text.FlowBox#getAscent() | |
56 */ | |
57 public int getAscent() { | |
58 int ascent = 0; | |
59 for (int i = 0; i < fragments.size(); i++) | |
60 ascent = Math.max(ascent, (cast(FlowBox)fragments.get(i)).getAscent()); | |
61 return ascent; | |
62 } | |
63 | |
64 /** | |
65 * Returns the remaining width available for line content. | |
66 * @return the available width in pixels | |
67 */ | |
68 int getAvailableWidth() { | |
69 if (recommendedWidth < 0) | |
70 return Integer.MAX_VALUE; | |
71 return recommendedWidth - getWidth(); | |
72 } | |
73 | |
74 int getBottomMargin() { | |
75 return 0; | |
76 } | |
77 | |
78 /** | |
79 * @see dwtx.draw2d.text.FlowBox#getDescent() | |
80 */ | |
81 public int getDescent() { | |
82 int descent = 0; | |
83 for (int i = 0; i < fragments.size(); i++) | |
84 descent = Math.max(descent, (cast(FlowBox)fragments.get(i)).getDescent()); | |
85 return descent; | |
86 } | |
87 | |
88 /** | |
89 * @return Returns the fragments. | |
90 */ | |
91 List getFragments() { | |
92 return fragments; | |
93 } | |
94 | |
95 int getTopMargin() { | |
96 return 0; | |
97 } | |
98 | |
99 /** | |
100 * @return <code>true</code> if this box contains any fragments | |
101 */ | |
102 public bool isOccupied() { | |
103 return !fragments.isEmpty(); | |
104 } | |
105 | |
106 /** | |
107 * @see dwtx.draw2d.text.FlowBox#requiresBidi() | |
108 */ | |
109 public bool requiresBidi() { | |
110 for (Iterator iter = getFragments().iterator(); iter.hasNext();) { | |
111 FlowBox box = cast(FlowBox)iter.next(); | |
112 if (box.requiresBidi()) | |
113 return true; | |
114 } | |
115 return false; | |
116 } | |
117 | |
118 } |