-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
ETClipView.m
99 lines (90 loc) · 3.49 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// ETClipView.m
// nvALT
//
// Created by elasticthreads on 8/15/11.
//
#import "ETClipView.h"
#import "GlobalPrefs.h"
#import "AppController.h"
#import "LinkingEditor.h"
@implementation ETClipView
- (id)initWithFrame:(NSRect)frameRect{
self = [super initWithFrame:frameRect];
if (self) {
managesTextWidth=[[GlobalPrefs defaultPrefs] managesTextWidthInWindow];
[[GlobalPrefs defaultPrefs] registerForSettingChange:@selector(setMaxNoteBodyWidth:sender:) withTarget:self];
[[GlobalPrefs defaultPrefs] registerForSettingChange:@selector(setManagesTextWidthInWindow:sender:) withTarget:self];
}
return self;
}
//
-(void)setFrame:(NSRect)frameRect{
if (managesTextWidth||([[NSApp delegate]isInFullScreen])) {
if (frameRect.size.width!=[self frame].size.width) {
NSRect clipRect;
NSRect docRect = [[self documentView] frame];
if ([self clipRect:&clipRect forFrameRect:frameRect]) {
frameRect=clipRect;
// docRect.origin.x=0.0;
docRect.size.width=frameRect.size.width;
// [[self documentView] setFrame:docRect];
[[self documentView] setConstrainedFrameSize:docRect.size];
}else if (docRect.size.width>[self frame].size.width){
// NSLog(@"problem");
docRect.size.width=[self frame].size.width;
[[self documentView] setConstrainedFrameSize:docRect.size];
}
}
}
[super setFrame:frameRect];
}
- (BOOL)clipRect:(NSRect *)clipRect forFrameRect:(NSRect)frameRect{
CGFloat theMax=[[GlobalPrefs defaultPrefs] maxNoteBodyWidth]+(kTextMargins*2);
if (frameRect.size.width>=(theMax+(kTextMargins/5))){
CGFloat diff = fabs(frameRect.size.width-theMax);
diff=round(diff/2);
frameRect.origin.x=diff;
frameRect.size.width=theMax;
*clipRect=frameRect;
return YES;
}
return NO;
}
- (BOOL)clipWidthSettingChanged:(NSRect)frameRect{
NSRect clipRect;
NSRect docRect = [[self documentView] frame];
if ([self clipRect:&clipRect forFrameRect:frameRect]) {
frameRect=clipRect;
docRect.size.width=frameRect.size.width;
[[self documentView] setConstrainedFrameSize:docRect.size];
[super setFrame:frameRect];
return YES;
}else{
NSScrollView *scrollV=[[self documentView] enclosingScrollView];
CGFloat numba=scrollV.frame.size.width;
if (![[scrollV verticalScroller] isHidden]) {
numba-=[[scrollV verticalScroller]frame].size.width;
}
if (numba>frameRect.size.width) {
frameRect.size.width=numba;
[self setFrame:frameRect];
return YES;
}
}
return NO;
}
- (void)settingChangedForSelectorString:(NSString*)selectorString{
if (([selectorString isEqualToString:SEL_STR(setMaxNoteBodyWidth:sender:)])||([selectorString isEqualToString:SEL_STR(setManagesTextWidthInWindow:sender:)])){
if ([selectorString isEqualToString:SEL_STR(setManagesTextWidthInWindow:sender:)]) {
managesTextWidth=[[GlobalPrefs defaultPrefs] managesTextWidthInWindow];
[[self documentView] setManagesTextWidth:managesTextWidth];
}
if (!managesTextWidth){
[[self documentView]resetInset];
}else if(![self clipWidthSettingChanged:[self frame]]) {
[[self documentView]updateInsetAndForceLayout:YES];
}
}
}
@end