-
Notifications
You must be signed in to change notification settings - Fork 1
/
slider_win.c
353 lines (306 loc) · 12 KB
/
slider_win.c
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
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
/*
This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.net
Copyright (C) 2018-2024 Daniel Marschall, ViaThinkSoft
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 "ff.h"
#include "slider_win.h"
// More information about the PLUGIN.DLL sliders:
// https://misc.daniel-marschall.de/projects/filter_factory/sliders.html
#ifdef use_plugin_dll_sliders
typedef BOOL(__cdecl* f_RegisterSlider)(HINSTANCE hInstanceDll, DWORD* MessageID);
/**
PLUGIN.DLL Sliders : This method will register the "slider" class used in dialogs.
*/
BOOL PluginDll_RegisterSlider(HINSTANCE hInstanceDll, DWORD* MessageID) {
f_RegisterSlider fRegisterSlider;
BOOL res;
if (!gdata->pluginDllSliderInfo.hLib) return false;
fRegisterSlider = (f_RegisterSlider)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "RegisterSlider");
res = (fRegisterSlider != 0) ? fRegisterSlider(hInstanceDll, MessageID) : false;
return res;
}
#endif
#ifdef use_plugin_dll_sliders
typedef BOOL(__cdecl* f_UnRegisterSlider)(HINSTANCE hInstanceDll);
/**
PLUGIN.DLL Sliders : This method will unregister the "slider" class used in dialogs.
*/
BOOL PluginDll_UnRegisterSlider(HINSTANCE hInstanceDll) {
f_UnRegisterSlider fUnRegisterSlider;
BOOL res;
if (!gdata->pluginDllSliderInfo.hLib) return false;
fUnRegisterSlider = (f_UnRegisterSlider)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "UnRegisterSlider");
res = (fUnRegisterSlider != 0) ? fUnRegisterSlider(hInstanceDll) : false;
return res;
}
#endif
#ifdef use_plugin_dll_sliders
typedef int(__cdecl* f_SetSliderRange)(HWND hWnd, int nMin, int nMax);
/**
PLUGIN.DLL Sliders: Set slider range (min/max)
*/
int PluginDll_SetSliderRange(HWND hWnd, int nMin, int nMax) {
f_SetSliderRange fSetSliderRange;
int res;
if (!gdata->pluginDllSliderInfo.hLib) return 0;
fSetSliderRange = (f_SetSliderRange)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "SetSliderRange");
res = (fSetSliderRange != 0) ? fSetSliderRange(hWnd, nMin, nMax) : 0;
return res;
}
#endif
#ifdef use_plugin_dll_sliders
#define FLAG_AUTOSNAP 0x40000000ul
typedef enum BitMode_ {
UnsetBits = -1,
SetExplicit = 0,
SetBits = 1
} BitMode;
typedef void(__cdecl* f_SetSliderFlags)(HWND hWnd, BitMode bitMode, int bits);
/**
PLUGIN.DLL Sliders: Set flags
*/
void __cdecl PluginDll_SetSliderFlags(HWND hWnd, BitMode bitMode, int bits) {
f_SetSliderFlags fSetSliderFlags;
if (!gdata->pluginDllSliderInfo.hLib) return;
fSetSliderFlags = (f_SetSliderFlags)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "SetSliderFlags");
if (fSetSliderFlags != 0) {
fSetSliderFlags(hWnd, bitMode, bits);
}
}
#endif
#ifdef use_plugin_dll_sliders
typedef int(__cdecl* f_SetSliderPos)(HWND hWnd, int nPos, BOOL bRepaint);
/**
PLUGIN.DLL Sliders : Sets slider position
*/
int PluginDll_SetSliderPos(HWND hWnd, int nPos, BOOL bRepaint) {
f_SetSliderPos fSetSliderPos;
int res;
if (!gdata->pluginDllSliderInfo.hLib) return 0;
fSetSliderPos = (f_SetSliderPos)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "SetSliderPos");
res = (fSetSliderPos != 0) ? fSetSliderPos(hWnd, nPos, bRepaint) : 0;
return res;
}
#endif
#ifdef use_plugin_dll_sliders
typedef int(__cdecl* f_GetSliderPos)(HWND hWnd, BOOL bPixelPosition);
/**
PLUGIN.DLL Sliders : Get slider position
*/
int PluginDll_GetSliderPos(HWND hWnd, BOOL bPixelPosition) {
f_GetSliderPos fGetSliderPos;
int res;
if (!gdata->pluginDllSliderInfo.hLib) return 0;
fGetSliderPos = (f_GetSliderPos)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "GetSliderPos");
res = (fGetSliderPos != 0) ? fGetSliderPos(hWnd, bPixelPosition) : 0;
return res;
}
#endif
void FF_SetSliderRange(HWND hDlg, int nIDDlgItem, int min, int max) {
if (!gdata->pluginDllSliderInfo.initialized) {
// Non PLUGIN.DLL sliders
SetWindowLongPtr(GetDlgItem(hDlg, nIDDlgItem), GWL_STYLE, TBS_HORZ | TBS_AUTOTICKS | WS_CHILD | WS_VISIBLE);
SendDlgItemMessage(hDlg, nIDDlgItem, TBM_SETRANGE, TRUE, MAKELONG(min, max));
SendDlgItemMessage(hDlg, nIDDlgItem, TBM_SETTICFREQ, SLIDERPAGE, 0);
SendDlgItemMessage(hDlg, nIDDlgItem, TBM_SETPAGESIZE, 0, SLIDERPAGE);
} else {
// PLUGIN.DLL sliders
#ifdef use_plugin_dll_sliders
PluginDll_SetSliderRange(GetDlgItem(hDlg, nIDDlgItem), min, max);
PluginDll_SetSliderFlags(GetDlgItem(hDlg, nIDDlgItem), SetBits, FLAG_AUTOSNAP);
#endif
}
}
int FF_GetSliderPos(HWND hDlg, int nIDDlgItem) {
if (gdata->pluginDllSliderInfo.initialized) {
return PluginDll_GetSliderPos(GetDlgItem(hDlg, nIDDlgItem), false);
} else if (gdata->comctlSliderInfo.initialized) {
return (int)SendDlgItemMessage(hDlg, nIDDlgItem, TBM_GETPOS, 0, 0);
} else {
return 0;
}
}
void FF_SetSliderPos(HWND hDlg, int nIDDlgItem, int pos) {
if (gdata->pluginDllSliderInfo.initialized) {
PluginDll_SetSliderPos(GetDlgItem(hDlg, nIDDlgItem), pos, true);
} else if (gdata->comctlSliderInfo.initialized) {
SendDlgItemMessage(hDlg, nIDDlgItem, TBM_SETPOS, TRUE, pos);
}
}
LRESULT CALLBACK DummyWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
void Win32sFixSuperclassing(HWND hDlg, int destItem, int sourceItem) {
// Win32s (Win3.11) compatibility fix: Since GetClassInfo(WC_BUTTON) and GetClassInfo(WC_STATIC) won't work,
// we had replaced the WndProc by a dummy. Now, we find out the real Button and Static WndProcs and give them
// to our classes, making them the intended superclasses. Messages which have been sent in between were lost,
// though...
WNDPROC wndProc;
#ifdef _WIN64
wndProc = (WNDPROC)GetWindowLongPtr(GetDlgItem(hDlg, destItem), GWLP_WNDPROC);
if (wndProc == DummyWndProc) {
wndProc = (WNDPROC)GetWindowLongPtr(GetDlgItem(hDlg, sourceItem), GWLP_WNDPROC);
SetWindowLongPtr(GetDlgItem(hDlg, destItem), GWLP_WNDPROC, (LONG_PTR)wndProc);
}
#else
wndProc = (WNDPROC)GetWindowLongPtr(GetDlgItem(hDlg, destItem), GWL_WNDPROC);
if (wndProc == DummyWndProc) {
wndProc = (WNDPROC)GetWindowLongPtr(GetDlgItem(hDlg, sourceItem), GWL_WNDPROC);
SetWindowLongPtr(GetDlgItem(hDlg, destItem), GWL_WNDPROC, (LONG_PTR)wndProc);
}
#endif
}
Boolean MakeSimpleSubclass(LPCTSTR targetClass, LPCTSTR sourceClass) {
WNDCLASS clx;
if (GetClassInfo(hDllInstance, sourceClass, &clx) != 0) {
clx.lpszClassName = targetClass;
if (RegisterClass(&clx) == 0) {
TCHAR s[0x300];
xstrcpy(s, (TCHAR*)TEXT("RegisterClass failed: ")); // TODO (Not so important): TRANSLATE
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + xstrlen(s), 0x300 - (DWORD)xstrlen(s), NULL);
simplealert(&s[0]);
return false;
} else {
return true;
}
} else {
if ((xstrcmp(sourceClass, WC_BUTTON) == 0) || (xstrcmp(sourceClass, WC_STATIC) == 0)) {
// GetClassInfo(WC_STATIC) and GetClassInfo(WC_BUTTON) fail on Win32s (Windows 3.11)
// So we create a fake-class now. It will be replaced with the real Button/Static WndProc later!
clx.style = 0;
clx.lpfnWndProc = DummyWndProc;
clx.cbClsExtra = 0;
clx.cbWndExtra = 0;
clx.hInstance = hDllInstance;
clx.hIcon = 0;
clx.hCursor = 0;
clx.hbrBackground = 0;
clx.lpszMenuName = 0;
clx.lpszClassName = targetClass;
if (RegisterClass(&clx) == 0) {
TCHAR s[0x300];
xstrcpy(s, (TCHAR*)TEXT("RegisterClass failed: ")); // TODO (Not so important): TRANSLATE
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + xstrlen(s), 0x300 - (DWORD)xstrlen(s), NULL);
simplealert(&s[0]);
return false;
} else {
return true;
}
} else {
simplealert((TCHAR*)TEXT("GetClassInfo failed")); // TODO (Not so important): TRANSLATE
}
return false;
}
}
Boolean Slider_Init_PluginDll(LPCTSTR targetClass) {
#ifndef use_plugin_dll_sliders
return false;
#else
if (gdata->pluginDllSliderInfo.initialized) return true;
if (!gdata->pluginDllSliderInfo.hLib) {
// DM 16.04.2022 : It is important that PLUGIN.DLL stays loaded, otherwise
// DialogBoxParamA crashes. Can be reproduced if all 8BX modules are disabled in Photoshop 7
// (they keep PLUGIN.DLL loaded).
gdata->pluginDllSliderInfo.hLib = LoadLibrary(TEXT("Plugin.dll"));
}
if (gdata->pluginDllSliderInfo.hLib && PluginDll_RegisterSlider(hDllInstance, &gdata->pluginDllSliderInfo.messageId)) {
// Make "1.3.6.1.4.1.37476.2.72.2.1" a subclass of "Slider" (defined by Plugin.dll) then
if (MakeSimpleSubclass(targetClass, TEXT("Slider"))) {
gdata->pluginDllSliderInfo.initialized = true;
return true;
} else {
return false;
}
} else {
// This can happen if PLUGIN.DLL is not existing
// It will also happen if a previous uninitialization failed (or was forgotten)
return false; // Fall back to Windows sliders
}
#endif
}
void Slider_Uninit_PluginDll(void) {
#ifndef use_plugin_dll_sliders
return;
#else
if (!gdata->pluginDllSliderInfo.initialized) return;
if (!PluginDll_UnRegisterSlider(hDllInstance)) {
simplealert((TCHAR*)TEXT("UnRegisterSlider failed")); // TODO (Not so important): TRANSLATE
return;
}
gdata->pluginDllSliderInfo.initialized = false;
if (gdata->pluginDllSliderInfo.hLib) {
FreeLibrary(gdata->pluginDllSliderInfo.hLib);
gdata->pluginDllSliderInfo.hLib = 0;
}
#endif
}
typedef void(__stdcall* f_InitCommonControls)();
typedef BOOL(__stdcall* f_InitCommonControlsEx)(const INITCOMMONCONTROLSEX* picce);
Boolean Slider_Init_MsTrackbar(LPCTSTR targetClass) {
f_InitCommonControls fInitCommonControls;
f_InitCommonControlsEx fInitCommonControlsEx;
if (gdata->comctlSliderInfo.initialized) return true;
// Make sure that Comctl32 is loaded
if (!gdata->comctlSliderInfo.hLib) {
gdata->comctlSliderInfo.hLib = LoadLibrary(TEXT("Comctl32.dll"));
}
if (gdata->comctlSliderInfo.hLib) {
fInitCommonControlsEx = (f_InitCommonControlsEx)(void*)GetProcAddress(gdata->comctlSliderInfo.hLib, "InitCommonControlsEx");
if (fInitCommonControlsEx != 0) {
INITCOMMONCONTROLSEX icce;
icce.dwSize = sizeof(INITCOMMONCONTROLSEX);
icce.dwICC = ICC_BAR_CLASSES;
fInitCommonControlsEx(&icce);
} else {
fInitCommonControls = (f_InitCommonControls)(void*)GetProcAddress(gdata->comctlSliderInfo.hLib, "InitCommonControls");
if (fInitCommonControls != 0) {
fInitCommonControls();
}
}
// Make "1.3.6.1.4.1.37476.2.72.2.1" a subclass of "msctls_trackbar32" then
if (MakeSimpleSubclass(targetClass, TEXT("msctls_trackbar32"))) {
gdata->comctlSliderInfo.initialized = true;
return true;
} else {
return false;
}
} else {
return false;
}
}
void Slider_Uninit_MsTrackbar(void) {
if (!gdata->comctlSliderInfo.initialized) return;
gdata->comctlSliderInfo.initialized = false;
if (gdata->comctlSliderInfo.hLib != 0) {
FreeLibrary(gdata->comctlSliderInfo.hLib);
gdata->comctlSliderInfo.hLib = 0;
}
}
/**
Make "1.3.6.1.4.1.37476.2.72.2.1" a subclass of "STATIC" (making it invisible)
*/
Boolean Slider_Init_None(LPCTSTR targetClass) {
if (gdata->noneSliderInfo.initialized) return true;
if (MakeSimpleSubclass(targetClass, WC_STATIC)) {
gdata->noneSliderInfo.initialized = true;
return true;
} else {
return false;
}
}
void Slider_Uninit_None(void) {
if (!gdata->noneSliderInfo.initialized) return;
// Nothing here
}