]> git.saurik.com Git - wxWidgets.git/blob - src/motif/mdi/test/MDItest.C
Distrib things
[wxWidgets.git] / src / motif / mdi / test / MDItest.C
1 /*
2 Copyright (C) 1996 Scott W. Sadler
3 All rights reserved.
4 */
5
6 /*
7 MDItest.c
8
9 History
10 03-Mar-96 1.0; Scott W. Sadler (sws@iti-oh.com)
11 Created
12 */
13
14 // Includes
15
16 #include <assert.h>
17 #include <Xm/MainW.h>
18 #include <Xm/RowColumn.h>
19 #include <Xm/CascadeBG.h>
20 #include <Xm/Text.h>
21 #include <Xm/PushBG.h>
22 #include <Xm/AtomMgr.h>
23 #include <Xm/Protocols.h>
24 #include "XsMDICanvas.h"
25 #include "XsMotifWindow.h"
26
27 // Fallback resources
28
29 static char *fallbacks[] = {
30 "*MDItest.height: 500",
31 "*MDItest.width: 500",
32 "*MDIinner.width: 300",
33 "*MDIinner.height: 300",
34
35 "*fileMenu.labelString: File",
36 "*fileMenu.mnemonic: F",
37 "*openMenuItem.labelString: Open...",
38 "*openMenuItem.mnemonic: O",
39 "*newMenuItem.labelString: New...",
40 "*newMenuItem.mnemonic: N",
41 "*editMenu.labelString: Edit",
42 "*editMenu.mnemonic: E",
43 "*cutMenuItem.labelString: Cut",
44 "*cutMenuItem.mnemonic: t",
45 "*copyMenuItem.labelString: Copy",
46 "*copyMenuItem.mnemonic: C",
47 "*pasteMenuItem.labelString: Paste",
48 "*pasteMenuItem.mnemonic: P",
49 "*helpMenu.labelString: Help",
50 "*helpMenu.mnemonic: H",
51 "*aboutMenuItem.labelString: About",
52 "*aboutMenuItem.mnemonic: A",
53 "*scrolledText.rows: 10",
54 "*scrolledText.columns: 30",
55
56 "*background: grey",
57 "*fontList: -*-helvetica-medium-r-normal-*-14-*-*-*-*-*-iso8859-1",
58
59 NULL
60 };
61
62 /*
63 ----------------------------------------------------------------------------
64 MyDocument class
65 */
66
67 class MyDocument : public XsMotifWindow {
68
69 public:
70
71 // Constructor/Destructor
72
73 MyDocument (const char *name, XsMDICanvas *canvas);
74 virtual ~MyDocument ( );
75
76 protected:
77
78 // This member function is called to create the document contents
79
80 virtual void _buildClientArea (Widget);
81
82 // Implementation
83
84 XsMDICanvas *_canvas;
85
86 // Callbacks
87
88 void _newWindow ( );
89 void _doNothing ( );
90
91 private:
92
93 // Callbacks
94
95 static void _newWindowCallback (Widget, XtPointer, XtPointer);
96 static void _doNothingCallback (Widget, XtPointer, XtPointer);
97 };
98
99 // Constructor
100
101 MyDocument::MyDocument (const char *name, XsMDICanvas *canvas) :
102 XsMotifWindow (name)
103 {
104 assert (canvas != 0);
105
106 // Initialize
107
108 _canvas = canvas;
109 }
110
111 // Destructor
112
113 MyDocument::~MyDocument ( )
114 {
115 // Empty
116 }
117
118 // _buildClientArea (called to create document contents)
119
120 void MyDocument::_buildClientArea (Widget parent)
121 {
122 assert (parent != 0);
123
124 Widget pulldown;
125 Widget cascade;
126 Widget button;
127
128 // Create a main window with some dummy menus
129
130 Widget mainW = XtVaCreateWidget ("mainWin", xmMainWindowWidgetClass, parent,
131 XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM,
132 XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM,
133 NULL);
134
135 // Create a menubar
136
137 Widget menuBar = XmCreateMenuBar (mainW, "menuBar", NULL, 0);
138
139 // Create the "file" menu
140
141 pulldown = XmCreatePulldownMenu (menuBar, "pulldown", NULL, 0);
142 cascade = XtVaCreateManagedWidget ("fileMenu", xmCascadeButtonGadgetClass,
143 menuBar, XmNsubMenuId, pulldown, NULL);
144
145 button = XtVaCreateManagedWidget ("openMenuItem", xmPushButtonGadgetClass,
146 pulldown, NULL);
147 XtAddCallback (button, XmNactivateCallback, _doNothingCallback, (XtPointer)this);
148
149 button = XtVaCreateManagedWidget ("newMenuItem", xmPushButtonGadgetClass,
150 pulldown, NULL);
151 XtAddCallback (button, XmNactivateCallback, _newWindowCallback, (XtPointer)this);
152
153 // Create the "edit" menu
154
155 pulldown = XmCreatePulldownMenu (menuBar, "pulldown", NULL, 0);
156 cascade = XtVaCreateManagedWidget ("editMenu", xmCascadeButtonGadgetClass,
157 menuBar, XmNsubMenuId, pulldown, NULL);
158
159 button = XtVaCreateManagedWidget ("cutMenuItem", xmPushButtonGadgetClass,
160 pulldown, NULL);
161 XtAddCallback (button, XmNactivateCallback, _doNothingCallback, (XtPointer)this);
162
163 button = XtVaCreateManagedWidget ("copyMenuItem", xmPushButtonGadgetClass,
164 pulldown, NULL);
165 XtAddCallback (button, XmNactivateCallback, _doNothingCallback, (XtPointer)this);
166
167 button = XtVaCreateManagedWidget ("pasteMenuItem", xmPushButtonGadgetClass,
168 pulldown, NULL);
169 XtAddCallback (button, XmNactivateCallback, _doNothingCallback, (XtPointer)this);
170
171 // Create the help menu
172
173 pulldown = XmCreatePulldownMenu (menuBar, "pulldown", NULL, 0);
174 cascade = XtVaCreateManagedWidget ("helpMenu", xmCascadeButtonGadgetClass,
175 menuBar, XmNsubMenuId, pulldown, NULL);
176
177 button = XtVaCreateManagedWidget ("aboutMenuItem", xmPushButtonGadgetClass,
178 pulldown, NULL);
179 XtAddCallback (button, XmNactivateCallback, _doNothingCallback, (XtPointer)this);
180
181 XtVaSetValues (menuBar, XmNmenuHelpWidget, cascade, NULL);
182
183 // Manage the menubar
184
185 XtManageChild (menuBar);
186
187 // Create the work area
188
189 const int nargs = 8;
190 Arg args[nargs];
191 int n;
192
193 n = 0;
194 XtSetArg (args[n], XmNscrollingPolicy, XmAUTOMATIC); n++;
195 XtSetArg (args[n], XmNhighlightThickness, (Dimension)0); n++;
196 XtSetArg (args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
197 XtSetArg (args[n], XmNeditable, True); n++;
198 XtSetArg (args[n], XmNwordWrap, False); n++;
199 XtSetArg (args[n], XmNcursorPositionVisible, True); n++;
200 XtSetArg (args[n], XmNverifyBell, True); n++;
201
202 assert (n <= nargs);
203
204 Widget scrolledText = XmCreateScrolledText (mainW, "scrolledText", args, n);
205 XtManageChild (scrolledText);
206
207 // Set the main window area
208
209 XtVaSetValues (mainW, XmNmenuBar, menuBar, XmNworkWindow,
210 XtParent (scrolledText), NULL);
211
212 XtManageChild (mainW);
213 }
214
215 // _newWindow
216
217 void MyDocument::_newWindow ( )
218 {
219
220 // Create a new document (this will leak, but who cares?)
221
222 MyDocument *newDoc = new MyDocument ("Document", _canvas);
223
224 // Add it to the canvas
225
226 _canvas->add (newDoc);
227 }
228
229 // _newWindowCallback
230
231 void MyDocument::_newWindowCallback (Widget, XtPointer clientData, XtPointer)
232 {
233 MyDocument *obj = (MyDocument*)clientData;
234 obj->_newWindow ( );
235 }
236
237 // _doNothingCallback
238
239 void MyDocument::_doNothingCallback (Widget w, XtPointer, XtPointer)
240 {
241 XBell (XtDisplayOfObject (w), 100);
242 }
243
244 /*
245 ----------------------------------------------------------------------------
246 MyDocument2 class
247 */
248
249 class MyDocument2 : public XsMotifWindow {
250
251 public:
252
253 // Constructor/Destructor
254
255 MyDocument2 (const char *name);
256 virtual ~MyDocument2 ( );
257
258 protected:
259
260 // This member function is called to create the document contents
261
262 virtual void _buildClientArea (Widget);
263
264 // Implementation
265
266 XsMDICanvas *_canvas;
267 MyDocument *_win1;
268 };
269
270 // Constructor
271
272 MyDocument2::MyDocument2 (const char *name) : XsMotifWindow (name)
273 {
274 _canvas = 0;
275 _win1 = 0;
276 }
277
278 // Destructor
279
280 MyDocument2::~MyDocument2 ( )
281 {
282 delete _canvas;
283 delete _win1;
284 }
285
286 // _buildClientArea
287
288 void MyDocument2::_buildClientArea (Widget parent)
289 {
290 assert (parent != 0);
291
292 // Create a nested MDI canvas
293
294 _canvas = new XsMDICanvas ("MDIinner", parent);
295
296 // Attach it up
297
298 XtVaSetValues (_canvas->base ( ), XmNtopAttachment, XmATTACH_FORM,
299 XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM,
300 XmNrightAttachment, XmATTACH_FORM, NULL);
301
302 // Create a document
303
304 _win1 = new MyDocument ("InnerWin", _canvas);
305
306 // Add the document to the canvas
307
308 _canvas->add (_win1);
309
310 // Show the canvas
311
312 _canvas->show ( );
313 }
314
315 /*
316 ----------------------------------------------------------------------------
317 main
318 */
319
320 static void _destroyCallback (Widget, XtPointer clientData, XtPointer)
321 {
322 Boolean *quit = (Boolean*)clientData;
323 *quit = True;
324 }
325
326 int main (int argc, char **argv)
327 {
328 XtAppContext appContext;
329 Widget topLevel;
330 Boolean quit = False;
331
332 // Initialize toolkit
333
334 topLevel = XtVaAppInitialize (&appContext, "MDI", NULL, 0, &argc, argv,
335 fallbacks, XmNdeleteResponse, XmDO_NOTHING, NULL);
336
337 Display *dpy = XtDisplay (topLevel);
338
339 // Add protocols
340
341 Atom WM_DELETE_WINDOW = XmInternAtom (dpy, "WM_DELETE_WINDOW", False);
342
343 XmAddWMProtocolCallback (topLevel, WM_DELETE_WINDOW, _destroyCallback,
344 &quit);
345
346 // Create the MDI canvas
347
348 XsMDICanvas *canvas = new XsMDICanvas ("MDItest", topLevel);
349
350 // Create the MDI documents
351
352 MyDocument *win1 = new MyDocument ("Document", canvas);
353 MyDocument2 *win2 = new MyDocument2 ("Document 2");
354
355 // Add documents to MDI canvas
356
357 canvas->add (win1);
358 canvas->add (win2);
359
360 // Show the canvas
361
362 canvas->show ( );
363
364 // Realize everything
365
366 XtRealizeWidget (topLevel);
367
368 // Let 'er rip
369
370 XEvent event;
371
372 while (!quit)
373 {
374 XtAppNextEvent (appContext, &event);
375 XtDispatchEvent (&event);
376 }
377
378 // Cleanup
379
380 delete win1;
381 delete win2;
382 delete canvas;
383
384 // Close the X connection
385
386 XtDestroyWidget (topLevel);
387 XtCloseDisplay (dpy);
388 XtDestroyApplicationContext (appContext);
389
390 return (0);
391 }