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