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).
|
|
|
|
*/
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <ctime>
|
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>
|
2019-05-04 18:14:48 +00:00
|
|
|
#include <memory>
|
2010-07-14 09:47:17 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
#include "ILoader.h"
|
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
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
#include "Position.h"
|
|
|
|
#include "UniqueString.h"
|
2010-07-14 09:47:17 +00:00
|
|
|
#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 "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"
|
2019-05-04 18:14:48 +00:00
|
|
|
#include "UniConversion.h"
|
|
|
|
#include "DBCS.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"
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
extern "C" NSString *ScintillaRecPboardType;
|
2010-07-14 09:47:17 +00:00
|
|
|
|
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).
|
|
|
|
*/
|
2019-05-04 18:14:48 +00:00
|
|
|
@interface TimerTarget : NSObject {
|
|
|
|
void *mTarget;
|
|
|
|
NSNotificationQueue *notificationQueue;
|
2010-07-14 09:47:17 +00:00
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
- (id) init: (void *) target;
|
|
|
|
- (void) timerFired: (NSTimer *) timer;
|
|
|
|
- (void) idleTimerFired: (NSTimer *) timer;
|
|
|
|
- (void) idleTriggered: (NSNotification *) notification;
|
2010-07-14 09:47:17 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
namespace Scintilla {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main scintilla class, implemented for OS X (Cocoa).
|
|
|
|
*/
|
2019-05-04 18:14:48 +00:00
|
|
|
class ScintillaCocoa : public ScintillaBase {
|
2010-07-14 09:47:17 +00:00
|
|
|
private:
|
2019-05-04 18:14:48 +00:00
|
|
|
ScintillaView *sciView;
|
|
|
|
TimerTarget *timerTarget;
|
|
|
|
NSEvent *lastMouseEvent;
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
id<ScintillaNotificationProtocol> delegate;
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
SciNotifyFunc notifyProc;
|
|
|
|
intptr_t notifyObj;
|
2010-07-14 09:47:17 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
bool capturedMouse;
|
2010-07-14 09:47:17 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
bool enteredSetScrollingSize;
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
bool GetPasteboardData(NSPasteboard *board, SelectionText *selectedText);
|
|
|
|
void SetPasteboardData(NSPasteboard *board, const SelectionText &selectedText);
|
|
|
|
Sci::Position TargetAsUTF8(char *text) const;
|
|
|
|
Sci::Position EncodedFromUTF8(const char *utf8, char *encoded) const;
|
2010-07-14 09:47:17 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
int scrollSpeed;
|
|
|
|
int scrollTicks;
|
|
|
|
CFRunLoopObserverRef observer;
|
2015-06-07 21:19:26 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
FindHighlightLayer *layerFindIndicator;
|
2013-08-28 00:44:27 +00:00
|
|
|
|
2010-07-14 09:47:17 +00:00
|
|
|
protected:
|
2019-05-04 18:14:48 +00:00
|
|
|
Point GetVisibleOriginInMain() const override;
|
|
|
|
PRectangle GetClientRectangle() const override;
|
|
|
|
PRectangle GetClientDrawingRectangle() override;
|
|
|
|
Point ConvertPoint(NSPoint point);
|
|
|
|
void RedrawRect(PRectangle rc) override;
|
|
|
|
void DiscardOverdraw() override;
|
|
|
|
void Redraw() override;
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
CaseFolder *CaseFolderForEncoding() override;
|
|
|
|
std::string CaseMapString(const std::string &s, int caseMapping) override;
|
|
|
|
void CancelModes() override;
|
2011-07-17 22:30:49 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
public:
|
2019-05-04 18:14:48 +00:00
|
|
|
ScintillaCocoa(ScintillaView *sciView_, SCIContentView *viewContent, SCIMarginView *viewMargin);
|
|
|
|
// Deleted so ScintillaCocoa objects can not be copied.
|
|
|
|
ScintillaCocoa(const ScintillaCocoa &) = delete;
|
|
|
|
ScintillaCocoa &operator=(const ScintillaCocoa &) = delete;
|
|
|
|
~ScintillaCocoa() override;
|
|
|
|
void Finalise() override;
|
|
|
|
|
|
|
|
void SetDelegate(id<ScintillaNotificationProtocol> delegate_);
|
|
|
|
void RegisterNotifyCallback(intptr_t windowid, SciNotifyFunc callback);
|
|
|
|
sptr_t WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) override;
|
|
|
|
|
|
|
|
NSScrollView *ScrollContainer() const;
|
|
|
|
SCIContentView *ContentView();
|
|
|
|
|
|
|
|
bool SyncPaint(void *gc, PRectangle rc);
|
|
|
|
bool Draw(NSRect rect, CGContextRef gc);
|
|
|
|
void PaintMargin(NSRect aRect);
|
|
|
|
|
|
|
|
sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) override;
|
|
|
|
void TickFor(TickReason reason) override;
|
|
|
|
bool FineTickerRunning(TickReason reason) override;
|
|
|
|
void FineTickerStart(TickReason reason, int millis, int tolerance) override;
|
|
|
|
void FineTickerCancel(TickReason reason) override;
|
|
|
|
bool SetIdle(bool on) override;
|
|
|
|
void SetMouseCapture(bool on) override;
|
|
|
|
bool HaveMouseCapture() override;
|
|
|
|
void WillDraw(NSRect rect);
|
|
|
|
void ScrollText(Sci::Line linesToMove) override;
|
|
|
|
void SetVerticalScrollPos() override;
|
|
|
|
void SetHorizontalScrollPos() override;
|
|
|
|
bool ModifyScrollBars(Sci::Line nMax, Sci::Line nPage) override;
|
|
|
|
bool SetScrollingSize(void);
|
|
|
|
void Resize();
|
|
|
|
void UpdateForScroll();
|
|
|
|
|
|
|
|
// Notifications for the owner.
|
|
|
|
void NotifyChange() override;
|
|
|
|
void NotifyFocus(bool focus) override;
|
|
|
|
void NotifyParent(SCNotification scn) override;
|
|
|
|
void NotifyURIDropped(const char *uri);
|
|
|
|
|
|
|
|
bool HasSelection();
|
|
|
|
bool CanUndo();
|
|
|
|
bool CanRedo();
|
|
|
|
void CopyToClipboard(const SelectionText &selectedText) override;
|
|
|
|
void Copy() override;
|
|
|
|
bool CanPaste() override;
|
|
|
|
void Paste() override;
|
|
|
|
void Paste(bool rectangular);
|
|
|
|
void CTPaint(void *gc, NSRect rc);
|
|
|
|
void CallTipMouseDown(NSPoint pt);
|
|
|
|
void CreateCallTipWindow(PRectangle rc) override;
|
|
|
|
void AddToPopUp(const char *label, int cmd = 0, bool enabled = true) override;
|
|
|
|
void ClaimSelection() override;
|
|
|
|
|
|
|
|
NSPoint GetCaretPosition();
|
|
|
|
|
|
|
|
static sptr_t DirectFunction(sptr_t ptr, unsigned int iMessage, uptr_t wParam, sptr_t lParam);
|
|
|
|
|
|
|
|
NSTimer *timers[tickPlatform+1];
|
|
|
|
void TimerFired(NSTimer *timer);
|
|
|
|
void IdleTimerFired();
|
|
|
|
static void UpdateObserver(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void *sci);
|
|
|
|
void ObserverAdd();
|
|
|
|
void ObserverRemove();
|
|
|
|
void IdleWork() override;
|
|
|
|
void QueueIdleWork(WorkNeeded::workItems items, Sci::Position upTo) override;
|
|
|
|
ptrdiff_t InsertText(NSString *input);
|
|
|
|
NSRange PositionsFromCharacters(NSRange rangeCharacters) const;
|
|
|
|
NSRange CharactersFromPositions(NSRange rangePositions) const;
|
|
|
|
NSString *RangeTextAsString(NSRange rangePositions) const;
|
|
|
|
NSInteger VisibleLineForIndex(NSInteger index);
|
|
|
|
NSRange RangeForVisibleLine(NSInteger lineVisible);
|
|
|
|
NSRect FrameForRange(NSRange rangeCharacters);
|
|
|
|
NSRect GetBounds() const;
|
|
|
|
void SelectOnlyMainSelection();
|
|
|
|
void ConvertSelectionVirtualSpace();
|
|
|
|
bool ClearAllSelections();
|
|
|
|
void CompositionStart();
|
|
|
|
void CompositionCommit();
|
|
|
|
void CompositionUndo();
|
|
|
|
void SetDocPointer(Document *document) override;
|
|
|
|
|
|
|
|
bool KeyboardInput(NSEvent *event);
|
|
|
|
void MouseDown(NSEvent *event);
|
|
|
|
void RightMouseDown(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() override;
|
|
|
|
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();
|
|
|
|
|
|
|
|
// Promote some methods needed for NSResponder actions.
|
|
|
|
void SelectAll() override;
|
|
|
|
void DeleteBackward();
|
|
|
|
void Cut() override;
|
|
|
|
void Undo() override;
|
|
|
|
void Redo() override;
|
|
|
|
|
|
|
|
bool ShouldDisplayPopupOnMargin();
|
|
|
|
bool ShouldDisplayPopupOnText();
|
|
|
|
NSMenu *CreateContextMenu(NSEvent *event);
|
|
|
|
void HandleCommand(NSInteger command);
|
|
|
|
|
|
|
|
void ActiveStateChanged(bool isActive);
|
|
|
|
void WindowWillMove();
|
|
|
|
|
|
|
|
// Find indicator
|
|
|
|
void ShowFindIndicatorForRange(NSRange charRange, BOOL retaining);
|
|
|
|
void MoveFindIndicatorWithBounce(BOOL bounce);
|
|
|
|
void HideFindIndicator();
|
2010-07-14 09:47:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|