root/trunk/AWT/AWT_map_key.cxx

Revision 8309, 3.2 KB (checked in by westram, 5 months ago)
  • moved much code into static scope
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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 <aw_window.hxx>
13#include <aw_root.hxx>
14#include <aw_awar.hxx>
15
16ed_key::ed_key()
17{
18    int i;
19    for (i=0; i<256; i++) map[i] = i;
20}
21
22char ed_key::map_key(char k) const {
23    int i = k & 0xff;
24    return map[i];
25}
26
27void ed_key::rehash_mapping(AW_root *awr) {
28    int i;
29    for (i=0; i<256; i++) map[i] = i;
30    char source[256];
31    char dest[256];
32    char *ps, *pd;
33    long enable = awr->awar("key_mapping/enable")->read_int();
34    if (enable) {
35        for (i=0; i<MAX_MAPPED_KEYS; i++) {
36            sprintf(source, "key_mapping/key_%i/source", i);
37            sprintf(dest, "key_mapping/key_%i/dest", i);
38            ps = awr->awar(source)->read_string();
39            pd = awr->awar(dest)->read_string();
40            if (strlen(ps) && strlen(pd)) {
41                map[(unsigned char)ps[0]] = pd[0];
42            }
43            free(ps);
44            free(pd);
45        }
46    }
47}
48
49static void ed_rehash_mapping(AW_root *awr, ed_key *ek) {
50    ek->rehash_mapping(awr);
51}
52
53void ed_key::create_awars(AW_root *awr)
54{
55    char source[256];
56    char dest[256];
57    int i;
58    for (i=0; i<MAX_MAPPED_KEYS; i++) {
59        sprintf(source, "key_mapping/key_%i/source", i);
60        sprintf(dest, "key_mapping/key_%i/dest", i);
61        awr->awar_string(source, "", AW_ROOT_DEFAULT);
62        awr->awar(source)->add_callback((AW_RCB1)ed_rehash_mapping, (AW_CL)this);
63        awr->awar_string(dest, "", AW_ROOT_DEFAULT);
64        awr->awar(dest)->add_callback((AW_RCB1)ed_rehash_mapping, (AW_CL)this);
65    }
66    awr->awar_int("key_mapping/enable", 1, AW_ROOT_DEFAULT);
67    awr->awar("key_mapping/enable")->add_callback((AW_RCB1)ed_rehash_mapping, (AW_CL)this);
68    ed_rehash_mapping(awr, this);
69}
70
71AW_window *create_key_map_window(AW_root *root)
72{
73    AW_window_simple *aws = new AW_window_simple;
74    aws->init(root, "KEY_MAPPING_PROPS", "KEY MAPPINGS");
75    aws->load_xfig("ed_key.fig");
76
77    aws->callback((AW_CB0)AW_POPDOWN);
78    aws->at("close");
79    aws->create_button("CLOSE", "CLOSE", "C");
80
81    aws->callback(AW_POPUP_HELP, (AW_CL)"nekey_map.hlp");
82    aws->at("help");
83    aws->create_button("HELP", "HELP", "H");
84
85    aws->at("data");
86    aws->auto_space(10, 0);
87
88    char source[256];
89    char dest[256];
90    int i;
91    for (i=0; i<MAX_MAPPED_KEYS; i++) {
92        sprintf(source, "key_mapping/key_%i/source", i);
93        sprintf(dest, "key_mapping/key_%i/dest", i);
94        aws->create_input_field(source, 3);
95        aws->create_input_field(dest, 3);
96        aws->at_newline();
97    }
98    aws->at("enable");
99    aws->create_toggle("key_mapping/enable");
100    return (AW_window *)aws;
101}
Note: See TracBrowser for help on using the browser.