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
|
/* This is the code for the "Learn" window.
* The "main" kanjidrill window is for drilling.
* THIS window, however, is purely for flashcard purposes.
* It respects the grade and usefile limitations currently in effect
* It shows the kanji, kana, and english reading of a char/phrase for
* as long as the user likes, until they press next, or close.
*/
#include <stdio.h>
#include <Xos.h>
#include <Intrinsic.h>
#include <StringDefs.h>
#include <Xfuncs.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 "init.h"
#include "utils.h"
#include "externs.h"
#include "game.h"
#include "convert.h"
#include "readfile.h"
#include "searchwidgets.h"
#include "multikanji.h"
#include "log.h"
Widget learn_popup; /* global, so Accelerator can check on it */
static Widget learn_close, learn_randnext,learn_next,learn_usefile;
static Widget learn_kanji,learn_kana,learn_english;
static TRANSLATION nowshowing=NULL;
int showindex=0;
/* This gets called after clicking on the "search" button, or
* using the keyboard accelerator. It pops up the search window.
*/
void LearnCallback(Widget w,XtPointer client_data, XtPointer call_data)
{
static int learn_up = -1;
static Position rel_x,rel_y;
Position x,y;
/* sometimes we are called with w==NULL by hand */
if(learn_up==-1){
/* first time init.. */
rel_x = GetXtrmNumber("learn_popupx","Learn_popupx");
rel_y = GetXtrmNumber("learn_popupy","Learn_popupy");
setup_deletewindow(learn_popup);
learn_up=0;
}
if(isMapped(learn_popup)==False){
/* Map in! */
XtTranslateCoords(toplevel,rel_x,rel_y,&x,&y);
/* it seems some window managers let you have extreme
* negative coordinates for pop-ups. sigh
*/
if(x<0) x=0;
if(y<0) y=0;
XtVaSetValues(learn_popup,
XtNx,x,
XtNy,y,
NULL);
XtMapWidget(learn_popup);
setstatus("Bringing up learn window...");
} else {
XtUnmapWidget(learn_popup);
}
}
/* refresh "learn" window with latest char.
* Routine kept separate, so we can externally toggle between
* romaji/kana display
*/
void DisplayLearnChar()
{
if(nowshowing==NULL) return;
/* This shouldnt be neccessary. It should be redundant with
* the creation args. But if I dont do this, and SEPARATELY,
* it doesnt display the kanji chars under solaris! :-(
*
*/
XtVaSetValues(learn_kanji,
XtNencoding, XawTextEncodingChar2b,
XtNfont,largekfont,
NULL);
XtVaSetValues(learn_kanji,XtNlabel,nowshowing->kanji, NULL);
if(romajiswitch==1){
char stringbuff[MAXROMAJI+1];
/* translate all kana into romaji */
/* translate to buffer, then set widget string*/
kanatoromaji(nowshowing->pronunciation, stringbuff);
XtVaSetValues(learn_kana,
XtNencoding,XawTextEncoding8bit,
XtNfont,englishfont,
NULL);
XtVaSetValues(learn_kana,
XtNlabel,stringbuff,
NULL);
} else {
XtVaSetValues(learn_kana,
XtNencoding, XawTextEncodingChar2b,
XtNfont,smallkfont,
NULL);
XtVaSetValues(learn_kana,
XtNlabel,nowshowing->pronunciation,NULL);
}
XtVaSetValues(learn_english, XtNlabel,nowshowing->english, NULL);
if(InUsefile(showindex)){
HighlightButton(learn_usefile);
} else {
UnhighlightButton(learn_usefile);
}
}
/* Pick a new char randomly, or in order if client_data==True, and
* display it on our window.
*/
void LearnNewChar(Widget w,XtPointer client_data, XtPointer call_data)
{
Boolean save_show=showinorder;
TRANSLATION save_last=lastpicked;
if(nowshowing!=NULL) {
lastpicked=nowshowing;
}
/* Okay, the 0xff is ugly: its to avoid an irritating size-of-int
* warning in casting
*/
showinorder=(Boolean)((int)(intptr_t)client_data & 0xff);
nowshowing=picktruevalue();
showinorder=save_show;
lastpicked=save_last;
showindex=trans_to_index(nowshowing);
DisplayLearnChar();
}
/* Toggle for 'is char in usefile?*/
void LearnUsefileToggle(Widget w,XtPointer client_data, XtPointer call_data)
{
if(nowshowing==NULL) return;
SetUseKanji(showindex, !InUsefile(showindex));
DisplayLearnChar();
UpdateSearchlabels();
RefreshMultiLabels();
CountKanji();
}
/* This is the only exported "make widgets" routine */
void MakeLearnPopup()
{
Widget learnform;
/* Yes, we really want "CreateWidget", NOT "CreateManagedWidget",
* Otherwise the initial size gets messed up.
*/
learn_popup = XtVaCreateWidget("kdrill_learn",
shellWidgetClass,
toplevel,
/* this SHOULD work, but does not */
XtNtitle,"inlinetitle",
XtCTitle,"TestTitle",
XtNiconName,"learn_win",
NULL);
/* If we dont do this, the window appears on startup */
XtSetMappedWhenManaged(learn_popup,False);
learnform=XtVaCreateManagedWidget(
"learnform",
formWidgetClass,
learn_popup,
XtNleft,XawChainLeft,
XtNright,XawChainRight,
XtNtop, XawChainTop,
XtNbottom, XawChainBottom,
NULL);
learn_kanji=XtVaCreateManagedWidget("learnkanji",
labelWidgetClass,
learnform,
XtNwidth,FULLWIDTH,
XtNlabel," ",
XtNleft,XawChainLeft,
XtNright,XawChainRight,
XtNtop, XawChainTop,
XtNbottom, XawChainTop,
XtNencoding,XawTextEncodingChar2b,
XtNfont,largekfont,
NULL);
learn_kana=XtVaCreateManagedWidget("learnkana",
labelWidgetClass,
learnform,
XtNwidth,FULLWIDTH,
XtNlabel," ",
XtNleft,XawChainLeft,
XtNright,XawChainRight,
XtNtop, XawChainTop,
XtNbottom, XawChainTop,
XtNencoding,XawTextEncodingChar2b,
XtNfont,smallkfont,
XtNfromVert,learn_kanji,
NULL);
learn_english=XtVaCreateManagedWidget("learnenglish",
labelWidgetClass,
learnform,
XtNwidth,FULLWIDTH,
XtNlabel,"Press a 'next' button",
XtNleft,XawChainLeft,
XtNright,XawChainRight,
XtNtop, XawChainTop,
XtNbottom, XawChainTop,
XtNfont,englishfont,
XtNfromVert,learn_kana,
NULL);
learn_next= XtVaCreateManagedWidget("learnnext",commandWidgetClass,
learnform,
XtNlabel,"Next",
XtNleft,XawChainLeft,
XtNright,XawChainLeft,
XtNtop, XawChainTop,
XtNbottom, XawChainTop,
XtNfromVert,learn_english,
NULL);
learn_randnext= XtVaCreateManagedWidget("learnnextrand",commandWidgetClass,
learnform,
XtNlabel,"Next(Random)",
XtNleft,XawChainLeft,
XtNright,XawChainLeft,
XtNtop, XawChainTop,
XtNbottom, XawChainTop,
XtNfromVert,learn_english,
XtNfromHoriz,learn_next,
NULL);
learn_usefile= XtVaCreateManagedWidget("learnusefile",commandWidgetClass,
learnform,
XtNlabel,"In usefile",
XtNleft,XawChainLeft,
XtNright,XawChainLeft,
XtNtop, XawChainTop,
XtNbottom, XawChainTop,
XtNfromVert,learn_english,
XtNfromHoriz,learn_randnext,
NULL);
learn_close= XtVaCreateManagedWidget("learnclose",commandWidgetClass,
learnform,
XtNlabel,"Close",
XtNleft,XawChainRight,
XtNright,XawChainRight,
XtNtop, XawChainTop,
XtNbottom, XawChainTop,
XtNfromVert,learn_english,
XtNfromHoriz,learn_usefile,
#ifdef WOULD_LIKE_TO_DO_THIS
XtNwinGravity, EastGravity,
#else
XtNhorizDistance,60,
#endif
NULL);
XtAddCallback(learn_next,XtNcallback,LearnNewChar,
(XtPointer)True);
XtAddCallback(learn_randnext,XtNcallback,LearnNewChar,
(XtPointer)False);
XtAddCallback(learn_usefile,XtNcallback,LearnUsefileToggle,NULL);
XtAddCallback(learn_close,XtNcallback,LearnCallback,NULL);
UnhighlightButton(learn_usefile);
}
|