Rev 435 | Rev 444 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 435 | Rev 439 | ||
---|---|---|---|
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 | /* Win32 user interface routines */ |
21 | /* Win32 user interface routines */ |
22 | 22 | ||
23 | #include "world.h" |
23 | #include "world.h" |
24 | 24 | ||
25 | #include "PIAbout.h" |
25 | #include "PIAbout.h" |
26 | 26 | ||
27 | #include <windows.h> |
27 | #include <windows.h> |
28 | #include <commctrl.h> |
28 | #include <commctrl.h> |
29 | 29 | ||
30 | #include "ff.h" |
30 | #include "ff.h" |
31 | - | ||
- | 31 | #include "slider_win.h" |
|
32 | #include "version.h" |
32 | #include "version.h" |
33 | 33 | ||
34 | #define use_plugin_dll_sliders |
- | |
35 | - | ||
36 | HWND preview_hwnd; |
34 | HWND preview_hwnd; |
37 | HCURSOR hCurHandOpen; |
35 | HCURSOR hCurHandOpen; |
38 | HCURSOR hCurHandGrab; |
36 | HCURSOR hCurHandGrab; |
39 | 37 | ||
40 | HCURSOR hCurHandQuestion; |
38 | HCURSOR hCurHandQuestion; |
41 | HICON hIconCautionSign; |
39 | HICON hIconCautionSign; |
42 | 40 | ||
43 | // PLUGIN.DLL Sliders: This method will register the "slider" class used in dialogs. |
- | |
44 | typedef int(__cdecl* f_RegisterSlider)(HINSTANCE hInstanceDll, DWORD* MessageID); |
- | |
45 | int RegisterSlider(HINSTANCE hInstanceDll, DWORD* MessageID) { |
- | |
46 | f_RegisterSlider fRegisterSlider; |
- | |
47 | - | ||
48 | if (!gdata->pluginDllModule) return 0; |
- | |
49 | fRegisterSlider = (f_RegisterSlider)(void*)GetProcAddress(gdata->pluginDllModule, "RegisterSlider"); |
- | |
50 | if (fRegisterSlider != 0) { |
- | |
51 | return fRegisterSlider(hInstanceDll, MessageID); |
- | |
52 | } |
- | |
53 | else { |
- | |
54 | return 0; |
- | |
55 | } |
- | |
56 | } |
- | |
57 | - | ||
58 | // PLUGIN.DLL Sliders: This method will unregister the "slider" class used in dialogs. |
- | |
59 | typedef int(__cdecl* f_UnregisterSlider)(HINSTANCE hInstanceDll); |
- | |
60 | int UnregisterSlider(HINSTANCE hInstanceDll) { |
- | |
61 | f_UnregisterSlider fUnregisterSlider; |
- | |
62 | - | ||
63 | if (!gdata->pluginDllModule) return 0; |
- | |
64 | fUnregisterSlider = (f_UnregisterSlider)(void*)GetProcAddress(gdata->pluginDllModule, "UnregisterSlider"); |
- | |
65 | if (fUnregisterSlider != 0) { |
- | |
66 | return fUnregisterSlider(hInstanceDll); |
- | |
67 | } |
- | |
68 | else { |
- | |
69 | return 0; |
- | |
70 | } |
- | |
71 | } |
- | |
72 | - | ||
73 | // PLUGIN.DLL Sliders: Set slider range (min/max) |
- | |
74 | typedef int(__cdecl* f_SetSliderRange)(HWND hWnd, int nMin, int nMax); |
- | |
75 | int SetSliderRange(HWND hWnd, int nMin, int nMax) { |
- | |
76 | f_SetSliderRange fSetSliderRange; |
- | |
77 | - | ||
78 | if (!gdata->pluginDllModule) return 0; |
- | |
79 | fSetSliderRange = (f_SetSliderRange)(void*)GetProcAddress(gdata->pluginDllModule, "SetSliderRange"); |
- | |
80 | if (fSetSliderRange != 0) { |
- | |
81 | return fSetSliderRange(hWnd, nMin, nMax); |
- | |
82 | } |
- | |
83 | else { |
- | |
84 | return 0; |
- | |
85 | } |
- | |
86 | } |
- | |
87 | - | ||
88 | // PLUGIN.DLL Sliders : Sets slider position |
- | |
89 | typedef int(__cdecl* f_SetSliderPos)(HWND hWnd, int nPos, BOOL bRepaint); |
- | |
90 | int SetSliderPos(HWND hWnd, int nPos, BOOL bRepaint) { |
- | |
91 | f_SetSliderPos fSetSliderPos; |
- | |
92 | - | ||
93 | if (!gdata->pluginDllModule) return 0; |
- | |
94 | fSetSliderPos = (f_SetSliderPos)(void*)GetProcAddress(gdata->pluginDllModule, "SetSliderPos"); |
- | |
95 | if (fSetSliderPos != 0) { |
- | |
96 | return fSetSliderPos(hWnd, nPos, bRepaint); |
- | |
97 | } |
- | |
98 | else { |
- | |
99 | return 0; |
- | |
100 | } |
- | |
101 | } |
- | |
102 | - | ||
103 | // PLUGIN.DLL Sliders : Get slider position |
- | |
104 | typedef int(__cdecl* f_GetSliderPos)(HWND hWnd, BOOL bPixelPosition); |
- | |
105 | int GetSliderPos(HWND hWnd, BOOL bPixelPosition) { |
- | |
106 | f_GetSliderPos fGetSliderPos; |
- | |
107 | - | ||
108 | if (!gdata->pluginDllModule) return 0; |
- | |
109 | fGetSliderPos = (f_GetSliderPos)(void*)GetProcAddress(gdata->pluginDllModule, "GetSliderPos"); |
- | |
110 | if (fGetSliderPos != 0) { |
- | |
111 | int res = fGetSliderPos(hWnd, bPixelPosition); |
- | |
112 | return res; |
- | |
113 | } |
- | |
114 | else { |
- | |
115 | return 0; |
- | |
116 | } |
- | |
117 | } |
- | |
118 | - | ||
119 | extern HINSTANCE hDllInstance; |
41 | extern HINSTANCE hDllInstance; |
120 | 42 | ||
121 | void DoAbout(AboutRecordPtr pb){ |
43 | void DoAbout(AboutRecordPtr pb){ |
122 | char text[1000]; |
44 | char text[1000]; |
123 | char title[200]; |
45 | char title[200]; |
124 | PlatformData *p = (PlatformData*)pb->platformData; |
46 | PlatformData *p = (PlatformData*)pb->platformData; |
125 | 47 | ||
126 | if (gdata && gdata->standalone) { |
48 | if (gdata && gdata->standalone) { |
127 | sprintf(title, "About %s", gdata->parm.szTitle); |
49 | sprintf(title, "About %s", gdata->parm.szTitle); |
128 | sprintf(text, "%s by %s\n" /* {Title} by {Author} */ |
50 | sprintf(text, "%s by %s\n" /* {Title} by {Author} */ |
129 | "%s\n" /* {Copyright} */ |
51 | "%s\n" /* {Copyright} */ |
130 | "\n" |
52 | "\n" |
131 | "This plugin was built using Filter Foundry " VERSION_STR |
53 | "This plugin was built using Filter Foundry " VERSION_STR |
132 | #ifdef _WIN64 |
54 | #ifdef _WIN64 |
133 | " (64 bit)\n" |
55 | " (64 bit)\n" |
134 | #else |
56 | #else |
135 | " (32 bit)\n" |
57 | " (32 bit)\n" |
136 | #endif |
58 | #endif |
137 | "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n" |
59 | "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n" |
138 | "available from " PROJECT_URL, |
60 | "available from " PROJECT_URL, |
139 | gdata->parm.szTitle, |
61 | gdata->parm.szTitle, |
140 | gdata->parm.szAuthor, |
62 | gdata->parm.szAuthor, |
141 | gdata->parm.szCopyright); |
63 | gdata->parm.szCopyright); |
142 | } else { |
64 | } else { |
143 | sprintf(title, "About Filter Foundry"); |
65 | sprintf(title, "About Filter Foundry"); |
144 | sprintf(text, "Filter Foundry " VERSION_STR |
66 | sprintf(text, "Filter Foundry " VERSION_STR |
145 | #ifdef _WIN64 |
67 | #ifdef _WIN64 |
146 | " (64 bit)\n" |
68 | " (64 bit)\n" |
147 | #else |
69 | #else |
148 | " (32 bit)\n" |
70 | " (32 bit)\n" |
149 | #endif |
71 | #endif |
150 | "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n" |
72 | "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n" |
151 | "\n" |
73 | "\n" |
152 | "Latest version available from\n" |
74 | "Latest version available from\n" |
153 | PROJECT_URL "\n" |
75 | PROJECT_URL "\n" |
154 | "\nPlease contact the author with any bug reports,\n" |
76 | "\nPlease contact the author with any bug reports,\n" |
155 | "suggestions or comments.\n" |
77 | "suggestions or comments.\n" |
156 | "If you use this program and like it, please consider\n" |
78 | "If you use this program and like it, please consider\n" |
157 | "making a donation."); |
79 | "making a donation."); |
158 | } |
80 | } |
159 | 81 | ||
160 | MessageBox((HWND)p->hwnd, text, title, MB_TASKMODAL|MB_ICONINFORMATION|MB_OK); |
82 | MessageBox((HWND)p->hwnd, text, title, MB_TASKMODAL|MB_ICONINFORMATION|MB_OK); |
161 | } |
83 | } |
162 | 84 | ||
163 | Boolean simplealert(char *s){ |
85 | Boolean simplealert(char *s){ |
164 | HWND hwnd; |
86 | HWND hwnd; |
165 | char* title; |
87 | char* title; |
166 | if (gdata && gdata->standalone) { |
88 | if (gdata && gdata->standalone) { |
167 | title = gdata->parm.szTitle; |
89 | title = gdata->parm.szTitle; |
168 | } else { |
90 | } else { |
169 | title = _strdup("Filter Foundry"); |
91 | title = _strdup("Filter Foundry"); |
170 | } |
92 | } |
171 | hwnd = gdata ? gdata->hWndMainDlg : NULL; |
93 | hwnd = gdata ? gdata->hWndMainDlg : NULL; |
172 | return MessageBox(hwnd, s, title, MB_TASKMODAL|MB_ICONERROR|MB_OK) == IDOK; |
94 | return MessageBox(hwnd, s, title, MB_TASKMODAL|MB_ICONERROR|MB_OK) == IDOK; |
173 | } |
95 | } |
174 | 96 | ||
175 | Boolean simplewarning(char* s) { |
97 | Boolean simplewarning(char* s) { |
176 | HWND hwnd; |
98 | HWND hwnd; |
177 | char* title; |
99 | char* title; |
178 | if (gdata && gdata->standalone) { |
100 | if (gdata && gdata->standalone) { |
179 | title = gdata->parm.szTitle; |
101 | title = gdata->parm.szTitle; |
180 | } else { |
102 | } else { |
181 | title = _strdup("Filter Foundry"); |
103 | title = _strdup("Filter Foundry"); |
182 | } |
104 | } |
183 | hwnd = gdata ? gdata->hWndMainDlg : NULL; |
105 | hwnd = gdata ? gdata->hWndMainDlg : NULL; |
184 | return MessageBox(hwnd,s,title,MB_TASKMODAL|MB_ICONEXCLAMATION|MB_OK) == IDOK; |
106 | return MessageBox(hwnd,s,title,MB_TASKMODAL|MB_ICONEXCLAMATION|MB_OK) == IDOK; |
185 | } |
107 | } |
186 | 108 | ||
187 | Boolean showmessage(char *s) { |
109 | Boolean showmessage(char *s) { |
188 | HWND hwnd; |
110 | HWND hwnd; |
189 | char* title; |
111 | char* title; |
190 | if (gdata && gdata->standalone) { |
112 | if (gdata && gdata->standalone) { |
191 | title = gdata->parm.szTitle; |
113 | title = gdata->parm.szTitle; |
192 | } else { |
114 | } else { |
193 | title = _strdup("Filter Foundry"); |
115 | title = _strdup("Filter Foundry"); |
194 | } |
116 | } |
195 | hwnd = gdata ? gdata->hWndMainDlg : NULL; |
117 | hwnd = gdata ? gdata->hWndMainDlg : NULL; |
196 | return MessageBox(hwnd,s,title,MB_TASKMODAL|MB_ICONINFORMATION|MB_OK) == IDOK; |
118 | return MessageBox(hwnd,s,title,MB_TASKMODAL|MB_ICONINFORMATION|MB_OK) == IDOK; |
197 | } |
119 | } |
198 | 120 | ||
199 | INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam); |
121 | INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam); |
200 | 122 | ||
201 | // Description: |
123 | // Description: |
202 | // Creates a tooltip for an item in a dialog box. |
124 | // Creates a tooltip for an item in a dialog box. |
203 | // Parameters: |
125 | // Parameters: |
204 | // idTool - identifier of an dialog box item. |
126 | // idTool - identifier of an dialog box item. |
205 | // nDlg - window handle of the dialog box. |
127 | // nDlg - window handle of the dialog box. |
206 | // pszText - string to use as the tooltip text. |
128 | // pszText - string to use as the tooltip text. |
207 | // Returns: |
129 | // Returns: |
208 | // The handle to the tooltip. |
130 | // The handle to the tooltip. |
209 | // |
131 | // |
210 | HWND CreateToolTip(int toolID, HWND hDlg, PTSTR pszText) { |
132 | HWND CreateToolTip(int toolID, HWND hDlg, PTSTR pszText) { |
211 | // Source: https://docs.microsoft.com/en-us/windows/win32/controls/create-a-tooltip-for-a-control (modified) |
133 | // Source: https://docs.microsoft.com/en-us/windows/win32/controls/create-a-tooltip-for-a-control (modified) |
212 | 134 | ||
213 | HWND hwndTool, hwndTip; |
135 | HWND hwndTool, hwndTip; |
214 | TOOLINFO toolInfo; |
136 | TOOLINFO toolInfo; |
215 | 137 | ||
216 | if (!toolID || !hDlg || !pszText) { |
138 | if (!toolID || !hDlg || !pszText) { |
217 | return FALSE; |
139 | return FALSE; |
218 | } |
140 | } |
219 | // Get the window of the tool. |
141 | // Get the window of the tool. |
220 | hwndTool = GetDlgItem(hDlg, toolID); |
142 | hwndTool = GetDlgItem(hDlg, toolID); |
221 | 143 | ||
222 | // Create the tooltip. g_hInst is the global instance handle. |
144 | // Create the tooltip. g_hInst is the global instance handle. |
223 | hwndTip = CreateWindowEx(0, TOOLTIPS_CLASS, NULL, |
145 | hwndTip = CreateWindowEx(0, TOOLTIPS_CLASS, NULL, |
224 | WS_POPUP | TTS_ALWAYSTIP /* | TTS_BALLOON*/, |
146 | WS_POPUP | TTS_ALWAYSTIP /* | TTS_BALLOON*/, |
225 | CW_USEDEFAULT, CW_USEDEFAULT, |
147 | CW_USEDEFAULT, CW_USEDEFAULT, |
226 | CW_USEDEFAULT, CW_USEDEFAULT, |
148 | CW_USEDEFAULT, CW_USEDEFAULT, |
227 | hDlg, NULL, |
149 | hDlg, NULL, |
228 | hDllInstance, NULL); |
150 | hDllInstance, NULL); |
229 | 151 | ||
230 | if (!hwndTool || !hwndTip) { |
152 | if (!hwndTool || !hwndTip) { |
231 | return (HWND)NULL; |
153 | return (HWND)NULL; |
232 | } |
154 | } |
233 | 155 | ||
234 | // Associate the tooltip with the tool. |
156 | // Associate the tooltip with the tool. |
235 | memset(&toolInfo, 0, sizeof(TOOLINFO)); // toolInfo = { 0 }; |
157 | memset(&toolInfo, 0, sizeof(TOOLINFO)); // toolInfo = { 0 }; |
236 | toolInfo.cbSize = sizeof(toolInfo); |
158 | toolInfo.cbSize = sizeof(toolInfo); |
237 | toolInfo.hwnd = hDlg; |
159 | toolInfo.hwnd = hDlg; |
238 | toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS; |
160 | toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS; |
239 | toolInfo.uId = (UINT_PTR)hwndTool; |
161 | toolInfo.uId = (UINT_PTR)hwndTool; |
240 | toolInfo.lpszText = pszText; |
162 | toolInfo.lpszText = pszText; |
241 | SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo); |
163 | SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo); |
242 | 164 | ||
243 | return hwndTip; |
165 | return hwndTip; |
244 | } |
166 | } |
245 | 167 | ||
246 | INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){ |
168 | INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){ |
247 | static POINT origpos; |
169 | static POINT origpos; |
248 | static Point origscroll; |
170 | static Point origscroll; |
249 | static Boolean panning = false; |
171 | static Boolean panning = false; |
250 | 172 | ||
251 | int item,i; |
173 | int item,i; |
252 | POINT newpos; |
174 | POINT newpos; |
253 | DRAWITEMSTRUCT *pdi; |
175 | DRAWITEMSTRUCT *pdi; |
254 | Point newscroll; |
176 | Point newscroll; |
255 | HGDIOBJ hfnt; |
177 | HGDIOBJ hfnt; |
256 | 178 | ||
257 | extern Boolean doupdates; |
179 | extern Boolean doupdates; |
258 | extern Handle preview_handle; |
180 | extern Handle preview_handle; |
259 | 181 | ||
260 | if ((gdata->pluginDllSliderMessageId != 0) && (wMsg == gdata->pluginDllSliderMessageId)) { |
182 | if ((gdata->pluginDllSliderMessageId != 0) && (wMsg == gdata->pluginDllSliderMessageId)) { |
261 | // This is for the PLUGIN.DLL sliders only |
183 | // This is for the PLUGIN.DLL sliders only |
262 | if (doupdates) { |
184 | if (doupdates) { |
263 | int sliderNum = wParam - FIRSTCTLITEM; |
185 | int sliderNum = wParam - FIRSTCTLITEM; |
264 | uint8_t sliderVal = (uint8_t)(lParam & 0xFFFF); |
186 | uint8_t sliderVal = (uint8_t)(lParam & 0xFFFF); |
265 | slider[sliderNum] = sliderVal; |
187 | slider[sliderNum] = sliderVal; |
266 | 188 | ||
267 | SETCTLTEXTINT(hDlg, FIRSTCTLTEXTITEM + sliderNum, sliderVal, false); |
189 | SETCTLTEXTINT(hDlg, FIRSTCTLTEXTITEM + sliderNum, sliderVal, false); |
268 | REPAINTCTL(hDlg, FIRSTCTLTEXTITEM + sliderNum); |
190 | REPAINTCTL(hDlg, FIRSTCTLTEXTITEM + sliderNum); |
269 | 191 | ||
270 | recalc_preview(gpb, hDlg); |
192 | recalc_preview(gpb, hDlg); |
271 | } |
193 | } |
272 | return true; |
194 | return true; |
273 | } |
195 | } |
274 | 196 | ||
275 | switch (wMsg) { |
197 | switch (wMsg) { |
276 | case WM_INITDIALOG: |
198 | case WM_INITDIALOG: |
277 | gdata->hWndMainDlg = hDlg; |
199 | gdata->hWndMainDlg = hDlg; |
278 | 200 | ||
279 | if(gdata->standalone){ |
201 | if(gdata->standalone){ |
280 | SetWindowText(hDlg,gdata->parm.szTitle); // window title bar |
202 | SetWindowText(hDlg,gdata->parm.szTitle); // window title bar |
281 | } |
203 | } |
282 | centre_window(hDlg); |
204 | centre_window(hDlg); |
283 | 205 | ||
284 | hfnt = GetStockObject(ANSI_FIXED_FONT); |
206 | hfnt = GetStockObject(ANSI_FIXED_FONT); |
285 | 207 | ||
286 | hCurHandOpen = LoadCursor(hDllInstance, "HAND_OPEN"); |
208 | hCurHandOpen = LoadCursor(hDllInstance, "HAND_OPEN"); |
287 | hCurHandGrab = LoadCursor(hDllInstance, "HAND_GRAB"); |
209 | hCurHandGrab = LoadCursor(hDllInstance, "HAND_GRAB"); |
288 | hCurHandQuestion = LoadCursor(hDllInstance, "HAND_QUESTION"); |
210 | hCurHandQuestion = LoadCursor(hDllInstance, "HAND_QUESTION"); |
289 | 211 | ||
290 | hIconCautionSign = LoadIcon(hDllInstance, "CAUTION_ICO"); |
212 | hIconCautionSign = LoadIcon(hDllInstance, "CAUTION_ICO"); |
291 | 213 | ||
292 | // Note: The whole class "Preview" gets the mouse cursor, not just the single item! |
214 | // Note: The whole class "Preview" gets the mouse cursor, not just the single item! |
293 | preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM); |
215 | preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM); |
294 | GetClientRect(preview_hwnd, &preview_rect); |
216 | GetClientRect(preview_hwnd, &preview_rect); |
295 | SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen); |
217 | SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen); |
296 | 218 | ||
297 | // Note: The whole class "Caution" gets the mouse cursor, not just the single item! |
219 | // Note: The whole class "Caution" gets the mouse cursor, not just the single item! |
298 | SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion); |
220 | SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion); |
299 | 221 | ||
300 | for(i = 0; i < 4; ++i){ |
222 | for(i = 0; i < 4; ++i){ |
301 | CreateToolTip(FIRSTICONITEM + i, hDlg, _strdup("Error in expression! Click to see details.")); |
223 | CreateToolTip(FIRSTICONITEM + i, hDlg, _strdup("Error in expression! Click to see details.")); |
302 | } |
224 | } |
303 | 225 | ||
304 | CreateToolTip(ZOOMINITEM, hDlg, _strdup("Zoom in")); |
226 | CreateToolTip(ZOOMINITEM, hDlg, _strdup("Zoom in")); |
305 | CreateToolTip(ZOOMOUTITEM, hDlg, _strdup("Zoom out")); |
227 | CreateToolTip(ZOOMOUTITEM, hDlg, _strdup("Zoom out")); |
306 | CreateToolTip(ZOOMLEVELITEM, hDlg, _strdup("Fully zoom in/out")); |
228 | CreateToolTip(ZOOMLEVELITEM, hDlg, _strdup("Fully zoom in/out")); |
307 | 229 | ||
308 | for(i = 0; i < 8; ++i){ |
230 | for(i = 0; i < 8; ++i){ |
309 | if (gdata->pluginDllSliderMessageId == 0) { |
231 | if (gdata->pluginDllSliderMessageId == 0) { |
310 | // Non PLUGIN.DLL sliders |
232 | // Non PLUGIN.DLL sliders |
311 | SetWindowLongPtr(GetDlgItem(hDlg, FIRSTCTLITEM + i), GWL_STYLE, TBS_HORZ | TBS_AUTOTICKS | WS_CHILD | WS_VISIBLE); |
233 | SetWindowLongPtr(GetDlgItem(hDlg, FIRSTCTLITEM + i), GWL_STYLE, TBS_HORZ | TBS_AUTOTICKS | WS_CHILD | WS_VISIBLE); |
312 | SendDlgItemMessage(hDlg, FIRSTCTLITEM + i, TBM_SETRANGE, TRUE, MAKELONG(0, 255)); |
234 | SendDlgItemMessage(hDlg, FIRSTCTLITEM + i, TBM_SETRANGE, TRUE, MAKELONG(0, 255)); |
313 | SendDlgItemMessage(hDlg, FIRSTCTLITEM + i, TBM_SETTICFREQ, SLIDERPAGE, 0); |
235 | SendDlgItemMessage(hDlg, FIRSTCTLITEM + i, TBM_SETTICFREQ, SLIDERPAGE, 0); |
314 | SendDlgItemMessage(hDlg, FIRSTCTLITEM + i, TBM_SETPAGESIZE, 0, SLIDERPAGE); |
236 | SendDlgItemMessage(hDlg, FIRSTCTLITEM + i, TBM_SETPAGESIZE, 0, SLIDERPAGE); |
315 | } |
237 | } |
316 | else { |
238 | else { |
317 | // PLUGIN.DLL sliders |
239 | // PLUGIN.DLL sliders |
318 | SetSliderRange(GetDlgItem(hDlg, FIRSTCTLITEM + i), 0, 255); |
240 | SetSliderRange(GetDlgItem(hDlg, FIRSTCTLITEM + i), 0, 255); |
319 | } |
241 | } |
320 | SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i, EM_SETLIMITTEXT,3,0); |
242 | SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i, EM_SETLIMITTEXT,3,0); |
321 | } |
243 | } |
322 | for(i = 0; i < 4; ++i){ |
244 | for(i = 0; i < 4; ++i){ |
323 | SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i, EM_SETLIMITTEXT,MAXEXPR-1,0); // we need 1 byte as NUL terminator, so our formula can be max 1023 |
245 | SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i, EM_SETLIMITTEXT,MAXEXPR-1,0); // we need 1 byte as NUL terminator, so our formula can be max 1023 |
324 | SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i, WM_SETFONT,(WPARAM)hfnt,false); |
246 | SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i, WM_SETFONT,(WPARAM)hfnt,false); |
325 | } |
247 | } |
326 | 248 | ||
327 | maindlginit(hDlg); |
249 | maindlginit(hDlg); |
328 | break; |
250 | break; |
329 | case WM_DESTROY: |
251 | case WM_DESTROY: |
330 | gdata->hWndMainDlg = 0; |
252 | gdata->hWndMainDlg = 0; |
331 | DestroyCursor(hCurHandOpen); |
253 | DestroyCursor(hCurHandOpen); |
332 | DestroyCursor(hCurHandGrab); |
254 | DestroyCursor(hCurHandGrab); |
333 | DestroyCursor(hCurHandQuestion); |
255 | DestroyCursor(hCurHandQuestion); |
334 | DestroyIcon(hIconCautionSign); |
256 | DestroyIcon(hIconCautionSign); |
335 | break; |
257 | break; |
336 | case WM_DRAWITEM: |
258 | case WM_DRAWITEM: |
337 | pdi = (DRAWITEMSTRUCT*)lParam; |
259 | pdi = (DRAWITEMSTRUCT*)lParam; |
338 | if(pdi->itemAction == ODA_DRAWENTIRE){ |
260 | if(pdi->itemAction == ODA_DRAWENTIRE){ |
339 | switch(pdi->CtlID){ |
261 | switch(pdi->CtlID){ |
340 | case PREVIEWITEM: |
262 | case PREVIEWITEM: |
341 | drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false)); |
263 | drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false)); |
342 | PIUNLOCKHANDLE(preview_handle); |
264 | PIUNLOCKHANDLE(preview_handle); |
343 | break; |
265 | break; |
344 | case FIRSTICONITEM: |
266 | case FIRSTICONITEM: |
345 | case FIRSTICONITEM + 1: |
267 | case FIRSTICONITEM + 1: |
346 | case FIRSTICONITEM + 2: |
268 | case FIRSTICONITEM + 2: |
347 | case FIRSTICONITEM + 3: |
269 | case FIRSTICONITEM + 3: |
348 | DrawIcon(pdi->hDC, 0, 0, hIconCautionSign); |
270 | DrawIcon(pdi->hDC, 0, 0, hIconCautionSign); |
349 | break; |
271 | break; |
350 | default: |
272 | default: |
351 | return false; |
273 | return false; |
352 | } |
274 | } |
353 | }else |
275 | }else |
354 | return false; // we couldn't handle the message |
276 | return false; // we couldn't handle the message |
355 | break; |
277 | break; |
356 | case WM_COMMAND: |
278 | case WM_COMMAND: |
357 | item = LOWORD(wParam); |
279 | item = LOWORD(wParam); |
358 | switch(HIWORD(wParam)){ |
280 | switch(HIWORD(wParam)){ |
359 | //case BN_CLICKED: |
281 | //case BN_CLICKED: |
360 | case STN_CLICKED: |
282 | case STN_CLICKED: |
361 | // BN_CLICKED = Button clicked |
283 | // BN_CLICKED = Button clicked |
362 | // STN_CLICKED = Static controls with SS_NOTIFY clicked |
284 | // STN_CLICKED = Static controls with SS_NOTIFY clicked |
363 | // Both have the same ordinal number |
285 | // Both have the same ordinal number |
364 | if(item==PREVIEWITEM && GetCursorPos(&origpos)){ |
286 | if(item==PREVIEWITEM && GetCursorPos(&origpos)){ |
365 | panning = true; |
287 | panning = true; |
366 | origscroll = preview_scroll; |
288 | origscroll = preview_scroll; |
367 | SetCursor(hCurHandGrab); |
289 | SetCursor(hCurHandGrab); |
368 | SetCapture(hDlg); |
290 | SetCapture(hDlg); |
369 | break; |
291 | break; |
370 | } |
292 | } |
371 | /* ... falls through ... */ |
293 | /* ... falls through ... */ |
372 | case EN_CHANGE: |
294 | case EN_CHANGE: |
373 | if(doupdates && !maindlgitem(hDlg,item)) |
295 | if(doupdates && !maindlgitem(hDlg,item)) |
374 | EndDialog(hDlg,item); |
296 | EndDialog(hDlg,item); |
375 | } |
297 | } |
376 | break; |
298 | break; |
377 | // case WM_LBUTTONDOWN: break; |
299 | // case WM_LBUTTONDOWN: break; |
378 | case WM_MOUSEMOVE: |
300 | case WM_MOUSEMOVE: |
379 | if(panning && GetCursorPos(&newpos)){ |
301 | if(panning && GetCursorPos(&newpos)){ |
380 | newscroll.h = (int16)(origscroll.h - zoomfactor*((double)newpos.x - (double)origpos.x)); |
302 | newscroll.h = (int16)(origscroll.h - zoomfactor*((double)newpos.x - (double)origpos.x)); |
381 | newscroll.v = (int16)(origscroll.v - zoomfactor*((double)newpos.y - (double)origpos.y)); |
303 | newscroll.v = (int16)(origscroll.v - zoomfactor*((double)newpos.y - (double)origpos.y)); |
382 | if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){ |
304 | if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){ |
383 | preview_scroll = newscroll; |
305 | preview_scroll = newscroll; |
384 | recalc_preview(gpb,hDlg); |
306 | recalc_preview(gpb,hDlg); |
385 | } |
307 | } |
386 | } |
308 | } |
387 | break; |
309 | break; |
388 | case WM_LBUTTONUP: |
310 | case WM_LBUTTONUP: |
389 | ReleaseCapture(); |
311 | ReleaseCapture(); |
390 | panning = false; |
312 | panning = false; |
391 | break; |
313 | break; |
392 | case WM_HSCROLL: |
314 | case WM_HSCROLL: |
393 | // Only for non-Plugin.dll-sliders |
315 | // Only for non-Plugin.dll-sliders |
394 | item = GetDlgCtrlID((HWND)lParam); |
316 | item = GetDlgCtrlID((HWND)lParam); |
395 | if(doupdates && gdata->pluginDllSliderMessageId == 0 && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7) |
317 | if(doupdates && gdata->pluginDllSliderMessageId == 0 && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7) |
396 | slidermoved(hDlg,item); |
318 | slidermoved(hDlg,item); |
397 | break; |
319 | break; |
398 | default: |
320 | default: |
399 | return false; |
321 | return false; |
400 | } |
322 | } |
401 | 323 | ||
402 | return true; |
324 | return true; |
403 | } |
325 | } |
404 | - | ||
405 | Boolean MakeSimpleSubclass(LPCSTR targetClass, LPCSTR sourceClass) { |
- | |
406 | WNDCLASS clx; |
- | |
407 | - | ||
408 | if (GetClassInfoA(hDllInstance, sourceClass, &clx) != 0) { |
- | |
409 | clx.lpszClassName = targetClass; |
- | |
410 | if (RegisterClass(&clx) == 0) { |
- | |
411 | char s[100]; |
- | |
412 | strcpy(s, "RegisterClass failed: "); |
- | |
413 | FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + strlen(s), 0x100, NULL); |
- | |
414 | dbg(s); |
- | |
415 | return false; |
- | |
416 | } |
- | |
417 | else { |
- | |
418 | return true; |
- | |
419 | } |
- | |
420 | } |
- | |
421 | else { |
- | |
422 | return false; |
- | |
423 | } |
- | |
424 | } |
- | |
425 | - | ||
426 | void Slider_Uninit_PluginDll() { |
- | |
427 | WNDCLASS clx; |
- | |
428 | - | ||
429 | #ifndef use_plugin_dll_sliders |
- | |
430 | return; |
- | |
431 | #endif |
- | |
432 | - | ||
433 | if (GetClassInfo(hDllInstance, "slider", &clx) != 0) { |
- | |
434 | UnregisterSlider(hDllInstance); |
- | |
435 | } |
- | |
436 | if (gdata->pluginDllModule) { |
- | |
437 | FreeLibrary(gdata->pluginDllModule); |
- | |
438 | gdata->pluginDllModule = 0; |
- | |
439 | } |
- | |
440 | } |
- | |
441 | - | ||
442 | Boolean Slider_Init_PluginDll(LPCSTR targetClass) { |
- | |
443 | DWORD sliderMsgId; |
- | |
444 | - | ||
445 | #ifndef use_plugin_dll_sliders |
- | |
446 | return false; |
- | |
447 | #endif |
- | |
448 | - | ||
449 | // Try loading PLUGIN.DLL (only Photoshop) in order to register the class "slider" |
- | |
450 | gdata->pluginDllModule = LoadLibraryA("PLUGIN.DLL"); |
- | |
451 | if (!gdata->pluginDllModule) return false; |
- | |
452 | sliderMsgId = 0; // important |
- | |
453 | RegisterSlider(hDllInstance, &sliderMsgId); |
- | |
454 | if (sliderMsgId != 0) { |
- | |
455 | // RegisterSlider will "remember" if it gave you a message ID before, |
- | |
456 | // and it will NOT give it to you again! (instead, the output variable stays untouched). |
- | |
457 | // The problem: PLUGIN.DLL stays loaded the whole time, so it keeps remembering, while Filter Foundry |
- | |
458 | // loses its internal state every time the window is closed. |
- | |
459 | // So, we keep the message ID in the global (persistant) data, so we remember it. |
- | |
460 | gdata->pluginDllSliderMessageId = sliderMsgId; |
- | |
461 | } |
- | |
462 | - | ||
463 | // Make "FoundrySlider" a subclass of "slider" then |
- | |
464 | return MakeSimpleSubclass(targetClass, "slider"); |
- | |
465 | } |
- | |
466 | - | ||
467 | typedef void(__stdcall* f_InitCommonControls)(); |
- | |
468 | typedef BOOL(__stdcall* f_InitCommonControlsEx)(const INITCOMMONCONTROLSEX* picce); |
- | |
469 | Boolean Slider_Init_MsTrackbar(LPCSTR targetClass) { |
- | |
470 | f_InitCommonControls fInitCommonControls; |
- | |
471 | f_InitCommonControlsEx fInitCommonControlsEx; |
- | |
472 | HMODULE libComctl32; |
- | |
473 | - | ||
474 | // Make sure that Comctl32 is loaded |
- | |
475 | libComctl32 = LoadLibraryA("Comctl32.dll"); |
- | |
476 | if (libComctl32) { |
- | |
477 | fInitCommonControlsEx = (f_InitCommonControlsEx)(void*)GetProcAddress(libComctl32, "InitCommonControlsEx"); |
- | |
478 | if (fInitCommonControlsEx != 0) { |
- | |
479 | INITCOMMONCONTROLSEX icce; |
- | |
480 | icce.dwSize = sizeof(INITCOMMONCONTROLSEX); |
- | |
481 | icce.dwICC = ICC_BAR_CLASSES; |
- | |
482 | fInitCommonControlsEx(&icce); |
- | |
483 | } |
- | |
484 | else { |
- | |
485 | fInitCommonControls = (f_InitCommonControls)(void*)GetProcAddress(libComctl32, "InitCommonControls"); |
- | |
486 | if (fInitCommonControls != 0) { |
- | |
487 | fInitCommonControls(); |
- | |
488 | } |
- | |
489 | } |
- | |
490 | // There seems to be a bug in Windows NT 3.11 (if PLUGIN.DLL does not exist): |
- | |
491 | // If we call FreeLibrary, and then open Filter Foundry again, |
- | |
492 | // then you get an error message "BRUSHES" cannot initialize Comctl32.dll ... |
- | |
493 | // I am not sure if it is OK to do a FreeLibrary after you have called InitCommonControls. |
- | |
494 | // Isn't that a contradiction? |
- | |
495 | //FreeLibrary(libComctl32); |
- | |
496 | } |
- | |
497 | - | ||
498 | // Make "FoundrySlider" a subclass of "msctls_trackbar32" then |
- | |
499 | return MakeSimpleSubclass(targetClass, "msctls_trackbar32"); |
- | |
500 | } |
- | |
501 | - | ||
502 | Boolean Slider_Init_None(LPCSTR targetClass) { |
- | |
503 | // Make "FoundrySlider" a subclass of "STATIC" (making it invisible) |
- | |
504 | return MakeSimpleSubclass(targetClass, "STATIC"); |
- | |
505 | } |
- | |
506 | 326 | ||
507 | Boolean maindialog(FilterRecordPtr pb){ |
327 | Boolean maindialog(FilterRecordPtr pb){ |
508 | PlatformData *p; |
328 | PlatformData *p; |
509 | INT_PTR res; |
329 | INT_PTR res; |
510 | 330 | ||
511 | // First try to use the sliders from PLUGIN.DLL (only Photoshop) |
331 | // First try to use the sliders from PLUGIN.DLL (only Photoshop) |
512 | if (!Slider_Init_PluginDll("FoundrySlider")) { |
332 | if (!Slider_Init_PluginDll("FoundrySlider")) { |
513 | // If we couldn't get the sliders from PLUGIN.DLL (probably not running in Photoshop), |
333 | // If we couldn't get the sliders from PLUGIN.DLL (probably not running in Photoshop), |
514 | // then try the Microsoft Trackbar Control instead |
334 | // then try the Microsoft Trackbar Control instead |
515 | if (!Slider_Init_MsTrackbar("FoundrySlider")) { |
335 | if (!Slider_Init_MsTrackbar("FoundrySlider")) { |
516 | // This will happen if we neither have PLUGIN.DLL, nor the Microsoft Trackbar Control (msctls_trackbar32). |
336 | // This will happen if we neither have PLUGIN.DLL, nor the Microsoft Trackbar Control (msctls_trackbar32). |
517 | // "msctls_trackbar32" is not included in Windows NT 3.1, and since there is no OCX or RegSvr32. |
337 | // "msctls_trackbar32" is not included in Windows NT 3.1, and since there is no OCX or RegSvr32. |
518 | // It is included in Windows NT 3.5x. |
338 | // It is included in Windows NT 3.5x. |
519 | 339 | ||
520 | //simplealert(_strdup("This plugin requires Photoshop's PLUGIN.DLL or the Microsoft Trackbar Control (msctls_trackbar32) which was not found on your system.")); |
340 | //simplealert(_strdup("This plugin requires Photoshop's PLUGIN.DLL or the Microsoft Trackbar Control (msctls_trackbar32) which was not found on your system.")); |
521 | //return false; |
341 | //return false; |
522 | 342 | ||
523 | // We simply hide the sliders and let the user enter the numeric values in the edit-box. |
343 | // We simply hide the sliders and let the user enter the numeric values in the edit-box. |
524 | simplewarning(_strdup("Visual sliders are not available because neither PLUGIN.DLL, nor the Microsoft Trackbar Control (msctls_trackbar32) was found on your system.")); |
344 | simplewarning(_strdup("Visual sliders are not available because neither PLUGIN.DLL, nor the Microsoft Trackbar Control (msctls_trackbar32) was found on your system.")); |
525 | Slider_Init_None("FoundrySlider"); |
345 | Slider_Init_None("FoundrySlider"); |
526 | } |
346 | } |
527 | } |
347 | } |
528 | 348 | ||
529 | // For the preview image and caution symbols, we register subclasses, so that we can assign a mouse cursor to this class. |
349 | // For the preview image and caution symbols, we register subclasses, so that we can assign a mouse cursor to this class. |
530 | MakeSimpleSubclass("Preview", "STATIC"); |
350 | MakeSimpleSubclass("Preview", "STATIC"); |
531 | MakeSimpleSubclass("Caution", "Button"); |
351 | MakeSimpleSubclass("Caution", "Button"); |
532 | 352 | ||
533 | // Now show the dialog |
353 | // Now show the dialog |
534 | p = (PlatformData*)pb->platformData; |
354 | p = (PlatformData*)pb->platformData; |
535 | 355 | ||
536 | // Note: "Invalid Cursor Handle" is the error when an unrecognized control class is detected |
356 | // Note: "Invalid Cursor Handle" is the error when an unrecognized control class is detected |
537 | res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG), |
357 | res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG), |
538 | (HWND)p->hwnd,maindlgproc,0); |
358 | (HWND)p->hwnd,maindlgproc,0); |
539 | if (res == 0) { |
359 | if (res == 0) { |
540 | simplealert(_strdup("DialogBoxParam in valid parent window handle")); |
360 | simplealert(_strdup("DialogBoxParam in valid parent window handle")); |
541 | } |
361 | } |
542 | if (res == -1) { |
362 | if (res == -1) { |
543 | char s[100]; |
363 | char s[100]; |
544 | strcpy(s, "DialogBoxParam failed: "); |
364 | strcpy(s, "DialogBoxParam failed: "); |
545 | FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + strlen(s), 0x100, NULL); |
365 | FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + strlen(s), 0x100, NULL); |
546 | dbg(s); |
366 | dbg(s); |
547 | } |
367 | } |
548 | 368 | ||
549 | // Clean up after the dialog has been closed |
369 | // Clean up after the dialog has been closed |
550 | UnregisterClass("Preview", hDllInstance); |
370 | UnregisterClass("Preview", hDllInstance); |
551 | UnregisterClass("Caution", hDllInstance); |
371 | UnregisterClass("Caution", hDllInstance); |
552 | UnregisterClass("FoundrySlider", hDllInstance); |
372 | UnregisterClass("FoundrySlider", hDllInstance); |
553 | Slider_Uninit_PluginDll(); |
373 | Slider_Uninit_PluginDll(); |
554 | 374 | ||
555 | return res == IDOK; |
375 | return res == IDOK; |
556 | } |
376 | } |
557 | 377 |