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