|
|
1.1 root 1: /*
2: * PSText.m, subclass of Text overriding paste: for adding functionality
3: * Author: Ali Ozer
4: * Created: Mar 22, 89
5: *
6: * You may freely copy, distribute and reuse the code in this example.
7: * NeXT disclaims any warranty of any kind, expressed or implied,
8: * as to its fitness for any particular use.
9: */
10:
11: #import <appkit/appkit.h>
12: #import <string.h>
13: #import <mach/mach.h>
14: #import "PSText.h"
15:
16: @implementation PSText
17:
18: /*
19: * The following method overrides the Text paste: method. If there's any
20: * PostScript on the pasteboard, this method will paste that in before pasting
21: * ASCII. If there's no PostScript on the pasteboard, then this method will
22: * simply call the overridden paste: method.
23: */
24: - paste:(id)sender
25: {
26: id pb = [Pasteboard new];
27: char *data;
28: char *const *s; /* We use s to go through types. */
29: char *const *types = [pb types];
30: int len;
31:
32: /* Check to see if we have any PostScript on the pasteboard... */
33:
34: for (s = types; *s; s++) if (!strcmp(*s, NXPostScriptPboard)) break;
35:
36: /* At this point, if *s != NULL, we found PostScript on the pasteboard. */
37:
38: if (*s && [pb readType:NXPostScriptPboard data:&data length:&len] && len) {
39: [self replaceSel:data length:len];
40: vm_deallocate (task_self(), (vm_address_t)data, (vm_size_t)len);
41: } else {
42: [super paste:sender]; /* No PS; pass the task on to Text. */
43: }
44:
45: return self;
46: }
47:
48: @end
49:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.