Mercurial > projects > dwt-addons
comparison dwtx/novocode/ishell/internal/TitleBar.d @ 189:71ca5bcf2307
Replaced String alias with import dwt.dwthelper.util
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 26 Oct 2008 14:57:25 +0100 |
parents | e3780acbbf80 |
children | df4e66472aff |
comparison
equal
deleted
inserted
replaced
188:e3780acbbf80 | 189:71ca5bcf2307 |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2005 Stefan Zeiger and others. | 2 * Copyright (c) 2005 Stefan Zeiger and others. |
3 * All rights reserved. This program and the accompanying materials | 3 * All rights reserved. This program and the accompanying materials |
4 * are made available under the terms of the Eclipse Public License v1.0 | 4 * are made available under the terms of the Eclipse Public License v1.0 |
5 * which accompanies this distribution, and is available at | 5 * which accompanies this distribution, and is available at |
6 * http://www.novocode.com/legal/epl-v10.html | 6 * http://www.novocode.com/legal/epl-v10.html |
7 * | 7 * |
8 * Contributors: | 8 * Contributors: |
9 * Stefan Zeiger (szeiger@novocode.com) - initial API and implementation | 9 * Stefan Zeiger (szeiger@novocode.com) - initial API and implementation |
10 *******************************************************************************/ | 10 *******************************************************************************/ |
11 | 11 |
12 module dwtx.novocode.ishell.internal.TitleBar; | 12 module dwtx.novocode.ishell.internal.TitleBar; |
36 import dwt.widgets.Shell; | 36 import dwt.widgets.Shell; |
37 | 37 |
38 import dwtx.novocode.ishell.DesktopForm; | 38 import dwtx.novocode.ishell.DesktopForm; |
39 import dwtx.novocode.ishell.InternalShell; | 39 import dwtx.novocode.ishell.InternalShell; |
40 | 40 |
41 alias char[] String; | 41 import dwt.dwthelper.utils; |
42 | 42 |
43 | 43 |
44 /** | 44 /** |
45 * A title bar for an InternalShell. | 45 * A title bar for an InternalShell. |
46 * | 46 * |
47 * @author Stefan Zeiger (szeiger@novocode.com) | 47 * @author Stefan Zeiger (szeiger@novocode.com) |
48 * @since Jan 21, 2005 | 48 * @since Jan 21, 2005 |
49 * @version $Id: TitleBar.java 342 2005-07-09 20:37:13 +0000 (Sat, 09 Jul 2005) szeiger $ | 49 * @version $Id: TitleBar.java 342 2005-07-09 20:37:13 +0000 (Sat, 09 Jul 2005) szeiger $ |
50 */ | 50 */ |
51 | 51 |
129 | 129 |
130 maximizeItem = new MenuItem(defaultPopup, DWT.PUSH); | 130 maximizeItem = new MenuItem(defaultPopup, DWT.PUSH); |
131 maximizeItem.setText("Ma&ximize"); | 131 maximizeItem.setText("Ma&ximize"); |
132 maximizeItem.setImage(maximizeImage); | 132 maximizeItem.setImage(maximizeImage); |
133 maximizeItem.addListener(DWT.Selection, dgListener(&maximizeListener)); | 133 maximizeItem.addListener(DWT.Selection, dgListener(&maximizeListener)); |
134 | 134 |
135 new MenuItem(defaultPopup, DWT.SEPARATOR); | 135 new MenuItem(defaultPopup, DWT.SEPARATOR); |
136 | 136 |
137 closeItem = new MenuItem(defaultPopup, DWT.PUSH); | 137 closeItem = new MenuItem(defaultPopup, DWT.PUSH); |
138 closeItem.setText("&Close"); | 138 closeItem.setText("&Close"); |
139 closeItem.setEnabled(styleClose); | 139 closeItem.setEnabled(styleClose); |
149 | 149 |
150 activateListener = dgListener(&onActivateListener); | 150 activateListener = dgListener(&onActivateListener); |
151 deactivateListener = dgListener(&onDeactivateListener); | 151 deactivateListener = dgListener(&onDeactivateListener); |
152 shell.addListener(DWT.Activate, activateListener); | 152 shell.addListener(DWT.Activate, activateListener); |
153 shell.addListener(DWT.Deactivate, deactivateListener); | 153 shell.addListener(DWT.Deactivate, deactivateListener); |
154 | 154 |
155 addListener(DWT.Dispose, dgListener(&onDispose)); | 155 addListener(DWT.Dispose, dgListener(&onDispose)); |
156 } | 156 } |
157 | 157 |
158 | 158 |
159 private void restoreListener(Event event) | 159 private void restoreListener(Event event) |
182 | 182 |
183 private void onPaint(Event event) | 183 private void onPaint(Event event) |
184 { | 184 { |
185 Rectangle r = getClientArea(); | 185 Rectangle r = getClientArea(); |
186 if(r.width is 0 || r.height is 0) return; | 186 if(r.width is 0 || r.height is 0) return; |
187 | 187 |
188 bool active = (shell is display.getActiveShell() && ishell.isActiveShell()); | 188 bool active = (shell is display.getActiveShell() && ishell.isActiveShell()); |
189 | 189 |
190 GC gc = event.gc; | 190 GC gc = event.gc; |
191 gc.setForeground(active ? gradStartColor : inactiveGradStartColor); | 191 gc.setForeground(active ? gradStartColor : inactiveGradStartColor); |
192 gc.setBackground(active ? gradEndColor : inactiveGradEndColor); | 192 gc.setBackground(active ? gradEndColor : inactiveGradEndColor); |
193 gc.fillGradientRectangle(r.x, r.y, r.width, r.height, false); | 193 gc.fillGradientRectangle(r.x, r.y, r.width, r.height, false); |
194 | 194 |
195 int textLeftPadding = LEFT_PADDING; | 195 int textLeftPadding = LEFT_PADDING; |
196 if(image !is null) | 196 if(image !is null) |
197 { | 197 { |
198 Rectangle imageBounds = image.getBounds(); | 198 Rectangle imageBounds = image.getBounds(); |
199 if(imageBounds.width > IMAGE_SIZE || imageBounds.height > IMAGE_SIZE) | 199 if(imageBounds.width > IMAGE_SIZE || imageBounds.height > IMAGE_SIZE) |
200 gc.drawImage(image, 0, 0, imageBounds.width, imageBounds.height, LEFT_PADDING, TOP_PADDING, IMAGE_SIZE, IMAGE_SIZE); | 200 gc.drawImage(image, 0, 0, imageBounds.width, imageBounds.height, LEFT_PADDING, TOP_PADDING, IMAGE_SIZE, IMAGE_SIZE); |
201 else | 201 else |
202 gc.drawImage(image, LEFT_PADDING + (IMAGE_SIZE-imageBounds.width)/2, (r.height-imageBounds.height)/2); | 202 gc.drawImage(image, LEFT_PADDING + (IMAGE_SIZE-imageBounds.width)/2, (r.height-imageBounds.height)/2); |
203 textLeftPadding += IMAGE_SIZE + LEFT_PADDING; | 203 textLeftPadding += IMAGE_SIZE + LEFT_PADDING; |
204 } | 204 } |
205 | 205 |
206 if(text !is null && text.length() > 0) | 206 if(text !is null && text.length() > 0) |
207 { | 207 { |
208 gc.setForeground(active ? textColor : inactiveTextColor); | 208 gc.setForeground(active ? textColor : inactiveTextColor); |
209 String s = text; | 209 String s = text; |
210 int availableWidth = r.width - textLeftPadding - RIGHT_PADDING; | 210 int availableWidth = r.width - textLeftPadding - RIGHT_PADDING; |
391 newX = Math.min(Math.max(newX, deskCA.x-bounds.x-bounds.width+MINIMUM_GRAB_AREA), deskCA.x-bounds.x+deskCA.width-minGrabSize.x); | 391 newX = Math.min(Math.max(newX, deskCA.x-bounds.x-bounds.width+MINIMUM_GRAB_AREA), deskCA.x-bounds.x+deskCA.width-minGrabSize.x); |
392 newY = Math.min(Math.max(newY, deskCA.y-bounds.y-bounds.height+MINIMUM_GRAB_AREA), deskCA.y-bounds.y+deskCA.height-MINIMUM_GRAB_AREA); | 392 newY = Math.min(Math.max(newY, deskCA.y-bounds.y-bounds.height+MINIMUM_GRAB_AREA), deskCA.y-bounds.y+deskCA.height-MINIMUM_GRAB_AREA); |
393 | 393 |
394 if(newX !is p.x || newY !is p.y) ishell.setLocation(newX, newY); | 394 if(newX !is p.x || newY !is p.y) ishell.setLocation(newX, newY); |
395 } | 395 } |
396 | 396 |
397 | 397 |
398 public Point getMinGrabSize() | 398 public Point getMinGrabSize() |
399 { | 399 { |
400 return minGrabSize; | 400 return minGrabSize; |
401 } | 401 } |
402 | 402 |
436 public bool isReparentable () | 436 public bool isReparentable () |
437 { | 437 { |
438 checkWidget(); | 438 checkWidget(); |
439 return false; | 439 return false; |
440 } | 440 } |
441 | 441 |
442 | 442 |
443 public void setText(String text) | 443 public void setText(String text) |
444 { | 444 { |
445 checkWidget(); | 445 checkWidget(); |
446 this.text = text; | 446 this.text = text; |
447 redraw(); | 447 redraw(); |
448 } | 448 } |
449 | 449 |
450 | 450 |
451 public String getText() { return text; } | 451 public String getText() { return text; } |
452 | 452 |
453 | 453 |
454 public void setImage(Image image) | 454 public void setImage(Image image) |
455 { | 455 { |
456 checkWidget(); | 456 checkWidget(); |
457 if(styleTool) return; | 457 if(styleTool) return; |
458 this.image = image; | 458 this.image = image; |
459 minGrabSize.x = MINIMUM_GRAB_AREA; | 459 minGrabSize.x = MINIMUM_GRAB_AREA; |
460 if(image !is null) minGrabSize.x += LEFT_PADDING + IMAGE_SIZE; | 460 if(image !is null) minGrabSize.x += LEFT_PADDING + IMAGE_SIZE; |
461 redraw(); | 461 redraw(); |
462 } | 462 } |
463 | 463 |
464 | 464 |
465 public Image getImage() { return image; } | 465 public Image getImage() { return image; } |
466 | 466 |
467 | 467 |
468 private Font createTitleFont(Font f, bool tool) | 468 private Font createTitleFont(Font f, bool tool) |
469 { | 469 { |
473 fd.setStyle(fd.getStyle() | DWT.BOLD); | 473 fd.setStyle(fd.getStyle() | DWT.BOLD); |
474 if(tool) fd.setHeight(cast(int)(fd.getHeight()*0.9)); | 474 if(tool) fd.setHeight(cast(int)(fd.getHeight()*0.9)); |
475 } | 475 } |
476 return new Font(getDisplay(), fds); | 476 return new Font(getDisplay(), fds); |
477 } | 477 } |
478 | 478 |
479 | 479 |
480 private void instrumentDefaultPopup(bool onImage) | 480 private void instrumentDefaultPopup(bool onImage) |
481 { | 481 { |
482 restoreItem.setEnabled(styleMax && ishell.getMaximized()); | 482 restoreItem.setEnabled(styleMax && ishell.getMaximized()); |
483 maximizeItem.setEnabled(styleMax && !ishell.getMaximized()); | 483 maximizeItem.setEnabled(styleMax && !ishell.getMaximized()); |
484 MenuItem def = null; | 484 MenuItem def = null; |
490 { | 490 { |
491 def = ishell.getMaximized() ? restoreItem : maximizeItem; | 491 def = ishell.getMaximized() ? restoreItem : maximizeItem; |
492 } | 492 } |
493 defaultPopup.setDefaultItem(def); | 493 defaultPopup.setDefaultItem(def); |
494 } | 494 } |
495 | 495 |
496 | 496 |
497 private static const int IMAGE_TYPE_CLOSE = 1; | 497 private static const int IMAGE_TYPE_CLOSE = 1; |
498 private static const int IMAGE_TYPE_MAXIMIZE = 2; | 498 private static const int IMAGE_TYPE_MAXIMIZE = 2; |
499 private static const int IMAGE_TYPE_RESTORE = 3; | 499 private static const int IMAGE_TYPE_RESTORE = 3; |
500 private static const int IMAGE_TYPE_MINIMIZE = 4; | 500 private static const int IMAGE_TYPE_MINIMIZE = 4; |
501 | 501 |
505 final Point size = new Point(height, height); | 505 final Point size = new Point(height, height); |
506 final int imgWidth = height + height/2; | 506 final int imgWidth = height + height/2; |
507 final Color fg = getForeground(); | 507 final Color fg = getForeground(); |
508 final Color white = getDisplay().getSystemColor(DWT.COLOR_WHITE); | 508 final Color white = getDisplay().getSystemColor(DWT.COLOR_WHITE); |
509 final RGB blackRGB = new RGB(0,0,0); | 509 final RGB blackRGB = new RGB(0,0,0); |
510 | 510 |
511 ImageData id = new ImageData(imgWidth, size.y, 1, new PaletteData([ blackRGB, fg.getRGB() ])); | 511 ImageData id = new ImageData(imgWidth, size.y, 1, new PaletteData([ blackRGB, fg.getRGB() ])); |
512 ImageData maskid = new ImageData(imgWidth, size.y, 1, new PaletteData([ blackRGB, white.getRGB() ])); | 512 ImageData maskid = new ImageData(imgWidth, size.y, 1, new PaletteData([ blackRGB, white.getRGB() ])); |
513 | 513 |
514 Image img = new Image(getDisplay(), id); | 514 Image img = new Image(getDisplay(), id); |
515 GC gc = new GC(img); | 515 GC gc = new GC(img); |
516 gc.setForeground(fg); | 516 gc.setForeground(fg); |
517 drawMenuImage(gc, size, type); | 517 drawMenuImage(gc, size, type); |
518 gc.dispose(); | 518 gc.dispose(); |
519 | 519 |
520 Image maskimg = new Image(getDisplay(), maskid); | 520 Image maskimg = new Image(getDisplay(), maskid); |
521 gc = new GC(maskimg); | 521 gc = new GC(maskimg); |
522 gc.setForeground(white); | 522 gc.setForeground(white); |
523 drawMenuImage(gc, size, type); | 523 drawMenuImage(gc, size, type); |
524 gc.dispose(); | 524 gc.dispose(); |