-
Notifications
You must be signed in to change notification settings - Fork 0
/
XeeClipboardSource.m
100 lines (75 loc) · 2.36 KB
/
XeeClipboardSource.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#import "XeeClipboardSource.h"
//#import "XeeNSImage.h"
#import "XeeImage.h"
#import <XADMaster/CSMemoryHandle.h>
#import <XADMaster/CSMultiHandle.h>
@implementation XeeClipboardSource
+(BOOL)canInitWithPasteboard:(NSPasteboard *)pboard
{
// return [NSBitmapImageRep canInitWithPasteboard:[NSPasteboard generalPasteboard]];
if([[pboard types] containsObject:NSTIFFPboardType]) return YES;
if([[pboard types] containsObject:NSPICTPboardType]) return YES;
return NO;
}
+(BOOL)canInitWithGeneralPasteboard
{
return [self canInitWithPasteboard:[NSPasteboard generalPasteboard]];
}
-(id)initWithPasteboard:(NSPasteboard *)pboard
{
if(self=[super init])
{
image=nil;
NSString *type=[pboard availableTypeFromArray:[NSArray arrayWithObjects:NSTIFFPboardType,NSPICTPboardType,nil]];
NSData *data=[pboard dataForType:type];
size=[data length];
CSHandle *handle;
if([type isEqual:NSPICTPboardType])
{
NSMutableData *head=[NSMutableData dataWithLength:512];
handle=[CSMultiHandle multiHandleWithHandles:
[CSMemoryHandle memoryHandleForReadingData:head],
[CSMemoryHandle memoryHandleForReadingData:data],
nil];
}
else handle=[CSMemoryHandle memoryHandleForReadingData:data];
/*NSLog(@"what");
[[[[handle copy] autorelease] remainingFileContents] writeToFile:@"/Users/dag/Desktop/test.pict" atomically:NO];
*/
image=[[XeeImage imageForHandle:handle] retain];
if(image) return self;
else NSBeep();
/* NSBitmapImageRep *rep=[NSBitmapImageRep imageRepWithPasteboard:pboard];
if(rep)
{
image=[[XeeNSImage alloc] initWithNSBitmapImageRep:rep];
if(image) return self;
}*/
[self release];
}
return nil;
}
-(id)initWithGeneralPasteboard
{
return [self initWithPasteboard:[NSPasteboard generalPasteboard]];
}
-(void)dealloc
{
[image release];
[super dealloc];
}
-(void)start
{
[image runLoader];
[self triggerImageChangeAction:image];
}
-(int)numberOfImages { return 1; }
-(int)indexOfCurrentImage { return 0; }
-(NSString *)windowTitle { return NSLocalizedString(@"Clipboard contents",@"Window title when showing the contents of the clipboard"); }
-(NSString *)descriptiveNameOfCurrentImage { return NSLocalizedString(@"Clipboard contents",@"Window title when showing the contents of the clipboard"); }
-(uint64_t)sizeOfCurrentImage { return size; }
-(void)pickImageAtIndex:(int)index next:(int)next
{
[self triggerImageChangeAction:image];
}
@end