ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/BeOS/clip_beos.cpp
Revision: 1.3
Committed: 2000-05-16T17:11:38Z (24 years, 6 months ago) by cebix
Branch: MAIN
CVS Tags: snapshot-13072000
Changes since 1.2: +37 -11 lines
Log Message:
- added "noclipconversion" prefs item

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * clip_beos.cpp - Clipboard handling, BeOS implementation
3     *
4 cebix 1.2 * Basilisk II (C) 1997-2000 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     * Mac application wrote to clipboard
58     */
59    
60     void PutScrap(uint32 type, void *scrap, int32 length)
61     {
62     D(bug("PutScrap type %08lx, data %08lx, length %ld\n", type, scrap, length));
63     if (length <= 0)
64     return;
65    
66     switch (type) {
67     case 'TEXT':
68     D(bug(" clipping TEXT\n"));
69     if (be_clipboard->Lock()) {
70     be_clipboard->Clear();
71     BMessage *clipper = be_clipboard->Data();
72    
73 cebix 1.3 if (no_clip_conversion) {
74    
75     // Only convert CR->LF
76     char *buf = new char[dest_length];
77     for (int i=0; i<length; i++) {
78     if (i[(char *)scrap] == 13)
79 cebix 1.1 buf[i] = 10;
80 cebix 1.3 else
81     buf[i] = i[(char *)scrap];
82     }
83    
84 cebix 1.1 // Add text to Be clipboard
85 cebix 1.3 clipper->AddData("text/plain", B_MIME_TYPE, buf, length);
86 cebix 1.1 be_clipboard->Commit();
87 cebix 1.3 delete[] buf;
88    
89     } else {
90    
91     // Convert text from Mac charset to UTF-8
92     int32 dest_length = length*3;
93     int32 state = 0;
94     char *buf = new char[dest_length];
95     if (convert_to_utf8(B_MAC_ROMAN_CONVERSION, (char *)scrap, &length, buf, &dest_length, &state) == B_OK) {
96     for (int i=0; i<dest_length; i++)
97     if (buf[i] == 13)
98     buf[i] = 10;
99    
100     // Add text to Be clipboard
101     clipper->AddData("text/plain", B_MIME_TYPE, buf, dest_length);
102     be_clipboard->Commit();
103     }
104     delete[] buf;
105 cebix 1.1 }
106     be_clipboard->Unlock();
107     }
108     break;
109     }
110     }