view src/win32/CmdAccelOb.cpp @ 4:5f6f2134e8ce

apu appears to not be used
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:35:58 -0600
parents f9f4f1b99eed
children
line wrap: on
line source
1 ////////////////////////////////////////////////////////////////////////////////
2 // Copyright (C) 1998 by Thierry Maurel
3 // All rights reserved
4 //
5 // Distribute freely, except: don't remove my name from the source or
6 // documentation (don't take credit for my work), mark your changes (don't
7 // get me blamed for your possible bugs), don't alter or remove this
8 // notice.
9 // No warrantee of any kind, express or implied, is included with this
10 // software; use at your own risk, responsibility for damages (if any) to
11 // anyone resulting from the use of this software rests entirely with the
12 // user.
13 //
14 // Send bug reports, bug fixes, enhancements, requests, flames, etc., and
15 // I'll try to keep a version up to date. I can be reached as follows:
16 // tmaurel@caramail.com (or tmaurel@hol.fr)
17 //
18 ////////////////////////////////////////////////////////////////////////////////
19 // File : CmdAccelOb.cpp
20 // Project : AccelsEditor
21 ////////////////////////////////////////////////////////////////////////////////
22 // Version : 1.0 * Author : T.Maurel
23 // Date : 17.08.98
24 //
25 // Remarks :
26 //
27 ////////////////////////////////////////////////////////////////////////////////
28 // modified by the VBA-rr team
30 #include "stdafx.h"
31 #include "CmdAccelOb.h"
33 ////////////////////////////////////////////////////////////////////////
34 //
35 //
36 MAPVIRTKEYS mapVirtKeys[] = {
37 { VK_LBUTTON, "LBUTTON" },
38 { VK_RBUTTON, "RBUTTON" },
39 { VK_CANCEL, "Cancel" },
40 { VK_MBUTTON, "MBUTTON" },
41 { VK_BACK, "Backspace" },
42 { VK_TAB, "Tab" },
43 { VK_CLEAR, "Clear" },
44 { VK_RETURN, "Enter" },
45 { VK_SHIFT, "Shift" },
46 { VK_LSHIFT, "LShift" },
47 { VK_RSHIFT, "RShift" },
48 { VK_CONTROL, "Control" },
49 { VK_LCONTROL, "LControl" },
50 { VK_RCONTROL, "RControl" },
51 { VK_MENU, "Alt" },
52 { VK_LMENU, "LAlt" },
53 { VK_RMENU, "RAlt" },
54 { VK_PAUSE, "Pause" },
55 { VK_CAPITAL, "Caps Lock" },
56 { VK_ESCAPE, "Escape" },
57 { VK_SPACE, "Space" },
58 { VK_PRIOR, "Prior" },
59 { VK_NEXT, "Next" },
60 { VK_END, "End" },
61 { VK_HOME, "Home" },
62 { VK_LEFT, "Left" },
63 { VK_UP, "Up" },
64 { VK_RIGHT, "Right" },
65 { VK_DOWN, "Down" },
66 { VK_SELECT, "Select" },
67 { VK_PRINT, "Print" },
68 { VK_EXECUTE, "Execute" },
69 { VK_SNAPSHOT, "Snapshot" },
70 { VK_INSERT, "Insert" },
71 { VK_DELETE, "Delete" },
72 { VK_HELP, "Help" },
73 { WORD('0'), "0" },
74 { WORD('1'), "1" },
75 { WORD('2'), "2" },
76 { WORD('3'), "3" },
77 { WORD('4'), "4" },
78 { WORD('5'), "5" },
79 { WORD('6'), "6" },
80 { WORD('7'), "7" },
81 { WORD('8'), "8" },
82 { WORD('9'), "9" },
83 { WORD('A'), "A" },
84 { WORD('B'), "B" },
85 { WORD('C'), "C" },
86 { WORD('D'), "D" },
87 { WORD('E'), "E" },
88 { WORD('F'), "F" },
89 { WORD('G'), "G" },
90 { WORD('H'), "H" },
91 { WORD('I'), "I" },
92 { WORD('J'), "J" },
93 { WORD('K'), "K" },
94 { WORD('L'), "L" },
95 { WORD('M'), "M" },
96 { WORD('N'), "N" },
97 { WORD('O'), "O" },
98 { WORD('P'), "P" },
99 { WORD('Q'), "Q" },
100 { WORD('R'), "R" },
101 { WORD('S'), "S" },
102 { WORD('T'), "T" },
103 { WORD('U'), "U" },
104 { WORD('V'), "V" },
105 { WORD('W'), "W" },
106 { WORD('X'), "X" },
107 { WORD('Y'), "Y" },
108 { WORD('Z'), "Z" },
109 { VK_LWIN, "LWIN" },
110 { VK_RWIN, "RWIN" },
111 { VK_APPS, "APPS" },
112 { VK_NUMPAD0, "NumPad0" },
113 { VK_NUMPAD1, "NumPad1" },
114 { VK_NUMPAD2, "NumPad2" },
115 { VK_NUMPAD3, "NumPad3" },
116 { VK_NUMPAD4, "NumPad4" },
117 { VK_NUMPAD5, "NumPad5" },
118 { VK_NUMPAD6, "NumPad6" },
119 { VK_NUMPAD7, "NumPad7" },
120 { VK_NUMPAD8, "NumPad8" },
121 { VK_NUMPAD9, "NumPad9" },
122 { VK_MULTIPLY, "NumpadMultiply" },
123 { VK_ADD, "NumpadAdd" },
124 { VK_SEPARATOR, "Separator" },
125 { VK_SUBTRACT, "NumpadSubtract" },
126 { VK_DECIMAL, "NumpadDecimal" },
127 { VK_DIVIDE, "NumpadDivide" },
128 { VK_F1, "F1" },
129 { VK_F2, "F2" },
130 { VK_F3, "F3" },
131 { VK_F4, "F4" },
132 { VK_F5, "F5" },
133 { VK_F6, "F6" },
134 { VK_F7, "F7" },
135 { VK_F8, "F8" },
136 { VK_F9, "F9" },
137 { VK_F10, "F10" },
138 { VK_F11, "F11" },
139 { VK_F12, "F12" },
140 { VK_F13, "F13" },
141 { VK_F14, "F14" },
142 { VK_F15, "F15" },
143 { VK_F16, "F16" },
144 { VK_F17, "F17" },
145 { VK_F18, "F18" },
146 { VK_F19, "F19" },
147 { VK_F20, "F20" },
148 { VK_F21, "F21" },
149 { VK_F22, "F22" },
150 { VK_F23, "F23" },
151 { VK_F24, "F24" },
152 { VK_NUMLOCK, "Num Lock" },
153 { VK_SCROLL, "Scroll Lock" },
154 { VK_ATTN, "Attention" },
155 { VK_CRSEL, "CRSEL" },
156 { VK_EXSEL, "EXSEL" },
157 { VK_EREOF, "EREOF" },
158 { VK_PLAY, "Play" },
159 { VK_ZOOM, "Zoom" },
160 { VK_NONAME, "No Name" },
161 { VK_PA1, "PA1" },
162 { VK_OEM_CLEAR, "Clear2" },
163 { VK_OEM_1, "Semicolon;" },
164 { VK_OEM_2, "Slash/" },
165 { VK_OEM_3, "Tilde~" },
166 { VK_OEM_4, "LBracket[" },
167 { VK_OEM_5, "Backslash\\" },
168 { VK_OEM_6, "RBracket]" },
169 { VK_OEM_7, "Apostrophe'" },
170 { VK_OEM_8, "OEM8" },
171 { VK_OEM_PLUS, "Plus+" },
172 { VK_OEM_MINUS, "Minus-" },
173 { VK_OEM_COMMA, "Comma," },
174 { VK_OEM_PERIOD, "Period." },
175 { VK_OEM_AX, "Apostrophe`" },
176 { VK_OEM_102, "<> or \\|" },
177 { VK_ICO_HELP, "ICO Help" },
178 { VK_ICO_00, "ICO 00" },
179 { VK_OEM_FJ_JISHO, "JISHO" },
180 { VK_OEM_FJ_MASSHOU, "MASSHOU" },
181 { VK_OEM_FJ_TOUROKU, "TOUROKU" },
182 { VK_OEM_FJ_LOYA, "LOYA" },
183 { VK_OEM_FJ_ROYA, "ROYA" },
184 { VK_OEM_NEC_EQUAL, "Numpad Equals" },
185 };
187 ////////////////////////////////////////////////////////////////////////
188 //
189 //
190 MAPVIRTKEYS mapVirtSysKeys[] = {
191 { FCONTROL, "Ctrl" },
192 { FALT, "Alt" },
193 { FSHIFT, "Shift" },
194 };
196 ////////////////////////////////////////////////////////////////////////
197 // helper fct for external access
198 ////////////////////////////////////////////////////////////////////////
199 //
200 //
201 TCHAR *mapVirtKeysStringFromWORD(WORD wKey)
202 {
203 for (int index = 0; index < sizeof(mapVirtKeys) / sizeof(mapVirtKeys[0]); index++)
204 {
205 if (mapVirtKeys[index].wKey == wKey)
206 return mapVirtKeys[index].szKey;
207 }
208 return NULL;
209 }
211 ////////////////////////////////////////////////////////////////////////
212 //
213 #define DEFAULT_ACCEL 0x01
214 #define USER_ACCEL 0x02
216 ////////////////////////////////////////////////////////////////////////
217 //
218 ////////////////////////////////////////////////////////////////////////
219 //
220 //
221 CAccelsOb::CAccelsOb()
222 {
223 m_cVirt = 0;
224 m_wKey = 0;
225 m_bLocked = false;
226 }
228 ////////////////////////////////////////////////////////////////////////
229 //
230 //
231 CAccelsOb::CAccelsOb(CAccelsOb *pFrom)
232 {
233 ASSERT(pFrom != NULL);
235 m_cVirt = pFrom->m_cVirt;
236 m_wKey = pFrom->m_wKey;
237 m_bLocked = pFrom->m_bLocked;
238 }
240 ////////////////////////////////////////////////////////////////////////
241 //
242 //
243 CAccelsOb::CAccelsOb(BYTE cVirt, WORD wKey, bool bLocked)
244 {
245 m_cVirt = cVirt;
246 m_wKey = wKey;
247 m_bLocked = bLocked;
248 }
250 ////////////////////////////////////////////////////////////////////////
251 //
252 //
253 CAccelsOb::CAccelsOb(LPACCEL pACCEL)
254 {
255 ASSERT(pACCEL != NULL);
257 m_cVirt = pACCEL->fVirt;
258 m_wKey = pACCEL->key;
259 m_bLocked = false;
260 }
262 ////////////////////////////////////////////////////////////////////////
263 //
264 //
265 CAccelsOb & CAccelsOb::operator=(const CAccelsOb &from)
266 {
267 m_cVirt = from.m_cVirt;
268 m_wKey = from.m_wKey;
269 m_bLocked = from.m_bLocked;
271 return *this;
272 }
274 ////////////////////////////////////////////////////////////////////////
275 //
276 ////////////////////////////////////////////////////////////////////////
277 //
278 //
279 void CAccelsOb::GetString(CString &szBuffer)
280 {
281 szBuffer = "";
283 // modifiers part
284 for (int i = 0; i < sizetable(mapVirtSysKeys); i++)
285 {
286 if (m_cVirt & mapVirtSysKeys[i].wKey)
287 {
288 szBuffer += mapVirtSysKeys[i].szKey;
289 if (m_wKey)
290 szBuffer += "+";
291 }
292 }
294 // in case of the object is not assigned, we avoid error messages
295 if (m_wKey == 0)
296 return;
298 // and virtual key part
299 for (int i = 0; i < sizetable(mapVirtKeys); i++)
300 {
301 if (m_wKey == mapVirtKeys[i].wKey)
302 {
303 szBuffer += mapVirtKeys[i].szKey;
304 return;
305 }
306 }
308 AfxMessageBox("Internal error : (CAccelsOb::GetString) m_wKey invalid");
309 }
311 ////////////////////////////////////////////////////////////////////////
312 //
313 //
314 bool CAccelsOb::IsEqual(WORD wKey, bool bCtrl, bool bAlt, bool bShift)
315 {
316 bool m_bCtrl = (m_cVirt & FCONTROL) ? true : false;
317 bool m_bAlt = (m_cVirt & FALT) ? true : false;
318 bool m_bShift = (m_cVirt & FSHIFT) ? true : false;
320 bool bRet = (bCtrl == m_bCtrl) && (bAlt == m_bAlt) && (bShift == m_bShift) && (m_wKey == wKey);
322 return bRet;
323 }
325 ////////////////////////////////////////////////////////////////////////
326 //
327 //
328 DWORD CAccelsOb::GetData()
329 {
330 BYTE cLocalCodes = 0;
331 if (m_bLocked)
332 cLocalCodes = DEFAULT_ACCEL;
333 else
334 cLocalCodes = USER_ACCEL;
336 WORD bCodes = MAKEWORD(m_cVirt, cLocalCodes);
337 return MAKELONG(m_wKey, bCodes);
338 }
340 ////////////////////////////////////////////////////////////////////////
341 //
342 //
343 bool CAccelsOb::SetData(DWORD dwDatas)
344 {
345 m_wKey = LOWORD(dwDatas);
347 WORD bCodes = HIWORD(dwDatas);
348 m_cVirt = LOBYTE(bCodes);
350 BYTE cLocalCodes = HIBYTE(bCodes);
351 m_bLocked = (cLocalCodes == DEFAULT_ACCEL);
353 return true;
354 }
356 ////////////////////////////////////////////////////////////////////////
357 //
358 #ifdef _DEBUG
359 ////////////////////////////////////////////////////////////////////////
360 //
361 //
362 void CAccelsOb::AssertValid() const
363 {
364 CObject::AssertValid();
365 }
367 ////////////////////////////////////////////////////////////////////////
368 //
369 //
370 void CAccelsOb::Dump(CDumpContext &dc) const
371 {
372 dc << "\t\t";
373 CObject::Dump(dc);
374 dc << "\t\tlocked=" << m_bLocked << ", cVirt=" << m_cVirt << ", wKey=" << m_wKey << "\n\n";
375 }
377 #endif
379 ////////////////////////////////////////////////////////////////////////
380 //
381 ////////////////////////////////////////////////////////////////////////
382 //
383 //
384 CCmdAccelOb::CCmdAccelOb()
385 {}
387 ////////////////////////////////////////////////////////////////////////
388 //
389 //
390 CCmdAccelOb::CCmdAccelOb(WORD wIDCommand, LPCTSTR szCommand)
391 {
392 ASSERT(szCommand != NULL);
394 m_wIDCommand = wIDCommand;
395 m_szCommand = szCommand;
396 }
398 ////////////////////////////////////////////////////////////////////////
399 //
400 //
401 CCmdAccelOb::CCmdAccelOb(BYTE cVirt, WORD wIDCommand, WORD wKey, LPCTSTR szCommand, bool bLocked)
402 {
403 ASSERT(szCommand != NULL);
405 m_wIDCommand = wIDCommand;
406 m_szCommand = szCommand;
408 CAccelsOb *pAccel = new CAccelsOb(cVirt, wKey, bLocked);
409 ASSERT(pAccel != NULL);
410 m_Accels.AddTail(pAccel);
411 }
413 ////////////////////////////////////////////////////////////////////////
414 //
415 //
416 CCmdAccelOb::~CCmdAccelOb()
417 {
418 POSITION pos = m_Accels.GetHeadPosition();
419 while (pos != NULL)
420 delete m_Accels.GetNext(pos);
421 m_Accels.RemoveAll();
422 }
424 ////////////////////////////////////////////////////////////////////////
425 //
426 ////////////////////////////////////////////////////////////////////////
427 //
428 //
429 void CCmdAccelOb::Add(BYTE cVirt, WORD wKey, bool bLocked)
430 {
431 CAccelsOb *pAccel = new CAccelsOb(cVirt, wKey, bLocked);
432 ASSERT(pAccel != NULL);
433 m_Accels.AddTail(pAccel);
434 }
436 ////////////////////////////////////////////////////////////////////////
437 //
438 //
439 void CCmdAccelOb::Add(CAccelsOb *pAccel)
440 {
441 ASSERT(pAccel != NULL);
442 m_Accels.AddTail(pAccel);
443 }
445 ////////////////////////////////////////////////////////////////////////
446 //
447 //
448 CCmdAccelOb & CCmdAccelOb::operator=(const CCmdAccelOb &from)
449 {
450 Reset();
452 m_wIDCommand = from.m_wIDCommand;
453 m_szCommand = from.m_szCommand;
455 CAccelsOb *pAccel;
456 POSITION pos = from.m_Accels.GetHeadPosition();
457 while (pos != NULL)
458 {
459 pAccel = new CAccelsOb(from.m_Accels.GetNext(pos));
460 ASSERT(pAccel != NULL);
461 m_Accels.AddTail(pAccel);
462 }
463 return *this;
464 }
466 ////////////////////////////////////////////////////////////////////////
467 //
468 //
469 void CCmdAccelOb::DeleteUserAccels()
470 {
471 CAccelsOb *pAccel;
472 POSITION prevPos;
473 POSITION pos = m_Accels.GetHeadPosition();
474 while (pos != NULL)
475 {
476 prevPos = pos;
477 pAccel = m_Accels.GetNext(pos);
478 if (!pAccel->m_bLocked)
479 {
480 delete pAccel;
481 m_Accels.RemoveAt(prevPos);
482 }
483 }
484 }
486 ////////////////////////////////////////////////////////////////////////
487 //
488 //
489 void CCmdAccelOb::Reset()
490 {
491 m_wIDCommand = 0;
492 m_szCommand = "Empty command";
494 CAccelsOb *pAccel;
495 POSITION pos = m_Accels.GetHeadPosition();
496 while (pos != NULL)
497 {
498 pAccel = m_Accels.GetNext(pos);
499 delete pAccel;
500 }
501 }
503 ////////////////////////////////////////////////////////////////////////
504 //
505 #ifdef _DEBUG
506 ////////////////////////////////////////////////////////////////////////
507 //
508 //
509 void CCmdAccelOb::AssertValid() const
510 {
511 // call base class function first
512 CObject::AssertValid();
513 }
515 ////////////////////////////////////////////////////////////////////////
516 //
517 //
518 void CCmdAccelOb::Dump(CDumpContext &dc) const
519 {
520 // call base class function first
521 dc << "\t";
522 CObject::Dump(dc);
524 // now do the stuff for our specific class
525 dc << "\tIDCommand = " << m_wIDCommand;
526 dc << "\n\tszCommand = " << m_szCommand;
527 dc << "\n\tAccelerators = {\n";
529 CAccelsOb *pAccel;
530 POSITION pos = m_Accels.GetHeadPosition();
531 while (pos != NULL)
532 {
533 pAccel = m_Accels.GetNext(pos);
534 dc << pAccel;
535 }
536 dc << "\t}\n";
537 }
539 #endif