annotate src/win32/AccelEditor.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
rev   line source
rlm@1 1 // AccelEditor.cpp : implementation file
rlm@1 2 //
rlm@1 3
rlm@1 4 #include "stdafx.h"
rlm@1 5 #include "resource.h"
rlm@1 6 #include "AccelEditor.h"
rlm@1 7 #include "CmdAccelOb.h"
rlm@1 8 #include "VBA.h"
rlm@1 9
rlm@1 10 /////////////////////////////////////////////////////////////////////////////
rlm@1 11 // AccelEditor dialog
rlm@1 12
rlm@1 13 AccelEditor::AccelEditor(CWnd *pParent, CMenu *pMenu, CAcceleratorManager *pExtMgr)
rlm@1 14 : ResizeDlg(AccelEditor::IDD, pParent), m_pMenuSrc(pMenu), m_pExtMgr(pExtMgr)
rlm@1 15 {
rlm@1 16 //{{AFX_DATA_INIT(AccelEditor)
rlm@1 17 // NOTE: the ClassWizard will add member initialization here
rlm@1 18 //}}AFX_DATA_INIT
rlm@1 19 }
rlm@1 20
rlm@1 21 BOOL AccelEditor::IsModified() const
rlm@1 22 {
rlm@1 23 return m_modified;
rlm@1 24 }
rlm@1 25
rlm@1 26 const CAcceleratorManager &AccelEditor::GetResultMangager() const
rlm@1 27 {
rlm@1 28 return m_result;
rlm@1 29 }
rlm@1 30
rlm@1 31 void AccelEditor::DoDataExchange(CDataExchange *pDX)
rlm@1 32 {
rlm@1 33 CDialog::DoDataExchange(pDX);
rlm@1 34 //{{AFX_DATA_MAP(AccelEditor)
rlm@1 35 DDX_Control(pDX, IDC_CURRENTS, m_currents);
rlm@1 36 DDX_Control(pDX, IDC_ALREADY_AFFECTED, m_alreadyAffected);
rlm@1 37 DDX_Control(pDX, IDC_COMMANDS, m_commands);
rlm@1 38 DDX_Control(pDX, IDC_EDIT_KEY, m_key);
rlm@1 39 DDX_Control(pDX, IDC_ACCELEDIT_AUTOTIMEOUT, m_timeout);
rlm@1 40 DDX_Control(pDX, IDC_ACCELEDIT_PROGRESSBAR, m_progress);
rlm@1 41 //}}AFX_DATA_MAP
rlm@1 42 }
rlm@1 43
rlm@1 44 BEGIN_MESSAGE_MAP(AccelEditor, CDialog)
rlm@1 45 //{{AFX_MSG_MAP(AccelEditor)
rlm@1 46 ON_BN_CLICKED(ID_OK, &AccelEditor::OnOk)
rlm@1 47 ON_BN_CLICKED(ID_CANCEL, &AccelEditor::OnCancel)
rlm@1 48 ON_BN_CLICKED(IDC_ACCELEDIT_APPLY, &AccelEditor::OnApply)
rlm@1 49 ON_BN_CLICKED(IDC_RESET, &AccelEditor::OnReset)
rlm@1 50 ON_BN_CLICKED(IDC_ASSIGN, &AccelEditor::OnAssign)
rlm@1 51 ON_BN_CLICKED(IDC_REMOVE, &AccelEditor::OnRemove)
rlm@1 52 ON_BN_CLICKED(IDC_ACCELEDIT_REPLACE, &AccelEditor::OnReplace)
rlm@1 53 ON_CONTROL(EN_CHANGE, IDC_EDIT_KEY, &AccelEditor::OnKeyboardEditChange)
rlm@1 54 ON_CONTROL(EN_KILLFOCUS, IDC_EDIT_KEY, &AccelEditor::OnKeyboardEditKillfocus)
rlm@1 55 ON_CONTROL(EN_SETFOCUS, IDC_ACCELEDIT_AUTOTIMEOUT, &AccelEditor::OnTimeoutEditSetfocus)
rlm@1 56 ON_CONTROL(EN_KILLFOCUS, IDC_ACCELEDIT_AUTOTIMEOUT, &AccelEditor::OnTimeoutEditKillfocus)
rlm@1 57 ON_NOTIFY(TVN_SELCHANGED, IDC_COMMANDS, &AccelEditor::OnTvnSelchangedCommands)
rlm@1 58 //ON_NOTIFY(LVN_ITEMCHANGED, IDC_CURRENTS, &AccelEditor::OnListItemChanged)
rlm@1 59 ON_NOTIFY(NM_DBLCLK, IDC_CURRENTS, &AccelEditor::OnListDblClick)
rlm@1 60 ON_NOTIFY(NM_CLICK, IDC_CURRENTS, &AccelEditor::OnListClick)
rlm@1 61 ON_WM_TIMER()
rlm@1 62 //}}AFX_MSG_MAP
rlm@1 63 END_MESSAGE_MAP()
rlm@1 64
rlm@1 65 /////////////////////////////////////////////////////////////////////////////
rlm@1 66 // AccelEditor message handlers
rlm@1 67
rlm@1 68 BOOL AccelEditor::OnInitDialog()
rlm@1 69 {
rlm@1 70 CDialog::OnInitDialog();
rlm@1 71
rlm@1 72 DIALOG_SIZER_START(sz)
rlm@1 73 DIALOG_SIZER_ENTRY(ID_OK, DS_MoveX)
rlm@1 74 DIALOG_SIZER_ENTRY(ID_CANCEL, DS_MoveX)
rlm@1 75 DIALOG_SIZER_ENTRY(IDC_ACCELEDIT_APPLY, DS_MoveX)
rlm@1 76 DIALOG_SIZER_ENTRY(IDC_ASSIGN, DS_MoveX)
rlm@1 77 DIALOG_SIZER_ENTRY(IDC_REMOVE, DS_MoveX)
rlm@1 78 DIALOG_SIZER_ENTRY(IDC_ACCELEDIT_REPLACE, DS_MoveX)
rlm@1 79 DIALOG_SIZER_ENTRY(IDC_COMMANDS, DS_SizeX | DS_SizeY)
rlm@1 80 DIALOG_SIZER_ENTRY(IDC_CURRENTS, DS_MoveX | DS_SizeY)
rlm@1 81 DIALOG_SIZER_ENTRY(IDC_EDIT_KEY, DS_MoveX | DS_MoveY)
rlm@1 82 DIALOG_SIZER_ENTRY(IDC_EDIT_KEY, DS_MoveX | DS_MoveY)
rlm@1 83 DIALOG_SIZER_ENTRY(IDC_STATIC2, DS_MoveY)
rlm@1 84 DIALOG_SIZER_ENTRY(IDC_STATIC3, DS_MoveX | DS_MoveY)
rlm@1 85 DIALOG_SIZER_ENTRY(IDC_STATIC4, DS_MoveX | DS_MoveY)
rlm@1 86 DIALOG_SIZER_ENTRY(IDC_STATIC5, DS_MoveX | DS_MoveY)
rlm@1 87 DIALOG_SIZER_ENTRY(IDC_ACCELEDIT_AUTOTIMEOUT, DS_SizeX | DS_MoveY)
rlm@1 88 DIALOG_SIZER_END()
rlm@1 89 SetData(sz,
rlm@1 90 TRUE,
rlm@1 91 HKEY_CURRENT_USER,
rlm@1 92 "Software\\Emulators\\VisualBoyAdvance\\Viewer\\AccelEditor",
rlm@1 93 NULL);
rlm@1 94
rlm@1 95 if (m_pExtMgr)
rlm@1 96 m_result = m_mgr = *m_pExtMgr;
rlm@1 97
rlm@1 98 m_currents.SetExtendedStyle(LVS_EX_FULLROWSELECT);
rlm@1 99 m_currents.InsertColumn(0, "Keys");
rlm@1 100 m_currents.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
rlm@1 101 InitCommands();
rlm@1 102 m_autoMode = AUTO_REPLACE;
rlm@1 103 m_modified = FALSE;
rlm@1 104 m_timeoutValue = 1000;
rlm@1 105 CString timeoutStr;
rlm@1 106 timeoutStr.Format("%d", m_timeoutValue);
rlm@1 107 m_timeout.SetWindowText(timeoutStr);
rlm@1 108 m_progress.SetPos(0);
rlm@1 109
rlm@1 110 GetDlgItem(IDC_ACCELEDIT_APPLY)->EnableWindow(FALSE);
rlm@1 111 return TRUE; // return TRUE unless you set the focus to a control
rlm@1 112 // EXCEPTION: OCX Property Pages should return FALSE
rlm@1 113 }
rlm@1 114
rlm@1 115 void AccelEditor::AddCommandsFromTable()
rlm@1 116 {
rlm@1 117 POSITION pos = m_mgr.m_mapAccelString.GetStartPosition();
rlm@1 118 while (pos != NULL)
rlm@1 119 {
rlm@1 120 CString command;
rlm@1 121 WORD wID;
rlm@1 122 m_mgr.m_mapAccelString.GetNextAssoc(pos, command, wID);
rlm@1 123 int nPos = command.Find('\\');
rlm@1 124
rlm@1 125 if (nPos == 0) // skip menu commands
rlm@1 126 {
rlm@1 127 continue;
rlm@1 128 }
rlm@1 129
rlm@1 130 HTREEITEM newItem = TVI_ROOT;
rlm@1 131 #if 0
rlm@1 132 /*
rlm@1 133 while (nPos != -1)
rlm@1 134 {
rlm@1 135 newItem = m_commands.InsertItem(command.Left(nPos), newItem);
rlm@1 136 command.Delete(0, nPos + 1);
rlm@1 137 nPos = command.Find('\\');
rlm@1 138 }
rlm@1 139 */
rlm@1 140 #endif
rlm@1 141 newItem = m_commands.InsertItem(command, newItem);
rlm@1 142 m_commands.SetItemData(newItem, wID);
rlm@1 143 m_hItems.AddTail(newItem);
rlm@1 144 }
rlm@1 145 }
rlm@1 146
rlm@1 147 // recursive calls
rlm@1 148 void AccelEditor::AddCommandsFromMenu(CMenu *pMenu, HTREEITEM hParent)
rlm@1 149 {
rlm@1 150 UINT nIndexMax = pMenu->GetMenuItemCount();
rlm@1 151 for (UINT nIndex = 0; nIndex < nIndexMax; ++nIndex)
rlm@1 152 {
rlm@1 153 UINT nID = pMenu->GetMenuItemID(nIndex);
rlm@1 154 if (nID == 0)
rlm@1 155 continue; // menu separator or invalid cmd - ignore it
rlm@1 156
rlm@1 157 if (nID == (UINT)-1)
rlm@1 158 {
rlm@1 159 // possibly a submenu
rlm@1 160 CMenu *pSubMenu = pMenu->GetSubMenu(nIndex);
rlm@1 161 if (pSubMenu != NULL)
rlm@1 162 {
rlm@1 163 CString tempStr;
rlm@1 164 pMenu->GetMenuString(nIndex, tempStr, MF_BYPOSITION);
rlm@1 165 tempStr.Remove('&');
rlm@1 166 HTREEITEM newItem = m_commands.InsertItem(tempStr, hParent);
rlm@1 167 AddCommandsFromMenu(pSubMenu, newItem);
rlm@1 168 }
rlm@1 169 }
rlm@1 170 else
rlm@1 171 {
rlm@1 172 // normal menu item
rlm@1 173 // generate the strings
rlm@1 174 CString command;
rlm@1 175 pMenu->GetMenuString(nIndex, command, MF_BYPOSITION);
rlm@1 176 int nPos = command.ReverseFind('\t');
rlm@1 177 if (nPos != -1)
rlm@1 178 {
rlm@1 179 command.Delete(nPos, command.GetLength() - nPos);
rlm@1 180 }
rlm@1 181 command.Remove('&');
rlm@1 182 HTREEITEM newItem = m_commands.InsertItem(command, hParent);
rlm@1 183 m_commands.SetItemData(newItem, nID);
rlm@1 184 m_hItems.AddTail(newItem);
rlm@1 185 }
rlm@1 186 }
rlm@1 187 }
rlm@1 188
rlm@1 189 void AccelEditor::InitCommands()
rlm@1 190 {
rlm@1 191 m_commands.DeleteAllItems();
rlm@1 192 m_hItems.RemoveAll();
rlm@1 193 m_alreadyAffected.SetWindowText("");
rlm@1 194
rlm@1 195 AddCommandsFromMenu(m_pMenuSrc, TVI_ROOT);
rlm@1 196 AddCommandsFromTable();
rlm@1 197 }
rlm@1 198
rlm@1 199 BOOL AccelEditor::PreTranslateMessage(MSG *pMsg)
rlm@1 200 {
rlm@1 201 CWnd *pFocus = GetFocus();
rlm@1 202 if (pFocus == &m_currents)
rlm@1 203 {
rlm@1 204 if (pMsg->message == WM_KEYDOWN)
rlm@1 205 {
rlm@1 206 switch (pMsg->wParam)
rlm@1 207 {
rlm@1 208 case VK_ESCAPE:
rlm@1 209 m_currents.SetItemState(-1, 0, LVIS_SELECTED);
rlm@1 210 CheckListSelections();
rlm@1 211 break;
rlm@1 212 case VK_RETURN:
rlm@1 213 case VK_INSERT:
rlm@1 214 // kludge to workaround CKeyboardEdit::PreTranslateMessage()
rlm@1 215 break;
rlm@1 216 case VK_DELETE:
rlm@1 217 case VK_BACK:
rlm@1 218 OnRemove();
rlm@1 219 break;
rlm@1 220 case VK_F6:
rlm@1 221 case VK_LEFT:
rlm@1 222 m_commands.SetFocus();
rlm@1 223 break;
rlm@1 224 case VK_RIGHT:
rlm@1 225 GetDlgItem(ID_OK)->SetFocus();
rlm@1 226 default:
rlm@1 227 return ResizeDlg::PreTranslateMessage(pMsg);
rlm@1 228 }
rlm@1 229 return TRUE;
rlm@1 230 }
rlm@1 231 else if (pMsg->message == WM_KEYUP) // kludge to workaround CKeyboardEdit::PreTranslateMessage()
rlm@1 232 {
rlm@1 233 switch (pMsg->wParam)
rlm@1 234 {
rlm@1 235 case VK_RETURN:
rlm@1 236 OnEdit();
rlm@1 237 break;
rlm@1 238 case VK_INSERT:
rlm@1 239 OnNew();
rlm@1 240 break;
rlm@1 241 default:
rlm@1 242 return ResizeDlg::PreTranslateMessage(pMsg);
rlm@1 243 }
rlm@1 244 return TRUE;
rlm@1 245 }
rlm@1 246 }
rlm@1 247 else if (pFocus == &m_commands)
rlm@1 248 {
rlm@1 249 if (pMsg->message == WM_KEYDOWN)
rlm@1 250 {
rlm@1 251 switch (pMsg->wParam)
rlm@1 252 {
rlm@1 253 case VK_F6:
rlm@1 254 m_currents.SetFocus();
rlm@1 255 break;
rlm@1 256 case VK_RIGHT:
rlm@1 257 if (!m_commands.ItemHasChildren(m_commands.GetSelectedItem()))
rlm@1 258 {
rlm@1 259 m_currents.SetFocus();
rlm@1 260 break;
rlm@1 261 }
rlm@1 262 // fall through
rlm@1 263 default:
rlm@1 264 return ResizeDlg::PreTranslateMessage(pMsg);
rlm@1 265 }
rlm@1 266 return TRUE;
rlm@1 267 }
rlm@1 268 }
rlm@1 269
rlm@1 270 return ResizeDlg::PreTranslateMessage(pMsg);
rlm@1 271 }
rlm@1 272
rlm@1 273 void AccelEditor::OnOk()
rlm@1 274 {
rlm@1 275 OnApply();
rlm@1 276 // OnTimeoutEditKillfocus();
rlm@1 277 EndDialog(TRUE);
rlm@1 278 }
rlm@1 279
rlm@1 280 void AccelEditor::OnCancel()
rlm@1 281 {
rlm@1 282 // OnTimeoutEditKillfocus();
rlm@1 283 // EndDialog(m_modified);
rlm@1 284 EndDialog(FALSE); // this allows the caller to cancel even if the user has Apply'ed
rlm@1 285 }
rlm@1 286
rlm@1 287 void AccelEditor::OnApply()
rlm@1 288 {
rlm@1 289 m_result = m_mgr;
rlm@1 290 GetDlgItem(IDC_ACCELEDIT_APPLY)->EnableWindow(FALSE);
rlm@1 291 }
rlm@1 292
rlm@1 293 void AccelEditor::OnReset()
rlm@1 294 {
rlm@1 295 m_mgr.Default(); /// FIXME accelerator reset NYI
rlm@1 296 systemMessage(
rlm@1 297 0,
rlm@1 298 "The \"Reset All Accelerators\" feature is currently unimplemented.\nYou can achieve the same result by closing VBA, opening up your \"vba.ini\" file, deleting the line that starts with \"keyboard\", then reopening VBA.");
rlm@1 299 InitCommands(); // update the listboxes.
rlm@1 300 }
rlm@1 301
rlm@1 302 void AccelEditor::OnAssign()
rlm@1 303 {
rlm@1 304 if (CheckAffected())
rlm@1 305 return;
rlm@1 306
rlm@1 307 // get the currently selected group
rlm@1 308 HTREEITEM hItem = m_commands.GetSelectedItem();
rlm@1 309 if (hItem == NULL)
rlm@1 310 return; // abort
rlm@1 311
rlm@1 312 // Get the object who manage the accels list, associated to the command.
rlm@1 313 WORD wIDCommand = LOWORD(m_commands.GetItemData(hItem));
rlm@1 314
rlm@1 315 CCmdAccelOb *pCmdAccel;
rlm@1 316 if (m_mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) != TRUE)
rlm@1 317 return;
rlm@1 318
rlm@1 319 WORD wKey;
rlm@1 320 bool bCtrl, bAlt, bShift;
rlm@1 321 if (!m_key.GetAccelKey(wKey, bCtrl, bAlt, bShift))
rlm@1 322 return; // no valid key, abort
rlm@1 323
rlm@1 324 BYTE cVirt = 0;
rlm@1 325 if (bCtrl)
rlm@1 326 cVirt |= FCONTROL;
rlm@1 327 if (bAlt)
rlm@1 328 cVirt |= FALT;
rlm@1 329 if (bShift)
rlm@1 330 cVirt |= FSHIFT;
rlm@1 331
rlm@1 332 cVirt |= FVIRTKEY;
rlm@1 333
rlm@1 334 // Create the new key...
rlm@1 335 CAccelsOb *pAccel = new CAccelsOb(cVirt, wKey, false);
rlm@1 336 ASSERT(pAccel != NULL);
rlm@1 337 // ...and add in the list.
rlm@1 338 pCmdAccel->m_Accels.AddTail(pAccel);
rlm@1 339
rlm@1 340 // Update the listbox.
rlm@1 341 CString szBuffer;
rlm@1 342 pAccel->GetString(szBuffer);
rlm@1 343
rlm@1 344 int index = m_currents.GetNextItem(-1, LVNI_SELECTED);
rlm@1 345 if (index < 0)
rlm@1 346 index = 0;
rlm@1 347 m_currents.InsertItem(index, szBuffer);
rlm@1 348 m_currents.SetItemData(index, reinterpret_cast<DWORD>(pAccel));
rlm@1 349 m_currents.SetItemState(-1, 0, LVIS_SELECTED); // deselect other items first
rlm@1 350 m_currents.SetItemState(index, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
rlm@1 351 GetDlgItem(IDC_REMOVE)->EnableWindow(TRUE);
rlm@1 352 GetDlgItem(IDC_ACCELEDIT_REPLACE)->EnableWindow(TRUE);
rlm@1 353
rlm@1 354 // Reset the key editor.
rlm@1 355 // m_key.ResetKey();
rlm@1 356
rlm@1 357 m_modified = TRUE;
rlm@1 358 GetDlgItem(IDC_ACCELEDIT_APPLY)->EnableWindow(TRUE);
rlm@1 359 }
rlm@1 360
rlm@1 361 void AccelEditor::OnRemove()
rlm@1 362 {
rlm@1 363 // Some controls
rlm@1 364 POSITION selected = m_currents.GetFirstSelectedItemPosition();
rlm@1 365 if (selected == NULL)
rlm@1 366 return;
rlm@1 367
rlm@1 368 HTREEITEM hItem = m_commands.GetSelectedItem();
rlm@1 369 if (hItem == NULL)
rlm@1 370 return;
rlm@1 371
rlm@1 372 // Ref to the ID command
rlm@1 373 WORD wIDCommand = LOWORD(m_commands.GetItemData(hItem));
rlm@1 374
rlm@1 375 // Run through the accels, and control if it can be deleted.
rlm@1 376 CCmdAccelOb *pCmdAccel;
rlm@1 377 if (m_mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) == TRUE)
rlm@1 378 {
rlm@1 379 POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
rlm@1 380 POSITION PrevPos;
rlm@1 381 while (pos != NULL)
rlm@1 382 {
rlm@1 383 PrevPos = pos;
rlm@1 384 CAccelsOb *pAccel = pCmdAccel->m_Accels.GetNext(pos);
rlm@1 385 do
rlm@1 386 {
rlm@1 387 int indexCurrent = m_currents.GetNextSelectedItem(selected);
rlm@1 388 CAccelsOb *pAccelCurrent = reinterpret_cast<CAccelsOb *>(m_currents.GetItemData(indexCurrent));
rlm@1 389 if (pAccel == pAccelCurrent)
rlm@1 390 {
rlm@1 391 if (!pAccel->m_bLocked)
rlm@1 392 {
rlm@1 393 // not locked, so we delete the key
rlm@1 394 pCmdAccel->m_Accels.RemoveAt(PrevPos);
rlm@1 395 delete pAccel;
rlm@1 396 // and update the listboxes/key editor/static text
rlm@1 397 m_currents.DeleteItem(indexCurrent);
rlm@1 398 m_modified = TRUE;
rlm@1 399 break;
rlm@1 400 }
rlm@1 401 else
rlm@1 402 {
rlm@1 403 systemMessage(0, "Unable to remove this locked accelerator: ", m_currents.GetItemText(indexCurrent, KEY_COLUMN));
rlm@1 404 m_currents.SetItemState(indexCurrent, 0, LVIS_SELECTED); // deselect it
rlm@1 405 break;
rlm@1 406 }
rlm@1 407 }
rlm@1 408 }
rlm@1 409 while (selected != NULL);
rlm@1 410
rlm@1 411 selected = m_currents.GetFirstSelectedItemPosition();
rlm@1 412 if (selected == NULL) // the normal exit of this function
rlm@1 413 {
rlm@1 414 m_currents.SetItemState(m_currents.GetNextItem(-1, LVIS_FOCUSED), LVIS_SELECTED, LVIS_SELECTED);
rlm@1 415 if (m_currents.GetSelectedCount() == 0)
rlm@1 416 {
rlm@1 417 GetDlgItem(IDC_REMOVE)->EnableWindow(FALSE);
rlm@1 418 GetDlgItem(IDC_ACCELEDIT_REPLACE)->EnableWindow(FALSE);
rlm@1 419 }
rlm@1 420 GetDlgItem(IDC_ACCELEDIT_APPLY)->EnableWindow(m_modified);
rlm@1 421 return;
rlm@1 422 }
rlm@1 423 }
rlm@1 424 systemMessage(0, "internal error (AccelEditor::Remove : pAccel unavailable)");
rlm@1 425 return;
rlm@1 426 }
rlm@1 427 systemMessage(0, "internal error (AccelEditor::Remove : Lookup failed)");
rlm@1 428 }
rlm@1 429
rlm@1 430 void AccelEditor::OnReplace()
rlm@1 431 {
rlm@1 432 if (CheckAffected())
rlm@1 433 return;
rlm@1 434 OnRemove();
rlm@1 435 OnAssign();
rlm@1 436 }
rlm@1 437
rlm@1 438 void AccelEditor::OnNew()
rlm@1 439 {
rlm@1 440 m_autoMode = AUTO_NEW;
rlm@1 441 m_key.SetFocus();
rlm@1 442 }
rlm@1 443
rlm@1 444 void AccelEditor::OnEdit()
rlm@1 445 {
rlm@1 446 m_autoMode = AUTO_REPLACE;
rlm@1 447 m_key.SetFocus();
rlm@1 448 }
rlm@1 449
rlm@1 450 BOOL AccelEditor::CheckAffected()
rlm@1 451 {
rlm@1 452 m_alreadyAffected.SetWindowText("");
rlm@1 453
rlm@1 454 WORD wKey;
rlm@1 455 bool bCtrl, bAlt, bShift;
rlm@1 456 if (!m_key.GetAccelKey(wKey, bCtrl, bAlt, bShift))
rlm@1 457 return TRUE; // no valid key, abort
rlm@1 458
rlm@1 459 POSITION posItem = m_hItems.GetHeadPosition();
rlm@1 460 while (posItem != NULL)
rlm@1 461 {
rlm@1 462 HTREEITEM hItem = m_hItems.GetNext(posItem);
rlm@1 463 WORD wIDCommand2 = LOWORD(m_commands.GetItemData(hItem));
rlm@1 464
rlm@1 465 CCmdAccelOb *pCmdAccel;
rlm@1 466 m_mgr.m_mapAccelTable.Lookup(wIDCommand2, pCmdAccel);
rlm@1 467
rlm@1 468 POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
rlm@1 469 while (pos != NULL)
rlm@1 470 {
rlm@1 471 CAccelsOb *pAccel = pCmdAccel->m_Accels.GetNext(pos);
rlm@1 472 if (pAccel->IsEqual(wKey, bCtrl, bAlt, bShift))
rlm@1 473 {
rlm@1 474 // the key is already affected (in the same or other command)
rlm@1 475 // (the parts that were commented out allow for a one-to-many mapping,
rlm@1 476 // which is only disabled because the MFC stuff that automagically activates the commands
rlm@1 477 // doesn't seem to be capable of activating more than one command per accelerator...)
rlm@1 478 m_alreadyAffected.SetWindowText(pCmdAccel->m_szCommand);
rlm@1 479 return TRUE;
rlm@1 480 }
rlm@1 481 }
rlm@1 482 }
rlm@1 483
rlm@1 484 return FALSE;
rlm@1 485 }
rlm@1 486
rlm@1 487 BOOL AccelEditor::CheckJammed()
rlm@1 488 {
rlm@1 489 WORD jam;
rlm@1 490 if (m_key.GetJamKey(jam))
rlm@1 491 {
rlm@1 492 // these go first, or the timer would be set again
rlm@1 493 m_key.ResetKey();
rlm@1 494 m_key.SetWindowText("Interrupted");
rlm@1 495 if (m_currents.IsWindowEnabled())
rlm@1 496 m_currents.SetFocus();
rlm@1 497 else
rlm@1 498 m_commands.SetFocus();
rlm@1 499 return TRUE;
rlm@1 500 }
rlm@1 501 return FALSE;
rlm@1 502 }
rlm@1 503
rlm@1 504 BOOL AccelEditor::CheckListSelections()
rlm@1 505 {
rlm@1 506 BOOL result = m_currents.GetFirstSelectedItemPosition() ? TRUE : FALSE;
rlm@1 507
rlm@1 508 GetDlgItem(IDC_REMOVE)->EnableWindow(result);
rlm@1 509 GetDlgItem(IDC_ACCELEDIT_REPLACE)->EnableWindow(result);
rlm@1 510
rlm@1 511 return result;
rlm@1 512 }
rlm@1 513
rlm@1 514 void AccelEditor::OnTvnSelchangedCommands(NMHDR *pNMHDR, LRESULT *pResult)
rlm@1 515 {
rlm@1 516 // LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
rlm@1 517
rlm@1 518 // TODO: Add your control notification handler code here
rlm@1 519 // Check if some commands exist.
rlm@1 520 HTREEITEM hItem = m_commands.GetSelectedItem();
rlm@1 521 if (hItem == NULL)
rlm@1 522 return;
rlm@1 523
rlm@1 524 m_currents.DeleteAllItems();
rlm@1 525
rlm@1 526 WORD wIDCommand = LOWORD(m_commands.GetItemData(hItem));
rlm@1 527 CCmdAccelOb *pCmdAccel;
rlm@1 528 if (m_mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel))
rlm@1 529 {
rlm@1 530 CAccelsOb *pAccel;
rlm@1 531 CString szBuffer;
rlm@1 532 POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();
rlm@1 533
rlm@1 534 // Add the keys to the 'currents keys' listbox.
rlm@1 535 while (pos != NULL)
rlm@1 536 {
rlm@1 537 pAccel = pCmdAccel->m_Accels.GetNext(pos);
rlm@1 538 pAccel->GetString(szBuffer);
rlm@1 539 int index = m_currents.InsertItem(m_currents.GetItemCount(), szBuffer);
rlm@1 540 // and a pointer to the accel object.
rlm@1 541 m_currents.SetItemData(index, (DWORD)pAccel);
rlm@1 542 }
rlm@1 543
rlm@1 544 m_currents.SetItemState(0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
rlm@1 545 GetDlgItem(IDC_ASSIGN)->EnableWindow(TRUE);
rlm@1 546 m_currents.EnableWindow(TRUE);
rlm@1 547 }
rlm@1 548 else
rlm@1 549 {
rlm@1 550 GetDlgItem(IDC_ASSIGN)->EnableWindow(FALSE);
rlm@1 551 m_currents.EnableWindow(FALSE);
rlm@1 552 }
rlm@1 553
rlm@1 554 // Init the key editor
rlm@1 555 // m_pKey->ResetKey();
rlm@1 556 // m_alreadyAffected.SetWindowText("");
rlm@1 557
rlm@1 558 CheckListSelections();
rlm@1 559
rlm@1 560 *pResult = 0;
rlm@1 561 }
rlm@1 562
rlm@1 563 /*
rlm@1 564 void AccelEditor::OnListItemChanged(NMHDR *pNMHDR, LRESULT *pResult)
rlm@1 565 {
rlm@1 566 NMLISTVIEW *pNMListView = reinterpret_cast<NMLISTVIEW *>(pNMHDR);
rlm@1 567 if (pNMListView->uChanged == LVIF_STATE)
rlm@1 568 {
rlm@1 569 if ((pNMListView->uOldState & LVIS_SELECTED) && !(pNMListView->uNewState & LVIS_SELECTED))
rlm@1 570 {
rlm@1 571 }
rlm@1 572 }
rlm@1 573
rlm@1 574 *pResult = 0;
rlm@1 575 }
rlm@1 576 */
rlm@1 577
rlm@1 578 void AccelEditor::OnListClick(NMHDR *pNMHDR, LRESULT *pResult)
rlm@1 579 {
rlm@1 580 CheckListSelections();
rlm@1 581 *pResult = 0;
rlm@1 582 }
rlm@1 583
rlm@1 584 void AccelEditor::OnListDblClick(NMHDR *pNMHDR, LRESULT *pResult)
rlm@1 585 {
rlm@1 586 if (m_currents.GetFirstSelectedItemPosition())
rlm@1 587 OnEdit();
rlm@1 588 else
rlm@1 589 OnNew();
rlm@1 590 *pResult = 0;
rlm@1 591 }
rlm@1 592
rlm@1 593 void AccelEditor::OnKeyboardEditChange()
rlm@1 594 {
rlm@1 595 if (!m_key.IsDefined())
rlm@1 596 return;
rlm@1 597
rlm@1 598 // if (CheckJammed())
rlm@1 599 // return;
rlm@1 600
rlm@1 601 OnKeyboardEditKillfocus();
rlm@1 602 CheckAffected();
rlm@1 603 if (m_timeoutValue == 0)
rlm@1 604 return;
rlm@1 605
rlm@1 606 m_progress.SetRange32(0, m_timeoutValue);
rlm@1 607 SetTimer(1, 50, NULL);
rlm@1 608 }
rlm@1 609
rlm@1 610 void AccelEditor::OnKeyboardEditKillfocus()
rlm@1 611 {
rlm@1 612 KillTimer(1);
rlm@1 613 m_timer = 0;
rlm@1 614 m_progress.SetPos(0);
rlm@1 615 m_progress.SetBarColor(RGB(128, 0, 255));
rlm@1 616 }
rlm@1 617
rlm@1 618 void AccelEditor::OnTimeoutEditSetfocus()
rlm@1 619 {
rlm@1 620 m_timeout.PostMessage(EM_SETSEL, 0, -1);
rlm@1 621 }
rlm@1 622
rlm@1 623 void AccelEditor::OnTimeoutEditKillfocus()
rlm@1 624 {
rlm@1 625 CString str;
rlm@1 626 m_timeout.GetWindowText(str);
rlm@1 627 m_timeoutValue = atoi(str);
rlm@1 628 m_autoMode = AUTO_REPLACE;
rlm@1 629 }
rlm@1 630
rlm@1 631 void AccelEditor::OnTimer(UINT_PTR nIDEvent)
rlm@1 632 {
rlm@1 633 if (nIDEvent == 1)
rlm@1 634 {
rlm@1 635 m_timer += 50;
rlm@1 636 if (m_timer >= m_timeoutValue)
rlm@1 637 {
rlm@1 638 m_progress.SetPos(m_timeoutValue);
rlm@1 639 m_progress.SetBarColor(RGB(255, 255, 0));
rlm@1 640 if (m_autoMode == AUTO_NEW)
rlm@1 641 {
rlm@1 642 OnAssign();
rlm@1 643 }
rlm@1 644 else
rlm@1 645 {
rlm@1 646 OnReplace();
rlm@1 647 }
rlm@1 648 if (m_currents.IsWindowEnabled())
rlm@1 649 m_currents.SetFocus();
rlm@1 650 else
rlm@1 651 m_commands.SetFocus();
rlm@1 652 return;
rlm@1 653 }
rlm@1 654 UINT green = (m_timer * 255 / m_timeoutValue) ;
rlm@1 655 m_progress.SetBarColor(RGB(128 + green / 2, green, 255 - green));
rlm@1 656 m_progress.SetPos(m_timer);
rlm@1 657 }
rlm@1 658 }
rlm@1 659