Mercurial > projects > dwt-samples
annotate snippets/composite/Snippet9.d @ 120:1f0a7a472680
fix rm snippets from module statements.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 20 Jul 2008 19:17:23 +0200 |
parents | 4a04b6759f98 |
children |
rev | line source |
---|---|
78 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2004 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 * D Port | |
11 * Jesse Phillips <Jesse.K.Phillips+D> gmail.com | |
12 *******************************************************************************/ | |
120
1f0a7a472680
fix rm snippets from module statements.
Frank Benoit <benoit@tionex.de>
parents:
78
diff
changeset
|
13 module composite.Snippit9; |
78 | 14 |
15 /* | |
16 * Composite example snippet: scroll a child control automatically | |
17 * | |
18 * For a list of all DWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 */ | |
21 import dwt.DWT; | |
22 import dwt.events.PaintListener; | |
23 import dwt.graphics.Color; | |
24 import dwt.graphics.Point; | |
25 import dwt.graphics.Rectangle; | |
26 import dwt.widgets.Composite; | |
27 import dwt.widgets.Display; | |
28 import dwt.widgets.Event; | |
29 import dwt.widgets.Listener; | |
30 import dwt.widgets.ScrollBar; | |
31 import dwt.widgets.Shell; | |
32 import dwt.dwthelper.utils; | |
33 | |
34 void main () { | |
35 auto display = new Display (); | |
36 auto shell = new Shell | |
37 (display, DWT.SHELL_TRIM | DWT.H_SCROLL | DWT.V_SCROLL); | |
38 auto composite = new Composite (shell, DWT.BORDER); | |
39 composite.setSize (700, 600); | |
40 auto red = display.getSystemColor (DWT.COLOR_RED); | |
41 composite.addPaintListener (new class PaintListener { | |
42 public void paintControl (PaintEvent e) { | |
43 e.gc.setBackground (red); | |
44 e.gc.fillOval (5, 5, 690, 590); | |
45 } | |
46 }); | |
47 auto hBar = shell.getHorizontalBar (); | |
48 hBar.addListener (DWT.Selection, new class Listener { | |
49 public void handleEvent (Event e) { | |
50 auto location = composite.getLocation (); | |
51 location.x = -hBar.getSelection (); | |
52 composite.setLocation (location); | |
53 } | |
54 }); | |
55 ScrollBar vBar = shell.getVerticalBar (); | |
56 vBar.addListener (DWT.Selection, new class Listener { | |
57 public void handleEvent (Event e) { | |
58 Point location = composite.getLocation (); | |
59 location.y = -vBar.getSelection (); | |
60 composite.setLocation (location); | |
61 } | |
62 }); | |
63 shell.addListener (DWT.Resize, new class Listener { | |
64 public void handleEvent (Event e) { | |
65 Point size = composite.getSize (); | |
66 Rectangle rect = shell.getClientArea (); | |
67 hBar.setMaximum (size.x); | |
68 vBar.setMaximum (size.y); | |
69 hBar.setThumb (Math.min (size.x, rect.width)); | |
70 vBar.setThumb (Math.min (size.y, rect.height)); | |
71 int hPage = size.x - rect.width; | |
72 int vPage = size.y - rect.height; | |
73 int hSelection = hBar.getSelection (); | |
74 int vSelection = vBar.getSelection (); | |
75 Point location = composite.getLocation (); | |
76 if (hSelection >= hPage) { | |
77 if (hPage <= 0) hSelection = 0; | |
78 location.x = -hSelection; | |
79 } | |
80 if (vSelection >= vPage) { | |
81 if (vPage <= 0) vSelection = 0; | |
82 location.y = -vSelection; | |
83 } | |
84 composite.setLocation (location); | |
85 } | |
86 }); | |
87 shell.open (); | |
88 while (!shell.isDisposed()) { | |
89 if (!display.readAndDispatch ()) display.sleep (); | |
90 } | |
91 display.dispose (); | |
92 } |