diff options
author | nyamatongwe <unknown> | 2011-02-07 13:54:07 +1100 |
---|---|---|
committer | nyamatongwe <unknown> | 2011-02-07 13:54:07 +1100 |
commit | 5350f8da7e73f683380fec5db5d6ebacf6b95511 (patch) | |
tree | 73e459dd94e115cd0ab514a6735c4330d4f565f9 | |
parent | 4d6720ee3d75e3e8ab186d610b879018a3a6114c (diff) | |
download | scintilla-mirror-5350f8da7e73f683380fec5db5d6ebacf6b95511.tar.gz |
Merged in current scintilla-cocoa from bzr.
-rw-r--r-- | cocoa/ScintillaCocoa.mm | 25 | ||||
-rw-r--r-- | cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj | 1 | ||||
-rw-r--r-- | cocoa/ScintillaTest/AppController.mm | 2 | ||||
-rw-r--r-- | cocoa/ScintillaView.h | 7 | ||||
-rw-r--r-- | cocoa/ScintillaView.mm | 87 |
5 files changed, 87 insertions, 35 deletions
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index 823bcfd3f..08c827b38 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -220,7 +220,8 @@ ScintillaCocoa::~ScintillaCocoa() void ScintillaCocoa::Initialise() { static bool initedLexers = false; - if (!initedLexers) { + if (!initedLexers) + { initedLexers = true; Scintilla_LinkLexers(); } @@ -1105,25 +1106,29 @@ void ScintillaCocoa::DoScroll(float position, NSScrollerPart part, bool horizont } else { - // VerticalScrolling is by line. - int topLine = (int) (position * MaxScrollPos()); - int page = LinesOnScreen(); + // VerticalScrolling is by line. If the user is scrolling using the knob we can directly + // set the new scroll position. Otherwise we have to compute it first. + if (part == NSScrollerKnob) + ScrollTo(position * MaxScrollPos(), false); + else + { switch (part) { case NSScrollerDecrementLine: - topLine--; + ScrollTo(topLine - 1, true); break; case NSScrollerDecrementPage: - topLine -= page; + ScrollTo(topLine - LinesOnScreen(), true); break; case NSScrollerIncrementLine: - topLine++; + ScrollTo(topLine + 1, true); break; case NSScrollerIncrementPage: - topLine += page; + ScrollTo(topLine + LinesOnScreen(), true); break; }; - ScrollTo(topLine, true); + + } } } @@ -1232,7 +1237,7 @@ void ScintillaCocoa::IdleTimerFired() /** * Main entry point for drawing the control. * - * @param rect The area to paint, given in the sender's coordinate. + * @param rect The area to paint, given in the sender's coordinate system. * @param gc The context we can use to paint. */ void ScintillaCocoa::Draw(NSRect rect, CGContextRef gc) diff --git a/cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj b/cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj index c5e428a8e..bd0783348 100644 --- a/cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj +++ b/cocoa/ScintillaFramework/ScintillaFramework.xcodeproj/project.pbxproj @@ -935,6 +935,7 @@ COPY_PHASE_STRIP = NO; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; + EXCLUDED_RECURSIVE_SEARCH_PATH_SUBDIRECTORIES = ".bzr *.nib *.lproj *.framework *.gch (*) CVS .svn *.xcodeproj *.xcode *.pbproj *.pbxproj"; FRAMEWORK_VERSION = A; GCC_DYNAMIC_NO_PIC = NO; GCC_ENABLE_FIX_AND_CONTINUE = YES; diff --git a/cocoa/ScintillaTest/AppController.mm b/cocoa/ScintillaTest/AppController.mm index 9bce5fd11..4c8801a33 100644 --- a/cocoa/ScintillaTest/AppController.mm +++ b/cocoa/ScintillaTest/AppController.mm @@ -100,7 +100,7 @@ const char user_keywords[] = // Definition of own keywords, not used by MySQL. // alternatively: [mEditor setEditorProperty: SCI_SETLEXERLANGUAGE parameter: nil value: (sptr_t) "mysql"]; // Number of styles we use with this lexer. - [mEditor setGeneralProperty: SCI_SETSTYLEBITS parameter: 5 value: 0]; + [mEditor setGeneralProperty: SCI_SETSTYLEBITS value: [mEditor getGeneralProperty: SCI_GETSTYLEBITSNEEDED]]; // Keywords to highlight. Indices are: // 0 - Major keywords (reserved keywords) diff --git a/cocoa/ScintillaView.h b/cocoa/ScintillaView.h index 0d66d36a4..9073be4ae 100644 --- a/cocoa/ScintillaView.h +++ b/cocoa/ScintillaView.h @@ -43,6 +43,9 @@ extern NSString *SCIUpdateUINotification; - (void) removeMarkedText; - (void) setCursor: (Scintilla::Window::Cursor) cursor; +- (BOOL) canUndo; +- (BOOL) canRedo; + @property (retain) ScintillaView* owner; @end @@ -76,6 +79,8 @@ extern NSString *SCIUpdateUINotification; value: (float) value; - (void) setCallback: (id <InfoBarCommunicator>) callback; +- (void) suspendDrawing: (BOOL) suspend; + // Scroller handling - (BOOL) setVerticalScrollRange: (int) range page: (int) page; - (void) setVerticalScrollPosition: (float) position; @@ -106,6 +111,8 @@ extern NSString *SCIUpdateUINotification; // Back end properties getters and setters. - (void) setGeneralProperty: (int) property parameter: (long) parameter value: (long) value; +- (void) setGeneralProperty: (int) property value: (long) value; + - (long) getGeneralProperty: (int) property; - (long) getGeneralProperty: (int) property parameter: (long) parameter; - (long) getGeneralProperty: (int) property parameter: (long) parameter extra: (long) extra; diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm index 6f4557c2b..d451c374f 100644 --- a/cocoa/ScintillaView.mm +++ b/cocoa/ScintillaView.mm @@ -179,7 +179,10 @@ NSString *SCIUpdateUINotification = @"SCIUpdateUI"; */ - (NSMenu*) menuForEvent: (NSEvent*) theEvent { - return mOwner.backend->CreateContextMenu(theEvent); + if (![mOwner respondsToSelector: @selector(menuForEvent:)]) + return mOwner.backend->CreateContextMenu(theEvent); + else + return [mOwner menuForEvent: theEvent]; } //-------------------------------------------------------------------------------------------------- @@ -279,11 +282,9 @@ NSString *SCIUpdateUINotification = @"SCIUpdateUI"; { // We have already marked text. Replace that. [mOwner setGeneralProperty: SCI_SETSELECTIONSTART - parameter: mMarkedTextRange.location - value: 0]; + value: mMarkedTextRange.location]; [mOwner setGeneralProperty: SCI_SETSELECTIONEND - parameter: mMarkedTextRange.location + mMarkedTextRange.length - value: 0]; + value: mMarkedTextRange.location + mMarkedTextRange.length]; currentPosition = mMarkedTextRange.location; } @@ -296,7 +297,7 @@ NSString *SCIUpdateUINotification = @"SCIUpdateUI"; 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]; + [mOwner setGeneralProperty: SCI_SETINDICATORCURRENT value: INPUT_INDICATOR]; [mOwner setGeneralProperty: SCI_INDICATORFILLRANGE parameter: mMarkedTextRange.location value: mMarkedTextRange.length]; @@ -305,11 +306,9 @@ NSString *SCIUpdateUINotification = @"SCIUpdateUI"; if (range.length > 0) { [mOwner setGeneralProperty: SCI_SETSELECTIONSTART - parameter: currentPosition + range.location - value: 0]; + value: currentPosition + range.location]; [mOwner setGeneralProperty: SCI_SETSELECTIONEND - parameter: currentPosition + range.location + range.length - value: 0]; + value: currentPosition + range.location + range.length]; } } @@ -319,7 +318,7 @@ NSString *SCIUpdateUINotification = @"SCIUpdateUI"; { if (mMarkedTextRange.length > 0) { - [mOwner setGeneralProperty: SCI_SETINDICATORCURRENT parameter: INPUT_INDICATOR value: 0]; + [mOwner setGeneralProperty: SCI_SETINDICATORCURRENT value: INPUT_INDICATOR]; [mOwner setGeneralProperty: SCI_INDICATORCLEARRANGE parameter: mMarkedTextRange.location value: mMarkedTextRange.length]; @@ -338,11 +337,9 @@ NSString *SCIUpdateUINotification = @"SCIUpdateUI"; { // We have already marked text. Replace that. [mOwner setGeneralProperty: SCI_SETSELECTIONSTART - parameter: mMarkedTextRange.location - value: 0]; + value: mMarkedTextRange.location]; [mOwner setGeneralProperty: SCI_SETSELECTIONEND - parameter: mMarkedTextRange.location + mMarkedTextRange.length - value: 0]; + value: mMarkedTextRange.location + mMarkedTextRange.length]; mOwner.backend->InsertText(@""); mMarkedTextRange = NSMakeRange(NSNotFound, 0); } @@ -546,6 +543,22 @@ NSString *SCIUpdateUINotification = @"SCIUpdateUI"; mOwner.backend->Redo(); } +- (BOOL) canUndo +{ + return mOwner.backend->CanUndo(); +} + +- (BOOL) canRedo +{ + return mOwner.backend->CanRedo(); +} + + +- (BOOL) isEditable +{ + return mOwner.backend->WndProc(SCI_GETREADONLY, 0, 0) == 0; +} + //-------------------------------------------------------------------------------------------------- - (void) dealloc @@ -621,7 +634,7 @@ NSString *SCIUpdateUINotification = @"SCIUpdateUI"; // Compute point increase/decrease based on default font size. int fontSize = [self getGeneralProperty: SCI_STYLEGETSIZE parameter: STYLE_DEFAULT]; int zoom = (int) (fontSize * (value - 1)); - [self setGeneralProperty: SCI_SETZOOM parameter: zoom value: 0]; + [self setGeneralProperty: SCI_SETZOOM value: zoom]; break; } }; @@ -637,6 +650,20 @@ NSString *SCIUpdateUINotification = @"SCIUpdateUI"; //-------------------------------------------------------------------------------------------------- /** + * 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]; +} + +//-------------------------------------------------------------------------------------------------- + +/** * Notification function used by Scintilla to call us back (e.g. for handling clicks on the * folder margin or changes in the editor). */ @@ -660,7 +687,7 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa { // Click on the folder margin. Toggle the current line if possible. int line = [editor getGeneralProperty: SCI_LINEFROMPOSITION parameter: scn->position]; - [editor setGeneralProperty: SCI_TOGGLEFOLD parameter: line value: 0]; + [editor setGeneralProperty: SCI_TOGGLEFOLD value: line]; } break; }; @@ -688,6 +715,7 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa NSPoint caretPosition = editor->mBackend->GetCaretPosition(); [editor->mInfoBar notify: IBNCaretChanged message: nil location: caretPosition value: 0]; [editor sendNotification: SCIUpdateUINotification]; + [editor sendNotification: NSTextViewDidChangeSelectionNotification]; break; } } @@ -984,7 +1012,7 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa */ - (void) scrollerAction: (id) sender { - float position = [sender floatValue]; + float position = [sender doubleValue]; mBackend->DoScroll(position, [sender hitPart], sender == mHorizontalScroller); } @@ -1095,7 +1123,7 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa - (BOOL) isEditable { - return mBackend->WndProc(SCI_GETREADONLY, 0, 0) != 0; + return mBackend->WndProc(SCI_GETREADONLY, 0, 0) == 0; } //-------------------------------------------------------------------------------------------------- @@ -1135,6 +1163,19 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa //-------------------------------------------------------------------------------------------------- /** + * 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); +} + +//-------------------------------------------------------------------------------------------------- + +/** * 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. @@ -1417,14 +1458,12 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa { // Highlight the found text. [self setGeneralProperty: SCI_SETSELECTIONSTART - parameter: position - value: 0]; + value: position]; [self setGeneralProperty: SCI_SETSELECTIONEND - parameter: position + [searchText length] - value: 0]; + value: position + [searchText length]]; if (scrollTo) - [self setGeneralProperty: SCI_SCROLLCARET parameter: 0 value: 0]; + [self setGeneralProperty: SCI_SCROLLCARET value: 0]; } } |