Skip to content

Commit

Permalink
Fix NPP 8.3.3 plugin API compatibility
Browse files Browse the repository at this point in the history
Changed length, line and position variables to (u)intptr_t, to support
files > 2 GB. This was done based on what the compiler complained about
after changing Call functions in ScintillaWindow, so it might not cover
everything.
  • Loading branch information
cmagnush committed Mar 26, 2022
1 parent 066aeb6 commit b39e09f
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 81 deletions.
16 changes: 8 additions & 8 deletions src/Dialogs/ConsoleDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ INT_PTR CALLBACK ConsoleDialog::run_dlgProc(UINT message, WPARAM wParam, LPARAM
return FALSE;
case WM_SIZE: {
RECT rect = { 0, 0, LOWORD(lParam), HIWORD(lParam) };
int h = min(m_sciInput.Call(SCI_GETLINECOUNT), 8) * m_sciInput.Call(SCI_TEXTHEIGHT, 1);
int h = static_cast<int>(min(m_sciInput.Call(SCI_GETLINECOUNT), 8) * m_sciInput.Call(SCI_TEXTHEIGHT, 1));
MoveWindow((HWND)m_sciOutput.GetID(), 0, 0, rect.right, rect.bottom - h - 14, TRUE);
MoveWindow((HWND)m_sciInput.GetID(), 0, rect.bottom - h - 14, rect.right - 50, h + 9, TRUE);
m_sciOutput.Call(SCI_DOCUMENTEND);
Expand Down Expand Up @@ -169,16 +169,16 @@ INT_PTR CALLBACK ConsoleDialog::run_dlgProc(UINT message, WPARAM wParam, LPARAM
if (scn->linesAdded != 0) {
RECT rect;
GetClientRect(_hSelf, &rect);
int h = min(m_sciInput.Call(SCI_GETLINECOUNT), 8) * m_sciInput.Call(SCI_TEXTHEIGHT, 1);
int h = static_cast<int>(min(m_sciInput.Call(SCI_GETLINECOUNT), 8) * m_sciInput.Call(SCI_TEXTHEIGHT, 1));
MoveWindow((HWND)m_sciOutput.GetID(), 0, 0, rect.right, rect.bottom - h - 14, TRUE);
MoveWindow((HWND)m_sciInput.GetID(), 0, rect.bottom - h - 14, rect.right - 50, h + 9, TRUE);
m_sciOutput.Call(SCI_DOCUMENTEND);
}

// Not the most efficient way but by far the easiest to do it here
int startLine = 0;
int endLine = m_sciInput.Call(SCI_GETLINECOUNT);
for (int i = startLine; i < endLine; ++i) {
intptr_t startLine = 0;
intptr_t endLine = m_sciInput.Call(SCI_GETLINECOUNT);
for (intptr_t i = startLine; i < endLine; ++i) {
m_sciInput.CallString(SCI_MARGINSETTEXT, i, ">");
m_sciInput.Call(SCI_MARGINSETSTYLE, i, STYLE_LINENUMBER);
}
Expand Down Expand Up @@ -299,8 +299,8 @@ LRESULT CALLBACK ConsoleDialog::inputWndProc(HWND hWnd, UINT uMsg, WPARAM wParam
}

void ConsoleDialog::runStatement() {
int prevLastLine = m_sciOutput.Call(SCI_GETLINECOUNT);
int newLastLine = 0;
intptr_t prevLastLine = m_sciOutput.Call(SCI_GETLINECOUNT);
intptr_t newLastLine = 0;

Sci_TextRange tr;
tr.chrg.cpMin = 0;
Expand All @@ -318,7 +318,7 @@ void ConsoleDialog::runStatement() {

newLastLine = m_sciOutput.Call(SCI_GETLINECOUNT);

for (int i = prevLastLine; i < newLastLine; ++i) {
for (intptr_t i = prevLastLine; i < newLastLine; ++i) {
m_sciOutput.CallString(SCI_MARGINSETTEXT, i - 1, ">");
m_sciOutput.Call(SCI_MARGINSETSTYLE, i - 1, STYLE_LINENUMBER);
}
Expand Down
34 changes: 17 additions & 17 deletions src/LuaConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static bool inline isBrace(int ch) {
return strchr("[]{}()", ch) != NULL;
}

static std::string getRange(GUI::ScintillaWindow *sw, int start, int end) {
static std::string getRange(GUI::ScintillaWindow *sw, intptr_t start, intptr_t end) {
if (end <= start) return std::string();

std::vector<char> buffer(end - start + 1);
Expand All @@ -104,14 +104,14 @@ static std::string getRange(GUI::ScintillaWindow *sw, int start, int end) {
return std::string(buffer.begin(), buffer.end() - 1); // don't copy the null
}

static std::string getWordAt(GUI::ScintillaWindow *sw, int pos) {
int word_start = sw->Call(SCI_WORDSTARTPOSITION, pos, true);
int word_end = sw->Call(SCI_WORDENDPOSITION, pos, true);
static std::string getWordAt(GUI::ScintillaWindow *sw, intptr_t pos) {
intptr_t word_start = sw->Call(SCI_WORDSTARTPOSITION, pos, true);
intptr_t word_end = sw->Call(SCI_WORDENDPOSITION, pos, true);
return getRange(sw, word_start, word_end);
}

static std::string getLuaIdentifierAt(GUI::ScintillaWindow *sw, int pos) {
const int line = sw->Call(SCI_LINEFROMPOSITION);
static std::string getLuaIdentifierAt(GUI::ScintillaWindow *sw, intptr_t pos) {
const intptr_t line = sw->Call(SCI_LINEFROMPOSITION);

Sci_TextToFind ttf = {
{
Expand Down Expand Up @@ -317,29 +317,29 @@ bool LuaConsole::processNotification(const SCNotification *scn) {
}

void LuaConsole::maintainIndentation() {
int curPos = m_sciInput->Call(SCI_GETCURRENTPOS);
int curLine = m_sciInput->Call(SCI_LINEFROMPOSITION, curPos);
int prevIndent = m_sciInput->Call(SCI_GETLINEINDENTATION, curLine - 1);
intptr_t curPos = m_sciInput->Call(SCI_GETCURRENTPOS);
intptr_t curLine = m_sciInput->Call(SCI_LINEFROMPOSITION, curPos);
intptr_t prevIndent = m_sciInput->Call(SCI_GETLINEINDENTATION, curLine - 1);
m_sciInput->Call(SCI_SETLINEINDENTATION, curLine, prevIndent);
curPos = m_sciInput->Call(SCI_GETLINEINDENTPOSITION, curLine);
m_sciInput->Call(SCI_SETEMPTYSELECTION, curPos);
}

void LuaConsole::braceMatch() {
int curPos = m_sciInput->Call(SCI_GETCURRENTPOS);
int bracePos = INVALID_POSITION;
intptr_t curPos = m_sciInput->Call(SCI_GETCURRENTPOS);
intptr_t bracePos = INVALID_POSITION;

// Check on both sides
if (isBrace(m_sciInput->Call(SCI_GETCHARAT, curPos - 1))) {
if (isBrace(static_cast<int>(m_sciInput->Call(SCI_GETCHARAT, curPos - 1)))) {
bracePos = curPos - 1;
}
else if (isBrace(m_sciInput->Call(SCI_GETCHARAT, curPos))) {
else if (isBrace(static_cast<int>(m_sciInput->Call(SCI_GETCHARAT, curPos)))) {
bracePos = curPos;
}

// See if we are next to a brace
if (bracePos != INVALID_POSITION) {
int otherPos = m_sciInput->Call(SCI_BRACEMATCH, bracePos, 0);
intptr_t otherPos = m_sciInput->Call(SCI_BRACEMATCH, bracePos, 0);
if (otherPos != INVALID_POSITION) {
m_sciInput->Call(SCI_BRACEHIGHLIGHT, bracePos, otherPos);
}
Expand All @@ -354,15 +354,15 @@ void LuaConsole::braceMatch() {

void LuaConsole::showAutoCompletion() {
std::string partialWord;
int curPos = m_sciInput->Call(SCI_GETCURRENTPOS);
int prevCh = m_sciInput->Call(SCI_GETCHARAT, curPos - 1);
intptr_t curPos = m_sciInput->Call(SCI_GETCURRENTPOS);
int prevCh = static_cast<int>(m_sciInput->Call(SCI_GETCHARAT, curPos - 1));

// The cursor could be at the end of a partial word e.g. editor.Sty|
if (isalpha(prevCh) || prevCh == '_') {
partialWord = getWordAt(m_sciInput, curPos - 1);

// Back up past the partial word
prevCh = m_sciInput->Call(SCI_GETCHARAT, curPos - 1 - partialWord.size());
prevCh = static_cast<int>(m_sciInput->Call(SCI_GETCHARAT, curPos - 1 - partialWord.size()));
curPos = curPos - static_cast<int>(partialWord.size());
}

Expand Down
8 changes: 4 additions & 4 deletions src/LuaScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,13 @@ extern "C" __declspec(dllexport) void beNotified(SCNotification *notifyCode) {
// Copied from SciTE
GUI::ScintillaWindow wEditor;
wEditor.SetID(curScintilla);
int lineEndStyled = wEditor.Call(SCI_LINEFROMPOSITION, wEditor.Call(SCI_GETENDSTYLED));
int endStyled = wEditor.Call(SCI_POSITIONFROMLINE, lineEndStyled);
intptr_t lineEndStyled = wEditor.Call(SCI_LINEFROMPOSITION, wEditor.Call(SCI_GETENDSTYLED));
intptr_t endStyled = wEditor.Call(SCI_POSITIONFROMLINE, lineEndStyled);
StyleWriter styler(wEditor);
int styleStart = 0;
if (endStyled > 0) styleStart = styler.StyleAt(endStyled - 1);
styler.SetCodePage(wEditor.Call(SCI_GETCODEPAGE));
LuaExtension::Instance().OnStyle(endStyled, static_cast<int>(notifyCode->position) - endStyled, styleStart, &styler);
styler.SetCodePage(static_cast<int>(wEditor.Call(SCI_GETCODEPAGE)));
LuaExtension::Instance().OnStyle(endStyled, notifyCode->position - endStyled, styleStart, &styler);
styler.Flush();
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Npp/Sci_Position.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef ptrdiff_t Sci_Position;
typedef size_t Sci_PositionU;

// For Sci_CharacterRange which is defined as long to be compatible with Win32 CHARRANGE
typedef long Sci_PositionCR;
typedef intptr_t Sci_PositionCR;

#ifdef _WIN32
#define SCI_METHOD __stdcall
Expand Down
6 changes: 3 additions & 3 deletions src/SciTE/GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class ScintillaWindow : public Window {
bool CanCall() const {
return wid && fn && ptr;
}
int Call(unsigned int msg, uptr_t wParam=0, sptr_t lParam=0) {
intptr_t Call(unsigned int msg, uptr_t wParam=0, sptr_t lParam=0) {
switch (msg) {
case SCI_CREATEDOCUMENT:
case SCI_CREATELOADER:
Expand All @@ -179,10 +179,10 @@ class ScintillaWindow : public Window {
throw ScintillaFailure(status);
return retVal;
}
int CallPointer(unsigned int msg, uptr_t wParam, void *s) {
intptr_t CallPointer(unsigned int msg, uptr_t wParam, void *s) {
return Call(msg, wParam, reinterpret_cast<sptr_t>(s));
}
int CallString(unsigned int msg, uptr_t wParam, const char *s) {
intptr_t CallString(unsigned int msg, uptr_t wParam, const char *s) {
return Call(msg, wParam, reinterpret_cast<sptr_t>(s));
}
sptr_t Send(unsigned int msg, uptr_t wParam=0, sptr_t lParam=0);
Expand Down
24 changes: 12 additions & 12 deletions src/SciTE/LuaExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1896,15 +1896,15 @@ void LuaExtension::CallShortcut(int id) {

// Similar to StyleContext class in Scintilla
struct StylingContext {
unsigned int startPos;
int lengthDoc;
uintptr_t startPos;
intptr_t lengthDoc;
int initStyle;
StyleWriter *styler;

unsigned int endPos;
unsigned int endDoc;
uintptr_t endPos;
uintptr_t endDoc;

unsigned int currentPos;
uintptr_t currentPos;
bool atLineStart;
bool atLineEnd;
int state;
Expand All @@ -1920,7 +1920,7 @@ struct StylingContext {
}

void Colourize() {
int end = currentPos - 1;
intptr_t end = currentPos - 1;
if (end >= static_cast<int>(endDoc))
end = static_cast<int>(endDoc)-1;
styler->ColourTo(end, state);
Expand Down Expand Up @@ -1981,7 +1981,7 @@ struct StylingContext {
void GetNextChar() {
lenCurrent = lenNext;
lenNext = 1;
int nextPos = currentPos + lenCurrent;
intptr_t nextPos = currentPos + lenCurrent;
unsigned char byteNext = static_cast<unsigned char>(styler->SafeGetCharAt(nextPos));
unsigned int nextSlot = (cursorPos + 1) % 3;
memcpy(cursor[nextSlot], "\0\0\0\0\0\0\0\0", 8);
Expand Down Expand Up @@ -2149,13 +2149,13 @@ struct StylingContext {

static int Token(lua_State *L) {
StylingContext *context = Context(L);
int start = context->styler->GetStartSegment();
int end = context->currentPos - 1;
int len = end - start + 1;
intptr_t start = context->styler->GetStartSegment();
intptr_t end = context->currentPos - 1;
intptr_t len = end - start + 1;
if (len <= 0)
len = 1;
char *sReturn = new char[len + 1];
for (int i = 0; i < len; i++) {
for (intptr_t i = 0; i < len; i++) {
sReturn[i] = context->styler->SafeGetCharAt(start + i);
}
sReturn[len] = '\0';
Expand Down Expand Up @@ -2187,7 +2187,7 @@ struct StylingContext {
}
};

bool LuaExtension::OnStyle(unsigned int startPos, int lengthDoc, int initStyle, StyleWriter *styler) {
bool LuaExtension::OnStyle(uintptr_t startPos, intptr_t lengthDoc, int initStyle, StyleWriter *styler) {
if (luaState) {
lua_pushstring(luaState, "Npp_Callbacks");
lua_gettable(luaState, LUA_REGISTRYINDEX);
Expand Down
2 changes: 1 addition & 1 deletion src/SciTE/LuaExtension.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class LuaExtension final {
void CallShortcut(int id);

// Scintilla callbacks
bool OnStyle(unsigned int startPos, int lengthDoc, int initStyle, StyleWriter *styler);
bool OnStyle(uintptr_t startPos, intptr_t lengthDoc, int initStyle, StyleWriter *styler);
bool OnChar(const SCNotification *sc);
bool OnSavePointReached(const SCNotification *sc);
bool OnSavePointLeft(const SCNotification *sc);
Expand Down
32 changes: 16 additions & 16 deletions src/SciTE/StyleWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ bool TextReader::InternalIsLeadByte(char ch) const {
return GUI::IsDBCSLeadByte(codePage, ch);
}

void TextReader::Fill(int position) {
void TextReader::Fill(intptr_t position) {
if (lenDoc == -1)
lenDoc = sw.Call(SCI_GETTEXTLENGTH, 0, 0);
startPos = position - slopSize;
Expand All @@ -48,30 +48,30 @@ bool TextReader::Match(int pos, const char *s) {
return true;
}

int TextReader::StyleAt(int position) {
int TextReader::StyleAt(intptr_t position) {
return static_cast<unsigned char>(sw.Call(SCI_GETSTYLEAT, position, 0));
}

int TextReader::GetLine(int position) {
intptr_t TextReader::GetLine(intptr_t position) {
return sw.Call(SCI_LINEFROMPOSITION, position, 0);
}

int TextReader::LineStart(int line) {
intptr_t TextReader::LineStart(intptr_t line) {
return sw.Call(SCI_POSITIONFROMLINE, line, 0);
}

int TextReader::LevelAt(int line) {
return sw.Call(SCI_GETFOLDLEVEL, line, 0);
int TextReader::LevelAt(intptr_t line) {
return static_cast<int>(sw.Call(SCI_GETFOLDLEVEL, line, 0));
}

int TextReader::Length() {
intptr_t TextReader::Length() {
if (lenDoc == -1)
lenDoc = sw.Call(SCI_GETTEXTLENGTH, 0, 0);
return lenDoc;
}

int TextReader::GetLineState(int line) {
return sw.Call(SCI_GETLINESTATE, line);
int TextReader::GetLineState(intptr_t line) {
return static_cast<int>(sw.Call(SCI_GETLINESTATE, line));
}

StyleWriter::StyleWriter(GUI::ScintillaWindow &sw_) :
Expand All @@ -81,19 +81,19 @@ StyleWriter::StyleWriter(GUI::ScintillaWindow &sw_) :
styleBuf[0] = 0;
}

int StyleWriter::SetLineState(int line, int state) {
return sw.Call(SCI_SETLINESTATE, line, state);
int StyleWriter::SetLineState(intptr_t line, int state) {
return static_cast<int>(sw.Call(SCI_SETLINESTATE, line, state));
}

void StyleWriter::StartAt(unsigned int start, char chMask) {
void StyleWriter::StartAt(uintptr_t start, char chMask) {
sw.Call(SCI_STARTSTYLING, start, chMask);
}

void StyleWriter::StartSegment(unsigned int pos) {
void StyleWriter::StartSegment(uintptr_t pos) {
startSeg = pos;
}

void StyleWriter::ColourTo(unsigned int pos, int chAttr) {
void StyleWriter::ColourTo(uintptr_t pos, int chAttr) {
// Only perform styling if non empty range
if (pos != startSeg - 1) {
if (validLen + (pos - startSeg + 1) >= bufferSize)
Expand All @@ -102,15 +102,15 @@ void StyleWriter::ColourTo(unsigned int pos, int chAttr) {
// Too big for buffer so send directly
sw.Call(SCI_SETSTYLING, pos - startSeg + 1, chAttr);
} else {
for (unsigned int i = startSeg; i <= pos; i++) {
for (uintptr_t i = startSeg; i <= pos; i++) {
styleBuf[validLen++] = static_cast<char>(chAttr);
}
}
}
startSeg = pos+1;
}

void StyleWriter::SetLevel(int line, int level) {
void StyleWriter::SetLevel(intptr_t line, int level) {
sw.Call(SCI_SETFOLDLEVEL, line, level);
}

Expand Down
Loading

0 comments on commit b39e09f

Please sign in to comment.