Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtmail / dtmail / DtMailGenDialog.C
1 /* $TOG: DtMailGenDialog.C /main/15 1999/07/07 15:08:18 mgreess $ */
2 /*
3  *+SNOTICE
4  *
5  *      $TOG: DtMailGenDialog.C /main/15 1999/07/07 15:08:18 mgreess $
6  *
7  *      RESTRICTED CONFIDENTIAL INFORMATION:
8  *      
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
15  *      Sun's request.
16  *
17  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
18  *
19  *+ENOTICE
20  */
21 //////////////////////////////////////////////////////////
22 // DtMailGenDialog.C: Generic dialog based on MessageBox
23 //////////////////////////////////////////////////////////
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <sys/param.h>
27 #include <assert.h>
28
29 #include <Dt/Dt.h>
30 #include <Dt/Icon.h>
31 #include <Dt/IconP.h>
32 #include <Dt/IconFile.h>
33 #include <Xm/MessageB.h>
34 #include <Xm/PushBG.h>
35 #include <Xm/MwmUtil.h>
36
37 #include "Application.h"
38 #include "DtMailGenDialog.hh"
39 #include "DtMailHelp.hh"
40 #include "Help.hh"
41 #include "MailMsg.h"
42
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;
47
48 DtMailGenDialog::DtMailGenDialog(char *name, Widget parent, int style)
49 : UIComponent(name)
50 {
51     
52     _w = XmCreateMessageDialog(parent, name, NULL, 0);
53     XtVaSetValues(_w, XmNdialogStyle, style, NULL);
54
55     // Disable the frame menu from all dialogs.  We don't want 
56     // the user to be able to dismiss dialogs through the frame
57     // menu.
58     //
59     XtVaSetValues(
60                 XtParent(_w),
61                 XmNmwmDecorations, MWM_DECOR_ALL | MWM_DECOR_MENU,
62                 NULL);
63
64     _info_dialog = 0;
65     _otherWidget = (Widget) NULL;
66     _textField = (Widget) NULL;
67     _maxTextlen = 0;
68     _clearText = NULL;
69
70     _parentshell = parent;
71     while (_parentshell && !XtIsShell(_parentshell))
72       _parentshell = XtParent(_parentshell);
73 }
74
75  
76 Widget 
77 DtMailGenDialog::post(void *clientData,
78                       DialogCallback ok,
79                       DialogCallback cancel,
80                       DialogCallback other,
81                       DialogCallback help,
82                       char *helpId)
83 {
84     // _w is the MessageBox widget created in the constructor...
85
86     Widget dialog = _w;
87     
88     // Make sure the dialog exists, and that it is an XmMessageBox
89     // or subclass, since the callbacks assume this widget type
90     
91     assert (dialog != NULL);
92
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);
97         
98     // Create an object to carry the additional data needed
99     // to cache the dialogs.
100     
101     DtMailDialogCallbackData *dcb = new DtMailDialogCallbackData( 
102                                                 (DtMailGenDialog *) this, 
103                                                 clientData,
104                                                 ok, 
105                                                 cancel, 
106                                                 other, 
107                                                 help, 
108                                                 _otherWidget);
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.
112
113     if ( ok )
114     {
115         XtAddCallback(
116                 dialog,
117                 XmNokCallback, &DtMailGenDialog::okCallback,
118                 (XtPointer) dcb);
119         if (!XtIsManaged(ok_button)) XtManageChild(ok_button);
120     }
121     else XtUnmanageChild(ok_button);
122
123     if (cancel)
124     {
125         XtAddCallback(
126                 dialog, 
127                 XmNcancelCallback, &DtMailGenDialog::cancelCallback,
128                 (XtPointer) dcb);
129         if (!XtIsManaged(cancel_button)) XtManageChild(cancel_button);
130     }
131     else XtUnmanageChild(cancel_button);
132
133
134     if (other)
135     {
136         XtAddCallback(
137                 _otherWidget,
138                 XmNactivateCallback, &DtMailGenDialog::otherCallback,
139                 (XtPointer) dcb);
140     }
141     else if (_otherWidget) XtUnmanageChild(_otherWidget);
142
143
144     if (help)
145     {
146         XtAddCallback(
147                 dialog,
148                 XmNhelpCallback, &HelpErrorCB,
149                 (XtPointer) helpId);
150         if (!XtIsManaged (help_button)) XtManageChild(help_button);
151     } else XtUnmanageChild(help_button);
152
153     //
154     // Make sure the parent dialog is popped up and occupying the
155     // current workspace.
156     //
157     if (NULL != _parentshell)
158     {
159         XtPopup(_parentshell, XtGrabNone);
160         displayInCurrentWorkspace(_parentshell);
161     }
162
163     // Post the dialog.
164     XtManageChild(dialog);
165
166     if (NULL != _textField && XtIsManaged(_textField))
167       XmProcessTraversal(_textField, XmTRAVERSE_CURRENT);
168     return dialog;
169 }
170
171 void 
172 DtMailGenDialog::okCallback(Widget w, XtPointer clientData, XtPointer cbs)
173 {
174     XmPushButtonCallbackStruct * pbcs = (XmPushButtonCallbackStruct *)cbs;
175
176     DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
177     DtMailGenDialog      *obj = (DtMailGenDialog *) dcd->dialog();
178     DialogCallback      callback;
179     
180     // If caller specified an ok callback, call the function
181     
182     if ((callback=dcd->ok()) != NULL) (*callback)(dcd->clientData());
183
184     // If the help widget was popped up, destroy it.
185     Widget helpWidget = getErrorHelpWidget();
186     if (helpWidget)
187     {
188         XtUnmanageChild (helpWidget);
189         XtDestroyWidget (helpWidget);
190         clearErrorHelpWidget();
191     }
192
193     // Reset for the next time
194     
195     Widget ow = dcd->other_w();
196     if (ow != NULL)
197         XtRemoveCallback(
198                         ow, 
199                         XmNactivateCallback, 
200                         &DtMailGenDialog::otherCallback,
201                         (XtPointer) dcd);
202
203     obj->cleanup(w, dcd);
204
205     if (obj->_info_dialog &&
206         (pbcs->event->xbutton.state & (ShiftMask | ControlMask)))
207     {
208 #ifdef NEVER
209         // Don't do credits for now
210         doCredits = 1;
211 #endif
212         doCredits = 0;
213         obj->setToAboutDialog();
214         // char * helpId = "About";
215         char * helpId = NULL;
216         int answer = obj->post_and_return(GETMSG(DT_catd, 1, 180, "OK"),
217                                           helpId);
218     }
219 }
220
221 void DtMailGenDialog::cancelCallback(Widget w, XtPointer clientData, XtPointer)
222 {
223     DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
224     DtMailGenDialog      *obj = (DtMailGenDialog *) dcd->dialog();
225     DialogCallback      callback;
226     
227     if ((callback=dcd->cancel()) != NULL) (*callback)(dcd->clientData());
228     
229     // If the help widget was popped up, destroy it.
230     Widget helpWidget = getErrorHelpWidget();
231     if (helpWidget)
232     {
233         XtUnmanageChild (helpWidget);
234         XtDestroyWidget (helpWidget);
235         clearErrorHelpWidget();
236     }
237
238
239     Widget ow = dcd->other_w();
240     if (ow != NULL)
241         XtRemoveCallback ( ow, 
242                       XmNactivateCallback, 
243                       &DtMailGenDialog::otherCallback,
244                       (XtPointer) dcd );
245
246     obj->cleanup(w, dcd);
247 }
248
249 void DtMailGenDialog::otherCallback(Widget w, XtPointer clientData, XtPointer)
250 {
251     DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
252     DtMailGenDialog      *obj = (DtMailGenDialog *) dcd->dialog();
253     DialogCallback      callback;
254     
255     if ((callback=dcd->other()) != NULL) (*callback)(dcd->clientData());
256
257     XtRemoveCallback(
258                 w, 
259                 XmNactivateCallback, 
260                 &DtMailGenDialog::otherCallback,
261                 (XtPointer) dcd);
262     
263     Widget pw = XtParent(w);
264     obj->cleanup(pw, dcd);
265 }
266
267 void DtMailGenDialog::helpCallback(Widget, XtPointer clientData, XtPointer)
268 {
269     DtMailDialogCallbackData *dcd = (DtMailDialogCallbackData *) clientData;
270     DtMailGenDialog      *obj = (DtMailGenDialog *) dcd->dialog();
271     DialogCallback      callback;
272
273     if ((callback=dcd->help()) != NULL) (*callback)(dcd->clientData());
274 }
275
276 void DtMailGenDialog::verifyCallback(Widget, XtPointer clientD, XtPointer callD)
277 {
278     DtMailGenDialog     *obj = (DtMailGenDialog*) clientD;
279     XmTextVerifyPtr     cbs = (XmTextVerifyPtr) callD;
280
281     obj->verify(cbs);
282 }
283
284 void DtMailGenDialog::verify(XmTextVerifyPtr cbs)
285 {
286     int                 i;
287     static char         buffer[MAXPATHLEN];
288     register char       *s, *t;
289
290 #if defined(SHROUDED_TEXTFIELD_DEBUG)
291     printf(
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);
296 #endif
297
298     for (i=0, s=buffer, t=_clearText; (*t && i<cbs->startPos); i++, s++, t++)
299       *s = *t;
300
301     if (cbs->text->ptr)
302     {
303         strcpy(s, cbs->text->ptr);
304         s += cbs->text->length;
305     }
306     else
307       *s = '\0';
308
309     if (strlen(_clearText) >= cbs->endPos)
310     {
311         t = _clearText+cbs->endPos;
312         if (strlen(t))
313           strcpy(s, t);
314     }
315
316     if (strlen(buffer) >= _maxTextlen)
317     {
318         _maxTextlen *= 2;
319         _clearText = (char*) realloc((void*) _clearText, (size_t) _maxTextlen);
320         assert(NULL!=_clearText);
321     }
322     strcpy(_clearText, buffer);
323
324     if (_shroudText && cbs->text->ptr)
325       for (i=0, s=cbs->text->ptr; i<cbs->text->length; i++, s++)
326         *s = '*';
327
328 #if defined(SHROUDED_TEXTFIELD_DEBUG)
329     printf("text=%s\n", _clearText);
330 #endif
331 }
332
333
334 void DtMailGenDialog::cleanup(Widget w, DtMailDialogCallbackData *dcd)
335 {
336     // Remove all callbacks to avoid having duplicate 
337     // callback functions installed.
338     
339     XtRemoveCallback(
340                 w,
341                 XmNokCallback, &DtMailGenDialog::okCallback,
342                 (XtPointer) dcd );
343     
344     XtRemoveCallback(
345                 w, 
346                 XmNcancelCallback, &DtMailGenDialog::cancelCallback,
347                 (XtPointer) dcd);
348    
349     if (XtHasCallbacks(w, XmNhelpCallback) == XtCallbackHasSome)
350       XtRemoveAllCallbacks(w, XmNhelpCallback);
351     
352     if (NULL != _textField && XtIsManaged(_textField))
353       XtUnmanageChild(_textField);
354     
355     // Delete the DtMailDialogCallbackData instance for this posting
356     delete dcd;
357 }
358
359 void
360 DtMailGenDialog::forceUpdate( Widget w )
361 {
362     Widget diashell, topshell;
363     Window diawindow, topwindow;
364
365     Display             *dpy;
366     XWindowAttributes   xwa;
367
368     if (!w) return;
369
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));
375
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))
381     {
382         XtAppProcessEvent(cxt, XtIMAll );
383     }
384     XmUpdateDisplay(topshell);
385 }
386
387
388
389 // Added this extra functionality
390
391 void
392 genDialogOKCallback( int *data )
393 {
394     *data=1;
395 }
396
397 void
398 genDialogCancelCallback( int *data )
399 {
400     *data=2;
401 }
402
403 void
404 genDialogOtherCallback( int *data )
405 {
406     *data=3;
407 }
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
411 // the dialog.
412 int
413 DtMailGenDialog::post_and_return(char *helpId)
414 {
415     int answer = 0;
416     XmString okLabel, cancelLabel;
417
418     // They may have been set via the overloaded post_and_return()
419     // method before. Reset them to their default values...
420
421     okLabel = XmStringCreateLocalized(GETMSG(DT_catd, 1, 181, "OK"));
422     cancelLabel = XmStringCreateLocalized(GETMSG(DT_catd, 1, 182, "Cancel"));
423
424     // Make sure the dialog exists, and that it is an XmMessageBox
425     // or subclass, since the callbacks assume this widget type
426     
427     assert ( _w != NULL );
428
429     XtVaSetValues(_w,
430                   XmNokLabelString, okLabel,
431                   XmNcancelLabelString, cancelLabel,
432                   NULL);
433     XmStringFree( okLabel);
434     XmStringFree( cancelLabel);
435
436     Widget dialog;
437     if (helpId) {
438         dialog =
439             this->post((void *) &answer,
440                    ( DialogCallback ) &genDialogOKCallback,
441                    ( DialogCallback ) &genDialogCancelCallback,
442                    ( DialogCallback ) NULL,
443                    ( DialogCallback ) &HelpErrorCB,
444                    helpId
445                    );
446     } else {
447         dialog =
448             this->post((void *) &answer,
449                    ( DialogCallback ) &genDialogOKCallback,
450                    ( DialogCallback ) &genDialogCancelCallback,
451                    ( DialogCallback ) NULL,
452                    ( DialogCallback ) NULL,
453                    NULL
454                    );
455     }
456
457     forceUpdate( dialog );
458     while ( answer==0 ) 
459     {
460         XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
461     }
462
463     // Process just one more event to pop down dialog.
464     XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
465
466     return(answer);
467
468 }
469
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().
473 int
474 DtMailGenDialog::post_and_return(
475         char *okLabelString,
476         char *helpId
477 )
478 {
479     int answer = 0;
480     XmString okLabel;
481
482     okLabel = XmStringCreateLocalized(okLabelString);
483
484     // Make sure the dialog exists, and that it is an XmMessageBox
485     // or subclass, since the callbacks assume this widget type
486     
487     assert ( _w != NULL );
488
489     XtVaSetValues(_w,
490                   XmNokLabelString, okLabel,
491                   NULL);
492     XmStringFree( okLabel);
493
494     Widget dialog;
495     if (helpId) {
496         dialog = this->post((void *) &answer,
497                                ( DialogCallback ) &genDialogOKCallback,
498                                ( DialogCallback ) NULL,
499                                ( DialogCallback ) NULL,
500                                ( DialogCallback ) &HelpErrorCB,
501                                helpId
502                                );
503     } else {
504         dialog = this->post((void *) &answer,
505                                ( DialogCallback ) &genDialogOKCallback,
506                                ( DialogCallback ) NULL,
507                                ( DialogCallback ) NULL,
508                                ( DialogCallback ) NULL,
509                                NULL
510                                );
511     }
512
513     forceUpdate( dialog );
514     while ( answer==0 ) 
515     {
516         XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
517     }
518
519     // Process just one more event to pop down dialog.
520     XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
521
522     return(answer);
523
524 }
525
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().
528 int
529 DtMailGenDialog::post_and_return(
530         char *okLabelString,
531         char *cancelLabelString,
532         char *helpId
533 )
534 {
535     int answer = 0;
536     XmString okLabel, cancelLabel;
537
538     okLabel = XmStringCreateLocalized(okLabelString);
539     cancelLabel = XmStringCreateLocalized(cancelLabelString);
540
541     // Make sure the dialog exists, and that it is an XmMessageBox
542     // or subclass, since the callbacks assume this widget type
543     
544     assert ( _w != NULL );
545
546     XtVaSetValues(_w,
547                   XmNokLabelString, okLabel,
548                   XmNcancelLabelString, cancelLabel,
549                   NULL);
550     XmStringFree( okLabel);
551     XmStringFree( cancelLabel);
552
553     Widget dialog = NULL;
554     if (helpId) {
555         dialog = this->post((void *) &answer,
556                                ( DialogCallback ) &genDialogOKCallback,
557                                ( DialogCallback ) &genDialogCancelCallback,
558                                ( DialogCallback ) NULL,
559                                ( DialogCallback ) &HelpErrorCB,
560                                helpId
561                                );
562     } else {
563         dialog = this->post((void *) &answer,
564                                ( DialogCallback ) &genDialogOKCallback,
565                                ( DialogCallback ) &genDialogCancelCallback,
566                                ( DialogCallback ) NULL,
567                                ( DialogCallback ) NULL,
568                                NULL
569                                );
570     }
571
572     forceUpdate( dialog );
573     while ( answer==0 ) 
574     {
575         XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll);
576     }
577
578     // Process just one more event to pop down dialog.
579     XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll);
580
581     return(answer);
582
583 }
584
585 int
586 DtMailGenDialog::post_and_return(
587         char *okLabelString,
588         char *cancelLabelString,
589         char *otherLabelString,
590         char *helpId
591 )
592 {
593     int answer = 0;
594     XmString okLabel, cancelLabel, otherLabel;
595
596     okLabel = XmStringCreateLocalized(okLabelString);
597     cancelLabel = XmStringCreateLocalized(cancelLabelString);
598     otherLabel = XmStringCreateLocalized(otherLabelString);
599
600
601     // Make sure the dialog exists, and that it is an XmMessageBox
602     // or subclass, since the callbacks assume this widget type
603     
604     assert ( _w != NULL );
605
606     Widget dialog = NULL;
607     Widget cancel_w = XmMessageBoxGetChild ( _w, XmDIALOG_CANCEL_BUTTON );
608
609     if (_otherWidget == NULL) {
610         _otherWidget = XtVaCreateWidget(otherLabelString,
611                                 xmPushButtonGadgetClass, _w,
612                                 XmNleftAttachment, XmMessageBoxGetChild ( _w,
613                                           XmDIALOG_OK_BUTTON ),
614                                 XmNrightAttachment, cancel_w,
615                                 NULL);
616         XtManageChild (_otherWidget);
617     }
618
619     if (!XtIsManaged(_otherWidget)) {
620         XtManageChild (_otherWidget);
621     }
622     if (!XtIsManaged ( cancel_w ) ) {
623         XtManageChild ( cancel_w );
624     }
625
626     XtVaSetValues(_w,
627                   XmNokLabelString, okLabel,
628                   XmNcancelLabelString, cancelLabel,
629                   NULL);
630     XtVaSetValues(_otherWidget,
631                   XmNlabelString, otherLabel,
632                   NULL);
633     XmStringFree( okLabel);
634     XmStringFree( cancelLabel);
635     XmStringFree( otherLabel);
636
637     if (helpId) {
638         dialog = this->post((void *) &answer,
639                    ( DialogCallback ) &genDialogOKCallback,
640                    ( DialogCallback ) &genDialogCancelCallback,
641                    ( DialogCallback ) &genDialogOtherCallback,
642                    ( DialogCallback ) &HelpErrorCB,
643                    helpId
644                    );
645     } else {
646         dialog =
647             this->post((void *) &answer,
648                    ( DialogCallback ) &genDialogOKCallback,
649                    ( DialogCallback ) &genDialogCancelCallback,
650                    ( DialogCallback ) &genDialogOtherCallback,
651                    ( DialogCallback ) NULL,
652                    NULL
653                    );
654     }
655
656     forceUpdate( dialog );
657     while ( answer==0 ) 
658     {
659         XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
660     }
661
662     // Process just one more event to pop down dialog.
663     XtAppProcessEvent(XtWidgetToApplicationContext(dialog), XtIMAll );
664
665     return(answer);
666
667 }
668 void
669 DtMailGenDialog::setDialog(char * title, char * text, unsigned char type)
670 {
671     XmString titleStr = XmStringCreateLocalized (title);
672     XmString xmStr = XmStringCreateLocalized(text);
673     XtVaSetValues ( _w,
674                     XmNmessageString, xmStr,
675                     XmNdialogTitle, titleStr,
676                     XmNdialogType,  type,
677                     NULL );
678     XmStringFree(xmStr);
679     XmStringFree ( titleStr );
680     _info_dialog = 0;
681 }
682
683 char *
684 DtMailGenDialog::getTextFieldValue()
685 {
686     if (_clearText) return strdup(_clearText);
687     return NULL;
688 }
689
690 void
691 DtMailGenDialog::setToTextFieldDialog(
692     char *title,
693     char *text,
694     int   shroud
695 )
696 {
697     if (NULL != _textField)
698     {
699         if (NULL != _clearText) *_clearText = '\0';
700         XtVaSetValues(_textField, XmNvalue, "", NULL);
701         XtManageChild(_textField);
702     }
703     else
704     {
705         _textField = XtVaCreateManagedWidget(
706                         "GenDialogTF", xmTextFieldWidgetClass, _w,
707                         XmNcolumns, 30,
708                         NULL);
709         XtAddCallback(
710                         _textField,
711                         XmNmodifyVerifyCallback,DtMailGenDialog::verifyCallback,
712                         this);
713         _maxTextlen = 256;
714         _clearText = (char*) malloc(_maxTextlen);
715         memset(_clearText, 0, _maxTextlen);
716         assert(NULL!=_clearText);
717     }
718     _shroudText = shroud;
719     setDialog(title, text, XmDIALOG_QUESTION);
720 }
721
722 void
723 DtMailGenDialog::setToQuestionDialog(
724     char *title,
725     char *text
726 )
727 {
728     if (NULL != _textField && XtIsManaged(_textField))
729       XtUnmanageChild(_textField);
730     
731     setDialog(title, text, XmDIALOG_QUESTION);
732 }
733
734 void
735 DtMailGenDialog::setToWarningDialog(
736     char *title,
737     char *text
738 )
739 {
740     if (NULL != _textField && XtIsManaged(_textField))
741       XtUnmanageChild(_textField);
742     
743     setDialog(title, text, XmDIALOG_WARNING);
744 }
745
746 void
747 DtMailGenDialog::setToErrorDialog(
748     char *title,
749     char *text
750 )
751 {
752     if (NULL != _textField && XtIsManaged(_textField))
753       XtUnmanageChild(_textField);
754     
755     setDialog(title, text, XmDIALOG_ERROR);
756 }
757
758 #ifdef DEAD_WOOD
759 void
760 DtMailGenDialog::setToInfoDialog(
761     char *title,
762     char *text
763 )
764 {
765     if (NULL != _textField && XtIsManaged(_textField))
766       XtUnmanageChild(_textField);
767     
768     setDialog(title, text, XmDIALOG_INFORMATION);
769 }
770 #endif /* DEAD_WOOD */
771
772 extern "C" Pixmap _DtGetMask(Screen * screen, char * image_name);
773
774 void
775 DtMailGenDialog::setToAboutDialog(void)
776 {
777     if (doCredits) {
778         setDialog((char *)"Credits",
779                   (char *)credits,
780                   XmDIALOG_INFORMATION);
781         doCredits = 0;
782     }
783     else {
784         if (NULL == ABOUT_TITLE) {
785             char *version;
786
787             ABOUT_TITLE = GETMSG(DT_catd, 1, 235, "Mailer - About Mailer");
788             version = GETMSG(DT_catd, 1, 236, "Mailer Version %d.%d.%d");
789
790             DTMAIL_VERSION = new char [strlen(version) + 16];
791             sprintf(
792                 DTMAIL_VERSION, version,
793                 DtVERSION, DtREVISION, DtUPDATE_LEVEL);
794         }
795         setDialog((char *)ABOUT_TITLE,
796                   (char *)DTMAIL_VERSION,
797                   XmDIALOG_INFORMATION);
798     }
799
800     _info_dialog = 1;
801
802     char * icon_filename = XmGetIconFileName(XtScreen(_w),
803                                              NULL,
804                                              "DtMail",
805                                              NULL,
806                                              DtLARGE);
807
808     if (icon_filename == NULL) {
809         return;
810     }
811
812     Pixmap fg, bg;
813
814     XtVaGetValues (_w,
815                    XmNforeground, &fg,
816                    XmNbackground, &bg,
817                    NULL);
818
819     Pixmap icon = XmGetPixmap(XtScreen(_w),
820                               icon_filename,
821                               fg, bg);
822
823     Pixmap icon_mask = _DtGetMask(XtScreen(_w), icon_filename);
824
825     Pixmap clipped_icon = icon;
826     if (icon_mask) {
827         Window root;
828         int x, y;
829         unsigned int width, height, border_width, depth;
830         XGetGeometry(XtDisplay(_w),
831                      icon,
832                      &root,
833                      &x, &y,
834                      &width, &height,
835                      &border_width, &depth);
836
837         XtRealizeWidget(_w);
838
839         clipped_icon = XCreatePixmap(XtDisplay(_w),
840                                      XtWindow(_w),
841                                      width,
842                                      height,
843                                      depth);
844
845         XGCValues gc_vals;
846         GC gc;
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),
852                        XtWindow(_w),
853                        GCForeground | GCBackground | GCFillStyle,
854                        &gc_vals);
855
856         XFillRectangle(XtDisplay(_w),
857                        clipped_icon,
858                        gc,
859                        0, 0,
860                        width, height);
861
862         XFreeGC(XtDisplay(_w), gc);
863
864         memset(&gc_vals, 0, sizeof(gc_vals));
865         gc_vals.background = bg;
866         gc = XCreateGC(XtDisplay(_w),
867                        XtWindow(_w),
868                        GCBackground,
869                        &gc_vals);
870
871         XSetClipMask(XtDisplay(_w), gc, icon_mask);
872
873         XCopyArea(XtDisplay(_w),
874                   icon,
875                   clipped_icon,
876                   gc,
877                   0, 0,
878                   width, height,
879                   0, 0);
880         XFreeGC(XtDisplay(_w), gc);
881     }
882
883     XtVaSetValues ( _w,
884                     XmNsymbolPixmap, clipped_icon,
885                     NULL );
886
887     if (NULL != _textField && XtIsManaged(_textField))
888       XtUnmanageChild(_textField);
889     
890 }