home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / win32 / AcceleratorManager.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-11-04  |  20.0 KB  |  785 lines

  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    : AcceleratorManager.cpp
  20. // Project : AccelsEditor
  21. ////////////////////////////////////////////////////////////////////////////////
  22. // Version : 1.0                       * Author : T.Maurel
  23. // Date    : 17.08.98
  24. //
  25. // Remarks : implementation of the CAcceleratorManager class.
  26. //
  27. ////////////////////////////////////////////////////////////////////////////////
  28.  
  29. #include "stdafx.h"
  30. //#include "resource.h"
  31. #include "../System.h"
  32.  
  33. #include "AcceleratorManager.h"
  34. #include "Reg.h"
  35.  
  36. #ifdef _DEBUG
  37. #undef THIS_FILE
  38. static char THIS_FILE[]=__FILE__;
  39. #define new DEBUG_NEW
  40. #endif
  41.  
  42.  
  43.  
  44. //////////////////////////////////////////////////////////////////////
  45. // Constructor/Destructor
  46. //////////////////////////////////////////////////////////////////////
  47. //
  48. //
  49. CAcceleratorManager::CAcceleratorManager()
  50. {
  51.   m_hRegKey = HKEY_CURRENT_USER;
  52.   m_szRegKey = "";
  53.   m_bAutoSave = FALSE;
  54.   m_pWndConnected = NULL;
  55.  
  56.   m_bDefaultTable = false;
  57. }
  58.  
  59.  
  60. //////////////////////////////////////////////////////////////////////
  61. //
  62. //
  63. CAcceleratorManager::~CAcceleratorManager()
  64. {
  65.   if ((m_bAutoSave == true) && (m_szRegKey.IsEmpty() != FALSE)) {
  66.     //          bool bRet = Write();
  67.     //          if (!bRet)
  68.     //                  systemMessage(0, "CAcceleratorManager::~CAcceleratorManager\nError in CAcceleratorManager::Write...");
  69.   }
  70.  
  71.   Reset();
  72. }
  73.  
  74.  
  75. //////////////////////////////////////////////////////////////////////
  76. // Internal fcts
  77. //////////////////////////////////////////////////////////////////////
  78. //
  79. //
  80. void CAcceleratorManager::Reset()
  81. {
  82.   CCmdAccelOb* pCmdAccel;
  83.   WORD wKey;
  84.   POSITION pos = m_mapAccelTable.GetStartPosition();
  85.   while (pos != NULL) {
  86.     m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
  87.     delete pCmdAccel;
  88.   }
  89.   m_mapAccelTable.RemoveAll();
  90.   m_mapAccelString.RemoveAll();
  91.  
  92.   pos = m_mapAccelTableSaved.GetStartPosition();
  93.   while (pos != NULL) {
  94.     m_mapAccelTableSaved.GetNextAssoc(pos, wKey, pCmdAccel);
  95.     delete pCmdAccel;
  96.   }
  97.   m_mapAccelTableSaved.RemoveAll();
  98. }
  99.  
  100.  
  101. //////////////////////////////////////////////////////////////////////
  102. //
  103. //
  104. bool CAcceleratorManager::AddAccel(BYTE cVirt, WORD wIDCommand, WORD wKey, LPCTSTR szCommand, bool bLocked)
  105. {
  106.   ASSERT(szCommand != NULL);
  107.  
  108.   WORD wIDCmd;
  109.   if (m_mapAccelString.Lookup(szCommand, wIDCmd) == TRUE) {
  110.     if (wIDCmd != wIDCommand)
  111.       return false;
  112.   }
  113.  
  114.   CCmdAccelOb* pCmdAccel = NULL;
  115.   if (m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) == TRUE) {
  116.     if (pCmdAccel->m_szCommand != szCommand) {
  117.       return false;
  118.     }
  119.     CAccelsOb* pAccel;
  120.     POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
  121.     while (pos != NULL) {
  122.       pAccel = pCmdAccel->m_Accels.GetNext(pos);
  123.       if (pAccel->m_cVirt == cVirt &&
  124.           pAccel->m_wKey == wKey)
  125.         return FALSE;
  126.     }
  127.     // Adding the accelerator
  128.     pCmdAccel->Add(cVirt, wKey, bLocked);
  129.  
  130.   } else {
  131.     pCmdAccel = new CCmdAccelOb(cVirt, wIDCommand, wKey, szCommand, bLocked);
  132.     ASSERT(pCmdAccel != NULL);
  133.     m_mapAccelTable.SetAt(wIDCommand, pCmdAccel);
  134.   }
  135.   // 2nd table
  136.   m_mapAccelString.SetAt(szCommand, wIDCommand);
  137.   return true;
  138. }
  139.  
  140.  
  141. //////////////////////////////////////////////////////////////////////
  142. // Debug fcts
  143. //////////////////////////////////////////////////////////////////////
  144. //
  145. //
  146. #ifdef _DEBUG
  147. void CAcceleratorManager::AssertValid() const
  148. {
  149. }
  150.  
  151. //////////////////////////////////////////////////////////////////////
  152. //
  153. //
  154. void CAcceleratorManager::Dump(CDumpContext& dc) const
  155. {
  156.   CCmdAccelOb* pCmdAccel;
  157.   WORD wKey;
  158.   dc << "CAcceleratorManager::Dump :\n";
  159.   dc << "m_mapAccelTable :\n";
  160.   POSITION pos = m_mapAccelTable.GetStartPosition();
  161.   while (pos != NULL) {
  162.     m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
  163.     dc << "a CCmdAccelOb at 0x"  << (void*)pCmdAccel << " = {\n";
  164.     dc << pCmdAccel;
  165.     dc << "}\n";
  166.   }
  167.   dc << "\nm_mapAccelTableSaved\n";
  168.   pos = m_mapAccelTableSaved.GetStartPosition();
  169.   while (pos != NULL) {
  170.     m_mapAccelTableSaved.GetNextAssoc(pos, wKey, pCmdAccel);
  171.     dc << "a CCmdAccelOb at 0x" << (void*)pCmdAccel << " = {\n";
  172.     dc << pCmdAccel;
  173.     dc << "}\n";
  174.   }
  175. }
  176. #endif
  177.  
  178.  
  179. //////////////////////////////////////////////////////////////////////
  180. //
  181. //////////////////////////////////////////////////////////////////////
  182. //
  183. //
  184. void CAcceleratorManager::Connect(CWnd* pWnd, bool bAutoSave)
  185. {
  186.   ASSERT(m_pWndConnected == NULL);
  187.   m_pWndConnected = pWnd;
  188.   m_bAutoSave = bAutoSave;
  189. }
  190.  
  191.  
  192. //////////////////////////////////////////////////////////////////////
  193. //
  194. //
  195. bool CAcceleratorManager::GetRegKey(HKEY& hRegKey, CString& szRegKey)
  196. {
  197.   if (m_szRegKey.IsEmpty())
  198.     return false;
  199.  
  200.   hRegKey = m_hRegKey;
  201.   szRegKey = m_szRegKey;
  202.   return true;
  203. }
  204.  
  205.  
  206. //////////////////////////////////////////////////////////////////////
  207. //
  208. //
  209. bool CAcceleratorManager::SetRegKey(HKEY hRegKey, LPCTSTR szRegKey)
  210. {
  211.   ASSERT(hRegKey != NULL);
  212.   ASSERT(szRegKey != NULL);
  213.  
  214.   m_szRegKey = szRegKey;
  215.   m_hRegKey = hRegKey;
  216.   return true;
  217. }
  218.  
  219.  
  220. //////////////////////////////////////////////////////////////////////
  221. // Update the application's ACCELs table
  222. //////////////////////////////////////////////////////////////////////
  223. //
  224. //
  225. bool CAcceleratorManager::UpdateWndTable()
  226. {
  227.   int iLoop = 0;
  228.   CTypedPtrArray<CPtrArray, LPACCEL> arrayACCEL;
  229.  
  230.   CCmdAccelOb* pCmdAccel;
  231.   WORD wKey;
  232.   LPACCEL pACCEL;
  233.   CAccelsOb* pAccelOb;
  234.   POSITION pos = m_mapAccelTable.GetStartPosition();
  235.   while (pos != NULL) {
  236.     m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
  237.     POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
  238.     while (pos != NULL) {
  239.       pAccelOb = pCmdAccel->m_Accels.GetNext(pos);
  240.  
  241.       pACCEL = new ACCEL;
  242.       ASSERT(pACCEL != NULL);
  243.       pACCEL->fVirt = pAccelOb->m_cVirt;
  244.       pACCEL->key = pAccelOb->m_wKey;
  245.       pACCEL->cmd = pCmdAccel->m_wIDCommand;
  246.       arrayACCEL.Add(pACCEL);
  247.     }
  248.   }
  249.   
  250.   int nAccel = arrayACCEL.GetSize();
  251.   LPACCEL lpAccel = (LPACCEL)LocalAlloc(LPTR, nAccel * sizeof(ACCEL));
  252.   if (!lpAccel) {
  253.     for (iLoop = 0; iLoop < nAccel; iLoop++)
  254.       delete arrayACCEL.GetAt(iLoop);
  255.     arrayACCEL.RemoveAll();
  256.  
  257.     return false;
  258.   }
  259.  
  260.   for (iLoop = 0; iLoop < nAccel; iLoop++) {
  261.     
  262.     pACCEL = arrayACCEL.GetAt(iLoop);
  263.     lpAccel[iLoop].fVirt = pACCEL->fVirt;
  264.     lpAccel[iLoop].key = pACCEL->key;
  265.     lpAccel[iLoop].cmd = pACCEL->cmd;
  266.  
  267.     delete pACCEL;
  268.   }
  269.   arrayACCEL.RemoveAll();
  270.  
  271.   HACCEL hNewTable = CreateAcceleratorTable(lpAccel, nAccel);
  272.   if (!hNewTable) {
  273.     ::LocalFree(lpAccel);
  274.     return false;
  275.   }
  276.   HACCEL hOldTable = theApp.hAccel;
  277.   if (!::DestroyAcceleratorTable(hOldTable)) {
  278.     ::LocalFree(lpAccel);
  279.     return false;
  280.   }
  281.   theApp.hAccel = hNewTable;
  282.   ::LocalFree(lpAccel);
  283.  
  284.   UpdateMenu(GetMenu(*AfxGetApp()->m_pMainWnd));
  285.  
  286.   return true;
  287. }
  288.  
  289.  
  290. //////////////////////////////////////////////////////////////////////
  291. // Create/Destroy accelerators
  292. //////////////////////////////////////////////////////////////////////
  293. //
  294. //
  295. bool CAcceleratorManager::DeleteAccel(BYTE cVirt, WORD wIDCommand, WORD wKey)
  296. {
  297.   CCmdAccelOb* pCmdAccel = NULL;
  298.   if (m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) == TRUE) {
  299.     POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
  300.     POSITION PrevPos;
  301.     CAccelsOb* pAccel = NULL;
  302.     while (pos != NULL) {
  303.       PrevPos = pos;
  304.       pAccel = pCmdAccel->m_Accels.GetNext(pos);
  305.       if (pAccel->m_bLocked == true)
  306.         return false;
  307.  
  308.       if (pAccel->m_cVirt == cVirt && pAccel->m_wKey == wKey) {
  309.         pCmdAccel->m_Accels.RemoveAt(PrevPos);
  310.         delete pAccel;
  311.         return true;
  312.       }
  313.     }
  314.   }
  315.   return false;
  316. }
  317.  
  318.  
  319. //////////////////////////////////////////////////////////////////////
  320. //
  321. //
  322. bool CAcceleratorManager::DeleteEntry(WORD wIDCommand)
  323. {
  324.   CCmdAccelOb* pCmdAccel = NULL;
  325.   VERIFY(m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) == TRUE);
  326.  
  327.   CAccelsOb* pAccel;
  328.   POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
  329.   while (pos != NULL) {
  330.     pAccel = pCmdAccel->m_Accels.GetNext(pos);
  331.     if (pAccel->m_bLocked == true)
  332.       return false;
  333.   }
  334.   m_mapAccelString.RemoveKey(pCmdAccel->m_szCommand);
  335.   m_mapAccelTable.RemoveKey(wIDCommand);
  336.   delete pCmdAccel;
  337.  
  338.   return true;
  339. }
  340.  
  341.  
  342. //////////////////////////////////////////////////////////////////////
  343. //
  344. //
  345. bool CAcceleratorManager::DeleteEntry(LPCTSTR szCommand)
  346. {
  347.   ASSERT(szCommand != NULL);
  348.  
  349.   WORD wIDCommand;
  350.   if (m_mapAccelString.Lookup(szCommand, wIDCommand) == TRUE) {
  351.     return DeleteEntry(wIDCommand);
  352.   }
  353.   return true;
  354. }
  355.  
  356.  
  357. //////////////////////////////////////////////////////////////////////
  358. //
  359. //
  360. bool CAcceleratorManager::SetAccel(BYTE cVirt, WORD wIDCommand, WORD wKey, LPCTSTR szCommand, bool bLocked)
  361. {
  362.   ASSERT(szCommand != NULL);
  363.  
  364.   return AddAccel(cVirt, wIDCommand, wKey, szCommand, bLocked);
  365. }
  366.  
  367.  
  368. //////////////////////////////////////////////////////////////////////
  369. //
  370. //
  371. bool CAcceleratorManager::AddCommandAccel(WORD wIDCommand, LPCTSTR szCommand, bool bLocked)
  372. {
  373.   ASSERT(szCommand != NULL);
  374.  
  375.   ASSERT(m_pWndConnected != NULL);
  376.   HACCEL hOriginalTable = theApp.hAccel;
  377.  
  378.   int nAccel = ::CopyAcceleratorTable(hOriginalTable, NULL, 0);
  379.   LPACCEL lpAccel = (LPACCEL)LocalAlloc(LPTR, (nAccel) * sizeof(ACCEL));
  380.   if (!lpAccel)
  381.     return false;
  382.   ::CopyAcceleratorTable(hOriginalTable, lpAccel, nAccel);
  383.  
  384.   bool bRet = false;
  385.   for (int i = 0; i < nAccel; i++) {
  386.     if (lpAccel[i].cmd == wIDCommand)
  387.       bRet = AddAccel(lpAccel[i].fVirt, wIDCommand, lpAccel[i].key, szCommand, bLocked);
  388.   }
  389.   ::LocalFree(lpAccel);
  390.   return bRet;
  391. }
  392.  
  393.  
  394. //////////////////////////////////////////////////////////////////////
  395. //
  396. //
  397. bool CAcceleratorManager::CreateEntry(WORD wIDCommand, LPCTSTR szCommand)
  398. {
  399.   ASSERT(szCommand != NULL);
  400.  
  401.   WORD wIDDummy;
  402.   if (m_mapAccelString.Lookup(szCommand, wIDDummy) == TRUE)
  403.     return false;
  404.  
  405.   CCmdAccelOb* pCmdAccel = new CCmdAccelOb(wIDCommand, szCommand);
  406.   ASSERT(pCmdAccel != NULL);
  407.   m_mapAccelTable.SetAt(wIDCommand, pCmdAccel);
  408.   m_mapAccelString.SetAt(szCommand, wIDCommand);
  409.  
  410.   return false;
  411. }
  412.  
  413.  
  414. //////////////////////////////////////////////////////////////////////
  415. // Get a string from the ACCEL definition
  416. //////////////////////////////////////////////////////////////////////
  417. //
  418. //
  419. bool CAcceleratorManager::GetStringFromACCEL(ACCEL* pACCEL, CString& szAccel)
  420. {
  421.   ASSERT(pACCEL != NULL);
  422.   
  423.   CAccelsOb accel(pACCEL);
  424.   accel.GetString(szAccel);
  425.  
  426.   if (szAccel.IsEmpty())
  427.     return false;
  428.   else
  429.     return true;
  430. }
  431.  
  432.  
  433. //////////////////////////////////////////////////////////////////////
  434. //
  435. //
  436. bool CAcceleratorManager::GetStringFromACCEL(BYTE cVirt, WORD nCode, CString& szAccel)
  437. {
  438.   CAccelsOb accel(cVirt, nCode);
  439.   accel.GetString(szAccel);
  440.  
  441.   if (szAccel.IsEmpty())
  442.     return false;
  443.   else
  444.     return true;
  445. }
  446.  
  447.  
  448. //////////////////////////////////////////////////////////////////////
  449. // Copy function
  450. //
  451. CAcceleratorManager& CAcceleratorManager::operator=(const CAcceleratorManager& accelmgr)
  452. {
  453.   Reset();
  454.  
  455.   CCmdAccelOb* pCmdAccel;
  456.   CCmdAccelOb* pNewCmdAccel;
  457.   WORD wKey;
  458.   // Copy the 2 tables : normal accel table...
  459.   POSITION pos = accelmgr.m_mapAccelTable.GetStartPosition();
  460.   while (pos != NULL) {
  461.     accelmgr.m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
  462.     pNewCmdAccel = new CCmdAccelOb;
  463.     ASSERT(pNewCmdAccel != NULL);
  464.     *pNewCmdAccel = *pCmdAccel;
  465.     m_mapAccelTable.SetAt(wKey, pNewCmdAccel);
  466.   }
  467.   // ... and saved accel table.
  468.   pos = accelmgr.m_mapAccelTableSaved.GetStartPosition();
  469.   while (pos != NULL) {
  470.     accelmgr.m_mapAccelTableSaved.GetNextAssoc(pos, wKey, pCmdAccel);
  471.     pNewCmdAccel = new CCmdAccelOb;
  472.     ASSERT(pNewCmdAccel != NULL);
  473.     *pNewCmdAccel = *pCmdAccel;
  474.     m_mapAccelTableSaved.SetAt(wKey, pNewCmdAccel);
  475.   }
  476.  
  477.   // The Strings-ID table
  478.   CString szKey;
  479.   pos = accelmgr.m_mapAccelString.GetStartPosition();
  480.   while (pos != NULL) {
  481.     accelmgr.m_mapAccelString.GetNextAssoc(pos, szKey, wKey);
  482.     m_mapAccelString.SetAt(szKey, wKey);
  483.   }
  484.   m_bDefaultTable = accelmgr.m_bDefaultTable;
  485.  
  486.   return *this;
  487. }
  488.  
  489. void CAcceleratorManager::UpdateMenu(HMENU menu)
  490. {
  491.   int count = GetMenuItemCount(menu);
  492.  
  493.   OSVERSIONINFO info;
  494.   info.dwOSVersionInfoSize = sizeof(info);
  495.   GetVersionEx(&info);
  496.   
  497.   if(info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
  498.     MENUITEMINFO info;
  499.     char ss[128];
  500.     ZeroMemory(&info, sizeof(info));
  501.     info.cbSize = sizeof(info) - sizeof(HBITMAP);
  502.     info.fMask = MIIM_ID | MIIM_SUBMENU;
  503.     for(int i = 0; i < count; i++) {
  504.       GetMenuItemInfo(menu, i, TRUE, &info);
  505.       
  506.       if(info.hSubMenu != NULL) {
  507.         UpdateMenu(info.hSubMenu);
  508.       } else {
  509.         if(info.wID != (UINT)-1) {
  510.           MENUITEMINFO info2;
  511.           ZeroMemory(&info2, sizeof(info2));
  512.           info2.cbSize = sizeof(info2) - sizeof(HBITMAP);
  513.           info2.fMask = MIIM_STRING;
  514.           info2.dwTypeData = ss;
  515.           info2.cch = 128;
  516.           GetMenuItemInfo(menu, i, MF_BYPOSITION, &info2);
  517.           CString str = ss;
  518.           int index = str.Find('\t');
  519.           if(index != -1)
  520.             str = str.Left(index);
  521.           
  522.           WORD command = info.wID;
  523.           
  524.           CCmdAccelOb *o;
  525.           if(m_mapAccelTable.Lookup(command, o)) {
  526.             if(o->m_Accels.GetCount()) {
  527.               POSITION pos = o->m_Accels.GetHeadPosition();
  528.               CAccelsOb *accel = o->m_Accels.GetNext(pos);
  529.               
  530.               CString s;
  531.               accel->GetString(s);
  532.               str += "\t";
  533.               str += s;
  534.             }
  535.           }
  536.           if(str != ss)
  537.             ModifyMenu(menu, i, MF_BYPOSITION | MF_STRING, info.wID, str);
  538.         }
  539.       }
  540.     }
  541.   } else {
  542.     MENUITEMINFO info;
  543.     wchar_t ss[128];
  544.     wchar_t str[512];
  545.     
  546.     ZeroMemory(&info, sizeof(info));
  547.     info.cbSize = sizeof(info);
  548.     info.fMask = MIIM_ID | MIIM_SUBMENU;
  549.     for(int i = 0; i < count; i++) {
  550.       GetMenuItemInfo(menu, i, TRUE, &info);
  551.       
  552.       if(info.hSubMenu != NULL) {
  553.         UpdateMenu(info.hSubMenu);
  554.       } else {
  555.         if(info.wID != (WORD)-1) {
  556.           MENUITEMINFOW info2;
  557.           ZeroMemory(&info2, sizeof(info2));
  558.           info2.cbSize = sizeof(info2);
  559.           info2.fMask = MIIM_STRING;
  560.           info2.dwTypeData = ss;
  561.           info2.cch = 128;
  562.           GetMenuItemInfoW(menu, i, MF_BYPOSITION, &info2);
  563.  
  564.           wcscpy(str, ss);
  565.           
  566.           wchar_t *p = wcschr(str, '\t');
  567.           if(p)
  568.             *p = 0;
  569.           
  570.           CCmdAccelOb *o;
  571.           WORD command = info.wID;
  572.           if(m_mapAccelTable.Lookup(command, o)) {
  573.             if(o->m_Accels.GetCount()) {
  574.               POSITION pos = o->m_Accels.GetHeadPosition();
  575.               
  576.               CAccelsOb *accel = o->m_Accels.GetNext(pos);
  577.               
  578.               CString s;
  579.               accel->GetString(s);
  580.  
  581.               wchar_t temp[128];
  582.               temp[0] = '\t';
  583.               temp[1] = 0;
  584.               wcscat(str, temp);
  585.               p = temp;
  586.               for(const char *sp = s; *sp; sp++)
  587.                 *p++ = *sp;
  588.               *p = 0;
  589.               wcscat(str, temp);
  590.             }
  591.           }
  592.           if(wcscmp(str,ss))
  593.             ModifyMenuW(menu, i, MF_BYPOSITION | MF_STRING, info.wID, str);
  594.         }
  595.       }
  596.     }
  597.   }
  598. }
  599.  
  600. //////////////////////////////////////////////////////////////////////
  601. // In/Out to the registry
  602. //////////////////////////////////////////////////////////////////////
  603. //
  604. //
  605. bool CAcceleratorManager::Load(HKEY hRegKey, LPCTSTR szRegKey)
  606. {
  607.   ASSERT(szRegKey != NULL);
  608.  
  609.   m_hRegKey = hRegKey;
  610.   m_szRegKey = szRegKey;
  611.  
  612.   DWORD data[2048/sizeof(DWORD)];
  613.  
  614.   DWORD len = sizeof(data);
  615.   if(regQueryBinaryValue("keyboard", (char *)data, len)) {
  616.     int count = len/sizeof(DWORD);
  617.  
  618.     CCmdAccelOb* pCmdAccel;
  619.     CAccelsOb* pAccel;
  620.     DWORD dwIDAccelData, dwAccelData;
  621.     BOOL bExistID;    
  622.     int iIndex = 0;
  623.     if(count) {
  624.       WORD wKey;
  625.       POSITION pos = m_mapAccelTable.GetStartPosition();
  626.  
  627.       while(pos != NULL) {
  628.         m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
  629.         pCmdAccel->DeleteUserAccels();
  630.       }
  631.       
  632.       while(iIndex < count) {
  633.         dwIDAccelData = data[iIndex++];
  634.         
  635.         WORD wIDCommand = LOWORD(dwIDAccelData);
  636.         bExistID = m_mapAccelTable.Lookup(wIDCommand, pCmdAccel);
  637.  
  638.         if (bExistID) {
  639.           pCmdAccel->DeleteUserAccels();
  640.         }
  641.         for (int j = 0; j < HIWORD(dwIDAccelData) && iIndex < count; j++) {
  642.           dwAccelData = data[iIndex++];
  643.           if (bExistID) {
  644.             pAccel = new CAccelsOb;
  645.             ASSERT(pAccel != NULL);
  646.             pAccel->SetData(dwAccelData);
  647.             pCmdAccel->Add(pAccel);
  648.           }
  649.         }
  650.       }
  651.     }
  652.     UpdateWndTable();
  653.     return true;
  654.   }
  655.   return false;
  656. }
  657.  
  658.  
  659. //////////////////////////////////////////////////////////////////////
  660. //
  661. //
  662. bool CAcceleratorManager::Load()
  663. {
  664.   BOOL bRet = FALSE;
  665.   if (!m_szRegKey.IsEmpty())
  666.     bRet = Load(m_hRegKey, m_szRegKey);
  667.  
  668.   if (bRet == TRUE)
  669.     return true;
  670.   else
  671.     return false;
  672. }
  673.  
  674.  
  675. //////////////////////////////////////////////////////////////////////
  676. //
  677. //
  678. bool CAcceleratorManager::Write()
  679. {
  680.   CDWordArray AccelsDatasArray;
  681.   CDWordArray CmdDatasArray;
  682.   
  683.   int iCount = 0;
  684.   CCmdAccelOb* pCmdAccel;
  685.   CAccelsOb* pAccel;
  686.   DWORD dwAccelData;
  687.   
  688.   WORD wKey;
  689.   POSITION pos = m_mapAccelTable.GetStartPosition();
  690.   while (pos != NULL) {
  691.     m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
  692.     CmdDatasArray.RemoveAll();
  693.  
  694.     POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
  695.     while (pos != NULL) {
  696.       pAccel = pCmdAccel->m_Accels.GetNext(pos);
  697.       //      if (!pAccel->m_bLocked) {
  698.       dwAccelData = pAccel->GetData();
  699.       CmdDatasArray.Add(dwAccelData);
  700.       //      }
  701.     }
  702.  
  703.     if (CmdDatasArray.GetSize() > 0) {
  704.       CmdDatasArray.InsertAt(0, MAKELONG(pCmdAccel->m_wIDCommand, CmdDatasArray.GetSize()));
  705.       
  706.       AccelsDatasArray.Append(CmdDatasArray);
  707.       iCount++;
  708.     }
  709.   }
  710.   //  AccelsDatasArray.InsertAt(0, MAKELONG(65535, iCount));
  711.   
  712.   int count = AccelsDatasArray.GetSize();
  713.   DWORD *data = (DWORD *)malloc(count * sizeof(DWORD));
  714.   ASSERT(data != NULL);
  715.  
  716.   for(int index = 0; index < count; index++)
  717.     data[index] = AccelsDatasArray[index];
  718.  
  719.   regSetBinaryValue("keyboard", (char *)data, count*sizeof(DWORD));
  720.  
  721.   AccelsDatasArray.RemoveAll();
  722.   CmdDatasArray.RemoveAll();
  723.  
  724.   free(data);
  725.  
  726.   return true;
  727. }
  728.  
  729.  
  730. //////////////////////////////////////////////////////////////////////
  731. // Defaults values management.
  732. //////////////////////////////////////////////////////////////////////
  733. //
  734. //
  735. bool CAcceleratorManager::CreateDefaultTable()
  736. {
  737.   if (m_bDefaultTable)
  738.     return false;
  739.         
  740.   CCmdAccelOb* pCmdAccel;
  741.   CCmdAccelOb* pNewCmdAccel;
  742.  
  743.   CAccelsOb* pAccel;
  744.   CAccelsOb* pNewAccel;
  745.  
  746.   WORD wKey;
  747.   POSITION pos = m_mapAccelTable.GetStartPosition();
  748.   while (pos != NULL) {
  749.     m_mapAccelTable.GetNextAssoc(pos, wKey, pCmdAccel);
  750.     pNewCmdAccel = new CCmdAccelOb;
  751.     ASSERT(pNewCmdAccel != NULL);
  752.     
  753.     POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
  754.     while (pos != NULL) {
  755.       pAccel = pCmdAccel->m_Accels.GetNext(pos);
  756.       if (!pAccel->m_bLocked) {
  757.         pNewAccel = new CAccelsOb;
  758.         ASSERT(pNewAccel != NULL);
  759.   
  760.         *pNewAccel = *pAccel;
  761.         pNewCmdAccel->m_Accels.AddTail(pNewAccel);
  762.       }
  763.     }
  764.     if (pNewCmdAccel->m_Accels.GetCount() != 0) {
  765.       pNewCmdAccel->m_wIDCommand = pCmdAccel->m_wIDCommand;
  766.       pNewCmdAccel->m_szCommand = pCmdAccel->m_szCommand;
  767.       
  768.       m_mapAccelTableSaved.SetAt(wKey, pNewCmdAccel);
  769.     } else 
  770.       delete pNewCmdAccel;
  771.   }
  772.  
  773.   m_bDefaultTable = true;
  774.   return true;
  775. }
  776.  
  777.  
  778. //////////////////////////////////////////////////////////////////////
  779. //
  780. //
  781. bool CAcceleratorManager::Default()
  782. {
  783.   return true;
  784. }
  785.