Subversion Repositories filter_foundry

Rev

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