Mercurial > projects > dwt-addons
annotate dwtx/ui/forms/widgets/ScrolledPageBook.d @ 104:04b47443bb01
Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections.
These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 07 Aug 2008 15:01:33 +0200 |
parents | 5d489b9f966c |
children | c3583c6ec027 |
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; | |
75 } | |
76 })); | |
77 } | |
78 /** | |
79 * Removes the default size of the composite, allowing the control to | |
80 * shrink to the trim. | |
81 * | |
82 * @param wHint | |
83 * the width hint | |
84 * @param hHint | |
85 * the height hint | |
86 * @param changed | |
87 * if <code>true</code>, do not use cached values | |
88 */ | |
89 public Point computeSize(int wHint, int hHint, bool changed) { | |
90 Rectangle trim = computeTrim(0, 0, 10, 10); | |
91 return new Point(trim.width, trim.height); | |
92 } | |
93 /** | |
94 * Tests if the page under the provided key is currently in the book. | |
95 * | |
96 * @param key | |
97 * the page key | |
98 * @return <code>true</code> if page exists, <code>false</code> | |
99 * otherwise. | |
100 */ | |
101 public bool hasPage(Object key) { | |
102 return pages.containsKey(key); | |
103 } | |
104 /** | |
105 * Creates a new page for the provided key. Use the returned composite to | |
106 * create children in it. | |
107 * | |
108 * @param key | |
109 * the page key | |
110 * @return the newly created page composite | |
111 */ | |
112 public Composite createPage(Object key) { | |
113 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
|
114 pages.put(key, page); |
75 | 115 return page; |
116 } | |
117 /** | |
118 * Returns the page book container. | |
119 * | |
120 * @return the page book container | |
121 */ | |
122 public Composite getContainer() { | |
123 return pageBook; | |
124 } | |
125 /** | |
126 * Registers a page under the privided key to be managed by the page book. | |
127 * The page must be a direct child of the page book container. | |
128 * | |
129 * @param key | |
130 * the page key | |
131 * @param page | |
132 * the page composite to register | |
133 * @see #createPage(Object) | |
134 * @see #getContainer | |
135 */ | |
136 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
|
137 pages.put(key, page); |
75 | 138 } |
139 /** | |
140 * Removes the page under the provided key from the page book. Does nothing | |
141 * if page with that key does not exist. | |
142 * | |
143 * @param key | |
144 * the page key. | |
145 */ | |
146 public void removePage(Object key) { | |
147 removePage(key, true); | |
148 } | |
149 /** | |
150 * Removes the page under the provided key from the page book. Does nothing | |
151 * if page with that key does not exist. | |
152 * | |
153 * @param key | |
154 * the page key. | |
155 * @param showEmptyPage | |
156 * if <code>true</code>, shows the empty page | |
157 * after page removal. | |
158 */ | |
159 public void removePage(Object key, bool showEmptyPage_) { | |
160 Control page = cast(Control) pages.get(key); | |
161 if (page !is null) { | |
162 pages.remove(key); | |
163 page.dispose(); | |
164 if (showEmptyPage_) | |
165 showEmptyPage(); | |
166 } | |
167 } | |
168 /** | |
169 * Shows the page with the provided key and hides the page previously | |
170 * showing. Does nothing if the page with that key does not exist. | |
171 * | |
172 * @param key | |
173 * the page key | |
174 */ | |
175 public void showPage(Object key) { | |
176 Control page = cast(Control) pages.get(key); | |
177 if (page !is null) { | |
178 pageBook.showPage(page); | |
179 if (currentPage !is null && currentPage !is page) { | |
180 // switching pages - force layout | |
181 if (null !is cast(Composite)page ) | |
182 (cast(Composite) page).layout(false); | |
183 } | |
184 currentPage = page; | |
185 } else { | |
186 showEmptyPage(); | |
187 } | |
188 reflow(true); | |
189 } | |
190 /** | |
191 * Shows a page with no children to be used if the desire is to not show | |
192 * any registered page. | |
193 */ | |
194 public void showEmptyPage() { | |
195 if (emptyPage is null) { | |
196 emptyPage = createPage(); | |
197 emptyPage.setLayout(new GridLayout()); | |
198 } | |
199 pageBook.showPage(emptyPage); | |
200 currentPage = emptyPage; | |
201 reflow(true); | |
202 } | |
203 /** | |
204 * Sets focus on the current page if shown. | |
205 */ | |
206 public bool setFocus() { | |
207 if (currentPage !is null) | |
208 return currentPage.setFocus(); | |
209 return super.setFocus(); | |
210 } | |
211 /** | |
212 * Returns the page currently showing. | |
213 * | |
214 * @return the current page | |
215 */ | |
216 public Control getCurrentPage() { | |
217 return currentPage; | |
218 } | |
219 private Composite createPage() { | |
220 Composite page = new LayoutComposite(pageBook, DWT.NULL); | |
221 page.setBackground(getBackground()); | |
222 page.setForeground(getForeground()); | |
223 page.setMenu(pageBook.getMenu()); | |
224 return page; | |
225 } | |
226 } |