|
|
1.1 root 1: // TileScrollView.m
2: // By Jayson Adams, NeXT Developer Support Team
3: // Modified for 3.0 by Ali Ozer, May '92
4: // You may freely copy, distribute and reuse the code in this example.
5: // NeXT disclaims any warranty of any kind, expressed or implied, as to its
6: // fitness for any particular use.
7:
8: #import <appkit/ClipView.h>
9: #import <appkit/Matrix.h>
10:
11: #import "RulerView.h"
12: #import "PostScriptView.h"
13:
14: #import "TileScrollView.h"
15:
16:
17: @implementation TileScrollView
18:
19:
20: /* instance methods */
21:
22: - initFrame:(const NXRect *)theFrame
23: {
24: NXRect rulerViewRect = {{0.0, 0.0}, {NX_WIDTH(theFrame), 20.0}};
25:
26: [super initFrame:theFrame];
27:
28: /* create a rulerView */
29: rulerView = [[RulerView alloc] initFrame:&rulerViewRect];
30:
31: /* make a clipView to hold it (we'll adjust its size & position in tile) */
32: rulerClipView = [[ClipView alloc] initFrame:&rulerViewRect];
33: [self addSubview:rulerClipView];
34: [rulerClipView setDocView:rulerView];
35:
36: /* remember the current scale factor */
37: oldScaleFactor = 1.0;
38:
39: return self;
40: }
41:
42: - free
43: {
44: [rulerView free];
45: [rulerClipView free];
46:
47: return [super free];
48: }
49:
50: - changeScale:sender
51: {
52: float scaleFactor = [[sender selectedCell] tag] / 100.0;
53:
54: if (scaleFactor != oldScaleFactor) {
55: [window disableDisplay];
56: [[self docView] scale:scaleFactor / oldScaleFactor];
57: [rulerView scale:scaleFactor / oldScaleFactor :1.0];
58: [self fixUpRuler];
59: [window reenableDisplay];
60: [self display];
61: oldScaleFactor = scaleFactor;
62: }
63:
64: return self;
65: }
66:
67: - (void)fixUpRuler
68: {
69: NXRect docViewBounds, rulerViewBounds;
70: [window disableDisplay];
71: [[self docView] getBounds:&docViewBounds];
72: [rulerView getBounds:&rulerViewBounds];
73: [rulerView sizeTo:NX_WIDTH(&docViewBounds) :NX_HEIGHT(&rulerViewBounds)];
74: [self tile];
75: [window reenableDisplay];
76: [self display];
77: }
78:
79: - setDocView:aView
80: {
81: id retVal = [super setDocView:aView];
82: [self fixUpRuler];
83: return retVal;
84: }
85:
86: - tile
87: /*
88: * tile gets called whenever the scrollView changes size. Its job is to resize
89: * all of the scrollView's "tiled" views (scrollers, contentView and any other
90: * views we might want to place in the scrollView's bounds).
91: */
92: {
93: NXRect contentViewRect, rulerRect, rulerClipRect, scrollerRect,
94: buttonRect, stubRect;
95:
96: /* resize and arrange the scrollers and contentView as usual */
97: [super tile];
98:
99: /* make sure the popup list and stub view are subviews of us */
100: if ([popupListButton superview] != self) {
101: [self addSubview:popupListButton];
102: }
103: if ([stubView superview] != self) {
104: [self addSubview:stubView];
105: }
106:
107: /* cut a slice from the contentView to make room for the rulerView */
108: [contentView getFrame:&contentViewRect];
109: [rulerView getFrame:&rulerRect];
110: NXDivideRect(&contentViewRect, &rulerClipRect, NX_HEIGHT(&rulerRect), 1);
111: [rulerClipView setFrame:&rulerClipRect];
112: [contentView setFrame:&contentViewRect];
113:
114: /* shrink the vScroller to make room for the stub view */
115: [vScroller getFrame:&scrollerRect];
116: NXDivideRect(&scrollerRect, &stubRect, NX_HEIGHT(&rulerRect), 1);
117: [vScroller setFrame:&scrollerRect];
118: [stubView setFrame:&stubRect];
119:
120: /* now make the hScroller smaller and stick the popupList next to it */
121: [hScroller getFrame:&scrollerRect];
122: NXDivideRect(&scrollerRect, &buttonRect, 60.0, 2);
123: [hScroller setFrame:&scrollerRect];
124: NXInsetRect(&buttonRect, 1.0, 1.0);
125: [popupListButton setFrame:&buttonRect];
126:
127: return self;
128: }
129:
130: - scrollClip:aClipView to:(NXPoint *)aPoint
131: {
132: NXPoint colOrigin;
133: NXRect colBounds;
134:
135: /* don't do anything if it's not the contentView */
136: if (aClipView != contentView) {
137: return self;
138: }
139:
140: /* turn off drawing (to the screen) */
141: [window disableFlushWindow];
142:
143: /* scroll the contentView to the new origin */
144: [aClipView rawScroll:aPoint];
145:
146: /* compute new origin for the rulerView (don't let it scroll vertically) */
147: [rulerClipView getBounds:&colBounds];
148: colOrigin.x = aPoint->x;
149: colOrigin.y = colBounds.origin.y;
150:
151: /* scroll the ruler view to that point */
152: [rulerClipView rawScroll:&colOrigin];
153:
154: /* send results to screen */
155: [[window reenableFlushWindow] flushWindow];
156:
157: return self;
158: }
159:
160: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.