[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
This commit is contained in:
parent
c2702447ff
commit
876bd5c2fa
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -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
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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<PluginInfo *> _pluginInfos;
|
||||
vector<PluginCommand> _pluginsCommands;
|
||||
bool _isDisabled;
|
||||
|
||||
IDAllocator _dynamicIDAlloc;
|
||||
void pluginCrashAlert(const TCHAR *pluginName, const TCHAR *funcSignature) {
|
||||
generic_string msg = pluginName;
|
||||
msg += TEXT(" just crash in\r");
|
||||
|
|
|
@ -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<int *>(lParam));
|
||||
|
||||
case NPPM_HIDETABBAR :
|
||||
{
|
||||
bool hide = (lParam != 0);
|
||||
|
|
|
@ -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))
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8,00"
|
||||
Version="8.00"
|
||||
Name="Notepad++"
|
||||
ProjectGUID="{FCF60E65-1B78-4D1D-AB59-4FC00AC8C248}"
|
||||
RootNamespace="Notepad++"
|
||||
|
@ -478,6 +478,10 @@
|
|||
RelativePath="..\src\WinControls\DockingWnd\Gripper.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\src\MISC\PluginsManager\IDAllocator.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\src\WinControls\ImageListSet\ImageListSet.cpp"
|
||||
>
|
||||
|
@ -807,6 +811,10 @@
|
|||
RelativePath="..\src\WinControls\DockingWnd\Gripper.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\src\MISC\PluginsManager\IDAllocator.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\src\WinControls\ImageListSet\ImageListSet.h"
|
||||
>
|
||||
|
|
Loading…
Reference in New Issue