1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
/*
Miranda NG: the free IM client for Microsoft* Windows*
Copyright (C) 2012-22 Miranda NG team (https://miranda-ng.org),
Copyright (c) 2000-08 Miranda ICQ/IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.
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; either version 2
of the License, or (at your option) any later version.
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, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "stdafx.h"
#include "modern_sync.h"
#define WM_DOCKCALLBACK (WM_USER+121)
#define WM_CREATEDOCKED (WM_USER+122)
#define EDGESENSITIVITY 3
#define DOCKED_NONE 0
#define DOCKED_LEFT 1
#define DOCKED_RIGHT 2
BOOL LockSubframeMoving = 0;
static int TempDock = 0;
static int dock_drag_dx = 0;
static int dock_drag_dy = 0;
static void Docking_GetMonitorRectFromPoint(POINT pt, RECT *rc)
{
MONITORINFO monitorInfo;
HMONITOR hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST); // always returns a valid value
monitorInfo.cbSize = sizeof(MONITORINFO);
if (GetMonitorInfo(hMonitor, &monitorInfo))
{
memcpy(rc, &monitorInfo.rcMonitor, sizeof(RECT));
return;
}
// "generic" win95/NT support, also serves as failsafe
rc->left = 0;
rc->top = 0;
rc->bottom = GetSystemMetrics(SM_CYSCREEN);
rc->right = GetSystemMetrics(SM_CXSCREEN);
}
void Docking_GetMonitorRectFromWindow(HWND hWnd, RECT *rc)
{
POINT ptWindow;
GetWindowRect(hWnd, rc);
ptWindow.x = rc->left;
ptWindow.y = rc->top;
Docking_GetMonitorRectFromPoint(ptWindow, rc);
}
static void Docking_AdjustPosition(HWND hwnd, RECT *rcDisplay, RECT *rc)
{
APPBARDATA abd;
memset(&abd, 0, sizeof(abd));
abd.cbSize = sizeof(abd);
abd.hWnd = hwnd;
abd.uEdge = g_CluiData.fDocked == DOCKED_LEFT ? ABE_LEFT : ABE_RIGHT;
abd.rc = *rc;
abd.rc.top = rcDisplay->top;
abd.rc.bottom = rcDisplay->bottom;
if (g_CluiData.fDocked == DOCKED_LEFT) {
abd.rc.right = rcDisplay->left + abd.rc.right - abd.rc.left;
abd.rc.left = rcDisplay->left;
}
else {
abd.rc.left = rcDisplay->right - (abd.rc.right - abd.rc.left);
abd.rc.right = rcDisplay->right;
}
SHAppBarMessage(ABM_SETPOS, &abd);
*rc = abd.rc;
}
int Docking_IsDocked(WPARAM, LPARAM)
{
return g_CluiData.fDocked;
}
int Docking_ProcessWindowMessage(WPARAM wParam, LPARAM lParam)
{
APPBARDATA abd;
static int draggingTitle;
MSG *msg = (MSG*)wParam;
if (msg->message == WM_DESTROY)
g_plugin.setByte("Docked", (uint8_t)g_CluiData.fDocked);
if (!g_CluiData.fDocked && msg->message != WM_CREATE && msg->message != WM_MOVING && msg->message != WM_CREATEDOCKED && msg->message != WM_MOVE && msg->message != WM_SIZE) return 0;
switch (msg->message) {
case WM_CREATE:
//if (GetSystemMetrics(SM_CMONITORS)>1) return 0;
if (g_plugin.getByte("Docked", 0) && db_get_b(0, "CLUI", "DockToSides", SETTING_DOCKTOSIDES_DEFAULT))
{
PostMessage(msg->hwnd, WM_CREATEDOCKED, 0, 0);
}
draggingTitle = 0;
return 0;
case WM_CREATEDOCKED:
//we need to post a message just after creation to let main message function do some work
g_CluiData.fDocked = (BOOL)g_plugin.getByte("Docked", 0);
if (IsWindowVisible(msg->hwnd) && !IsIconic(msg->hwnd)) {
RECT rc, rcMonitor;
memset(&abd, 0, sizeof(abd));
abd.cbSize = sizeof(abd);
abd.hWnd = msg->hwnd;
abd.lParam = 0;
abd.uCallbackMessage = WM_DOCKCALLBACK;
SHAppBarMessage(ABM_NEW, &abd);
GetWindowRect(msg->hwnd, &rc);
Docking_GetMonitorRectFromWindow(msg->hwnd, &rcMonitor);
Docking_AdjustPosition(msg->hwnd, &rcMonitor, &rc);
MoveWindow(msg->hwnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE);
g_CluiData.mutexPreventDockMoving = 0;
Sync(CLUIFrames_OnMoving, msg->hwnd, &rc);
g_CluiData.mutexPreventDockMoving = 1;
ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW, nullptr);
}
break;
case WM_CAPTURECHANGED:
ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW, nullptr);
return 0;
case WM_ACTIVATE:
memset(&abd, 0, sizeof(abd));
abd.cbSize = sizeof(abd);
abd.hWnd = msg->hwnd;
SHAppBarMessage(ABM_ACTIVATE, &abd);
return 0;
case WM_SIZE:
ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_REDRAW_ALL, nullptr);
return 0;
case WM_WINDOWPOSCHANGED:
{
if (g_CluiData.fDocked)
ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW, nullptr);
return 0;
}
case WM_MOVING:
{
RECT rcMonitor;
RECT rcWindow;
RECT *rc;
int dx = 0;
POINT ptCursor;
if (g_CluiData.fDocked) return 0;
// GetMessagePos() is no good, position is always unsigned
GetCursorPos(&ptCursor);
GetWindowRect(msg->hwnd, &rcWindow);
dock_drag_dx = rcWindow.left - ptCursor.x;
dock_drag_dy = rcWindow.top - ptCursor.y;
Docking_GetMonitorRectFromPoint(ptCursor, &rcMonitor);
if (((ptCursor.x < rcMonitor.left + EDGESENSITIVITY)
|| (ptCursor.x >= rcMonitor.right - EDGESENSITIVITY))
&& db_get_b(0, "CLUI", "DockToSides", SETTING_DOCKTOSIDES_DEFAULT))
{
memset(&abd, 0, sizeof(abd));
abd.cbSize = sizeof(abd);
abd.hWnd = msg->hwnd;
abd.lParam = 0;
abd.uCallbackMessage = WM_DOCKCALLBACK;
SHAppBarMessage(ABM_NEW, &abd);
if (ptCursor.x < rcMonitor.left + EDGESENSITIVITY) g_CluiData.fDocked = DOCKED_LEFT;
else g_CluiData.fDocked = DOCKED_RIGHT;
// TempDock = 1;
GetWindowRect(msg->hwnd, (LPRECT)msg->lParam);
rc = (RECT*)msg->lParam;
if (g_CluiData.fDocked == DOCKED_RIGHT)
dx = (rc->right > rcMonitor.right) ? rc->right - rcMonitor.right : 0;
else
dx = (rc->left < rcMonitor.left) ? rc->left - rcMonitor.left : 0;
OffsetRect(rc, -dx, 0);
Docking_AdjustPosition(msg->hwnd, (LPRECT)&rcMonitor, (LPRECT)msg->lParam);
SendMessage(msg->hwnd, WM_SIZE, 0, 0);
g_CluiData.mutexPreventDockMoving = 0;
Sync(CLUIFrames_OnMoving, msg->hwnd, (LPRECT)msg->lParam);
g_CluiData.mutexPreventDockMoving = 1;
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
g_plugin.setByte("Docked", (uint8_t)g_CluiData.fDocked);
ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW, nullptr);
return TRUE;
}
return 0;
}
case WM_EXITSIZEMOVE:
{
RECT rcMonitor;
RECT rcWindow;
if (TempDock) TempDock = 0;
GetWindowRect(msg->hwnd, &rcWindow);
Docking_GetMonitorRectFromWindow(msg->hwnd, &rcMonitor);
Docking_AdjustPosition(msg->hwnd, &rcMonitor, &rcWindow);
*((LRESULT*)lParam) = TRUE;
g_CluiData.mutexPreventDockMoving = 0;
SetWindowPos(msg->hwnd, nullptr, rcWindow.left, rcWindow.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOREDRAW | SWP_NOSENDCHANGING);
Sync(CLUIFrames_OnMoving, msg->hwnd, &rcWindow);
ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW, nullptr);// -= -= -=
g_CluiData.mutexPreventDockMoving = 1;
return 1;
}
case WM_MOVE:
{
ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_ALT_DRAW, nullptr);
return 0;
}
case WM_SIZING:
{
if (g_CluiData.fDocked) ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW, nullptr);
return FALSE;
}
case WM_SHOWWINDOW:
{
if (msg->lParam)
return 0;
if ((msg->wParam && g_CluiData.fDocked < 0) || (!msg->wParam && g_CluiData.fDocked>0))
g_CluiData.fDocked = -g_CluiData.fDocked;
memset(&abd, 0, sizeof(abd));
abd.cbSize = sizeof(abd);
abd.hWnd = msg->hwnd;
if (msg->wParam) {
RECT rc, rcMonitor;
Docking_GetMonitorRectFromWindow(msg->hwnd, &rcMonitor);
abd.lParam = 0;
abd.uCallbackMessage = WM_DOCKCALLBACK;
SHAppBarMessage(ABM_NEW, &abd);
GetWindowRect(msg->hwnd, &rc);
Docking_AdjustPosition(msg->hwnd, &rcMonitor, &rc);
MoveWindow(msg->hwnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE);
Sync(CLUIFrames_OnMoving, msg->hwnd, &rc);
ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW, nullptr);// -= -= -=
}
else {
SHAppBarMessage(ABM_REMOVE, &abd);
}
}
return 0;
case WM_NCHITTEST:
{ LONG result;
result = DefWindowProc(msg->hwnd, WM_NCHITTEST, msg->wParam, msg->lParam);
if (result == HTSIZE || result == HTTOP || result == HTTOPLEFT || result == HTTOPRIGHT ||
result == HTBOTTOM || result == HTBOTTOMRIGHT || result == HTBOTTOMLEFT) {
*((LRESULT*)lParam) = HTCLIENT; return TRUE;
}
if (g_CluiData.fDocked == DOCKED_LEFT && result == HTLEFT) { *((LRESULT*)lParam) = HTCLIENT; return TRUE; }
if (g_CluiData.fDocked == DOCKED_RIGHT && result == HTRIGHT) { *((LRESULT*)lParam) = HTCLIENT; return TRUE; }
return 0;
}
case WM_SYSCOMMAND:
if ((msg->wParam & 0xFFF0) != SC_MOVE) return 0;
SetActiveWindow(msg->hwnd);
SetCapture(msg->hwnd);
draggingTitle = 1;
*((LRESULT*)lParam) = 0;
return TRUE;
case WM_MOUSEMOVE:
if (!draggingTitle) return 0;
{ RECT rc;
POINT pt;
GetClientRect(msg->hwnd, &rc);
if (((g_CluiData.fDocked == DOCKED_LEFT || g_CluiData.fDocked == -DOCKED_LEFT) && (short)LOWORD(msg->lParam) > rc.right) ||
((g_CluiData.fDocked == DOCKED_RIGHT || g_CluiData.fDocked == -DOCKED_RIGHT) && (short)LOWORD(msg->lParam) < 0)) {
ReleaseCapture();
draggingTitle = 0;
memset(&abd, 0, sizeof(abd));
abd.cbSize = sizeof(abd);
abd.hWnd = msg->hwnd;
SHAppBarMessage(ABM_REMOVE, &abd);
g_CluiData.fDocked = 0;
GetCursorPos(&pt);
PostMessage(msg->hwnd, WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(pt.x, pt.y));
SetWindowPos(msg->hwnd, nullptr, pt.x - rc.right / 2, pt.y - GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYSMCAPTION) / 2, g_plugin.getDword("Width", 0), g_plugin.getDword("Height", 0), SWP_NOZORDER);
g_plugin.setByte("Docked", (uint8_t)g_CluiData.fDocked);
// ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW, nullptr);
}
return 1;
}
case WM_LBUTTONUP:
if (draggingTitle) {
ReleaseCapture();
draggingTitle = 0;
}
return 0;
case WM_DOCKCALLBACK:
switch (msg->wParam) {
case ABN_WINDOWARRANGE:
CLUI_ShowWindowMod(msg->hwnd, msg->lParam ? SW_HIDE : SW_SHOW);
{
RECT rc, rcMonitor;
Docking_GetMonitorRectFromWindow(msg->hwnd, &rcMonitor);
GetWindowRect(msg->hwnd, &rc);
Docking_AdjustPosition(msg->hwnd, &rcMonitor, &rc);
Sync(CLUIFrames_OnMoving, msg->hwnd, &rc); // -= -= -=
ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW, nullptr);
g_CluiData.mutexPreventDockMoving = 1;
}
break;
}
return TRUE;
case WM_DESTROY:
if (g_CluiData.fDocked > 0) {
memset(&abd, 0, sizeof(abd));
abd.cbSize = sizeof(abd);
abd.hWnd = msg->hwnd;
SHAppBarMessage(ABM_REMOVE, &abd);
ModernSkinButton_ReposButtons(msg->hwnd, SBRF_DO_NOT_DRAW, nullptr);
}
return 0;
}
return 0;
}
|