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 "../src/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
83 int noMetrics,noResources,noBins;
87 XtSetArg(args[0], XtNinsertPosition, &pos);
88 XtGetValues(text, args, ONE);
91 noMetrics = dataGrid.NumMetrics();
92 noResources = dataGrid.NumResources();
93 noBins = dataGrid.NumBins();
94 for(i=0;i < noMetrics; i++)
95 for(j=0;j<noResources;j++){
96 for(k=0;k<noBins;k++){
97 if((value = dataGrid[i][j][k]) != ERROR){
98 sprintf(&buf[0],"%s%d%s%d%s%d%s%f\n","dataGrid[",i,"][",j,"][",k,
102 sprintf(&buf[0],"%s%d%s%d%s%d%s\n","dataGrid[",i,"][",j,"][",k ,
110 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
111 fprintf(stderr,"XawTextReplace returned error\n");
114 XtSetArg(args[0], XtNinsertPosition, pos);
115 XtSetValues(text, args, ONE);
118 sprintf(&buf[0],"\n");
124 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
125 fprintf(stderr,"XawTextReplace returned error\n");
128 XtSetArg(args[0], XtNinsertPosition, pos);
129 XtSetValues(text, args, ONE);
134 // callback routine for ADDMETRICSRESOURCES
141 int noMetrics,noResources,noBins;
145 XtSetArg(args[0], XtNinsertPosition, &pos);
146 XtGetValues(text, args, ONE);
147 noMetrics = dataGrid.NumMetrics();
148 noResources = dataGrid.NumResources();
149 noBins = dataGrid.NumBins();
150 value = dataGrid.BinWidth();
151 aggr = dataGrid.FoldMethod(0);
152 sprintf(&buf[0],"\n%s%d%s%d%s%d%s%f%s%d\n","noMetrics = ",noMetrics,
153 ", no resources = ",noResources,", num Bins = ",noBins,
154 "\nbinWidth = ",value,", Fold Method = ",aggr);
161 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
162 fprintf(stderr,"XawTextReplace returned error\n");
165 XtSetArg(args[0], XtNinsertPosition, pos);
166 XtSetValues(text, args, ONE);
171 // callback routine for NEWMETRICSRESOURCES, PHASENAME
179 XtSetArg(args[0], XtNinsertPosition, &pos);
180 XtGetValues(text, args, ONE);
181 sprintf(&buf[0],"\n%s\n",
182 "This operation is not fully supported: only the call is implemented");
188 if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) {
189 fprintf(stderr,"XawTextReplace returned error\n");
192 XtSetArg(args[0], XtNinsertPosition, pos);
193 XtSetValues(text, args, ONE);
198 /////////////////////////////////////
199 static void GetMetsRes(Widget w,XtAppContext app_con,XtPointer call_data){
201 fprintf(stderr,"@@@@ in GetMetsRes before call\n");
202 vp->GetMetricResource(" "," ",0);
203 fprintf(stderr,"@@@@ in GetMetsRes after call\n");
206 static void StopMetsRes(Widget w,XtAppContext app_con,XtPointer call_data){
208 fprintf(stderr,"@@@@ in StopMetsRes before call\n");
209 vp->StopMetricResource(0,0);
210 fprintf(stderr,"@@@@ in StopMetsRes after call\n");
213 static void PName(Widget w,XtAppContext app_con,XtPointer call_data){
215 fprintf(stderr,"@@@@ in PName before call\n");
216 vp->PhaseName(0.0,1.0," ");
217 fprintf(stderr,"@@@@ in PName after call\n");
219 /////////////////////////////////////
222 int main(int argc,char **argv)
224 // XtAppContext app_con;
225 // Widget toplevel, paned, clear, print, quit, text;
228 /////////////////////////////////////
229 // variables added for paradyn integration
231 /////////////////////////////////////
233 toplevel = XtAppInitialize(&app_con, "Xtext", NULL, ZERO,
234 &argc, argv, fallback_resources,
238 * Check to see that all arguments were processed, and if not then
239 * report an error and exit.
243 Syntax(app_con, argv[0]);
245 //////////////////////////////////////
246 // call VisiInit: step (1) from README file
248 if((fd = VisiInit()) < 0){
251 //////////////////////////////////////
253 //////////////////////////////////////
254 // register event callbacks: step (2) from README file
256 ok = RegistrationCallback(ADDMETRICSRESOURCES,fd_input2);
257 ok = RegistrationCallback(DATAVALUES,fd_input);
258 ok = RegistrationCallback(FOLD,fd_input);
259 ok = RegistrationCallback(INVALIDMETRICSRESOURCES,fd_input);
260 ok = RegistrationCallback(NEWMETRICSRESOURCES,fd_input3);
261 ok = RegistrationCallback(PHASENAME,fd_input3);
262 //////////////////////////////////////
264 //////////////////////////////////////
265 // start visi: get initial metric and resource choices: step (3) from README
268 //////////////////////////////////////
270 paned = XtCreateManagedWidget("paned", panedWidgetClass, toplevel,
272 clear = XtCreateManagedWidget("clear", commandWidgetClass, paned,
274 print = XtCreateManagedWidget("print", commandWidgetClass, paned,
276 quit = XtCreateManagedWidget("quit", commandWidgetClass, paned,
278 //////////////////////////////////////
279 // this is for an upcall to Paradyn: step (3a) from README
281 getMR = XtCreateManagedWidget("Get Metric Resource",commandWidgetClass,
283 stopMR = XtCreateManagedWidget("Stop Metric Resource",commandWidgetClass,
285 phaseN = XtCreateManagedWidget("Name a Phase",commandWidgetClass,
288 //////////////////////////////////////
290 XtSetArg(args[0], XtNstring, "This is a test.\n");
292 text = XtCreateManagedWidget("text", asciiTextWidgetClass, paned,
295 XtAddCallback(clear, XtNcallback, ClearText, (XtPointer) text);
296 XtAddCallback(print, XtNcallback, PrintText, (XtPointer) text);
297 XtAddCallback(quit, XtNcallback, QuitProgram, (XtPointer) app_con);
299 ///////////////////////////////////////
300 // Add callbacks for upcalls to Paradyn: step (3b) from README
302 XtAddCallback(getMR, XtNcallback, GetMetsRes, (XtPointer) app_con);
303 XtAddCallback(stopMR, XtNcallback, StopMetsRes, (XtPointer) app_con);
304 XtAddCallback(phaseN, XtNcallback, PName, (XtPointer) app_con);
305 //////////////////////////////////////
307 //////////////////////////////////////
308 // register visi_callback routine as callback on events assoc. w/ file desc
309 // step (4) from README file
311 XtAppAddInput(app_con,fd,(XtPointer) XtInputReadMask,
312 (XtInputCallbackProc) visi_callback, text);
313 //////////////////////////////////////
315 XtRealizeWidget(toplevel);
316 XtAppMainLoop(app_con);
319 /* Function Name: ClearText
320 * Description: This function clears all text out of the text widget.
321 * Arguments: w - *** UNUSED ***
322 * text_ptr - a pointer to the text widget.
323 * call_data - *** UNUSED ***.
328 static void ClearText(Widget w,XtPointer text_ptr,XtPointer call_data)
330 Widget text = (Widget) text_ptr;
333 XtSetArg(args[0], XtNstring, "");
334 XtSetValues(text, args, ONE);
337 /* Function Name: PrintText
338 * Description: This function clears all text out of the text widget.
339 * Arguments: w - *** UNUSED ***
340 * text_ptr - a pointer to the text widget.
341 * call_data - *** UNUSED ***.
346 static void PrintText(Widget w,XtPointer text_ptr,XtPointer call_data)
348 Widget text = (Widget) text_ptr;
352 XtSetArg(args[0], XtNstring, &str);
353 XtGetValues(text, args, ONE);
355 fprintf(stderr, "Text String is:\n--------\n%s\n--------\n", str);
358 /* Function Name: QuitProgram
359 * Description: This function exits the program
360 * Arguments: w - *** UNUSED ***
361 * text_ptr - a pointer to the text widget.
362 * call_data - *** UNUSED ***.
367 static void QuitProgram(Widget w,XtAppContext app_con,XtPointer call_data)
369 fprintf(stderr, "Bye!\n");
370 XtDestroyApplicationContext(app_con);
374 /* Function Name: Syntax
375 * Description: Prints a the calling syntax for this function to stdout.
376 * Arguments: app_con - the application context.
377 * call - the name of the application.
378 * Returns: none - exits tho.
381 static void Syntax(XtAppContext app_con,char *call)
383 XtDestroyApplicationContext(app_con);
384 fprintf( stderr, "Usage: %s \n", call);