Skip to content

Commit

Permalink
Changes to Notepad++ API
Browse files Browse the repository at this point in the history
  • Loading branch information
pnedev committed Feb 23, 2024
1 parent 7ba85b0 commit 00664f1
Show file tree
Hide file tree
Showing 9 changed files with 720 additions and 292 deletions.
6 changes: 1 addition & 5 deletions src/INpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,12 @@ bool INpp::SearchText(const char* text, bool ignoreCase, bool wholeWord, bool re
/**
* \brief
*/
bool INpp::isSciWndRegistered(HWND hSciWnd, bool remove)
bool INpp::isSciWndRegistered(HWND hSciWnd)
{
for (std::vector<HWND>::iterator iSci = _hSciWndList.begin(); iSci != _hSciWndList.end(); ++iSci)
{
if (*iSci == hSciWnd)
{
if (remove)
_hSciWndList.erase(iSci);
return true;
}
}

return false;
Expand Down
8 changes: 1 addition & 7 deletions src/INpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ class INpp
return hSciWnd;
}

inline void DestroySciHandle(const HWND hSciWnd)
{
if (isSciWndRegistered(hSciWnd, true))
SendMessage(_nppData._nppHandle, NPPM_DESTROYSCINTILLAHANDLE, 0, (LPARAM)hSciWnd);
}

inline void GetMainDir(CPath& path) const
{
path.Resize(MAX_PATH);
Expand Down Expand Up @@ -338,7 +332,7 @@ class INpp
INpp(const INpp&);
~INpp() {}

bool isSciWndRegistered(HWND hSciWnd, bool remove = false);
bool isSciWndRegistered(HWND hSciWnd);

NppData _nppData;
HWND _hSC;
Expand Down
3 changes: 1 addition & 2 deletions src/NppAPI/Docking.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of Notepad++ project
// Copyright (C)2021 Don HO <[email protected]>
// Copyright (C)2022 Don HO <[email protected]>

// 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
Expand Down Expand Up @@ -36,7 +36,6 @@
#define DWS_ICONTAB 0x00000001 // Icon for tabs are available
#define DWS_ICONBAR 0x00000002 // Icon for icon bar are available (currently not supported)
#define DWS_ADDINFO 0x00000004 // Additional information are in use
#define DWS_USEOWNDARKMODE 0x00000008 // Use plugin's own dark mode
#define DWS_PARAMSALL (DWS_ICONTAB|DWS_ICONBAR|DWS_ADDINFO)

// default docking values for first call of plugin
Expand Down
886 changes: 637 additions & 249 deletions src/NppAPI/Notepad_plus_msgs.h

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions src/NppAPI/PluginInterface.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of Notepad++ project
// Copyright (C)2021 Don HO <[email protected]>
// Copyright (C)2024 Don HO <[email protected]>

// 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
Expand All @@ -15,12 +15,15 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.



// For more comprehensive information on plugin communication, please refer to the following resource:
// https://npp-user-manual.org/docs/plugin-communication/

#pragma once

#include "Scintilla.h"
#include "Notepad_plus_msgs.h"

const int nbChar = 64;

typedef const TCHAR * (__cdecl * PFUNCGETNAME)();

Expand All @@ -45,19 +48,21 @@ struct ShortcutKey
UCHAR _key = 0;
};

const int menuItemSize = 64;

struct FuncItem
{
FuncItem(const TCHAR* itemName = NULL, PFUNCPLUGINCMD pFunc = NULL,
bool init2Check = false, ShortcutKey* pShKey = NULL) :
_pFunc(pFunc), _init2Check(init2Check), _pShKey(pShKey)
{
if (itemName != NULL)
_tcscpy_s(_itemName, nbChar, itemName);
_tcscpy_s(_itemName, menuItemSize, itemName);
else
_itemName[0] = 0;
}

TCHAR _itemName[nbChar] = { '\0' };
TCHAR _itemName[menuItemSize] = { '\0' };
PFUNCPLUGINCMD _pFunc = nullptr;
int _cmdID = 0;
bool _init2Check = false;
Expand Down
34 changes: 31 additions & 3 deletions src/NppAPI/Scintilla.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,15 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP
#define SCFIND_REGEXP 0x00200000
#define SCFIND_POSIX 0x00400000
#define SCFIND_CXX11REGEX 0x00800000
#define SCI_FINDTEXT 2150

// Deprecated by Notepad++ 2GB+ support via new scintilla interfaces from 5.2.3 (see https://www.scintilla.org/ScintillaHistory.html)
// Please use Sci_Position, SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL, and SCI_FORMATRANGEFULL and corresponding defines/structs
//#define SCI_FINDTEXT 2150
#define SCI_FINDTEXTFULL 2196
#define SCI_FORMATRANGE 2151

// Deprecated by Notepad++ 2GB+ support via new scintilla interfaces from 5.2.3 (see https://www.scintilla.org/ScintillaHistory.html)
// Please use Sci_Position, SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL, and SCI_FORMATRANGEFULL and corresponding defines/structs
//#define SCI_FORMATRANGE 2151
#define SCI_FORMATRANGEFULL 2777
#define SC_CHANGE_HISTORY_DISABLED 0
#define SC_CHANGE_HISTORY_ENABLED 1
Expand All @@ -512,7 +518,10 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP
#define SCI_GETMODIFY 2159
#define SCI_SETSEL 2160
#define SCI_GETSELTEXT 2161
#define SCI_GETTEXTRANGE 2162

// Deprecated by Notepad++ 2GB+ support via new scintilla interfaces from 5.2.3 (see https://www.scintilla.org/ScintillaHistory.html)
// Please use Sci_Position, SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL, and SCI_FORMATRANGEFULL and corresponding defines/structs
//#define SCI_GETTEXTRANGE 2162
#define SCI_GETTEXTRANGEFULL 2039
#define SCI_HIDESELECTION 2163
#define SCI_GETSELECTIONHIDDEN 2088
Expand Down Expand Up @@ -875,7 +884,9 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP
#define SC_SEL_LINES 2
#define SC_SEL_THIN 3
#define SCI_SETSELECTIONMODE 2422
#define SCI_CHANGESELECTIONMODE 2659
#define SCI_GETSELECTIONMODE 2423
#define SCI_SETMOVEEXTENDSSELECTION 2719
#define SCI_GETMOVEEXTENDSSELECTION 2706
#define SCI_GETLINESELSTARTPOSITION 2424
#define SCI_GETLINESELENDPOSITION 2425
Expand Down Expand Up @@ -1021,6 +1032,7 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP
#define SCI_CLEARSELECTIONS 2571
#define SCI_SETSELECTION 2572
#define SCI_ADDSELECTION 2573
#define SCI_SELECTIONFROMPOINT 2474
#define SCI_DROPSELECTIONN 2671
#define SCI_SETMAINSELECTION 2574
#define SCI_GETMAINSELECTION 2575
Expand Down Expand Up @@ -1297,31 +1309,43 @@ typedef sptr_t (*SciFnDirectStatus)(sptr_t ptr, unsigned int iMessage, uptr_t wP
* CHARRANGE, TEXTRANGE, FINDTEXTEX, FORMATRANGE, and NMHDR structs.
* So older code that treats Scintilla as a RichEdit will work. */

// Deprecated by Notepad++ 2GB+ support via new scintilla interfaces from 5.2.3 (see https://www.scintilla.org/ScintillaHistory.html)
// Please use Sci_Position, SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL, and SCI_FORMATRANGEFULL and corresponding defines/structs
/*
struct Sci_CharacterRange {
Sci_PositionCR cpMin;
Sci_PositionCR cpMax;
};
*/

struct Sci_CharacterRangeFull {
Sci_Position cpMin;
Sci_Position cpMax;
};

// Deprecated by Notepad++ 2GB+ support via new scintilla interfaces from 5.2.3 (see https://www.scintilla.org/ScintillaHistory.html)
// Please use Sci_Position, SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL, and SCI_FORMATRANGEFULL and corresponding defines/structs
/*
struct Sci_TextRange {
struct Sci_CharacterRange chrg;
char *lpstrText;
};
*/

struct Sci_TextRangeFull {
struct Sci_CharacterRangeFull chrg;
char *lpstrText;
};

// Deprecated by Notepad++ 2GB+ support via new scintilla interfaces from 5.2.3 (see https://www.scintilla.org/ScintillaHistory.html)
// Please use Sci_Position, SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL, and SCI_FORMATRANGEFULL and corresponding defines/structs
/*
struct Sci_TextToFind {
struct Sci_CharacterRange chrg;
const char *lpstrText;
struct Sci_CharacterRange chrgText;
};
*/

struct Sci_TextToFindFull {
struct Sci_CharacterRangeFull chrg;
Expand All @@ -1341,13 +1365,17 @@ struct Sci_Rectangle {
/* This structure is used in printing and requires some of the graphics types
* from Platform.h. Not needed by most client code. */

// Deprecated by Notepad++ 2GB+ support via new scintilla interfaces from 5.2.3 (see https://www.scintilla.org/ScintillaHistory.html)
// Please use Sci_Position, SCI_GETTEXTRANGEFULL, SCI_FINDTEXTFULL, and SCI_FORMATRANGEFULL and corresponding defines/structs
/*
struct Sci_RangeToFormat {
Sci_SurfaceID hdc;
Sci_SurfaceID hdcTarget;
struct Sci_Rectangle rc;
struct Sci_Rectangle rcPage;
struct Sci_CharacterRange chrg;
};
*/

struct Sci_RangeToFormatFull {
Sci_SurfaceID hdc;
Expand Down
21 changes: 19 additions & 2 deletions src/NppAPI/menuCmdID.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of Notepad++ project
// Copyright (C)2021 Don HO <[email protected]>
// Copyright (C)2024 Don HO <[email protected]>

// 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
Expand Down Expand Up @@ -171,6 +171,16 @@
#define IDM_EDIT_COPY_ALL_NAMES (IDM_EDIT + 87)
#define IDM_EDIT_COPY_ALL_PATHS (IDM_EDIT + 88)
#define IDM_EDIT_BEGINENDSELECT_COLUMNMODE (IDM_EDIT + 89)
#define IDM_EDIT_MULTISELECTALL (IDM_EDIT + 90)
#define IDM_EDIT_MULTISELECTALLMATCHCASE (IDM_EDIT + 91)
#define IDM_EDIT_MULTISELECTALLWHOLEWORD (IDM_EDIT + 92)
#define IDM_EDIT_MULTISELECTALLMATCHCASEWHOLEWORD (IDM_EDIT + 93)
#define IDM_EDIT_MULTISELECTNEXT (IDM_EDIT + 94)
#define IDM_EDIT_MULTISELECTNEXTMATCHCASE (IDM_EDIT + 95)
#define IDM_EDIT_MULTISELECTNEXTWHOLEWORD (IDM_EDIT + 96)
#define IDM_EDIT_MULTISELECTNEXTMATCHCASEWHOLEWORD (IDM_EDIT + 97)
#define IDM_EDIT_MULTISELECTUNDO (IDM_EDIT + 98)
#define IDM_EDIT_MULTISELECTSSKIP (IDM_EDIT + 99)

#define IDM_EDIT_AUTOCOMPLETE (50000 + 0)
#define IDM_EDIT_AUTOCOMPLETE_CURRENTFILE (50000 + 1)
Expand Down Expand Up @@ -251,6 +261,10 @@
#define IDM_SEARCH_MARKONEEXT4 (IDM_SEARCH + 65)
#define IDM_SEARCH_MARKONEEXT5 (IDM_SEARCH + 66)

#define IDM_SEARCH_CHANGED_NEXT (IDM_SEARCH + 67)
#define IDM_SEARCH_CHANGED_PREV (IDM_SEARCH + 68)
#define IDM_SEARCH_CLEAR_CHANGE_HISTORY (IDM_SEARCH + 69)

#define IDM_MISC (IDM + 3500)
#define IDM_DOCLIST_FILESCLOSE (IDM_MISC + 1)
#define IDM_DOCLIST_FILESCLOSEOTHERS (IDM_MISC + 2)
Expand Down Expand Up @@ -374,6 +388,8 @@
#define IDM_VIEW_TAB_COLOUR_3 (IDM_VIEW + 113)
#define IDM_VIEW_TAB_COLOUR_4 (IDM_VIEW + 114)
#define IDM_VIEW_TAB_COLOUR_5 (IDM_VIEW + 115)
#define IDM_VIEW_TAB_START (IDM_VIEW + 116)
#define IDM_VIEW_TAB_END (IDM_VIEW + 117)

#define IDM_VIEW_NPC (IDM_VIEW + 130)
#define IDM_VIEW_NPC_CCUNIEOL (IDM_VIEW + 131)
Expand All @@ -382,7 +398,8 @@
#define IDM_VIEW_CLONE_TO_ANOTHER_VIEW 10002
#define IDM_VIEW_GOTO_NEW_INSTANCE 10003
#define IDM_VIEW_LOAD_IN_NEW_INSTANCE 10004

#define IDM_VIEW_GOTO_START 10005
#define IDM_VIEW_GOTO_END 10006

#define IDM_FORMAT (IDM + 5000)
#define IDM_FORMAT_TODOS (IDM_FORMAT + 1)
Expand Down
28 changes: 14 additions & 14 deletions src/ResultWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ const unsigned ResultWin::cSearchFontSize = 10;
const int ResultWin::cSearchWidth = 420;


ResultWin* ResultWin::RW = NULL;
ResultWin* ResultWin::RW = NULL;
HWND ResultWin::_hSci = NULL;
SciFnDirect ResultWin::_sciFunc = NULL;
sptr_t ResultWin::_sciPtr = 0;


/**
Expand Down Expand Up @@ -816,12 +819,6 @@ ResultWin::~ResultWin()
{
closeAllTabs();

if (_hSci)
{
INpp::Get().DestroySciHandle(_hSci);
_hSci = NULL;
}

SendMessage(_hWnd, WM_CLOSE, 0, 0);
}
}
Expand Down Expand Up @@ -908,11 +905,14 @@ HWND ResultWin::composeWindow()

npp.RegisterWinForDarkMode(_hWnd);

_hSci = npp.CreateSciHandle(_hWnd);
if (_hSci)
if (!_hSci)
{
_sciFunc = (SciFnDirect)::SendMessage(_hSci, SCI_GETDIRECTFUNCTION, 0, 0);
_sciPtr = (sptr_t)::SendMessage(_hSci, SCI_GETDIRECTPOINTER, 0, 0);
_hSci = npp.CreateSciHandle(_hWnd);
if (_hSci)
{
_sciFunc = (SciFnDirect)::SendMessage(_hSci, SCI_GETDIRECTFUNCTION, 0, 0);
_sciPtr = (sptr_t)::SendMessage(_hSci, SCI_GETDIRECTPOINTER, 0, 0);
}
}

if (_hSci == NULL || _sciFunc == NULL || _sciPtr == 0)
Expand Down Expand Up @@ -2083,7 +2083,7 @@ LRESULT CALLBACK ResultWin::keyHookProc(int code, WPARAM wParam, LPARAM lParam)
if (RW->_hSearch)
{
SendMessage(RW->_hSearch, WM_CLOSE, 0, 0);
SetFocus(RW->_hSci);
SetFocus(ResultWin::_hSci);
}
else
{
Expand Down Expand Up @@ -2136,7 +2136,7 @@ LRESULT CALLBACK ResultWin::keyHookProc(int code, WPARAM wParam, LPARAM lParam)
if (wParam == VK_ESCAPE && !shift)
{
SendMessage(RW->_hSearch, WM_CLOSE, 0, 0);
SetFocus(RW->_hSci);
SetFocus(ResultWin::_hSci);
return 1;
}
}
Expand All @@ -2159,7 +2159,7 @@ LRESULT APIENTRY ResultWin::wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM

case WM_SETFOCUS:
RW->hookKeyboard();
SetFocus(RW->_hSci);
SetFocus(ResultWin::_hSci);
return 0;

case WM_NOTIFY:
Expand Down
13 changes: 7 additions & 6 deletions src/ResultWin.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class ResultWin

static HWND GetSciHandleIfFocused()
{
if (RW && GetFocus() == RW->_hSci)
return RW->_hSci;
if (RW && GetFocus() == ResultWin::_hSci)
return ResultWin::_hSci;

return NULL;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ class ResultWin
static LRESULT APIENTRY wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static LRESULT APIENTRY searchWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

ResultWin() : _hWnd(NULL), _hSci(NULL), _hKeyHook(NULL), _sciFunc(NULL), _sciPtr(0), _activeTab(NULL),
ResultWin() : _hWnd(NULL), _hKeyHook(NULL), _activeTab(NULL),
_hSearch(NULL), _hSearchFont(NULL), _hBtnFont(NULL),
_lastRE(false), _lastIC(false), _lastWW(true) {}
ResultWin(const ResultWin&);
Expand Down Expand Up @@ -251,12 +251,13 @@ class ResultWin

static ResultWin* RW;

static HWND _hSci;
static SciFnDirect _sciFunc;
static sptr_t _sciPtr;

HWND _hWnd;
HWND _hSci;
HWND _hTab;
HHOOK _hKeyHook;
SciFnDirect _sciFunc;
sptr_t _sciPtr;
Tab* _activeTab;

HWND _hSearch;
Expand Down

0 comments on commit 00664f1

Please sign in to comment.