Subversion Repositories filter_foundry

Rev

Rev 230 | Rev 268 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 230 Rev 259
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
 
32
#include "version.h"
32
#include "version.h"
33
 
33
 
34
HWND preview_hwnd;
34
HWND preview_hwnd;
35
HCURSOR hCurHandOpen;
35
HCURSOR hCurHandOpen;
36
HCURSOR hCurHandGrab;
36
HCURSOR hCurHandGrab;
37
HCURSOR hCurHandQuestion;
37
HCURSOR hCurHandQuestion;
38
 
38
 
39
extern HINSTANCE hDllInstance;
39
extern HINSTANCE hDllInstance;
40
 
40
 
41
void DoAbout(AboutRecordPtr pb){
41
void DoAbout(AboutRecordPtr pb){
42
        char text[1000];
42
        char text[1000];
43
        char title[200];
43
        char title[200];
44
        PlatformData *p = (PlatformData*)pb->platformData;
44
        PlatformData *p = (PlatformData*)pb->platformData;
45
 
45
 
46
        if (gdata && gdata->standalone) {
46
        if (gdata && gdata->standalone) {
47
                sprintf(title, "About %s", INPLACEP2CSTR(gdata->parm.title));
47
                sprintf(title, "About %s", INPLACEP2CSTR(gdata->parm.title));
48
                sprintf(text,  "%s by %s\n" /* {Title} by {Author} */
48
                sprintf(text,  "%s by %s\n" /* {Title} by {Author} */
49
                               "%s\n" /* {Copyright} */
49
                               "%s\n" /* {Copyright} */
50
                               "\n"
50
                               "\n"
51
                               "This plugin was built using Filter Foundry " VERSION_STR
51
                               "This plugin was built using Filter Foundry " VERSION_STR
52
#ifdef _WIN64
52
#ifdef _WIN64
53
                               " (64 bit)\n"
53
                               " (64 bit)\n"
54
#else
54
#else
55
                               " (32 bit)\n"
55
                               " (32 bit)\n"
56
#endif
56
#endif
57
                               "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
57
                               "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
58
                               "available from " PROJECT_URL,
58
                               "available from " PROJECT_URL,
59
                               INPLACEP2CSTR(gdata->parm.title),
59
                               INPLACEP2CSTR(gdata->parm.title),
60
                               INPLACEP2CSTR(gdata->parm.author),
60
                               INPLACEP2CSTR(gdata->parm.author),
61
                               INPLACEP2CSTR(gdata->parm.copyright));
61
                               INPLACEP2CSTR(gdata->parm.copyright));
62
        } else {
62
        } else {
63
                sprintf(title, "About Filter Foundry");
63
                sprintf(title, "About Filter Foundry");
64
                sprintf(text,  "Filter Foundry " VERSION_STR
64
                sprintf(text,  "Filter Foundry " VERSION_STR
65
#ifdef _WIN64
65
#ifdef _WIN64
66
                               " (64 bit)\n"
66
                               " (64 bit)\n"
67
#else
67
#else
68
                               " (32 bit)\n"
68
                               " (32 bit)\n"
69
#endif
69
#endif
70
                               "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
70
                               "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
71
                               "\n"
71
                               "\n"
72
                               "Latest version available from\n"
72
                               "Latest version available from\n"
73
                               PROJECT_URL "\n"
73
                               PROJECT_URL "\n"
74
                               "\nPlease contact the author with any bug reports,\n"
74
                               "\nPlease contact the author with any bug reports,\n"
75
                               "suggestions or comments.\n"
75
                               "suggestions or comments.\n"
76
                               "If you use this program and like it, please consider\n"
76
                               "If you use this program and like it, please consider\n"
77
                               "making a donation.");
77
                               "making a donation.");
78
        }
78
        }
79
 
79
 
80
        MessageBox((HWND)p->hwnd, text, title, MB_APPLMODAL|MB_ICONINFORMATION|MB_OK);
80
        MessageBox((HWND)p->hwnd, text, title, MB_APPLMODAL|MB_ICONINFORMATION|MB_OK);
81
}
81
}
82
 
82
 
83
Boolean simplealert(char *s){
83
Boolean simplealert(char *s){
84
        char* title;
84
        char* title;
85
        if (gdata && gdata->standalone) {
85
        if (gdata && gdata->standalone) {
86
                title = INPLACEP2CSTR(gdata->parm.title);
86
                title = INPLACEP2CSTR(gdata->parm.title);
87
        } else {
87
        } else {
88
                title = _strdup("Filter Foundry");
88
                title = _strdup("Filter Foundry");
89
        }
89
        }
90
        return MessageBox(NULL,s,title,MB_TASKMODAL|MB_ICONERROR|MB_OK) == IDOK;
90
        return MessageBox(NULL,s,title,MB_TASKMODAL|MB_ICONERROR|MB_OK) == IDOK;
91
}
91
}
92
 
92
 
93
Boolean showmessage(char *s){
93
Boolean showmessage(char *s){
94
        char* title;
94
        char* title;
95
        if (gdata && gdata->standalone) {
95
        if (gdata && gdata->standalone) {
96
                title = INPLACEP2CSTR(gdata->parm.title);
96
                title = INPLACEP2CSTR(gdata->parm.title);
97
        } else {
97
        } else {
98
                title = _strdup("Filter Foundry");
98
                title = _strdup("Filter Foundry");
99
        }
99
        }
100
        return MessageBox(NULL,s,title,MB_TASKMODAL|MB_ICONINFORMATION|MB_OK) == IDOK;
100
        return MessageBox(NULL,s,title,MB_TASKMODAL|MB_ICONINFORMATION|MB_OK) == IDOK;
101
}
101
}
102
 
102
 
103
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
103
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
104
 
104
 
105
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){
105
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){
106
        static POINT origpos;
106
        static POINT origpos;
107
        static Point origscroll;
107
        static Point origscroll;
108
        static Boolean panning = false;
108
        static Boolean panning = false;
109
 
109
 
110
        int item,i;
110
        int item,i;
111
        POINT newpos;
111
        POINT newpos;
112
        DRAWITEMSTRUCT *pdi;
112
        DRAWITEMSTRUCT *pdi;
113
        Point newscroll;
113
        Point newscroll;
114
        HGDIOBJ hfnt;
114
        HGDIOBJ hfnt;
115
        char s[0x100];
115
        char s[0x100];
116
 
116
 
117
        extern Boolean doupdates;
117
        extern Boolean doupdates;
118
        extern Handle preview_handle;
118
        extern Handle preview_handle;
119
 
119
 
120
        switch(wMsg){
120
        switch(wMsg){
121
        case WM_INITDIALOG:
121
        case WM_INITDIALOG:
122
                gdata->hWndMainDlg = hDlg;
122
                gdata->hWndMainDlg = hDlg;
123
 
123
 
124
                if(gdata->standalone){
124
                if(gdata->standalone){
125
                        myp2cstrcpy(s,gdata->parm.title);
125
                        myp2cstrcpy(s,gdata->parm.title);
126
                        SetWindowText(hDlg,s); // window title bar
126
                        SetWindowText(hDlg,s); // window title bar
127
                }
127
                }
128
                centre_window(hDlg);
128
                centre_window(hDlg);
129
 
129
 
130
                hfnt = GetStockObject(ANSI_FIXED_FONT);
130
                hfnt = GetStockObject(ANSI_FIXED_FONT);
131
 
131
 
132
                hCurHandOpen = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_OPEN));
132
                hCurHandOpen = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_OPEN));
133
                hCurHandGrab = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_GRAB));
133
                hCurHandGrab = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_GRAB));
134
                hCurHandQuestion = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_QUESTION));
134
                hCurHandQuestion = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_QUESTION));
135
 
135
 
136
                preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM);
136
                preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM);
137
                GetClientRect(preview_hwnd, &preview_rect);
137
                GetClientRect(preview_hwnd, &preview_rect);
138
                SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen);
138
                SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen);
139
 
139
 
140
                SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion);
140
                SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion);
141
 
141
 
142
                for(i = 0; i < 4; ++i){
142
                for(i = 0; i < 4; ++i){
143
                        // If Visual Themes are applied, SS_ICON will be ignored for controls which are not exactly "STATIC" class.
143
                        // If Visual Themes are applied, SS_ICON will be ignored for controls which are not exactly "STATIC" class.
144
                        // Our derivated "CautionSign" class won't work. So we need to set the icon explicitly.
144
                        // Our derivated "CautionSign" class won't work. So we need to set the icon explicitly.
145
                        SendDlgItemMessage(hDlg, FIRSTICONITEM+i, STM_SETICON, (WPARAM)LoadImage(hDllInstance, "CAUTION_ICO",IMAGE_ICON,16,16, LR_DEFAULTCOLOR), 0);
145
                        SendDlgItemMessage(hDlg, FIRSTICONITEM+i, STM_SETICON, (WPARAM)LoadImage(hDllInstance, "CAUTION_ICO",IMAGE_ICON,16,16, LR_DEFAULTCOLOR), 0);
146
                }
146
                }
147
 
147
 
148
                for(i = 0; i < 8; ++i){
148
                for(i = 0; i < 8; ++i){
149
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETRANGE,TRUE,MAKELONG(0,255));
149
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETRANGE,TRUE,MAKELONG(0,255));
150
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETTICFREQ,SLIDERPAGE,0);
150
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETTICFREQ,SLIDERPAGE,0);
151
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETPAGESIZE,0,SLIDERPAGE);
151
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETPAGESIZE,0,SLIDERPAGE);
152
                        SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i,     EM_SETLIMITTEXT,3,0);
152
                        SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i,     EM_SETLIMITTEXT,3,0);
153
                }
153
                }
154
                for(i = 0; i < 4; ++i){
154
                for(i = 0; i < 4; ++i){
155
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        EM_SETLIMITTEXT,MAXEXPR-1,0); // we need 1 byte as NUL terminator, so our formula can be max 1023
155
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        EM_SETLIMITTEXT,MAXEXPR-1,0); // we need 1 byte as NUL terminator, so our formula can be max 1023
156
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        WM_SETFONT,(WPARAM)hfnt,false);
156
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        WM_SETFONT,(WPARAM)hfnt,false);
157
                }
157
                }
158
 
158
 
159
                maindlginit(hDlg);
159
                maindlginit(hDlg);
160
                break;
160
                break;
161
        case WM_DESTROY:
161
        case WM_DESTROY:
162
                gdata->hWndMainDlg = 0;
162
                gdata->hWndMainDlg = 0;
163
                DestroyCursor(hCurHandOpen);
163
                DestroyCursor(hCurHandOpen);
164
                DestroyCursor(hCurHandGrab);
164
                DestroyCursor(hCurHandGrab);
165
                DestroyCursor(hCurHandQuestion);
165
                DestroyCursor(hCurHandQuestion);
166
                break;
166
                break;
167
        case WM_DRAWITEM:
167
        case WM_DRAWITEM:
168
                pdi = (DRAWITEMSTRUCT*)lParam;
168
                pdi = (DRAWITEMSTRUCT*)lParam;
169
                if(pdi->itemAction == ODA_DRAWENTIRE){
169
                if(pdi->itemAction == ODA_DRAWENTIRE){
170
                        switch(pdi->CtlID){
170
                        switch(pdi->CtlID){
171
                        case PREVIEWITEM:
171
                        case PREVIEWITEM:
172
                                drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
172
                                drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
173
                                PIUNLOCKHANDLE(preview_handle);
173
                                PIUNLOCKHANDLE(preview_handle);
174
                                break;
174
                                break;
175
                        default:
175
                        default:
176
                                return false;
176
                                return false;
177
                        }
177
                        }
178
                }else
178
                }else
179
                        return false; // we couldn't handle the message
179
                        return false; // we couldn't handle the message
180
                break;
180
                break;
181
        case WM_COMMAND:
181
        case WM_COMMAND:
182
                item = LOWORD(wParam);
182
                item = LOWORD(wParam);
183
                switch(HIWORD(wParam)){
183
                switch(HIWORD(wParam)){
184
                case BN_CLICKED: //case STN_CLICKED:
184
                case BN_CLICKED: //case STN_CLICKED:
185
                        if(item==PREVIEWITEM && GetCursorPos(&origpos)){
185
                        if(item==PREVIEWITEM && GetCursorPos(&origpos)){
186
                                panning = true;
186
                                panning = true;
187
                                origscroll = preview_scroll;
187
                                origscroll = preview_scroll;
188
                                SetCursor(hCurHandGrab);
188
                                SetCursor(hCurHandGrab);
189
                                SetCapture(hDlg);
189
                                SetCapture(hDlg);
190
                                break;
190
                                break;
191
                        }
191
                        }
192
                        /* ... falls through ... */
192
                        /* ... falls through ... */
193
                case EN_CHANGE:
193
                case EN_CHANGE:
194
                        if(doupdates && !maindlgitem(hDlg,item))
194
                        if(doupdates && !maindlgitem(hDlg,item))
195
                                EndDialog(hDlg,item);
195
                                EndDialog(hDlg,item);
196
                }
196
                }
197
                break;
197
                break;
198
//      case WM_LBUTTONDOWN: break;
198
//      case WM_LBUTTONDOWN: break;
199
        case WM_MOUSEMOVE:
199
        case WM_MOUSEMOVE:
200
                if(panning && GetCursorPos(&newpos)){
200
                if(panning && GetCursorPos(&newpos)){
201
                        newscroll.h = (int16)(origscroll.h - zoomfactor*(newpos.x - origpos.x));
201
                        newscroll.h = (int16)(origscroll.h - zoomfactor*(newpos.x - origpos.x));
202
                        newscroll.v = (int16)(origscroll.v - zoomfactor*(newpos.y - origpos.y));
202
                        newscroll.v = (int16)(origscroll.v - zoomfactor*(newpos.y - origpos.y));
203
                        if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){
203
                        if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){
204
                                preview_scroll = newscroll;
204
                                preview_scroll = newscroll;
205
                                recalc_preview(gpb,hDlg);
205
                                recalc_preview(gpb,hDlg);
206
                        }
206
                        }
207
                }
207
                }
208
                break;
208
                break;
209
        case WM_LBUTTONUP:
209
        case WM_LBUTTONUP:
210
                ReleaseCapture();
210
                ReleaseCapture();
211
                panning = false;
211
                panning = false;
212
                break;
212
                break;
213
        case WM_HSCROLL:
213
        case WM_HSCROLL:
214
                item = GetDlgCtrlID((HWND)lParam);
214
                item = GetDlgCtrlID((HWND)lParam);
215
                if(doupdates && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7)
215
                if(doupdates && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7)
216
                        slidermoved(hDlg,item);
216
                        slidermoved(hDlg,item);
217
                break;
217
                break;
218
        default:
218
        default:
219
                return false;
219
                return false;
220
        }
220
        }
221
 
221
 
222
        return true;
222
        return true;
223
}
223
}
224
 
224
 
225
Boolean maindialog(FilterRecordPtr pb){
225
Boolean maindialog(FilterRecordPtr pb){
226
        PlatformData *p;
226
        PlatformData *p;
227
        WNDCLASSEX clx;
227
        WNDCLASSEX clx;
228
        Boolean res;
228
        Boolean res;
229
 
229
 
230
        // For the preview image, we register a class, so that we can assign a mouse cursor to this class.
230
        // For the preview image, we register a class, so that we can assign a mouse cursor to this class.
231
        clx.cbSize = sizeof(WNDCLASSEX);
231
        clx.cbSize = sizeof(WNDCLASSEX);
232
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
232
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
233
        clx.lpszClassName = "Preview";
233
        clx.lpszClassName = "Preview";
234
        RegisterClassEx(&clx);
234
        RegisterClassEx(&clx);
235
 
235
 
236
        // For the caution images, we register a class, so that we can assign a mouse cursor to this class.
236
        // For the caution images, we register a class, so that we can assign a mouse cursor to this class.
237
        clx.cbSize = sizeof(WNDCLASSEX);
237
        clx.cbSize = sizeof(WNDCLASSEX);
238
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
238
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
239
        clx.lpszClassName = "CautionSign";
239
        clx.lpszClassName = "CautionSign";
240
        RegisterClassEx(&clx);
240
        RegisterClassEx(&clx);
241
 
241
 
242
        // Now show the dialog
242
        // Now show the dialog
243
        p = (PlatformData*)pb->platformData;
243
        p = (PlatformData*)pb->platformData;
244
        res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG),
244
        res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG),
245
                             (HWND)p->hwnd,maindlgproc,0) == IDOK;
245
                             (HWND)p->hwnd,maindlgproc,0) == IDOK;
246
 
246
 
247
        UnregisterClass("Preview", hDllInstance);
247
        UnregisterClass("Preview", hDllInstance);
248
        UnregisterClass("CautionSign", hDllInstance);
248
        UnregisterClass("CautionSign", hDllInstance);
249
 
249
 
250
        return res;
250
        return res;
251
}
251
}
252
 
252
 
253
 
253