comparison org.eclipse.ui.forms/src/org/eclipse/ui/forms/widgets/Twistie.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
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 org.eclipse.ui.forms.widgets.Twistie;
14
15 import org.eclipse.ui.forms.widgets.ToggleHyperlink;
16
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.graphics.Color;
19 import org.eclipse.swt.graphics.GC;
20 import org.eclipse.swt.graphics.Point;
21 import org.eclipse.swt.widgets.Composite;
22
23 import java.lang.all;
24 import java.util.Set;
25
26 /**
27 * A custom selectable control that can be used to control areas that can be
28 * expanded or collapsed. The control control can be toggled between selected
29 * and deselected state with a mouse or by pressing 'Enter' while the control
30 * has focus.
31 * <p>
32 * The control is rendered as a triangle that points to the right in the
33 * collapsed and down in the expanded state. Triangle color can be changed.
34 *
35 * @see TreeNode
36 * @since 3.0
37 */
38 public class Twistie : ToggleHyperlink {
39 private static const int[] onPoints = [ 0, 2, 8, 2, 4, 6 ];
40
41 private static const int[] offPoints = [ 2, -1, 2, 8, 6, 4 ];
42
43 /**
44 * Creates a control in a provided composite.
45 *
46 * @param parent
47 * the parent
48 * @param style
49 * the style
50 */
51 public this(Composite parent, int style) {
52 super(parent, style);
53 innerWidth = 9;
54 innerHeight = 9;
55 }
56
57 /*
58 * @see SelectableControl#paint(GC)
59 */
60 protected void paintHyperlink(GC gc) {
61 Color bg;
62 if (!isEnabled())
63 bg = getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
64 else if (hover && getHoverDecorationColor() !is null)
65 bg = getHoverDecorationColor();
66 else if (getDecorationColor() !is null)
67 bg = getDecorationColor();
68 else
69 bg = getForeground();
70 gc.setBackground(bg);
71 int[] data;
72 Point size = getSize();
73 int x = (size.x - 9) / 2;
74 int y = (size.y - 9) / 2;
75 if (isExpanded())
76 data = translate(onPoints, x, y);
77 else
78 data = translate(offPoints, x, y);
79 gc.fillPolygon(data);
80 gc.setBackground(getBackground());
81 }
82
83 private int[] translate(int[] data, int x, int y) {
84 int[] target = new int[data.length];
85 for (int i = 0; i < data.length; i += 2) {
86 target[i] = data[i] + x;
87 }
88 for (int i = 1; i < data.length; i += 2) {
89 target[i] = data[i] + y;
90 }
91 return target;
92 }
93
94 /*
95 * (non-Javadoc)
96 *
97 * @see org.eclipse.swt.widgets.Control#setEnabled(bool)
98 */
99 public void setEnabled(bool enabled) {
100 super.setEnabled(enabled);
101 redraw();
102 }
103 }