Skip to content

Commit b39e09f

Browse files
committed
Fix NPP 8.3.3 plugin API compatibility
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.
1 parent 066aeb6 commit b39e09f

File tree

9 files changed

+81
-81
lines changed

9 files changed

+81
-81
lines changed

src/Dialogs/ConsoleDialog.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ INT_PTR CALLBACK ConsoleDialog::run_dlgProc(UINT message, WPARAM wParam, LPARAM
108108
return FALSE;
109109
case WM_SIZE: {
110110
RECT rect = { 0, 0, LOWORD(lParam), HIWORD(lParam) };
111-
int h = min(m_sciInput.Call(SCI_GETLINECOUNT), 8) * m_sciInput.Call(SCI_TEXTHEIGHT, 1);
111+
int h = static_cast<int>(min(m_sciInput.Call(SCI_GETLINECOUNT), 8) * m_sciInput.Call(SCI_TEXTHEIGHT, 1));
112112
MoveWindow((HWND)m_sciOutput.GetID(), 0, 0, rect.right, rect.bottom - h - 14, TRUE);
113113
MoveWindow((HWND)m_sciInput.GetID(), 0, rect.bottom - h - 14, rect.right - 50, h + 9, TRUE);
114114
m_sciOutput.Call(SCI_DOCUMENTEND);
@@ -169,16 +169,16 @@ INT_PTR CALLBACK ConsoleDialog::run_dlgProc(UINT message, WPARAM wParam, LPARAM
169169
if (scn->linesAdded != 0) {
170170
RECT rect;
171171
GetClientRect(_hSelf, &rect);
172-
int h = min(m_sciInput.Call(SCI_GETLINECOUNT), 8) * m_sciInput.Call(SCI_TEXTHEIGHT, 1);
172+
int h = static_cast<int>(min(m_sciInput.Call(SCI_GETLINECOUNT), 8) * m_sciInput.Call(SCI_TEXTHEIGHT, 1));
173173
MoveWindow((HWND)m_sciOutput.GetID(), 0, 0, rect.right, rect.bottom - h - 14, TRUE);
174174
MoveWindow((HWND)m_sciInput.GetID(), 0, rect.bottom - h - 14, rect.right - 50, h + 9, TRUE);
175175
m_sciOutput.Call(SCI_DOCUMENTEND);
176176
}
177177

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

301301
void ConsoleDialog::runStatement() {
302-
int prevLastLine = m_sciOutput.Call(SCI_GETLINECOUNT);
303-
int newLastLine = 0;
302+
intptr_t prevLastLine = m_sciOutput.Call(SCI_GETLINECOUNT);
303+
intptr_t newLastLine = 0;
304304

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

319319
newLastLine = m_sciOutput.Call(SCI_GETLINECOUNT);
320320

321-
for (int i = prevLastLine; i < newLastLine; ++i) {
321+
for (intptr_t i = prevLastLine; i < newLastLine; ++i) {
322322
m_sciOutput.CallString(SCI_MARGINSETTEXT, i - 1, ">");
323323
m_sciOutput.Call(SCI_MARGINSETSTYLE, i - 1, STYLE_LINENUMBER);
324324
}

src/LuaConsole.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static bool inline isBrace(int ch) {
9090
return strchr("[]{}()", ch) != NULL;
9191
}
9292

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

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

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

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

116116
Sci_TextToFind ttf = {
117117
{
@@ -317,29 +317,29 @@ bool LuaConsole::processNotification(const SCNotification *scn) {
317317
}
318318

319319
void LuaConsole::maintainIndentation() {
320-
int curPos = m_sciInput->Call(SCI_GETCURRENTPOS);
321-
int curLine = m_sciInput->Call(SCI_LINEFROMPOSITION, curPos);
322-
int prevIndent = m_sciInput->Call(SCI_GETLINEINDENTATION, curLine - 1);
320+
intptr_t curPos = m_sciInput->Call(SCI_GETCURRENTPOS);
321+
intptr_t curLine = m_sciInput->Call(SCI_LINEFROMPOSITION, curPos);
322+
intptr_t prevIndent = m_sciInput->Call(SCI_GETLINEINDENTATION, curLine - 1);
323323
m_sciInput->Call(SCI_SETLINEINDENTATION, curLine, prevIndent);
324324
curPos = m_sciInput->Call(SCI_GETLINEINDENTPOSITION, curLine);
325325
m_sciInput->Call(SCI_SETEMPTYSELECTION, curPos);
326326
}
327327

328328
void LuaConsole::braceMatch() {
329-
int curPos = m_sciInput->Call(SCI_GETCURRENTPOS);
330-
int bracePos = INVALID_POSITION;
329+
intptr_t curPos = m_sciInput->Call(SCI_GETCURRENTPOS);
330+
intptr_t bracePos = INVALID_POSITION;
331331

332332
// Check on both sides
333-
if (isBrace(m_sciInput->Call(SCI_GETCHARAT, curPos - 1))) {
333+
if (isBrace(static_cast<int>(m_sciInput->Call(SCI_GETCHARAT, curPos - 1)))) {
334334
bracePos = curPos - 1;
335335
}
336-
else if (isBrace(m_sciInput->Call(SCI_GETCHARAT, curPos))) {
336+
else if (isBrace(static_cast<int>(m_sciInput->Call(SCI_GETCHARAT, curPos)))) {
337337
bracePos = curPos;
338338
}
339339

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

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

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

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

src/LuaScript.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,13 @@ extern "C" __declspec(dllexport) void beNotified(SCNotification *notifyCode) {
299299
// Copied from SciTE
300300
GUI::ScintillaWindow wEditor;
301301
wEditor.SetID(curScintilla);
302-
int lineEndStyled = wEditor.Call(SCI_LINEFROMPOSITION, wEditor.Call(SCI_GETENDSTYLED));
303-
int endStyled = wEditor.Call(SCI_POSITIONFROMLINE, lineEndStyled);
302+
intptr_t lineEndStyled = wEditor.Call(SCI_LINEFROMPOSITION, wEditor.Call(SCI_GETENDSTYLED));
303+
intptr_t endStyled = wEditor.Call(SCI_POSITIONFROMLINE, lineEndStyled);
304304
StyleWriter styler(wEditor);
305305
int styleStart = 0;
306306
if (endStyled > 0) styleStart = styler.StyleAt(endStyled - 1);
307-
styler.SetCodePage(wEditor.Call(SCI_GETCODEPAGE));
308-
LuaExtension::Instance().OnStyle(endStyled, static_cast<int>(notifyCode->position) - endStyled, styleStart, &styler);
307+
styler.SetCodePage(static_cast<int>(wEditor.Call(SCI_GETCODEPAGE)));
308+
LuaExtension::Instance().OnStyle(endStyled, notifyCode->position - endStyled, styleStart, &styler);
309309
styler.Flush();
310310
break;
311311
}

src/Npp/Sci_Position.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ typedef ptrdiff_t Sci_Position;
1818
typedef size_t Sci_PositionU;
1919

2020
// For Sci_CharacterRange which is defined as long to be compatible with Win32 CHARRANGE
21-
typedef long Sci_PositionCR;
21+
typedef intptr_t Sci_PositionCR;
2222

2323
#ifdef _WIN32
2424
#define SCI_METHOD __stdcall

src/SciTE/GUI.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class ScintillaWindow : public Window {
153153
bool CanCall() const {
154154
return wid && fn && ptr;
155155
}
156-
int Call(unsigned int msg, uptr_t wParam=0, sptr_t lParam=0) {
156+
intptr_t Call(unsigned int msg, uptr_t wParam=0, sptr_t lParam=0) {
157157
switch (msg) {
158158
case SCI_CREATEDOCUMENT:
159159
case SCI_CREATELOADER:
@@ -179,10 +179,10 @@ class ScintillaWindow : public Window {
179179
throw ScintillaFailure(status);
180180
return retVal;
181181
}
182-
int CallPointer(unsigned int msg, uptr_t wParam, void *s) {
182+
intptr_t CallPointer(unsigned int msg, uptr_t wParam, void *s) {
183183
return Call(msg, wParam, reinterpret_cast<sptr_t>(s));
184184
}
185-
int CallString(unsigned int msg, uptr_t wParam, const char *s) {
185+
intptr_t CallString(unsigned int msg, uptr_t wParam, const char *s) {
186186
return Call(msg, wParam, reinterpret_cast<sptr_t>(s));
187187
}
188188
sptr_t Send(unsigned int msg, uptr_t wParam=0, sptr_t lParam=0);

src/SciTE/LuaExtension.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,15 +1896,15 @@ void LuaExtension::CallShortcut(int id) {
18961896

18971897
// Similar to StyleContext class in Scintilla
18981898
struct StylingContext {
1899-
unsigned int startPos;
1900-
int lengthDoc;
1899+
uintptr_t startPos;
1900+
intptr_t lengthDoc;
19011901
int initStyle;
19021902
StyleWriter *styler;
19031903

1904-
unsigned int endPos;
1905-
unsigned int endDoc;
1904+
uintptr_t endPos;
1905+
uintptr_t endDoc;
19061906

1907-
unsigned int currentPos;
1907+
uintptr_t currentPos;
19081908
bool atLineStart;
19091909
bool atLineEnd;
19101910
int state;
@@ -1920,7 +1920,7 @@ struct StylingContext {
19201920
}
19211921

19221922
void Colourize() {
1923-
int end = currentPos - 1;
1923+
intptr_t end = currentPos - 1;
19241924
if (end >= static_cast<int>(endDoc))
19251925
end = static_cast<int>(endDoc)-1;
19261926
styler->ColourTo(end, state);
@@ -1981,7 +1981,7 @@ struct StylingContext {
19811981
void GetNextChar() {
19821982
lenCurrent = lenNext;
19831983
lenNext = 1;
1984-
int nextPos = currentPos + lenCurrent;
1984+
intptr_t nextPos = currentPos + lenCurrent;
19851985
unsigned char byteNext = static_cast<unsigned char>(styler->SafeGetCharAt(nextPos));
19861986
unsigned int nextSlot = (cursorPos + 1) % 3;
19871987
memcpy(cursor[nextSlot], "\0\0\0\0\0\0\0\0", 8);
@@ -2149,13 +2149,13 @@ struct StylingContext {
21492149

21502150
static int Token(lua_State *L) {
21512151
StylingContext *context = Context(L);
2152-
int start = context->styler->GetStartSegment();
2153-
int end = context->currentPos - 1;
2154-
int len = end - start + 1;
2152+
intptr_t start = context->styler->GetStartSegment();
2153+
intptr_t end = context->currentPos - 1;
2154+
intptr_t len = end - start + 1;
21552155
if (len <= 0)
21562156
len = 1;
21572157
char *sReturn = new char[len + 1];
2158-
for (int i = 0; i < len; i++) {
2158+
for (intptr_t i = 0; i < len; i++) {
21592159
sReturn[i] = context->styler->SafeGetCharAt(start + i);
21602160
}
21612161
sReturn[len] = '\0';
@@ -2187,7 +2187,7 @@ struct StylingContext {
21872187
}
21882188
};
21892189

2190-
bool LuaExtension::OnStyle(unsigned int startPos, int lengthDoc, int initStyle, StyleWriter *styler) {
2190+
bool LuaExtension::OnStyle(uintptr_t startPos, intptr_t lengthDoc, int initStyle, StyleWriter *styler) {
21912191
if (luaState) {
21922192
lua_pushstring(luaState, "Npp_Callbacks");
21932193
lua_gettable(luaState, LUA_REGISTRYINDEX);

src/SciTE/LuaExtension.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class LuaExtension final {
5555
void CallShortcut(int id);
5656

5757
// Scintilla callbacks
58-
bool OnStyle(unsigned int startPos, int lengthDoc, int initStyle, StyleWriter *styler);
58+
bool OnStyle(uintptr_t startPos, intptr_t lengthDoc, int initStyle, StyleWriter *styler);
5959
bool OnChar(const SCNotification *sc);
6060
bool OnSavePointReached(const SCNotification *sc);
6161
bool OnSavePointLeft(const SCNotification *sc);

src/SciTE/StyleWriter.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bool TextReader::InternalIsLeadByte(char ch) const {
2424
return GUI::IsDBCSLeadByte(codePage, ch);
2525
}
2626

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

51-
int TextReader::StyleAt(int position) {
51+
int TextReader::StyleAt(intptr_t position) {
5252
return static_cast<unsigned char>(sw.Call(SCI_GETSTYLEAT, position, 0));
5353
}
5454

55-
int TextReader::GetLine(int position) {
55+
intptr_t TextReader::GetLine(intptr_t position) {
5656
return sw.Call(SCI_LINEFROMPOSITION, position, 0);
5757
}
5858

59-
int TextReader::LineStart(int line) {
59+
intptr_t TextReader::LineStart(intptr_t line) {
6060
return sw.Call(SCI_POSITIONFROMLINE, line, 0);
6161
}
6262

63-
int TextReader::LevelAt(int line) {
64-
return sw.Call(SCI_GETFOLDLEVEL, line, 0);
63+
int TextReader::LevelAt(intptr_t line) {
64+
return static_cast<int>(sw.Call(SCI_GETFOLDLEVEL, line, 0));
6565
}
6666

67-
int TextReader::Length() {
67+
intptr_t TextReader::Length() {
6868
if (lenDoc == -1)
6969
lenDoc = sw.Call(SCI_GETTEXTLENGTH, 0, 0);
7070
return lenDoc;
7171
}
7272

73-
int TextReader::GetLineState(int line) {
74-
return sw.Call(SCI_GETLINESTATE, line);
73+
int TextReader::GetLineState(intptr_t line) {
74+
return static_cast<int>(sw.Call(SCI_GETLINESTATE, line));
7575
}
7676

7777
StyleWriter::StyleWriter(GUI::ScintillaWindow &sw_) :
@@ -81,19 +81,19 @@ StyleWriter::StyleWriter(GUI::ScintillaWindow &sw_) :
8181
styleBuf[0] = 0;
8282
}
8383

84-
int StyleWriter::SetLineState(int line, int state) {
85-
return sw.Call(SCI_SETLINESTATE, line, state);
84+
int StyleWriter::SetLineState(intptr_t line, int state) {
85+
return static_cast<int>(sw.Call(SCI_SETLINESTATE, line, state));
8686
}
8787

88-
void StyleWriter::StartAt(unsigned int start, char chMask) {
88+
void StyleWriter::StartAt(uintptr_t start, char chMask) {
8989
sw.Call(SCI_STARTSTYLING, start, chMask);
9090
}
9191

92-
void StyleWriter::StartSegment(unsigned int pos) {
92+
void StyleWriter::StartSegment(uintptr_t pos) {
9393
startSeg = pos;
9494
}
9595

96-
void StyleWriter::ColourTo(unsigned int pos, int chAttr) {
96+
void StyleWriter::ColourTo(uintptr_t pos, int chAttr) {
9797
// Only perform styling if non empty range
9898
if (pos != startSeg - 1) {
9999
if (validLen + (pos - startSeg + 1) >= bufferSize)
@@ -102,15 +102,15 @@ void StyleWriter::ColourTo(unsigned int pos, int chAttr) {
102102
// Too big for buffer so send directly
103103
sw.Call(SCI_SETSTYLING, pos - startSeg + 1, chAttr);
104104
} else {
105-
for (unsigned int i = startSeg; i <= pos; i++) {
105+
for (uintptr_t i = startSeg; i <= pos; i++) {
106106
styleBuf[validLen++] = static_cast<char>(chAttr);
107107
}
108108
}
109109
}
110110
startSeg = pos+1;
111111
}
112112

113-
void StyleWriter::SetLevel(int line, int level) {
113+
void StyleWriter::SetLevel(intptr_t line, int level) {
114114
sw.Call(SCI_SETFOLDLEVEL, line, level);
115115
}
116116

0 commit comments

Comments
 (0)