Permalink
Browse files

Improvements to customs scrollers.

also fixed a bug where changing themes moves the insertion point.
  • Loading branch information...
1 parent e903b54 commit 6168e9d6513beb54d25263cf05c0ac7b9cb49795 @elasticthreads elasticthreads committed Apr 12, 2013
Showing with 81 additions and 45 deletions.
  1. +9 −1 AppController.m
  2. +3 −2 BTTransparentScroller.m
  3. +0 −2 ETClipView.m
  4. +1 −1 ETContentView.m
  5. +6 −4 ETOverlayScroller.m
  6. +51 −31 ETTransparentScroller.m
  7. +9 −4 LinkingEditor.m
  8. +2 −0 PreviewController.m
View
@@ -2127,8 +2127,16 @@ - (void)titleUpdatedForNote:(NoteObject*)aNoteObject {
- (void)contentsUpdatedForNote:(NoteObject*)aNoteObject {
if (aNoteObject == currentNote) {
-
+ NSArray *selRanges=[textView selectedRanges];
[[textView textStorage] setAttributedString:[aNoteObject contentString]];
+ if (![selRanges isEqualToArray:[textView selectedRanges]]) {
+ NSRange testEnd=[[selRanges lastObject] rangeValue];
+ NSUInteger test=testEnd.location+testEnd.length;
+
+ if (test<=[textView string].length) {
+ [textView setSelectedRanges:selRanges];
+ }
+ }
[self postTextUpdate];
[self updateWordCount:(![prefsController showWordCount])];
}
View
@@ -45,9 +45,10 @@ - (void)drawKnobSlotInRect:(NSRect)slotRect highlight:(BOOL)flag{
if (!IsLionOrLater) {
[[NSColor whiteColor]set];
NSRectFill([self bounds]);
- }else{
- [super drawKnobSlotInRect:slotRect highlight:flag];
}
+ //else{
+// [super drawKnobSlotInRect:slotRect highlight:flag];
+ // }
}
@end
View
@@ -13,8 +13,6 @@
@implementation ETClipView
-
-
- (id)initWithFrame:(NSRect)frameRect{
self = [super initWithFrame:frameRect];
if (self) {
View
@@ -29,7 +29,7 @@ - (void)dealloc
- (void)drawRect:(NSRect)dirtyRect
{
- [super drawRect:dirtyRect];
+// [super drawRect:dirtyRect];
if (!backColor) {
backColor = [[[NSApp delegate] backgrndColor] retain];
}
View
@@ -18,10 +18,12 @@ + (BOOL)isCompatibleWithOverlayScrollers {
- (id)initWithFrame:(NSRect)frameRect{
if ((self=[super initWithFrame:frameRect])) {
- verticalPaddingLeft = 5.25f;
- verticalPaddingRight = 1.5f;
- knobAlpha=0.7f;
- slotAlpha=0.55f;
+ verticalPaddingLeft = 5.0f;
+ verticalPaddingRight = 2.5f;
+ knobAlpha=0.6f;
+ slotAlpha=0.55f;
+ fillBackground=NO;
+ isOverlay=YES;
}
return self;
}
View
@@ -30,8 +30,8 @@ - (id)initWithFrame:(NSRect)frameRect{
slotTop = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"TransparentScrollerSlotTop.tif"]];
slotVerticalFill = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"TransparentScrollerSlotVerticalFill.tif"]];
slotBottom = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"TransparentScrollerSlotBottom.tif"]];
- verticalPaddingLeft = 3.0f;
- verticalPaddingRight = 3.75f;
+ verticalPaddingLeft = 4.0f;
+ verticalPaddingRight = 3.0f;
verticalPaddingTop =3.75f;
verticalPaddingBottom = 4.25f;
minKnobHeight = knobTop.size.height + knobVerticalFill.size.height + knobBottom.size.height + 20.0;
@@ -93,12 +93,19 @@ - (void)drawRect:(NSRect)aRect;
if (IsLionOrLater) {
[super drawRect:aRect];
}else{
- if (fillBackground) {
- [[[[self window] contentView] backgroundColor] setFill];
- NSRectFill([self bounds]);
- }
- if (([self bounds].size.height - verticalPaddingTop - verticalPaddingBottom + 1) > minKnobHeight)
- {
+ if (([self bounds].size.height - verticalPaddingTop - verticalPaddingBottom + 1) > minKnobHeight){
+// if (fillBackground) {
+// [[[[self window] contentView] backgroundColor] setFill];
+// NSRectFill([self bounds]);
+// }
+// else if (isOverlay){
+// [[NSColor clearColor] setFill];
+// NSRectFill([self bounds]);
+// }
+ if (fillBackground) {
+ [[[[self window] contentView] backgroundColor] setFill];
+ NSRectFill([self bounds]);
+ }
[self drawKnobSlotInRect:[self rectForPart:NSScrollerKnobSlot] highlight:NO];
if ([self knobProportion] > 0.0)
@@ -120,13 +127,16 @@ - (void)drawKnobSlotInRect:(NSRect)slotRect highlight:(BOOL)flag{
// }else{
// NSDrawThreePartImage(slotRect, slotTop, slotVerticalFill, slotBottom, YES, NSCompositeSourceOver, slotAlpha, NO);
// }
+
+
NSDrawThreePartImage(slotRect, slotTop, slotVerticalFill, slotBottom, YES, NSCompositeSourceOver, slotAlpha, NO);
+
}
- (void)drawKnob;
{
NSRect knobRect = [self rectForPart:NSScrollerKnob];
-
+
NSDrawThreePartImage(knobRect, knobTop, knobVerticalFill, knobBottom, YES, NSCompositeSourceOver, knobAlpha, NO);
}
@@ -160,32 +170,41 @@ - (NSRect)rectForPart:(NSScrollerPart)aPart;
}
case NSScrollerKnob:
{
- NSRect slotRect = [self rectForPart:NSScrollerKnobSlot];
NSRect knobRect=[super rectForPart:NSScrollerKnob];
-
- float knobHeight = roundf(slotRect.size.height * [self knobProportion]);
- if (knobHeight < minKnobHeight){
- if (minKnobHeight>slotRect.size.height) {
- knobHeight=knobRect.size.height;
- }else{
- knobHeight = minKnobHeight;
- }
+// NSRect slotRect = [self rectForPart:NSScrollerKnobSlot];
+// float knobHeight = roundf(slotRect.size.height * [self knobProportion]);
+// if (knobHeight < minKnobHeight){
+// if (minKnobHeight>slotRect.size.height) {
+// knobHeight=knobRect.size.height;
+// }else{
+// knobHeight = minKnobHeight;
+// }
+// }
+ CGFloat slotY=roundf(verticalPaddingTop);
+ CGFloat knobY=knobRect.origin.y;
+ CGFloat slotHt=roundf([self bounds].size.height-(verticalPaddingTop+verticalPaddingBottom));
+ if (knobY<slotY) {
+ knobY=slotY;
}
-
- float knobY = slotRect.origin.y + roundf((slotRect.size.height - knobHeight) * [self floatValue]);
- knobRect = NSMakeRect(verticalPaddingLeft, knobY, slotRect.size.width, knobHeight);
-
+ else if ((knobY+knobRect.size.height)>(slotHt+slotY)){
+ knobY=slotHt+slotY-knobRect.size.height;
+
+ }
+// knobRect = NSMakeRect(verticalPaddingLeft, knobY, slotRect.size.width, knobHeight);
+ knobRect.origin.x=roundf(verticalPaddingLeft);
+ knobRect.origin.y=roundf(knobY);
+ knobRect.size.width=roundf([self bounds].size.width - verticalPaddingLeft - verticalPaddingRight);
return knobRect;
}
break;
case NSScrollerKnobSlot:
{
- NSRect slotRect=[super rectForPart:NSScrollerKnobSlot];
+ NSRect slotRect=[self bounds];
slotRect.origin.x=roundf(verticalPaddingLeft);
- slotRect.size.width=roundf([self bounds].size.width - verticalPaddingLeft - verticalPaddingRight);
+ slotRect.size.width=roundf(slotRect.size.width - verticalPaddingLeft - verticalPaddingRight);
slotRect.origin.y=roundf(verticalPaddingTop);
- slotRect.size.height=roundf(slotRect.size.height-verticalPaddingTop-verticalPaddingBottom);
+ slotRect.size.height=roundf(slotRect.size.height-(verticalPaddingTop+verticalPaddingBottom));
return slotRect;
}
break;
@@ -199,11 +218,12 @@ - (NSRect)rectForPart:(NSScrollerPart)aPart;
{
NSRect incrementPageRect;
NSRect knobRect = [self rectForPart:NSScrollerKnob];
- NSRect slotRect = [self rectForPart:NSScrollerKnobSlot];
- NSRect decPageRect = [self rectForPart:NSScrollerDecrementPage];
-
- float knobY = knobRect.origin.y + knobRect.size.height;
- incrementPageRect = NSMakeRect(verticalPaddingLeft, knobY, knobRect.size.width, slotRect.size.height - knobRect.size.height - decPageRect.size.height);
+// NSRect slotRect = [self rectForPart:NSScrollerKnobSlot];
+// NSRect decPageRect = [self rectForPart:NSScrollerDecrementPage];
+ CGFloat slotHt=roundf([self bounds].size.height-(verticalPaddingTop+verticalPaddingBottom));
+ CGFloat knobY = roundf(knobRect.origin.y + knobRect.size.height);
+ CGFloat knobHt=roundf(slotHt - knobRect.size.height - knobRect.origin.y - verticalPaddingTop);
+ incrementPageRect = NSMakeRect(roundf(verticalPaddingLeft), knobY, knobRect.size.width, knobHt);
return incrementPageRect;
}
@@ -214,7 +234,7 @@ - (NSRect)rectForPart:(NSScrollerPart)aPart;
NSRect knobRect = [self rectForPart:NSScrollerKnob];
- decrementPageRect = NSMakeRect(verticalPaddingLeft, verticalPaddingTop, knobRect.size.width, knobRect.origin.y - verticalPaddingTop);
+ decrementPageRect = NSMakeRect(roundf(verticalPaddingLeft), roundf(verticalPaddingTop), knobRect.size.width, roundf(knobRect.origin.y - verticalPaddingTop));
return decrementPageRect;
}
View
@@ -1326,10 +1326,15 @@ - (void)setMouseInside:(BOOL)inside{
- (void)fixCursorForBackgroundUpdatingMouseInside:(BOOL)setMouseInside {
if (IsLeopardOrLater && whiteIBeamCursorIMP && defaultIBeamCursorIMP) {
- NSRect aRect=NSZeroRect;
- aRect.origin=[NSEvent mouseLocation];
- aRect=[[self window] convertRectFromScreen:aRect];
- NSPoint local_point = [self convertPoint:aRect.origin fromView:nil];
+ NSPoint local_point;
+ if (IsLionOrLater) {
+ NSRect aRect=NSZeroRect;
+ aRect.origin=[NSEvent mouseLocation];
+ aRect=[[self window] convertRectFromScreen:aRect];
+ local_point = [self convertPoint:aRect.origin fromView:nil];
+ }else{
+ local_point=[[self window]convertScreenToBase:[NSEvent mouseLocation]];
+ }
NSRect bnds=[self visibleRect];
if ([self textFinderIsVisible]&&(local_point.y<3.0)) {
mouseInside=NO;
View
@@ -161,10 +161,12 @@ -(void)awakeFromNib
lastNote = [[NSApp delegate] selectedNoteObject];
[sourceView setTextContainerInset:NSMakeSize(10.0,12.0)];
NSScrollView *scrlView=[sourceView enclosingScrollView];
+ if (!IsLionOrLater) {
NSRect vsRect=[[scrlView verticalScroller]frame];
BTTransparentScroller *theScroller=[[BTTransparentScroller alloc]initWithFrame:vsRect];
[scrlView setVerticalScroller:theScroller];
[theScroller release];
+ }
[scrlView setScrollsDynamically:YES];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
if (IsLionOrLater) {

0 comments on commit 6168e9d

Please sign in to comment.