Subversion Repositories filter_foundry

Rev

Rev 511 | Rev 537 | 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 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)")); tmp1++;
  382.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.afs;*.8bf;*.pff;*.prm;*.bin;*.rsrc;*.txt;*.ffx")); 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_ALL_FILES_ID);
  413.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.*)")); tmp1++;
  414.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.*")); tmp1++;
  415.  
  416.                 loadDlgRet = !gdata->standalone && choosefiletypes(
  417. #ifdef MAC_ENV
  418.                         "\pChoose filter settings", // "\p" means "Pascal string" // TODO (Not important yet): TRANSLATE
  419.                         &sfr, &reply, types, 2,
  420.                         filters
  421. #else
  422.                         title, &sfr, &reply, types, 2,
  423.                         filters, gdata->hWndMainDlg
  424. #endif
  425.                 );
  426.                
  427.                 free(filters);
  428.                 free(title);
  429.  
  430.                 if (loadDlgRet) {
  431.                         // Backup everything, otherwise we might lose parameter data if the loading fails
  432.                         bakState = saveInternalState();
  433.  
  434.                         if (loadfile(&sfr, &reason)) {
  435.                                 updatedialog(dp);
  436.                                 maindlgupdate(dp);
  437.                         }
  438.                         else {
  439.                                 alertuser_id(MSG_CANNOT_LOAD_SETTINGS_ID, reason);
  440.  
  441.                                 // Restore
  442.                                 restoreInternalState(bakState);
  443.                         }
  444.                         if (reason) FF_GetMsg_Free(reason);
  445.                 }
  446.                 break;
  447.         }
  448.         case SAVEITEM:
  449.         {
  450.                 TCHAR* tmp1;
  451.                 TCHAR* filters, *title;
  452.                 Boolean saveDlgRet;
  453.  
  454.                 title = (TCHAR*)malloc(1024);
  455.                 if (title == NULL) return false;
  456.  
  457.                 filters = (TCHAR*)malloc(4096);
  458.                 if (filters == NULL) return false;
  459.                 memset(filters, 0, 4096);
  460.                 tmp1 = filters;
  461.  
  462.                 FF_GetMsg(title, MSG_SAVE_FILTER_SETTINGS_TITLE_ID);
  463.  
  464.                 strcpy_advance_id(&tmp1, MSG_ALL_SUPPORTED_FILES_ID);
  465.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.afs, *.pff, *.txt)")); tmp1++;
  466.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.afs;*.pff;*.txt")); tmp1++;
  467.  
  468.                 strcpy_advance_id(&tmp1, MSG_SAVE_AFS_ID);
  469.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.afs)")); tmp1++;
  470.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.afs")); tmp1++;
  471.  
  472.                 strcpy_advance_id(&tmp1, MSG_SAVE_PFF_ID);
  473.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.pff)")); tmp1++;
  474.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.pff")); tmp1++;
  475.  
  476.                 strcpy_advance_id(&tmp1, MSG_SAVE_TXT_ID);
  477.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.txt)")); tmp1++;
  478.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.txt")); tmp1++;
  479.  
  480.                 strcpy_advance_id(&tmp1, MSG_ALL_FILES_ID);
  481.                 strcpy_advance(&tmp1, (TCHAR*)TEXT(" (*.*)")); tmp1++;
  482.                 strcpy_advance(&tmp1, (TCHAR*)TEXT("*.*")); tmp1++;
  483.  
  484.                 saveDlgRet = !gdata->standalone && putfile(
  485. #ifdef MAC_ENV
  486.                         "\pSave filter settings", // "\p" means "Pascal string" // TODO (Not important yet): TRANSLATE
  487.                         "\0",
  488.                         TEXT_FILETYPE, SIG_SIMPLETEXT, &reply, &sfr,
  489.                         "afs",
  490.                         filters, 1
  491. #else
  492.                         title,
  493.                         TEXT("\0"),
  494.                         TEXT_FILETYPE, SIG_SIMPLETEXT, &reply, &sfr,
  495.                         TEXT("afs"),
  496.                         filters, 1, gdata->hWndMainDlg
  497. #endif
  498.                 );
  499.                
  500.                 free(filters);
  501.                 free(title);
  502.  
  503.                 if (saveDlgRet) {
  504.                         if (savefile_afs_pff_picotxt(&sfr)) {
  505.                                 completesave(&reply);
  506.  
  507.                                 if (fileHasExtension(&sfr, TEXT(".txt"))) {
  508.                                         showmessage_id(MSG_PICO_SAVED_ID);
  509.  
  510.                                         #ifdef MAC_ENV
  511.                                         // TODO: Open text file instead
  512.                                         showmessage_id(MSG_PLEASE_EDIT_MANUALLY_ID);
  513.                                         #else
  514.                                         hShellRes = ShellExecute(
  515.                                                 gdata->hWndMainDlg,
  516.                                                 TEXT("open"),
  517.                                                 &sfr.sfFile.szName[0],
  518.                                                 NULL,
  519.                                                 NULL,
  520.                                                 SW_SHOWNORMAL
  521.                                         );
  522.                                         if (hShellRes <= (HINSTANCE)32) {
  523.                                                 // MSDN states: "If the function succeeds, it returns a value greater than 32."
  524.  
  525.                                                 TCHAR s[0x300];
  526.                                                 xstrcpy(s, (TCHAR*)TEXT("ShellExecute failed: ")); // TODO (Not so important): TRANSLATE
  527.                                                 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + xstrlen(s), 0x300 - (DWORD)xstrlen(s), NULL);
  528.                                                 simplealert(&s[0]);
  529.  
  530.                                                 showmessage_id(MSG_PLEASE_EDIT_MANUALLY_ID);
  531.                                         }
  532.                                         #endif
  533.                                 }
  534.  
  535.                         }
  536.                 }
  537.  
  538.                 break;
  539.         }
  540.         case MAKEITEM:
  541.                 if (gdata->standalone) return true; // should not happen since the button should be grayed out
  542.  
  543.                 builddialog(gpb);
  544.  
  545.                 break;
  546.         case HELPITEM:
  547.                 #ifdef MAC_ENV
  548.                 // TODO: Open web-browser instead
  549.                 showmessage_id(MSG_FIND_DOKU_HERE_ID);
  550.                 #else
  551.                 hShellRes = ShellExecute(
  552.                         gdata->hWndMainDlg,
  553.                         TEXT("open"),
  554.                         TEXT("https://github.com/danielmarschall/filter_foundry/blob/master/doc/The%20Filter%20Foundry.pdf"),
  555.                         NULL,
  556.                         NULL,
  557.                         SW_SHOWNORMAL
  558.                 );
  559.                 if (hShellRes == (HINSTANCE)ERROR_FILE_NOT_FOUND) {
  560.                         // On Win98 we get ERROR_FILE_NOT_FOUND, but the browser still opens!
  561.                         // So we ignore it for now...
  562.                 }
  563.                 else if (hShellRes <= (HINSTANCE)32) {
  564.                         // MSDN states: "If the function succeeds, it returns a value greater than 32."
  565.  
  566.                         TCHAR s[0x300];
  567.                         xstrcpy(s, (TCHAR*)TEXT("ShellExecute failed: ")); // TODO (Not so important): TRANSLATE
  568.                         FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + xstrlen(s), 0x300 - (DWORD)xstrlen(s), NULL);
  569.                         simplealert(&s[0]);
  570.  
  571.                         showmessage_id(MSG_FIND_DOKU_HERE_ID);
  572.                 }
  573.                 #endif
  574.                 break;
  575.         case ZOOMINITEM:
  576.                 zoomfactor = zoomfactor > 2. ? zoomfactor/2. : 1.;
  577.                 updatezoom(dp);
  578.                 previewerr = false;
  579.                 recalc_preview(gpb,dp);
  580.                 break;
  581.         case ZOOMOUTITEM:
  582.                 zoomfactor *= 2.;
  583.                 if(zoomfactor > fitzoom)
  584.                         zoomfactor = fitzoom;
  585.                 updatezoom(dp);
  586.                 previewerr = false;
  587.                 recalc_preview(gpb,dp);
  588.                 break;
  589.         case ZOOMLEVELITEM:
  590.                 zoomfactor = zoomfactor > 1. ? 1. : (fitzoom < 1. ? 1. : fitzoom);
  591.                 updatezoom(dp);
  592.                 previewerr = false;
  593.                 recalc_preview(gpb,dp);
  594.                 break;
  595.         case FIRSTCTLITEM:
  596.         case FIRSTCTLITEM+1:
  597.         case FIRSTCTLITEM+2:
  598.         case FIRSTCTLITEM+3:
  599.         case FIRSTCTLITEM+4:
  600.         case FIRSTCTLITEM+5:
  601.         case FIRSTCTLITEM+6:
  602.         case FIRSTCTLITEM+7:
  603.                 slidermoved(dp,item);
  604.                 recalc_preview(gpb,dp);
  605.                 break;
  606.         case FIRSTCTLTEXTITEM:
  607.         case FIRSTCTLTEXTITEM+1:
  608.         case FIRSTCTLTEXTITEM+2:
  609.         case FIRSTCTLTEXTITEM+3:
  610.         case FIRSTCTLTEXTITEM+4:
  611.         case FIRSTCTLTEXTITEM+5:
  612.         case FIRSTCTLTEXTITEM+6:
  613.         case FIRSTCTLTEXTITEM+7:
  614.                 slidertextchanged(dp,item);
  615.                 recalc_preview(gpb,dp);
  616.                 break;
  617.         case FIRSTICONITEM:
  618.         case FIRSTICONITEM+1:
  619.         case FIRSTICONITEM+2:
  620.         case FIRSTICONITEM+3:
  621.                 item -= FIRSTICONITEM;
  622.                 {
  623.                         simplealert(err[item]);
  624.                 }
  625.                 SELECTCTLTEXT(dp,FIRSTEXPRITEM+item,errstart[item],errpos[item]);
  626.                 break;
  627.         case FIRSTEXPRITEM:
  628.         case FIRSTEXPRITEM+1:
  629.         case FIRSTEXPRITEM+2:
  630.         case FIRSTEXPRITEM+3:
  631.                 if((item-FIRSTEXPRITEM) < nplanes){
  632.                         updateexpr(dp,item);
  633.                         maindlgupdate(dp);
  634.                 }
  635.                 break;
  636.         }
  637.  
  638.         return true; // keep going
  639. }
  640.  
  641. Boolean alertuser(TCHAR *err,TCHAR *more){
  642.         TCHAR *s, *q;
  643.         Boolean res;
  644.         size_t i;
  645.  
  646.         if (more == NULL) {
  647.                 return simplealert(err);
  648.         }
  649.  
  650.         s = (TCHAR*)malloc((xstrlen(err) + xstrlen(more) + 3) * sizeof(TCHAR)); // 3=CR+LF+NUL
  651.         if (s == NULL) return false;
  652.        
  653.         q = s;
  654.  
  655.         for (i = 0; i < xstrlen(err); i++) {
  656.                 *q++ = err[i];
  657.         }
  658.  
  659.         #ifdef WIN_ENV
  660.         *q++ = CR;
  661.         #endif
  662.         *q++ = LF;
  663.  
  664.         for (i = 0; i < xstrlen(more); i++) {
  665.                 *q++ = more[i];
  666.         }
  667.  
  668.         *q++ = 0;
  669.  
  670.         res = simplealert(s);
  671.         free(s);
  672.         return res;
  673. }
  674.  
  675. Boolean alertuser_id(int MsgId, TCHAR* more) {
  676.         TCHAR msg[1000];
  677.         FF_GetMsg(&msg[0], MsgId);
  678.         return alertuser(&msg[0], more);
  679. }
  680.  
  681. Boolean simplealert_id(int MsgId) {
  682.         TCHAR msg[1000];
  683.         FF_GetMsg(&msg[0], MsgId);
  684.         return simplealert(&msg[0]);
  685. }
  686.  
  687. Boolean simplewarning_id(int MsgId) {
  688.         TCHAR msg[1000];
  689.         FF_GetMsg(&msg[0], MsgId);
  690.         return simplewarning(&msg[0]);
  691. }
  692.  
  693. Boolean showmessage_id(int MsgId) {
  694.         TCHAR msg[1000];
  695.         FF_GetMsg(&msg[0], MsgId);
  696.         return showmessage(&msg[0]);
  697. }
  698.