Subversion Repositories filter_foundry

Rev

Rev 435 | Rev 444 | 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"
439 daniel-mar 31
#include "slider_win.h"
259 daniel-mar 32
#include "version.h"
33
 
34
HWND preview_hwnd;
35
HCURSOR hCurHandOpen;
36
HCURSOR hCurHandGrab;
419 daniel-mar 37
 
259 daniel-mar 38
HCURSOR hCurHandQuestion;
419 daniel-mar 39
HICON hIconCautionSign;
259 daniel-mar 40
 
41
extern HINSTANCE hDllInstance;
42
 
43
void DoAbout(AboutRecordPtr pb){
44
        char text[1000];
45
        char title[200];
46
        PlatformData *p = (PlatformData*)pb->platformData;
47
 
48
        if (gdata && gdata->standalone) {
393 daniel-mar 49
                sprintf(title, "About %s", gdata->parm.szTitle);
259 daniel-mar 50
                sprintf(text,  "%s by %s\n" /* {Title} by {Author} */
51
                               "%s\n" /* {Copyright} */
52
                               "\n"
53
                               "This plugin was built using Filter Foundry " VERSION_STR
268 daniel-mar 54
                                #ifdef _WIN64
259 daniel-mar 55
                               " (64 bit)\n"
268 daniel-mar 56
                                #else
259 daniel-mar 57
                               " (32 bit)\n"
268 daniel-mar 58
                                #endif
259 daniel-mar 59
                               "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
60
                               "available from " PROJECT_URL,
393 daniel-mar 61
                               gdata->parm.szTitle,
62
                               gdata->parm.szAuthor,
63
                               gdata->parm.szCopyright);
259 daniel-mar 64
        } else {
65
                sprintf(title, "About Filter Foundry");
66
                sprintf(text,  "Filter Foundry " VERSION_STR
268 daniel-mar 67
                                #ifdef _WIN64
259 daniel-mar 68
                               " (64 bit)\n"
268 daniel-mar 69
                                #else
259 daniel-mar 70
                               " (32 bit)\n"
268 daniel-mar 71
                                #endif
259 daniel-mar 72
                               "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
73
                               "\n"
74
                               "Latest version available from\n"
75
                               PROJECT_URL "\n"
76
                               "\nPlease contact the author with any bug reports,\n"
77
                               "suggestions or comments.\n"
78
                               "If you use this program and like it, please consider\n"
79
                               "making a donation.");
80
        }
81
 
412 daniel-mar 82
        MessageBox((HWND)p->hwnd, text, title, MB_TASKMODAL|MB_ICONINFORMATION|MB_OK);
259 daniel-mar 83
}
84
 
85
Boolean simplealert(char *s){
273 daniel-mar 86
        HWND hwnd;
259 daniel-mar 87
        char* title;
88
        if (gdata && gdata->standalone) {
393 daniel-mar 89
                title = gdata->parm.szTitle;
259 daniel-mar 90
        } else {
91
                title = _strdup("Filter Foundry");
92
        }
273 daniel-mar 93
        hwnd = gdata ? gdata->hWndMainDlg : NULL;
413 daniel-mar 94
        return MessageBox(hwnd, s, title, MB_TASKMODAL|MB_ICONERROR|MB_OK) == IDOK;
259 daniel-mar 95
}
96
 
320 daniel-mar 97
Boolean simplewarning(char* s) {
98
        HWND hwnd;
99
        char* title;
100
        if (gdata && gdata->standalone) {
393 daniel-mar 101
                title = gdata->parm.szTitle;
102
        } else {
320 daniel-mar 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) {
393 daniel-mar 113
                title = gdata->parm.szTitle;
259 daniel-mar 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:
393 daniel-mar 124
//   Creates a tooltip for an item in a dialog box.
353 daniel-mar 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) {
354 daniel-mar 133
        // Source: https://docs.microsoft.com/en-us/windows/win32/controls/create-a-tooltip-for-a-control (modified)
393 daniel-mar 134
 
354 daniel-mar 135
        HWND hwndTool, hwndTip;
136
        TOOLINFO toolInfo;
137
 
353 daniel-mar 138
        if (!toolID || !hDlg || !pszText) {
139
                return FALSE;
140
        }
141
        // Get the window of the tool.
354 daniel-mar 142
        hwndTool = GetDlgItem(hDlg, toolID);
353 daniel-mar 143
 
144
        // Create the tooltip. g_hInst is the global instance handle.
354 daniel-mar 145
        hwndTip = CreateWindowEx(0, TOOLTIPS_CLASS, NULL,
353 daniel-mar 146
                WS_POPUP | TTS_ALWAYSTIP /* | TTS_BALLOON*/,
147
                CW_USEDEFAULT, CW_USEDEFAULT,
148
                CW_USEDEFAULT, CW_USEDEFAULT,
149
                hDlg, NULL,
150
                hDllInstance, NULL);
151
 
152
        if (!hwndTool || !hwndTip) {
153
                return (HWND)NULL;
154
        }
155
 
156
        // Associate the tooltip with the tool.
354 daniel-mar 157
        memset(&toolInfo, 0, sizeof(TOOLINFO)); // toolInfo = { 0 };
353 daniel-mar 158
        toolInfo.cbSize = sizeof(toolInfo);
159
        toolInfo.hwnd = hDlg;
160
        toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
161
        toolInfo.uId = (UINT_PTR)hwndTool;
162
        toolInfo.lpszText = pszText;
163
        SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
164
 
165
        return hwndTip;
166
}
167
 
259 daniel-mar 168
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){
169
        static POINT origpos;
170
        static Point origscroll;
171
        static Boolean panning = false;
172
 
173
        int item,i;
174
        POINT newpos;
175
        DRAWITEMSTRUCT *pdi;
176
        Point newscroll;
177
        HGDIOBJ hfnt;
178
 
179
        extern Boolean doupdates;
180
        extern Handle preview_handle;
181
 
427 daniel-mar 182
        if ((gdata->pluginDllSliderMessageId != 0) && (wMsg == gdata->pluginDllSliderMessageId)) {
422 daniel-mar 183
                // This is for the PLUGIN.DLL sliders only
184
                if (doupdates) {
185
                        int sliderNum = wParam - FIRSTCTLITEM;
186
                        uint8_t sliderVal = (uint8_t)(lParam & 0xFFFF);
187
                        slider[sliderNum] = sliderVal;
188
 
189
                        SETCTLTEXTINT(hDlg, FIRSTCTLTEXTITEM + sliderNum, sliderVal, false);
190
                        REPAINTCTL(hDlg, FIRSTCTLTEXTITEM + sliderNum);
191
 
192
                        recalc_preview(gpb, hDlg);
193
                }
194
                return true;
195
        }
196
 
419 daniel-mar 197
        switch (wMsg) {
259 daniel-mar 198
        case WM_INITDIALOG:
199
                gdata->hWndMainDlg = hDlg;
200
 
201
                if(gdata->standalone){
393 daniel-mar 202
                        SetWindowText(hDlg,gdata->parm.szTitle); // window title bar
259 daniel-mar 203
                }
204
                centre_window(hDlg);
205
 
206
                hfnt = GetStockObject(ANSI_FIXED_FONT);
207
 
402 daniel-mar 208
                hCurHandOpen = LoadCursor(hDllInstance, "HAND_OPEN");
209
                hCurHandGrab = LoadCursor(hDllInstance, "HAND_GRAB");
210
                hCurHandQuestion = LoadCursor(hDllInstance, "HAND_QUESTION");
259 daniel-mar 211
 
419 daniel-mar 212
                hIconCautionSign = LoadIcon(hDllInstance, "CAUTION_ICO");
213
 
214
                // Note: The whole class "Preview" gets the mouse cursor, not just the single item!
259 daniel-mar 215
                preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM);
216
                GetClientRect(preview_hwnd, &preview_rect);
217
                SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen);
218
 
419 daniel-mar 219
                // Note: The whole class "Caution" gets the mouse cursor, not just the single item!
259 daniel-mar 220
                SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion);
221
 
222
                for(i = 0; i < 4; ++i){
419 daniel-mar 223
                        CreateToolTip(FIRSTICONITEM + i, hDlg, _strdup("Error in expression! Click to see details."));
259 daniel-mar 224
                }
225
 
355 daniel-mar 226
                CreateToolTip(ZOOMINITEM, hDlg, _strdup("Zoom in"));
227
                CreateToolTip(ZOOMOUTITEM, hDlg, _strdup("Zoom out"));
417 daniel-mar 228
                CreateToolTip(ZOOMLEVELITEM, hDlg, _strdup("Fully zoom in/out"));
353 daniel-mar 229
 
259 daniel-mar 230
                for(i = 0; i < 8; ++i){
427 daniel-mar 231
                        if (gdata->pluginDllSliderMessageId == 0) {
422 daniel-mar 232
                                // Non PLUGIN.DLL sliders
233
                                SetWindowLongPtr(GetDlgItem(hDlg, FIRSTCTLITEM + i), GWL_STYLE, TBS_HORZ | TBS_AUTOTICKS | WS_CHILD | WS_VISIBLE);
234
                                SendDlgItemMessage(hDlg, FIRSTCTLITEM + i, TBM_SETRANGE, TRUE, MAKELONG(0, 255));
235
                                SendDlgItemMessage(hDlg, FIRSTCTLITEM + i, TBM_SETTICFREQ, SLIDERPAGE, 0);
236
                                SendDlgItemMessage(hDlg, FIRSTCTLITEM + i, TBM_SETPAGESIZE, 0, SLIDERPAGE);
237
                        }
238
                        else {
239
                                // PLUGIN.DLL sliders
240
                                SetSliderRange(GetDlgItem(hDlg, FIRSTCTLITEM + i), 0, 255);
241
                        }
259 daniel-mar 242
                        SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i,     EM_SETLIMITTEXT,3,0);
243
                }
244
                for(i = 0; i < 4; ++i){
245
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        EM_SETLIMITTEXT,MAXEXPR-1,0); // we need 1 byte as NUL terminator, so our formula can be max 1023
246
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        WM_SETFONT,(WPARAM)hfnt,false);
247
                }
248
 
249
                maindlginit(hDlg);
250
                break;
251
        case WM_DESTROY:
252
                gdata->hWndMainDlg = 0;
253
                DestroyCursor(hCurHandOpen);
254
                DestroyCursor(hCurHandGrab);
255
                DestroyCursor(hCurHandQuestion);
419 daniel-mar 256
                DestroyIcon(hIconCautionSign);
259 daniel-mar 257
                break;
258
        case WM_DRAWITEM:
259
                pdi = (DRAWITEMSTRUCT*)lParam;
260
                if(pdi->itemAction == ODA_DRAWENTIRE){
261
                        switch(pdi->CtlID){
262
                        case PREVIEWITEM:
263
                                drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
264
                                PIUNLOCKHANDLE(preview_handle);
265
                                break;
419 daniel-mar 266
                        case FIRSTICONITEM:
267
                        case FIRSTICONITEM + 1:
268
                        case FIRSTICONITEM + 2:
269
                        case FIRSTICONITEM + 3:
270
                                DrawIcon(pdi->hDC, 0, 0, hIconCautionSign);
271
                                break;
259 daniel-mar 272
                        default:
273
                                return false;
274
                        }
275
                }else
276
                        return false; // we couldn't handle the message
277
                break;
278
        case WM_COMMAND:
279
                item = LOWORD(wParam);
280
                switch(HIWORD(wParam)){
419 daniel-mar 281
                //case BN_CLICKED:
282
                case STN_CLICKED:
283
                        // BN_CLICKED = Button clicked
284
                        // STN_CLICKED = Static controls with SS_NOTIFY clicked
285
                        // Both have the same ordinal number
259 daniel-mar 286
                        if(item==PREVIEWITEM && GetCursorPos(&origpos)){
287
                                panning = true;
288
                                origscroll = preview_scroll;
289
                                SetCursor(hCurHandGrab);
433 daniel-mar 290
                                SetCapture(hDlg);
259 daniel-mar 291
                                break;
292
                        }
419 daniel-mar 293
                /* ... falls through ... */
259 daniel-mar 294
                case EN_CHANGE:
295
                        if(doupdates && !maindlgitem(hDlg,item))
296
                                EndDialog(hDlg,item);
297
                }
298
                break;
299
//      case WM_LBUTTONDOWN: break;
300
        case WM_MOUSEMOVE:
301
                if(panning && GetCursorPos(&newpos)){
273 daniel-mar 302
                        newscroll.h = (int16)(origscroll.h - zoomfactor*((double)newpos.x - (double)origpos.x));
303
                        newscroll.v = (int16)(origscroll.v - zoomfactor*((double)newpos.y - (double)origpos.y));
259 daniel-mar 304
                        if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){
305
                                preview_scroll = newscroll;
306
                                recalc_preview(gpb,hDlg);
307
                        }
308
                }
309
                break;
310
        case WM_LBUTTONUP:
311
                ReleaseCapture();
312
                panning = false;
313
                break;
314
        case WM_HSCROLL:
422 daniel-mar 315
                // Only for non-Plugin.dll-sliders
259 daniel-mar 316
                item = GetDlgCtrlID((HWND)lParam);
427 daniel-mar 317
                if(doupdates && gdata->pluginDllSliderMessageId == 0 && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7)
259 daniel-mar 318
                        slidermoved(hDlg,item);
319
                break;
320
        default:
321
                return false;
322
        }
323
 
324
        return true;
325
}
326
 
431 daniel-mar 327
Boolean maindialog(FilterRecordPtr pb){
328
        PlatformData *p;
329
        INT_PTR res;
330
 
331
        // First try to use the sliders from PLUGIN.DLL (only Photoshop)
332
        if (!Slider_Init_PluginDll("FoundrySlider")) {
333
                // If we couldn't get the sliders from PLUGIN.DLL (probably not running in Photoshop),
334
                // then try the Microsoft Trackbar Control instead
335
                if (!Slider_Init_MsTrackbar("FoundrySlider")) {
336
                        // This will happen if we neither have PLUGIN.DLL, nor the Microsoft Trackbar Control (msctls_trackbar32).
337
                        // "msctls_trackbar32" is not included in Windows NT 3.1, and since there is no OCX or RegSvr32.
338
                        // It is included in Windows NT 3.5x.
339
 
430 daniel-mar 340
                        //simplealert(_strdup("This plugin requires Photoshop's PLUGIN.DLL or the Microsoft Trackbar Control (msctls_trackbar32) which was not found on your system."));
341
                        //return false;
342
 
343
                        // We simply hide the sliders and let the user enter the numeric values in the edit-box.
431 daniel-mar 344
                        simplewarning(_strdup("Visual sliders are not available because neither PLUGIN.DLL, nor the Microsoft Trackbar Control (msctls_trackbar32) was found on your system."));
345
                        Slider_Init_None("FoundrySlider");
419 daniel-mar 346
                }
413 daniel-mar 347
        }
348
 
431 daniel-mar 349
        // For the preview image and caution symbols, we register subclasses, so that we can assign a mouse cursor to this class.
350
        MakeSimpleSubclass("Preview", "STATIC");
351
        MakeSimpleSubclass("Caution", "Button");
259 daniel-mar 352
 
353
        // Now show the dialog
354
        p = (PlatformData*)pb->platformData;
419 daniel-mar 355
 
356
        // Note: "Invalid Cursor Handle" is the error when an unrecognized control class is detected
259 daniel-mar 357
        res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG),
412 daniel-mar 358
                             (HWND)p->hwnd,maindlgproc,0);
359
        if (res == 0) {
419 daniel-mar 360
                simplealert(_strdup("DialogBoxParam in valid parent window handle"));
412 daniel-mar 361
        }
362
        if (res == -1) {
363
                char s[100];
364
                strcpy(s, "DialogBoxParam failed: ");
365
                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + strlen(s), 0x100, NULL);
366
                dbg(s);
367
        }
259 daniel-mar 368
 
353 daniel-mar 369
        // Clean up after the dialog has been closed
259 daniel-mar 370
        UnregisterClass("Preview", hDllInstance);
419 daniel-mar 371
        UnregisterClass("Caution", hDllInstance);
422 daniel-mar 372
        UnregisterClass("FoundrySlider", hDllInstance);
431 daniel-mar 373
        Slider_Uninit_PluginDll();
259 daniel-mar 374
 
412 daniel-mar 375
        return res == IDOK;
259 daniel-mar 376
}