Noteworthy is that NSDragPasteboard is directly accessible, meaning drag and drop operations work a lot easier on OS X than they do on Windows. Also worthy of mention is NSFindPasteboard, something people on Windows wouldn't be at all familiar with: using special APIs (methods) all applications can at all times continue user searches with the last string used. Often the simple keyboard shortcuts ⌘D (search previous) and ⌘G (search next) are all that is needed. ⌘E takes the current selection and puts it on the find pasteboard for the next operation. As needed, applications can also create their own pasteboards by calling the class method +pasteboardWithUniqueName:. When the pasteboard is no longer needed, the instance method -releaseGlobally is called. Pasteboard Data TypesOS X admits of a plethora of predefined pasteboard data types.
To find out what objects can be sent for any given type, the class method +typesFilterableTo: can be used. The return is an array of all types that can be turned into the target type. Using a PasteboardPutting data on an OS X pasteboard is eminently straightforward: first the client tells the pasteboard what data types are to be expected, and then the client actually sends the data. { NSPasteboard *pb = [NSPasteboard pasteboardWithName:NSGeneralPasteboard]; [pb declareTypes: [NSArray arrayWithObject:NSStringPboardType] owner:self]; [pb setString:myString forType:NSStringPboardType]; } Getting data off a pasteboard is just as easy. { NSString *tmp = [[NSPasteboard pasteboardWithName:NSGeneralPasteboard] stringForType:NSStringPboardType]; if (tmp) [myString setString:tmp]; } Drag and DropAs drag and drop are simply a fancy way of using a pasteboard, implementation is again straightforward. Client and server are expected to conform to the NSDraggingDestination and NSDraggingSource informal protocols respectively. The client can control what happens when the drag enters its territory, what operations are permitted, as can the server. The server can also create a drag image for use in the operation. Many of the more sophisticated classes in OS X come with built in support for drag and drop. ServicesAs described elsewhere at this site, OS X services are 'a clipboard fantasy come true'. The Cocoa AppKit uses the pasteboard server to move data seamlessly between applications, offering filters and services on each application's menu. OS X services are the type of feature that are not even thinkable on a platform such as Windows where the number of available pasteboards is severely limited (1) and the user flexibility is nil. OS X pasteboard architecture is so well thought out that implementing services is mostly a matter of configuration only: everything else is set up by the system at runtime. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|