Back to index

im-sdk  12.3.91
ICState.hh
Go to the documentation of this file.
00001 #ifndef ICSTATE_HH_
00002 #define ICSTATE_HH_
00003 #include <config.h>
00004 #include <IMProtocolStruct.h>
00005 #include "basictype.hh"
00006 #include "ICHandler.hh"
00007 #include "IMState.hh"
00008 #include "IMLog.hh"
00009 
00010 class IMProtocol;
00011 class IIIMP_hotkey_profile;
00012 class ICState;
00013 class IMLExec_ICState : public IMLExec
00014 {
00015     // IMSyncObject so;
00016     ICState *pics;
00017     typedef list<iml_inst*> IMLInstList;
00018     IMLInstList pendinglist;
00019     void delete_inst(
00020        iml_inst *pinst
00021     );
00022 
00023     bool push_back(
00024        iml_inst *pinst
00025     );
00026 
00027     int execute_opcode(
00028        int opcode,
00029        iml_inst *rv
00030     );
00031 
00032     // IML instruction execution handlers.
00033     int imli_nop(
00034        iml_inst *rv
00035     );
00036     int imli_set_status(
00037        iml_inst *rv
00038     );
00039     int imli_reset(
00040        iml_inst *rv
00041     );
00042     int imli_keypress(
00043        iml_inst *rv
00044     );
00045     int imli_commit(
00046        iml_inst *rv
00047     );
00048     int imli_reset_return(
00049        iml_inst *rv
00050     );
00051     int imli_preedit_start(
00052        iml_inst *rv
00053     );
00054     int imli_preedit_draw(
00055        iml_inst *rv
00056     );
00057     int imli_preedit_done(
00058        iml_inst *rv
00059     );
00060     int imli_preedit_caret(
00061        iml_inst *rv
00062     );
00063     int imli_status_start(
00064        iml_inst *rv
00065     );
00066     int imli_status_draw(
00067        iml_inst *rv
00068     );
00069     int imli_status_done(
00070        iml_inst *rv
00071     );
00072     int imli_lookup_start(
00073        iml_inst *rv
00074     );
00075     int imli_lookup_draw(
00076        iml_inst *rv
00077     );
00078     int imli_lookup_process(
00079        iml_inst *rv
00080     );
00081     int imli_lookup_done(
00082        iml_inst *rv
00083     );
00084     int imli_aux_start(
00085        iml_inst *rv
00086     );
00087     int imli_aux_draw(
00088        iml_inst *rv
00089     );
00090     int imli_aux_done(
00091        iml_inst *rv
00092     );
00093     int imli_ns_listener(
00094        iml_inst *rv
00095     );
00096     int imli_key_info(
00097        iml_inst *rv
00098     );
00099     int imli_put_queue(
00100        iml_inst *rv
00101     );
00102 
00103   public:
00104     bool empty()
00105     { return pendinglist.empty(); }
00106     void set_icstate(
00107        ICState *x_pics
00108     )
00109     { pics = x_pics; }
00110     ICState* get_icstate()
00111     { return pics; }
00112     virtual iml_inst* push_insts(
00113        iml_inst **rrv
00114     );
00115     virtual bool execute();
00116     virtual ~IMLExec_ICState();
00117     IMLExec_ICState(ICState *x_pics = NULL)
00118     { pics = x_pics; }
00119 };
00120 
00121 class ICState
00122 {
00123     struct ICShared {
00124        CARD16BIT ic_id;
00125        IMState *pims;
00126        ICHandler *pich;
00127        IMLExec_ICState *pimlex;
00128        bool terminating;
00129     };
00130     ICState *pproc_state;
00131     ICState *pbase_state;
00132     ICShared *pshared;
00133 
00134     bool terminatingp()
00135     { return pshared->terminating; }
00136 
00137   protected:
00138     IMLExec_ICState* get_imlexec()
00139     { return pshared->pimlex; }
00140     bool mark_terminal()
00141     { 
00142        pshared->terminating = true;
00143        return true;
00144     }
00145     virtual bool state_send_available_p() = 0;
00146 
00147     void reset_state()
00148     { 
00149        ICState *p = pbase_state;
00150        if (p->pproc_state) delete p->pproc_state;
00151        p->pproc_state = NULL;
00152        p->pshared->pimlex->set_icstate(p);
00153     }
00154     void change_state(
00155        ICState &newstate,
00156        bool destroyp = true
00157     )
00158     {
00159        ICState *p = pbase_state;
00160        if (destroyp && p->pproc_state) delete p->pproc_state;
00161        if (p == &newstate) {
00162            p->pproc_state = NULL;
00163        } else {
00164            p->pproc_state = &newstate;
00165        }
00166        p->pshared->pimlex->set_icstate(&newstate);
00167     }
00168 
00169     IMProtocol* get_improtocol()
00170     { return pshared->pims->get_improtocol(); }
00171     ICHandler* get_ichandler()
00172     { return pshared->pich; }
00173     void invalidate_ichandler()
00174     { pshared->pich = NULL; }
00175     bool check_protocol_version(int version)
00176     { return get_imstate()->check_protocol_version(version); }
00177 
00178     int invalid_operation(
00179        const char *opstr
00180     );
00181 
00182     virtual bool message_proc(
00183        void *message
00184     ) = 0;
00185 
00186     // base constructors.
00187     ICState(
00188        ICState &x
00189     )
00190     {
00191        pshared = x.pshared;
00192        pbase_state = x.pbase_state;
00193        pproc_state = NULL;
00194     }
00195     virtual ~ICState()
00196     {
00197        if (!substatep()) {
00198            delete pshared;
00199            if (pproc_state) delete pproc_state;
00200        }
00201     }
00202 
00203   public:
00204     bool send_avail_p()
00205     {
00206        if (pbase_state->pproc_state)
00207            return pbase_state->pproc_state->state_send_available_p();
00208        else
00209            return pbase_state->state_send_available_p();
00210     }
00211     IMState* get_imstate()
00212     { return pshared->pims; }
00213     CARD16BIT get_im_id()
00214     { return get_imstate()->get_im_id(); }
00215     IIIMP_hotkey_profile* get_hotkey_profile()
00216     { return get_imstate()->get_hotkey_profile(); }
00217     CARD16BIT get_ic_id() const
00218     { return pshared->ic_id; }
00219     bool substatep() const
00220     { return (pbase_state != this); }
00221 
00222     bool deliver(
00223        void *message
00224     );
00225 
00226     virtual void destroy()
00227     {
00228        if (!substatep()) {
00229            pshared->pims->remove_icstate(this);
00230        }
00231        delete this;
00232     }
00233 
00234     ICState(
00235        CARD16BIT x_ic_id,
00236        IMState *x_pims,
00237        ICHandler *x_pich,
00238        IMLExec_ICState *x_pimlex
00239     )
00240     {
00241        pshared = new ICShared();
00242        pshared->ic_id = x_ic_id;
00243        pshared->pims = x_pims;
00244        pshared->pich = x_pich;
00245        pshared->pimlex = x_pimlex;
00246        pshared->terminating = false;
00247        x_pimlex->set_icstate(this);
00248        pproc_state = NULL;
00249        pbase_state = this;
00250     }
00251 
00252     // IC execution handlers.
00253     virtual int toggle_client_convmode(
00254        bool flag
00255     );
00256     virtual int forward_keyevent(
00257        IMKeyEventStruct *pkeyevent
00258     );
00259     virtual int commit_string(
00260        IMText *pimtext
00261     );
00262     virtual int preedit_start();
00263     virtual int draw_preedit(
00264        IMPreeditDrawCallbackStruct *pimpdraw
00265     );
00266     virtual int preedit_done();
00267     virtual int status_start();
00268     virtual int draw_status(
00269        IMStatusDrawCallbackStruct *pimsdraw
00270     );
00271     virtual int status_done();
00272     virtual int lookup_start(
00273        IMLookupStartCallbackStruct *pimls
00274     );
00275     virtual int draw_lookup(
00276        IMLookupDrawCallbackStruct *pimld
00277     );
00278     virtual int lookup_process(
00279        IMLookupProcessCallbackStruct *pimlp
00280     );
00281     virtual int lookup_done();
00282     virtual int aux_start(
00283        IMAuxStartCallbackStruct *pimauxstart
00284     );
00285     virtual int draw_aux(
00286        IMAuxDrawCallbackStruct *pimauxstart
00287     );
00288     virtual int aux_done(
00289        IMAuxDoneCallbackStruct *pimauxstart
00290     );
00291     virtual int ns_listener(
00292        IMNSListenerStruct *pons
00293     );
00294 };
00295 
00296 #endif /* not ICSTATE_HH_ */
00297 
00298 /* Local Variables: */
00299 /* c-file-style: "iiim-project" */
00300 /* End: */