static void
setup_romaji_window_value (ScimAnthyTableEditor *editor)
{
    GtkTreeView *treeview = GTK_TREE_VIEW (editor->treeview);
    GtkTreeModel *model = gtk_tree_view_get_model (treeview);
    GtkListStore *store = GTK_LIST_STORE (model);

    gtk_list_store_clear (store);

    std::vector<String> keys;
    __user_style_file.get_key_list (keys, __romaji_fund_table);
    if (keys.empty ()) {
        load_romaji_theme ();
        __user_style_file.get_key_list (keys, __romaji_fund_table);
    }

    std::vector<String>::iterator it;
    for (it = keys.begin (); it != keys.end (); it++) {
        std::vector<WideString> value;
        __user_style_file.get_string_array (value, __romaji_fund_table, *it);
        String result, cont;
        if (value.size () > 0) result = utf8_wcstombs(value[0]);
        if (value.size () > 1) cont   = utf8_wcstombs(value[1]);
        GtkTreeIter iter;
        gtk_list_store_append (store, &iter);
        gtk_list_store_set (store, &iter,
                            0, it->c_str (),
                            1, result.c_str (),
                            -1);
    }
}
Example #2
0
void
PinyinPhraseLib::dump_content (std::ostream &os, int minlen, int maxlen)
{
	PinyinPhraseLessThanByOffset less_op (this, m_pinyin_key_less);
	if (minlen < 1) minlen = 1;
	if (maxlen > SCIM_PHRASE_MAX_LENGTH) maxlen = SCIM_PHRASE_MAX_LENGTH;

	for (int i = minlen; i <= maxlen; ++ i) {
		PinyinPhraseOffsetVector offsets;
		for (PinyinPhraseTable::iterator tit = m_phrases [i-1].begin (); tit != m_phrases [i-1].end (); ++ tit) {
			PinyinPhraseOffsetVector::iterator begin = tit->get_vector ().begin ();
			PinyinPhraseOffsetVector::iterator end = tit->get_vector ().end ();
			offsets.insert (offsets.end (), begin, end);
		}

		std::sort (offsets.begin (), offsets.end (), less_op);

		for (PinyinPhraseOffsetVector::iterator oit = offsets.begin (); oit != offsets.end (); ++ oit) {
			bool before = false, after = false;

			os << get_phrase (oit->first).frequency () << "\t";
			if (oit > offsets.begin () && get_phrase ((oit-1)->first) == get_phrase (oit->first)) before = true;
			if (oit < offsets.end () - 1 && get_phrase ((oit+1)->first) == get_phrase (oit->first)) after = true;
			if (before || after) os << "+";
			else os << "-";
			os << utf8_wcstombs (get_phrase (oit->first).get_content ());
			os << " =";
			for (unsigned int j = 0; j < get_phrase (oit->first).length (); ++ j)
				os << " " << get_pinyin_key (oit->second + j);
			os << "\n";
		}
	}
}
Example #3
0
 void update_aux_string      (int icid, const WideString &str, const AttributeList &attrs)
 {
     if (m_send_refcount > 0 && m_current_icid == icid) {
         m_send_trans.put_command (SCIM_TRANS_CMD_UPDATE_AUX_STRING);
         m_send_trans.put_data (utf8_wcstombs (str));
         m_send_trans.put_data (attrs);
     }
 }
void
HangulInstance::update_candidates ()
{
    m_lookup_table.clear ();
    m_candidate_comments.clear ();

    HanjaList* list = NULL;

    // search for symbol character
    // key string for symbol character is like:
    //  'ㄱ', 'ㄴ', 'ㄷ', etc
    WideString preeditw = get_preedit_string();
    if (preeditw.length() == 1) {
	String key = utf8_wcstombs(preeditw);
	list = hanja_table_match_suffix(m_factory->m_symbol_table, key.c_str());
    }

    // search for hanja
    if (list == NULL) {
	String str = get_candidate_string();
	SCIM_DEBUG_IMENGINE(1) << "candidate string: " << str << "\n";

	if (str.length() > 0) {
	    if (is_hanja_mode() || m_factory->m_commit_by_word) {
		list = hanja_table_match_prefix(m_factory->m_hanja_table,
						    str.c_str());
	    } else {
		list = hanja_table_match_suffix(m_factory->m_hanja_table,
						    str.c_str());
	    }
	}
    } 
    
    if (list != NULL) {
	int n = hanja_list_get_size(list);
	for (int i = 0; i < n; ++i) {
	    const char* value = hanja_list_get_nth_value(list, i);
	    const char* comment = hanja_list_get_nth_comment(list, i);
	    WideString candidate = utf8_mbstowcs(value, -1);
	    m_lookup_table.append_candidate(candidate);
	    m_candidate_comments.push_back(String(comment));
	}

	m_lookup_table.set_page_size (9);
	m_lookup_table.show_cursor ();

	update_lookup_table (m_lookup_table);
	show_lookup_table ();

	hangul_update_aux_string ();

	hanja_list_delete(list);
    }

    if (m_lookup_table.number_of_candidates() <= 0) {
	delete_candidates();
    }
}
Example #5
0
void
StandardIMInstance::imm_update_property        (const IME_InputContext   *ic,
                                                const IME_Property       *property)
{
    if (ic && ic->id >= 0 && property) {
        StandardIMInstance *inst = __global->find_instance (ic->id);
        if (inst) {
            Property prop;
            prop.set_key (String (property->key));
            prop.set_icon (String (property->icon));
            prop.set_label (utf8_wcstombs (inst->m_factory->convert_string (String (property->label))));
            prop.set_tip (utf8_wcstombs (inst->m_factory->convert_string (String (property->tip))));
            prop.set_active ((property->state & IME_PROPERTY_ACTIVE) != 0);
            prop.show ((property->state & IME_PROPERTY_VISIBLE) != 0);
            inst->update_property (prop);
        }
    }
}
Example #6
0
/**
 * @brief Load all ISEs to initialize.
 *
 * @param type The loading ISE type.
 * @param config The config pointer for loading keyboard ISE.
 * @param uuids The ISE uuid list.
 * @param names The ISE name list.
 * @param module_names The ISE module name list.
 * @param langs The ISE language list.
 * @param icons The ISE icon list.
 * @param modes The ISE type list.
 * @param options The ISE option list.
 * @param ise_list The already loaded ISE list.
 */
void isf_get_factory_list (LOAD_ISE_TYPE  type,
                           const ConfigPointer &config,
                           std::vector<String> &uuids,
                           std::vector<String> &names,
                           std::vector<String> &module_names,
                           std::vector<String> &langs,
                           std::vector<String> &icons,
                           std::vector<TOOLBAR_MODE_T> &modes,
                           std::vector<uint32> &options,
                           const std::vector<String> &ise_list)
{
    uuids.clear ();
    names.clear ();
    module_names.clear ();
    langs.clear ();
    icons.clear ();
    modes.clear ();
    options.clear ();
    _groups.clear ();

    if (type != HELPER_ONLY) {
        /* Add "English/Keyboard" factory first. */
        IMEngineFactoryPointer factory = new ComposeKeyFactory ();
        uuids.push_back (factory->get_uuid ());
        names.push_back (utf8_wcstombs (factory->get_name ()));
        module_names.push_back (ENGLISH_KEYBOARD_MODULE);
        langs.push_back (isf_get_normalized_language (factory->get_language ()));
        icons.push_back (factory->get_icon_file ());
        modes.push_back (TOOLBAR_KEYBOARD_MODE);
        options.push_back (0);
        factory.reset ();
    }

    String user_file_name = String (USER_ENGINE_FILE_NAME);
    FILE *engine_list_file = fopen (user_file_name.c_str (), "r");
    if (engine_list_file == NULL) {
        std::cerr <<  user_file_name << " doesn't exist.\n";
        return;
    }

    char buf[MAXLINE];
    while (fgets (buf, MAXLINE, engine_list_file) != NULL) {
        ISEINFO info;
        isf_get_ise_info_from_string (buf, info);
        if (info.mode == TOOLBAR_HELPER_MODE || type != HELPER_ONLY) {
            names.push_back (info.name);
            uuids.push_back (info.uuid);
            module_names.push_back (info.module);
            langs.push_back (info.language);
            icons.push_back (info.icon);
            modes.push_back (info.mode);
            options.push_back (info.option);
        }
    }

    fclose (engine_list_file);
}
Example #7
0
static void fcopy_send_data(void)
{
	struct hv_start_fcopy *smsg_out = &fcopy_transaction.message;
	int operation = fcopy_transaction.fcopy_msg->operation;
	struct hv_start_fcopy *smsg_in;

	/*
	 * The  strings sent from the host are encoded in
	 * in utf16; convert it to utf8 strings.
	 * The host assures us that the utf16 strings will not exceed
	 * the max lengths specified. We will however, reserve room
	 * for the string terminating character - in the utf16s_utf8s()
	 * function we limit the size of the buffer where the converted
	 * string is placed to W_MAX_PATH -1 to guarantee
	 * that the strings can be properly terminated!
	 */

	switch (operation) {
	case START_FILE_COPY:
		memset(smsg_out, 0, sizeof(struct hv_start_fcopy));
		smsg_out->hdr.operation = operation;
		smsg_in = (struct hv_start_fcopy *)fcopy_transaction.fcopy_msg;

		utf8_wcstombs((__u8 *)smsg_out->file_name,
			      (wchar_t *)smsg_in->file_name,
			      W_MAX_PATH - 1);

		utf8_wcstombs((__u8 *)smsg_out->path_name,
			      (wchar_t *)smsg_in->path_name,
			      W_MAX_PATH - 1);

		smsg_out->copy_flags = smsg_in->copy_flags;
		smsg_out->file_size = smsg_in->file_size;
		break;

	default:
		break;
	}
	up(&fcopy_transaction.read_sema);
	return;
}
Example #8
0
std::ostream& utf8_write_phase_string(std::ostream& os,PhraseString& str)
{	
	std::vector<__u8> s;
	int size=str.size()*4;
	s.reserve(size); //utf8
	ucs4_t*p=&str[0];
	int len=utf8_wcstombs(&s[0],p,size);
	for(int i=0;i<len;i++){
		os<<s[i];
	}
	return os;	
}
Example #9
0
void
StandardIMInstance::imm_register_properties    (const IME_InputContext   *ic,
                                                const IME_PropertiesList *properties)
{
    if (ic && ic->id >= 0 && properties) {
        StandardIMInstance *inst = __global->find_instance (ic->id);
        if (inst) {
            PropertyList prop_list;
            if (properties->nr_properties > 0 && properties->properties) {
                Property prop;
                for (int i = 0; i < properties->nr_properties; ++i) {
                    prop.set_key (String (properties->properties [i].key));
                    prop.set_icon (String (properties->properties [i].icon));
                    prop.set_label (utf8_wcstombs (inst->m_factory->convert_string (String (properties->properties [i].label))));
                    prop.set_tip (utf8_wcstombs (inst->m_factory->convert_string (String (properties->properties [i].tip))));
                    prop.set_active ((properties->properties [i].state & IME_PROPERTY_ACTIVE) != 0);
                    prop.show ((properties->properties [i].state & IME_PROPERTY_VISIBLE) != 0);
                    prop_list.push_back (prop);
                }
            }
            inst->register_properties (prop_list);
        }
    }
}
void
CannaJRKanji::set_mode_line (void)
{
    if (m_enabled) {
        int max_mode_len = jrKanjiControl(m_context_id,
                                          KC_QUERYMAXMODESTR, 0);
        unsigned char current_mode[max_mode_len];
        jrKanjiControl(m_context_id, KC_QUERYMODE, (char *) current_mode);
        WideString dest;
        m_iconv.convert (dest, (const char *) current_mode);
        m_properties[0].set_label (utf8_wcstombs(dest).c_str());
        m_canna->register_properties (m_properties);
    } else {
        m_properties[0].set_label (_("[Off]"));
        m_canna->register_properties (m_properties);
    }
}
Example #11
0
void ISFSetupWin::create_ise_option_main (const char *str)
{
    if (!_setup_ui)
        _setup_ui = new SetupUI (_config);
    if (!_setup_ui)
        return;

    String setup_module_name;
    setup_module_name = utf8_wcstombs (utf8_mbstowcs (str)) + String ("-imengine-setup");

    SetupModule *setup_module = new SetupModule (setup_module_name);

    if (setup_module) {
        _setup_ui->add_module (setup_module);
        delete setup_module;
    }
}
Example #12
0
void
PinyinPhraseLib::create_pinyin_index ()
{
	if (!m_pinyin_table || !m_pinyin_table->size()) return;

	clear_phrase_index ();

	uint32 pinyin_offset = 0;

	WideString content;
	Phrase phrase;

	for (uint32 i=0; i<m_phrase_lib.number_of_phrases (); i++) {
		phrase = m_phrase_lib.get_phrase_by_index (i);

		content = phrase.get_content ();

		std::vector<PinyinKeyVector> key_vv;
		m_pinyin_table->find_key_strings (key_vv, content);

		for (uint32 j=0; j<key_vv.size(); j++) {
			for (uint32 k=0; k<key_vv[j].size(); k++)
				m_pinyin_lib.push_back (key_vv[j][k]);

			insert_pinyin_phrase_into_index (phrase.get_phrase_offset (), pinyin_offset);

			pinyin_offset = m_pinyin_lib.size ();
		}
#if 0
		if (key_vv.size () > 1 && content.length () > 1) {
			for (uint32 x=0; x<key_vv.size (); x++) {
				std::cerr << phrase.frequency () << "\t| " << 
						utf8_wcstombs (content) << " =";
				for (uint32 y=0; y<key_vv[x].size (); y++)
					std::cerr << " " << key_vv[x][y];
				std::cerr << "\n";
			}
		}
#endif
		std::cout << "." << std::flush;
	}

	sort_phrase_tables ();

	std::cout << "Phrase Number = " << count_phrase_number () << "\n";
}
String
HangulInstance::get_candidate_string()
{
    int cursor = 0;
    if (m_surrounding_text.empty())
	get_surrounding_text(m_surrounding_text, cursor, 10, 0);

    int i; 
    for (i = m_surrounding_text.length() - 1; i >= 0; i--) {
	if (!hangul_is_syllable(m_surrounding_text[i]))
	    break;
    }
    if (i >= 0)
	m_surrounding_text.erase(0, i + 1);

    return utf8_wcstombs(m_surrounding_text + get_preedit_string());
}
Example #14
0
static void test_nls_base(void) {

	wchar_t p=0x20;
	__u8 s=0x01;
	int n=2;
	struct nls_table nls;
	char charset[20]="David";
	
	load_nls_default();
	register_nls(&nls);
	unload_nls(&nls);
	load_nls(charset);
	unregister_nls(&nls);
	utf8_mbtowc(&p, &s, n);
	utf8_mbstowcs(&p, &s, n);
	n=20;
	utf8_wctomb(&s, p, n);
	utf8_wcstombs(&s, &p, n);
}
Example #15
0
static M4Err IS_ProcessData(SceneDecoder *plug, unsigned char *inBuffer, u32 inBufferLength, 
								u16 ES_ID, u32 AU_time, u32 mmlevel)
{
	u32 i, j, count;
	Double scene_time;
	BitStream *bs;
	ISPriv *priv = plug->privateStack;
	M4Err e = M4OK;

	/*decode data frame except if local stringSensor*/
	bs = NewBitStream(inBuffer, inBufferLength, BS_READ);
	for (i=0; i<ChainGetCount(priv->ddf); i++) {
		FieldInfo *field = ChainGetEntry(priv->ddf, i);
		/*store present flag in eventIn for command skip - this is an ugly hack but it works since DDF don't have event types*/
		field->eventType = BS_ReadInt(bs, 1);
		/*parse val ourselves (we don't want to depend on bifs codec)*/
		if (field->eventType) {
			switch (field->fieldType) {
			case FT_SFBool: * ((SFBool *) field->far_ptr) = (SFBool) BS_ReadInt(bs, 1); break;
			case FT_SFFloat: *((SFFloat *)field->far_ptr) = BS_ReadFloat(bs); break;
			case FT_SFInt32: *((SFInt32 *)field->far_ptr) = (s32) BS_ReadInt(bs, 32); break;
			case FT_SFTime: *((SFTime *)field->far_ptr) = BS_ReadDouble(bs); break;
			case FT_SFVec2f:
				((SFVec2f *)field->far_ptr)->x = BS_ReadFloat(bs);
				((SFVec2f *)field->far_ptr)->y = BS_ReadFloat(bs);
				break;
			case FT_SFVec3f:
				((SFVec3f *)field->far_ptr)->x = BS_ReadFloat(bs);
				((SFVec3f *)field->far_ptr)->y = BS_ReadFloat(bs);
				((SFVec3f *)field->far_ptr)->z = BS_ReadFloat(bs);
				break;
			case FT_SFColor:
				((SFColor *)field->far_ptr)->red = BS_ReadFloat(bs);;
				((SFColor *)field->far_ptr)->green = BS_ReadFloat(bs);
				((SFColor *)field->far_ptr)->blue = BS_ReadFloat(bs);
				break;
			case FT_SFRotation:
				((SFRotation *)field->far_ptr)->xAxis = BS_ReadFloat(bs);
				((SFRotation *)field->far_ptr)->yAxis = BS_ReadFloat(bs);
				((SFRotation *)field->far_ptr)->zAxis = BS_ReadFloat(bs);
				((SFRotation *)field->far_ptr)->angle = BS_ReadFloat(bs);
				break;

			case FT_SFString:
			{
				u32 size, length;
				size = BS_ReadInt(bs, 5);
				length = BS_ReadInt(bs, size);
				if (BS_Available(bs) < length) return M4NonCompliantBitStream;

				if ( ((SFString *)field->far_ptr)->buffer ) free( ((SFString *)field->far_ptr)->buffer);
				((SFString *)field->far_ptr)->buffer = malloc(sizeof(char)*(length+1));
				memset(((SFString *)field->far_ptr)->buffer , 0, length+1);
				for (j=0; j<length; j++) {
					 ((SFString *)field->far_ptr)->buffer[j] = BS_ReadInt(bs, 8);
				}
			}
				break;
			}
		}
	}
	DeleteBitStream(bs);

	/*special case for StringSensor in local mode: lookup for special chars*/
	if ((priv->type == IS_StringSensor) && priv->is_local) {
		char tmp_utf8[5000];
		const unsigned short *ptr;
		u32 len;
		FieldInfo *field1 = ChainGetEntry(priv->ddf, 0);
		FieldInfo *field2 = ChainGetEntry(priv->ddf, 1);
		SFString *inText = (SFString *) field1->far_ptr;
		SFString *outText = (SFString *) field2->far_ptr;

		field1->eventType = field2->eventType = 0;
		priv->enteredText[priv->text_len] = (short) '\0';

		len = utf8_wcslen(priv->enteredText);
		if (len && (priv->enteredText[len-1] == priv->termChar)) {
			ptr = priv->enteredText;
			len = utf8_wcstombs(tmp_utf8, 5000, &ptr);
			if (outText->buffer) free(outText->buffer);
			outText->buffer = malloc(sizeof(char) * (len+1));
			memcpy(outText->buffer, tmp_utf8, sizeof(char) * len);
			outText->buffer[len] = 0;
			if (inText->buffer) free(inText->buffer);
			inText->buffer = NULL;
			priv->text_len = 0;

			field1->eventType = field2->eventType = 1;
		} else {
			if (priv->delChar) {
				/*remove chars*/
				if (len && (priv->enteredText[len-1] == priv->delChar)) {
					priv->enteredText[len-1] = (short) '\0';
					len--;
					if (len) {
						priv->enteredText[len-1] = (short) '\0';
						len--;
					}
				}
			}
			priv->text_len = len;
			ptr = priv->enteredText;
			len = utf8_wcstombs(tmp_utf8, 5000, &ptr);
			if (inText->buffer) free(inText->buffer);
			inText->buffer = malloc(sizeof(char) * (len+1));
			memcpy(inText->buffer, tmp_utf8, sizeof(char) * len);
			inText->buffer[len] = 0;
			field1->eventType = 1;
		}
	}

	/*apply it*/
	for (i=0; i<ChainGetCount(priv->is_nodes); i++) {
		ISStack *st = ChainGetEntry(priv->is_nodes, i);
		assert(st->is);
		assert(st->is_dec);
		if (!st->is->enabled) continue;

		count = ChainGetCount(st->is->buffer.commandList);
		scene_time = IS_GetSceneTime(priv->scene);
		for (j=0; j<count; j++) {
			SGCommand *com = ChainGetEntry(st->is->buffer.commandList, j);
			FieldInfo *field = ChainGetEntry(priv->ddf, j);
			CommandFieldInfo *info = ChainGetEntry(com->command_fields, 0);
			if (info && field && field->eventType) {
				VRML_FieldCopy(info->field_ptr, field->far_ptr, field->fieldType);
				SG_ApplyCommand(priv->scene->graph, com, scene_time);
			}
		}
	}
	return e;
}
Example #16
0
void                                                                                                                         
asusnls_c2u(char *name)
{
#ifdef CONFIG_NLS
	char *codepage;
	char *xfrstr;
	struct nls_table *nls;
	int ret;

	strcpy(codebuf, name);
	codepage=codebuf+strlen(NLS_NVRAM_C2U);
	if((xfrstr=strchr(codepage, '_')))
	{
		*xfrstr=NULL;
		xfrstr++;

		/* debug message, start */
/*
		printk("%s, xfr from %s to utf8\n", xfrstr, codepage);
		printk("local:   %d, ", strlen(xfrstr));
		int j;
		for (j=0;j<strlen(xfrstr);j++)
			printk("%X ", (unsigned char)xfrstr[j]);
		printk("\n");
		printk("local:   %s\n", xfrstr);
*/
		/* debug message, end */

		strcpy(name, "");
		nls=load_nls(codepage);
		if(!nls)
		{
			printk("NLS table is null!!\n");
		}
		else
		{
			int charlen;
			int i;
			int len = strlen(xfrstr);
			for (i = 0; len && *xfrstr; i++, xfrstr += charlen, len -= charlen) {   /* string to unicode */
				charlen = nls->char2uni(xfrstr, len, &unibuf[i]);
				if (charlen < 1) {
					//unibuf[i] = 0x003f;     /* a question mark */
					//charlen = 1;
					strcpy(name ,"");
					unload_nls(nls);
					return;
				}
			}
			unibuf[i] = 0;
			ret=utf8_wcstombs(name, unibuf, 1024);  /* unicode to utf-8, 1024 is size of array unibuf */
			name[ret]=0;
			unload_nls(nls);
			/* debug message, start */
/*
			int k;
			printk("unicode: %d, ", i);
			for(k=0;k<i;k++)
				printk("%X ", unibuf[k]);
			printk("\n");
			printk("utf-8:    %s, %d, ", name, strlen(name));
			for (i=0;i<strlen(name);i++)
				printk("%X ", (unsigned char)name[i]);
			printk("\n");
*/
			/* debug message, end */
			if(!ret)
			{
				printk("can not xfr from %s to utf8\n", codepage);
				strcpy(name, "");
			}
		}
	}
	else
	{
		strcpy(name, "");
	}
#endif
}
Example #17
0
SocketFactory::SocketFactory (const String &peer_uuid)
    : m_name (utf8_mbstowcs (_("Unknown"))),
      m_language (String ("")),
      m_peer_uuid (peer_uuid),
      m_icon_file (String ("")),
      m_ok (false)
{
    String locales;
    String iconfile;
    int cmd;
    bool m_name_ok = false;
    bool m_locale_ok = false;
    Transaction trans;

    SCIM_DEBUG_IMENGINE(1) << "Create SocketFactory " << peer_uuid << ".\n";

    // Get factory name.
    global->init_transaction (trans);
    trans.put_command (SCIM_TRANS_CMD_GET_FACTORY_NAME);
    trans.put_data (m_peer_uuid);
    if (global->send_transaction (trans)) {
        if (global->receive_transaction (trans) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
            trans.get_data (m_name) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK) {

            SCIM_DEBUG_IMENGINE(2) << " Name (" << utf8_wcstombs (m_name) << ")\n";

            m_name_ok = true;

        } else {
            m_name = utf8_mbstowcs (_("Unknown"));
        }
    }

    // Get factory locales
    global->init_transaction (trans);
    trans.put_command (SCIM_TRANS_CMD_GET_FACTORY_LOCALES);
    trans.put_data (m_peer_uuid);
    if (global->send_transaction (trans)) {
        if (global->receive_transaction (trans) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
            trans.get_data (locales) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK) {

            SCIM_DEBUG_IMENGINE(2) << " Locales (" << locales << ")\n";

            set_locales (locales);
            m_locale_ok = true;
        }
    }

    // Get factory language
    global->init_transaction (trans);
    trans.put_command (SCIM_TRANS_CMD_GET_FACTORY_LANGUAGE);
    trans.put_data (m_peer_uuid);
    if (global->send_transaction (trans)) {
        if (global->receive_transaction (trans) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
            trans.get_data (m_language) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK) {

            SCIM_DEBUG_IMENGINE(2) << " Language (" << m_language << ")\n";

        } else {
            m_language.clear ();
        }
    }

    // Get icon file.
    global->init_transaction (trans);
    trans.put_command (SCIM_TRANS_CMD_GET_FACTORY_ICON_FILE);
    trans.put_data (m_peer_uuid);
    if (global->send_transaction (trans)) {
        if (global->receive_transaction (trans) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
            trans.get_data (iconfile) &&
            trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK) {
            m_icon_file = global->load_icon (iconfile);
        }
    }

    m_ok = (m_name_ok && m_locale_ok);
}
Example #18
0
void M4T_StringInput(MPEG4CLIENT term, u32 character)
{
	u32 i;
	BitStream *bs;
	SLHeader slh;
	unsigned char *buf;
	u32 buf_size;

	if (!character || !term) return;
	if (!ChainGetCount(term->input_streams) && !ChainGetCount(term->x3d_sensors)) return;

	memset(&slh, 0, sizeof(SLHeader));
	slh.accessUnitStartFlag = slh.accessUnitEndFlag = 1;
	slh.compositionTimeStampFlag = 1;
	/*cf above*/
	slh.compositionTimeStamp = 0;

	/*get all IS StringSensor decoders and send frame*/
	for (i=0; i<ChainGetCount(term->input_streams); i++) {
		GenericCodec *cod = ChainGetEntry(term->input_streams, i);
		ISPriv *is = cod->decio->privateStack;
		if (is->type==IS_StringSensor) {

			Channel *ch = ChainGetEntry(cod->inChannels, 0);
			is->enteredText[is->text_len] = character;
			is->text_len += 1;

			/*write empty DDF*/
			bs = NewBitStream(NULL, 0, BS_WRITE);
			BS_WriteInt(bs, 0, 1);
			BS_WriteInt(bs, 0, 1);
			BS_Align(bs);
			BS_GetContent(bs, &buf, &buf_size);
			DeleteBitStream(bs);
			
			Channel_RecieveSLP(ch->service, ch, buf, buf_size, &slh, M4OK);
			
			free(buf);
		}
	}


	/*get all X3D StringSensors*/
	for (i=0; i<ChainGetCount(term->x3d_sensors); i++) {
		StringSensorStack *st;
		char szStr[5000];
		const unsigned short *ptr;
		u32 len;
		X_StringSensor *n = ChainGetEntry(term->x3d_sensors, i);
		if (Node_GetTag((SFNode *)n) != TAG_X3D_StringSensor) continue;
		if (!n->enabled) continue;

		st = (StringSensorStack *) Node_GetPrivate((SFNode *)n);

		if (character=='\b') {
			if (n->deletionAllowed && st->text_len) {
				st->text_len -= 1;
				st->enteredText[st->text_len] = 0;
				ptr = st->enteredText;
				len = utf8_wcstombs(szStr, 10, &ptr);
				if (n->enteredText.buffer) free(n->enteredText.buffer);
				szStr[len] = 0;
				n->enteredText.buffer = strdup(szStr);
				Node_OnEventOutSTR((SFNode *)n, "enteredText");
			}
		} else if (character=='\r') {
			if (n->finalText.buffer) free(n->finalText.buffer);
			n->finalText.buffer = n->enteredText.buffer;
			n->enteredText.buffer = strdup("");
			st->text_len = 0;
			Node_OnEventOutSTR((SFNode *)n, "enteredText");
			Node_OnEventOutSTR((SFNode *)n, "finalText");
		} else {
			st->enteredText[st->text_len] = character;
			st->text_len += 1;
			st->enteredText[st->text_len] = 0;
			ptr = st->enteredText;
			len = utf8_wcstombs(szStr, 10, &ptr);
			if (n->enteredText.buffer) free(n->enteredText.buffer);
			szStr[len] = 0;
			n->enteredText.buffer = strdup(szStr);
			Node_OnEventOutSTR((SFNode *)n, "enteredText");
		}
	}
}
Example #19
0
// Convert a UTF-16 std::wstring into a multibyte UTF-8 string
std::string SharedUtil::UTF16ToMbUTF8 (const std::wstring& input)
{
    return utf8_wcstombs (input);
}
Example #20
0
/**
 * @brief Load one keyboard ISE module.
 *
 * @param module_name The keboard ISE module name.
 * @param config The config pointer for loading keyboard ISE.
 *
 * @return true if load module is successful, otherwise return false.
 */
static bool add_keyboard_ise_module (const String module_name, const ConfigPointer &config)
{
    if (module_name.length () <= 0 || module_name == "socket")
        return false;

    IMEngineFactoryPointer factory;
    IMEngineModule         ime_module;

    String filename = String (USER_ENGINE_FILE_NAME);
    FILE *engine_list_file = fopen (filename.c_str (), "a");
    if (engine_list_file == NULL) {
        std::cerr << "failed to open " << filename << "\n";
        return false;
    }

    ime_module.load (module_name, config);
    if (ime_module.valid ()) {
        for (size_t j = 0; j < ime_module.number_of_factories (); ++j) {
            try {
                factory = ime_module.create_factory (j);
            } catch (...) {
                factory.reset ();
            }

            if (!factory.null ()) {
                if (std::find (_uuids.begin (), _uuids.end (), factory->get_uuid ()) == _uuids.end ()) {
                    String uuid = factory->get_uuid ();
                    String name = utf8_wcstombs (factory->get_name ());
                    String language = isf_get_normalized_language (factory->get_language ());
                    String icon = factory->get_icon_file ();
                    char mode[12];
                    char option[12];

                    _uuids.push_back (uuid);
                    _names.push_back (name);
                    _module_names.push_back (module_name);
                    _langs.push_back (language);
                    _icons.push_back (icon);
                    _modes.push_back (TOOLBAR_KEYBOARD_MODE);
                    _options.push_back (0);

                    snprintf (mode, sizeof (mode), "%d", (int)TOOLBAR_KEYBOARD_MODE);
                    snprintf (option, sizeof (option), "%d", 0);

                    String line = isf_combine_ise_info_string (name, uuid, module_name, language, 
                                                               icon, String (mode), String (option), factory->get_locales ());
                    if (fputs (line.c_str (), engine_list_file) < 0) {
                        std::cerr << "write to ise cache file failed:" << line << "\n";
                        break;
                    }
                }
                factory.reset ();
            }
        }
        ime_module.unload ();
    }

    fclose (engine_list_file);

    return true;
}
Example #21
0
void M4T_KeyboardInput(MPEG4CLIENT term, s32 keyPressed, s32 keyReleased, s32 actionKeyPressed, s32 actionKeyReleased, u32 shiftKeyDown, u32 controlKeyDown, u32 altKeyDown)
{
	u32 i;
	BitStream *bs;
	SLHeader slh;
	unsigned char *buf;
	u32 buf_size;

	if (!term || (!ChainGetCount(term->input_streams) && !ChainGetCount(term->x3d_sensors)) ) return;

	memset(&slh, 0, sizeof(SLHeader));
	slh.accessUnitStartFlag = slh.accessUnitEndFlag = 1;
	slh.compositionTimeStampFlag = 1;
	/*cf above*/
	slh.compositionTimeStamp = 0;

	bs = NewBitStream(NULL, 0, BS_WRITE);

	BS_WriteInt(bs, keyPressed ? 1 : 0, 1); 
	if (keyPressed) BS_WriteInt(bs, keyPressed, 32);
	BS_WriteInt(bs, keyReleased ? 1 : 0, 1); 
	if (keyReleased) BS_WriteInt(bs, keyReleased, 32);
	BS_WriteInt(bs, actionKeyPressed ? 1 : 0, 1); 
	if (actionKeyPressed) BS_WriteInt(bs, actionKeyPressed, 32);
	BS_WriteInt(bs, actionKeyReleased ? 1 : 0, 1); 
	if (actionKeyReleased) BS_WriteInt(bs, actionKeyReleased, 32);
	BS_WriteInt(bs, shiftKeyDown ? 1 : 0 , 1); 
	if (shiftKeyDown) BS_WriteInt(bs, shiftKeyDown-1, 1);
	BS_WriteInt(bs, controlKeyDown ? 1 : 0 , 1); 
	if (controlKeyDown) BS_WriteInt(bs, controlKeyDown-1, 1);
	BS_WriteInt(bs, altKeyDown ? 1 : 0 , 1); 
	if (altKeyDown) BS_WriteInt(bs, altKeyDown, 1);

	BS_Align(bs);
	BS_GetContent(bs, &buf, &buf_size);
	DeleteBitStream(bs);

	/*get all IS keySensor decoders and send frame*/
	for (i=0; i<ChainGetCount(term->input_streams); i++) {
		GenericCodec *cod = ChainGetEntry(term->input_streams, i);
		ISPriv *is = cod->decio->privateStack;
		if (is->type==IS_KeySensor) {
			Channel *ch = ChainGetEntry(cod->inChannels, 0);
			Channel_RecieveSLP(ch->service, ch, buf, buf_size, &slh, M4OK);
		}
	}
	free(buf);
	
	for (i=0; i<ChainGetCount(term->x3d_sensors); i++) {
		u16 tc[2];
		u32 len;
		char szStr[10];
		const unsigned short *ptr;
		X_KeySensor *n = ChainGetEntry(term->x3d_sensors, i);
		if (Node_GetTag((SFNode *)n) != TAG_X3D_KeySensor) continue;
		if (!n->enabled) return;

		if (keyPressed) {
			if (n->keyPress.buffer) free(n->keyPress.buffer);
			tc[0] = keyPressed; tc[1] = 0;
			ptr = tc;
			len = utf8_wcstombs(szStr, 10, &ptr);
			n->keyPress.buffer = malloc(sizeof(char) * (len+1));
			memcpy(n->keyPress.buffer, szStr, sizeof(char) * len);
			n->keyPress.buffer[len] = 0;
			Node_OnEventOutSTR((SFNode *)n, "keyPress");
		}
		if (keyReleased) {
			if (n->keyRelease.buffer) free(n->keyRelease.buffer);
			tc[0] = keyReleased; tc[1] = 0;
			ptr = tc;
			len = utf8_wcstombs(szStr, 10, &ptr);
			n->keyRelease.buffer = malloc(sizeof(char) * (len+1));
			memcpy(n->keyRelease.buffer, szStr, sizeof(char) * len);
			n->keyRelease.buffer[len] = 0;
			Node_OnEventOutSTR((SFNode *)n, "keyRelease");
		}
		if (actionKeyPressed) {
			n->actionKeyPress = actionKeyPressed;
			Node_OnEventOutSTR((SFNode *)n, "actionKeyPress");
		}
		if (actionKeyReleased) {
			n->actionKeyRelease = actionKeyReleased;
			Node_OnEventOutSTR((SFNode *)n, "actionKeyRelease");
		}
		if (shiftKeyDown) {
			n->shiftKey = (shiftKeyDown-1) ? 1 : 0;
			Node_OnEventOutSTR((SFNode *)n, "shiftKey");
		}
		if (controlKeyDown) {
			n->controlKey = (controlKeyDown-1) ? 1 : 0;
			Node_OnEventOutSTR((SFNode *)n, "controlKey");
		}
		if (altKeyDown) {
			n->altKey= (altKeyDown-1) ? 1 : 0;
			Node_OnEventOutSTR((SFNode *)n, "altKey");
		}
		if (keyPressed || actionKeyPressed || (shiftKeyDown-1) || (controlKeyDown-1) || (altKeyDown-1)) {
			if (!n->isActive) {
				n->isActive = 1;
				Node_OnEventOutSTR((SFNode *)n, "isActive");
			}
		} else if (n->isActive) {
			n->isActive = 0;
			Node_OnEventOutSTR((SFNode *)n, "isActive");
		}
	}
}