コード例 #1
0
ファイル: chewingio.c プロジェクト: blue119/libchewing
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 );
	}
}
コード例 #2
0
ファイル: chewingio.c プロジェクト: shaform/ibus-freearray
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;
}
コード例 #3
0
ファイル: chewingio.c プロジェクト: shaform/ibus-freearray
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;
}