Subversion Repositories filter_foundry

Rev

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

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