dlgTextEntry_Keyboard: rename to TouchTextEntry
[xcsoar.git] / src / Input / InputConfig.hpp
blob4b31525b09483e554d0a0e8dd7d8ea03edf3506b
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #ifndef XCSOAR_INPUT_CONFIG_HPP
25 #define XCSOAR_INPUT_CONFIG_HPP
27 #include "InputQueue.hpp"
28 #include "Menu/MenuData.hpp"
29 #include "Util/RadixTree.hpp"
30 #include "Util/StaticString.hpp"
31 #include "Util/TrivialArray.hpp"
33 #include <assert.h>
34 #include <tchar.h>
36 struct InputConfig {
37 // Sensible maximums
38 enum {
39 MAX_MODE = 32,
40 MAX_MODE_STRING = 24,
41 #ifdef ENABLE_SDL
42 MAX_KEY = 400,
43 #elif defined(USE_EGL)
44 MAX_KEY = 0600,
45 #else
46 MAX_KEY = 255,
47 #endif
48 MAX_EVENTS = 2048,
51 typedef void (*pt2Event)(const TCHAR *);
53 // Events - What do you want to DO
54 struct Event {
55 // Which function to call (can be any, but should be here)
56 pt2Event event;
57 // Parameters
58 const TCHAR *misc;
59 // Next in event list - eg: Macros
60 unsigned next;
63 /** Map mode to location */
64 TrivialArray<StaticString<MAX_MODE_STRING>, MAX_MODE> modes;
66 // Key map to Event - Keys (per mode) mapped to events
67 unsigned short Key2Event[MAX_MODE][MAX_KEY]; // Points to Events location
69 RadixTree<unsigned> Gesture2Event;
71 // Glide Computer Events
72 unsigned short GC2Event[GCE_COUNT];
74 // NMEA Triggered Events
75 unsigned short N2Event[NE_COUNT];
77 TrivialArray<Event, MAX_EVENTS> events;
79 Menu menus[MAX_MODE];
81 void SetDefaults();
83 gcc_pure
84 int LookupMode(const TCHAR *name) const {
85 for (unsigned i = 0, size = modes.size(); i < size; ++i)
86 if (modes[i] == name)
87 return i;
89 return -1;
92 int AppendMode(const TCHAR *name) {
93 if (modes.full())
94 return -1;
96 modes.append() = name;
97 return modes.size() - 1;
100 gcc_pure
101 int MakeMode(const TCHAR *name) {
102 int mode = LookupMode(name);
103 if (mode < 0)
104 mode = AppendMode(name);
106 return mode;
109 unsigned AppendEvent(pt2Event handler, const TCHAR *misc,
110 unsigned next) {
111 if (events.full())
112 return 0;
114 Event &event = events.append();
115 event.event = handler;
116 event.misc = misc;
117 event.next = next;
119 return events.size() - 1;
122 void AppendMenu(unsigned mode_id, const TCHAR* label,
123 unsigned location, unsigned event_id) {
124 assert(mode_id < MAX_MODE);
126 menus[mode_id].Add(label, location, event_id);
129 gcc_pure
130 unsigned GetKeyEvent(unsigned mode, unsigned key_code) const {
131 assert(mode < MAX_MODE);
133 if (key_code >= MAX_KEY)
134 return 0;
136 if (mode > 0 && Key2Event[mode][key_code] != 0)
137 return Key2Event[mode][key_code];
139 /* fall back to the default mode */
140 return Key2Event[0][key_code];
143 gcc_pure
144 const MenuItem &GetMenuItem(unsigned mode, unsigned location) const {
145 assert(mode < MAX_MODE);
146 assert(location < Menu::MAX_ITEMS);
148 return menus[mode][location];
152 #endif