comparison dwtx/draw2d/text/NestedLine.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) 2004, 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
14 module dwtx.draw2d.text.NestedLine;
15
16 import dwt.dwthelper.utils;
17 import dwtx.draw2d.text.LineBox;
18 import dwtx.draw2d.text.LineRoot;
19 import dwtx.draw2d.text.InlineFlow;
20 import dwtx.draw2d.text.FlowUtilities;
21 import dwtx.draw2d.text.FlowBox;
22
23 /**
24 * @since 3.1
25 */
26 public class NestedLine : LineBox {
27
28 InlineFlow owner;
29 private LineRoot root;
30
31 this(InlineFlow owner) {
32 this.owner = owner;
33 }
34
35 /**
36 * @see dwtx.draw2d.text.FlowBox#containsPoint(int, int)
37 */
38 public bool containsPoint(int x, int y) {
39 //$TODO should contains use LineRoot?
40 return x >= getX()
41 && x < getX() + getWidth()
42 && y >= getBaseline() - getAscentWithBorder()
43 && y < getBaseline() + getDescentWithBorder();
44 }
45
46 int getAscentWithBorder() {
47 return contentAscent + FlowUtilities.getBorderAscent(owner);
48 }
49
50 int getDescentWithBorder() {
51 return contentDescent + FlowUtilities.getBorderDescent(owner);
52 }
53
54 /**
55 * @see dwtx.draw2d.text.FlowBox#getBaseline()
56 */
57 public int getBaseline() {
58 return root.getBaseline();
59 }
60
61 LineRoot getLineRoot() {
62 return root;
63 }
64
65 //int getVisibleAscent() {
66 // return contentAscent + FlowUtilities.getBorderAscent(owner);
67 //}
68 //
69 //int getVisibleDescent() {
70 // return contentDescent + FlowUtilities.getBorderDescent(owner);
71 //}
72
73 /**
74 * Returns the outer ascent of this box. The outer ascent is the ascent above the
75 * baseline including the border size and margin. This is used when adding content into a
76 * LineBox. The linebox's own border must be drawn around the children.
77 * @return the outer ascent of this box
78 */
79 public int getOuterAscent() {
80 return contentAscent + FlowUtilities.getBorderAscentWithMargin(owner);
81 }
82
83 /**
84 * Returns the outer descent of this box. The outer descent is the space below the
85 * baseline including the border size and margin. This is used when adding content into a
86 * LineBox. The linebox's own border must be drawn around the children.
87 * @return the outer descent of this box
88 */
89 public int getOuterDescent() {
90 return contentDescent + FlowUtilities.getBorderDescentWithMargin(owner);
91 }
92
93 void setLineRoot(LineRoot root) {
94 this.root = root;
95 for (int i = 0; i < fragments.size(); i++)
96 (cast(FlowBox)fragments.get(i)).setLineRoot(root);
97 }
98
99 /**
100 * @see dwtx.draw2d.text.CompositeBox#setLineTop(int)
101 */
102 public void setLineTop(int top) {
103 throw new RuntimeException("not supported"); //$NON-NLS-1$
104 }
105
106 }