Mercurial > projects > dynamin
annotate dynamin/gui/windows_clipboard.d @ 106:acdbb30fee7e
Port to D2.
Most of the effort was dealing with immutable and const.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Mon, 17 Dec 2012 23:41:50 -0600 |
parents | 73060bc3f004 |
children |
rev | line source |
---|---|
0 | 1 |
2 /* | |
103
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
3 * Copyright Jordan Miner |
0 | 4 * |
103
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
5 * This Source Code Form is subject to the terms of the Mozilla Public |
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
6 * License, v. 2.0. If a copy of the MPL was not distributed with this |
73060bc3f004
Change license to Boost 1.0 and MPL 2.0.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
0 | 8 * |
9 */ | |
10 | |
11 module dynamin.gui.windows_clipboard; | |
12 | |
13 import dynamin.c.windows; | |
14 import Utf = tango.text.convert.Utf; | |
15 | |
16 template ClipboardBackend() { | |
106 | 17 void backend_setText(cstring text) { |
0 | 18 if(!OpenClipboard(msgWnd)) |
19 return; | |
20 EmptyClipboard(); | |
21 auto wtext = Utf.toString16(text); | |
22 HGLOBAL hmem = GlobalAlloc(GMEM_MOVEABLE, (wtext.length+1)*wchar.sizeof); | |
23 wchar* data = cast(wchar*)GlobalLock(hmem); | |
24 data[0..wtext.length] = wtext; | |
25 data[wtext.length] = 0; | |
26 GlobalUnlock(hmem); | |
27 SetClipboardData(CF_UNICODETEXT, data); | |
28 CloseClipboard(); | |
29 } | |
106 | 30 mstring backend_getText() { |
0 | 31 if(!OpenClipboard(msgWnd)) |
32 return null; | |
33 wchar* data = cast(wchar*)GetClipboardData(CF_UNICODETEXT); | |
34 CloseClipboard(); | |
35 if(data is null) | |
36 return null; | |
37 int i = 0; | |
38 while(data[i] != '\0') | |
39 ++i; | |
40 if(i == 0) | |
41 return null; | |
42 return Utf.toString(data[0..i]); | |
43 } | |
44 bool backend_containsText() { | |
45 return IsClipboardFormatAvailable(CF_UNICODETEXT) ? true : false; | |
46 } | |
47 } | |
48 | |
49 // Windows only has one clipboard | |
50 template SelectionBackend() { | |
106 | 51 void backend_setText(cstring text) { |
0 | 52 } |
106 | 53 mstring backend_getText() { |
0 | 54 return null; |
55 } | |
56 bool backend_containsText() { | |
57 return false; | |
58 } | |
59 } | |
60 |