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