Rev 454 | Rev 461 | 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 | |||
460 | daniel-mar | 100 | LRESULT CALLBACK DummyWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { |
101 | return DefWindowProc(hwnd, uMsg, wParam, lParam); |
||
102 | } |
||
103 | |||
444 | daniel-mar | 104 | Boolean MakeSimpleSubclass(LPCTSTR targetClass, LPCTSTR sourceClass) { |
439 | daniel-mar | 105 | WNDCLASS clx; |
106 | |||
444 | daniel-mar | 107 | if (GetClassInfo(hDllInstance, sourceClass, &clx) != 0) { |
439 | daniel-mar | 108 | clx.lpszClassName = targetClass; |
109 | if (RegisterClass(&clx) == 0) { |
||
444 | daniel-mar | 110 | TCHAR s[0x300]; |
111 | xstrcpy(s, (TCHAR*)TEXT("RegisterClass failed: ")); |
||
454 | daniel-mar | 112 | FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + xstrlen(s), 0x300 - (DWORD)xstrlen(s), NULL); |
444 | daniel-mar | 113 | dbg(&s[0]); |
439 | daniel-mar | 114 | return false; |
115 | } |
||
116 | else { |
||
117 | return true; |
||
118 | } |
||
119 | } |
||
120 | else { |
||
460 | daniel-mar | 121 | if ((xstrcmp(sourceClass, WC_BUTTON) == 0) || (xstrcmp(sourceClass, WC_STATIC) == 0)) { |
122 | // GetClassInfo(WC_STATIC) and GetClassInfo(WC_BUTTON) fail on Win32s (Windows 3.11) |
||
123 | // So we create a fake-class now. It will be replaced with the real Button/Static WndProc later! |
||
124 | clx.style = 0; |
||
125 | clx.lpfnWndProc = DummyWndProc; |
||
126 | clx.cbClsExtra = 0; |
||
127 | clx.cbWndExtra = 0; |
||
128 | clx.hInstance = hDllInstance; |
||
129 | clx.hIcon = 0; |
||
130 | clx.hCursor = 0; |
||
131 | clx.hbrBackground = 0; |
||
132 | clx.lpszMenuName = 0; |
||
133 | clx.lpszClassName = targetClass; |
||
134 | |||
135 | if (RegisterClass(&clx) == 0) { |
||
136 | TCHAR s[0x300]; |
||
137 | xstrcpy(s, (TCHAR*)TEXT("RegisterClass failed: ")); |
||
138 | FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + xstrlen(s), 0x300 - (DWORD)xstrlen(s), NULL); |
||
139 | dbg(&s[0]); |
||
140 | return false; |
||
141 | } |
||
142 | else { |
||
143 | return true; |
||
144 | } |
||
145 | } |
||
146 | else { |
||
147 | simplealert(TEXT("GetClassInfo failed")); |
||
148 | } |
||
439 | daniel-mar | 149 | return false; |
150 | } |
||
151 | } |
||
152 | |||
153 | void Slider_Uninit_PluginDll() { |
||
154 | |||
155 | #ifndef use_plugin_dll_sliders |
||
156 | return; |
||
157 | #else |
||
158 | WNDCLASS clx; |
||
159 | |||
444 | daniel-mar | 160 | if (GetClassInfo(hDllInstance, TEXT("slider"), &clx) != 0) { |
439 | daniel-mar | 161 | UnregisterSlider(hDllInstance); |
162 | } |
||
163 | if (gdata->pluginDllModule) { |
||
164 | FreeLibrary(gdata->pluginDllModule); |
||
165 | gdata->pluginDllModule = 0; |
||
166 | } |
||
167 | #endif |
||
168 | |||
169 | } |
||
170 | |||
444 | daniel-mar | 171 | Boolean Slider_Init_PluginDll(LPCTSTR targetClass) { |
439 | daniel-mar | 172 | |
173 | #ifndef use_plugin_dll_sliders |
||
174 | return false; |
||
175 | #else |
||
176 | DWORD sliderMsgId; |
||
177 | |||
178 | // Try loading PLUGIN.DLL (only Photoshop) in order to register the class "slider" |
||
444 | daniel-mar | 179 | gdata->pluginDllModule = LoadLibrary(TEXT("PLUGIN.DLL")); |
439 | daniel-mar | 180 | if (!gdata->pluginDllModule) return false; |
181 | sliderMsgId = 0; // important |
||
182 | RegisterSlider(hDllInstance, &sliderMsgId); |
||
183 | if (sliderMsgId != 0) { |
||
184 | // RegisterSlider will "remember" if it gave you a message ID before, |
||
185 | // and it will NOT give it to you again! (instead, the output variable stays untouched). |
||
186 | // The problem: PLUGIN.DLL stays loaded the whole time, so it keeps remembering, while Filter Foundry |
||
187 | // loses its internal state every time the window is closed. |
||
188 | // So, we keep the message ID in the global (persistant) data, so we remember it. |
||
189 | gdata->pluginDllSliderMessageId = sliderMsgId; |
||
190 | } |
||
191 | |||
192 | // Make "FoundrySlider" a subclass of "slider" then |
||
444 | daniel-mar | 193 | return MakeSimpleSubclass(targetClass, TEXT("slider")); |
439 | daniel-mar | 194 | #endif |
195 | |||
196 | } |
||
197 | |||
198 | typedef void(__stdcall* f_InitCommonControls)(); |
||
199 | typedef BOOL(__stdcall* f_InitCommonControlsEx)(const INITCOMMONCONTROLSEX* picce); |
||
444 | daniel-mar | 200 | Boolean Slider_Init_MsTrackbar(LPCTSTR targetClass) { |
439 | daniel-mar | 201 | f_InitCommonControls fInitCommonControls; |
202 | f_InitCommonControlsEx fInitCommonControlsEx; |
||
203 | HMODULE libComctl32; |
||
204 | |||
205 | // Make sure that Comctl32 is loaded |
||
444 | daniel-mar | 206 | libComctl32 = LoadLibrary(TEXT("Comctl32.dll")); |
439 | daniel-mar | 207 | if (libComctl32) { |
208 | fInitCommonControlsEx = (f_InitCommonControlsEx)(void*)GetProcAddress(libComctl32, "InitCommonControlsEx"); |
||
209 | if (fInitCommonControlsEx != 0) { |
||
210 | INITCOMMONCONTROLSEX icce; |
||
211 | icce.dwSize = sizeof(INITCOMMONCONTROLSEX); |
||
212 | icce.dwICC = ICC_BAR_CLASSES; |
||
213 | fInitCommonControlsEx(&icce); |
||
214 | } |
||
215 | else { |
||
216 | fInitCommonControls = (f_InitCommonControls)(void*)GetProcAddress(libComctl32, "InitCommonControls"); |
||
217 | if (fInitCommonControls != 0) { |
||
218 | fInitCommonControls(); |
||
219 | } |
||
220 | } |
||
221 | // There seems to be a bug in Windows NT 3.11 (if PLUGIN.DLL does not exist): |
||
222 | // If we call FreeLibrary, and then open Filter Foundry again, |
||
223 | // then you get an error message "BRUSHES" cannot initialize Comctl32.dll ... |
||
224 | // I am not sure if it is OK to do a FreeLibrary after you have called InitCommonControls. |
||
225 | // Isn't that a contradiction? |
||
226 | //FreeLibrary(libComctl32); |
||
227 | } |
||
228 | |||
229 | // Make "FoundrySlider" a subclass of "msctls_trackbar32" then |
||
444 | daniel-mar | 230 | return MakeSimpleSubclass(targetClass, TEXT("msctls_trackbar32")); |
439 | daniel-mar | 231 | } |
232 | |||
444 | daniel-mar | 233 | Boolean Slider_Init_None(LPCTSTR targetClass) { |
439 | daniel-mar | 234 | // Make "FoundrySlider" a subclass of "STATIC" (making it invisible) |
460 | daniel-mar | 235 | return MakeSimpleSubclass(targetClass, WC_STATIC); |
439 | daniel-mar | 236 | } |