Subversion Repositories filter_foundry

Rev

Rev 355 | Rev 402 | 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) {
393 daniel-mar 48
                sprintf(title, "About %s", gdata->parm.szTitle);
259 daniel-mar 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,
393 daniel-mar 60
                               gdata->parm.szTitle,
61
                               gdata->parm.szAuthor,
62
                               gdata->parm.szCopyright);
259 daniel-mar 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) {
393 daniel-mar 88
                title = gdata->parm.szTitle;
259 daniel-mar 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) {
393 daniel-mar 100
                title = gdata->parm.szTitle;
101
        } else {
320 daniel-mar 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
 
353 daniel-mar 108
Boolean showmessage(char *s) {
273 daniel-mar 109
        HWND hwnd;
259 daniel-mar 110
        char* title;
111
        if (gdata && gdata->standalone) {
393 daniel-mar 112
                title = gdata->parm.szTitle;
259 daniel-mar 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
 
353 daniel-mar 122
// Description:
393 daniel-mar 123
//   Creates a tooltip for an item in a dialog box.
353 daniel-mar 124
// Parameters:
125
//   idTool - identifier of an dialog box item.
126
//   nDlg - window handle of the dialog box.
127
//   pszText - string to use as the tooltip text.
128
// Returns:
129
//   The handle to the tooltip.
130
//
131
HWND CreateToolTip(int toolID, HWND hDlg, PTSTR pszText) {
354 daniel-mar 132
        // Source: https://docs.microsoft.com/en-us/windows/win32/controls/create-a-tooltip-for-a-control (modified)
393 daniel-mar 133
 
354 daniel-mar 134
        HWND hwndTool, hwndTip;
135
        TOOLINFO toolInfo;
136
 
353 daniel-mar 137
        if (!toolID || !hDlg || !pszText) {
138
                return FALSE;
139
        }
140
        // Get the window of the tool.
354 daniel-mar 141
        hwndTool = GetDlgItem(hDlg, toolID);
353 daniel-mar 142
 
143
        // Create the tooltip. g_hInst is the global instance handle.
354 daniel-mar 144
        hwndTip = CreateWindowEx(0, TOOLTIPS_CLASS, NULL,
353 daniel-mar 145
                WS_POPUP | TTS_ALWAYSTIP /* | TTS_BALLOON*/,
146
                CW_USEDEFAULT, CW_USEDEFAULT,
147
                CW_USEDEFAULT, CW_USEDEFAULT,
148
                hDlg, NULL,
149
                hDllInstance, NULL);
150
 
151
        if (!hwndTool || !hwndTip) {
152
                return (HWND)NULL;
153
        }
154
 
155
        // Associate the tooltip with the tool.
354 daniel-mar 156
        memset(&toolInfo, 0, sizeof(TOOLINFO)); // toolInfo = { 0 };
353 daniel-mar 157
        toolInfo.cbSize = sizeof(toolInfo);
158
        toolInfo.hwnd = hDlg;
159
        toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
160
        toolInfo.uId = (UINT_PTR)hwndTool;
161
        toolInfo.lpszText = pszText;
162
        SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
163
 
164
        return hwndTip;
165
}
166
 
354 daniel-mar 167
#ifndef IDC_HAND
168
#define IDC_HAND            MAKEINTRESOURCE(32649)
169
#endif
170
 
259 daniel-mar 171
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){
172
        static POINT origpos;
173
        static Point origscroll;
174
        static Boolean panning = false;
175
 
176
        int item,i;
177
        POINT newpos;
178
        DRAWITEMSTRUCT *pdi;
179
        Point newscroll;
180
        HGDIOBJ hfnt;
181
 
182
        extern Boolean doupdates;
183
        extern Handle preview_handle;
184
 
185
        switch(wMsg){
186
        case WM_INITDIALOG:
187
                gdata->hWndMainDlg = hDlg;
188
 
189
                if(gdata->standalone){
393 daniel-mar 190
                        SetWindowText(hDlg,gdata->parm.szTitle); // window title bar
259 daniel-mar 191
                }
192
                centre_window(hDlg);
193
 
194
                hfnt = GetStockObject(ANSI_FIXED_FONT);
195
 
196
                hCurHandOpen = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_OPEN));
197
                hCurHandGrab = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_GRAB));
198
                hCurHandQuestion = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_QUESTION));
353 daniel-mar 199
                hCurHandPoint = LoadCursor(NULL, IDC_HAND);
259 daniel-mar 200
 
201
                preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM);
202
                GetClientRect(preview_hwnd, &preview_rect);
203
                SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen);
204
 
205
                SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion);
206
 
207
                for(i = 0; i < 4; ++i){
208
                        // If Visual Themes are applied, SS_ICON will be ignored for controls which are not exactly "STATIC" class.
209
                        // Our derivated "CautionSign" class won't work. So we need to set the icon explicitly.
210
                        SendDlgItemMessage(hDlg, FIRSTICONITEM+i, STM_SETICON, (WPARAM)LoadImage(hDllInstance, "CAUTION_ICO",IMAGE_ICON,16,16, LR_DEFAULTCOLOR), 0);
355 daniel-mar 211
                        CreateToolTip(FIRSTICONITEM + i, hDlg, _strdup("Syntax error! Click to see details."));
259 daniel-mar 212
                }
213
 
355 daniel-mar 214
                CreateToolTip(ZOOMINITEM, hDlg, _strdup("Zoom in"));
215
                CreateToolTip(ZOOMOUTITEM, hDlg, _strdup("Zoom out"));
216
                CreateToolTip(ZOOMLEVELITEM, hDlg, _strdup("Zoom fully in/out"));
353 daniel-mar 217
 
218
                // Note: Actually, the whole class gets the cursor, not just these three controls!!
354 daniel-mar 219
                if (hCurHandPoint) {
220
                        SetClassLongPtr(GetDlgItem(hDlg, ZOOMINITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandPoint);
221
                        SetClassLongPtr(GetDlgItem(hDlg, ZOOMOUTITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandPoint);
222
                        SetClassLongPtr(GetDlgItem(hDlg, ZOOMLEVELITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandPoint);
223
                }
353 daniel-mar 224
 
259 daniel-mar 225
                for(i = 0; i < 8; ++i){
226
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETRANGE,TRUE,MAKELONG(0,255));
227
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETTICFREQ,SLIDERPAGE,0);
228
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETPAGESIZE,0,SLIDERPAGE);
229
                        SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i,     EM_SETLIMITTEXT,3,0);
230
                }
231
                for(i = 0; i < 4; ++i){
232
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        EM_SETLIMITTEXT,MAXEXPR-1,0); // we need 1 byte as NUL terminator, so our formula can be max 1023
233
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        WM_SETFONT,(WPARAM)hfnt,false);
234
                }
235
 
236
                maindlginit(hDlg);
237
                break;
238
        case WM_DESTROY:
239
                gdata->hWndMainDlg = 0;
240
                DestroyCursor(hCurHandOpen);
241
                DestroyCursor(hCurHandGrab);
242
                DestroyCursor(hCurHandQuestion);
243
                break;
244
        case WM_DRAWITEM:
245
                pdi = (DRAWITEMSTRUCT*)lParam;
246
                if(pdi->itemAction == ODA_DRAWENTIRE){
247
                        switch(pdi->CtlID){
248
                        case PREVIEWITEM:
249
                                drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
250
                                PIUNLOCKHANDLE(preview_handle);
251
                                break;
252
                        default:
253
                                return false;
254
                        }
255
                }else
256
                        return false; // we couldn't handle the message
257
                break;
258
        case WM_COMMAND:
259
                item = LOWORD(wParam);
260
                switch(HIWORD(wParam)){
261
                case BN_CLICKED: //case STN_CLICKED:
262
                        if(item==PREVIEWITEM && GetCursorPos(&origpos)){
263
                                panning = true;
264
                                origscroll = preview_scroll;
265
                                SetCursor(hCurHandGrab);
266
                                SetCapture(hDlg);
267
                                break;
268
                        }
269
                        /* ... falls through ... */
270
                case EN_CHANGE:
271
                        if(doupdates && !maindlgitem(hDlg,item))
272
                                EndDialog(hDlg,item);
273
                }
274
                break;
275
//      case WM_LBUTTONDOWN: break;
276
        case WM_MOUSEMOVE:
277
                if(panning && GetCursorPos(&newpos)){
273 daniel-mar 278
                        newscroll.h = (int16)(origscroll.h - zoomfactor*((double)newpos.x - (double)origpos.x));
279
                        newscroll.v = (int16)(origscroll.v - zoomfactor*((double)newpos.y - (double)origpos.y));
259 daniel-mar 280
                        if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){
281
                                preview_scroll = newscroll;
282
                                recalc_preview(gpb,hDlg);
283
                        }
284
                }
285
                break;
286
        case WM_LBUTTONUP:
287
                ReleaseCapture();
288
                panning = false;
289
                break;
290
        case WM_HSCROLL:
291
                item = GetDlgCtrlID((HWND)lParam);
292
                if(doupdates && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7)
293
                        slidermoved(hDlg,item);
294
                break;
295
        default:
296
                return false;
297
        }
298
 
299
        return true;
300
}
301
 
302
Boolean maindialog(FilterRecordPtr pb){
303
        PlatformData *p;
304
        WNDCLASSEX clx;
305
        Boolean res;
306
 
307
        // For the preview image, we register a class, so that we can assign a mouse cursor to this class.
308
        clx.cbSize = sizeof(WNDCLASSEX);
309
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
310
        clx.lpszClassName = "Preview";
311
        RegisterClassEx(&clx);
312
 
313
        // For the caution images, we register a class, so that we can assign a mouse cursor to this class.
314
        clx.cbSize = sizeof(WNDCLASSEX);
315
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
316
        clx.lpszClassName = "CautionSign";
317
        RegisterClassEx(&clx);
318
 
319
        // Now show the dialog
320
        p = (PlatformData*)pb->platformData;
321
        res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG),
322
                             (HWND)p->hwnd,maindlgproc,0) == IDOK;
323
 
353 daniel-mar 324
        // Clean up after the dialog has been closed
259 daniel-mar 325
        UnregisterClass("Preview", hDllInstance);
326
        UnregisterClass("CautionSign", hDllInstance);
327
 
328
        return res;
329
}
330