comparison dynamin/gui/windows_clipboard.d @ 0:aa4efef0f0b1

Initial commit of code.
author Jordan Miner <jminer7@gmail.com>
date Mon, 15 Jun 2009 22:10:48 -0500
parents
children 73060bc3f004
comparison
equal deleted inserted replaced
-1:000000000000 0:aa4efef0f0b1
1 // Written in the D programming language
2 // www.digitalmars.com/d/
3
4 /*
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Dynamin library.
16 *
17 * The Initial Developer of the Original Code is Jordan Miner.
18 * Portions created by the Initial Developer are Copyright (C) 2006-2009
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 * Jordan Miner <jminer7@gmail.com>
23 *
24 */
25
26 module dynamin.gui.windows_clipboard;
27
28 import dynamin.c.windows;
29 import Utf = tango.text.convert.Utf;
30
31 template ClipboardBackend() {
32 void backend_setText(string text) {
33 if(!OpenClipboard(msgWnd))
34 return;
35 EmptyClipboard();
36 auto wtext = Utf.toString16(text);
37 HGLOBAL hmem = GlobalAlloc(GMEM_MOVEABLE, (wtext.length+1)*wchar.sizeof);
38 wchar* data = cast(wchar*)GlobalLock(hmem);
39 data[0..wtext.length] = wtext;
40 data[wtext.length] = 0;
41 GlobalUnlock(hmem);
42 SetClipboardData(CF_UNICODETEXT, data);
43 CloseClipboard();
44 }
45 string backend_getText() {
46 if(!OpenClipboard(msgWnd))
47 return null;
48 wchar* data = cast(wchar*)GetClipboardData(CF_UNICODETEXT);
49 CloseClipboard();
50 if(data is null)
51 return null;
52 int i = 0;
53 while(data[i] != '\0')
54 ++i;
55 if(i == 0)
56 return null;
57 return Utf.toString(data[0..i]);
58 }
59 bool backend_containsText() {
60 return IsClipboardFormatAvailable(CF_UNICODETEXT) ? true : false;
61 }
62 }
63
64 // Windows only has one clipboard
65 template SelectionBackend() {
66 void backend_setText(string text) {
67 }
68 string backend_getText() {
69 return null;
70 }
71 bool backend_containsText() {
72 return false;
73 }
74 }
75