mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 17:52:42 +00:00
This is a trivial test program for the pasteboard system.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@2417 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
36ed301c48
commit
d86d3beaaa
1 changed files with 51 additions and 0 deletions
51
Testing/testpb.m
Executable file
51
Testing/testpb.m
Executable file
|
@ -0,0 +1,51 @@
|
|||
#include <Foundation/NSRunLoop.h>
|
||||
#include <Foundation/NSData.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 cStringNoCopy];
|
||||
len = strlen(ptr);
|
||||
d = [NSData dataWithBytes: ptr length: len];
|
||||
[pb setData: d forType: type];
|
||||
}
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
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]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in a new issue