diff options
author | Goraf <22941576+Goraf@users.noreply.github.com> | 2017-11-03 15:13:56 +0100 |
---|---|---|
committer | Goraf <22941576+Goraf@users.noreply.github.com> | 2017-11-03 15:24:23 +0100 |
commit | 1b1e6455fa79f2f6993115f9afbb506a5f93e315 (patch) | |
tree | 9077992b8390fa5eea6870a4b18ad3f2d74cce6e /plugins/StartPosition | |
parent | 60db7dc0f88ccbff13e5bc8a7fcf2f20e4905ea9 (diff) |
StartPostion: use base class
* rewrite using classes
* reduce globals
* remove obsolete headers
* code cleaning
Diffstat (limited to 'plugins/StartPosition')
-rw-r--r-- | plugins/StartPosition/src/main.cpp | 75 | ||||
-rw-r--r-- | plugins/StartPosition/src/options.cpp | 54 | ||||
-rw-r--r-- | plugins/StartPosition/src/options.h | 4 | ||||
-rw-r--r-- | plugins/StartPosition/src/startposition.cpp | 57 | ||||
-rw-r--r-- | plugins/StartPosition/src/startposition.h | 34 | ||||
-rw-r--r-- | plugins/StartPosition/src/stdafx.cxx | 2 | ||||
-rw-r--r-- | plugins/StartPosition/src/stdafx.h | 11 | ||||
-rw-r--r-- | plugins/StartPosition/src/version.h | 2 |
8 files changed, 142 insertions, 97 deletions
diff --git a/plugins/StartPosition/src/main.cpp b/plugins/StartPosition/src/main.cpp index 8965ccffdb..1302faac10 100644 --- a/plugins/StartPosition/src/main.cpp +++ b/plugins/StartPosition/src/main.cpp @@ -23,77 +23,50 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h"
+
HINSTANCE g_hInst;
int hLangpack;
-StartPositionOptions spOptions;
-ClistOptions clOptions;
+StartPositionPlugin* startposition;
PLUGININFOEX pluginInfo = {
- sizeof(PLUGININFOEX),
- __PLUGIN_NAME,
- PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
- __DESCRIPTION,
- __AUTHOR,
- __AUTHOREMAIL,
- __COPYRIGHT,
- __AUTHORWEB,
- UNICODE_AWARE,
- // {211F6277-6F9B-4B77-A939-84D04B26B38C}
- {0x211f6277, 0x6f9b, 0x4b77, {0xa9, 0x39, 0x84, 0xd0, 0x4b, 0x26, 0xb3, 0x8c}}
+ sizeof(PLUGININFOEX),
+ __PLUGIN_NAME,
+ PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
+ __DESCRIPTION,
+ __AUTHOR,
+ __AUTHOREMAIL,
+ __COPYRIGHT,
+ __AUTHORWEB,
+ UNICODE_AWARE,
+ // {211F6277-6F9B-4B77-A939-84D04B26B38C}
+ {0x211f6277, 0x6f9b, 0x4b77, {0xa9, 0x39, 0x84, 0xd0, 0x4b, 0x26, 0xb3, 0x8c}}
};
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID)
{
- g_hInst = hinstDLL;
- return TRUE;
+ g_hInst = hinstDLL;
+ return TRUE;
}
extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
{
- return &pluginInfo;
+ return &pluginInfo;
}
extern "C" __declspec(dllexport) int Load(void)
{
- mir_getLP(&pluginInfo);
-
- RECT WorkArea;
- SystemParametersInfo(SPI_GETWORKAREA, 0, &WorkArea, 0);
-
- 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;
+ mir_getLP(&pluginInfo);
+ startposition = new StartPositionPlugin;
- if (spOptions.setTopPosition)
- clOptions.y = static_cast<DWORD>(spOptions.pixelsFromTop);
+ startposition->positionClist();
- 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;
- }
-
- HookEvent(ME_OPT_INITIALISE, OptInitialise);
-
- return 0;
+ return 0;
}
extern "C" __declspec(dllexport) int Unload(void)
{
- return 0;
+ delete startposition;
+ startposition = nullptr;
+
+ return 0;
}
diff --git a/plugins/StartPosition/src/options.cpp b/plugins/StartPosition/src/options.cpp index 66dc633ea9..da33fc6ef3 100644 --- a/plugins/StartPosition/src/options.cpp +++ b/plugins/StartPosition/src/options.cpp @@ -15,10 +15,9 @@ StartPositionOptions::StartPositionOptions() : clistWidth(MODULE_NAME, "CLWidth", 180) {} -extern StartPositionOptions spOptions; - -COptionsDlg::COptionsDlg() : +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), @@ -33,16 +32,16 @@ COptionsDlg::COptionsDlg() : chkStartHidden(this, IDC_CLSTATETRAY), chkStartNormal(this, IDC_CLSTATEOPENED) { - CreateLink(chkPositionTop, spOptions.setTopPosition); - CreateLink(chkPositionBottom, spOptions.setBottomPosition); - CreateLink(chkPositionSide, spOptions.setSidePosition); - CreateLink(chkWidth, spOptions.setClistWidth); - CreateLink(chkStartState, spOptions.setClistStartState); + 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, spOptions.pixelsFromTop); - CreateLink(edtPositionBottom, spOptions.pixelsFromBottom); - CreateLink(edtPositionSide, spOptions.pixelsFromSide); - CreateLink(edtWidth, spOptions.clistWidth); + 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); @@ -53,7 +52,7 @@ COptionsDlg::COptionsDlg() : void COptionsDlg::OnInitDialog() { - if (spOptions.clistState == ClistState::normal) + if (m_plugin->spOptions.clistState == ClistState::normal) chkStartNormal.SetState(true); else chkStartHidden.SetState(true); @@ -61,7 +60,7 @@ void COptionsDlg::OnInitDialog() chkStartHidden.Enable(chkStartState.GetState()); chkStartNormal.Enable(chkStartState.GetState()); - if (spOptions.clistAlign == ClistAlign::right) + if (m_plugin->spOptions.clistAlign == ClistAlign::right) chkFromRight.SetState(true); else chkFromLeft.SetState(true); @@ -80,23 +79,20 @@ void COptionsDlg::OnApply() removeOldSettings(); if (chkStartNormal.GetState()) - spOptions.clistState = ClistState::normal; + m_plugin->spOptions.clistState = ClistState::normal; else - spOptions.clistState = ClistState::hidden; + m_plugin->spOptions.clistState = ClistState::hidden; if (chkFromRight.GetState()) - spOptions.clistAlign = ClistAlign::right; + m_plugin->spOptions.clistAlign = ClistAlign::right; else - spOptions.clistAlign = ClistAlign::left; + m_plugin->spOptions.clistAlign = ClistAlign::left; } void COptionsDlg::removeOldSettings() { - if (db_get_b(0, MODULE_NAME, "CLEnableTop", dbERROR) == dbERROR) - { - db_unset(0, MODULE_NAME, "CLEnable"); - db_unset(0, MODULE_NAME, "CLuseLastWidth"); - } + m_plugin->delSetting("CLEnable"); + m_plugin->delSetting("CLuseLastWidth"); } void COptionsDlg::onCheck_PositionTop(CCtrlCheck*) @@ -126,15 +122,3 @@ void COptionsDlg::onCheck_StartState(CCtrlCheck*) chkStartHidden.Enable(chkStartState.GetState()); chkStartNormal.Enable(chkStartState.GetState()); } - -int OptInitialise(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; - odp.flags = ODPF_BOLDGROUPS; - Options_AddPage(wParam, &odp); - return 0; -} diff --git a/plugins/StartPosition/src/options.h b/plugins/StartPosition/src/options.h index 8066cddbf7..43d4a1d678 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(); + COptionsDlg(StartPositionPlugin* instance); virtual void OnInitDialog() override; virtual void OnApply() override; @@ -90,4 +90,6 @@ 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 new file mode 100644 index 0000000000..3f661f9f96 --- /dev/null +++ b/plugins/StartPosition/src/startposition.cpp @@ -0,0 +1,57 @@ +#include "stdafx.h" + + +StartPositionPlugin::StartPositionPlugin() : + PLUGIN<StartPositionPlugin>(MODULE_NAME) +{ + HookPluginEvent(ME_OPT_INITIALISE, &StartPositionPlugin::OnOptionsInit); +} + +void StartPositionPlugin::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; + } +} + +int StartPositionPlugin::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; +} diff --git a/plugins/StartPosition/src/startposition.h b/plugins/StartPosition/src/startposition.h new file mode 100644 index 0000000000..85453eacb2 --- /dev/null +++ b/plugins/StartPosition/src/startposition.h @@ -0,0 +1,34 @@ +/* +Copyright (C) 2012-17 Miranda NG project (https://miranda-ng.org) + +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 the Free Software Foundation version 2 +of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once + +#include "stdafx.h" + + +class StartPositionPlugin : public PLUGIN<StartPositionPlugin> +{ + friend COptionsDlg; + +public: + StartPositionPlugin(); + + int __cdecl OnOptionsInit(WPARAM, LPARAM); + void positionClist(); + + StartPositionOptions spOptions; +}; diff --git a/plugins/StartPosition/src/stdafx.cxx b/plugins/StartPosition/src/stdafx.cxx index b05ed73bc5..e0372ed6dc 100644 --- a/plugins/StartPosition/src/stdafx.cxx +++ b/plugins/StartPosition/src/stdafx.cxx @@ -15,4 +15,4 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "stdafx.h"
\ No newline at end of file +#include "stdafx.h"
diff --git a/plugins/StartPosition/src/stdafx.h b/plugins/StartPosition/src/stdafx.h index 27bef6bf2c..7b79fb2734 100644 --- a/plugins/StartPosition/src/stdafx.h +++ b/plugins/StartPosition/src/stdafx.h @@ -25,11 +25,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <windows.h>
#include <newpluginapi.h>
-#include <m_database.h>
#include <m_gui.h>
#include <m_langpack.h>
#include <m_options.h>
-#include <m_utils.h>
+#include <m_plugin.h>
#include "resource.h"
#include "version.h"
@@ -39,10 +38,6 @@ extern HINSTANCE g_hInst; #define MODULE_NAME "StartPosition"
#define CLIST_MODULE_NAME "CList"
-#define dbERROR -999999
-#define RIGHT 1
-#define LEFT 0
-
+class StartPositionPlugin;
#include "options.h"
-
-extern int OptInitialise(WPARAM wParam, LPARAM);
+#include "startposition.h"
diff --git a/plugins/StartPosition/src/version.h b/plugins/StartPosition/src/version.h index 4fd0f5a272..9adb18869b 100644 --- a/plugins/StartPosition/src/version.h +++ b/plugins/StartPosition/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 3 #define __RELEASE_NUM 0 -#define __BUILD_NUM 3 +#define __BUILD_NUM 4 #include <stdver.h> |