Skip to content
This repository
Browse code

Merge pull request #3034 from jhsrennie/win_paste

Move paste code to g_Windowing
  • Loading branch information...
commit 8bc7c1a9019f24d98db23413d41311878e2c911e 2 parents df91888 + 30f8944
John Rennie authored August 02, 2013
21  xbmc/dialogs/GUIDialogKeyboardGeneric.cpp
@@ -753,26 +753,7 @@ void CGUIDialogKeyboardGeneric::OnPasteClipboard(void)
753 753
   CStdStringW pasted_text;
754 754
 
755 755
 // Get text from the clipboard
756  
-#if defined(TARGET_DARWIN_OSX)
757  
-  const char *szStr = Cocoa_Paste();
758  
-  if (szStr)
759  
-    pasted_text = szStr;
760  
-#elif defined TARGET_WINDOWS
761  
-  if (OpenClipboard(NULL))
762  
-  {
763  
-    HGLOBAL hglb = GetClipboardData(CF_UNICODETEXT);
764  
-    if (hglb != NULL)
765  
-    {
766  
-      LPWSTR lpwstr = (LPWSTR) GlobalLock(hglb);
767  
-      if (lpwstr != NULL)
768  
-      {
769  
-        pasted_text = lpwstr;
770  
-        GlobalUnlock(hglb);
771  
-      }
772  
-    }
773  
-    CloseClipboard();
774  
-  }
775  
-#endif
  756
+  pasted_text = g_Windowing.GetClipboard();
776 757
 
777 758
   // Insert the pasted text at the current cursor position.
778 759
   if (pasted_text.length() > 0)
37  xbmc/guilib/GUIEditControl.cpp
@@ -27,6 +27,7 @@
27 27
 #include "Key.h"
28 28
 #include "LocalizeStrings.h"
29 29
 #include "XBDateTime.h"
  30
+#include "windowing/WindowingFactory.h"
30 31
 #include "utils/md5.h"
31 32
 
32 33
 #if defined(TARGET_DARWIN)
@@ -577,29 +578,21 @@ void CGUIEditControl::OnSMSCharacter(unsigned int key)
577 578
 
578 579
 void CGUIEditControl::OnPasteClipboard()
579 580
 {
580  
-#if defined(TARGET_DARWIN_OSX)
581  
-  const char *szStr = Cocoa_Paste();
582  
-  if (szStr)
583  
-  {
584  
-    m_text2 += szStr;
585  
-    m_cursorPos+=strlen(szStr);
586  
-    UpdateText();
587  
-  }
588  
-#elif defined TARGET_WINDOWS
589  
-  if (OpenClipboard(g_hWnd))
  581
+  CStdStringW pasted_text;
  582
+
  583
+// Get text from the clipboard
  584
+  pasted_text = g_Windowing.GetClipboard();
  585
+
  586
+  // Insert the pasted text at the current cursor position.
  587
+  if (pasted_text.length() > 0)
590 588
   {
591  
-    HGLOBAL hglb = GetClipboardData(CF_TEXT);
592  
-    if (hglb != NULL)
593  
-    {
594  
-      LPTSTR lptstr = (LPTSTR)GlobalLock(hglb);
595  
-      if (lptstr != NULL)
596  
-      {
597  
-        m_text2 = (char*)lptstr;
598  
-        GlobalUnlock(hglb);
599  
-      }
600  
-    }
601  
-    CloseClipboard();
  589
+    CStdStringW left_end = m_text2.Left(m_cursorPos);
  590
+    CStdStringW right_end = m_text2.Right(m_text2.length() - m_cursorPos);
  591
+
  592
+    m_text2 = left_end;
  593
+    m_text2.append(pasted_text);
  594
+    m_text2.append(right_end);
  595
+    m_cursorPos += pasted_text.length();
602 596
     UpdateText();
603 597
   }
604  
-#endif
605 598
 }
5  xbmc/windowing/WinSystem.cpp
@@ -235,3 +235,8 @@ bool CWinSystemBase::UseLimitedColor()
235 235
   return false;
236 236
 #endif
237 237
 }
  238
+
  239
+CStdStringW CWinSystemBase::GetClipboard(void)
  240
+{
  241
+  return "";
  242
+}
2  xbmc/windowing/WinSystem.h
@@ -108,6 +108,8 @@ class CWinSystemBase
108 108
   virtual void EnableTextInput(bool bEnable) {}
109 109
   virtual bool IsTextInputEnabled() { return false; }
110 110
 
  111
+  CStdStringW GetClipboard(void);
  112
+
111 113
 protected:
112 114
   void UpdateDesktopResolution(RESOLUTION_INFO& newRes, int screen, int width, int height, float refreshRate, uint32_t dwFlags = 0);
113 115
 
2  xbmc/windowing/osx/WinSystemOSX.h
@@ -69,6 +69,8 @@ class CWinSystemOSX : public CWinSystemBase
69 69
   
70 70
   void* GetCGLContextObj();
71 71
 
  72
+  CStdStringW GetClipboard(void);
  73
+
72 74
 protected:
73 75
   void* CreateWindowedContext(void* shareCtx);
74 76
   void* CreateFullScreenContext(int screen_index, void* shareCtx);
11  xbmc/windowing/osx/WinSystemOSX.mm
@@ -1626,4 +1626,15 @@ static void DisplayReconfigured(CGDirectDisplayID display,
1626 1626
   return [(NSOpenGLContext*)m_glContext CGLContextObj];
1627 1627
 }
1628 1628
 
  1629
+CStdStringW CWinSystemOSX::GetClipboard(void)
  1630
+{
  1631
+  CStdStringW pasted_text;
  1632
+
  1633
+  const char *szStr = Cocoa_Paste();
  1634
+  if (szStr)
  1635
+    pasted_text = szStr;
  1636
+
  1637
+  return pasted_text;
  1638
+}
  1639
+
1629 1640
 #endif
22  xbmc/windowing/windows/WinSystemWin32DX.cpp
@@ -98,4 +98,26 @@ bool CWinSystemWin32DX::SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, boo
98 98
   return true;
99 99
 }
100 100
 
  101
+CStdStringW CWinSystemWin32DX::GetClipboard(void)
  102
+{
  103
+  CStdStringW pasted_text;
  104
+
  105
+  if (OpenClipboard(NULL))
  106
+  {
  107
+    HGLOBAL hglb = GetClipboardData(CF_UNICODETEXT);
  108
+    if (hglb != NULL)
  109
+    {
  110
+      LPWSTR lpwstr = (LPWSTR) GlobalLock(hglb);
  111
+      if (lpwstr != NULL)
  112
+      {
  113
+        pasted_text = lpwstr;
  114
+        GlobalUnlock(hglb);
  115
+      }
  116
+    }
  117
+    CloseClipboard();
  118
+  }
  119
+
  120
+  return pasted_text;
  121
+}
  122
+
101 123
 #endif
2  xbmc/windowing/windows/WinSystemWin32DX.h
@@ -45,6 +45,8 @@ class CWinSystemWin32DX : public CWinSystemWin32, public CRenderSystemDX
45 45
   virtual bool SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays);
46 46
   virtual bool WindowedMode() { return CRenderSystemDX::m_useWindowedDX; }
47 47
 
  48
+  CStdStringW GetClipboard(void);
  49
+
48 50
 protected:
49 51
   virtual void UpdateMonitor();
50 52
   bool UseWindowedDX(bool fullScreen);

0 notes on commit 8bc7c1a

Please sign in to comment.
Something went wrong with that request. Please try again.