1 #!/usr/bin/env dub
2 /+
3 dub.sdl:
4     name "snippet165"
5     dependency "dwt" path="../../../../../../"
6     libs \
7       "atk-1.0" \
8       "cairo" \
9       "dl" \
10       "fontconfig" \
11       "gdk-x11-2.0" \
12       "gdk_pixbuf-2.0" \
13       "glib-2.0" \
14       "gmodule-2.0" \
15       "gnomeui-2" \
16       "gnomevfs-2" \
17       "gobject-2.0" \
18       "gthread-2.0" \
19       "gtk-x11-2.0" \
20       "pango-1.0" \
21       "pangocairo-1.0" \
22       "X11" \
23       "Xcomposite" \
24       "Xcursor" \
25       "Xdamage" \
26       "Xext" \
27       "Xfixes" \
28       "Xi" \
29       "Xinerama" \
30       "Xrandr" \
31       "Xrender" \
32       "Xtst" \
33       platform="linux"
34 +/
35 
36 /*******************************************************************************
37  * Copyright (c) 2000, 2004 IBM Corporation and others.
38  * All rights reserved. This program and the accompanying materials
39  * are made available under the terms of the Eclipse Public License v1.0
40  * which accompanies this distribution, and is available at
41  * http://www.eclipse.org/legal/epl-v10.html
42  *
43  * Contributors:
44  *     IBM Corporation - initial API and implementation
45  * D Port:
46  * 	 Jesse Phillips <Jesse.K.Phillips+D> gmail.com
47  *******************************************************************************/
48 module org.eclipse.swt.snippets.Snippet165;
49 
50 /*
51  * Create a CTabFolder with min and max buttons, as well as close button and 
52  * image only on selected tab.
53  *
54  * For a list of all SWT example snippets see
55  * http://www.eclipse.org/swt/snippets/
56  * 
57  * @since 3.0
58  */
59 import org.eclipse.swt.SWT;
60 import org.eclipse.swt.custom.CTabFolder;
61 import org.eclipse.swt.custom.CTabFolder2Adapter ;
62 import org.eclipse.swt.custom.CTabFolderEvent ;
63 import org.eclipse.swt.custom.CTabItem;
64 import org.eclipse.swt.graphics.GC;
65 import org.eclipse.swt.graphics.Image;
66 import org.eclipse.swt.layout.GridLayout;
67 import org.eclipse.swt.layout.GridData;
68 import org.eclipse.swt.widgets.Display;
69 import org.eclipse.swt.widgets.Shell;
70 import org.eclipse.swt.widgets.Text;
71 import java.lang.all;
72 
73 version(Tango){
74     import tango.util.Convert;
75 } else { // Phobos
76     import std.conv;
77 }
78 
79 void main () {
80     auto display = new Display ();
81     auto image = new Image(display, 16, 16);
82     auto gc = new GC(image);
83     gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
84     gc.fillRectangle(0, 0, 16, 16);
85     gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
86     gc.fillRectangle(3, 3, 10, 10);
87     gc.dispose();
88     auto shell = new Shell (display);
89     shell.setLayout(new GridLayout());
90     auto folder = new CTabFolder(shell, SWT.BORDER);
91     folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
92     folder.setSimple(false);
93     folder.setUnselectedImageVisible(false);
94     folder.setUnselectedCloseVisible(false);
95     for (int i = 0; i < 8; i++) {
96         CTabItem item = new CTabItem(folder, SWT.CLOSE);
97         item.setText("Item " ~ to!(String)(i));
98         item.setImage(image);
99         Text text = new Text(folder, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
100         text.setText("Text for item " ~ to!(String)(i) ~
101                      "\n\none, two, three\n\nabcdefghijklmnop");
102         item.setControl(text);
103     }
104     folder.setMinimizeVisible(true);
105     folder.setMaximizeVisible(true);
106     folder.addCTabFolder2Listener(new class CTabFolder2Adapter {
107         override
108         public void minimize(CTabFolderEvent event) {
109             folder.setMinimized(true);
110             shell.layout(true);
111         }
112         override
113         public void maximize(CTabFolderEvent event) {
114             folder.setMaximized(true);
115             folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
116             shell.layout(true);
117         }
118         override
119         public void restore(CTabFolderEvent event) {
120             folder.setMinimized(false);
121             folder.setMaximized(false);
122             folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
123             shell.layout(true);
124         }
125     });
126     shell.setSize(300, 300);
127     shell.open ();
128     while (!shell.isDisposed ()) {
129         if (!display.readAndDispatch ()) display.sleep ();
130     }
131     image.dispose();
132     display.dispose ();
133 }