File: skipsearch.c

package info (click to toggle)
kdrill 6.5deb2-12
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,340 kB
  • sloc: ansic: 7,636; makefile: 47
file content (413 lines) | stat: -rw-r--r-- 10,399 bytes parent folder | download | duplicates (5)
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
/* since were having problems with the SKIP window, I needed to split it out */

#include <stdio.h>

#include <Xos.h>
#include <Xfuncs.h>
#include <Intrinsic.h>
#include <StringDefs.h>

#include <Shell.h>

#include <Xaw/Command.h>
#include <Xaw/Label.h>
#include <Xaw/Form.h>
#include <Xaw/Box.h>
#include <Xaw/AsciiText.h>

#include "defs.h"
#include "externs.h"

#include "searchwidgets.h"
#include "search.h"
#include "convert.h"
#include "game.h"
#include "utils.h"
#include "init.h"
#include "readfile.h"


/****************************************************/
/* Now, "SKIP" method */
/****************************************************/


static Widget SKIPinput_popup;

Widget SKIPcategories[4];
static int SKIPchoice=0; /* This is the "type" of SKIP value we are using
			  * It is the first number in the X-Y-Z SKIP format
			  * 
			  */

Widget SKIPinput1,SKIPinput2;
Widget SKIPnumberinput[2];/* if SKIP type 1-3, input number */
Widget SKIPnumberlabel[2];
Widget SKIPshapeinput[4]; /* if SKIP type 4, click on closest shape */




void setSKIPlabels(int choice){
	SKIPchoice=choice;

	switch(choice){
	   case 0:
		XtVaSetValues(SKIPnumberlabel[0], XtNlabel,
			      "Number of strokes on left ",NULL);
		XtVaSetValues(SKIPnumberlabel[1], XtNlabel,
			      "Number of strokes on right",NULL);
		XtSetSensitive(SKIPshapeinput[0], False);
		XtSetSensitive(SKIPshapeinput[1], False);
		XtSetSensitive(SKIPshapeinput[2], False);
		XtSetSensitive(SKIPshapeinput[3], False);
		break;
	   case 1:
		XtVaSetValues(SKIPnumberlabel[0], XtNlabel,
			      "Number of strokes on top   ",NULL);
		XtVaSetValues(SKIPnumberlabel[1], XtNlabel,
			      "Number of strokes on bottom",NULL);
		XtSetSensitive(SKIPshapeinput[0], False);
		XtSetSensitive(SKIPshapeinput[1], False);
		XtSetSensitive(SKIPshapeinput[2], False);
		XtSetSensitive(SKIPshapeinput[3], False);
		break;
	   case 2:
		XtVaSetValues(SKIPnumberlabel[0], XtNlabel,
			      "Number of strokes on outside",NULL);
		XtVaSetValues(SKIPnumberlabel[1], XtNlabel,
			      "Number of strokes on inside ",NULL);
		XtSetSensitive(SKIPshapeinput[0], False);
		XtSetSensitive(SKIPshapeinput[1], False);
		XtSetSensitive(SKIPshapeinput[2], False);
		XtSetSensitive(SKIPshapeinput[3], False);
		break;
	   case 3:
		XtVaSetValues(SKIPnumberlabel[0], XtNlabel,
			      "Number of total strokes   ",NULL);
		XtVaSetValues(SKIPnumberlabel[1], XtNlabel,
			      "**Choose shape from below*",NULL);
		XtSetSensitive(SKIPshapeinput[0], True);
		XtSetSensitive(SKIPshapeinput[1], True);
		XtSetSensitive(SKIPshapeinput[2], True);
		XtSetSensitive(SKIPshapeinput[3], True);
		break;
	}
}



void SKIPshapecallback(Widget w,XtPointer client_data, XtPointer call_data){
/*	int shapenum=(int)client_data;*/
	
	char newlabel[3];
	sprintf(newlabel,"%1d",(int)(intptr_t)client_data);
	XtVaSetValues(SKIPnumberinput[1], XtNstring,   newlabel, NULL);
}

/* Gets called when user selects which of the four main categories
 * a kanji matches.
 * We read the current values in the text input fields, but use the
 * cached value of SKIPchoice.
 * Then we call doskipfind()
 */
void SKIPcallbacks(Widget w,XtPointer client_data, XtPointer call_data)
{
	int scount;
	int skipnum=(intptr_t)client_data;

	if(skipnum==10) {
		int s1,s2,s3;

		s1=SKIPchoice+1;

		s2=GetWidgetNumberval(SKIPnumberinput[0]);
		s3=GetWidgetNumberval(SKIPnumberinput[1]);

#ifdef DEBUG
		printf("s1=%d,s2=%d,s3=%d\n",s1,s2,s3);
#endif

		if((s1==0)) {
			setstatus("Insufficient values set");
			puts("BAD!");
			return;
		}

		doskipfind(skipfromthree(s1,s2,s3));
		return;
	}

	for(scount=0;scount<4;scount++) {
		if(scount==skipnum) {
			HighlightButton(SKIPcategories[scount]);
		} else {
			UnhighlightButton(SKIPcategories[scount]);
		}
	}
	setSKIPlabels(skipnum);
}

/* This exists solely to make asciiTextWidgetClass inputs ignore RETURN */
/* It gets initialized in MakeSKIPInputPopup */
static XtAccelerators ignoreAccel;
static char *ignoreAccelMap =
 " <Key>Return:  do-nothing()"; 



/* try to make the skip search widgets.
 * This is passed the top-level form. SO it is responsible for basically
 * EVERYTHING on the skip search window:
 *  -- The Top-FOUR skip mode buttons
 *  -- the help message
 *  -- the two "upper/lower" stroke count bits plus labels
 *  -- the last SKIP-factor quad input buttons
 *  -- the search button
 *
 * 
 */
void makeskipinput(Widget parent)
{
	XCharStruct charstruct = englishfont->max_bounds;
	int scount;
	char tmpname[30];
	XChar2b cat_string[10][2]=
	{
		{{0x21, 0x43}, {0,0}}, /* graphic glyphs for top buttons*/
		{{0x21, 0x3d}, {0,0}},
		{{0x22, 0x22}, {0,0}},
		{{0x21, 0x7a}, {0,0}},
		{{0,0}},
		/* graphic glyphs for bottom buttons */
		{{0x28, 0x40}, {0,0}},
		{{0x28, 0x3b}, {0,0}},
		{{0x22, 0x22}, {0,0}},
		{{0x22, 0x23}, {0,0}},
		{{0,0}},
		
	};
	
	Widget SKIPdirections, search;


	int wcount;
	for(wcount=0;wcount<4;wcount++){
		sprintf(tmpname, "skiptopb-%d",wcount);
		SKIPcategories[wcount]=
			XtVaCreateManagedWidget(tmpname, commandWidgetClass,
						parent,
					 XtNencoding, XawTextEncodingChar2b,
					 XtNfont, largekfont,
					 XtNlabel, cat_string[wcount],
			XtNleft,XawChainLeft,
			XtNright,XawChainLeft,
			XtNtop, XawChainTop,
			XtNbottom, XawChainTop,
					 NULL);
		if(wcount>0){
			XtVaSetValues(SKIPcategories[wcount],
				      XtNfromHoriz,SKIPcategories[wcount-1],
				      NULL);
		}
	}

	SKIPdirections = XtVaCreateManagedWidget(
			"directions", asciiTextWidgetClass, parent,
			XtNfromVert, SKIPcategories[0],
			XtNdisplayCaret, False,
			XtNwidth, 46*charstruct.width,
			XtNheight, 14*(charstruct.ascent+charstruct.descent),
			XtNleft,XawChainLeft,
			XtNright,XawChainLeft,
			XtNtop, XawChainTop,
			XtNbottom, XawChainTop,
			XtNstring,
"This is the SKIP kanji search window.\n"
"First, choose from the top whether the \n"
"kanji looks;\n"
"  Divided in half vertically,\n"
"  Divided in half horizontally,\n"
"  Enclosed somehow,\n"
"  or 'something else'.\n"
"\n"
"Then enter the number of strokes on \n"
"the left, then rightside.\n"
"Or strokes on top, then bottom.\n"
"Or pick closest match to type.\n"
"Then press the Search button",
			XtNfont,englishfont,
			NULL);

	SKIPinput1=XtVaCreateManagedWidget("skipinputform1", formWidgetClass,
					   parent,
					   XtNfromVert,SKIPdirections,
			XtNleft,XawChainLeft,
			XtNright,XawChainLeft,
			XtNtop, XawChainTop,
			XtNbottom, XawChainTop,
					   NULL);


	SKIPnumberinput[0] =
		XtVaCreateManagedWidget("ninput1", asciiTextWidgetClass,
					SKIPinput1,
				XtNlabel, "",
				XtNwidth,30,
				XtNeditType,XawtextEdit,
				NULL);
	SKIPnumberinput[1] =
		XtVaCreateManagedWidget("ninput2", asciiTextWidgetClass,
					SKIPinput1,
				XtNfromVert, SKIPnumberinput[0],
				XtNlabel, "",
				XtNwidth,30,
				XtNeditType,XawtextEdit,
				NULL);

	XtOverrideTranslations(SKIPnumberinput[0],ignoreAccel);
	XtOverrideTranslations(SKIPnumberinput[1],ignoreAccel);


	/* Yes, these are supposed to be to the RIGHT of the above */
	SKIPnumberlabel[0] =
		XtVaCreateManagedWidget("nlabel1", labelWidgetClass,
					SKIPinput1,
				XtNfromHoriz, SKIPnumberinput[0],
				XtNlabel, "______________________________",
				NULL);
	SKIPnumberlabel[1] =
		XtVaCreateManagedWidget("nlabel2", labelWidgetClass,
					SKIPinput1,
				XtNfromHoriz, SKIPnumberinput[0],
				XtNfromVert, SKIPnumberlabel[0],
				XtNlabel, "______________________________",
				NULL);



	SKIPinput2=XtVaCreateManagedWidget("skipinputform2", formWidgetClass,
					   parent,
					   XtNfromVert,SKIPinput1,
			XtNleft,XawChainLeft,
			XtNright,XawChainLeft,
			XtNtop, XawChainTop,
			XtNbottom, XawChainTop,
					   NULL);

	
	for(wcount=0;wcount<4;wcount++){
		sprintf(tmpname, "skipshape-%d",wcount);
		SKIPshapeinput[wcount]=
		XtVaCreateManagedWidget(tmpname, commandWidgetClass, SKIPinput2,
		     XtNencoding, XawTextEncodingChar2b,
		     XtNfont, largekfont,
		     XtNlabel, cat_string[5+wcount],
		     XtNsensitive,False,
		     NULL);
		if(wcount>0){
		     XtVaSetValues(SKIPshapeinput[wcount],
				   XtNfromHoriz, SKIPshapeinput[wcount-1],
		     NULL);
		}
	}


	/* What good is this? WHy did I have this?
	clear = XtVaCreateManagedWidget(
			"clear", commandWidgetClass, parent,
			XtNfromVert, SKIPinput2,
			NULL);
	*/

	search = XtVaCreateManagedWidget(
			"skipsearchstart", commandWidgetClass, parent,
			XtNfromVert, SKIPinput2,
			XtNfont, englishfont,
			XtNlabel, "Search",
			XtNleft,XawChainLeft,
			XtNright,XawChainLeft,
			XtNtop, XawChainTop,
			XtNbottom, XawChainTop,
			NULL);



	XtAddCallback(search,XtNcallback, SKIPcallbacks,(XtPointer) 10);

	for(scount=0; scount<4; scount++) {
		XtAddCallback(SKIPcategories[scount],
			      XtNcallback, SKIPcallbacks,
			      (XtPointer)(intptr_t) scount);
	}

	XtAddCallback(SKIPshapeinput[0],XtNcallback, SKIPshapecallback,
			      (XtPointer) 1);
	XtAddCallback(SKIPshapeinput[1],XtNcallback, SKIPshapecallback,
			      (XtPointer) 2);
	XtAddCallback(SKIPshapeinput[2],XtNcallback, SKIPshapecallback,
			      (XtPointer) 3);
	XtAddCallback(SKIPshapeinput[3],XtNcallback, SKIPshapecallback,
			      (XtPointer) 4);

#ifdef NONONON
#endif /* NONONON */
	
}

/* exported routine */
void MakeSKIPInputPopup()
{
	Widget skipinputform;

	ignoreAccel = XtParseAcceleratorTable(ignoreAccelMap);

	SKIPinput_popup = XtVaCreatePopupShell("kdrill_skipsearch ",
		/*transientShellWidgetClass,*/
		topLevelShellWidgetClass,
		search_popup,
		NULL);

	skipinputform = XtVaCreateManagedWidget("skipinputform",
					     formWidgetClass,
					     SKIPinput_popup,
					     NULL);

	/* make the 10 input things, plus 4 display things */ 
	makeskipinput(skipinputform);
}

/* This gets called after clicking on the "Kanji search" button.
 * It pops up the SKIP input window
 */
void ShowSKIP(Widget w,XtPointer client_data, XtPointer call_data)
{
	static int skip_up = -1;

	static Position rel_x,rel_y;
	Position x,y;


	if(skip_up==-1){
		/* first time init.. */
		rel_x = 10;
		rel_y = 10;
		skip_up=0;
	}
	if(isMapped(SKIPinput_popup)==False){

		XtTranslateCoords(search_popup,rel_x,rel_y,&x,&y);
		XtVaSetValues(SKIPinput_popup,
		      XtNx,x,
		      XtNy,y,
		      NULL);
		XtPopup(SKIPinput_popup,XtGrabNone);
		if(skip_up==0){
			setup_deletewindow(SKIPinput_popup);
			skip_up=1;
		}
		setstatus("Bringing up SKIP input window...");
	} else {
		XtPopdown(SKIPinput_popup);
	}
}