Subversion Repositories filter_foundry

Rev

Rev 216 | Rev 259 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
18 toby 1
/*
2
    This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
192 daniel-mar 3
    Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au
206 daniel-mar 4
    Copyright (C) 2018-2021 Daniel Marschall, ViaThinkSoft
18 toby 5
 
6
    This program is free software; you can redistribute it and/or modify
106 dmarschall 7
    it under the terms of the GNU General Public License as published by
18 toby 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
 
106 dmarschall 16
    You should have received a copy of the GNU General Public License
18 toby 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
 
78 toby 21
/* Win32 user interface routines */
2 toby 22
 
23
#include "world.h"
24
 
29 toby 25
#include "PIAbout.h"
2 toby 26
 
27
#include <windows.h>
28
#include <commctrl.h>
29
 
30
#include "ff.h"
94 toby 31
 
2 toby 32
#include "version.h"
33
 
34
HWND preview_hwnd;
106 dmarschall 35
HCURSOR hCurHandOpen;
36
HCURSOR hCurHandGrab;
126 dmarschall 37
HCURSOR hCurHandQuestion;
2 toby 38
 
198 daniel-mar 39
extern HINSTANCE hDllInstance;
2 toby 40
 
41
void DoAbout(AboutRecordPtr pb){
182 dmarschall 42
        char text[1000];
43
        char title[200];
2 toby 44
        PlatformData *p = (PlatformData*)pb->platformData;
45
 
182 dmarschall 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"
230 daniel-mar 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
192 daniel-mar 57
                               "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
216 daniel-mar 58
                               "available from " PROJECT_URL,
182 dmarschall 59
                               INPLACEP2CSTR(gdata->parm.title),
60
                               INPLACEP2CSTR(gdata->parm.author),
61
                               INPLACEP2CSTR(gdata->parm.copyright));
62
        } else {
63
                sprintf(title, "About Filter Foundry");
230 daniel-mar 64
                sprintf(text,  "Filter Foundry " VERSION_STR
65
#ifdef _WIN64
66
                               " (64 bit)\n"
67
#else
68
                               " (32 bit)\n"
69
#endif
192 daniel-mar 70
                               "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
182 dmarschall 71
                               "\n"
205 daniel-mar 72
                               "Latest version available from\n"
216 daniel-mar 73
                               PROJECT_URL "\n"
210 daniel-mar 74
                               "\nPlease contact the author with any bug reports,\n"
205 daniel-mar 75
                               "suggestions or comments.\n"
76
                               "If you use this program and like it, please consider\n"
77
                               "making a donation.");
182 dmarschall 78
        }
79
 
80
        MessageBox((HWND)p->hwnd, text, title, MB_APPLMODAL|MB_ICONINFORMATION|MB_OK);
2 toby 81
}
82
 
83
Boolean simplealert(char *s){
182 dmarschall 84
        char* title;
85
        if (gdata && gdata->standalone) {
86
                title = INPLACEP2CSTR(gdata->parm.title);
87
        } else {
198 daniel-mar 88
                title = _strdup("Filter Foundry");
182 dmarschall 89
        }
90
        return MessageBox(NULL,s,title,MB_TASKMODAL|MB_ICONERROR|MB_OK) == IDOK;
2 toby 91
}
92
 
184 dmarschall 93
Boolean showmessage(char *s){
94
        char* title;
95
        if (gdata && gdata->standalone) {
96
                title = INPLACEP2CSTR(gdata->parm.title);
97
        } else {
198 daniel-mar 98
                title = _strdup("Filter Foundry");
184 dmarschall 99
        }
100
        return MessageBox(NULL,s,title,MB_TASKMODAL|MB_ICONINFORMATION|MB_OK) == IDOK;
101
}
102
 
114 dmarschall 103
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
2 toby 104
 
114 dmarschall 105
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){
2 toby 106
        static POINT origpos;
107
        static Point origscroll;
108
        static Boolean panning = false;
109
 
23 toby 110
        int item,i;
2 toby 111
        POINT newpos;
112
        DRAWITEMSTRUCT *pdi;
113
        Point newscroll;
198 daniel-mar 114
        HGDIOBJ hfnt;
92 toby 115
        char s[0x100];
106 dmarschall 116
 
2 toby 117
        extern Boolean doupdates;
118
        extern Handle preview_handle;
119
 
120
        switch(wMsg){
121
        case WM_INITDIALOG:
106 dmarschall 122
                gdata->hWndMainDlg = hDlg;
123
 
92 toby 124
                if(gdata->standalone){
125
                        myp2cstrcpy(s,gdata->parm.title);
126
                        SetWindowText(hDlg,s); // window title bar
127
                }
2 toby 128
                centre_window(hDlg);
129
 
106 dmarschall 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));
126 dmarschall 134
                hCurHandQuestion = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_QUESTION));
106 dmarschall 135
 
2 toby 136
                preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM);
137
                GetClientRect(preview_hwnd, &preview_rect);
108 dmarschall 138
                SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen);
2 toby 139
 
126 dmarschall 140
                SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion);
141
 
158 dmarschall 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
 
78 toby 148
                for(i = 0; i < 8; ++i){
2 toby 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
                }
78 toby 154
                for(i = 0; i < 4; ++i){
106 dmarschall 155
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        EM_SETLIMITTEXT,MAXEXPR-1,0); // we need 1 byte as NUL terminator, so our formula can be max 1023
2 toby 156
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        WM_SETFONT,(WPARAM)hfnt,false);
157
                }
158
 
159
                maindlginit(hDlg);
160
                break;
106 dmarschall 161
        case WM_DESTROY:
162
                gdata->hWndMainDlg = 0;
112 dmarschall 163
                DestroyCursor(hCurHandOpen);
164
                DestroyCursor(hCurHandGrab);
126 dmarschall 165
                DestroyCursor(hCurHandQuestion);
106 dmarschall 166
                break;
2 toby 167
        case WM_DRAWITEM:
168
                pdi = (DRAWITEMSTRUCT*)lParam;
169
                if(pdi->itemAction == ODA_DRAWENTIRE){
170
                        switch(pdi->CtlID){
171
                        case PREVIEWITEM:
78 toby 172
                                drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
2 toby 173
                                PIUNLOCKHANDLE(preview_handle);
174
                                break;
78 toby 175
                        default:
176
                                return false;
2 toby 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;
106 dmarschall 188
                                SetCursor(hCurHandGrab);
2 toby 189
                                SetCapture(hDlg);
190
                                break;
191
                        }
194 daniel-mar 192
                        /* ... falls through ... */
2 toby 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)){
185 dmarschall 201
                        newscroll.h = (int16)(origscroll.h - zoomfactor*(newpos.x - origpos.x));
202
                        newscroll.v = (int16)(origscroll.v - zoomfactor*(newpos.y - origpos.y));
2 toby 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){
107 dmarschall 226
        PlatformData *p;
126 dmarschall 227
        WNDCLASSEX clx;
185 dmarschall 228
        Boolean res;
106 dmarschall 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);
158 dmarschall 232
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
106 dmarschall 233
        clx.lpszClassName = "Preview";
234
        RegisterClassEx(&clx);
235
 
126 dmarschall 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);
158 dmarschall 238
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
126 dmarschall 239
        clx.lpszClassName = "CautionSign";
240
        RegisterClassEx(&clx);
241
 
106 dmarschall 242
        // Now show the dialog
198 daniel-mar 243
        p = (PlatformData*)pb->platformData;
132 dmarschall 244
        res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG),
245
                             (HWND)p->hwnd,maindlgproc,0) == IDOK;
126 dmarschall 246
 
247
        UnregisterClass("Preview", hDllInstance);
248
        UnregisterClass("CautionSign", hDllInstance);
249
 
250
        return res;
2 toby 251
}
252