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;
93 _parentshell = parent;
94 while (_parentshell && !XtIsShell(_parentshell))
95 _parentshell = XtParent(_parentshell);
100 DtMailGenDialog::post(void *clientData,
102 DialogCallback cancel,
103 DialogCallback other,
107 // _w is the MessageBox widget created in the constructor...
111 // Make sure the dialog exists, and that it is an XmMessageBox
112 // or subclass, since the callbacks assume this widget type
114 assert (dialog != NULL);
116 // Make sure the dialog buttons are managed
117 Widget ok_button = XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON);
118 Widget cancel_button = XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON);
119 Widget help_button = XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON);
121 // Create an object to carry the additional data needed
122 // to cache the dialogs.
124 DtMailDialogCallbackData *dcb = new DtMailDialogCallbackData(
125 (DtMailGenDialog *) this,
132 // Install callback function for each button
133 // support by Motif dialogs. If there is no help callback
134 // unmanage the corresponding button instead, if possible.
140 XmNokCallback, &DtMailGenDialog::okCallback,
142 if (!XtIsManaged(ok_button)) XtManageChild(ok_button);
144 else XtUnmanageChild(ok_button);
150 XmNcancelCallback, &DtMailGenDialog::cancelCallback,
152 if (!XtIsManaged(cancel_button)) XtManageChild(cancel_button);
154 else XtUnmanageChild(cancel_button);
161 XmNactivateCallback, &DtMailGenDialog::otherCallback,
164 else if (_otherWidget) XtUnmanageChild(_otherWidget);
171 XmNhelpCallback, &HelpErrorCB,
173 if (!XtIsManaged (help_button)) XtManageChild(help_button);
174 } else XtUnmanageChild(help_button);
177 // Make sure the parent dialog is popped up and occupying the
178 // current workspace.
180 if (NULL != _parentshell)
182 XtPopup(_parentshell, XtGrabNone);
183 displayInCurrentWorkspace(_parentshell);
187 XtManageChild(dialog);
189 if (NULL != _textField && XtIsManaged(_textField))
190 XmProcessTraversal(_textField, XmTRAVERSE_CURRENT);
195 DtMailGenDialog::okCallback(Widget w, XtPointer clientData, XtPointer cbs)
197 XmPushButtonCallbackStruct * pbcs = (XmPushButtonCallbackStruct *)cbs;
199 DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
200 DtMailGenDialog *obj = (DtMailGenDialog *) dcd->dialog();
201 DialogCallback callback;
203 // If caller specified an ok callback, call the function
205 if ((callback=dcd->ok()) != NULL) (*callback)(dcd->clientData());
207 // If the help widget was popped up, destroy it.
208 Widget helpWidget = getErrorHelpWidget();
211 XtUnmanageChild (helpWidget);
212 XtDestroyWidget (helpWidget);
213 clearErrorHelpWidget();
216 // Reset for the next time
218 Widget ow = dcd->other_w();
223 &DtMailGenDialog::otherCallback,
226 obj->cleanup(w, dcd);
228 if (obj->_info_dialog &&
229 (pbcs->event->xbutton.state & (ShiftMask | ControlMask)))
232 // Don't do credits for now
236 obj->setToAboutDialog();
237 // char * helpId = "About";
238 char * helpId = NULL;
239 int answer = obj->post_and_return(GETMSG(DT_catd, 1, 180, "OK"),
244 void DtMailGenDialog::cancelCallback(Widget w, XtPointer clientData, XtPointer)
246 DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
247 DtMailGenDialog *obj = (DtMailGenDialog *) dcd->dialog();
248 DialogCallback callback;
250 if ((callback=dcd->cancel()) != NULL) (*callback)(dcd->clientData());
252 // If the help widget was popped up, destroy it.
253 Widget helpWidget = getErrorHelpWidget();
256 XtUnmanageChild (helpWidget);
257 XtDestroyWidget (helpWidget);
258 clearErrorHelpWidget();
262 Widget ow = dcd->other_w();
264 XtRemoveCallback ( ow,
266 &DtMailGenDialog::otherCallback,
269 obj->cleanup(w, dcd);
272 void DtMailGenDialog::otherCallback(Widget w, XtPointer clientData, XtPointer)
274 DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
275 DtMailGenDialog *obj = (DtMailGenDialog *) dcd->dialog();
276 DialogCallback callback;
278 if ((callback=dcd->other()) != NULL) (*callback)(dcd->clientData());
283 &DtMailGenDialog::otherCallback,
286 Widget pw = XtParent(w);
287 obj->cleanup(pw, dcd);
290 void DtMailGenDialog::helpCallback(Widget, XtPointer clientData, XtPointer)
292 DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
293 DtMailGenDialog *obj = (DtMailGenDialog *) dcd->dialog();
294 DialogCallback callback;
296 if ((callback=dcd->help()) != NULL) (*callback)(dcd->clientData());
299 void DtMailGenDialog::verifyCallback(Widget, XtPointer clientD, XtPointer callD)
301 DtMailGenDialog *obj = (DtMailGenDialog*) clientD;
302 XmTextVerifyPtr cbs = (XmTextVerifyPtr) callD;
307 void DtMailGenDialog::verify(XmTextVerifyPtr cbs)
310 static char buffer[MAXPATHLEN];
311 register char *s, *t;
313 #if defined(SHROUDED_TEXTFIELD_DEBUG)
315 "currInsert=%d newInsert=%d startPos=%d endPos=%d\n",
316 cbs->currInsert,cbs->newInsert,cbs->startPos, cbs->endPos);
317 if (cbs->text->ptr) printf("text->ptr=%s\n", cbs->text->ptr);
318 printf("_clearText=%s\n", _clearText);
321 for (i=0, s=buffer, t=_clearText; (*t && i<cbs->startPos); i++, s++, t++)
326 strcpy(s, cbs->text->ptr);
327 s += cbs->text->length;
332 if (strlen(_clearText) >= cbs->endPos)
334 t = _clearText+cbs->endPos;
339 if (strlen(buffer) >= _maxTextlen)
342 _clearText = (char*) realloc((void*) _clearText, (size_t) _maxTextlen);
343 assert(NULL!=_clearText);
345 strcpy(_clearText, buffer);
347 if (_shroudText && cbs->text->ptr)
348 for (i=0, s=cbs->text->ptr; i<cbs->text->length; i++, s++)
351 #if defined(SHROUDED_TEXTFIELD_DEBUG)
352 printf("text=%s\n", _clearText);
357 void DtMailGenDialog::cleanup(Widget w, DtMailDialogCallbackData *dcd)
359 // Remove all callbacks to avoid having duplicate
360 // callback functions installed.
364 XmNokCallback, &DtMailGenDialog::okCallback,
369 XmNcancelCallback, &DtMailGenDialog::cancelCallback,
372 if (XtHasCallbacks(w, XmNhelpCallback) == XtCallbackHasSome)
373 XtRemoveAllCallbacks(w, XmNhelpCallback);
375 if (NULL != _textField && XtIsManaged(_textField))
376 XtUnmanageChild(_textField);
378 // Delete the DtMailDialogCallbackData instance for this posting
383 DtMailGenDialog::forceUpdate( Widget w )
385 Widget diashell, topshell;
386 Window diawindow, topwindow;
389 XWindowAttributes xwa;
393 XtAppContext cxt=XtWidgetToApplicationContext( w );
394 for (diashell=w;!XtIsShell(diashell);diashell=XtParent(diashell));
395 for (topshell=diashell;
396 XtIsTopLevelShell(topshell);
397 topshell=XtParent(topshell));
399 dpy=XtDisplay(diashell);
400 diawindow=XtWindow(diashell);
401 topwindow=XtWindow(topshell);
402 while (XGetWindowAttributes(dpy,diawindow,&xwa) &&
403 xwa.map_state != IsViewable && XEventsQueued(dpy,QueuedAlready))
405 XtAppProcessEvent(cxt, XtIMAll );
407 XmUpdateDisplay(topshell);
412 // Added this extra functionality
415 genDialogOKCallback( int *data )
421 genDialogCancelCallback( int *data )
427 genDialogOtherCallback( int *data )
431 // post_and_return takes a helpId, which is a string that is used to
432 // reference the related help in the Mailer help volume. The helpId
433 // is passed to post(), which will attach help to the help button in
436 DtMailGenDialog::post_and_return(char *helpId)
439 XmString okLabel, cancelLabel;
441 // They may have been set via the overloaded post_and_return()
442 // method before. Reset them to their default values...
444 okLabel = XmStringCreateLocalized(GETMSG(DT_catd, 1, 181, "OK"));
445 cancelLabel = XmStringCreateLocalized(GETMSG(DT_catd, 1, 182, "Cancel"));
447 // Make sure the dialog exists, and that it is an XmMessageBox
448 // or subclass, since the callbacks assume this widget type
450 assert ( _w != NULL );
453 XmNokLabelString, okLabel,
454 XmNcancelLabelString, cancelLabel,
456 XmStringFree( okLabel);
457 XmStringFree( cancelLabel);
462 this->post((void *) &answer,
463 ( DialogCallback ) &genDialogOKCallback,
464 ( DialogCallback ) &genDialogCancelCallback,
465 ( DialogCallback ) NULL,
466 ( DialogCallback ) &HelpErrorCB,
471 this->post((void *) &answer,
472 ( DialogCallback ) &genDialogOKCallback,
473 ( DialogCallback ) &genDialogCancelCallback,
474 ( DialogCallback ) NULL,
475 ( DialogCallback ) NULL,
480 forceUpdate( dialog );
483 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
486 // Process just one more event to pop down dialog.
487 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
493 // post_and_return(char *, char *) takes the string to be used for the
494 // OK button and the string that contains the helpId for the dialog being
495 // created, and passes them to post().
497 DtMailGenDialog::post_and_return(
505 okLabel = XmStringCreateLocalized(okLabelString);
507 // Make sure the dialog exists, and that it is an XmMessageBox
508 // or subclass, since the callbacks assume this widget type
510 assert ( _w != NULL );
513 XmNokLabelString, okLabel,
515 XmStringFree( okLabel);
519 dialog = this->post((void *) &answer,
520 ( DialogCallback ) &genDialogOKCallback,
521 ( DialogCallback ) NULL,
522 ( DialogCallback ) NULL,
523 ( DialogCallback ) &HelpErrorCB,
527 dialog = this->post((void *) &answer,
528 ( DialogCallback ) &genDialogOKCallback,
529 ( DialogCallback ) NULL,
530 ( DialogCallback ) NULL,
531 ( DialogCallback ) NULL,
536 forceUpdate( dialog );
539 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
542 // Process just one more event to pop down dialog.
543 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
549 // post_and_return(char*, char*, char*) takes the OK button label, Cancel
550 // button label, and the help id for the dialog and passes them to post().
552 DtMailGenDialog::post_and_return(
554 char *cancelLabelString,
559 XmString okLabel, cancelLabel;
561 okLabel = XmStringCreateLocalized(okLabelString);
562 cancelLabel = XmStringCreateLocalized(cancelLabelString);
564 // Make sure the dialog exists, and that it is an XmMessageBox
565 // or subclass, since the callbacks assume this widget type
567 assert ( _w != NULL );
570 XmNokLabelString, okLabel,
571 XmNcancelLabelString, cancelLabel,
573 XmStringFree( okLabel);
574 XmStringFree( cancelLabel);
576 Widget dialog = NULL;
578 dialog = this->post((void *) &answer,
579 ( DialogCallback ) &genDialogOKCallback,
580 ( DialogCallback ) &genDialogCancelCallback,
581 ( DialogCallback ) NULL,
582 ( DialogCallback ) &HelpErrorCB,
586 dialog = this->post((void *) &answer,
587 ( DialogCallback ) &genDialogOKCallback,
588 ( DialogCallback ) &genDialogCancelCallback,
589 ( DialogCallback ) NULL,
590 ( DialogCallback ) NULL,
595 forceUpdate( dialog );
598 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll);
601 // Process just one more event to pop down dialog.
602 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll);
609 DtMailGenDialog::post_and_return(
611 char *cancelLabelString,
612 char *otherLabelString,
617 XmString okLabel, cancelLabel, otherLabel;
619 okLabel = XmStringCreateLocalized(okLabelString);
620 cancelLabel = XmStringCreateLocalized(cancelLabelString);
621 otherLabel = XmStringCreateLocalized(otherLabelString);
624 // Make sure the dialog exists, and that it is an XmMessageBox
625 // or subclass, since the callbacks assume this widget type
627 assert ( _w != NULL );
629 Widget dialog = NULL;
630 Widget cancel_w = XmMessageBoxGetChild ( _w, XmDIALOG_CANCEL_BUTTON );
632 if (_otherWidget == NULL) {
633 _otherWidget = XtVaCreateWidget(otherLabelString,
634 xmPushButtonGadgetClass, _w,
635 XmNleftAttachment, XmMessageBoxGetChild ( _w,
636 XmDIALOG_OK_BUTTON ),
637 XmNrightAttachment, cancel_w,
639 XtManageChild (_otherWidget);
642 if (!XtIsManaged(_otherWidget)) {
643 XtManageChild (_otherWidget);
645 if (!XtIsManaged ( cancel_w ) ) {
646 XtManageChild ( cancel_w );
650 XmNokLabelString, okLabel,
651 XmNcancelLabelString, cancelLabel,
653 XtVaSetValues(_otherWidget,
654 XmNlabelString, otherLabel,
656 XmStringFree( okLabel);
657 XmStringFree( cancelLabel);
658 XmStringFree( otherLabel);
661 dialog = this->post((void *) &answer,
662 ( DialogCallback ) &genDialogOKCallback,
663 ( DialogCallback ) &genDialogCancelCallback,
664 ( DialogCallback ) &genDialogOtherCallback,
665 ( DialogCallback ) &HelpErrorCB,
670 this->post((void *) &answer,
671 ( DialogCallback ) &genDialogOKCallback,
672 ( DialogCallback ) &genDialogCancelCallback,
673 ( DialogCallback ) &genDialogOtherCallback,
674 ( DialogCallback ) NULL,
679 forceUpdate( dialog );
682 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
685 // Process just one more event to pop down dialog.
686 XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
692 DtMailGenDialog::setDialog(char * title, char * text, unsigned char type)
694 XmString titleStr = XmStringCreateLocalized (title);
695 XmString xmStr = XmStringCreateLocalized(text);
697 XmNmessageString, xmStr,
698 XmNdialogTitle, titleStr,
702 XmStringFree ( titleStr );
707 DtMailGenDialog::getTextFieldValue()
709 if (_clearText) return strdup(_clearText);
714 DtMailGenDialog::setToTextFieldDialog(
720 if (NULL != _textField)
722 if (NULL != _clearText) *_clearText = '\0';
723 XtVaSetValues(_textField, XmNvalue, "", NULL);
724 XtManageChild(_textField);
728 _textField = XtVaCreateManagedWidget(
729 "GenDialogTF", xmTextFieldWidgetClass, _w,
734 XmNmodifyVerifyCallback,DtMailGenDialog::verifyCallback,
737 _clearText = (char*) malloc(_maxTextlen);
738 memset(_clearText, 0, _maxTextlen);
739 assert(NULL!=_clearText);
741 _shroudText = shroud;
742 setDialog(title, text, XmDIALOG_QUESTION);
746 DtMailGenDialog::setToQuestionDialog(
751 if (NULL != _textField && XtIsManaged(_textField))
752 XtUnmanageChild(_textField);
754 setDialog(title, text, XmDIALOG_QUESTION);
758 DtMailGenDialog::setToWarningDialog(
763 if (NULL != _textField && XtIsManaged(_textField))
764 XtUnmanageChild(_textField);
766 setDialog(title, text, XmDIALOG_WARNING);
770 DtMailGenDialog::setToErrorDialog(
775 if (NULL != _textField && XtIsManaged(_textField))
776 XtUnmanageChild(_textField);
778 setDialog(title, text, XmDIALOG_ERROR);
783 DtMailGenDialog::setToInfoDialog(
788 if (NULL != _textField && XtIsManaged(_textField))
789 XtUnmanageChild(_textField);
791 setDialog(title, text, XmDIALOG_INFORMATION);
793 #endif /* DEAD_WOOD */
795 extern "C" Pixmap _DtGetMask(Screen * screen, char * image_name);
798 DtMailGenDialog::setToAboutDialog(void)
801 setDialog((char *)"Credits",
803 XmDIALOG_INFORMATION);
807 if (NULL == ABOUT_TITLE) {
810 ABOUT_TITLE = GETMSG(DT_catd, 1, 235, "Mailer - About Mailer");
811 version = GETMSG(DT_catd, 1, 236, "Mailer Version %d.%d.%d");
813 DTMAIL_VERSION = new char [strlen(version) + 16];
815 DTMAIL_VERSION, version,
816 DtVERSION, DtREVISION, DtUPDATE_LEVEL);
818 setDialog((char *)ABOUT_TITLE,
819 (char *)DTMAIL_VERSION,
820 XmDIALOG_INFORMATION);
825 char * icon_filename = XmGetIconFileName(XtScreen(_w),
831 if (icon_filename == NULL) {
842 Pixmap icon = XmGetPixmap(XtScreen(_w),
846 Pixmap icon_mask = _DtGetMask(XtScreen(_w), icon_filename);
848 Pixmap clipped_icon = icon;
852 unsigned int width, height, border_width, depth;
853 XGetGeometry(XtDisplay(_w),
858 &border_width, &depth);
862 clipped_icon = XCreatePixmap(XtDisplay(_w),
870 memset(&gc_vals, 0, sizeof(gc_vals));
871 gc_vals.background = bg;
872 gc_vals.foreground = bg;
873 gc_vals.fill_style = FillSolid;
874 gc = XCreateGC(XtDisplay(_w),
876 GCForeground | GCBackground | GCFillStyle,
879 XFillRectangle(XtDisplay(_w),
885 XFreeGC(XtDisplay(_w), gc);
887 memset(&gc_vals, 0, sizeof(gc_vals));
888 gc_vals.background = bg;
889 gc = XCreateGC(XtDisplay(_w),
894 XSetClipMask(XtDisplay(_w), gc, icon_mask);
896 XCopyArea(XtDisplay(_w),
903 XFreeGC(XtDisplay(_w), gc);
907 XmNsymbolPixmap, clipped_icon,
910 if (NULL != _textField && XtIsManaged(_textField))
911 XtUnmanageChild(_textField);