initial paste support.

git-svn-id: svn://qnap.local/TwoTerm/trunk@1760 5590a31f-7b70-45f8-8c82-aa3a8e5f4507
This commit is contained in:
Kelvin Sherlock 2010-09-11 20:27:26 +00:00
parent b2a91bd801
commit d8ee6e8894
2 changed files with 91 additions and 3 deletions

View File

@ -17,6 +17,7 @@
#include "Screen.h"
@class EmulatorView;
class ViewScreen: public Screen
{
public:
@ -72,6 +73,10 @@ private:
#endif
}
@property (nonatomic, assign) int fd;
//@property (nonatomic, assign) iPoint cursor;
-(void)startBackgroundReader;
-(void)dataAvailable;
-(void)invalidateIRect: (iRect)rect;
@ -80,7 +85,11 @@ private:
-(void)cursorTimer: (NSTimer *)timer;
@property (nonatomic, assign) int fd;
//@property (nonatomic, assign) iPoint cursor;
-(void)autoTypeText: (NSString *)text;
-(IBAction)paste: (id)sender;
-(IBAction)copy: (id)sender;
@end

View File

@ -82,7 +82,7 @@
_cursorImg = [[_charGen imageForCharacter: '_'] retain];
_emulator = [VT100 new];
_emulator = [VT52 new];
}
@ -282,6 +282,52 @@
[self invalidateIRect: updateRect];
}
-(void)autoTypeText:(NSString *)text
{
typedef void (*ProcessCharFX)(id, SEL, uint8_t, Screen *, OutputChannel *);
std::vector<unichar> chars;
std::vector<unichar>::iterator iter;
iRect updateRect; // should be nil but whatever...
OutputChannel channel(_fd);
SEL cmd = @selector(processCharacter: screen: output:);
ProcessCharFX fx = (ProcessCharFX)[_emulator methodForSelector: cmd];
unsigned length = [text length];
if (!length) return;
chars.resize(length);
[text getCharacters: &chars[0] range: NSMakeRange(0, length)];
_screen.beginUpdate();
// this posts as if it was output, need to post as if it was input
for (iter = chars.begin(); iter != chars.end(); ++iter)
{
fx(_emulator,cmd, *iter, &_screen, &channel);
}
updateRect = _screen.endUpdate();
[self invalidateIRect: updateRect];
}
-(void)startBackgroundReader
{
if (_readerThread) return;
@ -464,6 +510,39 @@
[super setFrame: frameRect];
}
#pragma mark -
#pragma mark IBActions
-(IBAction)paste: (id)sender
{
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSArray *classArray = [NSArray arrayWithObject:[NSString class]];
NSDictionary *options = [NSDictionary dictionary];
BOOL ok = [pasteboard canReadObjectForClasses:classArray options:options];
if (ok)
{
NSArray *objectsToPaste = [pasteboard readObjectsForClasses:classArray options:options];
NSString *string = [objectsToPaste objectAtIndex: 0];
NSLog(@"%@", objectsToPaste);
[self autoTypeText: string];
}
}
-(IBAction)copy: (id)sender
{
}
@end