macemu/BasiliskII/src/BeOS/clip_beos.cpp

111 lines
2.5 KiB
C++
Raw Normal View History

1999-10-03 14:16:26 +00:00
/*
* clip_beos.cpp - Clipboard handling, BeOS implementation
*
* Basilisk II (C) 1997-2001 Christian Bauer
1999-10-03 14:16:26 +00:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
2000-05-16 17:11:39 +00:00
#include "sysdeps.h"
1999-10-03 14:16:26 +00:00
#include <AppKit.h>
#include <support/UTF8.h>
#include "clip.h"
2000-05-16 17:11:39 +00:00
#include "prefs.h"
1999-10-03 14:16:26 +00:00
#define DEBUG 1
#include "debug.h"
2000-05-16 17:11:39 +00:00
// Flag: Don't convert clipboard text
static bool no_clip_conversion;
1999-10-03 14:16:26 +00:00
/*
* Initialization
*/
void ClipInit(void)
{
2000-05-16 17:11:39 +00:00
no_clip_conversion = PrefsFindBool("noclipconversion");
1999-10-03 14:16:26 +00:00
}
/*
* Deinitialization
*/
void ClipExit(void)
{
}
/*
* Mac application wrote to clipboard
*/
void PutScrap(uint32 type, void *scrap, int32 length)
{
D(bug("PutScrap type %08lx, data %08lx, length %ld\n", type, scrap, length));
if (length <= 0)
return;
switch (type) {
case 'TEXT':
D(bug(" clipping TEXT\n"));
if (be_clipboard->Lock()) {
be_clipboard->Clear();
BMessage *clipper = be_clipboard->Data();
2000-05-16 17:11:39 +00:00
if (no_clip_conversion) {
// Only convert CR->LF
char *buf = new char[dest_length];
for (int i=0; i<length; i++) {
if (i[(char *)scrap] == 13)
1999-10-03 14:16:26 +00:00
buf[i] = 10;
2000-05-16 17:11:39 +00:00
else
buf[i] = i[(char *)scrap];
}
1999-10-03 14:16:26 +00:00
// Add text to Be clipboard
2000-05-16 17:11:39 +00:00
clipper->AddData("text/plain", B_MIME_TYPE, buf, length);
1999-10-03 14:16:26 +00:00
be_clipboard->Commit();
2000-05-16 17:11:39 +00:00
delete[] buf;
} else {
// Convert text from Mac charset to UTF-8
int32 dest_length = length*3;
int32 state = 0;
char *buf = new char[dest_length];
if (convert_to_utf8(B_MAC_ROMAN_CONVERSION, (char *)scrap, &length, buf, &dest_length, &state) == B_OK) {
for (int i=0; i<dest_length; i++)
if (buf[i] == 13)
buf[i] = 10;
// Add text to Be clipboard
clipper->AddData("text/plain", B_MIME_TYPE, buf, dest_length);
be_clipboard->Commit();
}
delete[] buf;
1999-10-03 14:16:26 +00:00
}
be_clipboard->Unlock();
}
break;
}
}