Subversion Repositories filter_foundry

Rev

Rev 443 | 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. #include "ff.h"
  22.  
  23. // PLUGIN.DLL Sliders: This method will register the "slider" class used in dialogs.
  24. typedef int(__cdecl* f_RegisterSlider)(HINSTANCE hInstanceDll, DWORD* MessageID);
  25. int RegisterSlider(HINSTANCE hInstanceDll, DWORD* MessageID) {
  26.         f_RegisterSlider fRegisterSlider;
  27.  
  28.         if (!gdata->pluginDllModule) return 0;
  29.         fRegisterSlider = (f_RegisterSlider)(void*)GetProcAddress(gdata->pluginDllModule, "RegisterSlider");
  30.         if (fRegisterSlider != 0) {
  31.                 return fRegisterSlider(hInstanceDll, MessageID);
  32.         }
  33.         else {
  34.                 return 0;
  35.         }
  36. }
  37.  
  38. // PLUGIN.DLL Sliders: This method will unregister the "slider" class used in dialogs.
  39. typedef int(__cdecl* f_UnregisterSlider)(HINSTANCE hInstanceDll);
  40. int UnregisterSlider(HINSTANCE hInstanceDll) {
  41.         f_UnregisterSlider fUnregisterSlider;
  42.  
  43.         if (!gdata->pluginDllModule) return 0;
  44.         fUnregisterSlider = (f_UnregisterSlider)(void*)GetProcAddress(gdata->pluginDllModule, "UnregisterSlider");
  45.         if (fUnregisterSlider != 0) {
  46.                 return fUnregisterSlider(hInstanceDll);
  47.         }
  48.         else {
  49.                 return 0;
  50.         }
  51. }
  52.  
  53. // PLUGIN.DLL Sliders: Set slider range (min/max)
  54. typedef int(__cdecl* f_SetSliderRange)(HWND hWnd, int nMin, int nMax);
  55. int SetSliderRange(HWND hWnd, int nMin, int nMax) {
  56.         f_SetSliderRange fSetSliderRange;
  57.  
  58.         if (!gdata->pluginDllModule) return 0;
  59.         fSetSliderRange = (f_SetSliderRange)(void*)GetProcAddress(gdata->pluginDllModule, "SetSliderRange");
  60.         if (fSetSliderRange != 0) {
  61.                 return fSetSliderRange(hWnd, nMin, nMax);
  62.         }
  63.         else {
  64.                 return 0;
  65.         }
  66. }
  67.  
  68. // PLUGIN.DLL Sliders : Sets slider position
  69. typedef int(__cdecl* f_SetSliderPos)(HWND hWnd, int nPos, BOOL bRepaint);
  70. int SetSliderPos(HWND hWnd, int nPos, BOOL bRepaint) {
  71.         f_SetSliderPos fSetSliderPos;
  72.  
  73.         if (!gdata->pluginDllModule) return 0;
  74.         fSetSliderPos = (f_SetSliderPos)(void*)GetProcAddress(gdata->pluginDllModule, "SetSliderPos");
  75.         if (fSetSliderPos != 0) {
  76.                 return fSetSliderPos(hWnd, nPos, bRepaint);
  77.         }
  78.         else {
  79.                 return 0;
  80.         }
  81. }
  82.  
  83. // PLUGIN.DLL Sliders : Get slider position
  84. typedef int(__cdecl* f_GetSliderPos)(HWND hWnd, BOOL bPixelPosition);
  85. int GetSliderPos(HWND hWnd, BOOL bPixelPosition) {
  86.         f_GetSliderPos fGetSliderPos;
  87.  
  88.         if (!gdata->pluginDllModule) return 0;
  89.         fGetSliderPos = (f_GetSliderPos)(void*)GetProcAddress(gdata->pluginDllModule, "GetSliderPos");
  90.         if (fGetSliderPos != 0) {
  91.                 int res = fGetSliderPos(hWnd, bPixelPosition);
  92.                 return res;
  93.         }
  94.         else {
  95.                 return 0;
  96.         }
  97. }
  98.  
  99. Boolean MakeSimpleSubclass(LPCSTR targetClass, LPCSTR sourceClass) {
  100.         WNDCLASS clx;
  101.  
  102.         if (GetClassInfoA(hDllInstance, sourceClass, &clx) != 0) {
  103.                 clx.lpszClassName = targetClass;
  104.                 if (RegisterClass(&clx) == 0) {
  105.                         char s[100];
  106.                         strcpy(s, "RegisterClass failed: ");
  107.                         FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + strlen(s), 0x100, NULL);
  108.                         dbg(s);
  109.                         return false;
  110.                 }
  111.                 else {
  112.                         return true;
  113.                 }
  114.         }
  115.         else {
  116.                 return false;
  117.         }
  118. }
  119.  
  120. void Slider_Uninit_PluginDll() {
  121.  
  122. #ifndef use_plugin_dll_sliders
  123.         return;
  124. #else
  125.         WNDCLASS clx;
  126.  
  127.         if (GetClassInfo(hDllInstance, "slider", &clx) != 0) {
  128.                 UnregisterSlider(hDllInstance);
  129.         }
  130.         if (gdata->pluginDllModule) {
  131.                 FreeLibrary(gdata->pluginDllModule);
  132.                 gdata->pluginDllModule = 0;
  133.         }
  134. #endif
  135.  
  136. }
  137.  
  138. Boolean Slider_Init_PluginDll(LPCSTR targetClass) {
  139.  
  140. #ifndef use_plugin_dll_sliders
  141.         return false;
  142. #else
  143.         DWORD sliderMsgId;
  144.  
  145.         // Try loading PLUGIN.DLL (only Photoshop) in order to register the class "slider"
  146.         gdata->pluginDllModule = LoadLibraryA("PLUGIN.DLL");
  147.         if (!gdata->pluginDllModule) return false;
  148.         sliderMsgId = 0; // important
  149.         RegisterSlider(hDllInstance, &sliderMsgId);
  150.         if (sliderMsgId != 0) {
  151.                 // RegisterSlider will "remember" if it gave you a message ID before,
  152.                 // and it will NOT give it to you again! (instead, the output variable stays untouched).
  153.                 // The problem: PLUGIN.DLL stays loaded the whole time, so it keeps remembering, while Filter Foundry
  154.                 // loses its internal state every time the window is closed.
  155.                 // So, we keep the message ID in the global (persistant) data, so we remember it.
  156.                 gdata->pluginDllSliderMessageId = sliderMsgId;
  157.         }
  158.  
  159.         // Make "FoundrySlider" a subclass of "slider" then
  160.         return MakeSimpleSubclass(targetClass, "slider");
  161. #endif
  162.  
  163. }
  164.  
  165. typedef void(__stdcall* f_InitCommonControls)();
  166. typedef BOOL(__stdcall* f_InitCommonControlsEx)(const INITCOMMONCONTROLSEX* picce);
  167. Boolean Slider_Init_MsTrackbar(LPCSTR targetClass) {
  168.         f_InitCommonControls fInitCommonControls;
  169.         f_InitCommonControlsEx fInitCommonControlsEx;
  170.         HMODULE libComctl32;
  171.  
  172.         // Make sure that Comctl32 is loaded
  173.         libComctl32 = LoadLibraryA("Comctl32.dll");
  174.         if (libComctl32) {
  175.                 fInitCommonControlsEx = (f_InitCommonControlsEx)(void*)GetProcAddress(libComctl32, "InitCommonControlsEx");
  176.                 if (fInitCommonControlsEx != 0) {
  177.                         INITCOMMONCONTROLSEX icce;
  178.                         icce.dwSize = sizeof(INITCOMMONCONTROLSEX);
  179.                         icce.dwICC = ICC_BAR_CLASSES;
  180.                         fInitCommonControlsEx(&icce);
  181.                 }
  182.                 else {
  183.                         fInitCommonControls = (f_InitCommonControls)(void*)GetProcAddress(libComctl32, "InitCommonControls");
  184.                         if (fInitCommonControls != 0) {
  185.                                 fInitCommonControls();
  186.                         }
  187.                 }
  188.                 // There seems to be a bug in Windows NT 3.11 (if PLUGIN.DLL does not exist):
  189.                 // If we call FreeLibrary, and then open Filter Foundry again,
  190.                 // then you get an error message "BRUSHES" cannot initialize Comctl32.dll ...
  191.                 // I am not sure if it is OK to do a FreeLibrary after you have called InitCommonControls.
  192.                 // Isn't that a contradiction?
  193.                 //FreeLibrary(libComctl32);
  194.         }
  195.  
  196.         // Make "FoundrySlider" a subclass of "msctls_trackbar32" then
  197.         return MakeSimpleSubclass(targetClass, "msctls_trackbar32");
  198. }
  199.  
  200. Boolean Slider_Init_None(LPCSTR targetClass) {
  201.         // Make "FoundrySlider" a subclass of "STATIC" (making it invisible)
  202.         return MakeSimpleSubclass(targetClass, "STATIC");
  203. }
  204.