Subversion Repositories filter_foundry

Rev

Rev 412 | Rev 419 | 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", gdata->parm.szTitle);
  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.                                gdata->parm.szTitle,
  61.                                gdata->parm.szAuthor,
  62.                                gdata->parm.szCopyright);
  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_TASKMODAL|MB_ICONINFORMATION|MB_OK);
  82. }
  83.  
  84. Boolean simplealert(char *s){
  85.         HWND hwnd;
  86.         char* title;
  87.         if (gdata && gdata->standalone) {
  88.                 title = gdata->parm.szTitle;
  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 = gdata->parm.szTitle;
  101.         } else {
  102.                 title = _strdup("Filter Foundry");
  103.         }
  104.         hwnd = gdata ? gdata->hWndMainDlg : NULL;
  105.         return MessageBox(hwnd,s,title,MB_TASKMODAL|MB_ICONEXCLAMATION|MB_OK) == IDOK;
  106. }
  107.  
  108. Boolean showmessage(char *s) {
  109.         HWND hwnd;
  110.         char* title;
  111.         if (gdata && gdata->standalone) {
  112.                 title = gdata->parm.szTitle;
  113.         } else {
  114.                 title = _strdup("Filter Foundry");
  115.         }
  116.         hwnd = gdata ? gdata->hWndMainDlg : NULL;
  117.         return MessageBox(hwnd,s,title,MB_TASKMODAL|MB_ICONINFORMATION|MB_OK) == IDOK;
  118. }
  119.  
  120. INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam);
  121.  
  122. // Description:
  123. //   Creates a tooltip for an item in a dialog box.
  124. // Parameters:
  125. //   idTool - identifier of an dialog box item.
  126. //   nDlg - window handle of the dialog box.
  127. //   pszText - string to use as the tooltip text.
  128. // Returns:
  129. //   The handle to the tooltip.
  130. //
  131. HWND CreateToolTip(int toolID, HWND hDlg, PTSTR pszText) {
  132.         // Source: https://docs.microsoft.com/en-us/windows/win32/controls/create-a-tooltip-for-a-control (modified)
  133.  
  134.         HWND hwndTool, hwndTip;
  135.         TOOLINFO toolInfo;
  136.  
  137.         if (!toolID || !hDlg || !pszText) {
  138.                 return FALSE;
  139.         }
  140.         // Get the window of the tool.
  141.         hwndTool = GetDlgItem(hDlg, toolID);
  142.  
  143.         // Create the tooltip. g_hInst is the global instance handle.
  144.         hwndTip = CreateWindowEx(0, TOOLTIPS_CLASS, NULL,
  145.                 WS_POPUP | TTS_ALWAYSTIP /* | TTS_BALLOON*/,
  146.                 CW_USEDEFAULT, CW_USEDEFAULT,
  147.                 CW_USEDEFAULT, CW_USEDEFAULT,
  148.                 hDlg, NULL,
  149.                 hDllInstance, NULL);
  150.  
  151.         if (!hwndTool || !hwndTip) {
  152.                 return (HWND)NULL;
  153.         }
  154.  
  155.         // Associate the tooltip with the tool.
  156.         memset(&toolInfo, 0, sizeof(TOOLINFO)); // toolInfo = { 0 };
  157.         toolInfo.cbSize = sizeof(toolInfo);
  158.         toolInfo.hwnd = hDlg;
  159.         toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
  160.         toolInfo.uId = (UINT_PTR)hwndTool;
  161.         toolInfo.lpszText = pszText;
  162.         SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
  163.  
  164.         return hwndTip;
  165. }
  166.  
  167. #ifndef IDC_HAND
  168. #define IDC_HAND            MAKEINTRESOURCE(32649)
  169. #endif
  170.  
  171. INT_PTR CALLBACK maindlgproc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam){
  172.         static POINT origpos;
  173.         static Point origscroll;
  174.         static Boolean panning = false;
  175.  
  176.         int item,i;
  177.         POINT newpos;
  178.         DRAWITEMSTRUCT *pdi;
  179.         Point newscroll;
  180.         HGDIOBJ hfnt;
  181.  
  182.         extern Boolean doupdates;
  183.         extern Handle preview_handle;
  184.  
  185.         switch(wMsg){
  186.         case WM_INITDIALOG:
  187.                 gdata->hWndMainDlg = hDlg;
  188.  
  189.                 if(gdata->standalone){
  190.                         SetWindowText(hDlg,gdata->parm.szTitle); // window title bar
  191.                 }
  192.                 centre_window(hDlg);
  193.  
  194.                 hfnt = GetStockObject(ANSI_FIXED_FONT);
  195.  
  196.                 hCurHandOpen = LoadCursor(hDllInstance, "HAND_OPEN");
  197.                 hCurHandGrab = LoadCursor(hDllInstance, "HAND_GRAB");
  198.                 hCurHandQuestion = LoadCursor(hDllInstance, "HAND_QUESTION");
  199.                 hCurHandPoint = LoadCursor(NULL, IDC_HAND);
  200.  
  201.                 preview_hwnd = GetDlgItem(hDlg, PREVIEWITEM);
  202.                 GetClientRect(preview_hwnd, &preview_rect);
  203.                 SetClassLongPtr(preview_hwnd, GCLP_HCURSOR, (LONG_PTR)hCurHandOpen);
  204.  
  205.                 SetClassLongPtr(GetDlgItem(hDlg, FIRSTICONITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandQuestion);
  206.  
  207.                 for(i = 0; i < 4; ++i){
  208.                         // If Visual Themes are applied, SS_ICON will be ignored for controls which are not exactly "STATIC" class.
  209.                         // Our derivated "CautionSign" class won't work. So we need to set the icon explicitly.
  210.                         SendDlgItemMessage(hDlg, FIRSTICONITEM+i, STM_SETICON, (WPARAM)LoadImage(hDllInstance, "CAUTION_ICO",IMAGE_ICON,16,16, LR_DEFAULTCOLOR), 0);
  211.                         CreateToolTip(FIRSTICONITEM + i, hDlg, _strdup("Syntax error! Click to see details."));
  212.                 }
  213.  
  214.                 CreateToolTip(ZOOMINITEM, hDlg, _strdup("Zoom in"));
  215.                 CreateToolTip(ZOOMOUTITEM, hDlg, _strdup("Zoom out"));
  216.                 CreateToolTip(ZOOMLEVELITEM, hDlg, _strdup("Zoom fully in/out"));
  217.  
  218.                 // Note: Actually, the whole class gets the cursor, not just these three controls!!
  219.                 if (hCurHandPoint) {
  220.                         SetClassLongPtr(GetDlgItem(hDlg, ZOOMINITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandPoint);
  221.                         SetClassLongPtr(GetDlgItem(hDlg, ZOOMOUTITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandPoint);
  222.                         SetClassLongPtr(GetDlgItem(hDlg, ZOOMLEVELITEM), GCLP_HCURSOR, (LONG_PTR)hCurHandPoint);
  223.                 }
  224.  
  225.                 for(i = 0; i < 8; ++i){
  226.                         SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETRANGE,TRUE,MAKELONG(0,255));
  227.                         SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETTICFREQ,SLIDERPAGE,0);
  228.                         SendDlgItemMessage(hDlg,FIRSTCTLITEM+i,         TBM_SETPAGESIZE,0,SLIDERPAGE);
  229.                         SendDlgItemMessage(hDlg,FIRSTCTLTEXTITEM+i,     EM_SETLIMITTEXT,3,0);
  230.                 }
  231.                 for(i = 0; i < 4; ++i){
  232.                         SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        EM_SETLIMITTEXT,MAXEXPR-1,0); // we need 1 byte as NUL terminator, so our formula can be max 1023
  233.                         SendDlgItemMessage(hDlg,FIRSTEXPRITEM+i,        WM_SETFONT,(WPARAM)hfnt,false);
  234.                 }
  235.  
  236.                 maindlginit(hDlg);
  237.                 break;
  238.         case WM_DESTROY:
  239.                 gdata->hWndMainDlg = 0;
  240.                 DestroyCursor(hCurHandOpen);
  241.                 DestroyCursor(hCurHandGrab);
  242.                 DestroyCursor(hCurHandQuestion);
  243.                 break;
  244.         case WM_DRAWITEM:
  245.                 pdi = (DRAWITEMSTRUCT*)lParam;
  246.                 if(pdi->itemAction == ODA_DRAWENTIRE){
  247.                         switch(pdi->CtlID){
  248.                         case PREVIEWITEM:
  249.                                 drawpreview(hDlg,pdi->hDC,PILOCKHANDLE(preview_handle,false));
  250.                                 PIUNLOCKHANDLE(preview_handle);
  251.                                 break;
  252.                         default:
  253.                                 return false;
  254.                         }
  255.                 }else
  256.                         return false; // we couldn't handle the message
  257.                 break;
  258.         case WM_COMMAND:
  259.                 item = LOWORD(wParam);
  260.                 switch(HIWORD(wParam)){
  261.                 case BN_CLICKED: //case STN_CLICKED:
  262.                         if(item==PREVIEWITEM && GetCursorPos(&origpos)){
  263.                                 panning = true;
  264.                                 origscroll = preview_scroll;
  265.                                 SetCursor(hCurHandGrab);
  266.                                 SetCapture(hDlg);
  267.                                 break;
  268.                         }
  269.                         /* ... falls through ... */
  270.                 case EN_CHANGE:
  271.                         if(doupdates && !maindlgitem(hDlg,item))
  272.                                 EndDialog(hDlg,item);
  273.                 }
  274.                 break;
  275. //      case WM_LBUTTONDOWN: break;
  276.         case WM_MOUSEMOVE:
  277.                 if(panning && GetCursorPos(&newpos)){
  278.                         newscroll.h = (int16)(origscroll.h - zoomfactor*((double)newpos.x - (double)origpos.x));
  279.                         newscroll.v = (int16)(origscroll.v - zoomfactor*((double)newpos.y - (double)origpos.y));
  280.                         if( newscroll.h != preview_scroll.h || newscroll.v != preview_scroll.v ){
  281.                                 preview_scroll = newscroll;
  282.                                 recalc_preview(gpb,hDlg);
  283.                         }
  284.                 }
  285.                 break;
  286.         case WM_LBUTTONUP:
  287.                 ReleaseCapture();
  288.                 panning = false;
  289.                 break;
  290.         case WM_HSCROLL:
  291.                 item = GetDlgCtrlID((HWND)lParam);
  292.                 if(doupdates && item>=FIRSTCTLITEM && item<=FIRSTCTLITEM+7)
  293.                         slidermoved(hDlg,item);
  294.                 break;
  295.         default:
  296.                 return false;
  297.         }
  298.  
  299.         return true;
  300. }
  301.  
  302. Boolean maindialog(FilterRecordPtr pb){
  303.         PlatformData *p;
  304.         WNDCLASS clx;
  305.         INT_PTR res;
  306.  
  307.         // ALL Versions of Windows show the confusing error message "Invalid Cursor Handle" when DialogBoxParamA
  308.         // tries to open a dialog with a control which class is unknown.
  309.         // "msctls_trackbar32" is not included in Windows NT 3.1, and since there is no OCX or RegSvr32,
  310.         // there seems no possibility to support this version of Windows at this point.
  311.         if (GetClassInfo(hDllInstance, "msctls_trackbar32", &clx) == 0) {
  312.                 simplealert("This plugin requires the Microsoft Trackbar Control (msctls_trackbar32) which is not found on your system.");
  313.                 return false;
  314.         }
  315.  
  316.         // For the preview image, we register a class, so that we can assign a mouse cursor to this class.
  317.         GetClassInfo(hDllInstance, "STATIC", &clx);
  318.         clx.lpszClassName = "Preview";
  319.         if (RegisterClass(&clx) == 0) {
  320.                 char s[100];
  321.                 strcpy(s, "RegisterClass failed: ");
  322.                 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + strlen(s), 0x100, NULL);
  323.                 dbg(s);
  324.         }
  325.  
  326.         // For the caution images, we register a class, so that we can assign a mouse cursor to this class.
  327.         GetClassInfo(hDllInstance, "STATIC", &clx);
  328.         clx.lpszClassName = "CautionSign";
  329.         if (RegisterClass(&clx) == 0) {
  330.                 char s[100];
  331.                 strcpy(s, "RegisterClass failed: ");
  332.                 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + strlen(s), 0x100, NULL);
  333.                 dbg(s);
  334.         }
  335.  
  336.         // Now show the dialog
  337.         p = (PlatformData*)pb->platformData;
  338.         res = DialogBoxParam(hDllInstance,MAKEINTRESOURCE(gdata->standalone ? ID_PARAMDLG : ID_MAINDLG),
  339.                              (HWND)p->hwnd,maindlgproc,0);
  340.         if (res == 0) {
  341.                 simplealert("DialogBoxParam in valid parent window handle");
  342.         }
  343.         if (res == -1) {
  344.                 char s[100];
  345.                 strcpy(s, "DialogBoxParam failed: ");
  346.                 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + strlen(s), 0x100, NULL);
  347.                 dbg(s);
  348.         }
  349.  
  350.         // Clean up after the dialog has been closed
  351.         UnregisterClass("Preview", hDllInstance);
  352.         UnregisterClass("CautionSign", hDllInstance);
  353.  
  354.         return res == IDOK;
  355. }
  356.  
  357.