]> git.lyx.org Git - lyx.git/blob - src/trans_mgr.h
Fix working of the spellchecker dialog with ispell when there are no
[lyx.git] / src / trans_mgr.h
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 #include "chset.h"
12 #include "LString.h"
13
14 class LyXText;
15 class Trans;
16
17 /// Translation State
18 class TransState {
19 public:
20         ///
21         virtual ~TransState() {}
22 #if 0
23         ///
24         virtual string const normalkey(char, string const &) = 0;
25 #else
26         ///
27         virtual string const normalkey(char) = 0;
28 #endif
29         ///
30         virtual bool backspace() = 0;
31         ///
32         virtual string const deadkey(char, KmodInfo) = 0;
33         ///
34         static char const TOKEN_SEP;
35 };
36
37
38 /// Translation FSM
39 class TransFSMData {
40 protected:
41         ///
42         virtual ~TransFSMData() {}
43         ///
44         char deadkey_;
45         ///
46         KmodInfo deadkey_info_;
47         ///
48         char deadkey2_;
49         ///
50         KmodInfo deadkey2_info_;
51 #if 0
52         ///
53         KmodException comb_info_;
54 #else
55         ///
56         Keyexc comb_info_;
57 #endif
58         ///
59         TransState * init_state_;
60         ///
61         TransState * deadkey_state_;
62         ///
63         TransState * combined_state_;
64         ///
65 public:
66         ///
67         TransFSMData();
68         ///
69         TransState * currentState;
70 };
71
72
73 /// Init State
74 class TransInitState :  virtual public TransFSMData, public TransState {
75 public:
76         ///
77         TransInitState();
78 #if 0
79         ///
80         virtual string const normalkey(char, string const &);
81 #else
82         ///
83         virtual string const normalkey(char);
84 #endif
85         ///
86         virtual bool backspace() { return true; }
87         ///
88         virtual string const deadkey(char, KmodInfo);
89 };
90
91
92 /// Deadkey State
93 class TransDeadkeyState : virtual public TransFSMData, public TransState {
94 public:
95         ///
96         TransDeadkeyState();
97 #if 0
98         ///
99         virtual string const normalkey(char, string const &);
100 #else
101         ///
102         virtual string const normalkey(char);
103 #endif
104         ///
105         virtual bool backspace() {
106                 currentState = init_state_;
107                 return false;
108         }
109         ///
110         virtual string const deadkey(char, KmodInfo);
111 };
112
113
114 /// Combined State
115 class TransCombinedState : virtual public TransFSMData, public TransState {
116 public:
117         ///
118         TransCombinedState();
119 #if 0
120         ///
121         virtual string const normalkey(char, string const &);
122 #else
123         ///
124         virtual string const normalkey(char);
125 #endif
126         ///
127         virtual bool backspace() {
128                 // cancel the second deadkey
129                 deadkey2_ = 0;
130                 deadkey2_info_.accent = TEX_NOACCENT;
131                 currentState = deadkey_state_;
132                 
133                 return false;
134         }
135         ///
136         virtual string const deadkey(char, KmodInfo);
137 };
138
139
140 ///
141 class TransFSM : virtual public TransFSMData,
142                  public TransInitState,
143                  public TransDeadkeyState,
144                  public TransCombinedState {
145 public:
146         ///
147         TransFSM();
148 };
149
150
151 ///
152 class TransManager {
153 private:
154         ///
155         TransFSM trans_fsm_;
156         ///
157         Trans * active_;
158         ///
159         Trans * t1_;
160         ///
161         Trans * t2_;
162         ///
163         static Trans default_;
164         ///
165         CharacterSet chset_;
166         ///
167         void insert(string const &, LyXText *);
168         ///
169         void insertVerbatim(string const &, LyXText *);
170 public:
171         ///
172         TransManager();
173         ///
174         virtual ~TransManager();
175         ///
176         int SetPrimary(string const &);
177         ///
178         int SetSecondary(string const &);
179         ///
180         void EnablePrimary();
181         ///
182         void EnableSecondary();
183         ///
184         void DisableKeymap();
185         ///
186         bool setCharset(string const &);
187         ///
188         bool backspace() {
189                 return trans_fsm_.currentState->backspace();
190         }
191         ///
192         void TranslateAndInsert(char, LyXText *);
193         ///
194         string const deadkey(char, KmodInfo);
195 #if 0
196         ///
197         string const normalkey(char, string const &);
198 #else
199         ///
200         string const normalkey(char);
201 #endif
202         ///
203         void deadkey(char, tex_accent, LyXText *);
204 };
205
206
207 #if 0
208 inline
209 string const TransManager::normalkey(char c, string const & t)
210 {
211         return trans_fsm_.currentState->normalkey(c, t);
212 }
213 #else
214 inline
215 string const TransManager::normalkey(char c)
216 {
217         return trans_fsm_.currentState->normalkey(c);
218 }
219 #endif
220
221
222 inline
223 string const TransManager::deadkey(char c, KmodInfo t)
224 {
225         return trans_fsm_.currentState->deadkey(c, t);
226 }
227
228 #endif