Subversion Repositories filter_foundry

Rev

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