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