1 | // ================================================================ // |
---|
2 | // // |
---|
3 | // File : AWT_map_key.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // ================================================================ // |
---|
10 | |
---|
11 | #include "awt_map_key.hxx" |
---|
12 | #include <arb_msg.h> |
---|
13 | #include <aw_window.hxx> |
---|
14 | #include <aw_root.hxx> |
---|
15 | #include <aw_awar.hxx> |
---|
16 | #include "awt_config_manager.hxx" |
---|
17 | |
---|
18 | #define KEYS_PER_COLUMN 10 |
---|
19 | #define MAPPED_KEYS (2*KEYS_PER_COLUMN) |
---|
20 | |
---|
21 | #define AWAR_KEYMAPPING_ENABLE "key_mapping/enable" |
---|
22 | |
---|
23 | ed_key::ed_key() { |
---|
24 | int i; |
---|
25 | for (i=0; i<256; i++) mapping[i] = i; |
---|
26 | } |
---|
27 | |
---|
28 | char ed_key::map_key(char k) const { |
---|
29 | int i = k & 0xff; |
---|
30 | return mapping[i]; |
---|
31 | } |
---|
32 | |
---|
33 | inline const char *mapping_awar_name(int idx, const char *subkey) { |
---|
34 | return GBS_global_string("key_mapping/key_%i/%s", idx, subkey); |
---|
35 | } |
---|
36 | inline char read_mapping_awar(AW_root *awr, int idx, const char *subkey) { |
---|
37 | const char *awar_content = awr->awar(mapping_awar_name(idx, subkey))->read_char_pntr(); |
---|
38 | return awar_content[0]; |
---|
39 | } |
---|
40 | |
---|
41 | void ed_key::rehash_mapping(AW_root *awr) { |
---|
42 | for (int i=0; i<256; i++) mapping[i] = i; |
---|
43 | |
---|
44 | long enable = awr->awar(AWAR_KEYMAPPING_ENABLE)->read_int(); |
---|
45 | if (enable) { |
---|
46 | for (int i=0; i<MAPPED_KEYS; i++) { |
---|
47 | char source = read_mapping_awar(awr, i, "source"); |
---|
48 | char dest = read_mapping_awar(awr, i, "dest"); |
---|
49 | |
---|
50 | if (source && dest) mapping[safeCharIndex(source)] = dest; |
---|
51 | } |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | static void ed_rehash_mapping(AW_root *awr, ed_key *ek) { |
---|
56 | ek->rehash_mapping(awr); |
---|
57 | } |
---|
58 | |
---|
59 | void ed_key::create_awars(AW_root *awr) { |
---|
60 | RootCallback rehash_mapping_cb = makeRootCallback(ed_rehash_mapping, this); |
---|
61 | |
---|
62 | for (int i=0; i<MAPPED_KEYS; i++) { |
---|
63 | awr->awar_string(mapping_awar_name(i, "source"))->add_callback(rehash_mapping_cb); |
---|
64 | awr->awar_string(mapping_awar_name(i, "dest"))->add_callback(rehash_mapping_cb); |
---|
65 | } |
---|
66 | awr->awar_int(AWAR_KEYMAPPING_ENABLE, 1)->add_callback(rehash_mapping_cb); |
---|
67 | rehash_mapping(awr); |
---|
68 | } |
---|
69 | |
---|
70 | static void setup_keymap_config(AWT_config_definition& cdef) { |
---|
71 | for (int i=0; i<MAPPED_KEYS; i++) { |
---|
72 | cdef.add(mapping_awar_name(i, "source"), GBS_global_string("src%02i", i)); |
---|
73 | cdef.add(mapping_awar_name(i, "dest"), GBS_global_string("dst%02i", i)); |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | AW_window *create_key_map_window(AW_root *root) { |
---|
78 | AW_window_simple *aws = new AW_window_simple; |
---|
79 | aws->init(root, "KEY_MAPPINGS", "KEY MAPPINGS"); |
---|
80 | aws->load_xfig("ed_key.fig"); |
---|
81 | |
---|
82 | aws->callback(AW_POPDOWN); |
---|
83 | aws->at("close"); |
---|
84 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
85 | |
---|
86 | aws->callback(makeHelpCallback("nekey_map.hlp")); |
---|
87 | aws->at("help"); |
---|
88 | aws->create_button("HELP", "HELP", "H"); |
---|
89 | |
---|
90 | aws->at("enable"); |
---|
91 | aws->create_toggle(AWAR_KEYMAPPING_ENABLE); |
---|
92 | |
---|
93 | aws->at("config"); |
---|
94 | AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, "keymap", makeConfigSetupCallback(setup_keymap_config)); |
---|
95 | |
---|
96 | aws->auto_space(10, 10); |
---|
97 | |
---|
98 | aws->at("ascii2"); int ax2 = aws->get_at_xposition(); |
---|
99 | aws->at("ascii1"); int ax1 = aws->get_at_xposition(); |
---|
100 | aws->at("key2"); int kx2 = aws->get_at_xposition(); |
---|
101 | aws->at("key1"); int kx1 = aws->get_at_xposition(); |
---|
102 | |
---|
103 | int y = aws->get_at_yposition(); |
---|
104 | |
---|
105 | for (int i=0; i<KEYS_PER_COLUMN; ++i) { |
---|
106 | aws->at(kx1, y); aws->create_input_field(mapping_awar_name(i, "source"), 2); |
---|
107 | aws->at(ax1, y); aws->create_input_field(mapping_awar_name(i, "dest"), 2); |
---|
108 | aws->at(kx2, y); aws->create_input_field(mapping_awar_name(i+KEYS_PER_COLUMN, "source"), 2); |
---|
109 | aws->at(ax2, y); aws->create_input_field(mapping_awar_name(i+KEYS_PER_COLUMN, "dest"), 2); |
---|
110 | |
---|
111 | aws->at_newline(); |
---|
112 | y = aws->get_at_yposition(); |
---|
113 | } |
---|
114 | |
---|
115 | return aws; |
---|
116 | } |
---|
117 | |
---|