Subversion Repositories filter_foundry

Rev

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