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