forked from ttscoff/nv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ETClipView.m
70 lines (61 loc) · 2.46 KB
/
ETClipView.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
67
68
69
70
//
// TestClipView.m
// TestTextViewApp
//
// Created by elasticthreads on 8/15/11.
//
#import "ETClipView.h"
#import "GlobalPrefs.h"
#import "AppController.h"
@implementation ETClipView
- (id)initWithFrame:(NSRect)frameRect{
self = [super initWithFrame:frameRect];
if (self) {
[[GlobalPrefs defaultPrefs] registerForSettingChange:@selector(setMaxNoteBodyWidth:sender:) withTarget:self];
[[GlobalPrefs defaultPrefs] registerForSettingChange:@selector(setManagesTextWidthInWindow:sender:) withTarget:self];
}
return self;
}
//
-(void)setFrame:(NSRect)frameRect
{
NSRect docRect = [[self documentView] frame];
if (([[NSApp delegate]isInFullScreen])||([[GlobalPrefs defaultPrefs] managesTextWidthInWindow])) {
docRect.origin.x=0.0;
if (!NSEqualSizes(frameRect.size, [self frame].size)) {
CGFloat theMax=[[GlobalPrefs defaultPrefs] maxNoteBodyWidth]+(kTextMargins*2);
if (frameRect.size.width>=(theMax+(kTextMargins/5))){
CGFloat diff = frameRect.size.width-theMax;
diff=round(diff/2);
frameRect.origin.x=diff;
frameRect.size.width=theMax;
}
}
}
docRect.size.width=frameRect.size.width;
[[self documentView] setFrame:docRect];
[super setFrame:frameRect];
}
- (void)settingChangedForSelectorString:(NSString*)selectorString{
if (([selectorString isEqualToString:SEL_STR(setMaxNoteBodyWidth:sender:)])||([selectorString isEqualToString:SEL_STR(setManagesTextWidthInWindow:sender:)])){
NSRect aRect=[[[self documentView]enclosingScrollView] frame];
[self clipWidthSettingChanged:aRect];
}
}
- (void)clipWidthSettingChanged:(NSRect)frameRect{
NSRect docRect = [[self documentView] frame];
if (([[NSApp delegate]isInFullScreen])||([[GlobalPrefs defaultPrefs] managesTextWidthInWindow])) {
docRect.origin.x=0.0;
CGFloat theMax=[[GlobalPrefs defaultPrefs] maxNoteBodyWidth]+(kTextMargins*2);
if (frameRect.size.width>=(theMax+(kTextMargins/5))){
CGFloat diff = frameRect.size.width-theMax;
diff=round(diff/2);
frameRect.origin.x=diff;
frameRect.size.width=theMax;
}
}
docRect.size.width=frameRect.size.width;
[super setFrame:frameRect];
[[self documentView] setFrame:docRect];
}
@end