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