Create Xref-Html Frames Remove All Frames
file:d:/code/LRC/Splicer/splicer_code_ver2.2/hsplicer-callbacks-c.c (Tue Mar 14 16:28:58 2000
)
1: /*
2: * Generated by the ICS builderXcessory (BX).
3: *
4: *
5: * Builder Xcessory 3.0.
6: *
7: */
8: #include <Xm/Xm.h>
9:
10: /*
11: * Standard includes for builtins.
12: */
13: #include <stdio.h>
14: #include <string.h>
15: #include <ctype.h>
16: #include "hsplicer-creation-c.h"
17: #include "splicer_defs.h"
18: #include <Xm/Form.h>
19: #include <Xm/Text.h>
20: #include <Xm/PushB.h>
21: #include <Xm/Separator.h>
22:
23:
24: /*
25: * Macros to make code look nicer between ANSI and K&R.
26: */
27: #ifndef ARGLIST
28: #if (NeedFunctionPrototypes == 0)
29: #define PROTOTYPE(p) ()
30: #define ARGLIST(p) p
31: #define ARG(a, b) a b;
32: #define GRA(a, b) a b;
33: #define UARG(a, b) a b;
34: #define GRAU(a, b) a b;
35: #else
36: #define PROTOTYPE(p) p
37: #define ARGLIST(p) (
38: #define ARG(a, b) a b,
39: #define GRA(a, b) a b)
40: #ifdef __cplusplus
41: #define UARG(a, b) a,
42: #define GRAU(a, b) a)
43: #else
44: #define UARG(a, b) a b,
45: #define GRAU(a, b) a b)
46: #endif
47: #endif
48: #endif
49:
50: Widget BxFindTopShell PROTOTYPE((Widget));
51: WidgetList BxWidgetIdsFromNames PROTOTYPE((Widget, char*, char*));
52:
53: #define MAXBUFFER (100)
54: char filename[200];
55: char *printstring,*getenv();
56: void SpManageWarningBox(),free(),*calloc(),*realloc();
57:
58:
59:
60: /* Function Name: BxExitCB
61: *
62: * Description: This functions expects an integer to be passed in
63: * client data. It calls the exit() system call with
64: * the integer value as the argument to the function.
65: *
66: * Arguments: Widget w: the activating widget.
67: * XtPointer client: the integer exit value.
68: * XtPointer call: the call data (unused).
69: */
70:
71: /* ARGSUSED */
72: void
73: BxExitCB ARGLIST((w, client, call))
74: UARG( Widget, w)
75: ARG( XtPointer, client)
76: GRAU( XtPointer, call)
77: {
78: int exitValue = (int)client;
79: void exit();
80:
81: if(printstring) free(printstring);
82: exit(exitValue);
83: }
84:
85: /* ARGSUSED */
86: void
87: HssaveCB(w, client, call)
88: Widget w;
89: XtPointer client;
90: XtPointer call;
91: {
92: FILE *fptr_out;
93: char outfile[200],buffer[500];
94:
95: /*SUPPRESS 594*/
96: XmFileSelectionBoxCallbackStruct *filebox=(XmFileSelectionBoxCallbackStruct*)call;
97: (void)strcpy(outfile,XmCvtXmStringToCT(filebox->value));
98: if((fptr_out=fopen(outfile,"w"))==NULL)
99: {
100: (void)sprintf("Error opening help output file %s.",outfile);
101: SpManageWarningBox(buffer);
102: }
103: else
104: {
105: (void)fputs((char*)XmTextGetString(textHelp),fptr_out);
106: fclose(fptr_out);
107: }
108: }
109:
110: /* ARGSUSED */
111: void
112: HsprintCB(w, client, call)
113: Widget w;
114: XtPointer client;
115: XtPointer call;
116: {
117: void XmTextFieldSetString();
118:
119: if(!printstring)
120: {
121: printstring=(char*)calloc(500,sizeof(char));
122: (void)sprintf(printstring,"lpr -rP%s",getenv("PRINTER"));
123: }
124: XmTextFieldSetString(textFieldPrint,printstring);
125: XtManageChild(formPrint);
126: }
127: /* Function Name: BxUnmanageCB
128: *
129: * Description: Given a string of the form:
130: * "(WL)[widgetName, widgetName, ...]"
131: * BxUnmanageCB attempts to convert the name to a Widget
132: * ID and unmanage the widget.
133: *
134: * Arguments: Widget w: the widget activating the callback.
135: * XtPointer client: the list of widget names to attempt
136: * to find and unmanage.
137: * XtPointer call: the call data (unused).
138: *
139: * Notes: * This function expects that there is an application
140: * shell from which all other widgets are descended.
141: */
142:
143: /* ARGSUSED */
144: void
145: BxUnmanageCB ARGLIST((w, client, call))
146: ARG( Widget, w)
147: ARG( XtPointer, client)
148: GRAU( XtPointer, call)
149: {
150: WidgetList widgets;
151: int i;
152:
153: /*
154: * This function returns a NULL terminated WidgetList. The memory for
155: * the list needs to be freed when it is no longer needed.
156: */
157: widgets = BxWidgetIdsFromNames(w, "BxUnmanageCB", (String)client);
158:
159: i = 0;
160: while( widgets && widgets[i] != NULL )
161: {
162: XtUnmanageChild(widgets[i]);
163: i++;
164: }
165: XtFree((char *)widgets);
166: }
167: /* Function Name: BxManageCB
168: *
169: * Description: Given a string of the form:
170: * "(WL)[widgetName, widgetName, ...]"
171: * BxManageCB attempts to convert the name to a Widget
172: * ID and manage the widget.
173: *
174: * Arguments: Widget w: the widget activating the callback.
175: * XtPointer client: the list of widget names to attempt
176: * to find and manage.
177: * XtPointer call: the call data (unused).
178: *
179: * Notes: * This function expects that there is an application
180: * shell from which all other widgets are descended.
181: */
182:
183: /* ARGSUSED */
184: void
185: BxManageCB ARGLIST((w, client, call))
186: ARG( Widget, w)
187: ARG( XtPointer, client)
188: GRAU( XtPointer, call)
189: {
190: WidgetList widgets;
191: int i;
192:
193: /*
194: * This function returns a NULL terminated WidgetList. The memory for
195: * the list needs to be freed when it is no longer needed.
196: */
197: widgets = BxWidgetIdsFromNames(w, "BxManageCB", (String)client);
198:
199: i = 0;
200: while( widgets && widgets[i] != NULL )
201: {
202: XtManageChild(widgets[i]);
203: i++;
204: }
205: XtFree((char *)widgets);
206: }
207:
208: /* Function Name: DestroyWidget
209: *
210: * Description: When called, destroys the widget passed to it
211: * as client data. This is used by the BXHelpCB function.
212: *
213: * Arguments: Widget w: the activating widget.
214: * XtPointer client: the widget to destroy
215: * XtPointer call: the call data (unused).
216: */
217:
218: /* ARGSUSED */
219: static void
220: DestroyWidget ARGLIST((w, client, call))
221: UARG( Widget, w)
222: ARG( XtPointer, client)
223: GRAU( XtPointer, call)
224: {
225: XtDestroyWidget((Widget)client);
226: }
227:
228: /* Function Name: BxHelpCB
229: *
230: * Description: This functions expects a string to be passed as
231: * client data. It creates and manages a dialog with a Text
232: * widget to display the string and a Dismiss button. The dialog
233: * is destroyed when it is dismissed.
234: *
235: * Arguments: Widget w: the activating widget.
236: * XtPointer client: the string to display
237: * XtPointer call: the call data (unused).
238: */
239:
240: /* ARGSUSED */
241: void
242: BxHelpCB ARGLIST((w, client, call))
243: ARG( Widget, w)
244: ARG( XtPointer, client)
245: GRAU( XtPointer, call)
246: {
247: String text = (String) client;
248: Widget formDialog = XmCreateFormDialog(w, "formDialog", NULL, 0);
249: Widget textWidget = XmCreateText(formDialog, "textWidget", NULL, 0);
250: Widget separator = XmCreateSeparator(formDialog, "separator", NULL, 0);
251: Widget dismiss = XmCreatePushButton(formDialog, "dismiss", NULL, 0);
252: String dismiss_label = "Dismiss";
253:
254: XtVaSetValues(XtParent(formDialog), XmNtitle, "HelpText", NULL);
255:
256: XtVaSetValues(textWidget,
257: XmNvalue, text,
258: XmNeditable, False,
259: XmNtopAttachment, XmATTACH_FORM,
260: XmNbottomAttachment, XmATTACH_WIDGET,
261: XmNbottomWidget, separator,
262: XmNleftAttachment, XmATTACH_FORM,
263: XmNrightAttachment, XmATTACH_FORM,
264: XmNwordWrap, True,
265: XmNeditMode, XmMULTI_LINE_EDIT,
266: XmNwidth, 250,
267: XmNheight, 100,
268: NULL);
269:
270: XtVaSetValues(separator,
271: XmNbottomAttachment, XmATTACH_WIDGET,
272: XmNbottomWidget, dismiss,
273: XmNbottomOffset, 10,
274: XmNleftAttachment, XmATTACH_FORM,
275: XmNrightAttachment, XmATTACH_FORM,
276: NULL);
277:
278: XtVaSetValues(dismiss,
279: XtVaTypedArg, XmNlabelString, XmRString,
280: dismiss_label, strlen(dismiss_label)+1,
281: XmNbottomAttachment, XmATTACH_FORM,
282: XmNbottomOffset, 10,
283: XmNleftAttachment, XmATTACH_POSITION,
284: XmNleftPosition, 25,
285: XmNrightAttachment, XmATTACH_POSITION,
286: XmNrightPosition, 75,
287: NULL);
288:
289: XtAddCallback(dismiss, XmNactivateCallback, DestroyWidget,
290: (XtPointer)XtParent(formDialog));
291:
292: XtManageChild(textWidget);
293: XtManageChild(separator);
294: XtManageChild(dismiss);
295: XtManageChild(formDialog);
296: }
297:
298: /* ARGSUSED */
299: void
300: HsHelpTopicCB(w, client, call)
301: Widget w;
302: XtPointer client;
303: XtPointer call;
304: {
305: FILE *fptr;
306: char buffer[MAXBUFFER],*helptext;
307: int len_allocated;
308:
309: /*SUPPRESS 594*/
310: String name = (String) client;
311: (void)sprintf(filename,"%s/%s",getenv("SPLICER_HELPFILES_PATH"),name);
312:
313: if((fptr=fopen(filename,"r"))==NULL)
314: {
315: (void)sprintf(buffer,"Error opening help topic file %s",filename);
316: SpManageWarningBox(buffer);
317: }
318: else
319: {
320: helptext=(char*)calloc(len_allocated=ALLOC_INT,sizeof(char));
321: helptext[0]='\0';
322: while(fgets(buffer,MAXBUFFER,fptr)!=NULL)
323: {
324: if((int)strlen(buffer)+(int)strlen(helptext)>=len_allocated)
325: {
326: helptext=(char*)realloc(helptext,(len_allocated+ALLOC_INT)*sizeof(char));
327: len_allocated+=ALLOC_INT;
328: }
329: (void)strcat(helptext,buffer);
330: }
331: fclose(fptr);
332: XtVaSetValues(textHelp,XmNvalue,helptext,NULL);
333: free(helptext);
334: }
335: }
336:
337: void SpManageWarningBox(message)
338: char *message;
339: {
340: XtVaSetValues(messageBoxError,XmNmessageString,XmStringCreateLocalized(message),NULL);
341: XtManageChild(messageBoxError);
342: }
343:
344:
345:
346: /* ARGSUSED */
347: void
348: HsPrintOKCB(w, client, call)
349: Widget w;
350: XtPointer client;
351: XtPointer call;
352: {
353: FILE *fptr;
354: char buffer[500],tmpfile[500];
355: int system();
356:
357: /*SUPPRESS 594*/
358:
359: /* make temporary file of help text */
360: if((fptr=fopen(tmpnam(tmpfile),"w"))==NULL)
361: {
362: (void)sprintf("Error opening temporary file for printing %s.",tmpfile);
363: SpManageWarningBox(buffer);
364: }
365: else
366: {
367: (void)fputs((char*)XmTextGetString(textHelp),fptr);
368: fclose(fptr);
369: }
370:
371: /* get printer name from environment and send command */
372: printstring=XmTextGetString(textFieldPrint);
373: (void)strcpy(buffer,printstring);
374: (void)strcat(buffer," ");
375: (void)strcat(buffer,tmpfile);
376: system(buffer);
377: }
378:
379: /* ARGSUSED */
380: void
381: HsTextHelpCer(w, client, call)
382: Widget w;
383: XtPointer client;
384: XtPointer call;
385: {
386: /*SUPPRESS 594*/
387: }
388:
389: /* ARGSUSED */
390: void
391: HsTextHelpCreateCB(w, client, call)
392: Widget w;
393: XtPointer client;
394: XtPointer call;
395: {
396: /*SUPPRESS 594*/
397: char buffer[MAXBUFFER],*helptext;
398: int len_allocated;
399:
400: /*SUPPRESS 594*/
401: helptext=(char*)calloc(len_allocated=ALLOC_INT,sizeof(char));
402: helptext[0]='\0';
403: while(fgets(buffer,MAXBUFFER,stdin)!=NULL)
404: {
405: if((int)strlen(buffer)+(int)strlen(helptext)>=len_allocated)
406: {
407: helptext=(char*)realloc(helptext,(len_allocated+ALLOC_INT)*sizeof(char));
408: len_allocated+=ALLOC_INT;
409: }
410: (void)strcat(helptext,buffer);
411: }
412: XtVaSetValues(textHelp,XmNvalue,helptext,NULL);
413: free(helptext);
414: }
415:
Html form generated by Xrefactory version 1.6.7 on Fri Sep 03 17:18:59 2004