2010-07-14 09:47:17 +00:00
|
|
|
/*
|
|
|
|
* ScintillaCocoa.h
|
|
|
|
*
|
|
|
|
* Mike Lischke <mlischke@sun.com>
|
|
|
|
*
|
|
|
|
* Based on ScintillaMacOSX.h
|
|
|
|
* Original code by Evan Jones on Sun Sep 01 2002.
|
|
|
|
* Contributors:
|
|
|
|
* Shane Caraveo, ActiveState
|
|
|
|
* Bernd Paradies, Adobe
|
|
|
|
*
|
|
|
|
* Copyright 2009 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).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
2015-06-07 21:19:26 +00:00
|
|
|
#include <ctype.h>
|
2010-07-14 09:47:17 +00:00
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <string>
|
2010-07-14 09:47:17 +00:00
|
|
|
#include <vector>
|
2013-08-28 00:44:27 +00:00
|
|
|
#include <map>
|
2010-07-14 09:47:17 +00:00
|
|
|
|
2010-08-21 23:59:56 +00:00
|
|
|
#include "ILexer.h"
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
#ifdef SCI_LEXER
|
|
|
|
#include "SciLexer.h"
|
|
|
|
#include "PropSetSimple.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "SplitVector.h"
|
|
|
|
#include "Partitioning.h"
|
|
|
|
#include "RunStyles.h"
|
|
|
|
#include "ContractionState.h"
|
|
|
|
#include "CellBuffer.h"
|
|
|
|
#include "CallTip.h"
|
|
|
|
#include "KeyMap.h"
|
|
|
|
#include "Indicator.h"
|
|
|
|
#include "XPM.h"
|
|
|
|
#include "LineMarker.h"
|
|
|
|
#include "Style.h"
|
|
|
|
#include "ViewStyle.h"
|
|
|
|
#include "CharClassify.h"
|
|
|
|
#include "Decoration.h"
|
2013-08-28 00:44:27 +00:00
|
|
|
#include "CaseFolder.h"
|
2010-07-14 09:47:17 +00:00
|
|
|
#include "Document.h"
|
2015-06-07 21:19:26 +00:00
|
|
|
#include "CaseConvert.h"
|
2010-07-14 09:47:17 +00:00
|
|
|
#include "Selection.h"
|
|
|
|
#include "PositionCache.h"
|
2015-06-07 21:19:26 +00:00
|
|
|
#include "EditModel.h"
|
|
|
|
#include "MarginView.h"
|
|
|
|
#include "EditView.h"
|
2010-07-14 09:47:17 +00:00
|
|
|
#include "Editor.h"
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
#include "AutoComplete.h"
|
2010-07-14 09:47:17 +00:00
|
|
|
#include "ScintillaBase.h"
|
|
|
|
|
|
|
|
extern "C" NSString* ScintillaRecPboardType;
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
@class SCIContentView;
|
|
|
|
@class SCIMarginView;
|
2010-07-14 09:47:17 +00:00
|
|
|
@class ScintillaView;
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
@class FindHighlightLayer;
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
/**
|
|
|
|
* Helper class to be used as timer target (NSTimer).
|
|
|
|
*/
|
|
|
|
@interface TimerTarget : NSObject
|
|
|
|
{
|
|
|
|
void* mTarget;
|
|
|
|
NSNotificationQueue* notificationQueue;
|
|
|
|
}
|
|
|
|
- (id) init: (void*) target;
|
|
|
|
- (void) timerFired: (NSTimer*) timer;
|
|
|
|
- (void) idleTimerFired: (NSTimer*) timer;
|
|
|
|
- (void) idleTriggered: (NSNotification*) notification;
|
|
|
|
@end
|
|
|
|
|
|
|
|
namespace Scintilla {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main scintilla class, implemented for OS X (Cocoa).
|
|
|
|
*/
|
|
|
|
class ScintillaCocoa : public ScintillaBase
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
TimerTarget* timerTarget;
|
|
|
|
NSEvent* lastMouseEvent;
|
2015-06-07 21:19:26 +00:00
|
|
|
|
|
|
|
id<ScintillaNotificationProtocol> delegate;
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
SciNotifyFunc notifyProc;
|
|
|
|
intptr_t notifyObj;
|
|
|
|
|
|
|
|
bool capturedMouse;
|
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
bool enteredSetScrollingSize;
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
// Private so ScintillaCocoa objects can not be copied
|
|
|
|
ScintillaCocoa(const ScintillaCocoa &) : ScintillaBase() {}
|
|
|
|
ScintillaCocoa &operator=(const ScintillaCocoa &) { return * this; }
|
|
|
|
|
|
|
|
bool GetPasteboardData(NSPasteboard* board, SelectionText* selectedText);
|
|
|
|
void SetPasteboardData(NSPasteboard* board, const SelectionText& selectedText);
|
2015-06-07 21:19:26 +00:00
|
|
|
int TargetAsUTF8(char *text);
|
|
|
|
int EncodedFromUTF8(char *utf8, char *encoded) const;
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
int scrollSpeed;
|
|
|
|
int scrollTicks;
|
2013-08-28 00:44:27 +00:00
|
|
|
NSTimer* tickTimer;
|
|
|
|
NSTimer* idleTimer;
|
|
|
|
CFRunLoopObserverRef observer;
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
FindHighlightLayer *layerFindIndicator;
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
protected:
|
2015-06-07 21:19:26 +00:00
|
|
|
Point GetVisibleOriginInMain() const;
|
|
|
|
PRectangle GetClientRectangle() const;
|
|
|
|
virtual PRectangle GetClientDrawingRectangle();
|
2010-07-14 09:47:17 +00:00
|
|
|
Point ConvertPoint(NSPoint point);
|
2015-06-07 21:19:26 +00:00
|
|
|
virtual void RedrawRect(PRectangle rc);
|
|
|
|
virtual void DiscardOverdraw();
|
|
|
|
virtual void Redraw();
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
virtual void Initialise();
|
|
|
|
virtual void Finalise();
|
2011-07-17 22:30:49 +00:00
|
|
|
virtual CaseFolder *CaseFolderForEncoding();
|
2010-08-21 23:59:56 +00:00
|
|
|
virtual std::string CaseMapString(const std::string &s, int caseMapping);
|
2013-08-28 00:44:27 +00:00
|
|
|
virtual void CancelModes();
|
2011-07-17 22:30:49 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
public:
|
2015-06-07 21:19:26 +00:00
|
|
|
ScintillaCocoa(SCIContentView* view, SCIMarginView* viewMargin);
|
2010-07-14 09:47:17 +00:00
|
|
|
virtual ~ScintillaCocoa();
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
void SetDelegate(id<ScintillaNotificationProtocol> delegate_);
|
2010-07-14 09:47:17 +00:00
|
|
|
void RegisterNotifyCallback(intptr_t windowid, SciNotifyFunc callback);
|
|
|
|
sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
NSScrollView* ScrollContainer() const;
|
|
|
|
SCIContentView* ContentView();
|
2010-07-14 09:47:17 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
bool SyncPaint(void* gc, PRectangle rc);
|
|
|
|
bool Draw(NSRect rect, CGContextRef gc);
|
|
|
|
void PaintMargin(NSRect aRect);
|
2010-07-14 09:47:17 +00:00
|
|
|
|
|
|
|
virtual sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam);
|
2015-06-07 21:19:26 +00:00
|
|
|
void TickFor(TickReason reason);
|
|
|
|
bool FineTickerAvailable();
|
|
|
|
bool FineTickerRunning(TickReason reason);
|
|
|
|
void FineTickerStart(TickReason reason, int millis, int tolerance);
|
|
|
|
void FineTickerCancel(TickReason reason);
|
2010-07-14 09:47:17 +00:00
|
|
|
bool SetIdle(bool on);
|
|
|
|
void SetMouseCapture(bool on);
|
|
|
|
bool HaveMouseCapture();
|
2015-06-07 21:19:26 +00:00
|
|
|
void WillDraw(NSRect rect);
|
2013-08-28 00:44:27 +00:00
|
|
|
void ScrollText(int linesToMove);
|
2010-07-14 09:47:17 +00:00
|
|
|
void SetVerticalScrollPos();
|
|
|
|
void SetHorizontalScrollPos();
|
|
|
|
bool ModifyScrollBars(int nMax, int nPage);
|
2013-08-28 00:44:27 +00:00
|
|
|
bool SetScrollingSize(void);
|
2010-07-14 09:47:17 +00:00
|
|
|
void Resize();
|
2013-08-28 00:44:27 +00:00
|
|
|
void UpdateForScroll();
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
// Notifications for the owner.
|
|
|
|
void NotifyChange();
|
|
|
|
void NotifyFocus(bool focus);
|
|
|
|
void NotifyParent(SCNotification scn);
|
|
|
|
void NotifyURIDropped(const char *uri);
|
|
|
|
|
|
|
|
bool HasSelection();
|
|
|
|
bool CanUndo();
|
|
|
|
bool CanRedo();
|
|
|
|
virtual void CopyToClipboard(const SelectionText &selectedText);
|
|
|
|
virtual void Copy();
|
|
|
|
virtual bool CanPaste();
|
|
|
|
virtual void Paste();
|
|
|
|
virtual void Paste(bool rectangular);
|
2011-07-17 22:30:49 +00:00
|
|
|
void CTPaint(void* gc, NSRect rc);
|
|
|
|
void CallTipMouseDown(NSPoint pt);
|
2010-07-14 09:47:17 +00:00
|
|
|
virtual void CreateCallTipWindow(PRectangle rc);
|
|
|
|
virtual void AddToPopUp(const char *label, int cmd = 0, bool enabled = true);
|
|
|
|
virtual void ClaimSelection();
|
|
|
|
|
|
|
|
NSPoint GetCaretPosition();
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
static sptr_t DirectFunction(sptr_t ptr, unsigned int iMessage, uptr_t wParam, sptr_t lParam);
|
|
|
|
|
|
|
|
NSTimer *timers[tickPlatform+1];
|
2010-07-14 09:47:17 +00:00
|
|
|
void TimerFired(NSTimer* timer);
|
|
|
|
void IdleTimerFired();
|
2013-08-28 00:44:27 +00:00
|
|
|
static void UpdateObserver(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *sci);
|
|
|
|
void ObserverAdd();
|
|
|
|
void ObserverRemove();
|
|
|
|
virtual void IdleWork();
|
|
|
|
virtual void QueueIdleWork(WorkNeeded::workItems items, int upTo);
|
2010-07-14 09:47:17 +00:00
|
|
|
int InsertText(NSString* input);
|
2015-06-07 21:19:26 +00:00
|
|
|
NSRange PositionsFromCharacters(NSRange range) const;
|
|
|
|
NSRange CharactersFromPositions(NSRange range) const;
|
2013-08-28 00:44:27 +00:00
|
|
|
void SelectOnlyMainSelection();
|
2015-06-07 21:19:26 +00:00
|
|
|
void ConvertSelectionVirtualSpace();
|
|
|
|
bool ClearAllSelections();
|
|
|
|
void CompositionStart();
|
|
|
|
void CompositionCommit();
|
|
|
|
void CompositionUndo();
|
2013-08-28 00:44:27 +00:00
|
|
|
virtual void SetDocPointer(Document *document);
|
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
bool KeyboardInput(NSEvent* event);
|
|
|
|
void MouseDown(NSEvent* event);
|
|
|
|
void MouseMove(NSEvent* event);
|
|
|
|
void MouseUp(NSEvent* event);
|
|
|
|
void MouseEntered(NSEvent* event);
|
|
|
|
void MouseExited(NSEvent* event);
|
|
|
|
void MouseWheel(NSEvent* event);
|
|
|
|
|
|
|
|
// Drag and drop
|
|
|
|
void StartDrag();
|
|
|
|
bool GetDragData(id <NSDraggingInfo> info, NSPasteboard &pasteBoard, SelectionText* selectedText);
|
|
|
|
NSDragOperation DraggingEntered(id <NSDraggingInfo> info);
|
|
|
|
NSDragOperation DraggingUpdated(id <NSDraggingInfo> info);
|
|
|
|
void DraggingExited(id <NSDraggingInfo> info);
|
|
|
|
bool PerformDragOperation(id <NSDraggingInfo> info);
|
|
|
|
void DragScroll();
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
// Promote some methods needed for NSResponder actions.
|
|
|
|
virtual void SelectAll();
|
|
|
|
void DeleteBackward();
|
|
|
|
virtual void Cut();
|
|
|
|
virtual void Undo();
|
|
|
|
virtual void Redo();
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
virtual NSMenu* CreateContextMenu(NSEvent* event);
|
|
|
|
void HandleCommand(NSInteger command);
|
|
|
|
|
2011-07-17 22:30:49 +00:00
|
|
|
virtual void ActiveStateChanged(bool isActive);
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
// Find indicator
|
|
|
|
void ShowFindIndicatorForRange(NSRange charRange, BOOL retaining);
|
|
|
|
void MoveFindIndicatorWithBounce(BOOL bounce);
|
|
|
|
void HideFindIndicator();
|
2010-07-14 09:47:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|