2 Copyright (C) 1996 Scott W. Sadler
10 03-Mar-96 1.0; Scott W. Sadler (sws@iti-oh.com)
18 #include <Xm/RowColumn.h>
19 #include <Xm/CascadeBG.h>
21 #include <Xm/PushBG.h>
22 #include <Xm/AtomMgr.h>
23 #include <Xm/Protocols.h>
24 #include "XsMDICanvas.h"
25 #include "XsMotifWindow.h"
29 static char *fallbacks[] = {
30 "*MDItest.height: 500",
31 "*MDItest.width: 500",
32 "*MDIinner.width: 300",
33 "*MDIinner.height: 300",
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",
57 "*fontList: -*-helvetica-medium-r-normal-*-14-*-*-*-*-*-iso8859-1",
63 ----------------------------------------------------------------------------
67 class MyDocument : public XsMotifWindow {
71 // Constructor/Destructor
73 MyDocument (const char *name, XsMDICanvas *canvas);
74 virtual ~MyDocument ( );
78 // This member function is called to create the document contents
80 virtual void _buildClientArea (Widget);
95 static void _newWindowCallback (Widget, XtPointer, XtPointer);
96 static void _doNothingCallback (Widget, XtPointer, XtPointer);
101 MyDocument::MyDocument (const char *name, XsMDICanvas *canvas) :
104 assert (canvas != 0);
113 MyDocument::~MyDocument ( )
118 // _buildClientArea (called to create document contents)
120 void MyDocument::_buildClientArea (Widget parent)
122 assert (parent != 0);
128 // Create a main window with some dummy menus
130 Widget mainW = XtVaCreateWidget ("mainWin", xmMainWindowWidgetClass, parent,
131 XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM,
132 XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM,
137 Widget menuBar = XmCreateMenuBar (mainW, "menuBar", NULL, 0);
139 // Create the "file" menu
141 pulldown = XmCreatePulldownMenu (menuBar, "pulldown", NULL, 0);
142 cascade = XtVaCreateManagedWidget ("fileMenu", xmCascadeButtonGadgetClass,
143 menuBar, XmNsubMenuId, pulldown, NULL);
145 button = XtVaCreateManagedWidget ("openMenuItem", xmPushButtonGadgetClass,
147 XtAddCallback (button, XmNactivateCallback, _doNothingCallback, (XtPointer)this);
149 button = XtVaCreateManagedWidget ("newMenuItem", xmPushButtonGadgetClass,
151 XtAddCallback (button, XmNactivateCallback, _newWindowCallback, (XtPointer)this);
153 // Create the "edit" menu
155 pulldown = XmCreatePulldownMenu (menuBar, "pulldown", NULL, 0);
156 cascade = XtVaCreateManagedWidget ("editMenu", xmCascadeButtonGadgetClass,
157 menuBar, XmNsubMenuId, pulldown, NULL);
159 button = XtVaCreateManagedWidget ("cutMenuItem", xmPushButtonGadgetClass,
161 XtAddCallback (button, XmNactivateCallback, _doNothingCallback, (XtPointer)this);
163 button = XtVaCreateManagedWidget ("copyMenuItem", xmPushButtonGadgetClass,
165 XtAddCallback (button, XmNactivateCallback, _doNothingCallback, (XtPointer)this);
167 button = XtVaCreateManagedWidget ("pasteMenuItem", xmPushButtonGadgetClass,
169 XtAddCallback (button, XmNactivateCallback, _doNothingCallback, (XtPointer)this);
171 // Create the help menu
173 pulldown = XmCreatePulldownMenu (menuBar, "pulldown", NULL, 0);
174 cascade = XtVaCreateManagedWidget ("helpMenu", xmCascadeButtonGadgetClass,
175 menuBar, XmNsubMenuId, pulldown, NULL);
177 button = XtVaCreateManagedWidget ("aboutMenuItem", xmPushButtonGadgetClass,
179 XtAddCallback (button, XmNactivateCallback, _doNothingCallback, (XtPointer)this);
181 XtVaSetValues (menuBar, XmNmenuHelpWidget, cascade, NULL);
183 // Manage the menubar
185 XtManageChild (menuBar);
187 // Create the work area
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++;
204 Widget scrolledText = XmCreateScrolledText (mainW, "scrolledText", args, n);
205 XtManageChild (scrolledText);
207 // Set the main window area
209 XtVaSetValues (mainW, XmNmenuBar, menuBar, XmNworkWindow,
210 XtParent (scrolledText), NULL);
212 XtManageChild (mainW);
217 void MyDocument::_newWindow ( )
220 // Create a new document (this will leak, but who cares?)
222 MyDocument *newDoc = new MyDocument ("Document", _canvas);
224 // Add it to the canvas
226 _canvas->add (newDoc);
229 // _newWindowCallback
231 void MyDocument::_newWindowCallback (Widget, XtPointer clientData, XtPointer)
233 MyDocument *obj = (MyDocument*)clientData;
237 // _doNothingCallback
239 void MyDocument::_doNothingCallback (Widget w, XtPointer, XtPointer)
241 XBell (XtDisplayOfObject (w), 100);
245 ----------------------------------------------------------------------------
249 class MyDocument2 : public XsMotifWindow {
253 // Constructor/Destructor
255 MyDocument2 (const char *name);
256 virtual ~MyDocument2 ( );
260 // This member function is called to create the document contents
262 virtual void _buildClientArea (Widget);
266 XsMDICanvas *_canvas;
272 MyDocument2::MyDocument2 (const char *name) : XsMotifWindow (name)
280 MyDocument2::~MyDocument2 ( )
288 void MyDocument2::_buildClientArea (Widget parent)
290 assert (parent != 0);
292 // Create a nested MDI canvas
294 _canvas = new XsMDICanvas ("MDIinner", parent);
298 XtVaSetValues (_canvas->base ( ), XmNtopAttachment, XmATTACH_FORM,
299 XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM,
300 XmNrightAttachment, XmATTACH_FORM, NULL);
304 _win1 = new MyDocument ("InnerWin", _canvas);
306 // Add the document to the canvas
308 _canvas->add (_win1);
316 ----------------------------------------------------------------------------
320 static void _destroyCallback (Widget, XtPointer clientData, XtPointer)
322 Boolean *quit = (Boolean*)clientData;
326 int main (int argc, char **argv)
328 XtAppContext appContext;
330 Boolean quit = False;
332 // Initialize toolkit
334 topLevel = XtVaAppInitialize (&appContext, "MDI", NULL, 0, &argc, argv,
335 fallbacks, XmNdeleteResponse, XmDO_NOTHING, NULL);
337 Display *dpy = XtDisplay (topLevel);
341 Atom WM_DELETE_WINDOW = XmInternAtom (dpy, "WM_DELETE_WINDOW", False);
343 XmAddWMProtocolCallback (topLevel, WM_DELETE_WINDOW, _destroyCallback,
346 // Create the MDI canvas
348 XsMDICanvas *canvas = new XsMDICanvas ("MDItest", topLevel);
350 // Create the MDI documents
352 MyDocument *win1 = new MyDocument ("Document", canvas);
353 MyDocument2 *win2 = new MyDocument2 ("Document 2");
355 // Add documents to MDI canvas
364 // Realize everything
366 XtRealizeWidget (topLevel);
374 XtAppNextEvent (appContext, &event);
375 XtDispatchEvent (&event);
384 // Close the X connection
386 XtDestroyWidget (topLevel);
387 XtCloseDisplay (dpy);
388 XtDestroyApplicationContext (appContext);