1 /***********************************************************************/
2 /* Open Visualization Data Explorer                                    */
3 /* (C) Copyright IBM Corp. 1989,1999                                   */
4 /* ALL RIGHTS RESERVED                                                 */
5 /* This code licensed under the                                        */
6 /*    "IBM PUBLIC LICENSE - Open Visualization Data Explorer"          */
7 /***********************************************************************/
8 
9 #include <dxconfig.h>
10 #include "../base/defines.h"
11 
12 
13 #include "Application.h"
14 #include "Dialog.h"
15 
16 #include <Xm/Protocols.h>
17 #include <Xm/AtomMgr.h>
18 #include <Xm/DialogS.h>
19 #include <Xm/Form.h>
20 #include <Xm/Label.h>
21 #include <Xm/Text.h>
22 #include <Xm/Separator.h>
23 #include <Xm/PushB.h>
24 
25 boolean Dialog::ClassInitialized = FALSE;
26 
27 
Dialog_OkCB(Widget,XtPointer clientData,XtPointer)28 extern "C" void Dialog_OkCB(Widget, XtPointer clientData, XtPointer)
29 {
30     Dialog 	      *dialog = (Dialog*)clientData;
31 
32     if (dialog->okCallback(dialog))
33         dialog->unmanage();
34 }
Dialog_CancelCB(Widget,XtPointer clientData,XtPointer)35 extern "C" void Dialog_CancelCB(Widget, XtPointer clientData, XtPointer)
36 {
37     Dialog 	      *dialog = (Dialog*)clientData;
38 
39     dialog->cancelCallback(dialog);
40     dialog->unmanage();
41 }
Dialog_HelpCB(Widget widget,XtPointer clientData,XtPointer)42 extern "C" void Dialog_HelpCB(Widget widget,
43 	        XtPointer clientData,
44 	        XtPointer)
45 {
46     Dialog 	      *dialog = (Dialog*)clientData;
47 
48     dialog->helpCallback(dialog);
49 }
50 
Dialog(const char * name,Widget parent)51 Dialog::Dialog(const char *name, Widget parent) :
52     UIComponent(name)
53 {
54     this->parent = parent;
55 
56     this->managed = FALSE;
57 
58     this->help = NULL;
59     this->ok = NULL;
60     this->cancel = NULL;
61 }
installDefaultResources(Widget baseWidget)62 void Dialog::installDefaultResources(Widget  baseWidget)
63 {
64 }
initialize()65 void Dialog::initialize()
66 {
67 }
68 
post()69 void Dialog::post()
70 {
71     theApplication->setBusyCursor(TRUE);
72     if (this->getRootWidget() == NULL)
73     {
74 	this->initialize();
75 	this->setRootWidget(this->createDialog(this->parent));
76 
77 	Widget shell = XtParent(this->getRootWidget());
78 	XtVaSetValues(shell, XmNdeleteResponse, XmDO_NOTHING, NULL);
79 	Atom WM_DELETE_WINDOW = XmInternAtom(XtDisplay(shell),
80 					    "WM_DELETE_WINDOW", False);
81 	XmAddWMProtocolCallback(shell, WM_DELETE_WINDOW,
82 				    (XtCallbackProc)Dialog_CancelCB,
83 				    (void *)(this));
84 
85 
86 	if (this->ok != NULL)
87 	    XtAddCallback(this->ok,
88 			  XmNactivateCallback,
89 			  (XtCallbackProc)Dialog_OkCB,
90 			  (XtPointer)this);
91 	if (this->help != NULL)
92 	    XtAddCallback(this->help,
93 			  XmNactivateCallback,
94 			  (XtCallbackProc)Dialog_HelpCB,
95 			  (XtPointer)this);
96 	if (this->cancel != NULL)
97 	    XtAddCallback(this->cancel,
98 			  XmNactivateCallback,
99 			  (XtCallbackProc)Dialog_CancelCB,
100 			  (XtPointer)this);
101     }
102 
103     this->manage();
104     theApplication->setBusyCursor(FALSE);
105 
106     XmUpdateDisplay(this->getRootWidget());
107 }
108 
createDialog(Widget)109 Widget Dialog::createDialog(Widget)
110 {
111     return NULL;
112 }
113 
114 //
115 // 10/6/95  The dec has a really big problem with using the old code.  Any Dialog
116 // which childs off a MainWindow always takes the size of the parent when the parent
117 // is resized.  The old code looks as though it should no longer be necessary.
118 // Martin
119 //
120 #define XmFormDialogWorks 1
121 
122 
123 #ifndef XmFormDialogWorks
124 //
125 // Used by Dialog::CreateMainForm() below
126 //
DestroyParentCB(Widget w,XtPointer,XtPointer)127 extern "C" void DestroyParentCB(Widget w, XtPointer , XtPointer)
128 {
129    XtDestroyWidget (XtParent (w));
130 }
131 #endif // XmFormDialogWorks
132 //
133 //
134 //  This is a fix of XmCreateFormDialog() which causes memory fault
135 //  on SGI indigo with Motif 1.1 and X11R4.
136 //  The original code was copied from Xm/Form.c.
137 //  NOTE:  This function creates a form contained by a shell which
138 //         takes popup/popdownCallback resources BUT minWidth/Height.
139 //
140 // FIXME: We may use different methods to create a FormDialog
141 // 	  on different platforms(by #ifdef) if neccesary.
142 //	  Right now I just use XmUtility:CreateFormDialog(),
143 //	  hoping it's OK on all platforms.
144 //
CreateMainForm(Widget parent,String name,ArgList arglist,Cardinal argcount)145 Widget Dialog::CreateMainForm(Widget parent, String name,
146                               ArgList arglist, Cardinal argcount)
147 {
148 #ifdef XmFormDialogWorks
149    return XmCreateFormDialog(parent,name,arglist,argcount);
150 #else
151    Widget form_shell;
152    Widget form;
153    Arg shell_arglist[2];
154    int shell_argcount = 0;
155    char buffer[256];
156 
157    /*  Create a pop-up shell for the form box.  */
158 
159    sprintf(buffer,"%sPopup",name);
160    XtSetArg (shell_arglist[0], XmNallowShellResize, True);
161    /* This function causes problem on indigo.
162     * form_shell = XmCreateDialogShell (parent, buffer,
163     *                                 shell_arglist, 1);
164     */
165    /* Use the following instead of the above */
166    form_shell = XtCreateWidget(buffer, xmDialogShellWidgetClass,
167                                 parent, shell_arglist, 1);
168 
169    /*  Create the widget  */
170 
171    form = XtCreateWidget (name, xmFormWidgetClass,
172                           form_shell, arglist, argcount);
173    XtAddCallback (form, XmNdestroyCallback, (XtCallbackProc)DestroyParentCB, NULL);
174    return form;
175 #endif // XmFormDialogWorks
176 
177 }
178 
manage()179 void Dialog::manage()
180 {
181     this->managed = TRUE;
182 
183     Widget w = this->getRootWidget();
184 
185     while(!XtIsShell(w))
186         w = XtParent(w);
187 
188     XWindowAttributes attr;
189     XGetWindowAttributes(XtDisplay(w), XtWindow(XtParent(w)), &attr);
190 
191     //
192     // MapRaise its parent only when it's unviewable or iconified.
193     //
194     if(XtParent(w) && (XtParent(w) != theApplication->getRootWidget())
195        && (attr.map_state==IsUnviewable || attr.map_state==IsUnmapped))
196         XMapRaised(XtDisplay(w), XtWindow(XtParent(w)));
197 
198     this->UIComponent::manage();
199     XMapRaised(XtDisplay(w), XtWindow(w));
200 }
201 
unmanage()202 void Dialog::unmanage()
203 {
204     this->UIComponent::unmanage();
205     this->managed = FALSE;
206 }
207 
isManaged()208 boolean Dialog::isManaged()
209 {
210     return this->managed;
211 }
212 //
213 // Set the title of the dialog after this->root has been created.
214 // Ignored if this->root has not been created yet.
215 //
setDialogTitle(const char * title)216 void Dialog::setDialogTitle(const char *title)
217 {
218     Widget shell;
219 
220     if ((shell=this->getRootWidget())) {
221     	while(NOT XtIsShell(shell))
222 	     shell = XtParent(shell);
223 
224 	if (shell)
225 	    XtVaSetValues(shell,  XmNtitle, title , NULL);
226     }
227 }
228