Subversion Repositories filter_foundry

Rev

Rev 536 | Rev 544 | 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.net
  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 maindlginit(DIALOGREF dp){
  258.         char s[0x100];
  259.         int i;
  260.         const char *channelsuffixes[] = {
  261.                 "", "KA", "I", "RGBA",
  262.                 "CMYK", "HSL", "HSB", "1234",
  263.                 "DA", "LabA"
  264.         };
  265.  
  266.         /* hide unused expression items */
  267.         if(gdata->standalone){
  268.                 strcpy_win_replace_ampersand(&s[0], &gdata->parm.szAuthor[0]);
  269.                 SETCTLTEXT(dp,PARAMAUTHORITEM,s);
  270.                 strcpy_win_replace_ampersand(&s[0], &gdata->parm.szCopyright[0]);
  271.                 SETCTLTEXT(dp,PARAMCOPYITEM,s);
  272.  
  273.                 // update labels for map() or ctl() sliders
  274.                 for(i = 0; i < 8; ++i){
  275.                         if(gdata->parm.map_used[i/2]) {
  276.                                 if((i&1) == 0){
  277.                                         // even (0, 2, 4, 6)
  278.                                         strcpy_win_replace_ampersand(&s[0], &gdata->parm.szMap[i/2][0]);
  279.                                         SETCTLTEXT(dp, FIRSTMAPLABELITEM + (i/2),s);
  280.                                         HideDialogItem(dp, FIRSTCTLLABELITEM + i);
  281.                                         HideDialogItem(dp, FIRSTCTLLABELITEM + i + 1);
  282.                                 }
  283.                         } else if(gdata->parm.ctl_used[i]) {
  284.                                 strcpy_win_replace_ampersand(&s[0], &gdata->parm.szCtl[i][0]);
  285.                                 SETCTLTEXT(dp, FIRSTCTLLABELITEM+i,s);
  286.                                 HideDialogItem(dp, FIRSTMAPLABELITEM + i/2);
  287.                         } else {
  288.                                 HideDialogItem(dp, FIRSTCTLITEM + i);
  289.                                 HideDialogItem(dp, FIRSTCTLTEXTITEM + i);
  290.                                 HideDialogItem(dp, FIRSTCTLLABELITEM + i);
  291.                                 HideDialogItem(dp, FIRSTMAPLABELITEM + i/2);
  292.                         }
  293.                 }
  294.         }
  295.  
  296.         strcpy(s,"X =");
  297.         for(i = 0; i < 4; ++i){
  298.                 if(i >= nplanes){
  299.                         HideDialogItem(dp,FIRSTICONITEM+i);
  300.                         HideDialogItem(dp,FIRSTEXPRITEM+i);
  301.                         HideDialogItem(dp,FIRSTLABELITEM+i);
  302.                 }else{
  303.                         s[0] = channelsuffixes[gpb->imageMode][i];
  304.                         SETCTLTEXT(dp,FIRSTLABELITEM+i,s);
  305.                 }
  306.         }
  307.  
  308.         if(setup_preview(gpb,nplanes)){
  309.                 // On very large images, processing a fully zoomed out preview (the initial default)
  310.                 // can cause out of memory errors, because Photoshop can't page in all data
  311.                 // during advanceState. To prevent this problem, zoom in until we aren't
  312.                 // previewing more than say 10% of Photoshop's indicated maxSpace.
  313.                 // (e.g., on a 1GB WinXP system, PS CS2 reports 520MB maxSpace, so this will let us
  314.                 // preview about 50MB of image data.)
  315.  
  316.                 /* Workaround: GIMP/PSPI sets maxSpace to 100 MB hardcoded, so the zoom is not adjusted correctly. */
  317.                 int disable_zoom_memory_check;
  318.                 disable_zoom_memory_check = !maxspace_available();
  319.  
  320.                 if (!disable_zoom_memory_check) {
  321.                         zoomfactor = sqrt(maxspace()/(10.*preview_w*preview_h*nplanes));
  322.                         if(zoomfactor > fitzoom)
  323.                                 zoomfactor = fitzoom;
  324.                         if(zoomfactor < 1.)
  325.                                 zoomfactor = 1.;
  326.                 } else {
  327.                         zoomfactor = fitzoom;
  328.                 }
  329.  
  330.                 updatezoom(dp);
  331.         }else{
  332.                 DISABLEDLGITEM(dp, ZOOMINITEM);    // HideDialogItem(dp,ZOOMINITEM);
  333.                 DISABLEDLGITEM(dp, ZOOMOUTITEM);   // HideDialogItem(dp,ZOOMOUTITEM);
  334.                 DISABLEDLGITEM(dp, ZOOMLEVELITEM); // HideDialogItem(dp,ZOOMLEVELITEM);
  335.         }
  336.  
  337.         updatedialog(dp);
  338.         maindlgupdate(dp);
  339. }
  340.  
  341.  
  342. /* process an item hit. return false if the dialog is finished; otherwise return true. */
  343.  
  344. Boolean maindlgitem(DIALOGREF dp,int item){
  345.         extern int previewerr;
  346.  
  347.         StandardFileReply sfr;
  348.         NavReplyRecord reply;
  349.         static OSType types[] = {TEXT_FILETYPE,PS_FILTER_FILETYPE};
  350.         TCHAR*reason = NULL;
  351.         HINSTANCE hShellRes;
  352.         InternalState bakState;
  353.  
  354.         switch(item){
  355. #ifdef MAC_ENV
  356.         case ok:
  357.         case cancel:
  358. #else
  359.         case IDOK:
  360.         case IDCANCEL:
  361. #endif
  362.                 dispose_preview();
  363.                 return false; // end dialog
  364.         case OPENITEM:
  365.         {
  366.                 TCHAR* tmp1;
  367.                 TCHAR* filters, *title;
  368.                 Boolean loadDlgRet;
  369.  
  370.                 title = (TCHAR*)malloc(1024);
  371.                 if (title == NULL) return false;
  372.  
  373.                 filters = (TCHAR*)malloc(4096);
  374.                 if (filters == NULL) return false;
  375.                 memset(filters, 0, 4096);
  376.                 tmp1 = filters;
  377.  
  378.                 FF_GetMsg(title, MSG_LOAD_FILTER_SETTINGS_TITLE_ID);
  379.  
  380.                 strcpy_advance_id(&tmp1, MSG_ALL_SUPPORTED_FILES_ID);
  381.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.afs, *.8bf, *.pff, *.prm, *.bin, *.rsrc, *.txt, *.ffx, *.guf)")); tmp1++;
  382.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.afs;*.8bf;*.pff;*.prm;*.bin;*.rsrc;*.txt;*.ffx;*.guf")); tmp1++;
  383.  
  384.                 strcpy_advance_id(&tmp1, MSG_OPEN_AFS_ID);
  385.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.afs)")); tmp1++;
  386.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.afs")); tmp1++;
  387.  
  388.                 strcpy_advance_id(&tmp1, MSG_OPEN_TXT_ID);
  389.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.txt)")); tmp1++;
  390.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.txt")); tmp1++;
  391.  
  392.                 strcpy_advance_id(&tmp1, MSG_OPEN_8BF_ID);
  393.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.8bf)")); tmp1++;
  394.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.8bf")); tmp1++;
  395.  
  396.                 strcpy_advance_id(&tmp1, MSG_OPEN_PFF_ID);
  397.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.pff)")); tmp1++;
  398.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.pff")); tmp1++;
  399.  
  400.                 strcpy_advance_id(&tmp1, MSG_OPEN_PRM_ID);
  401.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.prm)")); tmp1++;
  402.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.prm")); tmp1++;
  403.  
  404.                 strcpy_advance_id(&tmp1, MSG_OPEN_RSRC_ID);
  405.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.bin, *.rsrc)")); tmp1++;
  406.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.bin;*.rsrc")); tmp1++;
  407.  
  408.                 strcpy_advance_id(&tmp1, MSG_OPEN_FFX_ID);
  409.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.ffx)")); tmp1++;
  410.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.ffx")); tmp1++;
  411.  
  412.                 strcpy_advance_id(&tmp1, MSG_OPEN_GUF_ID);
  413.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.guf)")); tmp1++;
  414.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.guf")); tmp1++;
  415.  
  416.                 strcpy_advance_id(&tmp1, MSG_ALL_FILES_ID);
  417.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.*)")); tmp1++;
  418.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.*")); tmp1++;
  419.  
  420.                 loadDlgRet = !gdata->standalone && choosefiletypes(
  421. #ifdef MAC_ENV
  422.                         "\pChoose filter settings", // "\p" means "Pascal string" // TODO (Not important yet): TRANSLATE
  423.                         &sfr, &reply, types, 2,
  424.                         filters
  425. #else
  426.                         title, &sfr, &reply, types, 2,
  427.                         filters, gdata->hWndMainDlg
  428. #endif
  429.                 );
  430.  
  431.                 free(filters);
  432.                 free(title);
  433.  
  434.                 if (loadDlgRet) {
  435.                         // Backup everything, otherwise we might lose parameter data if the loading fails
  436.                         bakState = saveInternalState();
  437.  
  438.                         if (loadfile(&sfr, &reason)) {
  439.                                 updatedialog(dp);
  440.                                 maindlgupdate(dp);
  441.                         }
  442.                         else {
  443.                                 alertuser_id(MSG_CANNOT_LOAD_SETTINGS_ID, reason);
  444.  
  445.                                 // Restore
  446.                                 restoreInternalState(bakState);
  447.                         }
  448.                         if (reason) FF_GetMsg_Free(reason);
  449.                 }
  450.                 break;
  451.         }
  452.         case SAVEITEM:
  453.         {
  454.                 TCHAR* tmp1;
  455.                 TCHAR* filters, *title;
  456.                 Boolean saveDlgRet;
  457.  
  458.                 title = (TCHAR*)malloc(1024);
  459.                 if (title == NULL) return false;
  460.  
  461.                 filters = (TCHAR*)malloc(4096);
  462.                 if (filters == NULL) return false;
  463.                 memset(filters, 0, 4096);
  464.                 tmp1 = filters;
  465.  
  466.                 FF_GetMsg(title, MSG_SAVE_FILTER_SETTINGS_TITLE_ID);
  467.  
  468.                 strcpy_advance_id(&tmp1, MSG_ALL_SUPPORTED_FILES_ID);
  469.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.afs, *.pff, *.txt, *.guf)")); tmp1++;
  470.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.afs;*.pff;*.txt;*.guf")); tmp1++;
  471.  
  472.                 strcpy_advance_id(&tmp1, MSG_SAVE_AFS_ID);
  473.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.afs)")); tmp1++;
  474.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.afs")); tmp1++;
  475.  
  476.                 strcpy_advance_id(&tmp1, MSG_SAVE_PFF_ID);
  477.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.pff)")); tmp1++;
  478.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.pff")); tmp1++;
  479.  
  480.                 strcpy_advance_id(&tmp1, MSG_SAVE_TXT_ID);
  481.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.txt)")); tmp1++;
  482.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.txt")); tmp1++;
  483.  
  484.                 strcpy_advance_id(&tmp1, MSG_SAVE_GUF_ID);
  485.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.guf)")); tmp1++;
  486.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.guf")); tmp1++;
  487.  
  488.                 strcpy_advance_id(&tmp1, MSG_ALL_FILES_ID);
  489.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.*)")); tmp1++;
  490.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.*")); tmp1++;
  491.  
  492.                 saveDlgRet = !gdata->standalone && putfile(
  493. #ifdef MAC_ENV
  494.                         "\pSave filter settings", // "\p" means "Pascal string" // TODO (Not important yet): TRANSLATE
  495.                         "\0",
  496.                         TEXT_FILETYPE, SIG_SIMPLETEXT, &reply, &sfr,
  497.                         "afs",
  498.                         filters, 1
  499. #else
  500.                         title,
  501.                         TEXT("\0"),
  502.                         TEXT_FILETYPE, SIG_SIMPLETEXT, &reply, &sfr,
  503.                         TEXT("afs"),
  504.                         filters, 1, gdata->hWndMainDlg
  505. #endif
  506.                 );
  507.  
  508.                 free(filters);
  509.                 free(title);
  510.  
  511.                 if (saveDlgRet) {
  512.                         if (savefile_afs_pff_picotxt_guf(&sfr)) {
  513.                                 completesave(&reply);
  514.  
  515.                                 if (fileHasExtension(&sfr, TEXT(".txt"))) {
  516.                                         showmessage_id(MSG_PICO_SAVED_ID);
  517.  
  518.                                         #ifdef MAC_ENV
  519.                                         // TODO: Open text file instead
  520.                                         showmessage_id(MSG_PLEASE_EDIT_MANUALLY_ID);
  521.                                         #else
  522.                                         hShellRes = ShellExecute(
  523.                                                 gdata->hWndMainDlg,
  524.                                                 TEXT("open"),
  525.                                                 &sfr.sfFile.szName[0],
  526.                                                 NULL,
  527.                                                 NULL,
  528.                                                 SW_SHOWNORMAL
  529.                                         );
  530.                                         if (hShellRes <= (HINSTANCE)32) {
  531.                                                 // MSDN states: "If the function succeeds, it returns a value greater than 32."
  532.  
  533.                                                 TCHAR s[0x300];
  534.                                                 xstrcpy(s, (TCHAR*)TEXT("ShellExecute failed: ")); // TODO (Not so important): TRANSLATE
  535.                                                 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + xstrlen(s), 0x300 - (DWORD)xstrlen(s), NULL);
  536.                                                 simplealert(&s[0]);
  537.  
  538.                                                 showmessage_id(MSG_PLEASE_EDIT_MANUALLY_ID);
  539.                                         }
  540.                                         #endif
  541.                                 }
  542.  
  543.                         }
  544.                 }
  545.  
  546.                 break;
  547.         }
  548.         case MAKEITEM:
  549.                 if (gdata->standalone) return true; // should not happen since the button should be grayed out
  550.  
  551.                 builddialog(gpb);
  552.  
  553.                 break;
  554.         case HELPITEM:
  555.                 #ifdef MAC_ENV
  556.                 // TODO: Open web-browser instead
  557.                 showmessage_id(MSG_FIND_DOKU_HERE_ID);
  558.                 #else
  559.                 hShellRes = ShellExecute(
  560.                         gdata->hWndMainDlg,
  561.                         TEXT("open"),
  562.                         TEXT("https://github.com/danielmarschall/filter_foundry/blob/master/doc/The%20Filter%20Foundry.pdf"),
  563.                         NULL,
  564.                         NULL,
  565.                         SW_SHOWNORMAL
  566.                 );
  567.                 if (hShellRes == (HINSTANCE)ERROR_FILE_NOT_FOUND) {
  568.                         // On Win98 we get ERROR_FILE_NOT_FOUND, but the browser still opens!
  569.                         // So we ignore it for now...
  570.                 }
  571.                 else if (hShellRes <= (HINSTANCE)32) {
  572.                         // MSDN states: "If the function succeeds, it returns a value greater than 32."
  573.  
  574.                         TCHAR s[0x300];
  575.                         xstrcpy(s, (TCHAR*)TEXT("ShellExecute failed: ")); // TODO (Not so important): TRANSLATE
  576.                         FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + xstrlen(s), 0x300 - (DWORD)xstrlen(s), NULL);
  577.                         simplealert(&s[0]);
  578.  
  579.                         showmessage_id(MSG_FIND_DOKU_HERE_ID);
  580.                 }
  581.                 #endif
  582.                 break;
  583.         case ZOOMINITEM:
  584.                 zoomfactor = zoomfactor > 2. ? zoomfactor/2. : 1.;
  585.                 updatezoom(dp);
  586.                 previewerr = false;
  587.                 recalc_preview(gpb,dp);
  588.                 break;
  589.         case ZOOMOUTITEM:
  590.                 zoomfactor *= 2.;
  591.                 if(zoomfactor > fitzoom)
  592.                         zoomfactor = fitzoom;
  593.                 updatezoom(dp);
  594.                 previewerr = false;
  595.                 recalc_preview(gpb,dp);
  596.                 break;
  597.         case ZOOMLEVELITEM:
  598.                 zoomfactor = zoomfactor > 1. ? 1. : (fitzoom < 1. ? 1. : fitzoom);
  599.                 updatezoom(dp);
  600.                 previewerr = false;
  601.                 recalc_preview(gpb,dp);
  602.                 break;
  603.         case FIRSTCTLITEM:
  604.         case FIRSTCTLITEM+1:
  605.         case FIRSTCTLITEM+2:
  606.         case FIRSTCTLITEM+3:
  607.         case FIRSTCTLITEM+4:
  608.         case FIRSTCTLITEM+5:
  609.         case FIRSTCTLITEM+6:
  610.         case FIRSTCTLITEM+7:
  611.                 slidermoved(dp,item);
  612.                 recalc_preview(gpb,dp);
  613.                 break;
  614.         case FIRSTCTLTEXTITEM:
  615.         case FIRSTCTLTEXTITEM+1:
  616.         case FIRSTCTLTEXTITEM+2:
  617.         case FIRSTCTLTEXTITEM+3:
  618.         case FIRSTCTLTEXTITEM+4:
  619.         case FIRSTCTLTEXTITEM+5:
  620.         case FIRSTCTLTEXTITEM+6:
  621.         case FIRSTCTLTEXTITEM+7:
  622.                 slidertextchanged(dp,item);
  623.                 recalc_preview(gpb,dp);
  624.                 break;
  625.         case FIRSTICONITEM:
  626.         case FIRSTICONITEM+1:
  627.         case FIRSTICONITEM+2:
  628.         case FIRSTICONITEM+3:
  629.                 item -= FIRSTICONITEM;
  630.                 {
  631.                         simplealert(err[item]);
  632.                 }
  633.                 SELECTCTLTEXT(dp,FIRSTEXPRITEM+item,errstart[item],errpos[item]);
  634.                 break;
  635.         case FIRSTEXPRITEM:
  636.         case FIRSTEXPRITEM+1:
  637.         case FIRSTEXPRITEM+2:
  638.         case FIRSTEXPRITEM+3:
  639.                 if((item-FIRSTEXPRITEM) < nplanes){
  640.                         updateexpr(dp,item);
  641.                         maindlgupdate(dp);
  642.                 }
  643.                 break;
  644.         }
  645.  
  646.         return true; // keep going
  647. }
  648.  
  649. Boolean alertuser(TCHAR *err,TCHAR *more){
  650.         TCHAR *s, *q;
  651.         Boolean res;
  652.         size_t i;
  653.  
  654.         if (more == NULL) {
  655.                 return simplealert(err);
  656.         }
  657.  
  658.         s = (TCHAR*)malloc((xstrlen(err) + xstrlen(more) + 3) * sizeof(TCHAR)); // 3=CR+LF+NUL
  659.         if (s == NULL) return false;
  660.  
  661.         q = s;
  662.  
  663.         for (i = 0; i < xstrlen(err); i++) {
  664.                 *q++ = err[i];
  665.         }
  666.  
  667.         #ifdef WIN_ENV
  668.         *q++ = CR;
  669.         #endif
  670.         *q++ = LF;
  671.  
  672.         for (i = 0; i < xstrlen(more); i++) {
  673.                 *q++ = more[i];
  674.         }
  675.  
  676.         *q++ = 0;
  677.  
  678.         res = simplealert(s);
  679.         free(s);
  680.         return res;
  681. }
  682.  
  683. Boolean alertuser_id(int MsgId, TCHAR* more) {
  684.         TCHAR msg[1000];
  685.         FF_GetMsg(&msg[0], MsgId);
  686.         return alertuser(&msg[0], more);
  687. }
  688.  
  689. Boolean simplealert_id(int MsgId) {
  690.         TCHAR msg[1000];
  691.         FF_GetMsg(&msg[0], MsgId);
  692.         return simplealert(&msg[0]);
  693. }
  694.  
  695. Boolean simplewarning_id(int MsgId) {
  696.         TCHAR msg[1000];
  697.         FF_GetMsg(&msg[0], MsgId);
  698.         return simplewarning(&msg[0]);
  699. }
  700.  
  701. Boolean showmessage_id(int MsgId) {
  702.         TCHAR msg[1000];
  703.         FF_GetMsg(&msg[0], MsgId);
  704.         return showmessage(&msg[0]);
  705. }
  706.