Subversion Repositories filter_foundry

Rev

Rev 102 | Rev 107 | 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
 
64
BOOL CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
65
 
66
BOOL CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){
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);
106 dmarschall 99
                SetClassLongPtr(preview_hwnd, GCL_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;
116
                break;
2 toby 117
        case WM_DRAWITEM:
118
                pdi = (DRAWITEMSTRUCT*)lParam;
119
                if(pdi->itemAction == ODA_DRAWENTIRE){
120
                        switch(pdi->CtlID){
121
                        case PREVIEWITEM:
78 toby 122
                                drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
2 toby 123
                                PIUNLOCKHANDLE(preview_handle);
124
                                break;
78 toby 125
                        default:
126
                                return false;
2 toby 127
                        }
128
                }else
129
                        return false; // we couldn't handle the message
130
                break;
131
        case WM_COMMAND:
132
                item = LOWORD(wParam);
133
                switch(HIWORD(wParam)){
134
                case BN_CLICKED: //case STN_CLICKED:
135
                        if(item==PREVIEWITEM && GetCursorPos(&origpos)){
136
                                panning = true;
137
                                origscroll = preview_scroll;
106 dmarschall 138
                                SetCursor(hCurHandGrab);
2 toby 139
                                SetCapture(hDlg);
140
                                break;
141
                        }
142
                case EN_CHANGE:
143
                        if(doupdates && !maindlgitem(hDlg,item))
144
                                EndDialog(hDlg,item);
145
                }
146
                break;
147
//      case WM_LBUTTONDOWN: break;
148
        case WM_MOUSEMOVE:
149
                if(panning && GetCursorPos(&newpos)){
150
                        newscroll.h = origscroll.h - zoomfactor*(newpos.x - origpos.x);
151
                        newscroll.v = origscroll.v - zoomfactor*(newpos.y - origpos.y);
152
                        if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){
153
                                preview_scroll = newscroll;
154
                                recalc_preview(gpb,hDlg);
155
                        }
156
                }
157
                break;
158
        case WM_LBUTTONUP:
159
                ReleaseCapture();
160
                panning = false;
161
                break;
162
        case WM_HSCROLL:
163
                item = GetDlgCtrlID((HWND)lParam);
164
                if(doupdates && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7)
165
                        slidermoved(hDlg,item);
166
                break;
167
        default:
168
                return false;
169
        }
170
 
171
        return true;
172
}
173
 
174
Boolean maindialog(FilterRecordPtr pb){
106 dmarschall 175
 
176
        // For the preview image, we register a class, so that we can assign a mouse cursor to this class.
177
        WNDCLASSEX clx;
178
        clx.cbSize = sizeof(WNDCLASSEX);
179
        GetClassInfoEx(hDllInstance, "Static", &clx);
180
        clx.lpszClassName = "Preview";
181
        RegisterClassEx(&clx);
182
 
183
        // Now show the dialog
2 toby 184
        PlatformData *p = pb->platformData;
185
        return DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG),
186
                                                  (HWND)p->hwnd,maindlgproc,0) == IDOK;
187
}
188