From 876bd5c2fa57df56ec33e6c32104791b32f2a36b Mon Sep 17 00:00:00 2001 From: Don Ho Date: Mon, 13 Sep 2010 23:10:24 +0000 Subject: [PATCH] [NEW] (Author: Dave Brotherstone) Add NPPM_ALLOCATECMDID plugin message. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@665 f5eea248-9336-0410-98b8-ebc06183d4e3 --- .../src/MISC/PluginsManager/IDAllocator.cpp | 27 +++++++++++++++++++ .../src/MISC/PluginsManager/IDAllocator.h | 22 +++++++++++++++ .../MISC/PluginsManager/Notepad_plus_msgs.h | 9 +++++++ .../MISC/PluginsManager/PluginsManager.cpp | 15 +++++++++++ .../src/MISC/PluginsManager/PluginsManager.h | 11 ++++++-- PowerEditor/src/NppBigSwitch.cpp | 6 +++++ PowerEditor/src/NppCommands.cpp | 4 +++ PowerEditor/src/resource.h | 2 ++ PowerEditor/visual.net/notepadPlus.vcproj | 10 ++++++- 9 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 PowerEditor/src/MISC/PluginsManager/IDAllocator.cpp create mode 100644 PowerEditor/src/MISC/PluginsManager/IDAllocator.h diff --git a/PowerEditor/src/MISC/PluginsManager/IDAllocator.cpp b/PowerEditor/src/MISC/PluginsManager/IDAllocator.cpp new file mode 100644 index 000000000..743ff10d9 --- /dev/null +++ b/PowerEditor/src/MISC/PluginsManager/IDAllocator.cpp @@ -0,0 +1,27 @@ +// IDAllocator.h code is copyrighted (C) 2010 by Dave Brotherstone +// Part of Notepad++ - Copyright Don Ho +#include "precompiledHeaders.h" + +#include "IDAllocator.h" + +IDAllocator::IDAllocator(int start, int maximumID) + : _start(start), + _nextID(start), + _maximumID(maximumID) +{ +} + +int IDAllocator::allocate(int quantity) +{ + int retVal = -1; + + if (_nextID + quantity <= _maximumID && quantity > 0) + { + retVal = _nextID; + _nextID += quantity; + } + + return retVal; +} + + diff --git a/PowerEditor/src/MISC/PluginsManager/IDAllocator.h b/PowerEditor/src/MISC/PluginsManager/IDAllocator.h new file mode 100644 index 000000000..b72c5aade --- /dev/null +++ b/PowerEditor/src/MISC/PluginsManager/IDAllocator.h @@ -0,0 +1,22 @@ +// IDAllocator.h code is copyrighted (C) 2010 by Dave Brotherstone +// Part of Notepad++ - Copyright Don Ho +#ifndef IDALLOCATOR_H +#define IDALLOCATOR_H + +class IDAllocator +{ +public: + IDAllocator(int start, int maximumID); + + /// Returns -1 if not enough available + int allocate(int quantity); + + bool isInRange(int id) { return (id >= _start && id < _nextID); } + +private: + int _start; + int _nextID; + int _maximumID; +}; + +#endif diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index 6e6039173..a680c5cf2 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -315,7 +315,16 @@ enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV // INT NPPM_GETCURRENTNATIVELANGENCODING(0, 0) // returned value : the current native language enconding + #define NPPM_ALLOCATESUPPORTED (NPPMSG + 80) + // returns TRUE if NPPM_ALLOCATECMDID is supported + // Use to identify if subclassing is necessary + #define NPPM_ALLOCATECMDID (NPPMSG + 81) + // BOOL NPPM_ALLOCATECMDID(int numberRequested, int* startNumber) + // sets startNumber to the initial command ID if successful + // Returns: TRUE if successful, FALSE otherwise. startNumber will also be set to 0 if unsuccessful + + #define RUNCOMMAND_USER (WM_USER + 3000) #define NPPM_GETFULLCURRENTPATH (RUNCOMMAND_USER + FULL_CURRENT_PATH) #define NPPM_GETCURRENTDIRECTORY (RUNCOMMAND_USER + CURRENT_DIRECTORY) diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp index d98e19db5..b672154ef 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp @@ -471,4 +471,19 @@ bool PluginsManager::relayPluginMessages(UINT Message, WPARAM wParam, LPARAM lPa } } return false; +} + + +bool PluginsManager::allocateCmdID(int numberRequired, int *start) +{ + bool retVal = true; + + *start = _dynamicIDAlloc.allocate(numberRequired); + + if (-1 == *start) + { + *start = 0; + retVal = false; + } + return retVal; } \ No newline at end of file diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.h b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h index d482cf66b..615c7dd23 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.h +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h @@ -30,6 +30,10 @@ #include "PluginInterface.h" #endif //PLUGININTERFACE_H +#ifndef IDALLOCATOR_H +#include "IDAllocator.h" +#endif // IDALLOCATOR_H + typedef BOOL (__cdecl * PFUNCISUNICODE)(); struct PluginCommand { @@ -68,7 +72,7 @@ struct PluginInfo { class PluginsManager { public: - PluginsManager() : _hPluginsMenu(NULL), _isDisabled(false) {}; + PluginsManager() : _hPluginsMenu(NULL), _isDisabled(false), _dynamicIDAlloc(ID_PLUGINS_CMD_DYNAMIC, ID_PLUGINS_CMD_DYNAMIC_LIMIT) {}; ~PluginsManager() { for (size_t i = 0 ; i < _pluginInfos.size() ; i++) @@ -104,6 +108,9 @@ public: void disable() {_isDisabled = true;}; bool hasPlugins(){return (_pluginInfos.size()!= 0);}; + bool allocateCmdID(int numberRequired, int *start); + bool inDynamicRange(int id) { return _dynamicIDAlloc.isInRange(id); } + private: NppData _nppData; HMENU _hPluginsMenu; @@ -111,7 +118,7 @@ private: vector _pluginInfos; vector _pluginsCommands; bool _isDisabled; - + IDAllocator _dynamicIDAlloc; void pluginCrashAlert(const TCHAR *pluginName, const TCHAR *funcSignature) { generic_string msg = pluginName; msg += TEXT(" just crash in\r"); diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index b092ca376..c4e77ccc8 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -1596,6 +1596,12 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa return _pluginsManager.relayPluginMessages(Message, wParam, lParam); } + case NPPM_ALLOCATESUPPORTED: + return TRUE; + + case NPPM_ALLOCATECMDID: + return _pluginsManager.allocateCmdID(wParam, reinterpret_cast(lParam)); + case NPPM_HIDETABBAR : { bool hide = (lParam != 0); diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 13701084e..7dffb2471 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -1906,6 +1906,10 @@ void Notepad_plus::command(int id) int i = id - ID_PLUGINS_CMD; _pluginsManager.runPluginCommand(i); } + else if (_pluginsManager.inDynamicRange(id)) // in the dynamic range allocated with NPPM_ALLOCATECMDID + { + _pluginsManager.relayNppMessages(WM_COMMAND, id, 0); + } /*UNLOAD else if ((id >= ID_PLUGINS_REMOVING) && (id < ID_PLUGINS_REMOVING_END)) { diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index e5b182526..fa04b5c95 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -176,6 +176,8 @@ #define ID_PLUGINS_CMD 22000 #define ID_PLUGINS_CMD_LIMIT 22500 +#define ID_PLUGINS_CMD_DYNAMIC 23000 +#define ID_PLUGINS_CMD_DYNAMIC_LIMIT 24999 /*UNLOAD #define ID_PLUGINS_REMOVING 22501 #define ID_PLUGINS_REMOVING_END 22600 diff --git a/PowerEditor/visual.net/notepadPlus.vcproj b/PowerEditor/visual.net/notepadPlus.vcproj index 75c4ff1b6..57afd4cdf 100644 --- a/PowerEditor/visual.net/notepadPlus.vcproj +++ b/PowerEditor/visual.net/notepadPlus.vcproj @@ -1,7 +1,7 @@ + + @@ -807,6 +811,10 @@ RelativePath="..\src\WinControls\DockingWnd\Gripper.h" > + +