Subversion Repositories filter_foundry

Rev

Rev 205 | Rev 210 | 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. /* Win32 user interface routines */
  22.  
  23. #include "world.h"
  24.  
  25. #include "PIAbout.h"
  26.  
  27. #include <windows.h>
  28. #include <commctrl.h>
  29.  
  30. #include "ff.h"
  31.  
  32. #include "version.h"
  33.  
  34. HWND preview_hwnd;
  35. HCURSOR hCurHandOpen;
  36. HCURSOR hCurHandGrab;
  37. HCURSOR hCurHandQuestion;
  38.  
  39. extern HINSTANCE hDllInstance;
  40.  
  41. void DoAbout(AboutRecordPtr pb){
  42.         char text[1000];
  43.         char title[200];
  44.         PlatformData *p = (PlatformData*)pb->platformData;
  45.  
  46.         if (gdata && gdata->standalone) {
  47.                 sprintf(title, "About %s", INPLACEP2CSTR(gdata->parm.title));
  48.                 sprintf(text,  "%s by %s\n" /* {Title} by {Author} */
  49.                                "%s\n" /* {Copyright} */
  50.                                "\n"
  51.                                "This plugin was built using Filter Foundry " VERSION_STR "\n"
  52.                                "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
  53.                                "available from http://www.telegraphics.com.au/sw/",
  54.                                INPLACEP2CSTR(gdata->parm.title),
  55.                                INPLACEP2CSTR(gdata->parm.author),
  56.                                INPLACEP2CSTR(gdata->parm.copyright));
  57.         } else {
  58.                 sprintf(title, "About Filter Foundry");
  59.                 sprintf(text,  "Filter Foundry " VERSION_STR "\n"
  60.                                "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
  61.                                "\n"
  62.                                "Latest version available from\n"
  63.                                "\nhttps://github.com/danielmarschall/filter_foundry\n"
  64.                                "Please contact the author with any bug reports,\n"
  65.                                "suggestions or comments.\n"
  66.                                "If you use this program and like it, please consider\n"
  67.                                "making a donation.");
  68.         }
  69.  
  70.         MessageBox((HWND)p->hwnd, text, title, MB_APPLMODAL|MB_ICONINFORMATION|MB_OK);
  71. }
  72.  
  73. Boolean simplealert(char *s){
  74.         char* title;
  75.         if (gdata && gdata->standalone) {
  76.                 title = INPLACEP2CSTR(gdata->parm.title);
  77.         } else {
  78.                 title = _strdup("Filter Foundry");
  79.         }
  80.         return MessageBox(NULL,s,title,MB_TASKMODAL|MB_ICONERROR|MB_OK) == IDOK;
  81. }
  82.  
  83. Boolean showmessage(char *s){
  84.         char* title;
  85.         if (gdata && gdata->standalone) {
  86.                 title = INPLACEP2CSTR(gdata->parm.title);
  87.         } else {
  88.                 title = _strdup("Filter Foundry");
  89.         }
  90.         return MessageBox(NULL,s,title,MB_TASKMODAL|MB_ICONINFORMATION|MB_OK) == IDOK;
  91. }
  92.  
  93. INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
  94.  
  95. INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){
  96.         static POINT origpos;
  97.         static Point origscroll;
  98.         static Boolean panning = false;
  99.  
  100.         int item,i;
  101.         POINT newpos;
  102.         DRAWITEMSTRUCT *pdi;
  103.         Point newscroll;
  104.         HGDIOBJ hfnt;
  105.         char s[0x100];
  106.  
  107.         extern Boolean doupdates;
  108.         extern Handle preview_handle;
  109.  
  110.         switch(wMsg){
  111.         case WM_INITDIALOG:
  112.                 gdata->hWndMainDlg = hDlg;
  113.  
  114.                 if(gdata->standalone){
  115.                         myp2cstrcpy(s,gdata->parm.title);
  116.                         SetWindowText(hDlg,s); // window title bar
  117.                 }
  118.                 centre_window(hDlg);
  119.  
  120.                 hfnt = GetStockObject(ANSI_FIXED_FONT);
  121.  
  122.                 hCurHandOpen = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_OPEN));
  123.                 hCurHandGrab = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_GRAB));
  124.                 hCurHandQuestion = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_QUESTION));
  125.  
  126.                 preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM);
  127.                 GetClientRect(preview_hwnd, &preview_rect);
  128.                 SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen);
  129.  
  130.                 SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion);
  131.  
  132.                 for(i = 0; i < 4; ++i){
  133.                         // If Visual Themes are applied, SS_ICON will be ignored for controls which are not exactly "STATIC" class.
  134.                         // Our derivated "CautionSign" class won't work. So we need to set the icon explicitly.
  135.                         SendDlgItemMessage(hDlg, FIRSTICONITEM+i, STM_SETICON, (WPARAM)LoadImage(hDllInstance, "CAUTION_ICO",IMAGE_ICON,16,16, LR_DEFAULTCOLOR), 0);
  136.                 }
  137.  
  138.                 for(i = 0; i < 8; ++i){
  139.                         SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETRANGE,TRUE,MAKELONG(0,255));
  140.                         SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETTICFREQ,SLIDERPAGE,0);
  141.                         SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETPAGESIZE,0,SLIDERPAGE);
  142.                         SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i,     EM_SETLIMITTEXT,3,0);
  143.                 }
  144.                 for(i = 0; i < 4; ++i){
  145.                         SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        EM_SETLIMITTEXT,MAXEXPR-1,0); // we need 1 byte as NUL terminator, so our formula can be max 1023
  146.                         SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        WM_SETFONT,(WPARAM)hfnt,false);
  147.                 }
  148.  
  149.                 maindlginit(hDlg);
  150.                 break;
  151.         case WM_DESTROY:
  152.                 gdata->hWndMainDlg = 0;
  153.                 DestroyCursor(hCurHandOpen);
  154.                 DestroyCursor(hCurHandGrab);
  155.                 DestroyCursor(hCurHandQuestion);
  156.                 break;
  157.         case WM_DRAWITEM:
  158.                 pdi = (DRAWITEMSTRUCT*)lParam;
  159.                 if(pdi->itemAction == ODA_DRAWENTIRE){
  160.                         switch(pdi->CtlID){
  161.                         case PREVIEWITEM:
  162.                                 drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
  163.                                 PIUNLOCKHANDLE(preview_handle);
  164.                                 break;
  165.                         default:
  166.                                 return false;
  167.                         }
  168.                 }else
  169.                         return false; // we couldn't handle the message
  170.                 break;
  171.         case WM_COMMAND:
  172.                 item = LOWORD(wParam);
  173.                 switch(HIWORD(wParam)){
  174.                 case BN_CLICKED: //case STN_CLICKED:
  175.                         if(item==PREVIEWITEM && GetCursorPos(&origpos)){
  176.                                 panning = true;
  177.                                 origscroll = preview_scroll;
  178.                                 SetCursor(hCurHandGrab);
  179.                                 SetCapture(hDlg);
  180.                                 break;
  181.                         }
  182.                         /* ... falls through ... */
  183.                 case EN_CHANGE:
  184.                         if(doupdates && !maindlgitem(hDlg,item))
  185.                                 EndDialog(hDlg,item);
  186.                 }
  187.                 break;
  188. //      case WM_LBUTTONDOWN: break;
  189.         case WM_MOUSEMOVE:
  190.                 if(panning && GetCursorPos(&newpos)){
  191.                         newscroll.h = (int16)(origscroll.h - zoomfactor*(newpos.x - origpos.x));
  192.                         newscroll.v = (int16)(origscroll.v - zoomfactor*(newpos.y - origpos.y));
  193.                         if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){
  194.                                 preview_scroll = newscroll;
  195.                                 recalc_preview(gpb,hDlg);
  196.                         }
  197.                 }
  198.                 break;
  199.         case WM_LBUTTONUP:
  200.                 ReleaseCapture();
  201.                 panning = false;
  202.                 break;
  203.         case WM_HSCROLL:
  204.                 item = GetDlgCtrlID((HWND)lParam);
  205.                 if(doupdates && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7)
  206.                         slidermoved(hDlg,item);
  207.                 break;
  208.         default:
  209.                 return false;
  210.         }
  211.  
  212.         return true;
  213. }
  214.  
  215. Boolean maindialog(FilterRecordPtr pb){
  216.         PlatformData *p;
  217.         WNDCLASSEX clx;
  218.         Boolean res;
  219.  
  220.         // For the preview image, we register a class, so that we can assign a mouse cursor to this class.
  221.         clx.cbSize = sizeof(WNDCLASSEX);
  222.         GetClassInfoEx(hDllInstance, "STATIC", &clx);
  223.         clx.lpszClassName = "Preview";
  224.         RegisterClassEx(&clx);
  225.  
  226.         // For the caution images, we register a class, so that we can assign a mouse cursor to this class.
  227.         clx.cbSize = sizeof(WNDCLASSEX);
  228.         GetClassInfoEx(hDllInstance, "STATIC", &clx);
  229.         clx.lpszClassName = "CautionSign";
  230.         RegisterClassEx(&clx);
  231.  
  232.         // Now show the dialog
  233.         p = (PlatformData*)pb->platformData;
  234.         res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG),
  235.                              (HWND)p->hwnd,maindlgproc,0) == IDOK;
  236.  
  237.         UnregisterClass("Preview", hDllInstance);
  238.         UnregisterClass("CautionSign", hDllInstance);
  239.  
  240.         return res;
  241. }
  242.  
  243.