comparison dwtx/novocode/ishell/InternalShell.d @ 190:df4e66472aff

novocode line endings, indention
author Frank Benoit <benoit@tionex.de>
date Sun, 26 Oct 2008 15:04:41 +0100
parents 71ca5bcf2307
children
comparison
equal deleted inserted replaced
189:71ca5bcf2307 190:df4e66472aff
52 // [TODO] Support styles NO_TRIM, BORDER, TITLE 52 // [TODO] Support styles NO_TRIM, BORDER, TITLE
53 // [TODO] Separate "minimized" from "not visible" 53 // [TODO] Separate "minimized" from "not visible"
54 54
55 class InternalShell : Composite 55 class InternalShell : Composite
56 { 56 {
57 private static const int BORDER_SIZE = 4; 57 private static const int BORDER_SIZE = 4;
58 58
59 private Composite contentPane; 59 private Composite contentPane;
60 private TitleBar titleBar; 60 private TitleBar titleBar;
61 private SizeGrip sizeGrip; 61 private SizeGrip sizeGrip;
62 private SizeBorder sizeBorder; 62 private SizeBorder sizeBorder;
63 private int minWidth = 112; 63 private int minWidth = 112;
64 private int minHeight; 64 private int minHeight;
65 private DesktopForm desktop; 65 private DesktopForm desktop;
66 private bool maximized; 66 private bool maximized;
67 private Rectangle pluralizedBounds; 67 private Rectangle pluralizedBounds;
68 private int titleHeight; 68 private int titleHeight;
69 private int style; 69 private int style;
70 private TitleBarButton closeButton, maxButton, minButton; 70 private TitleBarButton closeButton, maxButton, minButton;
71 71
72 Control focusControl; 72 Control focusControl;
73 73
74 74
75 this(DesktopForm parent, int style) 75 this(DesktopForm parent, int style)
76 { 76 {
77 super(parent, checkStyle(style)); 77 super(parent, checkStyle(style));
78 this.desktop = parent; 78 this.desktop = parent;
79 this.style = style; 79 this.style = style;
80 setBackground(getDisplay().getSystemColor(DWT.COLOR_WIDGET_BACKGROUND)); 80 setBackground(getDisplay().getSystemColor(DWT.COLOR_WIDGET_BACKGROUND));
81 FormLayout layout = new FormLayout(); 81 FormLayout layout = new FormLayout();
82 setLayout(layout); 82 setLayout(layout);
83 FormData fd; 83 FormData fd;
84 84
85 titleBar = new TitleBar(this, style & (DWT.CLOSE | DWT.RESIZE | DWT.MAX | DWT.TOOL | DWT.MIN)); 85 titleBar = new TitleBar(this, style & (DWT.CLOSE | DWT.RESIZE | DWT.MAX | DWT.TOOL | DWT.MIN));
86 titleHeight = titleBar.computeSize(DWT.DEFAULT, DWT.DEFAULT, true).y; 86 titleHeight = titleBar.computeSize(DWT.DEFAULT, DWT.DEFAULT, true).y;
87 87
88 Control leftButton = null; 88 Control leftButton = null;
89 89
90 if((style & (DWT.CLOSE | DWT.MAX | DWT.MIN)) !is 0) 90 if((style & (DWT.CLOSE | DWT.MAX | DWT.MIN)) !is 0)
91 { 91 {
92 closeButton = new TitleBarButton(this, DWT.CLOSE); 92 closeButton = new TitleBarButton(this, DWT.CLOSE);
93 if((style & DWT.CLOSE) is 0) closeButton.setEnabled(false); 93 if((style & DWT.CLOSE) is 0) closeButton.setEnabled(false);
94 closeButton.addListener(DWT.Selection, dgListener(&closeListener)); 94 closeButton.addListener(DWT.Selection, dgListener(&closeListener));
95 fd = new FormData(titleHeight, titleHeight); 95 fd = new FormData(titleHeight, titleHeight);
96 if(leftButton !is null) fd.right = new FormAttachment(leftButton); 96 if(leftButton !is null) fd.right = new FormAttachment(leftButton);
97 else fd.right = new FormAttachment(100, -BORDER_SIZE); 97 else fd.right = new FormAttachment(100, -BORDER_SIZE);
98 fd.top = new FormAttachment(0, BORDER_SIZE); 98 fd.top = new FormAttachment(0, BORDER_SIZE);
99 closeButton.setLayoutData(fd); 99 closeButton.setLayoutData(fd);
100 leftButton = closeButton; 100 leftButton = closeButton;
101 101
102 if((style & (DWT.MAX|DWT.MIN)) !is 0) 102 if((style & (DWT.MAX|DWT.MIN)) !is 0)
103 { 103 {
104 maxButton = new TitleBarButton(this, DWT.MAX); 104 maxButton = new TitleBarButton(this, DWT.MAX);
105 if((style & DWT.MAX) is 0) maxButton.setEnabled(false); 105 if((style & DWT.MAX) is 0) maxButton.setEnabled(false);
106 maxButton.addListener(DWT.Selection, dgListener(&maximizeListener)); 106 maxButton.addListener(DWT.Selection, dgListener(&maximizeListener));
107 fd = new FormData(titleHeight, titleHeight); 107 fd = new FormData(titleHeight, titleHeight);
108 if(leftButton !is null) fd.right = new FormAttachment(leftButton);
109 else fd.right = new FormAttachment(100, -BORDER_SIZE);
110 fd.top = new FormAttachment(0, BORDER_SIZE);
111 maxButton.setLayoutData(fd);
112 leftButton = maxButton;
113
114 minButton = new TitleBarButton(this, DWT.MIN);
115 if((style & DWT.MIN) is 0) minButton.setEnabled(false);
116 minButton.addListener(DWT.Selection, dgListener(&minimizeListener));
117 fd = new FormData(titleHeight, titleHeight);
118 if(leftButton !is null) fd.right = new FormAttachment(leftButton);
119 else fd.right = new FormAttachment(100, -BORDER_SIZE);
120 fd.top = new FormAttachment(0, BORDER_SIZE);
121 minButton.setLayoutData(fd);
122 leftButton = minButton;
123 }
124 }
125
126 fd = new FormData();
127 fd.left = new FormAttachment(0, BORDER_SIZE);
108 if(leftButton !is null) fd.right = new FormAttachment(leftButton); 128 if(leftButton !is null) fd.right = new FormAttachment(leftButton);
109 else fd.right = new FormAttachment(100, -BORDER_SIZE); 129 else fd.right = new FormAttachment(100, -BORDER_SIZE);
110 fd.top = new FormAttachment(0, BORDER_SIZE); 130 fd.top = new FormAttachment(0, BORDER_SIZE);
111 maxButton.setLayoutData(fd); 131 titleBar.setLayoutData(fd);
112 leftButton = maxButton; 132
113 133 contentPane = new Composite(this, DWT.NONE);
114 minButton = new TitleBarButton(this, DWT.MIN); 134 fd = new FormData();
115 if((style & DWT.MIN) is 0) minButton.setEnabled(false); 135 fd.left = new FormAttachment(0, BORDER_SIZE);
116 minButton.addListener(DWT.Selection, dgListener(&minimizeListener)); 136 fd.right = new FormAttachment(100, -BORDER_SIZE);
117 fd = new FormData(titleHeight, titleHeight); 137 fd.top = new FormAttachment(titleBar, 1);
118 if(leftButton !is null) fd.right = new FormAttachment(leftButton); 138 fd.bottom = new FormAttachment(100, -BORDER_SIZE);
119 else fd.right = new FormAttachment(100, -BORDER_SIZE); 139 contentPane.setLayoutData(fd);
120 fd.top = new FormAttachment(0, BORDER_SIZE); 140
121 minButton.setLayoutData(fd); 141 sizeBorder = new SizeBorder(this, this, DWT.BORDER);
122 leftButton = minButton; 142 sizeBorder.setBorderWidth(BORDER_SIZE);
123 } 143 fd = new FormData();
124 } 144 fd.left = new FormAttachment(0);
125 145 fd.right = new FormAttachment(100);
126 fd = new FormData(); 146 fd.top = new FormAttachment(0);
127 fd.left = new FormAttachment(0, BORDER_SIZE); 147 fd.bottom = new FormAttachment(100);
128 if(leftButton !is null) fd.right = new FormAttachment(leftButton); 148 sizeBorder.setLayoutData(fd);
129 else fd.right = new FormAttachment(100, -BORDER_SIZE); 149
130 fd.top = new FormAttachment(0, BORDER_SIZE); 150 minHeight = titleHeight + 2*BORDER_SIZE;
131 titleBar.setLayoutData(fd); 151 sizeBorder.setMinimumShellSize(minWidth, minHeight);
132 152 sizeBorder.setCornerSize(titleHeight + BORDER_SIZE);
133 contentPane = new Composite(this, DWT.NONE); 153 if((style & DWT.RESIZE) is 0) sizeBorder.setEnabled(false);
134 fd = new FormData(); 154
135 fd.left = new FormAttachment(0, BORDER_SIZE); 155 setSize(320, 240);
136 fd.right = new FormAttachment(100, -BORDER_SIZE); 156 setVisible(false);
137 fd.top = new FormAttachment(titleBar, 1); 157
138 fd.bottom = new FormAttachment(100, -BORDER_SIZE); 158 desktop.manage(this);
139 contentPane.setLayoutData(fd); 159 }
140 160
141 sizeBorder = new SizeBorder(this, this, DWT.BORDER); 161
142 sizeBorder.setBorderWidth(BORDER_SIZE); 162 private void closeListener(Event event)
143 fd = new FormData(); 163 {
144 fd.left = new FormAttachment(0); 164 close();
145 fd.right = new FormAttachment(100); 165 }
146 fd.top = new FormAttachment(0); 166
147 fd.bottom = new FormAttachment(100); 167
148 sizeBorder.setLayoutData(fd); 168 private void maximizeListener(Event event)
149 169 {
150 minHeight = titleHeight + 2*BORDER_SIZE; 170 setMaximized(!maximized);
151 sizeBorder.setMinimumShellSize(minWidth, minHeight); 171 }
152 sizeBorder.setCornerSize(titleHeight + BORDER_SIZE); 172
153 if((style & DWT.RESIZE) is 0) sizeBorder.setEnabled(false); 173
154 174 private void minimizeListener(Event event)
155 setSize(320, 240); 175 {
156 setVisible(false); 176 setMinimized(true);
157 177 }
158 desktop.manage(this); 178
159 } 179
160 180 private static int checkStyle(int style)
161 181 {
162 private void closeListener(Event event) 182 int mask = DWT.NO_RADIO_GROUP;
163 { 183 style &= mask;
164 close(); 184 return style;
165 } 185 }
166 186
167 187
168 private void maximizeListener(Event event) 188 public int getStyle()
169 { 189 {
170 setMaximized(!maximized); 190 return style;
171 } 191 }
172 192
173 193
174 private void minimizeListener(Event event) 194 public Composite getContentPane() { return contentPane; }
175 { 195
176 setMinimized(true); 196
177 } 197 public void setText(String s) { titleBar.setText(s); }
178 198
179 199 public String getText() { return titleBar.getText(); }
180 private static int checkStyle(int style) 200
181 { 201
182 int mask = DWT.NO_RADIO_GROUP; 202 public void setCustomMenu(Menu menu) { titleBar.setMenu(menu); }
183 style &= mask; 203
184 return style; 204 public Menu getCustomMenu() { return titleBar.getMenu(); }
185 } 205
186 206
187 207 public void setImage(Image image) { titleBar.setImage(image); }
188 public int getStyle() 208
189 { 209 public Image getImage() { return titleBar.getImage(); }
190 return style; 210
191 } 211
192 212 public void createSizeGrip(int style)
193 213 {
194 public Composite getContentPane() { return contentPane; } 214 checkWidget();
195 215 if(sizeGrip !is null)
196 216 throw new DWTException("SizeGrip was already created");
197 public void setText(String s) { titleBar.setText(s); } 217 if((this.style & DWT.RESIZE) is 0)
198 218 throw new DWTException("Cannot create SizeGrip for InternalShell without style RESIZE");
199 public String getText() { return titleBar.getText(); } 219 sizeGrip = new SizeGrip(this, this, style);
200 220 sizeGrip.setBackground(contentPane.getBackground());
201 221 sizeGrip.moveAbove(contentPane);
202 public void setCustomMenu(Menu menu) { titleBar.setMenu(menu); } 222 FormData fd = new FormData();
203 223 fd.right = new FormAttachment(100, -BORDER_SIZE);
204 public Menu getCustomMenu() { return titleBar.getMenu(); } 224 fd.bottom = new FormAttachment(100, -BORDER_SIZE);
205 225 sizeGrip.setLayoutData(fd);
206 226 sizeGrip.setMinimumShellSize(minWidth, minHeight);
207 public void setImage(Image image) { titleBar.setImage(image); } 227 if(isVisible()) layout(true);
208 228 }
209 public Image getImage() { return titleBar.getImage(); } 229
210 230
211 231 public Point computeSize(int wHint, int hHint, bool changed)
212 public void createSizeGrip(int style) 232 {
213 { 233 Point p = super.computeSize(wHint, hHint, changed);
214 checkWidget(); 234 if(p.x < minWidth) p.x = minWidth;
215 if(sizeGrip !is null) 235 if(p.y < minHeight) p.y = minHeight;
216 throw new DWTException("SizeGrip was already created"); 236 return p;
217 if((this.style & DWT.RESIZE) is 0) 237 }
218 throw new DWTException("Cannot create SizeGrip for InternalShell without style RESIZE"); 238
219 sizeGrip = new SizeGrip(this, this, style); 239
220 sizeGrip.setBackground(contentPane.getBackground()); 240 public void setSize(int width, int height)
221 sizeGrip.moveAbove(contentPane); 241 {
222 FormData fd = new FormData(); 242 if(width < minWidth) width = minWidth;
223 fd.right = new FormAttachment(100, -BORDER_SIZE); 243 if(height < minHeight) height = minHeight;
224 fd.bottom = new FormAttachment(100, -BORDER_SIZE); 244 super.setSize(width, height);
225 sizeGrip.setLayoutData(fd); 245 }
226 sizeGrip.setMinimumShellSize(minWidth, minHeight); 246
227 if(isVisible()) layout(true); 247
228 } 248 public void setBounds(int x, int y, int width, int height)
229 249 {
230 250 if(width < minWidth) width = minWidth;
231 public Point computeSize(int wHint, int hHint, bool changed) 251 if(height < minHeight) height = minHeight;
232 { 252 super.setBounds(x, y, width, height);
233 Point p = super.computeSize(wHint, hHint, changed); 253 }
234 if(p.x < minWidth) p.x = minWidth; 254
235 if(p.y < minHeight) p.y = minHeight; 255
236 return p; 256 public void setMinimumSize(int width, int height)
237 } 257 {
238 258 checkWidget();
239 259 minWidth = width;
240 public void setSize(int width, int height) 260 minHeight = height;
241 { 261 sizeGrip.setMinimumShellSize(minWidth, minHeight);
242 if(width < minWidth) width = minWidth; 262 sizeBorder.setMinimumShellSize(minWidth, minHeight);
243 if(height < minHeight) height = minHeight; 263 Point size = getSize();
244 super.setSize(width, height); 264 if(size.x < minWidth || size.y < minHeight)
245 } 265 setSize(Math.max(minWidth, size.x), Math.max(minHeight, size.y));
246 266 }
247 267
248 public void setBounds(int x, int y, int width, int height) 268
249 { 269 public void close()
250 if(width < minWidth) width = minWidth; 270 {
251 if(height < minHeight) height = minHeight; 271 Event event = new Event();
252 super.setBounds(x, y, width, height); 272 notifyListeners(DWT.Close, event);
253 } 273 if(event.doit && !isDisposed()) dispose();
254 274 }
255 275
256 public void setMinimumSize(int width, int height) 276
257 { 277 public void open()
258 checkWidget(); 278 {
259 minWidth = width; 279 desktop.activate(this);
260 minHeight = height; 280 setVisible(true);
261 sizeGrip.setMinimumShellSize(minWidth, minHeight); 281 setFocus();
262 sizeBorder.setMinimumShellSize(minWidth, minHeight); 282 }
263 Point size = getSize(); 283
264 if(size.x < minWidth || size.y < minHeight) 284
265 setSize(Math.max(minWidth, size.x), Math.max(minHeight, size.y)); 285 public void setVisible(bool visible)
266 } 286 {
267 287 if(!visible) desktop.shellVisibilityChanged(this, false);
268 288 super.setVisible(visible);
269 public void close() 289 if(visible) desktop.shellVisibilityChanged(this, true);
270 { 290 }
271 Event event = new Event(); 291
272 notifyListeners(DWT.Close, event); 292
273 if(event.doit && !isDisposed()) dispose(); 293 public void setActive()
274 } 294 {
275 295 desktop.activate(this);
276 296 }
277 public void open() 297
278 { 298
279 desktop.activate(this); 299 public void setMaximized(bool maximized)
280 setVisible(true); 300 {
281 setFocus(); 301 checkWidget();
282 } 302 if(this.maximized is maximized) return;
283 303 setMaximizedWithoutNotification(maximized);
284 304 desktop.shellMaximizedOrRestored(this, maximized);
285 public void setVisible(bool visible) 305 }
286 { 306
287 if(!visible) desktop.shellVisibilityChanged(this, false); 307
288 super.setVisible(visible); 308 public void setMinimized(bool minimized)
289 if(visible) desktop.shellVisibilityChanged(this, true); 309 {
290 } 310 checkWidget();
291 311 bool wasMaximized = maximized;
292 312 setVisible(!minimized);
293 public void setActive() 313 maximized = wasMaximized;
294 { 314 }
295 desktop.activate(this); 315
296 } 316
297 317 public bool getMinimized()
298 318 {
299 public void setMaximized(bool maximized) 319 return getVisible();
300 { 320 }
301 checkWidget(); 321
302 if(this.maximized is maximized) return; 322
303 setMaximizedWithoutNotification(maximized); 323 void setMaximizedWithoutNotification(bool maximized)
304 desktop.shellMaximizedOrRestored(this, maximized); 324 {
305 } 325 if(this.maximized is maximized) return;
306 326 this.maximized = maximized;
307 327 if(maximized)
308 public void setMinimized(bool minimized) 328 {
309 { 329 pluralizedBounds = getBounds();
310 checkWidget(); 330 desktopResized(desktop.getClientArea());
311 bool wasMaximized = maximized; 331 }
312 setVisible(!minimized); 332 else
313 maximized = wasMaximized; 333 {
314 } 334 setBounds(pluralizedBounds.x,pluralizedBounds.y,pluralizedBounds.width,pluralizedBounds.height);
315 335 }
316 336 // Note: This method may be called in a Dispose event for this object
317 public bool getMinimized() 337 if(sizeGrip !is null && !sizeGrip.isDisposed()) sizeGrip.setVisible(!maximized);
318 { 338 if(!sizeBorder.isDisposed()) sizeBorder.setEnabled(!maximized && (style & DWT.RESIZE) !is 0);
319 return getVisible(); 339 if(maxButton !is null && !maxButton.isDisposed()) maxButton.redraw();
320 } 340 }
321 341
322 342
323 void setMaximizedWithoutNotification(bool maximized) 343 public bool getMaximized()
324 { 344 {
325 if(this.maximized is maximized) return; 345 checkWidget();
326 this.maximized = maximized; 346 return maximized;
327 if(maximized) 347 }
328 { 348
329 pluralizedBounds = getBounds(); 349
330 desktopResized(desktop.getClientArea()); 350 void redrawDecorationsAfterActivityChange()
331 } 351 {
332 else 352 // Note: This method may be called in a Dispose event for this object
333 { 353 if(!titleBar.isDisposed()) titleBar.redraw();
334 setBounds(pluralizedBounds.x,pluralizedBounds.y,pluralizedBounds.width,pluralizedBounds.height); 354 if(closeButton !is null && !closeButton.isDisposed()) closeButton.redraw();
335 } 355 if(maxButton !is null && !maxButton.isDisposed()) maxButton.redraw();
336 // Note: This method may be called in a Dispose event for this object 356 if(minButton !is null && !minButton.isDisposed()) minButton.redraw();
337 if(sizeGrip !is null && !sizeGrip.isDisposed()) sizeGrip.setVisible(!maximized); 357 }
338 if(!sizeBorder.isDisposed()) sizeBorder.setEnabled(!maximized && (style & DWT.RESIZE) !is 0); 358
339 if(maxButton !is null && !maxButton.isDisposed()) maxButton.redraw(); 359
340 } 360 void desktopResized(Rectangle deskCA)
341 361 {
342 362 if(maximized)
343 public bool getMaximized() 363 {
344 { 364 int hideTitle = desktop.getShowMaximizedTitle() ? 0 : (titleHeight+1);
345 checkWidget(); 365 setBounds(deskCA.x - BORDER_SIZE,
346 return maximized; 366 deskCA.y - BORDER_SIZE - hideTitle,
347 } 367 deskCA.width + 2*BORDER_SIZE,
348 368 deskCA.height + 2*BORDER_SIZE + hideTitle);
349 369 }
350 void redrawDecorationsAfterActivityChange() 370 else forceVisibleLocation(deskCA);
351 { 371 }
352 // Note: This method may be called in a Dispose event for this object 372
353 if(!titleBar.isDisposed()) titleBar.redraw(); 373
354 if(closeButton !is null && !closeButton.isDisposed()) closeButton.redraw(); 374 public bool setFocus()
355 if(maxButton !is null && !maxButton.isDisposed()) maxButton.redraw(); 375 {
356 if(minButton !is null && !minButton.isDisposed()) minButton.redraw(); 376 if(focusControl !is null && focusControl !is this && !focusControl.isDisposed())
357 } 377 return focusControl.setFocus();
358 378 return super.setFocus();
359 379 }
360 void desktopResized(Rectangle deskCA) 380
361 { 381
362 if(maximized) 382 public bool isActiveShell()
363 { 383 {
364 int hideTitle = desktop.getShowMaximizedTitle() ? 0 : (titleHeight+1); 384 return desktop.getActiveShell() is this;
365 setBounds(deskCA.x - BORDER_SIZE, 385 }
366 deskCA.y - BORDER_SIZE - hideTitle, 386
367 deskCA.width + 2*BORDER_SIZE, 387
368 deskCA.height + 2*BORDER_SIZE + hideTitle); 388 private void forceVisibleLocation(Rectangle deskCA)
369 } 389 {
370 else forceVisibleLocation(deskCA); 390 Point p = getLocation();
371 } 391 Point minGrabSize = titleBar.getMinGrabSize();
372 392 int x = p.x, y = p.y;
373 393 int minX = minGrabSize.x + BORDER_SIZE, minY = minGrabSize.y + BORDER_SIZE;
374 public bool setFocus() 394 x = Math.min(Math.max(x, deskCA.x+minY), deskCA.x+deskCA.width-minX);
375 { 395 y = Math.min(Math.max(y, deskCA.y+minY), deskCA.y+deskCA.height-minY);
376 if(focusControl !is null && focusControl !is this && !focusControl.isDisposed()) 396 if(x != p.x || y != p.y) setLocation(x, y);
377 return focusControl.setFocus(); 397 }
378 return super.setFocus();
379 }
380
381
382 public bool isActiveShell()
383 {
384 return desktop.getActiveShell() is this;
385 }
386
387
388 private void forceVisibleLocation(Rectangle deskCA)
389 {
390 Point p = getLocation();
391 Point minGrabSize = titleBar.getMinGrabSize();
392 int x = p.x, y = p.y;
393 int minX = minGrabSize.x + BORDER_SIZE, minY = minGrabSize.y + BORDER_SIZE;
394 x = Math.min(Math.max(x, deskCA.x+minY), deskCA.x+deskCA.width-minX);
395 y = Math.min(Math.max(y, deskCA.y+minY), deskCA.y+deskCA.height-minY);
396 if(x != p.x || y != p.y) setLocation(x, y);
397 }
398 } 398 }