예제 #1
0
void AccelEditor::OnSelchangeCommands()
{
  // Check if some commands exist.
  int index = m_commands.GetCurSel();
  if (index == LB_ERR)
    return;

  WORD wIDCommand = LOWORD(m_commands.GetItemData(index));
  m_currents.ResetContent();

  CCmdAccelOb* pCmdAccel;

  if (mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel)) {
    CAccelsOb* pAccel;
    CString szBuffer;
    POSITION pos = pCmdAccel->m_Accels.GetHeadPosition();

    // Add the keys to the 'currents keys' listbox.
    while (pos != NULL) {
      pAccel = pCmdAccel->m_Accels.GetNext(pos);
      pAccel->GetString(szBuffer);
      index = m_currents.AddString(szBuffer);
      // and a pointer to the accel object.
      m_currents.SetItemData(index, (DWORD_PTR)pAccel);
    }
  }
  // Init the key editor
  //  m_pKey->ResetKey();

}
예제 #2
0
void AccelEditor::SelChangeCommands()
{
  HWND h = GetDlgItem(IDC_COMMANDS);
  // Check if some commands exist.
  int index = SendMessage(h, LB_GETCURSEL, 0, 0);
  if (index == LB_ERR)
    return;

  WORD wIDCommand = LOWORD(SendMessage(h, LB_GETITEMDATA, index, 0));
  h = GetDlgItem(IDC_CURRENTS);
  SendMessage(h, LB_RESETCONTENT, 0, 0);

  CCmdAccelOb* pCmdAccel;
  CMapWordToCCmdAccelOb::iterator it = mgr.m_mapAccelTable.find(wIDCommand);
  if (it != mgr.m_mapAccelTable.end()) {
    CAccelsOb* pAccel;
    CStdString szBuffer;
    pCmdAccel = it->second;
    it++;
    std::list<CAccelsOb*>::iterator i = pCmdAccel->m_Accels.begin();
    // Add the keys to the 'currents keys' listbox.
    while (i != pCmdAccel->m_Accels.end()) {
      pAccel = *i;
      i++;
      pAccel->GetString(szBuffer);
      index = SendMessage(h, LB_ADDSTRING, 0, (LPARAM)((LPCSTR)szBuffer));
      // and a pointer to the accel object.
      SendMessage(h, LB_SETITEMDATA, index, (LPARAM)pAccel);
    }
  }
  // Init the key editor
//  m_pKey->ResetKey();

}
예제 #3
0
void AccelEditor::OnAssign()
{
	if (CheckAffected())
		return;

	// get the currently selected group
	HTREEITEM hItem = m_commands.GetSelectedItem();
	if (hItem == NULL)
		return;  // abort

	// Get the object who manage the accels list, associated to the command.
	WORD wIDCommand = LOWORD(m_commands.GetItemData(hItem));

	CCmdAccelOb *pCmdAccel;
	if (m_mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) != TRUE)
		return;

	WORD wKey;
	bool bCtrl, bAlt, bShift;
	if (!m_key.GetAccelKey(wKey, bCtrl, bAlt, bShift))
		return;  // no valid key, abort

	BYTE cVirt = 0;
	if (bCtrl)
		cVirt |= FCONTROL;
	if (bAlt)
		cVirt |= FALT;
	if (bShift)
		cVirt |= FSHIFT;

	cVirt |= FVIRTKEY;

	// Create the new key...
	CAccelsOb *pAccel = new CAccelsOb(cVirt, wKey, false);
	ASSERT(pAccel != NULL);
	// ...and add in the list.
	pCmdAccel->m_Accels.AddTail(pAccel);

	// Update the listbox.
	CString szBuffer;
	pAccel->GetString(szBuffer);

	int index = m_currents.GetNextItem(-1, LVNI_SELECTED);
	if (index < 0)
		index = 0;
	m_currents.InsertItem(index, szBuffer);
	m_currents.SetItemData(index, reinterpret_cast<DWORD>(pAccel));
	m_currents.SetItemState(-1, 0, LVIS_SELECTED);	// deselect other items first
	m_currents.SetItemState(index, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
	GetDlgItem(IDC_REMOVE)->EnableWindow(TRUE);
	GetDlgItem(IDC_ACCELEDIT_REPLACE)->EnableWindow(TRUE);

	// Reset the key editor.
//	m_key.ResetKey();

	m_modified = TRUE;
	GetDlgItem(IDC_ACCELEDIT_APPLY)->EnableWindow(TRUE);
}
void CAcceleratorManager::UpdateMenu(HMENU menu)
{
  int count = GetMenuItemCount(menu);

  MENUITEMINFO info;
  wchar_t ss[128];
  ZeroMemory(&info, sizeof(info));
  info.cbSize = sizeof(info);
  info.fMask = MIIM_ID | MIIM_SUBMENU;
  for(int i = 0; i < count; i++) {
    GetMenuItemInfo(menu, i, TRUE, &info);

    if(info.hSubMenu != NULL) {
      UpdateMenu(info.hSubMenu);
    } else {
      if(info.wID != -1) {
        MENUITEMINFOW info2;
        ZeroMemory(&info2, sizeof(info2));
        info2.cbSize = sizeof(info2);
        info2.fMask = MIIM_STRING;
        info2.dwTypeData = ss;
        info2.cch = 128;
        GetMenuItemInfoW(menu, i, MF_BYPOSITION, &info2);
        CStdStringW str = ss;
        int index = str.Find('\t');
        if(index != -1)
          str = str.Left(index);

        CMapWordToCCmdAccelOb::iterator it = m_mapAccelTable.find(info.wID);

        if(it != m_mapAccelTable.end()) {
          CCmdAccelOb *o = it->second;
          if(o->m_Accels.begin() != o->m_Accels.end()) {
            std::list<CAccelsOb*>::iterator j = o->m_Accels.begin();

            CAccelsOb *accel = *j;

            CStdString s;
            accel->GetString(s);
            str += "\t";
            str += s;
          }
        }
        if(str != ss)
          ModifyMenuW(menu, i, MF_BYPOSITION | MF_STRING, info.wID, str);
      }
    }
  }
}
예제 #5
0
void AccelEditor::OnTvnSelchangedCommands(NMHDR *pNMHDR, LRESULT *pResult)
{
//	LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);

	// TODO: Add your control notification handler code here
	// Check if some commands exist.
	HTREEITEM hItem = m_commands.GetSelectedItem();
	if (hItem == NULL)
		return;

	m_currents.DeleteAllItems();

	WORD wIDCommand = LOWORD(m_commands.GetItemData(hItem));
	CCmdAccelOb *pCmdAccel;
	if (m_mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel))
	{
		CAccelsOb *pAccel;
		CString	   szBuffer;
		POSITION   pos = pCmdAccel->m_Accels.GetHeadPosition();

		// Add the keys to the 'currents keys' listbox.
		while (pos != NULL)
		{
			pAccel = pCmdAccel->m_Accels.GetNext(pos);
			pAccel->GetString(szBuffer);
			int index = m_currents.InsertItem(m_currents.GetItemCount(), szBuffer);
			// and a pointer to the accel object.
			m_currents.SetItemData(index, (DWORD)pAccel);
		}

		m_currents.SetItemState(0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
		GetDlgItem(IDC_ASSIGN)->EnableWindow(TRUE);
		m_currents.EnableWindow(TRUE);
	}
	else
	{
		GetDlgItem(IDC_ASSIGN)->EnableWindow(FALSE);
		m_currents.EnableWindow(FALSE);
	}

	// Init the key editor
//  m_pKey->ResetKey();
//	m_alreadyAffected.SetWindowText("");

	CheckListSelections();

	*pResult = 0;
}
void CAcceleratorManager::UpdateMenu(HMENU menu)
{
	int count = GetMenuItemCount(menu);

	OSVERSIONINFO info = {0};
	info.dwOSVersionInfoSize = sizeof(info);
	GetVersionEx(&info);

	if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
	{
		MENUITEMINFO info = {0};
		info.cbSize = sizeof(info) - sizeof(HBITMAP);
		info.fMask  = MIIM_ID | MIIM_SUBMENU;
		for (int i = 0; i < count; i++)
		{
			GetMenuItemInfo(menu, i, TRUE, &info);

			if (info.hSubMenu != NULL)
			{
				UpdateMenu(info.hSubMenu);
			}
			else
			{
				if (info.wID != (UINT)-1)
				{
					char         ss[128];
					MENUITEMINFO info2 = {0};
					info2.cbSize     = sizeof(info2) - sizeof(HBITMAP);	// FIXME: why?
					info2.fMask      = MIIM_STRING;
					info2.dwTypeData = ss;
					info2.cch        = 128;
					GetMenuItemInfo(menu, i, MF_BYPOSITION, &info2);

					CString str(ss);
					int     index = str.Find('\t');
					if (index != -1)
						str = str.Left(index);

					WORD command = info.wID;

					CCmdAccelOb *o;
					if (m_mapAccelTable.Lookup(command, o))
					{
						if (o->m_Accels.GetCount())
						{
							POSITION   pos   = o->m_Accels.GetHeadPosition();
							CAccelsOb *accel = o->m_Accels.GetNext(pos);

							CString s;
							accel->GetString(s);
							str += "\t";
							str += s;
						}
					}
					if (str != ss)
						ModifyMenu(menu, i, MF_BYPOSITION | MF_STRING, info.wID, str);
				}
			}
		}
	}
	else
	{
		MENUITEMINFO info = {0};
		info.cbSize = sizeof(info);
		info.fMask  = MIIM_ID | MIIM_SUBMENU;
		for (int i = 0; i < count; i++)
		{
			GetMenuItemInfo(menu, i, TRUE, &info);

			if (info.hSubMenu != NULL)
			{
				UpdateMenu(info.hSubMenu);
			}
			else
			{
				if (info.wID != (WORD)-1)
				{
					wchar_t ss[128];
					wchar_t str[512];
					MENUITEMINFOW info2 = {0};
					info2.cbSize     = sizeof(info2);
					info2.fMask      = MIIM_STRING;
					info2.dwTypeData = ss;
					info2.cch        = 128;
					GetMenuItemInfoW(menu, i, MF_BYPOSITION, &info2);

					wcscpy(str, ss);

					wchar_t *p = wcschr(str, '\t');
					if (p)
						*p = 0;

					CCmdAccelOb *o;
					WORD         command = info.wID;
					if (m_mapAccelTable.Lookup(command, o))
					{
						if (o->m_Accels.GetCount())
						{
							POSITION pos = o->m_Accels.GetHeadPosition();

							CAccelsOb *accel = o->m_Accels.GetNext(pos);

							CString s;
							accel->GetString(s);

							wchar_t temp[128];
							temp[0] = '\t';
							temp[1] = 0;
							wcscat(str, temp);
							p = temp;
							for (const char *sp = s; *sp; sp++)
								*p++ = *sp;
							*p = 0;
							wcscat(str, temp);
						}
					}
					if (wcscmp(str, ss))
						ModifyMenuW(menu, i, MF_BYPOSITION | MF_STRING, info.wID, str);
				}
			}
		}
	}
}
예제 #7
0
void AccelEditor::OnAssign()
{
  // Control if it's not already affected
  CCmdAccelOb* pCmdAccel;
  CAccelsOb* pAccel;
  WORD wIDCommand;
  POSITION pos;

  WORD wKey;
  bool bCtrl, bAlt, bShift;

  if (!m_key.GetAccelKey(wKey, bCtrl, bAlt, bShift))
    return; // no valid key, abort

  int count = m_commands.GetCount();
  int index;
  for (index = 0; index < count; index++) {

    wIDCommand = LOWORD(m_commands.GetItemData(index));
    mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel);

    pos = pCmdAccel->m_Accels.GetHeadPosition();
    while (pos != NULL) {
      pAccel = pCmdAccel->m_Accels.GetNext(pos);
      if (pAccel->IsEqual(wKey, bCtrl, bAlt, bShift)) {
        // the key is already affected (in the same or other command)
        m_alreadyAffected.SetWindowText(pCmdAccel->m_szCommand);
        m_key.SetSel(0, -1);
        return; // abort
      }
    }
  }

  // OK, we can add the accel key in the currently selected group
  index = m_commands.GetCurSel();
  if (index == LB_ERR)
    return;

  // Get the object who manage the accels list, associated to the command.
  wIDCommand = LOWORD(m_commands.GetItemData(index));

  if (mgr.m_mapAccelTable.Lookup(wIDCommand, pCmdAccel) != TRUE)
    return;

  BYTE cVirt = 0;
  if (bCtrl)
    cVirt |= FCONTROL;
  if (bAlt)
    cVirt |= FALT;
  if (bShift)
    cVirt |= FSHIFT;

  cVirt |= FVIRTKEY;

  // Create the new key...
  pAccel = new CAccelsOb(cVirt, wKey, false);
  ASSERT(pAccel != NULL);
  // ...and add in the list.
  pCmdAccel->m_Accels.AddTail(pAccel);

  // Update the listbox.
  CString szBuffer;
  pAccel->GetString(szBuffer);

  index = m_currents.AddString(szBuffer);
  m_currents.SetItemData(index, (DWORD_PTR)pAccel);

  // Reset the key editor.
  m_key.ResetKey();
}
예제 #8
0
void AccelEditor::Assign()
{
  // Control if it's not already affected
  CCmdAccelOb* pCmdAccel;
  CAccelsOb* pAccel;
  WORD wIDCommand;
  
  WORD wKey;
  bool bCtrl, bAlt, bShift;

  if (!m_Key.GetAccelKey(wKey, bCtrl, bAlt, bShift))
    return; // no valid key, abort

  HWND h = GetDlgItem(IDC_COMMANDS);

  int count = ::SendMessage(h, LB_GETCOUNT, 0, 0);
  for (int index = 0; index < count; index++) {

    wIDCommand = LOWORD(::SendMessage(h, LB_GETITEMDATA, index, 0));
    CMapWordToCCmdAccelOb::iterator it = mgr.m_mapAccelTable.find(wIDCommand);
    ASSERT(it != mgr.m_mapAccelTable.end());

    pCmdAccel = it->second;

    std::list<CAccelsOb*>::iterator it2 = pCmdAccel->m_Accels.begin();
    while (it2 != pCmdAccel->m_Accels.end()) {
      pAccel = *it2;
      it2++;
      if (pAccel->IsEqual(wKey, bCtrl, bAlt, bShift)) {
        // the key is already affected (in the same or other command)
        ::SetWindowText(GetDlgItem(IDC_ALREADY_AFFECTED), pCmdAccel->m_szCommand);
        ::SendMessage(m_Key, EM_SETSEL, 0, -1);
        return; // abort
      }
    }
  }

  // OK, we can add the accel key in the currently selected group
  index = ::SendMessage(h, LB_GETCURSEL, 0, 0);
  if (index == LB_ERR)
    return;

  // Get the object who manage the accels list, associated to the command.
  wIDCommand = LOWORD(::SendMessage(h, LB_GETITEMDATA, index, 0));

  CMapWordToCCmdAccelOb::iterator it = mgr.m_mapAccelTable.find(wIDCommand);

  if (it == mgr.m_mapAccelTable.end())
    return;

  pCmdAccel = it->second;
  
  BYTE cVirt = 0;
  if (bCtrl)
    cVirt |= FCONTROL;
  if (bAlt)
    cVirt |= FALT;
  if (bShift)
    cVirt |= FSHIFT;

  cVirt |= FVIRTKEY;

  // Create the new key...
  pAccel = new CAccelsOb(cVirt, wKey, false);
  ASSERT(pAccel != NULL);
  // ...and add in the list.
  pCmdAccel->m_Accels.push_back(pAccel);

  // Update the listbox.
  CStdString szBuffer;
  pAccel->GetString(szBuffer);
  h = GetDlgItem(IDC_CURRENTS);

  index = ::SendMessage(h, LB_ADDSTRING, 0, (LPARAM)((LPCSTR)szBuffer));
  ::SendMessage(h, LB_SETITEMDATA, index, (LPARAM)pAccel);

  // Reset the key editor.
  m_Key.ResetKey();

}