Subversion Repositories filter_foundry

Rev

Rev 268 | Rev 320 | 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
 
95
Boolean showmessage(char *s){
273 daniel-mar 96
        HWND hwnd;
259 daniel-mar 97
        char* title;
98
        if (gdata && gdata->standalone) {
99
                title = INPLACEP2CSTR(gdata->parm.title);
100
        } else {
101
                title = _strdup("Filter Foundry");
102
        }
273 daniel-mar 103
        hwnd = gdata ? gdata->hWndMainDlg : NULL;
104
        return MessageBox(hwnd,s,title,MB_TASKMODAL|MB_ICONINFORMATION|MB_OK) == IDOK;
259 daniel-mar 105
}
106
 
107
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
108
 
109
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){
110
        static POINT origpos;
111
        static Point origscroll;
112
        static Boolean panning = false;
113
 
114
        int item,i;
115
        POINT newpos;
116
        DRAWITEMSTRUCT *pdi;
117
        Point newscroll;
118
        HGDIOBJ hfnt;
119
        char s[0x100];
120
 
121
        extern Boolean doupdates;
122
        extern Handle preview_handle;
123
 
124
        switch(wMsg){
125
        case WM_INITDIALOG:
126
                gdata->hWndMainDlg = hDlg;
127
 
128
                if(gdata->standalone){
129
                        myp2cstrcpy(s,gdata->parm.title);
130
                        SetWindowText(hDlg,s); // window title bar
131
                }
132
                centre_window(hDlg);
133
 
134
                hfnt = GetStockObject(ANSI_FIXED_FONT);
135
 
136
                hCurHandOpen = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_OPEN));
137
                hCurHandGrab = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_GRAB));
138
                hCurHandQuestion = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_QUESTION));
139
 
140
                preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM);
141
                GetClientRect(preview_hwnd, &preview_rect);
142
                SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen);
143
 
144
                SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion);
145
 
146
                for(i = 0; i < 4; ++i){
147
                        // If Visual Themes are applied, SS_ICON will be ignored for controls which are not exactly "STATIC" class.
148
                        // Our derivated "CautionSign" class won't work. So we need to set the icon explicitly.
149
                        SendDlgItemMessage(hDlg, FIRSTICONITEM+i, STM_SETICON, (WPARAM)LoadImage(hDllInstance, "CAUTION_ICO",IMAGE_ICON,16,16, LR_DEFAULTCOLOR), 0);
150
                }
151
 
152
                for(i = 0; i < 8; ++i){
153
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETRANGE,TRUE,MAKELONG(0,255));
154
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETTICFREQ,SLIDERPAGE,0);
155
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETPAGESIZE,0,SLIDERPAGE);
156
                        SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i,     EM_SETLIMITTEXT,3,0);
157
                }
158
                for(i = 0; i < 4; ++i){
159
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        EM_SETLIMITTEXT,MAXEXPR-1,0); // we need 1 byte as NUL terminator, so our formula can be max 1023
160
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        WM_SETFONT,(WPARAM)hfnt,false);
161
                }
162
 
163
                maindlginit(hDlg);
164
                break;
165
        case WM_DESTROY:
166
                gdata->hWndMainDlg = 0;
167
                DestroyCursor(hCurHandOpen);
168
                DestroyCursor(hCurHandGrab);
169
                DestroyCursor(hCurHandQuestion);
170
                break;
171
        case WM_DRAWITEM:
172
                pdi = (DRAWITEMSTRUCT*)lParam;
173
                if(pdi->itemAction == ODA_DRAWENTIRE){
174
                        switch(pdi->CtlID){
175
                        case PREVIEWITEM:
176
                                drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
177
                                PIUNLOCKHANDLE(preview_handle);
178
                                break;
179
                        default:
180
                                return false;
181
                        }
182
                }else
183
                        return false; // we couldn't handle the message
184
                break;
185
        case WM_COMMAND:
186
                item = LOWORD(wParam);
187
                switch(HIWORD(wParam)){
188
                case BN_CLICKED: //case STN_CLICKED:
189
                        if(item==PREVIEWITEM && GetCursorPos(&origpos)){
190
                                panning = true;
191
                                origscroll = preview_scroll;
192
                                SetCursor(hCurHandGrab);
193
                                SetCapture(hDlg);
194
                                break;
195
                        }
196
                        /* ... falls through ... */
197
                case EN_CHANGE:
198
                        if(doupdates && !maindlgitem(hDlg,item))
199
                                EndDialog(hDlg,item);
200
                }
201
                break;
202
//      case WM_LBUTTONDOWN: break;
203
        case WM_MOUSEMOVE:
204
                if(panning && GetCursorPos(&newpos)){
273 daniel-mar 205
                        newscroll.h = (int16)(origscroll.h - zoomfactor*((double)newpos.x - (double)origpos.x));
206
                        newscroll.v = (int16)(origscroll.v - zoomfactor*((double)newpos.y - (double)origpos.y));
259 daniel-mar 207
                        if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){
208
                                preview_scroll = newscroll;
209
                                recalc_preview(gpb,hDlg);
210
                        }
211
                }
212
                break;
213
        case WM_LBUTTONUP:
214
                ReleaseCapture();
215
                panning = false;
216
                break;
217
        case WM_HSCROLL:
218
                item = GetDlgCtrlID((HWND)lParam);
219
                if(doupdates && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7)
220
                        slidermoved(hDlg,item);
221
                break;
222
        default:
223
                return false;
224
        }
225
 
226
        return true;
227
}
228
 
229
Boolean maindialog(FilterRecordPtr pb){
230
        PlatformData *p;
231
        WNDCLASSEX clx;
232
        Boolean res;
233
 
234
        // For the preview image, we register a class, so that we can assign a mouse cursor to this class.
235
        clx.cbSize = sizeof(WNDCLASSEX);
236
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
237
        clx.lpszClassName = "Preview";
238
        RegisterClassEx(&clx);
239
 
240
        // For the caution images, we register a class, so that we can assign a mouse cursor to this class.
241
        clx.cbSize = sizeof(WNDCLASSEX);
242
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
243
        clx.lpszClassName = "CautionSign";
244
        RegisterClassEx(&clx);
245
 
246
        // Now show the dialog
247
        p = (PlatformData*)pb->platformData;
248
        res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG),
249
                             (HWND)p->hwnd,maindlgproc,0) == IDOK;
250
 
251
        UnregisterClass("Preview", hDllInstance);
252
        UnregisterClass("CautionSign", hDllInstance);
253
 
254
        return res;
255
}
256