-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZoomScrollView.m
executable file
·66 lines (55 loc) · 1.91 KB
/
ZoomScrollView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Methoden entnommen "Objective-C und Cocoa", seite 259 ff
#import "ZoomScrollView.h"
@implementation ZoomScrollView
-(void)awakeFromNib
{
NSPopUpButton *zoomButton;
if (!zoomMenu)
{
return;
}
zoomButton =[[[NSPopUpButton alloc] init] autorelease];
[zoomButton setTag:'ZOOM'];
[zoomButton setMenu:zoomMenu];
[zoomButton selectItem:[zoomMenu itemWithTag:100]];
NSButtonCell* zoomCell = [zoomButton cell];
[zoomCell setControlSize:NSMiniControlSize];
[zoomCell setAlignment:NSRightTextAlignment];
[zoomCell setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]]];
[zoomCell setBordered:YES];
[zoomCell setBezeled:YES];
[zoomCell setBezelStyle:NSSmallSquareBezelStyle];
[zoomButton setAction:@selector(receiveZoomLevelFrom:)];
[zoomButton setTarget:self];
[self addSubview:zoomButton];
[self setAutohidesScrollers:NO];
// NSLog(@"zoom %@", [self documentView]);
//Scrollbars setzen, so da§ die Grafik bei 100% zentriert erscheint
NSView *documentView = [self documentView];
[documentView scrollPoint:NSMakePoint(-25.0,-50.0)];
}
-(void)tile
{
NSRect zoomRect, scrollerRect;
[super tile];
scrollerRect = [[self horizontalScroller]frame];
NSDivideRect(scrollerRect, &zoomRect, &scrollerRect, 55.0, NSMinXEdge);
[[self viewWithTag:'ZOOM'] setFrame:zoomRect];
[[self horizontalScroller] setFrame:scrollerRect];
}
-(void)receiveZoomLevelFrom:(id)sender
{
NSView *documentView = [self documentView];
if ([sender isMemberOfClass:[NSPopUpButton class]])
{
NSRect bounds = [documentView bounds];
NSSize frameSize = [documentView frame].size;
frameSize.width = bounds.size.width * ((float)[[sender selectedItem]tag]) / 100.0;
frameSize.height = bounds.size.height * ((float)[[sender selectedItem]tag]) / 100.0;
[documentView setFrameSize:frameSize];
[documentView setBounds:bounds];
[self setDocumentView: documentView];
[[self contentView] setNeedsDisplay:YES];
}
}
@end