Subversion Repositories filter_foundry

Rev

Rev 433 | Rev 445 | 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-2021 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.         i -= FIRSTCTLITEM;
  194.         slider[i] = v;
  195.         SETCTLTEXTINT(dp,i+FIRSTCTLTEXTITEM,v,false);
  196. }
  197.  
  198. void slidertextchanged(DIALOGREF dp,int i){
  199.         int v = GETCTLTEXTINT(dp,i,NULL,false);
  200.         i -= FIRSTCTLTEXTITEM;
  201.         SETSLIDERVALUE(dp,i+FIRSTCTLITEM,v);
  202.         slider[i] = v;
  203. }
  204.  
  205. void maindlgupdate(DIALOGREF dp){
  206.         int i,unknown,ctls[8],maps[4];
  207.  
  208.         unknown = checksliders(nplanes,ctls,maps);
  209.  
  210.         for(i = 0; i < 8; i++)
  211.                 if(unknown || ctls[i]){
  212.                         ENABLEDLGITEM(dp,FIRSTCTLITEM+i); // TODO: slider is still shown as disabled
  213.                         REPAINTCTL(dp, FIRSTCTLITEM + i); // required for PLUGIN.DLL sliders
  214.                         ENABLEDLGITEM(dp,FIRSTCTLLABELITEM+i);
  215.                         ShowDialogItem(dp,FIRSTCTLTEXTITEM+i); /* FIXME: this changes keyboard focus */
  216.                 }else{
  217.                         DISABLEDLGITEM(dp,FIRSTCTLITEM+i);
  218.                         REPAINTCTL(dp,FIRSTCTLITEM+i); // required for PLUGIN.DLL sliders
  219.                         DISABLEDLGITEM(dp,FIRSTCTLLABELITEM+i);
  220.                         HideDialogItem(dp,FIRSTCTLTEXTITEM+i); /* FIXME: this changes keyboard focus */
  221.                 }
  222.  
  223.         for(i = 0; i < nplanes; i++)
  224.                 if(!tree[i]){
  225.                         /* uh oh, couldn't parse one of the saved expressions...this is fatal */
  226.                         DISABLEDLGITEM(dp,IDOK);
  227.                         if(gdata->standalone){
  228.                                 alertuser((TCHAR*)TEXT("Can't run this filter (there is a problem with the saved expressions)."), (TCHAR*)TEXT(""));
  229.                         }else{
  230.                                 DISABLEDLGITEM(dp,SAVEITEM);
  231.                                 DISABLEDLGITEM(dp,MAKEITEM);
  232.                         }
  233.                         return;
  234.                 }
  235.  
  236.         /* we have valid expression trees in all slots...proceed! */
  237.         updateglobals(dp);
  238.         if(setup(gpb))
  239.                 recalc_preview(gpb,dp);
  240.  
  241.         ENABLEDLGITEM(dp,IDOK);
  242.         if(!gdata->standalone){
  243.                 ENABLEDLGITEM(dp,SAVEITEM);
  244.                 ENABLEDLGITEM(dp,MAKEITEM);
  245.                 ENABLEDLGITEM(dp,HELPITEM);
  246.         }
  247. }
  248.  
  249. /* one-time initialisation of dialog box */
  250.  
  251. void maindlginit(DIALOGREF dp){
  252.         char s[0x100];
  253.         int i;
  254.         const char *channelsuffixes[] = {
  255.                 "", "KA", "I", "RGBA",
  256.                 "CMYK", "HSL", "HSB", "1234",
  257.                 "DA", "LabA"
  258.         };
  259.  
  260.         /* hide unused expression items */
  261.         if(gdata->standalone){
  262.                 SetDlgItemTextA(dp,PARAMAUTHORITEM,gdata->parm.szAuthor);
  263.                 SetDlgItemTextA(dp,PARAMCOPYITEM,gdata->parm.szCopyright);
  264.  
  265.                 // update labels for map() or ctl() sliders
  266.                 for(i = 0; i < 8; ++i){
  267.                         if(gdata->parm.map_used[i/2]){
  268.                                 if((i&1) == 0){
  269.                                         // even (0, 2, 4, 6)
  270.                                         strcpy(s,gdata->parm.szMap[i/2]);
  271.                                         SetDlgItemTextA(dp, FIRSTMAPLABELITEM+(i/2),s);
  272.                                         HideDialogItem(dp, FIRSTCTLLABELITEM + i);
  273.                                         HideDialogItem(dp, FIRSTCTLLABELITEM + i + 1);
  274.                                 }
  275.                         } else if(gdata->parm.ctl_used[i]){
  276.                                 strcpy(s,gdata->parm.szCtl[i]);
  277.                                 SetDlgItemTextA(dp, FIRSTCTLLABELITEM+i,s);
  278.                                 HideDialogItem(dp, FIRSTMAPLABELITEM + i/2);
  279.                         }else{
  280.                                 HideDialogItem(dp, FIRSTCTLITEM+i);
  281.                                 HideDialogItem(dp, FIRSTCTLTEXTITEM+i);
  282.                                 HideDialogItem(dp, FIRSTCTLLABELITEM + i);
  283.                                 HideDialogItem(dp, FIRSTMAPLABELITEM + i/2);
  284.                         }
  285.                 }
  286.         }
  287.  
  288.         strcpy(s,"X =");
  289.         for(i = 0; i < 4; ++i){
  290.                 if(i >= nplanes){
  291.                         HideDialogItem(dp,FIRSTICONITEM+i);
  292.                         HideDialogItem(dp,FIRSTEXPRITEM+i);
  293.                         HideDialogItem(dp,FIRSTLABELITEM+i);
  294.                 }else{
  295.                         s[0] = channelsuffixes[gpb->imageMode][i];
  296.                         SetDlgItemTextA(dp,FIRSTLABELITEM+i,s);
  297.                 }
  298.         }
  299.  
  300.         if(setup_preview(gpb,nplanes)){
  301.                 // On very large images, processing a fully zoomed out preview (the initial default)
  302.                 // can cause out of memory errors, because Photoshop can't page in all data
  303.                 // during advanceState. To prevent this problem, zoom in until we aren't
  304.                 // previewing more than say 10% of Photoshop's indicated maxSpace.
  305.                 // (e.g., on a 1GB WinXP system, PS CS2 reports 520MB maxSpace, so this will let us
  306.                 // preview about 50MB of image data.)
  307.  
  308.                 /* Workaround: GIMP/PSPI sets maxSpace to 100 MB hardcoded, so the zoom is not adjusted correctly. */
  309.                 int disable_zoom_memory_check;
  310.                 disable_zoom_memory_check = !maxspace_available();
  311.  
  312.                 if (!disable_zoom_memory_check) {
  313.                         zoomfactor = sqrt(maxspace()/(10.*preview_w*preview_h*nplanes));
  314.                         if(zoomfactor > fitzoom)
  315.                                 zoomfactor = fitzoom;
  316.                         if(zoomfactor < 1.)
  317.                                 zoomfactor = 1.;
  318.                 } else {
  319.                         zoomfactor = fitzoom;
  320.                 }
  321.  
  322.                 updatezoom(dp);
  323.         }else{
  324.                 DISABLEDLGITEM(dp, ZOOMINITEM);    // HideDialogItem(dp,ZOOMINITEM);
  325.                 DISABLEDLGITEM(dp, ZOOMOUTITEM);   // HideDialogItem(dp,ZOOMOUTITEM);
  326.                 DISABLEDLGITEM(dp, ZOOMLEVELITEM); // HideDialogItem(dp,ZOOMLEVELITEM);
  327.         }
  328.  
  329.         updatedialog(dp);
  330.         maindlgupdate(dp);
  331. }
  332.  
  333.  
  334. /* process an item hit. return false if the dialog is finished; otherwise return true. */
  335.  
  336. Boolean maindlgitem(DIALOGREF dp,int item){
  337.         extern int previewerr;
  338.  
  339.         StandardFileReply sfr;
  340.         NavReplyRecord reply;
  341.         static OSType types[] = {TEXT_FILETYPE,PS_FILTER_FILETYPE};
  342.         char *reason;
  343.         HINSTANCE hShellRes;
  344.         InternalState bakState;
  345.  
  346.         switch(item){
  347. #ifdef MAC_ENV
  348.         case ok:
  349.         case cancel:
  350. #else
  351.         case IDOK:
  352.         case IDCANCEL:
  353. #endif
  354.                 dispose_preview();
  355.                 return false; // end dialog
  356.         case OPENITEM:
  357.                 if(!gdata->standalone && choosefiletypes(
  358.                         #ifdef MAC_ENV
  359.                         (StringPtr)_strdup("\pChoose filter settings"), // "\p" means "Pascal string"
  360.                         & sfr, & reply, types, 2,
  361.                         "All supported files (*.afs, *.8bf, *.pff, *.prm, *.bin, *.rsrc, *.txt, *.ffx)\0*.afs;*.8bf;*.pff;*.prm;*.bin;*.rsrc;*.txt;*.ffx\0Filter Factory Settings (*.afs, *.txt)\0*.afs;*.txt\0PluginCommander or FFDecomp TXT file (*.txt)\0*.txt\0Filter Factory for Windows, Standalone Filter (*.8bf)\0*.8bf\0Premiere TF/FF Settings (*.pff)\0*.pff\0Premiere TT/FF for Windows, Standalone Filter (*.prm)\0*.prm\0FilterFactory for MacOS, Standalone Filter (*.bin, *.rsrc)\0*.bin\0\"Filters Unlimited\" filter (*.ffx)\0*.ffx\0All files (*.*)\0*.*\0\0"
  362.                         #else
  363.                         TEXT("Choose filter settings"),
  364.                         & sfr, & reply, types, 2,
  365.                         TEXT("All supported files (*.afs, *.8bf, *.pff, *.prm, *.bin, *.rsrc, *.txt, *.ffx)\0*.afs;*.8bf;*.pff;*.prm;*.bin;*.rsrc;*.txt;*.ffx\0Filter Factory Settings (*.afs, *.txt)\0*.afs;*.txt\0PluginCommander or FFDecomp TXT file (*.txt)\0*.txt\0Filter Factory for Windows, Standalone Filter (*.8bf)\0*.8bf\0Premiere TF/FF Settings (*.pff)\0*.pff\0Premiere TT/FF for Windows, Standalone Filter (*.prm)\0*.prm\0FilterFactory for MacOS, Standalone Filter (*.bin, *.rsrc)\0*.bin\0\"Filters Unlimited\" filter (*.ffx)\0*.ffx\0All files (*.*)\0*.*\0\0")
  366.                         ,gdata->hWndMainDlg
  367.                         #endif
  368.                 )){
  369.                         // Backup everything, otherwise we might lose parameter data if the loading fails
  370.                         bakState = saveInternalState();
  371.  
  372.                         if (loadfile(&sfr,&reason)) {
  373.                                 updatedialog(dp);
  374.                                 maindlgupdate(dp);
  375.                         }
  376.                         else {
  377.                                 #ifdef UNICODE
  378.                                 TCHAR reasonW[0x300];
  379.                                 mbstowcs(reasonW, reason, 0x300);
  380.                                 alertuser((TCHAR*)TEXT("Could not load settings."), reasonW);
  381.                                 #else
  382.                                 alertuser((TCHAR*)TEXT("Could not load settings."), reason);
  383.                                 #endif
  384.  
  385.                                 // Restore
  386.                                 restoreInternalState(bakState);
  387.                         }
  388.                 }
  389.                 break;
  390.         case SAVEITEM:
  391.                 if(!gdata->standalone && putfile(
  392.                         #ifdef MAC_ENV
  393.                         (StringPtr)_strdup("\pSave filter settings"), // "\p" means "Pascal string"
  394.                         (StringPtr)_strdup("\0"),
  395.                         TEXT_FILETYPE, SIG_SIMPLETEXT, & reply, & sfr,
  396.                         "afs",
  397.                         "All supported files (.afs, *.pff, .txt)\0*.afs;*.pff;*.txt\0Filter Factory Settings (*.afs)\0*.afs\0Premiere TF/FF Settings (*.pff)\0*.pff\0PluginCommander TXT file (*.txt)\0*.txt\0All files (*.*)\0*.*\0\0", 1
  398.                         #else
  399.                         TEXT("Save filter settings"),
  400.                         TEXT("\0"),
  401.                         TEXT_FILETYPE, SIG_SIMPLETEXT, & reply, & sfr,
  402.                         TEXT("afs"),
  403.                         TEXT("All supported files (.afs, *.pff, .txt)\0*.afs;*.pff;*.txt\0Filter Factory Settings (*.afs)\0*.afs\0Premiere TF/FF Settings (*.pff)\0*.pff\0PluginCommander TXT file (*.txt)\0*.txt\0All files (*.*)\0*.*\0\0"), 1
  404.                         ,gdata->hWndMainDlg
  405.                         #endif
  406.                 )){
  407.                         if(savefile_afs_pff_picotxt(&sfr)) {
  408.                                 completesave(&reply);
  409.  
  410.                                 if (fileHasExtension(&sfr, TEXT(".txt"))) {
  411.                                         showmessage((TCHAR*)TEXT("The file was successfully saved in the \"PluginCommander\" TXT format. The file will now be opened in a text editor, so that you can fill in the missing data: Category, Title, Copyright, Author, Filename, Slider/Map names."));
  412.  
  413.                                         #ifdef MAC_ENV
  414.                                         // TODO: Open text file instead
  415.                                         showmessage((TCHAR*)TEXT("Please edit the file manually to enter the title, category, authorname, copyright, slidernames etc."));
  416.                                         #else
  417.                                         hShellRes = ShellExecute(
  418.                                                 gdata->hWndMainDlg,
  419.                                                 TEXT("open"),
  420.                                                 &sfr.sfFile.szName[0],
  421.                                                 NULL,
  422.                                                 NULL,
  423.                                                 SW_SHOWNORMAL
  424.                                         );
  425.                                         if (hShellRes <= (HINSTANCE)32) {
  426.                                                 // MSDN states: "If the function succeeds, it returns a value greater than 32."
  427.  
  428.                                                 TCHAR s[0x300];
  429.                                                 xstrcpy(s, (TCHAR*)TEXT("ShellExecuteA failed: "));
  430.                                                 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + xstrlen(s), 0x300 - xstrlen(s), NULL);
  431.                                                 dbg(&s[0]);
  432.  
  433.                                                 showmessage((TCHAR*)TEXT("Please edit the file manually to enter the title, category, author, copyright, filename, slidernames etc."));
  434.                                         }
  435.                                         #endif
  436.                                 }
  437.  
  438.                         }
  439.                 }
  440.                 break;
  441.         case MAKEITEM:
  442.                 if (gdata->standalone) return true; // should not happen since the button should be grayed out
  443.  
  444.                 builddialog(gpb);
  445.  
  446.                 break;
  447.         case HELPITEM:
  448.                 #ifdef MAC_ENV
  449.                 // TODO: Open web-browser instead
  450.                 showmessage((TCHAR*)TEXT("You can find the documentation here: https://github.com/danielmarschall/filter_foundry/tree/master/doc"));
  451.                 #else
  452.                 hShellRes = ShellExecute(
  453.                         gdata->hWndMainDlg,
  454.                         TEXT("open"),
  455.                         TEXT("https://github.com/danielmarschall/filter_foundry/blob/master/doc/The%20Filter%20Foundry.pdf"),
  456.                         NULL,
  457.                         NULL,
  458.                         SW_SHOWNORMAL
  459.                 );
  460.                 if (hShellRes == (HINSTANCE)ERROR_FILE_NOT_FOUND) {
  461.                         // On Win98 we get ERROR_FILE_NOT_FOUND, but the browser still opens!
  462.                         // So we ignore it for now...
  463.                 }
  464.                 else if (hShellRes <= (HINSTANCE)32) {
  465.                         // MSDN states: "If the function succeeds, it returns a value greater than 32."
  466.  
  467.                         TCHAR s[0x300];
  468.                         xstrcpy(s, (TCHAR*)TEXT("ShellExecute failed: "));
  469.                         FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + xstrlen(s), 0x300 - xstrlen(s), NULL);
  470.                         dbg(&s[0]);
  471.  
  472.                         showmessage((TCHAR*)TEXT("You can find the documentation here: https://github.com/danielmarschall/filter_foundry/tree/master/doc"));
  473.                 }
  474.                 #endif
  475.                 break;
  476.         case ZOOMINITEM:
  477.                 zoomfactor = zoomfactor > 2. ? zoomfactor/2. : 1.;
  478.                 updatezoom(dp);
  479.                 previewerr = false;
  480.                 recalc_preview(gpb,dp);
  481.                 break;
  482.         case ZOOMOUTITEM:
  483.                 zoomfactor *= 2.;
  484.                 if(zoomfactor > fitzoom)
  485.                         zoomfactor = fitzoom;
  486.                 updatezoom(dp);
  487.                 previewerr = false;
  488.                 recalc_preview(gpb,dp);
  489.                 break;
  490.         case ZOOMLEVELITEM:
  491.                 zoomfactor = zoomfactor > 1. ? 1. : (fitzoom < 1. ? 1. : fitzoom);
  492.                 updatezoom(dp);
  493.                 previewerr = false;
  494.                 recalc_preview(gpb,dp);
  495.                 break;
  496.         case FIRSTCTLITEM:
  497.         case FIRSTCTLITEM+1:
  498.         case FIRSTCTLITEM+2:
  499.         case FIRSTCTLITEM+3:
  500.         case FIRSTCTLITEM+4:
  501.         case FIRSTCTLITEM+5:
  502.         case FIRSTCTLITEM+6:
  503.         case FIRSTCTLITEM+7:
  504.                 slidermoved(dp,item);
  505.                 recalc_preview(gpb,dp);
  506.                 break;
  507.         case FIRSTCTLTEXTITEM:
  508.         case FIRSTCTLTEXTITEM+1:
  509.         case FIRSTCTLTEXTITEM+2:
  510.         case FIRSTCTLTEXTITEM+3:
  511.         case FIRSTCTLTEXTITEM+4:
  512.         case FIRSTCTLTEXTITEM+5:
  513.         case FIRSTCTLTEXTITEM+6:
  514.         case FIRSTCTLTEXTITEM+7:
  515.                 slidertextchanged(dp,item);
  516.                 recalc_preview(gpb,dp);
  517.                 break;
  518.         case FIRSTICONITEM:
  519.         case FIRSTICONITEM+1:
  520.         case FIRSTICONITEM+2:
  521.         case FIRSTICONITEM+3:
  522.                 item -= FIRSTICONITEM;
  523.                 {
  524.                         #ifdef UNICODE
  525.                         TCHAR errW[0x300];
  526.                         mbstowcs(errW, err[item], 0x300);
  527.                         alertuser(errW, (TCHAR*)TEXT(""));
  528.                         #else
  529.                         alertuser(err[item], (TCHAR*)TEXT(""));
  530.                         #endif
  531.                 }
  532.                 SELECTCTLTEXT(dp,FIRSTEXPRITEM+item,errstart[item],errpos[item]);
  533.                 break;
  534.         case FIRSTEXPRITEM:
  535.         case FIRSTEXPRITEM+1:
  536.         case FIRSTEXPRITEM+2:
  537.         case FIRSTEXPRITEM+3:
  538.                 if((item-FIRSTEXPRITEM) < nplanes){
  539.                         updateexpr(dp,item);
  540.                         maindlgupdate(dp);
  541.                 }
  542.                 break;
  543.         }
  544.  
  545.         return true; // keep going
  546. }
  547.  
  548. Boolean alertuser(TCHAR *err,TCHAR *more){
  549.         TCHAR *s = (TCHAR*)malloc((xstrlen(err)+xstrlen(more)+2)*sizeof(TCHAR)), *q;
  550.         Boolean res;
  551.  
  552.         q = xstrcat(s,err);
  553.         *q++ = LF;
  554.         q = xstrcat(q,more);
  555.         *q = 0;
  556.         res = simplealert(s);
  557.         free(s);
  558.         return res;
  559. }
  560.