sdk: const correctness
[sdk] / ecere / src / gui / Key.ec
1 namespace gui;
2
3 import "Window"
4
5 public class Key
6 {
7 public:
8    KeyCode code:16;
9    bool shift:1, ctrl:1, alt:1, cmd:1;
10    Modifiers modifiers:16:16;
11    property SmartKey
12    {
13       get
14       {
15          SmartKey result = SmartKey { modifiers = modifiers };
16          switch(code)
17          {
18             case keyPadEnter:
19                return enter | result;
20             case keyPadLeft: return left | result;
21             case keyPadRight: return right | result;
22             case keyPadUp: return up | result;
23             case keyPadDown: return down | result;
24             case keyPadPageUp: return pageUp | result;
25             case keyPadPageDown: return pageDown | result;
26             case keyPadHome: return home | result;
27             case keyPadEnd: return end | result;
28             case keyPadStar: return k8 | result;
29             case keyPadSlash: return slash | result;
30             case keyPadMinus: return minus | result;
31             case keyPadPlus: return equal | result;
32             case keyPadDelete: return del | result;
33             case keyPadInsert: return insert | result;
34             case leftAlt: case rightAlt: return KeyCode::alt | result;
35             case leftControl: case rightControl: return KeyCode::control | result;
36             case rightShift: case leftShift: return KeyCode::shift | result;
37             default:
38                return (uint)this;
39          }
40       }
41    };
42
43    const char * OnGetString(char * stringOutput, void * fieldData, bool * needClass)
44    {
45       const char * string;
46       if((string = ((PredefinedKey)this).class::OnGetString(stringOutput, null, needClass /*null*/)))
47       {
48          if(needClass) *needClass = false;
49          return string;
50       }
51       else if((string = ((KeyCode)this).class::OnGetString(stringOutput, null, needClass /*null*/)))
52       {
53          if(needClass) *needClass = false;
54          return string;
55       }
56       else
57       {
58          return class::OnGetString(stringOutput, fieldData, needClass);
59       }
60    }
61
62    bool OnGetDataFromString(const char * string)
63    {
64       if(((PredefinedKey)this).class::OnGetDataFromString(string))
65          return true;
66       else
67          return class::OnGetDataFromString(string);
68    }
69 };
70
71 public class SmartKey
72 {
73 public:
74    KeyCode code:16;
75    bool shift:1, ctrl:1, alt:1;
76    Modifiers modifiers:16:16;
77 };
78
79 public enum KeyCode : Key
80 {
81    escape            = 0x01,
82    // Characters
83    k1                = 0x02,
84    bang              = 0x02,
85    k2                = 0x03,
86    commercial        = 0x03,
87    k3                = 0x04,
88    pound             = 0x04,
89    k4                = 0x05,
90    dollar            = 0x05,
91    k5                = 0x06,
92    percent           = 0x06,
93    k6                = 0x07,
94    circumflex        = 0x07,
95    k7                = 0x08,
96    ampersand         = 0x08,
97    k8                = 0x09,
98    star              = 0x09,
99    k9                = 0x0A,
100    leftParanthesis   = 0x0A,
101    k0                = 0x0B,
102    rightParanthesis  = 0x0A,
103    minus             = 0x0C,
104    underscore        = 0x0C,
105    equal             = 0x0D,
106    plus              = 0x0D,
107    backSpace         = 0x0E,
108    tab               = 0x0F,
109    q                 = 0x10,
110    w                 = 0x11,
111    e                 = 0x12,
112    r                 = 0x13,
113    t                 = 0x14,
114    y                 = 0x15,
115    u                 = 0x16,
116    i                 = 0x17,
117    o                 = 0x18,
118    p                 = 0x19,
119    leftBracket       = 0x1A,
120    rightBracket      = 0x1B,
121    enter             = 0x1C,
122    leftControl       = 0x1D,
123    a                 = 0x1E,
124    s                 = 0x1F,
125    d                 = 0x20,
126    f                 = 0x21,
127    g                 = 0x22,
128    h                 = 0x23,
129    j                 = 0x24,
130    k                 = 0x25,
131    l                 = 0x26,
132    semicolon         = 0x27,
133    colon             = 0x27,
134    quote             = 0x28,
135    doubleQuote       = 0x28,
136    tilde             = 0x29,
137    backQuote         = 0x29,
138    leftShift         = 0x2A,
139    backSlash         = 0x2B,
140    pipe              = 0x2B,
141    z                 = 0x2C,
142    x                 = 0x2D,
143    c                 = 0x2E,
144    v                 = 0x2F,
145    b                 = 0x30,
146    n                 = 0x31,
147    m                 = 0x32,
148    comma             = 0x33,
149    smallerThan       = 0x33,
150    period            = 0x34,
151    greaterThan       = 0x34,
152    slash             = 0x35,
153    questionMark      = 0x35,
154
155    rightShift        = 0x36,
156    keyPadStar        = 0x37,
157    leftAlt           = 0x38,
158    space             = 0x39,
159
160    capsLock          = 0x3A,
161
162    // Function keys 1-10
163    f1                = 0x3B,
164    f2                = 0x3C,
165    f3                = 0x3D,
166    f4                = 0x3E,
167    f5                = 0x3F,
168    f6                = 0x40,
169    f7                = 0x41,
170    f8                = 0x42,
171    f9                = 0x43,
172    f10               = 0x44,
173
174    // Num Pad
175    numLock           = 0x45,
176    scrollLock        = 0x46,
177    keyPadHome        = 0x47,
178    keyPad7           = 0x47,
179    keyPadUp          = 0x48,
180    keyPad8           = 0x48,
181    keyPadPageUp      = 0x49,
182    keyPad9           = 0x49,
183    keyPadMinus       = 0x4A,
184    keyPadLeft        = 0x4B,
185    keyPad4           = 0x4B,
186    keyPad5           = 0x4C,
187    keyPadRight       = 0x4D,
188    keyPad6           = 0x4D,
189    keyPadPlus        = 0x4E,
190    keyPadEnd         = 0x4F,
191    keyPad1           = 0x4F,
192    keyPadDown        = 0x50,
193    keyPad2           = 0x50,
194    keyPadPageDown    = 0x51,
195    keyPad3           = 0x51,
196    keyPadInsert      = 0x52,
197    keyPad0           = 0x52,
198    keyPadDelete      = 0x53,
199    // KeyPadLess        = 0x56,
200
201    // F11-F12
202    f11               = 0x57,
203    f12               = 0x58,
204
205    keyPadEnter       = 0x60,
206    rightControl      = 0x61,
207    keyPadSlash       = 0x62,
208    printScreen       = 0x63,
209    rightAlt          = 0x64,
210    pauseBreak        = 0x65,
211
212    // Function Pad
213    home              = 0x66,
214    up                = 0x67,
215    pageUp            = 0x68,
216    left              = 0x69,
217    right             = 0x6A,
218    end               = 0x6B,
219    down              = 0x6C,
220    pageDown          = 0x6D,
221    insert            = 0x6E,
222    del               = 0x6F,
223
224    // Pseudo keys
225    shift             = 0x100,
226    alt               = 0x101,
227    control           = 0x102,
228    wheelUp           = 0x103,
229    wheelDown         = 0x104,
230    hotKey            = 0x105,
231    defaultKey        = 0x106,
232    capsState         = 0x107,
233    numState          = 0x108,
234    scrollState       = 0x109,
235
236    // Remote Control Buttons
237    play              = 0x201,
238    record            = 0x202,
239    pause             = 0x203,
240    rewind            = 0x204,
241    fastForward       = 0x205,
242    previousTrack     = 0x206,
243    nextTrack         = 0x207,
244    stop              = 0x208,
245    eject             = 0x209,
246    volumeUp          = 0x20A,
247    volumeDown        = 0x20B,
248    mute              = 0x20C,
249    remoteHome        = 0x213,
250    back              = f1,
251    menu1             = f2,
252    menu2             = f3,
253    menu3             = f4,
254    menu4             = f5,
255    select            = enter
256 };
257
258 public class Modifiers
259 {
260    const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
261    {
262       if(needClass) *needClass = false;
263       return 0;
264    };
265
266    public bool shift:1, ctrl:1, alt:1, cmd:1, left:1, middle:1, right:1, isActivate:1, isSideEffect:1, closingDropDown:1;
267 };
268
269 public enum PredefinedKey : Key
270 {
271    alt0 = Key { k0, alt = true },
272    alt1 = Key { k1, alt = true },
273    alt2 = Key { k2, alt = true },
274    alt3 = Key { k3, alt = true },
275    alt4 = Key { k4, alt = true },
276    alt5 = Key { k5, alt = true },
277    alt6 = Key { k6, alt = true },
278    alt7 = Key { k7, alt = true },
279    alt8 = Key { k8, alt = true },
280    alt9 = Key { k9, alt = true },
281    altA = Key { a, alt = true },
282    altB = Key { b, alt = true },
283    altC = Key { c, alt = true },
284    altD = Key { d, alt = true },
285    altE = Key { e, alt = true },
286    altF = Key { f, alt = true },
287    altG = Key { g, alt = true },
288    altH = Key { h, alt = true },
289    altI = Key { i, alt = true },
290    altJ = Key { j, alt = true },
291    altK = Key { k, alt = true },
292    altL = Key { l, alt = true },
293    altM = Key { m, alt = true },
294    altN = Key { n, alt = true },
295    altO = Key { o, alt = true },
296    altP = Key { p, alt = true },
297    altQ = Key { q, alt = true },
298    altR = Key { r, alt = true },
299    altS = Key { s, alt = true },
300    altT = Key { t, alt = true },
301    altU = Key { u, alt = true },
302    altV = Key { v, alt = true },
303    altW = Key { w, alt = true },
304    altX = Key { x, alt = true },
305    altY = Key { y, alt = true },
306    altZ = Key { z, alt = true },
307    altF1 = Key { f1, alt = true },
308    altF2 = Key { f2, alt = true },
309    altF3 = Key { f3, alt = true },
310    altF4 = Key { f4, alt = true },
311    altF5 = Key { f5, alt = true },
312    altF6 = Key { f6, alt = true },
313    altF7 = Key { f7, alt = true },
314    altF8 = Key { f8, alt = true },
315    altF9 = Key { f9, alt = true },
316    altF10 = Key { f10, alt = true },
317    altF11 = Key { f11, alt = true },
318    altF12 = Key { f12, alt = true },
319    altLeft = Key { left, alt = true },
320    altRight = Key { right, alt = true },
321    altUp = Key { up, alt = true },
322    altDown = Key { down, alt = true },
323    altEnter = Key { enter, alt = true },
324    altKeyPadEnter = Key { keyPadEnter, alt = true },
325    altHome = Key { home, alt = true },
326    altEnd = Key { end, alt = true },
327    altMinus = Key { minus, alt = true },
328    altSpace = Key { space, alt = true },
329
330    ctrl0 = Key { k0, ctrl = true },
331    ctrl1 = Key { k1, ctrl = true },
332    ctrl2 = Key { k2, ctrl = true },
333    ctrl3 = Key { k3, ctrl = true },
334    ctrl4 = Key { k4, ctrl = true },
335    ctrl5 = Key { k5, ctrl = true },
336    ctrl6 = Key { k6, ctrl = true },
337    ctrl7 = Key { k7, ctrl = true },
338    ctrl8 = Key { k8, ctrl = true },
339    ctrl9 = Key { k9, ctrl = true },
340    ctrlA = Key { a, ctrl = true },
341    ctrlB = Key { b, ctrl = true },
342    ctrlC = Key { c, ctrl = true },
343    ctrlD = Key { d, ctrl = true },
344    ctrlE = Key { e, ctrl = true },
345    ctrlF = Key { f, ctrl = true },
346    ctrlG = Key { g, ctrl = true },
347    ctrlH = Key { h, ctrl = true },
348    ctrlI = Key { i, ctrl = true },
349    ctrlJ = Key { j, ctrl = true },
350    ctrlK = Key { k, ctrl = true },
351    ctrlL = Key { l, ctrl = true },
352    ctrlM = Key { m, ctrl = true },
353    ctrlN = Key { n, ctrl = true },
354    ctrlO = Key { o, ctrl = true },
355    ctrlP = Key { p, ctrl = true },
356    ctrlQ = Key { q, ctrl = true },
357    ctrlR = Key { r, ctrl = true },
358    ctrlS = Key { s, ctrl = true },
359    ctrlT = Key { t, ctrl = true },
360    ctrlU = Key { u, ctrl = true },
361    ctrlV = Key { v, ctrl = true },
362    ctrlW = Key { w, ctrl = true },
363    ctrlX = Key { x, ctrl = true },
364    ctrlY = Key { y, ctrl = true },
365    ctrlZ = Key { z, ctrl = true },
366    ctrlF1 = Key { f1, ctrl = true },
367    ctrlF2 = Key { f2, ctrl = true },
368    ctrlF3 = Key { f3, ctrl = true },
369    ctrlF4 = Key { f4, ctrl = true },
370    ctrlF5 = Key { f5, ctrl = true },
371    ctrlF6 = Key { f6, ctrl = true },
372    ctrlF7 = Key { f7, ctrl = true },
373    ctrlF8 = Key { f8, ctrl = true },
374    ctrlF9 = Key { f9, ctrl = true },
375    ctrlF10 = Key { f10, ctrl = true },
376    ctrlF11 = Key { f11, ctrl = true },
377    ctrlF12 = Key { f12, ctrl = true },
378    ctrlLeft = Key { left, ctrl = true },
379    ctrlRight = Key { right, ctrl = true },
380    ctrlUp = Key { up, ctrl = true },
381    ctrlDown = Key { down, ctrl = true },
382    ctrlEnter = Key { enter, ctrl = true },
383    ctrlHome = Key { home, ctrl = true },
384    ctrlEnd = Key { end, ctrl = true },
385    ctrlPageUp = Key { pageUp, ctrl = true },
386    ctrlPageDown = Key { pageDown, ctrl = true },
387    ctrlInsert = Key { insert, ctrl = true },
388    ctrlSpace = Key { space, ctrl = true },
389
390    shiftTab = Key { tab, shift = true },
391    shiftF1 = Key { f1, shift = true },
392    shiftF2 = Key { f2, shift = true },
393    shiftF3 = Key { f3, shift = true },
394    shiftF4 = Key { f4, shift = true },
395    shiftF5 = Key { f5, shift = true },
396    shiftF6 = Key { f6, shift = true },
397    shiftF7 = Key { f7, shift = true },
398    shiftF8 = Key { f8, shift = true },
399    shiftF9 = Key { f9, shift = true },
400    shiftF10 = Key { f10, shift = true },
401    shiftF11 = Key { f11, shift = true },
402    shiftF12 = Key { f12, shift = true },
403    shiftInsert = Key { insert, shift = true },
404    shiftDel = Key { del, shift = true }
405 };