Subversion Repositories filter_foundry

Rev

Rev 182 | Rev 185 | 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
 
184 dmarschall 83
Boolean showmessage(char *s){
84
        char* title;
85
        if (gdata && gdata->standalone) {
86
                title = INPLACEP2CSTR(gdata->parm.title);
87
        } else {
88
                title = "Filter Foundry";
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;
104
        HFONT 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
 
120
                // see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_3pbo.asp
106 dmarschall 121
                hfnt = GetStockObject(ANSI_FIXED_FONT);
122
 
123
                hCurHandOpen = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_OPEN));
124
                hCurHandGrab = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_GRAB));
126 dmarschall 125
                hCurHandQuestion = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_QUESTION));
106 dmarschall 126
 
2 toby 127
                preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM);
128
                GetClientRect(preview_hwnd, &preview_rect);
108 dmarschall 129
                SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen);
2 toby 130
 
126 dmarschall 131
                SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion);
132
 
158 dmarschall 133
                for(i = 0; i < 4; ++i){
134
                        // If Visual Themes are applied, SS_ICON will be ignored for controls which are not exactly "STATIC" class.
135
                        // Our derivated "CautionSign" class won't work. So we need to set the icon explicitly.
136
                        SendDlgItemMessage(hDlg, FIRSTICONITEM+i, STM_SETICON, (WPARAM)LoadImage(hDllInstance, "CAUTION_ICO",IMAGE_ICON,16,16, LR_DEFAULTCOLOR), 0);
137
                }
138
 
78 toby 139
                for(i = 0; i < 8; ++i){
2 toby 140
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETRANGE,TRUE,MAKELONG(0,255));
141
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETTICFREQ,SLIDERPAGE,0);
142
                        SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETPAGESIZE,0,SLIDERPAGE);
143
                        SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i,     EM_SETLIMITTEXT,3,0);
144
                }
78 toby 145
                for(i = 0; i < 4; ++i){
106 dmarschall 146
                        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 147
                        SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        WM_SETFONT,(WPARAM)hfnt,false);
148
                }
149
 
150
                maindlginit(hDlg);
151
                break;
106 dmarschall 152
        case WM_DESTROY:
153
                gdata->hWndMainDlg = 0;
112 dmarschall 154
                DestroyCursor(hCurHandOpen);
155
                DestroyCursor(hCurHandGrab);
126 dmarschall 156
                DestroyCursor(hCurHandQuestion);
106 dmarschall 157
                break;
2 toby 158
        case WM_DRAWITEM:
159
                pdi = (DRAWITEMSTRUCT*)lParam;
160
                if(pdi->itemAction == ODA_DRAWENTIRE){
161
                        switch(pdi->CtlID){
162
                        case PREVIEWITEM:
78 toby 163
                                drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
2 toby 164
                                PIUNLOCKHANDLE(preview_handle);
165
                                break;
78 toby 166
                        default:
167
                                return false;
2 toby 168
                        }
169
                }else
170
                        return false; // we couldn't handle the message
171
                break;
172
        case WM_COMMAND:
173
                item = LOWORD(wParam);
174
                switch(HIWORD(wParam)){
175
                case BN_CLICKED: //case STN_CLICKED:
176
                        if(item==PREVIEWITEM && GetCursorPos(&origpos)){
177
                                panning = true;
178
                                origscroll = preview_scroll;
106 dmarschall 179
                                SetCursor(hCurHandGrab);
2 toby 180
                                SetCapture(hDlg);
181
                                break;
182
                        }
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)){
191
                        newscroll.h = origscroll.h - zoomfactor*(newpos.x - origpos.x);
192
                        newscroll.v = origscroll.v - zoomfactor*(newpos.y - origpos.y);
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;
132 dmarschall 218
        INT_PTR 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
107 dmarschall 233
        p = 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