mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 01:21:08 +00:00
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3758 72102866-910b-0410-8b05-ffd578937521
72 lines
1.8 KiB
Objective-C
Executable file
72 lines
1.8 KiB
Objective-C
Executable file
#include <Foundation/NSRunLoop.h>
|
|
#include <Foundation/NSData.h>
|
|
#include <Foundation/NSArray.h>
|
|
#include <Foundation/NSAutoreleasePool.h>
|
|
#include <Foundation/NSGeometry.h>
|
|
#include <AppKit/NSPasteboard.h>
|
|
|
|
@interface pbOwner : NSObject
|
|
{
|
|
}
|
|
- (void) pasteboard: (NSPasteboard*)pb provideDataForType: (NSString*)type;
|
|
@end
|
|
|
|
@implementation pbOwner
|
|
- (void) pasteboard: (NSPasteboard*)pb provideDataForType: (NSString*)type
|
|
{
|
|
if ([type isEqual: NSFileContentsPboardType]) {
|
|
NSString* s = [pb stringForType: NSStringPboardType];
|
|
|
|
if (s) {
|
|
const char* ptr;
|
|
int len;
|
|
NSData* d;
|
|
|
|
ptr = [s cString];
|
|
len = strlen(ptr);
|
|
d = [NSData dataWithBytes: ptr length: len];
|
|
[pb setData: d forType: type];
|
|
}
|
|
}
|
|
}
|
|
@end
|
|
|
|
int
|
|
main(int argc, char** argv)
|
|
{
|
|
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
|
pbOwner *owner = [pbOwner new];
|
|
NSPasteboard *pb;
|
|
NSArray *types;
|
|
NSData *d;
|
|
|
|
[NSObject enableDoubleReleaseCheck: YES];
|
|
|
|
types = [NSArray arrayWithObjects:
|
|
NSStringPboardType, NSFileContentsPboardType, nil];
|
|
pb = [NSPasteboard generalPasteboard];
|
|
[pb declareTypes: types owner: owner];
|
|
[pb setString: @"This is a test" forType: NSStringPboardType];
|
|
d = [pb dataForType: NSFileContentsPboardType];
|
|
printf("%.*s\n", [d length], [d bytes]);
|
|
|
|
pb = [NSPasteboard pasteboardWithUniqueName];
|
|
types = [NSArray arrayWithObjects:
|
|
NSStringPboardType, nil];
|
|
[pb declareTypes: types owner: owner];
|
|
[pb setString: @"a lowercase test string" forType: NSStringPboardType];
|
|
if (NSPerformService(@"To upper", pb) == NO)
|
|
{
|
|
printf("Failed to perform 'To upper' service\n");
|
|
}
|
|
else
|
|
{
|
|
NSString *result = [pb stringForType: NSStringPboardType];
|
|
|
|
printf("To upper - result - '%s'\n", [result cString]);
|
|
}
|
|
[pool release];
|
|
exit(0);
|
|
}
|
|
|
|
|