diff options
author | John Rennie <john.rennie@ratsauce.co.uk> | 2013-08-01 19:54:14 +0100 |
---|---|---|
committer | John Rennie <john.rennie@ratsauce.co.uk> | 2013-08-01 19:54:14 +0100 |
commit | 75f09c854872737fa832342078db7d11b44654a0 (patch) | |
tree | c8318322ec574b1ae427f7269cfdbbd3e32cc605 | |
parent | 1573c21f495e77bb18040f7e58dc469c75ec0c21 (diff) |
Add OnPasteClipboard method to CGUIDialogKeyboardGeneric
-rw-r--r-- | xbmc/dialogs/GUIDialogKeyboardGeneric.cpp | 46 | ||||
-rw-r--r-- | xbmc/dialogs/GUIDialogKeyboardGeneric.h | 1 |
2 files changed, 47 insertions, 0 deletions
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(); |