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