diff options
Diffstat (limited to 'cocoa/ScintillaCocoa.mm')
| -rw-r--r-- | cocoa/ScintillaCocoa.mm | 2712 |
1 files changed, 1273 insertions, 1439 deletions
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index 3fa0904bb..eeb0daf8f 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -28,7 +28,7 @@ using namespace Scintilla; -NSString* ScintillaRecPboardType = @"com.scintilla.utf16-plain-text.rectangular"; +NSString *ScintillaRecPboardType = @"com.scintilla.utf16-plain-text.rectangular"; //-------------------------------------------------------------------------------------------------- @@ -37,100 +37,99 @@ NSString* ScintillaRecPboardType = @"com.scintilla.utf16-plain-text.rectangular" #define SCI_SCMD ( SCI_CMD | SCI_SHIFT) #define SCI_SMETA ( SCI_META | SCI_SHIFT) -static const KeyToCommand macMapDefault[] = -{ - // OS X specific - {SCK_DOWN, SCI_CTRL, SCI_DOCUMENTEND}, - {SCK_DOWN, SCI_CSHIFT, SCI_DOCUMENTENDEXTEND}, - {SCK_UP, SCI_CTRL, SCI_DOCUMENTSTART}, - {SCK_UP, SCI_CSHIFT, SCI_DOCUMENTSTARTEXTEND}, - {SCK_LEFT, SCI_CTRL, SCI_VCHOME}, - {SCK_LEFT, SCI_CSHIFT, SCI_VCHOMEEXTEND}, - {SCK_RIGHT, SCI_CTRL, SCI_LINEEND}, - {SCK_RIGHT, SCI_CSHIFT, SCI_LINEENDEXTEND}, - - // Similar to Windows and GTK+ - // Where equivalent clashes with OS X standard, use Meta instead - {SCK_DOWN, SCI_NORM, SCI_LINEDOWN}, - {SCK_DOWN, SCI_SHIFT, SCI_LINEDOWNEXTEND}, - {SCK_DOWN, SCI_META, SCI_LINESCROLLDOWN}, - {SCK_DOWN, SCI_ASHIFT, SCI_LINEDOWNRECTEXTEND}, - {SCK_UP, SCI_NORM, SCI_LINEUP}, - {SCK_UP, SCI_SHIFT, SCI_LINEUPEXTEND}, - {SCK_UP, SCI_META, SCI_LINESCROLLUP}, - {SCK_UP, SCI_ASHIFT, SCI_LINEUPRECTEXTEND}, - {'[', SCI_CTRL, SCI_PARAUP}, - {'[', SCI_CSHIFT, SCI_PARAUPEXTEND}, - {']', SCI_CTRL, SCI_PARADOWN}, - {']', SCI_CSHIFT, SCI_PARADOWNEXTEND}, - {SCK_LEFT, SCI_NORM, SCI_CHARLEFT}, - {SCK_LEFT, SCI_SHIFT, SCI_CHARLEFTEXTEND}, - {SCK_LEFT, SCI_ALT, SCI_WORDLEFT}, - {SCK_LEFT, SCI_META, SCI_WORDLEFT}, - {SCK_LEFT, SCI_SMETA, SCI_WORDLEFTEXTEND}, - {SCK_LEFT, SCI_ASHIFT, SCI_CHARLEFTRECTEXTEND}, - {SCK_RIGHT, SCI_NORM, SCI_CHARRIGHT}, - {SCK_RIGHT, SCI_SHIFT, SCI_CHARRIGHTEXTEND}, - {SCK_RIGHT, SCI_ALT, SCI_WORDRIGHT}, - {SCK_RIGHT, SCI_META, SCI_WORDRIGHT}, - {SCK_RIGHT, SCI_SMETA, SCI_WORDRIGHTEXTEND}, - {SCK_RIGHT, SCI_ASHIFT, SCI_CHARRIGHTRECTEXTEND}, - {'/', SCI_CTRL, SCI_WORDPARTLEFT}, - {'/', SCI_CSHIFT, SCI_WORDPARTLEFTEXTEND}, - {'\\', SCI_CTRL, SCI_WORDPARTRIGHT}, - {'\\', SCI_CSHIFT, SCI_WORDPARTRIGHTEXTEND}, - {SCK_HOME, SCI_NORM, SCI_VCHOME}, - {SCK_HOME, SCI_SHIFT, SCI_VCHOMEEXTEND}, - {SCK_HOME, SCI_CTRL, SCI_DOCUMENTSTART}, - {SCK_HOME, SCI_CSHIFT, SCI_DOCUMENTSTARTEXTEND}, - {SCK_HOME, SCI_ALT, SCI_HOMEDISPLAY}, - {SCK_HOME, SCI_ASHIFT, SCI_VCHOMERECTEXTEND}, - {SCK_END, SCI_NORM, SCI_LINEEND}, - {SCK_END, SCI_SHIFT, SCI_LINEENDEXTEND}, - {SCK_END, SCI_CTRL, SCI_DOCUMENTEND}, - {SCK_END, SCI_CSHIFT, SCI_DOCUMENTENDEXTEND}, - {SCK_END, SCI_ALT, SCI_LINEENDDISPLAY}, - {SCK_END, SCI_ASHIFT, SCI_LINEENDRECTEXTEND}, - {SCK_PRIOR, SCI_NORM, SCI_PAGEUP}, - {SCK_PRIOR, SCI_SHIFT, SCI_PAGEUPEXTEND}, - {SCK_PRIOR, SCI_ASHIFT, SCI_PAGEUPRECTEXTEND}, - {SCK_NEXT, SCI_NORM, SCI_PAGEDOWN}, - {SCK_NEXT, SCI_SHIFT, SCI_PAGEDOWNEXTEND}, - {SCK_NEXT, SCI_ASHIFT, SCI_PAGEDOWNRECTEXTEND}, - {SCK_DELETE, SCI_NORM, SCI_CLEAR}, - {SCK_DELETE, SCI_SHIFT, SCI_CUT}, - {SCK_DELETE, SCI_CTRL, SCI_DELWORDRIGHT}, - {SCK_DELETE, SCI_CSHIFT, SCI_DELLINERIGHT}, - {SCK_INSERT, SCI_NORM, SCI_EDITTOGGLEOVERTYPE}, - {SCK_INSERT, SCI_SHIFT, SCI_PASTE}, - {SCK_INSERT, SCI_CTRL, SCI_COPY}, - {SCK_ESCAPE, SCI_NORM, SCI_CANCEL}, - {SCK_BACK, SCI_NORM, SCI_DELETEBACK}, - {SCK_BACK, SCI_SHIFT, SCI_DELETEBACK}, - {SCK_BACK, SCI_CTRL, SCI_DELWORDLEFT}, - {SCK_BACK, SCI_ALT, SCI_DELWORDLEFT}, - {SCK_BACK, SCI_CSHIFT, SCI_DELLINELEFT}, - {'z', SCI_CMD, SCI_UNDO}, - {'z', SCI_SCMD, SCI_REDO}, - {'x', SCI_CMD, SCI_CUT}, - {'c', SCI_CMD, SCI_COPY}, - {'v', SCI_CMD, SCI_PASTE}, - {'a', SCI_CMD, SCI_SELECTALL}, - {SCK_TAB, SCI_NORM, SCI_TAB}, - {SCK_TAB, SCI_SHIFT, SCI_BACKTAB}, - {SCK_RETURN, SCI_NORM, SCI_NEWLINE}, - {SCK_RETURN, SCI_SHIFT, SCI_NEWLINE}, - {SCK_ADD, SCI_CMD, SCI_ZOOMIN}, - {SCK_SUBTRACT, SCI_CMD, SCI_ZOOMOUT}, - {SCK_DIVIDE, SCI_CMD, SCI_SETZOOM}, - {'l', SCI_CMD, SCI_LINECUT}, - {'l', SCI_CSHIFT, SCI_LINEDELETE}, - {'t', SCI_CSHIFT, SCI_LINECOPY}, - {'t', SCI_CTRL, SCI_LINETRANSPOSE}, - {'d', SCI_CTRL, SCI_SELECTIONDUPLICATE}, - {'u', SCI_CTRL, SCI_LOWERCASE}, - {'u', SCI_CSHIFT, SCI_UPPERCASE}, - {0, 0, 0}, +static const KeyToCommand macMapDefault[] = { + // OS X specific + {SCK_DOWN, SCI_CTRL, SCI_DOCUMENTEND}, + {SCK_DOWN, SCI_CSHIFT, SCI_DOCUMENTENDEXTEND}, + {SCK_UP, SCI_CTRL, SCI_DOCUMENTSTART}, + {SCK_UP, SCI_CSHIFT, SCI_DOCUMENTSTARTEXTEND}, + {SCK_LEFT, SCI_CTRL, SCI_VCHOME}, + {SCK_LEFT, SCI_CSHIFT, SCI_VCHOMEEXTEND}, + {SCK_RIGHT, SCI_CTRL, SCI_LINEEND}, + {SCK_RIGHT, SCI_CSHIFT, SCI_LINEENDEXTEND}, + + // Similar to Windows and GTK+ + // Where equivalent clashes with OS X standard, use Meta instead + {SCK_DOWN, SCI_NORM, SCI_LINEDOWN}, + {SCK_DOWN, SCI_SHIFT, SCI_LINEDOWNEXTEND}, + {SCK_DOWN, SCI_META, SCI_LINESCROLLDOWN}, + {SCK_DOWN, SCI_ASHIFT, SCI_LINEDOWNRECTEXTEND}, + {SCK_UP, SCI_NORM, SCI_LINEUP}, + {SCK_UP, SCI_SHIFT, SCI_LINEUPEXTEND}, + {SCK_UP, SCI_META, SCI_LINESCROLLUP}, + {SCK_UP, SCI_ASHIFT, SCI_LINEUPRECTEXTEND}, + {'[', SCI_CTRL, SCI_PARAUP}, + {'[', SCI_CSHIFT, SCI_PARAUPEXTEND}, + {']', SCI_CTRL, SCI_PARADOWN}, + {']', SCI_CSHIFT, SCI_PARADOWNEXTEND}, + {SCK_LEFT, SCI_NORM, SCI_CHARLEFT}, + {SCK_LEFT, SCI_SHIFT, SCI_CHARLEFTEXTEND}, + {SCK_LEFT, SCI_ALT, SCI_WORDLEFT}, + {SCK_LEFT, SCI_META, SCI_WORDLEFT}, + {SCK_LEFT, SCI_SMETA, SCI_WORDLEFTEXTEND}, + {SCK_LEFT, SCI_ASHIFT, SCI_CHARLEFTRECTEXTEND}, + {SCK_RIGHT, SCI_NORM, SCI_CHARRIGHT}, + {SCK_RIGHT, SCI_SHIFT, SCI_CHARRIGHTEXTEND}, + {SCK_RIGHT, SCI_ALT, SCI_WORDRIGHT}, + {SCK_RIGHT, SCI_META, SCI_WORDRIGHT}, + {SCK_RIGHT, SCI_SMETA, SCI_WORDRIGHTEXTEND}, + {SCK_RIGHT, SCI_ASHIFT, SCI_CHARRIGHTRECTEXTEND}, + {'/', SCI_CTRL, SCI_WORDPARTLEFT}, + {'/', SCI_CSHIFT, SCI_WORDPARTLEFTEXTEND}, + {'\\', SCI_CTRL, SCI_WORDPARTRIGHT}, + {'\\', SCI_CSHIFT, SCI_WORDPARTRIGHTEXTEND}, + {SCK_HOME, SCI_NORM, SCI_VCHOME}, + {SCK_HOME, SCI_SHIFT, SCI_VCHOMEEXTEND}, + {SCK_HOME, SCI_CTRL, SCI_DOCUMENTSTART}, + {SCK_HOME, SCI_CSHIFT, SCI_DOCUMENTSTARTEXTEND}, + {SCK_HOME, SCI_ALT, SCI_HOMEDISPLAY}, + {SCK_HOME, SCI_ASHIFT, SCI_VCHOMERECTEXTEND}, + {SCK_END, SCI_NORM, SCI_LINEEND}, + {SCK_END, SCI_SHIFT, SCI_LINEENDEXTEND}, + {SCK_END, SCI_CTRL, SCI_DOCUMENTEND}, + {SCK_END, SCI_CSHIFT, SCI_DOCUMENTENDEXTEND}, + {SCK_END, SCI_ALT, SCI_LINEENDDISPLAY}, + {SCK_END, SCI_ASHIFT, SCI_LINEENDRECTEXTEND}, + {SCK_PRIOR, SCI_NORM, SCI_PAGEUP}, + {SCK_PRIOR, SCI_SHIFT, SCI_PAGEUPEXTEND}, + {SCK_PRIOR, SCI_ASHIFT, SCI_PAGEUPRECTEXTEND}, + {SCK_NEXT, SCI_NORM, SCI_PAGEDOWN}, + {SCK_NEXT, SCI_SHIFT, SCI_PAGEDOWNEXTEND}, + {SCK_NEXT, SCI_ASHIFT, SCI_PAGEDOWNRECTEXTEND}, + {SCK_DELETE, SCI_NORM, SCI_CLEAR}, + {SCK_DELETE, SCI_SHIFT, SCI_CUT}, + {SCK_DELETE, SCI_CTRL, SCI_DELWORDRIGHT}, + {SCK_DELETE, SCI_CSHIFT, SCI_DELLINERIGHT}, + {SCK_INSERT, SCI_NORM, SCI_EDITTOGGLEOVERTYPE}, + {SCK_INSERT, SCI_SHIFT, SCI_PASTE}, + {SCK_INSERT, SCI_CTRL, SCI_COPY}, + {SCK_ESCAPE, SCI_NORM, SCI_CANCEL}, + {SCK_BACK, SCI_NORM, SCI_DELETEBACK}, + {SCK_BACK, SCI_SHIFT, SCI_DELETEBACK}, + {SCK_BACK, SCI_CTRL, SCI_DELWORDLEFT}, + {SCK_BACK, SCI_ALT, SCI_DELWORDLEFT}, + {SCK_BACK, SCI_CSHIFT, SCI_DELLINELEFT}, + {'z', SCI_CMD, SCI_UNDO}, + {'z', SCI_SCMD, SCI_REDO}, + {'x', SCI_CMD, SCI_CUT}, + {'c', SCI_CMD, SCI_COPY}, + {'v', SCI_CMD, SCI_PASTE}, + {'a', SCI_CMD, SCI_SELECTALL}, + {SCK_TAB, SCI_NORM, SCI_TAB}, + {SCK_TAB, SCI_SHIFT, SCI_BACKTAB}, + {SCK_RETURN, SCI_NORM, SCI_NEWLINE}, + {SCK_RETURN, SCI_SHIFT, SCI_NEWLINE}, + {SCK_ADD, SCI_CMD, SCI_ZOOMIN}, + {SCK_SUBTRACT, SCI_CMD, SCI_ZOOMOUT}, + {SCK_DIVIDE, SCI_CMD, SCI_SETZOOM}, + {'l', SCI_CMD, SCI_LINECUT}, + {'l', SCI_CSHIFT, SCI_LINEDELETE}, + {'t', SCI_CSHIFT, SCI_LINECOPY}, + {'t', SCI_CTRL, SCI_LINETRANSPOSE}, + {'d', SCI_CTRL, SCI_SELECTIONDUPLICATE}, + {'u', SCI_CTRL, SCI_LOWERCASE}, + {'u', SCI_CSHIFT, SCI_UPPERCASE}, + {0, 0, 0}, }; //-------------------------------------------------------------------------------------------------- @@ -142,8 +141,7 @@ static const KeyToCommand macMapDefault[] = /** * Class to display the animated gold roundrect used on OS X for matches. */ -@interface FindHighlightLayer : CAGradientLayer -{ +@interface FindHighlightLayer : CAGradientLayer { @private NSString *sFind; int positionFind; @@ -154,15 +152,15 @@ static const KeyToCommand macMapDefault[] = CGFloat fontSize; } -@property (copy) NSString *sFind; -@property (assign) int positionFind; -@property (assign) BOOL retaining; -@property (assign) CGFloat widthText; -@property (assign) CGFloat heightLine; -@property (copy) NSString *sFont; -@property (assign) CGFloat fontSize; +@property(copy) NSString *sFind; +@property(assign) int positionFind; +@property(assign) BOOL retaining; +@property(assign) CGFloat widthText; +@property(assign) CGFloat heightLine; +@property(copy) NSString *sFont; +@property(assign) CGFloat fontSize; -- (void) animateMatch: (CGPoint)ptText bounce:(BOOL)bounce; +- (void) animateMatch: (CGPoint) ptText bounce: (BOOL) bounce; - (void) hideMatch; @end @@ -173,7 +171,7 @@ static const KeyToCommand macMapDefault[] = @synthesize sFind, positionFind, retaining, widthText, heightLine, sFont, fontSize; --(id) init { +- (id) init { if (self = [super init]) { [self setNeedsDisplayOnBoundsChange: YES]; // A gold to slightly redder gradient to match other applications @@ -202,15 +200,15 @@ static const KeyToCommand macMapDefault[] = const CGFloat paddingHighlightX = 4; const CGFloat paddingHighlightY = 2; --(void) drawInContext:(CGContextRef)context { +- (void) drawInContext: (CGContextRef) context { if (!sFind || !sFont) return; CFStringRef str = (__bridge CFStringRef)(sFind); CFMutableDictionaryRef styleDict = CFDictionaryCreateMutable(kCFAllocatorDefault, 2, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks); + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); CGColorRef color = CGColorCreateGenericRGB(0.0, 0.0, 0.0, 1.0); CFDictionarySetValue(styleDict, kCTForegroundColorAttributeName, color); CTFontRef fontRef = ::CTFontCreateWithName((CFStringRef)sFont, fontSize, NULL); @@ -229,7 +227,7 @@ const CGFloat paddingHighlightY = 2; CFRelease(styleDict); } -- (void) animateMatch: (CGPoint)ptText bounce:(BOOL)bounce { +- (void) animateMatch: (CGPoint) ptText bounce: (BOOL) bounce { if (!self.sFind || !(self.sFind).length) { [self hideMatch]; return; @@ -249,8 +247,8 @@ const CGFloat paddingHighlightY = 2; ptText.y -= flipper * height / 2.0; [CATransaction begin]; - [CATransaction setValue:@0.0f forKey:kCATransactionAnimationDuration]; - self.bounds = CGRectMake(0,0, width, height); + [CATransaction setValue: @0.0f forKey: kCATransactionAnimationDuration]; + self.bounds = CGRectMake(0, 0, width, height); self.position = ptText; if (bounce) { // Do not reset visibility when just moving @@ -261,7 +259,7 @@ const CGFloat paddingHighlightY = 2; [CATransaction commit]; if (bounce) { - CABasicAnimation *animBounce = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; + CABasicAnimation *animBounce = [CABasicAnimation animationWithKeyPath: @"transform.scale"]; animBounce.duration = 0.15; animBounce.autoreverses = YES; animBounce.removedOnCompletion = NO; @@ -270,11 +268,11 @@ const CGFloat paddingHighlightY = 2; if (self.retaining) { - [self addAnimation: animBounce forKey:@"animateFound"]; + [self addAnimation: animBounce forKey: @"animateFound"]; } else { - CABasicAnimation *animFade = [CABasicAnimation animationWithKeyPath:@"opacity"]; + CABasicAnimation *animFade = [CABasicAnimation animationWithKeyPath: @"opacity"]; animFade.duration = 0.1; animFade.beginTime = 0.4; animFade.removedOnCompletion = NO; @@ -287,7 +285,7 @@ const CGFloat paddingHighlightY = 2; group.fillMode = kCAFillModeForwards; group.animations = @[animBounce, animFade]; - [self addAnimation:group forKey:@"animateFound"]; + [self addAnimation: group forKey: @"animateFound"]; } } } @@ -306,28 +304,25 @@ const CGFloat paddingHighlightY = 2; @implementation TimerTarget -- (id) init: (void*) target -{ - self = [super init]; - if (self != nil) - { - mTarget = target; +- (id) init: (void *) target { + self = [super init]; + if (self != nil) { + mTarget = target; - // Get the default notification queue for the thread which created the instance (usually the - // main thread). We need that later for idle event processing. - NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; - notificationQueue = [[NSNotificationQueue alloc] initWithNotificationCenter: center]; - [center addObserver: self selector: @selector(idleTriggered:) name: @"Idle" object: nil]; - } - return self; + // Get the default notification queue for the thread which created the instance (usually the + // main thread). We need that later for idle event processing. + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + notificationQueue = [[NSNotificationQueue alloc] initWithNotificationCenter: center]; + [center addObserver: self selector: @selector(idleTriggered:) name: @"Idle" object: nil]; + } + return self; } //-------------------------------------------------------------------------------------------------- -- (void) dealloc -{ - NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; - [center removeObserver:self]; +- (void) dealloc { + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + [center removeObserver: self]; } //-------------------------------------------------------------------------------------------------- @@ -335,10 +330,9 @@ const CGFloat paddingHighlightY = 2; /** * Method called by owning ScintillaCocoa object when it is destroyed. */ -- (void) ownerDestroyed -{ - mTarget = NULL; - notificationQueue = nil; +- (void) ownerDestroyed { + mTarget = NULL; + notificationQueue = nil; } //-------------------------------------------------------------------------------------------------- @@ -347,10 +341,9 @@ const CGFloat paddingHighlightY = 2; * Method called by a timer installed by ScintillaCocoa. This two step approach is needed because * a native Obj-C class is required as target for the timer. */ -- (void) timerFired: (NSTimer*) timer -{ - if (mTarget) - static_cast<ScintillaCocoa*>(mTarget)->TimerFired(timer); +- (void) timerFired: (NSTimer *) timer { + if (mTarget) + static_cast<ScintillaCocoa *>(mTarget)->TimerFired(timer); } //-------------------------------------------------------------------------------------------------- @@ -358,18 +351,17 @@ const CGFloat paddingHighlightY = 2; /** * Another timer callback for the idle timer. */ -- (void) idleTimerFired: (NSTimer*) timer -{ +- (void) idleTimerFired: (NSTimer *) timer { #pragma unused(timer) - // Idle timer event. - // Post a new idle notification, which gets executed when the run loop is idle. - // Since we are coalescing on name and sender there will always be only one actual notification - // even for multiple requests. - NSNotification *notification = [NSNotification notificationWithName: @"Idle" object: self]; - [notificationQueue enqueueNotification: notification - postingStyle: NSPostWhenIdle - coalesceMask: (NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender) - forModes: @[NSDefaultRunLoopMode, NSModalPanelRunLoopMode]]; + // Idle timer event. + // Post a new idle notification, which gets executed when the run loop is idle. + // Since we are coalescing on name and sender there will always be only one actual notification + // even for multiple requests. + NSNotification *notification = [NSNotification notificationWithName: @"Idle" object: self]; + [notificationQueue enqueueNotification: notification + postingStyle: NSPostWhenIdle + coalesceMask: (NSNotificationCoalescingOnName | NSNotificationCoalescingOnSender) + forModes: @[NSDefaultRunLoopMode, NSModalPanelRunLoopMode]]; } //-------------------------------------------------------------------------------------------------- @@ -378,50 +370,46 @@ const CGFloat paddingHighlightY = 2; * Another step for idle events. The timer (for idle events) simply requests a notification on * idle time. Only when this notification is send we actually call back the editor. */ -- (void) idleTriggered: (NSNotification*) notification -{ +- (void) idleTriggered: (NSNotification *) notification { #pragma unused(notification) - if (mTarget) - static_cast<ScintillaCocoa*>(mTarget)->IdleTimerFired(); + if (mTarget) + static_cast<ScintillaCocoa *>(mTarget)->IdleTimerFired(); } @end //----------------- ScintillaCocoa ----------------------------------------------------------------- -ScintillaCocoa::ScintillaCocoa(ScintillaView* sciView_, SCIContentView* viewContent, SCIMarginView* viewMargin) -{ - vs.marginInside = false; - - // Don't retain since we're owned by view, which would cause a cycle - sciView = sciView_; - wMain = (__bridge WindowID)viewContent; - wMargin = (__bridge WindowID)viewMargin; - - timerTarget = [[TimerTarget alloc] init: this]; - lastMouseEvent = NULL; - delegate = NULL; - notifyObj = NULL; - notifyProc = NULL; - capturedMouse = false; - enteredSetScrollingSize = false; - scrollSpeed = 1; - scrollTicks = 2000; - observer = NULL; - layerFindIndicator = NULL; - imeInteraction = imeInline; - for (TickReason tr=tickCaret; tr<=tickPlatform; tr = static_cast<TickReason>(tr+1)) - { - timers[tr] = nil; - } - Init(); +ScintillaCocoa::ScintillaCocoa(ScintillaView *sciView_, SCIContentView *viewContent, SCIMarginView *viewMargin) { + vs.marginInside = false; + + // Don't retain since we're owned by view, which would cause a cycle + sciView = sciView_; + wMain = (__bridge WindowID)viewContent; + wMargin = (__bridge WindowID)viewMargin; + + timerTarget = [[TimerTarget alloc] init: this]; + lastMouseEvent = NULL; + delegate = NULL; + notifyObj = NULL; + notifyProc = NULL; + capturedMouse = false; + enteredSetScrollingSize = false; + scrollSpeed = 1; + scrollTicks = 2000; + observer = NULL; + layerFindIndicator = NULL; + imeInteraction = imeInline; + for (TickReason tr=tickCaret; tr<=tickPlatform; tr = static_cast<TickReason>(tr+1)) { + timers[tr] = nil; + } + Init(); } //-------------------------------------------------------------------------------------------------- -ScintillaCocoa::~ScintillaCocoa() -{ - [timerTarget ownerDestroyed]; +ScintillaCocoa::~ScintillaCocoa() { + [timerTarget ownerDestroyed]; } //-------------------------------------------------------------------------------------------------- @@ -429,19 +417,18 @@ ScintillaCocoa::~ScintillaCocoa() /** * Core initialization of the control. Everything that needs to be set up happens here. */ -void ScintillaCocoa::Init() -{ - Scintilla_LinkLexers(); +void ScintillaCocoa::Init() { + Scintilla_LinkLexers(); - // Tell Scintilla not to buffer: Quartz buffers drawing for us. - WndProc(SCI_SETBUFFEREDDRAW, 0, 0); + // Tell Scintilla not to buffer: Quartz buffers drawing for us. + WndProc(SCI_SETBUFFEREDDRAW, 0, 0); - // We are working with Unicode exclusively. - WndProc(SCI_SETCODEPAGE, SC_CP_UTF8, 0); + // We are working with Unicode exclusively. + WndProc(SCI_SETCODEPAGE, SC_CP_UTF8, 0); - // Add Mac specific key bindings. - for (int i = 0; macMapDefault[i].key; i++) - kmap.AssignCmdKey(macMapDefault[i].key, macMapDefault[i].modifiers, macMapDefault[i].msg); + // Add Mac specific key bindings. + for (int i = 0; macMapDefault[i].key; i++) + kmap.AssignCmdKey(macMapDefault[i].key, macMapDefault[i].modifiers, macMapDefault[i].msg); } @@ -450,21 +437,19 @@ void ScintillaCocoa::Init() /** * We need some clean up. Do it here. */ -void ScintillaCocoa::Finalise() -{ - ObserverRemove(); - for (TickReason tr=tickCaret; tr<=tickPlatform; tr = static_cast<TickReason>(tr+1)) - { - FineTickerCancel(tr); - } - ScintillaBase::Finalise(); +void ScintillaCocoa::Finalise() { + ObserverRemove(); + for (TickReason tr=tickCaret; tr<=tickPlatform; tr = static_cast<TickReason>(tr+1)) { + FineTickerCancel(tr); + } + ScintillaBase::Finalise(); } //-------------------------------------------------------------------------------------------------- void ScintillaCocoa::UpdateObserver(CFRunLoopObserverRef /* observer */, CFRunLoopActivity /* activity */, void *info) { - ScintillaCocoa* sci = static_cast<ScintillaCocoa*>(info); - sci->IdleWork(); + ScintillaCocoa *sci = static_cast<ScintillaCocoa *>(info); + sci->IdleWork(); } //-------------------------------------------------------------------------------------------------- @@ -474,19 +459,19 @@ void ScintillaCocoa::UpdateObserver(CFRunLoopObserverRef /* observer */, CFRunLo */ void ScintillaCocoa::ObserverAdd() { - if (!observer) { - CFRunLoopObserverContext context; - context.version = 0; - context.info = this; - context.retain = NULL; - context.release = NULL; - context.copyDescription = NULL; - - CFRunLoopRef mainRunLoop = CFRunLoopGetMain(); - observer = CFRunLoopObserverCreate(NULL, kCFRunLoopEntry | kCFRunLoopBeforeWaiting, - true, 0, UpdateObserver, &context); - CFRunLoopAddObserver(mainRunLoop, observer, kCFRunLoopCommonModes); - } + if (!observer) { + CFRunLoopObserverContext context; + context.version = 0; + context.info = this; + context.retain = NULL; + context.release = NULL; + context.copyDescription = NULL; + + CFRunLoopRef mainRunLoop = CFRunLoopGetMain(); + observer = CFRunLoopObserverCreate(NULL, kCFRunLoopEntry | kCFRunLoopBeforeWaiting, + true, 0, UpdateObserver, &context); + CFRunLoopAddObserver(mainRunLoop, observer, kCFRunLoopCommonModes); + } } //-------------------------------------------------------------------------------------------------- @@ -495,26 +480,26 @@ void ScintillaCocoa::ObserverAdd() { * Remove the run loop observer. */ void ScintillaCocoa::ObserverRemove() { - if (observer) { - CFRunLoopRef mainRunLoop = CFRunLoopGetMain(); - CFRunLoopRemoveObserver(mainRunLoop, observer, kCFRunLoopCommonModes); - CFRelease(observer); - } - observer = NULL; + if (observer) { + CFRunLoopRef mainRunLoop = CFRunLoopGetMain(); + CFRunLoopRemoveObserver(mainRunLoop, observer, kCFRunLoopCommonModes); + CFRelease(observer); + } + observer = NULL; } //-------------------------------------------------------------------------------------------------- void ScintillaCocoa::IdleWork() { - Editor::IdleWork(); - ObserverRemove(); + Editor::IdleWork(); + ObserverRemove(); } //-------------------------------------------------------------------------------------------------- void ScintillaCocoa::QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo) { - Editor::QueueIdleWork(items, upTo); - ObserverAdd(); + Editor::QueueIdleWork(items, upTo); + ObserverAdd(); } //-------------------------------------------------------------------------------------------------- @@ -527,12 +512,12 @@ static std::string EncodedBytesString(CFStringRef cfsRef, CFStringEncoding encod const CFRange rangeAll = {0, CFStringGetLength(cfsRef)}; CFIndex usedLen = 0; CFStringGetBytes(cfsRef, rangeAll, encoding, '?', false, - NULL, 0, &usedLen); + NULL, 0, &usedLen); std::string buffer(usedLen, '\0'); if (usedLen > 0) { CFStringGetBytes(cfsRef, rangeAll, encoding, '?', false, - reinterpret_cast<UInt8 *>(&buffer[0]), usedLen, NULL); + reinterpret_cast<UInt8 *>(&buffer[0]), usedLen, NULL); } return buffer; } @@ -571,8 +556,8 @@ public: } else { CFStringRef cfsVal = CFStringFromString(mixed, lenMixed, encoding); - NSString *sMapped = [(__bridge NSString *)cfsVal stringByFoldingWithOptions:NSCaseInsensitiveSearch - locale:[NSLocale currentLocale]]; + NSString *sMapped = [(__bridge NSString *)cfsVal stringByFoldingWithOptions: NSCaseInsensitiveSearch + locale: [NSLocale currentLocale]]; std::string encoded = EncodedBytesString((__bridge CFStringRef)sMapped, encoding); @@ -594,7 +579,7 @@ CaseFolder *ScintillaCocoa::CaseFolderForEncoding() { return new CaseFolderUnicode(); } else { CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), - vs.styles[STYLE_DEFAULT].characterSet); + vs.styles[STYLE_DEFAULT].characterSet); if (pdoc->dbcsCodePage == 0) { CaseFolderTable *pcf = new CaseFolderTable(); pcf->StandardASCII(); @@ -606,8 +591,8 @@ CaseFolder *ScintillaCocoa::CaseFolderForEncoding() { if (!cfsVal) continue; - NSString *sMapped = [(__bridge NSString *)cfsVal stringByFoldingWithOptions:NSCaseInsensitiveSearch - locale:[NSLocale currentLocale]]; + NSString *sMapped = [(__bridge NSString *)cfsVal stringByFoldingWithOptions: NSCaseInsensitiveSearch + locale: [NSLocale currentLocale]]; std::string encoded = EncodedBytesString((__bridge CFStringRef)sMapped, encoding); @@ -630,41 +615,39 @@ CaseFolder *ScintillaCocoa::CaseFolderForEncoding() { /** * Case-fold the given string depending on the specified case mapping type. */ -std::string ScintillaCocoa::CaseMapString(const std::string &s, int caseMapping) -{ - if ((s.size() == 0) || (caseMapping == cmSame)) - return s; - - if (IsUnicodeMode()) { - std::string retMapped(s.length() * maxExpansionCaseConversion, 0); - size_t lenMapped = CaseConvertString(&retMapped[0], retMapped.length(), s.c_str(), s.length(), - (caseMapping == cmUpper) ? CaseConversionUpper : CaseConversionLower); - retMapped.resize(lenMapped); - return retMapped; - } - - CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), - vs.styles[STYLE_DEFAULT].characterSet); +std::string ScintillaCocoa::CaseMapString(const std::string &s, int caseMapping) { + if ((s.size() == 0) || (caseMapping == cmSame)) + return s; - CFStringRef cfsVal = CFStringFromString(s.c_str(), s.length(), encoding); + if (IsUnicodeMode()) { + std::string retMapped(s.length() * maxExpansionCaseConversion, 0); + size_t lenMapped = CaseConvertString(&retMapped[0], retMapped.length(), s.c_str(), s.length(), + (caseMapping == cmUpper) ? CaseConversionUpper : CaseConversionLower); + retMapped.resize(lenMapped); + return retMapped; + } - NSString *sMapped; - switch (caseMapping) - { - case cmUpper: - sMapped = ((__bridge NSString *)cfsVal).uppercaseString; - break; - case cmLower: - sMapped = ((__bridge NSString *)cfsVal).lowercaseString; - break; - default: - sMapped = (__bridge NSString *)cfsVal; - } + CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), + vs.styles[STYLE_DEFAULT].characterSet); + + CFStringRef cfsVal = CFStringFromString(s.c_str(), s.length(), encoding); + + NSString *sMapped; + switch (caseMapping) { + case cmUpper: + sMapped = ((__bridge NSString *)cfsVal).uppercaseString; + break; + case cmLower: + sMapped = ((__bridge NSString *)cfsVal).lowercaseString; + break; + default: + sMapped = (__bridge NSString *)cfsVal; + } - // Back to encoding - std::string result = EncodedBytesString((__bridge CFStringRef)sMapped, encoding); - CFRelease(cfsVal); - return result; + // Back to encoding + std::string result = EncodedBytesString((__bridge CFStringRef)sMapped, encoding); + CFRelease(cfsVal); + return result; } //-------------------------------------------------------------------------------------------------- @@ -673,8 +656,8 @@ std::string ScintillaCocoa::CaseMapString(const std::string &s, int caseMapping) * Cancel all modes, both for base class and any find indicator. */ void ScintillaCocoa::CancelModes() { - ScintillaBase::CancelModes(); - HideFindIndicator(); + ScintillaBase::CancelModes(); + HideFindIndicator(); } //-------------------------------------------------------------------------------------------------- @@ -682,9 +665,9 @@ void ScintillaCocoa::CancelModes() { /** * Helper function to get the scrolling view. */ -NSScrollView* ScintillaCocoa::ScrollContainer() const { - NSView* container = (__bridge NSView*)(wMain.GetID()); - return static_cast<NSScrollView*>(container.superview.superview); +NSScrollView *ScintillaCocoa::ScrollContainer() const { + NSView *container = (__bridge NSView *)(wMain.GetID()); + return static_cast<NSScrollView *>(container.superview.superview); } //-------------------------------------------------------------------------------------------------- @@ -692,9 +675,8 @@ NSScrollView* ScintillaCocoa::ScrollContainer() const { /** * Helper function to get the inner container which represents the actual "canvas" we work with. */ -SCIContentView* ScintillaCocoa::ContentView() -{ - return (__bridge SCIContentView*)(wMain.GetID()); +SCIContentView *ScintillaCocoa::ContentView() { + return (__bridge SCIContentView *)(wMain.GetID()); } //-------------------------------------------------------------------------------------------------- @@ -702,11 +684,10 @@ SCIContentView* ScintillaCocoa::ContentView() /** * Return the top left visible point relative to the origin point of the whole document. */ -Scintilla::Point ScintillaCocoa::GetVisibleOriginInMain() const -{ - NSScrollView *scrollView = ScrollContainer(); - NSRect contentRect = scrollView.contentView.bounds; - return Point(static_cast<XYPOSITION>(contentRect.origin.x), static_cast<XYPOSITION>(contentRect.origin.y)); +Scintilla::Point ScintillaCocoa::GetVisibleOriginInMain() const { + NSScrollView *scrollView = ScrollContainer(); + NSRect contentRect = scrollView.contentView.bounds; + return Point(static_cast<XYPOSITION>(contentRect.origin.x), static_cast<XYPOSITION>(contentRect.origin.y)); } //-------------------------------------------------------------------------------------------------- @@ -716,13 +697,12 @@ Scintilla::Point ScintillaCocoa::GetVisibleOriginInMain() const * in order to make scrolling working properly. * The returned value is in document coordinates. */ -PRectangle ScintillaCocoa::GetClientRectangle() const -{ - NSScrollView *scrollView = ScrollContainer(); - NSSize size = scrollView.contentView.bounds.size; - Point origin = GetVisibleOriginInMain(); - return PRectangle(origin.x, origin.y, static_cast<XYPOSITION>(origin.x+size.width), - static_cast<XYPOSITION>(origin.y + size.height)); +PRectangle ScintillaCocoa::GetClientRectangle() const { + NSScrollView *scrollView = ScrollContainer(); + NSSize size = scrollView.contentView.bounds.size; + Point origin = GetVisibleOriginInMain(); + return PRectangle(origin.x, origin.y, static_cast<XYPOSITION>(origin.x+size.width), + static_cast<XYPOSITION>(origin.y + size.height)); } //-------------------------------------------------------------------------------------------------- @@ -732,14 +712,14 @@ PRectangle ScintillaCocoa::GetClientRectangle() const */ PRectangle ScintillaCocoa::GetClientDrawingRectangle() { #if MAC_OS_X_VERSION_MAX_ALLOWED > 1080 - NSView *content = ContentView(); - if ([content respondsToSelector: @selector(setPreparedContentRect:)]) { - NSRect rcPrepared = content.preparedContentRect; - if (!NSIsEmptyRect(rcPrepared)) - return NSRectToPRectangle(rcPrepared); - } + NSView *content = ContentView(); + if ([content respondsToSelector: @selector(setPreparedContentRect:)]) { + NSRect rcPrepared = content.preparedContentRect; + if (!NSIsEmptyRect(rcPrepared)) + return NSRectToPRectangle(rcPrepared); + } #endif - return ScintillaCocoa::GetClientRectangle(); + return ScintillaCocoa::GetClientRectangle(); } //-------------------------------------------------------------------------------------------------- @@ -749,12 +729,11 @@ PRectangle ScintillaCocoa::GetClientDrawingRectangle() { * a native Point structure. Base coordinates are used for the top window used in the view hierarchy. * Returned value is in view coordinates. */ -Scintilla::Point ScintillaCocoa::ConvertPoint(NSPoint point) -{ - NSView* container = ContentView(); - NSPoint result = [container convertPoint: point fromView: nil]; - Scintilla::Point ptOrigin = GetVisibleOriginInMain(); - return Point(static_cast<XYPOSITION>(result.x - ptOrigin.x), static_cast<XYPOSITION>(result.y - ptOrigin.y)); +Scintilla::Point ScintillaCocoa::ConvertPoint(NSPoint point) { + NSView *container = ContentView(); + NSPoint result = [container convertPoint: point fromView: nil]; + Scintilla::Point ptOrigin = GetVisibleOriginInMain(); + return Point(static_cast<XYPOSITION>(result.x - ptOrigin.x), static_cast<XYPOSITION>(result.y - ptOrigin.y)); } //-------------------------------------------------------------------------------------------------- @@ -762,22 +741,20 @@ Scintilla::Point ScintillaCocoa::ConvertPoint(NSPoint point) /** * Do not clip like superclass as Cocoa is not reporting all of prepared area. */ -void ScintillaCocoa::RedrawRect(PRectangle rc) -{ - if (!rc.Empty()) - wMain.InvalidateRectangle(rc); +void ScintillaCocoa::RedrawRect(PRectangle rc) { + if (!rc.Empty()) + wMain.InvalidateRectangle(rc); } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::DiscardOverdraw() -{ +void ScintillaCocoa::DiscardOverdraw() { #if MAC_OS_X_VERSION_MAX_ALLOWED > 1080 - // If running on 10.9, reset prepared area to visible area - NSView *content = ContentView(); - if ([content respondsToSelector: @selector(setPreparedContentRect:)]) { - content.preparedContentRect = content.visibleRect; - } + // If running on 10.9, reset prepared area to visible area + NSView *content = ContentView(); + if ([content respondsToSelector: @selector(setPreparedContentRect:)]) { + content.preparedContentRect = content.visibleRect; + } #endif } @@ -786,11 +763,10 @@ void ScintillaCocoa::DiscardOverdraw() /** * Ensure all of prepared content is also redrawn. */ -void ScintillaCocoa::Redraw() -{ - wMargin.InvalidateAll(); - DiscardOverdraw(); - wMain.InvalidateAll(); +void ScintillaCocoa::Redraw() { + wMargin.InvalidateAll(); + DiscardOverdraw(); + wMain.InvalidateAll(); } //-------------------------------------------------------------------------------------------------- @@ -807,9 +783,8 @@ void ScintillaCocoa::Redraw() * @param lParam The other of the two free parameters. A signed long. */ sptr_t ScintillaCocoa::DirectFunction(sptr_t ptr, unsigned int iMessage, uptr_t wParam, - sptr_t lParam) -{ - return reinterpret_cast<ScintillaCocoa *>(ptr)->WndProc(iMessage, wParam, lParam); + sptr_t lParam) { + return reinterpret_cast<ScintillaCocoa *>(ptr)->WndProc(iMessage, wParam, lParam); } //-------------------------------------------------------------------------------------------------- @@ -818,10 +793,9 @@ sptr_t ScintillaCocoa::DirectFunction(sptr_t ptr, unsigned int iMessage, uptr_t * This method is very similar to DirectFunction. On Windows it sends a message (not in the Obj-C sense) * to the target window. Here we simply call our fake window proc. */ -sptr_t scintilla_send_message(void* sci, unsigned int iMessage, uptr_t wParam, sptr_t lParam) -{ - ScintillaView *control = (__bridge ScintillaView*)(sci); - return [control message:iMessage wParam:wParam lParam:lParam]; +sptr_t scintilla_send_message(void *sci, unsigned int iMessage, uptr_t wParam, sptr_t lParam) { + ScintillaView *control = (__bridge ScintillaView *)(sci); + return [control message: iMessage wParam: wParam lParam: lParam]; } //-------------------------------------------------------------------------------------------------- @@ -834,69 +808,67 @@ sptr_t scintilla_send_message(void* sci, unsigned int iMessage, uptr_t wParam, s * would be system messages on Windows (e.g. for key down, mouse move etc.) are handled by * directly calling appropriate handlers. */ -sptr_t ScintillaCocoa::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) -{ - try { - switch (iMessage) - { - case SCI_GETDIRECTFUNCTION: - return reinterpret_cast<sptr_t>(DirectFunction); +sptr_t ScintillaCocoa::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { + try { + switch (iMessage) { + case SCI_GETDIRECTFUNCTION: + return reinterpret_cast<sptr_t>(DirectFunction); - case SCI_GETDIRECTPOINTER: - return reinterpret_cast<sptr_t>(this); + case SCI_GETDIRECTPOINTER: + return reinterpret_cast<sptr_t>(this); - case SCI_TARGETASUTF8: - return TargetAsUTF8(reinterpret_cast<char*>(lParam)); + case SCI_TARGETASUTF8: + return TargetAsUTF8(reinterpret_cast<char *>(lParam)); - case SCI_ENCODEDFROMUTF8: - return EncodedFromUTF8(reinterpret_cast<char*>(wParam), - reinterpret_cast<char*>(lParam)); + case SCI_ENCODEDFROMUTF8: + return EncodedFromUTF8(reinterpret_cast<char *>(wParam), + reinterpret_cast<char *>(lParam)); - case SCI_SETIMEINTERACTION: - // Only inline IME supported on Cocoa - break; + case SCI_SETIMEINTERACTION: + // Only inline IME supported on Cocoa + break; - case SCI_GRABFOCUS: - [ContentView().window makeFirstResponder:ContentView()]; - break; + case SCI_GRABFOCUS: + [ContentView().window makeFirstResponder: ContentView()]; + break; - case SCI_SETBUFFEREDDRAW: - // Buffered drawing not supported on Cocoa - view.bufferedDraw = false; - break; + case SCI_SETBUFFEREDDRAW: + // Buffered drawing not supported on Cocoa + view.bufferedDraw = false; + break; - case SCI_FINDINDICATORSHOW: - ShowFindIndicatorForRange(NSMakeRange(wParam, lParam-wParam), YES); - return 0; + case SCI_FINDINDICATORSHOW: + ShowFindIndicatorForRange(NSMakeRange(wParam, lParam-wParam), YES); + return 0; - case SCI_FINDINDICATORFLASH: - ShowFindIndicatorForRange(NSMakeRange(wParam, lParam-wParam), NO); - return 0; + case SCI_FINDINDICATORFLASH: + ShowFindIndicatorForRange(NSMakeRange(wParam, lParam-wParam), NO); + return 0; - case SCI_FINDINDICATORHIDE: - HideFindIndicator(); - return 0; + case SCI_FINDINDICATORHIDE: + HideFindIndicator(); + return 0; - case SCI_SETPHASESDRAW: { - sptr_t r = ScintillaBase::WndProc(iMessage, wParam, lParam); - [sciView updateIndicatorIME]; - return r; - } + case SCI_SETPHASESDRAW: { + sptr_t r = ScintillaBase::WndProc(iMessage, wParam, lParam); + [sciView updateIndicatorIME]; + return r; + } - case SCI_GETACCESSIBILITY: - return SC_ACCESSIBILITY_ENABLED; + case SCI_GETACCESSIBILITY: + return SC_ACCESSIBILITY_ENABLED; - default: - sptr_t r = ScintillaBase::WndProc(iMessage, wParam, lParam); + default: + sptr_t r = ScintillaBase::WndProc(iMessage, wParam, lParam); - return r; - } - } catch (std::bad_alloc &) { - errorStatus = SC_STATUS_BADALLOC; - } catch (...) { - errorStatus = SC_STATUS_FAILURE; - } - return 0l; + return r; + } + } catch (std::bad_alloc &) { + errorStatus = SC_STATUS_BADALLOC; + } catch (...) { + errorStatus = SC_STATUS_FAILURE; + } + return 0l; } //-------------------------------------------------------------------------------------------------- @@ -905,9 +877,8 @@ sptr_t ScintillaCocoa::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lPar * In Windows lingo this is the handler which handles anything that wasn't handled in the normal * window proc which would usually send the message back to generic window proc that Windows uses. */ -sptr_t ScintillaCocoa::DefWndProc(unsigned int, uptr_t, sptr_t) -{ - return 0; +sptr_t ScintillaCocoa::DefWndProc(unsigned int, uptr_t, sptr_t) { + return 0; } //-------------------------------------------------------------------------------------------------- @@ -915,16 +886,12 @@ sptr_t ScintillaCocoa::DefWndProc(unsigned int, uptr_t, sptr_t) /** * Handle any ScintillaCocoa-specific ticking or call superclass. */ -void ScintillaCocoa::TickFor(TickReason reason) -{ - if (reason == tickPlatform) - { - DragScroll(); - } - else - { - Editor::TickFor(reason); - } +void ScintillaCocoa::TickFor(TickReason reason) { + if (reason == tickPlatform) { + DragScroll(); + } else { + Editor::TickFor(reason); + } } //-------------------------------------------------------------------------------------------------- @@ -932,9 +899,8 @@ void ScintillaCocoa::TickFor(TickReason reason) /** * Report that this Editor subclass has a working implementation of FineTickerStart. */ -bool ScintillaCocoa::FineTickerAvailable() -{ - return true; +bool ScintillaCocoa::FineTickerAvailable() { + return true; } //-------------------------------------------------------------------------------------------------- @@ -942,9 +908,8 @@ bool ScintillaCocoa::FineTickerAvailable() /** * Is a particular timer currently running? */ -bool ScintillaCocoa::FineTickerRunning(TickReason reason) -{ - return timers[reason] != nil; +bool ScintillaCocoa::FineTickerRunning(TickReason reason) { + return timers[reason] != nil; } //-------------------------------------------------------------------------------------------------- @@ -952,21 +917,19 @@ bool ScintillaCocoa::FineTickerRunning(TickReason reason) /** * Start a fine-grained timer. */ -void ScintillaCocoa::FineTickerStart(TickReason reason, int millis, int tolerance) -{ - FineTickerCancel(reason); - NSTimer *fineTimer = [NSTimer timerWithTimeInterval: millis / 1000.0 - target: timerTarget - selector: @selector(timerFired:) - userInfo: nil - repeats: YES]; - if (tolerance && [fineTimer respondsToSelector: @selector(setTolerance:)]) - { - fineTimer.tolerance = tolerance / 1000.0; - } - timers[reason] = fineTimer; - [NSRunLoop.currentRunLoop addTimer: fineTimer forMode: NSDefaultRunLoopMode]; - [NSRunLoop.currentRunLoop addTimer: fineTimer forMode: NSModalPanelRunLoopMode]; +void ScintillaCocoa::FineTickerStart(TickReason reason, int millis, int tolerance) { + FineTickerCancel(reason); + NSTimer *fineTimer = [NSTimer timerWithTimeInterval: millis / 1000.0 + target: timerTarget + selector: @selector(timerFired:) + userInfo: nil + repeats: YES]; + if (tolerance && [fineTimer respondsToSelector: @selector(setTolerance:)]) { + fineTimer.tolerance = tolerance / 1000.0; + } + timers[reason] = fineTimer; + [NSRunLoop.currentRunLoop addTimer: fineTimer forMode: NSDefaultRunLoopMode]; + [NSRunLoop.currentRunLoop addTimer: fineTimer forMode: NSModalPanelRunLoopMode]; } //-------------------------------------------------------------------------------------------------- @@ -974,77 +937,64 @@ void ScintillaCocoa::FineTickerStart(TickReason reason, int millis, int toleranc /** * Cancel a fine-grained timer. */ -void ScintillaCocoa::FineTickerCancel(TickReason reason) -{ - if (timers[reason]) - { - [timers[reason] invalidate]; - timers[reason] = nil; - } +void ScintillaCocoa::FineTickerCancel(TickReason reason) { + if (timers[reason]) { + [timers[reason] invalidate]; + timers[reason] = nil; + } } //-------------------------------------------------------------------------------------------------- -bool ScintillaCocoa::SetIdle(bool on) -{ - if (idler.state != on) - { - idler.state = on; - if (idler.state) - { - // Scintilla ticks = milliseconds - NSTimer *idleTimer = [NSTimer scheduledTimerWithTimeInterval: timer.tickSize / 1000.0 - target: timerTarget - selector: @selector(idleTimerFired:) - userInfo: nil - repeats: YES]; - [NSRunLoop.currentRunLoop addTimer: idleTimer forMode: NSModalPanelRunLoopMode]; - idler.idlerID = (__bridge IdlerID)idleTimer; - } - else - if (idler.idlerID != NULL) - { - [(__bridge NSTimer*)(idler.idlerID) invalidate]; - idler.idlerID = 0; - } - } - return true; +bool ScintillaCocoa::SetIdle(bool on) { + if (idler.state != on) { + idler.state = on; + if (idler.state) { + // Scintilla ticks = milliseconds + NSTimer *idleTimer = [NSTimer scheduledTimerWithTimeInterval: timer.tickSize / 1000.0 + target: timerTarget + selector: @selector(idleTimerFired:) + userInfo: nil + repeats: YES]; + [NSRunLoop.currentRunLoop addTimer: idleTimer forMode: NSModalPanelRunLoopMode]; + idler.idlerID = (__bridge IdlerID)idleTimer; + } else if (idler.idlerID != NULL) { + [(__bridge NSTimer *)(idler.idlerID) invalidate]; + idler.idlerID = 0; + } + } + return true; } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::CopyToClipboard(const SelectionText &selectedText) -{ - SetPasteboardData([NSPasteboard generalPasteboard], selectedText); +void ScintillaCocoa::CopyToClipboard(const SelectionText &selectedText) { + SetPasteboardData([NSPasteboard generalPasteboard], selectedText); } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::Copy() -{ - if (!sel.Empty()) - { - SelectionText selectedText; - CopySelectionRange(&selectedText); - CopyToClipboard(selectedText); - } +void ScintillaCocoa::Copy() { + if (!sel.Empty()) { + SelectionText selectedText; + CopySelectionRange(&selectedText); + CopyToClipboard(selectedText); + } } //-------------------------------------------------------------------------------------------------- -bool ScintillaCocoa::CanPaste() -{ - if (!Editor::CanPaste()) - return false; +bool ScintillaCocoa::CanPaste() { + if (!Editor::CanPaste()) + return false; - return GetPasteboardData([NSPasteboard generalPasteboard], NULL); + return GetPasteboardData([NSPasteboard generalPasteboard], NULL); } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::Paste() -{ - Paste(false); +void ScintillaCocoa::Paste() { + Paste(false); } //-------------------------------------------------------------------------------------------------- @@ -1052,52 +1002,51 @@ void ScintillaCocoa::Paste() /** * Pastes data from the paste board into the editor. */ -void ScintillaCocoa::Paste(bool forceRectangular) -{ - SelectionText selectedText; - bool ok = GetPasteboardData([NSPasteboard generalPasteboard], &selectedText); - if (forceRectangular) - selectedText.rectangular = forceRectangular; +void ScintillaCocoa::Paste(bool forceRectangular) { + SelectionText selectedText; + bool ok = GetPasteboardData([NSPasteboard generalPasteboard], &selectedText); + if (forceRectangular) + selectedText.rectangular = forceRectangular; - if (!ok || selectedText.Empty()) - // No data or no flavor we support. - return; + if (!ok || selectedText.Empty()) + // No data or no flavor we support. + return; - pdoc->BeginUndoAction(); - ClearSelection(false); - InsertPasteShape(selectedText.Data(), static_cast<int>(selectedText.Length()), - selectedText.rectangular ? pasteRectangular : pasteStream); - pdoc->EndUndoAction(); + pdoc->BeginUndoAction(); + ClearSelection(false); + InsertPasteShape(selectedText.Data(), static_cast<int>(selectedText.Length()), + selectedText.rectangular ? pasteRectangular : pasteStream); + pdoc->EndUndoAction(); - Redraw(); - EnsureCaretVisible(); + Redraw(); + EnsureCaretVisible(); } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::CTPaint(void* gc, NSRect rc) { +void ScintillaCocoa::CTPaint(void *gc, NSRect rc) { #pragma unused(rc) - std::unique_ptr<Surface> surfaceWindow(Surface::Allocate(SC_TECHNOLOGY_DEFAULT)); - surfaceWindow->Init(gc, wMain.GetID()); - surfaceWindow->SetUnicodeMode(SC_CP_UTF8 == ct.codePage); - surfaceWindow->SetDBCSMode(ct.codePage); - ct.PaintCT(surfaceWindow.get()); - surfaceWindow->Release(); + std::unique_ptr<Surface> surfaceWindow(Surface::Allocate(SC_TECHNOLOGY_DEFAULT)); + surfaceWindow->Init(gc, wMain.GetID()); + surfaceWindow->SetUnicodeMode(SC_CP_UTF8 == ct.codePage); + surfaceWindow->SetDBCSMode(ct.codePage); + ct.PaintCT(surfaceWindow.get()); + surfaceWindow->Release(); } @interface CallTipView : NSControl { - ScintillaCocoa *sci; + ScintillaCocoa *sci; } @end @implementation CallTipView -- (NSView*) initWithFrame: (NSRect) frame { +- (NSView *) initWithFrame: (NSRect) frame { self = [super initWithFrame: frame]; if (self) { - sci = NULL; + sci = NULL; } return self; @@ -1109,37 +1058,37 @@ void ScintillaCocoa::CTPaint(void* gc, NSRect rc) { } - (void) setSci: (ScintillaCocoa *) sci_ { - sci = sci_; + sci = sci_; } - (void) drawRect: (NSRect) needsDisplayInRect { - if (sci) { - CGContextRef context = (CGContextRef) [NSGraphicsContext currentContext].graphicsPort; - sci->CTPaint(context, needsDisplayInRect); - } + if (sci) { + CGContextRef context = (CGContextRef) [NSGraphicsContext currentContext].graphicsPort; + sci->CTPaint(context, needsDisplayInRect); + } } - (void) mouseDown: (NSEvent *) event { - if (sci) { - sci->CallTipMouseDown(event.locationInWindow); - } + if (sci) { + sci->CallTipMouseDown(event.locationInWindow); + } } // On OS X, only the key view should modify the cursor so the calltip can't. // This view does not become key so resetCursorRects never called. - (void) resetCursorRects { - //[super resetCursorRects]; - //[self addCursorRect: [self bounds] cursor: [NSCursor arrowCursor]]; + //[super resetCursorRects]; + //[self addCursorRect: [self bounds] cursor: [NSCursor arrowCursor]]; } @end void ScintillaCocoa::CallTipMouseDown(NSPoint pt) { - NSRect rectBounds = ((__bridge NSView *)(ct.wDraw.GetID())).bounds; - Point location(static_cast<XYPOSITION>(pt.x), - static_cast<XYPOSITION>(rectBounds.size.height - pt.y)); - ct.MouseClick(location); - CallTipClick(); + NSRect rectBounds = ((__bridge NSView *)(ct.wDraw.GetID())).bounds; + Point location(static_cast<XYPOSITION>(pt.x), + static_cast<XYPOSITION>(rectBounds.size.height - pt.y)); + ct.MouseClick(location); + CallTipClick(); } static bool HeightDifferent(WindowID wCallTip, PRectangle rc) { @@ -1149,54 +1098,52 @@ static bool HeightDifferent(WindowID wCallTip, PRectangle rc) { } void ScintillaCocoa::CreateCallTipWindow(PRectangle rc) { - if (ct.wCallTip.Created() && HeightDifferent(ct.wCallTip.GetID(), rc)) { - ct.wCallTip.Destroy(); - } - if (!ct.wCallTip.Created()) { - NSRect ctRect = NSMakeRect(rc.top,rc.bottom, rc.Width(), rc.Height()); - NSWindow *callTip = [[NSWindow alloc] initWithContentRect: ctRect - styleMask: NSBorderlessWindowMask - backing: NSBackingStoreBuffered - defer: NO]; - [callTip setLevel:NSFloatingWindowLevel]; - [callTip setHasShadow:YES]; - NSRect ctContent = NSMakeRect(0,0, rc.Width(), rc.Height()); - CallTipView *caption = [[CallTipView alloc] initWithFrame: ctContent]; - caption.autoresizingMask = NSViewWidthSizable | NSViewMaxYMargin; - [caption setSci: this]; - [callTip.contentView addSubview: caption]; - [callTip orderFront:caption]; - ct.wCallTip = (__bridge_retained WindowID)callTip; - ct.wDraw = (__bridge WindowID)caption; - } -} - -void ScintillaCocoa::AddToPopUp(const char *label, int cmd, bool enabled) -{ - NSMenuItem* item; - ScintillaContextMenu *menu = (__bridge ScintillaContextMenu*)(popup.GetID()); - [menu setOwner: this]; - [menu setAutoenablesItems: NO]; - - if (cmd == 0) { - item = [NSMenuItem separatorItem]; - } else { - item = [[NSMenuItem alloc] init]; - item.title = @(label); - } - item.target = menu; - item.action = @selector(handleCommand:); - item.tag = cmd; - item.enabled = enabled; - - [menu addItem: item]; + if (ct.wCallTip.Created() && HeightDifferent(ct.wCallTip.GetID(), rc)) { + ct.wCallTip.Destroy(); + } + if (!ct.wCallTip.Created()) { + NSRect ctRect = NSMakeRect(rc.top, rc.bottom, rc.Width(), rc.Height()); + NSWindow *callTip = [[NSWindow alloc] initWithContentRect: ctRect + styleMask: NSBorderlessWindowMask + backing: NSBackingStoreBuffered + defer: NO]; + [callTip setLevel: NSFloatingWindowLevel]; + [callTip setHasShadow: YES]; + NSRect ctContent = NSMakeRect(0, 0, rc.Width(), rc.Height()); + CallTipView *caption = [[CallTipView alloc] initWithFrame: ctContent]; + caption.autoresizingMask = NSViewWidthSizable | NSViewMaxYMargin; + [caption setSci: this]; + [callTip.contentView addSubview: caption]; + [callTip orderFront: caption]; + ct.wCallTip = (__bridge_retained WindowID)callTip; + ct.wDraw = (__bridge WindowID)caption; + } +} + +void ScintillaCocoa::AddToPopUp(const char *label, int cmd, bool enabled) { + NSMenuItem *item; + ScintillaContextMenu *menu = (__bridge ScintillaContextMenu *)(popup.GetID()); + [menu setOwner: this]; + [menu setAutoenablesItems: NO]; + + if (cmd == 0) { + item = [NSMenuItem separatorItem]; + } else { + item = [[NSMenuItem alloc] init]; + item.title = @(label); + } + item.target = menu; + item.action = @selector(handleCommand:); + item.tag = cmd; + item.enabled = enabled; + + [menu addItem: item]; } // ------------------------------------------------------------------------------------------------- -void ScintillaCocoa::ClaimSelection() -{ - // Mac OS X does not have a primary selection. +void ScintillaCocoa::ClaimSelection() { + // Mac OS X does not have a primary selection. } // ------------------------------------------------------------------------------------------------- @@ -1205,14 +1152,13 @@ void ScintillaCocoa::ClaimSelection() * Returns the current caret position (which is tracked as an offset into the entire text string) * as a row:column pair. The result is zero-based. */ -NSPoint ScintillaCocoa::GetCaretPosition() -{ - const Sci::Line line = pdoc->LineFromPosition(sel.RangeMain().caret.Position()); - NSPoint result; +NSPoint ScintillaCocoa::GetCaretPosition() { + const Sci::Line line = pdoc->LineFromPosition(sel.RangeMain().caret.Position()); + NSPoint result; - result.y = line; - result.x = sel.RangeMain().caret.Position() - pdoc->LineStart(line); - return result; + result.y = line; + result.x = sel.RangeMain().caret.Position() - pdoc->LineStart(line); + return result; } // ------------------------------------------------------------------------------------------------- @@ -1222,96 +1168,84 @@ NSPoint ScintillaCocoa::GetCaretPosition() /** * Triggered by the tick timer on a regular basis to scroll the content during a drag operation. */ -void ScintillaCocoa::DragScroll() -{ - if (!posDrag.IsValid()) - { - scrollSpeed = 1; - scrollTicks = 2000; - return; - } - - // TODO: does not work for wrapped lines, fix it. - Sci::Line line = pdoc->LineFromPosition(posDrag.Position()); - Sci::Line currentVisibleLine = cs.DisplayFromDoc(line); - Sci::Line lastVisibleLine = std::min(topLine + LinesOnScreen(), cs.LinesDisplayed()) - 2; - - if (currentVisibleLine <= topLine && topLine > 0) - ScrollTo(topLine - scrollSpeed); - else - if (currentVisibleLine >= lastVisibleLine) - ScrollTo(topLine + scrollSpeed); - else - { - scrollSpeed = 1; - scrollTicks = 2000; - return; - } - - // TODO: also handle horizontal scrolling. - - if (scrollSpeed == 1) - { - scrollTicks -= timer.tickSize; - if (scrollTicks <= 0) - { - scrollSpeed = 5; - scrollTicks = 2000; - } - } +void ScintillaCocoa::DragScroll() { + if (!posDrag.IsValid()) { + scrollSpeed = 1; + scrollTicks = 2000; + return; + } + + // TODO: does not work for wrapped lines, fix it. + Sci::Line line = pdoc->LineFromPosition(posDrag.Position()); + Sci::Line currentVisibleLine = cs.DisplayFromDoc(line); + Sci::Line lastVisibleLine = std::min(topLine + LinesOnScreen(), cs.LinesDisplayed()) - 2; + + if (currentVisibleLine <= topLine && topLine > 0) + ScrollTo(topLine - scrollSpeed); + else if (currentVisibleLine >= lastVisibleLine) + ScrollTo(topLine + scrollSpeed); + else { + scrollSpeed = 1; + scrollTicks = 2000; + return; + } + + // TODO: also handle horizontal scrolling. + + if (scrollSpeed == 1) { + scrollTicks -= timer.tickSize; + if (scrollTicks <= 0) { + scrollSpeed = 5; + scrollTicks = 2000; + } + } } //----------------- DragProviderSource ------------------------------------------------------- -@interface DragProviderSource : NSObject <NSPasteboardItemDataProvider> -{ - SelectionText selectedText; +@interface DragProviderSource : NSObject <NSPasteboardItemDataProvider> { + SelectionText selectedText; } @end @implementation DragProviderSource -- (id)initWithSelectedText:(const SelectionText *)other -{ - self = [super init]; +- (id) initWithSelectedText: (const SelectionText *) other { + self = [super init]; - if (self) { - selectedText.Copy(*other); - } + if (self) { + selectedText.Copy(*other); + } - return self; + return self; } -- (void)pasteboard:(NSPasteboard *)pasteboard item:(NSPasteboardItem *)item provideDataForType:(NSString *)type -{ +- (void) pasteboard: (NSPasteboard *) pasteboard item: (NSPasteboardItem *) item provideDataForType: (NSString *) type { #pragma unused(item) - if (selectedText.Length() == 0) - return; + if (selectedText.Length() == 0) + return; - if (([type compare: NSPasteboardTypeString] != NSOrderedSame) && - ([type compare: ScintillaRecPboardType] != NSOrderedSame)) - return; + if (([type compare: NSPasteboardTypeString] != NSOrderedSame) && + ([type compare: ScintillaRecPboardType] != NSOrderedSame)) + return; - CFStringEncoding encoding = EncodingFromCharacterSet(selectedText.codePage == SC_CP_UTF8, - selectedText.characterSet); + CFStringEncoding encoding = EncodingFromCharacterSet(selectedText.codePage == SC_CP_UTF8, + selectedText.characterSet); - CFStringRef cfsVal = CFStringFromString(selectedText.Data(), selectedText.Length(), encoding); + CFStringRef cfsVal = CFStringFromString(selectedText.Data(), selectedText.Length(), encoding); - if ([type compare: NSPasteboardTypeString] == NSOrderedSame) - { - [pasteboard setString:(__bridge NSString *)cfsVal forType: NSStringPboardType]; - } - else if ([type compare: ScintillaRecPboardType] == NSOrderedSame) - { - // This is specific to scintilla, allows us to drag rectangular selections around the document. - if (selectedText.rectangular) - [pasteboard setString:(__bridge NSString *)cfsVal forType: ScintillaRecPboardType]; - } + if ([type compare: NSPasteboardTypeString] == NSOrderedSame) { + [pasteboard setString: (__bridge NSString *)cfsVal forType: NSStringPboardType]; + } else if ([type compare: ScintillaRecPboardType] == NSOrderedSame) { + // This is specific to scintilla, allows us to drag rectangular selections around the document. + if (selectedText.rectangular) + [pasteboard setString: (__bridge NSString *)cfsVal forType: ScintillaRecPboardType]; + } - if (cfsVal) - CFRelease(cfsVal); + if (cfsVal) + CFRelease(cfsVal); } @end @@ -1321,164 +1255,163 @@ void ScintillaCocoa::DragScroll() /** * Called when a drag operation was initiated from within Scintilla. */ -void ScintillaCocoa::StartDrag() -{ - if (sel.Empty()) - return; - - inDragDrop = ddDragging; - - FineTickerStart(tickPlatform, timer.tickSize, 0); - - // Put the data to be dragged on the drag pasteboard. - SelectionText selectedText; - NSPasteboard* pasteboard = [NSPasteboard pasteboardWithName: NSDragPboard]; - CopySelectionRange(&selectedText); - SetPasteboardData(pasteboard, selectedText); - - // calculate the bounds of the selection - PRectangle client = GetTextRectangle(); - Sci::Position selStart = sel.RangeMain().Start().Position(); - Sci::Position selEnd = sel.RangeMain().End().Position(); - Sci::Line startLine = pdoc->LineFromPosition(selStart); - Sci::Line endLine = pdoc->LineFromPosition(selEnd); - Point pt; - long startPos, endPos, ep; - PRectangle rcSel; - - if (startLine==endLine && WndProc(SCI_GETWRAPMODE, 0, 0) != SC_WRAP_NONE) { - // Komodo bug http://bugs.activestate.com/show_bug.cgi?id=87571 - // Scintilla bug https://sourceforge.net/tracker/?func=detail&atid=102439&aid=3040200&group_id=2439 - // If the width on a wrapped-line selection is negative, - // find a better bounding rectangle. - - Point ptStart, ptEnd; - startPos = WndProc(SCI_GETLINESELSTARTPOSITION, startLine, 0); - endPos = WndProc(SCI_GETLINESELENDPOSITION, startLine, 0); - // step back a position if we're counting the newline - ep = WndProc(SCI_GETLINEENDPOSITION, startLine, 0); - if (endPos > ep) endPos = ep; - ptStart = LocationFromPosition(static_cast<int>(startPos)); - ptEnd = LocationFromPosition(static_cast<int>(endPos)); - if (ptStart.y == ptEnd.y) { - // We're just selecting part of one visible line - rcSel.left = ptStart.x; - rcSel.right = ptEnd.x < client.right ? ptEnd.x : client.right; - } else { - // Find the bounding box. - startPos = WndProc(SCI_POSITIONFROMLINE, startLine, 0); - rcSel.left = LocationFromPosition(static_cast<int>(startPos)).x; - rcSel.right = client.right; - } - rcSel.top = ptStart.y; - rcSel.bottom = ptEnd.y + vs.lineHeight; - if (rcSel.bottom > client.bottom) { - rcSel.bottom = client.bottom; - } - } else { - rcSel.top = rcSel.bottom = rcSel.right = rcSel.left = -1; - for (int l = startLine; l <= endLine; l++) { - startPos = WndProc(SCI_GETLINESELSTARTPOSITION, l, 0); - endPos = WndProc(SCI_GETLINESELENDPOSITION, l, 0); - if (endPos == startPos) continue; - // step back a position if we're counting the newline - ep = WndProc(SCI_GETLINEENDPOSITION, l, 0); - if (endPos > ep) endPos = ep; - pt = LocationFromPosition(static_cast<int>(startPos)); // top left of line selection - if (pt.x < rcSel.left || rcSel.left < 0) rcSel.left = pt.x; - if (pt.y < rcSel.top || rcSel.top < 0) rcSel.top = pt.y; - pt = LocationFromPosition(static_cast<int>(endPos)); // top right of line selection - pt.y += vs.lineHeight; // get to the bottom of the line - if (pt.x > rcSel.right || rcSel.right < 0) { - if (pt.x > client.right) - rcSel.right = client.right; - else - rcSel.right = pt.x; - } - if (pt.y > rcSel.bottom || rcSel.bottom < 0) { - if (pt.y > client.bottom) - rcSel.bottom = client.bottom; - else - rcSel.bottom = pt.y; - } - } - } - // must convert to global coordinates for drag regions, but also save the - // image rectangle for further calculations and copy operations - - // Prepare drag image. - NSRect selectionRectangle = PRectangleToNSRect(rcSel); - - SCIContentView* content = ContentView(); - - // To get a bitmap of the text we're dragging, we just use Paint on a pixmap surface. - SurfaceImpl sw; - sw.InitPixMap(static_cast<int>(client.Width()), static_cast<int>(client.Height()), NULL, NULL); - - const bool lastHideSelection = view.hideSelection; - view.hideSelection = true; - PRectangle imageRect = rcSel; - paintState = painting; - paintingAllText = true; - CGContextRef gcsw = sw.GetContext(); - CGContextTranslateCTM(gcsw, -client.left, -client.top); - Paint(&sw, client); - paintState = notPainting; - view.hideSelection = lastHideSelection; - - SurfaceImpl pixmap; - pixmap.InitPixMap(static_cast<int>(imageRect.Width()), static_cast<int>(imageRect.Height()), NULL, NULL); - pixmap.SetUnicodeMode(IsUnicodeMode()); - pixmap.SetDBCSMode(CodePage()); - - CGContextRef gc = pixmap.GetContext(); - // To make Paint() work on a bitmap, we have to flip our coordinates and translate the origin - CGContextTranslateCTM(gc, 0, imageRect.Height()); - CGContextScaleCTM(gc, 1.0, -1.0); - - pixmap.CopyImageRectangle(sw, imageRect, PRectangle(0.0f, 0.0f, imageRect.Width(), imageRect.Height())); - // XXX TODO: overwrite any part of the image that is not part of the - // selection to make it transparent. right now we just use - // the full rectangle which may include non-selected text. - - NSBitmapImageRep* bitmap = NULL; - CGImageRef imagePixmap = pixmap.GetImage(); - if (imagePixmap) - bitmap = [[NSBitmapImageRep alloc] initWithCGImage: imagePixmap]; - CGImageRelease(imagePixmap); - - NSImage* image = [[NSImage alloc] initWithSize: selectionRectangle.size]; - [image addRepresentation: bitmap]; - - NSImage* dragImage = [[NSImage alloc] initWithSize: selectionRectangle.size]; - dragImage.backgroundColor = [NSColor clearColor]; - [dragImage lockFocus]; - [image drawAtPoint: NSZeroPoint fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 0.5]; - [dragImage unlockFocus]; - - NSPoint startPoint; - startPoint.x = selectionRectangle.origin.x + client.left; - startPoint.y = selectionRectangle.origin.y + selectionRectangle.size.height + client.top; - - NSPasteboardItem *pbItem = [NSPasteboardItem new]; - DragProviderSource *dps = [[DragProviderSource alloc] initWithSelectedText:&selectedText]; - - NSArray *pbTypes = selectedText.rectangular ? - @[NSPasteboardTypeString, ScintillaRecPboardType] : - @[NSPasteboardTypeString]; - [pbItem setDataProvider:dps forTypes:pbTypes]; - NSDraggingItem *dragItem = [[NSDraggingItem alloc ]initWithPasteboardWriter:pbItem]; - - NSScrollView *scrollContainer = ScrollContainer(); - NSRect contentRect = scrollContainer.contentView.bounds; - NSRect draggingRect = NSOffsetRect(selectionRectangle, contentRect.origin.x, contentRect.origin.y); - [dragItem setDraggingFrame:draggingRect contents:dragImage]; - NSDraggingSession *dragSession = - [content beginDraggingSessionWithItems:@[dragItem] - event:lastMouseEvent - source:content]; - dragSession.animatesToStartingPositionsOnCancelOrFail = YES; - dragSession.draggingFormation = NSDraggingFormationNone; +void ScintillaCocoa::StartDrag() { + if (sel.Empty()) + return; + + inDragDrop = ddDragging; + + FineTickerStart(tickPlatform, timer.tickSize, 0); + + // Put the data to be dragged on the drag pasteboard. + SelectionText selectedText; + NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName: NSDragPboard]; + CopySelectionRange(&selectedText); + SetPasteboardData(pasteboard, selectedText); + + // calculate the bounds of the selection + PRectangle client = GetTextRectangle(); + Sci::Position selStart = sel.RangeMain().Start().Position(); + Sci::Position selEnd = sel.RangeMain().End().Position(); + Sci::Line startLine = pdoc->LineFromPosition(selStart); + Sci::Line endLine = pdoc->LineFromPosition(selEnd); + Point pt; + long startPos, endPos, ep; + PRectangle rcSel; + + if (startLine==endLine && WndProc(SCI_GETWRAPMODE, 0, 0) != SC_WRAP_NONE) { + // Komodo bug http://bugs.activestate.com/show_bug.cgi?id=87571 + // Scintilla bug https://sourceforge.net/tracker/?func=detail&atid=102439&aid=3040200&group_id=2439 + // If the width on a wrapped-line selection is negative, + // find a better bounding rectangle. + + Point ptStart, ptEnd; + startPos = WndProc(SCI_GETLINESELSTARTPOSITION, startLine, 0); + endPos = WndProc(SCI_GETLINESELENDPOSITION, startLine, 0); + // step back a position if we're counting the newline + ep = WndProc(SCI_GETLINEENDPOSITION, startLine, 0); + if (endPos > ep) endPos = ep; + ptStart = LocationFromPosition(static_cast<int>(startPos)); + ptEnd = LocationFromPosition(static_cast<int>(endPos)); + if (ptStart.y == ptEnd.y) { + // We're just selecting part of one visible line + rcSel.left = ptStart.x; + rcSel.right = ptEnd.x < client.right ? ptEnd.x : client.right; + } else { + // Find the bounding box. + startPos = WndProc(SCI_POSITIONFROMLINE, startLine, 0); + rcSel.left = LocationFromPosition(static_cast<int>(startPos)).x; + rcSel.right = client.right; + } + rcSel.top = ptStart.y; + rcSel.bottom = ptEnd.y + vs.lineHeight; + if (rcSel.bottom > client.bottom) { + rcSel.bottom = client.bottom; + } + } else { + rcSel.top = rcSel.bottom = rcSel.right = rcSel.left = -1; + for (int l = startLine; l <= endLine; l++) { + startPos = WndProc(SCI_GETLINESELSTARTPOSITION, l, 0); + endPos = WndProc(SCI_GETLINESELENDPOSITION, l, 0); + if (endPos == startPos) continue; + // step back a position if we're counting the newline + ep = WndProc(SCI_GETLINEENDPOSITION, l, 0); + if (endPos > ep) endPos = ep; + pt = LocationFromPosition(static_cast<int>(startPos)); // top left of line selection + if (pt.x < rcSel.left || rcSel.left < 0) rcSel.left = pt.x; + if (pt.y < rcSel.top || rcSel.top < 0) rcSel.top = pt.y; + pt = LocationFromPosition(static_cast<int>(endPos)); // top right of line selection + pt.y += vs.lineHeight; // get to the bottom of the line + if (pt.x > rcSel.right || rcSel.right < 0) { + if (pt.x > client.right) + rcSel.right = client.right; + else + rcSel.right = pt.x; + } + if (pt.y > rcSel.bottom || rcSel.bottom < 0) { + if (pt.y > client.bottom) + rcSel.bottom = client.bottom; + else + rcSel.bottom = pt.y; + } + } + } + // must convert to global coordinates for drag regions, but also save the + // image rectangle for further calculations and copy operations + + // Prepare drag image. + NSRect selectionRectangle = PRectangleToNSRect(rcSel); + + SCIContentView *content = ContentView(); + + // To get a bitmap of the text we're dragging, we just use Paint on a pixmap surface. + SurfaceImpl sw; + sw.InitPixMap(static_cast<int>(client.Width()), static_cast<int>(client.Height()), NULL, NULL); + + const bool lastHideSelection = view.hideSelection; + view.hideSelection = true; + PRectangle imageRect = rcSel; + paintState = painting; + paintingAllText = true; + CGContextRef gcsw = sw.GetContext(); + CGContextTranslateCTM(gcsw, -client.left, -client.top); + Paint(&sw, client); + paintState = notPainting; + view.hideSelection = lastHideSelection; + + SurfaceImpl pixmap; + pixmap.InitPixMap(static_cast<int>(imageRect.Width()), static_cast<int>(imageRect.Height()), NULL, NULL); + pixmap.SetUnicodeMode(IsUnicodeMode()); + pixmap.SetDBCSMode(CodePage()); + + CGContextRef gc = pixmap.GetContext(); + // To make Paint() work on a bitmap, we have to flip our coordinates and translate the origin + CGContextTranslateCTM(gc, 0, imageRect.Height()); + CGContextScaleCTM(gc, 1.0, -1.0); + + pixmap.CopyImageRectangle(sw, imageRect, PRectangle(0.0f, 0.0f, imageRect.Width(), imageRect.Height())); + // XXX TODO: overwrite any part of the image that is not part of the + // selection to make it transparent. right now we just use + // the full rectangle which may include non-selected text. + + NSBitmapImageRep *bitmap = NULL; + CGImageRef imagePixmap = pixmap.GetImage(); + if (imagePixmap) + bitmap = [[NSBitmapImageRep alloc] initWithCGImage: imagePixmap]; + CGImageRelease(imagePixmap); + + NSImage *image = [[NSImage alloc] initWithSize: selectionRectangle.size]; + [image addRepresentation: bitmap]; + + NSImage *dragImage = [[NSImage alloc] initWithSize: selectionRectangle.size]; + dragImage.backgroundColor = [NSColor clearColor]; + [dragImage lockFocus]; + [image drawAtPoint: NSZeroPoint fromRect: NSZeroRect operation: NSCompositeSourceOver fraction: 0.5]; + [dragImage unlockFocus]; + + NSPoint startPoint; + startPoint.x = selectionRectangle.origin.x + client.left; + startPoint.y = selectionRectangle.origin.y + selectionRectangle.size.height + client.top; + + NSPasteboardItem *pbItem = [NSPasteboardItem new]; + DragProviderSource *dps = [[DragProviderSource alloc] initWithSelectedText: &selectedText]; + + NSArray *pbTypes = selectedText.rectangular ? + @[NSPasteboardTypeString, ScintillaRecPboardType] : + @[NSPasteboardTypeString]; + [pbItem setDataProvider: dps forTypes: pbTypes]; + NSDraggingItem *dragItem = [[NSDraggingItem alloc ]initWithPasteboardWriter: pbItem]; + + NSScrollView *scrollContainer = ScrollContainer(); + NSRect contentRect = scrollContainer.contentView.bounds; + NSRect draggingRect = NSOffsetRect(selectionRectangle, contentRect.origin.x, contentRect.origin.y); + [dragItem setDraggingFrame: draggingRect contents: dragImage]; + NSDraggingSession *dragSession = + [content beginDraggingSessionWithItems: @[dragItem] + event: lastMouseEvent + source: content]; + dragSession.animatesToStartingPositionsOnCancelOrFail = YES; + dragSession.draggingFormation = NSDraggingFormationNone; } //-------------------------------------------------------------------------------------------------- @@ -1486,10 +1419,9 @@ void ScintillaCocoa::StartDrag() /** * Called when a drag operation reaches the control which was initiated outside. */ -NSDragOperation ScintillaCocoa::DraggingEntered(id <NSDraggingInfo> info) -{ - FineTickerStart(tickPlatform, timer.tickSize, 0); - return DraggingUpdated(info); +NSDragOperation ScintillaCocoa::DraggingEntered(id <NSDraggingInfo> info) { + FineTickerStart(tickPlatform, timer.tickSize, 0); + return DraggingUpdated(info); } //-------------------------------------------------------------------------------------------------- @@ -1499,27 +1431,26 @@ NSDragOperation ScintillaCocoa::DraggingEntered(id <NSDraggingInfo> info) * what drag operation we accept and update the drop caret position to indicate the * potential insertion point of the dragged data. */ -NSDragOperation ScintillaCocoa::DraggingUpdated(id <NSDraggingInfo> info) -{ - // Convert the drag location from window coordinates to view coordinates and - // from there to a text position to finally set the drag position. - Point location = ConvertPoint([info draggingLocation]); - SetDragPosition(SPositionFromLocation(location)); +NSDragOperation ScintillaCocoa::DraggingUpdated(id <NSDraggingInfo> info) { + // Convert the drag location from window coordinates to view coordinates and + // from there to a text position to finally set the drag position. + Point location = ConvertPoint([info draggingLocation]); + SetDragPosition(SPositionFromLocation(location)); - NSDragOperation sourceDragMask = [info draggingSourceOperationMask]; - if (sourceDragMask == NSDragOperationNone) - return sourceDragMask; + NSDragOperation sourceDragMask = [info draggingSourceOperationMask]; + if (sourceDragMask == NSDragOperationNone) + return sourceDragMask; - NSPasteboard* pasteboard = [info draggingPasteboard]; + NSPasteboard *pasteboard = [info draggingPasteboard]; - // Return what type of operation we will perform. Prefer move over copy. - if ([pasteboard.types containsObject: NSStringPboardType] || - [pasteboard.types containsObject: ScintillaRecPboardType]) - return (sourceDragMask & NSDragOperationMove) ? NSDragOperationMove : NSDragOperationCopy; + // Return what type of operation we will perform. Prefer move over copy. + if ([pasteboard.types containsObject: NSStringPboardType] || + [pasteboard.types containsObject: ScintillaRecPboardType]) + return (sourceDragMask & NSDragOperationMove) ? NSDragOperationMove : NSDragOperationCopy; - if ([pasteboard.types containsObject: NSFilenamesPboardType]) - return (sourceDragMask & NSDragOperationGeneric); - return NSDragOperationNone; + if ([pasteboard.types containsObject: NSFilenamesPboardType]) + return (sourceDragMask & NSDragOperationGeneric); + return NSDragOperationNone; } //-------------------------------------------------------------------------------------------------- @@ -1527,12 +1458,11 @@ NSDragOperation ScintillaCocoa::DraggingUpdated(id <NSDraggingInfo> info) /** * Resets the current drag position as we are no longer the drag target. */ -void ScintillaCocoa::DraggingExited(id <NSDraggingInfo> info) -{ +void ScintillaCocoa::DraggingExited(id <NSDraggingInfo> info) { #pragma unused(info) - SetDragPosition(SelectionPosition(Sci::invalidPosition)); - FineTickerCancel(tickPlatform); - inDragDrop = ddNone; + SetDragPosition(SelectionPosition(Sci::invalidPosition)); + FineTickerCancel(tickPlatform); + inDragDrop = ddNone; } //-------------------------------------------------------------------------------------------------- @@ -1540,60 +1470,53 @@ void ScintillaCocoa::DraggingExited(id <NSDraggingInfo> info) /** * Here is where the real work is done. Insert the text from the pasteboard. */ -bool ScintillaCocoa::PerformDragOperation(id <NSDraggingInfo> info) -{ - NSPasteboard* pasteboard = [info draggingPasteboard]; +bool ScintillaCocoa::PerformDragOperation(id <NSDraggingInfo> info) { + NSPasteboard *pasteboard = [info draggingPasteboard]; - if ([pasteboard.types containsObject: NSFilenamesPboardType]) - { - NSArray* files = [pasteboard propertyListForType: NSFilenamesPboardType]; - for (NSString* uri in files) - NotifyURIDropped(uri.UTF8String); - } - else - { - SelectionText text; - GetPasteboardData(pasteboard, &text); + if ([pasteboard.types containsObject: NSFilenamesPboardType]) { + NSArray *files = [pasteboard propertyListForType: NSFilenamesPboardType]; + for (NSString* uri in files) + NotifyURIDropped(uri.UTF8String); + } else { + SelectionText text; + GetPasteboardData(pasteboard, &text); - if (text.Length() > 0) - { - NSDragOperation operation = [info draggingSourceOperationMask]; - bool moving = (operation & NSDragOperationMove) != 0; + if (text.Length() > 0) { + NSDragOperation operation = [info draggingSourceOperationMask]; + bool moving = (operation & NSDragOperationMove) != 0; - DropAt(posDrag, text.Data(), text.Length(), moving, text.rectangular); - }; - } + DropAt(posDrag, text.Data(), text.Length(), moving, text.rectangular); + }; + } - return true; + return true; } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::SetPasteboardData(NSPasteboard* board, const SelectionText &selectedText) -{ - if (selectedText.Length() == 0) - return; +void ScintillaCocoa::SetPasteboardData(NSPasteboard *board, const SelectionText &selectedText) { + if (selectedText.Length() == 0) + return; - CFStringEncoding encoding = EncodingFromCharacterSet(selectedText.codePage == SC_CP_UTF8, - selectedText.characterSet); + CFStringEncoding encoding = EncodingFromCharacterSet(selectedText.codePage == SC_CP_UTF8, + selectedText.characterSet); - CFStringRef cfsVal = CFStringFromString(selectedText.Data(), selectedText.Length(), encoding); + CFStringRef cfsVal = CFStringFromString(selectedText.Data(), selectedText.Length(), encoding); - NSArray *pbTypes = selectedText.rectangular ? - @[NSStringPboardType, ScintillaRecPboardType] : - @[NSStringPboardType]; - [board declareTypes:pbTypes owner:nil]; + NSArray *pbTypes = selectedText.rectangular ? + @[NSStringPboardType, ScintillaRecPboardType] : + @[NSStringPboardType]; + [board declareTypes: pbTypes owner: nil]; - if (selectedText.rectangular) - { - // This is specific to scintilla, allows us to drag rectangular selections around the document. - [board setString: (__bridge NSString *)cfsVal forType: ScintillaRecPboardType]; - } + if (selectedText.rectangular) { + // This is specific to scintilla, allows us to drag rectangular selections around the document. + [board setString: (__bridge NSString *)cfsVal forType: ScintillaRecPboardType]; + } - [board setString: (__bridge NSString *)cfsVal forType: NSStringPboardType]; + [board setString: (__bridge NSString *)cfsVal forType: NSStringPboardType]; - if (cfsVal) - CFRelease(cfsVal); + if (cfsVal) + CFRelease(cfsVal); } //-------------------------------------------------------------------------------------------------- @@ -1601,190 +1524,174 @@ void ScintillaCocoa::SetPasteboardData(NSPasteboard* board, const SelectionText /** * Helper method to retrieve the best fitting alternative from the general pasteboard. */ -bool ScintillaCocoa::GetPasteboardData(NSPasteboard* board, SelectionText* selectedText) -{ - NSArray* supportedTypes = @[ScintillaRecPboardType, - NSStringPboardType]; - NSString *bestType = [board availableTypeFromArray: supportedTypes]; - NSString* data = [board stringForType: bestType]; +bool ScintillaCocoa::GetPasteboardData(NSPasteboard *board, SelectionText *selectedText) { + NSArray *supportedTypes = @[ScintillaRecPboardType, + NSStringPboardType]; + NSString *bestType = [board availableTypeFromArray: supportedTypes]; + NSString *data = [board stringForType: bestType]; - if (data != nil) - { - if (selectedText != nil) - { - CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), - vs.styles[STYLE_DEFAULT].characterSet); - CFRange rangeAll = {0, static_cast<CFIndex>(data.length)}; - CFIndex usedLen = 0; - CFStringGetBytes((CFStringRef)data, rangeAll, encoding, '?', - false, NULL, 0, &usedLen); + if (data != nil) { + if (selectedText != nil) { + CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), + vs.styles[STYLE_DEFAULT].characterSet); + CFRange rangeAll = {0, static_cast<CFIndex>(data.length)}; + CFIndex usedLen = 0; + CFStringGetBytes((CFStringRef)data, rangeAll, encoding, '?', + false, NULL, 0, &usedLen); - std::vector<UInt8> buffer(usedLen); + std::vector<UInt8> buffer(usedLen); - CFStringGetBytes((CFStringRef)data, rangeAll, encoding, '?', - false, buffer.data(),usedLen, NULL); + CFStringGetBytes((CFStringRef)data, rangeAll, encoding, '?', + false, buffer.data(), usedLen, NULL); - bool rectangular = bestType == ScintillaRecPboardType; + bool rectangular = bestType == ScintillaRecPboardType; - std::string dest(reinterpret_cast<const char *>(buffer.data()), usedLen); + std::string dest(reinterpret_cast<const char *>(buffer.data()), usedLen); - selectedText->Copy(dest, pdoc->dbcsCodePage, - vs.styles[STYLE_DEFAULT].characterSet , rectangular, false); - } - return true; - } + selectedText->Copy(dest, pdoc->dbcsCodePage, + vs.styles[STYLE_DEFAULT].characterSet, rectangular, false); + } + return true; + } - return false; + return false; } //-------------------------------------------------------------------------------------------------- // Returns the target converted to UTF8. // Return the length in bytes. -int ScintillaCocoa::TargetAsUTF8(char *text) -{ - const int targetLength = targetEnd - targetStart; - if (IsUnicodeMode()) - { - if (text) - pdoc->GetCharRange(text, targetStart, targetLength); - } - else - { - // Need to convert - const CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), - vs.styles[STYLE_DEFAULT].characterSet); - const std::string s = RangeText(targetStart, targetEnd); - CFStringRef cfsVal = CFStringFromString(s.c_str(), s.length(), encoding); - - const std::string tmputf = EncodedBytesString(cfsVal, kCFStringEncodingUTF8); - - if (text) - memcpy(text, tmputf.c_str(), tmputf.length()); - CFRelease(cfsVal); - return static_cast<int>(tmputf.length()); - } - return targetLength; +int ScintillaCocoa::TargetAsUTF8(char *text) { + const int targetLength = targetEnd - targetStart; + if (IsUnicodeMode()) { + if (text) + pdoc->GetCharRange(text, targetStart, targetLength); + } else { + // Need to convert + const CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), + vs.styles[STYLE_DEFAULT].characterSet); + const std::string s = RangeText(targetStart, targetEnd); + CFStringRef cfsVal = CFStringFromString(s.c_str(), s.length(), encoding); + + const std::string tmputf = EncodedBytesString(cfsVal, kCFStringEncodingUTF8); + + if (text) + memcpy(text, tmputf.c_str(), tmputf.length()); + CFRelease(cfsVal); + return static_cast<int>(tmputf.length()); + } + return targetLength; } //-------------------------------------------------------------------------------------------------- // Returns the text in the range converted to an NSString. NSString *ScintillaCocoa::RangeTextAsString(NSRange rangePositions) const { - const std::string text = RangeText(static_cast<int>(rangePositions.location), - static_cast<int>(NSMaxRange(rangePositions))); - if (IsUnicodeMode()) - { - return @(text.c_str()); - } - else - { - // Need to convert - const CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), - vs.styles[STYLE_DEFAULT].characterSet); - CFStringRef cfsVal = CFStringFromString(text.c_str(), text.length(), encoding); + const std::string text = RangeText(static_cast<int>(rangePositions.location), + static_cast<int>(NSMaxRange(rangePositions))); + if (IsUnicodeMode()) { + return @(text.c_str()); + } else { + // Need to convert + const CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), + vs.styles[STYLE_DEFAULT].characterSet); + CFStringRef cfsVal = CFStringFromString(text.c_str(), text.length(), encoding); - return (__bridge NSString *)cfsVal; - } + return (__bridge NSString *)cfsVal; + } } //-------------------------------------------------------------------------------------------------- // Return character range of a line. NSRange ScintillaCocoa::RangeForVisibleLine(NSInteger lineVisible) { - const Range posRangeLine = RangeDisplayLine(static_cast<int>(lineVisible)); - return CharactersFromPositions(NSMakeRange(posRangeLine.First(), - posRangeLine.Last() - posRangeLine.First())); + const Range posRangeLine = RangeDisplayLine(static_cast<int>(lineVisible)); + return CharactersFromPositions(NSMakeRange(posRangeLine.First(), + posRangeLine.Last() - posRangeLine.First())); } //-------------------------------------------------------------------------------------------------- // Returns visible line number of a text position in characters. NSInteger ScintillaCocoa::VisibleLineForIndex(NSInteger index) { - const NSRange rangePosition = PositionsFromCharacters(NSMakeRange(index, 0)); - const int lineVisible = DisplayFromPosition(static_cast<int>(rangePosition.location)); - return lineVisible; + const NSRange rangePosition = PositionsFromCharacters(NSMakeRange(index, 0)); + const int lineVisible = DisplayFromPosition(static_cast<int>(rangePosition.location)); + return lineVisible; } //-------------------------------------------------------------------------------------------------- // Returns a rectangle that frames the range for use by the VoiceOver cursor. NSRect ScintillaCocoa::FrameForRange(NSRange rangeCharacters) { - const NSRange posRange = PositionsFromCharacters(rangeCharacters); + const NSRange posRange = PositionsFromCharacters(rangeCharacters); - NSUInteger rangeEnd = NSMaxRange(posRange); - const bool endsWithLineEnd = rangeCharacters.length && - (pdoc->GetColumn(static_cast<int>(rangeEnd)) == 0); + NSUInteger rangeEnd = NSMaxRange(posRange); + const bool endsWithLineEnd = rangeCharacters.length && + (pdoc->GetColumn(static_cast<int>(rangeEnd)) == 0); - Point ptStart = LocationFromPosition(static_cast<int>(posRange.location)); - const PointEnd peEndRange = static_cast<PointEnd>(peSubLineEnd|peLineEnd); - Point ptEnd = LocationFromPosition(static_cast<int>(rangeEnd), peEndRange); + Point ptStart = LocationFromPosition(static_cast<int>(posRange.location)); + const PointEnd peEndRange = static_cast<PointEnd>(peSubLineEnd|peLineEnd); + Point ptEnd = LocationFromPosition(static_cast<int>(rangeEnd), peEndRange); - NSRect rect = NSMakeRect(ptStart.x, ptStart.y, - ptEnd.x - ptStart.x, - ptEnd.y - ptStart.y); + NSRect rect = NSMakeRect(ptStart.x, ptStart.y, + ptEnd.x - ptStart.x, + ptEnd.y - ptStart.y); - rect.size.width += 2; // Shows the last character better - if (endsWithLineEnd) { - // Add a block to the right to indicate a line end is selected - rect.size.width += 20; - } + rect.size.width += 2; // Shows the last character better + if (endsWithLineEnd) { + // Add a block to the right to indicate a line end is selected + rect.size.width += 20; + } - rect.size.height += vs.lineHeight; + rect.size.height += vs.lineHeight; - // Adjust for margin and scroll - rect.origin.x = rect.origin.x - vs.textStart + vs.fixedColumnWidth; + // Adjust for margin and scroll + rect.origin.x = rect.origin.x - vs.textStart + vs.fixedColumnWidth; - return rect; + return rect; } //-------------------------------------------------------------------------------------------------- // Returns a rectangle that frames the range for use by the VoiceOver cursor. NSRect ScintillaCocoa::GetBounds() const { - return PRectangleToNSRect(GetClientRectangle()); + return PRectangleToNSRect(GetClientRectangle()); } //-------------------------------------------------------------------------------------------------- // Translates a UTF8 string into the document encoding. // Return the length of the result in bytes. -int ScintillaCocoa::EncodedFromUTF8(char *utf8, char *encoded) const -{ - const int inputLength = (lengthForEncode >= 0) ? lengthForEncode : static_cast<int>(strlen(utf8)); - if (IsUnicodeMode()) - { - if (encoded) - memcpy(encoded, utf8, inputLength); - return inputLength; - } - else - { - // Need to convert - const CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), - vs.styles[STYLE_DEFAULT].characterSet); - - CFStringRef cfsVal = CFStringFromString(utf8, inputLength, encoding); - const std::string sEncoded = EncodedBytesString(cfsVal, encoding); - if (encoded) - memcpy(encoded, sEncoded.c_str(), sEncoded.length()); - CFRelease(cfsVal); - return static_cast<int>(sEncoded.length()); - } +int ScintillaCocoa::EncodedFromUTF8(char *utf8, char *encoded) const { + const int inputLength = (lengthForEncode >= 0) ? lengthForEncode : static_cast<int>(strlen(utf8)); + if (IsUnicodeMode()) { + if (encoded) + memcpy(encoded, utf8, inputLength); + return inputLength; + } else { + // Need to convert + const CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), + vs.styles[STYLE_DEFAULT].characterSet); + + CFStringRef cfsVal = CFStringFromString(utf8, inputLength, encoding); + const std::string sEncoded = EncodedBytesString(cfsVal, encoding); + if (encoded) + memcpy(encoded, sEncoded.c_str(), sEncoded.length()); + CFRelease(cfsVal); + return static_cast<int>(sEncoded.length()); + } } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::SetMouseCapture(bool on) -{ - capturedMouse = on; +void ScintillaCocoa::SetMouseCapture(bool on) { + capturedMouse = on; } //-------------------------------------------------------------------------------------------------- -bool ScintillaCocoa::HaveMouseCapture() -{ - return capturedMouse; +bool ScintillaCocoa::HaveMouseCapture() { + return capturedMouse; } //-------------------------------------------------------------------------------------------------- @@ -1792,31 +1699,29 @@ bool ScintillaCocoa::HaveMouseCapture() /** * Synchronously paint a rectangle of the window. */ -bool ScintillaCocoa::SyncPaint(void* gc, PRectangle rc) -{ - paintState = painting; - rcPaint = rc; - PRectangle rcText = GetTextRectangle(); - paintingAllText = rcPaint.Contains(rcText); - std::unique_ptr<Surface> sw(Surface::Allocate(SC_TECHNOLOGY_DEFAULT)); - CGContextSetAllowsAntialiasing((CGContextRef)gc, - vs.extraFontFlag != SC_EFF_QUALITY_NON_ANTIALIASED); - CGContextSetAllowsFontSmoothing((CGContextRef)gc, - vs.extraFontFlag == SC_EFF_QUALITY_LCD_OPTIMIZED); - CGContextSetAllowsFontSubpixelPositioning((CGContextRef)gc, - vs.extraFontFlag == SC_EFF_QUALITY_DEFAULT || - vs.extraFontFlag == SC_EFF_QUALITY_LCD_OPTIMIZED); - sw->Init(gc, wMain.GetID()); - Paint(sw.get(), rc); - const bool succeeded = paintState != paintAbandoned; - sw->Release(); - paintState = notPainting; - if (!succeeded) - { - NSView *marginView = (__bridge NSView*)(wMargin.GetID()); - [marginView setNeedsDisplay:YES]; - } - return succeeded; +bool ScintillaCocoa::SyncPaint(void *gc, PRectangle rc) { + paintState = painting; + rcPaint = rc; + PRectangle rcText = GetTextRectangle(); + paintingAllText = rcPaint.Contains(rcText); + std::unique_ptr<Surface> sw(Surface::Allocate(SC_TECHNOLOGY_DEFAULT)); + CGContextSetAllowsAntialiasing((CGContextRef)gc, + vs.extraFontFlag != SC_EFF_QUALITY_NON_ANTIALIASED); + CGContextSetAllowsFontSmoothing((CGContextRef)gc, + vs.extraFontFlag == SC_EFF_QUALITY_LCD_OPTIMIZED); + CGContextSetAllowsFontSubpixelPositioning((CGContextRef)gc, + vs.extraFontFlag == SC_EFF_QUALITY_DEFAULT || + vs.extraFontFlag == SC_EFF_QUALITY_LCD_OPTIMIZED); + sw->Init(gc, wMain.GetID()); + Paint(sw.get(), rc); + const bool succeeded = paintState != paintAbandoned; + sw->Release(); + paintState = notPainting; + if (!succeeded) { + NSView *marginView = (__bridge NSView *)(wMargin.GetID()); + [marginView setNeedsDisplay: YES]; + } + return succeeded; } //-------------------------------------------------------------------------------------------------- @@ -1824,26 +1729,24 @@ bool ScintillaCocoa::SyncPaint(void* gc, PRectangle rc) /** * Paint the margin into the SCIMarginView space. */ -void ScintillaCocoa::PaintMargin(NSRect aRect) -{ - CGContextRef gc = (CGContextRef) [NSGraphicsContext currentContext].graphicsPort; - - PRectangle rc = NSRectToPRectangle(aRect); - rcPaint = rc; - std::unique_ptr<Surface> sw(Surface::Allocate(SC_TECHNOLOGY_DEFAULT)); - if (sw) - { - CGContextSetAllowsAntialiasing(gc, - vs.extraFontFlag != SC_EFF_QUALITY_NON_ANTIALIASED); - CGContextSetAllowsFontSmoothing(gc, - vs.extraFontFlag == SC_EFF_QUALITY_LCD_OPTIMIZED); - CGContextSetAllowsFontSubpixelPositioning(gc, - vs.extraFontFlag == SC_EFF_QUALITY_DEFAULT || - vs.extraFontFlag == SC_EFF_QUALITY_LCD_OPTIMIZED); - sw->Init(gc, wMargin.GetID()); - PaintSelMargin(sw.get(), rc); - sw->Release(); - } +void ScintillaCocoa::PaintMargin(NSRect aRect) { + CGContextRef gc = (CGContextRef) [NSGraphicsContext currentContext].graphicsPort; + + PRectangle rc = NSRectToPRectangle(aRect); + rcPaint = rc; + std::unique_ptr<Surface> sw(Surface::Allocate(SC_TECHNOLOGY_DEFAULT)); + if (sw) { + CGContextSetAllowsAntialiasing(gc, + vs.extraFontFlag != SC_EFF_QUALITY_NON_ANTIALIASED); + CGContextSetAllowsFontSmoothing(gc, + vs.extraFontFlag == SC_EFF_QUALITY_LCD_OPTIMIZED); + CGContextSetAllowsFontSubpixelPositioning(gc, + vs.extraFontFlag == SC_EFF_QUALITY_DEFAULT || + vs.extraFontFlag == SC_EFF_QUALITY_LCD_OPTIMIZED); + sw->Init(gc, wMargin.GetID()); + PaintSelMargin(sw.get(), rc); + sw->Release(); + } } //-------------------------------------------------------------------------------------------------- @@ -1853,22 +1756,21 @@ void ScintillaCocoa::PaintMargin(NSRect aRect) * * @param rect The area that will be drawn, given in the sender's coordinate system. */ -void ScintillaCocoa::WillDraw(NSRect rect) -{ - RefreshStyleData(); - PRectangle rcWillDraw = NSRectToPRectangle(rect); - const int posAfterArea = PositionAfterArea(rcWillDraw); - const int posAfterMax = PositionAfterMaxStyling(posAfterArea, true); - pdoc->StyleToAdjustingLineDuration(posAfterMax); - StartIdleStyling(posAfterMax < posAfterArea); - NotifyUpdateUI(); - if (WrapLines(WrapScope::wsVisible)) { - // Wrap may have reduced number of lines so more lines may need to be styled - const int posAfterAreaWrapped = PositionAfterArea(rcWillDraw); - pdoc->EnsureStyledTo(posAfterAreaWrapped); - // The wrapping process has changed the height of some lines so redraw all. - Redraw(); - } +void ScintillaCocoa::WillDraw(NSRect rect) { + RefreshStyleData(); + PRectangle rcWillDraw = NSRectToPRectangle(rect); + const int posAfterArea = PositionAfterArea(rcWillDraw); + const int posAfterMax = PositionAfterMaxStyling(posAfterArea, true); + pdoc->StyleToAdjustingLineDuration(posAfterMax); + StartIdleStyling(posAfterMax < posAfterArea); + NotifyUpdateUI(); + if (WrapLines(WrapScope::wsVisible)) { + // Wrap may have reduced number of lines so more lines may need to be styled + const int posAfterAreaWrapped = PositionAfterArea(rcWillDraw); + pdoc->EnsureStyledTo(posAfterAreaWrapped); + // The wrapping process has changed the height of some lines so redraw all. + Redraw(); + } } //-------------------------------------------------------------------------------------------------- @@ -1876,8 +1778,7 @@ void ScintillaCocoa::WillDraw(NSRect rect) /** * ScrollText is empty because scrolling is handled by the NSScrollView. */ -void ScintillaCocoa::ScrollText(Sci::Line) -{ +void ScintillaCocoa::ScrollText(Sci::Line) { } //-------------------------------------------------------------------------------------------------- @@ -1885,15 +1786,14 @@ void ScintillaCocoa::ScrollText(Sci::Line) /** * Modifies the vertical scroll position to make the current top line show up as such. */ -void ScintillaCocoa::SetVerticalScrollPos() -{ - NSScrollView *scrollView = ScrollContainer(); - if (scrollView) { - NSClipView *clipView = scrollView.contentView; - NSRect contentRect = clipView.bounds; - [clipView scrollToPoint: NSMakePoint(contentRect.origin.x, topLine * vs.lineHeight)]; - [scrollView reflectScrolledClipView:clipView]; - } +void ScintillaCocoa::SetVerticalScrollPos() { + NSScrollView *scrollView = ScrollContainer(); + if (scrollView) { + NSClipView *clipView = scrollView.contentView; + NSRect contentRect = clipView.bounds; + [clipView scrollToPoint: NSMakePoint(contentRect.origin.x, topLine * vs.lineHeight)]; + [scrollView reflectScrolledClipView: clipView]; + } } //-------------------------------------------------------------------------------------------------- @@ -1901,23 +1801,22 @@ void ScintillaCocoa::SetVerticalScrollPos() /** * Modifies the horizontal scroll position to match xOffset. */ -void ScintillaCocoa::SetHorizontalScrollPos() -{ - PRectangle textRect = GetTextRectangle(); - - int maxXOffset = scrollWidth - static_cast<int>(textRect.Width()); - if (maxXOffset < 0) - maxXOffset = 0; - if (xOffset > maxXOffset) - xOffset = maxXOffset; - NSScrollView *scrollView = ScrollContainer(); - if (scrollView) { - NSClipView * clipView = scrollView.contentView; - NSRect contentRect = clipView.bounds; - [clipView scrollToPoint: NSMakePoint(xOffset, contentRect.origin.y)]; - [scrollView reflectScrolledClipView:clipView]; - } - MoveFindIndicatorWithBounce(NO); +void ScintillaCocoa::SetHorizontalScrollPos() { + PRectangle textRect = GetTextRectangle(); + + int maxXOffset = scrollWidth - static_cast<int>(textRect.Width()); + if (maxXOffset < 0) + maxXOffset = 0; + if (xOffset > maxXOffset) + xOffset = maxXOffset; + NSScrollView *scrollView = ScrollContainer(); + if (scrollView) { + NSClipView *clipView = scrollView.contentView; + NSRect contentRect = clipView.bounds; + [clipView scrollToPoint: NSMakePoint(xOffset, contentRect.origin.y)]; + [scrollView reflectScrolledClipView: clipView]; + } + MoveFindIndicatorWithBounce(NO); } //-------------------------------------------------------------------------------------------------- @@ -1930,10 +1829,9 @@ void ScintillaCocoa::SetHorizontalScrollPos() * @param nPage Number of lines per scroll page. * @return True if there was a change, otherwise false. */ -bool ScintillaCocoa::ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) -{ +bool ScintillaCocoa::ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) { #pragma unused(nMax, nPage) - return SetScrollingSize(); + return SetScrollingSize(); } bool ScintillaCocoa::SetScrollingSize(void) { @@ -1955,13 +1853,13 @@ bool ScintillaCocoa::SetScrollingSize(void) { docHeight = clipRect.size.height; CGFloat docWidth = scrollWidth; bool showHorizontalScroll = horizontalScrollBarVisible && - !Wrapping(); + !Wrapping(); if (!showHorizontalScroll) docWidth = clipRect.size.width; NSRect contentRect = {{0, 0}, {docWidth, docHeight}}; NSRect contentRectNow = inner.frame; changes = (contentRect.size.width != contentRectNow.size.width) || - (contentRect.size.height != contentRectNow.size.height); + (contentRect.size.height != contentRectNow.size.height); if (changes) { inner.frame = contentRect; } @@ -1976,10 +1874,9 @@ bool ScintillaCocoa::SetScrollingSize(void) { //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::Resize() -{ - SetScrollingSize(); - ChangeSize(); +void ScintillaCocoa::Resize() { + SetScrollingSize(); + ChangeSize(); } //-------------------------------------------------------------------------------------------------- @@ -1988,10 +1885,10 @@ void ScintillaCocoa::Resize() * Update fields to match scroll position after receiving a notification that the user has scrolled. */ void ScintillaCocoa::UpdateForScroll() { - Point ptOrigin = GetVisibleOriginInMain(); - xOffset = static_cast<int>(ptOrigin.x); - int newTop = Platform::Minimum(static_cast<int>(ptOrigin.y / vs.lineHeight), MaxScrollPos()); - SetTopLine(newTop); + Point ptOrigin = GetVisibleOriginInMain(); + xOffset = static_cast<int>(ptOrigin.x); + int newTop = Platform::Minimum(static_cast<int>(ptOrigin.y / vs.lineHeight), MaxScrollPos()); + SetTopLine(newTop); } //-------------------------------------------------------------------------------------------------- @@ -2004,9 +1901,8 @@ void ScintillaCocoa::UpdateForScroll() { * @param delegate_ A pointer to an object that implements ScintillaNotificationProtocol. */ -void ScintillaCocoa::SetDelegate(id<ScintillaNotificationProtocol> delegate_) -{ - delegate = delegate_; +void ScintillaCocoa::SetDelegate(id<ScintillaNotificationProtocol> delegate_) { + delegate = delegate_; } //-------------------------------------------------------------------------------------------------- @@ -2020,31 +1916,28 @@ void ScintillaCocoa::SetDelegate(id<ScintillaNotificationProtocol> delegate_) * @param callback The callback function to be used for future notifications. If NULL then no * notifications will be sent anymore. */ -void ScintillaCocoa::RegisterNotifyCallback(intptr_t windowid, SciNotifyFunc callback) -{ - notifyObj = windowid; - notifyProc = callback; +void ScintillaCocoa::RegisterNotifyCallback(intptr_t windowid, SciNotifyFunc callback) { + notifyObj = windowid; + notifyProc = callback; } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::NotifyChange() -{ - if (notifyProc != NULL) - notifyProc(notifyObj, WM_COMMAND, Platform::LongFromTwoShorts(static_cast<short>(GetCtrlID()), SCEN_CHANGE), - (uintptr_t) this); +void ScintillaCocoa::NotifyChange() { + if (notifyProc != NULL) + notifyProc(notifyObj, WM_COMMAND, Platform::LongFromTwoShorts(static_cast<short>(GetCtrlID()), SCEN_CHANGE), + (uintptr_t) this); } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::NotifyFocus(bool focus) -{ - if (notifyProc != NULL) - notifyProc(notifyObj, WM_COMMAND, Platform::LongFromTwoShorts(static_cast<short>(GetCtrlID()), - (focus ? SCEN_SETFOCUS : SCEN_KILLFOCUS)), - (uintptr_t) this); +void ScintillaCocoa::NotifyFocus(bool focus) { + if (notifyProc != NULL) + notifyProc(notifyObj, WM_COMMAND, Platform::LongFromTwoShorts(static_cast<short>(GetCtrlID()), + (focus ? SCEN_SETFOCUS : SCEN_KILLFOCUS)), + (uintptr_t) this); - Editor::NotifyFocus(focus); + Editor::NotifyFocus(focus); } //-------------------------------------------------------------------------------------------------- @@ -2055,77 +1948,68 @@ void ScintillaCocoa::NotifyFocus(bool focus) * * @param scn The notification to send. */ -void ScintillaCocoa::NotifyParent(SCNotification scn) -{ - scn.nmhdr.hwndFrom = (void*) this; - scn.nmhdr.idFrom = GetCtrlID(); - if (notifyProc != NULL) - notifyProc(notifyObj, WM_NOTIFY, GetCtrlID(), (uintptr_t) &scn); - if (delegate) - [delegate notification:&scn]; - if (scn.nmhdr.code == SCN_UPDATEUI) { - NSView *content = ContentView(); - if (scn.updated & SC_UPDATE_CONTENT) { - NSAccessibilityPostNotification(content, NSAccessibilityValueChangedNotification); - } - if (scn.updated & SC_UPDATE_SELECTION) { - NSAccessibilityPostNotification(content, NSAccessibilitySelectedTextChangedNotification); - } - } +void ScintillaCocoa::NotifyParent(SCNotification scn) { + scn.nmhdr.hwndFrom = (void *) this; + scn.nmhdr.idFrom = GetCtrlID(); + if (notifyProc != NULL) + notifyProc(notifyObj, WM_NOTIFY, GetCtrlID(), (uintptr_t) &scn); + if (delegate) + [delegate notification: &scn]; + if (scn.nmhdr.code == SCN_UPDATEUI) { + NSView *content = ContentView(); + if (scn.updated & SC_UPDATE_CONTENT) { + NSAccessibilityPostNotification(content, NSAccessibilityValueChangedNotification); + } + if (scn.updated & SC_UPDATE_SELECTION) { + NSAccessibilityPostNotification(content, NSAccessibilitySelectedTextChangedNotification); + } + } } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::NotifyURIDropped(const char *uri) -{ - SCNotification scn; - scn.nmhdr.code = SCN_URIDROPPED; - scn.text = uri; +void ScintillaCocoa::NotifyURIDropped(const char *uri) { + SCNotification scn; + scn.nmhdr.code = SCN_URIDROPPED; + scn.text = uri; - NotifyParent(scn); + NotifyParent(scn); } //-------------------------------------------------------------------------------------------------- -bool ScintillaCocoa::HasSelection() -{ - return !sel.Empty(); +bool ScintillaCocoa::HasSelection() { + return !sel.Empty(); } //-------------------------------------------------------------------------------------------------- -bool ScintillaCocoa::CanUndo() -{ - return pdoc->CanUndo(); +bool ScintillaCocoa::CanUndo() { + return pdoc->CanUndo(); } //-------------------------------------------------------------------------------------------------- -bool ScintillaCocoa::CanRedo() -{ - return pdoc->CanRedo(); +bool ScintillaCocoa::CanRedo() { + return pdoc->CanRedo(); } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::TimerFired(NSTimer* timer) -{ - for (TickReason tr=tickCaret; tr<=tickPlatform; tr = static_cast<TickReason>(tr+1)) - { - if (timers[tr] == timer) - { - TickFor(tr); - } - } +void ScintillaCocoa::TimerFired(NSTimer *timer) { + for (TickReason tr=tickCaret; tr<=tickPlatform; tr = static_cast<TickReason>(tr+1)) { + if (timers[tr] == timer) { + TickFor(tr); + } + } } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::IdleTimerFired() -{ - bool more = Idle(); - if (!more) - SetIdle(false); +void ScintillaCocoa::IdleTimerFired() { + bool more = Idle(); + if (!more) + SetIdle(false); } //-------------------------------------------------------------------------------------------------- @@ -2136,9 +2020,8 @@ void ScintillaCocoa::IdleTimerFired() * @param rect The area to paint, given in the sender's coordinate system. * @param gc The context we can use to paint. */ -bool ScintillaCocoa::Draw(NSRect rect, CGContextRef gc) -{ - return SyncPaint(gc, NSRectToPRectangle(rect)); +bool ScintillaCocoa::Draw(NSRect rect, CGContextRef gc) { + return SyncPaint(gc, NSRectToPRectangle(rect)); } //-------------------------------------------------------------------------------------------------- @@ -2146,58 +2029,56 @@ bool ScintillaCocoa::Draw(NSRect rect, CGContextRef gc) /** * Helper function to translate OS X key codes to Scintilla key codes. */ -static inline UniChar KeyTranslate(UniChar unicodeChar, NSEventModifierFlags modifierFlags) -{ - switch (unicodeChar) - { - case NSDownArrowFunctionKey: - return SCK_DOWN; - case NSUpArrowFunctionKey: - return SCK_UP; - case NSLeftArrowFunctionKey: - return SCK_LEFT; - case NSRightArrowFunctionKey: - return SCK_RIGHT; - case NSHomeFunctionKey: - return SCK_HOME; - case NSEndFunctionKey: - return SCK_END; - case NSPageUpFunctionKey: - return SCK_PRIOR; - case NSPageDownFunctionKey: - return SCK_NEXT; - case NSDeleteFunctionKey: - return SCK_DELETE; - case NSInsertFunctionKey: - return SCK_INSERT; - case '\n': - case 3: - return SCK_RETURN; - case 27: - return SCK_ESCAPE; - case '+': - if (modifierFlags & NSNumericPadKeyMask) - return SCK_ADD; - else - return unicodeChar; - case '-': - if (modifierFlags & NSNumericPadKeyMask) - return SCK_SUBTRACT; - else - return unicodeChar; - case '/': - if (modifierFlags & NSNumericPadKeyMask) - return SCK_DIVIDE; - else - return unicodeChar; - case 127: - return SCK_BACK; - case '\t': - case 25: // Shift tab, return to unmodified tab and handle that via modifiers. - return SCK_TAB; - default: - return unicodeChar; - } +static inline UniChar KeyTranslate(UniChar unicodeChar, NSEventModifierFlags modifierFlags) { + switch (unicodeChar) { + case NSDownArrowFunctionKey: + return SCK_DOWN; + case NSUpArrowFunctionKey: + return SCK_UP; + case NSLeftArrowFunctionKey: + return SCK_LEFT; + case NSRightArrowFunctionKey: + return SCK_RIGHT; + case NSHomeFunctionKey: + return SCK_HOME; + case NSEndFunctionKey: + return SCK_END; + case NSPageUpFunctionKey: + return SCK_PRIOR; + case NSPageDownFunctionKey: + return SCK_NEXT; + case NSDeleteFunctionKey: + return SCK_DELETE; + case NSInsertFunctionKey: + return SCK_INSERT; + case '\n': + case 3: + return SCK_RETURN; + case 27: + return SCK_ESCAPE; + case '+': + if (modifierFlags & NSNumericPadKeyMask) + return SCK_ADD; + else + return unicodeChar; + case '-': + if (modifierFlags & NSNumericPadKeyMask) + return SCK_SUBTRACT; + else + return unicodeChar; + case '/': + if (modifierFlags & NSNumericPadKeyMask) + return SCK_DIVIDE; + else + return unicodeChar; + case 127: + return SCK_BACK; + case '\t': + case 25: // Shift tab, return to unmodified tab and handle that via modifiers. + return SCK_TAB; + default: + return unicodeChar; + } } //-------------------------------------------------------------------------------------------------- @@ -2208,14 +2089,13 @@ static inline UniChar KeyTranslate(UniChar unicodeChar, NSEventModifierFlags mod * @param modifiers An integer bit set of NSSEvent modifier flags. * @return A set of SCI_* modifier flags. */ -static int TranslateModifierFlags(NSUInteger modifiers) -{ - // Signal Control as SCI_META - return - (((modifiers & NSShiftKeyMask) != 0) ? SCI_SHIFT : 0) | - (((modifiers & NSCommandKeyMask) != 0) ? SCI_CTRL : 0) | - (((modifiers & NSAlternateKeyMask) != 0) ? SCI_ALT : 0) | - (((modifiers & NSControlKeyMask) != 0) ? SCI_META : 0); +static int TranslateModifierFlags(NSUInteger modifiers) { + // Signal Control as SCI_META + return + (((modifiers & NSShiftKeyMask) != 0) ? SCI_SHIFT : 0) | + (((modifiers & NSCommandKeyMask) != 0) ? SCI_CTRL : 0) | + (((modifiers & NSAlternateKeyMask) != 0) ? SCI_ALT : 0) | + (((modifiers & NSControlKeyMask) != 0) ? SCI_META : 0); } //-------------------------------------------------------------------------------------------------- @@ -2227,30 +2107,28 @@ static int TranslateModifierFlags(NSUInteger modifiers) * @param event The event instance associated with the key down event. * @return True if the input was handled, false otherwise. */ -bool ScintillaCocoa::KeyboardInput(NSEvent* event) -{ - // For now filter out function keys. - NSString* input = event.charactersIgnoringModifiers; +bool ScintillaCocoa::KeyboardInput(NSEvent *event) { + // For now filter out function keys. + NSString *input = event.charactersIgnoringModifiers; - bool handled = false; + bool handled = false; - // Handle each entry individually. Usually we only have one entry anyway. - for (size_t i = 0; i < input.length; i++) - { - const UniChar originalKey = [input characterAtIndex: i]; - NSEventModifierFlags modifierFlags = event.modifierFlags; - - UniChar key = KeyTranslate(originalKey, modifierFlags); + // Handle each entry individually. Usually we only have one entry anyway. + for (size_t i = 0; i < input.length; i++) { + const UniChar originalKey = [input characterAtIndex: i]; + NSEventModifierFlags modifierFlags = event.modifierFlags; - bool consumed = false; // Consumed as command? + UniChar key = KeyTranslate(originalKey, modifierFlags); - if (KeyDownWithModifiers(key, TranslateModifierFlags(modifierFlags), &consumed)) - handled = true; - if (consumed) - handled = true; - } + bool consumed = false; // Consumed as command? - return handled; + if (KeyDownWithModifiers(key, TranslateModifierFlags(modifierFlags), &consumed)) + handled = true; + if (consumed) + handled = true; + } + + return handled; } //-------------------------------------------------------------------------------------------------- @@ -2258,17 +2136,15 @@ bool ScintillaCocoa::KeyboardInput(NSEvent* event) /** * Used to insert already processed text provided by the Cocoa text input system. */ -int ScintillaCocoa::InsertText(NSString* input) -{ - CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), - vs.styles[STYLE_DEFAULT].characterSet); - std::string encoded = EncodedBytesString((__bridge CFStringRef)input, encoding); +int ScintillaCocoa::InsertText(NSString *input) { + CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), + vs.styles[STYLE_DEFAULT].characterSet); + std::string encoded = EncodedBytesString((__bridge CFStringRef)input, encoding); - if (encoded.length() > 0) - { - AddCharUTF(encoded.c_str(), static_cast<unsigned int>(encoded.length()), false); - } - return static_cast<int>(encoded.length()); + if (encoded.length() > 0) { + AddCharUTF(encoded.c_str(), static_cast<unsigned int>(encoded.length()), false); + } + return static_cast<int>(encoded.length()); } //-------------------------------------------------------------------------------------------------- @@ -2276,15 +2152,14 @@ int ScintillaCocoa::InsertText(NSString* input) /** * Convert from a range of characters to a range of bytes. */ -NSRange ScintillaCocoa::PositionsFromCharacters(NSRange rangeCharacters) const -{ - long start = pdoc->GetRelativePositionUTF16(0, static_cast<int>(rangeCharacters.location)); - if (start == INVALID_POSITION) - start = pdoc->Length(); - long end = pdoc->GetRelativePositionUTF16(static_cast<int>(start), static_cast<int>(rangeCharacters.length)); - if (end == INVALID_POSITION) - end = pdoc->Length(); - return NSMakeRange(start, end - start); +NSRange ScintillaCocoa::PositionsFromCharacters(NSRange rangeCharacters) const { + long start = pdoc->GetRelativePositionUTF16(0, static_cast<int>(rangeCharacters.location)); + if (start == INVALID_POSITION) + start = pdoc->Length(); + long end = pdoc->GetRelativePositionUTF16(static_cast<int>(start), static_cast<int>(rangeCharacters.length)); + if (end == INVALID_POSITION) + end = pdoc->Length(); + return NSMakeRange(start, end - start); } //-------------------------------------------------------------------------------------------------- @@ -2292,12 +2167,11 @@ NSRange ScintillaCocoa::PositionsFromCharacters(NSRange rangeCharacters) const /** * Convert from a range of characters from a range of bytes. */ -NSRange ScintillaCocoa::CharactersFromPositions(NSRange rangePositions) const -{ - const long start = pdoc->CountUTF16(0, static_cast<int>(rangePositions.location)); - const long len = pdoc->CountUTF16(static_cast<int>(rangePositions.location), - static_cast<int>(NSMaxRange(rangePositions))); - return NSMakeRange(start, len); +NSRange ScintillaCocoa::CharactersFromPositions(NSRange rangePositions) const { + const long start = pdoc->CountUTF16(0, static_cast<int>(rangePositions.location)); + const long len = pdoc->CountUTF16(static_cast<int>(rangePositions.location), + static_cast<int>(NSMaxRange(rangePositions))); + return NSMakeRange(start, len); } //-------------------------------------------------------------------------------------------------- @@ -2306,10 +2180,9 @@ NSRange ScintillaCocoa::CharactersFromPositions(NSRange rangePositions) const * Used to ensure that only one selection is active for input composition as composition * does not support multi-typing. */ -void ScintillaCocoa::SelectOnlyMainSelection() -{ - sel.SetSelection(sel.RangeMain()); - Redraw(); +void ScintillaCocoa::SelectOnlyMainSelection() { + sel.SetSelection(sel.RangeMain()); + Redraw(); } //-------------------------------------------------------------------------------------------------- @@ -2317,9 +2190,8 @@ void ScintillaCocoa::SelectOnlyMainSelection() /** * Convert virtual space before selection into real space. */ -void ScintillaCocoa::ConvertSelectionVirtualSpace() -{ - ClearBeforeTentativeStart(); +void ScintillaCocoa::ConvertSelectionVirtualSpace() { + ClearBeforeTentativeStart(); } //-------------------------------------------------------------------------------------------------- @@ -2328,10 +2200,9 @@ void ScintillaCocoa::ConvertSelectionVirtualSpace() * Erase all selected text and return whether the selection is now empty. * The selection may not be empty if the selection contained protected text. */ -bool ScintillaCocoa::ClearAllSelections() -{ - ClearSelection(true); - return sel.Empty(); +bool ScintillaCocoa::ClearAllSelections() { + ClearSelection(true); + return sel.Empty(); } //-------------------------------------------------------------------------------------------------- @@ -2339,13 +2210,11 @@ bool ScintillaCocoa::ClearAllSelections() /** * Start composing for IME. */ -void ScintillaCocoa::CompositionStart() -{ - if (!sel.Empty()) - { - NSLog(@"Selection not empty when starting composition"); - } - pdoc->TentativeStart(); +void ScintillaCocoa::CompositionStart() { + if (!sel.Empty()) { + NSLog(@"Selection not empty when starting composition"); + } + pdoc->TentativeStart(); } //-------------------------------------------------------------------------------------------------- @@ -2353,11 +2222,10 @@ void ScintillaCocoa::CompositionStart() /** * Commit the IME text. */ -void ScintillaCocoa::CompositionCommit() -{ - pdoc->TentativeCommit(); - pdoc->DecorationSetCurrentIndicator(INDIC_IME); - pdoc->DecorationFillRange(0, 0, pdoc->Length()); +void ScintillaCocoa::CompositionCommit() { + pdoc->TentativeCommit(); + pdoc->DecorationSetCurrentIndicator(INDIC_IME); + pdoc->DecorationFillRange(0, 0, pdoc->Length()); } //-------------------------------------------------------------------------------------------------- @@ -2365,9 +2233,8 @@ void ScintillaCocoa::CompositionCommit() /** * Remove the IME text. */ -void ScintillaCocoa::CompositionUndo() -{ - pdoc->TentativeUndo(); +void ScintillaCocoa::CompositionUndo() { + pdoc->TentativeUndo(); } //-------------------------------------------------------------------------------------------------- @@ -2375,14 +2242,13 @@ void ScintillaCocoa::CompositionUndo() * When switching documents discard any incomplete character composition state as otherwise tries to * act on the new document. */ -void ScintillaCocoa::SetDocPointer(Document *document) -{ - // Drop input composition. - NSTextInputContext *inctxt = [NSTextInputContext currentInputContext]; - [inctxt discardMarkedText]; - SCIContentView *inner = ContentView(); - [inner unmarkText]; - Editor::SetDocPointer(document); +void ScintillaCocoa::SetDocPointer(Document *document) { + // Drop input composition. + NSTextInputContext *inctxt = [NSTextInputContext currentInputContext]; + [inctxt discardMarkedText]; + SCIContentView *inner = ContentView(); + [inner unmarkText]; + Editor::SetDocPointer(document); } //-------------------------------------------------------------------------------------------------- @@ -2390,146 +2256,127 @@ void ScintillaCocoa::SetDocPointer(Document *document) /** * Called by the owning view when the mouse pointer enters the control. */ -void ScintillaCocoa::MouseEntered(NSEvent* event) -{ - if (!HaveMouseCapture()) - { - WndProc(SCI_SETCURSOR, (long int)SC_CURSORNORMAL, 0); +void ScintillaCocoa::MouseEntered(NSEvent *event) { + if (!HaveMouseCapture()) { + WndProc(SCI_SETCURSOR, (long int)SC_CURSORNORMAL, 0); - // Mouse location is given in screen coordinates and might also be outside of our bounds. - Point location = ConvertPoint(event.locationInWindow); - ButtonMove(location); - } + // Mouse location is given in screen coordinates and might also be outside of our bounds. + Point location = ConvertPoint(event.locationInWindow); + ButtonMove(location); + } } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::MouseExited(NSEvent* /* event */) -{ - // Nothing to do here. +void ScintillaCocoa::MouseExited(NSEvent * /* event */) { + // Nothing to do here. } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::MouseDown(NSEvent* event) -{ - Point location = ConvertPoint(event.locationInWindow); - NSTimeInterval time = event.timestamp; - bool command = (event.modifierFlags & NSCommandKeyMask) != 0; - bool shift = (event.modifierFlags & NSShiftKeyMask) != 0; - bool alt = (event.modifierFlags & NSAlternateKeyMask) != 0; +void ScintillaCocoa::MouseDown(NSEvent *event) { + Point location = ConvertPoint(event.locationInWindow); + NSTimeInterval time = event.timestamp; + bool command = (event.modifierFlags & NSCommandKeyMask) != 0; + bool shift = (event.modifierFlags & NSShiftKeyMask) != 0; + bool alt = (event.modifierFlags & NSAlternateKeyMask) != 0; - ButtonDown(Point(location.x, location.y), (int) (time * 1000), shift, command, alt); + ButtonDown(Point(location.x, location.y), (int)(time * 1000), shift, command, alt); } -void ScintillaCocoa::RightMouseDown(NSEvent *event) -{ - Point location = ConvertPoint(event.locationInWindow); - NSTimeInterval time = event.timestamp; - bool command = (event.modifierFlags & NSCommandKeyMask) != 0; - bool shift = (event.modifierFlags & NSShiftKeyMask) != 0; - bool alt = (event.modifierFlags & NSAlternateKeyMask) != 0; +void ScintillaCocoa::RightMouseDown(NSEvent *event) { + Point location = ConvertPoint(event.locationInWindow); + NSTimeInterval time = event.timestamp; + bool command = (event.modifierFlags & NSCommandKeyMask) != 0; + bool shift = (event.modifierFlags & NSShiftKeyMask) != 0; + bool alt = (event.modifierFlags & NSAlternateKeyMask) != 0; - RightButtonDownWithModifiers(Point(location.x, location.y), (int) (time * 1000), ModifierFlags(shift, command, alt)); + RightButtonDownWithModifiers(Point(location.x, location.y), (int)(time * 1000), ModifierFlags(shift, command, alt)); } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::MouseMove(NSEvent* event) -{ - lastMouseEvent = event; +void ScintillaCocoa::MouseMove(NSEvent *event) { + lastMouseEvent = event; - ButtonMoveWithModifiers(ConvertPoint(event.locationInWindow), TranslateModifierFlags(event.modifierFlags)); + ButtonMoveWithModifiers(ConvertPoint(event.locationInWindow), TranslateModifierFlags(event.modifierFlags)); } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::MouseUp(NSEvent* event) -{ - NSTimeInterval time = event.timestamp; - bool control = (event.modifierFlags & NSControlKeyMask) != 0; +void ScintillaCocoa::MouseUp(NSEvent *event) { + NSTimeInterval time = event.timestamp; + bool control = (event.modifierFlags & NSControlKeyMask) != 0; - ButtonUp(ConvertPoint(event.locationInWindow), (int) (time * 1000), control); + ButtonUp(ConvertPoint(event.locationInWindow), (int)(time * 1000), control); } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::MouseWheel(NSEvent* event) -{ - bool command = (event.modifierFlags & NSCommandKeyMask) != 0; - int dY = 0; +void ScintillaCocoa::MouseWheel(NSEvent *event) { + bool command = (event.modifierFlags & NSCommandKeyMask) != 0; + int dY = 0; - // In order to make scrolling with larger offset smoother we scroll less lines the larger the - // delta value is. - if (event.deltaY < 0) - dY = -(int) sqrt(-10.0 * event.deltaY); - else - dY = (int) sqrt(10.0 * event.deltaY); + // In order to make scrolling with larger offset smoother we scroll less lines the larger the + // delta value is. + if (event.deltaY < 0) + dY = -(int) sqrt(-10.0 * event.deltaY); + else + dY = (int) sqrt(10.0 * event.deltaY); - if (command) - { - // Zoom! We play with the font sizes in the styles. - // Number of steps/line is ignored, we just care if sizing up or down. - if (dY > 0.5) - KeyCommand(SCI_ZOOMIN); - else if (dY < -0.5) - KeyCommand(SCI_ZOOMOUT); - } - else - { - } + if (command) { + // Zoom! We play with the font sizes in the styles. + // Number of steps/line is ignored, we just care if sizing up or down. + if (dY > 0.5) + KeyCommand(SCI_ZOOMIN); + else if (dY < -0.5) + KeyCommand(SCI_ZOOMOUT); + } else { + } } //-------------------------------------------------------------------------------------------------- // Helper methods for NSResponder actions. -void ScintillaCocoa::SelectAll() -{ - Editor::SelectAll(); +void ScintillaCocoa::SelectAll() { + Editor::SelectAll(); } -void ScintillaCocoa::DeleteBackward() -{ - KeyDown(SCK_BACK, false, false, false, nil); +void ScintillaCocoa::DeleteBackward() { + KeyDown(SCK_BACK, false, false, false, nil); } -void ScintillaCocoa::Cut() -{ - Editor::Cut(); +void ScintillaCocoa::Cut() { + Editor::Cut(); } -void ScintillaCocoa::Undo() -{ - Editor::Undo(); +void ScintillaCocoa::Undo() { + Editor::Undo(); } -void ScintillaCocoa::Redo() -{ - Editor::Redo(); +void ScintillaCocoa::Redo() { + Editor::Redo(); } //-------------------------------------------------------------------------------------------------- -bool ScintillaCocoa::ShouldDisplayPopupOnMargin() -{ - return displayPopupMenu == SC_POPUP_ALL; +bool ScintillaCocoa::ShouldDisplayPopupOnMargin() { + return displayPopupMenu == SC_POPUP_ALL; } -bool ScintillaCocoa::ShouldDisplayPopupOnText() -{ - return displayPopupMenu == SC_POPUP_ALL || displayPopupMenu == SC_POPUP_TEXT; +bool ScintillaCocoa::ShouldDisplayPopupOnText() { + return displayPopupMenu == SC_POPUP_ALL || displayPopupMenu == SC_POPUP_TEXT; } /** * Creates and returns a popup menu, which is then displayed by the Cocoa framework. */ -NSMenu* ScintillaCocoa::CreateContextMenu(NSEvent* /* event */) -{ - // Call ScintillaBase to create the context menu. - ContextMenu(Point(0, 0)); +NSMenu *ScintillaCocoa::CreateContextMenu(NSEvent * /* event */) { + // Call ScintillaBase to create the context menu. + ContextMenu(Point(0, 0)); - return (__bridge NSMenu*)(popup.GetID()); + return (__bridge NSMenu *)(popup.GetID()); } //-------------------------------------------------------------------------------------------------- @@ -2538,23 +2385,21 @@ NSMenu* ScintillaCocoa::CreateContextMenu(NSEvent* /* event */) * An intermediate function to forward context menu commands from the menu action handler to * scintilla. */ -void ScintillaCocoa::HandleCommand(NSInteger command) -{ - Command(static_cast<int>(command)); +void ScintillaCocoa::HandleCommand(NSInteger command) { + Command(static_cast<int>(command)); } //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::ActiveStateChanged(bool isActive) -{ - // If the window is being deactivated, lose the focus and turn off the ticking - if (!isActive) { - DropCaret(); - //SetFocusState( false ); - FineTickerCancel(tickCaret); - } else { - ShowCaretAtCurrentPosition(); - } +void ScintillaCocoa::ActiveStateChanged(bool isActive) { + // If the window is being deactivated, lose the focus and turn off the ticking + if (!isActive) { + DropCaret(); + //SetFocusState( false ); + FineTickerCancel(tickCaret); + } else { + ShowCaretAtCurrentPosition(); + } } //-------------------------------------------------------------------------------------------------- @@ -2564,8 +2409,8 @@ void ScintillaCocoa::ActiveStateChanged(bool isActive) * so cancel them. */ void ScintillaCocoa::WindowWillMove() { - AutoCompleteCancel(); - ct.CallTipCancel(); + AutoCompleteCancel(); + ct.CallTipCancel(); } // If building with old SDK, need to define version number for 10.8 @@ -2575,85 +2420,74 @@ void ScintillaCocoa::WindowWillMove() { //-------------------------------------------------------------------------------------------------- -void ScintillaCocoa::ShowFindIndicatorForRange(NSRange charRange, BOOL retaining) -{ +void ScintillaCocoa::ShowFindIndicatorForRange(NSRange charRange, BOOL retaining) { #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 - NSView *content = ContentView(); - if (!layerFindIndicator) - { - layerFindIndicator = [[FindHighlightLayer alloc] init]; - [content setWantsLayer: YES]; - layerFindIndicator.geometryFlipped = content.layer.geometryFlipped; - if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_8) - { - // Content layer is unflipped on 10.9, but the indicator shows wrong unless flipped - layerFindIndicator.geometryFlipped = YES; - } - [content.layer addSublayer:layerFindIndicator]; - } - [layerFindIndicator removeAnimationForKey:@"animateFound"]; - - if (charRange.length) - { - CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), - vs.styles[STYLE_DEFAULT].characterSet); - std::vector<char> buffer(charRange.length); - pdoc->GetCharRange(&buffer[0], static_cast<int>(charRange.location), static_cast<int>(charRange.length)); - - CFStringRef cfsFind = CFStringFromString(&buffer[0], charRange.length, encoding); - layerFindIndicator.sFind = (__bridge NSString *)cfsFind; - if (cfsFind) - CFRelease(cfsFind); - layerFindIndicator.retaining = retaining; - layerFindIndicator.positionFind = static_cast<int>(charRange.location); - // SCI_GETSTYLEAT reports a signed byte but want an unsigned to index into styles - const char styleByte = static_cast<char>(WndProc(SCI_GETSTYLEAT, charRange.location, 0)); - const long style = static_cast<unsigned char>(styleByte); - std::vector<char> bufferFontName(WndProc(SCI_STYLEGETFONT, style, 0) + 1); - WndProc(SCI_STYLEGETFONT, style, (sptr_t)&bufferFontName[0]); - layerFindIndicator.sFont = @(&bufferFontName[0]); - - layerFindIndicator.fontSize = WndProc(SCI_STYLEGETSIZEFRACTIONAL, style, 0) / - (float)SC_FONT_SIZE_MULTIPLIER; - layerFindIndicator.widthText = WndProc(SCI_POINTXFROMPOSITION, 0, charRange.location + charRange.length) - - WndProc(SCI_POINTXFROMPOSITION, 0, charRange.location); - layerFindIndicator.heightLine = WndProc(SCI_TEXTHEIGHT, 0, 0); - MoveFindIndicatorWithBounce(YES); - } - else - { - [layerFindIndicator hideMatch]; - } + NSView *content = ContentView(); + if (!layerFindIndicator) { + layerFindIndicator = [[FindHighlightLayer alloc] init]; + [content setWantsLayer: YES]; + layerFindIndicator.geometryFlipped = content.layer.geometryFlipped; + if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_8) { + // Content layer is unflipped on 10.9, but the indicator shows wrong unless flipped + layerFindIndicator.geometryFlipped = YES; + } + [content.layer addSublayer: layerFindIndicator]; + } + [layerFindIndicator removeAnimationForKey: @"animateFound"]; + + if (charRange.length) { + CFStringEncoding encoding = EncodingFromCharacterSet(IsUnicodeMode(), + vs.styles[STYLE_DEFAULT].characterSet); + std::vector<char> buffer(charRange.length); + pdoc->GetCharRange(&buffer[0], static_cast<int>(charRange.location), static_cast<int>(charRange.length)); + + CFStringRef cfsFind = CFStringFromString(&buffer[0], charRange.length, encoding); + layerFindIndicator.sFind = (__bridge NSString *)cfsFind; + if (cfsFind) + CFRelease(cfsFind); + layerFindIndicator.retaining = retaining; + layerFindIndicator.positionFind = static_cast<int>(charRange.location); + // SCI_GETSTYLEAT reports a signed byte but want an unsigned to index into styles + const char styleByte = static_cast<char>(WndProc(SCI_GETSTYLEAT, charRange.location, 0)); + const long style = static_cast<unsigned char>(styleByte); + std::vector<char> bufferFontName(WndProc(SCI_STYLEGETFONT, style, 0) + 1); + WndProc(SCI_STYLEGETFONT, style, (sptr_t)&bufferFontName[0]); + layerFindIndicator.sFont = @(&bufferFontName[0]); + + layerFindIndicator.fontSize = WndProc(SCI_STYLEGETSIZEFRACTIONAL, style, 0) / + (float)SC_FONT_SIZE_MULTIPLIER; + layerFindIndicator.widthText = WndProc(SCI_POINTXFROMPOSITION, 0, charRange.location + charRange.length) - + WndProc(SCI_POINTXFROMPOSITION, 0, charRange.location); + layerFindIndicator.heightLine = WndProc(SCI_TEXTHEIGHT, 0, 0); + MoveFindIndicatorWithBounce(YES); + } else { + [layerFindIndicator hideMatch]; + } #endif } -void ScintillaCocoa::MoveFindIndicatorWithBounce(BOOL bounce) -{ +void ScintillaCocoa::MoveFindIndicatorWithBounce(BOOL bounce) { #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 - if (layerFindIndicator) - { - CGPoint ptText = CGPointMake( - WndProc(SCI_POINTXFROMPOSITION, 0, layerFindIndicator.positionFind), - WndProc(SCI_POINTYFROMPOSITION, 0, layerFindIndicator.positionFind)); - ptText.x = ptText.x - vs.fixedColumnWidth + xOffset; - ptText.y += topLine * vs.lineHeight; - if (!layerFindIndicator.geometryFlipped) - { - NSView *content = ContentView(); - ptText.y = content.bounds.size.height - ptText.y; - } - [layerFindIndicator animateMatch:ptText bounce:bounce]; - } + if (layerFindIndicator) { + CGPoint ptText = CGPointMake( + WndProc(SCI_POINTXFROMPOSITION, 0, layerFindIndicator.positionFind), + WndProc(SCI_POINTYFROMPOSITION, 0, layerFindIndicator.positionFind)); + ptText.x = ptText.x - vs.fixedColumnWidth + xOffset; + ptText.y += topLine * vs.lineHeight; + if (!layerFindIndicator.geometryFlipped) { + NSView *content = ContentView(); + ptText.y = content.bounds.size.height - ptText.y; + } + [layerFindIndicator animateMatch: ptText bounce: bounce]; + } #endif } -void ScintillaCocoa::HideFindIndicator() -{ +void ScintillaCocoa::HideFindIndicator() { #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 - if (layerFindIndicator) - { - [layerFindIndicator hideMatch]; - } + if (layerFindIndicator) { + [layerFindIndicator hideMatch]; + } #endif } |
