Subversion Repositories filter_foundry

Rev

Rev 185 | Rev 194 | 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-2019 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 HANDLE 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.                            "http://www.telegraphics.com.au/sw/\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 through www.paypal.com\n"
  68.                            "(US$5 suggested) to the address above.");
  69.         }
  70.  
  71.         MessageBox((HWND)p->hwnd, text, title, MB_APPLMODAL|MB_ICONINFORMATION|MB_OK);
  72. }
  73.  
  74. Boolean simplealert(char *s){
  75.         char* title;
  76.         if (gdata && gdata->standalone) {
  77.                 title = INPLACEP2CSTR(gdata->parm.title);
  78.         } else {
  79.                 title = "Filter Foundry";
  80.         }
  81.         return MessageBox(NULL,s,title,MB_TASKMODAL|MB_ICONERROR|MB_OK) == IDOK;
  82. }
  83.  
  84. Boolean showmessage(char *s){
  85.         char* title;
  86.         if (gdata && gdata->standalone) {
  87.                 title = INPLACEP2CSTR(gdata->parm.title);
  88.         } else {
  89.                 title = "Filter Foundry";
  90.         }
  91.         return MessageBox(NULL,s,title,MB_TASKMODAL|MB_ICONINFORMATION|MB_OK) == IDOK;
  92. }
  93.  
  94. INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
  95.  
  96. INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){
  97.         static POINT origpos;
  98.         static Point origscroll;
  99.         static Boolean panning = false;
  100.  
  101.         int item,i;
  102.         POINT newpos;
  103.         DRAWITEMSTRUCT *pdi;
  104.         Point newscroll;
  105.         HFONT hfnt;
  106.         char s[0x100];
  107.  
  108.         extern Boolean doupdates;
  109.         extern Handle preview_handle;
  110.  
  111.         switch(wMsg){
  112.         case WM_INITDIALOG:
  113.                 gdata->hWndMainDlg = hDlg;
  114.  
  115.                 if(gdata->standalone){
  116.                         myp2cstrcpy(s,gdata->parm.title);
  117.                         SetWindowText(hDlg,s); // window title bar
  118.                 }
  119.                 centre_window(hDlg);
  120.  
  121.                 // see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_3pbo.asp
  122.                 hfnt = GetStockObject(ANSI_FIXED_FONT);
  123.  
  124.                 hCurHandOpen = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_OPEN));
  125.                 hCurHandGrab = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_GRAB));
  126.                 hCurHandQuestion = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_QUESTION));
  127.  
  128.                 preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM);
  129.                 GetClientRect(preview_hwnd, &preview_rect);
  130.                 SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen);
  131.  
  132.                 SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion);
  133.  
  134.                 for(i = 0; i < 4; ++i){
  135.                         // If Visual Themes are applied, SS_ICON will be ignored for controls which are not exactly "STATIC" class.
  136.                         // Our derivated "CautionSign" class won't work. So we need to set the icon explicitly.
  137.                         SendDlgItemMessage(hDlg, FIRSTICONITEM+i, STM_SETICON, (WPARAM)LoadImage(hDllInstance, "CAUTION_ICO",IMAGE_ICON,16,16, LR_DEFAULTCOLOR), 0);
  138.                 }
  139.  
  140.                 for(i = 0; i < 8; ++i){
  141.                         SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETRANGE,TRUE,MAKELONG(0,255));
  142.                         SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETTICFREQ,SLIDERPAGE,0);
  143.                         SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETPAGESIZE,0,SLIDERPAGE);
  144.                         SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i,     EM_SETLIMITTEXT,3,0);
  145.                 }
  146.                 for(i = 0; i < 4; ++i){
  147.                         SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        EM_SETLIMITTEXT,MAXEXPR-1,0); // we need 1 byte as NUL terminator, so our formula can be max 1023
  148.                         SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        WM_SETFONT,(WPARAM)hfnt,false);
  149.                 }
  150.  
  151.                 maindlginit(hDlg);
  152.                 break;
  153.         case WM_DESTROY:
  154.                 gdata->hWndMainDlg = 0;
  155.                 DestroyCursor(hCurHandOpen);
  156.                 DestroyCursor(hCurHandGrab);
  157.                 DestroyCursor(hCurHandQuestion);
  158.                 break;
  159.         case WM_DRAWITEM:
  160.                 pdi = (DRAWITEMSTRUCT*)lParam;
  161.                 if(pdi->itemAction == ODA_DRAWENTIRE){
  162.                         switch(pdi->CtlID){
  163.                         case PREVIEWITEM:
  164.                                 drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
  165.                                 PIUNLOCKHANDLE(preview_handle);
  166.                                 break;
  167.                         default:
  168.                                 return false;
  169.                         }
  170.                 }else
  171.                         return false; // we couldn't handle the message
  172.                 break;
  173.         case WM_COMMAND:
  174.                 item = LOWORD(wParam);
  175.                 switch(HIWORD(wParam)){
  176.                 case BN_CLICKED: //case STN_CLICKED:
  177.                         if(item==PREVIEWITEM && GetCursorPos(&origpos)){
  178.                                 panning = true;
  179.                                 origscroll = preview_scroll;
  180.                                 SetCursor(hCurHandGrab);
  181.                                 SetCapture(hDlg);
  182.                                 break;
  183.                         }
  184.                 case EN_CHANGE:
  185.                         if(doupdates && !maindlgitem(hDlg,item))
  186.                                 EndDialog(hDlg,item);
  187.                 }
  188.                 break;
  189. //      case WM_LBUTTONDOWN: break;
  190.         case WM_MOUSEMOVE:
  191.                 if(panning && GetCursorPos(&newpos)){
  192.                         newscroll.h = (int16)(origscroll.h - zoomfactor*(newpos.x - origpos.x));
  193.                         newscroll.v = (int16)(origscroll.v - zoomfactor*(newpos.y - origpos.y));
  194.                         if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){
  195.                                 preview_scroll = newscroll;
  196.                                 recalc_preview(gpb,hDlg);
  197.                         }
  198.                 }
  199.                 break;
  200.         case WM_LBUTTONUP:
  201.                 ReleaseCapture();
  202.                 panning = false;
  203.                 break;
  204.         case WM_HSCROLL:
  205.                 item = GetDlgCtrlID((HWND)lParam);
  206.                 if(doupdates && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7)
  207.                         slidermoved(hDlg,item);
  208.                 break;
  209.         default:
  210.                 return false;
  211.         }
  212.  
  213.         return true;
  214. }
  215.  
  216. Boolean maindialog(FilterRecordPtr pb){
  217.         PlatformData *p;
  218.         WNDCLASSEX clx;
  219.         Boolean res;
  220.  
  221.         // For the preview image, we register a class, so that we can assign a mouse cursor to this class.
  222.         clx.cbSize = sizeof(WNDCLASSEX);
  223.         GetClassInfoEx(hDllInstance, "STATIC", &clx);
  224.         clx.lpszClassName = "Preview";
  225.         RegisterClassEx(&clx);
  226.  
  227.         // For the caution images, we register a class, so that we can assign a mouse cursor to this class.
  228.         clx.cbSize = sizeof(WNDCLASSEX);
  229.         GetClassInfoEx(hDllInstance, "STATIC", &clx);
  230.         clx.lpszClassName = "CautionSign";
  231.         RegisterClassEx(&clx);
  232.  
  233.         // Now show the dialog
  234.         p = pb->platformData;
  235.         res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG),
  236.                              (HWND)p->hwnd,maindlgproc,0) == IDOK;
  237.  
  238.         UnregisterClass("Preview", hDllInstance);
  239.         UnregisterClass("CautionSign", hDllInstance);
  240.  
  241.         return res;
  242. }
  243.  
  244.