4 * This an example of how to use the Text and Paned widgets.
6 * November 14, 1989 - Chris D. Peterson
8 * Updated to also demonstrate XtAppAddInput() -- Bruce Irvin 3/8/94
12 * $XConsortium: xtext.c,v 1.16 91/05/16 14:56:23 swick Exp $
14 * Copyright 1989 Massachusetts Institute of Technology
16 * Permission to use, copy, modify, distribute, and sell this software and its
17 * documentation for any purpose is hereby granted without fee, provided that
18 * the above copyright notice appear in all copies and that both that
19 * copyright notice and this permission notice appear in supporting
20 * documentation, and that the name of M.I.T. not be used in advertising or
21 * publicity pertaining to distribution of the software without specific,
22 * written prior permission. M.I.T. makes no representations about the
23 * suitability of this software for any purpose. It is provided "as is"
24 * without express or implied warranty.
26 * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
28 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
29 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
30 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
31 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
35 #include <X11/Intrinsic.h>
36 #include <X11/StringDefs.h>
38 #include <X11/Xaw/AsciiText.h>
39 #include <X11/Xaw/Command.h>
40 #include <X11/Xaw/Paned.h>
42 #include <X11/Xaw/Cardinals.h>
44 //////////////////////////////////
45 #include "../h/visualization.h"
46 //////////////////////////////////
48 static void ClearText(Widget w,XtPointer text_ptr,XtPointer call_data);
49 static void PrintText(Widget w,XtPointer text_ptr,XtPointer call_data);
50 static void QuitProgram(Widget w,XtAppContext app_con,XtPointer call_data);
51 static void Syntax(XtAppContext app_con,char *call);
52 //////////////////////////////
54 Widget toplevel, paned, clear, print, quit, text;
55 Widget getMR, stopMR, phaseN;
56 //////////////////////////////
58 // extern int fprintf(), bcopy(), read(), perror(), printf();
60 String fallback_resources[] = {
63 "?.?.text.preferredPaneSize: 200",
64 "?.?.text.width: 200",
65 "?.?.text.textSource.editType: edit",
66 "?.?.text.scrollVertical: whenNeeded",
67 "?.?.text.scrollHorizontal: whenNeeded",
68 "?.?.text.autoFill: on",
69 "*clear*label: Clear",
70 "*print*label: Print",
75 // callback routine for FOLD and DATAVALUES
76 int fd_input(int dummy){
83 int noMetrics,noResources,noBins;
87 XtSetArg(args[0], XtNinsertPosition, &pos);
88 XtGetValues(text, args, ONE);
91 fprintf(stderr,"@@@@ in callback for datavalues and fold\n");
92 noMetrics = dataGrid.NumMetrics();
93 noResources = dataGrid.NumResources();
94 noBins = dataGrid.NumBins();
95 for(i=0;i < noMetrics; i++)
96 for(j=0;j<noResources;j++){
97 for(k=0;k<noBins;k++){
98 if((value = dataGrid[i][j][k]) != ERROR){
99 sprintf(&buf[0],"%s%d%s%d%s%d%s%f\n","dataGrid[",i,"][",j,"][",k,
103 sprintf(&buf[0],"%s%d%s%d%s%d%s\n","dataGrid[",i,"][",j,"][",k ,
111 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
112 fprintf(stderr,"XawTextReplace returned error\n");
115 XtSetArg(args[0], XtNinsertPosition, pos);
116 XtSetValues(text, args, ONE);
119 sprintf(&buf[0],"\n");
125 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
126 fprintf(stderr,"XawTextReplace returned error\n");
129 XtSetArg(args[0], XtNinsertPosition, pos);
130 XtSetValues(text, args, ONE);
132 fprintf(stderr,"@@@@ leaving callback for datavalues and fold\n");
136 // callback routine for ADDMETRICSRESOURCES
137 int fd_input2(int dummy){
143 int noMetrics,noResources,noBins;
147 XtSetArg(args[0], XtNinsertPosition, &pos);
148 XtGetValues(text, args, ONE);
149 noMetrics = dataGrid.NumMetrics();
150 noResources = dataGrid.NumResources();
151 noBins = dataGrid.NumBins();
152 value = dataGrid.BinWidth();
153 aggr = dataGrid.FoldMethod(0);
154 sprintf(&buf[0],"\n%s%d%s%d%s%d%s%f%s%d\n","noMetrics = ",noMetrics,
155 ", no resources = ",noResources,", num Bins = ",noBins,
156 "\nbinWidth = ",value,", Fold Method = ",aggr);
163 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
164 fprintf(stderr,"XawTextReplace returned error\n");
167 XtSetArg(args[0], XtNinsertPosition, pos);
168 XtSetValues(text, args, ONE);
173 // callback routine for NEWMETRICSRESOURCES, PHASENAME
174 int fd_input3(int dummy){
181 XtSetArg(args[0], XtNinsertPosition, &pos);
182 XtGetValues(text, args, ONE);
183 sprintf(&buf[0],"\n%s\n",
184 "This operation is not fully supported: only the call is implemented");
190 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
191 fprintf(stderr,"XawTextReplace returned error\n");
194 XtSetArg(args[0], XtNinsertPosition, pos);
195 XtSetValues(text, args, ONE);
200 /////////////////////////////////////
201 static void GetMetsRes(Widget w,XtAppContext app_con,XtPointer call_data){
203 fprintf(stderr,"@@@@ in GetMetsRes before call\n");
204 vp->GetMetricResource(" "," ",0);
205 fprintf(stderr,"@@@@ in GetMetsRes after call\n");
208 static void StopMetsRes(Widget w,XtAppContext app_con,XtPointer call_data){
210 fprintf(stderr,"@@@@ in StopMetsRes before call\n");
211 vp->StopMetricResource(0,0);
212 fprintf(stderr,"@@@@ in StopMetsRes after call\n");
215 static void PName(Widget w,XtAppContext app_con,XtPointer call_data){
217 fprintf(stderr,"@@@@ in PName before call\n");
218 vp->PhaseName(0.0,1.0," ");
219 fprintf(stderr,"@@@@ in PName after call\n");
221 /////////////////////////////////////
224 int main(int argc,char **argv)
226 // XtAppContext app_con;
227 // Widget toplevel, paned, clear, print, quit, text;
230 /////////////////////////////////////
231 // variables added for paradyn integration
233 /////////////////////////////////////
235 toplevel = XtAppInitialize(&app_con, "Xtext", NULL, ZERO,
236 &argc, argv, fallback_resources,
240 * Check to see that all arguments were processed, and if not then
241 * report an error and exit.
245 Syntax(app_con, argv[0]);
247 //////////////////////////////////////
248 // call VisiInit: step (1) from README file
250 if((fd = VisiInit()) < 0){
253 //////////////////////////////////////
255 //////////////////////////////////////
256 // register event callbacks: step (2) from README file
258 ok = RegistrationCallback(ADDMETRICSRESOURCES,fd_input2);
259 ok = RegistrationCallback(DATAVALUES,fd_input);
260 ok = RegistrationCallback(FOLD,fd_input);
261 ok = RegistrationCallback(INVALIDMETRICSRESOURCES,fd_input);
262 ok = RegistrationCallback(NEWMETRICSRESOURCES,fd_input3);
263 ok = RegistrationCallback(PHASENAME,fd_input3);
264 //////////////////////////////////////
266 //////////////////////////////////////
267 // start visi: get initial metric and resource choices: step (3) from README
270 //////////////////////////////////////
272 paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel,
274 clear = XtCreateManagedWidget("clear", commandWidgetClass, paned,
276 print = XtCreateManagedWidget("print", commandWidgetClass, paned,
278 quit = XtCreateManagedWidget("quit", commandWidgetClass, paned,
280 //////////////////////////////////////
281 // this is for an upcall to Paradyn: step (3a) from README
283 getMR = XtCreateManagedWidget("Get Metric Resource",commandWidgetClass,
285 stopMR = XtCreateManagedWidget("Stop Metric Resource",commandWidgetClass,
287 phaseN = XtCreateManagedWidget("Name a Phase",commandWidgetClass,
290 //////////////////////////////////////
292 XtSetArg(args[0], XtNstring, "This is a test.\n");
294 text = XtCreateManagedWidget("text", asciiTextWidgetClass, paned,
297 XtAddCallback(clear, XtNcallback, ClearText, (XtPointer) text);
298 XtAddCallback(print, XtNcallback, PrintText, (XtPointer) text);
299 XtAddCallback(quit, XtNcallback, QuitProgram, (XtPointer) app_con);
301 ///////////////////////////////////////
302 // Add callbacks for upcalls to Paradyn: step (3b) from README
304 XtAddCallback(getMR, XtNcallback, GetMetsRes, (XtPointer) app_con);
305 XtAddCallback(stopMR, XtNcallback, StopMetsRes, (XtPointer) app_con);
306 XtAddCallback(phaseN, XtNcallback, PName, (XtPointer) app_con);
307 //////////////////////////////////////
309 //////////////////////////////////////
310 // register visi_callback routine as callback on events assoc. w/ file desc
311 // step (4) from README file
313 XtAppAddInput(app_con,fd,(XtPointer) XtInputReadMask,
314 (XtInputCallbackProc) visi_callback, text);
315 //////////////////////////////////////
317 XtRealizeWidget(toplevel);
318 XtAppMainLoop(app_con);
321 /* Function Name: ClearText
322 * Description: This function clears all text out of the text widget.
323 * Arguments: w - *** UNUSED ***
324 * text_ptr - a pointer to the text widget.
325 * call_data - *** UNUSED ***.
330 static void ClearText(Widget w,XtPointer text_ptr,XtPointer call_data)
332 Widget text = (Widget) text_ptr;
335 XtSetArg(args[0], XtNstring, "");
336 XtSetValues(text, args, ONE);
339 /* Function Name: PrintText
340 * Description: This function clears all text out of the text widget.
341 * Arguments: w - *** UNUSED ***
342 * text_ptr - a pointer to the text widget.
343 * call_data - *** UNUSED ***.
348 static void PrintText(Widget w,XtPointer text_ptr,XtPointer call_data)
350 Widget text = (Widget) text_ptr;
354 XtSetArg(args[0], XtNstring, &str);
355 XtGetValues(text, args, ONE);
357 fprintf(stderr, "Text String is:\n--------\n%s\n--------\n", str);
360 /* Function Name: QuitProgram
361 * Description: This function exits the program
362 * Arguments: w - *** UNUSED ***
363 * text_ptr - a pointer to the text widget.
364 * call_data - *** UNUSED ***.
369 static void QuitProgram(Widget w,XtAppContext app_con,XtPointer call_data)
371 fprintf(stderr, "Bye!\n");
372 XtDestroyApplicationContext(app_con);
376 /* Function Name: Syntax
377 * Description: Prints a the calling syntax for this function to stdout.
378 * Arguments: app_con - the application context.
379 * call - the name of the application.
380 * Returns: none - exits tho.
383 static void Syntax(XtAppContext app_con,char *call)
385 XtDestroyApplicationContext(app_con);
386 fprintf( stderr, "Usage: %s \n", call);