source: branches/properties/AWT/AWT_map_key.cxx

Last change on this file was 19497, checked in by westram, 12 months ago
  • hardcode defaults for AWAR_DIST_CORR_TRANS and AWAR_DIST_CANCEL_CHARS
    • to value previously defined via ARBHOME/lib/arb_default/dist.arb
  • remove EDIT4 key mapping from arb_default (edit4). Instead add some default configs to config manager.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.7 KB
Line 
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
23ed_key::ed_key() {
24    int i;
25    for (i=0; i<256; i++) mapping[i] = i;
26}
27
28char ed_key::map_key(char k) const {
29    int i = k & 0xff;
30    return mapping[i];
31}
32
33inline const char *mapping_awar_name(int idx, const char *subkey) {
34    return GBS_global_string("key_mapping/key_%i/%s", idx, subkey);
35}
36inline 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
41void 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
55static void ed_rehash_mapping(AW_root *awr, ed_key *ek) {
56    ek->rehash_mapping(awr);
57}
58
59void 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
70static 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
77static AWT_predefined_config predefinedKeyMappingConfig[] = {
78    // Note: currently key mappings are only used in EDIT4 -> these config are editor specific.
79
80    { "*hbjl_mapping_rna", "Traditional mapping used in the 90ies to \nmanually enter (RNA) sequences.", "dst00='C';dst01='A';dst02='G';dst03='U';dst04='';dst05='c';dst06='a';dst07='g';dst08='u';dst09='';dst10='N';dst11='n';dst12='';dst13='';dst14='';dst15='';dst16='';dst17='';dst18='';dst19='';src00='h';src01='b';src02='j';src03='l';src04='';src05='H';src06='B';src07='J';src08='L';src09='';src10='n';src11='N';src12='';src13='';src14='';src15='';src16='';src17='';src18='';src19=''" },
81    { "*hbjl_mapping_dna", "Traditional mapping used in the 90ies to \nmanually enter (DNA) sequences.", "dst00='C';dst01='A';dst02='G';dst03='T';dst04='';dst05='c';dst06='a';dst07='g';dst08='t';dst09='';dst10='N';dst11='n';dst12='';dst13='';dst14='';dst15='';dst16='';dst17='';dst18='';dst19='';src00='h';src01='b';src02='j';src03='l';src04='';src05='H';src06='B';src07='J';src08='L';src09='';src10='n';src11='N';src12='';src13='';src14='';src15='';src16='';src17='';src18='';src19=''" },
82    { "*reversed_case", "swaps upper and lower case.\nspace is gap.", "dst00='A';dst01='C';dst02='G';dst03='T';dst04='U';dst05='N';dst06='-';dst07='';dst08='';dst09='';dst10='a';dst11='c';dst12='g';dst13='t';dst14='u';dst15='n';dst16='';dst17='';dst18='';dst19='';src00='a';src01='c';src02='g';src03='t';src04='u';src05='n';src06=' ';src07='';src08='';src09='';src10='A';src11='C';src12='G';src13='T';src14='U';src15='N';src16='';src17='';src18='';src19=''" },
83    { NULp, NULp, NULp }
84};
85
86AW_window *create_key_map_window(AW_root *root) {
87    AW_window_simple *aws = new AW_window_simple;
88    aws->init(root, "KEY_MAPPINGS", "KEY MAPPINGS");
89    aws->load_xfig("ed_key.fig");
90
91    aws->callback(AW_POPDOWN);
92    aws->at("close");
93    aws->create_button("CLOSE", "CLOSE", "C");
94
95    aws->callback(makeHelpCallback("nekey_map.hlp"));
96    aws->at("help");
97    aws->create_button("HELP", "HELP", "H");
98
99    aws->at("enable");
100    aws->create_toggle(AWAR_KEYMAPPING_ENABLE);
101
102    aws->at("config");
103    AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, "keymap", makeConfigSetupCallback(setup_keymap_config), NULp, predefinedKeyMappingConfig);
104
105    aws->auto_space(10, 10);
106
107    aws->at("ascii2"); int ax2 = aws->get_at_xposition();
108    aws->at("ascii1"); int ax1 = aws->get_at_xposition();
109    aws->at("key2");   int kx2 = aws->get_at_xposition();
110    aws->at("key1");   int kx1 = aws->get_at_xposition();
111
112    int y = aws->get_at_yposition();
113
114    for (int i=0; i<KEYS_PER_COLUMN; ++i) {
115        aws->at(kx1, y); aws->create_input_field(mapping_awar_name(i,                 "source"), 2);
116        aws->at(ax1, y); aws->create_input_field(mapping_awar_name(i,                 "dest"),   2);
117        aws->at(kx2, y); aws->create_input_field(mapping_awar_name(i+KEYS_PER_COLUMN, "source"), 2);
118        aws->at(ax2, y); aws->create_input_field(mapping_awar_name(i+KEYS_PER_COLUMN, "dest"),   2);
119
120        aws->at_newline();
121        y = aws->get_at_yposition();
122    }
123
124    return aws;
125}
126
Note: See TracBrowser for help on using the repository browser.