ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/BeOS/clip_beos.cpp
Revision: 1.9
Committed: 2005-01-30T21:42:13Z (19 years, 5 months ago) by gbeauche
Branch: MAIN
CVS Tags: nigel-build-19, nigel-build-17
Changes since 1.8: +1 -1 lines
Log Message:
Happy New Year!

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * clip_beos.cpp - Clipboard handling, BeOS implementation
3     *
4 gbeauche 1.9 * Basilisk II (C) 1997-2005 Christian Bauer
5 cebix 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 cebix 1.3 #include "sysdeps.h"
22    
23 cebix 1.1 #include <AppKit.h>
24     #include <support/UTF8.h>
25    
26     #include "clip.h"
27 cebix 1.3 #include "prefs.h"
28 cebix 1.1
29     #define DEBUG 1
30     #include "debug.h"
31    
32    
33 cebix 1.3 // Flag: Don't convert clipboard text
34     static bool no_clip_conversion;
35    
36    
37 cebix 1.1 /*
38     * Initialization
39     */
40    
41     void ClipInit(void)
42     {
43 cebix 1.3 no_clip_conversion = PrefsFindBool("noclipconversion");
44 cebix 1.1 }
45    
46    
47     /*
48     * Deinitialization
49     */
50    
51     void ClipExit(void)
52     {
53     }
54    
55    
56     /*
57 gbeauche 1.8 * Mac application reads clipboard
58     */
59    
60     void GetScrap(void **handle, uint32 type, int32 offset)
61     {
62     D(bug("GetScrap handle %p, type %08x, offset %d\n", handle, type, offset));
63     }
64    
65    
66     /*
67 cebix 1.1 * Mac application wrote to clipboard
68     */
69    
70     void PutScrap(uint32 type, void *scrap, int32 length)
71     {
72     D(bug("PutScrap type %08lx, data %08lx, length %ld\n", type, scrap, length));
73     if (length <= 0)
74     return;
75    
76     switch (type) {
77     case 'TEXT':
78     D(bug(" clipping TEXT\n"));
79     if (be_clipboard->Lock()) {
80     be_clipboard->Clear();
81     BMessage *clipper = be_clipboard->Data();
82    
83 cebix 1.3 if (no_clip_conversion) {
84    
85     // Only convert CR->LF
86 cebix 1.5 char *buf = new char[length];
87 cebix 1.3 for (int i=0; i<length; i++) {
88     if (i[(char *)scrap] == 13)
89 cebix 1.1 buf[i] = 10;
90 cebix 1.3 else
91     buf[i] = i[(char *)scrap];
92     }
93    
94 cebix 1.1 // Add text to Be clipboard
95 cebix 1.3 clipper->AddData("text/plain", B_MIME_TYPE, buf, length);
96 cebix 1.1 be_clipboard->Commit();
97 cebix 1.3 delete[] buf;
98    
99     } else {
100    
101     // Convert text from Mac charset to UTF-8
102     int32 dest_length = length*3;
103     int32 state = 0;
104     char *buf = new char[dest_length];
105     if (convert_to_utf8(B_MAC_ROMAN_CONVERSION, (char *)scrap, &length, buf, &dest_length, &state) == B_OK) {
106     for (int i=0; i<dest_length; i++)
107     if (buf[i] == 13)
108     buf[i] = 10;
109    
110     // Add text to Be clipboard
111     clipper->AddData("text/plain", B_MIME_TYPE, buf, dest_length);
112     be_clipboard->Commit();
113     }
114     delete[] buf;
115 cebix 1.1 }
116     be_clipboard->Unlock();
117     }
118     break;
119     }
120     }