Subversion Repositories filter_foundry

Rev

Rev 171 | Rev 184 | 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
171 dmarschall 3
    Copyright (C) 2003-2019 Toby Thain, toby@telegraphics.com.au
18 toby 4
 
5
    This program is free software; you can redistribute it and/or modify
106 dmarschall 6
    it under the terms of the GNU General Public License as published by
18 toby 7
    the Free Software Foundation; either version 2 of the License, or
8
    (at your option) any later version.
9
 
10
    This program is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    GNU General Public License for more details.
14
 
106 dmarschall 15
    You should have received a copy of the GNU General Public License
18 toby 16
    along with this program; if not, write to the Free Software
17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
*/
19
 
78 toby 20
/* Win32 user interface routines */
2 toby 21
 
22
#include "world.h"
23
 
29 toby 24
#include "PIAbout.h"
2 toby 25
 
26
#include <windows.h>
27
#include <commctrl.h>
28
 
29
#include "ff.h"
94 toby 30
 
2 toby 31
#include "version.h"
32
 
33
HWND preview_hwnd;
106 dmarschall 34
HCURSOR hCurHandOpen;
35
HCURSOR hCurHandGrab;
126 dmarschall 36
HCURSOR hCurHandQuestion;
2 toby 37
 
38
extern HANDLE hDllInstance;
39
 
40
void DoAbout(AboutRecordPtr pb){
182 dmarschall 41
        char text[1000];
42
        char title[200];
2 toby 43
        PlatformData *p = (PlatformData*)pb->platformData;
44
 
182 dmarschall 45
        if (gdata && gdata->standalone) {
46
                sprintf(title, "About %s", INPLACEP2CSTR(gdata->parm.title));
47
                sprintf(text,  "%s by %s\n" /* {Title} by {Author} */
48
                               "%s\n" /* {Copyright} */
49
                               "\n"
50
                               "This plugin was built using Filter Foundry " VERSION_STR "\n"
51
                               "(C) 2003-" RELEASE_YEAR " Toby Thain <toby@telegraphics.com.au>\n"
52
                               "available from http://www.telegraphics.com.au/sw/",
53
                               INPLACEP2CSTR(gdata->parm.title),
54
                               INPLACEP2CSTR(gdata->parm.author),
55
                               INPLACEP2CSTR(gdata->parm.copyright));
56
        } else {
57
                sprintf(title, "About Filter Foundry");
58
                sprintf(text,  "Filter Foundry " VERSION_STR "\n"
59
                               "(C) 2003-" RELEASE_YEAR " Toby Thain <toby@telegraphics.com.au>\n"
60
                               "\n"
61
                           "Latest version available from\n"
62
                           "http://www.telegraphics.com.au/sw/\n"
63
                           "Please contact the author with any bug reports,\n"
64
                           "suggestions or comments.\n"
65
                           "If you use this program and like it, please consider\n"
66
                           "making a donation through www.paypal.com\n"
67
                           "(US$5 suggested) to the address above.");
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 {
78
                title = "Filter Foundry";
79
        }
80
        return MessageBox(NULL,s,title,MB_TASKMODAL|MB_ICONERROR|MB_OK) == IDOK;
2 toby 81
}
82
 
114 dmarschall 83
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
2 toby 84
 
114 dmarschall 85
INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){
2 toby 86
        static POINT origpos;
87
        static Point origscroll;
88
        static Boolean panning = false;
89
 
23 toby 90
        int item,i;
2 toby 91
        POINT newpos;
92
        DRAWITEMSTRUCT *pdi;
93
        Point newscroll;
94
        HFONT hfnt;
92 toby 95
        char s[0x100];
106 dmarschall 96
 
2 toby 97
        extern Boolean doupdates;
98
        extern Handle preview_handle;
99
 
100
        switch(wMsg){
101
        case WM_INITDIALOG:
106 dmarschall 102
                gdata->hWndMainDlg = hDlg;
103
 
92 toby 104
                if(gdata->standalone){
105
                        myp2cstrcpy(s,gdata->parm.title);
106
                        SetWindowText(hDlg,s); // window title bar
107
                }
2 toby 108
                centre_window(hDlg);
109
 
110
                // see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_3pbo.asp
106 dmarschall 111
                hfnt = GetStockObject(ANSI_FIXED_FONT);
112
 
113
                hCurHandOpen = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_OPEN));
114
                hCurHandGrab = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_GRAB));
126 dmarschall 115
                hCurHandQuestion = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_QUESTION));
106 dmarschall 116
 
2 toby 117
                preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM);
118
                GetClientRect(preview_hwnd, &preview_rect);
108 dmarschall 119
                SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen);
2 toby 120
 
126 dmarschall 121
                SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion);
122
 
158 dmarschall 123
                for(i = 0; i < 4; ++i){
124
                        // If Visual Themes are applied, SS_ICON will be ignored for controls which are not exactly "STATIC" class.
125
                        // Our derivated "CautionSign" class won't work. So we need to set the icon explicitly.
126
                        SendDlgItemMessage(hDlg, FIRSTICONITEM+i, STM_SETICON, (WPARAM)LoadImage(hDllInstance, "CAUTION_ICO",IMAGE_ICON,16,16, LR_DEFAULTCOLOR), 0);
127
                }
128
 
78 toby 129
                for(i = 0; i < 8; ++i){
2 toby 130
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETRANGE,TRUE,MAKELONG(0,255));
131
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETTICFREQ,SLIDERPAGE,0);
132
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETPAGESIZE,0,SLIDERPAGE);
133
                        SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i,     EM_SETLIMITTEXT,3,0);
134
                }
78 toby 135
                for(i = 0; i < 4; ++i){
106 dmarschall 136
                        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 137
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        WM_SETFONT,(WPARAM)hfnt,false);
138
                }
139
 
140
                maindlginit(hDlg);
141
                break;
106 dmarschall 142
        case WM_DESTROY:
143
                gdata->hWndMainDlg = 0;
112 dmarschall 144
                DestroyCursor(hCurHandOpen);
145
                DestroyCursor(hCurHandGrab);
126 dmarschall 146
                DestroyCursor(hCurHandQuestion);
106 dmarschall 147
                break;
2 toby 148
        case WM_DRAWITEM:
149
                pdi = (DRAWITEMSTRUCT*)lParam;
150
                if(pdi->itemAction == ODA_DRAWENTIRE){
151
                        switch(pdi->CtlID){
152
                        case PREVIEWITEM:
78 toby 153
                                drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
2 toby 154
                                PIUNLOCKHANDLE(preview_handle);
155
                                break;
78 toby 156
                        default:
157
                                return false;
2 toby 158
                        }
159
                }else
160
                        return false; // we couldn't handle the message
161
                break;
162
        case WM_COMMAND:
163
                item = LOWORD(wParam);
164
                switch(HIWORD(wParam)){
165
                case BN_CLICKED: //case STN_CLICKED:
166
                        if(item==PREVIEWITEM && GetCursorPos(&origpos)){
167
                                panning = true;
168
                                origscroll = preview_scroll;
106 dmarschall 169
                                SetCursor(hCurHandGrab);
2 toby 170
                                SetCapture(hDlg);
171
                                break;
172
                        }
173
                case EN_CHANGE:
174
                        if(doupdates && !maindlgitem(hDlg,item))
175
                                EndDialog(hDlg,item);
176
                }
177
                break;
178
//      case WM_LBUTTONDOWN: break;
179
        case WM_MOUSEMOVE:
180
                if(panning && GetCursorPos(&newpos)){
181
                        newscroll.h = origscroll.h - zoomfactor*(newpos.x - origpos.x);
182
                        newscroll.v = origscroll.v - zoomfactor*(newpos.y - origpos.y);
183
                        if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){
184
                                preview_scroll = newscroll;
185
                                recalc_preview(gpb,hDlg);
186
                        }
187
                }
188
                break;
189
        case WM_LBUTTONUP:
190
                ReleaseCapture();
191
                panning = false;
192
                break;
193
        case WM_HSCROLL:
194
                item = GetDlgCtrlID((HWND)lParam);
195
                if(doupdates && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7)
196
                        slidermoved(hDlg,item);
197
                break;
198
        default:
199
                return false;
200
        }
201
 
202
        return true;
203
}
204
 
205
Boolean maindialog(FilterRecordPtr pb){
107 dmarschall 206
        PlatformData *p;
126 dmarschall 207
        WNDCLASSEX clx;
132 dmarschall 208
        INT_PTR res;
106 dmarschall 209
 
210
        // For the preview image, we register a class, so that we can assign a mouse cursor to this class.
211
        clx.cbSize = sizeof(WNDCLASSEX);
158 dmarschall 212
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
106 dmarschall 213
        clx.lpszClassName = "Preview";
214
        RegisterClassEx(&clx);
215
 
126 dmarschall 216
        // For the caution images, we register a class, so that we can assign a mouse cursor to this class.
217
        clx.cbSize = sizeof(WNDCLASSEX);
158 dmarschall 218
        GetClassInfoEx(hDllInstance, "STATIC", &clx);
126 dmarschall 219
        clx.lpszClassName = "CautionSign";
220
        RegisterClassEx(&clx);
221
 
106 dmarschall 222
        // Now show the dialog
107 dmarschall 223
        p = pb->platformData;
132 dmarschall 224
        res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG),
225
                             (HWND)p->hwnd,maindlgproc,0) == IDOK;
126 dmarschall 226
 
227
        UnregisterClass("Preview", hDllInstance);
228
        UnregisterClass("CautionSign", hDllInstance);
229
 
230
        return res;
2 toby 231
}
232