ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/clip_macosx.cpp
Revision: 1.5
Committed: 2006-03-21T06:43:02Z (18 years, 8 months ago) by gbeauche
Branch: MAIN
CVS Tags: nigel-build-19
Changes since 1.4: +42 -25 lines
Log Message:
fix clipboard handling for MacOS X

File Contents

# User Rev Content
1 gbeauche 1.1 /*
2     * clip_macosx.cpp - Clipboard handling, MacOS X (Carbon) implementation
3     *
4 gbeauche 1.4 * Basilisk II (C) 1997-2005 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     #include <Carbon/Carbon.h>
23    
24     #include "clip.h"
25     #include "main.h"
26     #include "cpu_emulation.h"
27     #include "emul_op.h"
28    
29     #define DEBUG 0
30     #include "debug.h"
31    
32    
33 gbeauche 1.2 // Flag for PutScrap(): the data was put by GetScrap(), don't bounce it back to the MacOS X side
34 gbeauche 1.1 static bool we_put_this_data = false;
35    
36    
37     /*
38     * Initialization
39     */
40    
41     void ClipInit(void)
42     {
43     }
44    
45    
46     /*
47     * Deinitialization
48     */
49    
50     void ClipExit(void)
51     {
52     }
53    
54    
55     /*
56     * Mac application reads clipboard
57     */
58    
59     void GetScrap(void **handle, uint32 type, int32 offset)
60     {
61     D(bug("GetScrap handle %p, type %08x, offset %d\n", handle, type, offset));
62     ScrapRef theScrap;
63    
64     if (GetCurrentScrap(&theScrap) != noErr) {
65 gbeauche 1.3 D(bug(" could not open scrap\n"));
66     return;
67 gbeauche 1.1 }
68    
69     Size byteCount;
70     if (GetScrapFlavorSize(theScrap, type, &byteCount) == noErr) {
71    
72 gbeauche 1.5 // Allocate space for new scrap in MacOS side
73     M68kRegisters r;
74     r.d[0] = byteCount;
75     Execute68kTrap(0xa71e, &r); // NewPtrSysClear()
76     uint32 scrap_area = r.a[0];
77    
78     // Get the native clipboard data
79     if (scrap_area) {
80     uint8 * const data = Mac2HostAddr(scrap_area);
81     if (GetScrapFlavorData(theScrap, type, &byteCount, data) == noErr) {
82    
83     // Add new data to clipboard
84     static uint8 proc[] = {
85     0x59, 0x8f, // subq.l #4,sp
86     0xa9, 0xfc, // ZeroScrap()
87     0x2f, 0x3c, 0, 0, 0, 0, // move.l #length,-(sp)
88     0x2f, 0x3c, 0, 0, 0, 0, // move.l #type,-(sp)
89     0x2f, 0x3c, 0, 0, 0, 0, // move.l #outbuf,-(sp)
90     0xa9, 0xfe, // PutScrap()
91     0x58, 0x8f, // addq.l #4,sp
92     M68K_RTS >> 8, M68K_RTS
93     };
94     r.d[0] = sizeof(proc);
95     Execute68kTrap(0xa71e, &r); // NewPtrSysClear()
96     uint32 proc_area = r.a[0];
97    
98     if (proc_area) {
99     Host2Mac_memcpy(proc_area, proc, sizeof(proc));
100     WriteMacInt32(proc_area + 6, byteCount);
101     WriteMacInt32(proc_area + 12, type);
102     WriteMacInt32(proc_area + 18, scrap_area);
103     we_put_this_data = true;
104     Execute68k(proc_area, &r);
105    
106     r.a[0] = proc_area;
107     Execute68kTrap(0xa01f, &r); // DisposePtr
108     }
109     }
110    
111     r.a[0] = scrap_area;
112     Execute68kTrap(0xa01f, &r); // DisposePtr
113     }
114 gbeauche 1.1 }
115     }
116    
117    
118     /*
119     * Mac application wrote to clipboard
120     */
121    
122     void PutScrap(uint32 type, void *scrap, int32 length)
123     {
124     D(bug("PutScrap type %08lx, data %08lx, length %ld\n", type, scrap, length));
125     ScrapRef theScrap;
126    
127     if (we_put_this_data) {
128 gbeauche 1.3 we_put_this_data = false;
129     return;
130 gbeauche 1.1 }
131     if (length <= 0)
132     return;
133    
134     ClearCurrentScrap();
135     if (GetCurrentScrap(&theScrap) != noErr) {
136     D(bug(" could not open scrap\n"));
137     return;
138     }
139    
140     if (PutScrapFlavor(theScrap, type, kScrapFlavorMaskNone, length, scrap) != noErr) {
141     D(bug(" could not put to scrap\n"));
142     return;
143     }
144     }