|
| 1 | +/*********************************************************************** |
| 2 | +** |
| 3 | +** REBOL [R3] Language Interpreter and Run-time Environment |
| 4 | +** |
| 5 | +** Copyright 2012 REBOL Technologies |
| 6 | +** REBOL is a trademark of REBOL Technologies |
| 7 | +** |
| 8 | +** Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | +** you may not use this file except in compliance with the License. |
| 10 | +** You may obtain a copy of the License at |
| 11 | +** |
| 12 | +** http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | +** |
| 14 | +** Unless required by applicable law or agreed to in writing, software |
| 15 | +** distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | +** See the License for the specific language governing permissions and |
| 18 | +** limitations under the License. |
| 19 | +** |
| 20 | +************************************************************************ |
| 21 | +** |
| 22 | +** Title: Device: Clipboard access for Win32 |
| 23 | +** Author: Carl Sassenrath, Oldes |
| 24 | +** Purpose: |
| 25 | +** Provides a very simple interface to the clipboard for text. |
| 26 | +** May be expanded in the future for images, etc. |
| 27 | +** |
| 28 | +************************************************************************ |
| 29 | +** |
| 30 | +** NOTE to PROGRAMMERS: |
| 31 | +** |
| 32 | +** 1. Keep code clear and simple. |
| 33 | +** 2. Document unusual code, reasoning, or gotchas. |
| 34 | +** 3. Use same style for code, vars, indent(4), comments, etc. |
| 35 | +** 4. Keep in mind Linux, OS X, BSD, big/little endian CPUs. |
| 36 | +** 5. Test everything, then test it again. |
| 37 | +** |
| 38 | +***********************************************************************/ |
| 39 | + |
| 40 | +#include <stdio.h> |
| 41 | + |
| 42 | +#include "sys-net.h" |
| 43 | +#include "reb-host.h" |
| 44 | +#include "host-lib.h" |
| 45 | + |
| 46 | + |
| 47 | +REBOOL GetClipboardStringData(REBREQ *req); |
| 48 | +REBOOL SetClipboardStringData(REBREQ *req); |
| 49 | + |
| 50 | +/*********************************************************************** |
| 51 | +** |
| 52 | +*/ DEVICE_CMD Open_Clipboard(REBREQ *req) |
| 53 | +/* |
| 54 | +***********************************************************************/ |
| 55 | +{ |
| 56 | + SET_OPEN(req); |
| 57 | + return DR_DONE; |
| 58 | +} |
| 59 | + |
| 60 | +/*********************************************************************** |
| 61 | +** |
| 62 | +*/ DEVICE_CMD Close_Clipboard(REBREQ *req) |
| 63 | +/* |
| 64 | +***********************************************************************/ |
| 65 | +{ |
| 66 | + SET_CLOSED(req); |
| 67 | + return DR_DONE; |
| 68 | +} |
| 69 | + |
| 70 | + |
| 71 | +/*********************************************************************** |
| 72 | +** |
| 73 | +*/ DEVICE_CMD Read_Clipboard(REBREQ *req) |
| 74 | +/* |
| 75 | +***********************************************************************/ |
| 76 | +{ |
| 77 | + req->actual = 0; |
| 78 | + |
| 79 | + if(!GetClipboardStringData(req)){ |
| 80 | + req->error = 20; |
| 81 | + // just a random number... would be better to have some system for it |
| 82 | + return DR_ERROR; |
| 83 | + } |
| 84 | + |
| 85 | + return DR_DONE; |
| 86 | +} |
| 87 | + |
| 88 | + |
| 89 | +/*********************************************************************** |
| 90 | +** |
| 91 | +*/ DEVICE_CMD Write_Clipboard(REBREQ *req) |
| 92 | +/* |
| 93 | +** Expects data in UTF8 encoding in req->data! |
| 94 | +** |
| 95 | +***********************************************************************/ |
| 96 | +{ |
| 97 | + if(!SetClipboardStringData(req)) { |
| 98 | + req->error = 20; |
| 99 | + // just a random number... would be better to have some system for it |
| 100 | + return DR_ERROR; |
| 101 | + } |
| 102 | + return DR_DONE; |
| 103 | +} |
| 104 | + |
| 105 | + |
| 106 | +/*********************************************************************** |
| 107 | +** |
| 108 | +*/ DEVICE_CMD Poll_Clipboard(REBREQ *req) |
| 109 | +/* |
| 110 | +***********************************************************************/ |
| 111 | +{ |
| 112 | + return DR_DONE; |
| 113 | +} |
| 114 | + |
| 115 | + |
| 116 | +/*********************************************************************** |
| 117 | +** |
| 118 | +** Command Dispatch Table (RDC_ enum order) |
| 119 | +** |
| 120 | +***********************************************************************/ |
| 121 | + |
| 122 | +static DEVICE_CMD_FUNC Dev_Cmds[RDC_MAX] = |
| 123 | +{ |
| 124 | + 0, |
| 125 | + 0, |
| 126 | + Open_Clipboard, |
| 127 | + Close_Clipboard, |
| 128 | + Read_Clipboard, |
| 129 | + Write_Clipboard, |
| 130 | + Poll_Clipboard, |
| 131 | +}; |
| 132 | + |
| 133 | +DEFINE_DEV(Dev_Clipboard, "Clipboard", 1, Dev_Cmds, RDC_MAX, 0); |
0 commit comments