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