Skip to content

Commit 6168e9d

Browse files
Improvements to customs scrollers.
also fixed a bug where changing themes moves the insertion point.
1 parent e903b54 commit 6168e9d

8 files changed

+81
-45
lines changed

AppController.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2127,8 +2127,16 @@ - (void)titleUpdatedForNote:(NoteObject*)aNoteObject {
21272127

21282128
- (void)contentsUpdatedForNote:(NoteObject*)aNoteObject {
21292129
if (aNoteObject == currentNote) {
2130-
2130+
NSArray *selRanges=[textView selectedRanges];
21312131
[[textView textStorage] setAttributedString:[aNoteObject contentString]];
2132+
if (![selRanges isEqualToArray:[textView selectedRanges]]) {
2133+
NSRange testEnd=[[selRanges lastObject] rangeValue];
2134+
NSUInteger test=testEnd.location+testEnd.length;
2135+
2136+
if (test<=[textView string].length) {
2137+
[textView setSelectedRanges:selRanges];
2138+
}
2139+
}
21322140
[self postTextUpdate];
21332141
[self updateWordCount:(![prefsController showWordCount])];
21342142
}

BTTransparentScroller.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ - (void)drawKnobSlotInRect:(NSRect)slotRect highlight:(BOOL)flag{
4545
if (!IsLionOrLater) {
4646
[[NSColor whiteColor]set];
4747
NSRectFill([self bounds]);
48-
}else{
49-
[super drawKnobSlotInRect:slotRect highlight:flag];
5048
}
49+
//else{
50+
// [super drawKnobSlotInRect:slotRect highlight:flag];
51+
// }
5152
}
5253

5354
@end

ETClipView.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
@implementation ETClipView
1515

16-
17-
1816
- (id)initWithFrame:(NSRect)frameRect{
1917
self = [super initWithFrame:frameRect];
2018
if (self) {

ETContentView.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ - (void)dealloc
2929

3030
- (void)drawRect:(NSRect)dirtyRect
3131
{
32-
[super drawRect:dirtyRect];
32+
// [super drawRect:dirtyRect];
3333
if (!backColor) {
3434
backColor = [[[NSApp delegate] backgrndColor] retain];
3535
}

ETOverlayScroller.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ + (BOOL)isCompatibleWithOverlayScrollers {
1818

1919
- (id)initWithFrame:(NSRect)frameRect{
2020
if ((self=[super initWithFrame:frameRect])) {
21-
verticalPaddingLeft = 5.25f;
22-
verticalPaddingRight = 1.5f;
23-
knobAlpha=0.7f;
24-
slotAlpha=0.55f;
21+
verticalPaddingLeft = 5.0f;
22+
verticalPaddingRight = 2.5f;
23+
knobAlpha=0.6f;
24+
slotAlpha=0.55f;
25+
fillBackground=NO;
26+
isOverlay=YES;
2527
}
2628
return self;
2729
}

ETTransparentScroller.m

Lines changed: 51 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ - (id)initWithFrame:(NSRect)frameRect{
3030
slotTop = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"TransparentScrollerSlotTop.tif"]];
3131
slotVerticalFill = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"TransparentScrollerSlotVerticalFill.tif"]];
3232
slotBottom = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"TransparentScrollerSlotBottom.tif"]];
33-
verticalPaddingLeft = 3.0f;
34-
verticalPaddingRight = 3.75f;
33+
verticalPaddingLeft = 4.0f;
34+
verticalPaddingRight = 3.0f;
3535
verticalPaddingTop =3.75f;
3636
verticalPaddingBottom = 4.25f;
3737
minKnobHeight = knobTop.size.height + knobVerticalFill.size.height + knobBottom.size.height + 20.0;
@@ -93,12 +93,19 @@ - (void)drawRect:(NSRect)aRect;
9393
if (IsLionOrLater) {
9494
[super drawRect:aRect];
9595
}else{
96-
if (fillBackground) {
97-
[[[[self window] contentView] backgroundColor] setFill];
98-
NSRectFill([self bounds]);
99-
}
100-
if (([self bounds].size.height - verticalPaddingTop - verticalPaddingBottom + 1) > minKnobHeight)
101-
{
96+
if (([self bounds].size.height - verticalPaddingTop - verticalPaddingBottom + 1) > minKnobHeight){
97+
// if (fillBackground) {
98+
// [[[[self window] contentView] backgroundColor] setFill];
99+
// NSRectFill([self bounds]);
100+
// }
101+
// else if (isOverlay){
102+
// [[NSColor clearColor] setFill];
103+
// NSRectFill([self bounds]);
104+
// }
105+
if (fillBackground) {
106+
[[[[self window] contentView] backgroundColor] setFill];
107+
NSRectFill([self bounds]);
108+
}
102109
[self drawKnobSlotInRect:[self rectForPart:NSScrollerKnobSlot] highlight:NO];
103110

104111
if ([self knobProportion] > 0.0)
@@ -120,13 +127,16 @@ - (void)drawKnobSlotInRect:(NSRect)slotRect highlight:(BOOL)flag{
120127
// }else{
121128
// NSDrawThreePartImage(slotRect, slotTop, slotVerticalFill, slotBottom, YES, NSCompositeSourceOver, slotAlpha, NO);
122129
// }
130+
131+
123132
NSDrawThreePartImage(slotRect, slotTop, slotVerticalFill, slotBottom, YES, NSCompositeSourceOver, slotAlpha, NO);
133+
124134
}
125135

126136
- (void)drawKnob;
127137
{
128138
NSRect knobRect = [self rectForPart:NSScrollerKnob];
129-
139+
130140
NSDrawThreePartImage(knobRect, knobTop, knobVerticalFill, knobBottom, YES, NSCompositeSourceOver, knobAlpha, NO);
131141

132142
}
@@ -160,32 +170,41 @@ - (NSRect)rectForPart:(NSScrollerPart)aPart;
160170
}
161171
case NSScrollerKnob:
162172
{
163-
NSRect slotRect = [self rectForPart:NSScrollerKnobSlot];
164173
NSRect knobRect=[super rectForPart:NSScrollerKnob];
165-
166-
float knobHeight = roundf(slotRect.size.height * [self knobProportion]);
167-
if (knobHeight < minKnobHeight){
168-
if (minKnobHeight>slotRect.size.height) {
169-
knobHeight=knobRect.size.height;
170-
}else{
171-
knobHeight = minKnobHeight;
172-
}
174+
// NSRect slotRect = [self rectForPart:NSScrollerKnobSlot];
175+
// float knobHeight = roundf(slotRect.size.height * [self knobProportion]);
176+
// if (knobHeight < minKnobHeight){
177+
// if (minKnobHeight>slotRect.size.height) {
178+
// knobHeight=knobRect.size.height;
179+
// }else{
180+
// knobHeight = minKnobHeight;
181+
// }
182+
// }
183+
CGFloat slotY=roundf(verticalPaddingTop);
184+
CGFloat knobY=knobRect.origin.y;
185+
CGFloat slotHt=roundf([self bounds].size.height-(verticalPaddingTop+verticalPaddingBottom));
186+
if (knobY<slotY) {
187+
knobY=slotY;
173188
}
174-
175-
float knobY = slotRect.origin.y + roundf((slotRect.size.height - knobHeight) * [self floatValue]);
176-
knobRect = NSMakeRect(verticalPaddingLeft, knobY, slotRect.size.width, knobHeight);
177-
189+
else if ((knobY+knobRect.size.height)>(slotHt+slotY)){
190+
knobY=slotHt+slotY-knobRect.size.height;
191+
192+
}
193+
// knobRect = NSMakeRect(verticalPaddingLeft, knobY, slotRect.size.width, knobHeight);
194+
knobRect.origin.x=roundf(verticalPaddingLeft);
195+
knobRect.origin.y=roundf(knobY);
196+
knobRect.size.width=roundf([self bounds].size.width - verticalPaddingLeft - verticalPaddingRight);
178197

179198
return knobRect;
180199
}
181200
break;
182201
case NSScrollerKnobSlot:
183202
{
184-
NSRect slotRect=[super rectForPart:NSScrollerKnobSlot];
203+
NSRect slotRect=[self bounds];
185204
slotRect.origin.x=roundf(verticalPaddingLeft);
186-
slotRect.size.width=roundf([self bounds].size.width - verticalPaddingLeft - verticalPaddingRight);
205+
slotRect.size.width=roundf(slotRect.size.width - verticalPaddingLeft - verticalPaddingRight);
187206
slotRect.origin.y=roundf(verticalPaddingTop);
188-
slotRect.size.height=roundf(slotRect.size.height-verticalPaddingTop-verticalPaddingBottom);
207+
slotRect.size.height=roundf(slotRect.size.height-(verticalPaddingTop+verticalPaddingBottom));
189208
return slotRect;
190209
}
191210
break;
@@ -199,11 +218,12 @@ - (NSRect)rectForPart:(NSScrollerPart)aPart;
199218
{
200219
NSRect incrementPageRect;
201220
NSRect knobRect = [self rectForPart:NSScrollerKnob];
202-
NSRect slotRect = [self rectForPart:NSScrollerKnobSlot];
203-
NSRect decPageRect = [self rectForPart:NSScrollerDecrementPage];
204-
205-
float knobY = knobRect.origin.y + knobRect.size.height;
206-
incrementPageRect = NSMakeRect(verticalPaddingLeft, knobY, knobRect.size.width, slotRect.size.height - knobRect.size.height - decPageRect.size.height);
221+
// NSRect slotRect = [self rectForPart:NSScrollerKnobSlot];
222+
// NSRect decPageRect = [self rectForPart:NSScrollerDecrementPage];
223+
CGFloat slotHt=roundf([self bounds].size.height-(verticalPaddingTop+verticalPaddingBottom));
224+
CGFloat knobY = roundf(knobRect.origin.y + knobRect.size.height);
225+
CGFloat knobHt=roundf(slotHt - knobRect.size.height - knobRect.origin.y - verticalPaddingTop);
226+
incrementPageRect = NSMakeRect(roundf(verticalPaddingLeft), knobY, knobRect.size.width, knobHt);
207227

208228
return incrementPageRect;
209229
}
@@ -214,7 +234,7 @@ - (NSRect)rectForPart:(NSScrollerPart)aPart;
214234
NSRect knobRect = [self rectForPart:NSScrollerKnob];
215235

216236

217-
decrementPageRect = NSMakeRect(verticalPaddingLeft, verticalPaddingTop, knobRect.size.width, knobRect.origin.y - verticalPaddingTop);
237+
decrementPageRect = NSMakeRect(roundf(verticalPaddingLeft), roundf(verticalPaddingTop), knobRect.size.width, roundf(knobRect.origin.y - verticalPaddingTop));
218238

219239
return decrementPageRect;
220240
}

LinkingEditor.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,10 +1326,15 @@ - (void)setMouseInside:(BOOL)inside{
13261326
- (void)fixCursorForBackgroundUpdatingMouseInside:(BOOL)setMouseInside {
13271327

13281328
if (IsLeopardOrLater && whiteIBeamCursorIMP && defaultIBeamCursorIMP) {
1329-
NSRect aRect=NSZeroRect;
1330-
aRect.origin=[NSEvent mouseLocation];
1331-
aRect=[[self window] convertRectFromScreen:aRect];
1332-
NSPoint local_point = [self convertPoint:aRect.origin fromView:nil];
1329+
NSPoint local_point;
1330+
if (IsLionOrLater) {
1331+
NSRect aRect=NSZeroRect;
1332+
aRect.origin=[NSEvent mouseLocation];
1333+
aRect=[[self window] convertRectFromScreen:aRect];
1334+
local_point = [self convertPoint:aRect.origin fromView:nil];
1335+
}else{
1336+
local_point=[[self window]convertScreenToBase:[NSEvent mouseLocation]];
1337+
}
13331338
NSRect bnds=[self visibleRect];
13341339
if ([self textFinderIsVisible]&&(local_point.y<3.0)) {
13351340
mouseInside=NO;

PreviewController.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,12 @@ -(void)awakeFromNib
161161
lastNote = [[NSApp delegate] selectedNoteObject];
162162
[sourceView setTextContainerInset:NSMakeSize(10.0,12.0)];
163163
NSScrollView *scrlView=[sourceView enclosingScrollView];
164+
if (!IsLionOrLater) {
164165
NSRect vsRect=[[scrlView verticalScroller]frame];
165166
BTTransparentScroller *theScroller=[[BTTransparentScroller alloc]initWithFrame:vsRect];
166167
[scrlView setVerticalScroller:theScroller];
167168
[theScroller release];
169+
}
168170
[scrlView setScrollsDynamically:YES];
169171
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
170172
if (IsLionOrLater) {

0 commit comments

Comments
 (0)