From 75f09c854872737fa832342078db7d11b44654a0 Mon Sep 17 00:00:00 2001 From: John Rennie Date: Thu, 1 Aug 2013 19:54:14 +0100 Subject: Add OnPasteClipboard method to CGUIDialogKeyboardGeneric --- xbmc/dialogs/GUIDialogKeyboardGeneric.cpp | 46 +++++++++++++++++++++++++++++++ xbmc/dialogs/GUIDialogKeyboardGeneric.h | 1 + 2 files changed, 47 insertions(+) diff --git a/xbmc/dialogs/GUIDialogKeyboardGeneric.cpp b/xbmc/dialogs/GUIDialogKeyboardGeneric.cpp index e8749b79f4..ed3b47a24b 100644 --- a/xbmc/dialogs/GUIDialogKeyboardGeneric.cpp +++ b/xbmc/dialogs/GUIDialogKeyboardGeneric.cpp @@ -145,6 +145,10 @@ bool CGUIDialogKeyboardGeneric::OnAction(const CAction &action) { OnRemoteNumberClick(action.GetID()); } + else if (action.GetID() == ACTION_PASTE) + { + OnPasteClipboard(); + } else if (action.GetID() >= KEY_VKEY && action.GetID() < KEY_ASCII) { // input from the keyboard (vkey, not ascii) if (!m_strEditing.IsEmpty()) @@ -740,3 +744,45 @@ bool CGUIDialogKeyboardGeneric::ShowAndGetInput(char_callback_t pCallback, const } else return false; } + +void CGUIDialogKeyboardGeneric::OnPasteClipboard(void) +{ + CStdStringW pasted_text; + +// Get text from the clipboard +#if defined(TARGET_DARWIN_OSX) +// NB - not tested on OSX yet. I'll uncomment this when I've tested it. +// const char *szStr = Cocoa_Paste(); +// if (szStr) +// pasted_text = szStr; +#elif defined TARGET_WINDOWS + if (OpenClipboard(NULL)) + { + HGLOBAL hglb = GetClipboardData(CF_UNICODETEXT); + if (hglb != NULL) + { + LPWSTR lpwstr = (LPWSTR) GlobalLock(hglb); + if (lpwstr != NULL) + { + pasted_text = lpwstr; + GlobalUnlock(hglb); + } + } + CloseClipboard(); + } +#endif + + // Insert the pasted text at the current cursor position. + if (pasted_text.length() > 0) + { + int i = GetCursorPos(); + CStdStringW left_end = m_strEdit.Left(i); + CStdStringW right_end = m_strEdit.Right(m_strEdit.length() - i); + + m_strEdit = left_end; + m_strEdit.append(pasted_text); + m_strEdit.append(right_end); + UpdateLabel(); + MoveCursor(pasted_text.length()); + } +} diff --git a/xbmc/dialogs/GUIDialogKeyboardGeneric.h b/xbmc/dialogs/GUIDialogKeyboardGeneric.h index ebe0f3993f..47df71fa05 100644 --- a/xbmc/dialogs/GUIDialogKeyboardGeneric.h +++ b/xbmc/dialogs/GUIDialogKeyboardGeneric.h @@ -46,6 +46,7 @@ class CGUIDialogKeyboardGeneric : public CGUIDialog, public CGUIKeyboard bool IsConfirmed() { return m_bIsConfirmed; }; void SetHiddenInput(bool hiddenInput) { m_hiddenInput = hiddenInput; }; void Character(WCHAR wch); + void OnPasteClipboard(void); protected: virtual void OnInitWindow(); -- cgit v1.2.3