Skip to content

Commit

Permalink
Npp 8.3 interface (#221)
Browse files Browse the repository at this point in the history
* - add n++ 8.3 interface files
- adapt generated code therefore regarding textrange
- fixed some compiler/intellisense warnings ScintillaWrapper.cpp
- format code in TestRunner.cpp

* use Sci_Position for position at Scintilla.iface

* avoid compiler warning
  • Loading branch information
chcg committed Feb 6, 2022
1 parent b09ab67 commit 9d26931
Show file tree
Hide file tree
Showing 16 changed files with 220 additions and 196 deletions.
10 changes: 5 additions & 5 deletions NppPlugin/include/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ class WcharMbcsConvertor final
return instance;
}

const wchar_t * char2wchar(const char *mbStr, UINT codepage, int lenIn=-1, int *pLenOut=NULL, int *pBytesNotProcessed=NULL);
const wchar_t * char2wchar(const char *mbcs2Convert, UINT codepage, int *mstart, int *mend);
const char * wchar2char(const wchar_t *wcStr, UINT codepage, int lenIn = -1, int *pLenOut = NULL);
const char * wchar2char(const wchar_t *wcStr, UINT codepage, long *mstart, long *mend);
const wchar_t * char2wchar(const char *mbStr, size_t codepage, int lenMbcs =-1, int* pLenOut=NULL, int* pBytesNotProcessed=NULL);
const wchar_t * char2wchar(const char *mbcs2Convert, size_t codepage, intptr_t* mstart, intptr_t* mend);
const char * wchar2char(const wchar_t *wcStr, size_t codepage, int lenIn = -1, int* pLenOut = NULL);
const char * wchar2char(const wchar_t *wcStr, size_t codepage, intptr_t* mstart, intptr_t* mend);

const char * encode(UINT fromCodepage, UINT toCodepage, const char *txt2Encode, int lenIn=-1, int *pLenOut=NULL, int *pBytesNotProcessed=NULL)
const char * encode(UINT fromCodepage, UINT toCodepage, const char *txt2Encode, int lenIn = -1, int* pLenOut=NULL, int* pBytesNotProcessed=NULL)
{
int lenWc = 0;
const wchar_t * strW = char2wchar(txt2Encode, fromCodepage, lenIn, &lenWc, pBytesNotProcessed);
Expand Down
2 changes: 1 addition & 1 deletion NppPlugin/include/DockingDlgInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected :
generic_string _pluginName;
bool _isClosed = false;

virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) {
virtual intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) {
switch (message)
{
case WM_ERASEBKGND:
Expand Down
2 changes: 1 addition & 1 deletion NppPlugin/include/Notepad_plus_msgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ enum LangType {L_TEXT, L_PHP , L_C, L_CPP, L_CS, L_OBJC, L_JAVA, L_RC,\
L_EXTERNAL};

enum winVer{ WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV_S2003, WV_XPX64, WV_VISTA, WV_WIN7, WV_WIN8, WV_WIN81, WV_WIN10 };
enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64 };
enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 };



Expand Down
4 changes: 3 additions & 1 deletion NppPlugin/include/Sci_Position.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
typedef ptrdiff_t Sci_Position;

// Unsigned variant used for ILexer::Lex and ILexer::Fold
// Definitions of common types
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 NppPlugin/include/Scintilla.h
Original file line number Diff line number Diff line change
Expand Up @@ -1279,12 +1279,12 @@ struct SCNotification {
};

struct SearchResultMarking {
long _start;
long _end;
intptr_t _start;
intptr_t _end;
};

struct SearchResultMarkings {
long _length;
intptr_t _length;
SearchResultMarking *_markings;
};

Expand Down
4 changes: 2 additions & 2 deletions NppPlugin/include/StaticDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public :

protected:
RECT _rc = { 0 };
static INT_PTR CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) = 0;
static intptr_t CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
virtual intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) = 0;

HGLOBAL makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate);
};
5 changes: 5 additions & 0 deletions NppPlugin/project/NppPlugin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,13 @@
<ClInclude Include="..\include\DockingDlgInterface.h" />
<ClInclude Include="..\include\dockingResource.h" />
<ClInclude Include="..\include\keys.h" />
<ClInclude Include="..\include\menuCmdID.h" />
<ClInclude Include="..\include\Notepad_plus_msgs.h" />
<ClInclude Include="..\include\NppDarkMode.h" />
<ClInclude Include="..\include\PluginInterface.h" />
<ClInclude Include="..\include\SciLexer.h" />
<ClInclude Include="..\include\Scintilla.h" />
<ClInclude Include="..\include\Sci_Position.h" />
<ClInclude Include="..\include\StaticDialog.h" />
<ClInclude Include="..\include\SysMsg.h" />
<ClInclude Include="..\include\Window.h" />
Expand Down
15 changes: 15 additions & 0 deletions NppPlugin/project/NppPlugin.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@
<ClInclude Include="..\stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\menuCmdID.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\NppDarkMode.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\Sci_Position.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\SciLexer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\Scintilla.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
Expand Down
2 changes: 1 addition & 1 deletion NppPlugin/src/StaticDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void StaticDialog::create(int dialogID, bool isRTL, bool msgDestParent)
::SendMessage(msgDestParent ? _hParent : (::GetParent(_hParent)), NPPM_MODELESSDIALOG, MODELESSDIALOGADD, reinterpret_cast<WPARAM>(_hSelf));
}

INT_PTR CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
intptr_t CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
Expand Down
25 changes: 12 additions & 13 deletions PythonScript.Tests/TestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ void deleteEntry(NppPythonScript::ReplaceEntry* entry)

void runReplace()
{

NppPythonScript::Replacer<NppPythonScript::Utf8CharTraits> replacer;
NppPythonScript::Replacer<NppPythonScript::Utf8CharTraits> replacer;
std::list<NppPythonScript::ReplaceEntry* > entries;
bool moreEntries = replacer.startReplace("aaabbbaaabb", 12, 0, 0, "(b+)", "x$1x", NppPythonScript::python_re_flag_normal, entries);
ASSERT_EQ(2, entries.size());
Expand All @@ -26,26 +25,26 @@ void runReplace()
int main(int argc, char* argv[])
{
#ifdef _DEBUG
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
_CrtMemState state;
_CrtMemCheckpoint(&state);
#endif


::testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();

// This function call is used to check if we've created memory leaks using startReplace
// Gtest creates various static objects, so it can be a bit tricky to identify leaks with Gtest running
// It's left commented out as it normally serves no purpose. If it looks like there's leaks, then remove the
// It's left commented out as it normally serves no purpose. If it looks like there's leaks, then remove the
// test code above, and uncomment this runReplace() call to try to identify the source of the leak.
// runReplace();
// runReplace();

#ifdef _DEBUG
_CrtMemDumpAllObjectsSince(&state);
Expand Down
12 changes: 6 additions & 6 deletions PythonScript/src/CreateWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

types = {
'string' : 'boost::python::object',
'position' : 'intptr_t',
'position' : 'Sci_Position',
'line' : 'intptr_t',
'cells' : 'ScintillaCells',
'pointer' : 'intptr_t',
Expand Down Expand Up @@ -122,8 +122,8 @@
# Must be kept in sync with pythonTypeExplosions
typeExplosions = {
#'colour' : lambda name: 'int {0}Red, int {0}Green, int {0}Blue'.format(name),
'findtext' : 'int start, int end, boost::python::object {}',
'textrange' : 'int start, int end'
'findtext' : 'Sci_PositionCR start, Sci_PositionCR end, boost::python::object {}',
'textrange' : 'Sci_PositionCR start, Sci_PositionCR end'
}

# Must be kept in sync with typeExplosions
Expand Down Expand Up @@ -321,7 +321,7 @@ def getTextRangeBody(v, out):
if (end < start)
{{
int temp = start;
Sci_PositionCR temp = start;
start = end;
end = temp;
}}
Expand All @@ -341,7 +341,7 @@ def getStyledTextBody(v, out):
''' Sci_TextRange src;
if (end < start)
{{
int temp = start;
Sci_PositionCR temp = start;
start = end;
end = temp;
}}
Expand Down Expand Up @@ -522,7 +522,7 @@ def getPythonParamNamesQuoted(param1Type, param1Name, param2Type, param2Name):


specialCases = {
'GetStyledText' : ('boost::python::tuple', 'int', 'start', 'int', 'end', getStyledTextBody),
'GetStyledText' : ('boost::python::tuple', 'Sci_PositionCR', 'start', 'Sci_PositionCR', 'end', getStyledTextBody),
'GetLine': ('boost::python::str', 'int', 'line', '', '', getLineBody),
'AnnotationSetText' : ('void', 'int', 'line', 'boost::python::object', 'text', annotationSetTextBody),
'SetDocPointer' :('void', '','','intptr_t', 'pointer', getSetDocPointerBody),
Expand Down
4 changes: 3 additions & 1 deletion PythonScript/src/Sci_Position.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
typedef ptrdiff_t Sci_Position;

// Unsigned variant used for ILexer::Lex and ILexer::Fold
// Definitions of common types
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 PythonScript/src/Scintilla.h
Original file line number Diff line number Diff line change
Expand Up @@ -1279,12 +1279,12 @@ struct SCNotification {
};

struct SearchResultMarking {
long _start;
long _end;
intptr_t _start;
intptr_t _end;
};

struct SearchResultMarkings {
long _length;
intptr_t _length;
SearchResultMarking *_markings;
};

Expand Down
9 changes: 5 additions & 4 deletions PythonScript/src/ScintillaWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ const char *ScintillaWrapper::getCurrentAnsiCodePageName()
}
}

std::string ScintillaWrapper::extractEncodedString(boost::python::object str, int toCodePage)
std::string ScintillaWrapper::extractEncodedString(boost::python::object str, intptr_t toCodePage)
{
std::string resultStr;
int searchLength;
Expand Down Expand Up @@ -848,7 +848,7 @@ void ScintillaWrapper::replaceImpl(boost::python::object searchStr, boost::pytho

BeginUndoAction();

CommunicationInfo commInfo;
CommunicationInfo commInfo{};
commInfo.internalMsg = PYSCR_RUNREPLACE;
commInfo.srcModuleName = _T("PythonScript.dll");
TCHAR pluginName[] = _T("PythonScript.dll");
Expand Down Expand Up @@ -999,7 +999,7 @@ boost::python::str ScintillaWrapper::getWord(boost::python::object position, boo

intptr_t startPos = callScintilla(SCI_WORDSTARTPOSITION, pos, wordChars);
intptr_t endPos = callScintilla(SCI_WORDENDPOSITION, pos, wordChars);
Sci_TextRange tr;
Sci_TextRange tr{};
tr.chrg.cpMin = startPos;
tr.chrg.cpMax = endPos;
tr.lpstrText = new char[size_t((endPos - startPos) + 1)];
Expand All @@ -1022,7 +1022,8 @@ void ScintillaWrapper::notAllowedInCallback(const char *message)

void ScintillaWrapper::swapColours()
{
int foreground, background;
intptr_t foreground = 0;
intptr_t background = 0;
SendMessage(m_handle, WM_SETREDRAW, FALSE, 0);
for(int i = 255; i >= 0; --i)
{
Expand Down

0 comments on commit 9d26931

Please sign in to comment.