-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelp.c
216 lines (186 loc) · 5.67 KB
/
help.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 Deutches Elektronen-Synchrotron in der Helmholtz-
* Gemelnschaft (DESY).
* Copyright (c) 2002 Berliner Speicherring-Gesellschaft fuer Synchrotron-
* Strahlung mbH (BESSY).
* Copyright (c) 2002 Southeastern Universities Research Association, as
* Operator of Thomas Jefferson National Accelerator Facility.
* Copyright (c) 2002 The Regents of the University of California, as
* Operator of Los Alamos National Laboratory.
* This file is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
/* help.h */
/************************DESCRIPTION***********************************
*This files contains the *PUBLIC* routines for creating a
*dialog message box. The created message dialog consists
*a message text widget and two push buttons-- 'Ok', and
*'Help'.
*
*The presence of 'Help' button depends on the help textaul
*string array. A single null string corresponds to a 'Help'
*button and causes remaining text shown on next page. Two
*consecutive null strings indicates the end of help text.
**********************************************************************/
#include <stdlib.h>
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/MessageB.h>
#include <Xm/PushB.h>
#include <Xm/CascadeB.h>
#include <Xm/RowColumn.h>
/* WIN32 differences */
#ifdef WIN32
/* Needs to be included before XlibXtra.h for Exceed 5 */
#include <stdio.h>
/* Hummingbird extra functions including lprintf
* Needs to be included after Intrinsic.h for Exceed 5
* (Intrinsic.h is included in xtParams.h) */
/*#include <X11/XlibXtra.h>*/
/* This is done in Exceed 6 but not in Exceed 5
* Need it to define printf as lprintf for Windows
* (as opposed to Console) apps */
#ifdef _WINDOWS
#ifndef printf
#define printf lprintf
#endif
#endif
#endif /* #ifdef WIN32 */
#include "ax.h"
/*******************************************************
delete an existing widget
*******************************************************/
static void xs_ok_callback(Widget w,void *client_data,
XmAnyCallbackStruct *call_data)
{
XtUnmanageChild(w);
XtDestroyWidget(w);
}
/*************************************************************
* xs_str_array_to_xmstr() : convert char ** to
* compound string
************************************************************/
static XmString xs_str_array_to_xmstr(char *cs[],int n)
{
XmString xmstr,xmsep, xmstr1,xmstr2 ;
int i;
/*
* if the array is empty just return an empty string.
*/
if (n <= 0)
return(XmStringCreate("",XmSTRING_DEFAULT_CHARSET));
xmstr = (XmString) NULL;
xmsep = XmStringSeparatorCreate();
for (i=0;i<n;i++) {
xmstr1=xmstr;
if (i > 0) xmstr = XmStringConcat(xmstr1,xmsep);
XmStringFree(xmstr1);
xmstr1 = xmstr;
xmstr2 = XmStringCreate(cs[i],XmSTRING_DEFAULT_CHARSET);
xmstr = XmStringConcat(xmstr1,xmstr2);
XmStringFree(xmstr1);
XmStringFree(xmstr2);
}
XmStringFree(xmsep);
return (xmstr);
}
/*************************************************************
* the help button call back function from a dialog widget
************************************************************/
void xs_help_callback(Widget w,char *str[],void *call_data)
{
int i,n;
Widget dialog;
XmString xmstr;
Arg wargs[5];
char *title=NULL;
char *buff=NULL;
/*
* Get the title name
*/
XtVaGetValues(w, XmNuserData, &title,NULL);
if (title){
buff=(char *)calloc(1,strlen(title)+12);
strcpy(buff,title);
strcat(buff," Guidance");
strcat(buff,"\0");
}
/*
* Create the message dialog to display the help.
*/
n=0;
if (buff){
XtSetArg(wargs[n], XmNtitle, buff);
n++;
}
XtSetArg(wargs[n], XmNautoUnmanage, FALSE);
n++;
XtSetArg(wargs[n], XmNallowShellResize, FALSE);
n++;
dialog = XmCreateMessageDialog(w, "Help", wargs, n);
free(buff);
/*
* We won't use the cancel widget. Unmanage it.
*/
XtUnmanageChild(XmMessageBoxGetChild(dialog,
XmDIALOG_CANCEL_BUTTON));
/*
* Retrieve the label widget and make the
* text left justified
*/
/*
label = XmMessageBoxGetChild(dialog,
XmDIALOG_MESSAGE_LABEL);
n = 0;
XtSetArg(wargs[n],XmNalignment,XmALIGNMENT_BEGINNING); n++;
XtSetValues(label, wargs, n);
*/
/*
* Add an OK callback to pop down the dialog.
*/
XtAddCallback(dialog, XmNokCallback,(XtCallbackProc)xs_ok_callback, NULL);
/*
* count the test up to the first NUll string.
*/
for (i=0;str[i][0] != '\0';i++)
;
/*
* convert the string array to an XmString array and set it as the label text.
*/
xmstr = xs_str_array_to_xmstr(str,i);
n = 0;
XtSetArg(wargs[n], XmNmessageString, xmstr);
n++;
XtSetValues(dialog, wargs, n);
XmStringFree(xmstr);
/*
* if the next entryu in the help string array is also NULL,
* then this is the last message. Unmanage the help button.
*/
if (str[++i][0] == '\0')
XtUnmanageChild( XmMessageBoxGetChild(dialog,
XmDIALOG_HELP_BUTTON));
/*
* otherwise add a help callback function with the address of
* the next entryu in the help string as client_data.
*/
else {
XtAddCallback(dialog, XmNhelpCallback,
(XtCallbackProc)xs_help_callback, &str[i]);
}
/*
* display the dialog.
*/
XtManageChild(dialog);
}
/******************************************************
helpCallback
******************************************************/
void helpCallback(Widget widget,int item,XmAnyCallbackStruct *cbs)
{
createDialog(widget,XmDIALOG_INFORMATION,
"Help is not available in this release."," ");
}