From a8ec0328ac3fa1fa3f1326c7e47a2d8ec1c3033f Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Sat, 24 Jul 2010 11:31:15 +1000 Subject: Updates from Scintilla-Cocoa project. Updated case mapping, modifier key for zoom, redo, mouse wheel, search and highlight. --- cocoa/ScintillaCocoa.h | 3 +- cocoa/ScintillaCocoa.mm | 62 +- cocoa/ScintillaTest/AppController.h | 1 + cocoa/ScintillaTest/AppController.mm | 12 + cocoa/ScintillaTest/English.lproj/MainMenu.xib | 927 +++++++++++++++++++++---- cocoa/ScintillaView.h | 16 +- cocoa/ScintillaView.mm | 88 ++- 7 files changed, 963 insertions(+), 146 deletions(-) (limited to 'cocoa') diff --git a/cocoa/ScintillaCocoa.h b/cocoa/ScintillaCocoa.h index 5be17c773..a5d6575f4 100644 --- a/cocoa/ScintillaCocoa.h +++ b/cocoa/ScintillaCocoa.h @@ -14,7 +14,7 @@ */ #include -#include +#include #include #include #include @@ -122,6 +122,7 @@ protected: virtual void Initialise(); virtual void Finalise(); + virtual std::string CaseMapString(const std::string &s, int caseMapping); public: ScintillaCocoa(NSView* view); virtual ~ScintillaCocoa(); diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index f91183aa2..6d3296a51 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -254,6 +254,31 @@ void ScintillaCocoa::Finalise() //-------------------------------------------------------------------------------------------------- +/** + * Case-fold the given string depending on the specified case mapping type. + * Note: ScintillaCocoa exclusively works with Unicode. We don't even think about adding support for + * obsolete code page stuff. + */ +std::string ScintillaCocoa::CaseMapString(const std::string &s, int caseMapping) +{ + NSString* textToConvert = [NSString stringWithUTF8String: s.c_str()]; + std::string result; + switch (caseMapping) + { + case cmUpper: + result = [[textToConvert uppercaseString] UTF8String]; + break; + case cmLower: + result = [[textToConvert lowercaseString] UTF8String]; + break; + default: + result = s; + } + return result; +} + +//-------------------------------------------------------------------------------------------------- + /** * Helper function to get the outer container which represents the Scintilla editor on application side. */ @@ -501,14 +526,15 @@ void ScintillaCocoa::Paste(bool forceRectangular) pdoc->BeginUndoAction(); ClearSelection(); + int length = selectedText.len - 1; // One less to avoid inserting the terminating 0 character. if (selectedText.rectangular) { SelectionPosition selStart = sel.RangeMain().Start(); - PasteRectangular(selStart, selectedText.s, selectedText.len); + PasteRectangular(selStart, selectedText.s, length); } else - if (pdoc->InsertString(sel.RangeMain().caret.Position(), selectedText.s, selectedText.len)) - SetEmptySelection(sel.RangeMain().caret.Position() + selectedText.len); + if (pdoc->InsertString(sel.RangeMain().caret.Position(), selectedText.s, length)) + SetEmptySelection(sel.RangeMain().caret.Position() + length); pdoc->EndUndoAction(); @@ -1373,34 +1399,32 @@ void ScintillaCocoa::MouseUp(NSEvent* event) void ScintillaCocoa::MouseWheel(NSEvent* event) { bool command = ([event modifierFlags] & NSCommandKeyMask) != 0; - bool shift = ([event modifierFlags] & NSShiftKeyMask) != 0; - int delta; - if (shift) - delta = 10 * [event deltaX]; // Arbitrary scale factor. - else - { + int dX = 0; + int dY = 0; + + dX = 10 * [event deltaX]; // Arbitrary scale factor. + // In order to make scrolling with larger offset smoother we scroll less lines the larger the // delta value is. if ([event deltaY] < 0) - delta = -(int) sqrt(-10.0 * [event deltaY]); + dY = -(int) sqrt(-10.0 * [event deltaY]); else - delta = (int) sqrt(10.0 * [event deltaY]); - } + 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 (delta > 0) + if (dY > 0.5) KeyCommand(SCI_ZOOMIN); - else + else if (dY < -0.5) KeyCommand(SCI_ZOOMOUT); } else - if (shift) - HorizontalScrollTo(xOffset - delta); - else - ScrollTo(topLine - delta, true); + { + HorizontalScrollTo(xOffset - dX); + ScrollTo(topLine - dY, true); + } } //-------------------------------------------------------------------------------------------------- @@ -1429,7 +1453,7 @@ void ScintillaCocoa::Undo() void ScintillaCocoa::Redo() { - Editor::Undo(); + Editor::Redo(); } //-------------------------------------------------------------------------------------------------- diff --git a/cocoa/ScintillaTest/AppController.h b/cocoa/ScintillaTest/AppController.h index f324615d1..dbc2417f5 100644 --- a/cocoa/ScintillaTest/AppController.h +++ b/cocoa/ScintillaTest/AppController.h @@ -19,5 +19,6 @@ - (void) awakeFromNib; - (void) setupEditor; +- (IBAction) searchText: (id) sender; @end diff --git a/cocoa/ScintillaTest/AppController.mm b/cocoa/ScintillaTest/AppController.mm index d660e0f75..9bce5fd11 100644 --- a/cocoa/ScintillaTest/AppController.mm +++ b/cocoa/ScintillaTest/AppController.mm @@ -209,6 +209,18 @@ const char user_keywords[] = // Definition of own keywords, not used by MySQL. [mEditor setStatusText: @"Operation complete"]; } +//-------------------------------------------------------------------------------------------------- + +- (IBAction) searchText: (id) sender +{ + NSSearchField* searchField = (NSSearchField*) sender; + [mEditor findAndHighlightText: [searchField stringValue] + matchCase: NO + wholeWord: NO + scrollTo: YES + wrap: YES]; +} + @end //-------------------------------------------------------------------------------------------------- diff --git a/cocoa/ScintillaTest/English.lproj/MainMenu.xib b/cocoa/ScintillaTest/English.lproj/MainMenu.xib index e795086ed..6de460712 100644 --- a/cocoa/ScintillaTest/English.lproj/MainMenu.xib +++ b/cocoa/ScintillaTest/English.lproj/MainMenu.xib @@ -1,23 +1,26 @@ - + 1050 - 9G55 - 677 - 949.43 - 353.00 + 10D573 + 762 + 1038.29 + 460.00 + + com.apple.InterfaceBuilder.CocoaPlugin + 762 + YES YES - com.apple.InterfaceBuilderKit com.apple.InterfaceBuilder.CocoaPlugin YES - + YES @@ -79,7 +82,7 @@ - UHJlZmVyZW5jZXPigKY + Preferences… , 1048576 2147483647 @@ -200,7 +203,7 @@ - T3BlbuKApg + Open… o 1048576 2147483647 @@ -264,7 +267,7 @@ - U2F2ZSBBc+KApg + Save As… S 1179648 2147483647 @@ -302,7 +305,7 @@ - UHJpbnTigKY + Print… p 1048576 2147483647 @@ -425,7 +428,7 @@ YES - RmluZOKApg + Find… f 1048576 2147483647 @@ -490,7 +493,7 @@ YES - U2hvdyBTcGVsbGluZ+KApg + Show Spelling… : 1048576 2147483647 @@ -1017,7 +1020,7 @@ - Q3VzdG9taXplIFRvb2xiYXLigKY + Customize Toolbar… 1048576 2147483647 @@ -1118,7 +1121,7 @@ Window NSWindow - {3.40282e+38, 3.40282e+38} + {1.79769e+308, 1.79769e+308} 319 @@ -1132,11 +1135,11 @@ 256 - {{1, 1}, {842, 640}} + {{1, 1}, {842, 590}} - {{17, 16}, {844, 656}} + {{17, 16}, {844, 606}} {0, 0} @@ -1145,10 +1148,10 @@ Scintilla Editor LucidaGrande - 1.100000e+01 + 11 3100 - + 6 System textBackgroundColor @@ -1178,9 +1181,9 @@ 67239424 134217728 Quit - + LucidaGrande - 1.300000e+01 + 13 1044 @@ -1192,12 +1195,81 @@ 25 + + + 268 + {{20, 630}, {287, 22}} + + YES + + 343014976 + 268436480 + + + + YES + 1 + + + 6 + System + controlTextColor + + 3 + MAA + + + + 130560 + 0 + search + + _searchFieldSearch: + + 138690815 + 0 + + 400 + 75 + + + 130560 + 0 + clear + + YES + + YES + + YES + AXDescription + NSAccessibilityEncodedAttributesValueType + + + YES + cancel + + + + + + _searchFieldCancel: + + 138690815 + 0 + + 400 + 75 + + 255 + + {982, 692} {{0, 0}, {1440, 878}} - {3.40282e+38, 3.40282e+38} + {1.79769e+308, 1.79769e+308} NSFontManager @@ -1753,34 +1825,40 @@ 455 + + + searchText: + + + + 468 + YES 0 - - YES - + -2 - - RmlsZSdzIE93bmVyA + + File's Owner -1 - + First Responder -3 - + Application @@ -1796,7 +1874,7 @@ - + MainMenu @@ -2332,7 +2410,7 @@ YES - + 372 @@ -2341,6 +2419,7 @@ YES + @@ -2652,12 +2731,12 @@ 420 - + 450 - + 451 @@ -2678,14 +2757,26 @@ + + 466 + + + YES + + + + + + 467 + + + YES - + YES - -1.IBPluginDependency - -2.IBPluginDependency -3.IBPluginDependency 103.IBPluginDependency 103.ImportedFromIB2 @@ -2817,6 +2908,7 @@ 354.IBPluginDependency 354.ImportedFromIB2 371.IBEditorWindowLastContentRect + 371.IBPluginDependency 371.IBWindowTemplateEditedContentRect 371.NSWindowTemplate.visibleAtLaunch 371.editorWindowContentRectSynchronizationRect @@ -2869,11 +2961,11 @@ 417.IBPluginDependency 418.IBPluginDependency 419.IBPluginDependency - 420.IBPluginDependency - 450.IBPluginDependency 451.IBPluginDependency 452.IBPluginDependency 453.IBPluginDependency + 466.IBPluginDependency + 467.IBPluginDependency 5.IBPluginDependency 5.ImportedFromIB2 56.IBPluginDependency @@ -2913,117 +3005,115 @@ YES com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilderKit - com.apple.InterfaceBuilderKit com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + {{596, 852}, {216, 23}} com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + {{522, 812}, {146, 23}} com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + {{436, 809}, {64, 6}} com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + {{608, 612}, {275, 83}} com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + {{187, 434}, {243, 243}} com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + {{608, 612}, {167, 43}} com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + {{608, 612}, {241, 103}} com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + {{525, 802}, {197, 73}} {{207, 285}, {478, 20}} com.apple.InterfaceBuilder.CocoaPlugin - + {74, 862} {{6, 978}, {478, 20}} com.apple.InterfaceBuilder.CocoaPlugin @@ -3032,21 +3122,22 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + {{608, 612}, {215, 63}} com.apple.InterfaceBuilder.CocoaPlugin - + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin - + + {{274, 370}, {982, 692}} com.apple.InterfaceBuilder.CocoaPlugin - - {{274, 369}, {982, 692}} - {{274, 369}, {982, 692}} - + {{274, 370}, {982, 692}} + {{33, 99}, {480, 360}} {3.40282e+38, 3.40282e+38} com.apple.InterfaceBuilder.CocoaPlugin @@ -3103,47 +3194,45 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + {{219, 102}, {245, 183}} com.apple.InterfaceBuilder.CocoaPlugin - + {{23, 794}, {245, 183}} com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + {{145, 474}, {199, 203}} com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin - + YES - - YES - + YES @@ -3151,15 +3240,13 @@ YES - - YES - + YES - 458 + 468 @@ -3167,6 +3254,10 @@ AppController NSObject + + searchText: + id + mEditHost NSBox @@ -3177,9 +3268,601 @@ + + YES + + NSActionCell + NSCell + + IBFrameworkSource + AppKit.framework/Headers/NSActionCell.h + + + + NSApplication + NSResponder + + IBFrameworkSource + AppKit.framework/Headers/NSApplication.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSApplicationScripting.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSColorPanel.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSHelpManager.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSPageLayout.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSUserInterfaceItemSearching.h + + + + NSBox + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSBox.h + + + + NSBrowser + NSControl + + IBFrameworkSource + AppKit.framework/Headers/NSBrowser.h + + + + NSButton + NSControl + + IBFrameworkSource + AppKit.framework/Headers/NSButton.h + + + + NSButtonCell + NSActionCell + + IBFrameworkSource + AppKit.framework/Headers/NSButtonCell.h + + + + NSCell + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSCell.h + + + + NSControl + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSControl.h + + + + NSDocument + NSObject + + YES + + YES + printDocument: + revertDocumentToSaved: + runPageLayout: + saveDocument: + saveDocumentAs: + saveDocumentTo: + + + YES + id + id + id + id + id + id + + + + IBFrameworkSource + AppKit.framework/Headers/NSDocument.h + + + + NSDocument + + IBFrameworkSource + AppKit.framework/Headers/NSDocumentScripting.h + + + + NSDocumentController + NSObject + + YES + + YES + clearRecentDocuments: + newDocument: + openDocument: + saveAllDocuments: + + + YES + id + id + id + id + + + + IBFrameworkSource + AppKit.framework/Headers/NSDocumentController.h + + + + NSFontManager + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSFontManager.h + + + + NSFormatter + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSFormatter.h + + + + NSMatrix + NSControl + + IBFrameworkSource + AppKit.framework/Headers/NSMatrix.h + + + + NSMenu + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSMenu.h + + + + NSMenuItem + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSMenuItem.h + + + + NSMovieView + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSMovieView.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSAccessibility.h + + + + NSObject + + + + NSObject + + + + NSObject + + + + NSObject + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSDictionaryController.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSDragging.h + + + + NSObject + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSFontPanel.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSKeyValueBinding.h + + + + NSObject + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSNibLoading.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSOutlineView.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSPasteboard.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSSavePanel.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSTableView.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSToolbarItem.h + + + + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSView.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSArchiver.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSClassDescription.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSError.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSFileManager.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueCoding.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueObserving.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyedArchiver.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSObject.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSObjectScripting.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSPortCoder.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSRunLoop.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSScriptClassDescription.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSScriptKeyValueCoding.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSScriptObjectSpecifiers.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSScriptWhoseTests.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSThread.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURL.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURLConnection.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURLDownload.h + + + + NSResponder + + IBFrameworkSource + AppKit.framework/Headers/NSInterfaceStyle.h + + + + NSResponder + NSObject + + IBFrameworkSource + AppKit.framework/Headers/NSResponder.h + + + + NSSearchField + NSTextField + + IBFrameworkSource + AppKit.framework/Headers/NSSearchField.h + + + + NSSearchFieldCell + NSTextFieldCell + + IBFrameworkSource + AppKit.framework/Headers/NSSearchFieldCell.h + + + + NSTableView + NSControl + + + + NSText + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSText.h + + + + NSTextField + NSControl + + IBFrameworkSource + AppKit.framework/Headers/NSTextField.h + + + + NSTextFieldCell + NSActionCell + + IBFrameworkSource + AppKit.framework/Headers/NSTextFieldCell.h + + + + NSTextView + NSText + + IBFrameworkSource + AppKit.framework/Headers/NSTextView.h + + + + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSClipView.h + + + + NSView + + + + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSRulerView.h + + + + NSView + NSResponder + + + + NSWindow + + IBFrameworkSource + AppKit.framework/Headers/NSDrawer.h + + + + NSWindow + NSResponder + + IBFrameworkSource + AppKit.framework/Headers/NSWindow.h + + + + NSWindow + + IBFrameworkSource + AppKit.framework/Headers/NSWindowScripting.h + + + 0 + IBCocoaFramework + + com.apple.InterfaceBuilder.CocoaPlugin.macosx + + + + com.apple.InterfaceBuilder.CocoaPlugin.macosx + + + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + + + YES ../ScintillaTest.xcodeproj 3 + + YES + + YES + NSMenuCheckmark + NSMenuMixedState + + + YES + {9, 8} + {7, 2} + + diff --git a/cocoa/ScintillaView.h b/cocoa/ScintillaView.h index 73903c369..0d66d36a4 100644 --- a/cocoa/ScintillaView.h +++ b/cocoa/ScintillaView.h @@ -53,6 +53,9 @@ extern NSString *SCIUpdateUINotification; // It uses the content view for display. Scintilla::ScintillaCocoa* mBackend; + // The object (eg NSDocument) that controls the ScintillaView. + NSObject* mOwner; + // This is the actual content to which the backend renders itself. InnerView* mContent; @@ -92,6 +95,11 @@ extern NSString *SCIUpdateUINotification; - (NSString*) selectedString; +- (void)setFontName: (NSString*) font + size: (int) size + bold: (BOOL) bold + italic: (BOOL) italic; + // Native call through to the backend. + (sptr_t) directCall: (ScintillaView*) sender message: (unsigned int) message wParam: (uptr_t) wParam lParam: (sptr_t) lParam; @@ -115,6 +123,12 @@ extern NSString *SCIUpdateUINotification; - (void) setInfoBar: (NSView *) aView top: (BOOL) top; - (void) setStatusText: (NSString*) text; -@property Scintilla::ScintillaCocoa* backend; +- (void) findAndHighlightText: (NSString*) searchText + matchCase: (BOOL) matchCase + wholeWord: (BOOL) wholeWord + scrollTo: (BOOL) scrollTo + wrap: (BOOL) wrap; +@property Scintilla::ScintillaCocoa* backend; +@property (retain) NSObject* owner; @end diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm index 84362e1c2..6f4557c2b 100644 --- a/cocoa/ScintillaView.mm +++ b/cocoa/ScintillaView.mm @@ -287,10 +287,13 @@ NSString *SCIUpdateUINotification = @"SCIUpdateUI"; currentPosition = mMarkedTextRange.location; } + // Note: Scintilla internally works almost always with bytes instead chars, so we need to take + // this into account when determining selection ranges and such. + std::string raw_text = [newText UTF8String]; mOwner.backend->InsertText(newText); mMarkedTextRange.location = currentPosition; - mMarkedTextRange.length = [newText length]; + mMarkedTextRange.length = raw_text.size(); // Mark the just inserted text. Keep the marked range for later reset. [mOwner setGeneralProperty: SCI_SETINDICATORCURRENT parameter: INPUT_INDICATOR value: 0]; @@ -298,7 +301,7 @@ NSString *SCIUpdateUINotification = @"SCIUpdateUI"; parameter: mMarkedTextRange.location value: mMarkedTextRange.length]; - // Select the part which is indicated in the given range. + // Select the part which is indicated in the given range. It does not scroll the caret into view. if (range.length > 0) { [mOwner setGeneralProperty: SCI_SETSELECTIONSTART @@ -558,6 +561,7 @@ NSString *SCIUpdateUINotification = @"SCIUpdateUI"; @implementation ScintillaView @synthesize backend = mBackend; +@synthesize owner = mOwner; /** * ScintiallView is a composite control made from an NSView and an embedded NSView that is @@ -1360,17 +1364,95 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa [mInfoBar notify: IBNStatusChanged message: text location: NSZeroPoint value: 0]; } +//-------------------------------------------------------------------------------------------------- + - (NSRange) selectedRange { return [mContent selectedRange]; } +//-------------------------------------------------------------------------------------------------- + - (void)insertText: (NSString*)text { [mContent insertText: text]; } -@end +//-------------------------------------------------------------------------------------------------- + +/** + * Searches and marks the first occurance of the given text and optionally scrolls it into view. + */ +- (void) findAndHighlightText: (NSString*) searchText + matchCase: (BOOL) matchCase + wholeWord: (BOOL) wholeWord + scrollTo: (BOOL) scrollTo + wrap: (BOOL) wrap +{ + // The current position is where we start searching. That is either the end of the current + // (main) selection or the caret position. That ensures we do proper "search next" too. + int currentPosition = [self getGeneralProperty: SCI_GETCURRENTPOS parameter: 0]; + int length = [self getGeneralProperty: SCI_GETTEXTLENGTH parameter: 0]; + + int searchFlags= 0; + if (matchCase) + searchFlags |= SCFIND_MATCHCASE; + if (wholeWord) + searchFlags |= SCFIND_WHOLEWORD; + + Sci_TextToFind ttf; + ttf.chrg.cpMin = currentPosition; + ttf.chrg.cpMax = length; + ttf.lpstrText = (char*) [searchText UTF8String]; + int position = mBackend->WndProc(SCI_FINDTEXT, searchFlags, (sptr_t) &ttf); + + if (position < 0 && wrap) + { + ttf.chrg.cpMin = 0; + ttf.chrg.cpMax = currentPosition; + position = mBackend->WndProc(SCI_FINDTEXT, searchFlags, (sptr_t) &ttf); + } + + if (position >= 0) + { + // Highlight the found text. + [self setGeneralProperty: SCI_SETSELECTIONSTART + parameter: position + value: 0]; + [self setGeneralProperty: SCI_SETSELECTIONEND + parameter: position + [searchText length] + value: 0]; + + if (scrollTo) + [self setGeneralProperty: SCI_SCROLLCARET parameter: 0 value: 0]; + } +} //-------------------------------------------------------------------------------------------------- +- (void) setFontName: (NSString*) font + size: (int) size + bold: (BOOL) bold + italic: (BOOL) italic +{ + for (int i = 0; i < 32; i++) + { + [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 + -- cgit v1.2.3