Mercurial > vba-clojure
diff src/win32/CmdAccelOb.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/win32/CmdAccelOb.cpp Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,539 @@ 1.4 +//////////////////////////////////////////////////////////////////////////////// 1.5 +// Copyright (C) 1998 by Thierry Maurel 1.6 +// All rights reserved 1.7 +// 1.8 +// Distribute freely, except: don't remove my name from the source or 1.9 +// documentation (don't take credit for my work), mark your changes (don't 1.10 +// get me blamed for your possible bugs), don't alter or remove this 1.11 +// notice. 1.12 +// No warrantee of any kind, express or implied, is included with this 1.13 +// software; use at your own risk, responsibility for damages (if any) to 1.14 +// anyone resulting from the use of this software rests entirely with the 1.15 +// user. 1.16 +// 1.17 +// Send bug reports, bug fixes, enhancements, requests, flames, etc., and 1.18 +// I'll try to keep a version up to date. I can be reached as follows: 1.19 +// tmaurel@caramail.com (or tmaurel@hol.fr) 1.20 +// 1.21 +//////////////////////////////////////////////////////////////////////////////// 1.22 +// File : CmdAccelOb.cpp 1.23 +// Project : AccelsEditor 1.24 +//////////////////////////////////////////////////////////////////////////////// 1.25 +// Version : 1.0 * Author : T.Maurel 1.26 +// Date : 17.08.98 1.27 +// 1.28 +// Remarks : 1.29 +// 1.30 +//////////////////////////////////////////////////////////////////////////////// 1.31 +// modified by the VBA-rr team 1.32 + 1.33 +#include "stdafx.h" 1.34 +#include "CmdAccelOb.h" 1.35 + 1.36 +//////////////////////////////////////////////////////////////////////// 1.37 +// 1.38 +// 1.39 +MAPVIRTKEYS mapVirtKeys[] = { 1.40 + { VK_LBUTTON, "LBUTTON" }, 1.41 + { VK_RBUTTON, "RBUTTON" }, 1.42 + { VK_CANCEL, "Cancel" }, 1.43 + { VK_MBUTTON, "MBUTTON" }, 1.44 + { VK_BACK, "Backspace" }, 1.45 + { VK_TAB, "Tab" }, 1.46 + { VK_CLEAR, "Clear" }, 1.47 + { VK_RETURN, "Enter" }, 1.48 + { VK_SHIFT, "Shift" }, 1.49 + { VK_LSHIFT, "LShift" }, 1.50 + { VK_RSHIFT, "RShift" }, 1.51 + { VK_CONTROL, "Control" }, 1.52 + { VK_LCONTROL, "LControl" }, 1.53 + { VK_RCONTROL, "RControl" }, 1.54 + { VK_MENU, "Alt" }, 1.55 + { VK_LMENU, "LAlt" }, 1.56 + { VK_RMENU, "RAlt" }, 1.57 + { VK_PAUSE, "Pause" }, 1.58 + { VK_CAPITAL, "Caps Lock" }, 1.59 + { VK_ESCAPE, "Escape" }, 1.60 + { VK_SPACE, "Space" }, 1.61 + { VK_PRIOR, "Prior" }, 1.62 + { VK_NEXT, "Next" }, 1.63 + { VK_END, "End" }, 1.64 + { VK_HOME, "Home" }, 1.65 + { VK_LEFT, "Left" }, 1.66 + { VK_UP, "Up" }, 1.67 + { VK_RIGHT, "Right" }, 1.68 + { VK_DOWN, "Down" }, 1.69 + { VK_SELECT, "Select" }, 1.70 + { VK_PRINT, "Print" }, 1.71 + { VK_EXECUTE, "Execute" }, 1.72 + { VK_SNAPSHOT, "Snapshot" }, 1.73 + { VK_INSERT, "Insert" }, 1.74 + { VK_DELETE, "Delete" }, 1.75 + { VK_HELP, "Help" }, 1.76 + { WORD('0'), "0" }, 1.77 + { WORD('1'), "1" }, 1.78 + { WORD('2'), "2" }, 1.79 + { WORD('3'), "3" }, 1.80 + { WORD('4'), "4" }, 1.81 + { WORD('5'), "5" }, 1.82 + { WORD('6'), "6" }, 1.83 + { WORD('7'), "7" }, 1.84 + { WORD('8'), "8" }, 1.85 + { WORD('9'), "9" }, 1.86 + { WORD('A'), "A" }, 1.87 + { WORD('B'), "B" }, 1.88 + { WORD('C'), "C" }, 1.89 + { WORD('D'), "D" }, 1.90 + { WORD('E'), "E" }, 1.91 + { WORD('F'), "F" }, 1.92 + { WORD('G'), "G" }, 1.93 + { WORD('H'), "H" }, 1.94 + { WORD('I'), "I" }, 1.95 + { WORD('J'), "J" }, 1.96 + { WORD('K'), "K" }, 1.97 + { WORD('L'), "L" }, 1.98 + { WORD('M'), "M" }, 1.99 + { WORD('N'), "N" }, 1.100 + { WORD('O'), "O" }, 1.101 + { WORD('P'), "P" }, 1.102 + { WORD('Q'), "Q" }, 1.103 + { WORD('R'), "R" }, 1.104 + { WORD('S'), "S" }, 1.105 + { WORD('T'), "T" }, 1.106 + { WORD('U'), "U" }, 1.107 + { WORD('V'), "V" }, 1.108 + { WORD('W'), "W" }, 1.109 + { WORD('X'), "X" }, 1.110 + { WORD('Y'), "Y" }, 1.111 + { WORD('Z'), "Z" }, 1.112 + { VK_LWIN, "LWIN" }, 1.113 + { VK_RWIN, "RWIN" }, 1.114 + { VK_APPS, "APPS" }, 1.115 + { VK_NUMPAD0, "NumPad0" }, 1.116 + { VK_NUMPAD1, "NumPad1" }, 1.117 + { VK_NUMPAD2, "NumPad2" }, 1.118 + { VK_NUMPAD3, "NumPad3" }, 1.119 + { VK_NUMPAD4, "NumPad4" }, 1.120 + { VK_NUMPAD5, "NumPad5" }, 1.121 + { VK_NUMPAD6, "NumPad6" }, 1.122 + { VK_NUMPAD7, "NumPad7" }, 1.123 + { VK_NUMPAD8, "NumPad8" }, 1.124 + { VK_NUMPAD9, "NumPad9" }, 1.125 + { VK_MULTIPLY, "NumpadMultiply" }, 1.126 + { VK_ADD, "NumpadAdd" }, 1.127 + { VK_SEPARATOR, "Separator" }, 1.128 + { VK_SUBTRACT, "NumpadSubtract" }, 1.129 + { VK_DECIMAL, "NumpadDecimal" }, 1.130 + { VK_DIVIDE, "NumpadDivide" }, 1.131 + { VK_F1, "F1" }, 1.132 + { VK_F2, "F2" }, 1.133 + { VK_F3, "F3" }, 1.134 + { VK_F4, "F4" }, 1.135 + { VK_F5, "F5" }, 1.136 + { VK_F6, "F6" }, 1.137 + { VK_F7, "F7" }, 1.138 + { VK_F8, "F8" }, 1.139 + { VK_F9, "F9" }, 1.140 + { VK_F10, "F10" }, 1.141 + { VK_F11, "F11" }, 1.142 + { VK_F12, "F12" }, 1.143 + { VK_F13, "F13" }, 1.144 + { VK_F14, "F14" }, 1.145 + { VK_F15, "F15" }, 1.146 + { VK_F16, "F16" }, 1.147 + { VK_F17, "F17" }, 1.148 + { VK_F18, "F18" }, 1.149 + { VK_F19, "F19" }, 1.150 + { VK_F20, "F20" }, 1.151 + { VK_F21, "F21" }, 1.152 + { VK_F22, "F22" }, 1.153 + { VK_F23, "F23" }, 1.154 + { VK_F24, "F24" }, 1.155 + { VK_NUMLOCK, "Num Lock" }, 1.156 + { VK_SCROLL, "Scroll Lock" }, 1.157 + { VK_ATTN, "Attention" }, 1.158 + { VK_CRSEL, "CRSEL" }, 1.159 + { VK_EXSEL, "EXSEL" }, 1.160 + { VK_EREOF, "EREOF" }, 1.161 + { VK_PLAY, "Play" }, 1.162 + { VK_ZOOM, "Zoom" }, 1.163 + { VK_NONAME, "No Name" }, 1.164 + { VK_PA1, "PA1" }, 1.165 + { VK_OEM_CLEAR, "Clear2" }, 1.166 + { VK_OEM_1, "Semicolon;" }, 1.167 + { VK_OEM_2, "Slash/" }, 1.168 + { VK_OEM_3, "Tilde~" }, 1.169 + { VK_OEM_4, "LBracket[" }, 1.170 + { VK_OEM_5, "Backslash\\" }, 1.171 + { VK_OEM_6, "RBracket]" }, 1.172 + { VK_OEM_7, "Apostrophe'" }, 1.173 + { VK_OEM_8, "OEM8" }, 1.174 + { VK_OEM_PLUS, "Plus+" }, 1.175 + { VK_OEM_MINUS, "Minus-" }, 1.176 + { VK_OEM_COMMA, "Comma," }, 1.177 + { VK_OEM_PERIOD, "Period." }, 1.178 + { VK_OEM_AX, "Apostrophe`" }, 1.179 + { VK_OEM_102, "<> or \\|" }, 1.180 + { VK_ICO_HELP, "ICO Help" }, 1.181 + { VK_ICO_00, "ICO 00" }, 1.182 + { VK_OEM_FJ_JISHO, "JISHO" }, 1.183 + { VK_OEM_FJ_MASSHOU, "MASSHOU" }, 1.184 + { VK_OEM_FJ_TOUROKU, "TOUROKU" }, 1.185 + { VK_OEM_FJ_LOYA, "LOYA" }, 1.186 + { VK_OEM_FJ_ROYA, "ROYA" }, 1.187 + { VK_OEM_NEC_EQUAL, "Numpad Equals" }, 1.188 +}; 1.189 + 1.190 +//////////////////////////////////////////////////////////////////////// 1.191 +// 1.192 +// 1.193 +MAPVIRTKEYS mapVirtSysKeys[] = { 1.194 + { FCONTROL, "Ctrl" }, 1.195 + { FALT, "Alt" }, 1.196 + { FSHIFT, "Shift" }, 1.197 +}; 1.198 + 1.199 +//////////////////////////////////////////////////////////////////////// 1.200 +// helper fct for external access 1.201 +//////////////////////////////////////////////////////////////////////// 1.202 +// 1.203 +// 1.204 +TCHAR *mapVirtKeysStringFromWORD(WORD wKey) 1.205 +{ 1.206 + for (int index = 0; index < sizeof(mapVirtKeys) / sizeof(mapVirtKeys[0]); index++) 1.207 + { 1.208 + if (mapVirtKeys[index].wKey == wKey) 1.209 + return mapVirtKeys[index].szKey; 1.210 + } 1.211 + return NULL; 1.212 +} 1.213 + 1.214 +//////////////////////////////////////////////////////////////////////// 1.215 +// 1.216 +#define DEFAULT_ACCEL 0x01 1.217 +#define USER_ACCEL 0x02 1.218 + 1.219 +//////////////////////////////////////////////////////////////////////// 1.220 +// 1.221 +//////////////////////////////////////////////////////////////////////// 1.222 +// 1.223 +// 1.224 +CAccelsOb::CAccelsOb() 1.225 +{ 1.226 + m_cVirt = 0; 1.227 + m_wKey = 0; 1.228 + m_bLocked = false; 1.229 +} 1.230 + 1.231 +//////////////////////////////////////////////////////////////////////// 1.232 +// 1.233 +// 1.234 +CAccelsOb::CAccelsOb(CAccelsOb *pFrom) 1.235 +{ 1.236 + ASSERT(pFrom != NULL); 1.237 + 1.238 + m_cVirt = pFrom->m_cVirt; 1.239 + m_wKey = pFrom->m_wKey; 1.240 + m_bLocked = pFrom->m_bLocked; 1.241 +} 1.242 + 1.243 +//////////////////////////////////////////////////////////////////////// 1.244 +// 1.245 +// 1.246 +CAccelsOb::CAccelsOb(BYTE cVirt, WORD wKey, bool bLocked) 1.247 +{ 1.248 + m_cVirt = cVirt; 1.249 + m_wKey = wKey; 1.250 + m_bLocked = bLocked; 1.251 +} 1.252 + 1.253 +//////////////////////////////////////////////////////////////////////// 1.254 +// 1.255 +// 1.256 +CAccelsOb::CAccelsOb(LPACCEL pACCEL) 1.257 +{ 1.258 + ASSERT(pACCEL != NULL); 1.259 + 1.260 + m_cVirt = pACCEL->fVirt; 1.261 + m_wKey = pACCEL->key; 1.262 + m_bLocked = false; 1.263 +} 1.264 + 1.265 +//////////////////////////////////////////////////////////////////////// 1.266 +// 1.267 +// 1.268 +CAccelsOb & CAccelsOb::operator=(const CAccelsOb &from) 1.269 +{ 1.270 + m_cVirt = from.m_cVirt; 1.271 + m_wKey = from.m_wKey; 1.272 + m_bLocked = from.m_bLocked; 1.273 + 1.274 + return *this; 1.275 +} 1.276 + 1.277 +//////////////////////////////////////////////////////////////////////// 1.278 +// 1.279 +//////////////////////////////////////////////////////////////////////// 1.280 +// 1.281 +// 1.282 +void CAccelsOb::GetString(CString &szBuffer) 1.283 +{ 1.284 + szBuffer = ""; 1.285 + 1.286 + // modifiers part 1.287 + for (int i = 0; i < sizetable(mapVirtSysKeys); i++) 1.288 + { 1.289 + if (m_cVirt & mapVirtSysKeys[i].wKey) 1.290 + { 1.291 + szBuffer += mapVirtSysKeys[i].szKey; 1.292 + if (m_wKey) 1.293 + szBuffer += "+"; 1.294 + } 1.295 + } 1.296 + 1.297 + // in case of the object is not assigned, we avoid error messages 1.298 + if (m_wKey == 0) 1.299 + return; 1.300 + 1.301 + // and virtual key part 1.302 + for (int i = 0; i < sizetable(mapVirtKeys); i++) 1.303 + { 1.304 + if (m_wKey == mapVirtKeys[i].wKey) 1.305 + { 1.306 + szBuffer += mapVirtKeys[i].szKey; 1.307 + return; 1.308 + } 1.309 + } 1.310 + 1.311 + AfxMessageBox("Internal error : (CAccelsOb::GetString) m_wKey invalid"); 1.312 +} 1.313 + 1.314 +//////////////////////////////////////////////////////////////////////// 1.315 +// 1.316 +// 1.317 +bool CAccelsOb::IsEqual(WORD wKey, bool bCtrl, bool bAlt, bool bShift) 1.318 +{ 1.319 + bool m_bCtrl = (m_cVirt & FCONTROL) ? true : false; 1.320 + bool m_bAlt = (m_cVirt & FALT) ? true : false; 1.321 + bool m_bShift = (m_cVirt & FSHIFT) ? true : false; 1.322 + 1.323 + bool bRet = (bCtrl == m_bCtrl) && (bAlt == m_bAlt) && (bShift == m_bShift) && (m_wKey == wKey); 1.324 + 1.325 + return bRet; 1.326 +} 1.327 + 1.328 +//////////////////////////////////////////////////////////////////////// 1.329 +// 1.330 +// 1.331 +DWORD CAccelsOb::GetData() 1.332 +{ 1.333 + BYTE cLocalCodes = 0; 1.334 + if (m_bLocked) 1.335 + cLocalCodes = DEFAULT_ACCEL; 1.336 + else 1.337 + cLocalCodes = USER_ACCEL; 1.338 + 1.339 + WORD bCodes = MAKEWORD(m_cVirt, cLocalCodes); 1.340 + return MAKELONG(m_wKey, bCodes); 1.341 +} 1.342 + 1.343 +//////////////////////////////////////////////////////////////////////// 1.344 +// 1.345 +// 1.346 +bool CAccelsOb::SetData(DWORD dwDatas) 1.347 +{ 1.348 + m_wKey = LOWORD(dwDatas); 1.349 + 1.350 + WORD bCodes = HIWORD(dwDatas); 1.351 + m_cVirt = LOBYTE(bCodes); 1.352 + 1.353 + BYTE cLocalCodes = HIBYTE(bCodes); 1.354 + m_bLocked = (cLocalCodes == DEFAULT_ACCEL); 1.355 + 1.356 + return true; 1.357 +} 1.358 + 1.359 +//////////////////////////////////////////////////////////////////////// 1.360 +// 1.361 +#ifdef _DEBUG 1.362 +//////////////////////////////////////////////////////////////////////// 1.363 +// 1.364 +// 1.365 +void CAccelsOb::AssertValid() const 1.366 +{ 1.367 + CObject::AssertValid(); 1.368 +} 1.369 + 1.370 +//////////////////////////////////////////////////////////////////////// 1.371 +// 1.372 +// 1.373 +void CAccelsOb::Dump(CDumpContext &dc) const 1.374 +{ 1.375 + dc << "\t\t"; 1.376 + CObject::Dump(dc); 1.377 + dc << "\t\tlocked=" << m_bLocked << ", cVirt=" << m_cVirt << ", wKey=" << m_wKey << "\n\n"; 1.378 +} 1.379 + 1.380 +#endif 1.381 + 1.382 +//////////////////////////////////////////////////////////////////////// 1.383 +// 1.384 +//////////////////////////////////////////////////////////////////////// 1.385 +// 1.386 +// 1.387 +CCmdAccelOb::CCmdAccelOb() 1.388 +{} 1.389 + 1.390 +//////////////////////////////////////////////////////////////////////// 1.391 +// 1.392 +// 1.393 +CCmdAccelOb::CCmdAccelOb(WORD wIDCommand, LPCTSTR szCommand) 1.394 +{ 1.395 + ASSERT(szCommand != NULL); 1.396 + 1.397 + m_wIDCommand = wIDCommand; 1.398 + m_szCommand = szCommand; 1.399 +} 1.400 + 1.401 +//////////////////////////////////////////////////////////////////////// 1.402 +// 1.403 +// 1.404 +CCmdAccelOb::CCmdAccelOb(BYTE cVirt, WORD wIDCommand, WORD wKey, LPCTSTR szCommand, bool bLocked) 1.405 +{ 1.406 + ASSERT(szCommand != NULL); 1.407 + 1.408 + m_wIDCommand = wIDCommand; 1.409 + m_szCommand = szCommand; 1.410 + 1.411 + CAccelsOb *pAccel = new CAccelsOb(cVirt, wKey, bLocked); 1.412 + ASSERT(pAccel != NULL); 1.413 + m_Accels.AddTail(pAccel); 1.414 +} 1.415 + 1.416 +//////////////////////////////////////////////////////////////////////// 1.417 +// 1.418 +// 1.419 +CCmdAccelOb::~CCmdAccelOb() 1.420 +{ 1.421 + POSITION pos = m_Accels.GetHeadPosition(); 1.422 + while (pos != NULL) 1.423 + delete m_Accels.GetNext(pos); 1.424 + m_Accels.RemoveAll(); 1.425 +} 1.426 + 1.427 +//////////////////////////////////////////////////////////////////////// 1.428 +// 1.429 +//////////////////////////////////////////////////////////////////////// 1.430 +// 1.431 +// 1.432 +void CCmdAccelOb::Add(BYTE cVirt, WORD wKey, bool bLocked) 1.433 +{ 1.434 + CAccelsOb *pAccel = new CAccelsOb(cVirt, wKey, bLocked); 1.435 + ASSERT(pAccel != NULL); 1.436 + m_Accels.AddTail(pAccel); 1.437 +} 1.438 + 1.439 +//////////////////////////////////////////////////////////////////////// 1.440 +// 1.441 +// 1.442 +void CCmdAccelOb::Add(CAccelsOb *pAccel) 1.443 +{ 1.444 + ASSERT(pAccel != NULL); 1.445 + m_Accels.AddTail(pAccel); 1.446 +} 1.447 + 1.448 +//////////////////////////////////////////////////////////////////////// 1.449 +// 1.450 +// 1.451 +CCmdAccelOb & CCmdAccelOb::operator=(const CCmdAccelOb &from) 1.452 +{ 1.453 + Reset(); 1.454 + 1.455 + m_wIDCommand = from.m_wIDCommand; 1.456 + m_szCommand = from.m_szCommand; 1.457 + 1.458 + CAccelsOb *pAccel; 1.459 + POSITION pos = from.m_Accels.GetHeadPosition(); 1.460 + while (pos != NULL) 1.461 + { 1.462 + pAccel = new CAccelsOb(from.m_Accels.GetNext(pos)); 1.463 + ASSERT(pAccel != NULL); 1.464 + m_Accels.AddTail(pAccel); 1.465 + } 1.466 + return *this; 1.467 +} 1.468 + 1.469 +//////////////////////////////////////////////////////////////////////// 1.470 +// 1.471 +// 1.472 +void CCmdAccelOb::DeleteUserAccels() 1.473 +{ 1.474 + CAccelsOb *pAccel; 1.475 + POSITION prevPos; 1.476 + POSITION pos = m_Accels.GetHeadPosition(); 1.477 + while (pos != NULL) 1.478 + { 1.479 + prevPos = pos; 1.480 + pAccel = m_Accels.GetNext(pos); 1.481 + if (!pAccel->m_bLocked) 1.482 + { 1.483 + delete pAccel; 1.484 + m_Accels.RemoveAt(prevPos); 1.485 + } 1.486 + } 1.487 +} 1.488 + 1.489 +//////////////////////////////////////////////////////////////////////// 1.490 +// 1.491 +// 1.492 +void CCmdAccelOb::Reset() 1.493 +{ 1.494 + m_wIDCommand = 0; 1.495 + m_szCommand = "Empty command"; 1.496 + 1.497 + CAccelsOb *pAccel; 1.498 + POSITION pos = m_Accels.GetHeadPosition(); 1.499 + while (pos != NULL) 1.500 + { 1.501 + pAccel = m_Accels.GetNext(pos); 1.502 + delete pAccel; 1.503 + } 1.504 +} 1.505 + 1.506 +//////////////////////////////////////////////////////////////////////// 1.507 +// 1.508 +#ifdef _DEBUG 1.509 +//////////////////////////////////////////////////////////////////////// 1.510 +// 1.511 +// 1.512 +void CCmdAccelOb::AssertValid() const 1.513 +{ 1.514 + // call base class function first 1.515 + CObject::AssertValid(); 1.516 +} 1.517 + 1.518 +//////////////////////////////////////////////////////////////////////// 1.519 +// 1.520 +// 1.521 +void CCmdAccelOb::Dump(CDumpContext &dc) const 1.522 +{ 1.523 + // call base class function first 1.524 + dc << "\t"; 1.525 + CObject::Dump(dc); 1.526 + 1.527 + // now do the stuff for our specific class 1.528 + dc << "\tIDCommand = " << m_wIDCommand; 1.529 + dc << "\n\tszCommand = " << m_szCommand; 1.530 + dc << "\n\tAccelerators = {\n"; 1.531 + 1.532 + CAccelsOb *pAccel; 1.533 + POSITION pos = m_Accels.GetHeadPosition(); 1.534 + while (pos != NULL) 1.535 + { 1.536 + pAccel = m_Accels.GetNext(pos); 1.537 + dc << pAccel; 1.538 + } 1.539 + dc << "\t}\n"; 1.540 +} 1.541 + 1.542 +#endif