Subversion Repositories filter_foundry

Rev

Rev 476 | Rev 478 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 476 Rev 477
Line 23... Line 23...
23
 
23
 
24
// More information about the PLUGIN.DLL sliders:
24
// More information about the PLUGIN.DLL sliders:
25
// https://misc.daniel-marschall.de/projects/filter_factory/sliders.html
25
// https://misc.daniel-marschall.de/projects/filter_factory/sliders.html
26
 
26
 
27
// PLUGIN.DLL Sliders: This method will register the "slider" class used in dialogs.
27
// PLUGIN.DLL Sliders: This method will register the "slider" class used in dialogs.
-
 
28
#ifdef use_plugin_dll_sliders
28
typedef BOOL(__cdecl* f_RegisterSlider)(HINSTANCE hInstanceDll, DWORD* MessageID);
29
typedef BOOL(__cdecl* f_RegisterSlider)(HINSTANCE hInstanceDll, DWORD* MessageID);
29
BOOL RegisterSlider(HINSTANCE hInstanceDll, DWORD* MessageID) {
30
BOOL RegisterSlider(HINSTANCE hInstanceDll, DWORD* MessageID) {
30
        f_RegisterSlider fRegisterSlider;
31
        f_RegisterSlider fRegisterSlider;
31
        BOOL res;
32
        BOOL res;
32
 
33
 
33
        if (!gdata->libPluginDll) return false;
34
        if (!gdata->pluginDllSliderInfo.hLib) return false;
34
        fRegisterSlider = (f_RegisterSlider)(void*)GetProcAddress(gdata->libPluginDll, "RegisterSlider");
35
        fRegisterSlider = (f_RegisterSlider)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "RegisterSlider");
35
        res = (fRegisterSlider != 0) ? fRegisterSlider(hInstanceDll, MessageID) : false;
36
        res = (fRegisterSlider != 0) ? fRegisterSlider(hInstanceDll, MessageID) : false;
36
        return res;
37
        return res;
37
}
38
}
-
 
39
#endif
38
 
40
 
39
// PLUGIN.DLL Sliders: This method will unregister the "slider" class used in dialogs.
41
// PLUGIN.DLL Sliders: This method will unregister the "slider" class used in dialogs.
-
 
42
#ifdef use_plugin_dll_sliders
40
typedef BOOL(__cdecl* f_UnRegisterSlider)(HINSTANCE hInstanceDll);
43
typedef BOOL(__cdecl* f_UnRegisterSlider)(HINSTANCE hInstanceDll);
41
BOOL UnRegisterSlider(HINSTANCE hInstanceDll) {
44
BOOL UnRegisterSlider(HINSTANCE hInstanceDll) {
42
        f_UnRegisterSlider fUnRegisterSlider;
45
        f_UnRegisterSlider fUnRegisterSlider;
43
        BOOL res;
46
        BOOL res;
44
 
47
 
45
        if (!gdata->libPluginDll) return false;
48
        if (!gdata->pluginDllSliderInfo.hLib) return false;
46
        fUnRegisterSlider = (f_UnRegisterSlider)(void*)GetProcAddress(gdata->libPluginDll, "UnRegisterSlider");
49
        fUnRegisterSlider = (f_UnRegisterSlider)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "UnRegisterSlider");
47
        res = (fUnRegisterSlider != 0) ? fUnRegisterSlider(hInstanceDll) : false;
50
        res = (fUnRegisterSlider != 0) ? fUnRegisterSlider(hInstanceDll) : false;
48
        return res;
51
        return res;
49
}
52
}
-
 
53
#endif
50
 
54
 
51
// PLUGIN.DLL Sliders: Set slider range (min/max)
55
// PLUGIN.DLL Sliders: Set slider range (min/max)
-
 
56
#ifdef use_plugin_dll_sliders
52
typedef int(__cdecl* f_SetSliderRange)(HWND hWnd, int nMin, int nMax);
57
typedef int(__cdecl* f_SetSliderRange)(HWND hWnd, int nMin, int nMax);
53
int SetSliderRange(HWND hWnd, int nMin, int nMax) {
58
int SetSliderRange(HWND hWnd, int nMin, int nMax) {
54
        f_SetSliderRange fSetSliderRange;
59
        f_SetSliderRange fSetSliderRange;
55
        int res;
60
        int res;
56
 
61
 
57
        if (!gdata->libPluginDll) return 0;
62
        if (!gdata->pluginDllSliderInfo.hLib) return 0;
58
        fSetSliderRange = (f_SetSliderRange)(void*)GetProcAddress(gdata->libPluginDll, "SetSliderRange");
63
        fSetSliderRange = (f_SetSliderRange)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "SetSliderRange");
59
        res = (fSetSliderRange != 0) ? fSetSliderRange(hWnd, nMin, nMax) : 0;
64
        res = (fSetSliderRange != 0) ? fSetSliderRange(hWnd, nMin, nMax) : 0;
60
        return res;
65
        return res;
61
}
66
}
-
 
67
#endif
62
 
68
 
63
// PLUGIN.DLL Sliders : Sets slider position
69
// PLUGIN.DLL Sliders : Sets slider position
-
 
70
#ifdef use_plugin_dll_sliders
64
typedef int(__cdecl* f_SetSliderPos)(HWND hWnd, int nPos, BOOL bRepaint);
71
typedef int(__cdecl* f_SetSliderPos)(HWND hWnd, int nPos, BOOL bRepaint);
65
int SetSliderPos(HWND hWnd, int nPos, BOOL bRepaint) {
72
int SetSliderPos(HWND hWnd, int nPos, BOOL bRepaint) {
66
        f_SetSliderPos fSetSliderPos;
73
        f_SetSliderPos fSetSliderPos;
67
        int res;
74
        int res;
68
 
75
 
69
        if (!gdata->libPluginDll) return 0;
76
        if (!gdata->pluginDllSliderInfo.hLib) return 0;
70
        fSetSliderPos = (f_SetSliderPos)(void*)GetProcAddress(gdata->libPluginDll, "SetSliderPos");
77
        fSetSliderPos = (f_SetSliderPos)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "SetSliderPos");
71
        res = (fSetSliderPos != 0) ? fSetSliderPos(hWnd, nPos, bRepaint) : 0;
78
        res = (fSetSliderPos != 0) ? fSetSliderPos(hWnd, nPos, bRepaint) : 0;
72
        return res;
79
        return res;
73
}
80
}
-
 
81
#else
-
 
82
int SetSliderPos(HWND hWnd, int nPos, BOOL bRepaint) {
-
 
83
        // This dummy is required, otherwise ui_compat.h won't compile
-
 
84
        return 0;
-
 
85
}
-
 
86
#endif
74
 
87
 
75
// PLUGIN.DLL Sliders : Get slider position
88
// PLUGIN.DLL Sliders : Get slider position
-
 
89
#ifdef use_plugin_dll_sliders
76
typedef int(__cdecl* f_GetSliderPos)(HWND hWnd, BOOL bPixelPosition);
90
typedef int(__cdecl* f_GetSliderPos)(HWND hWnd, BOOL bPixelPosition);
77
int GetSliderPos(HWND hWnd, BOOL bPixelPosition) {
91
int GetSliderPos(HWND hWnd, BOOL bPixelPosition) {
78
        f_GetSliderPos fGetSliderPos;
92
        f_GetSliderPos fGetSliderPos;
79
        int res;
93
        int res;
80
 
94
 
81
        if (!gdata->libPluginDll) return 0;
95
        if (!gdata->pluginDllSliderInfo.hLib) return 0;
82
        fGetSliderPos = (f_GetSliderPos)(void*)GetProcAddress(gdata->libPluginDll, "GetSliderPos");
96
        fGetSliderPos = (f_GetSliderPos)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "GetSliderPos");
83
        res = (fGetSliderPos != 0) ? fGetSliderPos(hWnd, bPixelPosition) : 0;
97
        res = (fGetSliderPos != 0) ? fGetSliderPos(hWnd, bPixelPosition) : 0;
84
        return res;
98
        return res;
85
}
99
}
-
 
100
#else
-
 
101
int GetSliderPos(HWND hWnd, BOOL bPixelPosition) {
-
 
102
        // This dummy is required, otherwise ui_compat.h won't compile
-
 
103
        return 0;
-
 
104
}
-
 
105
#endif
86
 
106
 
87
LRESULT CALLBACK DummyWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
107
LRESULT CALLBACK DummyWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
88
        return DefWindowProc(hwnd, uMsg, wParam, lParam);
108
        return DefWindowProc(hwnd, uMsg, wParam, lParam);
89
}
109
}
90
 
110
 
Line 162... Line 182...
162
Boolean Slider_Init_PluginDll(LPCTSTR targetClass) {
182
Boolean Slider_Init_PluginDll(LPCTSTR targetClass) {
163
 
183
 
164
#ifndef use_plugin_dll_sliders
184
#ifndef use_plugin_dll_sliders
165
        return false;
185
        return false;
166
#else
186
#else
167
        if (gdata->pluginDllSliderInitialized) return true;
187
        if (gdata->pluginDllSliderInfo.initialized) return true;
168
 
188
 
169
        if (!gdata->libPluginDll) {
189
        if (!gdata->pluginDllSliderInfo.hLib) {
170
                // DM 16.04.2022 : It is important that PLUGIN.DLL stays loaded, otherwise
190
                // DM 16.04.2022 : It is important that PLUGIN.DLL stays loaded, otherwise
171
                // DialogBoxParamA crashes. Can be reproduced if all 8BX modules are disabled in Photoshop 7
191
                // DialogBoxParamA crashes. Can be reproduced if all 8BX modules are disabled in Photoshop 7
172
                // (they keep PLUGIN.DLL loaded).
192
                // (they keep PLUGIN.DLL loaded).
173
                gdata->libPluginDll = LoadLibrary(TEXT("Plugin.dll"));
193
                gdata->pluginDllSliderInfo.hLib = LoadLibrary(TEXT("Plugin.dll"));
174
        }
194
        }
175
 
195
 
176
        if (gdata->libPluginDll && RegisterSlider(hDllInstance, &gdata->pluginDllSliderMessageId)) {
196
        if (gdata->pluginDllSliderInfo.hLib && RegisterSlider(hDllInstance, &gdata->pluginDllSliderInfo.messageId)) {
177
                gdata->pluginDllSliderInitialized = true;
-
 
178
 
-
 
179
                // Make "FoundrySlider" a subclass of "slider" then
197
                // Make "FoundrySlider" a subclass of "slider" then
180
                return MakeSimpleSubclass(targetClass, TEXT("slider"));
198
                if (MakeSimpleSubclass(targetClass, TEXT("slider"))) {
-
 
199
                        gdata->pluginDllSliderInfo.initialized = true;
-
 
200
                        return true;
-
 
201
                }
-
 
202
                else {
-
 
203
                        return false;
-
 
204
                }
181
        }
205
        }
182
        else {
206
        else {
183
                // This can happen if PLUGIN.DLL is not existing
207
                // This can happen if PLUGIN.DLL is not existing
184
                // It will also happen if a previous uninitialization failed (or was forgotten)
208
                // It will also happen if a previous uninitialization failed (or was forgotten)
185
                return false; // Fall back to Windows sliders
209
                return false; // Fall back to Windows sliders
Line 190... Line 214...
190
 
214
 
191
void Slider_Uninit_PluginDll() {
215
void Slider_Uninit_PluginDll() {
192
#ifndef use_plugin_dll_sliders
216
#ifndef use_plugin_dll_sliders
193
        return;
217
        return;
194
#else
218
#else
195
        if (gdata->pluginDllSliderInitialized) {
219
        if (!gdata->pluginDllSliderInfo.initialized) return;
196
                if (UnRegisterSlider(hDllInstance)) {
-
 
197
                        gdata->pluginDllSliderInitialized = false;
-
 
198
 
220
 
199
                        if (gdata->libPluginDll) {
221
        if (!UnRegisterSlider(hDllInstance)) {
200
                                FreeLibrary(gdata->libPluginDll);
-
 
201
                                gdata->libPluginDll = 0;
-
 
202
                        }
-
 
203
                }
-
 
204
                else {
-
 
205
                        simplealert((TCHAR*)TEXT("UnRegisterSlider failed"));
222
                simplealert((TCHAR*)TEXT("UnRegisterSlider failed"));
-
 
223
                return;
206
                }
224
        }
-
 
225
 
-
 
226
        gdata->pluginDllSliderInfo.initialized = false;
-
 
227
 
-
 
228
        if (gdata->pluginDllSliderInfo.hLib) {
-
 
229
                FreeLibrary(gdata->pluginDllSliderInfo.hLib);
-
 
230
                gdata->pluginDllSliderInfo.hLib = 0;
207
        }
231
        }
208
#endif
232
#endif
209
 
-
 
210
}
233
}
211
 
234
 
212
typedef void(__stdcall* f_InitCommonControls)();
235
typedef void(__stdcall* f_InitCommonControls)();
213
typedef BOOL(__stdcall* f_InitCommonControlsEx)(const INITCOMMONCONTROLSEX* picce);
236
typedef BOOL(__stdcall* f_InitCommonControlsEx)(const INITCOMMONCONTROLSEX* picce);
214
Boolean Slider_Init_MsTrackbar(LPCTSTR targetClass) {
237
Boolean Slider_Init_MsTrackbar(LPCTSTR targetClass) {
215
        f_InitCommonControls fInitCommonControls;
238
        f_InitCommonControls fInitCommonControls;
216
        f_InitCommonControlsEx fInitCommonControlsEx;
239
        f_InitCommonControlsEx fInitCommonControlsEx;
217
 
240
 
-
 
241
        if (gdata->comctlSliderInfo.initialized) return true;
-
 
242
 
218
        // Make sure that Comctl32 is loaded
243
        // Make sure that Comctl32 is loaded
219
        if (!gdata->libComctl32) {
244
        if (!gdata->comctlSliderInfo.hLib) {
220
                gdata->libComctl32 = LoadLibrary(TEXT("Comctl32.dll"));
245
                gdata->comctlSliderInfo.hLib = LoadLibrary(TEXT("Comctl32.dll"));
221
        }
246
        }
222
        if (gdata->libComctl32) {
247
        if (gdata->comctlSliderInfo.hLib) {
223
                fInitCommonControlsEx = (f_InitCommonControlsEx)(void*)GetProcAddress(gdata->libComctl32, "InitCommonControlsEx");
248
                fInitCommonControlsEx = (f_InitCommonControlsEx)(void*)GetProcAddress(gdata->comctlSliderInfo.hLib, "InitCommonControlsEx");
224
                if (fInitCommonControlsEx != 0) {
249
                if (fInitCommonControlsEx != 0) {
225
                        INITCOMMONCONTROLSEX icce;
250
                        INITCOMMONCONTROLSEX icce;
226
                        icce.dwSize = sizeof(INITCOMMONCONTROLSEX);
251
                        icce.dwSize = sizeof(INITCOMMONCONTROLSEX);
227
                        icce.dwICC = ICC_BAR_CLASSES;
252
                        icce.dwICC = ICC_BAR_CLASSES;
228
                        fInitCommonControlsEx(&icce);
253
                        fInitCommonControlsEx(&icce);
229
                }
254
                }
230
                else {
255
                else {
231
                        fInitCommonControls = (f_InitCommonControls)(void*)GetProcAddress(gdata->libComctl32, "InitCommonControls");
256
                        fInitCommonControls = (f_InitCommonControls)(void*)GetProcAddress(gdata->comctlSliderInfo.hLib, "InitCommonControls");
232
                        if (fInitCommonControls != 0) {
257
                        if (fInitCommonControls != 0) {
233
                                fInitCommonControls();
258
                                fInitCommonControls();
234
                        }
259
                        }
235
                }
260
                }
236
 
261
 
237
                // Make "FoundrySlider" a subclass of "msctls_trackbar32" then
262
                // Make "FoundrySlider" a subclass of "msctls_trackbar32" then
238
                return MakeSimpleSubclass(targetClass, TEXT("msctls_trackbar32"));
263
                if (MakeSimpleSubclass(targetClass, TEXT("msctls_trackbar32"))) {
-
 
264
                        gdata->comctlSliderInfo.initialized = true;
-
 
265
                        return true;
-
 
266
                }
-
 
267
                else {
-
 
268
                        return false;
-
 
269
                }
239
        }
270
        }
240
        else {
271
        else {
241
                return false;
272
                return false;
242
        }
273
        }
243
}
274
}
244
 
275
 
245
void Slider_Uninit_MsTrackbar() {
276
void Slider_Uninit_MsTrackbar() {
-
 
277
        if (!gdata->comctlSliderInfo.initialized) return;
-
 
278
 
-
 
279
        gdata->comctlSliderInfo.initialized = false;
-
 
280
 
246
        if (gdata->libComctl32 != 0) {
281
        if (gdata->comctlSliderInfo.hLib != 0) {
247
                FreeLibrary(gdata->libComctl32);
282
                FreeLibrary(gdata->comctlSliderInfo.hLib);
248
                gdata->libComctl32 = 0;
283
                gdata->comctlSliderInfo.hLib = 0;
249
        }
284
        }
250
}
285
}
251
 
286
 
252
Boolean Slider_Init_None(LPCTSTR targetClass) {
287
Boolean Slider_Init_None(LPCTSTR targetClass) {
253
        // Make "FoundrySlider" a subclass of "STATIC" (making it invisible)
288
        // Make "FoundrySlider" a subclass of "STATIC" (making it invisible)
-
 
289
 
-
 
290
        if (gdata->noneSliderInfo.initialized) return true;
-
 
291
 
254
        return MakeSimpleSubclass(targetClass, WC_STATIC);
292
        if (MakeSimpleSubclass(targetClass, WC_STATIC)) {
-
 
293
                gdata->noneSliderInfo.initialized = true;
-
 
294
                return true;
-
 
295
        }
-
 
296
        else {
-
 
297
                return false;
-
 
298
        }
255
}
299
}
256
 
300
 
257
void Slider_Uninit_None() {
301
void Slider_Uninit_None() {
-
 
302
        if (!gdata->noneSliderInfo.initialized) return;
-
 
303
 
258
        // Nothing here
304
        // Nothing here
259
}
305
}
260
306