help with copy: method
help with copy: method
- Subject: help with copy: method
- From: Sly Upah <email@hidden>
- Date: Wed, 04 Dec 2002 18:09:11 CST
I'm wondering how one would get the copy: method to invoke in the
following program (I'm not using PowerBuilder/InterfaceBuilder so
there is no Edit menu/MainMenu.nib).
Thanks for any assistance!
#import <Cocoa/Cocoa.h>
@interface ZView : NSTextView
{
}
-(void)windowWillClose:(NSNotification *)notification;
-(IBAction)copy:(id)sender;
@end
@implementation ZView
-(void)windowWillClose:(NSNotification *)notification
{
[NSApp terminate:self];
}
-(IBAction)copy:(id)sender
{
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
NSArray *types = [NSArray arrayWithObject:NSStringPboardType];
printf("HERE\n");
[pboard declareTypes:types owner:self];
[pboard addTypes:types owner:self];
// need some help with setString...
[pboard setString:??? forType:NSStringPboardType];
}
@end
setup()
{
NSWindow *window;
NSTextView *textView;
NSScrollView *scrollView;
NSTextView *zView;
NSRect scrollViewRect = {{0, 0}, {width, height}};
NSRect winRect = {{0, 0}, {width, height}};
NSRect textRect;
unsigned int style = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask;
window = [[NSWindow alloc] initWithContentRect: winRect
styleMask: style
backing: NSBackingStoreBuffered
defer: NO];
[window setMinSize:NSMakeSize(300, 300)];
scrollView = [[[NSScrollView alloc] initWithFrame: scrollViewRect] autorelease];
[scrollView setHasHorizontalScroller: YES];
[scrollView setHasVerticalScroller: YES];
[scrollView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
[[scrollView contentView] setAutoresizingMask: NSViewHeightSizable
| NSViewWidthSizable];
[[scrollView contentView] setAutoresizesSubviews:YES];
textRect = [[scrollView contentView] frame];
textView = [[[NSTextView alloc] initWithFrame: textRect] autorelease];
[textView setBackgroundColor: [NSColor whiteColor]];
[textView setString:outbuf];
[textView setEditable: YES];
[textView setFont:[NSFont userFixedPitchFontOfSize:12]];
[textView setHorizontallyResizable: YES];
[textView setVerticallyResizable: YES];
[textView setMinSize: NSMakeSize(0, 0)];
[textView setMaxSize: NSMakeSize(1E7, 1E7)];
[textView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
[[textView textContainer] setContainerSize:NSMakeSize(1E7, 1E7)];
[[textView textContainer] setWidthTracksTextView: YES];
[scrollView setDocumentView: textView];
[window setContentView: scrollView];
[window setTitle: title];
zView = [[[ZView alloc] initWithFrame: scrollViewRect] autorelease];
[textView setDelegate: zView];
[window setDelegate: zView];
[window makeKeyAndOrderFront: nil];
}
int main(int argc,char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSApp = [NSApplication sharedApplication];
setup();
[NSApp run];
// we get here when the window is closed
[NSApp release];
[pool release];
return(0);
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.