ARB
AWT_map_key.cxx
Go to the documentation of this file.
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 
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 
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 
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 
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 
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 
char read_mapping_awar(AW_root *awr, int idx, const char *subkey)
Definition: AWT_map_key.cxx:36
void add(const char *awar_name, const char *config_name)
#define MAPPED_KEYS
Definition: AWT_map_key.cxx:19
static char * y[maxsp+1]
AW_window * create_key_map_window(AW_root *root)
Definition: AWT_map_key.cxx:77
CONSTEXPR_INLINE unsigned char safeCharIndex(char c)
Definition: dupstr.h:73
void load_xfig(const char *file, bool resize=true)
Definition: AW_window.cxx:717
void AWT_insert_config_manager(AW_window *aww, AW_default default_file_, const char *id, const StoreConfigCallback &store_cb, const RestoreConfigCallback &load_or_reset_cb, const char *macro_id, const AWT_predefined_config *predef)
long read_int() const
Definition: AW_awar.cxx:187
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:204
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:234
char map_key(char) const
Definition: AWT_map_key.cxx:28
#define KEYS_PER_COLUMN
Definition: AWT_map_key.cxx:18
const char * read_char_pntr() const
Definition: AW_awar.cxx:171
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
void create_awars(AW_root *root)
Definition: AWT_map_key.cxx:59
void rehash_mapping(AW_root *awr)
Definition: AWT_map_key.cxx:41
const char * mapping_awar_name(int idx, const char *subkey)
Definition: AWT_map_key.cxx:33
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
static void ed_rehash_mapping(AW_root *awr, ed_key *ek)
Definition: AWT_map_key.cxx:55
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:580
#define AWAR_KEYMAPPING_ENABLE
Definition: AWT_map_key.cxx:21
static void setup_keymap_config(AWT_config_definition &cdef)
Definition: AWT_map_key.cxx:70
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:570
#define AW_ROOT_DEFAULT
Definition: aw_base.hxx:106