| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#include "bltInt.h" |
| 26 |
|
| 27 |
#ifndef NO_CUTBUFFER |
| 28 |
|
| 29 |
#ifndef WIN32 |
| 30 |
#include <X11/Xproto.h> |
| 31 |
#endif |
| 32 |
|
| 33 |
static int |
| 34 |
GetCutNumber(interp, string, bufferPtr) |
| 35 |
Tcl_Interp *interp; |
| 36 |
char *string; |
| 37 |
int *bufferPtr; |
| 38 |
{ |
| 39 |
int number; |
| 40 |
|
| 41 |
if (Tcl_GetInt(interp, string, &number) != TCL_OK) { |
| 42 |
return TCL_ERROR; |
| 43 |
} |
| 44 |
if ((number < 0) || (number > 7)) { |
| 45 |
Tcl_AppendResult(interp, "bad buffer # \"", string, "\"", (char *)NULL); |
| 46 |
return TCL_ERROR; |
| 47 |
} |
| 48 |
*bufferPtr = number; |
| 49 |
return TCL_OK; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
static int |
| 54 |
RotateErrorProc(clientData, errEventPtr) |
| 55 |
ClientData clientData; |
| 56 |
XErrorEvent *errEventPtr; |
| 57 |
{ |
| 58 |
int *errorPtr = clientData; |
| 59 |
|
| 60 |
*errorPtr = TCL_ERROR; |
| 61 |
return 0; |
| 62 |
} |
| 63 |
|
| 64 |
static int |
| 65 |
GetOp(interp, tkwin, argc, argv) |
| 66 |
Tcl_Interp *interp; |
| 67 |
Tk_Window tkwin; |
| 68 |
int argc; |
| 69 |
char **argv; |
| 70 |
{ |
| 71 |
char *string; |
| 72 |
int buffer; |
| 73 |
int nBytes; |
| 74 |
|
| 75 |
buffer = 0; |
| 76 |
if (argc == 3) { |
| 77 |
if (GetCutNumber(interp, argv[2], &buffer) != TCL_OK) { |
| 78 |
return TCL_ERROR; |
| 79 |
} |
| 80 |
} |
| 81 |
string = XFetchBuffer(Tk_Display(tkwin), &nBytes, buffer); |
| 82 |
if (string != NULL) { |
| 83 |
int limit; |
| 84 |
register char *p; |
| 85 |
register int i; |
| 86 |
int c; |
| 87 |
|
| 88 |
if (string[nBytes - 1] == '\0') { |
| 89 |
limit = nBytes - 1; |
| 90 |
} else { |
| 91 |
limit = nBytes; |
| 92 |
} |
| 93 |
for (p = string, i = 0; i < limit; i++, p++) { |
| 94 |
c = (unsigned char)*p; |
| 95 |
if (c == 0) { |
| 96 |
*p = ' '; |
| 97 |
} |
| 98 |
} |
| 99 |
if (limit == nBytes) { |
| 100 |
char *newPtr; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
newPtr = Blt_Malloc(nBytes + 1); |
| 107 |
assert(newPtr); |
| 108 |
memcpy(newPtr, string, nBytes); |
| 109 |
newPtr[nBytes] = '\0'; |
| 110 |
Blt_Free(string); |
| 111 |
string = newPtr; |
| 112 |
} |
| 113 |
Tcl_SetResult(interp, string, TCL_DYNAMIC); |
| 114 |
} |
| 115 |
return TCL_OK; |
| 116 |
} |
| 117 |
|
| 118 |
static int |
| 119 |
RotateOp(interp, tkwin, argc, argv) |
| 120 |
Tcl_Interp *interp; |
| 121 |
Tk_Window tkwin; |
| 122 |
int argc; |
| 123 |
char **argv; |
| 124 |
{ |
| 125 |
int count; |
| 126 |
int result; |
| 127 |
Tk_ErrorHandler handler; |
| 128 |
|
| 129 |
count = 1; |
| 130 |
if (argc == 3) { |
| 131 |
if (Tcl_GetInt(interp, argv[2], &count) != TCL_OK) { |
| 132 |
return TCL_ERROR; |
| 133 |
} |
| 134 |
if ((count < 0) || (count > 8)) { |
| 135 |
Tcl_AppendResult(interp, "bad rotate count \"", argv[2], "\"", |
| 136 |
(char *)NULL); |
| 137 |
return TCL_ERROR; |
| 138 |
} |
| 139 |
} |
| 140 |
result = TCL_OK; |
| 141 |
handler = Tk_CreateErrorHandler(Tk_Display(tkwin), BadMatch, |
| 142 |
X_RotateProperties, -1, RotateErrorProc, &result); |
| 143 |
XRotateBuffers(Tk_Display(tkwin), count); |
| 144 |
Tk_DeleteErrorHandler(handler); |
| 145 |
XSync(Tk_Display(tkwin), False); |
| 146 |
if (result != TCL_OK) { |
| 147 |
Tcl_AppendResult(interp, "can't rotate cutbuffers unless all are set", |
| 148 |
(char *)NULL); |
| 149 |
return TCL_ERROR; |
| 150 |
} |
| 151 |
return TCL_OK; |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
static int |
| 156 |
SetOp(interp, tkwin, argc, argv) |
| 157 |
Tcl_Interp *interp; |
| 158 |
Tk_Window tkwin; |
| 159 |
int argc; |
| 160 |
char **argv; |
| 161 |
{ |
| 162 |
int buffer; |
| 163 |
|
| 164 |
buffer = 0; |
| 165 |
if (argc == 4) { |
| 166 |
if (GetCutNumber(interp, argv[3], &buffer) != TCL_OK) { |
| 167 |
return TCL_ERROR; |
| 168 |
} |
| 169 |
} |
| 170 |
XStoreBuffer(Tk_Display(tkwin), argv[2], strlen(argv[2]) + 1, buffer); |
| 171 |
return TCL_OK; |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
static Blt_OpSpec cbOps[] = |
| 190 |
{ |
| 191 |
{"get", 1, (Blt_Op)GetOp, 2, 3, "?buffer?",}, |
| 192 |
{"rotate", 1, (Blt_Op)RotateOp, 2, 3, "?count?",}, |
| 193 |
{"set", 1, (Blt_Op)SetOp, 3, 4, "value ?buffer?",}, |
| 194 |
}; |
| 195 |
static int numCbOps = sizeof(cbOps) / sizeof(Blt_OpSpec); |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
static int |
| 216 |
CutbufferCmd(clientData, interp, argc, argv) |
| 217 |
ClientData clientData; |
| 218 |
|
| 219 |
Tcl_Interp *interp; |
| 220 |
int argc; |
| 221 |
char **argv; |
| 222 |
{ |
| 223 |
Tk_Window tkwin; |
| 224 |
Blt_Op proc; |
| 225 |
int result; |
| 226 |
|
| 227 |
proc = Blt_GetOp(interp, numCbOps, cbOps, BLT_OP_ARG1, argc, argv, 0); |
| 228 |
if (proc == NULL) { |
| 229 |
return TCL_ERROR; |
| 230 |
} |
| 231 |
tkwin = Tk_MainWindow(interp); |
| 232 |
result = (*proc) (interp, tkwin, argc, argv); |
| 233 |
return result; |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
int |
| 253 |
Blt_CutbufferInit(interp) |
| 254 |
Tcl_Interp *interp; |
| 255 |
{ |
| 256 |
static Blt_CmdSpec cmdSpec = |
| 257 |
{"cutbuffer", CutbufferCmd,}; |
| 258 |
|
| 259 |
if (Blt_InitCmd(interp, "blt", &cmdSpec) == NULL) { |
| 260 |
return TCL_ERROR; |
| 261 |
} |
| 262 |
return TCL_OK; |
| 263 |
} |
| 264 |
|
| 265 |
#endif |