summaryrefslogtreecommitdiff
path: root/plugins/StartPosition
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-04-18 18:14:33 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-04-18 18:14:33 +0300
commitb172c4bbc75cdad0e8ccd22292aa671ba43cac45 (patch)
tree4677a04a47f3987c88f3fb44c6b70d2642b1f8a3 /plugins/StartPosition
parent524d1c7186eca3f0a4da08548eeb919785227101 (diff)
PLUGIN<> to half-automatically calculate the dll's g_hInstance and pass it inside
Diffstat (limited to 'plugins/StartPosition')
-rw-r--r--plugins/StartPosition/src/main.cpp27
-rw-r--r--plugins/StartPosition/src/options.cpp169
-rw-r--r--plugins/StartPosition/src/options.h4
-rw-r--r--plugins/StartPosition/src/startposition.cpp93
-rw-r--r--plugins/StartPosition/src/startposition.h13
-rw-r--r--plugins/StartPosition/src/stdafx.h3
6 files changed, 147 insertions, 162 deletions
diff --git a/plugins/StartPosition/src/main.cpp b/plugins/StartPosition/src/main.cpp
index 24ae37c529..e802790da2 100644
--- a/plugins/StartPosition/src/main.cpp
+++ b/plugins/StartPosition/src/main.cpp
@@ -23,10 +23,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
-
-HINSTANCE g_hInst;
+CMPlugin g_plugin;
+HINSTANCE g_hInstance;
int hLangpack;
-StartPositionPlugin* startposition;
PLUGININFOEX pluginInfo = {
sizeof(PLUGININFOEX),
@@ -41,31 +40,23 @@ PLUGININFOEX pluginInfo = {
{0x211f6277, 0x6f9b, 0x4b77, {0xa9, 0x39, 0x84, 0xd0, 0x4b, 0x26, 0xb3, 0x8c}}
};
-BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID)
-{
- g_hInst = hinstDLL;
- return TRUE;
-}
-
extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
{
- return &pluginInfo;
+ return &pluginInfo;
}
+extern "C" _pfnCrtInit _pRawDllMain = &CMPlugin::RawDllMain;
+
extern "C" __declspec(dllexport) int Load(void)
{
- mir_getLP(&pluginInfo);
- startposition = new StartPositionPlugin;
+ mir_getLP(&pluginInfo);
- startposition->positionClist();
+ g_plugin.positionClist();
- return 0;
+ return 0;
}
extern "C" __declspec(dllexport) int Unload(void)
{
- delete startposition;
- startposition = nullptr;
-
- return 0;
+ return 0;
}
diff --git a/plugins/StartPosition/src/options.cpp b/plugins/StartPosition/src/options.cpp
index da33fc6ef3..f797c1d030 100644
--- a/plugins/StartPosition/src/options.cpp
+++ b/plugins/StartPosition/src/options.cpp
@@ -1,124 +1,123 @@
#include "stdafx.h"
-
StartPositionOptions::StartPositionOptions() :
- setTopPosition(MODULE_NAME, "CLEnableTop", 1),
- setBottomPosition(MODULE_NAME, "CLEnableBottom", 0),
- setSidePosition(MODULE_NAME, "CLEnableSide", 1),
- clistAlign(MODULE_NAME, "CLAlign", ClistAlign::right),
- setClistWidth(MODULE_NAME, "CLEnableWidth", 0),
- setClistStartState(MODULE_NAME, "CLEnableState", 0),
- clistState(MODULE_NAME, "CLState", ClistState::normal),
- pixelsFromTop(MODULE_NAME, "CLpixelsTop", 3),
- pixelsFromBottom(MODULE_NAME, "CLpixelsBottom", 3),
- pixelsFromSide(MODULE_NAME, "CLpixelsSide", 3),
- clistWidth(MODULE_NAME, "CLWidth", 180)
-{}
-
-COptionsDlg::COptionsDlg(StartPositionPlugin* instance) :
- CPluginDlgBase(g_hInst, IDD_OPTIONS, MODULE_NAME),
- m_plugin(instance),
- chkPositionTop(this, IDC_CLTOPENABLE),
- edtPositionTop(this, IDC_CLTOP),
- chkPositionBottom(this, IDC_CLBOTTOMENABLE),
- edtPositionBottom(this, IDC_CLBOTTOM),
- chkPositionSide(this, IDC_CLSIDEENABLE),
- edtPositionSide(this, IDC_CLSIDE),
- chkFromLeft(this, IDC_CLALIGNLEFT),
- chkFromRight(this, IDC_CLALIGNRIGHT),
- chkWidth(this, IDC_CLWIDTHENABLE),
- edtWidth(this, IDC_CLWIDTH),
- chkStartState(this, IDC_CLSTATEENABLE),
- chkStartHidden(this, IDC_CLSTATETRAY),
- chkStartNormal(this, IDC_CLSTATEOPENED)
+ setTopPosition(MODULE_NAME, "CLEnableTop", 1),
+ setBottomPosition(MODULE_NAME, "CLEnableBottom", 0),
+ setSidePosition(MODULE_NAME, "CLEnableSide", 1),
+ clistAlign(MODULE_NAME, "CLAlign", ClistAlign::right),
+ setClistWidth(MODULE_NAME, "CLEnableWidth", 0),
+ setClistStartState(MODULE_NAME, "CLEnableState", 0),
+ clistState(MODULE_NAME, "CLState", ClistState::normal),
+ pixelsFromTop(MODULE_NAME, "CLpixelsTop", 3),
+ pixelsFromBottom(MODULE_NAME, "CLpixelsBottom", 3),
+ pixelsFromSide(MODULE_NAME, "CLpixelsSide", 3),
+ clistWidth(MODULE_NAME, "CLWidth", 180)
+{
+}
+
+COptionsDlg::COptionsDlg() :
+ CPluginDlgBase(g_hInstance, IDD_OPTIONS, MODULE_NAME),
+ chkPositionTop(this, IDC_CLTOPENABLE),
+ edtPositionTop(this, IDC_CLTOP),
+ chkPositionBottom(this, IDC_CLBOTTOMENABLE),
+ edtPositionBottom(this, IDC_CLBOTTOM),
+ chkPositionSide(this, IDC_CLSIDEENABLE),
+ edtPositionSide(this, IDC_CLSIDE),
+ chkFromLeft(this, IDC_CLALIGNLEFT),
+ chkFromRight(this, IDC_CLALIGNRIGHT),
+ chkWidth(this, IDC_CLWIDTHENABLE),
+ edtWidth(this, IDC_CLWIDTH),
+ chkStartState(this, IDC_CLSTATEENABLE),
+ chkStartHidden(this, IDC_CLSTATETRAY),
+ chkStartNormal(this, IDC_CLSTATEOPENED)
{
- CreateLink(chkPositionTop, m_plugin->spOptions.setTopPosition);
- CreateLink(chkPositionBottom, m_plugin->spOptions.setBottomPosition);
- CreateLink(chkPositionSide, m_plugin->spOptions.setSidePosition);
- CreateLink(chkWidth, m_plugin->spOptions.setClistWidth);
- CreateLink(chkStartState, m_plugin->spOptions.setClistStartState);
-
- CreateLink(edtPositionTop, m_plugin->spOptions.pixelsFromTop);
- CreateLink(edtPositionBottom, m_plugin->spOptions.pixelsFromBottom);
- CreateLink(edtPositionSide, m_plugin->spOptions.pixelsFromSide);
- CreateLink(edtWidth, m_plugin->spOptions.clistWidth);
-
- chkPositionTop.OnChange = Callback(this, &COptionsDlg::onCheck_PositionTop);
- chkPositionBottom.OnChange = Callback(this, &COptionsDlg::onCheck_PositionBottom);
- chkPositionSide.OnChange = Callback(this, &COptionsDlg::onCheck_PositionSide);
- chkWidth.OnChange = Callback(this, &COptionsDlg::onCheck_Width);
- chkStartState.OnChange = Callback(this, &COptionsDlg::onCheck_StartState);
+ CreateLink(chkPositionTop, g_plugin.spOptions.setTopPosition);
+ CreateLink(chkPositionBottom, g_plugin.spOptions.setBottomPosition);
+ CreateLink(chkPositionSide, g_plugin.spOptions.setSidePosition);
+ CreateLink(chkWidth, g_plugin.spOptions.setClistWidth);
+ CreateLink(chkStartState, g_plugin.spOptions.setClistStartState);
+
+ CreateLink(edtPositionTop, g_plugin.spOptions.pixelsFromTop);
+ CreateLink(edtPositionBottom, g_plugin.spOptions.pixelsFromBottom);
+ CreateLink(edtPositionSide, g_plugin.spOptions.pixelsFromSide);
+ CreateLink(edtWidth, g_plugin.spOptions.clistWidth);
+
+ chkPositionTop.OnChange = Callback(this, &COptionsDlg::onCheck_PositionTop);
+ chkPositionBottom.OnChange = Callback(this, &COptionsDlg::onCheck_PositionBottom);
+ chkPositionSide.OnChange = Callback(this, &COptionsDlg::onCheck_PositionSide);
+ chkWidth.OnChange = Callback(this, &COptionsDlg::onCheck_Width);
+ chkStartState.OnChange = Callback(this, &COptionsDlg::onCheck_StartState);
}
void COptionsDlg::OnInitDialog()
{
- if (m_plugin->spOptions.clistState == ClistState::normal)
- chkStartNormal.SetState(true);
- else
- chkStartHidden.SetState(true);
-
- chkStartHidden.Enable(chkStartState.GetState());
- chkStartNormal.Enable(chkStartState.GetState());
-
- if (m_plugin->spOptions.clistAlign == ClistAlign::right)
- chkFromRight.SetState(true);
- else
- chkFromLeft.SetState(true);
-
- chkFromLeft.Enable(chkPositionSide.GetState());
- chkFromRight.Enable(chkPositionSide.GetState());
-
- edtPositionTop.Enable(chkPositionTop.GetState());
- edtPositionBottom.Enable(chkPositionBottom.GetState());
- edtPositionSide.Enable(chkPositionSide.GetState());
- edtWidth.Enable(chkWidth.GetState());
+ if (g_plugin.spOptions.clistState == ClistState::normal)
+ chkStartNormal.SetState(true);
+ else
+ chkStartHidden.SetState(true);
+
+ chkStartHidden.Enable(chkStartState.GetState());
+ chkStartNormal.Enable(chkStartState.GetState());
+
+ if (g_plugin.spOptions.clistAlign == ClistAlign::right)
+ chkFromRight.SetState(true);
+ else
+ chkFromLeft.SetState(true);
+
+ chkFromLeft.Enable(chkPositionSide.GetState());
+ chkFromRight.Enable(chkPositionSide.GetState());
+
+ edtPositionTop.Enable(chkPositionTop.GetState());
+ edtPositionBottom.Enable(chkPositionBottom.GetState());
+ edtPositionSide.Enable(chkPositionSide.GetState());
+ edtWidth.Enable(chkWidth.GetState());
}
void COptionsDlg::OnApply()
{
- removeOldSettings();
+ removeOldSettings();
- if (chkStartNormal.GetState())
- m_plugin->spOptions.clistState = ClistState::normal;
- else
- m_plugin->spOptions.clistState = ClistState::hidden;
+ if (chkStartNormal.GetState())
+ g_plugin.spOptions.clistState = ClistState::normal;
+ else
+ g_plugin.spOptions.clistState = ClistState::hidden;
- if (chkFromRight.GetState())
- m_plugin->spOptions.clistAlign = ClistAlign::right;
- else
- m_plugin->spOptions.clistAlign = ClistAlign::left;
+ if (chkFromRight.GetState())
+ g_plugin.spOptions.clistAlign = ClistAlign::right;
+ else
+ g_plugin.spOptions.clistAlign = ClistAlign::left;
}
void COptionsDlg::removeOldSettings()
{
- m_plugin->delSetting("CLEnable");
- m_plugin->delSetting("CLuseLastWidth");
+ g_plugin.delSetting("CLEnable");
+ g_plugin.delSetting("CLuseLastWidth");
}
void COptionsDlg::onCheck_PositionTop(CCtrlCheck*)
{
- edtPositionTop.Enable(chkPositionTop.GetState());
+ edtPositionTop.Enable(chkPositionTop.GetState());
}
void COptionsDlg::onCheck_PositionBottom(CCtrlCheck*)
{
- edtPositionBottom.Enable(chkPositionBottom.GetState());
+ edtPositionBottom.Enable(chkPositionBottom.GetState());
}
void COptionsDlg::onCheck_PositionSide(CCtrlCheck*)
{
- edtPositionSide.Enable(chkPositionSide.GetState());
- chkFromLeft.Enable(chkPositionSide.GetState());
- chkFromRight.Enable(chkPositionSide.GetState());
+ edtPositionSide.Enable(chkPositionSide.GetState());
+ chkFromLeft.Enable(chkPositionSide.GetState());
+ chkFromRight.Enable(chkPositionSide.GetState());
}
void COptionsDlg::onCheck_Width(CCtrlCheck*)
{
- edtWidth.Enable(chkWidth.GetState());
+ edtWidth.Enable(chkWidth.GetState());
}
void COptionsDlg::onCheck_StartState(CCtrlCheck*)
{
- chkStartHidden.Enable(chkStartState.GetState());
- chkStartNormal.Enable(chkStartState.GetState());
+ chkStartHidden.Enable(chkStartState.GetState());
+ chkStartNormal.Enable(chkStartState.GetState());
}
diff --git a/plugins/StartPosition/src/options.h b/plugins/StartPosition/src/options.h
index 9208157f24..ed3dcfb5f3 100644
--- a/plugins/StartPosition/src/options.h
+++ b/plugins/StartPosition/src/options.h
@@ -77,7 +77,7 @@ class COptionsDlg : public CPluginDlgBase
CCtrlCheck chkStartState, chkStartHidden, chkStartNormal;
public:
- COptionsDlg(StartPositionPlugin* instance);
+ COptionsDlg();
void OnInitDialog() override;
void OnApply() override;
@@ -90,6 +90,4 @@ private:
void onCheck_PositionSide(CCtrlCheck*);
void onCheck_Width(CCtrlCheck*);
void onCheck_StartState(CCtrlCheck*);
-
- StartPositionPlugin* m_plugin;
};
diff --git a/plugins/StartPosition/src/startposition.cpp b/plugins/StartPosition/src/startposition.cpp
index 3f661f9f96..26c845b5ca 100644
--- a/plugins/StartPosition/src/startposition.cpp
+++ b/plugins/StartPosition/src/startposition.cpp
@@ -1,57 +1,56 @@
#include "stdafx.h"
-
-StartPositionPlugin::StartPositionPlugin() :
- PLUGIN<StartPositionPlugin>(MODULE_NAME)
+CMPlugin::CMPlugin() :
+ PLUGIN<CMPlugin>(MODULE_NAME)
{
- HookPluginEvent(ME_OPT_INITIALISE, &StartPositionPlugin::OnOptionsInit);
+ HookPluginEvent(ME_OPT_INITIALISE, &CMPlugin::OnOptionsInit);
}
-void StartPositionPlugin::positionClist()
+void CMPlugin::positionClist()
{
- ClistOptions clOptions;
-
- if (spOptions.setClistStartState)
- clOptions.state = static_cast<BYTE>(spOptions.clistState);
-
- if (spOptions.setClistWidth && spOptions.clistWidth > 0)
- clOptions.width = static_cast<DWORD>(spOptions.clistWidth);
- else
- spOptions.clistWidth = static_cast<DWORD>(clOptions.width);
-
- if (spOptions.setTopPosition || spOptions.setBottomPosition || spOptions.setSidePosition)
- clOptions.isDocked = false;
-
- if (spOptions.setTopPosition)
- clOptions.y = static_cast<DWORD>(spOptions.pixelsFromTop);
-
- RECT WorkArea;
- SystemParametersInfo(SPI_GETWORKAREA, 0, &WorkArea, 0);
-
- if (spOptions.setBottomPosition) {
- if (spOptions.setTopPosition)
- clOptions.height = WorkArea.bottom - WorkArea.top - spOptions.pixelsFromTop - spOptions.pixelsFromBottom;
- else
- clOptions.y = WorkArea.bottom - spOptions.pixelsFromBottom - clOptions.height;
- }
-
- if (spOptions.setSidePosition) {
- if (spOptions.clistAlign == ClistAlign::right)
- clOptions.x = WorkArea.right - spOptions.clistWidth - spOptions.pixelsFromSide;
- else
- clOptions.x = WorkArea.left + spOptions.pixelsFromSide;
- }
+ ClistOptions clOptions;
+
+ if (spOptions.setClistStartState)
+ clOptions.state = static_cast<BYTE>(spOptions.clistState);
+
+ if (spOptions.setClistWidth && spOptions.clistWidth > 0)
+ clOptions.width = static_cast<DWORD>(spOptions.clistWidth);
+ else
+ spOptions.clistWidth = static_cast<DWORD>(clOptions.width);
+
+ if (spOptions.setTopPosition || spOptions.setBottomPosition || spOptions.setSidePosition)
+ clOptions.isDocked = false;
+
+ if (spOptions.setTopPosition)
+ clOptions.y = static_cast<DWORD>(spOptions.pixelsFromTop);
+
+ RECT WorkArea;
+ SystemParametersInfo(SPI_GETWORKAREA, 0, &WorkArea, 0);
+
+ if (spOptions.setBottomPosition) {
+ if (spOptions.setTopPosition)
+ clOptions.height = WorkArea.bottom - WorkArea.top - spOptions.pixelsFromTop - spOptions.pixelsFromBottom;
+ else
+ clOptions.y = WorkArea.bottom - spOptions.pixelsFromBottom - clOptions.height;
+ }
+
+ if (spOptions.setSidePosition) {
+ if (spOptions.clistAlign == ClistAlign::right)
+ clOptions.x = WorkArea.right - spOptions.clistWidth - spOptions.pixelsFromSide;
+ else
+ clOptions.x = WorkArea.left + spOptions.pixelsFromSide;
+ }
}
-int StartPositionPlugin::OnOptionsInit(WPARAM wParam, LPARAM)
+int CMPlugin::OnOptionsInit(WPARAM wParam, LPARAM)
{
- OPTIONSDIALOGPAGE odp = {};
- odp.hInstance = g_hInst;
- odp.szGroup.a = LPGEN("Contact list");
- odp.szTitle.a = LPGEN("Start position");
- odp.pDialog = new COptionsDlg(this);
- odp.flags = ODPF_BOLDGROUPS;
- Options_AddPage(wParam, &odp);
-
- return 0;
+ OPTIONSDIALOGPAGE odp = {};
+ odp.hInstance = g_hInstance;
+ odp.szGroup.a = LPGEN("Contact list");
+ odp.szTitle.a = LPGEN("Start position");
+ odp.pDialog = new COptionsDlg();
+ odp.flags = ODPF_BOLDGROUPS;
+ Options_AddPage(wParam, &odp);
+
+ return 0;
}
diff --git a/plugins/StartPosition/src/startposition.h b/plugins/StartPosition/src/startposition.h
index b4ce8dc896..fe5235e521 100644
--- a/plugins/StartPosition/src/startposition.h
+++ b/plugins/StartPosition/src/startposition.h
@@ -19,16 +19,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
-
-class StartPositionPlugin : public PLUGIN<StartPositionPlugin>
+class CMPlugin : public PLUGIN<CMPlugin>
{
- friend COptionsDlg;
+ friend COptionsDlg;
public:
- StartPositionPlugin();
+ CMPlugin();
- int __cdecl OnOptionsInit(WPARAM, LPARAM);
- void positionClist();
+ int __cdecl OnOptionsInit(WPARAM, LPARAM);
+ void positionClist();
- StartPositionOptions spOptions;
+ StartPositionOptions spOptions;
};
diff --git a/plugins/StartPosition/src/stdafx.h b/plugins/StartPosition/src/stdafx.h
index 5ecea86a97..a4995fad9b 100644
--- a/plugins/StartPosition/src/stdafx.h
+++ b/plugins/StartPosition/src/stdafx.h
@@ -33,11 +33,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "resource.h"
#include "version.h"
-extern HINSTANCE g_hInst;
+extern HINSTANCE g_hInstance;
#define MODULE_NAME "StartPosition"
#define CLIST_MODULE_NAME "CList"
-class StartPositionPlugin;
#include "options.h"
#include "startposition.h"