annotate src/win32/AcceleratorManager.cpp @ 2:3549bbe597ed

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