Mercurial > vba-linux
diff src/win32/AcceleratorManager.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/AcceleratorManager.cpp Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,729 @@ 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 : AcceleratorManager.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 : implementation of the CAcceleratorManager class. 1.29 +// 1.30 +//////////////////////////////////////////////////////////////////////////////// 1.31 +// Modified by aquanull: 1.32 +// All win32 registry stuff removed 1.33 + 1.34 +#include "stdafx.h" 1.35 +#include <windows.h> // MIIM_STRING 1.36 +#include "resource.h" 1.37 +#include "AcceleratorManager.h" 1.38 +#include "CmdAccelOb.h" 1.39 +#include "Reg.h" 1.40 +#include "VBA.h" 1.41 +//#include "../common/System.h" 1.42 + 1.43 +CAcceleratorManager::CAcceleratorManager() 1.44 +{ 1.45 + m_bAutoSave = FALSE; 1.46 + m_pWndConnected = NULL; 1.47 + 1.48 + m_bDefaultTable = false; 1.49 +} 1.50 + 1.51 +CAcceleratorManager::~CAcceleratorManager() 1.52 +{ 1.53 +#if 0 1.54 + if (m_bAutoSave) 1.55 + { 1.56 + bool bRet = Write(); 1.57 + if (!bRet) 1.58 + systemMessage(0, "CAcceleratorManager::~CAcceleratorManager\nError in CAcceleratorManager::Write..."); 1.59 + } 1.60 +#endif 1.61 + Reset(); 1.62 +} 1.63 + 1.64 +CAcceleratorManager & CAcceleratorManager::operator=(const CAcceleratorManager& accelmgr) 1.65 +{ 1.66 + Reset(); 1.67 + 1.68 + CCmdAccelOb*pCmdAccel; 1.69 + CCmdAccelOb*pNewCmdAccel; 1.70 + WORD wKey; 1.71 + // Copy the 2 tables : normal accel table... 1.72 + POSITION pos = accelmgr.m_mapAccelTable.GetStartPosition(); 1.73 + while (pos != NULL) 1.74 + { 1.75 + accelmgr.m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel); 1.76 + pNewCmdAccel = new CCmdAccelOb; 1.77 + ASSERT(pNewCmdAccel != NULL); 1.78 + *pNewCmdAccel = *pCmdAccel; 1.79 + m_mapAccelTable.SetAt(wKey, pNewCmdAccel); 1.80 + } 1.81 + // ... and saved accel table. 1.82 + pos = accelmgr.m_mapAccelTableSaved.GetStartPosition(); 1.83 + while (pos != NULL) 1.84 + { 1.85 + accelmgr.m_mapAccelTableSaved.GetNextAssoc(pos, wKey, pCmdAccel); 1.86 + pNewCmdAccel = new CCmdAccelOb; 1.87 + ASSERT(pNewCmdAccel != NULL); 1.88 + *pNewCmdAccel = *pCmdAccel; 1.89 + m_mapAccelTableSaved.SetAt(wKey, pNewCmdAccel); 1.90 + } 1.91 + 1.92 + // The Strings-ID table 1.93 + CString szKey; 1.94 + pos = accelmgr.m_mapAccelString.GetStartPosition(); 1.95 + while (pos != NULL) 1.96 + { 1.97 + accelmgr.m_mapAccelString.GetNextAssoc(pos, szKey, wKey); 1.98 + m_mapAccelString.SetAt(szKey, wKey); 1.99 + } 1.100 + m_bDefaultTable = accelmgr.m_bDefaultTable; 1.101 + 1.102 + return *this; 1.103 +} 1.104 + 1.105 +////////////////////////////////////////////////////////////////////// 1.106 +// Internal fcts 1.107 +// 1.108 +void CAcceleratorManager::Reset() 1.109 +{ 1.110 + CCmdAccelOb*pCmdAccel; 1.111 + WORD wKey; 1.112 + POSITION pos = m_mapAccelTable.GetStartPosition(); 1.113 + while (pos != NULL) 1.114 + { 1.115 + m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel); 1.116 + delete pCmdAccel; 1.117 + } 1.118 + m_mapAccelTable.RemoveAll(); 1.119 + m_mapAccelString.RemoveAll(); 1.120 + 1.121 + pos = m_mapAccelTableSaved.GetStartPosition(); 1.122 + while (pos != NULL) 1.123 + { 1.124 + m_mapAccelTableSaved.GetNextAssoc(pos, wKey, pCmdAccel); 1.125 + delete pCmdAccel; 1.126 + } 1.127 + m_mapAccelTableSaved.RemoveAll(); 1.128 +} 1.129 + 1.130 +bool CAcceleratorManager::AddAccel(BYTE cVirt, WORD wIDCommand, WORD wKey, LPCTSTR szCommand, bool bLocked) 1.131 +{ 1.132 + ASSERT(szCommand != NULL); 1.133 + 1.134 + WORD wIDCmd; 1.135 + if (m_mapAccelString.Lookup(szCommand, wIDCmd) == TRUE) 1.136 + { 1.137 + if (wIDCmd != wIDCommand) 1.138 + return false; 1.139 + } 1.140 + 1.141 + CCmdAccelOb*pCmdAccel = NULL; 1.142 + if (m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) == TRUE) 1.143 + { 1.144 + if (pCmdAccel->m_szCommand != szCommand) 1.145 + { 1.146 + return false; 1.147 + } 1.148 + CAccelsOb*pAccel; 1.149 + POSITION pos = pCmdAccel->m_Accels.GetHeadPosition(); 1.150 + while (pos != NULL) 1.151 + { 1.152 + pAccel = pCmdAccel->m_Accels.GetNext(pos); 1.153 + if (pAccel->m_cVirt == cVirt && 1.154 + pAccel->m_wKey == wKey) 1.155 + return FALSE; 1.156 + } 1.157 + // Adding the accelerator 1.158 + pCmdAccel->Add(cVirt, wKey, bLocked); 1.159 + } 1.160 + else 1.161 + { 1.162 + pCmdAccel = new CCmdAccelOb(cVirt, wIDCommand, wKey, szCommand, bLocked); 1.163 + ASSERT(pCmdAccel != NULL); 1.164 + m_mapAccelTable.SetAt(wIDCommand, pCmdAccel); 1.165 + } 1.166 + // 2nd table 1.167 + m_mapAccelString.SetAt(szCommand, wIDCommand); 1.168 + return true; 1.169 +} 1.170 + 1.171 +////////////////////////////////////////////////////////////////////// 1.172 +// Debug fcts 1.173 +// 1.174 +#ifdef _DEBUG 1.175 +void CAcceleratorManager::AssertValid() const 1.176 +{} 1.177 + 1.178 +void CAcceleratorManager::Dump(CDumpContext& dc) const 1.179 +{ 1.180 + CCmdAccelOb*pCmdAccel; 1.181 + WORD wKey; 1.182 + dc << "CAcceleratorManager::Dump :\n"; 1.183 + dc << "m_mapAccelTable :\n"; 1.184 + POSITION pos = m_mapAccelTable.GetStartPosition(); 1.185 + while (pos != NULL) 1.186 + { 1.187 + m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel); 1.188 + dc << "a CCmdAccelOb at 0x" << (void *)pCmdAccel << " = {\n"; 1.189 + dc << pCmdAccel; 1.190 + dc << "}\n"; 1.191 + } 1.192 + dc << "\nm_mapAccelTableSaved\n"; 1.193 + pos = m_mapAccelTableSaved.GetStartPosition(); 1.194 + while (pos != NULL) 1.195 + { 1.196 + m_mapAccelTableSaved.GetNextAssoc(pos, wKey, pCmdAccel); 1.197 + dc << "a CCmdAccelOb at 0x" << (void *)pCmdAccel << " = {\n"; 1.198 + dc << pCmdAccel; 1.199 + dc << "}\n"; 1.200 + } 1.201 +} 1.202 + 1.203 +#endif 1.204 + 1.205 +void CAcceleratorManager::Connect(CWnd*pWnd, bool bAutoSave) 1.206 +{ 1.207 + ASSERT(m_pWndConnected == NULL); 1.208 + m_pWndConnected = pWnd; 1.209 + m_bAutoSave = bAutoSave; 1.210 +} 1.211 + 1.212 +////////////////////////////////////////////////////////////////////// 1.213 +// Update the application's ACCELs table 1.214 +// 1.215 +bool CAcceleratorManager::UpdateWndTable() 1.216 +{ 1.217 + int iLoop = 0; 1.218 + CTypedPtrArray<CPtrArray, LPACCEL> arrayACCEL; 1.219 + 1.220 + CCmdAccelOb*pCmdAccel; 1.221 + WORD wKey; 1.222 + LPACCEL pACCEL; 1.223 + CAccelsOb* pAccelOb; 1.224 + POSITION pos = m_mapAccelTable.GetStartPosition(); 1.225 + while (pos != NULL) 1.226 + { 1.227 + m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel); 1.228 + POSITION pos = pCmdAccel->m_Accels.GetHeadPosition(); 1.229 + while (pos != NULL) 1.230 + { 1.231 + pAccelOb = pCmdAccel->m_Accels.GetNext(pos); 1.232 + 1.233 + pACCEL = new ACCEL; 1.234 + ASSERT(pACCEL != NULL); 1.235 + pACCEL->fVirt = pAccelOb->m_cVirt; 1.236 + pACCEL->key = pAccelOb->m_wKey; 1.237 + pACCEL->cmd = pCmdAccel->m_wIDCommand; 1.238 + arrayACCEL.Add(pACCEL); 1.239 + } 1.240 + } 1.241 + 1.242 + int nAccel = arrayACCEL.GetSize(); 1.243 + LPACCEL lpAccel = (LPACCEL)LocalAlloc(LPTR, nAccel * sizeof(ACCEL)); 1.244 + if (!lpAccel) 1.245 + { 1.246 + for (iLoop = 0; iLoop < nAccel; iLoop++) 1.247 + delete arrayACCEL.GetAt(iLoop); 1.248 + arrayACCEL.RemoveAll(); 1.249 + 1.250 + return false; 1.251 + } 1.252 + 1.253 + for (iLoop = 0; iLoop < nAccel; iLoop++) 1.254 + { 1.255 + pACCEL = arrayACCEL.GetAt(iLoop); 1.256 + lpAccel[iLoop].fVirt = pACCEL->fVirt; 1.257 + lpAccel[iLoop].key = pACCEL->key; 1.258 + lpAccel[iLoop].cmd = pACCEL->cmd; 1.259 + 1.260 + delete pACCEL; 1.261 + } 1.262 + arrayACCEL.RemoveAll(); 1.263 + 1.264 + HACCEL hNewTable = CreateAcceleratorTable(lpAccel, nAccel); 1.265 + if (!hNewTable) 1.266 + { 1.267 + ::LocalFree(lpAccel); 1.268 + return false; 1.269 + } 1.270 + HACCEL hOldTable = theApp.hAccel; 1.271 + if (!::DestroyAcceleratorTable(hOldTable)) 1.272 + { 1.273 + ::LocalFree(lpAccel); 1.274 + return false; 1.275 + } 1.276 + theApp.hAccel = hNewTable; 1.277 + ::LocalFree(lpAccel); 1.278 + 1.279 + UpdateMenu(GetMenu(*AfxGetApp()->m_pMainWnd)); 1.280 + 1.281 + return true; 1.282 +} 1.283 + 1.284 +////////////////////////////////////////////////////////////////////// 1.285 +// Create/Destroy accelerators 1.286 +// 1.287 +bool CAcceleratorManager::DeleteAccel(BYTE cVirt, WORD wIDCommand, WORD wKey) 1.288 +{ 1.289 + CCmdAccelOb*pCmdAccel = NULL; 1.290 + if (m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) == TRUE) 1.291 + { 1.292 + POSITION pos = pCmdAccel->m_Accels.GetHeadPosition(); 1.293 + POSITION PrevPos; 1.294 + CAccelsOb*pAccel = NULL; 1.295 + while (pos != NULL) 1.296 + { 1.297 + PrevPos = pos; 1.298 + pAccel = pCmdAccel->m_Accels.GetNext(pos); 1.299 + if (pAccel->m_bLocked == true) 1.300 + return false; 1.301 + 1.302 + if (pAccel->m_cVirt == cVirt && pAccel->m_wKey == wKey) 1.303 + { 1.304 + pCmdAccel->m_Accels.RemoveAt(PrevPos); 1.305 + delete pAccel; 1.306 + return true; 1.307 + } 1.308 + } 1.309 + } 1.310 + return false; 1.311 +} 1.312 + 1.313 +bool CAcceleratorManager::DeleteEntry(WORD wIDCommand) 1.314 +{ 1.315 + CCmdAccelOb*pCmdAccel = NULL; 1.316 + VERIFY(m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) == TRUE); 1.317 + 1.318 + CAccelsOb*pAccel; 1.319 + POSITION pos = pCmdAccel->m_Accels.GetHeadPosition(); 1.320 + while (pos != NULL) 1.321 + { 1.322 + pAccel = pCmdAccel->m_Accels.GetNext(pos); 1.323 + if (pAccel->m_bLocked == true) 1.324 + return false; 1.325 + } 1.326 + m_mapAccelString.RemoveKey(pCmdAccel->m_szCommand); 1.327 + m_mapAccelTable.RemoveKey(wIDCommand); 1.328 + delete pCmdAccel; 1.329 + 1.330 + return true; 1.331 +} 1.332 + 1.333 +bool CAcceleratorManager::DeleteEntry(LPCTSTR szCommand) 1.334 +{ 1.335 + ASSERT(szCommand != NULL); 1.336 + 1.337 + WORD wIDCommand; 1.338 + if (m_mapAccelString.Lookup(szCommand, wIDCommand) == TRUE) 1.339 + { 1.340 + return DeleteEntry(wIDCommand); 1.341 + } 1.342 + return true; 1.343 +} 1.344 + 1.345 +bool CAcceleratorManager::SetAccel(BYTE cVirt, WORD wIDCommand, WORD wKey, LPCTSTR szCommand, bool bLocked) 1.346 +{ 1.347 + ASSERT(szCommand != NULL); 1.348 + 1.349 + return AddAccel(cVirt, wIDCommand, wKey, szCommand, bLocked); 1.350 +} 1.351 + 1.352 +bool CAcceleratorManager::AddCommandAccel(WORD wIDCommand, LPCTSTR szCommand, bool bLocked) 1.353 +{ 1.354 + ASSERT(szCommand != NULL); 1.355 + 1.356 + ASSERT(m_pWndConnected != NULL); 1.357 + HACCEL hOriginalTable = theApp.hAccel; 1.358 + 1.359 + int nAccel = ::CopyAcceleratorTable(hOriginalTable, NULL, 0); 1.360 + LPACCEL lpAccel = (LPACCEL)LocalAlloc(LPTR, (nAccel) * sizeof(ACCEL)); 1.361 + if (!lpAccel) 1.362 + return false; 1.363 + ::CopyAcceleratorTable(hOriginalTable, lpAccel, nAccel); 1.364 + 1.365 + bool bRet = false; 1.366 + for (int i = 0; i < nAccel; i++) 1.367 + { 1.368 + if (lpAccel[i].cmd == wIDCommand) 1.369 + bRet = AddAccel(lpAccel[i].fVirt, wIDCommand, lpAccel[i].key, szCommand, bLocked); 1.370 + } 1.371 + ::LocalFree(lpAccel); 1.372 + return bRet; 1.373 +} 1.374 + 1.375 +bool CAcceleratorManager::CreateEntry(WORD wIDCommand, LPCTSTR szCommand) 1.376 +{ 1.377 + ASSERT(szCommand != NULL); 1.378 + 1.379 + WORD wIDDummy; 1.380 + if (m_mapAccelString.Lookup(szCommand, wIDDummy) == TRUE) 1.381 + return false; 1.382 + 1.383 + CCmdAccelOb*pCmdAccel = new CCmdAccelOb(wIDCommand, szCommand); 1.384 + ASSERT(pCmdAccel != NULL); 1.385 + m_mapAccelTable.SetAt(wIDCommand, pCmdAccel); 1.386 + m_mapAccelString.SetAt(szCommand, wIDCommand); 1.387 + 1.388 + return false; 1.389 +} 1.390 + 1.391 +////////////////////////////////////////////////////////////////////// 1.392 +// Get a string from the ACCEL definition 1.393 +// 1.394 +bool CAcceleratorManager::GetStringFromACCEL(ACCEL*pACCEL, CString& szAccel) 1.395 +{ 1.396 + ASSERT(pACCEL != NULL); 1.397 + 1.398 + CAccelsOb accel(pACCEL); 1.399 + accel.GetString(szAccel); 1.400 + 1.401 + if (szAccel.IsEmpty()) 1.402 + return false; 1.403 + else 1.404 + return true; 1.405 +} 1.406 + 1.407 +bool CAcceleratorManager::GetStringFromACCEL(BYTE cVirt, WORD nCode, CString& szAccel) 1.408 +{ 1.409 + CAccelsOb accel(cVirt, nCode); 1.410 + accel.GetString(szAccel); 1.411 + 1.412 + if (szAccel.IsEmpty()) 1.413 + return false; 1.414 + else 1.415 + return true; 1.416 +} 1.417 + 1.418 +void CAcceleratorManager::UpdateMenu(HMENU menu) 1.419 +{ 1.420 + int count = GetMenuItemCount(menu); 1.421 + 1.422 + OSVERSIONINFO info = {0}; 1.423 + info.dwOSVersionInfoSize = sizeof(info); 1.424 + GetVersionEx(&info); 1.425 + 1.426 + if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) 1.427 + { 1.428 + MENUITEMINFO info = {0}; 1.429 + info.cbSize = sizeof(info) - sizeof(HBITMAP); 1.430 + info.fMask = MIIM_ID | MIIM_SUBMENU; 1.431 + for (int i = 0; i < count; i++) 1.432 + { 1.433 + GetMenuItemInfo(menu, i, TRUE, &info); 1.434 + 1.435 + if (info.hSubMenu != NULL) 1.436 + { 1.437 + UpdateMenu(info.hSubMenu); 1.438 + } 1.439 + else 1.440 + { 1.441 + if (info.wID != (UINT)-1) 1.442 + { 1.443 + char ss[128]; 1.444 + MENUITEMINFO info2 = {0}; 1.445 + info2.cbSize = sizeof(info2) - sizeof(HBITMAP); // FIXME: why? 1.446 + info2.fMask = MIIM_STRING; 1.447 + info2.dwTypeData = ss; 1.448 + info2.cch = 128; 1.449 + GetMenuItemInfo(menu, i, MF_BYPOSITION, &info2); 1.450 + 1.451 + CString str(ss); 1.452 + int index = str.Find('\t'); 1.453 + if (index != -1) 1.454 + str = str.Left(index); 1.455 + 1.456 + WORD command = info.wID; 1.457 + 1.458 + CCmdAccelOb *o; 1.459 + if (m_mapAccelTable.Lookup(command, o)) 1.460 + { 1.461 + if (o->m_Accels.GetCount()) 1.462 + { 1.463 + POSITION pos = o->m_Accels.GetHeadPosition(); 1.464 + CAccelsOb *accel = o->m_Accels.GetNext(pos); 1.465 + 1.466 + CString s; 1.467 + accel->GetString(s); 1.468 + str += "\t"; 1.469 + str += s; 1.470 + } 1.471 + } 1.472 + if (str != ss) 1.473 + ModifyMenu(menu, i, MF_BYPOSITION | MF_STRING, info.wID, str); 1.474 + } 1.475 + } 1.476 + } 1.477 + } 1.478 + else 1.479 + { 1.480 + MENUITEMINFO info = {0}; 1.481 + info.cbSize = sizeof(info); 1.482 + info.fMask = MIIM_ID | MIIM_SUBMENU; 1.483 + for (int i = 0; i < count; i++) 1.484 + { 1.485 + GetMenuItemInfo(menu, i, TRUE, &info); 1.486 + 1.487 + if (info.hSubMenu != NULL) 1.488 + { 1.489 + UpdateMenu(info.hSubMenu); 1.490 + } 1.491 + else 1.492 + { 1.493 + if (info.wID != (WORD)-1) 1.494 + { 1.495 + wchar_t ss[128]; 1.496 + wchar_t str[512]; 1.497 + MENUITEMINFOW info2 = {0}; 1.498 + info2.cbSize = sizeof(info2); 1.499 + info2.fMask = MIIM_STRING; 1.500 + info2.dwTypeData = ss; 1.501 + info2.cch = 128; 1.502 + GetMenuItemInfoW(menu, i, MF_BYPOSITION, &info2); 1.503 + 1.504 + wcscpy(str, ss); 1.505 + 1.506 + wchar_t *p = wcschr(str, '\t'); 1.507 + if (p) 1.508 + *p = 0; 1.509 + 1.510 + CCmdAccelOb *o; 1.511 + WORD command = info.wID; 1.512 + if (m_mapAccelTable.Lookup(command, o)) 1.513 + { 1.514 + if (o->m_Accels.GetCount()) 1.515 + { 1.516 + POSITION pos = o->m_Accels.GetHeadPosition(); 1.517 + 1.518 + CAccelsOb *accel = o->m_Accels.GetNext(pos); 1.519 + 1.520 + CString s; 1.521 + accel->GetString(s); 1.522 + 1.523 + wchar_t temp[128]; 1.524 + temp[0] = '\t'; 1.525 + temp[1] = 0; 1.526 + wcscat(str, temp); 1.527 + p = temp; 1.528 + for (const char *sp = s; *sp; sp++) 1.529 + *p++ = *sp; 1.530 + *p = 0; 1.531 + wcscat(str, temp); 1.532 + } 1.533 + } 1.534 + if (wcscmp(str, ss)) 1.535 + ModifyMenuW(menu, i, MF_BYPOSITION | MF_STRING, info.wID, str); 1.536 + } 1.537 + } 1.538 + } 1.539 + } 1.540 +} 1.541 + 1.542 +////////////////////////////////////////////////////////////////////// 1.543 +// In/Out to the registry 1.544 +// 1.545 +bool CAcceleratorManager::Load() 1.546 +{ 1.547 +// ASSERT(szRegKey != NULL); 1.548 + 1.549 +// m_hRegKey = hRegKey; 1.550 +// m_szRegKey = szRegKey; 1.551 + 1.552 + DWORD data[2048/sizeof(DWORD)]; 1.553 + 1.554 + DWORD len = sizeof(data); 1.555 + if (regQueryBinaryValue("keyboard", (char *)data, len)) 1.556 + { 1.557 + int count = len/sizeof(DWORD); 1.558 + 1.559 + CCmdAccelOb*pCmdAccel; 1.560 + CAccelsOb* pAccel; 1.561 + DWORD dwIDAccelData, dwAccelData; 1.562 + BOOL bExistID; 1.563 + int iIndex = 0; 1.564 + if (count) 1.565 + { 1.566 + WORD wKey; 1.567 + POSITION pos = m_mapAccelTable.GetStartPosition(); 1.568 + 1.569 + while (pos != NULL) 1.570 + { 1.571 + m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel); 1.572 + pCmdAccel->DeleteUserAccels(); 1.573 + } 1.574 + 1.575 + while (iIndex < count) 1.576 + { 1.577 + dwIDAccelData = data[iIndex++]; 1.578 + 1.579 + WORD wIDCommand = LOWORD(dwIDAccelData); 1.580 + bExistID = m_mapAccelTable.Lookup(wIDCommand, pCmdAccel); 1.581 + 1.582 + if (bExistID) 1.583 + { 1.584 + pCmdAccel->DeleteUserAccels(); 1.585 + } 1.586 + for (int j = 0; j < HIWORD(dwIDAccelData) && iIndex < count; j++) 1.587 + { 1.588 + dwAccelData = data[iIndex++]; 1.589 + if (bExistID) 1.590 + { 1.591 + pAccel = new CAccelsOb; 1.592 + ASSERT(pAccel != NULL); 1.593 + pAccel->SetData(dwAccelData); 1.594 + pCmdAccel->Add(pAccel); 1.595 + } 1.596 + } 1.597 + } 1.598 + } 1.599 + UpdateWndTable(); 1.600 + return true; 1.601 + } 1.602 + return false; 1.603 +} 1.604 + 1.605 +bool CAcceleratorManager::Write() 1.606 +{ 1.607 + CDWordArray AccelsDatasArray; 1.608 + CDWordArray CmdDatasArray; 1.609 + 1.610 + int iCount = 0; 1.611 + CCmdAccelOb*pCmdAccel; 1.612 + CAccelsOb* pAccel; 1.613 + DWORD dwAccelData; 1.614 + 1.615 + WORD wKey; 1.616 + POSITION pos = m_mapAccelTable.GetStartPosition(); 1.617 + while (pos != NULL) 1.618 + { 1.619 + m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel); 1.620 + CmdDatasArray.RemoveAll(); 1.621 + 1.622 + POSITION pos = pCmdAccel->m_Accels.GetHeadPosition(); 1.623 + while (pos != NULL) 1.624 + { 1.625 + pAccel = pCmdAccel->m_Accels.GetNext(pos); 1.626 + // if (!pAccel->m_bLocked) { 1.627 + dwAccelData = pAccel->GetData(); 1.628 + CmdDatasArray.Add(dwAccelData); 1.629 + // } 1.630 + } 1.631 + 1.632 + if (CmdDatasArray.GetSize() > 0) 1.633 + { 1.634 + CmdDatasArray.InsertAt(0, MAKELONG(pCmdAccel->m_wIDCommand, CmdDatasArray.GetSize())); 1.635 + 1.636 + AccelsDatasArray.Append(CmdDatasArray); 1.637 + iCount++; 1.638 + } 1.639 + } 1.640 + // AccelsDatasArray.InsertAt(0, MAKELONG(65535, iCount)); 1.641 + 1.642 + int count = AccelsDatasArray.GetSize(); 1.643 + DWORD *data = (DWORD *)malloc(count * sizeof(DWORD)); 1.644 + ASSERT(data != NULL); 1.645 + 1.646 + for (int index = 0; index < count; index++) 1.647 + data[index] = AccelsDatasArray[index]; 1.648 + 1.649 + regSetBinaryValue("keyboard", (char *)data, count*sizeof(DWORD)); 1.650 + 1.651 + AccelsDatasArray.RemoveAll(); 1.652 + CmdDatasArray.RemoveAll(); 1.653 + 1.654 + free(data); 1.655 + 1.656 + return true; 1.657 +} 1.658 + 1.659 +////////////////////////////////////////////////////////////////////// 1.660 +// Defaults values management. 1.661 +// 1.662 +bool CAcceleratorManager::CreateDefaultTable() 1.663 +{ 1.664 + if (m_bDefaultTable) 1.665 + return false; 1.666 + 1.667 + CCmdAccelOb*pCmdAccel; 1.668 + CCmdAccelOb*pNewCmdAccel; 1.669 + 1.670 + CAccelsOb*pAccel; 1.671 + CAccelsOb*pNewAccel; 1.672 + 1.673 + WORD wKey; 1.674 + POSITION pos = m_mapAccelTable.GetStartPosition(); 1.675 + while (pos != NULL) 1.676 + { 1.677 + m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel); 1.678 + pNewCmdAccel = new CCmdAccelOb; 1.679 + ASSERT(pNewCmdAccel != NULL); 1.680 + 1.681 + POSITION pos = pCmdAccel->m_Accels.GetHeadPosition(); 1.682 + while (pos != NULL) 1.683 + { 1.684 + pAccel = pCmdAccel->m_Accels.GetNext(pos); 1.685 + if (!pAccel->m_bLocked) 1.686 + { 1.687 + pNewAccel = new CAccelsOb; 1.688 + ASSERT(pNewAccel != NULL); 1.689 + 1.690 + *pNewAccel = *pAccel; 1.691 + pNewCmdAccel->m_Accels.AddTail(pNewAccel); 1.692 + } 1.693 + } 1.694 + if (pNewCmdAccel->m_Accels.GetCount() != 0) 1.695 + { 1.696 + pNewCmdAccel->m_wIDCommand = pCmdAccel->m_wIDCommand; 1.697 + pNewCmdAccel->m_szCommand = pCmdAccel->m_szCommand; 1.698 + 1.699 + m_mapAccelTableSaved.SetAt(wKey, pNewCmdAccel); 1.700 + } 1.701 + else 1.702 + delete pNewCmdAccel; 1.703 + } 1.704 + 1.705 + m_bDefaultTable = true; 1.706 + return true; 1.707 +} 1.708 + 1.709 +#include "mainwnd.h" 1.710 +bool CAcceleratorManager::Default() 1.711 +{ 1.712 + /// this is NYI for some reason, so the "Reset All" button doesn't work 1.713 + 1.714 +#if 0 1.715 + // still doesn't work: 1.716 + Reset(); 1.717 + regDeleteValue("keyboard"); 1.718 + regDeleteValue("keyboardCount"); 1.719 + Connect((MainWnd *)theApp.m_pMainWnd); 1.720 + extern void winAccelAddCommands(CAcceleratorManager& mgr); 1.721 + Load(); 1.722 + CreateDefaultTable(); 1.723 + winAccelAddCommands(*this); 1.724 + UpdateWndTable(); 1.725 + Write(); 1.726 + UpdateMenu(theApp.menu); 1.727 + m_pWndConnected = NULL; 1.728 +#endif 1.729 + 1.730 + return true; 1.731 +} 1.732 +