File: mainwindow.c

package info (click to toggle)
kdrill 6.5deb2-12
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 1,340 kB
  • sloc: ansic: 7,636; makefile: 47
file content (175 lines) | stat: -rw-r--r-- 3,936 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
/* "mainwindow.c"
 *	Has all the widget management routines for the
 *	main-window english/widget widgets.
 */

#include <stdio.h>
#include <stdlib.h>

#include <ctype.h>
#include <Intrinsic.h>
#include <StringDefs.h>
#include <Xaw/Command.h>
#include <Xaw/Label.h>
#include <Xaw/Form.h>
#include <stdint.h>

#include "defs.h"
#include "game.h"
#include "widgets.h"
#include "searchwidgets.h"
#include "options.h"
#include "utils.h"
#include "externs.h"

/* Keeps track of if we are using 'cheat' to have a button highlighted */

static int cheat_on=0;

/* BackCallback:
 *	go back to last kanji.
 *  Has to be in game.c, to access static vars
 */
void BackCallback(Widget w,XtPointer client_data,XtPointer call_data)
{
	TRANSLATION buffer;

	if(lastpicked == 0) return;

	buffer= values[truevalue];
	values[truevalue] = lastpicked;
	lastpicked = buffer;

	setstatus("Going to previous character");
	printquestion();
	printallchoices();
	DescribeCurrent(values[truevalue]);
	
}

/* changemode:
 *	Change from guessing kanji to guessing english, or vica verse,
 *	 by clicking on the appropriate button
 *	Which button has been clicked, is indicated in the
 *	  "data" field.
 *
 *   Also handles changing from english <->kana display,
 *   calling CountKanji(), because we have to .
 */
void ChangeMode(Widget w,XtPointer data,XtPointer calldata)
{
	/* whichbutton is
	 * EITHER
	 *    [mode 4kanji]<->[mode 4english] button,
	 * OR
	 *   [change  kana<->english]
	 */
	int buttonpressed = (int)(intptr_t) data;
#ifdef DEBUG
	printf("button mode change: %d\n",buttonpressed);
#endif
	switch(buttonpressed){
		case GUESS_ENGLISH:
			SetXtrmString("guessmode", "english");
			break;
		case GUESS_KANJI:
			SetXtrmString("guessmode", "kanji");
			break;
		case GUESS_KANA:
			SetXtrmString("guessmode", "kana");
			break;
		default:
			fprintf(stderr,"Error: cannot switch to non-existant mode\n");
			return;
	}
	choicesmode = buttonpressed;
	if(switchKanaEnglish){ /* allow switching in place */
		printallchoices();
	} else {
		CountKanji();
		SetupGuess();
	}
}


/* Change the "Question" label at the top of the main window,
 * between kanji, kana, and english display
 */
void ChangeQuestion(Widget w,XtPointer data,XtPointer calldata)
{
	int buttonpressed = (int)(intptr_t) data;

#ifdef DEBUG
	printf("changing question display\n");
#endif
	questionmode = buttonpressed;
	switch(questionmode){
		case GUESS_ENGLISH:
			SetXtrmString("questionmode", "english");
			break;
		case GUESS_KANJI:
			SetXtrmString("questionmode", "kanji");
			break;
		case GUESS_KANA:
			SetXtrmString("questionmode", "kana");
			break;
	}
	printquestion();
}

/* Guessvalue:
 *	accelerator function so we can guess with 1,2,3,4 keys
 *	NOTE:
 *	we get passed the value (key-1)
 */
void Guessvalue(Widget w,XEvent *event,String *params,Cardinal *num_parags)
{
	int value;
	value = atoi(*params);
	if(value >=NUMBEROFCHOICES) return;
	guessvalue(value);
}


/* This is called by both button and key-accelerator.
 * Either sets the 'cheat' highlight, or turns it off, if already set.
 * set client_data to non-NULL if you dont want status message set
 */
void cheatcallback(Widget w,XtPointer client_data,XtPointer calldata)
{
	ReverseButton(choicesWidgets[truevalue]);
	cheat_on=!cheat_on;
	printallchoices();

	if((client_data ==NULL) && cheat_on){
		setstatus("Try Harder!");
	}
}

/* This is currently ONLY called by key-accelerator
 * Do BOTH highlight of correct value, AND pop up search window
 * with full details of that kanji
 */
void supercheat()
{
	cheatcallback(NULL,NULL,NULL);
	printsearch(values[truevalue]);
}

/* Hook for guessvalue in game.c to clear 'cheat' highlighting */
void ClearCheat()
{
	if(!cheat_on) return;

	ReverseButton(choicesWidgets[truevalue]);
	cheat_on=0;
}

/* choicescallback:
 *	Handles clicking on guess
 */
void choicescallback(Widget w,XtPointer data,XtPointer calldata)
{
	guessvalue((int)(intptr_t) data);
}