1/* Copyright 1992 NEC Corporation, Tokyo, Japan. 2 * 3 * Permission to use, copy, modify, distribute and sell this software 4 * and its documentation for any purpose is hereby granted without 5 * fee, provided that the above copyright notice appear in all copies 6 * and that both that copyright notice and this permission notice 7 * appear in supporting documentation, and that the name of NEC 8 * Corporation not be used in advertising or publicity pertaining to 9 * distribution of the software without specific, written prior 10 * permission. NEC Corporation makes no representations about the 11 * suitability of this software for any purpose. It is provided "as 12 * is" without express or implied warranty. 13 * 14 * NEC CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN 16 * NO EVENT SHALL NEC CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR 17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF 18 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 19 * OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 20 * PERFORMANCE OF THIS SOFTWARE. 21 */ 22 23#if !defined(lint) && !defined(__CODECENTER__) 24static char rcs_id[] = "@(#) 102.1 $Id: onoff.c 14875 2005-11-12 21:25:31Z bonefish $"; 25#endif /* lint */ 26 27#include <errno.h> 28#include "canna.h" 29 30#ifndef NO_EXTEND_MENU 31#define ICHISIZE 9 32 33static void popOnOffMode(uiContext d); 34static int makeOnOffIchiran(uiContext d, int nelem, int bangomax, int currentkouho, unsigned char *status); 35static int OnOffSelect(uiContext d); 36static int OnOffKakutei(uiContext d); 37 38static int makeOnOffIchiran(); 39 40static WCHAR_T *black; 41static WCHAR_T *white; 42static WCHAR_T *space; 43 44int 45initOnoffTable(void) 46{ 47 black = WString("\241\375"); 48 /* ���� */ 49 white = WString("\241\373"); 50 /* ���� */ 51 space = WString("\241\241"); 52 /* ���� */ 53 54 if (!black || !white || !space) { 55 return NG; 56 } 57 return 0; 58} 59 60static void 61popOnOffMode(uiContext d) 62{ 63 ichiranContext oc = (ichiranContext)d->modec; 64 65 d->modec = oc->next; 66 d->current_mode = oc->prevMode; 67 freeIchiranContext(oc); 68} 69 70/* 71 * �������������������������������� 72 */ 73int selectOnOff(uiContext d, WCHAR_T **buf, int *ck, int nelem, int bangomax, int currentkouho, unsigned char *status, int (*everyTimeCallback )(...), int (*exitCallback )(...), int (*quitCallback )(...), int (*auxCallback )(...)) 74{ 75 extern KanjiModeRec onoff_mode; 76 ichiranContext oc; 77 int retval = 0; 78 ichiranContext newIchiranContext(); 79 80 if(pushCallback(d, d->modec, 81 (int(*)(_uiContext*, int, _coreContextRec*))everyTimeCallback, 82 (int(*)(_uiContext*, int, _coreContextRec*))exitCallback, 83 (int(*)(_uiContext*, int, _coreContextRec*))quitCallback, 84 (int(*)(_uiContext*, int, _coreContextRec*))auxCallback) == 0) { 85 jrKanjiError = "malloc (pushCallback) \244\307\244\255\244\336\244\273\244\363\244\307\244\267\244\277"; 86 /* �������������������������������� */ 87 return(NG); 88 } 89 90 if ((oc = (ichiranContext)newIchiranContext()) == (ichiranContext)NULL) { 91 popCallback(d); 92 return(NG); 93 } 94 oc->next = d->modec; 95 d->modec = (mode_context)oc; 96 97 oc->prevMode = d->current_mode; 98 d->current_mode = &onoff_mode; 99 100 oc->allkouho = buf; 101 oc->curIkouho = ck; 102 103 if((retval = makeOnOffIchiran(d, nelem, bangomax, 104 currentkouho, status)) == NG) { 105 popOnOffMode(d); 106 popCallback(d); 107 return(NG); 108 } 109 return(retval); 110} 111 112/* 113 * �������������������������������������������������������������������������������������������� 114 * 115 * ����glineinfo ���� kouhoinfo�������������������� 116 * 117 * ������������ uiContext 118 * ������������ �������������������� 0 �������������������� -1 119 */ 120static int 121makeOnOffIchiran(uiContext d, int nelem, int bangomax, int currentkouho, unsigned char *status) 122{ 123 ichiranContext oc = (ichiranContext)d->modec; 124 WCHAR_T **kkptr, *kptr, *gptr, *svgptr; 125 int ko, lnko, cn = 0, svcn, line = 0, dn = 0, svdn; 126 127 oc->nIkouho = nelem; /* ���������������� */ 128 129 /* ������������������������������������������������ */ 130 oc->svIkouho = *(oc->curIkouho); 131 *(oc->curIkouho) += currentkouho; 132 if(*(oc->curIkouho) >= oc->nIkouho) 133 oc->svIkouho = *(oc->curIkouho) = 0; 134 135 if(allocIchiranBuf(d) == NG) 136 return(NG); 137 138 if(d->ncolumns < 1) { 139 oc->tooSmall = 1; 140 return(0); 141 } 142 143 /* glineinfo����kouhoinfo������������ */ 144 /* 145 ����glineinfo���� 146 int glkosu : int glhead : int gllen : WCHAR_T *gldata 147 ������������������������ : �������������������� : �������������������� : ������������������������������������ 148 : ���������������������������� : 149 ------------------------------------------------------------------------- 150 0 | 6 : 0 : 24 : ������������������������������������������������ 151 1 | 4 : 6 : 16 : �������������������������������� 152 153 ����kouhoinfo���� 154 int khretsu : int khpoint : WCHAR_T *khdata 155 �������������������� : ������������������������ : ������������������������ 156 �������������������� : ������������������������ : 157 ------------------------------------------------------------------------- 158 0 | 0 : 0 : ���� 159 1 | 0 : 4 : ���� 160 : : : 161 7 | 1 : 0 : ���� 162 8 | 1 : 4 : ���� 163 */ 164 165 kkptr = oc->allkouho; 166 kptr = *(oc->allkouho); 167 gptr = oc->glinebufp; 168 169 /* line -- ���������������� 170 ko -- �������������������������������������������������������� 171 lnko -- ���������������������������������������������������� 172 cn -- ������������������������������������������������ */ 173 174 for(line=0, ko=0; ko<oc->nIkouho; line++) { 175 oc->glineifp[line].gldata = gptr; /* �������������������������������������������������������� */ 176 oc->glineifp[line].glhead = ko; /* ��������������������������������������������������������ko�������� */ 177 178 oc->tooSmall = 1; 179 for(lnko = cn = dn = 0; 180 dn<d->ncolumns - (cannaconf.kCount ? ICHISIZE + 1: 0) && 181 lnko<bangomax && ko<oc->nIkouho ; lnko++, ko++) { 182 oc->tooSmall = 0; 183 kptr = kkptr[ko]; 184 oc->kouhoifp[ko].khretsu = line; /* ������������������������������������������������ */ 185 oc->kouhoifp[ko].khpoint = cn + (lnko ? 1 : 0); 186 oc->kouhoifp[ko].khdata = kptr; /* �������������������������������������������� */ 187 svgptr = gptr; 188 svcn = cn; 189 svdn = dn; 190 191 /* ������������������������������������ */ 192 if(lnko) { 193 WStrncpy(gptr++, space, WStrlen(space)); 194 cn++; dn += 2; 195 } 196 if(status[ko] == 1) 197 WStrncpy(gptr, black, WStrlen(black)); 198 else 199 WStrncpy(gptr, white, WStrlen(white)); 200 cn ++; gptr++; dn +=2; 201 /* �������������������������������� */ 202 for(; *kptr && dn<d->ncolumns - (cannaconf.kCount ? ICHISIZE + 1: 0); 203 gptr++, kptr++, cn++) { 204 if (((*gptr = *kptr) & 0x8080) == 0x8080) dn++; 205 dn++; 206 } 207 208 /* �������������������������������������������������������������������������������������������������������� */ 209 if ((dn >= d->ncolumns - (cannaconf.kCount ? ICHISIZE + 1: 0)) 210 && *kptr) { 211 if (lnko) { 212 gptr = svgptr; 213 cn = svcn; 214 dn = svdn; 215 } 216 else { 217 oc->tooSmall = 1; 218 } 219 break; 220 } 221 } 222 if (oc->tooSmall) { 223 return 0; 224 } 225 if (cannaconf.kCount) { 226 for (;dn < d->ncolumns - 1; dn++) { 227 *gptr++ = ' '; 228 } 229 } 230 /* �������������������� */ 231 *gptr++ = (WCHAR_T)0; 232 oc->glineifp[line].glkosu = lnko; 233 oc->glineifp[line].gllen = WStrlen(oc->glineifp[line].gldata); 234 } 235 /* ������������NULL���������������� */ 236 oc->kouhoifp[ko].khretsu = 0; 237 oc->kouhoifp[ko].khpoint = 0; 238 oc->kouhoifp[ko].khdata = (WCHAR_T *)NULL; 239 oc->glineifp[line].glkosu = 0; 240 oc->glineifp[line].glhead = 0; 241 oc->glineifp[line].gllen = 0; 242 oc->glineifp[line].gldata = (WCHAR_T *)NULL; 243 244#if defined(DEBUG) && !defined(WIN) 245 if (iroha_debug) { 246 int i; 247 for(i=0; oc->glineifp[i].glkosu; i++) 248 printf("%d: %s\n", i, oc->glineifp[i].gldata); 249 } 250#endif 251 252 return(0); 253} 254 255/* 256 * ������������������������������������������������������������(ON����OFF, OFF����ON) 257 * 258 * ������������ uiContext 259 * ������������ �������������������� 0 �������������������� -1 260 */ 261static 262int OnOffSelect(uiContext d) 263{ 264 ichiranContext oc = (ichiranContext)d->modec; 265 mountContext mc = (mountContext)oc->next; 266 int point, retval = 0; 267 WCHAR_T *gline; 268 269 /* mountNewStatus �������������������� (1����0, 0����1) */ 270 if(mc->mountNewStatus[*(oc->curIkouho)]) 271 mc->mountNewStatus[*(oc->curIkouho)] = 0; 272 else 273 mc->mountNewStatus[*(oc->curIkouho)] = 1; 274 275 /* gline�������������������������������������������� (������������, ������������) */ 276 gline = oc->glineifp[oc->kouhoifp[*(oc->curIkouho)].khretsu].gldata; 277 point = oc->kouhoifp[*(oc->curIkouho)].khpoint; 278 279 *(gline+point) = ((mc->mountNewStatus[*(oc->curIkouho)]) ? *black : *white); 280 makeGlineStatus(d); 281 /* d->status = EVERYTIME_CALLBACK; */ 282 283 return(retval); 284} 285 286/* 287 * status ��������������������������������OnOff����������������POP�������� (EXIT_CALLBACK) 288 * 289 * ������������ uiContext 290 * ������������ �������������������� 0 �������������������� -1 291 */ 292static 293int OnOffKakutei(uiContext d) 294{ 295 ichiranContext oc = (ichiranContext)d->modec; 296 int retval = 0; 297/* ���������������������������� unsigned char *kakuteiStrings;*/ 298 299 /* ������������������������������������������������������������������������ */ 300 freeIchiranBuf(oc); 301 302 popOnOffMode(d); 303 304#if defined(DEBUG) && !defined(WIN) 305 if(iroha_debug) { 306 mountContext mc = (mountContext)d->modec; 307 int i; 308 309 printf("<����mount>\n"); 310 for(i= 0; mc->mountList[i]; i++) 311 printf("[%s][%x][%x]\n", mc->mountList[i], 312 mc->mountOldStatus[i], mc->mountNewStatus[i]); 313 printf("\n"); 314 } 315#endif 316 317 /* gline ������������������������ */ 318 GlineClear(d); 319 320 d->status = EXIT_CALLBACK; 321 322 return(retval); 323} 324#endif /* NO_EXTEND_MENU */ 325 326#include "onoffmap.h" 327