71
77
addstr( FILL_BLANK );
74
if ( pgo->chiSymbolBufLen == 0 ) {
80
/* Check if buffer is available. */
81
if ( ! chewing_buffer_Check( ctx ) ) {
79
for ( i = 0 ;i < pgo->chiSymbolBufLen; i++ ) {
86
for ( i = 0 ;i < ctx->output->chiSymbolBufLen; i++ ) {
80
87
arrPos[ i ] = count;
81
count += strlen( pgo->chiSymbolBuf[ i ].s );
88
count += strlen( (const char *) ctx->output->chiSymbolBuf[ i ].s ) - 3 < 0 ? 1 : 2;
83
90
arrPos[ i ] = count;
85
92
memset( out_buf, ' ', count * ( sizeof( char ) ) );
86
93
out_buf[ count ] = '\0';
88
for ( i = 0; i < pgo->nDispInterval; i++ ) {
89
if ( ( pgo->dispInterval[ i ].to - pgo->dispInterval[ i ].from ) == 1 ) {
90
out_buf[ arrPos[ pgo->dispInterval[ i ].from ] ] = ' ';
91
out_buf[ arrPos[ pgo->dispInterval[ i ].to ] - 1 ] = ' ';
95
for ( i = 0; i < ctx->output->nDispInterval; i++ ) {
96
if ( ( ctx->output->dispInterval[ i ].to - ctx->output->dispInterval[ i ].from ) == 1 ) {
97
out_buf[ arrPos[ ctx->output->dispInterval[ i ].from ] ] = ' ';
98
out_buf[ arrPos[ ctx->output->dispInterval[ i ].to ] - 1 ] = ' ';
94
out_buf[ arrPos[ pgo->dispInterval[ i ].from ] ] = '[';
95
out_buf[ arrPos[ pgo->dispInterval[ i ].to ] - 1 ] = ']';
101
out_buf[ arrPos[ ctx->output->dispInterval[ i ].from ] ] = '[';
102
out_buf[ arrPos[ ctx->output->dispInterval[ i ].to ] - 1 ] = ']';
98
&out_buf[ arrPos[ pgo->dispInterval[ i ].from ] + 1 ], '-',
99
arrPos[ pgo->dispInterval[ i ].to ] - arrPos[ pgo->dispInterval[ i ].from ] - 2 );
105
&out_buf[ arrPos[ ctx->output->dispInterval[ i ].from ] + 1 ], '-',
106
arrPos[ ctx->output->dispInterval[ i ].to ] - arrPos[ ctx->output->dispInterval[ i ].from ] - 2 );
101
108
addstr( out_buf );
104
void showZuin( ChewingOutput *pgo )
111
void showZuin( ChewingContext *ctx )
116
if ( chewing_get_ChiEngMode( ctx ) )
112
for ( i = 0, a = 2; i < ZUIN_SIZE; i++ ) {
113
if ( pgo->zuinBuf[ i ].s[ 0 ] != '\0' ) {
114
addstr( pgo->zuinBuf[ i ].s );
121
zuin_string = chewing_zuin_String( ctx, &zuin_count );
122
addstr( zuin_string );
119
void show_zuin_buffer( int x, int y, ChewingOutput *pgo )
126
void show_zuin_buffer( int x, int y, ChewingContext *ctx )
122
129
addstr( FILL_BLANK );
125
132
attron( COLOR_PAIR( 1 ) );
128
135
attroff( COLOR_PAIR( 1 ) );
131
void show_userphrase( int x, int y, wch_t showMsg[], int len )
136
memset( out_buf, 0, sizeof( out_buf ) );
137
for ( i = 0; i < len; i++ ) {
138
strcat( out_buf, showMsg[ i ].s );
138
void show_full_shape( int x, int y, ChewingContext *ctx )
143
attron( COLOR_PAIR( 2 ) );
144
if ( chewing_get_ShapeMode( ctx ) == FULLSHAPE_MODE )
149
attroff( COLOR_PAIR( 2 ) );
153
void show_userphrase( int x, int y, ChewingContext *ctx )
156
if ( chewing_aux_Length( ctx ) == 0 )
141
160
addstr( FILL_BLANK );
144
163
attron( COLOR_PAIR( 2 ) );
164
aux_string = chewing_aux_String( ctx );
165
addstr( aux_string );
147
168
attroff( COLOR_PAIR( 2 ) );
150
void show_choose_buffer( int x, int y, ChewingOutput *pgo )
171
void show_choose_buffer( int x, int y, ChewingContext *ctx )
155
178
addstr( FILL_BLANK );
158
if ( pgo->pci->nPage != 0 ) {
159
no = pgo->pci->pageNo * pgo->pci->nChoicePerPage;
162
for ( i = 0; i < pgo->pci->nChoicePerPage; no++, i++ ) {
163
if ( no >= pgo->pci->nTotalChoice )
165
sprintf( str, "%d.", i + 1 );
167
attron( COLOR_PAIR( 3 ) );
170
attroff( COLOR_PAIR( 3 ) );
171
sprintf( str, " %s ", pgo->pci->totalChoiceStr[ no ] );
174
if ( pgo->pci->nPage != 1 ) {
175
if ( pgo->pci->pageNo == 0 )
177
else if ( pgo->pci->pageNo == ( pgo->pci->nPage - 1 ) )
181
if ( chewing_cand_TotalPage( ctx ) == 0 )
184
chewing_cand_Enumerate( ctx );
185
while ( chewing_cand_hasNext( ctx ) ) {
186
if ( i == chewing_cand_ChoicePerPage( ctx ) )
188
sprintf( str, "%d.", i );
190
attron( COLOR_PAIR( 3 ) );
193
attroff( COLOR_PAIR( 3 ) );
194
cand_string = chewing_cand_String( ctx );
195
sprintf( str, " %s ", cand_string );
200
currentPageNo = chewing_cand_CurrentPage( ctx );
201
if ( chewing_cand_TotalPage( ctx ) != 1 ) {
202
if ( currentPageNo == 0 )
204
else if ( currentPageNo == ( chewing_cand_TotalPage( ctx ) - 1 ) )
185
void show_commit_string( ChewingOutput *pgo )
211
void show_commit_string( ChewingContext *ctx )
188
214
static int y = 0;
190
218
if ( pgo->keystrokeRtn & KEYSTROKE_COMMIT ) {
191
219
for ( i = 0; i < pgo->nCommitStr; i++ ) {
192
mvaddstr( x, y, pgo->commitStr[ i ].s );
220
mvaddstr( x, y, (const char *) pgo->commitStr[ i ].s );
193
221
y = ( y >= 54 ) ?
195
( y + strlen( pgo->commitStr[ i ].s ) );
223
( y + strlen( (const char *) pgo->commitStr[ i ].s ) - 3 < 0 ? y + 1 : y + 2 );
196
224
x = ( y == 0 ) ? ( x + 1 ) : x;
228
if ( chewing_commit_Check( ctx ) ) {
229
commit_string = chewing_commit_String( ctx );
230
mvaddstr( x, y, FILL_BLANK);
231
mvaddstr( x, y, commit_string );
232
free( commit_string );
201
void set_cursor( int x, ChewingOutput *pgo )
236
void set_cursor( int x, ChewingContext *ctx )
205
for ( count = 0, i = 0; i < pgo->chiSymbolCursor; i++) {
206
count += strlen( pgo->chiSymbolBuf[ i ].s );
240
for ( count = 0, i = 0; i < ctx->output->chiSymbolCursor; i++) {
241
count += strlen( (const char *) ctx->output->chiSymbolBuf[ i ].s) - 3 < 0 ? 1 : 2;
208
243
move( x, count );
211
246
int main( int argc, char *argv[] )
213
ChewingConf *cf = (ChewingConf *) malloc( sizeof( ChewingConf ) );
214
ChewingData *da = (ChewingData *) malloc( sizeof( ChewingData ) );
248
ChewingConfigData config;
218
251
char *prefix = CHEWING_DATA_PREFIX;
253
287
/* Initialize libchewing */
254
cf->kb_type = KBStr2Num( "KB_DEFAULT" );
255
cf->inp_cname = ( char * ) strdup( "�s�ŭ�" );
256
cf->inp_ename = ( char * ) strdup( "Chewing" );
260
288
/* for the sake of testing, we should not change existing hash data */
261
ReadHash( TEST_HASH_DIR );
262
InitChewing( da, cf );
264
config.selectAreaLen = 55;
265
config.maxChiSymbolLen = 16;
289
chewing_Init( prefix, TEST_HASH_DIR );
291
/* Request handle to ChewingContext */
294
/* Set keyboard type */
295
chewing_set_KBType( ctx, chewing_KBStr2Num( "KB_DEFAULT" ) );
297
/* Fill configuration values */
298
config.selectAreaLen = 20;
299
config.maxChiSymbolLen = 16;
266
300
config.bAddPhraseForward = 1;
268
for ( i = 0; i < 10; i++ )
269
config.selKey[ i ] = selKey_define[ i ];
270
SetConfig( da, &config );
302
for ( i = 0; i < 10; i++ )
303
config.selKey[ i ] = selKey_define[ i ];
305
/* Enable the configurations */
306
chewing_Configure( ctx, &config );
272
309
mvaddstr( 0, 0, "Any key to start testing..." );
278
OnKeyLeft( da, &gOut );
315
chewing_handle_Left( ctx );
279
316
fprintf( fout, "<L>" );
282
OnKeyShiftLeft( da, &gOut );
319
chewing_handle_ShiftLeft( ctx );
283
320
fprintf( fout, "<SL>" );
286
OnKeyRight( da, &gOut );
323
chewing_handle_Right( ctx );
287
324
fprintf( fout, "<R>" );
290
OnKeyShiftRight( da, &gOut );
327
chewing_handle_ShiftRight( ctx );
291
328
fprintf( fout, "<SR>" );
294
OnKeyUp( da, &gOut );
331
chewing_handle_Up( ctx );
295
332
fprintf( fout, "<U>" );
298
OnKeyDown( da, &gOut );
335
chewing_handle_Down( ctx );
299
336
fprintf( fout, "<D>" );
302
OnKeySpace( da, &gOut );
339
chewing_handle_Space( ctx );
303
340
fprintf( fout, " " );
306
OnKeyEnter( da, &gOut );
343
chewing_handle_Enter( ctx );
307
344
fprintf( fout, "<E>" );
309
346
case KEY_BACKSPACE:
310
OnKeyBackspace( da, &gOut );
347
chewing_handle_Backspace( ctx );
311
348
fprintf( fout, "<B>" );
314
OnKeyEsc( da, &gOut );
351
chewing_handle_Esc( ctx );
315
352
fprintf( fout, "<EE>" );
318
OnKeyDel( da, &gOut );
355
chewing_handle_Del( ctx );
319
356
fprintf( fout, "<DC>" );
322
OnKeyHome( da, &gOut );
359
chewing_handle_Home( ctx );
323
360
fprintf( fout, "<H>" );
326
OnKeyEnd( da, &gOut );
363
chewing_handle_End( ctx );
327
364
fprintf( fout, "<EN>" );
330
OnKeyTab( da, &gOut );
367
chewing_handle_Tab( ctx );
331
368
fprintf( fout, "<T>" );
343
380
add_phrase_length = ( ch - CTRL_0 + '0' );
381
chewing_handle_CtrlNum( ctx, add_phrase_length );
348
382
fprintf( fout, "<C%c>", add_phrase_length );
352
OnKeyCapslock(da, &gOut);
355
384
case KEY_CTRL_('B'): /* emulate CapsLock */
356
OnKeyCapslock(da, &gOut);
385
chewing_handle_Capslock( ctx );
357
386
fprintf( fout, "<CB>");
359
388
case KEY_CTRL_('D'):
390
case KEY_CTRL_('H'): /* emulate Shift */
391
if ( chewing_get_ShapeMode( ctx ) == FULLSHAPE_MODE )
392
chewing_set_ShapeMode( ctx, HALFSHAPE_MODE );
394
chewing_set_ShapeMode( ctx, FULLSHAPE_MODE );
362
OnKeyDefault( da, (char) ch, &gOut );
397
chewing_handle_Default( ctx, (char) ch );
363
398
fprintf( fout, "%c", (char) ch );
366
401
drawline( 0, 0 );
367
show_edit_buffer( 1, 0, &gOut );
402
show_edit_buffer( 1, 0, ctx );
368
403
drawline( 2, 0 );
369
show_interval_buffer( 3, 0, &gOut );
404
show_interval_buffer( 3, 0, ctx );
370
405
drawline( 4, 0 );
371
show_choose_buffer( 5, 0, &gOut );
406
show_choose_buffer( 5, 0, ctx );
372
407
drawline( 6, 0 );
373
show_zuin_buffer( 7, 0, &gOut );
408
show_zuin_buffer( 7, 0, ctx );
409
show_full_shape( 7, 5, ctx );
374
410
drawline( 8, 0 );
375
411
mvaddstr( 9, 0, "Ctrl + d : leave" );
376
mvaddstr( 9, 20, "Ctrl + b : switch Eng/Chi mode" );
412
mvaddstr( 9, 20, "Ctrl + b : toggle Eng/Chi mode" );
377
413
mvaddstr( 10, 0, "F1, F2, F3, ..., F9 : Add user defined phrase");
378
show_commit_string( &gOut );
379
if ( da->showMsgLen > 0 ) {
380
show_userphrase( 7, 12, gOut.showMsg, gOut.showMsgLen );
383
set_cursor( 1, &gOut );
414
mvaddstr( 11, 0, "Crtl + h : toggle Full/Half shape mode" );
415
show_commit_string( ctx );
416
show_userphrase( 7, 12, ctx );
417
set_cursor( 1, ctx );
422
/* Release Chewing context */
425
/* Termate Chewing services */
388
428
fprintf( fout, "\n" );