Subversion Repositories filter_foundry

Rev

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