1 /***********************************************************************/
2 /* Open Visualization Data Explorer                                    */
3 /* (C) Copyright IBM Corp. 1989,1999                                   */
4 /* ALL RIGHTS RESERVED                                                 */
5 /* This code licensed under the                                        */
6 /*    "IBM PUBLIC LICENSE - Open Visualization Data Explorer"          */
7 /***********************************************************************/
8 
9 #include <dxconfig.h>
10 #include "../base/defines.h"
11 
12 
13 
14 
15 #include <Xm/Xm.h>
16 #include <Xm/PushB.h>
17 #include <Xm/Form.h>
18 #include <Xm/Label.h>
19 
20 #include "DXStrings.h"
21 #include "Application.h"
22 #include "TimedMessage.h"
23 
24 
25 
TimedMessage(const char * name,Widget parent,const char * message,const char * title,int timeout)26 TimedMessage::TimedMessage(const char *name,
27 			   Widget parent,
28 			   const char *message,
29 			   const char *title,
30 			   int         timeout) :
31     TimedDialog(name, parent, timeout)
32 {
33     this->message = DuplicateString(message);
34     this->title = DuplicateString(title);
35 }
36 
~TimedMessage()37 TimedMessage::~TimedMessage()
38 {
39     if (this->message)
40 	delete[] this->message;
41     if (this->title)
42 	delete[] this->title;
43     if(theApplication->getLogoPixmap(FALSE) != XtUnspecifiedPixmap)
44 	theApplication->cleanupLogo();
45 }
46 
createDialog(Widget parent)47 Widget TimedMessage::createDialog(Widget parent)
48 {
49     Widget dialog;
50     Widget label;
51 
52     //
53     // Create the information dialog.  Realize it due to a bug under SGI (and
54     // maybe elsewhere).
55     //
56     dialog = XmCreateFormDialog(parent, this->name, NUL(ArgList), 0);
57     XtRealizeWidget(dialog);
58 
59     //
60     // Set the ok button to be the default button.
61     //
62     this->ok =
63 	XtVaCreateManagedWidget(
64 		"OK", xmPushButtonWidgetClass, dialog,
65 		XmNshowAsDefault, True,
66 		XmNtopAttachment, XmATTACH_FORM,
67 		XmNtopOffset, 5,
68 		XmNalignment, XmALIGNMENT_CENTER,
69 		NULL);
70 
71     //
72     // Use the Logo as the button
73     //
74     if (theApplication->getLogoPixmap(FALSE) != XtUnspecifiedPixmap) {
75 	XtVaSetValues(this->ok,
76 		XmNlabelPixmap, theApplication->getLogoPixmap(FALSE),
77 		XmNlabelType, XmPIXMAP,
78 		NULL);
79     } else {
80 	XmString xmstr = XmStringCreate("OK", XmSTRING_DEFAULT_CHARSET);
81 	XtVaSetValues(this->ok, XmNlabelString,xmstr, NULL);
82         XmStringFree(xmstr);
83     }
84 
85     XmString messageString =
86 	XmStringCreateLtoR(this->message, XmSTRING_DEFAULT_CHARSET);
87 
88     //
89     // Create the label
90     //
91     label =
92 	XtVaCreateManagedWidget(
93 		"label", xmLabelWidgetClass, dialog,
94 		XmNalignment, XmALIGNMENT_CENTER,
95 		XmNlabelString, messageString,
96 		XmNbottomAttachment, XmATTACH_FORM,
97 		XmNbottomOffset, 5,
98 		XmNtopAttachment, XmATTACH_WIDGET,
99 		XmNtopWidget, this->ok,
100 		XmNtopOffset, 5,
101 		NULL);
102 
103     XmString titleString =
104 	XmStringCreate(this->title, XmSTRING_DEFAULT_CHARSET);
105 
106     XtVaSetValues(dialog,
107 	XmNdefaultButton, this->ok,
108 	XmNdialogTitle,   titleString,
109 	NULL);
110 
111     XmStringFree(messageString);
112     XmStringFree(titleString);
113 
114     //
115     // Return the created dialog.
116     //
117     Dimension b_width, l_width;
118     XtVaGetValues(label, XmNwidth, &l_width, NULL);
119     XtVaGetValues(this->ok, XmNwidth, &b_width, NULL);
120 
121     int offset;
122     if(l_width > b_width)
123     {
124 	offset = (l_width-b_width)>>1;
125 	XtVaSetValues(this->ok,
126 	    XmNleftAttachment, XmATTACH_NONE,
127 	    XmNx, offset+5,
128 	    NULL);
129 	XtVaSetValues(label,
130 	    XmNleftAttachment, XmATTACH_FORM,
131 	    XmNleftOffset, 5,
132 	    XmNrightAttachment, XmATTACH_FORM,
133 	    XmNrightOffset, 5,
134 	    NULL);
135     }
136     else
137     {
138         offset = (b_width-l_width)>>1;
139 	XtVaSetValues(label,
140 	    XmNleftAttachment, XmATTACH_NONE,
141 	    XmNx, offset,
142 	    NULL);
143 	XtVaSetValues(this->ok,
144 	    XmNleftAttachment, XmATTACH_FORM,
145 	    XmNrightAttachment, XmATTACH_FORM,
146 	    NULL);
147     }
148 
149     return dialog;
150 }
151