diff options
author | Goraf <22941576+Goraf@users.noreply.github.com> | 2017-09-25 13:51:41 +0200 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-09-25 14:51:41 +0300 |
commit | cf0855b36f260ea19c96e43e99f94988f81dcf12 (patch) | |
tree | 89096fa83fdd88741e5776e7d762988137942bb2 /plugins/AsSingleWindow/src | |
parent | d701a30b0f6c15241293a483fa3df95e5ce37efb (diff) |
AsSingleWindow: make it working (#941)
* AsSingleWindow: remove interfaces to be able to load plugin
* AsSingleWindow: fix saving options
* AsSingleWindow: remove unnecessary handles
* AsSingleWindow: code cleaning
* AsSingleWindow: move plugin info to separate version.h
Diffstat (limited to 'plugins/AsSingleWindow/src')
-rw-r--r-- | plugins/AsSingleWindow/src/AsSingleWindow.cpp | 44 | ||||
-rw-r--r-- | plugins/AsSingleWindow/src/AsSingleWindow.h | 11 | ||||
-rw-r--r-- | plugins/AsSingleWindow/src/Options.cpp | 59 | ||||
-rw-r--r-- | plugins/AsSingleWindow/src/Options.h | 17 | ||||
-rw-r--r-- | plugins/AsSingleWindow/src/WindowsManager.cpp | 205 | ||||
-rw-r--r-- | plugins/AsSingleWindow/src/WindowsManager.h | 7 | ||||
-rw-r--r-- | plugins/AsSingleWindow/src/stdafx.cxx | 2 | ||||
-rw-r--r-- | plugins/AsSingleWindow/src/stdafx.h | 4 | ||||
-rw-r--r-- | plugins/AsSingleWindow/src/version.h | 14 |
9 files changed, 172 insertions, 191 deletions
diff --git a/plugins/AsSingleWindow/src/AsSingleWindow.cpp b/plugins/AsSingleWindow/src/AsSingleWindow.cpp index ef96b0e7f3..f4fd623e24 100644 --- a/plugins/AsSingleWindow/src/AsSingleWindow.cpp +++ b/plugins/AsSingleWindow/src/AsSingleWindow.cpp @@ -2,19 +2,20 @@ #include "AsSingleWindow.h" #include "Options.h" #include "WindowsManager.h" +#include "version.h" CLIST_INTERFACE *pcli; int hLangpack; PLUGININFOEX pluginInfo = { - sizeof(PLUGININFOEX), // PLUGININFOEX - "AsSingleWindow", - PLUGIN_MAKE_VERSION(0, 1, 2, 1), - "Makes easier windows manipulation: allows you to move, minimize and activate Miranda's windows as if it were a single window.", - "Aleksey Smyrnov aka Soar", - "i@soar.name", - "© Soar, 2010-2011", - "http://soar.name/tag/assinglewindow/", + sizeof(PLUGININFOEX), + __PLUGIN_NAME, + PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), + __DESCRIPTION, + __AUTHOR, + __AUTHOREMAIL, + __COPYRIGHT, + __AUTHORWEB, UNICODE_AWARE, {0xF6C73B4, 0x2B2B, 0x711D, {0xFB, 0xB6, 0xBB, 0x26, 0x7D, 0xFD, 0x72, 0x08}}, // 0xF6C73B42B2B711DFBB6BB267DFD7208 }; @@ -27,12 +28,6 @@ bool WINAPI DllMain(HINSTANCE hInstDLL, DWORD, LPVOID) return true; } -static const MUUID interfaces[] = {MIID_CLIST, MIID_SRMM, MIID_LAST}; -extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void) -{ - return interfaces; -} - extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) { return &pluginInfo; @@ -45,17 +40,14 @@ extern "C" __declspec(dllexport) int Load(void) ::InitializeCriticalSection(&pluginVars.m_CS); pluginVars.IsUpdateInProgress = false; - pluginVars.heModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); - pluginVars.heOptionsLoaded = HookEvent(ME_OPT_INITIALISE, InitOptions); + HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + HookEvent(ME_OPT_INITIALISE, InitOptions); return 0; } extern "C" __declspec(dllexport) int Unload(void) { - UnhookEvent(pluginVars.heOptionsLoaded); - UnhookEvent(pluginVars.heModulesLoaded); - ::DeleteCriticalSection(&pluginVars.m_CS); return 0; @@ -66,7 +58,7 @@ int OnModulesLoaded(WPARAM, LPARAM) HWND hWndCListWindow = pcli->hwndContactList; windowAdd(hWndCListWindow, true); - pluginVars.heMsgWndEvent = HookEvent(ME_MSG_WINDOWEVENT, MsgWindowEvent); + HookEvent(ME_MSG_WINDOWEVENT, MsgWindowEvent); optionsLoad(); @@ -83,14 +75,12 @@ int MsgWindowEvent(WPARAM, LPARAM lParam) switch (data->uType) { - // Здесь можно отлавливать только открытие окна, - // т.к. закрытие может быть закрытием вкладки - case MSG_WINDOW_EVT_OPEN: - windowAdd(data->hwndWindow, false); - break; + // Здесь можно отлавливать только открытие окна, + // т.к. закрытие может быть закрытием вкладки + case MSG_WINDOW_EVT_OPEN: + windowAdd(data->hwndWindow, false); + break; } return 0; } - -// end of file
\ No newline at end of file diff --git a/plugins/AsSingleWindow/src/AsSingleWindow.h b/plugins/AsSingleWindow/src/AsSingleWindow.h index e32bc6f948..d28bbfcb3d 100644 --- a/plugins/AsSingleWindow/src/AsSingleWindow.h +++ b/plugins/AsSingleWindow/src/AsSingleWindow.h @@ -1,8 +1,5 @@ #pragma once -#ifndef _ASSINGLEWINDOW_H -#define _ASSINGLEWINDOW_H - #include "stdafx.h" #include "WindowsManager.h" @@ -24,10 +21,6 @@ struct sPluginVars { HWND contactListHWND; windowsList allWindows; - HANDLE heModulesLoaded; - HANDLE heOptionsLoaded; - HANDLE heMsgWndEvent; - bool IsUpdateInProgress; struct { @@ -41,7 +34,3 @@ extern PLUGININFOEX pluginInfo; int OnModulesLoaded(WPARAM, LPARAM); int MsgWindowEvent(WPARAM, LPARAM); - -#endif - -// end of file
\ No newline at end of file diff --git a/plugins/AsSingleWindow/src/Options.cpp b/plugins/AsSingleWindow/src/Options.cpp index 546c20245a..200134bc8c 100644 --- a/plugins/AsSingleWindow/src/Options.cpp +++ b/plugins/AsSingleWindow/src/Options.cpp @@ -1,4 +1,4 @@ -#include "stdafx.h" +#include "stdafx.h" #include "AsSingleWindow.h" #include "Options.h" #include "resource.h" @@ -23,29 +23,35 @@ int InitOptions(WPARAM wParam, LPARAM) INT_PTR CALLBACK cbOptionsDialog(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { - case WM_INITDIALOG: - dlgProcessInit(hWnd, msg, wParam, lParam); - break; - case WM_COMMAND: - dlgProcessCommand(hWnd, msg, wParam, lParam); - break; - case WM_NOTIFY: - if (((LPNMHDR)lParam)->idFrom == 0) { - switch (((LPNMHDR)lParam)->code) { - case PSN_RESET: - optionsLoad(); - break; - case PSN_APPLY: - optionsUpdate(hWnd); - optionsSave(); - windowReposition(hWnd); // - break; - } + case WM_INITDIALOG: + dlgProcessInit(hWnd, msg, wParam, lParam); + break; + + case WM_COMMAND: + dlgProcessCommand(hWnd, msg, wParam, lParam); + break; + + case WM_NOTIFY: + if (((LPNMHDR)lParam)->idFrom == 0) + { + switch (((LPNMHDR)lParam)->code) + { + case PSN_RESET: + optionsLoad(); + break; + + case PSN_APPLY: + optionsUpdate(hWnd); + optionsSave(); + windowReposition(hWnd); // нициируем перерасчет координат + break; } - break; - case WM_DESTROY: - // free up resources - break; + } + break; + + case WM_DESTROY: + // free up resources + break; } return false; @@ -82,6 +88,7 @@ void dlgProcessCommand(HWND hWnd, UINT, WPARAM wParam, LPARAM) SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0); } break; + case IDC_RADIO_G2_MERGEALL: case IDC_RADIO_G2_MERGEONE: case IDC_RADIO_G2_DISABLEMERGE: @@ -122,8 +129,6 @@ void optionsUpdate(HWND hWnd) void optionsSave() { - db_get_b(0, SETTINGSNAME, "DrivenWindowPosition", pluginVars.Options.DrivenWindowPos); - db_get_b(0, SETTINGSNAME, "WindowsMerging", pluginVars.Options.WindowsMerging); + db_set_b(0, SETTINGSNAME, "DrivenWindowPosition", pluginVars.Options.DrivenWindowPos); + db_set_b(0, SETTINGSNAME, "WindowsMerging", pluginVars.Options.WindowsMerging); } - -// end of file
\ No newline at end of file diff --git a/plugins/AsSingleWindow/src/Options.h b/plugins/AsSingleWindow/src/Options.h index f7519ed554..4c0a265793 100644 --- a/plugins/AsSingleWindow/src/Options.h +++ b/plugins/AsSingleWindow/src/Options.h @@ -1,20 +1,7 @@ #pragma once -#ifndef _OPTIONS_H -#define _OPTIONS_H - #define SETTINGSNAME "AsSingleWindow" -#ifdef UNICODE -#define LPGENSTR LPGENT -#define DBGetString DBGetContactSettingTString -#define DBWriteString DBWriteContactSettingTString -#else -#define LPGENSTR LPGEN -#define DBGetString DBGetContactSettingString -#define DBWriteString DBWriteContactSettingString -#endif - int InitOptions(WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK cbOptionsDialog(HWND, UINT, WPARAM, LPARAM); @@ -25,7 +12,3 @@ void dlgUpdateControls(HWND); void optionsLoad(); void optionsUpdate(HWND); void optionsSave(); - -#endif - -// end of file
\ No newline at end of file diff --git a/plugins/AsSingleWindow/src/WindowsManager.cpp b/plugins/AsSingleWindow/src/WindowsManager.cpp index ed8fcb87af..66cf18a3ab 100644 --- a/plugins/AsSingleWindow/src/WindowsManager.cpp +++ b/plugins/AsSingleWindow/src/WindowsManager.cpp @@ -11,22 +11,24 @@ void sWindowInfo::saveState() switch (wndPlace.showCmd) { - case SW_HIDE: - this->eState = WINDOW_STATE_HIDDEN; - break; - case SW_MINIMIZE: - case SW_SHOWMINIMIZED: - case SW_SHOWMINNOACTIVE: - this->eState = WINDOW_STATE_MINIMIZED; - break; - case SW_MAXIMIZE: - case SW_RESTORE: - case SW_SHOW: - case SW_SHOWNA: - case SW_SHOWNOACTIVATE: - case SW_SHOWNORMAL: - this->eState = WINDOW_STATE_NORMAL; - break; + case SW_HIDE: + this->eState = WINDOW_STATE_HIDDEN; + break; + + case SW_MINIMIZE: + case SW_SHOWMINIMIZED: + case SW_SHOWMINNOACTIVE: + this->eState = WINDOW_STATE_MINIMIZED; + break; + + case SW_MAXIMIZE: + case SW_RESTORE: + case SW_SHOW: + case SW_SHOWNA: + case SW_SHOWNOACTIVATE: + case SW_SHOWNORMAL: + this->eState = WINDOW_STATE_NORMAL; + break; } } @@ -34,16 +36,17 @@ void sWindowInfo::saveRect() { switch (this->eState) { - case WINDOW_STATE_HIDDEN: - case WINDOW_STATE_MINIMIZED: - WINDOWPLACEMENT wndPlace; - wndPlace.length = sizeof(wndPlace); - if (GetWindowPlacement(this->hWnd, &wndPlace)) - this->rLastSavedPosition = wndPlace.rcNormalPosition; - break; - default: - GetWindowRect(this->hWnd, &this->rLastSavedPosition); - break; + case WINDOW_STATE_HIDDEN: + case WINDOW_STATE_MINIMIZED: + WINDOWPLACEMENT wndPlace; + wndPlace.length = sizeof(wndPlace); + if (GetWindowPlacement(this->hWnd, &wndPlace)) + this->rLastSavedPosition = wndPlace.rcNormalPosition; + break; + + default: + GetWindowRect(this->hWnd, &this->rLastSavedPosition); + break; } } @@ -131,8 +134,8 @@ void windowAdd(HWND hWnd, bool IsMain) thisWindowInfo.hWnd = hWnd; thisWindowInfo.eState = WINDOW_STATE_NORMAL; - thisWindowInfo.pPrevWndProc = (WNDPROC) SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR) wndProcSync); - + thisWindowInfo.pPrevWndProc = (WNDPROC)SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)wndProcSync); + pluginVars.allWindows.push_back(thisWindowInfo); if (IsMain) @@ -161,7 +164,7 @@ void windowListUpdate() windowsList::iterator itr = pluginVars.allWindows.begin(); while (itr != pluginVars.allWindows.end()) // Не удаляем КЛ в принципе, нет необходимости - if (! IsWindow(itr->hWnd) && itr->hWnd != pluginVars.contactListHWND) + if (!IsWindow(itr->hWnd) && itr->hWnd != pluginVars.contactListHWND) { if (itr->hWnd == pluginVars.contactListHWND) pluginVars.contactListHWND = 0; @@ -172,7 +175,7 @@ void windowListUpdate() ++itr; if (isRemoved) - if (! pluginVars.allWindows.empty()) + if (!pluginVars.allWindows.empty()) // TODO: разобраться, почему после этого КЛ пропадает в трей allWindowsMoveAndSize(pluginVars.contactListHWND); } @@ -199,7 +202,7 @@ void windowReposition(HWND hWnd) break; } } - else if (! pluginVars.allWindows.empty()) + else if (!pluginVars.allWindows.empty()) { windowsList::iterator itr = pluginVars.allWindows.begin(); if (GetWindowRect(itr->hWnd, &prevWindowPos)) @@ -324,27 +327,29 @@ void allWindowsActivation(HWND hWnd) switch (wndState) { - // Восстанавливаем все окна и выстраиваем на переднем плане - case WINDOW_STATE_NORMAL: - ShowWindow(itr->hWnd, SW_SHOWNA); - ShowWindow(itr->hWnd, SW_RESTORE); - SetWindowPos(itr->hWnd, hWnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOACTIVATE); - itr->eState = WINDOW_STATE_NORMAL; - break; - // Прячем окна диалогов, окно КЛ - скрываем - case WINDOW_STATE_MINIMIZED: - if (itr->hWnd != pluginVars.contactListHWND) - ShowWindow(itr->hWnd, SW_MINIMIZE); - else - ShowWindow(itr->hWnd, SW_HIDE); - itr->eState = WINDOW_STATE_MINIMIZED; - break; - // Прячем все окна - case WINDOW_STATE_HIDDEN: - case WINDOW_STATE_CLOSED: + // Восстанавливаем все окна и выстраиваем на переднем плане + case WINDOW_STATE_NORMAL: + ShowWindow(itr->hWnd, SW_SHOWNA); + ShowWindow(itr->hWnd, SW_RESTORE); + SetWindowPos(itr->hWnd, hWnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOACTIVATE); + itr->eState = WINDOW_STATE_NORMAL; + break; + + // Прячем окна диалогов, окно КЛ - скрываем + case WINDOW_STATE_MINIMIZED: + if (itr->hWnd != pluginVars.contactListHWND) + ShowWindow(itr->hWnd, SW_MINIMIZE); + else ShowWindow(itr->hWnd, SW_HIDE); - itr->eState = WINDOW_STATE_HIDDEN; - break; + itr->eState = WINDOW_STATE_MINIMIZED; + break; + + // Прячем все окна + case WINDOW_STATE_HIDDEN: + case WINDOW_STATE_CLOSED: + ShowWindow(itr->hWnd, SW_HIDE); + itr->eState = WINDOW_STATE_HIDDEN; + break; } } } @@ -356,25 +361,28 @@ void windowChangeState(HWND hWnd, WPARAM cmd, LPARAM) { switch (cmd) { - case SC_CLOSE: - wndInfo->eState = WINDOW_STATE_CLOSED; - windowReposition(hWnd); - break; - case SC_MAXIMIZE: - wndInfo->eState = WINDOW_STATE_MAXIMIZED; - windowReposition(hWnd); - break; - case SC_MINIMIZE: - wndInfo->eState = WINDOW_STATE_MINIMIZED; - allWindowsActivation(hWnd); - break; - case SC_RESTORE: - case SC_MOVE: - case SC_SIZE: - wndInfo->eState = WINDOW_STATE_NORMAL; - allWindowsActivation(hWnd); - windowReposition(hWnd); - break; + case SC_CLOSE: + wndInfo->eState = WINDOW_STATE_CLOSED; + windowReposition(hWnd); + break; + + case SC_MAXIMIZE: + wndInfo->eState = WINDOW_STATE_MAXIMIZED; + windowReposition(hWnd); + break; + + case SC_MINIMIZE: + wndInfo->eState = WINDOW_STATE_MINIMIZED; + allWindowsActivation(hWnd); + break; + + case SC_RESTORE: + case SC_MOVE: + case SC_SIZE: + wndInfo->eState = WINDOW_STATE_NORMAL; + allWindowsActivation(hWnd); + windowReposition(hWnd); + break; } } } @@ -386,10 +394,10 @@ void windowChangeState(HWND hWnd, WindowState newState) wndInfo->eState = newState; switch (newState) { - case WINDOW_STATE_NORMAL: - case WINDOW_STATE_HIDDEN: - allWindowsActivation(hWnd); - break; + case WINDOW_STATE_NORMAL: + case WINDOW_STATE_HIDDEN: + allWindowsActivation(hWnd); + break; } } } @@ -437,27 +445,32 @@ LRESULT CALLBACK wndProcSync(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) switch (msg) { - case WM_SYSCOMMAND: - windowChangeState(hWnd, wParam, lParam); - break; - case WM_SIZE: - allWindowsMoveAndSize(hWnd); - break; - case WM_MOVE: - allWindowsMoveAndSize(hWnd); - break; - case WM_SHOWWINDOW: - windowChangeState(hWnd, wParam ? WINDOW_STATE_NORMAL : WINDOW_STATE_HIDDEN); - allWindowsMoveAndSize(hWnd); - break; - case WM_ACTIVATE: - if (wParam) - windowActivation(hWnd, (HWND) lParam); - break; - //case WM_ACTIVATEAPP: - // if (! wParam) - // windowActivation(hWnd, 0); - // break; + case WM_SYSCOMMAND: + windowChangeState(hWnd, wParam, lParam); + break; + + case WM_SIZE: + allWindowsMoveAndSize(hWnd); + break; + + case WM_MOVE: + allWindowsMoveAndSize(hWnd); + break; + + case WM_SHOWWINDOW: + windowChangeState(hWnd, wParam ? WINDOW_STATE_NORMAL : WINDOW_STATE_HIDDEN); + allWindowsMoveAndSize(hWnd); + break; + + case WM_ACTIVATE: + if (wParam) + windowActivation(hWnd, (HWND)lParam); + break; + + //case WM_ACTIVATEAPP: + // if (! wParam) + // windowActivation(hWnd, 0); + // break; } pluginSetDone(); @@ -486,5 +499,3 @@ bool calcNewWindowPosition(HWND hWndLeading, HWND hWndDriven, sWndCoords* wndCoo return true; } - -// end of file
\ No newline at end of file diff --git a/plugins/AsSingleWindow/src/WindowsManager.h b/plugins/AsSingleWindow/src/WindowsManager.h index e47c03655e..a93f33678c 100644 --- a/plugins/AsSingleWindow/src/WindowsManager.h +++ b/plugins/AsSingleWindow/src/WindowsManager.h @@ -1,8 +1,5 @@ #pragma once -#ifndef WINDOWSMANAGER_H -#define WINDOWSMANAGER_H - #include "stdafx.h" enum WindowState { @@ -56,7 +53,3 @@ bool calcNewWindowPosition(HWND, HWND, sWndCoords*, eWindowPosition); LRESULT CALLBACK wndProcSync(HWND, UINT, WPARAM, LPARAM); void allWindowsMoveAndSize(HWND); void allWindowsActivation(HWND); - -#endif WINDOWSMANAGER_H - -// end of file
\ No newline at end of file diff --git a/plugins/AsSingleWindow/src/stdafx.cxx b/plugins/AsSingleWindow/src/stdafx.cxx index 8279ea6a37..5126af91d5 100644 --- a/plugins/AsSingleWindow/src/stdafx.cxx +++ b/plugins/AsSingleWindow/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/AsSingleWindow/src/stdafx.h b/plugins/AsSingleWindow/src/stdafx.h index a7e42fdf90..8b24b19292 100644 --- a/plugins/AsSingleWindow/src/stdafx.h +++ b/plugins/AsSingleWindow/src/stdafx.h @@ -2,7 +2,6 @@ #define WIN32_LEAN_AND_MEAN -// Файлы заголовков Windows: #include <windows.h> #include <stdio.h> #include <stdlib.h> @@ -11,7 +10,6 @@ #include <list> #include <algorithm> -// Miranda headers #include "newpluginapi.h" #include "m_system.h" #include "m_langpack.h" @@ -22,5 +20,3 @@ //#include "m_clui.h" #include "m_options.h" //#include "m_plugins.h" - -// end of file
\ No newline at end of file diff --git a/plugins/AsSingleWindow/src/version.h b/plugins/AsSingleWindow/src/version.h new file mode 100644 index 0000000000..463c157e1a --- /dev/null +++ b/plugins/AsSingleWindow/src/version.h @@ -0,0 +1,14 @@ +#define __MAJOR_VERSION 0 +#define __MINOR_VERSION 1 +#define __RELEASE_NUM 2 +#define __BUILD_NUM 1 + +#include <stdver.h> + +#define __PLUGIN_NAME "AsSingleWindow" +#define __FILENAME "AsSingleWindow.dll" +#define __DESCRIPTION "Makes easier windows manipulation. Allows you to move, minimize and activate Miranda's windows as if it were a single window." +#define __AUTHOR "Aleksey Smyrnov aka Soar" +#define __AUTHOREMAIL "i@soar.name" +#define __AUTHORWEB "https://miranda-ng.org/p/AsSingleWindow/" +#define __COPYRIGHT " 2010-2011 Soar" |