Upgrade Scintilla - Adaptation of PowerEditor part

This commit is contained in:
Don HO 2019-05-08 11:13:21 +02:00
parent 2d90b38795
commit d22d1609ab
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
11 changed files with 61 additions and 52 deletions

View File

@ -72,6 +72,14 @@ bool SecurityGard::checkModule(const std::wstring& filePath, NppModule module2ch
bool SecurityGard::checkSha256(const std::wstring& filePath, NppModule module2check) bool SecurityGard::checkSha256(const std::wstring& filePath, NppModule module2check)
{ {
// Uncomment the following code if the components are rebuilt for testing
// It should be stay in commenting out
/*
bool dontCheck = true;
if (dontCheck)
return true;
*/
std::string content = getFileContent(filePath.c_str()); std::string content = getFileContent(filePath.c_str());
uint8_t sha2hash[32]; uint8_t sha2hash[32];
calc_sha_256(sha2hash, reinterpret_cast<const uint8_t*>(content.c_str()), content.length()); calc_sha_256(sha2hash, reinterpret_cast<const uint8_t*>(content.c_str()), content.length());

View File

@ -349,7 +349,7 @@ private:
bool _isFolding = false; bool _isFolding = false;
//For Dynamic selection highlight //For Dynamic selection highlight
CharacterRange _prevSelectedRange; Sci_CharacterRange _prevSelectedRange;
//Synchronized Scolling //Synchronized Scolling
struct SyncInfo final struct SyncInfo final

View File

@ -612,7 +612,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
{ {
if ((notification->nmhdr.hwndFrom == _mainEditView.getHSelf()) || (notification->nmhdr.hwndFrom == _subEditView.getHSelf())) if ((notification->nmhdr.hwndFrom == _mainEditView.getHSelf()) || (notification->nmhdr.hwndFrom == _subEditView.getHSelf()))
{ {
int lineClicked = notification->line; size_t lineClicked = notification->line;
if (!_isFolding) if (!_isFolding)
{ {
@ -997,21 +997,21 @@ BOOL Notepad_plus::notify(SCNotification *notification)
if (not notifyView->execute(SCI_STYLEGETHOTSPOT, style)) if (not notifyView->execute(SCI_STYLEGETHOTSPOT, style))
break; break;
int startPos, endPos, docLen; long long startPos, endPos, docLen;
startPos = endPos = notification->position; startPos = endPos = notification->position;
docLen = notifyView->getCurrentDocLen(); docLen = notifyView->getCurrentDocLen();
// Walk backwards/forwards to get the contiguous text in the same style // Walk backwards/forwards to get the contiguous text in the same style
while (startPos > 0 && static_cast<uint8_t>(notifyView->execute(SCI_GETSTYLEAT, startPos - 1)) == style) while (startPos > 0 && static_cast<uint8_t>(notifyView->execute(SCI_GETSTYLEAT, static_cast<WPARAM>(startPos - 1))) == style)
startPos--; startPos--;
while (endPos < docLen && static_cast<uint8_t>(notifyView->execute(SCI_GETSTYLEAT, endPos)) == style) while (endPos < docLen && static_cast<uint8_t>(notifyView->execute(SCI_GETSTYLEAT, static_cast<WPARAM>(endPos))) == style)
endPos++; endPos++;
// Select the entire link // Select the entire link
notifyView->execute(SCI_SETANCHOR, startPos); notifyView->execute(SCI_SETANCHOR, static_cast<WPARAM>(startPos));
notifyView->execute(SCI_SETCURRENTPOS, endPos); notifyView->execute(SCI_SETCURRENTPOS, static_cast<WPARAM>(endPos));
generic_string url = notifyView->getGenericTextAsString(startPos, endPos); generic_string url = notifyView->getGenericTextAsString(static_cast<size_t>(startPos), static_cast<size_t>(endPos));
// remove the flickering: it seems a mouse left button up is missing after SCN_HOTSPOTDOUBLECLICK // remove the flickering: it seems a mouse left button up is missing after SCN_HOTSPOTDOUBLECLICK
::PostMessage(notifyView->getHSelf(), WM_LBUTTONUP, 0, 0); ::PostMessage(notifyView->getHSelf(), WM_LBUTTONUP, 0, 0);

View File

@ -749,7 +749,7 @@ void AutoCompletion::update(int character)
} }
} }
void AutoCompletion::callTipClick(int direction) { void AutoCompletion::callTipClick(size_t direction) {
if (!_funcCompletionActive) if (!_funcCompletionActive)
return; return;

View File

@ -80,7 +80,7 @@ public:
void insertMatchedChars(int character, const MatchedPairConf & matchedPairConf); void insertMatchedChars(int character, const MatchedPairConf & matchedPairConf);
void update(int character); void update(int character);
void callTipClick(int direction); void callTipClick(size_t direction);
void getCloseTag(char *closeTag, size_t closeTagLen, size_t caretPos, bool isHTML); void getCloseTag(char *closeTag, size_t closeTagLen, size_t caretPos, bool isHTML);
private: private:

View File

@ -467,7 +467,7 @@ bool Finder::notify(SCNotification *notification)
{ {
// remove selection from the finder // remove selection from the finder
isDoubleClicked = true; isDoubleClicked = true;
int pos = notification->position; size_t pos = notification->position;
if (pos == INVALID_POSITION) if (pos == INVALID_POSITION)
pos = static_cast<int32_t>(_scintView.execute(SCI_GETLINEENDPOSITION, notification->line)); pos = static_cast<int32_t>(_scintView.execute(SCI_GETLINEENDPOSITION, notification->line));
_scintView.execute(SCI_SETSEL, pos, pos); _scintView.execute(SCI_SETSEL, pos, pos);
@ -905,7 +905,7 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
{ {
if (LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE) if (LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE)
{ {
CharacterRange cr = (*_ppEditView)->getSelection(); Sci_CharacterRange cr = (*_ppEditView)->getSelection();
int nbSelected = cr.cpMax - cr.cpMin; int nbSelected = cr.cpMax - cr.cpMin;
_options._isInSelection = isCheckedOrNot(IDC_IN_SELECTION_CHECK)?1:0; _options._isInSelection = isCheckedOrNot(IDC_IN_SELECTION_CHECK)?1:0;
@ -1532,7 +1532,7 @@ bool FindReplaceDlg::processFindNext(const TCHAR *txt2find, const FindOption *op
} }
int docLength = int((*_ppEditView)->execute(SCI_GETLENGTH)); int docLength = int((*_ppEditView)->execute(SCI_GETLENGTH));
CharacterRange cr = (*_ppEditView)->getSelection(); Sci_CharacterRange cr = (*_ppEditView)->getSelection();
//The search "zone" is relative to the selection, so search happens 'outside' //The search "zone" is relative to the selection, so search happens 'outside'
@ -1817,7 +1817,7 @@ int FindReplaceDlg::processAll(ProcessOperation op, const FindOption *opt, bool
const TCHAR *txt2find = pOptions->_str2Search.c_str(); const TCHAR *txt2find = pOptions->_str2Search.c_str();
const TCHAR *txt2replace = pOptions->_str4Replace.c_str(); const TCHAR *txt2replace = pOptions->_str4Replace.c_str();
CharacterRange cr = (*_ppEditView)->getSelection(); Sci_CharacterRange cr = (*_ppEditView)->getSelection();
int docLength = int((*_ppEditView)->execute(SCI_GETLENGTH)); int docLength = int((*_ppEditView)->execute(SCI_GETLENGTH));
// Default : // Default :
@ -3521,7 +3521,7 @@ INT_PTR CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR
// selected (no change, if there was no selection) // selected (no change, if there was no selection)
if (updateCase && !isFound) if (updateCase && !isFound)
{ {
CharacterRange range = (*(_pFRDlg->_ppEditView))->getSelection(); Sci_CharacterRange range = (*(_pFRDlg->_ppEditView))->getSelection();
(*(_pFRDlg->_ppEditView))->execute(SCI_SETSEL, static_cast<WPARAM>(-1), range.cpMin); (*(_pFRDlg->_ppEditView))->execute(SCI_SETSEL, static_cast<WPARAM>(-1), range.cpMin);
} }
} }
@ -3559,7 +3559,7 @@ void FindIncrementDlg::markSelectedTextInc(bool enable, FindOption *opt)
return; return;
//Get selection //Get selection
CharacterRange range = (*(_pFRDlg->_ppEditView))->getSelection(); Sci_CharacterRange range = (*(_pFRDlg->_ppEditView))->getSelection();
//If nothing selected, dont mark anything //If nothing selected, dont mark anything
if (range.cpMin == range.cpMax) if (range.cpMin == range.cpMax)

View File

@ -39,7 +39,7 @@ struct NPP_RangeToFormat {
HDC hdcTarget; HDC hdcTarget;
RECT rc; RECT rc;
RECT rcPage; RECT rcPage;
CharacterRange chrg; Sci_CharacterRange chrg;
}; };
class Printer class Printer

View File

@ -431,7 +431,7 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa
// get the current text selection // get the current text selection
CharacterRange range = getSelection(); Sci_CharacterRange range = getSelection();
if (range.cpMax == range.cpMin) if (range.cpMax == range.cpMin)
{ {
// no selection: select the current word instead // no selection: select the current word instead
@ -1736,10 +1736,11 @@ void ScintillaEditView::defineDocType(LangType typeDoc)
setSpecialStyle(styleLN); setSpecialStyle(styleLN);
} }
setTabSettings(_pParameter->getLangFromID(typeDoc)); setTabSettings(_pParameter->getLangFromID(typeDoc));
/*
execute(SCI_SETSTYLEBITS, 8); // Always use 8 bit mask in Document class (Document::stylingBitsMask), execute(SCI_SETSTYLEBITS, 8); // Always use 8 bit mask in Document class (Document::stylingBitsMask),
// in that way Editor::PositionIsHotspot will return correct hotspot styleID. // in that way Editor::PositionIsHotspot will return correct hotspot styleID.
// This value has no effect on LexAccessor::mask. // This value has no effect on LexAccessor::mask.
*/
} }
BufferID ScintillaEditView::attachDefaultDoc() BufferID ScintillaEditView::attachDefaultDoc()
@ -2024,7 +2025,7 @@ void ScintillaEditView::foldAll(bool mode)
void ScintillaEditView::getText(char *dest, size_t start, size_t end) const void ScintillaEditView::getText(char *dest, size_t start, size_t end) const
{ {
TextRange tr; Sci_TextRange tr;
tr.chrg.cpMin = static_cast<long>(start); tr.chrg.cpMin = static_cast<long>(start);
tr.chrg.cpMax = static_cast<long>(end); tr.chrg.cpMax = static_cast<long>(end);
tr.lpstrText = dest; tr.lpstrText = dest;
@ -2138,7 +2139,7 @@ char * ScintillaEditView::getSelectedText(char * txt, int size, bool expand)
{ {
if (!size) if (!size)
return NULL; return NULL;
CharacterRange range = getSelection(); Sci_CharacterRange range = getSelection();
if (range.cpMax == range.cpMin && expand) if (range.cpMax == range.cpMin && expand)
{ {
expandWordSelection(); expandWordSelection();
@ -2282,27 +2283,27 @@ void ScintillaEditView::beginOrEndSelect()
} }
else else
{ {
execute(SCI_SETANCHOR, _beginSelectPosition); execute(SCI_SETANCHOR, static_cast<WPARAM>(_beginSelectPosition));
_beginSelectPosition = -1; _beginSelectPosition = -1;
} }
} }
void ScintillaEditView::updateBeginEndSelectPosition(const bool is_insert, const int position, const int length) void ScintillaEditView::updateBeginEndSelectPosition(bool is_insert, size_t position, size_t length)
{ {
if (_beginSelectPosition != -1 && position < _beginSelectPosition - 1) if (_beginSelectPosition != -1 && static_cast<long long>(position) < _beginSelectPosition - 1)
{ {
if (is_insert) if (is_insert)
_beginSelectPosition += length; _beginSelectPosition += static_cast<long long>(length);
else else
_beginSelectPosition -= length; _beginSelectPosition -= static_cast<long long>(length);
assert(_beginSelectPosition >= 0); assert(_beginSelectPosition >= 0);
} }
} }
void ScintillaEditView::marginClick(int position, int modifiers) void ScintillaEditView::marginClick(Sci_Position position, int modifiers)
{ {
int lineClick = int(execute(SCI_LINEFROMPOSITION, position, 0)); size_t lineClick = execute(SCI_LINEFROMPOSITION, position, 0);
int levelClick = int(execute(SCI_GETFOLDLEVEL, lineClick, 0)); int levelClick = int(execute(SCI_GETFOLDLEVEL, lineClick, 0));
if (levelClick & SC_FOLDLEVELHEADERFLAG) if (levelClick & SC_FOLDLEVELHEADERFLAG)
{ {
@ -2337,9 +2338,9 @@ void ScintillaEditView::marginClick(int position, int modifiers)
} }
} }
void ScintillaEditView::expand(int &line, bool doExpand, bool force, int visLevels, int level) void ScintillaEditView::expand(size_t& line, bool doExpand, bool force, int visLevels, int level)
{ {
int lineMaxSubord = int(execute(SCI_GETLASTCHILD, line, level & SC_FOLDLEVELNUMBERMASK)); size_t lineMaxSubord = execute(SCI_GETLASTCHILD, line, level & SC_FOLDLEVELNUMBERMASK);
++line; ++line;
while (line <= lineMaxSubord) while (line <= lineMaxSubord)
{ {
@ -2461,7 +2462,7 @@ void ScintillaEditView::performGlobalStyles()
void ScintillaEditView::setLineIndent(int line, int indent) const { void ScintillaEditView::setLineIndent(int line, int indent) const {
if (indent < 0) if (indent < 0)
return; return;
CharacterRange crange = getSelection(); Sci_CharacterRange crange = getSelection();
int posBefore = static_cast<int32_t>(execute(SCI_GETLINEINDENTPOSITION, line)); int posBefore = static_cast<int32_t>(execute(SCI_GETLINEINDENTPOSITION, line));
execute(SCI_SETLINEINDENTATION, line, indent); execute(SCI_SETLINEINDENTATION, line, indent);
int32_t posAfter = static_cast<int32_t>(execute(SCI_GETLINEINDENTPOSITION, line)); int32_t posAfter = static_cast<int32_t>(execute(SCI_GETLINEINDENTPOSITION, line));
@ -3050,7 +3051,7 @@ void ScintillaEditView::columnReplace(ColumnModeInfos & cmi, int initial, int in
} }
void ScintillaEditView::foldChanged(int line, int levelNow, int levelPrev) void ScintillaEditView::foldChanged(size_t line, int levelNow, int levelPrev)
{ {
if (levelNow & SC_FOLDLEVELHEADERFLAG) //line can be folded if (levelNow & SC_FOLDLEVELHEADERFLAG) //line can be folded
{ {
@ -3196,7 +3197,7 @@ void ScintillaEditView::notifyMarkers(Buffer * buf, bool isHide, int location, b
} }
//Run through full document. When switching in or opening folding //Run through full document. When switching in or opening folding
//hide is false only when user click on margin //hide is false only when user click on margin
void ScintillaEditView::runMarkers(bool doHide, int searchStart, bool endOfDoc, bool doDelete) void ScintillaEditView::runMarkers(bool doHide, size_t searchStart, bool endOfDoc, bool doDelete)
{ {
//Removes markers if opening //Removes markers if opening
/* /*
@ -3224,12 +3225,12 @@ void ScintillaEditView::runMarkers(bool doHide, int searchStart, bool endOfDoc,
Skip to LASTCHILD Skip to LASTCHILD
Set last start to lastchild Set last start to lastchild
*/ */
int maxLines = static_cast<int32_t>(execute(SCI_GETLINECOUNT)); size_t maxLines = execute(SCI_GETLINECOUNT);
if (doHide) if (doHide)
{ {
int startHiding = searchStart; auto startHiding = searchStart;
bool isInSection = false; bool isInSection = false;
for (int i = searchStart; i < maxLines; ++i) for (auto i = searchStart; i < maxLines; ++i)
{ {
auto state = execute(SCI_MARKERGET, i); auto state = execute(SCI_MARKERGET, i);
if ( ((state & (1 << MARK_HIDELINESEND)) != 0) ) if ( ((state & (1 << MARK_HIDELINESEND)) != 0) )
@ -3254,9 +3255,9 @@ void ScintillaEditView::runMarkers(bool doHide, int searchStart, bool endOfDoc,
} }
else else
{ {
int startShowing = searchStart; auto startShowing = searchStart;
bool isInSection = false; bool isInSection = false;
for (int i = searchStart; i < maxLines; ++i) for (auto i = searchStart; i < maxLines; ++i)
{ {
auto state = execute(SCI_MARKERGET, i); auto state = execute(SCI_MARKERGET, i);
if ( ((state & (1 << MARK_HIDELINESEND)) != 0) ) if ( ((state & (1 << MARK_HIDELINESEND)) != 0) )

View File

@ -244,7 +244,7 @@ public:
void replaceSelWith(const char * replaceText); void replaceSelWith(const char * replaceText);
int getSelectedTextCount() { int getSelectedTextCount() {
CharacterRange range = getSelection(); Sci_CharacterRange range = getSelection();
return (range.cpMax - range.cpMin); return (range.cpMax - range.cpMin);
}; };
@ -281,8 +281,8 @@ public:
return int(execute(SCI_GETLENGTH)); return int(execute(SCI_GETLENGTH));
}; };
CharacterRange getSelection() const { Sci_CharacterRange getSelection() const {
CharacterRange crange; Sci_CharacterRange crange;
crange.cpMin = long(execute(SCI_GETSELECTIONSTART)); crange.cpMin = long(execute(SCI_GETSELECTIONSTART));
crange.cpMax = long(execute(SCI_GETSELECTIONEND)); crange.cpMax = long(execute(SCI_GETSELECTIONEND));
return crange; return crange;
@ -336,8 +336,8 @@ public:
return (execute(SCI_GETMARGINWIDTHN, witchMarge, 0) != 0); return (execute(SCI_GETMARGINWIDTHN, witchMarge, 0) != 0);
}; };
void updateBeginEndSelectPosition(const bool is_insert, const int position, const int length); void updateBeginEndSelectPosition(bool is_insert, size_t position, size_t length);
void marginClick(int position, int modifiers); void marginClick(Sci_Position position, int modifiers);
void setMakerStyle(folderStyle style) { void setMakerStyle(folderStyle style) {
bool display; bool display;
@ -532,7 +532,7 @@ public:
void performGlobalStyles(); void performGlobalStyles();
void expand(int &line, bool doExpand, bool force = false, int visLevels = 0, int level = -1); void expand(size_t& line, bool doExpand, bool force = false, int visLevels = 0, int level = -1);
std::pair<int, int> getSelectionLinesRange() const; std::pair<int, int> getSelectionLinesRange() const;
void currentLinesUp() const; void currentLinesUp() const;
@ -569,7 +569,7 @@ public:
void collapse(int level2Collapse, bool mode); void collapse(int level2Collapse, bool mode);
void foldAll(bool mode); void foldAll(bool mode);
void fold(size_t line, bool mode); void fold(size_t line, bool mode);
bool isFolded(int line){ bool isFolded(size_t line) {
return (execute(SCI_GETFOLDEXPANDED, line) != 0); return (execute(SCI_GETFOLDEXPANDED, line) != 0);
}; };
void foldCurrentPos(bool mode); void foldCurrentPos(bool mode);
@ -584,7 +584,7 @@ public:
void columnReplace(ColumnModeInfos & cmi, const TCHAR *str); void columnReplace(ColumnModeInfos & cmi, const TCHAR *str);
void columnReplace(ColumnModeInfos & cmi, int initial, int incr, int repeat, UCHAR format); void columnReplace(ColumnModeInfos & cmi, int initial, int incr, int repeat, UCHAR format);
void foldChanged(int line, int levelNow, int levelPrev); void foldChanged(size_t line, int levelNow, int levelPrev);
void clearIndicator(int indicatorNumber) { void clearIndicator(int indicatorNumber) {
int docStart = 0; int docStart = 0;
int docEnd = getCurrentDocLen(); int docEnd = getCurrentDocLen();
@ -604,11 +604,11 @@ public:
bool markerMarginClick(int lineNumber); //true if it did something bool markerMarginClick(int lineNumber); //true if it did something
void notifyMarkers(Buffer * buf, bool isHide, int location, bool del); void notifyMarkers(Buffer * buf, bool isHide, int location, bool del);
void runMarkers(bool doHide, int searchStart, bool endOfDoc, bool doDelete); void runMarkers(bool doHide, size_t searchStart, bool endOfDoc, bool doDelete);
bool isSelecting() const { bool isSelecting() const {
static CharacterRange previousSelRange = getSelection(); static Sci_CharacterRange previousSelRange = getSelection();
CharacterRange currentSelRange = getSelection(); Sci_CharacterRange currentSelRange = getSelection();
if (currentSelRange.cpMin == currentSelRange.cpMax) if (currentSelRange.cpMin == currentSelRange.cpMax)
{ {
@ -682,7 +682,7 @@ protected:
typedef std::unordered_map<BufferID, StyleMap*> BufferStyleMap; typedef std::unordered_map<BufferID, StyleMap*> BufferStyleMap;
BufferStyleMap _hotspotStyles; BufferStyleMap _hotspotStyles;
int _beginSelectPosition = -1; long long _beginSelectPosition = -1;
static std::string _defaultCharList; static std::string _defaultCharList;

View File

@ -332,7 +332,7 @@ void DocumentMap::doMove()
::MoveWindow(_vzDlg.getHSelf(), pt.x, pt.y, (rc.right - rc.left), (rc.bottom - rc.top), TRUE); ::MoveWindow(_vzDlg.getHSelf(), pt.x, pt.y, (rc.right - rc.left), (rc.bottom - rc.top), TRUE);
} }
void DocumentMap::fold(int line, bool foldOrNot) void DocumentMap::fold(size_t line, bool foldOrNot)
{ {
_pMapView->fold(line, foldOrNot); _pMapView->fold(line, foldOrNot);
} }

View File

@ -128,7 +128,7 @@ public:
void scrollMap(bool direction, moveMode whichMode); void scrollMap(bool direction, moveMode whichMode);
void scrollMapWith(const MapPosition & mapPos); void scrollMapWith(const MapPosition & mapPos);
void doMove(); void doMove();
void fold(int line, bool foldOrNot); void fold(size_t line, bool foldOrNot);
void foldAll(bool mode); void foldAll(bool mode);
void setSyntaxHiliting(); void setSyntaxHiliting();
void changeTextDirection(bool isRTL); void changeTextDirection(bool isRTL);