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 *******************************************************************************/
|
|
13 module snippets.ctabfolder.Snippet165;
|
|
14
|
|
15 /*
|
|
16 * Create a CTabFolder with min and max buttons, as well as close button and
|
|
17 * image only on selected tab.
|
|
18 *
|
|
19 * For a list of all DWT example snippets see
|
|
20 * http://www.eclipse.org/swt/snippets/
|
|
21 *
|
|
22 * @since 3.0
|
|
23 */
|
|
24 import dwt.DWT;
|
|
25 import dwt.custom.CTabFolder;
|
|
26 import dwt.custom.CTabFolder2Adapter ;
|
|
27 import dwt.custom.CTabFolderEvent ;
|
|
28 import dwt.custom.CTabItem;
|
|
29 import dwt.graphics.GC;
|
|
30 import dwt.graphics.Image;
|
|
31 import dwt.layout.GridLayout;
|
|
32 import dwt.layout.GridData;
|
|
33 import dwt.widgets.Display;
|
|
34 import dwt.widgets.Shell;
|
|
35 import dwt.widgets.Text;
|
|
36
|
|
37 import tango.util.Convert;
|
|
38
|
|
39 void main () {
|
|
40 auto display = new Display ();
|
|
41 auto image = new Image(display, 16, 16);
|
|
42 auto gc = new GC(image);
|
|
43 gc.setBackground(display.getSystemColor(DWT.COLOR_BLUE));
|
|
44 gc.fillRectangle(0, 0, 16, 16);
|
|
45 gc.setBackground(display.getSystemColor(DWT.COLOR_YELLOW));
|
|
46 gc.fillRectangle(3, 3, 10, 10);
|
|
47 gc.dispose();
|
|
48 auto shell = new Shell (display);
|
|
49 shell.setLayout(new GridLayout());
|
|
50 auto folder = new CTabFolder(shell, DWT.BORDER);
|
|
51 folder.setLayoutData(new GridData(DWT.FILL, DWT.FILL, true, false));
|
|
52 folder.setSimple(false);
|
|
53 folder.setUnselectedImageVisible(false);
|
|
54 folder.setUnselectedCloseVisible(false);
|
|
55 for (int i = 0; i < 8; i++) {
|
|
56 CTabItem item = new CTabItem(folder, DWT.CLOSE);
|
|
57 item.setText("Item " ~ to!(char[])(i));
|
|
58 item.setImage(image);
|
|
59 Text text = new Text(folder, DWT.MULTI | DWT.V_SCROLL | DWT.H_SCROLL);
|
|
60 text.setText("Text for item " ~ to!(char[])(i) ~
|
|
61 "\n\none, two, three\n\nabcdefghijklmnop");
|
|
62 item.setControl(text);
|
|
63 }
|
|
64 folder.setMinimizeVisible(true);
|
|
65 folder.setMaximizeVisible(true);
|
|
66 folder.addCTabFolder2Listener(new class CTabFolder2Adapter {
|
|
67 public void minimize(CTabFolderEvent event) {
|
|
68 folder.setMinimized(true);
|
|
69 shell.layout(true);
|
|
70 }
|
|
71 public void maximize(CTabFolderEvent event) {
|
|
72 folder.setMaximized(true);
|
|
73 folder.setLayoutData(new GridData(DWT.FILL, DWT.FILL, true, true));
|
|
74 shell.layout(true);
|
|
75 }
|
|
76 public void restore(CTabFolderEvent event) {
|
|
77 folder.setMinimized(false);
|
|
78 folder.setMaximized(false);
|
|
79 folder.setLayoutData(new GridData(DWT.FILL, DWT.FILL, true, false));
|
|
80 shell.layout(true);
|
|
81 }
|
|
82 });
|
|
83 shell.setSize(300, 300);
|
|
84 shell.open ();
|
|
85 while (!shell.isDisposed ()) {
|
|
86 if (!display.readAndDispatch ()) display.sleep ();
|
|
87 }
|
|
88 image.dispose();
|
|
89 display.dispose ();
|
|
90 }
|