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
|
#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 "search.h"
#include "searchwidgets.h"
#include "convert.h"
#include "game.h"
#include "readfile.h"
#include "utils.h"
#include "init.h"
/***************************************************/
/* We implement "stroke count search" here. */
/***************************************************/
Widget kanjistroke_popup;
enum {SKIP_RL, SKIP_UD, SKIP_ENC, SKIP_DK, SKIP_NUMW};
static Widget skiptoggle[5];
static short skipval;
Widget strokeinputw;
/*
* Get the number of strokes input, and pass along to appropriate
* kanji search routine.
* Also use skip value, if present.
*/
void DoStrokeSearch(Widget w, XtPointer data, XtPointer call_data)
{
int strokecount;
strokecount=GetWidgetNumberval(strokeinputw);
if(strokecount<1) {
XtVaSetValues(strokeinputw,XtNstring,"",NULL);
return;
}
dostrokefind(strokecount,skipval);
}
/* handle toggle for additional narrowing parameter on search.
* we cross-reference with initial SKIP number
*/
void StrokeSKIPcount(Widget w, XtPointer data, XtPointer call_data)
{
int bcount;
for(bcount=0;bcount<SKIP_NUMW;bcount++){
UnhighlightButton(skiptoggle[bcount]);
}
HighlightButton(w);
if(w == skiptoggle[SKIP_RL]){
skipval=skipfromthree(1,0,0);
}
if(w == skiptoggle[SKIP_UD]){
skipval=skipfromthree(2,0,0);
}
if(w == skiptoggle[SKIP_ENC]){
skipval=skipfromthree(3,0,0);
}
if(w == skiptoggle[SKIP_DK]){
skipval=0;
}
}
static char * strokeAccel =
" <Key>Return: stroke-search()";
/*
* make the widgets for the "search by stroke count" kanji search method
* It also makes buttons for our pseudo-"SKIP" coding cross reference.
*
*/
void makestrokeinput(Widget parent)
{
XtAccelerators Accel;
int bcount;
Widget slabel;
Widget skiplabel;
Widget leftform, rightform;
Widget gosearch;
leftform=XtVaCreateManagedWidget("leftform", formWidgetClass,
parent,
XtNleft,XawChainLeft,
XtNright,XawChainLeft,
XtNtop, XawChainTop,
XtNbottom, XawChainTop,
NULL);
slabel=XtVaCreateManagedWidget("strokelabel",
labelWidgetClass, leftform,
XtNborderWidth,0,
XtNlabel, "Stroke count",
NULL);
strokeinputw=XtVaCreateManagedWidget("strokecount",
asciiTextWidgetClass, leftform,
XtNfromVert,slabel,
XtNwidth,40,
XtNeditType,XawtextEdit,
XtNleft,XawChainLeft,
XtNright,XawChainLeft,
XtNtop, XawChainTop,
XtNbottom, XawChainTop,
NULL);
rightform=XtVaCreateManagedWidget("rightform", formWidgetClass,
parent,
XtNfromHoriz,leftform,
XtNleft,XawChainLeft,
XtNright,XawChainLeft,
XtNtop,XawChainTop,
XtNbottom, XawChainTop,
NULL);
skiplabel=XtVaCreateManagedWidget("skiplabel", labelWidgetClass,
rightform,XtNlabel,"Shape of kanji",
XtNborderWidth,0,NULL);
skiptoggle[SKIP_RL]=XtVaCreateWidget("strokeskip0",
commandWidgetClass,
rightform,
XtNlabel,"l/r",
XtNfromVert,skiplabel,
NULL);
skiptoggle[SKIP_UD]=XtVaCreateWidget("strokeskip1",
commandWidgetClass,
rightform,
XtNlabel,"u/d",
XtNfromVert,skiplabel,
XtNfromHoriz,skiptoggle[SKIP_RL],
NULL);
skiptoggle[SKIP_ENC]=XtVaCreateWidget("strokeskip2",
commandWidgetClass,
rightform,
XtNlabel,"enc",
XtNfromVert,skiplabel,
XtNfromHoriz,skiptoggle[SKIP_UD],
NULL);
skiptoggle[SKIP_DK]=XtVaCreateWidget("strokeskip3",
commandWidgetClass,
rightform,
XtNlabel,"dontknow",
XtNfromVert,skiptoggle[SKIP_RL],
NULL);
gosearch=XtVaCreateManagedWidget("strokesearch", commandWidgetClass,
parent,
XtNlabel,"search",XtNfromVert,leftform,
XtNleft,XawChainLeft,
XtNright,XawChainLeft,
XtNtop, XawChainTop,
XtNbottom, XawChainTop,
NULL);
XtManageChildren(&skiptoggle[0],SKIP_NUMW);
for(bcount=0;bcount<SKIP_NUMW;bcount++){
XtAddCallback(skiptoggle[bcount],
XtNcallback, StrokeSKIPcount, NULL);
}
XtAddCallback(gosearch, XtNcallback, DoStrokeSearch, (XtPointer) NULL);
Accel = XtParseAcceleratorTable(strokeAccel);
XtOverrideTranslations(strokeinputw, Accel);
StrokeSKIPcount(skiptoggle[SKIP_DK],NULL,NULL);
}
/* exported routine */
void MakeStrokeinputPopup()
{
Widget strokeinputform;
kanjistroke_popup = XtVaCreatePopupShell("kdrill_strokesearch ",
topLevelShellWidgetClass,
search_popup,
NULL);
strokeinputform = XtVaCreateManagedWidget("strokeinputform",
formWidgetClass,
kanjistroke_popup,
NULL);
/* make all the substuff */
makestrokeinput(strokeinputform);
}
/*
* Exported routine:
*
* It pops up the kanji strokecount search window
*/
void Showstroke(Widget w,XtPointer client_data, XtPointer call_data)
{
static int stroke_up = -1;
static Position rel_x,rel_y;
Position x,y;
if(stroke_up==-1){
/* first time init.. */
/*rel_x = GetXtNumber("kanjistroke_popupx","Search_popupx");*/
/*rel_y = GetXtNumber("kanjistroke_popupy","Search_popupy");*/
rel_x = 10;
rel_y = 10;
stroke_up=0;
}
if(isMapped(kanjistroke_popup)==False){
XtTranslateCoords(search_popup,rel_x,rel_y,&x,&y);
XtVaSetValues(kanjistroke_popup,
XtNx,x,
XtNy,y,
NULL);
XtPopup(kanjistroke_popup,XtGrabNone);
if(stroke_up==0){
setup_deletewindow(kanjistroke_popup);
stroke_up=1;
}
setstatus("Bringing up stroke input window...");
} else {
XtPopdown(kanjistroke_popup);
}
}
|