1 /* $TOG: DtMailGenDialog.C /main/15 1999/07/07 15:08:18 mgreess $ */
5 * $TOG: DtMailGenDialog.C /main/15 1999/07/07 15:08:18 mgreess $
7 * RESTRICTED CONFIDENTIAL INFORMATION:
9 * The information in this document is subject to special
10 * restrictions in a confidential disclosure agreement bertween
11 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
12 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
13 * Sun's specific written approval. This documment and all copies
14 * and derivative works thereof must be returned or destroyed at
17 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
21 //////////////////////////////////////////////////////////
22 // DtMailGenDialog.C: Generic dialog based on MessageBox
23 //////////////////////////////////////////////////////////
26 #include <sys/param.h>
32 #include <Dt/IconFile.h>
33 #include <Xm/MessageB.h>
34 #include <Xm/PushBG.h>
35 #include <Xm/MwmUtil.h>
37 #include "Application.h"
38 #include "DtMailGenDialog.hh"
39 #include "DtMailHelp.hh"
43 static const char *ABOUT_TITLE = NULL;
44 static char *DTMAIL_VERSION = NULL;
45 static const char *credits = "Dtmail was brought to you by: ";
46 static int doCredits = 0;
48 DtMailGenDialog::DtMailGenDialog(char *name, Widget parent, int style)
52 _w = XmCreateMessageDialog(parent, name, NULL, 0);
53 XtVaSetValues(_w, XmNdialogStyle, style, NULL);
55 // Disable the frame menu from all dialogs. We don't want
56 // the user to be able to dismiss dialogs through the frame
61 XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_MENU,
65 _otherWidget = (Widget) NULL;
66 _textField = (Widget) NULL;
70 _parentshell = parent;
71 while (_parentshell && !XtIsShell(_parentshell))
72 _parentshell = XtParent(_parentshell);
77 DtMailGenDialog::post(void *clientData,
79 DialogCallback cancel,
84 // _w is the MessageBox widget created in the constructor...
88 // Make sure the dialog exists, and that it is an XmMessageBox
89 // or subclass, since the callbacks assume this widget type
91 assert (dialog != NULL);
93 // Make sure the dialog buttons are managed
94 Widget ok_button = XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON);
95 Widget cancel_button = XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON);
96 Widget help_button = XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON);
98 // Create an object to carry the additional data needed
99 // to cache the dialogs.
101 DtMailDialogCallbackData *dcb = new DtMailDialogCallbackData(
102 (DtMailGenDialog *) this,
109 // Install callback function for each button
110 // support by Motif dialogs. If there is no help callback
111 // unmanage the corresponding button instead, if possible.
117 XmNokCallback, &DtMailGenDialog::okCallback,
119 if (!XtIsManaged(ok_button)) XtManageChild(ok_button);
121 else XtUnmanageChild(ok_button);
127 XmNcancelCallback, &DtMailGenDialog::cancelCallback,
129 if (!XtIsManaged(cancel_button)) XtManageChild(cancel_button);
131 else XtUnmanageChild(cancel_button);
138 XmNactivateCallback, &DtMailGenDialog::otherCallback,
141 else if (_otherWidget) XtUnmanageChild(_otherWidget);
148 XmNhelpCallback, &HelpErrorCB,
150 if (!XtIsManaged (help_button)) XtManageChild(help_button);
151 } else XtUnmanageChild(help_button);
154 // Make sure the parent dialog is popped up and occupying the
155 // current workspace.
157 if (NULL != _parentshell)
159 XtPopup(_parentshell, XtGrabNone);
160 displayInCurrentWorkspace(_parentshell);
164 XtManageChild(dialog);
166 if (NULL != _textField && XtIsManaged(_textField))
167 XmProcessTraversal(_textField, XmTRAVERSE_CURRENT);
172 DtMailGenDialog::okCallback(Widget w, XtPointer clientData, XtPointer cbs)
174 XmPushButtonCallbackStruct * pbcs = (XmPushButtonCallbackStruct *)cbs;
176 DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
177 DtMailGenDialog *obj = (DtMailGenDialog *) dcd->dialog();
178 DialogCallback callback;
180 // If caller specified an ok callback, call the function
182 if ((callback=dcd->ok()) != NULL) (*callback)(dcd->clientData());
184 // If the help widget was popped up, destroy it.
185 Widget helpWidget = getErrorHelpWidget();
188 XtUnmanageChild (helpWidget);
189 XtDestroyWidget (helpWidget);
190 clearErrorHelpWidget();
193 // Reset for the next time
195 Widget ow = dcd->other_w();
200 &DtMailGenDialog::otherCallback,
203 obj->cleanup(w, dcd);
205 if (obj->_info_dialog &&
206 (pbcs->event->xbutton.state & (ShiftMask | ControlMask)))
209 // Don't do credits for now
213 obj->setToAboutDialog();
214 // char * helpId = "About";
215 char * helpId = NULL;
216 int answer = obj->post_and_return(GETMSG(DT_catd, 1, 180, "OK"),
221 void DtMailGenDialog::cancelCallback(Widget w, XtPointer clientData, XtPointer)
223 DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
224 DtMailGenDialog *obj = (DtMailGenDialog *) dcd->dialog();
225 DialogCallback callback;
227 if ((callback=dcd->cancel()) != NULL) (*callback)(dcd->clientData());
229 // If the help widget was popped up, destroy it.
230 Widget helpWidget = getErrorHelpWidget();
233 XtUnmanageChild (helpWidget);
234 XtDestroyWidget (helpWidget);
235 clearErrorHelpWidget();
239 Widget ow = dcd->other_w();
241 XtRemoveCallback ( ow,
243 &DtMailGenDialog::otherCallback,
246 obj->cleanup(w, dcd);
249 void DtMailGenDialog::otherCallback(Widget w, XtPointer clientData, XtPointer)
251 DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
252 DtMailGenDialog *obj = (DtMailGenDialog *) dcd->dialog();
253 DialogCallback callback;
255 if ((callback=dcd->other()) != NULL) (*callback)(dcd->clientData());
260 &DtMailGenDialog::otherCallback,
263 Widget pw = XtParent(w);
264 obj->cleanup(pw, dcd);
267 void DtMailGenDialog::helpCallback(Widget, XtPointer clientData, XtPointer)
269 DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
270 DtMailGenDialog *obj = (DtMailGenDialog *) dcd->dialog();
271 DialogCallback callback;
273 if ((callback=dcd->help()) != NULL) (*callback)(dcd->clientData());
276 void DtMailGenDialog::verifyCallback(Widget, XtPointer clientD, XtPointer callD)
278 DtMailGenDialog *obj = (DtMailGenDialog*) clientD;
279 XmTextVerifyPtr cbs = (XmTextVerifyPtr) callD;
284 void DtMailGenDialog::verify(XmTextVerifyPtr cbs)
287 static char buffer[MAXPATHLEN];
288 register char *s, *t;
290 #if defined(SHROUDED_TEXTFIELD_DEBUG)
292 "currInsert=%d newInsert=%d startPos=%d endPos=%d\n",
293 cbs->currInsert,cbs->newInsert,cbs->startPos, cbs->endPos);
294 if (cbs->text->ptr) printf("text->ptr=%s\n", cbs->text->ptr);
295 printf("_clearText=%s\n", _clearText);
298 for (i=0, s=buffer, t=_clearText; (*t && i<cbs->startPos); i++, s++, t++)
303 strcpy(s, cbs->text->ptr);
304 s += cbs->text->length;
309 if (strlen(_clearText) >= cbs->endPos)
311 t = _clearText+cbs->endPos;
316 if (strlen(buffer) >= _maxTextlen)
319 _clearText = (char*) realloc((void*) _clearText, (size_t) _maxTextlen);
320 assert(NULL!=_clearText);
322 strcpy(_clearText, buffer);
324 if (_shroudText && cbs->text->ptr)
325 for (i=0, s=cbs->text->ptr; i<cbs->text->length; i++, s++)
328 #if defined(SHROUDED_TEXTFIELD_DEBUG)
329 printf("text=%s\n", _clearText);
334 void DtMailGenDialog::cleanup(Widget w, DtMailDialogCallbackData *dcd)
336 // Remove all callbacks to avoid having duplicate
337 // callback functions installed.
341 XmNokCallback, &DtMailGenDialog::okCallback,
346 XmNcancelCallback, &DtMailGenDialog::cancelCallback,
349 if (XtHasCallbacks(w, XmNhelpCallback) == XtCallbackHasSome)
350 XtRemoveAllCallbacks(w, XmNhelpCallback);
352 if (NULL != _textField && XtIsManaged(_textField))
353 XtUnmanageChild(_textField);
355 // Delete the DtMailDialogCallbackData instance for this posting
360 DtMailGenDialog::forceUpdate( Widget w )
362 Widget diashell, topshell;
363 Window diawindow, topwindow;
366 XWindowAttributes xwa;
370 XtAppContext cxt=XtWidgetToApplicationContext( w );
371 for (diashell=w;!XtIsShell(diashell);diashell=XtParent(diashell));
372 for (topshell=diashell;
373 XtIsTopLevelShell(topshell);
374 topshell=XtParent(topshell));
376 dpy=XtDisplay(diashell);
377 diawindow=XtWindow(diashell);
378 topwindow=XtWindow(topshell);
379 while (XGetWindowAttributes(dpy,diawindow,&xwa) &&
380 xwa.map_state != IsViewable && XEventsQueued(dpy,QueuedAlready))
382 XtAppProcessEvent(cxt, XtIMAll );
384 XmUpdateDisplay(topshell);
389 // Added this extra functionality
392 genDialogOKCallback( int *data )
398 genDialogCancelCallback( int *data )
404 genDialogOtherCallback( int *data )
408 // post_and_return takes a helpId, which is a string that is used to
409 // reference the related help in the Mailer help volume. The helpId
410 // is passed to post(), which will attach help to the help button in
413 DtMailGenDialog::post_and_return(char *helpId)
416 XmString okLabel, cancelLabel;
418 // They may have been set via the overloaded post_and_return()
419 // method before. Reset them to their default values...
421 okLabel = XmStringCreateLocalized(GETMSG(DT_catd, 1, 181, "OK"));
422 cancelLabel = XmStringCreateLocalized(GETMSG(DT_catd, 1, 182, "Cancel"));
424 // Make sure the dialog exists, and that it is an XmMessageBox
425 // or subclass, since the callbacks assume this widget type
427 assert ( _w != NULL );
430 XmNokLabelString, okLabel,
431 XmNcancelLabelString, cancelLabel,
433 XmStringFree( okLabel);
434 XmStringFree( cancelLabel);
439 this->post((void *) &answer,
440 ( DialogCallback ) &genDialogOKCallback,
441 ( DialogCallback ) &genDialogCancelCallback,
442 ( DialogCallback ) NULL,
443 ( DialogCallback ) &HelpErrorCB,
448 this->post((void *) &answer,
449 ( DialogCallback ) &genDialogOKCallback,
450 ( DialogCallback ) &genDialogCancelCallback,
451 ( DialogCallback ) NULL,
452 ( DialogCallback ) NULL,
457 forceUpdate( dialog );
460 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
463 // Process just one more event to pop down dialog.
464 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
470 // post_and_return(char *, char *) takes the string to be used for the
471 // OK button and the string that contains the helpId for the dialog being
472 // created, and passes them to post().
474 DtMailGenDialog::post_and_return(
482 okLabel = XmStringCreateLocalized(okLabelString);
484 // Make sure the dialog exists, and that it is an XmMessageBox
485 // or subclass, since the callbacks assume this widget type
487 assert ( _w != NULL );
490 XmNokLabelString, okLabel,
492 XmStringFree( okLabel);
496 dialog = this->post((void *) &answer,
497 ( DialogCallback ) &genDialogOKCallback,
498 ( DialogCallback ) NULL,
499 ( DialogCallback ) NULL,
500 ( DialogCallback ) &HelpErrorCB,
504 dialog = this->post((void *) &answer,
505 ( DialogCallback ) &genDialogOKCallback,
506 ( DialogCallback ) NULL,
507 ( DialogCallback ) NULL,
508 ( DialogCallback ) NULL,
513 forceUpdate( dialog );
516 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
519 // Process just one more event to pop down dialog.
520 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
526 // post_and_return(char*, char*, char*) takes the OK button label, Cancel
527 // button label, and the help id for the dialog and passes them to post().
529 DtMailGenDialog::post_and_return(
531 char *cancelLabelString,
536 XmString okLabel, cancelLabel;
538 okLabel = XmStringCreateLocalized(okLabelString);
539 cancelLabel = XmStringCreateLocalized(cancelLabelString);
541 // Make sure the dialog exists, and that it is an XmMessageBox
542 // or subclass, since the callbacks assume this widget type
544 assert ( _w != NULL );
547 XmNokLabelString, okLabel,
548 XmNcancelLabelString, cancelLabel,
550 XmStringFree( okLabel);
551 XmStringFree( cancelLabel);
553 Widget dialog = NULL;
555 dialog = this->post((void *) &answer,
556 ( DialogCallback ) &genDialogOKCallback,
557 ( DialogCallback ) &genDialogCancelCallback,
558 ( DialogCallback ) NULL,
559 ( DialogCallback ) &HelpErrorCB,
563 dialog = this->post((void *) &answer,
564 ( DialogCallback ) &genDialogOKCallback,
565 ( DialogCallback ) &genDialogCancelCallback,
566 ( DialogCallback ) NULL,
567 ( DialogCallback ) NULL,
572 forceUpdate( dialog );
575 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll);
578 // Process just one more event to pop down dialog.
579 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll);
586 DtMailGenDialog::post_and_return(
588 char *cancelLabelString,
589 char *otherLabelString,
594 XmString okLabel, cancelLabel, otherLabel;
596 okLabel = XmStringCreateLocalized(okLabelString);
597 cancelLabel = XmStringCreateLocalized(cancelLabelString);
598 otherLabel = XmStringCreateLocalized(otherLabelString);
601 // Make sure the dialog exists, and that it is an XmMessageBox
602 // or subclass, since the callbacks assume this widget type
604 assert ( _w != NULL );
606 Widget dialog = NULL;
607 Widget cancel_w = XmMessageBoxGetChild ( _w, XmDIALOG_CANCEL_BUTTON );
609 if (_otherWidget == NULL) {
610 _otherWidget = XtVaCreateWidget(otherLabelString,
611 xmPushButtonGadgetClass, _w,
612 XmNleftAttachment, XmMessageBoxGetChild ( _w,
613 XmDIALOG_OK_BUTTON ),
614 XmNrightAttachment, cancel_w,
616 XtManageChild (_otherWidget);
619 if (!XtIsManaged(_otherWidget)) {
620 XtManageChild (_otherWidget);
622 if (!XtIsManaged ( cancel_w ) ) {
623 XtManageChild ( cancel_w );
627 XmNokLabelString, okLabel,
628 XmNcancelLabelString, cancelLabel,
630 XtVaSetValues(_otherWidget,
631 XmNlabelString, otherLabel,
633 XmStringFree( okLabel);
634 XmStringFree( cancelLabel);
635 XmStringFree( otherLabel);
638 dialog = this->post((void *) &answer,
639 ( DialogCallback ) &genDialogOKCallback,
640 ( DialogCallback ) &genDialogCancelCallback,
641 ( DialogCallback ) &genDialogOtherCallback,
642 ( DialogCallback ) &HelpErrorCB,
647 this->post((void *) &answer,
648 ( DialogCallback ) &genDialogOKCallback,
649 ( DialogCallback ) &genDialogCancelCallback,
650 ( DialogCallback ) &genDialogOtherCallback,
651 ( DialogCallback ) NULL,
656 forceUpdate( dialog );
659 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
662 // Process just one more event to pop down dialog.
663 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
669 DtMailGenDialog::setDialog(char * title, char * text, unsigned char type)
671 XmString titleStr = XmStringCreateLocalized (title);
672 XmString xmStr = XmStringCreateLocalized(text);
674 XmNmessageString, xmStr,
675 XmNdialogTitle, titleStr,
679 XmStringFree ( titleStr );
684 DtMailGenDialog::getTextFieldValue()
686 if (_clearText) return strdup(_clearText);
691 DtMailGenDialog::setToTextFieldDialog(
697 if (NULL != _textField)
699 if (NULL != _clearText) *_clearText = '\0';
700 XtVaSetValues(_textField, XmNvalue, "", NULL);
701 XtManageChild(_textField);
705 _textField = XtVaCreateManagedWidget(
706 "GenDialogTF", xmTextFieldWidgetClass, _w,
711 XmNmodifyVerifyCallback,DtMailGenDialog::verifyCallback,
714 _clearText = (char*) malloc(_maxTextlen);
715 memset(_clearText, 0, _maxTextlen);
716 assert(NULL!=_clearText);
718 _shroudText = shroud;
719 setDialog(title, text, XmDIALOG_QUESTION);
723 DtMailGenDialog::setToQuestionDialog(
728 if (NULL != _textField && XtIsManaged(_textField))
729 XtUnmanageChild(_textField);
731 setDialog(title, text, XmDIALOG_QUESTION);
735 DtMailGenDialog::setToWarningDialog(
740 if (NULL != _textField && XtIsManaged(_textField))
741 XtUnmanageChild(_textField);
743 setDialog(title, text, XmDIALOG_WARNING);
747 DtMailGenDialog::setToErrorDialog(
752 if (NULL != _textField && XtIsManaged(_textField))
753 XtUnmanageChild(_textField);
755 setDialog(title, text, XmDIALOG_ERROR);
760 DtMailGenDialog::setToInfoDialog(
765 if (NULL != _textField && XtIsManaged(_textField))
766 XtUnmanageChild(_textField);
768 setDialog(title, text, XmDIALOG_INFORMATION);
770 #endif /* DEAD_WOOD */
772 extern "C" Pixmap _DtGetMask(Screen * screen, char * image_name);
775 DtMailGenDialog::setToAboutDialog(void)
778 setDialog((char *)"Credits",
780 XmDIALOG_INFORMATION);
784 if (NULL == ABOUT_TITLE) {
787 ABOUT_TITLE = GETMSG(DT_catd, 1, 235, "Mailer - About Mailer");
788 version = GETMSG(DT_catd, 1, 236, "Mailer Version %d.%d.%d");
790 DTMAIL_VERSION = new char [strlen(version) + 16];
792 DTMAIL_VERSION, version,
793 DtVERSION, DtREVISION, DtUPDATE_LEVEL);
795 setDialog((char *)ABOUT_TITLE,
796 (char *)DTMAIL_VERSION,
797 XmDIALOG_INFORMATION);
802 char * icon_filename = XmGetIconFileName(XtScreen(_w),
808 if (icon_filename == NULL) {
819 Pixmap icon = XmGetPixmap(XtScreen(_w),
823 Pixmap icon_mask = _DtGetMask(XtScreen(_w), icon_filename);
825 Pixmap clipped_icon = icon;
829 unsigned int width, height, border_width, depth;
830 XGetGeometry(XtDisplay(_w),
835 &border_width, &depth);
839 clipped_icon = XCreatePixmap(XtDisplay(_w),
847 memset(&gc_vals, 0, sizeof(gc_vals));
848 gc_vals.background = bg;
849 gc_vals.foreground = bg;
850 gc_vals.fill_style = FillSolid;
851 gc = XCreateGC(XtDisplay(_w),
853 GCForeground | GCBackground | GCFillStyle,
856 XFillRectangle(XtDisplay(_w),
862 XFreeGC(XtDisplay(_w), gc);
864 memset(&gc_vals, 0, sizeof(gc_vals));
865 gc_vals.background = bg;
866 gc = XCreateGC(XtDisplay(_w),
871 XSetClipMask(XtDisplay(_w), gc, icon_mask);
873 XCopyArea(XtDisplay(_w),
880 XFreeGC(XtDisplay(_w), gc);
884 XmNsymbolPixmap, clipped_icon,
887 if (NULL != _textField && XtIsManaged(_textField))
888 XtUnmanageChild(_textField);