ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/clip_macosx.cpp
(Generate patch)

Comparing BasiliskII/src/MacOSX/clip_macosx.cpp (file contents):
Revision 1.3 by gbeauche, 2004-06-27T22:22:42Z vs.
Revision 1.10 by asvitkine, 2010-10-16T04:11:18Z

# Line 1 | Line 1
1   /*
2   *  clip_macosx.cpp - Clipboard handling, MacOS X (Carbon) implementation
3   *
4 < *  Basilisk II (C) 1997-2004 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
# Line 19 | Line 19
19   */
20  
21   #include "sysdeps.h"
22 + #define _UINT64
23   #include <Carbon/Carbon.h>
24  
25   #include "clip.h"
# Line 34 | Line 35
35   static bool we_put_this_data = false;
36  
37  
38 + static void SwapScrapData(uint32 type, void *data, int32 length, int from_host) {
39 + #if BYTE_ORDER != BIG_ENDIAN
40 +        if (type == kScrapFlavorTypeTextStyle) {
41 +                uint16 *sdata = (uint16 *) data;
42 +                // the first short stores the number of runs
43 +                uint16 runs = sdata[0];
44 +                sdata[0] = htons(sdata[0]);
45 +                if (from_host)
46 +                        runs = sdata[0];
47 +                sdata++;
48 +                // loop through each run
49 +                for (int i = 0; i < runs; i++) {
50 +                        struct style_data {
51 +                                uint32 offset;
52 +                                uint16 line_height;
53 +                                uint16 line_ascent;
54 +                                uint16 font_family;
55 +                                uint16 character_style; // not swapped
56 +                                uint16 point_size;
57 +                                uint16 red;
58 +                                uint16 green;
59 +                                uint16 blue;
60 +                        } *style = (struct style_data *) (sdata + i*10);
61 +                        style->offset = htonl(style->offset);
62 +                        style->line_height = htons(style->line_height);
63 +                        style->line_ascent = htons(style->line_ascent);
64 +                        style->font_family = htons(style->font_family);
65 +                        style->point_size = htons(style->point_size);
66 +                        style->red = htons(style->red);
67 +                        style->green = htons(style->green);
68 +                        style->blue = htons(style->blue);
69 +                }
70 +        } else {
71 +                // add byteswapping code for other flavor types here ...
72 +        }
73 + #endif
74 + }
75 +
76 +
77   /*
78   *  Initialization
79   */
# Line 58 | Line 98 | void ClipExit(void)
98  
99   void GetScrap(void **handle, uint32 type, int32 offset)
100   {
101 + #if defined(__LP64__)
102 +        D(bug("GetScrap handle %p, type %08x, offset %d\n", handle, type, offset));
103 +        #warning Carbon scrapbook function are not implemented in 64-bit mode
104 + #else
105          D(bug("GetScrap handle %p, type %08x, offset %d\n", handle, type, offset));
106          ScrapRef theScrap;
107  
# Line 69 | Line 113 | void GetScrap(void **handle, uint32 type
113          Size byteCount;
114          if (GetScrapFlavorSize(theScrap, type, &byteCount) == noErr) {
115  
116 <          // Get the native clipboard data
117 <          uint8 *data = new uint8[byteCount];
118 <          if (GetScrapFlavorData(theScrap, type, &byteCount, data) == noErr) {
119 <                  M68kRegisters r;
120 <
121 <                  // Add new data to clipboard
122 <                  static uint16 proc[] = {
123 <                          0x598f,                               // subq.l               #4,sp
124 <                          0xa9fc,                               // ZeroScrap()
125 <                          0x2f3c, 0, 0,                 // move.l               #length,-(sp)
126 <                          0x2f3c, 0, 0,                 // move.l               #type,-(sp)
127 <                          0x2f3c, 0, 0,                 // move.l               #outbuf,-(sp)
128 <                          0xa9fe,                               // PutScrap()
129 <                          0x588f,                               // addq.l               #4,sp
130 <                          M68K_RTS
131 <                  };
132 <                  uint32 proc_area = (uint32)proc;
133 <                  WriteMacInt32(proc_area +  6, byteCount);
134 <                  WriteMacInt32(proc_area + 12, type);
135 <                  WriteMacInt32(proc_area + 18, (uint32)data);
136 <                  we_put_this_data = true;
137 <                  Execute68k(proc_area, &r);
138 <          }
139 <
140 <          delete[] data;
116 >                // Allocate space for new scrap in MacOS side
117 >                M68kRegisters r;
118 >                r.d[0] = byteCount;
119 >                Execute68kTrap(0xa71e, &r);                             // NewPtrSysClear()
120 >                uint32 scrap_area = r.a[0];
121 >
122 >                // Get the native clipboard data
123 >                if (scrap_area) {
124 >                        uint8 * const data = Mac2HostAddr(scrap_area);
125 >                        if (GetScrapFlavorData(theScrap, type, &byteCount, data) == noErr) {
126 >                                SwapScrapData(type, data, byteCount, FALSE);
127 >                                // Add new data to clipboard
128 >                                static uint8 proc[] = {
129 >                                        0x59, 0x8f,                                     // subq.l       #4,sp
130 >                                        0xa9, 0xfc,                                     // ZeroScrap()
131 >                                        0x2f, 0x3c, 0, 0, 0, 0,         // move.l       #length,-(sp)
132 >                                        0x2f, 0x3c, 0, 0, 0, 0,         // move.l       #type,-(sp)
133 >                                        0x2f, 0x3c, 0, 0, 0, 0,         // move.l       #outbuf,-(sp)
134 >                                        0xa9, 0xfe,                                     // PutScrap()
135 >                                        0x58, 0x8f,                                     // addq.l       #4,sp
136 >                                        M68K_RTS >> 8, M68K_RTS
137 >                                };
138 >                                r.d[0] = sizeof(proc);
139 >                                Execute68kTrap(0xa71e, &r);             // NewPtrSysClear()
140 >                                uint32 proc_area = r.a[0];
141 >
142 >                                if (proc_area) {
143 >                                        Host2Mac_memcpy(proc_area, proc, sizeof(proc));
144 >                                        WriteMacInt32(proc_area +  6, byteCount);
145 >                                        WriteMacInt32(proc_area + 12, type);
146 >                                        WriteMacInt32(proc_area + 18, scrap_area);
147 >                                        we_put_this_data = true;
148 >                                        Execute68k(proc_area, &r);
149 >
150 >                                        r.a[0] = proc_area;
151 >                                        Execute68kTrap(0xa01f, &r);     // DisposePtr
152 >                                }
153 >                        }
154 >
155 >                        r.a[0] = scrap_area;
156 >                        Execute68kTrap(0xa01f, &r);                     // DisposePtr
157 >                }
158          }
159 + #endif
160   }
161  
162  
# Line 104 | Line 166 | void GetScrap(void **handle, uint32 type
166  
167   void PutScrap(uint32 type, void *scrap, int32 length)
168   {
169 <        D(bug("PutScrap type %08lx, data %08lx, length %ld\n", type, scrap, length));
169 > #if defined(__LP64__)
170 >        #warning Carbon scrapbook function are not implemented in 64-bit mode
171 >        D(bug("PutScrap type %4.4s, data %08lx, length %ld\n", &type, scrap, length));
172 > #else
173 >        static bool clear = true;
174 >        D(bug("PutScrap type %4.4s, data %08lx, length %ld\n", &type, scrap, length));
175          ScrapRef theScrap;
176  
177          if (we_put_this_data) {
178                  we_put_this_data = false;
179 +                clear = true;
180                  return;
181          }
182          if (length <= 0)
183                  return;
184  
185 <        ClearCurrentScrap();
185 >        if (clear) {
186 >                D(bug(" calling ClearCurrentScrap\n"));
187 >                ClearCurrentScrap();
188 >        }
189          if (GetCurrentScrap(&theScrap) != noErr) {
190                  D(bug(" could not open scrap\n"));
191                  return;
192          }
193  
194 +        SwapScrapData(type, scrap, length, TRUE);
195          if (PutScrapFlavor(theScrap, type, kScrapFlavorMaskNone, length, scrap) != noErr) {
196                  D(bug(" could not put to scrap\n"));
197 <                return;
197 >                //return;
198          }
199 +        SwapScrapData(type, scrap, length, FALSE); // swap it back
200 + #endif
201   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines