pdcurses/pdcclip.c

Wed, 20 Jul 2016 12:55:39 +0300

author
Teemu Piippo <teemu@compsta2.com>
date
Wed, 20 Jul 2016 12:55:39 +0300
branch
protocol5
changeset 131
4996c8684b93
parent 97
2d43f05b284c
permissions
-rw-r--r--

Merged with default

97
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
1 /* Public Domain Curses */
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
2
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
3 #include "pdcwin.h"
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
4
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
5 RCSID("$Id: pdcclip.c,v 1.30 2008/07/14 04:24:52 wmcbrine Exp $")
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
6
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
7 /*man-start**************************************************************
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
8
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
9 Name: clipboard
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
10
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
11 Synopsis:
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
12 int PDC_getclipboard(char **contents, long *length);
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
13 int PDC_setclipboard(const char *contents, long length);
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
14 int PDC_freeclipboard(char *contents);
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
15 int PDC_clearclipboard(void);
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
16
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
17 Description:
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
18 PDC_getclipboard() gets the textual contents of the system's
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
19 clipboard. This function returns the contents of the clipboard
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
20 in the contents argument. It is the responsibilitiy of the
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
21 caller to free the memory returned, via PDC_freeclipboard().
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
22 The length of the clipboard contents is returned in the length
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
23 argument.
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
24
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
25 PDC_setclipboard copies the supplied text into the system's
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
26 clipboard, emptying the clipboard prior to the copy.
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
27
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
28 PDC_clearclipboard() clears the internal clipboard.
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
29
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
30 Return Values:
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
31 indicator of success/failure of call.
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
32 PDC_CLIP_SUCCESS the call was successful
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
33 PDC_CLIP_MEMORY_ERROR unable to allocate sufficient memory for
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
34 the clipboard contents
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
35 PDC_CLIP_EMPTY the clipboard contains no text
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
36 PDC_CLIP_ACCESS_ERROR no clipboard support
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
37
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
38 Portability X/Open BSD SYS V
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
39 PDC_getclipboard - - -
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
40 PDC_setclipboard - - -
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
41 PDC_freeclipboard - - -
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
42 PDC_clearclipboard - - -
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
43
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
44 **man-end****************************************************************/
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
45
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
46 #ifdef PDC_WIDE
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
47 # define PDC_TEXT CF_UNICODETEXT
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
48 #else
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
49 # define PDC_TEXT CF_OEMTEXT
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
50 #endif
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
51
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
52 int PDC_getclipboard(char **contents, long *length)
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
53 {
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
54 HANDLE handle;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
55 long len;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
56
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
57 PDC_LOG(("PDC_getclipboard() - called\n"));
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
58
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
59 if (!OpenClipboard(NULL))
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
60 return PDC_CLIP_ACCESS_ERROR;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
61
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
62 if ((handle = GetClipboardData(PDC_TEXT)) == NULL)
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
63 {
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
64 CloseClipboard();
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
65 return PDC_CLIP_EMPTY;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
66 }
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
67
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
68 #ifdef PDC_WIDE
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
69 len = wcslen((wchar_t *)handle) * 3;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
70 #else
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
71 len = strlen((char *)handle);
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
72 #endif
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
73 *contents = (char *)GlobalAlloc(GMEM_FIXED, len + 1);
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
74
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
75 if (!*contents)
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
76 {
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
77 CloseClipboard();
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
78 return PDC_CLIP_MEMORY_ERROR;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
79 }
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
80
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
81 #ifdef PDC_WIDE
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
82 len = PDC_wcstombs((char *)*contents, (wchar_t *)handle, len);
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
83 #else
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
84 strcpy((char *)*contents, (char *)handle);
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
85 #endif
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
86 *length = len;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
87 CloseClipboard();
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
88
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
89 return PDC_CLIP_SUCCESS;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
90 }
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
91
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
92 int PDC_setclipboard(const char *contents, long length)
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
93 {
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
94 HGLOBAL ptr1;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
95 LPTSTR ptr2;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
96
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
97 PDC_LOG(("PDC_setclipboard() - called\n"));
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
98
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
99 if (!OpenClipboard(NULL))
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
100 return PDC_CLIP_ACCESS_ERROR;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
101
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
102 ptr1 = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
103 (length + 1) * sizeof(TCHAR));
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
104
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
105 if (!ptr1)
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
106 return PDC_CLIP_MEMORY_ERROR;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
107
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
108 ptr2 = GlobalLock(ptr1);
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
109
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
110 #ifdef PDC_WIDE
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
111 PDC_mbstowcs((wchar_t *)ptr2, contents, length);
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
112 #else
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
113 memcpy((char *)ptr2, contents, length + 1);
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
114 #endif
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
115 GlobalUnlock(ptr1);
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
116 EmptyClipboard();
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
117
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
118 if (!SetClipboardData(PDC_TEXT, ptr1))
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
119 {
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
120 GlobalFree(ptr1);
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
121 return PDC_CLIP_ACCESS_ERROR;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
122 }
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
123
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
124 CloseClipboard();
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
125 GlobalFree(ptr1);
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
126
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
127 return PDC_CLIP_SUCCESS;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
128 }
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
129
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
130 int PDC_freeclipboard(char *contents)
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
131 {
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
132 PDC_LOG(("PDC_freeclipboard() - called\n"));
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
133
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
134 GlobalFree(contents);
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
135 return PDC_CLIP_SUCCESS;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
136 }
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
137
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
138 int PDC_clearclipboard(void)
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
139 {
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
140 PDC_LOG(("PDC_clearclipboard() - called\n"));
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
141
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
142 EmptyClipboard();
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
143
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
144 return PDC_CLIP_SUCCESS;
2d43f05b284c Added pdcurses source files, if no curses library is provided, these source files will be fallen back to instead of raising an error. Should make compiling on windows slightly less painful.
Teemu Piippo <tsapii@utu.fi>
parents:
diff changeset
145 }

mercurial