Rev 114 | Rev 131 | 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; |
||
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" |
46 | "(C) 2003-9 Toby Thain <toby@telegraphics.com.au>\n\n"); |
||
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){ |
||
62 | return MessageBox(NULL,s,"Filter Foundry",MB_APPLMODAL|MB_ICONERROR|MB_OK) == IDOK; |
||
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 | |||
78 | toby | 105 | for(i = 0; i < 8; ++i){ |
2 | toby | 106 | SendDlgItemMessage(hDlg,FIRSTCTLITEM+i, TBM_SETRANGE,TRUE,MAKELONG(0,255)); |
107 | SendDlgItemMessage(hDlg,FIRSTCTLITEM+i, TBM_SETTICFREQ,SLIDERPAGE,0); |
||
108 | SendDlgItemMessage(hDlg,FIRSTCTLITEM+i, TBM_SETPAGESIZE,0,SLIDERPAGE); |
||
109 | SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i, EM_SETLIMITTEXT,3,0); |
||
110 | } |
||
78 | toby | 111 | for(i = 0; i < 4; ++i){ |
106 | dmarschall | 112 | 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 | 113 | SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i, WM_SETFONT,(WPARAM)hfnt,false); |
114 | } |
||
115 | |||
116 | maindlginit(hDlg); |
||
117 | break; |
||
106 | dmarschall | 118 | case WM_DESTROY: |
119 | gdata->hWndMainDlg = 0; |
||
112 | dmarschall | 120 | DestroyCursor(hCurHandOpen); |
121 | DestroyCursor(hCurHandGrab); |
||
126 | dmarschall | 122 | DestroyCursor(hCurHandQuestion); |
106 | dmarschall | 123 | break; |
2 | toby | 124 | case WM_DRAWITEM: |
125 | pdi = (DRAWITEMSTRUCT*)lParam; |
||
126 | if(pdi->itemAction == ODA_DRAWENTIRE){ |
||
127 | switch(pdi->CtlID){ |
||
128 | case PREVIEWITEM: |
||
78 | toby | 129 | drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false)); |
2 | toby | 130 | PIUNLOCKHANDLE(preview_handle); |
131 | break; |
||
78 | toby | 132 | default: |
133 | return false; |
||
2 | toby | 134 | } |
135 | }else |
||
136 | return false; // we couldn't handle the message |
||
137 | break; |
||
138 | case WM_COMMAND: |
||
139 | item = LOWORD(wParam); |
||
140 | switch(HIWORD(wParam)){ |
||
141 | case BN_CLICKED: //case STN_CLICKED: |
||
142 | if(item==PREVIEWITEM && GetCursorPos(&origpos)){ |
||
143 | panning = true; |
||
144 | origscroll = preview_scroll; |
||
106 | dmarschall | 145 | SetCursor(hCurHandGrab); |
2 | toby | 146 | SetCapture(hDlg); |
147 | break; |
||
148 | } |
||
149 | case EN_CHANGE: |
||
150 | if(doupdates && !maindlgitem(hDlg,item)) |
||
151 | EndDialog(hDlg,item); |
||
152 | } |
||
153 | break; |
||
154 | // case WM_LBUTTONDOWN: break; |
||
155 | case WM_MOUSEMOVE: |
||
156 | if(panning && GetCursorPos(&newpos)){ |
||
157 | newscroll.h = origscroll.h - zoomfactor*(newpos.x - origpos.x); |
||
158 | newscroll.v = origscroll.v - zoomfactor*(newpos.y - origpos.y); |
||
159 | if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){ |
||
160 | preview_scroll = newscroll; |
||
161 | recalc_preview(gpb,hDlg); |
||
162 | } |
||
163 | } |
||
164 | break; |
||
165 | case WM_LBUTTONUP: |
||
166 | ReleaseCapture(); |
||
167 | panning = false; |
||
168 | break; |
||
169 | case WM_HSCROLL: |
||
170 | item = GetDlgCtrlID((HWND)lParam); |
||
171 | if(doupdates && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7) |
||
172 | slidermoved(hDlg,item); |
||
173 | break; |
||
174 | default: |
||
175 | return false; |
||
176 | } |
||
177 | |||
178 | return true; |
||
179 | } |
||
180 | |||
181 | Boolean maindialog(FilterRecordPtr pb){ |
||
107 | dmarschall | 182 | PlatformData *p; |
126 | dmarschall | 183 | WNDCLASSEX clx; |
106 | dmarschall | 184 | |
185 | // For the preview image, we register a class, so that we can assign a mouse cursor to this class. |
||
186 | clx.cbSize = sizeof(WNDCLASSEX); |
||
187 | GetClassInfoEx(hDllInstance, "Static", &clx); |
||
188 | clx.lpszClassName = "Preview"; |
||
189 | RegisterClassEx(&clx); |
||
190 | |||
126 | dmarschall | 191 | // For the caution images, we register a class, so that we can assign a mouse cursor to this class. |
192 | clx.cbSize = sizeof(WNDCLASSEX); |
||
193 | GetClassInfoEx(hDllInstance, "Static", &clx); |
||
194 | clx.lpszClassName = "CautionSign"; |
||
195 | RegisterClassEx(&clx); |
||
196 | |||
106 | dmarschall | 197 | // Now show the dialog |
107 | dmarschall | 198 | p = pb->platformData; |
126 | dmarschall | 199 | INT_PTR res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG), |
200 | (HWND)p->hwnd,maindlgproc,0) == IDOK; |
||
201 | |||
202 | UnregisterClass("Preview", hDllInstance); |
||
203 | UnregisterClass("CautionSign", hDllInstance); |
||
204 | |||
205 | return res; |
||
2 | toby | 206 | } |
207 |