Ejemplo n.º 1
0
static void chooseCandidate( ChewingContext *ctx, int toSelect, int key_buf_cursor )
{
	ChewingData *pgdata = ctx->data;
	if ( toSelect ) {
		if ( ! pgdata->bSelect ) {
			ChoiceFirstAvail( pgdata );
		} else {
			if ( pgdata->config.bPhraseChoiceRearward ) {
				int avail_willbe = (pgdata->availInfo.currentAvail > 0) ?
					pgdata->availInfo.currentAvail - 1 :
					pgdata->availInfo.nAvail - 1;
				pgdata->chiSymbolCursor = pgdata->choiceInfo.oldChiSymbolCursor -
					pgdata->availInfo.avail[ avail_willbe ].len;
				if ( chewing_buffer_Len( ctx ) >
						pgdata->choiceInfo.oldChiSymbolCursor ) {
					pgdata->chiSymbolCursor++;
				}
			}
			ChoiceNextAvail( pgdata );
		}
	} else if ( pgdata->symbolKeyBuf[ key_buf_cursor ] ) {
		/* Open Symbol Choice List */
		if ( pgdata->choiceInfo.isSymbol == WORD_CHOICE )
			OpenSymbolChoice( pgdata );
	}
}
Ejemplo n.º 2
0
CHEWING_API int chewing_handle_Down( ChewingContext *ctx )
{
	ChewingData *pgdata = ctx->data;
	ChewingOutput *pgo = ctx->output;
	int toSelect = 0;
	int keystrokeRtn = KEYSTROKE_ABSORB;
	int key_buf_cursor;

	CheckAndResetRange( pgdata );

	if ( ! ChewingIsEntering( pgdata ) ) {
		keystrokeRtn = KEYSTROKE_IGNORE;
	}

	key_buf_cursor = pgdata->chiSymbolCursor;
	if ( pgdata->chiSymbolCursor == pgdata->chiSymbolBufLen )
		key_buf_cursor--;

	/* see if to select */
	if ( ChewingIsChiAt( key_buf_cursor, pgdata ) )
			toSelect = 1;

	if ( toSelect ) {
		if( ! pgdata->bSelect ) {
			ChoiceFirstAvail( pgdata );
		}
		else {
			ChoiceNextAvail( pgdata );
		}
	} 
	else if ( pgdata->symbolKeyBuf[ key_buf_cursor ] ) {
		/* Open Symbol Choice List */
		if ( ! pgdata->choiceInfo.isSymbol )
			OpenSymbolChoice( pgdata );
	}

	MakeOutputWithRtn( pgo, pgdata, keystrokeRtn );
	return 0;
}
Ejemplo n.º 3
0
CHEWING_API int chewing_handle_Space( ChewingContext *ctx )
{
	ChewingData *pgdata = ctx->data;
	ChewingOutput *pgo = ctx->output;
	int keystrokeRtn = KEYSTROKE_ABSORB;
	int toSelect = 0;
	int rtn, key_buf_cursor;
	int bQuickCommit = 0;

	/* check if Old Chewing style */
	if ( ! pgdata->config.bSpaceAsSelection ) {
		return chewing_handle_Default( ctx, ' ' );
	}

	CheckAndResetRange( pgdata );

	if ( pgdata->bSelect ) {
		if ( pgdata->choiceInfo.pageNo < ( pgdata->choiceInfo.nPage - 1 ) ) {
			return chewing_handle_Right( ctx );
		}
	}

	if ( ! ChewingIsEntering( pgdata ) ) {
		if ( pgdata->bFullShape ) {
			rtn = FullShapeSymbolInput( ' ', pgdata );
		}
		else {
			rtn = SymbolInput( ' ', pgdata );
		}
		pgo->commitStr[ 0 ] = pgdata->chiSymbolBuf[ 0 ];
		pgo->nCommitStr = 1;
		pgdata->chiSymbolBufLen = 0;
		pgdata->chiSymbolCursor = 0;
		keystrokeRtn = KEYSTROKE_COMMIT;
	} 
	else if ( pgdata->bChiSym != CHINESE_MODE ) {
		/* see if buffer contains nothing */
		if ( pgdata->chiSymbolBufLen == 0 ) {
			bQuickCommit = 1;
		}

		if ( pgdata->bFullShape ) {
			rtn = FullShapeSymbolInput( ' ', pgdata );
		}
		else {
			rtn = SymbolInput( ' ', pgdata );
		}

		keystrokeRtn = KEYSTROKE_ABSORB;
		if ( rtn == SYMBOL_KEY_ERROR ) {
			keystrokeRtn = KEYSTROKE_IGNORE;
			/*
			 * If the key is not a printable symbol, 
			 * then it's wrong to commit it.
			 */
			bQuickCommit = 0;
		} 
		else {
			keystrokeRtn = KEYSTROKE_ABSORB;
		}

		if ( ! bQuickCommit ) {
			CallPhrasing( pgdata );
			if( ReleaseChiSymbolBuf( pgdata, pgo ) != 0 )
				keystrokeRtn = KEYSTROKE_COMMIT;
		}
		/* Quick commit */
		else {
			DEBUG_OUT(
				"\t\tQuick commit buf[0]=%c\n", 
				pgdata->chiSymbolBuf[ 0 ].s[ 0 ] );
			pgo->commitStr[ 0 ] = pgdata->chiSymbolBuf[ 0 ]; 
			pgo->nCommitStr = 1;
			pgdata->chiSymbolBufLen = 0;
			pgdata->chiSymbolCursor = 0;
			keystrokeRtn = KEYSTROKE_COMMIT;
		}
	}
	else {
		rtn = ZuinPhoInput( &( pgdata->zuinData ), ' ' );
		switch ( rtn ) {
			case ZUIN_ABSORB:
				keystrokeRtn = KEYSTROKE_ABSORB;
				break;
			case ZUIN_COMMIT:
				AddChi( pgdata->zuinData.phone, pgdata );
				CallPhrasing( pgdata );
				break;
			case ZUIN_NO_WORD:
				keystrokeRtn = KEYSTROKE_BELL | KEYSTROKE_ABSORB;
				break;
			case ZUIN_KEY_ERROR:
			case ZUIN_IGNORE:
				key_buf_cursor = pgdata->chiSymbolCursor;
				if ( pgdata->chiSymbolCursor == pgdata->chiSymbolBufLen )
					key_buf_cursor--;

				/* see if to select */
				if ( ChewingIsChiAt( key_buf_cursor, pgdata ) )
					toSelect = 1;

				if ( toSelect ) {
					if ( ! pgdata->bSelect )
						ChoiceFirstAvail( pgdata );
					else
						ChoiceNextAvail( pgdata );
				}
				else if ( pgdata->symbolKeyBuf[ key_buf_cursor ] ) {
					/* Open Symbol Choice List */
					if( ! pgdata->choiceInfo.isSymbol )
						OpenSymbolChoice( pgdata );
				}
				break;
		}
	}

	MakeOutputWithRtn( pgo, pgdata, keystrokeRtn );
	return 0;
}
Ejemplo n.º 4
0
CHEWING_API int chewing_handle_Default( ChewingContext *ctx, int key )
{
	ChewingData *pgdata = ctx->data;
	ChewingOutput *pgo = ctx->output;
	int rtn, num;
	int keystrokeRtn = KEYSTROKE_ABSORB;
	int bQuickCommit = 0;

	/* Update lifetime */
	chewing_lifetime++;

	/* Skip the special key */
	if ( key & 0xFF00 ) {
		keystrokeRtn = KEYSTROKE_IGNORE;
		goto End_KeyDefault;
	}

	/* We ignore non-printable input */
	if ( ! isprint( key ) )
		goto End_KeyDefault;

	CheckAndResetRange( pgdata );

	DEBUG_CHECKPOINT();
	DEBUG_OUT( "   key=%d", key );

	/* Dvorak Hsu */
	if ( pgdata->zuinData.kbtype == KB_DVORAK_HSU ) {
		key = dvorak_convert( key );
	}

	/* selecting */
	if ( pgdata->bSelect ) {
		if ( key == ' ' )
			return chewing_handle_Right( ctx );
		/* num starts from 0 */
		num = CountSelKeyNum( key, pgdata );
		if ( num >= 0 ) {
			DoSelect( pgdata, num );
			goto End_keyproc;
		}
		
		/* Otherwise, use 'j' and 'k' for paging in selection mode */
		DEBUG_OUT(
			"\t\tchecking paging key, got '%c'\n",
			key );
		switch ( key ) {
			case 'j':
			case 'J':
				if ( pgdata->chiSymbolCursor > 0 ) {
					if ( ! ChewingIsEntering( pgdata ) ) {
						keystrokeRtn = KEYSTROKE_IGNORE;
					}
					CheckAndResetRange( pgdata );
					pgdata->chiSymbolCursor--;
					ChoiceFirstAvail( pgdata );
				}
				goto End_Paging;
			case 'k':
			case 'K':
				if ( pgdata->chiSymbolCursor < pgdata->chiSymbolBufLen ) {
					if ( ! ChewingIsEntering( pgdata ) ) {
						keystrokeRtn = KEYSTROKE_IGNORE;
					}
					CheckAndResetRange( pgdata );
					pgdata->chiSymbolCursor++;
					ChoiceFirstAvail( pgdata );
				}
				goto End_Paging;
			default:
				break;
		}
	}
	/* editing */
	else {
		if ( pgdata->bChiSym == CHINESE_MODE ) {
			if ( pgdata->config.bEasySymbolInput != 0 ) {
				EasySymbolInput( key, pgdata, pgo );
				goto End_keyproc;
			}

			/* open symbol table */
			if ( key == '`' ) {
				pgdata->bSelect = 1;
				pgdata->choiceInfo.oldChiSymbolCursor = pgdata->chiSymbolCursor;

				HaninSymbolInput(
					&( pgdata->choiceInfo ),
					&( pgdata->availInfo ),
					pgdata->phoneSeq,
					pgdata->config.candPerPage );
				goto End_KeyDefault;
			}

			rtn = ZuinPhoInput( &( pgdata->zuinData ), key );
			DEBUG_OUT(
				"\t\tChinese mode key, "
				"ZuinPhoInput return value = %d\n", 
				rtn );
			DEBUG_FLUSH;
			
			if ( rtn == ZUIN_KEY_ERROR )
				rtn = SpecialSymbolInput( key, pgdata );
			switch ( rtn ) {
				case ZUIN_ABSORB:
					keystrokeRtn = KEYSTROKE_ABSORB;
					break;
				case ZUIN_COMMIT:
					AddChi( pgdata->zuinData.phone, pgdata );
					break;
				case ZUIN_NO_WORD:
					keystrokeRtn = KEYSTROKE_BELL | KEYSTROKE_ABSORB;
					break;
				case ZUIN_KEY_ERROR:
				case ZUIN_IGNORE:
					DEBUG_OUT(
						"\t\tbefore isupper(key),key=%d\n", 
						key );
					/* change upper case into lower case */
					if ( isupper( key ) ) 
						key = tolower( key );

					DEBUG_OUT(
						"\t\tafter isupper(key),key=%d\n", 
						key );

					/* see if buffer contains nothing */
					if ( pgdata->chiSymbolBufLen == 0 ) {
						bQuickCommit = 1;
					}

					if ( pgdata->config.bEasySymbolInput == 0 ) {
						if ( pgdata->bFullShape )
							rtn = FullShapeSymbolInput( key, pgdata );
						else
							rtn = SymbolInput( key, pgdata );
					}

					if ( rtn == SYMBOL_KEY_ERROR ) {
						keystrokeRtn = KEYSTROKE_IGNORE;
						/*
						 * If the key is not a printable symbol, 
						 * then it's wrong to commit it.
						 */
						bQuickCommit = 0;
					}
					else
						keystrokeRtn = KEYSTROKE_ABSORB;

					break;

			}
		}
		/* English mode */
		else {
			/* see if buffer contains nothing */
			if ( pgdata->chiSymbolBufLen == 0 ) {
				bQuickCommit = 1;
			}
			if ( pgdata->bFullShape ) {
				rtn = FullShapeSymbolInput( key, pgdata );
			}
			else {
				rtn = SymbolInput( key, pgdata );
			}

			if ( rtn == SYMBOL_KEY_ERROR ) {
				keystrokeRtn = KEYSTROKE_IGNORE;
				bQuickCommit = 0;
			}
		}
	}

End_keyproc:
	if ( ! bQuickCommit ) {
		CallPhrasing( pgdata );
		if ( ReleaseChiSymbolBuf( pgdata, pgo ) != 0 )
			keystrokeRtn = KEYSTROKE_COMMIT;
	}
	/* Quick commit */
	else {
		DEBUG_OUT(
				"\t\tQuick commit buf[0]=%c\n", 
				pgdata->chiSymbolBuf[ 0 ].s[ 0 ] );
		pgo->commitStr[ 0 ] = pgdata->chiSymbolBuf[ 0 ]; 
		pgo->nCommitStr = 1;
		pgdata->chiSymbolBufLen = 0;
		pgdata->chiSymbolCursor = 0;
		keystrokeRtn = KEYSTROKE_COMMIT;
	}

	if ( pgdata->phrOut.nNumCut > 0 ) {
		int i;
		for ( i = 0; i < pgdata->phrOut.nDispInterval; i++ ) {
			pgdata->bUserArrBrkpt[ pgdata->phrOut.dispInterval[ i ].from ] = 1;
			pgdata->bUserArrBrkpt[ pgdata->phrOut.dispInterval[ i ].to ] = 1;
		}
		pgdata->phrOut.nNumCut = 0;
	}

End_KeyDefault:
	CallPhrasing( pgdata );
End_Paging:
	MakeOutputWithRtn( pgo, pgdata, keystrokeRtn );
	return 0;
}