1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 #include <Xm/Xm.h>
51 #include <Xm/DrawnB.h>
52 #include <Xm/Form.h>
53 #include <Xm/Label.h>
54 #include <Xm/PushB.h>
55 #include <XmL/Folder.h>
56
57 void addTab();
58 void removeTab();
59 void activate();
60
61 #define sphere_width
16
62 #define sphere_height
16
63 static unsigned char sphere_bits[] = {
64 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, 0xe0, 0x0f, 0xf0, 0x1f, 0x38, 0x3f,
65 0xb8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf8, 0x3f, 0xf0, 0x1f, 0xe0, 0x0f,
66 0xc0, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
67
68 #define monitor_width
16
69 #define monitor_height
16
70 static unsigned char monitor_bits[] = {
71 0x00, 0x00, 0xf8, 0x3f, 0xf8, 0x3f, 0x18, 0x30, 0x58, 0x37, 0x18, 0x30,
72 0x58, 0x37, 0x18, 0x30, 0xf8, 0x3f, 0xf8, 0x3f, 0x80, 0x03, 0x80, 0x03,
73 0xf0, 0x1f, 0xf0, 0x1f, 0x00, 0x00, 0x00, 0x00};
74
75 Widget folder, label;
76
77 Pixmap monitorPixmap, spherePixmap;
78
79 main(argc, argv)
80 int argc;
81 char *argv[];
82 {
83 XtAppContext app;
84 Widget shell, form, folderForm, addButton, removeButton;
85 Pixel black, grey;
86
87 shell = XtAppInitialize(&app,
"Folder4",
NULL,
0,
88 &argc, argv,
NULL,
NULL,
0);
89
90 XtVaSetValues(shell,
91 XmNallowShellResize, True,
92 NULL);
93
94 form = XtVaCreateManagedWidget(
"form",
95 xmFormWidgetClass, shell,
96 XtVaTypedArg, XmNbackground, XmRString,
"#C0C0C0",
8,
97 XmNmarginWidth,
8,
98 XmNmarginHeight,
8,
99 XmNhorizontalSpacing,
4,
100 XmNverticalSpacing,
4,
101 XmNshadowThickness,
0,
102 NULL);
103
104
105 black = BlackPixelOfScreen(XtScreen(shell));
106 XtVaGetValues(form,
107 XmNbackground, &grey,
108 NULL);
109 spherePixmap = XCreatePixmapFromBitmapData(XtDisplay(shell),
110 DefaultRootWindow(XtDisplay(shell)),
111 sphere_bits, sphere_width, sphere_height,
112 black, grey,
113 DefaultDepthOfScreen(XtScreen(shell)));
114 monitorPixmap = XCreatePixmapFromBitmapData(XtDisplay(shell),
115 DefaultRootWindow(XtDisplay(shell)),
116 monitor_bits, monitor_width, monitor_height,
117 black, grey,
118 DefaultDepthOfScreen(XtScreen(shell)));
119
120 removeButton = XtVaCreateManagedWidget(
"Remove Tab",
121 xmPushButtonWidgetClass, form,
122 XtVaTypedArg, XmNbackground, XmRString,
"#C0C0C0",
8,
123 XtVaTypedArg, XmNforeground, XmRString,
"black",
6,
124 XmNrightAttachment, XmATTACH_FORM,
125 XmNbottomAttachment, XmATTACH_FORM,
126 XmNmarginWidth,
10,
127 NULL);
128 XtAddCallback(removeButton, XmNactivateCallback, removeTab,
NULL);
129
130 addButton = XtVaCreateManagedWidget(
"Add Tab",
131 xmPushButtonWidgetClass, form,
132 XtVaTypedArg, XmNbackground, XmRString,
"#C0C0C0",
8,
133 XtVaTypedArg, XmNforeground, XmRString,
"black",
6,
134 XmNrightAttachment, XmATTACH_WIDGET,
135 XmNrightWidget, removeButton,
136 XmNbottomAttachment, XmATTACH_FORM,
137 XmNmarginWidth,
20,
138 NULL);
139 XtAddCallback(addButton, XmNactivateCallback, addTab,
NULL);
140
141 folder = XtVaCreateManagedWidget(
"folder",
142 xmlFolderWidgetClass, form,
143 XtVaTypedArg, XmNbackground, XmRString,
"#C0C0C0",
8,
144 XtVaTypedArg, XmNforeground, XmRString,
"black",
6,
145 XmNtabsPerRow,
4,
146 XmNcornerStyle, XmCORNER_NONE,
147 XmNspacing,
1,
148 XmNtopAttachment, XmATTACH_FORM,
149 XmNbottomAttachment, XmATTACH_WIDGET,
150 XmNbottomWidget, removeButton,
151 XmNleftAttachment, XmATTACH_FORM,
152 XmNrightAttachment, XmATTACH_FORM,
153 XmNresizePolicy, XmRESIZE_DYNAMIC,
154 NULL);
155 XtAddCallback(folder, XmNactivateCallback, activate,
NULL);
156
157
158 folderForm = XtVaCreateManagedWidget(
"form",
159 xmFormWidgetClass, folder,
160 XtVaTypedArg, XmNbackground, XmRString,
"#C0C0C0",
8,
161 NULL);
162
163
164 label = XtVaCreateManagedWidget(
"Page Area",
165 xmLabelWidgetClass, folderForm,
166 XtVaTypedArg, XmNbackground, XmRString,
"#C0C0C0",
8,
167 XtVaTypedArg, XmNforeground, XmRString,
"black",
6,
168 XmNmarginWidth,
100,
169 XmNmarginHeight,
80,
170 XmNrecomputeSize, False,
171 XmNtopAttachment, XmATTACH_FORM,
172 XmNbottomAttachment, XmATTACH_FORM,
173 XmNleftAttachment, XmATTACH_FORM,
174 XmNrightAttachment, XmATTACH_FORM,
175 NULL);
176
177 XtRealizeWidget(shell);
178 XtAppMainLoop(app);
179 }
180
181 void addTab(w, clientData, callData)
182 Widget w;
183 XtPointer clientData;
184 XtPointer callData;
185 {
186 Widget tabButton, form;
187 int count;
188 char tabName[
30];
189 XmString str;
190 Pixmap pixmap;
191
192 XtVaGetValues(folder,
193 XmNtabCount, &count,
194 NULL);
195
196
197 if (count %
2)
198 pixmap = spherePixmap;
199 else
200 pixmap = monitorPixmap;
201
202
203 sprintf(tabName,
"Tab %d", count);
204 str = XmStringCreateSimple(tabName);
205 tabButton = XtVaCreateManagedWidget(
"tab",
206 xmDrawnButtonWidgetClass, folder,
207 XmNlabelString, str,
208 XmNmarginWidth,
8,
209 XmNtabPixmap, pixmap,
210 XmNtabInactivePixmap, pixmap,
211 NULL);
212 XmStringFree(str);
213 }
214
215 void removeTab(w, clientData, callData)
216 Widget w;
217 XtPointer clientData;
218 XtPointer callData;
219 {
220 int count;
221 WidgetList tabs;
222
223 XtVaGetValues(folder,
224 XmNtabCount, &count,
225 XmNtabWidgetList, &tabs,
226 NULL);
227 if (!count)
228 return;
229 XtDestroyWidget(tabs[count -
1]);
230 }
231
232 void activate(w, clientData, callData)
233 Widget w;
234 XtPointer clientData;
235 XtPointer callData;
236 {
237 XmLFolderCallbackStruct *cbs;
238 XmString str;
239 char buf[
20];
240 int pos;
241
242
243
244 cbs = (XmLFolderCallbackStruct *)callData;
245 sprintf(buf,
"Page %d", cbs->pos);
246 str = XmStringCreateSimple(buf);
247 XtVaSetValues(label,
248 XmNlabelString, str,
249 NULL);
250 }
251