Add remaining files
[juce-lv2.git] / juce / source / src / native / windows / juce_win32_Misc.cpp
blob0358337832a30399206d6abaae77e492b2d906c3
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 // (This file gets included by juce_win32_NativeCode.cpp, rather than being
27 // compiled on its own).
28 #if JUCE_INCLUDED_FILE
31 //==============================================================================
32 void SystemClipboard::copyTextToClipboard (const String& text)
34 if (OpenClipboard (0) != 0)
36 if (EmptyClipboard() != 0)
38 const int bytesNeeded = CharPointer_UTF16::getBytesRequiredFor (text.getCharPointer()) + 4;
40 if (bytesNeeded > 0)
42 HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT, bytesNeeded + sizeof (WCHAR));
44 if (bufH != 0)
46 WCHAR* const data = static_cast <WCHAR*> (GlobalLock (bufH));
47 text.copyToUTF16 (data, bytesNeeded);
48 GlobalUnlock (bufH);
50 SetClipboardData (CF_UNICODETEXT, bufH);
55 CloseClipboard();
59 String SystemClipboard::getTextFromClipboard()
61 String result;
63 if (OpenClipboard (0) != 0)
65 HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
67 if (bufH != 0)
69 const WCHAR* const data = (const WCHAR*) GlobalLock (bufH);
71 if (data != nullptr)
73 result = String (data, (int) (GlobalSize (bufH) / sizeof (WCHAR)));
75 GlobalUnlock (bufH);
79 CloseClipboard();
82 return result;
86 #endif