2010-07-14 09:47:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of the native Cocoa View that serves as container for the scintilla parts.
|
|
|
|
*
|
|
|
|
* Created by Mike Lischke.
|
|
|
|
*
|
2013-08-28 00:44:27 +00:00
|
|
|
* Copyright 2011, 2013, Oracle and/or its affiliates. All rights reserved.
|
|
|
|
* Copyright 2009, 2011 Sun Microsystems, Inc. All rights reserved.
|
2010-07-14 09:47:17 +00:00
|
|
|
* This file is dual licensed under LGPL v2.1 and the Scintilla license (http://www.scintilla.org/License.txt).
|
|
|
|
*/
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
#import "Platform.h"
|
2010-07-14 09:47:17 +00:00
|
|
|
#import "ScintillaView.h"
|
2015-06-07 21:19:26 +00:00
|
|
|
#import "ScintillaCocoa.h"
|
2010-07-14 09:47:17 +00:00
|
|
|
|
|
|
|
using namespace Scintilla;
|
|
|
|
|
|
|
|
// Two additional cursors we need, which aren't provided by Cocoa.
|
|
|
|
static NSCursor* reverseArrowCursor;
|
|
|
|
static NSCursor* waitCursor;
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
NSString *const SCIUpdateUINotification = @"SCIUpdateUI";
|
2010-07-14 09:47:17 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
/**
|
|
|
|
* Provide an NSCursor object that matches the Window::Cursor enumeration.
|
|
|
|
*/
|
|
|
|
static NSCursor *cursorFromEnum(Window::Cursor cursor)
|
|
|
|
{
|
|
|
|
switch (cursor)
|
|
|
|
{
|
|
|
|
case Window::cursorText:
|
|
|
|
return [NSCursor IBeamCursor];
|
|
|
|
case Window::cursorArrow:
|
|
|
|
return [NSCursor arrowCursor];
|
|
|
|
case Window::cursorWait:
|
|
|
|
return waitCursor;
|
|
|
|
case Window::cursorHoriz:
|
|
|
|
return [NSCursor resizeLeftRightCursor];
|
|
|
|
case Window::cursorVert:
|
|
|
|
return [NSCursor resizeUpDownCursor];
|
|
|
|
case Window::cursorReverseArrow:
|
|
|
|
return reverseArrowCursor;
|
|
|
|
case Window::cursorUp:
|
|
|
|
default:
|
|
|
|
return [NSCursor arrowCursor];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
@implementation SCIMarginView
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
@synthesize marginWidth, owner;
|
|
|
|
|
|
|
|
- (id)initWithScrollView:(NSScrollView *)aScrollView
|
|
|
|
{
|
|
|
|
self = [super initWithScrollView:aScrollView orientation:NSVerticalRuler];
|
|
|
|
if (self != nil)
|
|
|
|
{
|
|
|
|
owner = nil;
|
|
|
|
marginWidth = 20;
|
|
|
|
currentCursors = [[NSMutableArray arrayWithCapacity:0] retain];
|
2015-06-07 21:19:26 +00:00
|
|
|
for (size_t i=0; i<=SC_MAX_MARGIN; i++)
|
2013-08-28 00:44:27 +00:00
|
|
|
{
|
|
|
|
[currentCursors addObject: [reverseArrowCursor retain]];
|
|
|
|
}
|
|
|
|
[self setClientView:[aScrollView documentView]];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[currentCursors release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setFrame: (NSRect) frame
|
|
|
|
{
|
|
|
|
[super setFrame: frame];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
[[self window] invalidateCursorRectsForView: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)requiredThickness
|
|
|
|
{
|
|
|
|
return marginWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)drawHashMarksAndLabelsInRect:(NSRect)aRect
|
|
|
|
{
|
|
|
|
if (owner) {
|
|
|
|
NSRect contentRect = [[[self scrollView] contentView] bounds];
|
|
|
|
NSRect marginRect = [self bounds];
|
|
|
|
// Ensure paint to bottom of view to avoid glitches
|
|
|
|
if (marginRect.size.height > contentRect.size.height) {
|
|
|
|
// Legacy scroll bar mode leaves a poorly painted corner
|
|
|
|
aRect = marginRect;
|
|
|
|
}
|
|
|
|
owner.backend->PaintMargin(aRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseDown: (NSEvent *) theEvent
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
NSClipView *textView = [[self scrollView] contentView];
|
|
|
|
[[textView window] makeFirstResponder:textView];
|
2013-08-28 00:44:27 +00:00
|
|
|
owner.backend->MouseDown(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseDragged: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
owner.backend->MouseMove(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseMoved: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
owner.backend->MouseMove(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseUp: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
owner.backend->MouseUp(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called to give us the opportunity to define our mouse sensitive rectangle.
|
|
|
|
*/
|
|
|
|
- (void) resetCursorRects
|
|
|
|
{
|
|
|
|
[super resetCursorRects];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
int x = 0;
|
|
|
|
NSRect marginRect = [self bounds];
|
|
|
|
size_t co = [currentCursors count];
|
|
|
|
for (size_t i=0; i<co; i++)
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
long cursType = owner.backend->WndProc(SCI_GETMARGINCURSORN, i, 0);
|
|
|
|
long width =owner.backend->WndProc(SCI_GETMARGINWIDTHN, i, 0);
|
2013-08-28 00:44:27 +00:00
|
|
|
NSCursor *cc = cursorFromEnum(static_cast<Window::Cursor>(cursType));
|
|
|
|
[currentCursors replaceObjectAtIndex:i withObject: cc];
|
|
|
|
marginRect.origin.x = x;
|
|
|
|
marginRect.size.width = width;
|
|
|
|
[self addCursorRect: marginRect cursor: cc];
|
|
|
|
[cc setOnMouseEntered: YES];
|
|
|
|
x += width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
@implementation SCIContentView
|
2010-07-14 09:47:17 +00:00
|
|
|
|
|
|
|
@synthesize owner = mOwner;
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
- (NSView*) initWithFrame: (NSRect) frame
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
|
|
|
self = [super initWithFrame: frame];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
if (self != nil)
|
|
|
|
{
|
|
|
|
// Some initialization for our view.
|
|
|
|
mCurrentCursor = [[NSCursor arrowCursor] retain];
|
2015-06-07 21:19:26 +00:00
|
|
|
trackingArea = nil;
|
2010-07-14 09:47:17 +00:00
|
|
|
mMarkedTextRange = NSMakeRange(NSNotFound, 0);
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
[self registerForDraggedTypes: [NSArray arrayWithObjects:
|
|
|
|
NSStringPboardType, ScintillaRecPboardType, NSFilenamesPboardType, nil]];
|
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
2015-06-07 21:19:26 +00:00
|
|
|
* When the view is resized or scrolled we need to update our tracking area.
|
|
|
|
*/
|
|
|
|
- (void) updateTrackingAreas
|
|
|
|
{
|
|
|
|
if (trackingArea)
|
|
|
|
[self removeTrackingArea:trackingArea];
|
|
|
|
|
|
|
|
int opts = (NSTrackingActiveAlways | NSTrackingInVisibleRect | NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved);
|
|
|
|
trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds]
|
|
|
|
options:opts
|
|
|
|
owner:self
|
|
|
|
userInfo:nil];
|
|
|
|
[self addTrackingArea: trackingArea];
|
|
|
|
[super updateTrackingAreas];
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When the view is resized we need to let the backend know.
|
2010-07-14 09:47:17 +00:00
|
|
|
*/
|
|
|
|
- (void) setFrame: (NSRect) frame
|
|
|
|
{
|
|
|
|
[super setFrame: frame];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
mOwner.backend->Resize();
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by the backend if a new cursor must be set for the view.
|
|
|
|
*/
|
2015-06-07 21:19:26 +00:00
|
|
|
- (void) setCursor: (int) cursor
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
Window::Cursor eCursor = (Window::Cursor)cursor;
|
2010-07-14 09:47:17 +00:00
|
|
|
[mCurrentCursor autorelease];
|
2015-06-07 21:19:26 +00:00
|
|
|
mCurrentCursor = cursorFromEnum(eCursor);
|
2010-07-14 09:47:17 +00:00
|
|
|
[mCurrentCursor retain];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
// Trigger recreation of the cursor rectangle(s).
|
|
|
|
[[self window] invalidateCursorRectsForView: self];
|
2015-06-07 21:19:26 +00:00
|
|
|
[mOwner updateMarginCursors];
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called to give us the opportunity to define our mouse sensitive rectangle.
|
|
|
|
*/
|
|
|
|
- (void) resetCursorRects
|
|
|
|
{
|
|
|
|
[super resetCursorRects];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
// We only have one cursor rect: our bounds.
|
|
|
|
[self addCursorRect: [self bounds] cursor: mCurrentCursor];
|
|
|
|
[mCurrentCursor setOnMouseEntered: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
/**
|
|
|
|
* Called before repainting.
|
|
|
|
*/
|
|
|
|
- (void) viewWillDraw
|
|
|
|
{
|
|
|
|
const NSRect *rects;
|
|
|
|
NSInteger nRects = 0;
|
|
|
|
[self getRectsBeingDrawn:&rects count:&nRects];
|
|
|
|
if (nRects > 0) {
|
|
|
|
NSRect rectUnion = rects[0];
|
|
|
|
for (int i=0;i<nRects;i++) {
|
|
|
|
rectUnion = NSUnionRect(rectUnion, rects[i]);
|
|
|
|
}
|
|
|
|
mOwner.backend->WillDraw(rectUnion);
|
|
|
|
}
|
|
|
|
[super viewWillDraw];
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called before responsive scrolling overdraw.
|
|
|
|
*/
|
|
|
|
- (void) prepareContentInRect: (NSRect) rect
|
|
|
|
{
|
|
|
|
mOwner.backend->WillDraw(rect);
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED > 1080
|
|
|
|
[super prepareContentInRect: rect];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
/**
|
|
|
|
* Gets called by the runtime when the view needs repainting.
|
|
|
|
*/
|
|
|
|
- (void) drawRect: (NSRect) rect
|
|
|
|
{
|
|
|
|
CGContextRef context = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
if (!mOwner.backend->Draw(rect, context)) {
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
});
|
|
|
|
}
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Windows uses a client coordinate system where the upper left corner is the origin in a window
|
2015-06-07 21:19:26 +00:00
|
|
|
* (and so does Scintilla). We have to adjust for that. However by returning YES here, we are
|
2010-07-14 09:47:17 +00:00
|
|
|
* already done with that.
|
|
|
|
* Note that because of returning YES here most coordinates we use now (e.g. for painting,
|
|
|
|
* invalidating rectangles etc.) are given with +Y pointing down!
|
|
|
|
*/
|
|
|
|
- (BOOL) isFlipped
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (BOOL) isOpaque
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implement the "click through" behavior by telling the caller we accept the first mouse event too.
|
|
|
|
*/
|
|
|
|
- (BOOL) acceptsFirstMouse: (NSEvent *) theEvent
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
#pragma unused(theEvent)
|
2010-07-14 09:47:17 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make this view accepting events as first responder.
|
|
|
|
*/
|
|
|
|
- (BOOL) acceptsFirstResponder
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by the framework if it wants to show a context menu for the editor.
|
|
|
|
*/
|
|
|
|
- (NSMenu*) menuForEvent: (NSEvent*) theEvent
|
|
|
|
{
|
2011-03-22 00:16:49 +00:00
|
|
|
if (![mOwner respondsToSelector: @selector(menuForEvent:)])
|
|
|
|
return mOwner.backend->CreateContextMenu(theEvent);
|
|
|
|
else
|
|
|
|
return [mOwner menuForEvent: theEvent];
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
// Adoption of NSTextInputClient protocol.
|
2010-07-14 09:47:17 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
const NSRange posRange = mOwner.backend->PositionsFromCharacters(aRange);
|
|
|
|
// The backend validated aRange and may have removed characters beyond the end of the document.
|
|
|
|
const NSRange charRange = mOwner.backend->CharactersFromPositions(posRange);
|
|
|
|
if (!NSEqualRanges(aRange, charRange))
|
|
|
|
{
|
|
|
|
*actualRange = charRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
[mOwner message: SCI_SETTARGETRANGE wParam: posRange.location lParam: NSMaxRange(posRange)];
|
|
|
|
std::string text([mOwner message: SCI_TARGETASUTF8] + 1, 0);
|
|
|
|
[mOwner message: SCI_TARGETASUTF8 wParam: 0 lParam: reinterpret_cast<sptr_t>(&text[0])];
|
|
|
|
NSString *result = [NSString stringWithUTF8String: text.c_str()];
|
|
|
|
NSMutableAttributedString *asResult = [[[NSMutableAttributedString alloc] initWithString:result] autorelease];
|
|
|
|
|
|
|
|
const NSRange rangeAS = NSMakeRange(0, [asResult length]);
|
|
|
|
const long style = [mOwner message: SCI_GETSTYLEAT wParam:posRange.location];
|
|
|
|
std::string fontName([mOwner message: SCI_STYLEGETFONT wParam:style lParam:0] + 1, 0);
|
|
|
|
[mOwner message: SCI_STYLEGETFONT wParam:style lParam:(sptr_t)&fontName[0]];
|
|
|
|
const CGFloat fontSize = [mOwner message: SCI_STYLEGETSIZEFRACTIONAL wParam:style] / 100.0f;
|
|
|
|
NSString *sFontName = [NSString stringWithUTF8String: fontName.c_str()];
|
|
|
|
NSFont *font = [NSFont fontWithName:sFontName size:fontSize];
|
|
|
|
[asResult addAttribute:NSFontAttributeName value:font range:rangeAS];
|
|
|
|
|
|
|
|
return asResult;
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (NSUInteger) characterIndexForPoint: (NSPoint) point
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
const NSRect rectPoint = {point, NSZeroSize};
|
|
|
|
const NSRect rectInWindow = [self.window convertRectFromScreen:rectPoint];
|
|
|
|
const NSRect rectLocal = [[[self superview] superview] convertRect:rectInWindow fromView:nil];
|
|
|
|
|
|
|
|
const long position = [mOwner message: SCI_CHARPOSITIONFROMPOINT
|
|
|
|
wParam: rectLocal.origin.x
|
|
|
|
lParam: rectLocal.origin.y];
|
|
|
|
if (position == INVALID_POSITION)
|
|
|
|
{
|
|
|
|
return NSNotFound;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const NSRange index = mOwner.backend->CharactersFromPositions(NSMakeRange(position, 0));
|
|
|
|
return index.location;
|
|
|
|
}
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (void) doCommandBySelector: (SEL) selector
|
|
|
|
{
|
|
|
|
if ([self respondsToSelector: @selector(selector)])
|
|
|
|
[self performSelector: selector withObject: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
- (NSRect) firstRectForCharacterRange: (NSRange) aRange actualRange: (NSRangePointer) actualRange
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
const NSRange posRange = mOwner.backend->PositionsFromCharacters(aRange);
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
NSRect rect;
|
2015-06-07 21:19:26 +00:00
|
|
|
rect.origin.x = [mOwner message: SCI_POINTXFROMPOSITION wParam: 0 lParam: posRange.location];
|
|
|
|
rect.origin.y = [mOwner message: SCI_POINTYFROMPOSITION wParam: 0 lParam: posRange.location];
|
|
|
|
const NSUInteger rangeEnd = NSMaxRange(posRange);
|
|
|
|
rect.size.width = [mOwner message: SCI_POINTXFROMPOSITION wParam: 0 lParam: rangeEnd] - rect.origin.x;
|
|
|
|
rect.size.height = [mOwner message: SCI_POINTYFROMPOSITION wParam: 0 lParam: rangeEnd] - rect.origin.y;
|
|
|
|
rect.size.height += [mOwner message: SCI_TEXTHEIGHT wParam: 0 lParam: 0];
|
|
|
|
const NSRect rectInWindow = [[[self superview] superview] convertRect:rect toView:nil];
|
|
|
|
const NSRect rectScreen = [self.window convertRectToScreen:rectInWindow];
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
return rectScreen;
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (BOOL) hasMarkedText
|
|
|
|
{
|
|
|
|
return mMarkedTextRange.length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* General text input. Used to insert new text at the current input position, replacing the current
|
|
|
|
* selection if there is any.
|
2013-08-28 00:44:27 +00:00
|
|
|
* First removes the replacementRange.
|
2010-07-14 09:47:17 +00:00
|
|
|
*/
|
2013-08-28 00:44:27 +00:00
|
|
|
- (void) insertText: (id) aString replacementRange: (NSRange) replacementRange
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
if ((mMarkedTextRange.location != NSNotFound) && (replacementRange.location != NSNotFound))
|
|
|
|
{
|
|
|
|
NSLog(@"Trying to insertText when there is both a marked range and a replacement range");
|
|
|
|
}
|
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
// Remove any previously marked text first.
|
2015-06-07 21:19:26 +00:00
|
|
|
mOwner.backend->CompositionUndo();
|
|
|
|
if (mMarkedTextRange.location != NSNotFound)
|
|
|
|
{
|
|
|
|
const NSRange posRangeMark = mOwner.backend->PositionsFromCharacters(mMarkedTextRange);
|
|
|
|
[mOwner message: SCI_SETEMPTYSELECTION wParam: posRangeMark.location];
|
|
|
|
}
|
|
|
|
mMarkedTextRange = NSMakeRange(NSNotFound, 0);
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
if (replacementRange.location == (NSNotFound-1))
|
|
|
|
// This occurs when the accent popup is visible and menu selected.
|
2015-06-07 21:19:26 +00:00
|
|
|
// Its replacing a non-existent position so do nothing.
|
2013-08-28 00:44:27 +00:00
|
|
|
return;
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
if (replacementRange.location != NSNotFound)
|
2013-08-28 00:44:27 +00:00
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
const NSRange posRangeReplacement = mOwner.backend->PositionsFromCharacters(replacementRange);
|
|
|
|
[mOwner message: SCI_DELETERANGE
|
|
|
|
wParam: posRangeReplacement.location
|
|
|
|
lParam: posRangeReplacement.length];
|
|
|
|
[mOwner message: SCI_SETEMPTYSELECTION wParam: posRangeReplacement.location];
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
NSString* newText = @"";
|
|
|
|
if ([aString isKindOfClass:[NSString class]])
|
|
|
|
newText = (NSString*) aString;
|
|
|
|
else if ([aString isKindOfClass:[NSAttributedString class]])
|
|
|
|
newText = (NSString*) [aString string];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
mOwner.backend->InsertText(newText);
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (NSRange) markedRange
|
|
|
|
{
|
|
|
|
return mMarkedTextRange;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (NSRange) selectedRange
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
const long positionBegin = [mOwner message: SCI_GETSELECTIONSTART];
|
|
|
|
const long positionEnd = [mOwner message: SCI_GETSELECTIONEND];
|
|
|
|
NSRange posRangeSel = NSMakeRange(positionBegin, positionEnd-positionBegin);
|
|
|
|
return mOwner.backend->CharactersFromPositions(posRangeSel);
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by the input manager to set text which might be combined with further input to form
|
|
|
|
* the final text (e.g. composition of ^ and a to â).
|
|
|
|
*
|
|
|
|
* @param aString The text to insert, either what has been marked already or what is selected already
|
|
|
|
* or simply added at the current insertion point. Depending on what is available.
|
|
|
|
* @param range The range of the new text to select (given relative to the insertion point of the new text).
|
2013-08-28 00:44:27 +00:00
|
|
|
* @param replacementRange The range to remove before insertion.
|
2010-07-14 09:47:17 +00:00
|
|
|
*/
|
2013-08-28 00:44:27 +00:00
|
|
|
- (void) setMarkedText: (id) aString selectedRange: (NSRange)range replacementRange: (NSRange)replacementRange
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
NSString* newText = @"";
|
|
|
|
if ([aString isKindOfClass:[NSString class]])
|
|
|
|
newText = (NSString*) aString;
|
|
|
|
else
|
|
|
|
if ([aString isKindOfClass:[NSAttributedString class]])
|
|
|
|
newText = (NSString*) [aString string];
|
2010-07-14 09:47:17 +00:00
|
|
|
|
|
|
|
// Replace marked text if there is one.
|
|
|
|
if (mMarkedTextRange.length > 0)
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
mOwner.backend->CompositionUndo();
|
|
|
|
if (replacementRange.location != NSNotFound)
|
|
|
|
{
|
|
|
|
// This situation makes no sense and has not occurred in practice.
|
|
|
|
NSLog(@"Can not handle a replacement range when there is also a marked range");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
replacementRange = mMarkedTextRange;
|
|
|
|
const NSRange posRangeMark = mOwner.backend->PositionsFromCharacters(mMarkedTextRange);
|
|
|
|
[mOwner message: SCI_SETEMPTYSELECTION wParam: posRangeMark.location];
|
|
|
|
}
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
else
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
// Must perform deletion before entering composition mode or else
|
|
|
|
// both document and undo history will not contain the deleted text
|
|
|
|
// leading to an inaccurate and unusable undo history.
|
|
|
|
|
|
|
|
// Convert selection virtual space into real space
|
|
|
|
mOwner.backend->ConvertSelectionVirtualSpace();
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
if (replacementRange.location != NSNotFound)
|
|
|
|
{
|
|
|
|
const NSRange posRangeReplacement = mOwner.backend->PositionsFromCharacters(replacementRange);
|
|
|
|
[mOwner message: SCI_DELETERANGE
|
|
|
|
wParam: posRangeReplacement.location
|
|
|
|
lParam: posRangeReplacement.length];
|
|
|
|
}
|
|
|
|
else // No marked or replacement range, so replace selection
|
|
|
|
{
|
|
|
|
if (!mOwner.backend->ScintillaCocoa::ClearAllSelections()) {
|
|
|
|
// Some of the selection is protected so can not perform composition here
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Ensure only a single selection.
|
|
|
|
mOwner.backend->SelectOnlyMainSelection();
|
|
|
|
replacementRange = [self selectedRange];
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
2010-07-14 09:47:17 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
// To support IME input to multiple selections, the following code would
|
|
|
|
// need to insert newText at each selection, mark each piece of new text and then
|
|
|
|
// select range relative to each insertion.
|
2010-07-14 09:47:17 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
if ([newText length])
|
2013-08-28 00:44:27 +00:00
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
// Switching into composition.
|
|
|
|
mOwner.backend->CompositionStart();
|
|
|
|
|
|
|
|
NSRange posRangeCurrent = mOwner.backend->PositionsFromCharacters(NSMakeRange(replacementRange.location, 0));
|
|
|
|
// Note: Scintilla internally works almost always with bytes instead chars, so we need to take
|
|
|
|
// this into account when determining selection ranges and such.
|
|
|
|
int lengthInserted = mOwner.backend->InsertText(newText);
|
|
|
|
posRangeCurrent.length = lengthInserted;
|
|
|
|
mMarkedTextRange = mOwner.backend->CharactersFromPositions(posRangeCurrent);
|
2013-08-28 00:44:27 +00:00
|
|
|
// Mark the just inserted text. Keep the marked range for later reset.
|
2015-06-07 21:19:26 +00:00
|
|
|
[mOwner setGeneralProperty: SCI_SETINDICATORCURRENT value: INDIC_IME];
|
2013-08-28 00:44:27 +00:00
|
|
|
[mOwner setGeneralProperty: SCI_INDICATORFILLRANGE
|
2015-06-07 21:19:26 +00:00
|
|
|
parameter: posRangeCurrent.location
|
|
|
|
value: posRangeCurrent.length];
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
mMarkedTextRange = NSMakeRange(NSNotFound, 0);
|
2013-08-28 00:44:27 +00:00
|
|
|
// Re-enable undo action collection if composition ended (indicated by an empty mark string).
|
2015-06-07 21:19:26 +00:00
|
|
|
mOwner.backend->CompositionCommit();
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
|
|
|
|
2010-08-21 23:59:56 +00:00
|
|
|
// Select the part which is indicated in the given range. It does not scroll the caret into view.
|
2010-07-14 09:47:17 +00:00
|
|
|
if (range.length > 0)
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
// range is in characters so convert to bytes for selection.
|
2015-06-07 21:19:26 +00:00
|
|
|
range.location += replacementRange.location;
|
|
|
|
NSRange posRangeSelect = mOwner.backend->PositionsFromCharacters(range);
|
|
|
|
[mOwner setGeneralProperty: SCI_SETSELECTION parameter: NSMaxRange(posRangeSelect) value: posRangeSelect.location];
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (void) unmarkText
|
|
|
|
{
|
|
|
|
if (mMarkedTextRange.length > 0)
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
mOwner.backend->CompositionCommit();
|
2010-07-14 09:47:17 +00:00
|
|
|
mMarkedTextRange = NSMakeRange(NSNotFound, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (NSArray*) validAttributesForMarkedText
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
// End of the NSTextInputClient protocol adoption.
|
2010-07-14 09:47:17 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic input method. It is used to pass on keyboard input to Scintilla. The control itself only
|
|
|
|
* handles shortcuts. The input is then forwarded to the Cocoa text input system, which in turn does
|
2013-08-28 00:44:27 +00:00
|
|
|
* its own input handling (character composition via NSTextInputClient protocol):
|
2010-07-14 09:47:17 +00:00
|
|
|
*/
|
|
|
|
- (void) keyDown: (NSEvent *) theEvent
|
|
|
|
{
|
2011-07-17 22:30:49 +00:00
|
|
|
if (mMarkedTextRange.length == 0)
|
|
|
|
mOwner.backend->KeyboardInput(theEvent);
|
2010-07-14 09:47:17 +00:00
|
|
|
NSArray* events = [NSArray arrayWithObject: theEvent];
|
|
|
|
[self interpretKeyEvents: events];
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
- (void) mouseDown: (NSEvent *) theEvent
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
|
|
|
mOwner.backend->MouseDown(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (void) mouseDragged: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
mOwner.backend->MouseMove(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (void) mouseUp: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
mOwner.backend->MouseUp(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (void) mouseMoved: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
mOwner.backend->MouseMove(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (void) mouseEntered: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
mOwner.backend->MouseEntered(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (void) mouseExited: (NSEvent *) theEvent
|
|
|
|
{
|
|
|
|
mOwner.backend->MouseExited(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
/**
|
|
|
|
* Mouse wheel with command key magnifies text.
|
2015-06-07 21:19:26 +00:00
|
|
|
* Enabling this code causes visual garbage to appear when scrolling
|
|
|
|
* horizontally on OS X 10.9 with a retina display.
|
|
|
|
* Pinch gestures and key commands can be used for magnification.
|
2013-08-28 00:44:27 +00:00
|
|
|
*/
|
2015-06-07 21:19:26 +00:00
|
|
|
#ifdef SCROLL_WHEEL_MAGNIFICATION
|
2010-07-14 09:47:17 +00:00
|
|
|
- (void) scrollWheel: (NSEvent *) theEvent
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
if (([theEvent modifierFlags] & NSCommandKeyMask) != 0) {
|
|
|
|
mOwner.backend->MouseWheel(theEvent);
|
|
|
|
} else {
|
|
|
|
[super scrollWheel:theEvent];
|
|
|
|
}
|
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
#endif
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure scrolling is aligned to whole lines instead of starting part-way through a line
|
|
|
|
*/
|
|
|
|
- (NSRect)adjustScroll:(NSRect)proposedVisibleRect
|
|
|
|
{
|
|
|
|
NSRect rc = proposedVisibleRect;
|
|
|
|
// Snap to lines
|
|
|
|
NSRect contentRect = [self bounds];
|
|
|
|
if ((rc.origin.y > 0) && (NSMaxY(rc) < contentRect.size.height)) {
|
|
|
|
// Only snap for positions inside the document - allow outside
|
|
|
|
// for overshoot.
|
2015-06-07 21:19:26 +00:00
|
|
|
long lineHeight = mOwner.backend->WndProc(SCI_TEXTHEIGHT, 0, 0);
|
|
|
|
rc.origin.y = roundf(static_cast<XYPOSITION>(rc.origin.y) / lineHeight) * lineHeight;
|
2013-08-28 00:44:27 +00:00
|
|
|
}
|
|
|
|
return rc;
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The editor is getting the foreground control (the one getting the input focus).
|
|
|
|
*/
|
|
|
|
- (BOOL) becomeFirstResponder
|
|
|
|
{
|
|
|
|
mOwner.backend->WndProc(SCI_SETFOCUS, 1, 0);
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The editor is losing the input focus.
|
|
|
|
*/
|
|
|
|
- (BOOL) resignFirstResponder
|
|
|
|
{
|
|
|
|
mOwner.backend->WndProc(SCI_SETFOCUS, 0, 0);
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
2015-06-07 21:19:26 +00:00
|
|
|
* Implement NSDraggingSource.
|
|
|
|
*/
|
|
|
|
|
|
|
|
- (NSDragOperation)draggingSession: (NSDraggingSession *) session
|
|
|
|
sourceOperationMaskForDraggingContext: (NSDraggingContext) context
|
|
|
|
{
|
|
|
|
switch(context)
|
|
|
|
{
|
|
|
|
case NSDraggingContextOutsideApplication:
|
|
|
|
return NSDragOperationCopy | NSDragOperationMove | NSDragOperationDelete;
|
|
|
|
|
|
|
|
case NSDraggingContextWithinApplication:
|
|
|
|
default:
|
|
|
|
return NSDragOperationCopy | NSDragOperationMove | NSDragOperationDelete;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)draggingSession:(NSDraggingSession *)session
|
|
|
|
movedToPoint:(NSPoint)screenPoint
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)draggingSession:(NSDraggingSession *)session
|
|
|
|
endedAtPoint:(NSPoint)screenPoint
|
|
|
|
operation:(NSDragOperation)operation
|
|
|
|
{
|
|
|
|
if (operation == NSDragOperationDelete)
|
|
|
|
{
|
|
|
|
mOwner.backend->WndProc(SCI_CLEAR, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implement NSDraggingDestination.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when an external drag operation enters the view.
|
2010-07-14 09:47:17 +00:00
|
|
|
*/
|
|
|
|
- (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
|
|
|
|
{
|
|
|
|
return mOwner.backend->DraggingEntered(sender);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called frequently during an external drag operation if we are the target.
|
|
|
|
*/
|
|
|
|
- (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
|
|
|
|
{
|
|
|
|
return mOwner.backend->DraggingUpdated(sender);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drag image left the view. Clean up if necessary.
|
|
|
|
*/
|
|
|
|
- (void) draggingExited: (id <NSDraggingInfo>) sender
|
|
|
|
{
|
|
|
|
mOwner.backend->DraggingExited(sender);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
#pragma unused(sender)
|
2010-07-14 09:47:17 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
return mOwner.backend->PerformDragOperation(sender);
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drag operation is done. Notify editor.
|
|
|
|
*/
|
|
|
|
- (void) concludeDragOperation: (id <NSDraggingInfo>) sender
|
|
|
|
{
|
|
|
|
// Clean up is the same as if we are no longer the drag target.
|
|
|
|
mOwner.backend->DraggingExited(sender);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// NSResponder actions.
|
|
|
|
|
|
|
|
- (void) selectAll: (id) sender
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
#pragma unused(sender)
|
2010-07-14 09:47:17 +00:00
|
|
|
mOwner.backend->SelectAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) deleteBackward: (id) sender
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
#pragma unused(sender)
|
2010-07-14 09:47:17 +00:00
|
|
|
mOwner.backend->DeleteBackward();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) cut: (id) sender
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
#pragma unused(sender)
|
2010-07-14 09:47:17 +00:00
|
|
|
mOwner.backend->Cut();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) copy: (id) sender
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
#pragma unused(sender)
|
2010-07-14 09:47:17 +00:00
|
|
|
mOwner.backend->Copy();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) paste: (id) sender
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
#pragma unused(sender)
|
2015-06-07 21:19:26 +00:00
|
|
|
if (mMarkedTextRange.location != NSNotFound)
|
|
|
|
{
|
|
|
|
[[NSTextInputContext currentInputContext] discardMarkedText];
|
|
|
|
mOwner.backend->CompositionCommit();
|
|
|
|
mMarkedTextRange = NSMakeRange(NSNotFound, 0);
|
|
|
|
}
|
2010-07-14 09:47:17 +00:00
|
|
|
mOwner.backend->Paste();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) undo: (id) sender
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
#pragma unused(sender)
|
2015-06-07 21:19:26 +00:00
|
|
|
if (mMarkedTextRange.location != NSNotFound)
|
|
|
|
{
|
|
|
|
[[NSTextInputContext currentInputContext] discardMarkedText];
|
|
|
|
mOwner.backend->CompositionCommit();
|
|
|
|
mMarkedTextRange = NSMakeRange(NSNotFound, 0);
|
|
|
|
}
|
2010-07-14 09:47:17 +00:00
|
|
|
mOwner.backend->Undo();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) redo: (id) sender
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
#pragma unused(sender)
|
2010-07-14 09:47:17 +00:00
|
|
|
mOwner.backend->Redo();
|
|
|
|
}
|
|
|
|
|
2011-03-22 00:16:49 +00:00
|
|
|
- (BOOL) canUndo
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
return mOwner.backend->CanUndo() && (mMarkedTextRange.location == NSNotFound);
|
2011-03-22 00:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) canRedo
|
|
|
|
{
|
|
|
|
return mOwner.backend->CanRedo();
|
|
|
|
}
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
- (BOOL) validateUserInterfaceItem: (id <NSValidatedUserInterfaceItem>) anItem
|
|
|
|
{
|
|
|
|
SEL action = [anItem action];
|
|
|
|
if (action==@selector(undo:)) {
|
|
|
|
return [self canUndo];
|
|
|
|
}
|
|
|
|
else if (action==@selector(redo:)) {
|
|
|
|
return [self canRedo];
|
|
|
|
}
|
|
|
|
else if (action==@selector(cut:) || action==@selector(copy:) || action==@selector(clear:)) {
|
|
|
|
return mOwner.backend->HasSelection();
|
|
|
|
}
|
|
|
|
else if (action==@selector(paste:)) {
|
|
|
|
return mOwner.backend->CanPaste();
|
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) clear: (id) sender
|
|
|
|
{
|
|
|
|
[self deleteBackward:sender];
|
|
|
|
}
|
2011-03-22 00:16:49 +00:00
|
|
|
|
|
|
|
- (BOOL) isEditable
|
|
|
|
{
|
|
|
|
return mOwner.backend->WndProc(SCI_GETREADONLY, 0, 0) == 0;
|
|
|
|
}
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[mCurrentCursor release];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
@implementation ScintillaView
|
|
|
|
|
|
|
|
@synthesize backend = mBackend;
|
2013-08-28 00:44:27 +00:00
|
|
|
@synthesize delegate = mDelegate;
|
|
|
|
@synthesize scrollView;
|
2010-07-14 09:47:17 +00:00
|
|
|
|
|
|
|
/**
|
2013-08-28 00:44:27 +00:00
|
|
|
* ScintillaView is a composite control made from an NSView and an embedded NSView that is
|
2010-07-14 09:47:17 +00:00
|
|
|
* used as canvas for the output (by the backend, using its CGContext), plus other elements
|
|
|
|
* (scrollers, info bar).
|
|
|
|
*/
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize custom cursor.
|
|
|
|
*/
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [ScintillaView class])
|
|
|
|
{
|
|
|
|
NSBundle* bundle = [NSBundle bundleForClass: [ScintillaView class]];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
|
|
|
NSString* path = [bundle pathForResource: @"mac_cursor_busy" ofType: @"tiff" inDirectory: nil];
|
2010-07-14 09:47:17 +00:00
|
|
|
NSImage* image = [[[NSImage alloc] initWithContentsOfFile: path] autorelease];
|
|
|
|
waitCursor = [[NSCursor alloc] initWithImage: image hotSpot: NSMakePoint(2, 2)];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
|
|
|
path = [bundle pathForResource: @"mac_cursor_flipped" ofType: @"tiff" inDirectory: nil];
|
2010-07-14 09:47:17 +00:00
|
|
|
image = [[[NSImage alloc] initWithContentsOfFile: path] autorelease];
|
|
|
|
reverseArrowCursor = [[NSCursor alloc] initWithImage: image hotSpot: NSMakePoint(12, 2)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
/**
|
|
|
|
* Specify the SCIContentView class. Can be overridden in a subclass to provide an SCIContentView subclass.
|
|
|
|
*/
|
|
|
|
|
|
|
|
+ (Class) contentViewClass
|
|
|
|
{
|
|
|
|
return [SCIContentView class];
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
/**
|
|
|
|
* Receives zoom messages, for example when a "pinch zoom" is performed on the trackpad.
|
|
|
|
*/
|
|
|
|
- (void) magnifyWithEvent: (NSEvent *) event
|
|
|
|
{
|
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
|
|
|
|
zoomDelta += event.magnification * 10.0;
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
if (fabs(zoomDelta)>=1.0) {
|
|
|
|
long zoomFactor = static_cast<long>([self getGeneralProperty: SCI_GETZOOM] + zoomDelta);
|
2013-08-28 00:44:27 +00:00
|
|
|
[self setGeneralProperty: SCI_SETZOOM parameter: zoomFactor value:0];
|
|
|
|
zoomDelta = 0.0;
|
2015-06-07 21:19:26 +00:00
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) beginGestureWithEvent: (NSEvent *) event
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
// Scintilla is only interested in this event as the starft of a zoom
|
|
|
|
#pragma unused(event)
|
2013-08-28 00:44:27 +00:00
|
|
|
zoomDelta = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
/**
|
|
|
|
* Sends a new notification of the given type to the default notification center.
|
|
|
|
*/
|
|
|
|
- (void) sendNotification: (NSString*) notificationName
|
|
|
|
{
|
|
|
|
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
|
|
|
|
[center postNotificationName: notificationName object: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
2011-07-17 22:30:49 +00:00
|
|
|
* Called by a connected component (usually the info bar) if something changed there.
|
2010-07-14 09:47:17 +00:00
|
|
|
*
|
|
|
|
* @param type The type of the notification.
|
|
|
|
* @param message Carries the new status message if the type is a status message change.
|
|
|
|
* @param location Carries the new location (e.g. caret) if the type is a caret change or similar type.
|
2015-06-07 21:19:26 +00:00
|
|
|
* @param value Carries the new zoom value if the type is a zoom change.
|
2010-07-14 09:47:17 +00:00
|
|
|
*/
|
|
|
|
- (void) notify: (NotificationType) type message: (NSString*) message location: (NSPoint) location
|
|
|
|
value: (float) value
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
// These parameters are just to conform to the protocol
|
|
|
|
#pragma unused(message)
|
|
|
|
#pragma unused(location)
|
2010-07-14 09:47:17 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case IBNZoomChanged:
|
|
|
|
{
|
|
|
|
// Compute point increase/decrease based on default font size.
|
2013-08-28 00:44:27 +00:00
|
|
|
long fontSize = [self getGeneralProperty: SCI_STYLEGETSIZE parameter: STYLE_DEFAULT];
|
2010-07-14 09:47:17 +00:00
|
|
|
int zoom = (int) (fontSize * (value - 1));
|
2011-03-22 00:16:49 +00:00
|
|
|
[self setGeneralProperty: SCI_SETZOOM value: zoom];
|
2010-07-14 09:47:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-07-17 22:30:49 +00:00
|
|
|
default:
|
|
|
|
break;
|
2010-07-14 09:47:17 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (void) setCallback: (id <InfoBarCommunicator>) callback
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
// Not used. Only here to satisfy protocol.
|
|
|
|
#pragma unused(callback)
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2011-03-22 00:16:49 +00:00
|
|
|
/**
|
|
|
|
* Prevents drawing of the inner view to avoid flickering when doing many visual updates
|
|
|
|
* (like clearing all marks and setting new ones etc.).
|
|
|
|
*/
|
|
|
|
- (void) suspendDrawing: (BOOL) suspend
|
|
|
|
{
|
|
|
|
if (suspend)
|
|
|
|
[[self window] disableFlushWindow];
|
|
|
|
else
|
|
|
|
[[self window] enableFlushWindow];
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
/**
|
2015-06-07 21:19:26 +00:00
|
|
|
* Method receives notifications from Scintilla (e.g. for handling clicks on the
|
2010-07-14 09:47:17 +00:00
|
|
|
* folder margin or changes in the editor).
|
2013-08-28 00:44:27 +00:00
|
|
|
* A delegate can be set to receive all notifications. If set no handling takes place here, except
|
|
|
|
* for action pertaining to internal stuff (like the info bar).
|
2010-07-14 09:47:17 +00:00
|
|
|
*/
|
2015-06-07 21:19:26 +00:00
|
|
|
- (void) notification: (Scintilla::SCNotification*)scn
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
// Parent notification. Details are passed as SCNotification structure.
|
|
|
|
|
|
|
|
if (mDelegate != nil)
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
[mDelegate notification: scn];
|
|
|
|
if (scn->nmhdr.code != SCN_ZOOM && scn->nmhdr.code != SCN_UPDATEUI)
|
|
|
|
return;
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
switch (scn->nmhdr.code)
|
|
|
|
{
|
|
|
|
case SCN_MARGINCLICK:
|
|
|
|
{
|
|
|
|
if (scn->margin == 2)
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
// Click on the folder margin. Toggle the current line if possible.
|
|
|
|
long line = [self getGeneralProperty: SCI_LINEFROMPOSITION parameter: scn->position];
|
|
|
|
[self setGeneralProperty: SCI_TOGGLEFOLD value: line];
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-06-07 21:19:26 +00:00
|
|
|
};
|
|
|
|
case SCN_MODIFIED:
|
|
|
|
{
|
|
|
|
// Decide depending on the modification type what to do.
|
|
|
|
// There can be more than one modification carried by one notification.
|
|
|
|
if (scn->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT))
|
|
|
|
[self sendNotification: NSTextDidChangeNotification];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCN_ZOOM:
|
|
|
|
{
|
|
|
|
// A zoom change happened. Notify info bar if there is one.
|
|
|
|
float zoom = [self getGeneralProperty: SCI_GETZOOM parameter: 0];
|
|
|
|
long fontSize = [self getGeneralProperty: SCI_STYLEGETSIZE parameter: STYLE_DEFAULT];
|
|
|
|
float factor = (zoom / fontSize) + 1;
|
|
|
|
[mInfoBar notify: IBNZoomChanged message: nil location: NSZeroPoint value: factor];
|
|
|
|
break;
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
case SCN_UPDATEUI:
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
// Triggered whenever changes in the UI state need to be reflected.
|
|
|
|
// These can be: caret changes, selection changes etc.
|
|
|
|
NSPoint caretPosition = mBackend->GetCaretPosition();
|
|
|
|
[mInfoBar notify: IBNCaretChanged message: nil location: caretPosition value: 0];
|
|
|
|
[self sendNotification: SCIUpdateUINotification];
|
|
|
|
if (scn->updated & (SC_UPDATE_SELECTION | SC_UPDATE_CONTENT))
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
[self sendNotification: NSTextViewDidChangeSelectionNotification];
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
case SCN_FOCUSOUT:
|
|
|
|
[self sendNotification: NSTextDidEndEditingNotification];
|
|
|
|
break;
|
|
|
|
case SCN_FOCUSIN: // Nothing to do for now.
|
|
|
|
break;
|
|
|
|
}
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialization of the view. Used to setup a few other things we need.
|
|
|
|
*/
|
|
|
|
- (id) initWithFrame: (NSRect) frame
|
|
|
|
{
|
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
if (self)
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
mContent = [[[[[self class] contentViewClass] alloc] initWithFrame:NSZeroRect] autorelease];
|
2010-07-14 09:47:17 +00:00
|
|
|
mContent.owner = self;
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
// Initialize the scrollers but don't show them yet.
|
|
|
|
// Pick an arbitrary size, just to make NSScroller selecting the proper scroller direction
|
|
|
|
// (horizontal or vertical).
|
|
|
|
NSRect scrollerRect = NSMakeRect(0, 0, 100, 10);
|
2013-08-28 00:44:27 +00:00
|
|
|
scrollView = [[[NSScrollView alloc] initWithFrame: scrollerRect] autorelease];
|
|
|
|
[scrollView setDocumentView: mContent];
|
|
|
|
[scrollView setHasVerticalScroller:YES];
|
|
|
|
[scrollView setHasHorizontalScroller:YES];
|
|
|
|
[scrollView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
|
|
|
|
//[scrollView setScrollerStyle:NSScrollerStyleLegacy];
|
|
|
|
//[scrollView setScrollerKnobStyle:NSScrollerKnobStyleDark];
|
|
|
|
//[scrollView setHorizontalScrollElasticity:NSScrollElasticityNone];
|
|
|
|
[self addSubview: scrollView];
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
marginView = [[SCIMarginView alloc] initWithScrollView:scrollView];
|
2013-08-28 00:44:27 +00:00
|
|
|
marginView.owner = self;
|
|
|
|
[marginView setRuleThickness:[marginView requiredThickness]];
|
|
|
|
[scrollView setVerticalRulerView:marginView];
|
|
|
|
[scrollView setHasHorizontalRuler:NO];
|
|
|
|
[scrollView setHasVerticalRuler:YES];
|
|
|
|
[scrollView setRulersVisible:YES];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
mBackend = new ScintillaCocoa(mContent, marginView);
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
// Establish a connection from the back end to this container so we can handle situations
|
|
|
|
// which require our attention.
|
2015-06-07 21:19:26 +00:00
|
|
|
mBackend->SetDelegate(self);
|
|
|
|
|
|
|
|
// Setup a special indicator used in the editor to provide visual feedback for
|
2010-07-14 09:47:17 +00:00
|
|
|
// input composition, depending on language, keyboard etc.
|
2015-06-07 21:19:26 +00:00
|
|
|
[self setColorProperty: SCI_INDICSETFORE parameter: INDIC_IME fromHTML: @"#FF0000"];
|
|
|
|
[self setGeneralProperty: SCI_INDICSETUNDER parameter: INDIC_IME value: 1];
|
|
|
|
[self setGeneralProperty: SCI_INDICSETSTYLE parameter: INDIC_IME value: INDIC_PLAIN];
|
|
|
|
[self setGeneralProperty: SCI_INDICSETALPHA parameter: INDIC_IME value: 100];
|
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
|
|
|
[center addObserver:self
|
|
|
|
selector:@selector(applicationDidResignActive:)
|
|
|
|
name:NSApplicationDidResignActiveNotification
|
|
|
|
object:nil];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
[center addObserver:self
|
|
|
|
selector:@selector(applicationDidBecomeActive:)
|
|
|
|
name:NSApplicationDidBecomeActiveNotification
|
|
|
|
object:nil];
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
[[scrollView contentView] setPostsBoundsChangedNotifications:YES];
|
|
|
|
[center addObserver:self
|
|
|
|
selector:@selector(scrollerAction:)
|
|
|
|
name:NSViewBoundsDidChangeNotification
|
|
|
|
object:[scrollView contentView]];
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
2010-07-14 09:47:17 +00:00
|
|
|
delete mBackend;
|
2015-06-07 21:19:26 +00:00
|
|
|
[marginView release];
|
2010-07-14 09:47:17 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
- (void) applicationDidResignActive: (NSNotification *)note {
|
2013-08-28 00:44:27 +00:00
|
|
|
#pragma unused(note)
|
2011-07-17 22:30:49 +00:00
|
|
|
mBackend->ActiveStateChanged(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (void) applicationDidBecomeActive: (NSNotification *)note {
|
2013-08-28 00:44:27 +00:00
|
|
|
#pragma unused(note)
|
2011-07-17 22:30:49 +00:00
|
|
|
mBackend->ActiveStateChanged(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
- (void) viewDidMoveToWindow
|
|
|
|
{
|
|
|
|
[super viewDidMoveToWindow];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
[self positionSubViews];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
// Enable also mouse move events for our window (and so this view).
|
|
|
|
[[self window] setAcceptsMouseMovedEvents: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to position and size the parts of the editor (content, scrollers, info bar).
|
|
|
|
*/
|
2013-08-28 00:44:27 +00:00
|
|
|
- (void) positionSubViews
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
CGFloat scrollerWidth = [NSScroller scrollerWidthForControlSize:NSRegularControlSize
|
|
|
|
scrollerStyle:NSScrollerStyleLegacy];
|
2010-07-14 09:47:17 +00:00
|
|
|
|
|
|
|
NSSize size = [self frame].size;
|
2015-06-07 21:19:26 +00:00
|
|
|
NSRect barFrame = {{0, size.height - scrollerWidth}, {size.width, scrollerWidth}};
|
2010-07-14 09:47:17 +00:00
|
|
|
BOOL infoBarVisible = mInfoBar != nil && ![mInfoBar isHidden];
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
// Horizontal offset of the content. Almost always 0 unless the vertical scroller
|
|
|
|
// is on the left side.
|
2015-06-07 21:19:26 +00:00
|
|
|
CGFloat contentX = 0;
|
|
|
|
NSRect scrollRect = {{contentX, 0}, {size.width, size.height}};
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
// Info bar frame.
|
|
|
|
if (infoBarVisible)
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
scrollRect.size.height -= scrollerWidth;
|
2010-07-14 09:47:17 +00:00
|
|
|
// Initial value already is as if the bar is at top.
|
2013-08-28 00:44:27 +00:00
|
|
|
if (!mInfoBarAtTop)
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
scrollRect.origin.y += scrollerWidth;
|
2010-07-14 09:47:17 +00:00
|
|
|
barFrame.origin.y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
if (!NSEqualRects([scrollView frame], scrollRect)) {
|
|
|
|
[scrollView setFrame: scrollRect];
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
if (infoBarVisible)
|
|
|
|
[mInfoBar setFrame: barFrame];
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
2013-08-28 00:44:27 +00:00
|
|
|
* Set the width of the margin.
|
2010-07-14 09:47:17 +00:00
|
|
|
*/
|
2013-08-28 00:44:27 +00:00
|
|
|
- (void) setMarginWidth: (int) width
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
if (marginView.ruleThickness != width)
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
marginView.marginWidth = width;
|
|
|
|
[marginView setRuleThickness:[marginView requiredThickness]];
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggered by one of the scrollers when it gets manipulated by the user. Notify the backend
|
|
|
|
* about the change.
|
|
|
|
*/
|
|
|
|
- (void) scrollerAction: (id) sender
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
mBackend->UpdateForScroll();
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to reposition our content depending on the size of the view.
|
|
|
|
*/
|
|
|
|
- (void) setFrame: (NSRect) newFrame
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
NSRect previousFrame = [self frame];
|
2010-07-14 09:47:17 +00:00
|
|
|
[super setFrame: newFrame];
|
2013-08-28 00:44:27 +00:00
|
|
|
[self positionSubViews];
|
|
|
|
if (!NSEqualRects(previousFrame, newFrame)) {
|
|
|
|
mBackend->Resize();
|
|
|
|
}
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter for the currently selected text in raw form (no formatting information included).
|
|
|
|
* If there is no text available an empty string is returned.
|
|
|
|
*/
|
|
|
|
- (NSString*) selectedString
|
|
|
|
{
|
|
|
|
NSString *result = @"";
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
const long length = mBackend->WndProc(SCI_GETSELTEXT, 0, 0);
|
2010-07-14 09:47:17 +00:00
|
|
|
if (length > 0)
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
std::string buffer(length + 1, '\0');
|
2010-07-14 09:47:17 +00:00
|
|
|
try
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
mBackend->WndProc(SCI_GETSELTEXT, length + 1, (sptr_t) &buffer[0]);
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
result = [NSString stringWithUTF8String: buffer.c_str()];
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
/**
|
|
|
|
* Delete a range from the document.
|
|
|
|
*/
|
|
|
|
- (void) deleteRange: (NSRange) aRange
|
|
|
|
{
|
|
|
|
if (aRange.length > 0)
|
|
|
|
{
|
|
|
|
NSRange posRange = mBackend->PositionsFromCharacters(aRange);
|
|
|
|
[self message: SCI_DELETERANGE wParam: posRange.location lParam: posRange.length];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
/**
|
|
|
|
* Getter for the current text in raw form (no formatting information included).
|
|
|
|
* If there is no text available an empty string is returned.
|
|
|
|
*/
|
|
|
|
- (NSString*) string
|
|
|
|
{
|
|
|
|
NSString *result = @"";
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
const long length = mBackend->WndProc(SCI_GETLENGTH, 0, 0);
|
2010-07-14 09:47:17 +00:00
|
|
|
if (length > 0)
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
std::string buffer(length + 1, '\0');
|
2010-07-14 09:47:17 +00:00
|
|
|
try
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
mBackend->WndProc(SCI_GETTEXT, length + 1, (sptr_t) &buffer[0]);
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
result = [NSString stringWithUTF8String: buffer.c_str()];
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setter for the current text (no formatting included).
|
|
|
|
*/
|
|
|
|
- (void) setString: (NSString*) aString
|
|
|
|
{
|
|
|
|
const char* text = [aString UTF8String];
|
|
|
|
mBackend->WndProc(SCI_SETTEXT, 0, (long) text);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (void) insertString: (NSString*) aString atOffset: (int)offset
|
|
|
|
{
|
|
|
|
const char* text = [aString UTF8String];
|
|
|
|
mBackend->WndProc(SCI_ADDTEXT, offset, (long) text);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (void) setEditable: (BOOL) editable
|
|
|
|
{
|
|
|
|
mBackend->WndProc(SCI_SETREADONLY, editable ? 0 : 1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
- (BOOL) isEditable
|
|
|
|
{
|
2011-03-22 00:16:49 +00:00
|
|
|
return mBackend->WndProc(SCI_GETREADONLY, 0, 0) == 0;
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
- (SCIContentView*) content
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
|
|
|
return mContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
- (void) updateMarginCursors {
|
|
|
|
[[self window] invalidateCursorRectsForView: marginView];
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
/**
|
|
|
|
* Direct call into the backend to allow uninterpreted access to it. The values to be passed in and
|
|
|
|
* the result heavily depend on the message that is used for the call. Refer to the Scintilla
|
|
|
|
* documentation to learn what can be used here.
|
|
|
|
*/
|
|
|
|
+ (sptr_t) directCall: (ScintillaView*) sender message: (unsigned int) message wParam: (uptr_t) wParam
|
|
|
|
lParam: (sptr_t) lParam
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
return ScintillaCocoa::DirectFunction(
|
|
|
|
reinterpret_cast<sptr_t>(sender->mBackend), message, wParam, lParam);
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
- (sptr_t) message: (unsigned int) message wParam: (uptr_t) wParam lParam: (sptr_t) lParam
|
|
|
|
{
|
|
|
|
return mBackend->WndProc(message, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (sptr_t) message: (unsigned int) message wParam: (uptr_t) wParam
|
|
|
|
{
|
|
|
|
return mBackend->WndProc(message, wParam, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (sptr_t) message: (unsigned int) message
|
|
|
|
{
|
|
|
|
return mBackend->WndProc(message, 0, 0);
|
|
|
|
}
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a helper method to set properties in the backend, with native parameters.
|
|
|
|
*
|
|
|
|
* @param property Main property like SCI_STYLESETFORE for which a value is to be set.
|
|
|
|
* @param parameter Additional info for this property like a parameter or index.
|
|
|
|
* @param value The actual value. It depends on the property what this parameter means.
|
|
|
|
*/
|
|
|
|
- (void) setGeneralProperty: (int) property parameter: (long) parameter value: (long) value
|
|
|
|
{
|
|
|
|
mBackend->WndProc(property, parameter, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2011-03-22 00:16:49 +00:00
|
|
|
/**
|
|
|
|
* A simplified version for setting properties which only require one parameter.
|
|
|
|
*
|
|
|
|
* @param property Main property like SCI_STYLESETFORE for which a value is to be set.
|
|
|
|
* @param value The actual value. It depends on the property what this parameter means.
|
|
|
|
*/
|
|
|
|
- (void) setGeneralProperty: (int) property value: (long) value
|
|
|
|
{
|
|
|
|
mBackend->WndProc(property, value, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
/**
|
|
|
|
* This is a helper method to get a property in the backend, with native parameters.
|
|
|
|
*
|
|
|
|
* @param property Main property like SCI_STYLESETFORE for which a value is to get.
|
|
|
|
* @param parameter Additional info for this property like a parameter or index.
|
|
|
|
* @param extra Yet another parameter if needed.
|
|
|
|
* @result A generic value which must be interpreted depending on the property queried.
|
|
|
|
*/
|
|
|
|
- (long) getGeneralProperty: (int) property parameter: (long) parameter extra: (long) extra
|
|
|
|
{
|
|
|
|
return mBackend->WndProc(property, parameter, extra);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience function to avoid unneeded extra parameter.
|
|
|
|
*/
|
|
|
|
- (long) getGeneralProperty: (int) property parameter: (long) parameter
|
|
|
|
{
|
|
|
|
return mBackend->WndProc(property, parameter, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience function to avoid unneeded parameters.
|
|
|
|
*/
|
|
|
|
- (long) getGeneralProperty: (int) property
|
|
|
|
{
|
|
|
|
return mBackend->WndProc(property, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use this variant if you have to pass in a reference to something (e.g. a text range).
|
|
|
|
*/
|
|
|
|
- (long) getGeneralProperty: (int) property ref: (const void*) ref
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
return mBackend->WndProc(property, 0, (sptr_t) ref);
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specialized property setter for colors.
|
|
|
|
*/
|
|
|
|
- (void) setColorProperty: (int) property parameter: (long) parameter value: (NSColor*) value
|
|
|
|
{
|
|
|
|
if ([value colorSpaceName] != NSDeviceRGBColorSpace)
|
|
|
|
value = [value colorUsingColorSpaceName: NSDeviceRGBColorSpace];
|
2015-06-07 21:19:26 +00:00
|
|
|
long red = static_cast<long>([value redComponent] * 255);
|
|
|
|
long green = static_cast<long>([value greenComponent] * 255);
|
|
|
|
long blue = static_cast<long>([value blueComponent] * 255);
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
long color = (blue << 16) + (green << 8) + red;
|
|
|
|
mBackend->WndProc(property, parameter, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Another color property setting, which allows to specify the color as string like in HTML
|
|
|
|
* documents (i.e. with leading # and either 3 hex digits or 6).
|
|
|
|
*/
|
|
|
|
- (void) setColorProperty: (int) property parameter: (long) parameter fromHTML: (NSString*) fromHTML
|
|
|
|
{
|
|
|
|
if ([fromHTML length] > 3 && [fromHTML characterAtIndex: 0] == '#')
|
|
|
|
{
|
|
|
|
bool longVersion = [fromHTML length] > 6;
|
|
|
|
int index = 1;
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
char value[3] = {0, 0, 0};
|
2015-06-07 21:19:26 +00:00
|
|
|
value[0] = static_cast<char>([fromHTML characterAtIndex: index++]);
|
2010-07-14 09:47:17 +00:00
|
|
|
if (longVersion)
|
2015-06-07 21:19:26 +00:00
|
|
|
value[1] = static_cast<char>([fromHTML characterAtIndex: index++]);
|
2010-07-14 09:47:17 +00:00
|
|
|
else
|
|
|
|
value[1] = value[0];
|
|
|
|
|
|
|
|
unsigned rawRed;
|
|
|
|
[[NSScanner scannerWithString: [NSString stringWithUTF8String: value]] scanHexInt: &rawRed];
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
value[0] = static_cast<char>([fromHTML characterAtIndex: index++]);
|
2010-07-14 09:47:17 +00:00
|
|
|
if (longVersion)
|
2015-06-07 21:19:26 +00:00
|
|
|
value[1] = static_cast<char>([fromHTML characterAtIndex: index++]);
|
2010-07-14 09:47:17 +00:00
|
|
|
else
|
|
|
|
value[1] = value[0];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
unsigned rawGreen;
|
|
|
|
[[NSScanner scannerWithString: [NSString stringWithUTF8String: value]] scanHexInt: &rawGreen];
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
value[0] = static_cast<char>([fromHTML characterAtIndex: index++]);
|
2010-07-14 09:47:17 +00:00
|
|
|
if (longVersion)
|
2015-06-07 21:19:26 +00:00
|
|
|
value[1] = static_cast<char>([fromHTML characterAtIndex: index++]);
|
2010-07-14 09:47:17 +00:00
|
|
|
else
|
|
|
|
value[1] = value[0];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
unsigned rawBlue;
|
|
|
|
[[NSScanner scannerWithString: [NSString stringWithUTF8String: value]] scanHexInt: &rawBlue];
|
|
|
|
|
|
|
|
long color = (rawBlue << 16) + (rawGreen << 8) + rawRed;
|
|
|
|
mBackend->WndProc(property, parameter, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specialized property getter for colors.
|
|
|
|
*/
|
|
|
|
- (NSColor*) getColorProperty: (int) property parameter: (long) parameter
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
long color = mBackend->WndProc(property, parameter, 0);
|
2015-06-07 21:19:26 +00:00
|
|
|
CGFloat red = (color & 0xFF) / 255.0;
|
|
|
|
CGFloat green = ((color >> 8) & 0xFF) / 255.0;
|
|
|
|
CGFloat blue = ((color >> 16) & 0xFF) / 255.0;
|
2010-07-14 09:47:17 +00:00
|
|
|
NSColor* result = [NSColor colorWithDeviceRed: red green: green blue: blue alpha: 1];
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specialized property setter for references (pointers, addresses).
|
|
|
|
*/
|
|
|
|
- (void) setReferenceProperty: (int) property parameter: (long) parameter value: (const void*) value
|
|
|
|
{
|
|
|
|
mBackend->WndProc(property, parameter, (sptr_t) value);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specialized property getter for references (pointers, addresses).
|
|
|
|
*/
|
|
|
|
- (const void*) getReferenceProperty: (int) property parameter: (long) parameter
|
|
|
|
{
|
|
|
|
return (const void*) mBackend->WndProc(property, parameter, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specialized property setter for string values.
|
|
|
|
*/
|
|
|
|
- (void) setStringProperty: (int) property parameter: (long) parameter value: (NSString*) value
|
|
|
|
{
|
|
|
|
const char* rawValue = [value UTF8String];
|
|
|
|
mBackend->WndProc(property, parameter, (sptr_t) rawValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specialized property getter for string values.
|
|
|
|
*/
|
|
|
|
- (NSString*) getStringProperty: (int) property parameter: (long) parameter
|
|
|
|
{
|
|
|
|
const char* rawValue = (const char*) mBackend->WndProc(property, parameter, 0);
|
|
|
|
return [NSString stringWithUTF8String: rawValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specialized property setter for lexer properties, which are commonly passed as strings.
|
|
|
|
*/
|
|
|
|
- (void) setLexerProperty: (NSString*) name value: (NSString*) value
|
|
|
|
{
|
|
|
|
const char* rawName = [name UTF8String];
|
|
|
|
const char* rawValue = [value UTF8String];
|
|
|
|
mBackend->WndProc(SCI_SETPROPERTY, (sptr_t) rawName, (sptr_t) rawValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specialized property getter for references (pointers, addresses).
|
|
|
|
*/
|
|
|
|
- (NSString*) getLexerProperty: (NSString*) name
|
|
|
|
{
|
|
|
|
const char* rawName = [name UTF8String];
|
|
|
|
const char* result = (const char*) mBackend->WndProc(SCI_SETPROPERTY, (sptr_t) rawName, 0);
|
|
|
|
return [NSString stringWithUTF8String: result];
|
|
|
|
}
|
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the notification callback
|
|
|
|
*/
|
|
|
|
- (void) registerNotifyCallback: (intptr_t) windowid value: (Scintilla::SciNotifyFunc) callback
|
|
|
|
{
|
|
|
|
mBackend->RegisterNotifyCallback(windowid, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the new control which is displayed as info bar at the top or bottom of the editor.
|
|
|
|
* Set newBar to nil if you want to hide the bar again.
|
|
|
|
* The info bar's height is set to the height of the scrollbar.
|
|
|
|
*/
|
|
|
|
- (void) setInfoBar: (NSView <InfoBarCommunicator>*) newBar top: (BOOL) top
|
|
|
|
{
|
|
|
|
if (mInfoBar != newBar)
|
|
|
|
{
|
|
|
|
[mInfoBar removeFromSuperview];
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
mInfoBar = newBar;
|
|
|
|
mInfoBarAtTop = top;
|
|
|
|
if (mInfoBar != nil)
|
|
|
|
{
|
|
|
|
[self addSubview: mInfoBar];
|
|
|
|
[mInfoBar setCallback: self];
|
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
[self positionSubViews];
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the edit's info bar status message. This call only has an effect if there is an info bar.
|
|
|
|
*/
|
|
|
|
- (void) setStatusText: (NSString*) text
|
|
|
|
{
|
|
|
|
if (mInfoBar != nil)
|
|
|
|
[mInfoBar notify: IBNStatusChanged message: text location: NSZeroPoint value: 0];
|
|
|
|
}
|
|
|
|
|
2010-08-21 23:59:56 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
- (NSRange) selectedRange
|
|
|
|
{
|
|
|
|
return [mContent selectedRange];
|
|
|
|
}
|
|
|
|
|
2010-08-21 23:59:56 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
- (void)insertText: (id) aString
|
2010-07-14 09:47:17 +00:00
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
if ([aString isKindOfClass:[NSString class]])
|
|
|
|
mBackend->InsertText(aString);
|
|
|
|
else if ([aString isKindOfClass:[NSAttributedString class]])
|
|
|
|
mBackend->InsertText([aString string]);
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
2010-08-21 23:59:56 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
2013-08-28 00:44:27 +00:00
|
|
|
* For backwards compatibility.
|
2010-08-21 23:59:56 +00:00
|
|
|
*/
|
2013-08-28 00:44:27 +00:00
|
|
|
- (BOOL) findAndHighlightText: (NSString*) searchText
|
2010-08-21 23:59:56 +00:00
|
|
|
matchCase: (BOOL) matchCase
|
|
|
|
wholeWord: (BOOL) wholeWord
|
|
|
|
scrollTo: (BOOL) scrollTo
|
|
|
|
wrap: (BOOL) wrap
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
return [self findAndHighlightText: searchText
|
|
|
|
matchCase: matchCase
|
|
|
|
wholeWord: wholeWord
|
|
|
|
scrollTo: scrollTo
|
|
|
|
wrap: wrap
|
|
|
|
backwards: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2010-08-21 23:59:56 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
/**
|
2015-06-07 21:19:26 +00:00
|
|
|
* Searches and marks the first occurrence of the given text and optionally scrolls it into view.
|
2013-08-28 00:44:27 +00:00
|
|
|
*
|
|
|
|
* @result YES if something was found, NO otherwise.
|
|
|
|
*/
|
|
|
|
- (BOOL) findAndHighlightText: (NSString*) searchText
|
|
|
|
matchCase: (BOOL) matchCase
|
|
|
|
wholeWord: (BOOL) wholeWord
|
|
|
|
scrollTo: (BOOL) scrollTo
|
|
|
|
wrap: (BOOL) wrap
|
|
|
|
backwards: (BOOL) backwards
|
|
|
|
{
|
2010-08-21 23:59:56 +00:00
|
|
|
int searchFlags= 0;
|
|
|
|
if (matchCase)
|
|
|
|
searchFlags |= SCFIND_MATCHCASE;
|
|
|
|
if (wholeWord)
|
|
|
|
searchFlags |= SCFIND_WHOLEWORD;
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
long selectionStart = [self getGeneralProperty: SCI_GETSELECTIONSTART parameter: 0];
|
|
|
|
long selectionEnd = [self getGeneralProperty: SCI_GETSELECTIONEND parameter: 0];
|
|
|
|
|
|
|
|
// Sets the start point for the coming search to the beginning of the current selection.
|
2013-08-28 00:44:27 +00:00
|
|
|
// For forward searches we have therefore to set the selection start to the current selection end
|
|
|
|
// for proper incremental search. This does not harm as we either get a new selection if something
|
|
|
|
// is found or the previous selection is restored.
|
|
|
|
if (!backwards)
|
|
|
|
[self getGeneralProperty: SCI_SETSELECTIONSTART parameter: selectionEnd];
|
|
|
|
[self setGeneralProperty: SCI_SEARCHANCHOR value: 0];
|
|
|
|
sptr_t result;
|
|
|
|
const char* textToSearch = [searchText UTF8String];
|
|
|
|
|
|
|
|
// The following call will also set the selection if something was found.
|
|
|
|
if (backwards)
|
2010-08-21 23:59:56 +00:00
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
result = [ScintillaView directCall: self
|
|
|
|
message: SCI_SEARCHPREV
|
|
|
|
wParam: searchFlags
|
|
|
|
lParam: (sptr_t) textToSearch];
|
|
|
|
if (result < 0 && wrap)
|
|
|
|
{
|
|
|
|
// Try again from the end of the document if nothing could be found so far and
|
|
|
|
// wrapped search is set.
|
|
|
|
[self getGeneralProperty: SCI_SETSELECTIONSTART parameter: [self getGeneralProperty: SCI_GETTEXTLENGTH parameter: 0]];
|
|
|
|
[self setGeneralProperty: SCI_SEARCHANCHOR value: 0];
|
|
|
|
result = [ScintillaView directCall: self
|
|
|
|
message: SCI_SEARCHNEXT
|
|
|
|
wParam: searchFlags
|
|
|
|
lParam: (sptr_t) textToSearch];
|
|
|
|
}
|
2010-08-21 23:59:56 +00:00
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
result = [ScintillaView directCall: self
|
|
|
|
message: SCI_SEARCHNEXT
|
|
|
|
wParam: searchFlags
|
|
|
|
lParam: (sptr_t) textToSearch];
|
|
|
|
if (result < 0 && wrap)
|
|
|
|
{
|
|
|
|
// Try again from the start of the document if nothing could be found so far and
|
|
|
|
// wrapped search is set.
|
|
|
|
[self getGeneralProperty: SCI_SETSELECTIONSTART parameter: 0];
|
|
|
|
[self setGeneralProperty: SCI_SEARCHANCHOR value: 0];
|
|
|
|
result = [ScintillaView directCall: self
|
|
|
|
message: SCI_SEARCHNEXT
|
|
|
|
wParam: searchFlags
|
|
|
|
lParam: (sptr_t) textToSearch];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result >= 0)
|
2010-08-21 23:59:56 +00:00
|
|
|
{
|
|
|
|
if (scrollTo)
|
2011-03-22 00:16:49 +00:00
|
|
|
[self setGeneralProperty: SCI_SCROLLCARET value: 0];
|
2010-08-21 23:59:56 +00:00
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Restore the former selection if we did not find anything.
|
|
|
|
[self setGeneralProperty: SCI_SETSELECTIONSTART value: selectionStart];
|
|
|
|
[self setGeneralProperty: SCI_SETSELECTIONEND value: selectionEnd];
|
|
|
|
}
|
|
|
|
return (result >= 0) ? YES : NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Searches the given text and replaces
|
|
|
|
*
|
|
|
|
* @result Number of entries replaced, 0 if none.
|
|
|
|
*/
|
|
|
|
- (int) findAndReplaceText: (NSString*) searchText
|
|
|
|
byText: (NSString*) newText
|
|
|
|
matchCase: (BOOL) matchCase
|
|
|
|
wholeWord: (BOOL) wholeWord
|
|
|
|
doAll: (BOOL) doAll
|
|
|
|
{
|
2015-06-07 21:19:26 +00:00
|
|
|
// The current position is where we start searching for single occurrences. Otherwise we start at
|
2013-08-28 00:44:27 +00:00
|
|
|
// the beginning of the document.
|
2015-06-07 21:19:26 +00:00
|
|
|
long startPosition;
|
2013-08-28 00:44:27 +00:00
|
|
|
if (doAll)
|
|
|
|
startPosition = 0; // Start at the beginning of the text if we replace all occurrences.
|
|
|
|
else
|
2015-06-07 21:19:26 +00:00
|
|
|
// For a single replacement we start at the current caret position.
|
2013-08-28 00:44:27 +00:00
|
|
|
startPosition = [self getGeneralProperty: SCI_GETCURRENTPOS];
|
2015-06-07 21:19:26 +00:00
|
|
|
long endPosition = [self getGeneralProperty: SCI_GETTEXTLENGTH];
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
int searchFlags= 0;
|
|
|
|
if (matchCase)
|
|
|
|
searchFlags |= SCFIND_MATCHCASE;
|
|
|
|
if (wholeWord)
|
|
|
|
searchFlags |= SCFIND_WHOLEWORD;
|
|
|
|
[self setGeneralProperty: SCI_SETSEARCHFLAGS value: searchFlags];
|
|
|
|
[self setGeneralProperty: SCI_SETTARGETSTART value: startPosition];
|
|
|
|
[self setGeneralProperty: SCI_SETTARGETEND value: endPosition];
|
|
|
|
|
|
|
|
const char* textToSearch = [searchText UTF8String];
|
2015-06-07 21:19:26 +00:00
|
|
|
long sourceLength = strlen(textToSearch); // Length in bytes.
|
2013-08-28 00:44:27 +00:00
|
|
|
const char* replacement = [newText UTF8String];
|
2015-06-07 21:19:26 +00:00
|
|
|
long targetLength = strlen(replacement); // Length in bytes.
|
2013-08-28 00:44:27 +00:00
|
|
|
sptr_t result;
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
int replaceCount = 0;
|
|
|
|
if (doAll)
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
result = [ScintillaView directCall: self
|
|
|
|
message: SCI_SEARCHINTARGET
|
|
|
|
wParam: sourceLength
|
|
|
|
lParam: (sptr_t) textToSearch];
|
|
|
|
if (result < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
replaceCount++;
|
|
|
|
[ScintillaView directCall: self
|
|
|
|
message: SCI_REPLACETARGET
|
|
|
|
wParam: targetLength
|
|
|
|
lParam: (sptr_t) replacement];
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
// The replacement changes the target range to the replaced text. Continue after that till the end.
|
2013-08-28 00:44:27 +00:00
|
|
|
// The text length might be changed by the replacement so make sure the target end is the actual
|
|
|
|
// text end.
|
|
|
|
[self setGeneralProperty: SCI_SETTARGETSTART value: [self getGeneralProperty: SCI_GETTARGETEND]];
|
|
|
|
[self setGeneralProperty: SCI_SETTARGETEND value: [self getGeneralProperty: SCI_GETTEXTLENGTH]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = [ScintillaView directCall: self
|
|
|
|
message: SCI_SEARCHINTARGET
|
|
|
|
wParam: sourceLength
|
|
|
|
lParam: (sptr_t) textToSearch];
|
|
|
|
replaceCount = (result < 0) ? 0 : 1;
|
|
|
|
|
|
|
|
if (replaceCount > 0)
|
|
|
|
{
|
|
|
|
[ScintillaView directCall: self
|
|
|
|
message: SCI_REPLACETARGET
|
|
|
|
wParam: targetLength
|
|
|
|
lParam: (sptr_t) replacement];
|
|
|
|
|
|
|
|
// For a single replace we set the new selection to the replaced text.
|
|
|
|
[self setGeneralProperty: SCI_SETSELECTIONSTART value: [self getGeneralProperty: SCI_GETTARGETSTART]];
|
|
|
|
[self setGeneralProperty: SCI_SETSELECTIONEND value: [self getGeneralProperty: SCI_GETTARGETEND]];
|
|
|
|
}
|
|
|
|
}
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
return replaceCount;
|
2010-08-21 23:59:56 +00:00
|
|
|
}
|
2010-07-14 09:47:17 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2010-08-21 23:59:56 +00:00
|
|
|
- (void) setFontName: (NSString*) font
|
|
|
|
size: (int) size
|
|
|
|
bold: (BOOL) bold
|
|
|
|
italic: (BOOL) italic
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
for (int i = 0; i < 128; i++)
|
2010-08-21 23:59:56 +00:00
|
|
|
{
|
|
|
|
[self setGeneralProperty: SCI_STYLESETFONT
|
|
|
|
parameter: i
|
|
|
|
value: (sptr_t)[font UTF8String]];
|
|
|
|
[self setGeneralProperty: SCI_STYLESETSIZE
|
|
|
|
parameter: i
|
|
|
|
value: size];
|
|
|
|
[self setGeneralProperty: SCI_STYLESETBOLD
|
|
|
|
parameter: i
|
|
|
|
value: bold];
|
|
|
|
[self setGeneralProperty: SCI_STYLESETITALIC
|
|
|
|
parameter: i
|
|
|
|
value: italic];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
@end
|
|
|
|
|