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
14
15 #include <Xm/Xm.h>
16 #include <Xm/Text.h>
17 #include <Xm/Form.h>
18 #include <Xm/PushB.h>
19
20 #include "Application.h"
21 #include "FileSelectorNode.h"
22 #include "FileSelectorInteractor.h"
23 #include "FileSelectorDialog.h"
24 #include "InteractorInstance.h"
25 #include "FileSelectorInstance.h"
26 #include "ErrorDialogManager.h"
27
28 #define TEXT_COLUMNS 16
29
30 boolean FileSelectorInteractor::ClassInitialized = FALSE;
31
32 String FileSelectorInteractor::DefaultResources[] =
33 {
34 ".allowHorizontalResizing: True",
35 "*fsdButton.labelString: ...",
36 "*fsdButton.bottomOffset: 2",
37 "*fsdButton.topOffset: 2",
38 "*fsdButton.rightOffset: 3",
39 "*textEditor.bottomOffset: 2",
40 "*textEditor.topOffset: 2",
41 "*textEditor.leftOffset: 3",
42 "*pinLeftRight: True",
43 NUL(char*)
44 };
45
FileSelectorInteractor(const char * name,InteractorInstance * ii)46 FileSelectorInteractor::FileSelectorInteractor(const char * name,
47 InteractorInstance *ii) :
48 ValueInteractor(name, ii)
49 {
50 this->fileSelectorDialog = NULL;
51 this->fsdButton = NULL;
52 }
53
~FileSelectorInteractor()54 FileSelectorInteractor::~FileSelectorInteractor()
55 {
56 if (this->fileSelectorDialog)
57 delete this->fileSelectorDialog;
58 }
59 //
60 // Allocate the interactor.
61 //
AllocateInteractor(const char * name,InteractorInstance * ii)62 Interactor *FileSelectorInteractor::AllocateInteractor(const char *name,
63 InteractorInstance *ii)
64 {
65 FileSelectorInteractor *i = new FileSelectorInteractor(name,ii);
66 return (Interactor*)i;
67 }
68
initialize()69 void FileSelectorInteractor::initialize()
70 {
71 //
72 // Initialize default resources (once only).
73 //
74 if (NOT FileSelectorInteractor::ClassInitialized)
75 {
76 ASSERT(theApplication);
77 this->setDefaultResources(theApplication->getRootWidget(),
78 FileSelectorInteractor::DefaultResources);
79 this->setDefaultResources(theApplication->getRootWidget(),
80 ValueInteractor::DefaultResources);
81 this->setDefaultResources(theApplication->getRootWidget(),
82 Interactor::DefaultResources);
83 FileSelectorInteractor::ClassInitialized = TRUE;
84 }
85 }
86 //
87 // Put the super class's interactive part in a form with a button that
88 // opens the file selection box.
89 //
createInteractivePart(Widget form)90 Widget FileSelectorInteractor::createInteractivePart(Widget form)
91 {
92 // FIXME: install modifyVerify callback to ensure that file exists.
93 Widget text = this->ValueInteractor::createInteractivePart(form);
94 XtVaSetValues(text, XmNleftAttachment, XmATTACH_FORM,
95 XmNtopAttachment, XmATTACH_FORM,
96 XmNbottomAttachment, XmATTACH_FORM,
97 #if (XmVersion < 1001)
98 XmNcolumns, 4*TEXT_COLUMNS,
99 #else
100 XmNcolumns, TEXT_COLUMNS,
101 #endif
102 NULL);
103
104 this->fsdButton = XtVaCreateManagedWidget("fsdButton",
105 xmPushButtonWidgetClass, form,
106 XmNrightAttachment, XmATTACH_FORM,
107 XmNtopAttachment, XmATTACH_FORM,
108 XmNbottomAttachment, XmATTACH_FORM,
109 NULL);
110
111 XtVaSetValues(text, XmNrightAttachment, XmATTACH_WIDGET,
112 XmNrightWidget, this->fsdButton,
113 XmNrightOffset, 10,
114 XmNbottomAttachment, XmATTACH_FORM,
115 NULL);
116
117 XtAddCallback(this->fsdButton,
118 XmNactivateCallback,
119 (XtCallbackProc)FileSelectorInteractor_ButtonCB,
120 (XtPointer)this);
121
122 return form;
123
124 }
125 //
126 // Calls the virtual method this->buttonCallback() when the
127 // button is pressed.
128 //
FileSelectorInteractor_ButtonCB(Widget w,XtPointer clientData,XtPointer callData)129 extern "C" void FileSelectorInteractor_ButtonCB(Widget w,
130 XtPointer clientData,
131 XtPointer callData)
132 {
133 FileSelectorInteractor *fsi = (FileSelectorInteractor*) clientData;
134 fsi->buttonCallback(w,callData);
135 }
136 //
137 // Opens/closes the interactor's file selector dialog.
138 //
buttonCallback(Widget w,XtPointer callData)139 void FileSelectorInteractor::buttonCallback(Widget w, XtPointer callData)
140 {
141 InteractorInstance *ii = this->interactorInstance;
142 boolean first = FALSE;
143 if (!this->fileSelectorDialog) {
144 first = TRUE;
145 this->fileSelectorDialog = new FileSelectorDialog(
146 this->getRootWidget(),
147 (FileSelectorInstance*)ii);
148 }
149
150 FileSelectorDialog *fsd = this->fileSelectorDialog;
151 fsd->post();
152
153 if (first) {
154 const char *labelString = ii->getInteractorLabel();
155 if (labelString) {
156 char *s = this->FilterLabelString(labelString);
157 fsd->setDialogTitle(s);
158 delete s;
159 }
160 }
161 }
162
completeInteractivePart()163 void FileSelectorInteractor::completeInteractivePart()
164 {
165 this->ValueInteractor::completeInteractivePart();
166
167 //
168 // Make the fsdButton the same height as the text widget
169 //
170 Dimension height;
171 XtVaGetValues(this->textEditor, XmNheight, &height, NULL);
172 XtVaSetValues(this->fsdButton,
173 XmNheight, height,
174 XmNrecomputeSize, False,
175 NULL);
176 }
177 //
178 // Update the FileSelectorInteractor's title to match that of
179 // this interactor.
180 //
handleInteractivePartStateChange(InteractorInstance * src_ii,boolean major_change)181 void FileSelectorInteractor::handleInteractivePartStateChange(
182 InteractorInstance *src_ii,
183 boolean major_change)
184 {
185 this->updateDisplayedInteractorValue();
186 }
187 //
188 // Update the text value from the instance's notion of the current text.
189 // This is the same as ValueInteractor except that we strip of the
190 // double quotes and right justify the text.
191 //
updateDisplayedInteractorValue()192 void FileSelectorInteractor::updateDisplayedInteractorValue()
193 {
194 InteractorInstance *ii = (InteractorInstance*)this->interactorInstance;
195 Node *vnode = ii->getNode();
196 const char *v = vnode->getOutputValueString(1);
197 int len;
198
199 #ifdef RM_QUOTES
200 char *p = strchr(v,'"');
201 if (p && strchr(p+1,'"')) {
202 p = DuplicateString(p+1);
203 char *c = strchr(p,'"');
204 ASSERT(c);
205 *c = '\0';
206 this->installNewText(p);
207 len = STRLEN(p);
208 delete p;
209 } else {
210 this->installNewText(v);
211 len = STRLEN(v);
212 }
213 #else
214 this->ValueInteractor::updateDisplayedInteractorValue();
215 len = STRLEN(v);
216 #endif
217
218 //
219 // Right justify the text
220 //
221 XmTextShowPosition(this->textEditor,len);
222 XmTextSetInsertionPosition(this->textEditor,len);
223 }
224 //
225 // After calling the super class method, set the label on the
226 // FileSelectorDialog if we have one.
227 //
setLabel(const char * labelString,boolean re_layout)228 void FileSelectorInteractor::setLabel(const char *labelString,
229 boolean re_layout)
230 {
231 this->ValueInteractor::setLabel(labelString,re_layout);
232 if (this->fileSelectorDialog) {
233 char *s = this->FilterLabelString(labelString);
234 this->fileSelectorDialog->setDialogTitle(s);
235 delete s;
236 }
237 }
238
239
240