Subversion Repositories filter_foundry

Rev

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