File: CommScrTxt1.c

package info (click to toggle)
motif 2.3.4-13
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 81,160 kB
  • ctags: 51,769
  • sloc: ansic: 596,938; cpp: 3,951; yacc: 2,854; makefile: 2,070; csh: 1,199; sh: 1,070; lex: 455
file content (230 lines) | stat: -rw-r--r-- 7,136 bytes parent folder | download | duplicates (3)
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/* $XConsortium: CommScrTxt1.c /main/6 1995/07/15 21:10:33 drk $ */
/*
 * Motif
 *
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
 *
 * These libraries and programs are free software; you can
 * redistribute them and/or modify them under the terms of the GNU
 * Lesser General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * These libraries and programs are distributed in the hope that
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with these librararies and programs; if not, write
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301 USA
 */
/*
 * HISTORY
 */
#include <testlib.h>

Widget BBoard1;
Widget Text1, Text2;
Widget EditLabel, ToggleB1;
Arg args[MAX_ARGS];
int n;

static char new_string1[] = "\
As I was going to St. Ives\n\
I met a man with seven wives\n\
Each wife had seven sacks,\n\
Each sack had seven cats,\n\
Each cat had seven kits\n\
Kits, cats, sacks, and wives,\n\
How many were going to St. Ives?";

static char new_string2[] = "\
Jack Sprat could eat no fat\n\
His wife could eat no lean\n\
And so between them both\n\
They licked the platter clean";

static char new_string3[] = "\
john said, jack, enjoy the job";

int     EditMode;

static char font_name1[] = "8x13bold"; 
static char font_name2[] = "variable"; 

static char render_tag[] = "Render1";

static void HelpCB(Widget w, XtPointer client_data,
                                XtPointer call_data)
{
        Widget info_box = NULL;
        XmString helpString, titleString, okString;

        helpString = XmStringGenerate ("Help has arrived!",
                XmFONTLIST_DEFAULT_TAG,  XmCHARSET_TEXT, NULL );
        titleString = XmStringCreateLtoR ("Info box",
                XmSTRING_DEFAULT_CHARSET);
        okString = XmStringCreateLtoR ("Dismiss",
                XmSTRING_DEFAULT_CHARSET);
        n = 0;
        XtSetArg (args[n], XmNmessageString, helpString); n++;
        XtSetArg (args[n], XmNokLabelString, okString); n++;
        XtSetArg (args[n], XmNdialogTitle, titleString); n++;
        info_box = XmCreateInformationDialog (Shell1, "info_box", args, n);
        XtManageChild (info_box);

        XmStringFree (helpString);
        XmStringFree (titleString);
        XmStringFree (okString);
}

static void ChangeString(Widget w, XtPointer client_data,
                                XtPointer call_data)
{
        int file_length;
        unsigned char *file_string;
        XmString string;

        static int swtch = 0;

	XmTextSetString( Text1, " " );

        if( swtch++ % 2 )
        {
	  XmTextSetString( Text1, new_string2 );
        }
        else
        {
          n = 0;
	  XtSetArg( args[n], XmNvalue, new_string1 ); n++;
          XtSetValues( Text1, args, n );
        }
}


static void ChangeEditMode(Widget w, XtPointer client_data,
                                XtPointer call_data)
{
        XmString        tcs;
        int     rows;

        EditMode = XmMULTI_LINE_EDIT + XmSINGLE_LINE_EDIT - EditMode;

        n = 0;
        XtSetArg(args[n], XmNeditMode, EditMode); n++;
        XtSetArg(args[n], XmNrows, 3); n++;
        XtSetValues(Text2, args, n);

        if (EditMode == XmSINGLE_LINE_EDIT)
                tcs = XmStringCreateLtoR("XmSINGLE_LINE_EDIT",
                        XmSTRING_DEFAULT_CHARSET);
        else
                tcs = XmStringCreateLtoR("XmMULTI_LINE_EDIT",
                        XmSTRING_DEFAULT_CHARSET);

        n = 0;
        XtSetArg(args[n], XmNlabelString, tcs); n++;
        XtSetValues(w, args, n);
        XmStringFree(tcs);
}

void
main_scrtext1(int argc, char **argv)
{
        XtTranslations table1;
        static String trans_string1 = "Shift<Key>osfPageDown: activate()";
        XmString        tcs, string;
        XmRendition     rendition;
        XmRenderTable   renderTab = NULL;

        /*  initialize toolkit  */
        CommonTestInit(argc, argv);

        table1 = XtParseTranslationTable (trans_string1);

        n = 0;
        BBoard1 = XmCreateBulletinBoard (Shell1, "BBoard1", args, n);
        XtManageChild (BBoard1);

        n = 0;
        XtSetArg(args[n], XmNrows, 10);  n++;
        XtSetArg(args[n], XmNscrollVertical, True);  n++;
        XtSetArg(args[n], XmNscrollHorizontal, True);  n++;
        XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
	XtSetArg(args[n], XmNvalue, new_string2); n++;
	XtSetArg(args[n], XmNfontList, CommonGetFontList(font_name1));  n++;
        Text1 = XmCreateScrolledText(BBoard1, "Text1", args, n);

        XtAddCallback(Text1, XmNactivateCallback, ChangeString, NULL);
        XtOverrideTranslations (Text1, table1);
        XtManageChild(Text1);

        XtRealizeWidget(Shell1);

        CommonPause();

        XtAddCallback(Text1, XmNhelpCallback, HelpCB, NULL);

        CommonPause();

        /* test case for PIR 2574, see .dat */
        CommonPause();
        /* end of test case for PIR 2574 */

        /* test case for PIR 2127 */

        n = 0;
        XtSetArg(args[n], XmNfontList, CommonGetFontList(font_name2));  n++;
        XtSetArg(args[n], XmNvalue, new_string3);  n++;
        XtSetValues(Text1, args, n);

        CommonPause();
        /* end of test case for PIR 2127 */

        /* test case for PIR 4120 */
        XtUnmanageChild(Text1);

        n = 0;
        XtSetArg(args[n], XmNeditable, True); n++;
        XtSetArg(args[n], XmNeditMode, XmSINGLE_LINE_EDIT); n++;
	XtSetArg(args[n], XmNvalue, new_string1); n++;
        XtSetArg(args[n], XmNcolumns, 50); n++;
        XtSetArg(args[n], XmNrows, 3); n++;
        XtSetArg(args[n], XmNscrollHorizontal, True); n++;
        XtSetArg(args[n], XmNscrollVertical, True); n++;
        Text2 = XmCreateScrolledText(BBoard1, "Text2", args, n);
        XtManageChild (Text2);


        /* EditMode togglebutton & label */
        EditMode = XmSINGLE_LINE_EDIT;

        tcs = XmStringCreateLtoR("Current EditMode: ",
                XmSTRING_DEFAULT_CHARSET);
        n = 0;
        XtSetArg(args[n], XmNy, 95);  n++;
        XtSetArg(args[n], XmNlabelString, tcs); n++;
        EditLabel = XmCreateLabel(BBoard1, "EditLabel", args, n);
        XtManageChild(EditLabel);
        XmStringFree(tcs);

        tcs = XmStringCreateLtoR("XmSINGLE_LINE_EDIT",
                XmSTRING_DEFAULT_CHARSET);
        n = 0;
        XtSetArg(args[n], XmNy, 115);  n++;
        XtSetArg(args[n], XmNlabelString, tcs); n++;
        XtSetArg(args[n], XmNset, True); n++;
        ToggleB1 = XmCreateToggleButton(BBoard1, "ToggleB1", args, n);
        XtManageChild(ToggleB1);
        XtAddCallback(ToggleB1, XmNvalueChangedCallback,
                ChangeEditMode, NULL);
        XmStringFree(tcs);

        CommonPause();
        /* end of test case for PIR 4120 */

        XtAppMainLoop(app_context);
}