-
Notifications
You must be signed in to change notification settings - Fork 0
/
Yata_keys.cs
279 lines (254 loc) · 7.06 KB
/
Yata_keys.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
using System;
using System.Drawing;
using System.Windows.Forms;
namespace yata
{
sealed partial class Yata
{
#region Fields (static)
int _dontbeep; // directs keydown [Enter] to the appropriate funct: Goto or Search
const int DONTBEEP_DEFAULT = 0;
const int DONTBEEP_GOTO = 1;
const int DONTBEEP_SEARCH = 2;
#endregion Fields (static)
#if Keys
protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
{
if ((e.KeyData & ~gc.ControlShift) != 0)
logfile.Log("Yata.OnPreviewKeyDown() e.KeyData= " + e.KeyData + " e.IsInputKey= " + e.IsInputKey);
base.OnPreviewKeyDown(e);
}
#endif
/// <summary>
/// Processes so-called command-keys.
/// </summary>
/// <param name="msg"></param>
/// <param name="keyData"></param>
/// <returns></returns>
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
#if Keys
if ((keyData & ~gc.ControlShift) != 0)
logfile.Log("Yata.ProcessCmdKey() keyData= " + keyData);
#endif
switch (keyData)
{
case Keys.Menu | Keys.Alt:
// NOTE: The Menubar container is by default TabStop=FALSE and ... (not) forced TRUE in Yata.cTor <-
// so it can never take focus - but its subcontrols are fucked re. "focus".
// ... because they aren't actually 'Controls'.
if (Table != null)
{
#if Keys
logfile.Log(". select Table");
#endif
// set '_editor.Visible' FALSE else its leave event
// fires twice when it loses focus ->
Table.editresultdefault();
Table.Select();
}
else
{
#if Keys
logfile.Log(". select Tabs");
#endif
Tabs.Select();
}
return false; // do not return True. [Alt] needs to 'activate' the Menubar.
}
bool ret = base.ProcessCmdKey(ref msg, keyData);
#if Keys
if ((keyData & ~gc.ControlShift) != 0)
logfile.Log(". Yata.ProcessCmdKey ret= " + ret);
#endif
return ret;
}
#if Keys
protected override bool IsInputKey(Keys keyData)
{
if ((keyData & ~gc.ControlShift) != 0)
logfile.Log("Yata.IsInputKey() keyData= " + keyData);
bool ret = base.IsInputKey(keyData);
if ((keyData & ~gc.ControlShift) != 0)
logfile.Log(". Yata.IsInputKey ret= " + ret);
return ret;
}
protected override bool ProcessDialogKey(Keys keyData)
{
if ((keyData & ~gc.ControlShift) != 0)
logfile.Log("Yata.ProcessDialogKey() keyData= " + keyData);
bool ret = base.ProcessDialogKey(keyData);
if ((keyData & ~gc.ControlShift) != 0)
logfile.Log(". Yata.ProcessDialogKey ret= " + ret);
return ret;
}
#endif
/// <summary>
/// Handles the <c>KeyDown</c> event at the form-level.
/// </summary>
/// <param name="e"></param>
/// <remarks>Requires the form's <c>KeyPreview</c> property flagged
/// <c>true</c>.
///
///
/// Fires repeatedly if a key is held depressed.</remarks>
protected override void OnKeyDown(KeyEventArgs e)
{
#if Keys
if ((e.KeyData & ~gc.ControlShift) != 0)
logfile.Log("Yata.OnKeyDown() e.KeyData= " + e.KeyData);
#endif
if (Table != null)
{
switch (e.KeyData)
{
case Keys.Enter: // do this here to get rid of the beep.
case Keys.Shift | Keys.Enter:
#if Keys
logfile.Log(". Keys.Enter");
#endif
if (tb_Search.Focused || cb_SearchOption.Focused)
{
#if Keys
if (e.KeyData == Keys.Enter) logfile.Log(". . Search forward");
else logfile.Log(". . Search reverse");
#endif
_dontbeep = DONTBEEP_SEARCH;
}
else if (tb_Goto.Focused && e.KeyData == Keys.Enter)
{
#if Keys
logfile.Log(". . Goto");
#endif
_dontbeep = DONTBEEP_GOTO;
}
else
{
#if Keys
logfile.Log(". . Search or Goto not focused");
#endif
_dontbeep = DONTBEEP_DEFAULT;
}
if (_dontbeep != DONTBEEP_DEFAULT)
{
e.SuppressKeyPress = true;
BeginInvoke(DontBeepEvent);
}
break;
case Keys.Escape:
#if Keys
logfile.Log(". Keys.Escape");
#endif
if (Tabs.Focused || bu_Propanel.Focused) // btn -> jic. The Propanel button can become focused by
{ // keyboard (I saw it happen once) but can't figure out how.
#if Keys // NOTE: It wasn't actually focused, it was a graphical glitch.
logfile.Log(". . deselect Tabs -> select Grid");
#endif
e.SuppressKeyPress = true;
Table.Select();
}
#if Keys
else logfile.Log(". . Tabs not focused");
#endif
break;
case Keys.Space:
#if Keys
logfile.Log(". Keys.Space");
#endif
if (!Table._editor.Visible
&& (Table.Propanel == null || !Table.Propanel._editor.Visible))
{
#if Keys
logfile.Log(". . select first cell");
#endif
e.SuppressKeyPress = true;
Table.SelectCell_first();
}
#if Keys
else logfile.Log(". . an Editor is visible -> do not select first cell");
#endif
break;
case Keys.Control | Keys.Space:
#if Keys
logfile.Log(". Keys.Control | Keys.Space");
#endif
if (!Table._editor.Visible
&& (Table.Propanel == null || !Table.Propanel._editor.Visible))
{
#if Keys
logfile.Log(". . select first row");
#endif
e.SuppressKeyPress = true;
Table.SelectRow_first();
}
#if Keys
else logfile.Log(". . an Editor is visible -> do not select first row");
#endif
break;
}
// clear the col-width adjustor on '_panelCols' ->
switch (e.KeyCode)
{
case Keys.Menu: // Keys.Alt
case Keys.ControlKey: // Keys.Control
case Keys.ShiftKey: // Keys.Shift
Table._panelCols.Cursor = Cursors.Default;
Table._panelCols.IsCursorSplit = false;
Table._panelCols.IsGrab = false;
break;
}
}
base.OnKeyDown(e);
}
/// <summary>
/// Overrides the <c>KeyUp</c> eventhandler. Enables the col-width
/// adjustor if appropriate.
/// </summary>
/// <param name="e"></param>
protected override void OnKeyUp(KeyEventArgs e)
{
if (Table != null)
{
// enable the col-width adjustor on '_panelCols' ->
switch (e.KeyCode)
{
case Keys.Menu: // Keys.Alt
case Keys.ControlKey: // Keys.Control
case Keys.ShiftKey: // Keys.Shift
if (ModifierKeys == Keys.None)
{
Point pos = Table._panelCols.PointToClient(Cursor.Position);
if (Table._panelCols.GetSplitterCol(pos.X) != -1
&& pos.Y >= Table._panelCols.Location.Y
&& pos.Y < Table._panelCols.Location.Y + Table._panelCols.Height)
{
Table._panelCols.Cursor = Cursors.VSplit;
Table._panelCols.IsCursorSplit = true;
}
}
break;
}
}
base.OnKeyUp(e);
}
/// <summary>
/// Forwards a <c>KeyDown</c> <c>[Enter]</c> event to an appropriate
/// funct.
/// </summary>
/// <remarks>Is basically just a convoluted handler for the
/// <c><see cref="OnKeyDown()">OnKeyDown()</see></c> handler to stop the
/// *beep* if <c>[Enter]</c> is keyed when a <c>TextBox</c> is focused.</remarks>
void HandleDontBeepEvent()
{
switch (_dontbeep)
{
case DONTBEEP_SEARCH:
Search_keyEnter();
break;
case DONTBEEP_GOTO:
Table.Goto(tb_Goto.Text, true);
break;
}
}
}
}