From 968d40dc006d57bf614f9522a9d262650beee4cc Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 31 Oct 2013 18:16:31 +0000 Subject: - subclassing fix - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@6722 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MagneticWindows/src/MagneticWindows.cpp | 74 ++- .../MagneticWindows/src/MagneticWindowsCore.cpp | 516 +++++++++------------ plugins/MagneticWindows/src/MagneticWindowsCore.h | 16 +- plugins/MagneticWindows/src/Options.cpp | 151 +++--- plugins/MagneticWindows/src/Options.h | 2 - plugins/MagneticWindows/src/SnapToListService.cpp | 7 +- plugins/MagneticWindows/src/SnapToListService.h | 3 - 7 files changed, 309 insertions(+), 460 deletions(-) diff --git a/plugins/MagneticWindows/src/MagneticWindows.cpp b/plugins/MagneticWindows/src/MagneticWindows.cpp index 80b05731c0..bcf38c3036 100644 --- a/plugins/MagneticWindows/src/MagneticWindows.cpp +++ b/plugins/MagneticWindows/src/MagneticWindows.cpp @@ -31,9 +31,6 @@ PLUGININFOEX pluginInfo = { {0x8c01613, 0x24c8, 0x486f, { 0xbd, 0xae, 0x2c, 0x3d, 0xdc, 0xaf, 0x93, 0x47 }} }; - -HANDLE hLoadedHook, hShootDownHook, hAddService, hRemService, hWindowEventHook; - HINSTANCE hInst; int hLangpack; @@ -43,42 +40,40 @@ int hLangpack; //For other Plugins to start snapping for other Windows -INT_PTR SnapPluginWindowStart(WPARAM wParam, LPARAM) { +INT_PTR SnapPluginWindowStart(WPARAM wParam, LPARAM) +{ if (!WindowOpen((HWND)wParam)) return 1; - return 0; } + //For other Plugins to stop snapping for other Windows -INT_PTR SnapPluginWindowStop(WPARAM wParam, LPARAM) { +INT_PTR SnapPluginWindowStop(WPARAM wParam, LPARAM) +{ if (!WindowClose((HWND)wParam)) return 1; - return 0; } -int PluginMessageWindowEvent(WPARAM, LPARAM lParam) { - HWND hWndParent, hWnd; - +int PluginMessageWindowEvent(WPARAM, LPARAM lParam) +{ MessageWindowEventData *Data = (MessageWindowEventData*) lParam; switch (Data->uType) { - case MSG_WINDOW_EVT_OPEN: - hWnd = Data->hwndWindow; - //WindowOpen(hWnd); - hWndParent = GetParent(hWnd); + case MSG_WINDOW_EVT_OPEN: + { + HWND hWnd = Data->hwndWindow; + HWND hWndParent = GetParent(hWnd); while ((hWndParent != 0) && (hWndParent != GetDesktopWindow()) && (IsWindowVisible(hWndParent))) { hWnd = hWndParent; hWndParent = GetParent(hWnd); } WindowOpen(hWnd); - break; - - case MSG_WINDOW_EVT_CLOSING: - WindowClose(Data->hwndWindow); - break; - - default: - break; + } + break; + + case MSG_WINDOW_EVT_CLOSING: + WindowClose(Data->hwndWindow); + break; } return 0; @@ -89,28 +84,19 @@ int PluginMessageWindowEvent(WPARAM, LPARAM lParam) { // Main Functions /////////////////////////////////////////////////////////////////////////////////////////////////// - -int SnapPluginStart(WPARAM, LPARAM) { +int SnapPluginStart(WPARAM, LPARAM) +{ LoadOptions(); - hWindowEventHook = HookEvent(ME_MSG_WINDOWEVENT, PluginMessageWindowEvent); + HookEvent(ME_MSG_WINDOWEVENT, PluginMessageWindowEvent); WindowOpen((HWND)CallService(MS_CLUI_GETHWND,0,0)); return 0; } -int SnapPluginShootDown(WPARAM, LPARAM) { - UnhookEvent(hWindowEventHook); - UnhookEvent(hLoadedHook); - UnhookEvent(hShootDownHook); - UnhookEvent(hInitOptionsHook); - +int SnapPluginShutDown(WPARAM, LPARAM) +{ WindowCloseAll(); - - DestroyServiceFunction(hAddService); - DestroyServiceFunction(hRemService); - DestroyServiceFunction(hSnapToListService); - return 0; } @@ -128,14 +114,15 @@ extern "C" int __declspec(dllexport) Load() { mir_getLP(&pluginInfo); - hLoadedHook = HookEvent(ME_SYSTEM_MODULESLOADED, SnapPluginStart); - hShootDownHook = HookEvent(ME_SYSTEM_PRESHUTDOWN, SnapPluginShootDown); - hInitOptionsHook = HookEvent(ME_OPT_INITIALISE, InitOptions); + HookEvent(ME_SYSTEM_MODULESLOADED, SnapPluginStart); + HookEvent(ME_SYSTEM_PRESHUTDOWN, SnapPluginShutDown); + HookEvent(ME_OPT_INITIALISE, InitOptions); - hAddService = CreateServiceFunction(MS_MW_ADDWINDOW, SnapPluginWindowStart); - hRemService = CreateServiceFunction(MS_MW_REMWINDOW, SnapPluginWindowStop); - hSnapToListService = CreateServiceFunction(MS_MW_SNAPTOLIST, SnapToList); + CreateServiceFunction(MS_MW_ADDWINDOW, SnapPluginWindowStart); + CreateServiceFunction(MS_MW_REMWINDOW, SnapPluginWindowStop); + CreateServiceFunction(MS_MW_SNAPTOLIST, SnapToList); + WindowStart(); return 0; } @@ -152,6 +139,5 @@ extern "C" int __declspec(dllexport) Unload() BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { hInst = hinstDLL; - - return TRUE; + return TRUE; } diff --git a/plugins/MagneticWindows/src/MagneticWindowsCore.cpp b/plugins/MagneticWindows/src/MagneticWindowsCore.cpp index a3cd5f78d6..f81c29cb92 100644 --- a/plugins/MagneticWindows/src/MagneticWindowsCore.cpp +++ b/plugins/MagneticWindows/src/MagneticWindowsCore.cpp @@ -4,11 +4,17 @@ // Variables /////////////////////////////////////////////////////////////////////////////////////////////////// +struct TWindowData +{ + HWND hWnd; + RECT Rect; +}; + +static LIST arWindows(10, HandleKeySortT); + TWorkingVariables Globals = { - NULL, - NULL, - 0,0, - false,false + 0, 0, + false, false }; /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -19,29 +25,13 @@ int Abs(int a) { return (a<0) ? -a : a; } - -PDockingWindow FindDockingWindow(HWND hWnd) { - PDockingWindow i = Globals.WindowList; - - while (i != NULL) { - if (i->hWnd == hWnd) return i; - - i = i->Next; - } - - return NULL; -} - - -void DockWindowRect(HWND hWnd, bool Sizing, RECT& GivenRect, int SizingEdge, int MouseX = 0, int MouseY = 0) { +void DockWindowRect(HWND hWnd, bool Sizing, RECT& GivenRect, int SizingEdge, int MouseX = 0, int MouseY = 0) +{ POINT p; - int W, H; int XPos, YPos; int tmpXPos, tmpYPos; int tmpMouseX, tmpMouseY; - PRectList ActRect; - int diffX = Options.SnapWidth, diffY = Options.SnapWidth; RECT tmpRect = GivenRect; @@ -55,260 +45,219 @@ void DockWindowRect(HWND hWnd, bool Sizing, RECT& GivenRect, int SizingEdge, int tmpMouseX = p.x - tmpRect.left; OffsetRect(&tmpRect, tmpMouseX - MouseX, 0); OffsetRect(&GivenRect, tmpMouseX - MouseX, 0); - } else { - MouseX = p.x - tmpRect.left; } + else MouseX = p.x - tmpRect.left; + if (Globals.SnappedY) { tmpMouseY = p.y - tmpRect.top; OffsetRect(&tmpRect, 0, tmpMouseY - MouseY); OffsetRect(&GivenRect, 0, tmpMouseY - MouseY); - } else { - MouseY = p.y - tmpRect.top; } + else MouseY = p.y - tmpRect.top; } - W = tmpRect.right - tmpRect.left; - H = tmpRect.bottom - tmpRect.top; + int W = tmpRect.right - tmpRect.left; + int H = tmpRect.bottom - tmpRect.top; if (!Sizing) { - ActRect = Globals.Rects; - while (ActRect != NULL) { - if ((tmpRect.left >= (ActRect->Rect.left - Options.SnapWidth)) && - (tmpRect.left <= (ActRect->Rect.left + Options.SnapWidth)) && - ((tmpRect.top - Options.SnapWidth) < ActRect->Rect.bottom) & - ((tmpRect.bottom + Options.SnapWidth) > ActRect->Rect.top) && - (Abs(tmpRect.left - ActRect->Rect.left) < diffX)) + for (int i=0; i < arWindows.getCount(); i++) { + TWindowData *p = arWindows[i]; + if (p->hWnd == hWnd) + continue; + + if ((tmpRect.left >= (p->Rect.left - Options.SnapWidth)) && + (tmpRect.left <= (p->Rect.left + Options.SnapWidth)) && + ((tmpRect.top - Options.SnapWidth) < p->Rect.bottom) & + ((tmpRect.bottom + Options.SnapWidth) > p->Rect.top) && + (Abs(tmpRect.left - p->Rect.left) < diffX)) { - GivenRect.left = ActRect->Rect.left; + GivenRect.left = p->Rect.left; GivenRect.right = GivenRect.left + W; - diffX = Abs(tmpRect.left - ActRect->Rect.left); + diffX = Abs(tmpRect.left - p->Rect.left); FoundX = true; - } else - if ((ActRect != Globals.Rects) && - (tmpRect.left >= (ActRect->Rect.right - Options.SnapWidth)) && - (tmpRect.left <= (ActRect->Rect.right + Options.SnapWidth)) && - ((tmpRect.top - Options.SnapWidth) < ActRect->Rect.bottom) && - ((tmpRect.bottom + Options.SnapWidth) > ActRect->Rect.top) && - (Abs(tmpRect.left - ActRect->Rect.right) < diffX)) + } + else if (i != 0 && + (tmpRect.left >= (p->Rect.right - Options.SnapWidth)) && + (tmpRect.left <= (p->Rect.right + Options.SnapWidth)) && + ((tmpRect.top - Options.SnapWidth) < p->Rect.bottom) && + ((tmpRect.bottom + Options.SnapWidth) > p->Rect.top) && + (Abs(tmpRect.left - p->Rect.right) < diffX)) { - GivenRect.left = ActRect->Rect.right; + GivenRect.left = p->Rect.right; GivenRect.right = GivenRect.left + W; - diffX = Abs(tmpRect.left - ActRect->Rect.right); + diffX = Abs(tmpRect.left - p->Rect.right); FoundX = true; - } else - if ((ActRect != Globals.Rects) && - (tmpRect.right >= (ActRect->Rect.left - Options.SnapWidth)) && - (tmpRect.right <= (ActRect->Rect.left + Options.SnapWidth)) && - ((tmpRect.top - Options.SnapWidth) < ActRect->Rect.bottom) && - ((tmpRect.bottom + Options.SnapWidth) > ActRect->Rect.top) && - (Abs(tmpRect.right - ActRect->Rect.left) < diffX)) + } + else if (i != 0 && + (tmpRect.right >= (p->Rect.left - Options.SnapWidth)) && + (tmpRect.right <= (p->Rect.left + Options.SnapWidth)) && + ((tmpRect.top - Options.SnapWidth) < p->Rect.bottom) && + ((tmpRect.bottom + Options.SnapWidth) > p->Rect.top) && + (Abs(tmpRect.right - p->Rect.left) < diffX)) { - GivenRect.right = ActRect->Rect.left; + GivenRect.right = p->Rect.left; GivenRect.left = GivenRect.right - W; - diffX = Abs(tmpRect.right - ActRect->Rect.left); + diffX = Abs(tmpRect.right - p->Rect.left); FoundX = true; - } else - if ((tmpRect.right >= (ActRect->Rect.right - Options.SnapWidth)) && - (tmpRect.right <= (ActRect->Rect.right + Options.SnapWidth)) && - ((tmpRect.top - Options.SnapWidth) < ActRect->Rect.bottom) && - ((tmpRect.bottom + Options.SnapWidth) > ActRect->Rect.top) && - (Abs(tmpRect.right - ActRect->Rect.right) < diffX)) + } + else if ((tmpRect.right >= (p->Rect.right - Options.SnapWidth)) && + (tmpRect.right <= (p->Rect.right + Options.SnapWidth)) && + ((tmpRect.top - Options.SnapWidth) < p->Rect.bottom) && + ((tmpRect.bottom + Options.SnapWidth) > p->Rect.top) && + (Abs(tmpRect.right - p->Rect.right) < diffX)) { - GivenRect.right = ActRect->Rect.right; + GivenRect.right = p->Rect.right; GivenRect.left = GivenRect.right - W; - diffX = Abs(tmpRect.right - ActRect->Rect.right); + diffX = Abs(tmpRect.right - p->Rect.right); FoundX = true; } - - if ((tmpRect.top >= (ActRect->Rect.top - Options.SnapWidth)) && - (tmpRect.top <= (ActRect->Rect.top + Options.SnapWidth)) && - ((tmpRect.left - Options.SnapWidth) < ActRect->Rect.right) && - ((tmpRect.right + Options.SnapWidth) > ActRect->Rect.left) && - (Abs(tmpRect.top - ActRect->Rect.top) < diffY)) + if ((tmpRect.top >= (p->Rect.top - Options.SnapWidth)) && + (tmpRect.top <= (p->Rect.top + Options.SnapWidth)) && + ((tmpRect.left - Options.SnapWidth) < p->Rect.right) && + ((tmpRect.right + Options.SnapWidth) > p->Rect.left) && + (Abs(tmpRect.top - p->Rect.top) < diffY)) { - GivenRect.top = ActRect->Rect.top; + GivenRect.top = p->Rect.top; GivenRect.bottom = GivenRect.top + H; - diffY = Abs(tmpRect.top - ActRect->Rect.top); + diffY = Abs(tmpRect.top - p->Rect.top); FoundY = true; - } else - if ((ActRect != Globals.Rects) && - (tmpRect.top >= (ActRect->Rect.bottom - Options.SnapWidth)) && - (tmpRect.top <= (ActRect->Rect.bottom + Options.SnapWidth)) && - ((tmpRect.left - Options.SnapWidth) < ActRect->Rect.right) && - ((tmpRect.right + Options.SnapWidth) > ActRect->Rect.left) && - (Abs(tmpRect.top - ActRect->Rect.bottom) < diffY)) + } + else if (i != 0 && + (tmpRect.top >= (p->Rect.bottom - Options.SnapWidth)) && + (tmpRect.top <= (p->Rect.bottom + Options.SnapWidth)) && + ((tmpRect.left - Options.SnapWidth) < p->Rect.right) && + ((tmpRect.right + Options.SnapWidth) > p->Rect.left) && + (Abs(tmpRect.top - p->Rect.bottom) < diffY)) { - GivenRect.top = ActRect->Rect.bottom; + GivenRect.top = p->Rect.bottom; GivenRect.bottom = GivenRect.top + H; - diffY = Abs(tmpRect.top - ActRect->Rect.bottom); + diffY = Abs(tmpRect.top - p->Rect.bottom); FoundY = true; - } else - if ((ActRect != Globals.Rects) && - (tmpRect.bottom >= (ActRect->Rect.top - Options.SnapWidth)) && - (tmpRect.bottom <= (ActRect->Rect.top + Options.SnapWidth)) && - ((tmpRect.left - Options.SnapWidth) < ActRect->Rect.right) && - ((tmpRect.right + Options.SnapWidth) > ActRect->Rect.left) && - (Abs(tmpRect.bottom - ActRect->Rect.top) < diffY)) + } + else if (i != 0 && + (tmpRect.bottom >= (p->Rect.top - Options.SnapWidth)) && + (tmpRect.bottom <= (p->Rect.top + Options.SnapWidth)) && + ((tmpRect.left - Options.SnapWidth) < p->Rect.right) && + ((tmpRect.right + Options.SnapWidth) > p->Rect.left) && + (Abs(tmpRect.bottom - p->Rect.top) < diffY)) { - GivenRect.bottom = ActRect->Rect.top; + GivenRect.bottom = p->Rect.top; GivenRect.top = GivenRect.bottom - H; - diffY = Abs(tmpRect.bottom - ActRect->Rect.top); + diffY = Abs(tmpRect.bottom - p->Rect.top); FoundY = true; - } else - if ((tmpRect.bottom >= (ActRect->Rect.bottom - Options.SnapWidth)) && - (tmpRect.bottom <= (ActRect->Rect.bottom + Options.SnapWidth)) && - ((tmpRect.left - Options.SnapWidth) < ActRect->Rect.right) && - ((tmpRect.right + Options.SnapWidth) > ActRect->Rect.left) && - (Abs(tmpRect.bottom - ActRect->Rect.bottom) < diffY)) + } + else if ((tmpRect.bottom >= (p->Rect.bottom - Options.SnapWidth)) && + (tmpRect.bottom <= (p->Rect.bottom + Options.SnapWidth)) && + ((tmpRect.left - Options.SnapWidth) < p->Rect.right) && + ((tmpRect.right + Options.SnapWidth) > p->Rect.left) && + (Abs(tmpRect.bottom - p->Rect.bottom) < diffY)) { - GivenRect.bottom = ActRect->Rect.bottom; + GivenRect.bottom = p->Rect.bottom; GivenRect.top = GivenRect.bottom - H; - diffY = Abs(tmpRect.bottom - ActRect->Rect.bottom); + diffY = Abs(tmpRect.bottom - p->Rect.bottom); FoundY = true; } - - ActRect = ActRect->Next; - } //next rect + } Globals.SnappedX = FoundX; Globals.SnappedY = FoundY; } else //Sizing { - if ((SizingEdge == WMSZ_LEFT) || - (SizingEdge == WMSZ_TOPLEFT) || - (SizingEdge == WMSZ_BOTTOMLEFT)) - { + if (SizingEdge == WMSZ_LEFT || SizingEdge == WMSZ_TOPLEFT || SizingEdge == WMSZ_BOTTOMLEFT) XPos = GivenRect.left; - } else { + else XPos = GivenRect.right; - } - if ((SizingEdge == WMSZ_TOP) || - (SizingEdge == WMSZ_TOPLEFT) || - (SizingEdge == WMSZ_TOPRIGHT)) - { + if (SizingEdge == WMSZ_TOP || SizingEdge == WMSZ_TOPLEFT || SizingEdge == WMSZ_TOPRIGHT) YPos = GivenRect.top; - } else { + else YPos = GivenRect.bottom; - } tmpXPos = XPos; tmpYPos = YPos; - ActRect = Globals.Rects; - while (ActRect != NULL) { - if ((tmpXPos >= (ActRect->Rect.left - Options.SnapWidth)) && - (tmpXPos <= (ActRect->Rect.left + Options.SnapWidth)) && - ((tmpRect.top - Options.SnapWidth) < ActRect->Rect.bottom) && - ((tmpRect.bottom + Options.SnapWidth) > ActRect->Rect.top) && - (Abs(tmpXPos - ActRect->Rect.left) < diffX)) + for (int i=0; i < arWindows.getCount(); i++) { + TWindowData *p = arWindows[i]; + if (p->hWnd == hWnd) + continue; + + if ((tmpXPos >= (p->Rect.left - Options.SnapWidth)) && + (tmpXPos <= (p->Rect.left + Options.SnapWidth)) && + ((tmpRect.top - Options.SnapWidth) < p->Rect.bottom) && + ((tmpRect.bottom + Options.SnapWidth) > p->Rect.top) && + (Abs(tmpXPos - p->Rect.left) < diffX)) { - XPos = ActRect->Rect.left; - - diffX = Abs(tmpXPos - ActRect->Rect.left); - } else - if ((tmpXPos >= (ActRect->Rect.right - Options.SnapWidth)) && - (tmpXPos <= (ActRect->Rect.right + Options.SnapWidth)) && - ((tmpRect.top - Options.SnapWidth) < ActRect->Rect.bottom) && - ((tmpRect.bottom + Options.SnapWidth) > ActRect->Rect.top) && - (Abs(tmpXPos - ActRect->Rect.right) < diffX)) + XPos = p->Rect.left; + diffX = Abs(tmpXPos - p->Rect.left); + } + else if ((tmpXPos >= (p->Rect.right - Options.SnapWidth)) && + (tmpXPos <= (p->Rect.right + Options.SnapWidth)) && + ((tmpRect.top - Options.SnapWidth) < p->Rect.bottom) && + ((tmpRect.bottom + Options.SnapWidth) > p->Rect.top) && + (Abs(tmpXPos - p->Rect.right) < diffX)) { - XPos = ActRect->Rect.right; - - diffX = Abs(tmpXPos - ActRect->Rect.right); + XPos = p->Rect.right; + diffX = Abs(tmpXPos - p->Rect.right); } - if ((tmpYPos >= (ActRect->Rect.top - Options.SnapWidth)) && - (tmpYPos <= (ActRect->Rect.top + Options.SnapWidth)) && - ((tmpRect.left - Options.SnapWidth) < ActRect->Rect.right) && - ((tmpRect.right + Options.SnapWidth) > ActRect->Rect.left) && - (Abs(tmpYPos - ActRect->Rect.top) < diffY)) + if ((tmpYPos >= (p->Rect.top - Options.SnapWidth)) && + (tmpYPos <= (p->Rect.top + Options.SnapWidth)) && + ((tmpRect.left - Options.SnapWidth) < p->Rect.right) && + ((tmpRect.right + Options.SnapWidth) > p->Rect.left) && + (Abs(tmpYPos - p->Rect.top) < diffY)) { - YPos = ActRect->Rect.top; - - diffY = Abs(tmpYPos - ActRect->Rect.top); - } else - if ((tmpYPos >= (ActRect->Rect.bottom - Options.SnapWidth)) && - (tmpYPos <= (ActRect->Rect.bottom + Options.SnapWidth)) && - ((tmpRect.left - Options.SnapWidth) < ActRect->Rect.right) && - ((tmpRect.right + Options.SnapWidth) > ActRect->Rect.left) && - (Abs(tmpYPos - ActRect->Rect.bottom) < diffY)) + YPos = p->Rect.top; + diffY = Abs(tmpYPos - p->Rect.top); + } + else if ((tmpYPos >= (p->Rect.bottom - Options.SnapWidth)) && + (tmpYPos <= (p->Rect.bottom + Options.SnapWidth)) && + ((tmpRect.left - Options.SnapWidth) < p->Rect.right) && + ((tmpRect.right + Options.SnapWidth) > p->Rect.left) && + (Abs(tmpYPos - p->Rect.bottom) < diffY)) { - YPos = ActRect->Rect.bottom; - - diffY = Abs(tmpYPos - ActRect->Rect.bottom); + YPos = p->Rect.bottom; + diffY = Abs(tmpYPos - p->Rect.bottom); } + } - ActRect = ActRect->Next; - } //Next rect - - if ((SizingEdge == WMSZ_LEFT) || - (SizingEdge == WMSZ_TOPLEFT) || - (SizingEdge == WMSZ_BOTTOMLEFT)) - { + if (SizingEdge == WMSZ_LEFT || SizingEdge == WMSZ_TOPLEFT || SizingEdge == WMSZ_BOTTOMLEFT) GivenRect.left = XPos; - } else { + else GivenRect.right = XPos; - } - if ((SizingEdge == WMSZ_TOP) || - (SizingEdge == WMSZ_TOPLEFT) || - (SizingEdge == WMSZ_TOPRIGHT)) - { + + if (SizingEdge == WMSZ_TOP || SizingEdge == WMSZ_TOPLEFT || SizingEdge == WMSZ_TOPRIGHT) GivenRect.top = YPos; - } else { + else GivenRect.bottom = YPos; - } } } +void GetFrmRects(HWND ForWindow) +{ + SystemParametersInfo(SPI_GETWORKAREA, 0, &arWindows[0]->Rect, 0); -void GetFrmRects(HWND ForWindow) { - PDockingWindow i; - PRectList Rect, l; - - Rect = Globals.Rects; - while (Rect != NULL) { - l = Rect; - Rect = Rect->Next; - free(l); - } - - Rect = (PRectList)malloc(sizeof(TRectList)); - Rect->Next = NULL; - Globals.Rects = Rect; - - SystemParametersInfo(SPI_GETWORKAREA, 0, &(Rect->Rect), 0); - i = Globals.WindowList; - - while (i != NULL) { - if ((i->hWnd != ForWindow) && IsWindowVisible(i->hWnd)) { - l = Rect; - Rect = (PRectList)malloc(sizeof(TRectList)); - Rect->Next = NULL; - l->Next = Rect; - - GetWindowRect(i->hWnd, &(Rect->Rect)); - } - - i = i->Next; + for (int i=1; i < arWindows.getCount(); i++) { + TWindowData *p = arWindows[i]; + if (p->hWnd != ForWindow && IsWindowVisible(p->hWnd)) + GetWindowRect(p->hWnd, &p->Rect); } } @@ -316,136 +265,91 @@ void GetFrmRects(HWND ForWindow) { // Subclass Window Proc /////////////////////////////////////////////////////////////////////////////////////////////////// -LRESULT CALLBACK WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { +LRESULT CALLBACK WindowProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) +{ RECT r; POINT p; - PDockingWindow i = FindDockingWindow(hWnd); - - WNDPROC OldRun = NULL; - - if (i != NULL) { //else we have a problem - OldRun = i->OldWindowProc; - - if (Options.DoSnap) { - switch (Msg) { - case WM_ENTERSIZEMOVE: { - if (Options.ScriverWorkAround) - keybd_event(VK_CONTROL, 0, 0, 0); - - GetWindowRect(hWnd, &r); - GetCursorPos(&p); - Globals.MouseX = p.x - r.left; - Globals.MouseY = p.y - r.top; - - GetFrmRects(hWnd); - - break; - } - case WM_EXITSIZEMOVE: { - if (Options.ScriverWorkAround) - keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); - - break; - } - case WM_SIZING: - case WM_MOVING: { - r = *((PRECT)lParam); - if (Msg == WM_SIZING) { - DockWindowRect(hWnd, true, r, wParam); - } else { - DockWindowRect(hWnd, false, r, wParam, Globals.MouseX, Globals.MouseY); - } - - (*(PRECT)lParam) = r; - - if (Msg == WM_SIZING) { - return 1; - } - - break; - } - } //switch - } //if dosnap - - if (OldRun != NULL) { - if (IsWindowUnicode(hWnd)) { - return CallWindowProcW(OldRun, hWnd, Msg, wParam, lParam); - } else { - return CallWindowProcA(OldRun, hWnd, Msg, wParam, lParam); - } - } + if (Options.DoSnap) { + switch (Msg) { + case WM_ENTERSIZEMOVE: + if (Options.ScriverWorkAround) + keybd_event(VK_CONTROL, 0, 0, 0); + + GetWindowRect(hWnd, &r); + GetCursorPos(&p); + Globals.MouseX = p.x - r.left; + Globals.MouseY = p.y - r.top; + GetFrmRects(hWnd); + break; + + case WM_EXITSIZEMOVE: + if (Options.ScriverWorkAround) + keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0); + break; + + case WM_SIZING: + case WM_MOVING: + r = *((PRECT)lParam); + if (Msg == WM_SIZING) + DockWindowRect(hWnd, true, r, wParam); + else + DockWindowRect(hWnd, false, r, wParam, Globals.MouseX, Globals.MouseY); + + (*(PRECT)lParam) = r; + + if (Msg == WM_SIZING) + return 1; + + break; + } } - return 0; + return mir_callNextSubclass(hWnd, WindowProc, Msg, wParam, lParam); } - /////////////////////////////////////////////////////////////////////////////////////////////////// // exportet Functions /////////////////////////////////////////////////////////////////////////////////////////////////// -bool WindowOpen(HWND hWnd) { - PDockingWindow i; - - if ((hWnd != 0) && (FindDockingWindow(hWnd) == NULL)) { - i = (PDockingWindow)mir_alloc(sizeof(TDockingWindow)); - i->Next = Globals.WindowList; - i->hWnd = hWnd; - Globals.WindowList = i; - - if (IsWindowUnicode(hWnd)) { - i->OldWindowProc = (WNDPROC) GetWindowLongPtrW(hWnd, GWLP_WNDPROC); - SetWindowLongPtrW(hWnd, GWLP_WNDPROC, (LONG_PTR)(&WindowProc)); - } else { - i->OldWindowProc = (WNDPROC) GetWindowLongPtrA(hWnd, GWLP_WNDPROC); - SetWindowLongPtrA(hWnd, GWLP_WNDPROC, (LONG_PTR)(&WindowProc)); - } - - return true; - } - return false; +void WindowStart() +{ + TWindowData *p = (TWindowData*)mir_calloc(sizeof(TWindowData)); + arWindows.insert(p); } -bool WindowClose(HWND hWnd) { - PDockingWindow i, l; +bool WindowOpen(HWND hWnd) +{ + if (hWnd == 0) + return false; - l = NULL; - i = Globals.WindowList; + TWindowData *p = (TWindowData*)mir_alloc(sizeof(TWindowData)); + p->hWnd = hWnd; + GetWindowRect(hWnd, &p->Rect); + arWindows.insert(p); - while ((i != NULL) && (i->hWnd != hWnd)) { - l = i; - i = i->Next; - } - - if (i != NULL) { - if (l == NULL) { - Globals.WindowList = i->Next; - } else { - l->Next = i->Next; - } - - if (IsWindowUnicode(hWnd)) { - SetWindowLongPtrW(hWnd, GWLP_WNDPROC, (LONG_PTR) (i->OldWindowProc)); - } else { - SetWindowLongPtrA(hWnd, GWLP_WNDPROC, (LONG_PTR) (i->OldWindowProc)); - } - - mir_free(i); + mir_subclassWindow(hWnd, WindowProc); + return true; +} - return true; +bool WindowClose(HWND hWnd) +{ + if (hWnd == 0) + return false; + + mir_unsubclassWindow(hWnd, WindowProc); + int idx = arWindows.indexOf((TWindowData*)&hWnd); + if (idx != -1) { + TWindowData *p = arWindows[idx]; + arWindows.remove(idx); + mir_free(p); } + return true; +} - return false; +void WindowCloseAll() +{ + for (int i=0; i < arWindows.getCount(); i++) + mir_free(arWindows[i]); + arWindows.destroy(); } -bool WindowCloseAll() { - PDockingWindow i, l; - i = Globals.WindowList; - while (i != NULL) { - l = i; - WindowClose(i->hWnd); - i = i->Next; - mir_free(l); - } - return true; -} \ No newline at end of file diff --git a/plugins/MagneticWindows/src/MagneticWindowsCore.h b/plugins/MagneticWindows/src/MagneticWindowsCore.h index 84ebf91100..aaff256590 100644 --- a/plugins/MagneticWindows/src/MagneticWindowsCore.h +++ b/plugins/MagneticWindows/src/MagneticWindowsCore.h @@ -18,21 +18,8 @@ #include "resource.h" #include "Version.h" -typedef - struct TDockingWindow { - HWND hWnd; - WNDPROC OldWindowProc; - TDockingWindow* Next; - } TDockingWindow, *PDockingWindow; -typedef - struct TRectList { - RECT Rect; - TRectList* Next; - } TRectList, *PRectList; typedef struct { - PDockingWindow WindowList; - PRectList Rects; int MouseX, MouseY; bool SnappedX, SnappedY; } TWorkingVariables; @@ -42,6 +29,7 @@ typedef #define MODULE_NAME "MagneticWindows" extern HINSTANCE hInst; +void WindowStart(); bool WindowOpen(HWND); bool WindowClose(HWND); -bool WindowCloseAll(); \ No newline at end of file +void WindowCloseAll(); diff --git a/plugins/MagneticWindows/src/Options.cpp b/plugins/MagneticWindows/src/Options.cpp index 8d986a26f5..6729e33861 100644 --- a/plugins/MagneticWindows/src/Options.cpp +++ b/plugins/MagneticWindows/src/Options.cpp @@ -1,117 +1,96 @@ #include "MagneticWindowsCore.h" -HANDLE hInitOptionsHook; TOptions Options = { - true, - cDefaultSnapWidth, - false + true, + cDefaultSnapWidth, + false }; +INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + TCHAR str[64]; -INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { - case WM_INITDIALOG: { - TranslateDialogDefault(hwndDlg); - - CheckDlgButton(hwndDlg, IDC_CHK_SNAP, Options.DoSnap?BST_CHECKED:BST_UNCHECKED); - SendDlgItemMessage(hwndDlg, IDC_SLIDER_SNAPWIDTH, TBM_SETRANGE, FALSE, MAKELONG(1,32)); - SendDlgItemMessage(hwndDlg, IDC_SLIDER_SNAPWIDTH, TBM_SETPOS, TRUE, Options.SnapWidth); - - TCHAR str[64]; - mir_sntprintf(str, SIZEOF(str),TranslateT("%d pix"), Options.SnapWidth); - SetDlgItemText(hwndDlg, IDC_TXT_SNAPWIDTH, str); - - EnableWindow(GetDlgItem(hwndDlg, IDC_SLIDER_SNAPWIDTH), Options.DoSnap); - EnableWindow(GetDlgItem(hwndDlg, IDC_TXT_SNAPWIDTH), Options.DoSnap); - - CheckDlgButton(hwndDlg, IDC_CHK_SCRIVERWORKAROUND, Options.ScriverWorkAround?BST_CHECKED:BST_UNCHECKED); - - break; - } - case WM_HSCROLL: { - TCHAR str[64]; - mir_sntprintf(str, SIZEOF(str), TranslateT("%d pix"), SendDlgItemMessage(hwndDlg, IDC_SLIDER_SNAPWIDTH, TBM_GETPOS, 0, 0)); - SetDlgItemText(hwndDlg, IDC_TXT_SNAPWIDTH, str); + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - } + CheckDlgButton(hwndDlg, IDC_CHK_SNAP, Options.DoSnap?BST_CHECKED:BST_UNCHECKED); + SendDlgItemMessage(hwndDlg, IDC_SLIDER_SNAPWIDTH, TBM_SETRANGE, FALSE, MAKELONG(1,32)); + SendDlgItemMessage(hwndDlg, IDC_SLIDER_SNAPWIDTH, TBM_SETPOS, TRUE, Options.SnapWidth); - case WM_COMMAND: { - WORD idCtrl = LOWORD(wParam), wNotifyCode = HIWORD(wParam); - - switch(idCtrl) { - case IDC_CHK_SNAP: { - if (wNotifyCode == BN_CLICKED) { - EnableWindow(GetDlgItem(hwndDlg, IDC_SLIDER_SNAPWIDTH), IsDlgButtonChecked(hwndDlg, IDC_CHK_SNAP)); - EnableWindow(GetDlgItem(hwndDlg, IDC_TXT_SNAPWIDTH), IsDlgButtonChecked(hwndDlg, IDC_CHK_SNAP)); - - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } - break; - } - case IDC_CHK_SCRIVERWORKAROUND: { - if (wNotifyCode == BN_CLICKED) { - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - } - break; - } - } - break; - } + mir_sntprintf(str, SIZEOF(str),TranslateT("%d pix"), Options.SnapWidth); + SetDlgItemText(hwndDlg, IDC_TXT_SNAPWIDTH, str); - case WM_NOTIFY: { //Here we have pressed either the OK or the APPLY button. - switch(((LPNMHDR)lParam)->idFrom) { - case 0: - switch (((LPNMHDR)lParam)->code) { - case PSN_RESET: - LoadOptions(); - break; - - case PSN_APPLY: { - Options.DoSnap = (IsDlgButtonChecked(hwndDlg, IDC_CHK_SNAP) == TRUE); - Options.SnapWidth = SendDlgItemMessage(hwndDlg, IDC_SLIDER_SNAPWIDTH, TBM_GETPOS, 0, 0); - Options.ScriverWorkAround = (IsDlgButtonChecked(hwndDlg, IDC_CHK_SCRIVERWORKAROUND) == TRUE); - - db_set_b(NULL, MODULE_NAME, "DoSnap", Options.DoSnap); - db_set_b(NULL, MODULE_NAME, "SnapWidth", Options.SnapWidth); - db_set_b(NULL, MODULE_NAME, "ScriverWorkAround", Options.ScriverWorkAround); - - break; - } - } - break; - } + EnableWindow(GetDlgItem(hwndDlg, IDC_SLIDER_SNAPWIDTH), Options.DoSnap); + EnableWindow(GetDlgItem(hwndDlg, IDC_TXT_SNAPWIDTH), Options.DoSnap); + + CheckDlgButton(hwndDlg, IDC_CHK_SCRIVERWORKAROUND, Options.ScriverWorkAround?BST_CHECKED:BST_UNCHECKED); + break; + + case WM_HSCROLL: + mir_sntprintf(str, SIZEOF(str), TranslateT("%d pix"), SendDlgItemMessage(hwndDlg, IDC_SLIDER_SNAPWIDTH, TBM_GETPOS, 0, 0)); + SetDlgItemText(hwndDlg, IDC_TXT_SNAPWIDTH, str); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + case WM_COMMAND: + switch( LOWORD(wParam)) { + case IDC_CHK_SNAP: + if (HIWORD(wParam) == BN_CLICKED) { + EnableWindow(GetDlgItem(hwndDlg, IDC_SLIDER_SNAPWIDTH), IsDlgButtonChecked(hwndDlg, IDC_CHK_SNAP)); + EnableWindow(GetDlgItem(hwndDlg, IDC_TXT_SNAPWIDTH), IsDlgButtonChecked(hwndDlg, IDC_CHK_SNAP)); + + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + } break; - - } - default: + case IDC_CHK_SCRIVERWORKAROUND: + if (HIWORD(wParam) == BN_CLICKED) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; + } + break; + + case WM_NOTIFY: //Here we have pressed either the OK or the APPLY button. + switch(((LPNMHDR)lParam)->idFrom) { + case 0: + switch (((LPNMHDR)lParam)->code) { + case PSN_RESET: + LoadOptions(); + break; + + case PSN_APPLY: + Options.DoSnap = (IsDlgButtonChecked(hwndDlg, IDC_CHK_SNAP) == TRUE); + Options.SnapWidth = SendDlgItemMessage(hwndDlg, IDC_SLIDER_SNAPWIDTH, TBM_GETPOS, 0, 0); + Options.ScriverWorkAround = (IsDlgButtonChecked(hwndDlg, IDC_CHK_SCRIVERWORKAROUND) == TRUE); + + db_set_b(NULL, MODULE_NAME, "DoSnap", Options.DoSnap); + db_set_b(NULL, MODULE_NAME, "SnapWidth", Options.SnapWidth); + db_set_b(NULL, MODULE_NAME, "ScriverWorkAround", Options.ScriverWorkAround); + break; + } + } + break; } return 0; - } -int InitOptions(WPARAM wParam, LPARAM) { - OPTIONSDIALOGPAGE Opt = { 0 }; - - Opt.cbSize = sizeof(Opt); +int InitOptions(WPARAM wParam, LPARAM) +{ + OPTIONSDIALOGPAGE Opt = { sizeof(Opt) }; Opt.pfnDlgProc = OptionsDlgProc; Opt.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_MAGNETICWINDOWS); Opt.hInstance = hInst; Opt.pszGroup = LPGEN("Customize"); Opt.pszTitle = LPGEN("Magnetic Windows"); Opt.flags = ODPF_BOLDGROUPS; - Options_AddPage(wParam, &Opt); - return 0; } -void LoadOptions() { +void LoadOptions() +{ Options.DoSnap = db_get_b(NULL, MODULE_NAME, "DoSnap", 1) != 0; Options.SnapWidth = db_get_b(NULL, MODULE_NAME, "SnapWidth", cDefaultSnapWidth); Options.ScriverWorkAround = db_get_b(NULL, MODULE_NAME, "ScriverWorkAround", 0) != 0; -} \ No newline at end of file +} diff --git a/plugins/MagneticWindows/src/Options.h b/plugins/MagneticWindows/src/Options.h index 8eae719fcb..1e9affa629 100644 --- a/plugins/MagneticWindows/src/Options.h +++ b/plugins/MagneticWindows/src/Options.h @@ -8,10 +8,8 @@ typedef bool ScriverWorkAround; } TOptions; -extern HANDLE hInitOptionsHook; extern TOptions Options; - INT_PTR CALLBACK OptionsDlgProc(HWND, UINT, WPARAM, LPARAM); int InitOptions(WPARAM, LPARAM); diff --git a/plugins/MagneticWindows/src/SnapToListService.cpp b/plugins/MagneticWindows/src/SnapToListService.cpp index df29a2cf70..586fa594b1 100644 --- a/plugins/MagneticWindows/src/SnapToListService.cpp +++ b/plugins/MagneticWindows/src/SnapToListService.cpp @@ -1,10 +1,7 @@ #include "MagneticWindowsCore.h" - -HANDLE hSnapToListService; - - -INT_PTR SnapToList(WPARAM wParam, LPARAM Align) { +INT_PTR SnapToList(WPARAM wParam, LPARAM Align) +{ HWND hWnd, hWndList; RECT WndRect, ListRect; RECT AlignRect; diff --git a/plugins/MagneticWindows/src/SnapToListService.h b/plugins/MagneticWindows/src/SnapToListService.h index 6e3b9a4077..3a421c454d 100644 --- a/plugins/MagneticWindows/src/SnapToListService.h +++ b/plugins/MagneticWindows/src/SnapToListService.h @@ -1,5 +1,2 @@ - -extern HANDLE hSnapToListService; - INT_PTR SnapToList(WPARAM, LPARAM); -- cgit v1.2.3