Mercurial > projects > dwt-addons
annotate dwtx/ui/forms/widgets/ScrolledPageBook.d @ 192:c3583c6ec027
Added missing default cases for switch statements
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 03 Nov 2008 22:52:26 +0100 |
parents | 04b47443bb01 |
children |
rev | line source |
---|---|
75 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 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 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.ui.forms.widgets.ScrolledPageBook; | |
14 | |
15 import dwtx.ui.forms.widgets.SharedScrolledComposite; | |
16 import dwtx.ui.forms.widgets.LayoutComposite; | |
17 | |
18 import dwt.DWT; | |
19 import dwt.graphics.Point; | |
20 import dwt.graphics.Rectangle; | |
21 import dwt.layout.GridLayout; | |
22 import dwt.widgets.Composite; | |
23 import dwt.widgets.Control; | |
24 import dwt.widgets.Event; | |
25 import dwt.widgets.Listener; | |
26 import dwtx.ui.internal.forms.widgets.WrappedPageBook; | |
27 | |
28 import dwt.dwthelper.utils; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
29 import dwtx.dwtxhelper.Collection; |
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
30 |
75 | 31 /** |
32 * ScrolledPageBook is a class that is capable of stacking several composites | |
33 * (pages), while showing one at a time. The content is scrolled if there is | |
34 * not enough space to fit it in the client area. | |
35 * | |
36 * @since 3.0 | |
37 */ | |
38 public class ScrolledPageBook : SharedScrolledComposite { | |
39 private WrappedPageBook pageBook; | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
40 private Hashtable pages; |
75 | 41 private Composite emptyPage; |
42 private Control currentPage; | |
43 /** | |
44 * Creates a new instance in the provided parent | |
45 * | |
46 * @param parent | |
47 */ | |
48 public this(Composite parent) { | |
49 this(parent, DWT.H_SCROLL | DWT.V_SCROLL); | |
50 } | |
51 /** | |
52 * Creates a new instance in the provided parent and with the provided | |
53 * style. | |
54 * | |
55 * @param parent | |
56 * the control parent | |
57 * @param style | |
58 * the style to use | |
59 */ | |
60 public this(Composite parent, int style) { | |
61 super(parent, style); | |
62 pageBook = new WrappedPageBook(this, DWT.NULL); | |
63 setContent(pageBook); | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
64 pages = new Hashtable(); |
75 | 65 setExpandHorizontal(true); |
66 setExpandVertical(true); | |
67 this.addListener(DWT.Traverse, dgListener( (Event e) { | |
68 switch (e.detail) { | |
69 case DWT.TRAVERSE_ESCAPE : | |
70 case DWT.TRAVERSE_RETURN : | |
71 case DWT.TRAVERSE_TAB_NEXT : | |
72 case DWT.TRAVERSE_TAB_PREVIOUS : | |
73 e.doit = true; | |
74 break; | |
192
c3583c6ec027
Added missing default cases for switch statements
Frank Benoit <benoit@tionex.de>
parents:
104
diff
changeset
|
75 default: |
75 | 76 } |
77 })); | |
78 } | |
79 /** | |
80 * Removes the default size of the composite, allowing the control to | |
81 * shrink to the trim. | |
82 * | |
83 * @param wHint | |
84 * the width hint | |
85 * @param hHint | |
86 * the height hint | |
87 * @param changed | |
88 * if <code>true</code>, do not use cached values | |
89 */ | |
90 public Point computeSize(int wHint, int hHint, bool changed) { | |
91 Rectangle trim = computeTrim(0, 0, 10, 10); | |
92 return new Point(trim.width, trim.height); | |
93 } | |
94 /** | |
95 * Tests if the page under the provided key is currently in the book. | |
96 * | |
97 * @param key | |
98 * the page key | |
99 * @return <code>true</code> if page exists, <code>false</code> | |
100 * otherwise. | |
101 */ | |
102 public bool hasPage(Object key) { | |
103 return pages.containsKey(key); | |
104 } | |
105 /** | |
106 * Creates a new page for the provided key. Use the returned composite to | |
107 * create children in it. | |
108 * | |
109 * @param key | |
110 * the page key | |
111 * @return the newly created page composite | |
112 */ | |
113 public Composite createPage(Object key) { | |
114 Composite page = createPage(); | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
115 pages.put(key, page); |
75 | 116 return page; |
117 } | |
118 /** | |
119 * Returns the page book container. | |
120 * | |
121 * @return the page book container | |
122 */ | |
123 public Composite getContainer() { | |
124 return pageBook; | |
125 } | |
126 /** | |
127 * Registers a page under the privided key to be managed by the page book. | |
128 * The page must be a direct child of the page book container. | |
129 * | |
130 * @param key | |
131 * the page key | |
132 * @param page | |
133 * the page composite to register | |
134 * @see #createPage(Object) | |
135 * @see #getContainer | |
136 */ | |
137 public void registerPage(Object key, Control page) { | |
104
04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
Frank Benoit <benoit@tionex.de>
parents:
75
diff
changeset
|
138 pages.put(key, page); |
75 | 139 } |
140 /** | |
141 * Removes the page under the provided key from the page book. Does nothing | |
142 * if page with that key does not exist. | |
143 * | |
144 * @param key | |
145 * the page key. | |
146 */ | |
147 public void removePage(Object key) { | |
148 removePage(key, true); | |
149 } | |
150 /** | |
151 * Removes the page under the provided key from the page book. Does nothing | |
152 * if page with that key does not exist. | |
153 * | |
154 * @param key | |
155 * the page key. | |
156 * @param showEmptyPage | |
157 * if <code>true</code>, shows the empty page | |
158 * after page removal. | |
159 */ | |
160 public void removePage(Object key, bool showEmptyPage_) { | |
161 Control page = cast(Control) pages.get(key); | |
162 if (page !is null) { | |
163 pages.remove(key); | |
164 page.dispose(); | |
165 if (showEmptyPage_) | |
166 showEmptyPage(); | |
167 } | |
168 } | |
169 /** | |
170 * Shows the page with the provided key and hides the page previously | |
171 * showing. Does nothing if the page with that key does not exist. | |
172 * | |
173 * @param key | |
174 * the page key | |
175 */ | |
176 public void showPage(Object key) { | |
177 Control page = cast(Control) pages.get(key); | |
178 if (page !is null) { | |
179 pageBook.showPage(page); | |
180 if (currentPage !is null && currentPage !is page) { | |
181 // switching pages - force layout | |
182 if (null !is cast(Composite)page ) | |
183 (cast(Composite) page).layout(false); | |
184 } | |
185 currentPage = page; | |
186 } else { | |
187 showEmptyPage(); | |
188 } | |
189 reflow(true); | |
190 } | |
191 /** | |
192 * Shows a page with no children to be used if the desire is to not show | |
193 * any registered page. | |
194 */ | |
195 public void showEmptyPage() { | |
196 if (emptyPage is null) { | |
197 emptyPage = createPage(); | |
198 emptyPage.setLayout(new GridLayout()); | |
199 } | |
200 pageBook.showPage(emptyPage); | |
201 currentPage = emptyPage; | |
202 reflow(true); | |
203 } | |
204 /** | |
205 * Sets focus on the current page if shown. | |
206 */ | |
207 public bool setFocus() { | |
208 if (currentPage !is null) | |
209 return currentPage.setFocus(); | |
210 return super.setFocus(); | |
211 } | |
212 /** | |
213 * Returns the page currently showing. | |
214 * | |
215 * @return the current page | |
216 */ | |
217 public Control getCurrentPage() { | |
218 return currentPage; | |
219 } | |
220 private Composite createPage() { | |
221 Composite page = new LayoutComposite(pageBook, DWT.NULL); | |
222 page.setBackground(getBackground()); | |
223 page.setForeground(getForeground()); | |
224 page.setMenu(pageBook.getMenu()); | |
225 return page; | |
226 } | |
227 } |