1 /* $Header: /cvsroot/lesstif/lesstif/test/Xm/text/test6.c,v 1.6 2001/05/21 14:44:48 amai Exp $
2    A copy of test3.c without the double use of source
3 */
4 
5 /* Extended to print some internals of the widget set */
6 
7 /*
8 ** Generated by X-Designer
9 */
10 
11 #include <stdlib.h>
12 #include <stdio.h>
13 
14 #include <X11/Xatom.h>
15 #include <X11/Intrinsic.h>
16 #include <X11/Shell.h>
17 
18 #include <Xm/Xm.h>
19 #include <Xm/DialogS.h>
20 #include <Xm/RowColumn.h>
21 #include <Xm/ScrollBar.h>
22 #include <Xm/Text.h>
23 #include <Xm/TextP.h>
24 
25 #include "../../common/Test.h"
26 
27 
28 Widget appshell = (Widget) NULL;
29 Widget rowcol = (Widget) NULL;
30 Widget text1_sw = (Widget) NULL;
31 Widget text1 = (Widget) NULL;
32 Widget text2_sw = (Widget) NULL;
33 Widget text2 = (Widget) NULL;
34 
Doit(Widget w,XtPointer client,XtPointer call)35 void Doit(Widget w, XtPointer client, XtPointer call)
36 {
37 	XmTextWidget	tw = (XmTextWidget)w;
38  	XmTextLineTable	p;
39 	int		i;
40 	Line		l;
41 
42 	/* Print the Line Table */
43 	p = tw->text.line_table;
44 
45 	fprintf(stderr, "Line Table (size %d index %d)\n",
46 		tw->text.table_size,
47 		tw->text.table_index);
48 
49 	for (i=0; i<tw->text.table_size; i++) {
50 	    fprintf(stderr, "\tline %d start_pos %d virt_line %d\n",
51 		i, p[i].start_pos, p[i].virt_line);
52 	    if (i != 0 && p[i].start_pos == 0)
53 		break;
54 	}
55 
56 	/* Print Lines */
57 	fprintf(stderr, "LineCount %d\n", tw->text.number_lines);
58 	for (i=0; i<tw->text.number_lines; i++) {
59 		l = &tw->text.line[i];
60 
61 		fprintf(stderr, "Line %d\tstart %d changed %d past_end %d",
62 			i, (int)l->start, (int)l->changed, (int)l->past_end);
63 		if (l->extra)
64 			fprintf(stderr, " extra : width %d wrappedbychar %d",
65 				l->extra->width, l->extra->wrappedbychar);
66 		fprintf(stderr, "\n");
67 	}
68 }
69 
create_appshell(Display * display,char * app_name,int app_argc,char ** app_argv)70 void create_appshell(Display *display,
71                      char *app_name,
72                      int app_argc,
73                      char **app_argv)
74 {
75 	Arg al[64];                    /* Arg List */
76 	register int ac = 0;           /* Arg Count */
77 
78 	XtSetArg(al[ac], XmNallowShellResize, TRUE); ac++;
79 	XtSetArg(al[ac], XmNtitle, "Text Sources"); ac++;
80 	XtSetArg(al[ac], XmNargc, app_argc); ac++;
81 	XtSetArg(al[ac], XmNargv, app_argv); ac++;
82 	appshell = XtAppCreateShell ( app_name, "XApplication", applicationShellWidgetClass, display, al, ac );
83 	ac = 0;
84 	XtSetArg(al[ac], XmNorientation, XmHORIZONTAL); ac++;
85 	rowcol = XmCreateRowColumn ( appshell, "rowcol", al, ac );
86 	ac = 0;
87 	XtSetArg(al[ac], XmNcolumns, 38); ac++;
88 	XtSetArg(al[ac], XmNeditMode, XmMULTI_LINE_EDIT); ac++;
89 	XtSetArg(al[ac], XmNrows, 8); ac++;
90 	XtSetArg(al[ac], XmNwordWrap, TRUE); ac++;
91 	XtSetArg(al[ac], XmNscrollHorizontal, FALSE); ac++;
92 	text1 = XmCreateScrolledText ( rowcol, "text1", al, ac );
93 	ac = 0;
94 	text1_sw = XtParent ( text1 );
95 
96 	XmTextSetString ( text1, "These two text widgets share a common text source\n\nThis means that any edits I make in one text widget will be automatically reflected in the other.\n\nThe text widgets can be displaying different parts of the source at the same time." );
97 	XtManageChild(text1);
98 	XtManageChild ( rowcol);
99 
100 	XtAddCallback(text1, XmNfocusCallback, Doit, NULL);
101 }
102 
103 
104 
105 XtAppContext app_context;
106 Display *display;       /*  Display             */
107 
main(int argc,char ** argv)108 int main (int  argc, char **argv)
109 {
110 	XtSetLanguageProc ( (XtAppContext) NULL, (XtLanguageProc) NULL, (XtPointer) NULL );
111 	XtToolkitInitialize ();
112 	app_context = XtCreateApplicationContext ();
113 	display = XtOpenDisplay (app_context, NULL, argv[0], "XApplication",
114 	                         NULL, 0, &argc, argv);
115 	if (!display)
116 	{
117 	    printf("%s: can't open display, exiting...\n", argv[0]);
118 	    exit (-1);
119 	}
120 	create_appshell ( display, argv[0], argc, argv );
121 	XtRealizeWidget (appshell);
122 
123 
124 {
125     static XtWidgetGeometry Expected[] = {
126    CWWidth | CWHeight            ,   56,   72,  271,  128, 0,0,0, /* rowcol */
127    CWWidth | CWHeight | CWX | CWY,    3,    3,  265,  122, 0,0,0, /* text1SW */
128    CWWidth | CWHeight | CWX | CWY,  250,    0,   15,  122, 0,0,0, /* VertScrollBar */
129    CWWidth | CWHeight | CWX | CWY,    0,    0,  246,  122, 0,0,0, /* text1 */
130     };
131     PrintDetails(appshell,Expected);
132 };
133   LessTifTestMainLoop(appshell);
134 
135 	exit (0);
136 }
137