Subversion Repositories filter_foundry

Compare Revisions

Regard whitespace Rev 476 → Rev 477

/trunk/slider_win.c
25,64 → 25,84
// https://misc.daniel-marschall.de/projects/filter_factory/sliders.html
 
// PLUGIN.DLL Sliders: This method will register the "slider" class used in dialogs.
#ifdef use_plugin_dll_sliders
typedef BOOL(__cdecl* f_RegisterSlider)(HINSTANCE hInstanceDll, DWORD* MessageID);
BOOL RegisterSlider(HINSTANCE hInstanceDll, DWORD* MessageID) {
f_RegisterSlider fRegisterSlider;
BOOL res;
 
if (!gdata->libPluginDll) return false;
fRegisterSlider = (f_RegisterSlider)(void*)GetProcAddress(gdata->libPluginDll, "RegisterSlider");
if (!gdata->pluginDllSliderInfo.hLib) return false;
fRegisterSlider = (f_RegisterSlider)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "RegisterSlider");
res = (fRegisterSlider != 0) ? fRegisterSlider(hInstanceDll, MessageID) : false;
return res;
}
#endif
 
// PLUGIN.DLL Sliders: This method will unregister the "slider" class used in dialogs.
#ifdef use_plugin_dll_sliders
typedef BOOL(__cdecl* f_UnRegisterSlider)(HINSTANCE hInstanceDll);
BOOL UnRegisterSlider(HINSTANCE hInstanceDll) {
f_UnRegisterSlider fUnRegisterSlider;
BOOL res;
 
if (!gdata->libPluginDll) return false;
fUnRegisterSlider = (f_UnRegisterSlider)(void*)GetProcAddress(gdata->libPluginDll, "UnRegisterSlider");
if (!gdata->pluginDllSliderInfo.hLib) return false;
fUnRegisterSlider = (f_UnRegisterSlider)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "UnRegisterSlider");
res = (fUnRegisterSlider != 0) ? fUnRegisterSlider(hInstanceDll) : false;
return res;
}
#endif
 
// PLUGIN.DLL Sliders: Set slider range (min/max)
#ifdef use_plugin_dll_sliders
typedef int(__cdecl* f_SetSliderRange)(HWND hWnd, int nMin, int nMax);
int SetSliderRange(HWND hWnd, int nMin, int nMax) {
f_SetSliderRange fSetSliderRange;
int res;
 
if (!gdata->libPluginDll) return 0;
fSetSliderRange = (f_SetSliderRange)(void*)GetProcAddress(gdata->libPluginDll, "SetSliderRange");
if (!gdata->pluginDllSliderInfo.hLib) return 0;
fSetSliderRange = (f_SetSliderRange)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "SetSliderRange");
res = (fSetSliderRange != 0) ? fSetSliderRange(hWnd, nMin, nMax) : 0;
return res;
}
#endif
 
// PLUGIN.DLL Sliders : Sets slider position
#ifdef use_plugin_dll_sliders
typedef int(__cdecl* f_SetSliderPos)(HWND hWnd, int nPos, BOOL bRepaint);
int SetSliderPos(HWND hWnd, int nPos, BOOL bRepaint) {
f_SetSliderPos fSetSliderPos;
int res;
 
if (!gdata->libPluginDll) return 0;
fSetSliderPos = (f_SetSliderPos)(void*)GetProcAddress(gdata->libPluginDll, "SetSliderPos");
if (!gdata->pluginDllSliderInfo.hLib) return 0;
fSetSliderPos = (f_SetSliderPos)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "SetSliderPos");
res = (fSetSliderPos != 0) ? fSetSliderPos(hWnd, nPos, bRepaint) : 0;
return res;
}
#else
int SetSliderPos(HWND hWnd, int nPos, BOOL bRepaint) {
// This dummy is required, otherwise ui_compat.h won't compile
return 0;
}
#endif
 
// PLUGIN.DLL Sliders : Get slider position
#ifdef use_plugin_dll_sliders
typedef int(__cdecl* f_GetSliderPos)(HWND hWnd, BOOL bPixelPosition);
int GetSliderPos(HWND hWnd, BOOL bPixelPosition) {
f_GetSliderPos fGetSliderPos;
int res;
 
if (!gdata->libPluginDll) return 0;
fGetSliderPos = (f_GetSliderPos)(void*)GetProcAddress(gdata->libPluginDll, "GetSliderPos");
if (!gdata->pluginDllSliderInfo.hLib) return 0;
fGetSliderPos = (f_GetSliderPos)(void*)GetProcAddress(gdata->pluginDllSliderInfo.hLib, "GetSliderPos");
res = (fGetSliderPos != 0) ? fGetSliderPos(hWnd, bPixelPosition) : 0;
return res;
}
#else
int GetSliderPos(HWND hWnd, BOOL bPixelPosition) {
// This dummy is required, otherwise ui_compat.h won't compile
return 0;
}
#endif
 
LRESULT CALLBACK DummyWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
return DefWindowProc(hwnd, uMsg, wParam, lParam);
164,22 → 184,26
#ifndef use_plugin_dll_sliders
return false;
#else
if (gdata->pluginDllSliderInitialized) return true;
if (gdata->pluginDllSliderInfo.initialized) return true;
 
if (!gdata->libPluginDll) {
if (!gdata->pluginDllSliderInfo.hLib) {
// DM 16.04.2022 : It is important that PLUGIN.DLL stays loaded, otherwise
// DialogBoxParamA crashes. Can be reproduced if all 8BX modules are disabled in Photoshop 7
// (they keep PLUGIN.DLL loaded).
gdata->libPluginDll = LoadLibrary(TEXT("Plugin.dll"));
gdata->pluginDllSliderInfo.hLib = LoadLibrary(TEXT("Plugin.dll"));
}
 
if (gdata->libPluginDll && RegisterSlider(hDllInstance, &gdata->pluginDllSliderMessageId)) {
gdata->pluginDllSliderInitialized = true;
 
if (gdata->pluginDllSliderInfo.hLib && RegisterSlider(hDllInstance, &gdata->pluginDllSliderInfo.messageId)) {
// Make "FoundrySlider" a subclass of "slider" then
return MakeSimpleSubclass(targetClass, TEXT("slider"));
if (MakeSimpleSubclass(targetClass, TEXT("slider"))) {
gdata->pluginDllSliderInfo.initialized = true;
return true;
}
else {
return false;
}
}
else {
// This can happen if PLUGIN.DLL is not existing
// It will also happen if a previous uninitialization failed (or was forgotten)
return false; // Fall back to Windows sliders
192,21 → 216,20
#ifndef use_plugin_dll_sliders
return;
#else
if (gdata->pluginDllSliderInitialized) {
if (UnRegisterSlider(hDllInstance)) {
gdata->pluginDllSliderInitialized = false;
if (!gdata->pluginDllSliderInfo.initialized) return;
 
if (gdata->libPluginDll) {
FreeLibrary(gdata->libPluginDll);
gdata->libPluginDll = 0;
}
}
else {
if (!UnRegisterSlider(hDllInstance)) {
simplealert((TCHAR*)TEXT("UnRegisterSlider failed"));
return;
}
 
gdata->pluginDllSliderInfo.initialized = false;
 
if (gdata->pluginDllSliderInfo.hLib) {
FreeLibrary(gdata->pluginDllSliderInfo.hLib);
gdata->pluginDllSliderInfo.hLib = 0;
}
#endif
 
}
 
typedef void(__stdcall* f_InitCommonControls)();
215,12 → 238,14
f_InitCommonControls fInitCommonControls;
f_InitCommonControlsEx fInitCommonControlsEx;
 
if (gdata->comctlSliderInfo.initialized) return true;
 
// Make sure that Comctl32 is loaded
if (!gdata->libComctl32) {
gdata->libComctl32 = LoadLibrary(TEXT("Comctl32.dll"));
if (!gdata->comctlSliderInfo.hLib) {
gdata->comctlSliderInfo.hLib = LoadLibrary(TEXT("Comctl32.dll"));
}
if (gdata->libComctl32) {
fInitCommonControlsEx = (f_InitCommonControlsEx)(void*)GetProcAddress(gdata->libComctl32, "InitCommonControlsEx");
if (gdata->comctlSliderInfo.hLib) {
fInitCommonControlsEx = (f_InitCommonControlsEx)(void*)GetProcAddress(gdata->comctlSliderInfo.hLib, "InitCommonControlsEx");
if (fInitCommonControlsEx != 0) {
INITCOMMONCONTROLSEX icce;
icce.dwSize = sizeof(INITCOMMONCONTROLSEX);
228,7 → 253,7
fInitCommonControlsEx(&icce);
}
else {
fInitCommonControls = (f_InitCommonControls)(void*)GetProcAddress(gdata->libComctl32, "InitCommonControls");
fInitCommonControls = (f_InitCommonControls)(void*)GetProcAddress(gdata->comctlSliderInfo.hLib, "InitCommonControls");
if (fInitCommonControls != 0) {
fInitCommonControls();
}
235,25 → 260,46
}
 
// Make "FoundrySlider" a subclass of "msctls_trackbar32" then
return MakeSimpleSubclass(targetClass, TEXT("msctls_trackbar32"));
if (MakeSimpleSubclass(targetClass, TEXT("msctls_trackbar32"))) {
gdata->comctlSliderInfo.initialized = true;
return true;
}
else {
return false;
}
}
else {
return false;
}
}
 
void Slider_Uninit_MsTrackbar() {
if (gdata->libComctl32 != 0) {
FreeLibrary(gdata->libComctl32);
gdata->libComctl32 = 0;
if (!gdata->comctlSliderInfo.initialized) return;
 
gdata->comctlSliderInfo.initialized = false;
 
if (gdata->comctlSliderInfo.hLib != 0) {
FreeLibrary(gdata->comctlSliderInfo.hLib);
gdata->comctlSliderInfo.hLib = 0;
}
}
 
Boolean Slider_Init_None(LPCTSTR targetClass) {
// Make "FoundrySlider" a subclass of "STATIC" (making it invisible)
return MakeSimpleSubclass(targetClass, WC_STATIC);
 
if (gdata->noneSliderInfo.initialized) return true;
 
if (MakeSimpleSubclass(targetClass, WC_STATIC)) {
gdata->noneSliderInfo.initialized = true;
return true;
}
else {
return false;
}
}
 
void Slider_Uninit_None() {
if (!gdata->noneSliderInfo.initialized) return;
 
// Nothing here
}