Browse Source

Changed shortcut processing class to handle duplicates

Scott Brogden 9 years ago
parent
commit
8e20f74deb
5 changed files with 66 additions and 54 deletions
  1. 43 44
      Accels.cpp
  2. 10 5
      Accels.h
  3. 1 1
      CP_Main.rc
  4. 11 4
      QuickPasteKeyboard.cpp
  5. 1 0
      QuickPasteKeyboard.h

+ 43 - 44
Accels.cpp

@@ -6,67 +6,50 @@ CAccels::CAccels()
 {
 	m_handleRepeatKeys = false;
 	m_firstMapTick = 0;
+	m_activeFirstKey = 0;
 }
 
 void CAccels::AddAccel(CAccel a)
 {
-    m_Map.SetAt(a.Key, a);
+	m_multiMap.insert(pair<DWORD, CAccel>(a.Key, a));
 }
 
 void CAccels::AddAccel(DWORD cmd, DWORD key, DWORD key2)
 {
-	CAccel a(key, cmd);
-	
-	if((int)key2 > 0)
-	{
-		a.SecondKey = true;
-		m_Map2.SetAt(key2, a);
-	}
+	CAccel a(key, cmd, key2);
 
-	m_Map.SetAt(key, a);
+	m_multiMap.insert(pair<DWORD, CAccel>(key, a));
 }
 
 void CAccels::RemoveAll()
 {
-	m_Map.RemoveAll();
-	m_Map2.RemoveAll();
+	m_multiMap.clear();
 }
 
 CString CAccels::GetCmdKeyText(DWORD cmd)
 {
-	CString cmdShortcutText = _T("");
-	POSITION pos = m_Map.GetStartPosition();
-	DWORD mapShortcut;
-	CAccel a;
-	while (pos != NULL)
+	CString cmdShortcutText;
+	for (multimap<DWORD, CAccel>::iterator it = m_multiMap.begin(); it != m_multiMap.end(); ++it)
 	{
-		m_Map.GetNextAssoc(pos, mapShortcut, a);
-
-		if(a.Cmd == cmd)
+		if (it->second.Cmd == cmd)
 		{
-			CString cmdShortcutText2;
-			CAccel a2;
-			DWORD mapShortcut2;
-			POSITION pos2 = m_Map2.GetStartPosition();
-			while (pos2 != NULL)
+			if (it->second.Key != 0)
 			{
-				m_Map2.GetNextAssoc(pos2, mapShortcut2, a2);
-				if(a2.Cmd == cmd)
+				cmdShortcutText = CHotKey::GetHotKeyDisplayStatic(it->second.Key);
+				if (it->second.Key2 != 0)
 				{
-					cmdShortcutText2 = CHotKey::GetHotKeyDisplayStatic(mapShortcut2);
-				}
-			}
+					CString cmdShortcutText2 = CHotKey::GetHotKeyDisplayStatic(it->second.Key);
 
-			cmdShortcutText = CHotKey::GetHotKeyDisplayStatic(mapShortcut);
-
-			if(cmdShortcutText2.GetLength() > 0)
-			{
-				cmdShortcutText += _T(" - ");
-				cmdShortcutText += cmdShortcutText2;
+					if (cmdShortcutText2.GetLength() > 0)
+					{
+						cmdShortcutText += _T(" - ");
+						cmdShortcutText += cmdShortcutText2;
+					}
+				}
 			}
 			break;
 		}
-	}
+	}	
 
 	return cmdShortcutText;
 }
@@ -87,7 +70,7 @@ bool CAccels::OnMsg(MSG *pMsg, CAccel &a)
 
 	m_handleRepeatKeys = false;
 
-    if(!pMsg || m_Map.GetCount() <= 0)
+    if(!pMsg)
     {
         return NULL;
     }
@@ -99,28 +82,44 @@ bool CAccels::OnMsg(MSG *pMsg, CAccel &a)
     CString cs;
     cs.Format(_T("Key: %d, Mod: %d, vkey: %d"), key, mod, vkey);
     OutputDebugString(cs);
-
+		
 	if (m_firstMapTick != 0 &&
 		(GetTickCount() - m_firstMapTick) < 500)
 	{
-		if (m_Map2.Lookup(key, a))
+		pair<multimap<DWORD, CAccel>::iterator, multimap<DWORD, CAccel>::iterator> ppp;
+		ppp = m_multiMap.equal_range(m_activeFirstKey);
+
+		for (multimap<DWORD, CAccel>::iterator it2 = ppp.first; it2 != ppp.second; ++it2)
 		{
-			m_firstMapTick = 0;
-			return true;
+			if (vkey == it2->second.Key2)
+			{
+				a = (*it2).second;
+				m_firstMapTick = 0;
+				m_activeFirstKey = 0;
+				return true;
+			}
 		}
 	}
 	else
 	{
-		if (m_Map.Lookup(key, a))
+		m_firstMapTick = 0;
+		m_activeFirstKey = 0;
+
+		pair<multimap<DWORD, CAccel>::iterator, multimap<DWORD, CAccel>::iterator> ppp;
+		ppp = m_multiMap.equal_range(vkey);
+
+		for (multimap<DWORD, CAccel>::iterator it2 = ppp.first; it2 != ppp.second; ++it2)
 		{
-			if (a.SecondKey == false)
+			if (it2->second.Key2 == 0)
 			{
-				m_firstMapTick = 0;
+				a = (*it2).second;
 				return true;
 			}
 			else
 			{
+				m_activeFirstKey = vkey;
 				m_firstMapTick = GetTickCount();
+				break;
 			}
 		}
 	}

+ 10 - 5
Accels.h

@@ -1,23 +1,27 @@
 #pragma once
 
+#include <map>
+
 #define ACCEL_VKEY(key)			LOBYTE(key)
 #define ACCEL_MOD(key)			HIBYTE(key)
 #define ACCEL_MAKEKEY(vkey,mod) ((mod << 8) | vkey)
 
+using namespace std;
+
 class CAccel
 {
 public:
     DWORD Key;
+	DWORD Key2;
     DWORD Cmd;
 	int RefId;
-	bool SecondKey;
 
-    CAccel(DWORD key = 0, DWORD cmd = 0)
+    CAccel(DWORD key = 0, DWORD cmd = 0, DWORD key2 = 0)
     {
         Key = key;
+		Key2 = key2;
         Cmd = cmd;
 		RefId = 0;
-		SecondKey = false;
     }
 };
 
@@ -47,8 +51,9 @@ public:
     static BYTE GetKeyStateModifiers();
 
 protected:
-	CMap < DWORD, DWORD, CAccel, CAccel > m_Map;
-	CMap < DWORD, DWORD, CAccel, CAccel > m_Map2;
+
+	multimap<DWORD, CAccel> m_multiMap;
+	DWORD m_activeFirstKey;
 
 	DWORD m_firstMapTick;
 };

+ 1 - 1
CP_Main.rc

@@ -897,7 +897,7 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSM
 CAPTION " "
 FONT 8, "MS Shell Dlg", 400, 0, 0x1
 BEGIN
-    CONTROL         "",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,7,23,361,144
+    CONTROL         "",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,7,21,361,146
     CONTROL         "",IDC_HOTKEY1,"msctls_hotkey32",WS_BORDER | WS_TABSTOP,25,225,80,14
     PUSHBUTTON      "Assign",IDC_ASSIGN,318,266,50,14
     CONTROL         "",IDC_HOTKEY2,"msctls_hotkey32",WS_BORDER | WS_TABSTOP,195,225,80,14

+ 11 - 4
QuickPasteKeyboard.cpp

@@ -151,6 +151,8 @@ void CQuickPasteKeyboard::LoadItems()
 			row++;
 		}
 	}
+
+	SelectedRow(0);
 }
 
 CString CQuickPasteKeyboard::GetShortCutText(KeyboardAB ab)
@@ -754,10 +756,15 @@ void CQuickPasteKeyboard::OnBnClickedButtonReset()
 		m_list.SetItem(&lvi);
 	}
 
-	m_list.SetItemState(0, LVIS_FOCUSED, LVIS_FOCUSED);
-	m_list.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
-	m_list.SetSelectionMark(0);
-	m_list.EnsureVisible(0, FALSE);
+	SelectedRow(0);	
+}
+
+void CQuickPasteKeyboard::SelectedRow(int row)
+{
+	m_list.SetItemState(row, LVIS_FOCUSED, LVIS_FOCUSED);
+	m_list.SetItemState(row, LVIS_SELECTED, LVIS_SELECTED);
+	m_list.SetSelectionMark(row);
+	m_list.EnsureVisible(row, FALSE);
 }
 
 

+ 1 - 0
QuickPasteKeyboard.h

@@ -60,6 +60,7 @@ protected:
 	int SelectedCommandShortCutId();
 	int SelectedCommandRow();
 	void SelectMouseTypeCombo(CComboBox &combo, int value);
+	void SelectedRow(int row);
 
 public:
 	afx_msg void OnLvnItemActivateList1(NMHDR *pNMHDR, LRESULT *pResult);