75
|
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.ui.forms.widgets.Twistie;
|
|
14
|
|
15 import dwtx.ui.forms.widgets.ToggleHyperlink;
|
|
16
|
|
17 import dwt.DWT;
|
|
18 import dwt.graphics.Color;
|
|
19 import dwt.graphics.GC;
|
|
20 import dwt.graphics.Point;
|
|
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 a triangle that points to the right in the
|
|
32 * collapsed and down in the expanded state. Triangle color can be changed.
|
|
33 *
|
|
34 * @see TreeNode
|
|
35 * @since 3.0
|
|
36 */
|
|
37 public class Twistie : ToggleHyperlink {
|
|
38 private static const int[] onPoints = [ 0, 2, 8, 2, 4, 6 ];
|
|
39
|
|
40 private static const int[] offPoints = [ 2, -1, 2, 8, 6, 4 ];
|
|
41
|
|
42 /**
|
|
43 * Creates a control in a provided composite.
|
|
44 *
|
|
45 * @param parent
|
|
46 * the parent
|
|
47 * @param style
|
|
48 * the style
|
|
49 */
|
|
50 public this(Composite parent, int style) {
|
|
51 super(parent, style);
|
|
52 innerWidth = 9;
|
|
53 innerHeight = 9;
|
|
54 }
|
|
55
|
|
56 /*
|
|
57 * @see SelectableControl#paint(GC)
|
|
58 */
|
|
59 protected void paintHyperlink(GC gc) {
|
|
60 Color bg;
|
|
61 if (!isEnabled())
|
|
62 bg = getDisplay().getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW);
|
|
63 else if (hover && getHoverDecorationColor() !is null)
|
|
64 bg = getHoverDecorationColor();
|
|
65 else if (getDecorationColor() !is null)
|
|
66 bg = getDecorationColor();
|
|
67 else
|
|
68 bg = getForeground();
|
|
69 gc.setBackground(bg);
|
|
70 int[] data;
|
|
71 Point size = getSize();
|
|
72 int x = (size.x - 9) / 2;
|
|
73 int y = (size.y - 9) / 2;
|
|
74 if (isExpanded())
|
|
75 data = translate(onPoints, x, y);
|
|
76 else
|
|
77 data = translate(offPoints, x, y);
|
|
78 gc.fillPolygon(data);
|
|
79 gc.setBackground(getBackground());
|
|
80 }
|
|
81
|
|
82 private int[] translate(int[] data, int x, int y) {
|
|
83 int[] target = new int[data.length];
|
|
84 for (int i = 0; i < data.length; i += 2) {
|
|
85 target[i] = data[i] + x;
|
|
86 }
|
|
87 for (int i = 1; i < data.length; i += 2) {
|
|
88 target[i] = data[i] + y;
|
|
89 }
|
|
90 return target;
|
|
91 }
|
|
92
|
|
93 /*
|
|
94 * (non-Javadoc)
|
|
95 *
|
|
96 * @see dwt.widgets.Control#setEnabled(bool)
|
|
97 */
|
|
98 public void setEnabled(bool enabled) {
|
|
99 super.setEnabled(enabled);
|
|
100 redraw();
|
|
101 }
|
|
102 }
|