Back to index

im-sdk  12.3.91
IMInputContext.cpp
Go to the documentation of this file.
00001 #include <config.h>
00002 #include <stdio.h>
00003 #include "IMInputContext.hh"
00004 #include "IMConnection.hh"
00005 #include "IMSvr.hh"
00006 #include "LEMgr.hh"
00007 #include "IMLog.hh"
00008 
00009 //
00010 // LEContext management.
00011 //
00012 
00013 LEMgr*
00014 IMInputContext::get_lemgr()
00015 {
00016     return get_imconnection()->get_imsvr()->get_lemgr();
00017 }
00018 
00019 LEContext*
00020 IMInputContext::create_lecontext()
00021 {
00022     LEContext* plec;
00023 
00024     plec = get_lemgr()->choose_LE(this);
00025     if (plec) leclist.push_back(plec);
00026 
00027     return plec;
00028 }
00029 
00030 LEContext*
00031 IMInputContext::get_current_lecontext()
00032 {
00033     if (pcur_lec) return pcur_lec;
00034     pcur_lec = create_lecontext();
00035 
00036     if (!pcur_lec) {
00037        LOG_ERROR("Failed to create LE context.");
00038     }
00039     //TODO attr = pcur_lec->get_icattribute();
00040     return pcur_lec;
00041 }
00042 
00043 bool
00044 IMInputContext::switch_lecontext(
00045     const ICAttribute &x_attr
00046 )
00047 {
00048     // TODO  spcicial client HTT_XBE requires this feature...
00049     return false;
00050 }
00051 
00052 //
00053 // service for LEContext.
00054 //
00055 
00056 void
00057 IMInputContext::get_lecontext_args(
00058     vector<IMArg> &args
00059 )
00060 {
00061     IMArg a;
00062 
00063     IMSetArg(a, SC_CLIENT_LOCALE,
00064             attr.get_inputlanguage().get_charstr());
00065     args.push_back(a);
00066     IMSetArg(a, SC_CLIENT_INPUT_METHOD_NAME,
00067             attr.get_inputmethod().get_charstr());
00068     args.push_back(a);
00069     IMSetArg(a, SC_CLIENT_CHARACTER_SUBSETS,
00070             attr.get_character_subsets().get_c_csidices());
00071     args.push_back(a);
00072 
00073     return;
00074 }
00075 
00076 /*******************************************************************************
00077                         ICHandler realization
00078 *******************************************************************************/
00079 
00080 bool
00081 IMInputContext::send_event(
00082     IMLExec* pimlex,
00083     IMInputEvent* pimevent
00084 )
00085 {
00086 #if 0 // AUX forwarding... TODO!!!!
00087     if (fev->type == IM_EventAux) {
00088        IMAuxEvent *aux_event = (IMAuxEvent*)fev;
00089        ImlSession *temp_session;
00090 
00091        for (int i = 1; i <= session_list.getSize(); i++) {
00092            temp_session = (ImlSession *)&(session_list.getItem(i));
00093            int len = temp_session->mAuxName.length();
00094            if (len > 0 && strstr(aux_event->aux->aux_name,
00095                               (const char*)temp_session->mAuxName)) {
00096               sc = temp_session->sc;
00097               break;
00098            }
00099        }
00100 #if 0
00101        // not found, save current aux name for later comparison.
00102        if (active_session->mAuxName.length() == 0) {
00103            char *p = 0;
00104            char *aux_name = strdup(aux_event->aux->aux_name);
00105            if (p = rindex (aux_name, '.'))
00106               *p = 0;
00107            active_session->mAuxName = CompoundString(aux_name);
00108            free (aux_name);
00109        }
00110 #endif
00111     }
00112 #endif
00113     LEContext *plec = get_current_lecontext();
00114 
00115     if (!plec) return false;
00116 
00117     return plec->send_event(pimlex, pimevent);
00118 }
00119 
00120 bool
00121 IMInputContext::send_event_getvalues(
00122     IMLExec* pimlex,
00123     IMInputEvent* pimevent
00124 )
00125 {
00126     LEContext *plec = get_current_lecontext();
00127 
00128     if (!plec) return false;
00129 
00130     return plec->send_event_getvalues(pimlex, pimevent);
00131 }
00132 
00133 bool
00134 IMInputContext::send_event_getvalues_finished(
00135     IMLExec* pimlex
00136 )
00137 {
00138     LEContext *plec = get_current_lecontext();
00139 
00140     if (!plec) return false;
00141 
00142     return plec->send_event_getvalues_finished(pimlex);
00143 }
00144 
00145 const ICAttribute&
00146 IMInputContext::get_icattr()
00147 {
00148     return attr;
00149 }
00150 
00151 bool
00152 IMInputContext::set_icattr(
00153     const ICAttribute &x_attr
00154 )
00155 {
00156     attr = x_attr;
00157     // TODO...
00158     pcur_lec = create_lecontext();
00159 
00160     return true;
00161 }
00162 
00163 bool
00164 IMInputContext::toggle_conversion(
00165     IMLExec *pimlex,
00166     bool flag
00167 )
00168 {
00169     LEContext *plec = get_current_lecontext();
00170 
00171     if (!plec) return false;
00172 
00173     return plec->toggle_conversion(pimlex, flag);
00174 }
00175 
00176 bool
00177 IMInputContext::invoke_desktop_listener(
00178     IMLExec *pimlex,
00179     int listener_id,
00180     int file_size,
00181     void *object
00182 )
00183 {
00184     LEContext *plec = get_current_lecontext();
00185     iml_desktop_t *desktop = plec->get_iml_desktop();
00186     iml_listener_t *l;
00187 
00188     if (!plec) return false;
00189 
00190     l = desktop->lookupListenerFromDesktop(plec->get_iml_session(), listener_id);
00191     l->listener(listener_id, file_size, object, l->private_data);
00192    
00193     return true;
00194 }
00195 
00196 iml_desktop_t *
00197 IMInputContext::get_current_desktop()
00198 {
00199     LEContext *plec = get_current_lecontext();
00200     return plec->get_iml_desktop();
00201 }
00202 
00203 bool
00204 IMInputContext::reset(
00205     IMLExec *pimlex
00206 )
00207 {
00208     LEContext *plec = get_current_lecontext();
00209 
00210     if (!plec) return false;
00211 
00212     return plec->reset(pimlex);
00213 }
00214 
00215 bool
00216 IMInputContext::destroy(
00217     IMLExec *pimlex
00218 )
00219 {
00220     LEContextList::iterator i;
00221     for (i = leclist.begin(); i != leclist.end(); i++) {
00222        (*i)->destroy(pimlex);
00223     }
00224     delete this;
00225     return true;
00226 }
00227 
00228 void
00229 IMInputContext::destroy()
00230 {
00231     destroy_all(leclist);
00232     delete this;
00233 }
00234 
00235 bool
00236 IMInputContext::toggle_focus(
00237     IMLExec *pimlex,
00238     bool flag
00239 )
00240 {
00241     LEContext *plec = get_current_lecontext();
00242 
00243     if (!plec) return false;
00244 
00245     return plec->toggle_focus(pimlex, flag);
00246 }
00247 
00248 /*******************************************************************************
00249                        Constructor/Destructor
00250 *******************************************************************************/
00251 
00252 IMInputContext::IMInputContext(
00253     IMConnection *x_pimc,
00254     const ICAttribute &x_attr
00255 )
00256 {
00257     pimc = x_pimc;
00258     attr = x_attr;
00259     pcur_lec = NULL;
00260 }
00261 
00262 IMInputContext::~IMInputContext()
00263 {
00264 }
00265 
00266 /* Local Variables: */
00267 /* c-file-style: "iiim-project" */
00268 /* End: */