ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/clip_macosx.cpp
Revision: 1.11
Committed: 2012-01-01T23:24:26Z (12 years, 4 months ago) by asvitkine
Branch: MAIN
CVS Tags: HEAD
Changes since 1.10: +1 -1 lines
Log Message:
fix a warning

File Contents

# User Rev Content
1 gbeauche 1.1 /*
2     * clip_macosx.cpp - Clipboard handling, MacOS X (Carbon) implementation
3     *
4 gbeauche 1.7 * Basilisk II (C) 1997-2008 Christian Bauer
5 gbeauche 1.1 *
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
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * This program is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with this program; if not, write to the Free Software
18     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19     */
20    
21     #include "sysdeps.h"
22 asvitkine 1.9 #define _UINT64
23 gbeauche 1.1 #include <Carbon/Carbon.h>
24    
25     #include "clip.h"
26     #include "main.h"
27     #include "cpu_emulation.h"
28     #include "emul_op.h"
29    
30     #define DEBUG 0
31     #include "debug.h"
32    
33    
34 gbeauche 1.2 // Flag for PutScrap(): the data was put by GetScrap(), don't bounce it back to the MacOS X side
35 gbeauche 1.1 static bool we_put_this_data = false;
36    
37    
38 asvitkine 1.6 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 gbeauche 1.1 /*
78     * Initialization
79     */
80    
81     void ClipInit(void)
82     {
83     }
84    
85    
86     /*
87     * Deinitialization
88     */
89    
90     void ClipExit(void)
91     {
92     }
93    
94    
95     /*
96     * Mac application reads clipboard
97     */
98    
99     void GetScrap(void **handle, uint32 type, int32 offset)
100     {
101 asvitkine 1.10 #if defined(__LP64__)
102 asvitkine 1.9 D(bug("GetScrap handle %p, type %08x, offset %d\n", handle, type, offset));
103 asvitkine 1.10 #warning Carbon scrapbook function are not implemented in 64-bit mode
104 asvitkine 1.9 #else
105 gbeauche 1.1 D(bug("GetScrap handle %p, type %08x, offset %d\n", handle, type, offset));
106     ScrapRef theScrap;
107    
108     if (GetCurrentScrap(&theScrap) != noErr) {
109 gbeauche 1.3 D(bug(" could not open scrap\n"));
110     return;
111 gbeauche 1.1 }
112    
113     Size byteCount;
114     if (GetScrapFlavorSize(theScrap, type, &byteCount) == noErr) {
115    
116 gbeauche 1.5 // 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 asvitkine 1.6 SwapScrapData(type, data, byteCount, FALSE);
127 gbeauche 1.5 // 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 asvitkine 1.11 M68K_RTS >> 8, M68K_RTS & 0xff
137 gbeauche 1.5 };
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 gbeauche 1.1 }
159 asvitkine 1.9 #endif
160 gbeauche 1.1 }
161    
162    
163     /*
164     * Mac application wrote to clipboard
165     */
166    
167     void PutScrap(uint32 type, void *scrap, int32 length)
168     {
169 asvitkine 1.10 #if defined(__LP64__)
170     #warning Carbon scrapbook function are not implemented in 64-bit mode
171 asvitkine 1.9 D(bug("PutScrap type %4.4s, data %08lx, length %ld\n", &type, scrap, length));
172     #else
173 asvitkine 1.8 static bool clear = true;
174     D(bug("PutScrap type %4.4s, data %08lx, length %ld\n", &type, scrap, length));
175 gbeauche 1.1 ScrapRef theScrap;
176    
177     if (we_put_this_data) {
178 gbeauche 1.3 we_put_this_data = false;
179 asvitkine 1.8 clear = true;
180 gbeauche 1.3 return;
181 gbeauche 1.1 }
182     if (length <= 0)
183     return;
184    
185 asvitkine 1.8 if (clear) {
186     D(bug(" calling ClearCurrentScrap\n"));
187     ClearCurrentScrap();
188     }
189 gbeauche 1.1 if (GetCurrentScrap(&theScrap) != noErr) {
190     D(bug(" could not open scrap\n"));
191     return;
192     }
193    
194 asvitkine 1.6 SwapScrapData(type, scrap, length, TRUE);
195 gbeauche 1.1 if (PutScrapFlavor(theScrap, type, kScrapFlavorMaskNone, length, scrap) != noErr) {
196     D(bug(" could not put to scrap\n"));
197 asvitkine 1.8 //return;
198 gbeauche 1.1 }
199 asvitkine 1.8 SwapScrapData(type, scrap, length, FALSE); // swap it back
200 asvitkine 1.9 #endif
201 gbeauche 1.1 }