Subversion Repositories filter_foundry

Rev

Rev 320 | Rev 354 | 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;
353 daniel-mar 38
HCURSOR hCurHandPoint;
259 daniel-mar 39
 
40
extern HINSTANCE hDllInstance;
41
 
42
void DoAbout(AboutRecordPtr pb){
43
        char text[1000];
44
        char title[200];
45
        PlatformData *p = (PlatformData*)pb->platformData;
46
 
47
        if (gdata && gdata->standalone) {
48
                sprintf(title, "About %s", INPLACEP2CSTR(gdata->parm.title));
49
                sprintf(text,  "%s by %s\n" /* {Title} by {Author} */
50
                               "%s\n" /* {Copyright} */
51
                               "\n"
52
                               "This plugin was built using Filter Foundry " VERSION_STR
268 daniel-mar 53
                                #ifdef _WIN64
259 daniel-mar 54
                               " (64 bit)\n"
268 daniel-mar 55
                                #else
259 daniel-mar 56
                               " (32 bit)\n"
268 daniel-mar 57
                                #endif
259 daniel-mar 58
                               "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
59
                               "available from " PROJECT_URL,
60
                               INPLACEP2CSTR(gdata->parm.title),
61
                               INPLACEP2CSTR(gdata->parm.author),
62
                               INPLACEP2CSTR(gdata->parm.copyright));
63
        } else {
64
                sprintf(title, "About Filter Foundry");
65
                sprintf(text,  "Filter Foundry " VERSION_STR
268 daniel-mar 66
                                #ifdef _WIN64
259 daniel-mar 67
                               " (64 bit)\n"
268 daniel-mar 68
                                #else
259 daniel-mar 69
                               " (32 bit)\n"
268 daniel-mar 70
                                #endif
259 daniel-mar 71
                               "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
72
                               "\n"
73
                               "Latest version available from\n"
74
                               PROJECT_URL "\n"
75
                               "\nPlease contact the author with any bug reports,\n"
76
                               "suggestions or comments.\n"
77
                               "If you use this program and like it, please consider\n"
78
                               "making a donation.");
79
        }
80
 
81
        MessageBox((HWND)p->hwnd, text, title, MB_APPLMODAL|MB_ICONINFORMATION|MB_OK);
82
}
83
 
84
Boolean simplealert(char *s){
273 daniel-mar 85
        HWND hwnd;
259 daniel-mar 86
        char* title;
87
        if (gdata && gdata->standalone) {
88
                title = INPLACEP2CSTR(gdata->parm.title);
89
        } else {
90
                title = _strdup("Filter Foundry");
91
        }
273 daniel-mar 92
        hwnd = gdata ? gdata->hWndMainDlg : NULL;
93
        return MessageBox(hwnd,s,title,MB_TASKMODAL|MB_ICONERROR|MB_OK) == IDOK;
259 daniel-mar 94
}
95
 
320 daniel-mar 96
Boolean simplewarning(char* s) {
97
        HWND hwnd;
98
        char* title;
99
        if (gdata && gdata->standalone) {
100
                title = INPLACEP2CSTR(gdata->parm.title);
101
        }
102
        else {
103
                title = _strdup("Filter Foundry");
104
        }
105
        hwnd = gdata ? gdata->hWndMainDlg : NULL;
106
        return MessageBox(hwnd,s,title,MB_TASKMODAL|MB_ICONEXCLAMATION|MB_OK) == IDOK;
107
}
108
 
353 daniel-mar 109
Boolean showmessage(char *s) {
273 daniel-mar 110
        HWND hwnd;
259 daniel-mar 111
        char* title;
112
        if (gdata && gdata->standalone) {
113
                title = INPLACEP2CSTR(gdata->parm.title);
114
        } else {
115
                title = _strdup("Filter Foundry");
116
        }
273 daniel-mar 117
        hwnd = gdata ? gdata->hWndMainDlg : NULL;
118
        return MessageBox(hwnd,s,title,MB_TASKMODAL|MB_ICONINFORMATION|MB_OK) == IDOK;
259 daniel-mar 119
}
120
 
121
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
122
 
353 daniel-mar 123
// Description:
124
//   Creates a tooltip for an item in a dialog box. 
125
// Parameters:
126
//   idTool - identifier of an dialog box item.
127
//   nDlg - window handle of the dialog box.
128
//   pszText - string to use as the tooltip text.
129
// Returns:
130
//   The handle to the tooltip.
131
//
132
HWND CreateToolTip(int toolID, HWND hDlg, PTSTR pszText) {
133
        // Source: https://docs.microsoft.com/en-us/windows/win32/controls/create-a-tooltip-for-a-control
134
        if (!toolID || !hDlg || !pszText) {
135
                return FALSE;
136
        }
137
        // Get the window of the tool.
138
        HWND hwndTool = GetDlgItem(hDlg, toolID);
139
 
140
        // Create the tooltip. g_hInst is the global instance handle.
141
        HWND hwndTip = CreateWindowEx(0, TOOLTIPS_CLASS, NULL,
142
                WS_POPUP | TTS_ALWAYSTIP /* | TTS_BALLOON*/,
143
                CW_USEDEFAULT, CW_USEDEFAULT,
144
                CW_USEDEFAULT, CW_USEDEFAULT,
145
                hDlg, NULL,
146
                hDllInstance, NULL);
147
 
148
        if (!hwndTool || !hwndTip) {
149
                return (HWND)NULL;
150
        }
151
 
152
        // Associate the tooltip with the tool.
153
        TOOLINFO toolInfo = { 0 };
154
        toolInfo.cbSize = sizeof(toolInfo);
155
        toolInfo.hwnd = hDlg;
156
        toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
157
        toolInfo.uId = (UINT_PTR)hwndTool;
158
        toolInfo.lpszText = pszText;
159
        SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
160
 
161
        return hwndTip;
162
}
163
 
259 daniel-mar 164
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){
165
        static POINT origpos;
166
        static Point origscroll;
167
        static Boolean panning = false;
168
 
169
        int item,i;
170
        POINT newpos;
171
        DRAWITEMSTRUCT *pdi;
172
        Point newscroll;
173
        HGDIOBJ hfnt;
174
        char s[0x100];
175
 
176
        extern Boolean doupdates;
177
        extern Handle preview_handle;
178
 
179
        switch(wMsg){
180
        case WM_INITDIALOG:
181
                gdata->hWndMainDlg = hDlg;
182
 
183
                if(gdata->standalone){
184
                        myp2cstrcpy(s,gdata->parm.title);
185
                        SetWindowText(hDlg,s); // window title bar
186
                }
187
                centre_window(hDlg);
188
 
189
                hfnt = GetStockObject(ANSI_FIXED_FONT);
190
 
191
                hCurHandOpen = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_OPEN));
192
                hCurHandGrab = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_GRAB));
193
                hCurHandQuestion = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_QUESTION));
353 daniel-mar 194
                hCurHandPoint = LoadCursor(NULL, IDC_HAND);
259 daniel-mar 195
 
196
                preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM);
197
                GetClientRect(preview_hwnd, &preview_rect);
198
                SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen);
199
 
200
                SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion);
201
 
202
                for(i = 0; i < 4; ++i){
203
                        // If Visual Themes are applied, SS_ICON will be ignored for controls which are not exactly "STATIC" class.
204
                        // Our derivated "CautionSign" class won't work. So we need to set the icon explicitly.
205
                        SendDlgItemMessage(hDlg, FIRSTICONITEM+i, STM_SETICON, (WPARAM)LoadImage(hDllInstance, "CAUTION_ICO",IMAGE_ICON,16,16, LR_DEFAULTCOLOR), 0);
353 daniel-mar 206
                        CreateToolTip(FIRSTICONITEM + i, hDlg, "Syntax error! Click to see details.");
259 daniel-mar 207
                }
208
 
353 daniel-mar 209
                CreateToolTip(ZOOMINITEM, hDlg, "Zoom in");
210
                CreateToolTip(ZOOMOUTITEM, hDlg, "Zoom out");
211
                CreateToolTip(ZOOMLEVELITEM, hDlg, "Zoom fully in/out");
212
 
213
                // Note: Actually, the whole class gets the cursor, not just these three controls!!
214
                SetClassLongPtr(GetDlgItem(hDlg, ZOOMINITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandPoint);
215
                SetClassLongPtr(GetDlgItem(hDlg, ZOOMOUTITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandPoint);
216
                SetClassLongPtr(GetDlgItem(hDlg, ZOOMLEVELITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandPoint);
217
 
259 daniel-mar 218
                for(i = 0; i < 8; ++i){
219
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETRANGE,TRUE,MAKELONG(0,255));
220
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETTICFREQ,SLIDERPAGE,0);
221
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETPAGESIZE,0,SLIDERPAGE);
222
                        SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i,     EM_SETLIMITTEXT,3,0);
223
                }
224
                for(i = 0; i < 4; ++i){
225
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        EM_SETLIMITTEXT,MAXEXPR-1,0); // we need 1 byte as NUL terminator, so our formula can be max 1023
226
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        WM_SETFONT,(WPARAM)hfnt,false);
227
                }
228
 
229
                maindlginit(hDlg);
230
                break;
231
        case WM_DESTROY:
232
                gdata->hWndMainDlg = 0;
233
                DestroyCursor(hCurHandOpen);
234
                DestroyCursor(hCurHandGrab);
235
                DestroyCursor(hCurHandQuestion);
236
                break;
237
        case WM_DRAWITEM:
238
                pdi = (DRAWITEMSTRUCT*)lParam;
239
                if(pdi->itemAction == ODA_DRAWENTIRE){
240
                        switch(pdi->CtlID){
241
                        case PREVIEWITEM:
242
                                drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
243
                                PIUNLOCKHANDLE(preview_handle);
244
                                break;
245
                        default:
246
                                return false;
247
                        }
248
                }else
249
                        return false; // we couldn't handle the message
250
                break;
251
        case WM_COMMAND:
252
                item = LOWORD(wParam);
253
                switch(HIWORD(wParam)){
254
                case BN_CLICKED: //case STN_CLICKED:
255
                        if(item==PREVIEWITEM && GetCursorPos(&origpos)){
256
                                panning = true;
257
                                origscroll = preview_scroll;
258
                                SetCursor(hCurHandGrab);
259
                                SetCapture(hDlg);
260
                                break;
261
                        }
262
                        /* ... falls through ... */
263
                case EN_CHANGE:
264
                        if(doupdates && !maindlgitem(hDlg,item))
265
                                EndDialog(hDlg,item);
266
                }
267
                break;
268
//      case WM_LBUTTONDOWN: break;
269
        case WM_MOUSEMOVE:
270
                if(panning && GetCursorPos(&newpos)){
273 daniel-mar 271
                        newscroll.h = (int16)(origscroll.h - zoomfactor*((double)newpos.x - (double)origpos.x));
272
                        newscroll.v = (int16)(origscroll.v - zoomfactor*((double)newpos.y - (double)origpos.y));
259 daniel-mar 273
                        if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){
274
                                preview_scroll = newscroll;
275
                                recalc_preview(gpb,hDlg);
276
                        }
277
                }
278
                break;
279
        case WM_LBUTTONUP:
280
                ReleaseCapture();
281
                panning = false;
282
                break;
283
        case WM_HSCROLL:
284
                item = GetDlgCtrlID((HWND)lParam);
285
                if(doupdates && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7)
286
                        slidermoved(hDlg,item);
287
                break;
288
        default:
289
                return false;
290
        }
291
 
292
        return true;
293
}
294
 
295
Boolean maindialog(FilterRecordPtr pb){
296
        PlatformData *p;
297
        WNDCLASSEX clx;
298
        Boolean res;
299
 
300
        // For the preview image, we register a class, so that we can assign a mouse cursor to this class.
301
        clx.cbSize = sizeof(WNDCLASSEX);
302
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
303
        clx.lpszClassName = "Preview";
304
        RegisterClassEx(&clx);
305
 
306
        // For the caution images, we register a class, so that we can assign a mouse cursor to this class.
307
        clx.cbSize = sizeof(WNDCLASSEX);
308
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
309
        clx.lpszClassName = "CautionSign";
310
        RegisterClassEx(&clx);
311
 
312
        // Now show the dialog
313
        p = (PlatformData*)pb->platformData;
314
        res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG),
315
                             (HWND)p->hwnd,maindlgproc,0) == IDOK;
316
 
353 daniel-mar 317
        // Clean up after the dialog has been closed
259 daniel-mar 318
        UnregisterClass("Preview", hDllInstance);
319
        UnregisterClass("CautionSign", hDllInstance);
320
 
321
        return res;
322
}
323