Esempio n. 1
0
void CHexEdit::OnEditClear() 
{
	m_currentAddress = m_selStart;
	SelDelete(m_selStart, m_selEnd);
	RepositionCaret(m_currentAddress);
	RedrawWindow();
}
Esempio n. 2
0
void CHexEdit::OnEditCut() 
{
	OnEditCopy();
	SelDelete(m_selStart, m_selEnd);
	m_selStart=m_selEnd=m_currentAddress;
	Invalidate(FALSE);
}
Esempio n. 3
0
void CHexEdit::OnEditPaste() 
{
	COleDataObject	obj;	
	if (obj.AttachClipboard()) 
	{
		HGLOBAL hmem = NULL;
		if (obj.IsDataAvailable(RegisterClipboardFormat("BinaryData"))) 
		{
			hmem = obj.GetGlobalData(RegisterClipboardFormat("BinaryData"));
		}	
		else if (obj.IsDataAvailable(CF_TEXT)) 
		{
			hmem = obj.GetGlobalData(CF_TEXT);
		}
		if(hmem)
		{
			LPBYTE	p = (BYTE*)::GlobalLock(hmem);
			DWORD	dwSizeMem=::GlobalSize(hmem);
			DWORD	dwSizeSel=GetSelLength();
			DWORD	dwLen =dwSizeMem>dwSizeSel?dwSizeSel:dwSizeMem;
			int		insert;
			
			NormalizeSel();
			if(m_selStart == 0xffffffff)
			{
				if(m_currentMode == EDIT_LOW)
					m_currentAddress++;
				insert = m_currentAddress;
				SelInsert(m_currentAddress, dwLen);
			}
			else
			{
				insert = m_selStart;
				SelDelete(m_selStart,m_selStart+dwLen-1);
				SelInsert(insert, dwLen);
			}
			memcpy(m_pData+insert, p, dwLen);
			
			m_currentAddress = insert+dwLen;
//			RepositionCaret(m_currentAddress);
			ResetPos();
			Invalidate(FALSE);
			::GlobalUnlock(hmem);
		}
	}
}
Esempio n. 4
0
void CHexEdit::OnEditPaste() 
{
	COleDataObject	obj;	
	if (obj.AttachClipboard()) 
	{
		HGLOBAL hmem = NULL;
		if (obj.IsDataAvailable(RegisterClipboardFormat(L"BinaryData"))) 
		{
			hmem = obj.GetGlobalData(RegisterClipboardFormat(L"BinaryData"));
		}	
		else if (obj.IsDataAvailable(CF_TEXT)) 
		{
			hmem = obj.GetGlobalData(CF_TEXT);
		}
		if(hmem)
		{
			LPBYTE	p = (BYTE*)::GlobalLock(hmem);
			DWORD	dwLen = ::GlobalSize(hmem);
			int		insert;
			int		oa = m_currentAddress;
			
			NormalizeSel();
			if(m_selStart == 0xffffffff)
			{
				if(m_currentMode == EDIT_LOW)
					m_currentAddress++;
				insert = m_currentAddress;
				SelInsert(m_currentAddress, dwLen);
			}
			else
			{
				insert = m_selStart;
				SelDelete(m_selStart, m_selEnd);
				SelInsert(insert, dwLen);
				SetSel(-1, -1);
			}

			memcpy(m_pData+insert, p, dwLen);

			m_currentAddress = oa;
			RedrawWindow();
			::GlobalUnlock(hmem);
		}
	}
}
Esempio n. 5
0
void CHexEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	nFlags;	nRepCnt;

	BOOL bShift = GetKeyState(VK_SHIFT) & 0x80000000;
	BOOL bac = m_bNoAddressChange;
	m_bNoAddressChange = TRUE;
	switch(nChar)
	{
		case VK_DOWN:
			if(bShift)
			{
				if(!IsSelected())
				{
					m_selStart = m_currentAddress;
				}
				Move(0,1);
				m_selEnd   = m_currentAddress;
				if(m_currentMode == EDIT_HIGH || m_currentMode == EDIT_LOW)
					m_selEnd++;
				RedrawWindow();
				break;
			}
			else
				SetSel(-1, -1);
			Move(0,1);
			break;
		case VK_UP:
			if(bShift)
			{
				if(!IsSelected())
				{
					m_selStart = m_currentAddress;
				}
				Move(0,-1);
				m_selEnd   = m_currentAddress;
				RedrawWindow();
				break;
			}
			else
				SetSel(-1, -1);
			Move(0,-1);
			break;
		case VK_LEFT:
			if(bShift)
			{
				if(!IsSelected())
				{
					m_selStart = m_currentAddress;
				}
				Move(-1,0);
				m_selEnd   = m_currentAddress;
				RedrawWindow();
				break;
			}
			else
				SetSel(-1, -1);
			Move(-1,0);
			break;
		case VK_RIGHT:
			if(bShift)
			{
				if(!IsSelected())
				{
					m_selStart = m_currentAddress;
				}
				Move(1,0);
				m_selEnd   = m_currentAddress;
				if(m_currentMode == EDIT_HIGH || m_currentMode == EDIT_LOW)
					m_selEnd++;
				RedrawWindow();
				break;
			}
			else
				SetSel(-1, -1);
			Move(1,0);
			break;
		case VK_PRIOR:
			if(bShift)
			{
				if(!IsSelected())
				{
					m_selStart = m_currentAddress;
				}
				OnVScroll(SB_PAGEUP, 0, NULL);
				Move(0,0);
				m_selEnd   = m_currentAddress;
				RedrawWindow();
				break;
			}
			else
				SetSel(-1, -1);
			OnVScroll(SB_PAGEUP, 0, NULL);
			Move(0,0);
			break;
		case VK_NEXT:
			if(bShift)
			{
				if(!IsSelected())
				{
					m_selStart = m_currentAddress;
				}
				OnVScroll(SB_PAGEDOWN, 0, NULL);
				Move(0,0);
				m_selEnd   = m_currentAddress;
				RedrawWindow();
				break;
			}
			else
				SetSel(-1, -1);
			OnVScroll(SB_PAGEDOWN, 0, NULL);
			Move(0,0);
			break;
		case VK_HOME:
			if(bShift)
			{
				if(!IsSelected())
				{
					m_selStart = m_currentAddress;
				}
				if(GetKeyState(VK_CONTROL) & 0x80000000)
				{
					OnVScroll(SB_THUMBTRACK, 0, NULL);
					Move(0,0);
				}
				else
				{
					m_currentAddress /= m_bpr;
					m_currentAddress *= m_bpr;
					Move(0,0);
				}
				m_selEnd   = m_currentAddress;
				RedrawWindow();
				break;
			}
			else
				SetSel(-1, -1);
			if(GetKeyState(VK_CONTROL) & 0x80000000)
			{
				OnVScroll(SB_THUMBTRACK, 0, NULL);
				m_currentAddress = 0;
				Move(0,0);
			}
			else
			{
				m_currentAddress /= m_bpr;
				m_currentAddress *= m_bpr;
				Move(0,0);
			}
			break;
		case VK_END:
			if(bShift)
			{
				if(!IsSelected())
				{
					m_selStart = m_currentAddress;
				}
				if(GetKeyState(VK_CONTROL) & 0x80000000)
				{
					m_currentAddress = m_length-1;
					OnVScroll(SB_THUMBTRACK, ((m_length+(m_bpr/2)) / m_bpr) - m_lpp, NULL);
					Move(0,0);
				}
				else
				{
					m_currentAddress /= m_bpr;
					m_currentAddress *= m_bpr;
					m_currentAddress += m_bpr - 1;
					if(m_currentAddress > m_length)
						m_currentAddress = m_length-1;
					Move(0,0);
				}
				m_selEnd   = m_currentAddress;
				RedrawWindow();
				break;
			}
			else
				SetSel(-1, -1);
			if(GetKeyState(VK_CONTROL) & 0x80000000)
			{
				m_currentAddress = m_length-1;
				if(m_bHalfPage)
					OnVScroll(SB_THUMBTRACK, 0, NULL);
				else
					OnVScroll(SB_THUMBTRACK, ((m_length+(m_bpr/2)) / m_bpr) - m_lpp, NULL);
				Move(0,0);
			}
			else
			{
				m_currentAddress /= m_bpr;
				m_currentAddress *= m_bpr;
				m_currentAddress += m_bpr - 1;
				if(m_currentAddress > m_length)
					m_currentAddress = m_length-1;
				Move(0,0);
			}
			break;
		case VK_INSERT:
			SelInsert(m_currentAddress, max(1, m_selEnd-m_selStart));
			RedrawWindow();
			break;
		case VK_DELETE:
			if(IsSelected())
			{
				OnEditClear();
			}
			else
			{
				SelDelete(m_currentAddress, m_currentAddress+1);
				RedrawWindow();
			}
			break;
		case '\t':
			switch(m_currentMode)
			{
				case EDIT_NONE:
					m_currentMode = EDIT_HIGH;
					break;
				case EDIT_HIGH:
				case EDIT_LOW:
					m_currentMode = EDIT_ASCII;
					break;
				case EDIT_ASCII:
					m_currentMode = EDIT_HIGH;
					break;
			}
			Move(0,0);
			break;

	}
	m_bNoAddressChange = bac;
}
Esempio n. 6
0
void CHexEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	nFlags;nRepCnt;
	if(!m_pData)
		return;
	if(nChar == '\t')
		return;
	if(GetKeyState(VK_CONTROL) & 0x80000000)
	{
		switch(nChar)
		{
			case 0x03:
				if(IsSelected())
					OnEditCopy();
				return;
			case 0x16:
				OnEditPaste();
				return;
			case 0x18:
				if(IsSelected())
					OnEditCut();
				return;
			case 0x1a:
				OnEditUndo();
				return;
		}
	}

	if(nChar == 0x08)
	{
		if(m_currentAddress > 0)
		{
			m_currentAddress--;
			SelDelete(m_currentAddress, m_currentAddress+1);
			RepositionCaret(m_currentAddress);
			RedrawWindow();
		}
		return;
	}

	SetSel(-1, -1);
	switch(m_currentMode)
	{
		case EDIT_NONE:
			return;
		case EDIT_HIGH:
		case EDIT_LOW:
			if((nChar >= '0' && nChar <= '9') || (nChar >= 'a' && nChar <= 'f'))
			{
				UINT b = nChar - '0';
				if(b > 9) 
					b = 10 + nChar - 'a';

				if(m_currentMode == EDIT_HIGH)
				{
					m_pData[m_currentAddress] = (unsigned char)((m_pData[m_currentAddress] & 0x0f) | (b << 4));
				}
				else
				{
					m_pData[m_currentAddress] = (unsigned char)((m_pData[m_currentAddress] & 0xf0) | b);
				}
				Move(1,0);
			}
			break;
		case EDIT_ASCII:
			m_pData[m_currentAddress] = (unsigned char)nChar;
			Move(1,0);
			break;
	}
	RedrawWindow();
}
Esempio n. 7
0
void CHexEdit::OnEditCut() 
{
	OnEditCopy();
	SelDelete(m_selStart, m_selEnd);
	RedrawWindow();
}
Esempio n. 8
0
void CHexEdit::OnEditClear() 
{
	SelDelete(m_selStart, m_selEnd);
}