macemu/BasiliskII/src/BeOS/clip_beos.cpp
CharlesJS ed28705ee3 Patch for copying and pasting styled text in Basilisk II / SheepShaver
Added code to parse the Classic Mac OS 'styl' resources, allowing formatted text to be copied and pasted out of SheepShaver, not just plain text. In order to do this, I made some changes to the emul_op mechanism, patching ZeroScrap() in addition to the scrap methods that were already being patched. The reason for this is that since we need to read data from multiple items that are on the clipboard at once, we cannot simply assume a zero at the beginning of each PutScrap() operation.

This patch uses RTF to store styled text on the host side; unfortunately, since the APIs to convert to and from RTF data are in Cocoa but not in CoreFoundation, I had to write the new portions in Objective-C rather than C, and changed the extension from .cpp to .mm accordingly. In the future, if we are confident that this file will only be used on Mac OS X 10.6 and up, we can rewrite the Pasteboard Manager code to use NSPasteboardReading/Writing instead. This would allow us to read and write NSAttributedString objects directly to and from the pasteboard, which would make sure we were always using the OS's preferred rich text format internally instead of hard-coding it specifically to RTF as in the current implementation.

I believe that this patch should also fix the problem Ronald reported with copying accented characters.

Since I am new to 68k assembly and the emul_op mechanism, I would appreciate if someone could double-check all my changes to make sure that I have done everything correctly.

Thanks,
Charles
2012-06-30 22:20:55 -04:00

129 lines
2.7 KiB
C++

/*
* clip_beos.cpp - Clipboard handling, BeOS implementation
*
* Basilisk II (C) 1997-2008 Christian Bauer
*
* 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
*/
#include "sysdeps.h"
#include <AppKit.h>
#include <support/UTF8.h>
#include "clip.h"
#include "prefs.h"
#define DEBUG 1
#include "debug.h"
// Flag: Don't convert clipboard text
static bool no_clip_conversion;
/*
* Initialization
*/
void ClipInit(void)
{
no_clip_conversion = PrefsFindBool("noclipconversion");
}
/*
* Deinitialization
*/
void ClipExit(void)
{
}
/*
* Mac application zeroes clipboard
*/
void ZeroScrap()
{
}
/*
* Mac application reads clipboard
*/
void GetScrap(void **handle, uint32 type, int32 offset)
{
D(bug("GetScrap handle %p, type %08x, offset %d\n", handle, type, offset));
}
/*
* 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();
if (no_clip_conversion) {
// Only convert CR->LF
char *buf = new char[length];
for (int i=0; i<length; i++) {
if (i[(char *)scrap] == 13)
buf[i] = 10;
else
buf[i] = i[(char *)scrap];
}
// Add text to Be clipboard
clipper->AddData("text/plain", B_MIME_TYPE, buf, length);
be_clipboard->Commit();
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;
}
be_clipboard->Unlock();
}
break;
}
}