ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/clip_macosx.cpp
Revision: 1.2
Committed: 2004-06-27T20:36:09Z (20 years, 2 months ago) by gbeauche
Branch: MAIN
Changes since 1.1: +1 -1 lines
Log Message:
typo

File Contents

# User Rev Content
1 gbeauche 1.1 /*
2     * clip_macosx.cpp - Clipboard handling, MacOS X (Carbon) implementation
3     *
4     * Basilisk II (C) 1997-2004 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
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     D(bug(" could not open scrap\n"));
66     return;
67     }
68    
69     Size byteCount;
70     if (GetScrapFlavorSize(theScrap, type, &byteCount) == noErr) {
71    
72     // Get the native clipboard data
73     uint8 *data = new uint8[byteCount];
74     if (GetScrapFlavorData(theScrap, type, &byteCount, data) == noErr) {
75     M68kRegisters r;
76    
77     // Add new data to clipboard
78     static uint16 proc[] = {
79     0x598f, // subq.l #4,sp
80     0xa9fc, // ZeroScrap()
81     0x2f3c, 0, 0, // move.l #length,-(sp)
82     0x2f3c, 0, 0, // move.l #type,-(sp)
83     0x2f3c, 0, 0, // move.l #outbuf,-(sp)
84     0xa9fe, // PutScrap()
85     0x588f, // addq.l #4,sp
86     M68K_RTS
87     };
88     uint32 proc_area = (uint32)proc;
89     WriteMacInt32(proc_area + 6, byteCount);
90     WriteMacInt32(proc_area + 12, type);
91     WriteMacInt32(proc_area + 18, (uint32)data);
92     we_put_this_data = true;
93     Execute68k(proc_area, &r);
94     }
95    
96     delete[] data;
97     }
98     }
99    
100    
101     /*
102     * Mac application wrote to clipboard
103     */
104    
105     void PutScrap(uint32 type, void *scrap, int32 length)
106     {
107     D(bug("PutScrap type %08lx, data %08lx, length %ld\n", type, scrap, length));
108     ScrapRef theScrap;
109    
110     if (we_put_this_data) {
111     we_put_this_data = false;
112     return;
113     }
114     if (length <= 0)
115     return;
116    
117     ClearCurrentScrap();
118     if (GetCurrentScrap(&theScrap) != noErr) {
119     D(bug(" could not open scrap\n"));
120     return;
121     }
122    
123     if (PutScrapFlavor(theScrap, type, kScrapFlavorMaskNone, length, scrap) != noErr) {
124     D(bug(" could not put to scrap\n"));
125     return;
126     }
127     }