|
|
1.1 root 1: #import "textundo.h"
2:
3: @implementation TextSelection
4:
5: /*
6: * The TextSelection class takes a snapshot of the current selection of
7: * a Text object. It remembers the position of the selection and records
8: * the characters in the selection with an RTF stream.
9: */
10:
11: - initText:aView
12: {
13: NXSelPt selStart, selEnd;
14:
15: [aView getSel:&selStart :&selEnd];
16: return [self initText:aView start:selStart.cp end:selEnd.cp];
17: }
18:
19: - initText:aView start:(int)startPos end:(int)endPos
20: {
21: [super init];
22:
23: text = aView;
24: start = startPos;
25: end = endPos;
26:
27: selectionChars = (NXStream *) 0;
28:
29: if (start == 0 && end == [text textLength]) {
30: allText = YES;
31: } else {
32: allText = NO;
33: }
34:
35: [text getFrame:&frame];
36:
37: return self;
38: }
39:
40: - free
41: {
42: if (selectionChars) {
43: NXCloseMemory(selectionChars, NX_FREEBUFFER);
44: }
45:
46: return [super free];
47: }
48:
49: - (int)clickCount
50: {
51: return clickCount;
52: }
53:
54: - setClickCount:(int)value
55: {
56: clickCount = value;
57: return self;
58: }
59:
60: /*
61: * The Text object doesn't save everything out in writeRichText:from:to: even
62: * if the bounds specify the entire contents of the object. Things like tab
63: * stops and margins are missing. However, writeRichText: does a better job,
64: * although not perfect.
65: */
66:
67: - capture
68: {
69: clickCount = [text clickCount];
70:
71: if (start < end || allText) {
72: selectionChars = NXOpenMemory(NULL, 0, NX_READWRITE);
73: if (allText) {
74: [text writeRichText:selectionChars];
75: } else {
76: [text writeRichText:selectionChars from:start to:end];
77: }
78: }
79:
80: return self;
81: }
82:
83: - install
84: {
85: [text setSel:start :start];
86: [text setFrame:&frame];
87:
88: if (selectionChars) {
89: NXSeek(selectionChars, 0, NX_FROMSTART);
90:
91: if (allText) {
92: [text readRichText:selectionChars];
93: [text display];
94: } else {
95: [text replaceSelWithRichText:selectionChars];
96: }
97:
98: [text setSel:start :end];
99:
100: }
101:
102: return self;
103: }
104:
105: - remove
106: {
107: [text setSel:start :end];
108: [text setClickCount:clickCount];
109: [text eraseSelection];
110:
111: return self;
112: }
113:
114: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.