Mercurial > projects > dwt-addons
comparison dwtx/novocode/CustomSeparator.d @ 188:e3780acbbf80
Added ported sources from Novocode, thanks to WasserDragoon
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 26 Oct 2008 14:54:39 +0100 |
parents | |
children | df4e66472aff |
comparison
equal
deleted
inserted
replaced
187:293a2f22f944 | 188:e3780acbbf80 |
---|---|
1 /** | |
2 Original: com.novocode.naf.swt.custom.CustomSeparator | |
3 ***/ | |
4 | |
5 /******************************************************************************* | |
6 * Copyright (c) 2004 Stefan Zeiger and others. | |
7 * All rights reserved. This program and the accompanying materials | |
8 * are made available under the terms of the Eclipse Public License v1.0 | |
9 * which accompanies this distribution, and is available at | |
10 * http://www.novocode.com/legal/epl-v10.html | |
11 * | |
12 * Contributors: | |
13 * Stefan Zeiger (szeiger@novocode.com) - initial API and implementation | |
14 *******************************************************************************/ | |
15 | |
16 module dwtx.novocode.CustomSeparator; | |
17 | |
18 import dwt.DWT; | |
19 /**import dwt.events.PaintEvent;**/ | |
20 /**import dwt.events.PaintListener;**/ | |
21 import dwt.graphics.Color; | |
22 import dwt.graphics.Point; | |
23 import dwt.graphics.Rectangle; | |
24 import dwt.widgets.Canvas; | |
25 import dwt.widgets.Composite; | |
26 import dwt.widgets.Display; | |
27 import dwt.widgets.Event; | |
28 import dwt.widgets.Listener; | |
29 | |
30 | |
31 /** | |
32 * Instances of this class are non-native separator lines. | |
33 * <dl> | |
34 * <dt><b>Styles:</b></dt> | |
35 * <dd>SHADOW_IN, SHADOW_OUT, SHADOW_NONE, HORIZONTAL, VERTICAL</dd> | |
36 * <dt><b>Events:</b></dt> | |
37 * <dd>(none)</dd> | |
38 * </dl> | |
39 * <p> | |
40 * Note: Only one of SHADOW_IN, SHADOW_OUT and SHADOW_NONE may be specified. | |
41 * If neither ist specified, the default value SHADOW_IN is used. If SHADOW_NONE | |
42 * is specified, a single line is drawn with the control's foreground color. | |
43 * Only one of HORIZONTAL and VERTICAL may be specified. The default is VERTICAL. | |
44 * </p> | |
45 * | |
46 * @author Stefan Zeiger (szeiger@novocode.com) | |
47 * @since Feb 12, 2004 | |
48 * @version $Id: CustomSeparator.java 199 2004-10-08 13:20:36 +0000 (Fri, 08 Oct 2004) szeiger $ | |
49 */ | |
50 | |
51 class CustomSeparator : Canvas | |
52 { | |
53 private int lineSize; | |
54 private int style; | |
55 | |
56 | |
57 this(Composite parent, int style) | |
58 { | |
59 super(parent, style = checkStyle (style)); | |
60 | |
61 this.style = style; | |
62 | |
63 if((style & DWT.SHADOW_IN) !is 0 || (style & DWT.SHADOW_OUT) !is 0) lineSize = 2; | |
64 else lineSize = 1; | |
65 | |
66 /**addPaintListener(new class() PaintListener | |
67 { | |
68 public void paintControl(PaintEvent event) { onPaint(event); } | |
69 });*/ | |
70 addListener(DWT.Paint, dgListener(&onPaint)); | |
71 } | |
72 | |
73 | |
74 private int checkStyle(int style) | |
75 { | |
76 int mask = DWT.SHADOW_IN | DWT.SHADOW_OUT| DWT.SHADOW_NONE | DWT.HORIZONTAL | DWT.VERTICAL; | |
77 style &= mask; | |
78 if((style & (DWT.SHADOW_IN | DWT.SHADOW_OUT| DWT.SHADOW_NONE)) is 0) style |= DWT.SHADOW_IN; | |
79 if((style & (DWT.HORIZONTAL | DWT.VERTICAL)) is 0) style |= DWT.VERTICAL; | |
80 return style; | |
81 } | |
82 | |
83 | |
84 public Point computeSize(int wHint, int hHint, bool changed) | |
85 { | |
86 checkWidget(); | |
87 if(wHint is DWT.DEFAULT) wHint = lineSize; | |
88 if(hHint is DWT.DEFAULT) hHint = lineSize; | |
89 return new Point(wHint, hHint); | |
90 } | |
91 | |
92 | |
93 public bool setFocus() | |
94 { | |
95 checkWidget(); | |
96 return false; | |
97 } | |
98 | |
99 | |
100 private void onPaint(PaintEvent event) | |
101 { | |
102 Rectangle r = getClientArea(); | |
103 if(r.width is 0 || r.height is 0) return; | |
104 bool horiz = ((style & DWT.HORIZONTAL) !is 0); | |
105 int mid = horiz ? r.y + (r.height/2) : r.x + (r.width/2); | |
106 | |
107 Display disp = getDisplay(); | |
108 event.gc.setLineWidth(1); | |
109 | |
110 if((style & DWT.SHADOW_IN) !is 0) | |
111 { | |
112 Color shadow = disp.getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW); | |
113 Color highlight = disp.getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW); | |
114 event.gc.setForeground(shadow); | |
115 if(horiz) event.gc.drawLine(r.x, mid-1, r.x+r.width-1, mid-1); | |
116 else event.gc.drawLine(mid-1, r.y, mid-1, r.y+r.height-1); | |
117 event.gc.setForeground(highlight); | |
118 if(horiz) event.gc.drawLine(r.x, mid, r.x+r.width-1, mid); | |
119 else event.gc.drawLine(mid, r.y, mid, r.y+r.height-1); | |
120 } | |
121 else if((style & DWT.SHADOW_OUT) !is 0) | |
122 { | |
123 Color shadow = disp.getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW); | |
124 Color highlight = disp.getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW); | |
125 event.gc.setForeground(highlight); | |
126 if(horiz) event.gc.drawLine(r.x, mid-1, r.x+r.width-1, mid-1); | |
127 else event.gc.drawLine(mid-1, r.y, mid-1, r.y+r.height-1); | |
128 event.gc.setForeground(shadow); | |
129 if(horiz) event.gc.drawLine(r.x, mid, r.x+r.width-1, mid); | |
130 else event.gc.drawLine(mid, r.y, mid, r.y+r.height-1); | |
131 } | |
132 else | |
133 { | |
134 event.gc.setForeground(getForeground()); | |
135 if(horiz) event.gc.drawLine(r.x, mid, r.x+r.width-1, mid); | |
136 else event.gc.drawLine(mid, r.y, mid, r.y+r.height-1); | |
137 } | |
138 } | |
139 } |