1 |
|
/* |
2 |
|
* clip_macosx.cpp - Clipboard handling, MacOS X (Carbon) implementation |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2005 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2008 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
34 |
|
static bool we_put_this_data = false; |
35 |
|
|
36 |
|
|
37 |
+ |
static void SwapScrapData(uint32 type, void *data, int32 length, int from_host) { |
38 |
+ |
#if BYTE_ORDER != BIG_ENDIAN |
39 |
+ |
if (type == kScrapFlavorTypeTextStyle) { |
40 |
+ |
uint16 *sdata = (uint16 *) data; |
41 |
+ |
// the first short stores the number of runs |
42 |
+ |
uint16 runs = sdata[0]; |
43 |
+ |
sdata[0] = htons(sdata[0]); |
44 |
+ |
if (from_host) |
45 |
+ |
runs = sdata[0]; |
46 |
+ |
sdata++; |
47 |
+ |
// loop through each run |
48 |
+ |
for (int i = 0; i < runs; i++) { |
49 |
+ |
struct style_data { |
50 |
+ |
uint32 offset; |
51 |
+ |
uint16 line_height; |
52 |
+ |
uint16 line_ascent; |
53 |
+ |
uint16 font_family; |
54 |
+ |
uint16 character_style; // not swapped |
55 |
+ |
uint16 point_size; |
56 |
+ |
uint16 red; |
57 |
+ |
uint16 green; |
58 |
+ |
uint16 blue; |
59 |
+ |
} *style = (struct style_data *) (sdata + i*10); |
60 |
+ |
style->offset = htonl(style->offset); |
61 |
+ |
style->line_height = htons(style->line_height); |
62 |
+ |
style->line_ascent = htons(style->line_ascent); |
63 |
+ |
style->font_family = htons(style->font_family); |
64 |
+ |
style->point_size = htons(style->point_size); |
65 |
+ |
style->red = htons(style->red); |
66 |
+ |
style->green = htons(style->green); |
67 |
+ |
style->blue = htons(style->blue); |
68 |
+ |
} |
69 |
+ |
} else { |
70 |
+ |
// add byteswapping code for other flavor types here ... |
71 |
+ |
} |
72 |
+ |
#endif |
73 |
+ |
} |
74 |
+ |
|
75 |
+ |
|
76 |
|
/* |
77 |
|
* Initialization |
78 |
|
*/ |
118 |
|
if (scrap_area) { |
119 |
|
uint8 * const data = Mac2HostAddr(scrap_area); |
120 |
|
if (GetScrapFlavorData(theScrap, type, &byteCount, data) == noErr) { |
121 |
< |
|
121 |
> |
SwapScrapData(type, data, byteCount, FALSE); |
122 |
|
// Add new data to clipboard |
123 |
|
static uint8 proc[] = { |
124 |
|
0x59, 0x8f, // subq.l #4,sp |
160 |
|
|
161 |
|
void PutScrap(uint32 type, void *scrap, int32 length) |
162 |
|
{ |
163 |
< |
D(bug("PutScrap type %08lx, data %08lx, length %ld\n", type, scrap, length)); |
163 |
> |
static bool clear = true; |
164 |
> |
D(bug("PutScrap type %4.4s, data %08lx, length %ld\n", &type, scrap, length)); |
165 |
|
ScrapRef theScrap; |
166 |
|
|
167 |
|
if (we_put_this_data) { |
168 |
|
we_put_this_data = false; |
169 |
+ |
clear = true; |
170 |
|
return; |
171 |
|
} |
172 |
|
if (length <= 0) |
173 |
|
return; |
174 |
|
|
175 |
< |
ClearCurrentScrap(); |
175 |
> |
if (clear) { |
176 |
> |
D(bug(" calling ClearCurrentScrap\n")); |
177 |
> |
ClearCurrentScrap(); |
178 |
> |
} |
179 |
|
if (GetCurrentScrap(&theScrap) != noErr) { |
180 |
|
D(bug(" could not open scrap\n")); |
181 |
|
return; |
182 |
|
} |
183 |
|
|
184 |
+ |
SwapScrapData(type, scrap, length, TRUE); |
185 |
|
if (PutScrapFlavor(theScrap, type, kScrapFlavorMaskNone, length, scrap) != noErr) { |
186 |
|
D(bug(" could not put to scrap\n")); |
187 |
< |
return; |
187 |
> |
//return; |
188 |
|
} |
189 |
+ |
SwapScrapData(type, scrap, length, FALSE); // swap it back |
190 |
|
} |