Subversion Repositories filter_foundry

Rev

Rev 511 | Rev 536 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 511 Rev 512
1
/*
1
/*
2
    This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
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
3
    Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au
4
    Copyright (C) 2018-2022 Daniel Marschall, ViaThinkSoft
4
    Copyright (C) 2018-2022 Daniel Marschall, ViaThinkSoft
5
 
5
 
6
    This program is free software; you can redistribute it and/or modify
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
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
8
    the Free Software Foundation; either version 2 of the License, or
9
    (at your option) any later version.
9
    (at your option) any later version.
10
 
10
 
11
    This program is distributed in the hope that it will be useful,
11
    This program is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
14
    GNU General Public License for more details.
15
 
15
 
16
    You should have received a copy of the GNU General Public License
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
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
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
*/
19
*/
20
 
20
 
21
/* This is PLATFORM INDEPENDENT user interface code - mainly dialog logic */
21
/* This is PLATFORM INDEPENDENT user interface code - mainly dialog logic */
22
 
22
 
23
#include "ff.h"
23
#include "ff.h"
24
 
24
 
25
#include "node.h"
25
#include "node.h"
26
#include "funcs.h"
26
#include "funcs.h"
27
#include "y.tab.h"
27
#include "y.tab.h"
28
#include "choosefile.h"
28
#include "choosefile.h"
29
#include "sprintf_tiny.h"
29
#include "sprintf_tiny.h"
30
#include "compat_string.h"
30
#include "compat_string.h"
31
 
31
 
32
#ifdef MAC_ENV
32
#ifdef MAC_ENV
33
        #include <plstringfuncs.h>
33
        #include <plstringfuncs.h>
34
#endif
34
#endif
35
 
35
 
36
Boolean doupdates = true;
36
Boolean doupdates = true;
37
 
37
 
38
void updateglobals(DIALOGREF dp);
38
void updateglobals(DIALOGREF dp);
39
struct node *updateexpr(DIALOGREF dp,int i);
39
struct node *updateexpr(DIALOGREF dp,int i);
40
void updatedialog(DIALOGREF dp);
40
void updatedialog(DIALOGREF dp);
41
void slidertextchanged(DIALOGREF dp,int item);
41
void slidertextchanged(DIALOGREF dp,int item);
42
void updatezoom(DIALOGREF dp);
42
void updatezoom(DIALOGREF dp);
43
 
43
 
44
void updatedialog(DIALOGREF dp){
44
void updatedialog(DIALOGREF dp){
45
        int i;
45
        int i;
46
 
46
 
47
        doupdates = false;
47
        doupdates = false;
48
 
48
 
49
        for(i = 0; i < 8; ++i){
49
        for(i = 0; i < 8; ++i){
50
                SETSLIDERVALUE(dp,FIRSTCTLITEM+i,slider[i]);
50
                SETSLIDERVALUE(dp,FIRSTCTLITEM+i,slider[i]);
51
                SETCTLTEXTINT(dp,FIRSTCTLTEXTITEM+i,slider[i],false);
51
                SETCTLTEXTINT(dp,FIRSTCTLTEXTITEM+i,slider[i],false);
52
        }
52
        }
53
 
53
 
54
        for(i = 0; i < 4; ++i){
54
        for(i = 0; i < 4; ++i){
55
                if(!gdata->standalone)
55
                if(!gdata->standalone)
56
                        SETCTLTEXT(dp,FIRSTEXPRITEM+i,expr[i] ? expr[i] : "");
56
                        SETCTLTEXT(dp,FIRSTEXPRITEM+i,expr[i] ? expr[i] : "");
57
                if(i < nplanes)
57
                if(i < nplanes)
58
                        updateexpr(dp,FIRSTEXPRITEM+i);
58
                        updateexpr(dp,FIRSTEXPRITEM+i);
59
        }
59
        }
60
 
60
 
61
        if(!gdata->standalone)
61
        if(!gdata->standalone)
62
                SELECTCTLTEXT(dp,FIRSTEXPRITEM,0,-1);
62
                SELECTCTLTEXT(dp,FIRSTEXPRITEM,0,-1);
63
 
63
 
64
        doupdates = true;
64
        doupdates = true;
65
}
65
}
66
 
66
 
67
/* copy dialog settings to global variables (sliders, expressions) */
67
/* copy dialog settings to global variables (sliders, expressions) */
68
 
68
 
69
void updateglobals(DIALOGREF dp){
69
void updateglobals(DIALOGREF dp){
70
 
70
 
71
        UNREFERENCED_PARAMETER(dp);
71
        UNREFERENCED_PARAMETER(dp);
72
 
72
 
73
        // DM 28 Nov 2021: Removed this function. It makes no sense! The internal state is in the memory
73
        // DM 28 Nov 2021: Removed this function. It makes no sense! The internal state is in the memory
74
        // and the dialog is only the view!
74
        // and the dialog is only the view!
75
 
75
 
76
        /*
76
        /*
77
        int i;
77
        int i;
78
        char s[MAXEXPR+1];
78
        char s[MAXEXPR+1];
79
 
79
 
80
        for(i = 0; i < 8; ++i)
80
        for(i = 0; i < 8; ++i)
81
                slider[i] = (value_type)(GETSLIDERVALUE(dp,FIRSTCTLITEM+i));
81
                slider[i] = (value_type)(GETSLIDERVALUE(dp,FIRSTCTLITEM+i));
82
 
82
 
83
        if(!gdata->standalone)
83
        if(!gdata->standalone)
84
                for(i = 0; i < 4; ++i){
84
                for(i = 0; i < 4; ++i){
85
                        // stash expression strings
85
                        // stash expression strings
86
                        if(GETCTLTEXT(dp,FIRSTEXPRITEM+i,s,MAXEXPR)){
86
                        if(GETCTLTEXT(dp,FIRSTEXPRITEM+i,s,MAXEXPR)){
87
                                if(expr[i])
87
                                if(expr[i])
88
                                        free(expr[i]);
88
                                        free(expr[i]);
89
                                expr[i] = _strdup(s);
89
                                expr[i] = _strdup(s);
90
                        }
90
                        }
91
                        if(!expr[i])
91
                        if(!expr[i])
92
                                expr[i] = _strdup("c");
92
                                expr[i] = _strdup("c");
93
                }
93
                }
94
        */
94
        */
95
}
95
}
96
 
96
 
97
struct node *updateexpr(DIALOGREF dp,int item){
97
struct node *updateexpr(DIALOGREF dp,int item){
98
        char s[MAXEXPR+1];
98
        char s[MAXEXPR+1];
99
        int i;
99
        int i;
100
 
100
 
101
        i = item - FIRSTEXPRITEM;
101
        i = item - FIRSTEXPRITEM;
102
 
102
 
103
        freetree(tree[i]);
103
        freetree(tree[i]);
104
 
104
 
105
        if(!gdata->standalone){
105
        if(!gdata->standalone){
106
                GETCTLTEXT(dp,item,s,MAXEXPR);
106
                GETCTLTEXT(dp,item,s,MAXEXPR);
107
 
107
 
108
                if(expr[i])
108
                if(expr[i])
109
                        free(expr[i]);
109
                        free(expr[i]);
110
                expr[i] = _strdup(s);
110
                expr[i] = _strdup(s);
111
        }
111
        }
112
 
112
 
113
        tree[i] = parseexpr(expr[i]);
113
        tree[i] = parseexpr(expr[i]);
114
 
114
 
115
        if(!gdata->standalone){
115
        if(!gdata->standalone){
116
                if(tree[i])
116
                if(tree[i])
117
                        HideDialogItem(dp,FIRSTICONITEM+i);
117
                        HideDialogItem(dp,FIRSTICONITEM+i);
118
                else{
118
                else{
119
                        err[i] = errstr;
119
                        err[i] = errstr;
120
                        errstart[i] = tokstart;
120
                        errstart[i] = tokstart;
121
                        errpos[i] = tokpos;
121
                        errpos[i] = tokpos;
122
                        ShowDialogItem(dp,FIRSTICONITEM+i);
122
                        ShowDialogItem(dp,FIRSTICONITEM+i);
123
                }
123
                }
124
        }
124
        }
125
        return tree[i];
125
        return tree[i];
126
}
126
}
127
 
127
 
128
void updatezoom(DIALOGREF dp){
128
void updatezoom(DIALOGREF dp){
129
        char s[10];
129
        char s[10];
130
        sprintf(s, "%d%%", (int)(100./zoomfactor));
130
        sprintf(s, "%d%%", (int)(100./zoomfactor));
131
        SETCTLTEXT(dp,ZOOMLEVELITEM,s);
131
        SETCTLTEXT(dp,ZOOMLEVELITEM,s);
132
        if (zoomfactor > 1.)
132
        if (zoomfactor > 1.)
133
                ENABLEDLGITEM(dp, ZOOMINITEM);   // ShowDialogItem(dp,ZOOMINITEM);
133
                ENABLEDLGITEM(dp, ZOOMINITEM);   // ShowDialogItem(dp,ZOOMINITEM);
134
        else
134
        else
135
                DISABLEDLGITEM(dp, ZOOMINITEM);  // HideDialogItem(dp, ZOOMINITEM);
135
                DISABLEDLGITEM(dp, ZOOMINITEM);  // HideDialogItem(dp, ZOOMINITEM);
136
        if(zoomfactor < fitzoom)
136
        if(zoomfactor < fitzoom)
137
                ENABLEDLGITEM(dp, ZOOMOUTITEM);  // ShowDialogItem(dp,ZOOMOUTITEM);
137
                ENABLEDLGITEM(dp, ZOOMOUTITEM);  // ShowDialogItem(dp,ZOOMOUTITEM);
138
        else
138
        else
139
                DISABLEDLGITEM(dp, ZOOMOUTITEM); // HideDialogItem(dp,ZOOMOUTITEM);
139
                DISABLEDLGITEM(dp, ZOOMOUTITEM); // HideDialogItem(dp,ZOOMOUTITEM);
140
}
140
}
141
 
141
 
142
/* traverse expression tree, looking for constant references to sliders/maps */
142
/* traverse expression tree, looking for constant references to sliders/maps */
143
 
143
 
144
static int _checksl(struct node*p,int ctlflags[],int mapflags[]){
144
static int _checksl(struct node*p,int ctlflags[],int mapflags[]){
145
        int s, i, result;
145
        int s, i, result;
146
 
146
 
147
        result = 0;
147
        result = 0;
148
        if(p){
148
        if(p){
149
                if( (p->kind==TOK_FN1 && p->v.sym->fn == (pfunc_type)ff_ctl)
149
                if( (p->kind==TOK_FN1 && p->v.sym->fn == (pfunc_type)ff_ctl)
150
                 || (p->kind==TOK_FN3 && p->v.sym->fn == (pfunc_type)ff_val) ){
150
                 || (p->kind==TOK_FN3 && p->v.sym->fn == (pfunc_type)ff_val) ){
151
                        if(p->child[0]->kind == TOK_NUM){
151
                        if(p->child[0]->kind == TOK_NUM){
152
                                s = p->child[0]->v.value;
152
                                s = p->child[0]->v.value;
153
                                if(s>=0 && s<=7)
153
                                if(s>=0 && s<=7)
154
                                        ctlflags[s] = 1;
154
                                        ctlflags[s] = 1;
155
                        }else
155
                        }else
156
                                result |= CHECKSLIDERS_CTL_AMBIGUOUS; /* can't determine which ctl() */
156
                                result |= CHECKSLIDERS_CTL_AMBIGUOUS; /* can't determine which ctl() */
157
                }else if(p->kind==TOK_FN2 && p->v.sym->fn == (pfunc_type)ff_map){
157
                }else if(p->kind==TOK_FN2 && p->v.sym->fn == (pfunc_type)ff_map){
158
                        if(p->child[0]->kind == TOK_NUM){
158
                        if(p->child[0]->kind == TOK_NUM){
159
                                s = p->child[0]->v.value;
159
                                s = p->child[0]->v.value;
160
                                if(s>=0 && s<=3){
160
                                if(s>=0 && s<=3){
161
                                        mapflags[s] = 1;
161
                                        mapflags[s] = 1;
162
                                        ctlflags[s*2] = ctlflags[s*2+1] = 1;
162
                                        ctlflags[s*2] = ctlflags[s*2+1] = 1;
163
                                }
163
                                }
164
                        }else
164
                        }else
165
                                result |= CHECKSLIDERS_MAP_AMBIGUOUS; /* can't determine which map() */
165
                                result |= CHECKSLIDERS_MAP_AMBIGUOUS; /* can't determine which map() */
166
                 }
166
                 }
167
 
167
 
168
                for( i = 0 ; i < MAXCHILDREN ; ++i )
168
                for( i = 0 ; i < MAXCHILDREN ; ++i )
169
                        result |= _checksl(p->child[i],ctlflags,mapflags);
169
                        result |= _checksl(p->child[i],ctlflags,mapflags);
170
        }
170
        }
171
 
171
 
172
        return result;
172
        return result;
173
}
173
}
174
 
174
 
175
int checksliders(int exprs,int ctlflags[],int mapflags[]){
175
int checksliders(int exprs,int ctlflags[],int mapflags[]){
176
        int i, result;
176
        int i, result;
177
 
177
 
178
        result = 0;
178
        result = 0;
179
 
179
 
180
        for(i = 4; i--;)
180
        for(i = 4; i--;)
181
                mapflags[i] = 0;
181
                mapflags[i] = 0;
182
        for(i = 8; i--;)
182
        for(i = 8; i--;)
183
                ctlflags[i] = 0;
183
                ctlflags[i] = 0;
184
 
184
 
185
        for(i = 0; i < exprs; i++)
185
        for(i = 0; i < exprs; i++)
186
                result |= _checksl(tree[i],ctlflags,mapflags);
186
                result |= _checksl(tree[i],ctlflags,mapflags);
187
 
187
 
188
        return result;
188
        return result;
189
}
189
}
190
 
190
 
191
void slidermoved(DIALOGREF dp,int i){
191
void slidermoved(DIALOGREF dp,int i){
192
        int v = GETSLIDERVALUE(dp,i);
192
        int v = GETSLIDERVALUE(dp,i);
193
        if (v < 0) v = 0;
193
        if (v < 0) v = 0;
194
        else if (v > 255) v = 255;
194
        else if (v > 255) v = 255;
195
        i -= FIRSTCTLITEM;
195
        i -= FIRSTCTLITEM;
196
        slider[i] = (uint8_t)v;
196
        slider[i] = (uint8_t)v;
197
        SETCTLTEXTINT(dp,i+FIRSTCTLTEXTITEM,v,false);
197
        SETCTLTEXTINT(dp,i+FIRSTCTLTEXTITEM,v,false);
198
}
198
}
199
 
199
 
200
void slidertextchanged(DIALOGREF dp,int i){
200
void slidertextchanged(DIALOGREF dp,int i){
201
        int v = GETCTLTEXTINT(dp,i,NULL,false);
201
        int v = GETCTLTEXTINT(dp,i,NULL,false);
202
        if (v < 0) v = 0;
202
        if (v < 0) v = 0;
203
        else if (v > 255) v = 255;
203
        else if (v > 255) v = 255;
204
        i -= FIRSTCTLTEXTITEM;
204
        i -= FIRSTCTLTEXTITEM;
205
        SETSLIDERVALUE(dp,i+FIRSTCTLITEM,v);
205
        SETSLIDERVALUE(dp,i+FIRSTCTLITEM,v);
206
        slider[i] = (uint8_t)v;
206
        slider[i] = (uint8_t)v;
207
}
207
}
208
 
208
 
209
void maindlgupdate(DIALOGREF dp){
209
void maindlgupdate(DIALOGREF dp){
210
        int i,unknown,ctls[8],maps[4];
210
        int i,unknown,ctls[8],maps[4];
211
 
211
 
212
        unknown = checksliders(nplanes,ctls,maps);
212
        unknown = checksliders(nplanes,ctls,maps);
213
 
213
 
214
        for(i = 0; i < 8; i++)
214
        for(i = 0; i < 8; i++)
215
                if(unknown || ctls[i]){
215
                if(unknown || ctls[i]){
216
                        ENABLEDLGITEM(dp,FIRSTCTLITEM+i); // TODO: slider is still shown as disabled
216
                        ENABLEDLGITEM(dp,FIRSTCTLITEM+i); // TODO: slider is still shown as disabled
217
                        REPAINTCTL(dp, FIRSTCTLITEM+i); // required for PLUGIN.DLL sliders
217
                        REPAINTCTL(dp, FIRSTCTLITEM+i); // required for PLUGIN.DLL sliders
218
                        ENABLEDLGITEM(dp,FIRSTCTLLABELITEM+i);
218
                        ENABLEDLGITEM(dp,FIRSTCTLLABELITEM+i);
219
                        ShowDialogItem(dp,FIRSTCTLTEXTITEM+i); /* FIXME: this changes keyboard focus */
219
                        ShowDialogItem(dp,FIRSTCTLTEXTITEM+i); /* FIXME: this changes keyboard focus */
220
                }else{
220
                }else{
221
                        DISABLEDLGITEM(dp,FIRSTCTLITEM+i);
221
                        DISABLEDLGITEM(dp,FIRSTCTLITEM+i);
222
                        REPAINTCTL(dp,FIRSTCTLITEM+i); // required for PLUGIN.DLL sliders
222
                        REPAINTCTL(dp,FIRSTCTLITEM+i); // required for PLUGIN.DLL sliders
223
                        DISABLEDLGITEM(dp,FIRSTCTLLABELITEM+i);
223
                        DISABLEDLGITEM(dp,FIRSTCTLLABELITEM+i);
224
                        HideDialogItem(dp,FIRSTCTLTEXTITEM+i); /* FIXME: this changes keyboard focus */
224
                        HideDialogItem(dp,FIRSTCTLTEXTITEM+i); /* FIXME: this changes keyboard focus */
225
                }
225
                }
226
 
226
 
227
        for(i = 0; i < nplanes; i++)
227
        for(i = 0; i < nplanes; i++)
228
                if(!tree[i]){
228
                if(!tree[i]){
229
                        /* uh oh, couldn't parse one of the saved expressions...this is fatal */
229
                        /* uh oh, couldn't parse one of the saved expressions...this is fatal */
230
                        DISABLEDLGITEM(dp,IDOK);
230
                        DISABLEDLGITEM(dp,IDOK);
231
                        if(gdata->standalone){
231
                        if(gdata->standalone){
232
                                // TODO: But before this happens, we get filterBadParameters in filterSelectorStart, since setup() failed
232
                                // TODO: But before this happens, we get filterBadParameters in filterSelectorStart, since setup() failed
233
                                //       so, do we need this message here at all?
233
                                //       so, do we need this message here at all?
234
                                simplealert_id(MSG_SAVED_EXPR_ERR_ID);
234
                                simplealert_id(MSG_SAVED_EXPR_ERR_ID);
235
                        }else{
235
                        }else{
236
                                DISABLEDLGITEM(dp,SAVEITEM);
236
                                DISABLEDLGITEM(dp,SAVEITEM);
237
                                DISABLEDLGITEM(dp,MAKEITEM);
237
                                DISABLEDLGITEM(dp,MAKEITEM);
238
                        }
238
                        }
239
                        return;
239
                        return;
240
                }
240
                }
241
 
241
 
242
        /* we have valid expression trees in all slots...proceed! */
242
        /* we have valid expression trees in all slots...proceed! */
243
        updateglobals(dp);
243
        updateglobals(dp);
244
        if(setup(gpb))
244
        if(setup(gpb))
245
                recalc_preview(gpb,dp);
245
                recalc_preview(gpb,dp);
246
 
246
 
247
        ENABLEDLGITEM(dp,IDOK);
247
        ENABLEDLGITEM(dp,IDOK);
248
        if(!gdata->standalone){
248
        if(!gdata->standalone){
249
                ENABLEDLGITEM(dp,SAVEITEM);
249
                ENABLEDLGITEM(dp,SAVEITEM);
250
                ENABLEDLGITEM(dp,MAKEITEM);
250
                ENABLEDLGITEM(dp,MAKEITEM);
251
                ENABLEDLGITEM(dp,HELPITEM);
251
                ENABLEDLGITEM(dp,HELPITEM);
252
        }
252
        }
253
}
253
}
254
 
254
 
255
/* one-time initialisation of dialog box */
255
/* one-time initialisation of dialog box */
256
 
256
 
257
void strcpy_win_replace_ampersand(char *dst, char *src) {
-
 
258
        size_t i;
-
 
259
        for (i = 0; i < strlen(src); i++) {
-
 
260
#ifdef WIN_ENV
-
 
261
                // & needs to be replaced to && in:
-
 
262
                // - Labels (SETCTLTEXT)
-
 
263
                // - Menu items (i.e. PIPL)
-
 
264
                // It is not required in:
-
 
265
                // - Filedialog FileName
-
 
266
                // - MessageBox title or content
-
 
267
                // - Window titles
-
 
268
                // - Input boxes, e.g. import+export of an existing filter
-
 
269
                if (src[i] == '&') {
-
 
270
                        *dst++ = src[i];
-
 
271
                }
-
 
272
#endif
-
 
273
                *dst++ = src[i];
-
 
274
        }
-
 
275
        *dst++ = '\0';
-
 
276
}
-
 
277
 
-
 
278
void maindlginit(DIALOGREF dp){
257
void maindlginit(DIALOGREF dp){
279
        char s[0x100];
258
        char s[0x100];
280
        int i;
259
        int i;
281
        const char *channelsuffixes[] = {
260
        const char *channelsuffixes[] = {
282
                "", "KA", "I", "RGBA",
261
                "", "KA", "I", "RGBA",
283
                "CMYK", "HSL", "HSB", "1234",
262
                "CMYK", "HSL", "HSB", "1234",
284
                "DA", "LabA"
263
                "DA", "LabA"
285
        };
264
        };
286
 
265
 
287
        /* hide unused expression items */
266
        /* hide unused expression items */
288
        if(gdata->standalone){
267
        if(gdata->standalone){
289
                strcpy_win_replace_ampersand(&s[0], &gdata->parm.szAuthor[0]);
268
                strcpy_win_replace_ampersand(&s[0], &gdata->parm.szAuthor[0]);
290
                SETCTLTEXT(dp,PARAMAUTHORITEM,s);
269
                SETCTLTEXT(dp,PARAMAUTHORITEM,s);
291
                strcpy_win_replace_ampersand(&s[0], &gdata->parm.szCopyright[0]);
270
                strcpy_win_replace_ampersand(&s[0], &gdata->parm.szCopyright[0]);
292
                SETCTLTEXT(dp,PARAMCOPYITEM,s);
271
                SETCTLTEXT(dp,PARAMCOPYITEM,s);
293
 
272
 
294
                // update labels for map() or ctl() sliders
273
                // update labels for map() or ctl() sliders
295
                for(i = 0; i < 8; ++i){
274
                for(i = 0; i < 8; ++i){
296
                        if(gdata->parm.map_used[i/2]) {
275
                        if(gdata->parm.map_used[i/2]) {
297
                                if((i&1) == 0){
276
                                if((i&1) == 0){
298
                                        // even (0, 2, 4, 6)
277
                                        // even (0, 2, 4, 6)
299
                                        strcpy_win_replace_ampersand(&s[0], &gdata->parm.szMap[i/2][0]);
278
                                        strcpy_win_replace_ampersand(&s[0], &gdata->parm.szMap[i/2][0]);
300
                                        SETCTLTEXT(dp, FIRSTMAPLABELITEM + (i/2),s);
279
                                        SETCTLTEXT(dp, FIRSTMAPLABELITEM + (i/2),s);
301
                                        HideDialogItem(dp, FIRSTCTLLABELITEM + i);
280
                                        HideDialogItem(dp, FIRSTCTLLABELITEM + i);
302
                                        HideDialogItem(dp, FIRSTCTLLABELITEM + i + 1);
281
                                        HideDialogItem(dp, FIRSTCTLLABELITEM + i + 1);
303
                                }
282
                                }
304
                        } else if(gdata->parm.ctl_used[i]) {
283
                        } else if(gdata->parm.ctl_used[i]) {
305
                                strcpy_win_replace_ampersand(&s[0], &gdata->parm.szCtl[i][0]);
284
                                strcpy_win_replace_ampersand(&s[0], &gdata->parm.szCtl[i][0]);
306
                                SETCTLTEXT(dp, FIRSTCTLLABELITEM+i,s);
285
                                SETCTLTEXT(dp, FIRSTCTLLABELITEM+i,s);
307
                                HideDialogItem(dp, FIRSTMAPLABELITEM + i/2);
286
                                HideDialogItem(dp, FIRSTMAPLABELITEM + i/2);
308
                        } else {
287
                        } else {
309
                                HideDialogItem(dp, FIRSTCTLITEM + i);
288
                                HideDialogItem(dp, FIRSTCTLITEM + i);
310
                                HideDialogItem(dp, FIRSTCTLTEXTITEM + i);
289
                                HideDialogItem(dp, FIRSTCTLTEXTITEM + i);
311
                                HideDialogItem(dp, FIRSTCTLLABELITEM + i);
290
                                HideDialogItem(dp, FIRSTCTLLABELITEM + i);
312
                                HideDialogItem(dp, FIRSTMAPLABELITEM + i/2);
291
                                HideDialogItem(dp, FIRSTMAPLABELITEM + i/2);
313
                        }
292
                        }
314
                }
293
                }
315
        }
294
        }
316
 
295
 
317
        strcpy(s,"X =");
296
        strcpy(s,"X =");
318
        for(i = 0; i < 4; ++i){
297
        for(i = 0; i < 4; ++i){
319
                if(i >= nplanes){
298
                if(i >= nplanes){
320
                        HideDialogItem(dp,FIRSTICONITEM+i);
299
                        HideDialogItem(dp,FIRSTICONITEM+i);
321
                        HideDialogItem(dp,FIRSTEXPRITEM+i);
300
                        HideDialogItem(dp,FIRSTEXPRITEM+i);
322
                        HideDialogItem(dp,FIRSTLABELITEM+i);
301
                        HideDialogItem(dp,FIRSTLABELITEM+i);
323
                }else{
302
                }else{
324
                        s[0] = channelsuffixes[gpb->imageMode][i];
303
                        s[0] = channelsuffixes[gpb->imageMode][i];
325
                        SETCTLTEXT(dp,FIRSTLABELITEM+i,s);
304
                        SETCTLTEXT(dp,FIRSTLABELITEM+i,s);
326
                }
305
                }
327
        }
306
        }
328
 
307
 
329
        if(setup_preview(gpb,nplanes)){
308
        if(setup_preview(gpb,nplanes)){
330
                // On very large images, processing a fully zoomed out preview (the initial default)
309
                // On very large images, processing a fully zoomed out preview (the initial default)
331
                // can cause out of memory errors, because Photoshop can't page in all data
310
                // can cause out of memory errors, because Photoshop can't page in all data
332
                // during advanceState. To prevent this problem, zoom in until we aren't
311
                // during advanceState. To prevent this problem, zoom in until we aren't
333
                // previewing more than say 10% of Photoshop's indicated maxSpace.
312
                // previewing more than say 10% of Photoshop's indicated maxSpace.
334
                // (e.g., on a 1GB WinXP system, PS CS2 reports 520MB maxSpace, so this will let us
313
                // (e.g., on a 1GB WinXP system, PS CS2 reports 520MB maxSpace, so this will let us
335
                // preview about 50MB of image data.)
314
                // preview about 50MB of image data.)
336
 
315
 
337
                /* Workaround: GIMP/PSPI sets maxSpace to 100 MB hardcoded, so the zoom is not adjusted correctly. */
316
                /* Workaround: GIMP/PSPI sets maxSpace to 100 MB hardcoded, so the zoom is not adjusted correctly. */
338
                int disable_zoom_memory_check;
317
                int disable_zoom_memory_check;
339
                disable_zoom_memory_check = !maxspace_available();
318
                disable_zoom_memory_check = !maxspace_available();
340
 
319
 
341
                if (!disable_zoom_memory_check) {
320
                if (!disable_zoom_memory_check) {
342
                        zoomfactor = sqrt(maxspace()/(10.*preview_w*preview_h*nplanes));
321
                        zoomfactor = sqrt(maxspace()/(10.*preview_w*preview_h*nplanes));
343
                        if(zoomfactor > fitzoom)
322
                        if(zoomfactor > fitzoom)
344
                                zoomfactor = fitzoom;
323
                                zoomfactor = fitzoom;
345
                        if(zoomfactor < 1.)
324
                        if(zoomfactor < 1.)
346
                                zoomfactor = 1.;
325
                                zoomfactor = 1.;
347
                } else {
326
                } else {
348
                        zoomfactor = fitzoom;
327
                        zoomfactor = fitzoom;
349
                }
328
                }
350
 
329
 
351
                updatezoom(dp);
330
                updatezoom(dp);
352
        }else{
331
        }else{
353
                DISABLEDLGITEM(dp, ZOOMINITEM);    // HideDialogItem(dp,ZOOMINITEM);
332
                DISABLEDLGITEM(dp, ZOOMINITEM);    // HideDialogItem(dp,ZOOMINITEM);
354
                DISABLEDLGITEM(dp, ZOOMOUTITEM);   // HideDialogItem(dp,ZOOMOUTITEM);
333
                DISABLEDLGITEM(dp, ZOOMOUTITEM);   // HideDialogItem(dp,ZOOMOUTITEM);
355
                DISABLEDLGITEM(dp, ZOOMLEVELITEM); // HideDialogItem(dp,ZOOMLEVELITEM);
334
                DISABLEDLGITEM(dp, ZOOMLEVELITEM); // HideDialogItem(dp,ZOOMLEVELITEM);
356
        }
335
        }
357
 
336
 
358
        updatedialog(dp);
337
        updatedialog(dp);
359
        maindlgupdate(dp);
338
        maindlgupdate(dp);
360
}
339
}
361
 
340
 
362
 
341
 
363
/* process an item hit. return false if the dialog is finished; otherwise return true. */
342
/* process an item hit. return false if the dialog is finished; otherwise return true. */
364
 
343
 
365
Boolean maindlgitem(DIALOGREF dp,int item){
344
Boolean maindlgitem(DIALOGREF dp,int item){
366
        extern int previewerr;
345
        extern int previewerr;
367
 
346
 
368
        StandardFileReply sfr;
347
        StandardFileReply sfr;
369
        NavReplyRecord reply;
348
        NavReplyRecord reply;
370
        static OSType types[] = {TEXT_FILETYPE,PS_FILTER_FILETYPE};
349
        static OSType types[] = {TEXT_FILETYPE,PS_FILTER_FILETYPE};
371
        TCHAR*reason = NULL;
350
        TCHAR*reason = NULL;
372
        HINSTANCE hShellRes;
351
        HINSTANCE hShellRes;
373
        InternalState bakState;
352
        InternalState bakState;
374
 
353
 
375
        switch(item){
354
        switch(item){
376
#ifdef MAC_ENV
355
#ifdef MAC_ENV
377
        case ok:
356
        case ok:
378
        case cancel:
357
        case cancel:
379
#else
358
#else
380
        case IDOK:
359
        case IDOK:
381
        case IDCANCEL:
360
        case IDCANCEL:
382
#endif
361
#endif
383
                dispose_preview();
362
                dispose_preview();
384
                return false; // end dialog
363
                return false; // end dialog
385
        case OPENITEM:
364
        case OPENITEM:
386
        {
365
        {
387
                TCHAR* tmp1;
366
                TCHAR* tmp1;
388
                TCHAR* filters, *title;
367
                TCHAR* filters, *title;
389
                Boolean loadDlgRet;
368
                Boolean loadDlgRet;
390
 
369
 
391
                title = (TCHAR*)malloc(1024);
370
                title = (TCHAR*)malloc(1024);
392
                if (title == NULL) return false;
371
                if (title == NULL) return false;
393
 
372
 
394
                filters = (TCHAR*)malloc(4096);
373
                filters = (TCHAR*)malloc(4096);
395
                if (filters == NULL) return false;
374
                if (filters == NULL) return false;
396
                memset(filters, 0, 4096);
375
                memset(filters, 0, 4096);
397
                tmp1 = filters;
376
                tmp1 = filters;
398
 
377
 
399
                FF_GetMsg(title, MSG_LOAD_FILTER_SETTINGS_TITLE_ID);
378
                FF_GetMsg(title, MSG_LOAD_FILTER_SETTINGS_TITLE_ID);
400
 
379
 
401
                strcpy_advance_id(&tmp1, MSG_ALL_SUPPORTED_FILES_ID);
380
                strcpy_advance_id(&tmp1, MSG_ALL_SUPPORTED_FILES_ID);
402
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.afs, *.8bf, *.pff, *.prm, *.bin, *.rsrc, *.txt, *.ffx)")); tmp1++;
381
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.afs, *.8bf, *.pff, *.prm, *.bin, *.rsrc, *.txt, *.ffx)")); tmp1++;
403
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.afs;*.8bf;*.pff;*.prm;*.bin;*.rsrc;*.txt;*.ffx")); tmp1++;
382
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.afs;*.8bf;*.pff;*.prm;*.bin;*.rsrc;*.txt;*.ffx")); tmp1++;
404
 
383
 
405
                strcpy_advance_id(&tmp1, MSG_OPEN_AFS_ID);
384
                strcpy_advance_id(&tmp1, MSG_OPEN_AFS_ID);
406
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.afs)")); tmp1++;
385
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.afs)")); tmp1++;
407
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.afs")); tmp1++;
386
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.afs")); tmp1++;
408
 
387
 
409
                strcpy_advance_id(&tmp1, MSG_OPEN_TXT_ID);
388
                strcpy_advance_id(&tmp1, MSG_OPEN_TXT_ID);
410
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.txt)")); tmp1++;
389
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.txt)")); tmp1++;
411
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.txt")); tmp1++;
390
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.txt")); tmp1++;
412
 
391
 
413
                strcpy_advance_id(&tmp1, MSG_OPEN_8BF_ID);
392
                strcpy_advance_id(&tmp1, MSG_OPEN_8BF_ID);
414
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.8bf)")); tmp1++;
393
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.8bf)")); tmp1++;
415
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.8bf")); tmp1++;
394
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.8bf")); tmp1++;
416
 
395
 
417
                strcpy_advance_id(&tmp1, MSG_OPEN_PFF_ID);
396
                strcpy_advance_id(&tmp1, MSG_OPEN_PFF_ID);
418
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.pff)")); tmp1++;
397
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.pff)")); tmp1++;
419
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.pff")); tmp1++;
398
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.pff")); tmp1++;
420
 
399
 
421
                strcpy_advance_id(&tmp1, MSG_OPEN_PRM_ID);
400
                strcpy_advance_id(&tmp1, MSG_OPEN_PRM_ID);
422
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.prm)")); tmp1++;
401
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.prm)")); tmp1++;
423
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.prm")); tmp1++;
402
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.prm")); tmp1++;
424
 
403
 
425
                strcpy_advance_id(&tmp1, MSG_OPEN_RSRC_ID);
404
                strcpy_advance_id(&tmp1, MSG_OPEN_RSRC_ID);
426
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.bin, *.rsrc)")); tmp1++;
405
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.bin, *.rsrc)")); tmp1++;
427
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.bin;*.rsrc")); tmp1++;
406
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.bin;*.rsrc")); tmp1++;
428
 
407
 
429
                strcpy_advance_id(&tmp1, MSG_OPEN_FFX_ID);
408
                strcpy_advance_id(&tmp1, MSG_OPEN_FFX_ID);
430
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.ffx)")); tmp1++;
409
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.ffx)")); tmp1++;
431
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.ffx")); tmp1++;
410
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.ffx")); tmp1++;
432
 
411
 
433
                strcpy_advance_id(&tmp1, MSG_ALL_FILES_ID);
412
                strcpy_advance_id(&tmp1, MSG_ALL_FILES_ID);
434
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.*)")); tmp1++;
413
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.*)")); tmp1++;
435
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.*")); tmp1++;
414
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.*")); tmp1++;
436
 
415
 
437
                loadDlgRet = !gdata->standalone && choosefiletypes(
416
                loadDlgRet = !gdata->standalone && choosefiletypes(
438
#ifdef MAC_ENV
417
#ifdef MAC_ENV
439
                        "\pChoose filter settings", // "\p" means "Pascal string" // TODO (Not important yet): TRANSLATE
418
                        "\pChoose filter settings", // "\p" means "Pascal string" // TODO (Not important yet): TRANSLATE
440
                        &sfr, &reply, types, 2,
419
                        &sfr, &reply, types, 2,
441
                        filters
420
                        filters
442
#else
421
#else
443
                        title, &sfr, &reply, types, 2,
422
                        title, &sfr, &reply, types, 2,
444
                        filters, gdata->hWndMainDlg
423
                        filters, gdata->hWndMainDlg
445
#endif
424
#endif
446
                );
425
                );
447
               
426
               
448
                free(filters);
427
                free(filters);
449
                free(title);
428
                free(title);
450
 
429
 
451
                if (loadDlgRet) {
430
                if (loadDlgRet) {
452
                        // Backup everything, otherwise we might lose parameter data if the loading fails
431
                        // Backup everything, otherwise we might lose parameter data if the loading fails
453
                        bakState = saveInternalState();
432
                        bakState = saveInternalState();
454
 
433
 
455
                        if (loadfile(&sfr, &reason)) {
434
                        if (loadfile(&sfr, &reason)) {
456
                                updatedialog(dp);
435
                                updatedialog(dp);
457
                                maindlgupdate(dp);
436
                                maindlgupdate(dp);
458
                        }
437
                        }
459
                        else {
438
                        else {
460
                                alertuser_id(MSG_CANNOT_LOAD_SETTINGS_ID, reason);
439
                                alertuser_id(MSG_CANNOT_LOAD_SETTINGS_ID, reason);
461
 
440
 
462
                                // Restore
441
                                // Restore
463
                                restoreInternalState(bakState);
442
                                restoreInternalState(bakState);
464
                        }
443
                        }
465
                        if (reason) FF_GetMsg_Free(reason);
444
                        if (reason) FF_GetMsg_Free(reason);
466
                }
445
                }
467
                break;
446
                break;
468
        }
447
        }
469
        case SAVEITEM:
448
        case SAVEITEM:
470
        {
449
        {
471
                TCHAR* tmp1;
450
                TCHAR* tmp1;
472
                TCHAR* filters, *title;
451
                TCHAR* filters, *title;
473
                Boolean saveDlgRet;
452
                Boolean saveDlgRet;
474
 
453
 
475
                title = (TCHAR*)malloc(1024);
454
                title = (TCHAR*)malloc(1024);
476
                if (title == NULL) return false;
455
                if (title == NULL) return false;
477
 
456
 
478
                filters = (TCHAR*)malloc(4096);
457
                filters = (TCHAR*)malloc(4096);
479
                if (filters == NULL) return false;
458
                if (filters == NULL) return false;
480
                memset(filters, 0, 4096);
459
                memset(filters, 0, 4096);
481
                tmp1 = filters;
460
                tmp1 = filters;
482
 
461
 
483
                FF_GetMsg(title, MSG_SAVE_FILTER_SETTINGS_TITLE_ID);
462
                FF_GetMsg(title, MSG_SAVE_FILTER_SETTINGS_TITLE_ID);
484
 
463
 
485
                strcpy_advance_id(&tmp1, MSG_ALL_SUPPORTED_FILES_ID);
464
                strcpy_advance_id(&tmp1, MSG_ALL_SUPPORTED_FILES_ID);
486
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.afs, *.pff, *.txt)")); tmp1++;
465
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.afs, *.pff, *.txt)")); tmp1++;
487
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.afs;*.pff;*.txt")); tmp1++;
466
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.afs;*.pff;*.txt")); tmp1++;
488
 
467
 
489
                strcpy_advance_id(&tmp1, MSG_SAVE_AFS_ID);
468
                strcpy_advance_id(&tmp1, MSG_SAVE_AFS_ID);
490
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.afs)")); tmp1++;
469
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.afs)")); tmp1++;
491
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.afs")); tmp1++;
470
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.afs")); tmp1++;
492
 
471
 
493
                strcpy_advance_id(&tmp1, MSG_SAVE_PFF_ID);
472
                strcpy_advance_id(&tmp1, MSG_SAVE_PFF_ID);
494
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.pff)")); tmp1++;
473
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.pff)")); tmp1++;
495
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.pff")); tmp1++;
474
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.pff")); tmp1++;
496
 
475
 
497
                strcpy_advance_id(&tmp1, MSG_SAVE_TXT_ID);
476
                strcpy_advance_id(&tmp1, MSG_SAVE_TXT_ID);
498
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.txt)")); tmp1++;
477
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.txt)")); tmp1++;
499
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.txt")); tmp1++;
478
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.txt")); tmp1++;
500
 
479
 
501
                strcpy_advance_id(&tmp1, MSG_ALL_FILES_ID);
480
                strcpy_advance_id(&tmp1, MSG_ALL_FILES_ID);
502
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.*)")); tmp1++;
481
                strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.*)")); tmp1++;
503
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.*")); tmp1++;
482
                strcpy_advance(&tmp1, (TCHAR*)TEXT("*.*")); tmp1++;
504
 
483
 
505
                saveDlgRet = !gdata->standalone && putfile(
484
                saveDlgRet = !gdata->standalone && putfile(
506
#ifdef MAC_ENV
485
#ifdef MAC_ENV
507
                        "\pSave filter settings", // "\p" means "Pascal string" // TODO (Not important yet): TRANSLATE
486
                        "\pSave filter settings", // "\p" means "Pascal string" // TODO (Not important yet): TRANSLATE
508
                        "\0",
487
                        "\0",
509
                        TEXT_FILETYPE, SIG_SIMPLETEXT, &reply, &sfr,
488
                        TEXT_FILETYPE, SIG_SIMPLETEXT, &reply, &sfr,
510
                        "afs",
489
                        "afs",
511
                        filters, 1
490
                        filters, 1
512
#else
491
#else
513
                        title,
492
                        title,
514
                        TEXT("\0"),
493
                        TEXT("\0"),
515
                        TEXT_FILETYPE, SIG_SIMPLETEXT, &reply, &sfr,
494
                        TEXT_FILETYPE, SIG_SIMPLETEXT, &reply, &sfr,
516
                        TEXT("afs"),
495
                        TEXT("afs"),
517
                        filters, 1, gdata->hWndMainDlg
496
                        filters, 1, gdata->hWndMainDlg
518
#endif
497
#endif
519
                );
498
                );
520
               
499
               
521
                free(filters);
500
                free(filters);
522
                free(title);
501
                free(title);
523
 
502
 
524
                if (saveDlgRet) {
503
                if (saveDlgRet) {
525
                        if (savefile_afs_pff_picotxt(&sfr)) {
504
                        if (savefile_afs_pff_picotxt(&sfr)) {
526
                                completesave(&reply);
505
                                completesave(&reply);
527
 
506
 
528
                                if (fileHasExtension(&sfr, TEXT(".txt"))) {
507
                                if (fileHasExtension(&sfr, TEXT(".txt"))) {
529
                                        showmessage_id(MSG_PICO_SAVED_ID);
508
                                        showmessage_id(MSG_PICO_SAVED_ID);
530
 
509
 
531
                                        #ifdef MAC_ENV
510
                                        #ifdef MAC_ENV
532
                                        // TODO: Open text file instead
511
                                        // TODO: Open text file instead
533
                                        showmessage_id(MSG_PLEASE_EDIT_MANUALLY_ID);
512
                                        showmessage_id(MSG_PLEASE_EDIT_MANUALLY_ID);
534
                                        #else
513
                                        #else
535
                                        hShellRes = ShellExecute(
514
                                        hShellRes = ShellExecute(
536
                                                gdata->hWndMainDlg,
515
                                                gdata->hWndMainDlg,
537
                                                TEXT("open"),
516
                                                TEXT("open"),
538
                                                &sfr.sfFile.szName[0],
517
                                                &sfr.sfFile.szName[0],
539
                                                NULL,
518
                                                NULL,
540
                                                NULL,
519
                                                NULL,
541
                                                SW_SHOWNORMAL
520
                                                SW_SHOWNORMAL
542
                                        );
521
                                        );
543
                                        if (hShellRes <= (HINSTANCE)32) {
522
                                        if (hShellRes <= (HINSTANCE)32) {
544
                                                // MSDN states: "If the function succeeds, it returns a value greater than 32."
523
                                                // MSDN states: "If the function succeeds, it returns a value greater than 32."
545
 
524
 
546
                                                TCHAR s[0x300];
525
                                                TCHAR s[0x300];
547
                                                xstrcpy(s, (TCHAR*)TEXT("ShellExecute failed: ")); // TODO (Not so important): TRANSLATE
526
                                                xstrcpy(s, (TCHAR*)TEXT("ShellExecute failed: ")); // TODO (Not so important): TRANSLATE
548
                                                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + xstrlen(s), 0x300 - (DWORD)xstrlen(s), NULL);
527
                                                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + xstrlen(s), 0x300 - (DWORD)xstrlen(s), NULL);
549
                                                simplealert(&s[0]);
528
                                                simplealert(&s[0]);
550
 
529
 
551
                                                showmessage_id(MSG_PLEASE_EDIT_MANUALLY_ID);
530
                                                showmessage_id(MSG_PLEASE_EDIT_MANUALLY_ID);
552
                                        }
531
                                        }
553
                                        #endif
532
                                        #endif
554
                                }
533
                                }
555
 
534
 
556
                        }
535
                        }
557
                }
536
                }
558
 
537
 
559
                break;
538
                break;
560
        }
539
        }
561
        case MAKEITEM:
540
        case MAKEITEM:
562
                if (gdata->standalone) return true; // should not happen since the button should be grayed out
541
                if (gdata->standalone) return true; // should not happen since the button should be grayed out
563
 
542
 
564
                builddialog(gpb);
543
                builddialog(gpb);
565
 
544
 
566
                break;
545
                break;
567
        case HELPITEM:
546
        case HELPITEM:
568
                #ifdef MAC_ENV
547
                #ifdef MAC_ENV
569
                // TODO: Open web-browser instead
548
                // TODO: Open web-browser instead
570
                showmessage_id(MSG_FIND_DOKU_HERE_ID);
549
                showmessage_id(MSG_FIND_DOKU_HERE_ID);
571
                #else
550
                #else
572
                hShellRes = ShellExecute(
551
                hShellRes = ShellExecute(
573
                        gdata->hWndMainDlg,
552
                        gdata->hWndMainDlg,
574
                        TEXT("open"),
553
                        TEXT("open"),
575
                        TEXT("https://github.com/danielmarschall/filter_foundry/blob/master/doc/The%20Filter%20Foundry.pdf"),
554
                        TEXT("https://github.com/danielmarschall/filter_foundry/blob/master/doc/The%20Filter%20Foundry.pdf"),
576
                        NULL,
555
                        NULL,
577
                        NULL,
556
                        NULL,
578
                        SW_SHOWNORMAL
557
                        SW_SHOWNORMAL
579
                );
558
                );
580
                if (hShellRes == (HINSTANCE)ERROR_FILE_NOT_FOUND) {
559
                if (hShellRes == (HINSTANCE)ERROR_FILE_NOT_FOUND) {
581
                        // On Win98 we get ERROR_FILE_NOT_FOUND, but the browser still opens!
560
                        // On Win98 we get ERROR_FILE_NOT_FOUND, but the browser still opens!
582
                        // So we ignore it for now...
561
                        // So we ignore it for now...
583
                }
562
                }
584
                else if (hShellRes <= (HINSTANCE)32) {
563
                else if (hShellRes <= (HINSTANCE)32) {
585
                        // MSDN states: "If the function succeeds, it returns a value greater than 32."
564
                        // MSDN states: "If the function succeeds, it returns a value greater than 32."
586
 
565
 
587
                        TCHAR s[0x300];
566
                        TCHAR s[0x300];
588
                        xstrcpy(s, (TCHAR*)TEXT("ShellExecute failed: ")); // TODO (Not so important): TRANSLATE
567
                        xstrcpy(s, (TCHAR*)TEXT("ShellExecute failed: ")); // TODO (Not so important): TRANSLATE
589
                        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + xstrlen(s), 0x300 - (DWORD)xstrlen(s), NULL);
568
                        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + xstrlen(s), 0x300 - (DWORD)xstrlen(s), NULL);
590
                        simplealert(&s[0]);
569
                        simplealert(&s[0]);
591
 
570
 
592
                        showmessage_id(MSG_FIND_DOKU_HERE_ID);
571
                        showmessage_id(MSG_FIND_DOKU_HERE_ID);
593
                }
572
                }
594
                #endif
573
                #endif
595
                break;
574
                break;
596
        case ZOOMINITEM:
575
        case ZOOMINITEM:
597
                zoomfactor = zoomfactor > 2. ? zoomfactor/2. : 1.;
576
                zoomfactor = zoomfactor > 2. ? zoomfactor/2. : 1.;
598
                updatezoom(dp);
577
                updatezoom(dp);
599
                previewerr = false;
578
                previewerr = false;
600
                recalc_preview(gpb,dp);
579
                recalc_preview(gpb,dp);
601
                break;
580
                break;
602
        case ZOOMOUTITEM:
581
        case ZOOMOUTITEM:
603
                zoomfactor *= 2.;
582
                zoomfactor *= 2.;
604
                if(zoomfactor > fitzoom)
583
                if(zoomfactor > fitzoom)
605
                        zoomfactor = fitzoom;
584
                        zoomfactor = fitzoom;
606
                updatezoom(dp);
585
                updatezoom(dp);
607
                previewerr = false;
586
                previewerr = false;
608
                recalc_preview(gpb,dp);
587
                recalc_preview(gpb,dp);
609
                break;
588
                break;
610
        case ZOOMLEVELITEM:
589
        case ZOOMLEVELITEM:
611
                zoomfactor = zoomfactor > 1. ? 1. : (fitzoom < 1. ? 1. : fitzoom);
590
                zoomfactor = zoomfactor > 1. ? 1. : (fitzoom < 1. ? 1. : fitzoom);
612
                updatezoom(dp);
591
                updatezoom(dp);
613
                previewerr = false;
592
                previewerr = false;
614
                recalc_preview(gpb,dp);
593
                recalc_preview(gpb,dp);
615
                break;
594
                break;
616
        case FIRSTCTLITEM:
595
        case FIRSTCTLITEM:
617
        case FIRSTCTLITEM+1:
596
        case FIRSTCTLITEM+1:
618
        case FIRSTCTLITEM+2:
597
        case FIRSTCTLITEM+2:
619
        case FIRSTCTLITEM+3:
598
        case FIRSTCTLITEM+3:
620
        case FIRSTCTLITEM+4:
599
        case FIRSTCTLITEM+4:
621
        case FIRSTCTLITEM+5:
600
        case FIRSTCTLITEM+5:
622
        case FIRSTCTLITEM+6:
601
        case FIRSTCTLITEM+6:
623
        case FIRSTCTLITEM+7:
602
        case FIRSTCTLITEM+7:
624
                slidermoved(dp,item);
603
                slidermoved(dp,item);
625
                recalc_preview(gpb,dp);
604
                recalc_preview(gpb,dp);
626
                break;
605
                break;
627
        case FIRSTCTLTEXTITEM:
606
        case FIRSTCTLTEXTITEM:
628
        case FIRSTCTLTEXTITEM+1:
607
        case FIRSTCTLTEXTITEM+1:
629
        case FIRSTCTLTEXTITEM+2:
608
        case FIRSTCTLTEXTITEM+2:
630
        case FIRSTCTLTEXTITEM+3:
609
        case FIRSTCTLTEXTITEM+3:
631
        case FIRSTCTLTEXTITEM+4:
610
        case FIRSTCTLTEXTITEM+4:
632
        case FIRSTCTLTEXTITEM+5:
611
        case FIRSTCTLTEXTITEM+5:
633
        case FIRSTCTLTEXTITEM+6:
612
        case FIRSTCTLTEXTITEM+6:
634
        case FIRSTCTLTEXTITEM+7:
613
        case FIRSTCTLTEXTITEM+7:
635
                slidertextchanged(dp,item);
614
                slidertextchanged(dp,item);
636
                recalc_preview(gpb,dp);
615
                recalc_preview(gpb,dp);
637
                break;
616
                break;
638
        case FIRSTICONITEM:
617
        case FIRSTICONITEM:
639
        case FIRSTICONITEM+1:
618
        case FIRSTICONITEM+1:
640
        case FIRSTICONITEM+2:
619
        case FIRSTICONITEM+2:
641
        case FIRSTICONITEM+3:
620
        case FIRSTICONITEM+3:
642
                item -= FIRSTICONITEM;
621
                item -= FIRSTICONITEM;
643
                {
622
                {
644
                        simplealert(err[item]);
623
                        simplealert(err[item]);
645
                }
624
                }
646
                SELECTCTLTEXT(dp,FIRSTEXPRITEM+item,errstart[item],errpos[item]);
625
                SELECTCTLTEXT(dp,FIRSTEXPRITEM+item,errstart[item],errpos[item]);
647
                break;
626
                break;
648
        case FIRSTEXPRITEM:
627
        case FIRSTEXPRITEM:
649
        case FIRSTEXPRITEM+1:
628
        case FIRSTEXPRITEM+1:
650
        case FIRSTEXPRITEM+2:
629
        case FIRSTEXPRITEM+2:
651
        case FIRSTEXPRITEM+3:
630
        case FIRSTEXPRITEM+3:
652
                if((item-FIRSTEXPRITEM) < nplanes){
631
                if((item-FIRSTEXPRITEM) < nplanes){
653
                        updateexpr(dp,item);
632
                        updateexpr(dp,item);
654
                        maindlgupdate(dp);
633
                        maindlgupdate(dp);
655
                }
634
                }
656
                break;
635
                break;
657
        }
636
        }
658
 
637
 
659
        return true; // keep going
638
        return true; // keep going
660
}
639
}
661
 
640
 
662
Boolean alertuser(TCHAR *err,TCHAR *more){
641
Boolean alertuser(TCHAR *err,TCHAR *more){
663
        TCHAR *s, *q;
642
        TCHAR *s, *q;
664
        Boolean res;
643
        Boolean res;
665
        size_t i;
644
        size_t i;
666
 
645
 
667
        if (more == NULL) {
646
        if (more == NULL) {
668
                return simplealert(err);
647
                return simplealert(err);
669
        }
648
        }
670
 
649
 
671
        s = (TCHAR*)malloc((xstrlen(err) + xstrlen(more) + 3) * sizeof(TCHAR)); // 3=CR+LF+NUL
650
        s = (TCHAR*)malloc((xstrlen(err) + xstrlen(more) + 3) * sizeof(TCHAR)); // 3=CR+LF+NUL
672
        if (s == NULL) return false;
651
        if (s == NULL) return false;
673
       
652
       
674
        q = s;
653
        q = s;
675
 
654
 
676
        for (i = 0; i < xstrlen(err); i++) {
655
        for (i = 0; i < xstrlen(err); i++) {
677
                *q++ = err[i];
656
                *q++ = err[i];
678
        }
657
        }
679
 
658
 
680
        #ifdef WIN_ENV
659
        #ifdef WIN_ENV
681
        *q++ = CR;
660
        *q++ = CR;
682
        #endif
661
        #endif
683
        *q++ = LF;
662
        *q++ = LF;
684
 
663
 
685
        for (i = 0; i < xstrlen(more); i++) {
664
        for (i = 0; i < xstrlen(more); i++) {
686
                *q++ = more[i];
665
                *q++ = more[i];
687
        }
666
        }
688
 
667
 
689
        *q++ = 0;
668
        *q++ = 0;
690
 
669
 
691
        res = simplealert(s);
670
        res = simplealert(s);
692
        free(s);
671
        free(s);
693
        return res;
672
        return res;
694
}
673
}
695
 
674
 
696
Boolean alertuser_id(int MsgId, TCHAR* more) {
675
Boolean alertuser_id(int MsgId, TCHAR* more) {
697
        TCHAR msg[1000];
676
        TCHAR msg[1000];
698
        FF_GetMsg(&msg[0], MsgId);
677
        FF_GetMsg(&msg[0], MsgId);
699
        return alertuser(&msg[0], more);
678
        return alertuser(&msg[0], more);
700
}
679
}
701
 
680
 
702
Boolean simplealert_id(int MsgId) {
681
Boolean simplealert_id(int MsgId) {
703
        TCHAR msg[1000];
682
        TCHAR msg[1000];
704
        FF_GetMsg(&msg[0], MsgId);
683
        FF_GetMsg(&msg[0], MsgId);
705
        return simplealert(&msg[0]);
684
        return simplealert(&msg[0]);
706
}
685
}
707
 
686
 
708
Boolean simplewarning_id(int MsgId) {
687
Boolean simplewarning_id(int MsgId) {
709
        TCHAR msg[1000];
688
        TCHAR msg[1000];
710
        FF_GetMsg(&msg[0], MsgId);
689
        FF_GetMsg(&msg[0], MsgId);
711
        return simplewarning(&msg[0]);
690
        return simplewarning(&msg[0]);
712
}
691
}
713
 
692
 
714
Boolean showmessage_id(int MsgId) {
693
Boolean showmessage_id(int MsgId) {
715
        TCHAR msg[1000];
694
        TCHAR msg[1000];
716
        FF_GetMsg(&msg[0], MsgId);
695
        FF_GetMsg(&msg[0], MsgId);
717
        return showmessage(&msg[0]);
696
        return showmessage(&msg[0]);
718
}
697
}
719
 
698