Subversion Repositories filter_foundry

Rev

Rev 510 | Rev 512 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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