2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: DtMailGenDialog.C /main/15 1999/07/07 15:08:18 mgreess $ */
27 * $TOG: DtMailGenDialog.C /main/15 1999/07/07 15:08:18 mgreess $
29 * RESTRICTED CONFIDENTIAL INFORMATION:
31 * The information in this document is subject to special
32 * restrictions in a confidential disclosure agreement bertween
33 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
35 * Sun's specific written approval. This documment and all copies
36 * and derivative works thereof must be returned or destroyed at
39 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
43 //////////////////////////////////////////////////////////
44 // DtMailGenDialog.C: Generic dialog based on MessageBox
45 //////////////////////////////////////////////////////////
48 #include <sys/param.h>
54 #include <Dt/IconFile.h>
55 #include <Xm/MessageB.h>
56 #include <Xm/PushBG.h>
57 #include <Xm/MwmUtil.h>
59 #include "Application.h"
60 #include "DtMailGenDialog.hh"
61 #include "DtMailHelp.hh"
65 static const char *ABOUT_TITLE = NULL;
66 static char *DTMAIL_VERSION = NULL;
67 static const char *credits = "Dtmail was brought to you by: ";
68 static int doCredits = 0;
70 DtMailGenDialog::DtMailGenDialog(char *name, Widget parent, int style)
74 _w = XmCreateMessageDialog(parent, name, NULL, 0);
75 XtVaSetValues(_w, XmNdialogStyle, style, NULL);
77 // Disable the frame menu from all dialogs. We don't want
78 // the user to be able to dismiss dialogs through the frame
83 XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_MENU,
87 _otherWidget = (Widget) NULL;
88 _textField = (Widget) NULL;
92 _parentshell = parent;
93 while (_parentshell && !XtIsShell(_parentshell))
94 _parentshell = XtParent(_parentshell);
99 DtMailGenDialog::post(void *clientData,
101 DialogCallback cancel,
102 DialogCallback other,
106 // _w is the MessageBox widget created in the constructor...
110 // Make sure the dialog exists, and that it is an XmMessageBox
111 // or subclass, since the callbacks assume this widget type
113 assert (dialog != NULL);
115 // Make sure the dialog buttons are managed
116 Widget ok_button = XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON);
117 Widget cancel_button = XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON);
118 Widget help_button = XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON);
120 // Create an object to carry the additional data needed
121 // to cache the dialogs.
123 DtMailDialogCallbackData *dcb = new DtMailDialogCallbackData(
124 (DtMailGenDialog *) this,
131 // Install callback function for each button
132 // support by Motif dialogs. If there is no help callback
133 // unmanage the corresponding button instead, if possible.
139 XmNokCallback, &DtMailGenDialog::okCallback,
141 if (!XtIsManaged(ok_button)) XtManageChild(ok_button);
143 else XtUnmanageChild(ok_button);
149 XmNcancelCallback, &DtMailGenDialog::cancelCallback,
151 if (!XtIsManaged(cancel_button)) XtManageChild(cancel_button);
153 else XtUnmanageChild(cancel_button);
160 XmNactivateCallback, &DtMailGenDialog::otherCallback,
163 else if (_otherWidget) XtUnmanageChild(_otherWidget);
170 XmNhelpCallback, &HelpErrorCB,
172 if (!XtIsManaged (help_button)) XtManageChild(help_button);
173 } else XtUnmanageChild(help_button);
176 // Make sure the parent dialog is popped up and occupying the
177 // current workspace.
179 if (NULL != _parentshell)
181 XtPopup(_parentshell, XtGrabNone);
182 displayInCurrentWorkspace(_parentshell);
186 XtManageChild(dialog);
188 if (NULL != _textField && XtIsManaged(_textField))
189 XmProcessTraversal(_textField, XmTRAVERSE_CURRENT);
194 DtMailGenDialog::okCallback(Widget w, XtPointer clientData, XtPointer cbs)
196 XmPushButtonCallbackStruct * pbcs = (XmPushButtonCallbackStruct *)cbs;
198 DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
199 DtMailGenDialog *obj = (DtMailGenDialog *) dcd->dialog();
200 DialogCallback callback;
202 // If caller specified an ok callback, call the function
204 if ((callback=dcd->ok()) != NULL) (*callback)(dcd->clientData());
206 // If the help widget was popped up, destroy it.
207 Widget helpWidget = getErrorHelpWidget();
210 XtUnmanageChild (helpWidget);
211 XtDestroyWidget (helpWidget);
212 clearErrorHelpWidget();
215 // Reset for the next time
217 Widget ow = dcd->other_w();
222 &DtMailGenDialog::otherCallback,
225 obj->cleanup(w, dcd);
227 if (obj->_info_dialog &&
228 (pbcs->event->xbutton.state & (ShiftMask | ControlMask)))
231 // Don't do credits for now
235 obj->setToAboutDialog();
236 // char * helpId = "About";
237 char * helpId = NULL;
238 int answer = obj->post_and_return(GETMSG(DT_catd, 1, 180, "OK"),
243 void DtMailGenDialog::cancelCallback(Widget w, XtPointer clientData, XtPointer)
245 DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
246 DtMailGenDialog *obj = (DtMailGenDialog *) dcd->dialog();
247 DialogCallback callback;
249 if ((callback=dcd->cancel()) != NULL) (*callback)(dcd->clientData());
251 // If the help widget was popped up, destroy it.
252 Widget helpWidget = getErrorHelpWidget();
255 XtUnmanageChild (helpWidget);
256 XtDestroyWidget (helpWidget);
257 clearErrorHelpWidget();
261 Widget ow = dcd->other_w();
263 XtRemoveCallback ( ow,
265 &DtMailGenDialog::otherCallback,
268 obj->cleanup(w, dcd);
271 void DtMailGenDialog::otherCallback(Widget w, XtPointer clientData, XtPointer)
273 DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
274 DtMailGenDialog *obj = (DtMailGenDialog *) dcd->dialog();
275 DialogCallback callback;
277 if ((callback=dcd->other()) != NULL) (*callback)(dcd->clientData());
282 &DtMailGenDialog::otherCallback,
285 Widget pw = XtParent(w);
286 obj->cleanup(pw, dcd);
289 void DtMailGenDialog::helpCallback(Widget, XtPointer clientData, XtPointer)
291 DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
292 DtMailGenDialog *obj = (DtMailGenDialog *) dcd->dialog();
293 DialogCallback callback;
295 if ((callback=dcd->help()) != NULL) (*callback)(dcd->clientData());
298 void DtMailGenDialog::verifyCallback(Widget, XtPointer clientD, XtPointer callD)
300 DtMailGenDialog *obj = (DtMailGenDialog*) clientD;
301 XmTextVerifyPtr cbs = (XmTextVerifyPtr) callD;
306 void DtMailGenDialog::verify(XmTextVerifyPtr cbs)
309 static char buffer[MAXPATHLEN];
310 register char *s, *t;
312 #if defined(SHROUDED_TEXTFIELD_DEBUG)
314 "currInsert=%d newInsert=%d startPos=%d endPos=%d\n",
315 cbs->currInsert,cbs->newInsert,cbs->startPos, cbs->endPos);
316 if (cbs->text->ptr) printf("text->ptr=%s\n", cbs->text->ptr);
317 printf("_clearText=%s\n", _clearText);
320 for (i=0, s=buffer, t=_clearText; (*t && i<cbs->startPos); i++, s++, t++)
325 strcpy(s, cbs->text->ptr);
326 s += cbs->text->length;
331 if (strlen(_clearText) >= cbs->endPos)
333 t = _clearText+cbs->endPos;
338 if (strlen(buffer) >= _maxTextlen)
341 _clearText = (char*) realloc((void*) _clearText, (size_t) _maxTextlen);
342 assert(NULL!=_clearText);
344 strcpy(_clearText, buffer);
346 if (_shroudText && cbs->text->ptr)
347 for (i=0, s=cbs->text->ptr; i<cbs->text->length; i++, s++)
350 #if defined(SHROUDED_TEXTFIELD_DEBUG)
351 printf("text=%s\n", _clearText);
356 void DtMailGenDialog::cleanup(Widget w, DtMailDialogCallbackData *dcd)
358 // Remove all callbacks to avoid having duplicate
359 // callback functions installed.
363 XmNokCallback, &DtMailGenDialog::okCallback,
368 XmNcancelCallback, &DtMailGenDialog::cancelCallback,
371 if (XtHasCallbacks(w, XmNhelpCallback) == XtCallbackHasSome)
372 XtRemoveAllCallbacks(w, XmNhelpCallback);
374 if (NULL != _textField && XtIsManaged(_textField))
375 XtUnmanageChild(_textField);
377 // Delete the DtMailDialogCallbackData instance for this posting
382 DtMailGenDialog::forceUpdate( Widget w )
384 Widget diashell, topshell;
385 Window diawindow, topwindow;
388 XWindowAttributes xwa;
392 XtAppContext cxt=XtWidgetToApplicationContext( w );
393 for (diashell=w;!XtIsShell(diashell);diashell=XtParent(diashell));
394 for (topshell=diashell;
395 XtIsTopLevelShell(topshell);
396 topshell=XtParent(topshell));
398 dpy=XtDisplay(diashell);
399 diawindow=XtWindow(diashell);
400 topwindow=XtWindow(topshell);
401 while (XGetWindowAttributes(dpy,diawindow,&xwa) &&
402 xwa.map_state != IsViewable && XEventsQueued(dpy,QueuedAlready))
404 XtAppProcessEvent(cxt, XtIMAll );
406 XmUpdateDisplay(topshell);
411 // Added this extra functionality
414 genDialogOKCallback( int *data )
420 genDialogCancelCallback( int *data )
426 genDialogOtherCallback( int *data )
430 // post_and_return takes a helpId, which is a string that is used to
431 // reference the related help in the Mailer help volume. The helpId
432 // is passed to post(), which will attach help to the help button in
435 DtMailGenDialog::post_and_return(char *helpId)
438 XmString okLabel, cancelLabel;
440 // They may have been set via the overloaded post_and_return()
441 // method before. Reset them to their default values...
443 okLabel = XmStringCreateLocalized(GETMSG(DT_catd, 1, 181, "OK"));
444 cancelLabel = XmStringCreateLocalized(GETMSG(DT_catd, 1, 182, "Cancel"));
446 // Make sure the dialog exists, and that it is an XmMessageBox
447 // or subclass, since the callbacks assume this widget type
449 assert ( _w != NULL );
452 XmNokLabelString, okLabel,
453 XmNcancelLabelString, cancelLabel,
455 XmStringFree( okLabel);
456 XmStringFree( cancelLabel);
461 this->post((void *) &answer,
462 ( DialogCallback ) &genDialogOKCallback,
463 ( DialogCallback ) &genDialogCancelCallback,
464 ( DialogCallback ) NULL,
465 ( DialogCallback ) &HelpErrorCB,
470 this->post((void *) &answer,
471 ( DialogCallback ) &genDialogOKCallback,
472 ( DialogCallback ) &genDialogCancelCallback,
473 ( DialogCallback ) NULL,
474 ( DialogCallback ) NULL,
479 forceUpdate( dialog );
482 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
485 // Process just one more event to pop down dialog.
486 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
492 // post_and_return(char *, char *) takes the string to be used for the
493 // OK button and the string that contains the helpId for the dialog being
494 // created, and passes them to post().
496 DtMailGenDialog::post_and_return(
504 okLabel = XmStringCreateLocalized(okLabelString);
506 // Make sure the dialog exists, and that it is an XmMessageBox
507 // or subclass, since the callbacks assume this widget type
509 assert ( _w != NULL );
512 XmNokLabelString, okLabel,
514 XmStringFree( okLabel);
518 dialog = this->post((void *) &answer,
519 ( DialogCallback ) &genDialogOKCallback,
520 ( DialogCallback ) NULL,
521 ( DialogCallback ) NULL,
522 ( DialogCallback ) &HelpErrorCB,
526 dialog = this->post((void *) &answer,
527 ( DialogCallback ) &genDialogOKCallback,
528 ( DialogCallback ) NULL,
529 ( DialogCallback ) NULL,
530 ( DialogCallback ) NULL,
535 forceUpdate( dialog );
538 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
541 // Process just one more event to pop down dialog.
542 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
548 // post_and_return(char*, char*, char*) takes the OK button label, Cancel
549 // button label, and the help id for the dialog and passes them to post().
551 DtMailGenDialog::post_and_return(
553 char *cancelLabelString,
558 XmString okLabel, cancelLabel;
560 okLabel = XmStringCreateLocalized(okLabelString);
561 cancelLabel = XmStringCreateLocalized(cancelLabelString);
563 // Make sure the dialog exists, and that it is an XmMessageBox
564 // or subclass, since the callbacks assume this widget type
566 assert ( _w != NULL );
569 XmNokLabelString, okLabel,
570 XmNcancelLabelString, cancelLabel,
572 XmStringFree( okLabel);
573 XmStringFree( cancelLabel);
575 Widget dialog = NULL;
577 dialog = this->post((void *) &answer,
578 ( DialogCallback ) &genDialogOKCallback,
579 ( DialogCallback ) &genDialogCancelCallback,
580 ( DialogCallback ) NULL,
581 ( DialogCallback ) &HelpErrorCB,
585 dialog = this->post((void *) &answer,
586 ( DialogCallback ) &genDialogOKCallback,
587 ( DialogCallback ) &genDialogCancelCallback,
588 ( DialogCallback ) NULL,
589 ( DialogCallback ) NULL,
594 forceUpdate( dialog );
597 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll);
600 // Process just one more event to pop down dialog.
601 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll);
608 DtMailGenDialog::post_and_return(
610 char *cancelLabelString,
611 char *otherLabelString,
616 XmString okLabel, cancelLabel, otherLabel;
618 okLabel = XmStringCreateLocalized(okLabelString);
619 cancelLabel = XmStringCreateLocalized(cancelLabelString);
620 otherLabel = XmStringCreateLocalized(otherLabelString);
623 // Make sure the dialog exists, and that it is an XmMessageBox
624 // or subclass, since the callbacks assume this widget type
626 assert ( _w != NULL );
628 Widget dialog = NULL;
629 Widget cancel_w = XmMessageBoxGetChild ( _w, XmDIALOG_CANCEL_BUTTON );
631 if (_otherWidget == NULL) {
632 _otherWidget = XtVaCreateWidget(otherLabelString,
633 xmPushButtonGadgetClass, _w,
634 XmNleftAttachment, XmMessageBoxGetChild ( _w,
635 XmDIALOG_OK_BUTTON ),
636 XmNrightAttachment, cancel_w,
638 XtManageChild (_otherWidget);
641 if (!XtIsManaged(_otherWidget)) {
642 XtManageChild (_otherWidget);
644 if (!XtIsManaged ( cancel_w ) ) {
645 XtManageChild ( cancel_w );
649 XmNokLabelString, okLabel,
650 XmNcancelLabelString, cancelLabel,
652 XtVaSetValues(_otherWidget,
653 XmNlabelString, otherLabel,
655 XmStringFree( okLabel);
656 XmStringFree( cancelLabel);
657 XmStringFree( otherLabel);
660 dialog = this->post((void *) &answer,
661 ( DialogCallback ) &genDialogOKCallback,
662 ( DialogCallback ) &genDialogCancelCallback,
663 ( DialogCallback ) &genDialogOtherCallback,
664 ( DialogCallback ) &HelpErrorCB,
669 this->post((void *) &answer,
670 ( DialogCallback ) &genDialogOKCallback,
671 ( DialogCallback ) &genDialogCancelCallback,
672 ( DialogCallback ) &genDialogOtherCallback,
673 ( DialogCallback ) NULL,
678 forceUpdate( dialog );
681 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
684 // Process just one more event to pop down dialog.
685 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
691 DtMailGenDialog::setDialog(char * title, char * text, unsigned char type)
693 XmString titleStr = XmStringCreateLocalized (title);
694 XmString xmStr = XmStringCreateLocalized(text);
696 XmNmessageString, xmStr,
697 XmNdialogTitle, titleStr,
701 XmStringFree ( titleStr );
706 DtMailGenDialog::getTextFieldValue()
708 if (_clearText) return strdup(_clearText);
713 DtMailGenDialog::setToTextFieldDialog(
719 if (NULL != _textField)
721 if (NULL != _clearText) *_clearText = '\0';
722 XtVaSetValues(_textField, XmNvalue, "", NULL);
723 XtManageChild(_textField);
727 _textField = XtVaCreateManagedWidget(
728 "GenDialogTF", xmTextFieldWidgetClass, _w,
733 XmNmodifyVerifyCallback,DtMailGenDialog::verifyCallback,
736 _clearText = (char*) malloc(_maxTextlen);
737 memset(_clearText, 0, _maxTextlen);
738 assert(NULL!=_clearText);
740 _shroudText = shroud;
741 setDialog(title, text, XmDIALOG_QUESTION);
745 DtMailGenDialog::setToQuestionDialog(
750 if (NULL != _textField && XtIsManaged(_textField))
751 XtUnmanageChild(_textField);
753 setDialog(title, text, XmDIALOG_QUESTION);
757 DtMailGenDialog::setToWarningDialog(
762 if (NULL != _textField && XtIsManaged(_textField))
763 XtUnmanageChild(_textField);
765 setDialog(title, text, XmDIALOG_WARNING);
769 DtMailGenDialog::setToErrorDialog(
774 if (NULL != _textField && XtIsManaged(_textField))
775 XtUnmanageChild(_textField);
777 setDialog(title, text, XmDIALOG_ERROR);
782 DtMailGenDialog::setToInfoDialog(
787 if (NULL != _textField && XtIsManaged(_textField))
788 XtUnmanageChild(_textField);
790 setDialog(title, text, XmDIALOG_INFORMATION);
792 #endif /* DEAD_WOOD */
794 extern "C" Pixmap _DtGetMask(Screen * screen, char * image_name);
797 DtMailGenDialog::setToAboutDialog(void)
800 setDialog((char *)"Credits",
802 XmDIALOG_INFORMATION);
806 if (NULL == ABOUT_TITLE) {
809 ABOUT_TITLE = GETMSG(DT_catd, 1, 235, "Mailer - About Mailer");
810 version = GETMSG(DT_catd, 1, 236, "Mailer Version %d.%d.%d");
812 DTMAIL_VERSION = new char [strlen(version) + 16];
814 DTMAIL_VERSION, version,
815 DtVERSION, DtREVISION, DtUPDATE_LEVEL);
817 setDialog((char *)ABOUT_TITLE,
818 (char *)DTMAIL_VERSION,
819 XmDIALOG_INFORMATION);
824 char * icon_filename = XmGetIconFileName(XtScreen(_w),
830 if (icon_filename == NULL) {
841 Pixmap icon = XmGetPixmap(XtScreen(_w),
845 Pixmap icon_mask = _DtGetMask(XtScreen(_w), icon_filename);
847 Pixmap clipped_icon = icon;
851 unsigned int width, height, border_width, depth;
852 XGetGeometry(XtDisplay(_w),
857 &border_width, &depth);
861 clipped_icon = XCreatePixmap(XtDisplay(_w),
869 memset(&gc_vals, 0, sizeof(gc_vals));
870 gc_vals.background = bg;
871 gc_vals.foreground = bg;
872 gc_vals.fill_style = FillSolid;
873 gc = XCreateGC(XtDisplay(_w),
875 GCForeground | GCBackground | GCFillStyle,
878 XFillRectangle(XtDisplay(_w),
884 XFreeGC(XtDisplay(_w), gc);
886 memset(&gc_vals, 0, sizeof(gc_vals));
887 gc_vals.background = bg;
888 gc = XCreateGC(XtDisplay(_w),
893 XSetClipMask(XtDisplay(_w), gc, icon_mask);
895 XCopyArea(XtDisplay(_w),
902 XFreeGC(XtDisplay(_w), gc);
906 XmNsymbolPixmap, clipped_icon,
909 if (NULL != _textField && XtIsManaged(_textField))
910 XtUnmanageChild(_textField);