Ejemplo n.º 1
0
void
ClipboardToSelection(HWND hWnd,LPEDIT lp)
{
	HGLOBAL hCbData;
	LPSTR 	lpCbData;

	if (!OpenClipboard(hWnd))
		return;

	if ((hCbData = GetClipboardData(CF_TEXT)) == (HGLOBAL)0)
	{
		CloseClipboard();
		return;
	}

	if ((lpCbData = (LPSTR)GlobalLock(hCbData)) == NULL)
	{
		CloseClipboard();
		return;
	}
						
	InsertChars(lp, lpCbData, lstrlen(lpCbData), TRUE);

	CloseClipboard();
}
Ejemplo n.º 2
0
bool CUIEdit::HandleKeypress(SDL_Event *event) {
	bool Handled = false;

	if (event->type == SDL_KEYDOWN) {
		switch (event->key.keysym.sym) {
		case SDLK_ESCAPE:
		case SDLK_TAB:
		case SDLK_RETURN:
			return false;

			// ctrl+A
		case SDLK_a:
			if (CBKeyboardState::IsControlDown()) {
				m_SelStart = 0;
				m_SelEnd = strlen(m_Text);
				Handled = true;
			}
			break;

		case SDLK_BACKSPACE:
			if (m_SelStart == m_SelEnd) {
				if (Game->m_TextRTL) DeleteChars(m_SelStart, m_SelStart + 1);
				else DeleteChars(m_SelStart - 1, m_SelStart);
			} else DeleteChars(m_SelStart, m_SelEnd);
			if (m_SelEnd >= m_SelStart) m_SelEnd -= std::max(1, m_SelEnd - m_SelStart);
			m_SelStart = m_SelEnd;

			Handled = true;
			break;

		case SDLK_LEFT:
		case SDLK_UP:
			m_SelEnd--;
			if (!CBKeyboardState::IsShiftDown()) m_SelStart = m_SelEnd;
			Handled = true;
			break;

		case SDLK_RIGHT:
		case SDLK_DOWN:
			m_SelEnd++;
			if (!CBKeyboardState::IsShiftDown()) m_SelStart = m_SelEnd;
			Handled = true;
			break;

		case SDLK_HOME:
			if (Game->m_TextRTL) {
				m_SelEnd = strlen(m_Text);
				if (!CBKeyboardState::IsShiftDown()) m_SelStart = m_SelEnd;
			} else {
				m_SelEnd = 0;
				if (!CBKeyboardState::IsShiftDown()) m_SelStart = m_SelEnd;
			}
			Handled = true;
			break;

		case SDLK_END:
			if (Game->m_TextRTL) {
				m_SelEnd = 0;
				if (!CBKeyboardState::IsShiftDown()) m_SelStart = m_SelEnd;
			} else {
				m_SelEnd = strlen(m_Text);
				if (!CBKeyboardState::IsShiftDown()) m_SelStart = m_SelEnd;
			}
			Handled = true;
			break;

		case SDLK_DELETE:
			if (m_SelStart == m_SelEnd) {
				if (Game->m_TextRTL) {
					DeleteChars(m_SelStart - 1, m_SelStart);
					m_SelEnd--;
					if (m_SelEnd < 0) m_SelEnd = 0;
				} else DeleteChars(m_SelStart, m_SelStart + 1);
			} else DeleteChars(m_SelStart, m_SelEnd);
			if (m_SelEnd > m_SelStart) m_SelEnd -= (m_SelEnd - m_SelStart);

			m_SelStart = m_SelEnd;
			Handled = true;
			break;
		}
		return Handled;
	}

	else if (event->type == SDL_TEXTINPUT) {
		if (m_SelStart != m_SelEnd) DeleteChars(m_SelStart, m_SelEnd);

		WideString wstr = StringUtil::Utf8ToWide(event->text.text);
		m_SelEnd += InsertChars(m_SelEnd, (byte  *)StringUtil::WideToAnsi(wstr).c_str(), 1);

		if (Game->m_TextRTL) m_SelEnd = m_SelStart;
		else m_SelStart = m_SelEnd;

		return true;
	}

	return false;
}