2021-12-26 23:18:28 +08:00
/*
* Copyright ( C ) 2020 - 2022 Roy Qu ( royqh1979 @ gmail . com )
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https : //www.gnu.org/licenses/>.
*/
2021-05-14 23:56:43 +08:00
# ifndef SYNEDIT_H
# define SYNEDIT_H
# include <QAbstractScrollArea>
# include <QCursor>
# include <QDateTime>
# include <QFrame>
# include <QStringList>
# include <QTimer>
# include <QWidget>
# include "MiscClasses.h"
# include "CodeFolding.h"
# include "Types.h"
# include "TextBuffer.h"
# include "KeyStrokes.h"
2021-08-02 17:24:11 +08:00
# include "SearchBase.h"
2021-05-14 23:56:43 +08:00
enum class SynFontSmoothMethod {
None , AntiAlias , ClearType
} ;
enum class SynScrollHintFormat {
shfTopLineOnly , shfTopToBottom
} ;
enum class SynScrollStyle {
ssNone , ssHorizontal , ssVertical , ssBoth
} ;
enum class SynEditCaretType {
2021-06-07 11:02:03 +08:00
ctVerticalLine = 0 , ctHorizontalLine = 1 , ctHalfBlock = 2 , ctBlock = 3
2021-05-14 23:56:43 +08:00
} ;
2021-06-10 09:34:59 +08:00
enum SynStatusChange {
2021-05-14 23:56:43 +08:00
scNone = 0 ,
scAll = 0x0001 ,
scCaretX = 0x0002 ,
scCaretY = 0x0004 ,
scLeftChar = 0x0008 ,
scTopLine = 0x0010 ,
scInsertMode = 0x0020 ,
2021-11-04 00:38:40 +08:00
scModifyChanged = 0x0040 ,
2021-05-14 23:56:43 +08:00
scSelection = 0x0080 ,
scReadOnly = 0x0100 ,
2021-11-04 00:38:40 +08:00
scOpenFile = 0x0200 ,
scModified = 0x0400
2021-05-14 23:56:43 +08:00
} ;
Q_DECLARE_FLAGS ( SynStatusChanges , SynStatusChange )
Q_DECLARE_OPERATORS_FOR_FLAGS ( SynStatusChanges )
enum class SynStateFlag {
sfCaretChanged = 0x0001 ,
sfScrollbarChanged = 0x0002 ,
sfLinesChanging = 0x0004 ,
sfIgnoreNextChar = 0x0008 ,
sfCaretVisible = 0x0010 ,
sfDblClicked = 0x0020 ,
sfWaitForDragging = 0x0040
} ;
Q_DECLARE_FLAGS ( SynStateFlags , SynStateFlag )
Q_DECLARE_OPERATORS_FOR_FLAGS ( SynStateFlags )
enum SynEditorOption {
eoAltSetsColumnMode = 0x00000001 , //Holding down the Alt Key will put the selection mode into columnar format
2021-10-29 15:15:43 +08:00
eoAutoIndent = 0x00000002 , //Will auto calculate the indent when input
2022-01-10 20:16:26 +08:00
eoLigatureSupport = 0x00000004 , //Support ligaures in fonts like fira code
2021-06-08 21:41:42 +08:00
eoDragDropEditing = 0x00000008 , //Allows you to select a block of text and drag it within the document to another location
eoDropFiles = 0x00000010 , //Allows the editor accept OLE file drops
eoEnhanceHomeKey = 0x00000020 , //enhances home key positioning, similar to visual studio
eoEnhanceEndKey = 0x00000040 , //enhances End key positioning, similar to JDeveloper
eoGroupUndo = 0x00000080 , //When undoing/redoing actions, handle all continous changes of the same kind in one call instead undoing/redoing each command separately
eoHalfPageScroll = 0x00000100 , //When scrolling with page-up and page-down commands, only scroll a half page at a time
eoHideShowScrollbars = 0x00000200 , //if enabled, then the scrollbars will only show when necessary. If you have ScrollPastEOL, then it the horizontal bar will always be there (it uses MaxLength instead)
eoKeepCaretX = 0x00000400 , //When moving through lines w/o Cursor Past EOL, keeps the X position of the cursor
eoRightMouseMovesCursor = 0x00000800 , //When clicking with the right mouse for a popup menu, move the cursor to that location
eoScrollByOneLess = 0x00001000 , //Forces scrolling to be one less
eoScrollPastEof = 0x00002000 , //Allows the cursor to go past the end of file marker
eoScrollPastEol = 0x00004000 , //Allows the cursor to go past the last character into the white space at the end of a line
eoShowSpecialChars = 0x00008000 , //Shows the special Characters
2021-11-03 23:27:05 +08:00
// eoSpecialLineDefaultFg = 0x00010000, //disables the foreground text color override when using the OnSpecialLineColor event
2021-06-08 21:41:42 +08:00
eoTabIndent = 0x00020000 , //When active <Tab> and <Shift><Tab> act as block indent, unindent when text is selected
eoTabsToSpaces = 0x00040000 , //Converts a tab character to a specified number of space characters
eoShowRainbowColor = 0x00080000 ,
eoTrimTrailingSpaces = 0x00100000 , //Spaces at the end of lines will be trimmed and not saved
eoSelectWordByDblClick = 0x00200000 ,
2022-04-07 17:30:06 +08:00
// eoNoSelection = 0x00400000, //Disables selecting text
2021-06-08 21:41:42 +08:00
//eoAutoSizeMaxScrollWidth = 0x00000008, //Automatically resizes the MaxScrollWidth property when inserting text
//eoDisableScrollArrows = 0x00000010 , //Disables the scroll bar arrow buttons when you can't scroll in that direction any more
// eoScrollHintFollows = 0x00020000, //The scroll hint follows the mouse when scrolling vertically
// eoShowScrollHint = 0x00100000, //Shows a hint of the visible line numbers when scrolling vertically
// eoSmartTabDelete = 0x00400000, //similar to Smart Tabs, but when you delete characters
// eoSmartTabs = 0x00800000, //When tabbing, the cursor will go to the next non-white space character of the previous line
// eoNoCaret = 0x00000800, //Makes it so the caret is never visible
2021-05-14 23:56:43 +08:00
} ;
Q_DECLARE_FLAGS ( SynEditorOptions , SynEditorOption )
Q_DECLARE_OPERATORS_FOR_FLAGS ( SynEditorOptions )
2021-08-04 09:13:41 +08:00
enum class SynSearchAction {
Replace ,
ReplaceAll ,
Skip ,
Exit
2021-05-14 23:56:43 +08:00
} ;
enum class SynTransientType {
ttBefore , ttAfter
} ;
enum class SynScrollBarKind {
sbHorizontal , sbVertical
} ;
/*
using SynPaintTransientProc = std : : function < void ( const QPaintDevice & paintDevice ,
SynTransientType transientType ) > ;
*/
using SynPlaceMarkProc = std : : function < void ( PSynEditMark & Mark ) > ;
using SynProcessCommandProc = std : : function < void ( SynEditorCommand & command , QChar & AChar , void * data ) > ;
using SynMouseCursorProc = std : : function < void ( const BufferCoord & aLineCharPos , QCursor & aCursor ) > ;
using SynPaintProc = std : : function < void ( const QPaintDevice & paintDevice ) > ;
2021-08-28 09:01:40 +08:00
//using SynPreparePaintHighlightTokenProc = std::function<void(int row,
// int column, const QString& token, PSynHighlighterAttribute attr,
// SynFontStyles& style, QColor& foreground, QColor& background)>;
2021-08-04 09:13:41 +08:00
using SynSearchMathedProc = std : : function < SynSearchAction ( const QString & sSearch ,
const QString & sReplace , int Line , int ch , int wordLen ) > ;
2022-01-24 18:03:35 +08:00
using SynSearchConfirmAroundProc = std : : function < bool ( ) > ;
2021-05-14 23:56:43 +08:00
class SynEdit ;
using PSynEdit = std : : shared_ptr < SynEdit > ;
class SynEdit : public QAbstractScrollArea
{
Q_OBJECT
public :
2021-09-25 08:40:18 +08:00
explicit SynEdit ( QWidget * parent = nullptr ) ;
2021-05-24 00:41:00 +08:00
/**
2021-05-27 20:33:25 +08:00
* Returns how many rows are there in the editor
2021-05-24 00:41:00 +08:00
* @ return
*/
2021-06-08 21:41:42 +08:00
int displayLineCount ( ) const ;
2021-05-27 20:33:25 +08:00
/**
* @ brief displayX
* @ return
*/
2021-06-08 21:41:42 +08:00
DisplayCoord displayXY ( ) const ;
int displayX ( ) const ;
int displayY ( ) const ;
BufferCoord caretXY ( ) const ;
int caretX ( ) const ;
int caretY ( ) const ;
2021-05-14 23:56:43 +08:00
void invalidateGutter ( ) ;
void invalidateGutterLine ( int aLine ) ;
void invalidateGutterLines ( int FirstLine , int LastLine ) ;
2022-03-31 19:36:46 +08:00
DisplayCoord pixelsToNearestRowColumn ( int aX , int aY ) const ;
2021-06-08 21:41:42 +08:00
DisplayCoord pixelsToRowColumn ( int aX , int aY ) const ;
2021-09-20 15:57:48 +08:00
QPoint rowColumnToPixels ( const DisplayCoord & coord ) const ;
2021-06-08 21:41:42 +08:00
DisplayCoord bufferToDisplayPos ( const BufferCoord & p ) const ;
BufferCoord displayToBufferPos ( const DisplayCoord & p ) const ;
2021-09-20 15:57:48 +08:00
2021-09-20 23:33:53 +08:00
//normalized buffer coord operations
2021-09-25 08:40:18 +08:00
ContentsCoord fromBufferCoord ( const BufferCoord & p ) const ;
ContentsCoord createNormalizedBufferCoord ( int aChar , int aLine ) const ;
QStringList getContents ( const ContentsCoord & pStart , const ContentsCoord & pEnd ) ;
QString getJoinedContents ( const ContentsCoord & pStart , const ContentsCoord & pEnd , const QString & joinStr ) ;
2021-09-20 15:57:48 +08:00
2021-06-08 21:41:42 +08:00
int leftSpaces ( const QString & line ) const ;
QString GetLeftSpacing ( int charCount , bool wantTabs ) const ;
int charToColumn ( int aLine , int aChar ) const ;
int charToColumn ( const QString & s , int aChar ) const ;
int columnToChar ( int aLine , int aColumn ) const ;
int stringColumns ( const QString & line , int colsBefore ) const ;
int getLineIndent ( const QString & line ) const ;
int rowToLine ( int aRow ) const ;
int lineToRow ( int aLine ) const ;
int foldRowToLine ( int Row ) const ;
int foldLineToRow ( int Line ) const ;
2021-05-14 23:56:43 +08:00
void setDefaultKeystrokes ( ) ;
2022-04-16 20:14:47 +08:00
void setExtraKeystrokes ( ) ;
2021-05-14 23:56:43 +08:00
void invalidateLine ( int Line ) ;
void invalidateLines ( int FirstLine , int LastLine ) ;
void invalidateSelection ( ) ;
void invalidateRect ( const QRect & rect ) ;
void invalidate ( ) ;
void lockPainter ( ) ;
void unlockPainter ( ) ;
2021-06-08 21:41:42 +08:00
bool selAvail ( ) const ;
2022-03-25 12:59:53 +08:00
bool colSelAvail ( ) const ;
2021-09-20 15:57:48 +08:00
QString wordAtCursor ( ) ;
QString wordAtRowCol ( const BufferCoord & XY ) ;
2021-06-03 20:26:36 +08:00
2022-01-12 18:07:52 +08:00
QChar charAt ( const BufferCoord & pos ) ;
2022-04-13 16:42:23 +08:00
QChar nextNotspaceChar ( int line , int ch ) ;
2021-06-08 21:41:42 +08:00
int charColumns ( QChar ch ) const ;
2022-01-04 16:50:54 +08:00
2021-09-20 15:57:48 +08:00
bool isPointInSelection ( const BufferCoord & Value ) const ;
BufferCoord nextWordPos ( ) ;
BufferCoord nextWordPosEx ( const BufferCoord & XY ) ;
BufferCoord wordStart ( ) ;
BufferCoord wordStartEx ( const BufferCoord & XY ) ;
BufferCoord wordEnd ( ) ;
BufferCoord wordEndEx ( const BufferCoord & XY ) ;
BufferCoord prevWordPos ( ) ;
BufferCoord prevWordPosEx ( const BufferCoord & XY ) ;
void commandProcessor ( SynEditorCommand Command , QChar AChar = QChar ( ) , void * pData = nullptr ) ;
2021-06-03 20:26:36 +08:00
//Caret
void showCaret ( ) ;
void hideCaret ( ) ;
void setCaretX ( int value ) ;
void setCaretY ( int value ) ;
void setCaretXY ( const BufferCoord & value ) ;
2021-12-16 10:46:38 +08:00
void setCaretXYEx ( bool CallEnsureCursorPosVisible , BufferCoord value ) ;
void setCaretXYCentered ( const BufferCoord & value ) ;
2021-08-05 12:31:53 +08:00
void setCaretAndSelection ( const BufferCoord & ptCaret ,
const BufferCoord & ptBefore ,
const BufferCoord & ptAfter ) ;
2022-03-10 12:15:44 +08:00
bool inputMethodOn ( ) ;
2021-11-13 17:41:16 +08:00
void collapseAll ( ) ;
void unCollpaseAll ( ) ;
2021-06-24 16:05:19 +08:00
void uncollapseAroundLine ( int line ) ;
PSynEditFoldRange foldHidesLine ( int line ) ;
2021-08-26 17:48:23 +08:00
void setSelLength ( int Value ) ;
2021-10-06 23:35:45 +08:00
void setSelText ( const QString & text ) ;
2021-08-26 17:48:23 +08:00
2021-08-04 09:13:41 +08:00
int searchReplace ( const QString & sSearch , const QString & sReplace , SynSearchOptions options ,
2022-01-24 18:03:35 +08:00
PSynSearchBase searchEngine , SynSearchMathedProc matchedCallback = nullptr ,
SynSearchConfirmAroundProc confirmAroundCallback = nullptr ) ;
2021-08-02 17:24:11 +08:00
2021-06-08 21:41:42 +08:00
int maxScrollWidth ( ) const ;
int maxScrollHeight ( ) const ;
2021-09-20 15:57:48 +08:00
bool getHighlighterAttriAtRowCol ( const BufferCoord & XY , QString & Token ,
2021-06-03 20:26:36 +08:00
PSynHighlighterAttribute & Attri ) ;
2021-09-20 15:57:48 +08:00
bool getHighlighterAttriAtRowCol ( const BufferCoord & XY , QString & Token ,
2021-06-03 20:26:36 +08:00
bool & tokenFinished , SynHighlighterTokenType & TokenType ,
PSynHighlighterAttribute & Attri ) ;
2021-09-20 15:57:48 +08:00
bool getHighlighterAttriAtRowColEx ( const BufferCoord & XY , QString & Token ,
2021-06-03 20:26:36 +08:00
SynHighlighterTokenType & TokenType , SynTokenKind & TokenKind , int & Start ,
PSynHighlighterAttribute & Attri ) ;
2021-06-08 21:41:42 +08:00
2022-03-07 20:51:56 +08:00
void beginUndoBlock ( ) ;
void endUndoBlock ( ) ;
2021-06-03 20:26:36 +08:00
//Commands
2021-09-20 15:57:48 +08:00
virtual void cutToClipboard ( ) { commandProcessor ( SynEditorCommand : : ecCut ) ; }
virtual void copyToClipboard ( ) { commandProcessor ( SynEditorCommand : : ecCopy ) ; }
virtual void pasteFromClipboard ( ) { commandProcessor ( SynEditorCommand : : ecPaste ) ; }
virtual void undo ( ) { commandProcessor ( SynEditorCommand : : ecUndo ) ; }
virtual void redo ( ) { commandProcessor ( SynEditorCommand : : ecRedo ) ; }
virtual void zoomIn ( ) { commandProcessor ( SynEditorCommand : : ecZoomIn ) ; }
virtual void zoomOut ( ) { commandProcessor ( SynEditorCommand : : ecZoomOut ) ; }
virtual void selectAll ( ) { commandProcessor ( SynEditorCommand : : ecSelectAll ) ; }
virtual void tab ( ) { commandProcessor ( SynEditorCommand : : ecTab ) ; }
2021-10-06 23:35:45 +08:00
virtual void shifttab ( ) { commandProcessor ( SynEditorCommand : : ecShiftTab ) ; }
2021-09-20 15:57:48 +08:00
virtual void toggleComment ( ) { commandProcessor ( SynEditorCommand : : ecToggleComment ) ; }
2022-03-12 18:03:52 +08:00
virtual void toggleBlockComment ( ) { commandProcessor ( SynEditorCommand : : ecToggleBlockComment ) ; }
2022-03-13 18:45:48 +08:00
virtual void matchBracket ( ) { commandProcessor ( SynEditorCommand : : ecMatchBracket ) ; }
2022-04-01 23:10:38 +08:00
virtual void moveSelUp ( ) { commandProcessor ( SynEditorCommand : : ecMoveSelUp ) ; }
virtual void moveSelDown ( ) { commandProcessor ( SynEditorCommand : : ecMoveSelDown ) ; }
2021-06-03 20:26:36 +08:00
2021-06-22 23:00:34 +08:00
virtual void beginUpdate ( ) ;
virtual void endUpdate ( ) ;
virtual BufferCoord getMatchingBracket ( ) ;
virtual BufferCoord getMatchingBracketEx ( BufferCoord APoint ) ;
2021-10-05 21:25:23 +08:00
QStringList contents ( ) ;
2021-10-07 07:52:20 +08:00
QString text ( ) ;
2021-10-05 21:25:23 +08:00
2021-09-20 15:57:48 +08:00
bool getPositionOfMouse ( BufferCoord & aPos ) ;
bool getLineOfMouse ( int & line ) ;
bool pointToCharLine ( const QPoint & point , BufferCoord & coord ) ;
bool pointToLine ( const QPoint & point , int & line ) ;
2021-09-03 16:39:20 +08:00
bool isIdentChar ( const QChar & ch ) ;
2021-08-29 17:23:40 +08:00
2021-09-19 17:59:03 +08:00
void setRainbowAttrs ( const PSynHighlighterAttribute & attr0 ,
const PSynHighlighterAttribute & attr1 ,
const PSynHighlighterAttribute & attr2 ,
const PSynHighlighterAttribute & attr3 ) ;
2021-09-27 00:52:25 +08:00
void updateMouseCursor ( ) ;
2021-12-13 16:38:22 +08:00
2022-03-18 23:13:43 +08:00
bool isCaretVisible ( ) ;
2021-12-13 19:10:16 +08:00
// setter && getters
2021-05-14 23:56:43 +08:00
int topLine ( ) const ;
void setTopLine ( int value ) ;
int linesInWindow ( ) const ;
int leftChar ( ) const ;
void setLeftChar ( int Value ) ;
BufferCoord blockBegin ( ) const ;
BufferCoord blockEnd ( ) const ;
2021-08-26 17:48:23 +08:00
void setBlockBegin ( BufferCoord value ) ;
void setBlockEnd ( BufferCoord Value ) ;
2021-05-14 23:56:43 +08:00
SynSelectionMode activeSelectionMode ( ) const ;
void setActiveSelectionMode ( const SynSelectionMode & Value ) ;
int charsInWindow ( ) const ;
int charWidth ( ) const ;
2022-03-20 18:10:53 +08:00
void setUndoLimit ( int size ) ;
2021-05-14 23:56:43 +08:00
int gutterWidth ( ) const ;
void setGutterWidth ( int value ) ;
bool modified ( ) const ;
void setModified ( bool Value ) ;
2021-05-27 20:33:25 +08:00
PSynHighlighter highlighter ( ) const ;
void setHighlighter ( const PSynHighlighter & highlighter ) ;
bool useCodeFolding ( ) const ;
void setUseCodeFolding ( bool value ) ;
2021-09-20 16:03:24 +08:00
SynEditCodeFolding & codeFolding ( ) ;
2021-06-24 22:33:57 +08:00
2021-09-20 15:57:48 +08:00
QString lineText ( ) const ;
2021-05-27 20:33:25 +08:00
void setLineText ( const QString s ) ;
2022-04-19 21:18:41 +08:00
const PSynDocument & document ( ) const ;
2021-05-24 00:41:00 +08:00
bool empty ( ) ;
2021-05-27 23:45:22 +08:00
SynSelectionMode selectionMode ( ) const ;
void setSelectionMode ( SynSelectionMode value ) ;
2021-05-29 21:35:46 +08:00
QString selText ( ) ;
QString lineBreak ( ) ;
2021-06-07 11:02:03 +08:00
SynEditorOptions getOptions ( ) const ;
void setOptions ( const SynEditorOptions & Value ) ;
2022-04-19 21:18:41 +08:00
int tabWidth ( ) const { return mDocument - > tabWidth ( ) ; }
2021-06-07 11:02:03 +08:00
void setTabWidth ( int tabWidth ) ;
2021-06-12 22:36:23 +08:00
QColor caretColor ( ) const ;
2021-06-07 11:02:03 +08:00
void setCaretColor ( const QColor & caretColor ) ;
2021-06-12 22:36:23 +08:00
QColor activeLineColor ( ) const ;
2021-06-07 11:02:03 +08:00
void setActiveLineColor ( const QColor & activeLineColor ) ;
2021-06-12 22:36:23 +08:00
SynEditCaretType overwriteCaret ( ) const ;
2021-06-07 11:02:03 +08:00
void setOverwriteCaret ( const SynEditCaretType & overwriteCaret ) ;
2021-06-12 22:36:23 +08:00
SynEditCaretType insertCaret ( ) const ;
2021-06-07 11:02:03 +08:00
void setInsertCaret ( const SynEditCaretType & insertCaret ) ;
2021-06-09 17:12:23 +08:00
SynGutter & gutter ( ) ;
2021-06-12 22:36:23 +08:00
bool readOnly ( ) const ;
void setReadOnly ( bool readOnly ) ;
void setInsertMode ( bool value ) ;
bool insertMode ( ) const ;
bool canUndo ( ) const ;
bool canRedo ( ) const ;
2021-06-24 16:05:19 +08:00
int textHeight ( ) const ;
2021-08-28 09:01:40 +08:00
const QColor & selectedForeground ( ) const ;
void setSelectedForeground ( const QColor & newSelectedForeground ) ;
const QColor & selectedBackground ( ) const ;
void setSelectedBackground ( const QColor & newSelectedBackground ) ;
2021-09-04 00:13:42 +08:00
int rightEdge ( ) const ;
void setRightEdge ( int newRightEdge ) ;
const QColor & rightEdgeColor ( ) const ;
void setRightEdgeColor ( const QColor & newRightEdgeColor ) ;
2021-09-15 14:35:37 +08:00
bool caretUseTextColor ( ) const ;
void setCaretUseTextColor ( bool newCaretUseTextColor ) ;
2021-09-19 17:59:03 +08:00
const PSynHighlighterAttribute & rainbowAttr0 ( ) const ;
const PSynHighlighterAttribute & rainbowAttr1 ( ) const ;
const PSynHighlighterAttribute & rainbowAttr2 ( ) const ;
const PSynHighlighterAttribute & rainbowAttr3 ( ) const ;
2021-10-20 12:27:44 +08:00
int mouseWheelScrollSpeed ( ) const ;
void setMouseWheelScrollSpeed ( int newMouseWheelScrollSpeed ) ;
2021-11-03 18:09:12 +08:00
const QColor & foregroundColor ( ) const ;
void setForegroundColor ( const QColor & newForegroundColor ) ;
const QColor & backgroundColor ( ) const ;
void setBackgroundColor ( const QColor & newBackgroundColor ) ;
2021-05-14 23:56:43 +08:00
signals :
2021-09-02 12:14:02 +08:00
void linesDeleted ( int FirstLine , int Count ) ;
void linesInserted ( int FirstLine , int Count ) ;
2021-09-20 15:57:48 +08:00
void changed ( ) ;
2021-05-14 23:56:43 +08:00
2021-09-20 15:57:48 +08:00
// void chainUndoAdded();
// void chainRedoAdded();
// void chainLinesChanging();
// void chainLinesChanged();
// void chainListCleared();
2021-05-14 23:56:43 +08:00
2021-09-20 15:57:48 +08:00
// void chainListDeleted(int Index, int Count);
// void chainListInserted(int Index, int Count);
// void chainListPutted(int Index, int Count);
2021-05-14 23:56:43 +08:00
2021-09-20 15:57:48 +08:00
// void filesDropped(int X,int Y, const QStringList& AFiles);
2021-06-09 17:12:23 +08:00
void gutterClicked ( Qt : : MouseButton button , int x , int y , int line ) ;
2021-09-20 15:57:48 +08:00
// void imeInputed(const QString& s);
2021-05-14 23:56:43 +08:00
2021-09-20 15:57:48 +08:00
// void contextHelp(const QString& word);
2021-05-14 23:56:43 +08:00
2021-09-20 15:57:48 +08:00
// void scrolled(SynScrollBarKind ScrollBar);
2021-05-14 23:56:43 +08:00
void statusChanged ( SynStatusChanges changes ) ;
2021-05-18 15:49:58 +08:00
void fontChanged ( ) ;
void tabSizeChanged ( ) ;
2021-05-21 23:33:53 +08:00
protected :
2021-05-24 00:41:00 +08:00
virtual bool onGetSpecialLineColors ( int Line ,
2021-05-21 23:33:53 +08:00
QColor & foreground , QColor & backgroundColor ) ;
2021-05-24 00:41:00 +08:00
virtual void onGetEditingAreas ( int Line , SynEditingAreaList & areaList ) ;
2021-05-21 23:33:53 +08:00
virtual void onGutterGetText ( int aLine , QString & aText ) ;
2021-05-24 00:41:00 +08:00
virtual void onGutterPaint ( QPainter & painter , int aLine , int X , int Y ) ;
virtual void onPaint ( QPainter & painter ) ;
2021-08-29 22:51:23 +08:00
virtual void onPreparePaintHighlightToken ( int line ,
int aChar , const QString & token , PSynHighlighterAttribute attr ,
2021-08-28 09:01:40 +08:00
SynFontStyles & style , QColor & foreground , QColor & background ) ;
2021-05-27 20:33:25 +08:00
virtual void onProcessCommand ( SynEditorCommand Command , QChar AChar , void * pData ) ;
virtual void onCommandProcessed ( SynEditorCommand Command , QChar AChar , void * pData ) ;
virtual void ExecuteCommand ( SynEditorCommand Command , QChar AChar , void * pData ) ;
2021-10-04 11:07:35 +08:00
virtual void onEndFirstPaintLock ( ) ;
virtual void onBeginFirstPaintLock ( ) ;
2021-05-24 00:41:00 +08:00
2021-05-14 23:56:43 +08:00
private :
void clearAreaList ( SynEditingAreaList areaList ) ;
2022-03-07 20:30:45 +08:00
void computeCaret ( ) ;
void computeScroll ( bool isDragging ) ;
2021-05-14 23:56:43 +08:00
void incPaintLock ( ) ;
void decPaintLock ( ) ;
int clientWidth ( ) ;
int clientHeight ( ) ;
int clientTop ( ) ;
int clientLeft ( ) ;
QRect clientRect ( ) ;
void synFontChanged ( ) ;
void doOnPaintTransient ( SynTransientType TransientType ) ;
2021-10-06 23:35:45 +08:00
void doSetSelText ( const QString & Value ) ;
2021-05-14 23:56:43 +08:00
void updateLastCaretX ( ) ;
void ensureCursorPosVisible ( ) ;
void ensureCursorPosVisibleEx ( bool ForceToMiddle ) ;
void scrollWindow ( int dx , int dy ) ;
void setInternalDisplayXY ( const DisplayCoord & aPos ) ;
void internalSetCaretXY ( const BufferCoord & Value ) ;
2021-05-29 21:35:46 +08:00
void internalSetCaretX ( int Value ) ;
void internalSetCaretY ( int Value ) ;
2021-05-14 23:56:43 +08:00
void setStatusChanged ( SynStatusChanges changes ) ;
void doOnStatusChange ( SynStatusChanges changes ) ;
void insertBlock ( const BufferCoord & BB , const BufferCoord & BE , const QString & ChangeStr ,
bool AddToUndoList ) ;
void updateScrollbars ( ) ;
void updateCaret ( ) ;
void recalcCharExtent ( ) ;
QString expandAtWideGlyphs ( const QString & S ) ;
void updateModifiedStatus ( ) ;
2021-09-23 12:06:26 +08:00
int scanFrom ( int Index , int canStopIndex ) ;
2021-10-29 15:15:43 +08:00
void rescanRange ( int line ) ;
void rescanRanges ( ) ;
2021-05-14 23:56:43 +08:00
void uncollapse ( PSynEditFoldRange FoldRange ) ;
2021-06-09 17:12:23 +08:00
void collapse ( PSynEditFoldRange FoldRange ) ;
2021-05-14 23:56:43 +08:00
void foldOnListInserted ( int Line , int Count ) ;
void foldOnListDeleted ( int Line , int Count ) ;
void foldOnListCleared ( ) ;
2021-10-29 15:15:43 +08:00
void rescanFolds ( ) ; // rescan for folds
2021-05-14 23:56:43 +08:00
void rescanForFoldRanges ( ) ;
void scanForFoldRanges ( PSynEditFoldRanges TopFoldRanges ) ;
int lineHasChar ( int Line , int startChar , QChar character , const QString & highlighterAttrName ) ;
2021-05-27 01:05:49 +08:00
void findSubFoldRange ( PSynEditFoldRanges TopFoldRanges , int FoldIndex , PSynEditFoldRanges & parentFoldRanges , PSynEditFoldRange Parent ) ;
2021-05-14 23:56:43 +08:00
PSynEditFoldRange collapsedFoldStartAtLine ( int Line ) ;
void doOnPaintTransientEx ( SynTransientType TransientType , bool Lock ) ;
void initializeCaret ( ) ;
2021-05-21 23:33:53 +08:00
PSynEditFoldRange foldStartAtLine ( int Line ) ;
QString substringByColumns ( const QString & s , int startColumn , int & colLen ) ;
PSynEditFoldRange foldAroundLine ( int Line ) ;
PSynEditFoldRange foldAroundLineEx ( int Line , bool WantCollapsed , bool AcceptFromLine , bool AcceptToLine ) ;
2021-05-24 00:41:00 +08:00
PSynEditFoldRange checkFoldRange ( SynEditFoldRanges * FoldRangeToCheck , int Line , bool WantCollapsed , bool AcceptFromLine , bool AcceptToLine ) ;
PSynEditFoldRange foldEndAtLine ( int Line ) ;
void paintCaret ( QPainter & painter , const QRect rcClip ) ;
2021-06-08 21:41:42 +08:00
int textOffset ( ) const ;
2021-05-27 20:33:25 +08:00
SynEditorCommand TranslateKeyCode ( int key , Qt : : KeyboardModifiers modifiers ) ;
/**
* Move the caret to right DX columns
* @ param DX
* @ param SelectionCommand
*/
2021-09-20 15:57:48 +08:00
void moveCaretHorz ( int DX , bool isSelection ) ;
void moveCaretVert ( int DY , bool isSelection ) ;
void moveCaretAndSelection ( const BufferCoord & ptBefore , const BufferCoord & ptAfter ,
2021-05-27 20:33:25 +08:00
bool isSelection ) ;
2021-09-20 15:57:48 +08:00
void moveCaretToLineStart ( bool isSelection ) ;
void moveCaretToLineEnd ( bool isSelection ) ;
void setSelectedTextEmpty ( ) ;
void setSelTextPrimitive ( const QString & aValue ) ;
void setSelTextPrimitiveEx ( SynSelectionMode PasteMode ,
2021-05-29 21:35:46 +08:00
const QString & Value , bool AddToUndoList ) ;
2021-09-02 12:14:02 +08:00
void doLinesDeleted ( int FirstLine , int Count ) ;
void doLinesInserted ( int FirstLine , int Count ) ;
2021-11-13 13:03:42 +08:00
void properSetLine ( int ALine , const QString & ALineText , bool notify = true ) ;
2021-09-20 15:57:48 +08:00
void deleteSelection ( const BufferCoord & BB , const BufferCoord & BE ) ;
void insertText ( const QString & Value , SynSelectionMode PasteMode , bool AddToUndoList ) ;
int insertTextByNormalMode ( const QString & Value ) ;
int insertTextByColumnMode ( const QString & Value , bool AddToUndoList ) ;
int insertTextByLineMode ( const QString & Value ) ;
void deleteFromTo ( const BufferCoord & start , const BufferCoord & end ) ;
void setSelWord ( ) ;
void setWordBlock ( BufferCoord Value ) ;
2021-08-05 12:31:53 +08:00
2021-12-20 08:45:16 +08:00
2021-10-28 09:20:58 +08:00
int calcIndentSpaces ( int line , const QString & lineText , bool addIndent ) ;
2021-12-20 08:45:16 +08:00
int findCommentStartLine ( int searchStartLine ) ;
int findStatementStartLine ( int searchStartLine ) ;
2021-10-28 08:56:13 +08:00
2021-06-09 17:12:23 +08:00
void processGutterClick ( QMouseEvent * event ) ;
2021-06-03 20:26:36 +08:00
void clearUndo ( ) ;
2021-10-30 18:28:40 +08:00
int findIndentsStartLine ( int line , QVector < int > indents ) ;
BufferCoord getPreviousLeftBrace ( int x , int y ) ;
2021-09-20 15:57:48 +08:00
bool canDoBlockIndent ( ) ;
2021-06-03 20:26:36 +08:00
2021-11-08 21:19:48 +08:00
QRect calculateCaretRect ( ) const ;
QRect calculateInputCaretRect ( ) const ;
2021-10-05 00:42:35 +08:00
2021-06-03 20:26:36 +08:00
//Commands
2021-06-07 11:02:03 +08:00
void doDeleteLastChar ( ) ;
void doDeleteCurrentChar ( ) ;
void doDeleteWord ( ) ;
void doDeleteToEOL ( ) ;
2022-01-24 11:23:30 +08:00
void doDeleteToWordStart ( ) ;
void doDeleteToWordEnd ( ) ;
2021-06-07 11:02:03 +08:00
void doDeleteFromBOL ( ) ;
void doDeleteLine ( ) ;
2022-01-10 18:37:00 +08:00
void doSelecteLine ( ) ;
2021-06-07 11:02:03 +08:00
void doDuplicateLine ( ) ;
2022-04-01 23:10:38 +08:00
void doMoveSelUp ( bool addUndo = true ) ;
void doMoveSelDown ( bool addUndo = true ) ;
2021-06-07 11:02:03 +08:00
void clearAll ( ) ;
void insertLine ( bool moveCaret ) ;
void doTabKey ( ) ;
void doShiftTabKey ( ) ;
2021-06-03 20:26:36 +08:00
void doBlockIndent ( ) ;
void doBlockUnindent ( ) ;
2021-06-07 11:02:03 +08:00
void doAddChar ( QChar AChar ) ;
void doCutToClipboard ( ) ;
void doCopyToClipboard ( ) ;
void internalDoCopyToClipboard ( const QString & s ) ;
void doPasteFromClipboard ( ) ;
void doAddStr ( const QString & s ) ;
void doUndo ( ) ;
void doUndoItem ( ) ;
void doRedo ( ) ;
void doRedoItem ( ) ;
void doZoomIn ( ) ;
void doZoomOut ( ) ;
void doSelectAll ( ) ;
2021-06-21 11:21:26 +08:00
void doComment ( ) ;
void doUncomment ( ) ;
void doToggleComment ( ) ;
2022-03-12 18:03:52 +08:00
void doToggleBlockComment ( ) ;
2021-11-26 19:04:04 +08:00
void doMouseScroll ( bool isDragging ) ;
2021-06-03 20:26:36 +08:00
2021-05-14 23:56:43 +08:00
private slots :
2021-09-02 12:14:02 +08:00
void onBookMarkOptionsChanged ( ) ;
void onGutterChanged ( ) ;
void onLinesChanged ( ) ;
void onLinesChanging ( ) ;
void onLinesCleared ( ) ;
void onLinesDeleted ( int index , int count ) ;
void onLinesInserted ( int index , int count ) ;
void onLinesPutted ( int index , int count ) ;
void onRedoAdded ( ) ;
void onScrollTimeout ( ) ;
2021-11-26 19:04:04 +08:00
void onDraggingScrollTimeout ( ) ;
2021-09-02 12:14:02 +08:00
void onUndoAdded ( ) ;
void onSizeOrFontChanged ( bool bFont ) ;
void onChanged ( ) ;
void onScrolled ( int value ) ;
2021-05-14 23:56:43 +08:00
private :
2021-05-24 00:41:00 +08:00
std : : shared_ptr < QImage > mContentImage ;
2021-05-14 23:56:43 +08:00
SynEditFoldRanges mAllFoldRanges ;
SynEditCodeFolding mCodeFolding ;
bool mUseCodeFolding ;
bool mAlwaysShowCaret ;
BufferCoord mBlockBegin ;
BufferCoord mBlockEnd ;
int mCaretX ;
2021-06-03 23:18:51 +08:00
int mLastCaretColumn ;
2021-05-14 23:56:43 +08:00
int mCaretY ;
int mCharsInWindow ;
int mCharWidth ;
QFont mFontDummy ;
2022-01-26 14:31:26 +08:00
QFont mFontForNonAscii ;
2021-05-14 23:56:43 +08:00
SynFontSmoothMethod mFontSmoothing ;
bool mMouseMoved ;
2022-03-10 12:15:44 +08:00
2021-05-14 23:56:43 +08:00
bool mInserting ;
bool mPainting ;
2022-04-19 21:18:41 +08:00
PSynDocument mDocument ;
PSynDocument mOrigLines ;
2021-05-14 23:56:43 +08:00
PSynEditUndoList mOrigUndoList ;
PSynEditUndoList mOrigRedoList ;
int mLinesInWindow ;
int mLeftChar ;
int mPaintLock ; // lock counter for internal calculations
bool mReadOnly ;
int mRightEdge ;
QColor mRightEdgeColor ;
QColor mScrollHintColor ;
SynScrollHintFormat mScrollHintFormat ;
SynScrollStyle mScrollBars ;
int mTextHeight ;
int mTopLine ;
PSynHighlighter mHighlighter ;
QColor mSelectedForeground ;
QColor mSelectedBackground ;
2021-11-03 18:09:12 +08:00
QColor mForegroundColor ;
QColor mBackgroundColor ;
2021-05-24 18:11:07 +08:00
QColor mCaretColor ;
2021-09-19 17:59:03 +08:00
PSynHighlighterAttribute mRainbowAttr0 ;
PSynHighlighterAttribute mRainbowAttr1 ;
PSynHighlighterAttribute mRainbowAttr2 ;
PSynHighlighterAttribute mRainbowAttr3 ;
2021-09-15 14:35:37 +08:00
bool mCaretUseTextColor ;
2021-05-14 23:56:43 +08:00
QColor mActiveLineColor ;
PSynEditUndoList mUndoList ;
PSynEditUndoList mRedoList ;
SynEditMarkList mBookMarks ;
2021-05-29 21:35:46 +08:00
QPoint mMouseDownPos ;
2021-05-14 23:56:43 +08:00
SynBookMarkOpt mBookMarkOpt ;
bool mHideSelection ;
int mMouseWheelAccumulator ;
SynEditCaretType mOverwriteCaret ;
SynEditCaretType mInsertCaret ;
QPoint mCaretOffset ;
SynEditKeyStrokes mKeyStrokes ;
bool mModified ;
QDateTime mLastModifyTime ;
SynEditMarkList mMarkList ;
int mExtraLineSpacing ;
SynSelectionMode mSelectionMode ;
SynSelectionMode mActiveSelectionMode ; //mode of the active selection
bool mWantReturns ;
bool mWantTabs ;
SynGutter mGutter ;
QRect mInvalidateRect ;
SynStateFlags mStateFlags ;
SynEditorOptions mOptions ;
SynStatusChanges mStatusChanges ;
int mLastKey ;
Qt : : KeyboardModifiers mLastKeyModifiers ;
//fSearchEngine: TSynEditSearchCustom;
//fHookedCommandHandlers: TList;
//fKbdHandler: TSynEditKbdHandler;
// fFocusList: TList;
// fPlugins: TList;
QTimer * mScrollTimer ;
int mScrollDeltaX ;
int mScrollDeltaY ;
PSynEdit fChainedEditor ;
int mPaintTransientLock ;
bool mIsScrolling ;
int mPainterLock ; // lock counter to prevent repaint while painting
bool mUndoing ;
// event handlers
SynPlaceMarkProc mOnClearMark ;
SynProcessCommandProc mOnCommandProcessed ;
SynMouseCursorProc mOnMouseCursor ;
SynPaintProc mOnPaint ;
2021-08-28 09:01:40 +08:00
// SynPreparePaintHighlightTokenProc mOnPaintHighlightToken;
2021-05-14 23:56:43 +08:00
SynPlaceMarkProc mOnPlaceMark ;
SynProcessCommandProc mOnProcessingCommand ;
SynProcessCommandProc mOnProcessingUserCommand ;
2021-05-21 23:33:53 +08:00
// SynSpecialLineColorsProc mOnSpecialLineColors;
// SynEditingAreasProc mOnEditingAreas;
// SynGutterGetTextProc mOnGutterGetText;
// SynTGutterPaintProc mOnGutterPaint;
2021-05-14 23:56:43 +08:00
int mGutterWidth ;
//caret blink related
int m_blinkTimerId ;
2021-05-24 18:11:07 +08:00
int m_blinkStatus ;
2021-05-14 23:56:43 +08:00
2021-06-07 11:02:03 +08:00
QCursor mDefaultCursor ;
2021-10-05 00:42:35 +08:00
QString mInputPreeditString ;
2021-10-20 12:27:44 +08:00
int mMouseWheelScrollSpeed ;
2022-03-04 19:04:45 +08:00
int mMouseSelectionScrollSpeed ;
2021-10-20 12:27:44 +08:00
2021-11-13 12:33:33 +08:00
BufferCoord mDragCaretSave ;
BufferCoord mDragSelBeginSave ;
BufferCoord mDragSelEndSave ;
2022-03-12 18:03:52 +08:00
bool mDropped ;
2021-11-13 12:33:33 +08:00
2021-05-14 23:56:43 +08:00
friend class SynEditTextPainter ;
2021-05-24 00:41:00 +08:00
// QWidget interface
protected :
2022-04-19 21:18:41 +08:00
void paintEvent ( QPaintEvent * event ) override ;
void resizeEvent ( QResizeEvent * event ) override ;
void timerEvent ( QTimerEvent * event ) override ;
bool event ( QEvent * event ) override ;
void focusInEvent ( QFocusEvent * event ) override ;
void focusOutEvent ( QFocusEvent * event ) override ;
void keyPressEvent ( QKeyEvent * event ) override ;
void mousePressEvent ( QMouseEvent * event ) override ;
void mouseReleaseEvent ( QMouseEvent * event ) override ;
void mouseMoveEvent ( QMouseEvent * event ) override ;
void mouseDoubleClickEvent ( QMouseEvent * event ) override ;
void inputMethodEvent ( QInputMethodEvent * event ) override ;
void leaveEvent ( QEvent * event ) override ;
void wheelEvent ( QWheelEvent * event ) override ;
2021-06-07 21:34:48 +08:00
// QAbstractScrollArea interface
protected :
2022-04-19 21:18:41 +08:00
bool viewportEvent ( QEvent * event ) override ;
2021-11-08 21:19:48 +08:00
2022-04-19 21:18:41 +08:00
// QWidget interface
public :
QVariant inputMethodQuery ( Qt : : InputMethodQuery property ) const override ;
2021-11-13 12:33:33 +08:00
2022-04-19 21:18:41 +08:00
// QWidget interface
const QFont & fontForNonAscii ( ) const ;
void setFontForNonAscii ( const QFont & newFontForNonAscii ) ;
2022-01-26 14:31:26 +08:00
2022-04-19 21:18:41 +08:00
int mouseSelectionScrollSpeed ( ) const ;
void setMouseSelectionScrollSpeed ( int newMouseSelectionScrollSpeed ) ;
2022-03-04 19:04:45 +08:00
2021-11-13 12:33:33 +08:00
protected :
2022-04-19 21:18:41 +08:00
void dragEnterEvent ( QDragEnterEvent * event ) override ;
void dropEvent ( QDropEvent * event ) override ;
void dragMoveEvent ( QDragMoveEvent * event ) override ;
void dragLeaveEvent ( QDragLeaveEvent * event ) override ;
2021-05-14 23:56:43 +08:00
} ;
# endif // SYNEDIT_H