aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2010-04-22 09:28:18 +0000
committernyamatongwe <devnull@localhost>2010-04-22 09:28:18 +0000
commitdfc27758ce34c3bfe0c420d36cb80e4e07f883b3 (patch)
treea780e2c7bffab445e8a885561ec7d91dc1b6915b
parentc06f40d97ccdf72bafa44a1767aaf8beeddc2ef7 (diff)
downloadscintilla-mirror-dfc27758ce34c3bfe0c420d36cb80e4e07f883b3.tar.gz
Updated to launchpad scintilla-cocoa revision 33.
Context menu implemented. Many warnings avoided. Make files added.
-rw-r--r--cocoa/Framework.mk85
-rw-r--r--cocoa/InfoBar.mm2
-rw-r--r--cocoa/PlatCocoa.h9
-rw-r--r--cocoa/PlatCocoa.mm80
-rw-r--r--cocoa/SciTest.mk54
-rw-r--r--cocoa/ScintillaCocoa.h7
-rw-r--r--cocoa/ScintillaCocoa.mm135
-rw-r--r--cocoa/ScintillaView.h4
-rw-r--r--cocoa/ScintillaView.mm89
9 files changed, 322 insertions, 143 deletions
diff --git a/cocoa/Framework.mk b/cocoa/Framework.mk
new file mode 100644
index 000000000..06a29735b
--- /dev/null
+++ b/cocoa/Framework.mk
@@ -0,0 +1,85 @@
+### start defines ###
+
+ARCH=-arch i386
+CC=gcc -x c++ $(ARCH)
+CO=gcc -x objective-c++ $(ARCH)
+
+INST_NAME=-install_name @executable_path/../Frameworks/Sci.framework/Versions/A/Sci
+LD=gcc $(ARCH) -dynamiclib -framework Cocoa $(INST_NAME)
+
+gDEFs=-DSCI_NAMESPACE -DSCI_LEXER
+
+INCS=-I../src/ -I../include/ -I.
+CCX=$(CC) $(gDEFs) $(INCS)
+CCO=$(CO) $(gDEFs) $(INCS)
+
+BLD=build/framebuild
+
+SCI_LEXERS=LexAPDL.o LexASY.o LexAU3.o LexAVE.o LexAbaqus.o LexAda.o LexAsm.o LexAsn1.o \
+ LexBaan.o LexBash.o LexBasic.o LexBullant.o LexCLW.o LexCOBOL.o LexCPP.o LexCSS.o \
+ LexCaml.o LexCmake.o LexConf.o LexCrontab.o LexCsound.o LexD.o LexEScript.o LexEiffel.o \
+ LexErlang.o LexFlagship.o LexForth.o LexFortran.o LexGAP.o LexGui4Cli.o LexHTML.o \
+ LexHaskell.o LexInno.o LexKix.o LexLisp.o LexLout.o LexLua.o LexMMIXAL.o LexMPT.o \
+ LexMSSQL.o LexMagik.o LexMarkdown.o LexMatlab.o LexMetapost.o LexMySQL.o LexNimrod.o \
+ LexNsis.o LexOpal.o LexOthers.o LexPB.o LexPLM.o LexPOV.o LexPS.o LexPascal.o LexPerl.o \
+ LexPowerPro.o LexPowerShell.o LexProgress.o LexPython.o LexR.o LexRebol.o LexRuby.o \
+ LexSML.o LexSQL.o LexScriptol.o LexSmalltalk.o LexSorcus.o LexSpecman.o LexSpice.o \
+ LexTACL.o LexTADS3.o LexTAL.o LexTCL.o LexTeX.o LexVB.o LexVHDL.o LexVerilog.o LexYAML.o
+
+SCI_OBJ=AutoComplete.o CallTip.o CellBuffer.o CharClassify.o ContractionState.o Decoration.o \
+ Document.o DocumentAccessor.o Editor.o ExternalLexer.o Indicator.o KeyMap.o KeyWords.o \
+ LineMarker.o PerLine.o PositionCache.o PropSet.o RESearch.o RunStyles.o ScintillaBase.o \
+ Style.o StyleContext.o UniConversion.o ViewStyle.o WindowAccessor.o XPM.o Selection.o $(SCI_LEXERS)
+COC_OBJ=PlatCocoa.o ScintillaCocoa.o ScintillaView.o InfoBar.o
+
+OBJ=$(SCI_OBJ) $(COC_OBJ)
+OBJS=$(addprefix $(BLD)/,$(OBJ))
+
+TARG=$(APP)/Versions/A/Sci
+APP=$(BLD)/Sci.framework
+### end defines ###
+
+### start targets ###
+
+all: $(BLD) $(TARG)
+
+$(APP): $(BLD)
+ -rm -rf $(APP)
+ -mkdir $(APP)
+ -mkdir $(APP)/Versions
+ -mkdir $(APP)/Versions/A
+ -mkdir $(APP)/Versions/A/Headers
+ -mkdir $(APP)/Versions/A/Resources
+ -ln -sf `pwd`/$(APP)/Versions/A `pwd`/$(APP)/Versions/Current
+ -ln -sf `pwd`/$(APP)/Versions/A/Headers `pwd`/$(APP)/Headers
+ -ln -sf `pwd`/$(APP)/Versions/A/Resources `pwd`/$(APP)/Resources
+ -cp *.h $(APP)/Headers/
+ -cp ../src/*.h $(APP)/Headers/
+ -cp ../include/*.h $(APP)/Headers/
+ -cp -R ScintillaFramework/English.lproj $(APP)/Resources
+ -cp res/*.png $(APP)/Resources
+ -cp ScintillaFramework/Info.plist $(APP)/Resources
+
+$(TARG) : $(OBJS) $(APP)
+ $(LD) $(OBJS) $(gDEFs) -o $(TARG) -lstdc++
+ -ln `pwd`/$(TARG) `pwd`/$(APP)/Sci
+
+$(BLD):
+ -mkdir build
+ -mkdir $(BLD)
+
+clean:
+ -rm -rf $(BLD)
+
+$(BLD)/%.o : ../src/%.cxx
+ $(CCX) -c ../src/$< -o $@
+
+$(BLD)/%.o : %.mm
+ $(CCO) -c $< -o $@
+
+### get around to filling out the real dependencies later ###
+$(BLD)/AutoComplete.o : ../src/AutoComplete.cxx ../src/AutoComplete.h ../include/Platform.h
+
+$(BLD)/CallTip.o : ../src/CallTip.cxx ../src/CallTip.h ../include/Platform.h
+
+### end targets ### \ No newline at end of file
diff --git a/cocoa/InfoBar.mm b/cocoa/InfoBar.mm
index a96634dd1..63d68c4a1 100644
--- a/cocoa/InfoBar.mm
+++ b/cocoa/InfoBar.mm
@@ -216,7 +216,7 @@ static float BarFontSize = 10.0;
[mStatusTextLabel setFont: [NSFont menuBarFontOfSize: BarFontSize]];
cell = [mStatusTextLabel cell];
- [cell setPlaceholderString: @"Default status text"];
+ [cell setPlaceholderString: @""];
[self addSubview: mStatusTextLabel];
[mStatusTextLabel release];
diff --git a/cocoa/PlatCocoa.h b/cocoa/PlatCocoa.h
index a650c653e..250d94ad6 100644
--- a/cocoa/PlatCocoa.h
+++ b/cocoa/PlatCocoa.h
@@ -24,6 +24,15 @@
NSRect PRectangleToNSRect(Scintilla::PRectangle& rc);
Scintilla::PRectangle NSRectToPRectangle(NSRect& rc);
+@interface ScintillaContextMenu : NSMenu
+{
+ Scintilla::ScintillaCocoa* owner;
+}
+- (void) handleCommand: (NSMenuItem*) sender;
+- (void) setOwner: (Scintilla::ScintillaCocoa*) newOwner;
+
+@end
+
namespace Scintilla {
// A class to do the actual text rendering for us using Quartz 2D.
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm
index 5d6d43b09..259387846 100644
--- a/cocoa/PlatCocoa.mm
+++ b/cocoa/PlatCocoa.mm
@@ -1352,8 +1352,8 @@ void ListBoxImpl::Create(Window &/*parent*/, int /*ctrlID*/, Scintilla::Point /*
unicodeMode = unicodeMode_;
maxWidth = 2000;
- WindowClass windowClass = kHelpWindowClass;
- WindowAttributes attributes = kWindowNoAttributes;
+ //WindowClass windowClass = kHelpWindowClass;
+ //WindowAttributes attributes = kWindowNoAttributes;
Rect contentBounds;
WindowRef outWindow;
@@ -1365,7 +1365,7 @@ void ListBoxImpl::Create(Window &/*parent*/, int /*ctrlID*/, Scintilla::Point /*
//InstallStandardEventHandler(GetWindowEventTarget(outWindow));
- ControlRef root;
+ //ControlRef root;
//CreateRootControl(outWindow, &root);
//CreateDataBrowserControl(outWindow, &contentBounds, kDataBrowserListView, &lb);
@@ -1377,22 +1377,24 @@ void ListBoxImpl::Create(Window &/*parent*/, int /*ctrlID*/, Scintilla::Point /*
// get rid of the frame, forces databrowser to the full size
// of the window
- Boolean frameAndFocus = false;
+ //Boolean frameAndFocus = false;
//SetControlData(lb, kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag,
// sizeof(frameAndFocus), &frameAndFocus);
- ListBoxImpl* lbThis = this;
+ //ListBoxImpl* lbThis = this;
//SetControlProperty( lb, scintillaListBoxType, 0, sizeof( this ), &lbThis );
ConfigureDataBrowser();
InstallDataBrowserCustomCallbacks();
// install event handlers
+ /*
static const EventTypeSpec kWindowEvents[] =
{
{ kEventClassMouse, kEventMouseDown },
{ kEventClassMouse, kEventMouseMoved },
};
+ */
eventHandler = NULL;
//InstallWindowEventHandler( outWindow, WindowEventHandler,
@@ -1537,7 +1539,7 @@ pascal void ListBoxDrawItemCallback(ControlRef browser, DataBrowserItemID item,
{
if (property != kIconColumn) return;
ListBoxImpl* lbThis = NULL;
- OSStatus err;
+ //OSStatus err;
//err = GetControlProperty( browser, scintillaListBoxType, 0, sizeof( lbThis ), NULL, &lbThis );
// adjust our rect
lbThis->DrawRow(item, property, itemState, theRect);
@@ -1547,7 +1549,7 @@ pascal void ListBoxDrawItemCallback(ControlRef browser, DataBrowserItemID item,
void ListBoxImpl::ConfigureDataBrowser()
{
DataBrowserViewStyle viewStyle;
- DataBrowserSelectionFlags selectionFlags;
+ //DataBrowserSelectionFlags selectionFlags;
//GetDataBrowserViewStyle(lb, &viewStyle);
//SetDataBrowserHasScrollBars(lb, false, true);
@@ -1793,7 +1795,7 @@ int ListBoxImpl::Find(const char *prefix) {
char s[255];
for (int i = 0; i < count; i++) {
GetValue(i, s, 255);
- if (s[0] != NULL && (0 == strncmp(prefix, s, strlen(prefix)))) {
+ if ((s[0] != '\0') && (0 == strncmp(prefix, s, strlen(prefix)))) {
return i;
}
}
@@ -1840,6 +1842,27 @@ void ListBoxImpl::ClearRegisteredImages() {
xset.Clear();
}
+//----------------- ScintillaContextMenu -----------------------------------------------------------
+
+@implementation ScintillaContextMenu : NSMenu
+
+// This NSMenu subclass serves also as target for menu commands and forwards them as
+// notfication messages to the front end.
+
+- (void) handleCommand: (NSMenuItem*) sender
+{
+ owner->HandleCommand([sender tag]);
+}
+
+//--------------------------------------------------------------------------------------------------
+
+- (void) setOwner: (Scintilla::ScintillaCocoa*) newOwner
+{
+ owner = newOwner;
+}
+
+@end
+
//----------------- Menu ---------------------------------------------------------------------------
Menu::Menu()
@@ -1849,34 +1872,27 @@ Menu::Menu()
//--------------------------------------------------------------------------------------------------
-void Menu::CreatePopUp() {
- // TODO: Could I just feed a constant menu ID parameter, or does
- // it really need to be unique?
- static int nextMenuID = 1;
+void Menu::CreatePopUp()
+{
Destroy();
- OSStatus err;
- // err = CreateNewMenu( nextMenuID++, 0, reinterpret_cast<MenuRef*>( &id ) );
+ mid = [[ScintillaContextMenu alloc] initWithTitle: @""];
}
-void Menu::Destroy() {
+//--------------------------------------------------------------------------------------------------
+
+void Menu::Destroy()
+{
+ ScintillaContextMenu* menu = reinterpret_cast<ScintillaContextMenu*>(mid);
+ [menu release];
+ mid = NULL;
}
-void Menu::Show(Point pt, Window &) {
- /*
- UInt32 userSelection = 0;
- SInt16 menuId = 0;
- MenuItemIndex menuItem = 0;
- ::Point globalPoint;
- globalPoint.h = pt.x;
- globalPoint.v = pt.y;
- OSStatus err;
- err = ContextualMenuSelect( reinterpret_cast<MenuRef>( id ), globalPoint,
- false, kCMHelpItemRemoveHelp, NULL,
- NULL, &userSelection,
- &menuId,
- &menuItem
- );
- */
+//--------------------------------------------------------------------------------------------------
+
+void Menu::Show(Point pt, Window &)
+{
+ // Cocoa menus are handled a bit differently. We only create the menu. The framework
+ // takes care to show it properly.
}
//----------------- ElapsedTime --------------------------------------------------------------------
@@ -1973,7 +1989,7 @@ bool Platform::MouseButtonBounce()
*/
long Platform::SendScintilla(WindowID w, unsigned int msg, unsigned long wParam, long lParam)
{
- return scintilla_send_message( w, msg, wParam, lParam );
+ return scintilla_send_message(w, msg, wParam, lParam);
}
//--------------------------------------------------------------------------------------------------
diff --git a/cocoa/SciTest.mk b/cocoa/SciTest.mk
new file mode 100644
index 000000000..cd922e1b5
--- /dev/null
+++ b/cocoa/SciTest.mk
@@ -0,0 +1,54 @@
+### start defines ###
+NAME=Editor
+
+ARCH=-arch i386
+CC=gcc -x c++ $(ARCH)
+CO=gcc -x objective-c++ $(ARCH)
+LD=gcc $(ARCH) -framework Cocoa
+
+gDEFs=-DSCI_NAMESPACE -DSCI_LEXER
+
+INCS=-I../src/ -I../include/ -I.
+CCX=$(CC) $(gDEFs) $(INCS)
+CCO=$(CO) $(gDEFs) $(INCS)
+
+BLD=build/SciAppBuild
+TARG=$(APP)/Contents/MacOS/$(NAME)
+APP=$(BLD)/$(NAME).app
+
+all: $(BLD) $(TARG)
+
+clean:
+ -rm -rf $(BLD)
+
+$(APP):
+ -rm -rf $(APP)
+ -mkdir $(APP)
+ -mkdir $(APP)/Contents/
+ -mkdir $(APP)/Contents/Frameworks/
+ -mkdir $(APP)/Contents/MacOS/
+ -mkdir $(APP)/Contents/Resources/
+ -cp ScintillaTest/Info.plist $(APP)/Contents/Info.plist.bak
+ -sed "s/\$${EXECUTABLE_NAME}/$(NAME)/g" < $(APP)/Contents/Info.plist.bak > $(APP)/Contents/Info.plist.bak2
+ -sed "s/\$${PRODUCT_NAME}/$(NAME)/g" < $(APP)/Contents/Info.plist.bak2 > $(APP)/Contents/Info.plist
+ -rm $(APP)/Contents/Info.plist.bak $(APP)/Contents/Info.plist.bak2
+ -cp -r ScintillaTest/English.lproj $(APP)/Contents/Resources/
+ /Developer/usr/bin/ibtool --errors --warnings --notices --output-format human-readable-text \
+ --compile $(APP)/Contents/Resources/English.lproj/MainMenu.nib ScintillaTest/English.lproj/MainMenu.xib
+ -cp ScintillaTest/TestData.sql $(APP)/Contents/Resources/
+ -make -f Framework.mk all
+
+$(TARG) : $(BLD)/main.o $(BLD)/AppController.o $(APP)
+ -cp -R build/framebuild/Sci.framework $(APP)/Contents/Frameworks/
+ $(LD) $(BLD)/main.o $(BLD)/AppController.o $(APP)/Contents/Frameworks/Sci.framework/Sci -o $(TARG) -lstdc++
+
+
+$(BLD) :
+ -mkdir build
+ -mkdir $(BLD)
+
+$(BLD)/%.o : ScintillaTest/%.mm
+ $(CCO) -c $< -o $@
+
+$(BLD)/%.o : ScintillaTest/%.m
+ $(CCO) -c $< -o $@
diff --git a/cocoa/ScintillaCocoa.h b/cocoa/ScintillaCocoa.h
index 6f563431b..3f4d20093 100644
--- a/cocoa/ScintillaCocoa.h
+++ b/cocoa/ScintillaCocoa.h
@@ -78,7 +78,7 @@ namespace Scintilla {
* back to the parent. Therefore, there must be a callback handler that acts
* like a Windows WndProc, where Scintilla can send notifications to. Use
* ScintillaCocoa::RegisterNotifyHandler() to register such a handler.
- * Messgae format is:
+ * Message format is:
* <br>
* WM_COMMAND: HIWORD (wParam) = notification code, LOWORD (wParam) = 0 (no control ID), lParam = ScintillaCocoa*
* <br>
@@ -196,8 +196,9 @@ public:
virtual void Undo();
virtual void Redo();
- // virtual OSStatus ContextualMenuClick( HIPoint& location );
-//
+ virtual NSMenu* CreateContextMenu(NSEvent* event);
+ void HandleCommand(NSInteger command);
+
// virtual OSStatus ActiveStateChanged();
//
// virtual void CallTipClick();
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm
index a04c7220f..318c364e5 100644
--- a/cocoa/ScintillaCocoa.mm
+++ b/cocoa/ScintillaCocoa.mm
@@ -3,14 +3,14 @@
* Scintilla source code edit control
* ScintillaCocoa.mm - Cocoa subclass of ScintillaBase
*
- * Mike Lischke <mlischke@sun.com>
+ * Written by Mike Lischke <mlischke@sun.com>
*
* Loosely based on ScintillaMacOSX.cxx.
* Copyright 2003 by Evan Jones <ejones@uwaterloo.ca>
* Based on ScintillaGTK.cxx Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
* The License.txt file describes the conditions under which this software may be distributed.
*
- * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ * Copyright (c) 2009, 2010 Sun Microsystems, Inc. All rights reserved.
* This file is dual licensed under LGPL v2.1 and the Scintilla license (http://www.scintilla.org/License.txt).
*/
@@ -59,12 +59,12 @@ static const KeyToCommand macMapDefault[] =
{SCK_LEFT, SCI_SHIFT, SCI_CHARLEFTEXTEND},
{SCK_LEFT, SCI_ALT, SCI_WORDLEFT},
{SCK_LEFT, SCI_CSHIFT, SCI_WORDLEFTEXTEND},
- {SCK_LEFT, SCI_ASHIFT, SCI_CHARLEFTRECTEXTEND},
+ {SCK_LEFT, SCI_ASHIFT, SCI_WORDLEFTEXTEND},
{SCK_RIGHT, SCI_NORM, SCI_CHARRIGHT},
{SCK_RIGHT, SCI_SHIFT, SCI_CHARRIGHTEXTEND},
{SCK_RIGHT, SCI_ALT, SCI_WORDRIGHT},
{SCK_RIGHT, SCI_CSHIFT, SCI_WORDRIGHTEXTEND},
- {SCK_RIGHT, SCI_ASHIFT, SCI_CHARRIGHTRECTEXTEND},
+ {SCK_RIGHT, SCI_ASHIFT, SCI_WORDRIGHTEXTEND},
{'/', SCI_CTRL, SCI_WORDPARTLEFT},
{'/', SCI_CSHIFT, SCI_WORDPARTLEFTEXTEND},
{'\\', SCI_CTRL, SCI_WORDPARTRIGHT},
@@ -137,7 +137,7 @@ static const KeyToCommand macMapDefault[] =
// Get the default notification queue for the thread which created the instance (usually the
// main thread). We need that later for idle event processing.
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
- notificationQueue = [[[NSNotificationQueue alloc] initWithNotificationCenter: center] autorelease];
+ notificationQueue = [[NSNotificationQueue alloc] initWithNotificationCenter: center];
[center addObserver: self selector: @selector(idleTriggered:) name: @"Idle" object: nil];
}
return self;
@@ -145,6 +145,14 @@ static const KeyToCommand macMapDefault[] =
//--------------------------------------------------------------------------------------------------
+- (void) dealloc
+{
+ [notificationQueue release];
+ [super dealloc];
+}
+
+//--------------------------------------------------------------------------------------------------
+
/**
* Method called by a timer installed by ScintillaCocoa. This two step approach is needed because
* a native Obj-C class is required as target for the timer.
@@ -460,8 +468,7 @@ bool ScintillaCocoa::CanPaste()
if (!Editor::CanPaste())
return false;
- bool ok = GetPasteboardData([NSPasteboard generalPasteboard], NULL);
- return ok;
+ return GetPasteboardData([NSPasteboard generalPasteboard], NULL);
}
//--------------------------------------------------------------------------------------------------
@@ -508,7 +515,7 @@ void ScintillaCocoa::Paste(bool forceRectangular)
void ScintillaCocoa::CreateCallTipWindow(PRectangle rc)
{
-#if 0
+/*
// create a calltip window
if (!ct.wCallTip.Created()) {
WindowClass windowClass = kHelpWindowClass;
@@ -573,60 +580,29 @@ void ScintillaCocoa::CreateCallTipWindow(PRectangle rc)
HIViewSetVisible(ctw,true);
}
-#endif
+*/
}
void ScintillaCocoa::AddToPopUp(const char *label, int cmd, bool enabled)
{
- // Translate stuff into menu item attributes
- MenuItemAttributes attributes = 0;
- if (label[0] == '\0')
- attributes |= kMenuItemAttrSeparator;
- if (!enabled)
- attributes |= kMenuItemAttrDisabled;
+ NSMenuItem* item;
+ ScintillaContextMenu *menu= reinterpret_cast<ScintillaContextMenu*>(popup.GetID());
+ [menu setOwner: this];
+ [menu setAutoenablesItems: NO];
- // Translate Scintilla commands into Mac OS commands
- // TODO: If I create an AEDesc, OS X may insert these standard
- // text editing commands into the menu for me.
- MenuCommand macCommand;
- switch (cmd)
- {
- case idcmdUndo:
- macCommand = kHICommandUndo;
- break;
- case idcmdRedo:
- macCommand = kHICommandRedo;
- break;
- case idcmdCut:
- macCommand = kHICommandCut;
- break;
- case idcmdCopy:
- macCommand = kHICommandCopy;
- break;
- case idcmdPaste:
- macCommand = kHICommandPaste;
- break;
- case idcmdDelete:
- macCommand = kHICommandClear;
- break;
- case idcmdSelectAll:
- macCommand = kHICommandSelectAll;
- break;
- case 0:
- macCommand = 0;
- break;
- default:
- assert( false );
- return;
- }
+ if (cmd == 0)
+ item = [NSMenuItem separatorItem];
+ else
+ item = [[NSMenuItem alloc] init];
-// NSMenu *menu= reinterpret_cast<NSMenu*>(popup.GetID());
+ [item setTarget: menu];
+ [item setAction: @selector(handleCommand:)];
+ [item setTag: cmd];
+ [item setTitle: [NSString stringWithUTF8String: label]];
+ [item setEnabled: enabled];
- //XXX TODO:XXX
-// [menu addItemWithTitle:[NSString stringWithUTF8String:label]
-// action:@selector()
-// keyEquivalent:@""];
+ [menu addItem: item];
}
// -------------------------------------------------------------------------------------------------
@@ -640,7 +616,7 @@ void ScintillaCocoa::ClaimSelection()
/**
* Returns the current caret position (which is tracked as an offset into the entire text string)
- * to a row:column pair. The result is zero-based.
+ * as a row:column pair. The result is zero-based.
*/
NSPoint ScintillaCocoa::GetCaretPosition()
{
@@ -925,7 +901,7 @@ bool ScintillaCocoa::GetPasteboardData(NSPasteboard* board, SelectionText* selec
{
char* text = (char*) [data UTF8String];
bool rectangular = bestType == ScintillaRecPboardType;
- selectedText->Copy(text, strlen(text), 0, 0, rectangular, false);
+ selectedText->Copy(text, strlen(text) + 1, SC_CP_UTF8, SC_CHARSET_DEFAULT , rectangular, false);
}
return true;
}
@@ -1028,22 +1004,21 @@ bool ScintillaCocoa::ModifyScrollBars(int nMax, int nPage)
{
// Input values are given in lines, not pixels, so we have to convert.
int lineHeight = WndProc(SCI_TEXTHEIGHT, 0, 0);
- NSView* container = ContentView();
- NSRect bounds = [container frame];
+ PRectangle bounds = GetTextRectangle();
ScintillaView* topContainer = TopContainer();
// Set page size to the same value as the scroll range to hide the scrollbar.
int scrollRange = lineHeight * (nMax + 1); // +1 because the caller subtracted one.
int pageSize;
if (verticalScrollBarVisible)
- pageSize = bounds.size.height;
+ pageSize = bounds.Height();
else
pageSize = scrollRange;
bool verticalChange = [topContainer setVerticalScrollRange: scrollRange page: pageSize];
scrollRange = scrollWidth;
if (horizontalScrollBarVisible)
- pageSize = bounds.size.width;
+ pageSize = bounds.Width();
else
pageSize = scrollRange;
bool horizontalChange = [topContainer setHorizontalScrollRange: scrollRange page: pageSize];
@@ -1399,7 +1374,7 @@ void ScintillaCocoa::MouseWheel(NSEvent* event)
delta = 10 * [event deltaX]; // Arbitrary scale factor.
else
{
- // In order to make scrolling with larger offset smoother we scroll less line the larger the
+ // 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]);
@@ -1454,19 +1429,30 @@ void ScintillaCocoa::Redo()
//--------------------------------------------------------------------------------------------------
-//OSStatus ScintillaCocoa::ContextualMenuClick( HIPoint& location )
-//{
-// // convert screen coords to window relative
-// Rect bounds;
-// OSStatus err;
-// err = GetWindowBounds( this->GetOwner(), kWindowContentRgn, &bounds );
-// assert( err == noErr );
-// location.x += bounds.left;
-// location.y += bounds.top;
-// ContextMenu( Scintilla::Point( static_cast<int>( location.x ), static_cast<int>( location.y ) ) );
-// return noErr;
-//}
-//
+/**
+ * Creates and returns a popup menu, which is then displayed by the Cocoa framework.
+ */
+NSMenu* ScintillaCocoa::CreateContextMenu(NSEvent* event)
+{
+ // Call ScintillaBase to create the context menu.
+ ContextMenu(Point(0, 0));
+
+ return reinterpret_cast<NSMenu*>(popup.GetID());
+}
+
+//--------------------------------------------------------------------------------------------------
+
+/**
+ * An intermediate function to forward context menu commands from the menu action handler to
+ * scintilla.
+ */
+void ScintillaCocoa::HandleCommand(NSInteger command)
+{
+ Command(command);
+}
+
+//--------------------------------------------------------------------------------------------------
+
//OSStatus ScintillaCocoa::ActiveStateChanged()
//{
// // If the window is being deactivated, lose the focus and turn off the ticking
@@ -1482,3 +1468,4 @@ void ScintillaCocoa::Redo()
//
//--------------------------------------------------------------------------------------------------
+
diff --git a/cocoa/ScintillaView.h b/cocoa/ScintillaView.h
index 8368e46c3..73903c369 100644
--- a/cocoa/ScintillaView.h
+++ b/cocoa/ScintillaView.h
@@ -85,7 +85,9 @@ extern NSString *SCIUpdateUINotification;
// NSTextView compatibility layer.
- (NSString*) string;
- (void) setString: (NSString*) aString;
+- (void) insertText: (NSString*) aString;
- (void) setEditable: (BOOL) editable;
+- (BOOL) isEditable;
- (NSRange) selectedRange;
- (NSString*) selectedString;
@@ -96,8 +98,10 @@ extern NSString *SCIUpdateUINotification;
// Back end properties getters and setters.
- (void) setGeneralProperty: (int) property parameter: (long) parameter value: (long) value;
+- (long) getGeneralProperty: (int) property;
- (long) getGeneralProperty: (int) property parameter: (long) parameter;
- (long) getGeneralProperty: (int) property parameter: (long) parameter extra: (long) extra;
+- (long) getGeneralProperty: (int) property ref: (const void*) ref;
- (void) setColorProperty: (int) property parameter: (long) parameter value: (NSColor*) value;
- (void) setColorProperty: (int) property parameter: (long) parameter fromHTML: (NSString*) fromHTML;
- (NSColor*) getColorProperty: (int) property parameter: (long) parameter;
diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm
index 1f428c017..84362e1c2 100644
--- a/cocoa/ScintillaView.mm
+++ b/cocoa/ScintillaView.mm
@@ -174,6 +174,16 @@ NSString *SCIUpdateUINotification = @"SCIUpdateUI";
//--------------------------------------------------------------------------------------------------
+/**
+ * Called by the framework if it wants to show a context menu for the editor.
+ */
+- (NSMenu*) menuForEvent: (NSEvent*) theEvent
+{
+ return mOwner.backend->CreateContextMenu(theEvent);
+}
+
+//--------------------------------------------------------------------------------------------------
+
// Adoption of NSTextInput protocol.
- (NSAttributedString*) attributedSubstringFromRange: (NSRange) range
@@ -228,7 +238,6 @@ NSString *SCIUpdateUINotification = @"SCIUpdateUI";
{
// Remove any previously marked text first.
[self removeMarkedText];
-
mOwner.backend->InsertText((NSString*) aString);
}
@@ -604,11 +613,13 @@ NSString *SCIUpdateUINotification = @"SCIUpdateUI";
switch (type)
{
case IBNZoomChanged:
+ {
// 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];
break;
+ }
};
}
@@ -987,12 +998,12 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa
//--------------------------------------------------------------------------------------------------
/**
- * Getter for the current text in raw form (no formatting information included).
+ * 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 = nil;
+ NSString *result = @"";
char *buffer(0);
const int length = mBackend->WndProc(SCI_GETSELTEXT, 0, 0);
@@ -1013,8 +1024,6 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa
buffer = 0;
}
}
- else
- result = [NSString stringWithUTF8String: ""];
return result;
}
@@ -1027,7 +1036,7 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa
*/
- (NSString*) string
{
- NSString *result = nil;
+ NSString *result = @"";
char *buffer(0);
const int length = mBackend->WndProc(SCI_GETLENGTH, 0, 0);
@@ -1048,8 +1057,6 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa
buffer = 0;
}
}
- else
- result = [NSString stringWithUTF8String: ""];
return result;
}
@@ -1067,6 +1074,14 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa
//--------------------------------------------------------------------------------------------------
+- (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);
@@ -1074,6 +1089,13 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa
//--------------------------------------------------------------------------------------------------
+- (BOOL) isEditable
+{
+ return mBackend->WndProc(SCI_GETREADONLY, 0, 0) != 0;
+}
+
+//--------------------------------------------------------------------------------------------------
+
- (InnerView*) content
{
return mContent;
@@ -1095,13 +1117,13 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa
//--------------------------------------------------------------------------------------------------
/**
- * This is a helper method to set a property in the backend, with native parameters.
+ * 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 get.
+ * @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 value to be set.
+ * @param value The actual value. It depends on the property what this parameter means.
*/
-- (void) setEditorProperty: (int) property wParam: (long) parameter lParam: (long) value
+- (void) setGeneralProperty: (int) property parameter: (long) parameter value: (long) value
{
mBackend->WndProc(property, parameter, value);
}
@@ -1113,51 +1135,42 @@ static void notification(intptr_t windowid, unsigned int iMessage, uintptr_t wPa
*
* @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) getEditorProperty: (int) property wParam: (long) parameter
+- (long) getGeneralProperty: (int) property parameter: (long) parameter extra: (long) extra
{
- return mBackend->WndProc(property, parameter, 0);
+ return mBackend->WndProc(property, parameter, extra);
}
-
//--------------------------------------------------------------------------------------------------
/**
- * 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.
+ * Convenience function to avoid unneeded extra parameter.
*/
-- (void) setGeneralProperty: (int) property parameter: (long) parameter value: (long) value
+- (long) getGeneralProperty: (int) property parameter: (long) parameter
{
- mBackend->WndProc(property, parameter, value);
+ return mBackend->WndProc(property, parameter, 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.
- * @param parameter Additional info for this property like a parameter or index.
- * @result A generic value which must be interpreted depending on the property queried.
+ * Convenience function to avoid unneeded parameters.
*/
-- (long) getGeneralProperty: (int) property parameter: (long) parameter
+- (long) getGeneralProperty: (int) property
{
- return mBackend->WndProc(property, parameter, 0);
+ return mBackend->WndProc(property, 0, 0);
}
//--------------------------------------------------------------------------------------------------
/**
- * Very similar to getGeneralProperty:parameter, but allows to specify an additional value
- * which certain actions require.
+ * Use this variant if you have to pass in a reference to something (e.g. a text range).
*/
-- (long) getGeneralProperty: (int) property parameter: (long) parameter extra: (long) extra
+- (long) getGeneralProperty: (int) property ref: (const void*) ref
{
- return mBackend->WndProc(property, parameter, extra);
+ return mBackend->WndProc(property, 0, (sptr_t) ref);
}
//--------------------------------------------------------------------------------------------------
@@ -1347,6 +1360,16 @@ 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
//--------------------------------------------------------------------------------------------------