⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scim_chewing_imengine.cpp

📁 scim 修改过的可以在手机上运行的代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * SCIM-chewing - *	Intelligent Chinese Phonetic IM Engine for SCIM. * * Copyright (c) 2004, 2005, 2006 *	SCIM-chewing Developers. See ChangeLog for details. * * See the file "COPYING" for information on usage and redistribution * of this file. */#define Uses_SCIM_UTILITY#define Uses_SCIM_IMENGINE#define Uses_SCIM_CONFIG_BASE#define Uses_SCIM_CONFIG_PATH#define Uses_SCIM_LOOKUP_TABLE#define Uses_SCIM_IMENGINE_MODULE#define Uses_SCIM_ICONV#define Uses_SCIM_DEBUG#define Uses_SCIM_C_STRING#ifdef HAVE_CONFIG_H#include <config.h>#endif#ifdef HAVE_GETTEXT  #include <libintl.h>  #define _(String) dgettext(PACKAGE,String)  #define N_(String) (String)#else  #define _(String) (String)  #define N_(String) (String)  #define bindtextdomain(Package,Directory)  #define textdomain(domain)  #define bind_textdomain_codeset(domain,codeset)#endif#define SCIM_PROP_CHIENG \	"/IMEngine/Chinese/Chewing/ChiEngMode"#define SCIM_PROP_LETTER \	"/IMEngine/Chinese/Chewing/FullHalfLetter"#define SCIM_CHEWING_SELECTION_KEYS_NUM_DEF 9static int _selection_keys_num;#include <scim.h>#include <chewing/chewing.h>#include "scim_chewing_imengine.h"#include "scim_chewing_config_entry.h"using namespace scim;static IMEngineFactoryPointer _scim_chewing_factory( 0 );static ConfigPointer _scim_config( 0 );static Property _chieng_property (SCIM_PROP_CHIENG, "");static Property _letter_property (SCIM_PROP_LETTER, "");//static Property _punct_property  (SCIM_PROP_PUNCT, _("Full/Half Punct"));extern "C" {	void scim_module_init()	{		bindtextdomain (GETTEXT_PACKAGE, SCIM_CHEWING_LOCALEDIR);		bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");	}	void scim_module_exit()	{		_scim_config.reset();		/* New API introduced in libchewing 0.2.7 */		chewing_Terminate();	}	unsigned int scim_imengine_module_init( const ConfigPointer& config )	{		_chieng_property.set_tip (_("The status of the current input method. Click to change it."));		_chieng_property.set_label (_("Eng"));		_letter_property.set_label (_("Half"));		_scim_config = config;		return 1;	}	IMEngineFactoryPointer scim_imengine_module_create_factory(			uint32 engine )	{		if ( engine != 0 )			return IMEngineFactoryPointer( 0 );		if ( _scim_chewing_factory.null() ) {			ChewingIMEngineFactory *factory =				new ChewingIMEngineFactory( _scim_config );			if ( factory && factory->valid() )				_scim_chewing_factory = factory;			else				delete factory;		}		return _scim_chewing_factory;	}}/** * Implementation of ChewingIMEngineFactory. */ChewingIMEngineFactory::ChewingIMEngineFactory( const ConfigPointer& config )	: m_config( config ),	  m_valid( false ){	reload_config( config );	set_languages( "zh_TW,zh_HK,zh_SG" );	m_valid = init();	m_reload_signal_connection = m_config->signal_connect_reload (			slot (this, &ChewingIMEngineFactory::reload_config));}bool ChewingIMEngineFactory::init(){	char prefix[] = CHEWING_DATADIR;	char hash_postfix[] = "/.chewing/";	chewing_Init(prefix, (char *)(scim_get_home_dir() + hash_postfix).c_str() );	return true;}static char *chewing_preedit_bgcolor[] = {	SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_DEF_1,	SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_DEF_2,	SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_DEF_3,	SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_DEF_4,	SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_DEF_5};void ChewingIMEngineFactory::reload_config( const ConfigPointer &scim_config ){	String str;    SCIM_DEBUG_IMENGINE( 2 ) <<        "ReloadConfig\n";	// Load Chi/Eng mode keys    SCIM_DEBUG_IMENGINE( 2 ) <<        "Load Chi/Eng mode keys\n";	str = m_config->read(			String( SCIM_CONFIG_IMENGINE_CHEWING_CHI_ENG_KEY ),			String( "Shift+Shift_L+KeyRelease" ) + 			String( "Shift+Shift_R+KeyRelease" ) );	scim_string_to_key_list( m_chi_eng_keys, str );	// Load keyboard type    SCIM_DEBUG_IMENGINE( 2 ) <<        "Load keyboard type\n";	m_KeyboardType = m_config->read (			String( SCIM_CONFIG_IMENGINE_CHEWING_USER_KB_TYPE ),			String( "KB_DEFAULT" ));	// SCIM_CONFIG_IMENGINE_CHEWING_USER_SELECTION_KEYS	m_selection_keys = m_config->read(                	String( SCIM_CONFIG_IMENGINE_CHEWING_USER_SELECTION_KEYS ),                	String( SCIM_CONFIG_IMENGINE_CHEWING_SELECTION_KEYS ) );	// SCIM_CHEWING_SELECTION_KEYS_NUM	m_selection_keys_num = _selection_keys_num = m_config->read(			String( SCIM_CHEWING_SELECTION_KEYS_NUM ),			9);	// SCIM_CONFIG_IMENGINE_CHEWING_ADD_PHRASE_FORWARD	m_add_phrase_forward = m_config->read(			String( SCIM_CONFIG_IMENGINE_CHEWING_ADD_PHRASE_FORWARD ),			false);	// SCIM_CONFIG_IMENGINE_CHEWING_ESC_CLEAN_ALL_BUFFER	m_esc_clean_all_buffer = m_config->read(			String( SCIM_CONFIG_IMENGINE_CHEWING_ESC_CLEAN_ALL_BUFFER ),			false);	// SCIM_CONFIG_IMENGINE_CHEWING_SPACE_AS_SELECTION	m_space_as_selection = m_config->read(			String( SCIM_CONFIG_IMENGINE_CHEWING_SPACE_AS_SELECTION ),			true);	// SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_	for (int i = 0; i < SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_NUM; i++) {		int red, green, blue;		char bgcolor_str[64];		String str;		sprintf(bgcolor_str, SCIM_CONFIG_IMENGINE_CHEWING_PREEDIT_BGCOLOR_ "_%d", i + 1);		str = m_config->read(			String(bgcolor_str),			String(chewing_preedit_bgcolor[i] ));		sscanf (str.c_str (), "#%02X%02X%02X", &red, &green, &blue);		m_preedit_bgcolor[i] = SCIM_RGB_COLOR (red, green, blue);	}}ChewingIMEngineFactory::~ChewingIMEngineFactory(){	m_reload_signal_connection.disconnect ();}WideString ChewingIMEngineFactory::get_name() const{	return utf8_mbstowcs( _( "Chewing" ) );}String ChewingIMEngineFactory::get_uuid() const{	return String( "fcff66b6-4d3e-4cf2-833c-01ef66ac6025" );}String ChewingIMEngineFactory::get_icon_file() const{	return String( SCIM_CHEWING_ICON_FILE );}WideString ChewingIMEngineFactory::get_authors() const{	return utf8_mbstowcs( _( "Chewing core team <http://chewing.csie.net>" ) );}WideString ChewingIMEngineFactory::get_credits() const{	return WideString();}WideString ChewingIMEngineFactory::get_help() const{	String help;	String chi_eng_mode_switch;	scim_key_list_to_string( chi_eng_mode_switch, m_chi_eng_keys );	help =	String( _( "Hot Keys:" ) ) +		String( "\n\n  " ) + chi_eng_mode_switch + String( ":\n" ) +		String( _( "    Switch between English/Chinese mode." ) ) +		String( _( "\n\n  Space:\n"			   "    Use space key to select candidate phrases."			   "\n\n  Tab:\n"			   "    Use tab key to dispart or connect a phrase."			   "\n\n  Ctrl + [number]:\n"			   "    Use ctrl + number key to add a user-defined phrase.\n"			   "    (Here number stands for the length of the user-defined phrase.)"			   "\n\n  Ctrl + 0:\n"			   "    Use Ctrl + 0 to specify symbolic input."		) );	return utf8_mbstowcs( help );}IMEngineInstancePointer ChewingIMEngineFactory::create_instance(		const String& encoding, int id ){	return new ChewingIMEngineInstance( this, encoding, id );}bool ChewingIMEngineFactory::validate_encoding( const String& encoding ) const{	return IMEngineFactoryBase::validate_encoding( encoding );}bool ChewingIMEngineFactory::validate_locale( const String& locale ) const{	return IMEngineFactoryBase::validate_locale( locale );}/** * Implementation of ChewingIMEngineInstance */ChewingIMEngineInstance::ChewingIMEngineInstance(		ChewingIMEngineFactory *factory, 		const String& encoding, int id )	: IMEngineInstanceBase( factory, encoding, id ),	  m_factory( factory ){    SCIM_DEBUG_IMENGINE( 2 ) <<        "Create IMEngineInstance\n";	ctx = chewing_new();	reload_config( m_factory->m_config );	m_lookup_table.init( m_factory->m_selection_keys,			     m_factory->m_selection_keys_num );	m_reload_signal_connection =		m_factory->m_config->signal_connect_reload(			slot( this, &ChewingIMEngineInstance::reload_config ) );}void ChewingIMEngineInstance::reload_config( const ConfigPointer& scim_config ){    SCIM_DEBUG_IMENGINE( 2 ) <<        "IMEngine Instance ReloadConfig\n";	// Reset all data.	reset();	config.selectAreaLen = m_factory->m_selection_keys_num * 2;	config.maxChiSymbolLen = 16;	// SCIM_CONFIG_IMENGINE_CHEWING_ADD_PHRASE_FORWARD	config.bAddPhraseForward = m_factory->m_add_phrase_forward ? 0 : 1;	// SCIM_CONFIG_IMENGINE_CHEWING_SPACE_AS_SELECTION	config.bSpaceAsSelection = m_factory->m_space_as_selection ? 1 : 0;	// SCIM_CONFIG_IMENGINE_CHEWING_ESC_CLEAN_ALL_BUFFER	config.bEscCleanAllBuf = m_factory->m_esc_clean_all_buffer ? 0 : 1;	//SetConfig( &da, &config );	chewing_Configure( ctx, &config );}ChewingIMEngineInstance::~ChewingIMEngineInstance(){	chewing_free( ctx );	m_reload_signal_connection.disconnect();}bool ChewingIMEngineInstance::process_key_event( const KeyEvent& key ){    SCIM_DEBUG_IMENGINE( 2 ) <<        "Process Key Event\n";	if ( match_key_event( m_factory->m_chi_eng_keys, key ) ) {		m_prev_key = key;		trigger_property( SCIM_PROP_CHIENG );		SCIM_DEBUG_IMENGINE( 2 ) <<			"Matcg Chi/Eng Key, End Process\n";		return true;	}	m_prev_key = key;	/* 	 * This is a workaround against the known issue in OpenOffice with 	 * GTK+ im module hanlding key pressed/released events.	 */	if ( key.is_key_release() ) {        SCIM_DEBUG_IMENGINE( 2 ) <<            "Key Release, End Process Key\n";		return true;    }        if ( key.mask == 0 ) {		switch ( key.code ) {			case SCIM_KEY_Left:				chewing_handle_Left( ctx );				break;			case SCIM_KEY_Right:				chewing_handle_Right( ctx );				break;			case SCIM_KEY_Up:				chewing_handle_Up( ctx );				break;			case SCIM_KEY_Down:				chewing_handle_Down( ctx );				break;			case SCIM_KEY_space:				chewing_handle_Space( ctx );				break;			case SCIM_KEY_Return:				chewing_handle_Enter( ctx );				break;			case SCIM_KEY_BackSpace:				chewing_handle_Backspace( ctx );				break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -