Rev 363 | Rev 366 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
259 | daniel-mar | 1 | /* |
2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
||
3 | Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au |
||
4 | Copyright (C) 2018-2021 Daniel Marschall, ViaThinkSoft |
||
5 | |||
6 | This program is free software; you can redistribute it and/or modify |
||
7 | it under the terms of the GNU General Public License as published by |
||
8 | the Free Software Foundation; either version 2 of the License, or |
||
9 | (at your option) any later version. |
||
10 | |||
11 | This program is distributed in the hope that it will be useful, |
||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | GNU General Public License for more details. |
||
15 | |||
16 | You should have received a copy of the GNU General Public License |
||
17 | along with this program; if not, write to the Free Software |
||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
19 | */ |
||
20 | |||
21 | /* This is PLATFORM INDEPENDENT user interface code - mainly dialog logic */ |
||
22 | |||
23 | #include "ff.h" |
||
365 | daniel-mar | 24 | #include "compat_string.h" |
259 | daniel-mar | 25 | |
26 | int ctls[8],maps[4]; |
||
27 | int checksliders_result; |
||
28 | |||
29 | /* one-time initialisation of dialog box */ |
||
30 | |||
31 | void builddlginit(DIALOGREF dp){ |
||
32 | int i; |
||
33 | char s[0x100]; |
||
34 | |||
35 | if(gdata->parmloaded){ |
||
36 | SetDlgItemText(dp,CATEGORYITEM, INPLACEP2CSTR(gdata->parm.category)); |
||
37 | SetDlgItemText(dp,TITLEITEM, INPLACEP2CSTR(gdata->parm.title)); |
||
38 | SetDlgItemText(dp,COPYRIGHTITEM,INPLACEP2CSTR(gdata->parm.copyright)); |
||
39 | SetDlgItemText(dp,AUTHORITEM, INPLACEP2CSTR(gdata->parm.author)); |
||
40 | for(i=0;i<4;++i){ |
||
41 | SetDlgItemText(dp,FIRSTMAPNAMEITEM+i,INPLACEP2CSTR(gdata->parm.map[i])); |
||
42 | } |
||
43 | for(i=0;i<8;++i){ |
||
44 | SetDlgItemText(dp,FIRSTCTLNAMEITEM+i,INPLACEP2CSTR(gdata->parm.ctl[i])); |
||
45 | } |
||
46 | }else{ |
||
47 | /* strictly speaking this is not needed on the Mac, |
||
48 | we can set initial values statically in the rez description */ |
||
49 | SetDlgItemText(dp,CATEGORYITEM, "Filter Foundry"); |
||
50 | SetDlgItemText(dp,TITLEITEM, "Untitled"); |
||
51 | SetDlgItemText(dp,COPYRIGHTITEM,""); //"Filter Foundry Copyright (C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall" |
||
52 | SetDlgItemText(dp,AUTHORITEM, "Anonymous"); |
||
53 | strcpy(s,"Map X"); |
||
54 | for(i = 0; i < 4; ++i){ |
||
55 | s[4] = '0'+i; |
||
56 | SetDlgItemText(dp,FIRSTMAPNAMEITEM+i,s); |
||
57 | } |
||
58 | strcpy(s,"ctl(X)"); |
||
59 | for(i = 0; i < 8; ++i){ |
||
60 | s[4] = '0'+i; |
||
61 | SetDlgItemText(dp,FIRSTCTLNAMEITEM+i,s); |
||
62 | } |
||
63 | } |
||
64 | |||
65 | checksliders_result = checksliders(4,ctls,maps); |
||
66 | for(i = 4; i--;){ |
||
67 | DISABLEDLGITEM(dp,FIRSTMAPCHECKITEM+i); |
||
68 | if(maps[i] || (checksliders_result & CHECKSLIDERS_MAP_AMBIGUOUS)) |
||
69 | CHECKDLGBUTTON(dp,FIRSTMAPCHECKITEM+i,true); |
||
70 | else |
||
71 | HideDialogItem(dp,FIRSTMAPNAMEITEM+i); |
||
72 | } |
||
73 | for(i = 8; i--;){ |
||
74 | DISABLEDLGITEM(dp,FIRSTCTLCHECKITEM+i); |
||
75 | if((ctls[i] || (checksliders_result & CHECKSLIDERS_CTL_AMBIGUOUS)) && |
||
76 | // When map() is activated, we don't need ctl labels, |
||
77 | // since the standalone filter will only show map labels |
||
78 | !maps[i/2] && |
||
79 | (!(checksliders_result & CHECKSLIDERS_MAP_AMBIGUOUS)) |
||
80 | ) |
||
81 | CHECKDLGBUTTON(dp,FIRSTCTLCHECKITEM+i,true); |
||
82 | else |
||
83 | HideDialogItem(dp,FIRSTCTLNAMEITEM+i); |
||
84 | } |
||
85 | |||
339 | daniel-mar | 86 | CHECKDLGBUTTON(dp, PROTECTITEM, 0); // TODO: should we remember the last setting? |
87 | |||
259 | daniel-mar | 88 | SELECTDLGITEMTEXT(dp,TITLEITEM,0,-1); |
89 | } |
||
90 | |||
91 | |||
92 | /* process an item hit. return false if the dialog is finished; otherwise return true. */ |
||
93 | |||
94 | Boolean builddlgitem(DIALOGREF dp,int item){ |
||
95 | enum{MAXFIELD=0x100}; |
||
96 | char s[MAXFIELD+1]; |
||
97 | int i,needui; |
||
365 | daniel-mar | 98 | Str255 fname; |
99 | StandardFileReply sfr; |
||
100 | NavReplyRecord reply; |
||
259 | daniel-mar | 101 | |
102 | switch(item){ |
||
363 | daniel-mar | 103 | #ifdef MAC_ENV |
104 | case ok: |
||
105 | #else |
||
259 | daniel-mar | 106 | case IDOK: |
363 | daniel-mar | 107 | #endif |
259 | daniel-mar | 108 | // Do a few checks first |
109 | GetDlgItemText(dp, CATEGORYITEM, s, MAXFIELD); |
||
110 | if (strlen(s) == 0) { |
||
111 | simplealert(_strdup("Category must not be empty!")); |
||
363 | daniel-mar | 112 | return true; // don't continue (i.e. don't call EndDialog). Let the user correct the input |
259 | daniel-mar | 113 | } |
114 | GetDlgItemText(dp, TITLEITEM, s, MAXFIELD); |
||
115 | if (strlen(s) == 0) { |
||
116 | simplealert(_strdup("Title must not be empty!")); |
||
363 | daniel-mar | 117 | return true; // don't continue (i.e. don't call EndDialog). Let the user correct the input |
259 | daniel-mar | 118 | } |
119 | |||
120 | // Now begin |
||
121 | memset(&gdata->parm,0,sizeof(PARM_T)); |
||
122 | GetDlgItemText(dp,CATEGORYITEM,s,MAXFIELD); myc2pstrcpy(gdata->parm.category,s); |
||
123 | GetDlgItemText(dp,TITLEITEM,s,MAXFIELD); myc2pstrcpy(gdata->parm.title,s); |
||
124 | GetDlgItemText(dp,COPYRIGHTITEM,s,MAXFIELD); myc2pstrcpy(gdata->parm.copyright,s); |
||
125 | GetDlgItemText(dp,AUTHORITEM,s,MAXFIELD); myc2pstrcpy(gdata->parm.author,s); |
||
126 | gdata->parm.cbSize = PARM_SIZE; |
||
127 | gdata->parm.standalone = 1; //0=original FF, 1=standalone filter |
||
128 | needui = 0; |
||
129 | for(i = 0; i < 8; ++i){ |
||
130 | gdata->parm.val[i] = slider[i]; |
||
131 | gdata->parm.ctl_used[i] = ctls[i] || (checksliders_result & CHECKSLIDERS_CTL_AMBIGUOUS); |
||
132 | needui |= gdata->parm.ctl_used[i]; |
||
133 | GetDlgItemText(dp,FIRSTCTLNAMEITEM+i,s,MAXFIELD); myc2pstrcpy(gdata->parm.ctl[i],s); |
||
134 | } |
||
135 | for(i = 0; i < 4; ++i){ |
||
136 | gdata->parm.map_used[i] = maps[i] || (checksliders_result & CHECKSLIDERS_MAP_AMBIGUOUS); |
||
137 | needui |= gdata->parm.map_used[i]; |
||
138 | GetDlgItemText(dp,FIRSTMAPNAMEITEM+i,s,MAXFIELD); myc2pstrcpy(gdata->parm.map[i],s); |
||
139 | strcpy(gdata->parm.formula[i],expr[i] ? expr[i] : "bug! see builddlgitem"); |
||
140 | } |
||
141 | gdata->parm.popDialog = needui; //true if need to pop a parameter dialog |
||
142 | gdata->parm.unknown1 = gdata->parm.unknown2 = gdata->parm.unknown3 = 0; |
||
143 | gdata->parm.iProtected = ISDLGBUTTONCHECKED(dp,PROTECTITEM); // == 1 means protected |
||
144 | gdata->obfusc = ISDLGBUTTONCHECKED(dp,PROTECTITEM); |
||
365 | daniel-mar | 145 | |
146 | PLstrcpy(fname, gdata->parm.title); |
||
147 | #ifdef MACMACHO |
||
148 | PLstrcat(fname, (StringPtr)"\p.plugin"); // "\p" means "Pascal string" |
||
149 | #endif |
||
150 | if (putfile( |
||
151 | #ifdef MAC_ENV |
||
152 | (StringPtr)_strdup("\pMake standalone filter"), // "\p" means "Pascal string" |
||
153 | #else |
||
154 | (StringPtr)_strdup("\026Make standalone filter"), |
||
155 | #endif |
||
156 | fname, |
||
157 | PS_FILTER_FILETYPE, kPhotoshopSignature, &reply, &sfr, |
||
158 | "8bf", "Filter plugin file (.8bf)\0*.8bf\0\0", 1 |
||
159 | #ifdef _WIN32 |
||
160 | , (HWND)dp |
||
161 | #endif /* _WIN32 */ |
||
162 | )) { |
||
163 | make_standalone(&sfr); |
||
164 | } |
||
165 | else { |
||
166 | return true; // keep going. Let the user correct their input |
||
167 | } |
||
168 | |||
259 | daniel-mar | 169 | /* ... falls through ... */ |
363 | daniel-mar | 170 | #ifdef MAC_ENV |
171 | case cancel: |
||
172 | #else |
||
259 | daniel-mar | 173 | case IDCANCEL: |
363 | daniel-mar | 174 | #endif |
259 | daniel-mar | 175 | return false; // end dialog |
176 | case PROTECTITEM: |
||
177 | CHECKDLGBUTTON(dp, item, ISDLGBUTTONCHECKED(dp,item) ^ 1); |
||
178 | break; |
||
179 | } |
||
180 | |||
181 | return true; // keep going |
||
182 | } |