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;
42 HGLOBAL bufH
= GlobalAlloc (GMEM_MOVEABLE
| GMEM_DDESHARE
| GMEM_ZEROINIT
, bytesNeeded
+ sizeof (WCHAR
));
46 WCHAR
* const data
= static_cast <WCHAR
*> (GlobalLock (bufH
));
47 text
.copyToUTF16 (data
, bytesNeeded
);
50 SetClipboardData (CF_UNICODETEXT
, bufH
);
59 String
SystemClipboard::getTextFromClipboard()
63 if (OpenClipboard (0) != 0)
65 HANDLE bufH
= GetClipboardData (CF_UNICODETEXT
);
69 const WCHAR
* const data
= (const WCHAR
*) GlobalLock (bufH
);
73 result
= String (data
, (int) (GlobalSize (bufH
) / sizeof (WCHAR
)));