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 <limits.h>
14 #include <Xm/DialogS.h>
15 #include <Xm/Form.h>
16 #include <Xm/Frame.h>
17 #include <Xm/List.h>
18 #include <Xm/Text.h>
19 #include <Xm/SeparatoG.h>
20 #include <Xm/ScrolledW.h>
21 #include <Xm/PushB.h>
22 #include <Xm/ToggleB.h>
23 #include <Xm/Label.h>
24
25 #include "DXStrings.h"
26 #include "ListIterator.h"
27 #include "ControlPanel.h"
28 #include "ControlPanelGroupDialog.h"
29 #include "PanelGroupManager.h"
30 #include "Network.h"
31 #include "DXApplication.h"
32 #include "ErrorDialogManager.h"
33 #include "XmUtility.h"
34
35 ControlPanelGroupDialog* theCPGroupDialog = NULL;
36
37 boolean ControlPanelGroupDialog::ClassInitialized = FALSE;
38
39 String ControlPanelGroupDialog::DefaultResources[] = {
40 "*XmToggleButton.indicatorSize: 15",
41 "*dialogTitle: Control Panel Group...",
42 "*text.width: 280",
43 "*scrolledWindow.height: 170",
44 "*addButton.labelString: Add",
45 "*deleteButton.labelString: Delete",
46 "*changeButton.labelString: Modify",
47 "*closeButton.labelString: Close",
48 "*nameLabel.labelString: Group Name: ",
49 "*groupLabel.labelString: Groups: ",
50 "*panelLabel.labelString: Panels: ",
51 NULL
52 };
53
ControlPanelGroupDialog(Widget parent)54 ControlPanelGroupDialog::ControlPanelGroupDialog(Widget parent)
55 : Dialog("panelGroupDialog", parent)
56 {
57 if (NOT ControlPanelGroupDialog::ClassInitialized)
58 {
59 ControlPanelGroupDialog::ClassInitialized = TRUE;
60 this->installDefaultResources(theApplication->getRootWidget());
61 }
62 }
~ControlPanelGroupDialog()63 ControlPanelGroupDialog::~ControlPanelGroupDialog()
64 {
65 }
66
67
68 //
69 // Install the default resources for this class.
70 //
installDefaultResources(Widget baseWidget)71 void ControlPanelGroupDialog::installDefaultResources(Widget baseWidget)
72 {
73 this->setDefaultResources(baseWidget,
74 ControlPanelGroupDialog::DefaultResources);
75 this->Dialog::installDefaultResources( baseWidget);
76 }
77
78
createDialog(Widget parent)79 Widget ControlPanelGroupDialog::createDialog(Widget parent)
80 {
81 Widget frame1, frame2, sw1, sw2, separator1;
82 Widget nameLabel, groupLabel;
83 Arg arg[5];
84 int n = 0;
85
86 XtSetArg(arg[n], XmNautoUnmanage, False); n++;
87 XtSetArg(arg[n], XmNresizePolicy, XmRESIZE_NONE); n++;
88
89 Widget mainform = this->CreateMainForm(parent, this->name, arg, n);
90
91 this->addbtn = XtVaCreateManagedWidget("addButton",
92 xmPushButtonWidgetClass,mainform,
93 XmNleftAttachment, XmATTACH_FORM,
94 XmNleftOffset, 5,
95 XmNbottomAttachment, XmATTACH_FORM,
96 XmNbottomOffset, 10,
97 XmNwidth, 60,
98 NULL);
99
100 this->deletebtn = XtVaCreateManagedWidget("deleteButton",
101 xmPushButtonWidgetClass,mainform,
102 XmNleftAttachment, XmATTACH_WIDGET,
103 XmNleftWidget, this->addbtn,
104 XmNleftOffset, 10,
105 XmNbottomAttachment, XmATTACH_FORM,
106 XmNbottomOffset, 10,
107 XmNwidth, 60,
108 NULL);
109
110 this->changebtn = XtVaCreateManagedWidget("changeButton",
111 xmPushButtonWidgetClass,mainform,
112 XmNleftAttachment, XmATTACH_WIDGET,
113 XmNleftWidget, this->deletebtn,
114 XmNleftOffset, 10,
115 XmNbottomAttachment, XmATTACH_FORM,
116 XmNbottomOffset, 10,
117 XmNwidth, 60,
118 XmNsensitive, False,
119 NULL);
120
121 this->cancel = XtVaCreateManagedWidget("closeButton",
122 xmPushButtonWidgetClass,mainform,
123 XmNrightAttachment, XmATTACH_FORM,
124 XmNrightOffset, 5,
125 XmNbottomAttachment, XmATTACH_FORM,
126 XmNbottomOffset, 10,
127 XmNwidth, 60,
128 NULL);
129
130 separator1 = XtVaCreateManagedWidget("separator",
131 xmSeparatorGadgetClass, mainform,
132 XmNleftAttachment, XmATTACH_FORM,
133 XmNleftOffset, 2,
134 XmNrightAttachment, XmATTACH_FORM,
135 XmNrightOffset, 2,
136 XmNbottomAttachment, XmATTACH_WIDGET,
137 XmNbottomWidget, this->addbtn,
138 XmNbottomOffset, 10,
139 NULL);
140
141 nameLabel = XtVaCreateManagedWidget("nameLabel",
142 xmLabelWidgetClass,mainform,
143 XmNleftAttachment, XmATTACH_FORM,
144 XmNleftOffset, 5,
145 XmNbottomAttachment, XmATTACH_WIDGET,
146 XmNbottomWidget, separator1,
147 XmNbottomOffset, 14,
148 XmNalignment, XmALIGNMENT_BEGINNING,
149 NULL);
150
151 this->text = XtVaCreateManagedWidget("text",
152 xmTextWidgetClass, mainform,
153 XmNbottomAttachment, XmATTACH_WIDGET,
154 XmNbottomWidget, separator1,
155 XmNbottomOffset, 10,
156 XmNrightAttachment, XmATTACH_FORM,
157 XmNleftAttachment, XmATTACH_WIDGET,
158 XmNleftOffset, 10,
159 XmNrightOffset, 5,
160 XmNleftWidget, nameLabel,
161 XmNeditMode, XmSINGLE_LINE_EDIT,
162 XmNeditable, True,
163 NULL);
164
165 groupLabel = XtVaCreateManagedWidget("groupLabel",
166 xmLabelWidgetClass,mainform,
167 XmNtopAttachment, XmATTACH_FORM,
168 XmNleftAttachment, XmATTACH_FORM,
169 XmNtopOffset, 5,
170 XmNleftOffset, 5,
171 XmNalignment, XmALIGNMENT_BEGINNING,
172 NULL);
173
174 XtVaCreateManagedWidget("panelLabel",
175 xmLabelWidgetClass,mainform,
176 XmNtopAttachment, XmATTACH_FORM,
177 XmNleftAttachment, XmATTACH_POSITION,
178 XmNleftPosition, 50,
179 XmNtopOffset, 5,
180 XmNleftOffset, 5,
181 XmNalignment, XmALIGNMENT_BEGINNING,
182 NULL);
183
184 frame1 = XtVaCreateManagedWidget("frame",
185 xmFrameWidgetClass, mainform,
186 XmNshadowThickness, 1,
187 XmNtopAttachment, XmATTACH_WIDGET,
188 XmNtopWidget, groupLabel,
189 XmNleftAttachment, XmATTACH_FORM,
190 XmNrightAttachment, XmATTACH_POSITION,
191 XmNrightPosition, 50,
192 XmNbottomAttachment, XmATTACH_WIDGET,
193 XmNbottomWidget, this->text,
194 XmNshadowType, XmSHADOW_IN,
195 XmNleftOffset, 5,
196 XmNrightOffset, 3,
197 XmNtopOffset, 5,
198 XmNbottomOffset, 10,
199 NULL);
200
201 frame2 = XtVaCreateManagedWidget("frame",
202 xmFrameWidgetClass, mainform,
203 XmNshadowThickness, 1,
204 XmNtopAttachment, XmATTACH_WIDGET,
205 XmNtopWidget, groupLabel,
206 XmNleftAttachment, XmATTACH_POSITION,
207 XmNleftPosition, 50,
208 XmNrightAttachment, XmATTACH_FORM,
209 XmNbottomAttachment, XmATTACH_WIDGET,
210 XmNbottomWidget, this->text,
211 XmNshadowType, XmSHADOW_IN,
212 XmNleftOffset, 3,
213 XmNrightOffset, 5,
214 XmNtopOffset, 5,
215 XmNbottomOffset, 10,
216 NULL);
217
218 sw1 = XtVaCreateManagedWidget("scrolledWindow",
219 xmScrolledWindowWidgetClass,
220 frame1,
221 XmNscrollingPolicy, XmAPPLICATION_DEFINED,
222 XmNshadowThickness,0,
223 XmNscrollBarDisplayPolicy, XmSTATIC,
224 NULL);
225
226 this->list = XtVaCreateManagedWidget("list",
227 xmListWidgetClass,
228 sw1,
229 XmNlistMarginHeight,3,
230 XmNlistMarginWidth, 3,
231 XmNlistSpacing, 3,
232 XmNshadowThickness, 0,
233 XmNselectionPolicy, XmSINGLE_SELECT,
234 XmNlistSizePolicy, XmCONSTANT,
235 NULL);
236
237 XtVaSetValues(sw1, XmNworkWindow, this->list, NULL);
238
239 sw2 = XtVaCreateManagedWidget("scrolledWindow",
240 xmScrolledWindowWidgetClass,
241 frame2,
242 XmNscrollingPolicy, XmAUTOMATIC,
243 XmNshadowThickness,0,
244 NULL);
245 this->sform = XtVaCreateManagedWidget("sform",
246 xmFormWidgetClass,
247 sw2,
248 NULL);
249
250 XtVaSetValues(sw2, XmNworkWindow, this->sform, NULL);
251
252 XtAddCallback(this->list,
253 XmNsingleSelectionCallback,
254 (XtCallbackProc)ControlPanelGroupDialog_SelectCB,
255 (XtPointer)this);
256
257 XtAddCallback(this->addbtn,
258 XmNactivateCallback,
259 (XtCallbackProc)ControlPanelGroupDialog_AddCB,
260 (XtPointer)this);
261
262 XtAddCallback(this->deletebtn,
263 XmNactivateCallback,
264 (XtCallbackProc)ControlPanelGroupDialog_DeleteCB,
265 (XtPointer)this);
266
267 XtAddCallback(this->changebtn,
268 XmNactivateCallback,
269 (XtCallbackProc)ControlPanelGroupDialog_ChangeCB,
270 (XtPointer)this);
271
272 XtAddCallback(this->text,
273 XmNmodifyVerifyCallback,
274 (XtCallbackProc)ControlPanelGroupDialog_TextVerifyCB,
275 (XtPointer)this);
276
277 return mainform;
278 }
279
280
makeGroupList(int item)281 void ControlPanelGroupDialog::makeGroupList(int item)
282 {
283 XmString *xmstrings;
284 int items = this->panelManager->getGroupCount();
285 int i = -1;
286
287 if (items != 0)
288 {
289 xmstrings = new XmString[items];
290 for(i=0; i < items; i++)
291 {
292 xmstrings[i] =
293 XmStringCreateSimple((char*)this->panelManager->getPanelGroup(i+1, NULL));
294 }
295 }
296 else
297 {
298 items = 1;
299 xmstrings = new XmString[1];
300 xmstrings[0] = XmStringCreateSimple("(none)");
301 }
302
303 XtVaSetValues(this->list,
304 XmNitemCount, items,
305 XmNvisibleItemCount, items,
306 XmNitems, xmstrings,
307 NULL);
308
309 this->lastIndex = 0;
310
311 if(i < 0 OR item == 0)
312 {
313 XmTextSetString(this->text, NULL);
314 XtVaSetValues(this->changebtn, XmNsensitive, False, NULL);
315 XtVaSetValues(this->deletebtn, XmNsensitive, False, NULL);
316 XmListDeselectAllItems(this->list);
317 this->setToggles();
318 }
319 else
320 {
321 if(item > 0)
322 XmListSelectPos(this->list, item > items ? 0 : item, True);
323 else
324 {
325 char *name = XmTextGetString(this->text);
326 for(i=1; i<=items; i++)
327 if(EqualString(name,
328 (char*)this->panelManager->getPanelGroup(i,NULL)))
329 break;
330 XmListSelectPos(this->list, i, True);
331 XtFree(name); // AJ
332 }
333 }
334
335 for (i=0 ; i<items ; i++)
336 XmStringFree(xmstrings[i]);
337
338 delete xmstrings;
339 }
340
makeToggles()341 void ControlPanelGroupDialog::makeToggles()
342 {
343 int i;
344 Boolean set = FALSE, state = FALSE;
345 Widget widget, lastwidget = NULL; // NULL stops scary cc warnings
346 ControlPanel *cp;
347 List glist;
348 char *pname;
349 Network *network = this->panelManager->getNetwork();
350
351 ListIterator li(this->toggleList[0]);
352 int size = network->getPanelCount();
353
354 XtUnmanageChild(this->sform);
355
356 if(this->toggleList[0].getSize() > 0)
357 {
358 while( (widget = (Widget)li.getNext()) )
359 XtDestroyWidget(widget);
360
361 li.setList(this->toggleList[1]);
362 while( (widget = (Widget)li.getNext()) )
363 XtDestroyWidget(widget);
364
365 this->toggleList[0].clear();
366 this->toggleList[1].clear();
367 }
368
369 if(size == 0)
370 {
371 this->unmanage();
372 return;
373 }
374
375 set = this->lastIndex
376 AND this->panelManager->getGroupCount()
377 AND this->panelManager->getPanelGroup(this->lastIndex, &glist);
378
379 for(i = 0; i < size; i++)
380 {
381 cp = network->getPanelByIndex(i+1);
382 /*inst = cp->getInstanceNumber();*/
383 if(set)
384 state = glist.isMember((void*)cp->getInstanceNumber());
385 else
386 state = FALSE;
387
388 pname = (char*)cp->getPanelNameString();
389 if(IsBlankString(pname))
390 pname = "Control Panel";
391
392 widget = XmCreateToggleButton(this->sform,
393 pname,
394 NULL,
395 0);
396 XtVaSetValues(widget,
397 XmNset, state,
398 XmNindicatorType, XmN_OF_MANY,
399 XmNalignment, XmALIGNMENT_BEGINNING,
400 XmNshadowThickness,0,
401 XmNleftAttachment, XmATTACH_FORM,
402 XmNrightAttachment,XmATTACH_POSITION,
403 XmNrightPosition, 70,
404 XmNtopOffset, 2,
405 XmNleftOffset, 2,
406 NULL);
407 if(i == 0)
408 XtVaSetValues(widget, XmNtopAttachment,XmATTACH_FORM,NULL);
409 else
410 XtVaSetValues(widget,
411 XmNtopAttachment,XmATTACH_WIDGET,
412 XmNtopWidget, lastwidget,
413 NULL);
414
415 this->toggleList[0].appendElement((void*)widget);
416 XtManageChild(widget);
417
418 state = cp->isManaged();
419 widget = XmCreateToggleButton(this->sform,
420 "...",
421 NULL,
422 0);
423 XtVaSetValues(widget,
424 XmNuserData, cp,
425 XmNset, state,
426 XmNindicatorOn, False,
427 XmNfillOnSelect, False,
428 XmNrightAttachment,XmATTACH_FORM,
429 XmNleftAttachment,XmATTACH_POSITION,
430 XmNleftPosition, 70,
431 XmNindicatorSize, 1,
432 XmNtopOffset, 2,
433 XmNleftOffset, 5,
434 NULL);
435 if(i == 0)
436 XtVaSetValues(widget, XmNtopAttachment,XmATTACH_FORM,NULL);
437 else
438 XtVaSetValues(widget,
439 XmNtopAttachment,XmATTACH_WIDGET,
440 XmNtopWidget, lastwidget,
441 NULL);
442
443 XtAddCallback(widget,
444 XmNvalueChangedCallback,
445 (XtCallbackProc)ControlPanelGroupDialog_OpenPanelCB,
446 (XtPointer)this);
447
448 this->toggleList[1].appendElement((void*)widget);
449 XtManageChild(widget);
450
451 lastwidget = widget;
452 }
453
454 XtManageChild(this->sform);
455 }
456
setToggles()457 void ControlPanelGroupDialog::setToggles()
458 {
459 Widget widget;
460 List plist;
461 int i, size = this->toggleList[0].getSize();
462 boolean state=false, set = this->lastIndex;
463 ControlPanel *cp;
464
465 if(set)
466 this->panelManager->getPanelGroup(this->lastIndex, &plist);
467
468 for(i = 1; i <= size; i++)
469 {
470 widget = (Widget)this->toggleList[1].getElement(i);
471 XtVaGetValues(widget, XmNuserData, &cp, NULL);
472 XtVaSetValues(widget, XmNset, cp->isManaged(), NULL);
473 if(set)
474 state = plist.isMember((void*)cp->getInstanceNumber());
475 widget = (Widget)this->toggleList[0].getElement(i);
476 XtVaSetValues(widget, XmNset, set AND state, NULL);
477 }
478
479 }
480
ControlPanelGroupDialog_DeleteCB(Widget widget,XtPointer clientData,XtPointer callData)481 extern "C" void ControlPanelGroupDialog_DeleteCB(Widget widget,
482 XtPointer clientData,
483 XtPointer callData)
484 {
485 const char *name;
486 ControlPanelGroupDialog* pgd = (ControlPanelGroupDialog*)clientData;
487
488 if(pgd->lastIndex == 0)
489 ModalErrorMessage(pgd->getRootWidget(), "No group name is chosen.");
490 else if(pgd->panelManager->getGroupCount() == 0)
491 ModalErrorMessage(pgd->getRootWidget(), "No group exists.");
492 else
493 {
494 name = pgd->panelManager->getPanelGroup(pgd->lastIndex, NULL);
495 pgd->panelManager->removePanelGroup(name);
496 pgd->makeGroupList(pgd->lastIndex);
497 }
498
499 //
500 // Let the application know that the panels have changed (generally,
501 // this means notifying the DXWindows which may have panelAccessDialogs
502 // open).
503 //
504 theDXApplication->notifyPanelChanged();
505 }
506
ControlPanelGroupDialog_ChangeCB(Widget widget,XtPointer clientData,XtPointer callData)507 extern "C" void ControlPanelGroupDialog_ChangeCB(Widget widget,
508 XtPointer clientData,
509 XtPointer callData)
510 {
511 ControlPanelGroupDialog* pgd = (ControlPanelGroupDialog*)clientData;
512 ASSERT(pgd->lastIndex);
513
514 ControlPanelGroupDialog_AddCB(widget, clientData, callData);
515 }
516
ControlPanelGroupDialog_AddCB(Widget widget,XtPointer clientData,XtPointer callData)517 extern "C" void ControlPanelGroupDialog_AddCB(Widget widget,
518 XtPointer clientData,
519 XtPointer callData)
520 {
521 ControlPanelGroupDialog* pgd = (ControlPanelGroupDialog*)clientData;
522 char* oldname = NULL;
523 char* name = XmTextGetString(pgd->text);
524 Boolean setting;
525
526 if(widget == pgd->changebtn)
527 {
528 oldname = (char*)pgd->panelManager->getPanelGroup(pgd->lastIndex, NULL);
529 if(EqualString(oldname, name))
530 {
531 pgd->panelManager->removePanelGroup(name);
532 oldname = NULL;
533 }
534 }
535
536 if(IsBlankString(name))
537 {
538 ModalErrorMessage(pgd->getRootWidget(), "No name is given.");
539 goto error;
540 }
541 else
542 if(NOT pgd->panelManager->createPanelGroup(name))
543 {
544 ModalErrorMessage(pgd->getRootWidget(), "%s already exists.", name);
545 goto error;
546 }
547 else
548 {
549 int i, size = pgd->toggleList[0].getSize();
550 Widget widget;
551 ControlPanel *cp;
552
553 for(i = 1; i <= size; i++)
554 {
555 widget = (Widget)pgd->toggleList[0].getElement(i);
556 XtVaGetValues(widget, XmNset, &setting, NULL);
557 if(setting)
558 {
559 widget = (Widget)pgd->toggleList[1].getElement(i);
560 XtVaGetValues(widget, XmNuserData, &cp, NULL);
561 pgd->panelManager->addGroupMember(name,cp->getInstanceNumber());
562 }
563 }
564
565 if(oldname)
566 pgd->panelManager->removePanelGroup(oldname);
567 pgd->makeGroupList(-1);
568 }
569
570
571 //
572 // Let the application know that the panels have changed (generally,
573 // this means notifying the DXWindows which may have panelAccessDialogs
574 // open).
575 //
576 theDXApplication->notifyPanelChanged();
577
578 error:
579 if(name) XtFree(name); // AJ
580 }
581
ControlPanelGroupDialog_SelectCB(Widget widget,XtPointer clientData,XtPointer callData)582 extern "C" void ControlPanelGroupDialog_SelectCB(Widget widget,
583 XtPointer clientData,
584 XtPointer callData)
585 {
586 ControlPanelGroupDialog* pgd = (ControlPanelGroupDialog*)clientData;
587 XmListCallbackStruct* cs = (XmListCallbackStruct*)callData;
588
589 int callIndex = cs->item_position;
590
591 if(callIndex == pgd->lastIndex)
592 {
593 pgd->lastIndex = 0;
594 XmTextSetString(pgd->text, NULL);
595 XtVaSetValues(pgd->changebtn, XmNsensitive, False, NULL);
596 XtVaSetValues(pgd->deletebtn, XmNsensitive, False, NULL);
597 pgd->setToggles();
598 }
599 else
600 {
601 char *name = (char*)pgd->panelManager->getPanelGroup(callIndex, NULL);
602 XmTextSetString(pgd->text, name);
603 if(name)
604 {
605 XtVaSetValues(pgd->changebtn, XmNsensitive, True, NULL);
606 XtVaSetValues(pgd->deletebtn, XmNsensitive, True, NULL);
607 }
608
609 pgd->lastIndex = callIndex;
610 pgd->setToggles();
611 }
612 }
613
614
ControlPanelGroupDialog_OpenPanelCB(Widget widget,XtPointer clientData,XtPointer callData)615 extern "C" void ControlPanelGroupDialog_OpenPanelCB(Widget widget,
616 XtPointer clientData,
617 XtPointer callData)
618 {
619 Boolean set;
620 ControlPanelGroupDialog *pgd = (ControlPanelGroupDialog*)clientData;
621 ControlPanel *cp;
622 int cpCount2, cpCount1 = pgd->panelManager->getNetwork()->getPanelCount();
623
624 XtVaGetValues(widget,
625 XmNset, &set,
626 XmNuserData, &cp,
627 NULL);
628
629 set ? cp->manage() : cp->unmanage();
630
631 cpCount2 = pgd->panelManager->getNetwork()->getPanelCount();
632
633 if(cpCount2 == 0)
634 pgd->unmanage();
635 else if (cpCount2 < cpCount1)
636 pgd->makeToggles();
637 }
638
ControlPanelGroupDialog_TextVerifyCB(Widget widget,XtPointer clientData,XtPointer callData)639 extern "C" void ControlPanelGroupDialog_TextVerifyCB(Widget widget,
640 XtPointer clientData,
641 XtPointer callData)
642 {
643 XmTextVerifyCallbackStruct *cbs = (XmTextVerifyCallbackStruct *)callData;
644
645 VerifyNameText(widget, cbs);
646 }
647
648
manage()649 void ControlPanelGroupDialog::manage()
650 {
651 this->makeGroupList();
652 this->makeToggles();
653 XmTextSetString(this->text,NULL);
654 this->Dialog::manage();
655 }
656
setData(PanelGroupManager * pgm)657 void ControlPanelGroupDialog::setData(PanelGroupManager* pgm)
658 {
659 this->panelManager = pgm;
660 }
661
SetControlPanelGroup(PanelGroupManager * pgm)662 void SetControlPanelGroup(PanelGroupManager* pgm)
663 {
664 if(NOT theCPGroupDialog)
665 theCPGroupDialog =
666 new ControlPanelGroupDialog(theDXApplication->getRootWidget());
667 theCPGroupDialog->setData(pgm);
668 theCPGroupDialog->post();
669 }
670
671