4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
8 * \author Matthias Ettrich
11 * Full author contact details are available in file CREDITS.
18 #include "support/docstring.h"
20 #include <boost/scoped_ptr.hpp>
71 TEX_MAX_ACCENT
= TEX_OGONEK
75 struct tex_accent_struct
{
78 /// UCS4 code point of this accent
87 extern tex_accent_struct
get_accent(kb_action action
);
92 /// character to make exception
96 /// Combination with another deadkey
98 /// The accent comined with
103 typedef std::list
<Keyexc
> KmodException
;
113 KmodException exception_list
;
117 /////////////////////////////////////////////////////////////////////
119 // Trans: holds a .kmap file
121 /////////////////////////////////////////////////////////////////////
128 ~Trans() { freeKeymap(); }
131 int load(std::string
const & language
);
133 bool isDefined() const;
135 std::string
const & getName() const { return name_
; }
137 docstring
const process(char_type
, TransManager
&);
139 bool isAccentDefined(tex_accent
, KmodInfo
&) const;
143 void addDeadkey(tex_accent
, docstring
const &);
149 docstring
const & match(char_type c
);
151 void insertException(KmodException
& exclist
, char_type c
,
152 docstring
const & data
, bool = false,
153 tex_accent
= TEX_NOACCENT
);
155 void freeException(KmodException
& exclist
);
160 std::map
<char_type
, docstring
> keymap_
;
162 std::map
<tex_accent
, KmodInfo
> kmod_list_
;
168 docstring
const & Trans::match(char_type c
)
170 std::map
<char_type
, docstring
>::iterator it
= keymap_
.find(c
);
171 if (it
!= keymap_
.end()) {
174 static docstring dummy
;
179 /////////////////////////////////////////////////////////////////////
183 /////////////////////////////////////////////////////////////////////
185 /// Translation state
189 virtual ~TransState() {}
191 virtual docstring
const normalkey(char_type
) = 0;
193 virtual bool backspace() = 0;
195 virtual docstring
const deadkey(char_type
, KmodInfo
) = 0;
197 static char_type
const TOKEN_SEP
;
205 virtual ~TransFSMData() {}
209 KmodInfo deadkey_info_
;
213 KmodInfo deadkey2_info_
;
217 TransState
* init_state_
;
219 TransState
* deadkey_state_
;
221 TransState
* combined_state_
;
227 TransState
* currentState
;
232 class TransInitState
: virtual public TransFSMData
, public TransState
{
237 virtual docstring
const normalkey(char_type
);
239 virtual bool backspace() { return true; }
241 virtual docstring
const deadkey(char_type
, KmodInfo
);
246 class TransDeadkeyState
: virtual public TransFSMData
, public TransState
{
251 virtual docstring
const normalkey(char_type
);
253 virtual bool backspace() {
254 currentState
= init_state_
;
258 virtual docstring
const deadkey(char_type
, KmodInfo
);
263 class TransCombinedState
: virtual public TransFSMData
, public TransState
{
266 TransCombinedState();
268 virtual docstring
const normalkey(char_type
);
270 virtual bool backspace() {
271 // cancel the second deadkey
273 deadkey2_info_
.accent
= TEX_NOACCENT
;
274 currentState
= deadkey_state_
;
279 virtual docstring
const deadkey(char_type
, KmodInfo
);
284 class TransFSM
: virtual public TransFSMData
,
285 public TransInitState
,
286 public TransDeadkeyState
,
287 public TransCombinedState
{
295 /////////////////////////////////////////////////////////////////////
299 /////////////////////////////////////////////////////////////////////
308 boost::scoped_ptr
<Trans
> t1_
;
310 boost::scoped_ptr
<Trans
> t2_
;
312 static Trans default_
;
314 void insert(docstring
const &, Text
*, Cursor
& cur
);
321 int setPrimary(std::string
const &);
323 int setSecondary(std::string
const &);
325 void enablePrimary();
327 void enableSecondary();
329 void disableKeymap();
331 bool backspace() { return trans_fsm_
.currentState
->backspace(); }
333 void translateAndInsert(char_type
, Text
*, Cursor
&);
335 docstring
const deadkey(char_type c
, KmodInfo t
)
336 { return trans_fsm_
.currentState
->deadkey(c
, t
); }
338 docstring
const normalkey(char_type c
)
339 { return trans_fsm_
.currentState
->normalkey(c
); }
341 void deadkey(char_type
, tex_accent
, Text
*, Cursor
&);