Subversion Repositories filter_foundry

Rev

Rev 392 | Rev 456 | 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. #include "compat_string.h"
  25.  
  26. int ctls[8],maps[4];
  27. int checksliders_result;
  28.  
  29. /* one-time initialisation of dialog box */
  30.  
  31. void builddlginit(DIALOGREF dp){
  32.         int i;
  33.         char s[0x100];
  34.  
  35.         if(gdata->parmloaded){
  36.                 SetDlgItemText(dp,CATEGORYITEM, gdata->parm.szCategory);
  37.                 SetDlgItemText(dp,TITLEITEM,    gdata->parm.szTitle);
  38.                 SetDlgItemText(dp,COPYRIGHTITEM,gdata->parm.szCopyright);
  39.                 SetDlgItemText(dp,AUTHORITEM,   gdata->parm.szAuthor);
  40.                 for(i=0;i<4;++i){
  41.                         SetDlgItemText(dp,FIRSTMAPNAMEITEM+i,gdata->parm.szMap[i]);
  42.                 }
  43.                 for(i=0;i<8;++i){
  44.                         SetDlgItemText(dp,FIRSTCTLNAMEITEM+i,gdata->parm.szCtl[i]);
  45.                 }
  46.         }else{
  47.                 /* strictly speaking this is not needed on the Mac,
  48.                    we can set initial values statically in the rez description */
  49.                 SetDlgItemText(dp,CATEGORYITEM, "Filter Foundry");
  50.                 SetDlgItemText(dp,TITLEITEM,    "Untitled");
  51.                 SetDlgItemText(dp,COPYRIGHTITEM,""); //"Filter Foundry Copyright (C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall"
  52.                 SetDlgItemText(dp,AUTHORITEM,   "Anonymous");
  53.                 strcpy(s,"Map X");
  54.                 for(i = 0; i < 4; ++i){
  55.                         s[4] = '0'+i;
  56.                         SetDlgItemText(dp,FIRSTMAPNAMEITEM+i,s);
  57.                 }
  58.                 strcpy(s,"ctl(X)");
  59.                 for(i = 0; i < 8; ++i){
  60.                         s[4] = '0'+i;
  61.                         SetDlgItemText(dp,FIRSTCTLNAMEITEM+i,s);
  62.                 }
  63.         }
  64.  
  65.         checksliders_result = checksliders(4,ctls,maps);
  66.         for(i = 4; i--;){
  67.                 DISABLEDLGITEM(dp,FIRSTMAPCHECKITEM+i);
  68.                 if(maps[i] || (checksliders_result & CHECKSLIDERS_MAP_AMBIGUOUS))
  69.                         CHECKDLGBUTTON(dp,FIRSTMAPCHECKITEM+i,true);
  70.                 else
  71.                         HideDialogItem(dp,FIRSTMAPNAMEITEM+i);
  72.         }
  73.         for(i = 8; i--;){
  74.                 DISABLEDLGITEM(dp,FIRSTCTLCHECKITEM+i);
  75.                 if((ctls[i] || (checksliders_result & CHECKSLIDERS_CTL_AMBIGUOUS)) &&
  76.                    // When map() is activated, we don't need ctl labels,
  77.                    // since the standalone filter will only show map labels
  78.                    !maps[i/2] &&
  79.                    (!(checksliders_result & CHECKSLIDERS_MAP_AMBIGUOUS))
  80.                    )
  81.                         CHECKDLGBUTTON(dp,FIRSTCTLCHECKITEM+i,true);
  82.                 else
  83.                         HideDialogItem(dp,FIRSTCTLNAMEITEM+i);
  84.         }
  85.  
  86.         CHECKDLGBUTTON(dp, PROTECTITEM, 0); // TODO: should we remember the last setting?
  87.  
  88.         SELECTDLGITEMTEXT(dp,TITLEITEM,0,-1);
  89. }
  90.  
  91.  
  92. /* process an item hit. return false if the dialog is finished; otherwise return true. */
  93.  
  94. Boolean builddlgitem(DIALOGREF dp,int item){
  95.         enum{MAXFIELD=0x100};
  96.         char s[MAXFIELD+1];
  97.         int i,needui;
  98.         char fname[256];
  99.         StandardFileReply sfr;
  100.         NavReplyRecord reply;
  101.  
  102.         switch(item){
  103. #ifdef MAC_ENV
  104.         case ok:
  105. #else
  106.         case IDOK:
  107. #endif
  108.                 // Do a few checks first
  109.                 GetDlgItemText(dp, CATEGORYITEM, s, MAXFIELD);
  110.                 if (strlen(s) == 0) {
  111.                         simplealert(_strdup("Category must not be empty!"));
  112.                         return true; // don't continue (i.e. don't call EndDialog). Let the user correct the input
  113.                 }
  114.                 GetDlgItemText(dp, TITLEITEM, s, MAXFIELD);
  115.                 if (strlen(s) == 0) {
  116.                         simplealert(_strdup("Title must not be empty!"));
  117.                         return true; // don't continue (i.e. don't call EndDialog). Let the user correct the input
  118.                 }
  119.  
  120.                 // Now begin
  121.                 memset(&gdata->parm,0,sizeof(PARM_T));
  122.                 GetDlgItemText(dp,CATEGORYITEM,gdata->parm.szCategory,MAXFIELD-4/*ProtectFlag*/);
  123.                 GetDlgItemText(dp,TITLEITEM,gdata->parm.szTitle,MAXFIELD);
  124.                 GetDlgItemText(dp,COPYRIGHTITEM,gdata->parm.szCopyright,MAXFIELD);
  125.                 GetDlgItemText(dp,AUTHORITEM,gdata->parm.szAuthor,MAXFIELD);
  126.                 gdata->parm.cbSize = PARM_SIZE;
  127.                 gdata->parm.standalone = 1;  //0=original FF, 1=standalone filter
  128.                 needui = 0;
  129.                 // Sliders
  130.                 for(i = 0; i < 8; ++i){
  131.                         gdata->parm.val[i] = slider[i];
  132.                         gdata->parm.ctl_used[i] = ctls[i] || (checksliders_result & CHECKSLIDERS_CTL_AMBIGUOUS);
  133.                         needui |= gdata->parm.ctl_used[i];
  134.                         GetDlgItemText(dp,FIRSTCTLNAMEITEM+i, gdata->parm.szCtl[i],MAXFIELD);
  135.                 }
  136.                 // Maps
  137.                 for (i = 0; i < 4; ++i) {
  138.                         gdata->parm.map_used[i] = maps[i] || (checksliders_result & CHECKSLIDERS_MAP_AMBIGUOUS);
  139.                         needui |= gdata->parm.map_used[i];
  140.                         GetDlgItemText(dp, FIRSTMAPNAMEITEM + i, gdata->parm.szMap[i], MAXFIELD);
  141.                 }
  142.                 // Expressions
  143.                 for (i = 0; i < 4; ++i) {
  144.                         if (!expr[i]) {
  145.                                 simplealert(_strdup("Bug! see builddlgitem"));
  146.                                 return true; // keep going. Let the user try again
  147.                         }
  148.                         if (strlen(expr[i]) >= sizeof(gdata->parm.szFormula[i])) {
  149.                                 if (i == 0) {
  150.                                         simplealert(_strdup("Attention! The formula for channel R was too long (longer than 1023 characters) and was truncated."));
  151.                                 }
  152.                                 else if (i == 1) {
  153.                                         simplealert(_strdup("Attention! The formula for channel G was too long (longer than 1023 characters) and was truncated."));
  154.                                 }
  155.                                 else if (i == 2) {
  156.                                         simplealert(_strdup("Attention! The formula for channel B was too long (longer than 1023 characters) and was truncated."));
  157.                                 }
  158.                                 else if (i == 3) {
  159.                                         simplealert(_strdup("Attention! The formula for channel A was too long (longer than 1023 characters) and was truncated."));
  160.                                 }
  161.                                 expr[i][sizeof(gdata->parm.szFormula[i]) - 1] = '\0';
  162.                         }
  163.                         strcpy(gdata->parm.szFormula[i], expr[i]);
  164.                 }
  165.                 gdata->parm.popDialog = needui; //true if need to pop a parameter dialog
  166.                 gdata->parm.unknown1 = gdata->parm.unknown2 = gdata->parm.unknown3 = 0;
  167.                 gdata->parm.iProtected = ISDLGBUTTONCHECKED(dp,PROTECTITEM); // == 1 means protected
  168.                 gdata->obfusc = ISDLGBUTTONCHECKED(dp,PROTECTITEM);
  169.  
  170.                 strcpy(fname, gdata->parm.szTitle);
  171.                 #ifdef MACMACHO
  172.                 strcat(fname, ".plugin");
  173.                 #endif
  174.                 if (putfile(
  175.                         #ifdef MAC_ENV
  176.                         (StringPtr)_strdup("\pMake standalone filter"), // "\p" means "Pascal string"
  177.                         #else
  178.                         (StringPtr)_strdup("\026Make standalone filter"),
  179.                         #endif
  180.                         (StringPtr)myc2pstr(_strdup(fname)),
  181.                         PS_FILTER_FILETYPE, kPhotoshopSignature, &reply, &sfr,
  182.                         "8bf", "Filter plugin file (.8bf)\0*.8bf\0\0", 1
  183.                         #ifdef _WIN32
  184.                         , (HWND)dp
  185.                         #endif /* _WIN32 */
  186.                 )) {
  187.                         make_standalone(&sfr);
  188.                 }
  189.                 else {
  190.                         return true; // keep going. Let the user correct their input
  191.                 }
  192.  
  193.                 return false; // end dialog
  194. #ifdef MAC_ENV
  195.         case cancel:
  196. #else
  197.         case IDCANCEL:
  198. #endif
  199.                 return false; // end dialog
  200.         case PROTECTITEM:
  201.                 CHECKDLGBUTTON(dp, item, ISDLGBUTTONCHECKED(dp,item) ^ 1);
  202.                 break;
  203.         }
  204.  
  205.         return true; // keep going
  206. }
  207.