]> git.lyx.org Git - lyx.git/blob - src/intl.C
Extracted from r14281
[lyx.git] / src / intl.C
1 /**
2  * \file intl.h
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  * \author Lars Gullik Bjønnes
8  * \author Angus Leeming
9  * \author John Levon
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "intl.h"
17 #include "debug.h"
18 #include "lyxrc.h"
19
20
21 using std::endl;
22
23
24 Intl::Intl()
25         : keymap(Intl::PRIMARY), keymapon(lyxrc.use_kbmap),
26         prim_lang(lyxrc.primary_kbmap), sec_lang(lyxrc.secondary_kbmap)
27 {
28 }
29
30
31 void Intl::keyMapOn(bool on)
32 {
33         keymapon = on;
34
35         if (on) {
36                 if (keymap == PRIMARY)
37                         keyMapPrim();
38                 else
39                         keyMapSec();
40         } else
41                 trans.disableKeymap();
42 }
43
44
45 void Intl::toggleKeyMap()
46 {
47         if (keymapon && (keymap == PRIMARY)) {
48                 keyMapSec();
49         } else if (keymapon) {
50                 keyMapOn(false);
51         } else
52                 keyMapPrim();
53 }
54
55
56 void Intl::keyMapPrim()
57 {
58         if (!trans.setPrimary(prim_lang))
59                 trans.enablePrimary();
60
61         keymapon = true;
62         keymap = PRIMARY;
63 }
64
65
66 void Intl::keyMapSec()
67 {
68         if (!trans.setSecondary(sec_lang))
69                 trans.enableSecondary();
70
71         keymapon = true;
72         keymap = SECONDARY;
73 }
74
75
76 void Intl::initKeyMapper(bool on)
77 {
78         lyxerr[Debug::INIT] << "Initializing key mappings..." << endl;
79
80         if (trans.setPrimary(prim_lang) == -1)
81                 prim_lang.erase();
82         if (trans.setSecondary(sec_lang) == -1)
83                 sec_lang.erase();
84         trans.setCharset(lyxrc.font_norm);
85
86         if (prim_lang.empty() && sec_lang.empty())
87                 keymapon = false;
88         else
89                 keymapon = on;
90
91         keyMapOn(keymapon);
92
93         if (keymapon)
94                 keyMapPrim();
95 }