Subversion Repositories filter_foundry

Rev

Rev 353 | Rev 355 | 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. HCURSOR hCurHandPoint;
  39.  
  40. extern HINSTANCE hDllInstance;
  41.  
  42. void DoAbout(AboutRecordPtr pb){
  43.         char text[1000];
  44.         char title[200];
  45.         PlatformData *p = (PlatformData*)pb->platformData;
  46.  
  47.         if (gdata && gdata->standalone) {
  48.                 sprintf(title, "About %s", INPLACEP2CSTR(gdata->parm.title));
  49.                 sprintf(text,  "%s by %s\n" /* {Title} by {Author} */
  50.                                "%s\n" /* {Copyright} */
  51.                                "\n"
  52.                                "This plugin was built using Filter Foundry " VERSION_STR
  53.                                 #ifdef _WIN64
  54.                                " (64 bit)\n"
  55.                                 #else
  56.                                " (32 bit)\n"
  57.                                 #endif
  58.                                "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
  59.                                "available from " PROJECT_URL,
  60.                                INPLACEP2CSTR(gdata->parm.title),
  61.                                INPLACEP2CSTR(gdata->parm.author),
  62.                                INPLACEP2CSTR(gdata->parm.copyright));
  63.         } else {
  64.                 sprintf(title, "About Filter Foundry");
  65.                 sprintf(text,  "Filter Foundry " VERSION_STR
  66.                                 #ifdef _WIN64
  67.                                " (64 bit)\n"
  68.                                 #else
  69.                                " (32 bit)\n"
  70.                                 #endif
  71.                                "(C) 2003-2009 Toby Thain, 2018-" RELEASE_YEAR " Daniel Marschall\n"
  72.                                "\n"
  73.                                "Latest version available from\n"
  74.                                PROJECT_URL "\n"
  75.                                "\nPlease contact the author with any bug reports,\n"
  76.                                "suggestions or comments.\n"
  77.                                "If you use this program and like it, please consider\n"
  78.                                "making a donation.");
  79.         }
  80.  
  81.         MessageBox((HWND)p->hwnd, text, title, MB_APPLMODAL|MB_ICONINFORMATION|MB_OK);
  82. }
  83.  
  84. Boolean simplealert(char *s){
  85.         HWND hwnd;
  86.         char* title;
  87.         if (gdata && gdata->standalone) {
  88.                 title = INPLACEP2CSTR(gdata->parm.title);
  89.         } else {
  90.                 title = _strdup("Filter Foundry");
  91.         }
  92.         hwnd = gdata ? gdata->hWndMainDlg : NULL;
  93.         return MessageBox(hwnd,s,title,MB_TASKMODAL|MB_ICONERROR|MB_OK) == IDOK;
  94. }
  95.  
  96. Boolean simplewarning(char* s) {
  97.         HWND hwnd;
  98.         char* title;
  99.         if (gdata && gdata->standalone) {
  100.                 title = INPLACEP2CSTR(gdata->parm.title);
  101.         }
  102.         else {
  103.                 title = _strdup("Filter Foundry");
  104.         }
  105.         hwnd = gdata ? gdata->hWndMainDlg : NULL;
  106.         return MessageBox(hwnd,s,title,MB_TASKMODAL|MB_ICONEXCLAMATION|MB_OK) == IDOK;
  107. }
  108.  
  109. Boolean showmessage(char *s) {
  110.         HWND hwnd;
  111.         char* title;
  112.         if (gdata && gdata->standalone) {
  113.                 title = INPLACEP2CSTR(gdata->parm.title);
  114.         } else {
  115.                 title = _strdup("Filter Foundry");
  116.         }
  117.         hwnd = gdata ? gdata->hWndMainDlg : NULL;
  118.         return MessageBox(hwnd,s,title,MB_TASKMODAL|MB_ICONINFORMATION|MB_OK) == IDOK;
  119. }
  120.  
  121. INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
  122.  
  123. // Description:
  124. //   Creates a tooltip for an item in a dialog box.
  125. // Parameters:
  126. //   idTool - identifier of an dialog box item.
  127. //   nDlg - window handle of the dialog box.
  128. //   pszText - string to use as the tooltip text.
  129. // Returns:
  130. //   The handle to the tooltip.
  131. //
  132. HWND CreateToolTip(int toolID, HWND hDlg, PTSTR pszText) {
  133.         // Source: https://docs.microsoft.com/en-us/windows/win32/controls/create-a-tooltip-for-a-control (modified)
  134.        
  135.         HWND hwndTool, hwndTip;
  136.         TOOLINFO toolInfo;
  137.  
  138.         if (!toolID || !hDlg || !pszText) {
  139.                 return FALSE;
  140.         }
  141.         // Get the window of the tool.
  142.         hwndTool = GetDlgItem(hDlg, toolID);
  143.  
  144.         // Create the tooltip. g_hInst is the global instance handle.
  145.         hwndTip = CreateWindowEx(0, TOOLTIPS_CLASS, NULL,
  146.                 WS_POPUP | TTS_ALWAYSTIP /* | TTS_BALLOON*/,
  147.                 CW_USEDEFAULT, CW_USEDEFAULT,
  148.                 CW_USEDEFAULT, CW_USEDEFAULT,
  149.                 hDlg, NULL,
  150.                 hDllInstance, NULL);
  151.  
  152.         if (!hwndTool || !hwndTip) {
  153.                 return (HWND)NULL;
  154.         }
  155.  
  156.         // Associate the tooltip with the tool.
  157.         memset(&toolInfo, 0, sizeof(TOOLINFO)); // toolInfo = { 0 };
  158.         toolInfo.cbSize = sizeof(toolInfo);
  159.         toolInfo.hwnd = hDlg;
  160.         toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
  161.         toolInfo.uId = (UINT_PTR)hwndTool;
  162.         toolInfo.lpszText = pszText;
  163.         SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
  164.  
  165.         return hwndTip;
  166. }
  167.  
  168. #ifndef IDC_HAND
  169. #define IDC_HAND            MAKEINTRESOURCE(32649)
  170. #endif
  171.  
  172. INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){
  173.         static POINT origpos;
  174.         static Point origscroll;
  175.         static Boolean panning = false;
  176.  
  177.         int item,i;
  178.         POINT newpos;
  179.         DRAWITEMSTRUCT *pdi;
  180.         Point newscroll;
  181.         HGDIOBJ hfnt;
  182.         char s[0x100];
  183.  
  184.         extern Boolean doupdates;
  185.         extern Handle preview_handle;
  186.  
  187.         switch(wMsg){
  188.         case WM_INITDIALOG:
  189.                 gdata->hWndMainDlg = hDlg;
  190.  
  191.                 if(gdata->standalone){
  192.                         myp2cstrcpy(s,gdata->parm.title);
  193.                         SetWindowText(hDlg,s); // window title bar
  194.                 }
  195.                 centre_window(hDlg);
  196.  
  197.                 hfnt = GetStockObject(ANSI_FIXED_FONT);
  198.  
  199.                 hCurHandOpen = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_OPEN));
  200.                 hCurHandGrab = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_GRAB));
  201.                 hCurHandQuestion = LoadCursor(hDllInstance, MAKEINTRESOURCE(IDC_FF_HAND_QUESTION));
  202.                 hCurHandPoint = LoadCursor(NULL, IDC_HAND);
  203.  
  204.                 preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM);
  205.                 GetClientRect(preview_hwnd, &preview_rect);
  206.                 SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen);
  207.  
  208.                 SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion);
  209.  
  210.                 for(i = 0; i < 4; ++i){
  211.                         // If Visual Themes are applied, SS_ICON will be ignored for controls which are not exactly "STATIC" class.
  212.                         // Our derivated "CautionSign" class won't work. So we need to set the icon explicitly.
  213.                         SendDlgItemMessage(hDlg, FIRSTICONITEM+i, STM_SETICON, (WPARAM)LoadImage(hDllInstance, "CAUTION_ICO",IMAGE_ICON,16,16, LR_DEFAULTCOLOR), 0);
  214.                         CreateToolTip(FIRSTICONITEM + i, hDlg, "Syntax error! Click to see details.");
  215.                 }
  216.  
  217.                 CreateToolTip(ZOOMINITEM, hDlg, "Zoom in");
  218.                 CreateToolTip(ZOOMOUTITEM, hDlg, "Zoom out");
  219.                 CreateToolTip(ZOOMLEVELITEM, hDlg, "Zoom fully in/out");
  220.  
  221.                 // Note: Actually, the whole class gets the cursor, not just these three controls!!
  222.                 if (hCurHandPoint) {
  223.                         SetClassLongPtr(GetDlgItem(hDlg, ZOOMINITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandPoint);
  224.                         SetClassLongPtr(GetDlgItem(hDlg, ZOOMOUTITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandPoint);
  225.                         SetClassLongPtr(GetDlgItem(hDlg, ZOOMLEVELITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandPoint);
  226.                 }
  227.  
  228.                 for(i = 0; i < 8; ++i){
  229.                         SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETRANGE,TRUE,MAKELONG(0,255));
  230.                         SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETTICFREQ,SLIDERPAGE,0);
  231.                         SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETPAGESIZE,0,SLIDERPAGE);
  232.                         SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i,     EM_SETLIMITTEXT,3,0);
  233.                 }
  234.                 for(i = 0; i < 4; ++i){
  235.                         SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        EM_SETLIMITTEXT,MAXEXPR-1,0); // we need 1 byte as NUL terminator, so our formula can be max 1023
  236.                         SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        WM_SETFONT,(WPARAM)hfnt,false);
  237.                 }
  238.  
  239.                 maindlginit(hDlg);
  240.                 break;
  241.         case WM_DESTROY:
  242.                 gdata->hWndMainDlg = 0;
  243.                 DestroyCursor(hCurHandOpen);
  244.                 DestroyCursor(hCurHandGrab);
  245.                 DestroyCursor(hCurHandQuestion);
  246.                 break;
  247.         case WM_DRAWITEM:
  248.                 pdi = (DRAWITEMSTRUCT*)lParam;
  249.                 if(pdi->itemAction == ODA_DRAWENTIRE){
  250.                         switch(pdi->CtlID){
  251.                         case PREVIEWITEM:
  252.                                 drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
  253.                                 PIUNLOCKHANDLE(preview_handle);
  254.                                 break;
  255.                         default:
  256.                                 return false;
  257.                         }
  258.                 }else
  259.                         return false; // we couldn't handle the message
  260.                 break;
  261.         case WM_COMMAND:
  262.                 item = LOWORD(wParam);
  263.                 switch(HIWORD(wParam)){
  264.                 case BN_CLICKED: //case STN_CLICKED:
  265.                         if(item==PREVIEWITEM && GetCursorPos(&origpos)){
  266.                                 panning = true;
  267.                                 origscroll = preview_scroll;
  268.                                 SetCursor(hCurHandGrab);
  269.                                 SetCapture(hDlg);
  270.                                 break;
  271.                         }
  272.                         /* ... falls through ... */
  273.                 case EN_CHANGE:
  274.                         if(doupdates && !maindlgitem(hDlg,item))
  275.                                 EndDialog(hDlg,item);
  276.                 }
  277.                 break;
  278. //      case WM_LBUTTONDOWN: break;
  279.         case WM_MOUSEMOVE:
  280.                 if(panning && GetCursorPos(&newpos)){
  281.                         newscroll.h = (int16)(origscroll.h - zoomfactor*((double)newpos.x - (double)origpos.x));
  282.                         newscroll.v = (int16)(origscroll.v - zoomfactor*((double)newpos.y - (double)origpos.y));
  283.                         if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){
  284.                                 preview_scroll = newscroll;
  285.                                 recalc_preview(gpb,hDlg);
  286.                         }
  287.                 }
  288.                 break;
  289.         case WM_LBUTTONUP:
  290.                 ReleaseCapture();
  291.                 panning = false;
  292.                 break;
  293.         case WM_HSCROLL:
  294.                 item = GetDlgCtrlID((HWND)lParam);
  295.                 if(doupdates && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7)
  296.                         slidermoved(hDlg,item);
  297.                 break;
  298.         default:
  299.                 return false;
  300.         }
  301.  
  302.         return true;
  303. }
  304.  
  305. Boolean maindialog(FilterRecordPtr pb){
  306.         PlatformData *p;
  307.         WNDCLASSEX clx;
  308.         Boolean res;
  309.  
  310.         // For the preview image, we register a class, so that we can assign a mouse cursor to this class.
  311.         clx.cbSize = sizeof(WNDCLASSEX);
  312.         GetClassInfoEx(hDllInstance, "STATIC", &clx);
  313.         clx.lpszClassName = "Preview";
  314.         RegisterClassEx(&clx);
  315.  
  316.         // For the caution images, we register a class, so that we can assign a mouse cursor to this class.
  317.         clx.cbSize = sizeof(WNDCLASSEX);
  318.         GetClassInfoEx(hDllInstance, "STATIC", &clx);
  319.         clx.lpszClassName = "CautionSign";
  320.         RegisterClassEx(&clx);
  321.  
  322.         // Now show the dialog
  323.         p = (PlatformData*)pb->platformData;
  324.         res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG),
  325.                              (HWND)p->hwnd,maindlgproc,0) == IDOK;
  326.  
  327.         // Clean up after the dialog has been closed
  328.         UnregisterClass("Preview", hDllInstance);
  329.         UnregisterClass("CautionSign", hDllInstance);
  330.  
  331.         return res;
  332. }
  333.  
  334.