diff options
| -rw-r--r-- | cocoa/ScintillaCocoa.mm | 2 | ||||
| -rw-r--r-- | cocoa/ScintillaTest/AppController.h | 3 | ||||
| -rw-r--r-- | cocoa/ScintillaTest/ScintillaTest.xcodeproj/project.pbxproj | 10 | ||||
| -rw-r--r-- | cocoa/ScintillaView.h | 5 | ||||
| -rw-r--r-- | cocoa/ScintillaView.mm | 65 | 
5 files changed, 70 insertions, 15 deletions
| diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index 81dd991e7..a04c7220f 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -101,7 +101,7 @@ static const KeyToCommand macMapDefault[] =    {SCK_BACK,      SCI_ALT,    SCI_UNDO},    {SCK_BACK,      SCI_CSHIFT, SCI_DELLINELEFT},    {'z',           SCI_CMD,    SCI_UNDO}, -  {'y',           SCI_CMD,    SCI_REDO}, +  {'z',           SCI_SCMD,   SCI_REDO},    {'x',           SCI_CMD,    SCI_CUT},    {'c',           SCI_CMD,    SCI_COPY},    {'v',           SCI_CMD,    SCI_PASTE}, diff --git a/cocoa/ScintillaTest/AppController.h b/cocoa/ScintillaTest/AppController.h index 7c4f029e5..f324615d1 100644 --- a/cocoa/ScintillaTest/AppController.h +++ b/cocoa/ScintillaTest/AppController.h @@ -9,9 +9,6 @@  #import <Cocoa/Cocoa.h> -#define SCI_LEXER -#define SCI_NAMESPACE -  #import "ScintillaView.h"  #import "InfoBar.h" diff --git a/cocoa/ScintillaTest/ScintillaTest.xcodeproj/project.pbxproj b/cocoa/ScintillaTest/ScintillaTest.xcodeproj/project.pbxproj index 25aabb608..d630e1da9 100644 --- a/cocoa/ScintillaTest/ScintillaTest.xcodeproj/project.pbxproj +++ b/cocoa/ScintillaTest/ScintillaTest.xcodeproj/project.pbxproj @@ -286,7 +286,10 @@  				GCC_OPTIMIZATION_LEVEL = 0;  				GCC_PRECOMPILE_PREFIX_HEADER = YES;  				GCC_PREFIX_HEADER = ScintillaTest_Prefix.pch; -				GCC_PREPROCESSOR_DEFINITIONS = ""; +				GCC_PREPROCESSOR_DEFINITIONS = ( +					SCI_LEXER, +					SCI_NAMESPACE, +				);  				HEADER_SEARCH_PATHS = "../..//**";  				INFOPLIST_FILE = Info.plist;  				INSTALL_PATH = "$(HOME)/Applications"; @@ -309,7 +312,10 @@  				GCC_MODEL_TUNING = G5;  				GCC_PRECOMPILE_PREFIX_HEADER = YES;  				GCC_PREFIX_HEADER = ScintillaTest_Prefix.pch; -				GCC_PREPROCESSOR_DEFINITIONS = ""; +				GCC_PREPROCESSOR_DEFINITIONS = ( +					SCI_LEXER, +					SCI_NAMESPACE, +				);  				HEADER_SEARCH_PATHS = "../..//**";  				INFOPLIST_FILE = Info.plist;  				INSTALL_PATH = "$(HOME)/Applications"; diff --git a/cocoa/ScintillaView.h b/cocoa/ScintillaView.h index 574c2337d..8368e46c3 100644 --- a/cocoa/ScintillaView.h +++ b/cocoa/ScintillaView.h @@ -19,6 +19,8 @@  @class ScintillaView; +extern NSString *SCIUpdateUINotification; +  /**   * InnerView is the Cocoa interface to the Scintilla backend. It handles text input and   * provides a canvas for painting the output. @@ -84,6 +86,9 @@  - (NSString*) string;  - (void) setString: (NSString*) aString;  - (void) setEditable: (BOOL) editable; +- (NSRange) selectedRange; + +- (NSString*) selectedString;  // Native call through to the backend.  + (sptr_t) directCall: (ScintillaView*) sender message: (unsigned int) message wParam: (uptr_t) wParam diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm index 5ff3de720..1f428c017 100644 --- a/cocoa/ScintillaView.mm +++ b/cocoa/ScintillaView.mm @@ -19,6 +19,8 @@ static NSCursor* waitCursor;  // The scintilla indicator used for keyboard input.  #define INPUT_INDICATOR INDIC_MAX - 1 +NSString *SCIUpdateUINotification = @"SCIUpdateUI"; +  @implementation InnerView  @synthesize owner = mOwner; @@ -638,35 +640,42 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa        switch (scn->nmhdr.code)        {          case SCN_MARGINCLICK: +        {            if (scn->margin == 2)            {              // 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]; -          }; +          }            break; +          };          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))              [editor sendNotification: NSTextDidChangeNotification];            break; +        }          case SCN_ZOOM: -		  { +        {            // A zoom change happend. Notify info bar if there is one.            float zoom = [editor getGeneralProperty: SCI_GETZOOM parameter: 0];            int fontSize = [editor getGeneralProperty: SCI_STYLEGETSIZE parameter: STYLE_DEFAULT];            float factor = (zoom / fontSize) + 1;            [editor->mInfoBar notify: IBNZoomChanged message: nil location: NSZeroPoint value: factor]; -          } -		  break; +          break; +        }          case SCN_UPDATEUI: +        {            // Triggered whenever changes in the UI state need to be reflected.            // These can be: caret changes, selection changes etc.            NSPoint caretPosition = editor->mBackend->GetCaretPosition();            [editor->mInfoBar notify: IBNCaretChanged message: nil location: caretPosition value: 0]; +          [editor sendNotification: SCIUpdateUINotification];            break;        } +      }        break;      }      case WM_COMMAND: @@ -979,19 +988,20 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa  /**   * 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*) selectedString  {    NSString *result = nil;    char *buffer(0); -  const int length = mBackend->WndProc(SCI_GETLENGTH, 0, 0); +  const int length = mBackend->WndProc(SCI_GETSELTEXT, 0, 0);    if (length > 0)    {      buffer = new char[length + 1];      try      { -      mBackend->WndProc(SCI_GETTEXT, length + 1, (sptr_t) buffer); +      mBackend->WndProc(SCI_GETSELTEXT, length + 1, (sptr_t) buffer);        mBackend->WndProc(SCI_SETSAVEPOINT, 0, 0);        result = [NSString stringWithUTF8String: buffer]; @@ -1003,15 +1013,45 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa        buffer = 0;      }    } +  else +    result = [NSString stringWithUTF8String: ""];    return result;  }  //-------------------------------------------------------------------------------------------------- -- (void) setEditable: (BOOL) editable +/** + * 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  { -  mBackend->WndProc(SCI_SETREADONLY, editable ? 0 : 1, 0); +  NSString *result = nil; +   +  char *buffer(0); +  const int length = mBackend->WndProc(SCI_GETLENGTH, 0, 0); +  if (length > 0) +  { +    buffer = new char[length + 1]; +    try +    { +      mBackend->WndProc(SCI_GETTEXT, length + 1, (sptr_t) buffer); +      mBackend->WndProc(SCI_SETSAVEPOINT, 0, 0); +       +      result = [NSString stringWithUTF8String: buffer]; +      delete[] buffer; +    } +    catch (...) +    { +      delete[] buffer; +      buffer = 0; +    } +  } +  else +    result = [NSString stringWithUTF8String: ""]; +   +  return result;  }  //-------------------------------------------------------------------------------------------------- @@ -1027,6 +1067,13 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa  //-------------------------------------------------------------------------------------------------- +- (void) setEditable: (BOOL) editable +{ +  mBackend->WndProc(SCI_SETREADONLY, editable ? 0 : 1, 0); +} + +//-------------------------------------------------------------------------------------------------- +  - (InnerView*) content  {    return mContent; | 
