Mercurial > projects > dwt-addons
comparison dwtx/ui/forms/widgets/TreeNode.d @ 75:5d489b9f966c
Fix continue porting
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 24 May 2008 05:11:16 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
74:dad2e11b8ae4 | 75:5d489b9f966c |
---|---|
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.forms.widgets.TreeNode; | |
14 | |
15 import dwtx.ui.forms.widgets.ToggleHyperlink; | |
16 | |
17 import dwt.DWT; | |
18 import dwt.events.PaintEvent; | |
19 import dwt.graphics.GC; | |
20 import dwt.graphics.Rectangle; | |
21 import dwt.widgets.Composite; | |
22 | |
23 import dwt.dwthelper.utils; | |
24 | |
25 /** | |
26 * A custom selectable control that can be used to control areas that can be | |
27 * expanded or collapsed. The control control can be toggled between selected | |
28 * and deselected state with a mouse or by pressing 'Enter' while the control | |
29 * has focus. | |
30 * <p> | |
31 * The control is rendered as box with a '+' or '-' sign, depending on the | |
32 * expansion state. Focus indication is rendered around the box when the | |
33 * control has keyboard focus. | |
34 * | |
35 * @see Twistie | |
36 * @since 3.0 | |
37 */ | |
38 public class TreeNode : ToggleHyperlink { | |
39 /** | |
40 * Creates a control in a provided composite. | |
41 * | |
42 * @param parent | |
43 * the parent | |
44 * @param style | |
45 * the style | |
46 */ | |
47 public this(Composite parent, int style) { | |
48 super(parent, style); | |
49 innerWidth = 10; | |
50 innerHeight = 10; | |
51 } | |
52 protected void paint(PaintEvent e) { | |
53 paintHyperlink(e.gc); | |
54 } | |
55 protected void paintHyperlink(GC gc) { | |
56 Rectangle box = getBoxBounds(gc); | |
57 gc.setForeground(getDisplay().getSystemColor( | |
58 DWT.COLOR_WIDGET_NORMAL_SHADOW)); | |
59 gc.drawRectangle(box); | |
60 gc.setForeground(getForeground()); | |
61 gc.drawLine(box.x + 2, box.y + 4, box.x + 6, box.y + 4); | |
62 if (!isExpanded()) { | |
63 gc.drawLine(box.x + 4, box.y + 2, box.x + 4, box.y + 6); | |
64 } | |
65 if (paintFocus && getSelection()) { | |
66 gc.setForeground(getForeground()); | |
67 gc.drawFocus(box.x - 1, box.y - 1, box.width + 3, box.height + 3); | |
68 } | |
69 } | |
70 private Rectangle getBoxBounds(GC gc) { | |
71 int x = 1; | |
72 int y = 0; | |
73 gc.setFont(getFont()); | |
74 //int height = gc.getFontMetrics().getHeight(); | |
75 //y = height / 2 - 4; | |
76 //y = Math.max(y, 0); | |
77 y = 2; | |
78 return new Rectangle(x, y, 8, 8); | |
79 } | |
80 } |