--- SheepShaver/src/Unix/clip_unix.cpp 2003/12/31 18:23:41 1.4 +++ SheepShaver/src/Unix/clip_unix.cpp 2004/01/12 15:37:21 1.8 @@ -1,7 +1,7 @@ /* * clip_unix.cpp - Clipboard handling, Unix implementation * - * SheepShaver (C) 1997-2003 Christian Bauer and Marc Hellwig + * SheepShaver (C) 1997-2004 Christian Bauer and Marc Hellwig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,6 +45,11 @@ * For safety purposes, we lock the X11 display in the emulator * thread during the whole GetScrap/PutScrap execution. Of course, we * temporarily release the lock when waiting for SelectioNotify. + * + * TODO: + * - handle 'PICT' to image/png, image/ppm, PIXMAP (prefs order) + * - handle 'styl' to text/richtext (OOo Writer) + * - patch ZeroScrap so that we know when cached 'styl' is stale? */ #include "sysdeps.h" @@ -69,12 +74,6 @@ using std::vector; #endif -// Do we replace PutScrap()? -#define REPLACE_PUTSCRAP 1 - -// Do we replace GetScrap()? -#define REPLACE_GETSCRAP 1 - // Do we want GetScrap() to check for TIMESTAMP and optimize out clipboard syncs? #define GETSCRAP_REQUESTS_TIMESTAMP 0 @@ -308,8 +307,6 @@ void ClipExit(void) void PutScrap(uint32 type, void *scrap, int32 length) { D(bug("PutScrap type %08lx, data %p, length %ld\n", type, scrap, length)); - if (!REPLACE_PUTSCRAP) - return; if (we_put_this_data) { we_put_this_data = false; return; @@ -326,7 +323,7 @@ static void do_putscrap(uint32 type, voi { clip_data.type = None; switch (type) { - case FOURCC('T','E','X','T'): + case FOURCC('T','E','X','T'): { D(bug(" clipping TEXT\n")); clip_data.type = XA_STRING; clip_data.data.clear(); @@ -346,6 +343,28 @@ static void do_putscrap(uint32 type, voi break; } + case FOURCC('s','t','y','l'): { + D(bug(" clipping styl\n")); + uint16 *p = (uint16 *)scrap; + uint16 n = ntohs(*p++); + D(bug(" %d styles (%d bytes)\n", n, length)); + for (int i = 0; i < n; i++) { + uint32 offset = ntohl(*(uint32 *)p); p += 2; + uint16 line_height = ntohs(*p++); + uint16 font_ascent = ntohs(*p++); + uint16 font_family = ntohs(*p++); + uint16 style_code = ntohs(*p++); + uint16 char_size = ntohs(*p++); + uint16 r = ntohs(*p++); + uint16 g = ntohs(*p++); + uint16 b = ntohs(*p++); + D(bug(" offset=%d, height=%d, font ascent=%d, id=%d, style=%x, size=%d, RGB=%x/%x/%x\n", + offset, line_height, font_ascent, font_family, style_code, char_size, r, g, b)); + } + break; + } + } + // Acquire selection ownership if (clip_data.type != None) { clip_data.time = CurrentTime; @@ -362,8 +381,6 @@ static void do_putscrap(uint32 type, voi void GetScrap(void **handle, uint32 type, int32 offset) { D(bug("GetScrap handle %p, type %08x, offset %d\n", handle, type, offset)); - if (!REPLACE_GETSCRAP) - return; XDisplayLock(); do_getscrap(handle, type, offset); @@ -413,6 +430,7 @@ static void do_getscrap(void **handle, u long *atoms = (long *)data.data(); for (int i = 0; i < n_atoms; i++) { Atom target = atoms[i]; + D(bug(" target %08x (%s)\n", target, XGetAtomName(x_display, target))); switch (type) { case FOURCC('T','E','X','T'): D(bug(" clipping TEXT\n")); @@ -469,17 +487,17 @@ static void do_getscrap(void **handle, u } // Add new data to clipboard - static uint8 proc[] = { - 0x59, 0x8f, // subq.l #4,sp - 0xa9, 0xfc, // ZeroScrap() - 0x2f, 0x3c, 0, 0, 0, 0, // move.l #length,-(sp) - 0x2f, 0x3c, 0, 0, 0, 0, // move.l #type,-(sp) - 0x2f, 0x3c, 0, 0, 0, 0, // move.l #outbuf,-(sp) - 0xa9, 0xfe, // PutScrap() - 0x58, 0x8f, // addq.l #4,sp - M68K_RTS >> 8, M68K_RTS + static uint16 proc[] = { + PW(0x598f), // subq.l #4,sp + PW(0xa9fc), // ZeroScrap() + PW(0x2f3c), 0, 0, // move.l #length,-(sp) + PW(0x2f3c), 0, 0, // move.l #type,-(sp) + PW(0x2f3c), 0, 0, // move.l #outbuf,-(sp) + PW(0xa9fe), // PutScrap() + PW(0x588f), // addq.l #4,sp + PW(M68K_RTS) }; - uint32 proc_area = (uint32)proc; // FIXME: make sure 32-bit relocs are used + uint32 proc_area = (uint32)proc; WriteMacInt32(proc_area + 6, data.size()); WriteMacInt32(proc_area + 12, type); WriteMacInt32(proc_area + 18, scrap_area);