Subversion Repositories filter_foundry

Rev

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