Mercurial > projects > dwt-addons
comparison dwtx/novocode/ishell/internal/TitleBarButton.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 | 71ca5bcf2307 |
comparison
equal
deleted
inserted
replaced
187:293a2f22f944 | 188:e3780acbbf80 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2005 Stefan Zeiger 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.novocode.com/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * Stefan Zeiger (szeiger@novocode.com) - initial API and implementation | |
10 *******************************************************************************/ | |
11 | |
12 module dwtx.novocode.ishell.internal.TitleBarButton; | |
13 | |
14 import dwt.DWT; | |
15 import dwt.graphics.Color; | |
16 import dwt.graphics.GC; | |
17 import dwt.graphics.Point; | |
18 import dwt.widgets.Display; | |
19 import dwt.widgets.Event; | |
20 import dwt.widgets.Listener; | |
21 import dwt.widgets.Shell; | |
22 | |
23 import dwtx.novocode.ishell.InternalShell; | |
24 import dwtx.novocode.ishell.internal.CustomDrawnButton; | |
25 | |
26 | |
27 /** | |
28 * A title bar button for an InternalShell. | |
29 * | |
30 * @author Stefan Zeiger (szeiger@novocode.com) | |
31 * @since Jan 30, 2005 | |
32 * @version $Id: TitleBarButton.java 322 2005-02-26 20:31:26 +0000 (Sat, 26 Feb 2005) szeiger $ | |
33 */ | |
34 | |
35 class TitleBarButton : CustomDrawnButton | |
36 { | |
37 private Color highlightShadowColor, lightShadowColor, normalShadowColor, darkShadowColor; | |
38 private Color gradEndColor, inactiveGradEndColor, widgetBackgroundColor, widgetForegroundColor; | |
39 private int style; | |
40 private Shell shell; | |
41 private Display display; | |
42 private InternalShell ishell; | |
43 private int leftOff, rightOff; | |
44 private Listener activateListener, deactivateListener; | |
45 | |
46 this(InternalShell parent, int style) | |
47 { | |
48 super(parent, DWT.NO_FOCUS | DWT.NO_BACKGROUND); | |
49 this.style = style; | |
50 this.shell = getShell(); | |
51 this.display = getDisplay(); | |
52 this.ishell = parent; | |
53 | |
54 highlightShadowColor = display.getSystemColor(DWT.COLOR_WIDGET_HIGHLIGHT_SHADOW); | |
55 lightShadowColor = display.getSystemColor(DWT.COLOR_WIDGET_LIGHT_SHADOW); | |
56 normalShadowColor = display.getSystemColor(DWT.COLOR_WIDGET_NORMAL_SHADOW); | |
57 darkShadowColor = display.getSystemColor(DWT.COLOR_WIDGET_DARK_SHADOW); | |
58 gradEndColor = display.getSystemColor(DWT.COLOR_TITLE_BACKGROUND_GRADIENT); | |
59 inactiveGradEndColor = display.getSystemColor(DWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT); | |
60 widgetBackgroundColor = display.getSystemColor(DWT.COLOR_WIDGET_BACKGROUND); | |
61 widgetForegroundColor = display.getSystemColor(DWT.COLOR_WIDGET_FOREGROUND); | |
62 | |
63 if((style & (DWT.CLOSE | DWT.MAX)) !is 0) rightOff = 2; | |
64 else leftOff = 2; | |
65 | |
66 activateListener = dgListener(&onActivateListener); | |
67 deactivateListener = dgListener(&onDeactivateListener); | |
68 shell.addListener(DWT.Activate, activateListener); | |
69 shell.addListener(DWT.Deactivate, deactivateListener); | |
70 | |
71 addListener(DWT.Dispose, dgListener(&onDispose)); | |
72 } | |
73 | |
74 | |
75 private void onActivateListener(Event event) | |
76 { | |
77 redraw(); | |
78 } | |
79 | |
80 | |
81 private void onDeactivateListener(Event event) | |
82 { | |
83 redraw(); | |
84 } | |
85 | |
86 | |
87 private void onDispose(Event event) | |
88 { | |
89 shell.removeListener(DWT.Activate, activateListener); | |
90 shell.removeListener(DWT.Deactivate, deactivateListener); | |
91 } | |
92 | |
93 | |
94 public int getStyle() | |
95 { | |
96 return style; | |
97 } | |
98 | |
99 | |
100 protected void onPaint(Event event, bool pressed) | |
101 { | |
102 Point size = getSize(); | |
103 bool active = (shell is display.getActiveShell() && ishell.isActiveShell()); | |
104 GC gc = event.gc; | |
105 | |
106 gc.setBackground(active ? gradEndColor : inactiveGradEndColor); | |
107 gc.fillRectangle(0, 0, size.x, size.y); | |
108 gc.setBackground(widgetBackgroundColor); | |
109 gc.fillRectangle(2, 4, size.x-4, size.y-6); | |
110 | |
111 Color tloColor, tliColor, broColor, briColor; | |
112 int pOff; | |
113 if(pressed) | |
114 { | |
115 tloColor = darkShadowColor; | |
116 tliColor = normalShadowColor; | |
117 broColor = highlightShadowColor; | |
118 briColor = lightShadowColor; | |
119 pOff = 1; | |
120 } | |
121 else | |
122 { | |
123 tloColor = highlightShadowColor; | |
124 tliColor = lightShadowColor; | |
125 broColor = darkShadowColor; | |
126 briColor = normalShadowColor; | |
127 pOff = 0; | |
128 } | |
129 | |
130 drawBevelRect(gc, leftOff, 2, size.x-1-leftOff-rightOff, size.y-5, tloColor, broColor); | |
131 drawBevelRect(gc, 1+leftOff, 3, size.x-3-leftOff-rightOff, size.y-7, tliColor, briColor); | |
132 | |
133 if(isEnabled()) | |
134 { | |
135 gc.setForeground(widgetForegroundColor); | |
136 drawImage(gc, size, pOff); | |
137 } | |
138 else | |
139 { | |
140 gc.setForeground(highlightShadowColor); | |
141 drawImage(gc, size, 1); | |
142 gc.setForeground(normalShadowColor); | |
143 drawImage(gc, size, 0); | |
144 } | |
145 } | |
146 | |
147 | |
148 private void drawImage(GC gc, Point size, int pOff) | |
149 { | |
150 if((style & DWT.CLOSE) !is 0) drawCloseImage(gc, size, pOff); | |
151 else if((style & DWT.MAX) !is 0) | |
152 { | |
153 if(ishell.getMaximized()) drawRestoreImage(gc, size, pOff); | |
154 else drawMaximizeImage(gc, size, pOff); | |
155 } | |
156 else if((style & DWT.MIN) !is 0) drawMinimizeImage(gc, size, pOff); | |
157 } | |
158 | |
159 | |
160 private static void drawBevelRect(GC gc, int x, int y, int w, int h, Color topleft, Color bottomright) | |
161 { | |
162 gc.setForeground(bottomright); | |
163 gc.drawLine(x + w, y, x + w, y + h); | |
164 gc.drawLine(x, y + h, x + w, y + h); | |
165 | |
166 gc.setForeground(topleft); | |
167 gc.drawLine(x, y, x + w - 1, y); | |
168 gc.drawLine(x, y, x, y + h - 1); | |
169 } | |
170 | |
171 | |
172 private void drawCloseImage(GC gc, Point size, int pOff) | |
173 { | |
174 gc.drawLine(pOff+leftOff+4, pOff+5, pOff+size.x-leftOff-rightOff-6, pOff+size.y-7); | |
175 gc.drawLine(pOff+leftOff+5, pOff+5, pOff+size.x-leftOff-rightOff-5, pOff+size.y-7); | |
176 gc.drawLine(pOff+leftOff+4, pOff+size.y-7, pOff+size.x-leftOff-rightOff-6, pOff+5); | |
177 gc.drawLine(pOff+leftOff+5, pOff+size.y-7, pOff+size.x-leftOff-rightOff-5, pOff+5); | |
178 } | |
179 | |
180 | |
181 private void drawRestoreImage(GC gc, Point size, int pOff) | |
182 { | |
183 gc.drawRectangle(pOff+leftOff+3, pOff+7, size.x-leftOff-rightOff-11, size.y-13); | |
184 gc.drawLine(pOff+leftOff+4, pOff+8, pOff+size.x-leftOff-rightOff-9, pOff+8); | |
185 gc.drawLine(pOff+leftOff+6, pOff+5, pOff+size.x-leftOff-rightOff-7, pOff+5); | |
186 gc.drawLine(pOff+leftOff+5, pOff+4, pOff+size.x-leftOff-rightOff-6, pOff+4); | |
187 gc.drawLine(pOff+size.x-leftOff-rightOff-7, pOff+size.y-9, pOff+size.x-leftOff-rightOff-6, pOff+size.y-9); | |
188 gc.drawLine(pOff+size.x-leftOff-rightOff-6, pOff+size.y-10, pOff+size.x-leftOff-rightOff-6, pOff+5); | |
189 gc.drawLine(pOff+leftOff+5, pOff+5, pOff+leftOff+5, pOff+6); | |
190 } | |
191 | |
192 | |
193 private void drawMaximizeImage(GC gc, Point size, int pOff) | |
194 { | |
195 gc.drawRectangle(pOff+leftOff+3, pOff+4, size.x-leftOff-rightOff-8, size.y-10); | |
196 gc.drawLine(pOff+leftOff+4, pOff+5, pOff+size.x-leftOff-rightOff-6, pOff+5); | |
197 } | |
198 | |
199 | |
200 private void drawMinimizeImage(GC gc, Point size, int pOff) | |
201 { | |
202 gc.drawLine(pOff+leftOff+4, pOff+size.y-6, pOff+size.x-leftOff-rightOff-5, pOff+size.y-6); | |
203 gc.drawLine(pOff+leftOff+4, pOff+size.y-7, pOff+size.x-leftOff-rightOff-5, pOff+size.y-7); | |
204 } | |
205 } |