Mercurial > projects > dwt-addons
comparison dwtx/ui/internal/forms/widgets/WrappedPageBook.d @ 75:5d489b9f966c
Fix continue porting
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 24 May 2008 05:11:16 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
74:dad2e11b8ae4 | 75:5d489b9f966c |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2004, 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.internal.forms.widgets.WrappedPageBook; | |
14 | |
15 import dwt.DWT; | |
16 import dwt.graphics.Point; | |
17 import dwt.widgets.Composite; | |
18 import dwt.widgets.Control; | |
19 import dwt.widgets.Layout; | |
20 import dwtx.ui.forms.widgets.ILayoutExtension; | |
21 | |
22 import dwt.dwthelper.utils; | |
23 | |
24 /** | |
25 * A pagebook is a composite control where only a single control is visible at | |
26 * a time. It is similar to a notebook, but without tabs. | |
27 * <p> | |
28 * This class may be instantiated; it is not intended to be subclassed. | |
29 * </p> | |
30 */ | |
31 public class WrappedPageBook : Composite { | |
32 class PageBookLayout : Layout, ILayoutExtension { | |
33 protected Point computeSize(Composite composite, int wHint, int hHint, | |
34 bool flushCache) { | |
35 if (wHint !is DWT.DEFAULT && hHint !is DWT.DEFAULT) | |
36 return new Point(wHint, hHint); | |
37 Point result = null; | |
38 if (currentPage !is null) { | |
39 result = currentPage.computeSize(wHint, hHint, flushCache); | |
40 } else { | |
41 result = new Point(0, 0); | |
42 } | |
43 return result; | |
44 } | |
45 protected void layout(Composite composite, bool flushCache) { | |
46 if (currentPage !is null) { | |
47 currentPage.setBounds(composite.getClientArea()); | |
48 } | |
49 } | |
50 /* | |
51 * (non-Javadoc) | |
52 * | |
53 * @see dwtx.ui.forms.widgets.ILayoutExtension#computeMaximumWidth(dwt.widgets.Composite, | |
54 * bool) | |
55 */ | |
56 public int computeMaximumWidth(Composite parent, bool changed) { | |
57 return computeSize(parent, DWT.DEFAULT, DWT.DEFAULT, changed).x; | |
58 } | |
59 /* | |
60 * (non-Javadoc) | |
61 * | |
62 * @see dwtx.ui.forms.widgets.ILayoutExtension#computeMinimumWidth(dwt.widgets.Composite, | |
63 * bool) | |
64 */ | |
65 public int computeMinimumWidth(Composite parent, bool changed) { | |
66 return computeSize(parent, 0, DWT.DEFAULT, changed).x; | |
67 } | |
68 } | |
69 /** | |
70 * The current control; <code>null</code> if none. | |
71 */ | |
72 private Control currentPage = null; | |
73 /** | |
74 * Creates a new empty pagebook. | |
75 * | |
76 * @param parent | |
77 * the parent composite | |
78 * @param style | |
79 * the DWT style bits | |
80 */ | |
81 public this(Composite parent, int style) { | |
82 super(parent, style); | |
83 setLayout(new PageBookLayout()); | |
84 } | |
85 /** | |
86 * Shows the given page. This method has no effect if the given page is not | |
87 * contained in this pagebook. | |
88 * | |
89 * @param page | |
90 * the page to show | |
91 */ | |
92 public void showPage(Control page) { | |
93 if (page is currentPage) | |
94 return; | |
95 if (page.getParent() !is this) | |
96 return; | |
97 Control oldPage = currentPage; | |
98 currentPage = page; | |
99 // show new page | |
100 if (page !is null) { | |
101 if (!page.isDisposed()) { | |
102 //page.setVisible(true); | |
103 layout(true); | |
104 page.setVisible(true); | |
105 } | |
106 } | |
107 // hide old *after* new page has been made visible in order to avoid | |
108 // flashing | |
109 if (oldPage !is null && !oldPage.isDisposed()) | |
110 oldPage.setVisible(false); | |
111 } | |
112 public Point computeSize(int wHint, int hHint, bool changed) { | |
113 return (cast(PageBookLayout) getLayout()).computeSize(this, wHint, hHint, | |
114 changed); | |
115 } | |
116 } |