Subversion Repositories filter_foundry

Rev

Rev 443 | Rev 454 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
439 daniel-mar 1
/*
2
        This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
3
        Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au
4
        Copyright (C) 2018-2021 Daniel Marschall, ViaThinkSoft
5
 
6
        This program is free software; you can redistribute it and/or modify
7
        it under the terms of the GNU General Public License as published by
8
        the Free Software Foundation; either version 2 of the License, or
9
        (at your option) any later version.
10
 
11
        This program is distributed in the hope that it will be useful,
12
        but WITHOUT ANY WARRANTY; without even the implied warranty of
13
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
        GNU General Public License for more details.
15
 
16
        You should have received a copy of the GNU General Public License
17
        along with this program; if not, write to the Free Software
18
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
*/
20
 
21
#include "ff.h"
443 daniel-mar 22
#include "slider_win.h"
439 daniel-mar 23
 
24
// PLUGIN.DLL Sliders: This method will register the "slider" class used in dialogs.
25
typedef int(__cdecl* f_RegisterSlider)(HINSTANCE hInstanceDll, DWORD* MessageID);
26
int RegisterSlider(HINSTANCE hInstanceDll, DWORD* MessageID) {
27
        f_RegisterSlider fRegisterSlider;
28
 
29
        if (!gdata->pluginDllModule) return 0;
30
        fRegisterSlider = (f_RegisterSlider)(void*)GetProcAddress(gdata->pluginDllModule, "RegisterSlider");
31
        if (fRegisterSlider != 0) {
32
                return fRegisterSlider(hInstanceDll, MessageID);
33
        }
34
        else {
35
                return 0;
36
        }
37
}
38
 
39
// PLUGIN.DLL Sliders: This method will unregister the "slider" class used in dialogs.
40
typedef int(__cdecl* f_UnregisterSlider)(HINSTANCE hInstanceDll);
41
int UnregisterSlider(HINSTANCE hInstanceDll) {
42
        f_UnregisterSlider fUnregisterSlider;
43
 
44
        if (!gdata->pluginDllModule) return 0;
45
        fUnregisterSlider = (f_UnregisterSlider)(void*)GetProcAddress(gdata->pluginDllModule, "UnregisterSlider");
46
        if (fUnregisterSlider != 0) {
47
                return fUnregisterSlider(hInstanceDll);
48
        }
49
        else {
50
                return 0;
51
        }
52
}
53
 
54
// PLUGIN.DLL Sliders: Set slider range (min/max)
55
typedef int(__cdecl* f_SetSliderRange)(HWND hWnd, int nMin, int nMax);
56
int SetSliderRange(HWND hWnd, int nMin, int nMax) {
57
        f_SetSliderRange fSetSliderRange;
58
 
59
        if (!gdata->pluginDllModule) return 0;
60
        fSetSliderRange = (f_SetSliderRange)(void*)GetProcAddress(gdata->pluginDllModule, "SetSliderRange");
61
        if (fSetSliderRange != 0) {
62
                return fSetSliderRange(hWnd, nMin, nMax);
63
        }
64
        else {
65
                return 0;
66
        }
67
}
68
 
69
// PLUGIN.DLL Sliders : Sets slider position
70
typedef int(__cdecl* f_SetSliderPos)(HWND hWnd, int nPos, BOOL bRepaint);
71
int SetSliderPos(HWND hWnd, int nPos, BOOL bRepaint) {
72
        f_SetSliderPos fSetSliderPos;
73
 
74
        if (!gdata->pluginDllModule) return 0;
75
        fSetSliderPos = (f_SetSliderPos)(void*)GetProcAddress(gdata->pluginDllModule, "SetSliderPos");
76
        if (fSetSliderPos != 0) {
77
                return fSetSliderPos(hWnd, nPos, bRepaint);
78
        }
79
        else {
80
                return 0;
81
        }
82
}
83
 
84
// PLUGIN.DLL Sliders : Get slider position
85
typedef int(__cdecl* f_GetSliderPos)(HWND hWnd, BOOL bPixelPosition);
86
int GetSliderPos(HWND hWnd, BOOL bPixelPosition) {
87
        f_GetSliderPos fGetSliderPos;
88
 
89
        if (!gdata->pluginDllModule) return 0;
90
        fGetSliderPos = (f_GetSliderPos)(void*)GetProcAddress(gdata->pluginDllModule, "GetSliderPos");
91
        if (fGetSliderPos != 0) {
92
                int res = fGetSliderPos(hWnd, bPixelPosition);
93
                return res;
94
        }
95
        else {
96
                return 0;
97
        }
98
}
99
 
444 daniel-mar 100
Boolean MakeSimpleSubclass(LPCTSTR targetClass, LPCTSTR sourceClass) {
439 daniel-mar 101
        WNDCLASS clx;
102
 
444 daniel-mar 103
        if (GetClassInfo(hDllInstance, sourceClass, &clx) != 0) {
439 daniel-mar 104
                clx.lpszClassName = targetClass;
105
                if (RegisterClass(&clx) == 0) {
444 daniel-mar 106
                        TCHAR s[0x300];
107
                        xstrcpy(s, (TCHAR*)TEXT("RegisterClass failed: "));
108
                        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + xstrlen(s), 0x300 - xstrlen(s), NULL);
109
                        dbg(&s[0]);
439 daniel-mar 110
                        return false;
111
                }
112
                else {
113
                        return true;
114
                }
115
        }
116
        else {
117
                return false;
118
        }
119
}
120
 
121
void Slider_Uninit_PluginDll() {
122
 
123
#ifndef use_plugin_dll_sliders
124
        return;
125
#else
126
        WNDCLASS clx;
127
 
444 daniel-mar 128
        if (GetClassInfo(hDllInstance, TEXT("slider"), &clx) != 0) {
439 daniel-mar 129
                UnregisterSlider(hDllInstance);
130
        }
131
        if (gdata->pluginDllModule) {
132
                FreeLibrary(gdata->pluginDllModule);
133
                gdata->pluginDllModule = 0;
134
        }
135
#endif
136
 
137
}
138
 
444 daniel-mar 139
Boolean Slider_Init_PluginDll(LPCTSTR targetClass) {
439 daniel-mar 140
 
141
#ifndef use_plugin_dll_sliders
142
        return false;
143
#else
144
        DWORD sliderMsgId;
145
 
146
        // Try loading PLUGIN.DLL (only Photoshop) in order to register the class "slider"
444 daniel-mar 147
        gdata->pluginDllModule = LoadLibrary(TEXT("PLUGIN.DLL"));
439 daniel-mar 148
        if (!gdata->pluginDllModule) return false;
149
        sliderMsgId = 0; // important
150
        RegisterSlider(hDllInstance, &sliderMsgId);
151
        if (sliderMsgId != 0) {
152
                // RegisterSlider will "remember" if it gave you a message ID before,
153
                // and it will NOT give it to you again! (instead, the output variable stays untouched).
154
                // The problem: PLUGIN.DLL stays loaded the whole time, so it keeps remembering, while Filter Foundry
155
                // loses its internal state every time the window is closed.
156
                // So, we keep the message ID in the global (persistant) data, so we remember it.
157
                gdata->pluginDllSliderMessageId = sliderMsgId;
158
        }
159
 
160
        // Make "FoundrySlider" a subclass of "slider" then
444 daniel-mar 161
        return MakeSimpleSubclass(targetClass, TEXT("slider"));
439 daniel-mar 162
#endif
163
 
164
}
165
 
166
typedef void(__stdcall* f_InitCommonControls)();
167
typedef BOOL(__stdcall* f_InitCommonControlsEx)(const INITCOMMONCONTROLSEX* picce);
444 daniel-mar 168
Boolean Slider_Init_MsTrackbar(LPCTSTR targetClass) {
439 daniel-mar 169
        f_InitCommonControls fInitCommonControls;
170
        f_InitCommonControlsEx fInitCommonControlsEx;
171
        HMODULE libComctl32;
172
 
173
        // Make sure that Comctl32 is loaded
444 daniel-mar 174
        libComctl32 = LoadLibrary(TEXT("Comctl32.dll"));
439 daniel-mar 175
        if (libComctl32) {
176
                fInitCommonControlsEx = (f_InitCommonControlsEx)(void*)GetProcAddress(libComctl32, "InitCommonControlsEx");
177
                if (fInitCommonControlsEx != 0) {
178
                        INITCOMMONCONTROLSEX icce;
179
                        icce.dwSize = sizeof(INITCOMMONCONTROLSEX);
180
                        icce.dwICC = ICC_BAR_CLASSES;
181
                        fInitCommonControlsEx(&icce);
182
                }
183
                else {
184
                        fInitCommonControls = (f_InitCommonControls)(void*)GetProcAddress(libComctl32, "InitCommonControls");
185
                        if (fInitCommonControls != 0) {
186
                                fInitCommonControls();
187
                        }
188
                }
189
                // There seems to be a bug in Windows NT 3.11 (if PLUGIN.DLL does not exist):
190
                // If we call FreeLibrary, and then open Filter Foundry again,
191
                // then you get an error message "BRUSHES" cannot initialize Comctl32.dll ...
192
                // I am not sure if it is OK to do a FreeLibrary after you have called InitCommonControls.
193
                // Isn't that a contradiction?
194
                //FreeLibrary(libComctl32);
195
        }
196
 
197
        // Make "FoundrySlider" a subclass of "msctls_trackbar32" then
444 daniel-mar 198
        return MakeSimpleSubclass(targetClass, TEXT("msctls_trackbar32"));
439 daniel-mar 199
}
200
 
444 daniel-mar 201
Boolean Slider_Init_None(LPCTSTR targetClass) {
439 daniel-mar 202
        // Make "FoundrySlider" a subclass of "STATIC" (making it invisible)
444 daniel-mar 203
        return MakeSimpleSubclass(targetClass, TEXT("STATIC"));
439 daniel-mar 204
}