Subversion Repositories filter_foundry

Rev

Rev 206 | Rev 213 | 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"
51
                               "This plugin was built using Filter Foundry " VERSION_STR "\n"
192 daniel-mar 52
                               "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
182 dmarschall 53
                               "available from http://www.telegraphics.com.au/sw/",
54
                               INPLACEP2CSTR(gdata->parm.title),
55
                               INPLACEP2CSTR(gdata->parm.author),
56
                               INPLACEP2CSTR(gdata->parm.copyright));
57
        } else {
58
                sprintf(title, "About Filter Foundry");
59
                sprintf(text,  "Filter Foundry " VERSION_STR "\n"
192 daniel-mar 60
                               "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
182 dmarschall 61
                               "\n"
205 daniel-mar 62
                               "Latest version available from\n"
210 daniel-mar 63
                               "https://github.com/danielmarschall/filter_foundry\n"
64
                               "\nPlease contact the author with any bug reports,\n"
205 daniel-mar 65
                               "suggestions or comments.\n"
66
                               "If you use this program and like it, please consider\n"
67
                               "making a donation.");
182 dmarschall 68
        }
69
 
70
        MessageBox((HWND)p->hwnd, text, title, MB_APPLMODAL|MB_ICONINFORMATION|MB_OK);
2 toby 71
}
72
 
73
Boolean simplealert(char *s){
182 dmarschall 74
        char* title;
75
        if (gdata && gdata->standalone) {
76
                title = INPLACEP2CSTR(gdata->parm.title);
77
        } else {
198 daniel-mar 78
                title = _strdup("Filter Foundry");
182 dmarschall 79
        }
80
        return MessageBox(NULL,s,title,MB_TASKMODAL|MB_ICONERROR|MB_OK) == IDOK;
2 toby 81
}
82
 
184 dmarschall 83
Boolean showmessage(char *s){
84
        char* title;
85
        if (gdata && gdata->standalone) {
86
                title = INPLACEP2CSTR(gdata->parm.title);
87
        } else {
198 daniel-mar 88
                title = _strdup("Filter Foundry");
184 dmarschall 89
        }
90
        return MessageBox(NULL,s,title,MB_TASKMODAL|MB_ICONINFORMATION|MB_OK) == IDOK;
91
}
92
 
114 dmarschall 93
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
2 toby 94
 
114 dmarschall 95
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){
2 toby 96
        static POINT origpos;
97
        static Point origscroll;
98
        static Boolean panning = false;
99
 
23 toby 100
        int item,i;
2 toby 101
        POINT newpos;
102
        DRAWITEMSTRUCT *pdi;
103
        Point newscroll;
198 daniel-mar 104
        HGDIOBJ hfnt;
92 toby 105
        char s[0x100];
106 dmarschall 106
 
2 toby 107
        extern Boolean doupdates;
108
        extern Handle preview_handle;
109
 
110
        switch(wMsg){
111
        case WM_INITDIALOG:
106 dmarschall 112
                gdata->hWndMainDlg = hDlg;
113
 
92 toby 114
                if(gdata->standalone){
115
                        myp2cstrcpy(s,gdata->parm.title);
116
                        SetWindowText(hDlg,s); // window title bar
117
                }
2 toby 118
                centre_window(hDlg);
119
 
106 dmarschall 120
                hfnt = GetStockObject(ANSI_FIXED_FONT);
121
 
122
                hCurHandOpen = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_OPEN));
123
                hCurHandGrab = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_GRAB));
126 dmarschall 124
                hCurHandQuestion = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_QUESTION));
106 dmarschall 125
 
2 toby 126
                preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM);
127
                GetClientRect(preview_hwnd, &preview_rect);
108 dmarschall 128
                SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen);
2 toby 129
 
126 dmarschall 130
                SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion);
131
 
158 dmarschall 132
                for(i = 0; i < 4; ++i){
133
                        // If Visual Themes are applied, SS_ICON will be ignored for controls which are not exactly "STATIC" class.
134
                        // Our derivated "CautionSign" class won't work. So we need to set the icon explicitly.
135
                        SendDlgItemMessage(hDlg, FIRSTICONITEM+i, STM_SETICON, (WPARAM)LoadImage(hDllInstance, "CAUTION_ICO",IMAGE_ICON,16,16, LR_DEFAULTCOLOR), 0);
136
                }
137
 
78 toby 138
                for(i = 0; i < 8; ++i){
2 toby 139
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETRANGE,TRUE,MAKELONG(0,255));
140
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETTICFREQ,SLIDERPAGE,0);
141
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETPAGESIZE,0,SLIDERPAGE);
142
                        SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i,     EM_SETLIMITTEXT,3,0);
143
                }
78 toby 144
                for(i = 0; i < 4; ++i){
106 dmarschall 145
                        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 146
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        WM_SETFONT,(WPARAM)hfnt,false);
147
                }
148
 
149
                maindlginit(hDlg);
150
                break;
106 dmarschall 151
        case WM_DESTROY:
152
                gdata->hWndMainDlg = 0;
112 dmarschall 153
                DestroyCursor(hCurHandOpen);
154
                DestroyCursor(hCurHandGrab);
126 dmarschall 155
                DestroyCursor(hCurHandQuestion);
106 dmarschall 156
                break;
2 toby 157
        case WM_DRAWITEM:
158
                pdi = (DRAWITEMSTRUCT*)lParam;
159
                if(pdi->itemAction == ODA_DRAWENTIRE){
160
                        switch(pdi->CtlID){
161
                        case PREVIEWITEM:
78 toby 162
                                drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
2 toby 163
                                PIUNLOCKHANDLE(preview_handle);
164
                                break;
78 toby 165
                        default:
166
                                return false;
2 toby 167
                        }
168
                }else
169
                        return false; // we couldn't handle the message
170
                break;
171
        case WM_COMMAND:
172
                item = LOWORD(wParam);
173
                switch(HIWORD(wParam)){
174
                case BN_CLICKED: //case STN_CLICKED:
175
                        if(item==PREVIEWITEM && GetCursorPos(&origpos)){
176
                                panning = true;
177
                                origscroll = preview_scroll;
106 dmarschall 178
                                SetCursor(hCurHandGrab);
2 toby 179
                                SetCapture(hDlg);
180
                                break;
181
                        }
194 daniel-mar 182
                        /* ... falls through ... */
2 toby 183
                case EN_CHANGE:
184
                        if(doupdates && !maindlgitem(hDlg,item))
185
                                EndDialog(hDlg,item);
186
                }
187
                break;
188
//      case WM_LBUTTONDOWN: break;
189
        case WM_MOUSEMOVE:
190
                if(panning && GetCursorPos(&newpos)){
185 dmarschall 191
                        newscroll.h = (int16)(origscroll.h - zoomfactor*(newpos.x - origpos.x));
192
                        newscroll.v = (int16)(origscroll.v - zoomfactor*(newpos.y - origpos.y));
2 toby 193
                        if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){
194
                                preview_scroll = newscroll;
195
                                recalc_preview(gpb,hDlg);
196
                        }
197
                }
198
                break;
199
        case WM_LBUTTONUP:
200
                ReleaseCapture();
201
                panning = false;
202
                break;
203
        case WM_HSCROLL:
204
                item = GetDlgCtrlID((HWND)lParam);
205
                if(doupdates && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7)
206
                        slidermoved(hDlg,item);
207
                break;
208
        default:
209
                return false;
210
        }
211
 
212
        return true;
213
}
214
 
215
Boolean maindialog(FilterRecordPtr pb){
107 dmarschall 216
        PlatformData *p;
126 dmarschall 217
        WNDCLASSEX clx;
185 dmarschall 218
        Boolean res;
106 dmarschall 219
 
220
        // For the preview image, we register a class, so that we can assign a mouse cursor to this class.
221
        clx.cbSize = sizeof(WNDCLASSEX);
158 dmarschall 222
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
106 dmarschall 223
        clx.lpszClassName = "Preview";
224
        RegisterClassEx(&clx);
225
 
126 dmarschall 226
        // For the caution images, we register a class, so that we can assign a mouse cursor to this class.
227
        clx.cbSize = sizeof(WNDCLASSEX);
158 dmarschall 228
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
126 dmarschall 229
        clx.lpszClassName = "CautionSign";
230
        RegisterClassEx(&clx);
231
 
106 dmarschall 232
        // Now show the dialog
198 daniel-mar 233
        p = (PlatformData*)pb->platformData;
132 dmarschall 234
        res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG),
235
                             (HWND)p->hwnd,maindlgproc,0) == IDOK;
126 dmarschall 236
 
237
        UnregisterClass("Preview", hDllInstance);
238
        UnregisterClass("CautionSign", hDllInstance);
239
 
240
        return res;
2 toby 241
}
242