home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / lyx-0.13.2.tar.gz / lyx-0.13.2.tar / lyx-0.13.2 / src / trans_mgr.h < prev    next >
C/C++ Source or Header  |  1998-04-23  |  3KB  |  202 lines

  1. // -*- C++ -*-
  2. #ifndef _Trans_Manager_h_
  3. #define _Trans_Manager_h_
  4.  
  5. #ifdef __GNUG__
  6. #pragma interface
  7. #endif
  8.  
  9. #include "tex-accent.h"
  10. #include "trans_decl.h"
  11.  
  12. class LyXText;
  13. class LString;
  14. class CharacterSet;
  15. class Trans;
  16.  
  17. /// Translation State
  18. class TransState {
  19. public:
  20.     ///
  21.     virtual ~TransState();
  22.     ///
  23.     virtual LString normalkey(char,char*)=0;
  24.     ///
  25.     virtual bool backspace()=0;
  26.     ///
  27.     virtual LString deadkey(char,KmodInfo)=0;
  28.     ///
  29.     static const char TOKEN_SEP;
  30. };
  31.  
  32.  
  33. /// Translation FSM
  34. class TransFSMData {
  35. protected:
  36.     ///
  37.     virtual ~TransFSMData()
  38.     {}
  39.     ///
  40.     char deadkey_;
  41.     ///
  42.     KmodInfo deadkey_info_;
  43.     ///
  44.     char deadkey2_;
  45.     ///
  46.     KmodInfo deadkey2_info_;
  47.     ///
  48.     KmodException comb_info_;
  49.     ///
  50.     TransState* init_state_;
  51.     ///
  52.     TransState* deadkey_state_;
  53.     ///
  54.     TransState* combined_state_;
  55.     ///
  56. public:
  57.     ///
  58.     TransFSMData();
  59.     ///
  60.     TransState* currentState;
  61. };
  62.  
  63.  
  64. /// Init State
  65. class TransInitState: 
  66.     virtual public TransFSMData,
  67.     public TransState {
  68. public:
  69.         ///
  70.         TransInitState();
  71.         ///
  72.         virtual LString normalkey(char,char*);
  73.         ///
  74.         virtual bool backspace() { return true; }
  75.         ///
  76.         virtual LString deadkey(char,KmodInfo);
  77. };
  78.  
  79.  
  80. /// Deadkey State
  81. class TransDeadkeyState: 
  82.     virtual public TransFSMData,
  83.     public TransState {
  84. public:
  85.         ///
  86.         TransDeadkeyState();
  87.         ///
  88.         virtual LString normalkey(char,char*);
  89.         ///
  90.         virtual bool backspace()
  91.     {
  92.         currentState=init_state_;
  93.         return false;
  94.     }
  95.         ///
  96.         virtual LString deadkey(char,KmodInfo);
  97. };
  98.  
  99.  
  100. /// Combined State
  101. class TransCombinedState: 
  102.     virtual public TransFSMData,
  103.     public TransState {
  104. public:
  105.         ///
  106.         TransCombinedState();
  107.         ///
  108.         virtual LString normalkey(char,char*);
  109.         ///
  110.         virtual bool backspace()
  111.     {
  112.         // cancel the second deadkey
  113.         deadkey2_=0;
  114.         deadkey2_info_.accent=TEX_NOACCENT;
  115.         currentState=deadkey_state_;
  116.         
  117.         return false;
  118.     }
  119.         ///
  120.         virtual LString deadkey(char,KmodInfo);
  121. };
  122.  
  123.  
  124. ///
  125. class TransFSM:    
  126.     virtual public TransFSMData,
  127.     public TransInitState,
  128.     public TransDeadkeyState,
  129.     public TransCombinedState
  130. {
  131. public:
  132.     ///
  133.     TransFSM();
  134. };
  135.  
  136. ///
  137. class TransManager
  138. {
  139. private:
  140.     ///
  141.     TransFSM trans_fsm_;
  142.     ///
  143.     Trans* active_;
  144.     ///
  145.     Trans* t1_;
  146.     ///
  147.     Trans* t2_;
  148.     ///
  149.     static Trans* default_;
  150.     ///
  151.     CharacterSet* chset_;
  152.     ///
  153.     void insert(LString,LyXText*);
  154.     ///
  155.     void insertVerbatim(const LString&,LyXText*);
  156. public:
  157.     ///
  158.     TransManager();
  159.     ///
  160.     virtual ~TransManager();
  161.     ///
  162.     int SetPrimary(LString const &);
  163.     ///
  164.     int SetSecondary(LString const &);
  165.     ///
  166.     void EnablePrimary();
  167.     ///
  168.     void EnableSecondary();
  169.     ///
  170.     void DisableKeymap();
  171.     ///
  172.     bool setCharset(const char*);
  173.     ///
  174.     bool backspace()
  175.     {
  176.         return trans_fsm_.currentState->backspace();
  177.     }
  178.     ///
  179.     void TranslateAndInsert(char,LyXText*);
  180.     ///
  181.     inline LString deadkey(char,KmodInfo);
  182.     ///
  183.     inline LString normalkey(char,char*);
  184.     ///
  185.     void deadkey(char,tex_accent,LyXText*);
  186.     
  187. };
  188.  
  189.  
  190. LString TransManager::normalkey(char c,char *t)
  191. {
  192.     return trans_fsm_.currentState->normalkey(c,t);
  193. }
  194.  
  195.  
  196. LString TransManager::deadkey(char c,KmodInfo t)
  197. {
  198.     return trans_fsm_.currentState->deadkey(c,t);
  199. }
  200.  
  201. #endif
  202.