|

楼主 |
发表于 2008-6-22 17:18:33
|
显示全部楼层
好了 弄出来了。。。。
- #define Uses_SCIM_LOOKUP_TABLE
- #define Uses_SCIM_FRONTEND
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <scim.h>
- #include <locale.h>
- #include <sstream>
- #include <iostream>
- using namespace scim;
- class MyFrontEnd: public FrontEndBase {
- private:
- int id;
- private:
- WideString factory_info(String uuid) {
- std::basic_stringstream<wchar_t> stream;
- stream << "Name:" << get_factory_name(uuid).c_str() << ' ';
- stream << "Language:" << get_factory_language(uuid).c_str() << ' ';
- stream << "Authors:" << get_factory_authors(uuid).c_str() << ' ';
- stream << "Credits:" << get_factory_credits(uuid).c_str() << ' ';
- //stream << "Help:"<<get_factory_help(uuid).c_str()<<' ';
- //stream << "Icon_file:"<<get_factory_icon_file(uuid).c_str()<<' ';
- stream << "Locales:" << get_factory_locales(uuid).c_str() << ' ';
- //stream<<'\n';
- return stream.str();
- }
- WideString instance_info(int id) {
- std::basic_stringstream<wchar_t> stream;
- stream << "Name:" << get_instance_name(id).c_str() << ' ';
- stream << "Encoding:" << get_instance_encoding(id).c_str() << ' ';
- stream << "Authors:" << get_instance_authors(id).c_str() << ' ';
- stream << "Credits:" << get_instance_credits(id).c_str() << ' ';
- //stream << "Help:"<<get_instance_help(id).c_str()<<' ';
- //stream << "Icon_file:"<<get_instance_icon_file(id).c_str()<<' ';
- stream << "UUID:" << get_instance_uuid(id).c_str() << ' ';
- //stream<<'\n';
- return stream.str();
- }
- void dump_factory() {
- std::vector<String> uuids;
- String language;
- uint32 ret = get_factory_list_for_language(uuids, language);
- if (ret > 0) {
- std::vector<String>::const_iterator it;
- for (it = uuids.begin(); it != uuids.end();++it) {
- printf("%S\n",factory_info(*it).c_str() );
- }
- }
- }
- void test_key(const KeyEvent& key) {
- focus_in(id);
- if(process_key_event (id, key)) {
- printf("Process key success\n");
- } else {
- perror("Process key error!\n");
- }
- }
- public:
- MyFrontEnd(const BackEndPointer &backend) :
- FrontEndBase(backend) {
- setlocale(LC_ALL, "zh_CN.UTF-8");
- }
- void init(int argc, char **argv) {
- String uuid;
- String language="zh_CN";
- String encoding="UTF-8";
- uuid=get_default_factory (language, encoding);
- id= new_instance (uuid, encoding);
- printf("Default IM:%S\n",instance_info(id).c_str());
- }
- void run () {
- if(id==-1) {
- perror("new_instance Error\n");
- }
- else {
- printf("Get IM success\n");
- test_key(KeyEvent("a"));
- test_key(KeyEvent("n"));
- test_key(KeyEvent("n"));
- test_key(KeyEvent("n"));
- test_key(KeyEvent("n"));
- }
- }
- void update_aux_string(int id, const WideString & str, const AttributeList & attrs)
- {
- printf("In update_aux_string -> Get string %S\n",str.c_str());
- }
- void update_preedit_string (int id, const WideString & str, const AttributeList & attrs)
- {
- printf("In update_preedit_string-> Get string %S\n",str.c_str());
- }
- void
- update_lookup_table (int id, const LookupTable & table)
- {
- printf("In update_lookup_table\n");
- size_t n=table.number_of_candidates();
- for(size_t i=0;i<n;++i){
- printf("%d->%S ",i,table.get_candidate(i).c_str());
- if(i>0 && i%10 ==0 ){
- printf("\n");
- }
- }
- }
- };
- //Module Interface
- static Pointer<MyFrontEnd> _scim_frontend(0);
- static int _argc;
- static char **_argv;
- extern "C" {
- void scim_module_init(void) {
- SCIM_DEBUG_FRONTEND(1) << "Initializing Socket FrontEnd module...\n";
- }
- void scim_module_exit(void) {
- SCIM_DEBUG_FRONTEND(1) << "Exiting Socket FrontEnd module...\n";
- _scim_frontend.reset();
- }
- void scim_frontend_module_init(const BackEndPointer &backend,
- const ConfigPointer &config, int argc, char **argv) {
- if (_scim_frontend.null()) {
- SCIM_DEBUG_FRONTEND(1) << "Initializing Socket FrontEnd module (more)...\n";
- _scim_frontend = new MyFrontEnd(backend);
- _argc = argc;
- _argv = argv;
- }
- }
- void scim_frontend_module_run(void) {
- if (!_scim_frontend.null()) {
- SCIM_DEBUG_FRONTEND(1) << "Starting Socket FrontEnd module...\n";
- _scim_frontend->init(_argc, _argv);
- _scim_frontend->run();
- }
- }
- }
复制代码 |
|