aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRadAd <adamgates84+github@gmail.com>2019-05-24 16:57:43 +1000
committerRadAd <adamgates84+github@gmail.com>2019-05-24 16:57:43 +1000
commit2386836e0a162b2dd09f03df7f3f863a2795544d (patch)
tree041ca845d7d56638c5aa72e113dee8400cdb8684
parentad69d865e54ea07ce8c1a4e6b8edf437785236e9 (diff)
downloadRadTerminal-2386836e0a162b2dd09f03df7f3f863a2795544d.tar.gz
RadTerminal-2386836e0a162b2dd09f03df7f3f863a2795544d.zip
Implement paste from clipboard
-rw-r--r--RadTerminal.cpp50
1 files changed, 41 insertions, 9 deletions
diff --git a/RadTerminal.cpp b/RadTerminal.cpp
index 07e29f6..54d1a0f 100644
--- a/RadTerminal.cpp
+++ b/RadTerminal.cpp
@@ -387,9 +387,12 @@ int ActionCopyToClipboard(HWND hWnd)
}
}
- *lastnonnull = '\0';
- int cut = (int) ((buf + len) - lastnonnull);
- len -= cut;
+ if (lastnonnull != nullptr)
+ {
+ *lastnonnull = '\0';
+ int cut = (int) ((buf + len) - lastnonnull);
+ len -= cut;
+ }
}
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len + 1);
@@ -422,6 +425,33 @@ int ActionClearSelection(HWND hWnd)
return len;
}
+int ActionPasteFromClipboard(HWND hWnd)
+{
+ const RadTerminalData* const data = (RadTerminalData*) GetWindowLongPtr(hWnd, GWLP_USERDATA);
+ if (IsClipboardFormatAvailable(CF_TEXT))
+ {
+ while (!OpenClipboard(hWnd))
+ ;
+ HANDLE hData = GetClipboardData(CF_TEXT);
+ if (hData != NULL)
+ {
+ LPCSTR lptstr = (LPCSTR) GlobalLock(hData);
+ while (*lptstr != '\0')
+ {
+ uint32_t keysym = XKB_KEY_NoSymbol;
+ uint32_t ascii = *lptstr;
+ uint32_t unicode = ascii;
+ unsigned int mods = 0; // TODO Should capital letters be faked with a Shift?
+ tsm_vte_handle_keyboard(data->vte, keysym, ascii, mods, unicode);
+ ++lptstr;
+ }
+ GlobalUnlock(hData);
+ }
+ CHECK_ONLY(CloseClipboard());
+ }
+ return 0;
+}
+
BOOL RadTerminalWindowOnCreate(HWND hWnd, LPCREATESTRUCT lpCreateStruct)
{
const RadTerminalCreate* const rtc = (RadTerminalCreate*) lpCreateStruct->lpCreateParams;
@@ -536,6 +566,7 @@ void RadTerminalWindowOnKeyDown(HWND hWnd, UINT vk, BOOL fDown, int cRepeat, UIN
{
case VK_ESCAPE: bPassOn = ActionClearSelection(hWnd) < 0; break;
case VK_RETURN: bPassOn = ActionCopyToClipboard(hWnd) < 0; break;
+ case 'V': if (KeyState[VK_CONTROL] & 0x80) bPassOn = ActionPasteFromClipboard(hWnd) < 0; break;
}
if (bPassOn)
@@ -545,15 +576,15 @@ void RadTerminalWindowOnKeyDown(HWND hWnd, UINT vk, BOOL fDown, int cRepeat, UIN
uint32_t unicode = ascii;
unsigned int mods = 0;
- if (KeyState[VK_SHIFT] & 0x8)
+ if (KeyState[VK_SHIFT] & 0x80)
mods |= TSM_SHIFT_MASK;
- if (KeyState[VK_SCROLL] & 0x8)
+ if (KeyState[VK_SCROLL] & 0x80)
mods |= TSM_LOCK_MASK;
- if (KeyState[VK_CONTROL] & 0x8)
+ if (KeyState[VK_CONTROL] & 0x80)
mods |= TSM_CONTROL_MASK;
- if (KeyState[VK_MENU] & 0x8)
+ if (KeyState[VK_MENU] & 0x80)
mods |= TSM_ALT_MASK;
- if (KeyState[VK_LWIN] & 0x8)
+ if (KeyState[VK_LWIN] & 0x80)
mods |= TSM_LOGO_MASK;
UINT scan = (cRepeat >> 8);
@@ -760,7 +791,8 @@ void RadTerminalWindowOnLButtonUp(HWND hWnd, int x, int y, UINT keyFlags)
void RadTerminalWindowOnRButtonDown(HWND hWnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
{
- ActionCopyToClipboard(hWnd);
+ if (ActionCopyToClipboard(hWnd) < 0)
+ ActionPasteFromClipboard(hWnd);
}
void RadTerminalWindowOnTimer(HWND hWnd, UINT id)