Subversion Repositories filter_foundry

Rev

Rev 435 | Rev 444 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 435 Rev 439
Line 26... Line 26...
26
 
26
 
27
#include <windows.h>
27
#include <windows.h>
28
#include <commctrl.h>
28
#include <commctrl.h>
29
 
29
 
30
#include "ff.h"
30
#include "ff.h"
31
 
-
 
-
 
31
#include "slider_win.h"
32
#include "version.h"
32
#include "version.h"
33
 
33
 
34
#define use_plugin_dll_sliders
-
 
35
 
-
 
36
HWND preview_hwnd;
34
HWND preview_hwnd;
37
HCURSOR hCurHandOpen;
35
HCURSOR hCurHandOpen;
38
HCURSOR hCurHandGrab;
36
HCURSOR hCurHandGrab;
39
 
37
 
40
HCURSOR hCurHandQuestion;
38
HCURSOR hCurHandQuestion;
41
HICON hIconCautionSign;
39
HICON hIconCautionSign;
42
 
40
 
43
// PLUGIN.DLL Sliders: This method will register the "slider" class used in dialogs.
-
 
44
typedef int(__cdecl* f_RegisterSlider)(HINSTANCE hInstanceDll, DWORD* MessageID);
-
 
45
int RegisterSlider(HINSTANCE hInstanceDll, DWORD* MessageID) {
-
 
46
        f_RegisterSlider fRegisterSlider;
-
 
47
 
-
 
48
        if (!gdata->pluginDllModule) return 0;
-
 
49
        fRegisterSlider = (f_RegisterSlider)(void*)GetProcAddress(gdata->pluginDllModule, "RegisterSlider");
-
 
50
        if (fRegisterSlider != 0) {
-
 
51
                return fRegisterSlider(hInstanceDll, MessageID);
-
 
52
        }
-
 
53
        else {
-
 
54
                return 0;
-
 
55
        }
-
 
56
}
-
 
57
 
-
 
58
// PLUGIN.DLL Sliders: This method will unregister the "slider" class used in dialogs.
-
 
59
typedef int(__cdecl* f_UnregisterSlider)(HINSTANCE hInstanceDll);
-
 
60
int UnregisterSlider(HINSTANCE hInstanceDll) {
-
 
61
        f_UnregisterSlider fUnregisterSlider;
-
 
62
 
-
 
63
        if (!gdata->pluginDllModule) return 0;
-
 
64
        fUnregisterSlider = (f_UnregisterSlider)(void*)GetProcAddress(gdata->pluginDllModule, "UnregisterSlider");
-
 
65
        if (fUnregisterSlider != 0) {
-
 
66
                return fUnregisterSlider(hInstanceDll);
-
 
67
        }
-
 
68
        else {
-
 
69
                return 0;
-
 
70
        }
-
 
71
}
-
 
72
 
-
 
73
// PLUGIN.DLL Sliders: Set slider range (min/max)
-
 
74
typedef int(__cdecl* f_SetSliderRange)(HWND hWnd, int nMin, int nMax);
-
 
75
int SetSliderRange(HWND hWnd, int nMin, int nMax) {
-
 
76
        f_SetSliderRange fSetSliderRange;
-
 
77
 
-
 
78
        if (!gdata->pluginDllModule) return 0;
-
 
79
        fSetSliderRange = (f_SetSliderRange)(void*)GetProcAddress(gdata->pluginDllModule, "SetSliderRange");
-
 
80
        if (fSetSliderRange != 0) {
-
 
81
                return fSetSliderRange(hWnd, nMin, nMax);
-
 
82
        }
-
 
83
        else {
-
 
84
                return 0;
-
 
85
        }
-
 
86
}
-
 
87
 
-
 
88
// PLUGIN.DLL Sliders : Sets slider position
-
 
89
typedef int(__cdecl* f_SetSliderPos)(HWND hWnd, int nPos, BOOL bRepaint);
-
 
90
int SetSliderPos(HWND hWnd, int nPos, BOOL bRepaint) {
-
 
91
        f_SetSliderPos fSetSliderPos;
-
 
92
 
-
 
93
        if (!gdata->pluginDllModule) return 0;
-
 
94
        fSetSliderPos = (f_SetSliderPos)(void*)GetProcAddress(gdata->pluginDllModule, "SetSliderPos");
-
 
95
        if (fSetSliderPos != 0) {
-
 
96
                return fSetSliderPos(hWnd, nPos, bRepaint);
-
 
97
        }
-
 
98
        else {
-
 
99
                return 0;
-
 
100
        }
-
 
101
}
-
 
102
 
-
 
103
// PLUGIN.DLL Sliders : Get slider position
-
 
104
typedef int(__cdecl* f_GetSliderPos)(HWND hWnd, BOOL bPixelPosition);
-
 
105
int GetSliderPos(HWND hWnd, BOOL bPixelPosition) {
-
 
106
        f_GetSliderPos fGetSliderPos;
-
 
107
 
-
 
108
        if (!gdata->pluginDllModule) return 0;
-
 
109
        fGetSliderPos = (f_GetSliderPos)(void*)GetProcAddress(gdata->pluginDllModule, "GetSliderPos");
-
 
110
        if (fGetSliderPos != 0) {
-
 
111
                int res = fGetSliderPos(hWnd, bPixelPosition);
-
 
112
                return res;
-
 
113
        }
-
 
114
        else {
-
 
115
                return 0;
-
 
116
        }
-
 
117
}
-
 
118
 
-
 
119
extern HINSTANCE hDllInstance;
41
extern HINSTANCE hDllInstance;
120
 
42
 
121
void DoAbout(AboutRecordPtr pb){
43
void DoAbout(AboutRecordPtr pb){
122
        char text[1000];
44
        char text[1000];
123
        char title[200];
45
        char title[200];
Line 400... Line 322...
400
        }
322
        }
401
 
323
 
402
        return true;
324
        return true;
403
}
325
}
404
 
326
 
405
Boolean MakeSimpleSubclass(LPCSTR targetClass, LPCSTR sourceClass) {
-
 
406
        WNDCLASS clx;
-
 
407
 
-
 
408
        if (GetClassInfoA(hDllInstance, sourceClass, &clx) != 0) {
-
 
409
                clx.lpszClassName = targetClass;
-
 
410
                if (RegisterClass(&clx) == 0) {
-
 
411
                        char s[100];
-
 
412
                        strcpy(s, "RegisterClass failed: ");
-
 
413
                        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, s + strlen(s), 0x100, NULL);
-
 
414
                        dbg(s);
-
 
415
                        return false;
-
 
416
                }
-
 
417
                else {
-
 
418
                        return true;
-
 
419
                }
-
 
420
        }
-
 
421
        else {
-
 
422
                return false;
-
 
423
        }
-
 
424
}
-
 
425
 
-
 
426
void Slider_Uninit_PluginDll() {
-
 
427
        WNDCLASS clx;
-
 
428
 
-
 
429
        #ifndef use_plugin_dll_sliders
-
 
430
        return;
-
 
431
        #endif
-
 
432
 
-
 
433
        if (GetClassInfo(hDllInstance, "slider", &clx) != 0) {
-
 
434
                UnregisterSlider(hDllInstance);
-
 
435
        }
-
 
436
        if (gdata->pluginDllModule) {
-
 
437
                FreeLibrary(gdata->pluginDllModule);
-
 
438
                gdata->pluginDllModule = 0;
-
 
439
        }
-
 
440
}
-
 
441
 
-
 
442
Boolean Slider_Init_PluginDll(LPCSTR targetClass) {
-
 
443
        DWORD sliderMsgId;
-
 
444
 
-
 
445
        #ifndef use_plugin_dll_sliders
-
 
446
        return false;
-
 
447
        #endif
-
 
448
 
-
 
449
        // Try loading PLUGIN.DLL (only Photoshop) in order to register the class "slider"
-
 
450
        gdata->pluginDllModule = LoadLibraryA("PLUGIN.DLL");
-
 
451
        if (!gdata->pluginDllModule) return false;
-
 
452
        sliderMsgId = 0; // important
-
 
453
        RegisterSlider(hDllInstance, &sliderMsgId);
-
 
454
        if (sliderMsgId != 0) {
-
 
455
                // RegisterSlider will "remember" if it gave you a message ID before,
-
 
456
                // and it will NOT give it to you again! (instead, the output variable stays untouched).
-
 
457
                // The problem: PLUGIN.DLL stays loaded the whole time, so it keeps remembering, while Filter Foundry
-
 
458
                // loses its internal state every time the window is closed.
-
 
459
                // So, we keep the message ID in the global (persistant) data, so we remember it.
-
 
460
                gdata->pluginDllSliderMessageId = sliderMsgId;
-
 
461
        }
-
 
462
 
-
 
463
        // Make "FoundrySlider" a subclass of "slider" then
-
 
464
        return MakeSimpleSubclass(targetClass, "slider");
-
 
465
}
-
 
466
 
-
 
467
typedef void(__stdcall* f_InitCommonControls)();
-
 
468
typedef BOOL(__stdcall* f_InitCommonControlsEx)(const INITCOMMONCONTROLSEX* picce);
-
 
469
Boolean Slider_Init_MsTrackbar(LPCSTR targetClass) {
-
 
470
        f_InitCommonControls fInitCommonControls;
-
 
471
        f_InitCommonControlsEx fInitCommonControlsEx;
-
 
472
        HMODULE libComctl32;
-
 
473
 
-
 
474
        // Make sure that Comctl32 is loaded
-
 
475
        libComctl32 = LoadLibraryA("Comctl32.dll");
-
 
476
        if (libComctl32) {
-
 
477
                fInitCommonControlsEx = (f_InitCommonControlsEx)(void*)GetProcAddress(libComctl32, "InitCommonControlsEx");
-
 
478
                if (fInitCommonControlsEx != 0) {
-
 
479
                        INITCOMMONCONTROLSEX icce;
-
 
480
                        icce.dwSize = sizeof(INITCOMMONCONTROLSEX);
-
 
481
                        icce.dwICC = ICC_BAR_CLASSES;
-
 
482
                        fInitCommonControlsEx(&icce);
-
 
483
                }
-
 
484
                else {
-
 
485
                        fInitCommonControls = (f_InitCommonControls)(void*)GetProcAddress(libComctl32, "InitCommonControls");
-
 
486
                        if (fInitCommonControls != 0) {
-
 
487
                                fInitCommonControls();
-
 
488
                        }
-
 
489
                }
-
 
490
                // There seems to be a bug in Windows NT 3.11 (if PLUGIN.DLL does not exist):
-
 
491
                // If we call FreeLibrary, and then open Filter Foundry again,
-
 
492
                // then you get an error message "BRUSHES" cannot initialize Comctl32.dll ...
-
 
493
                // I am not sure if it is OK to do a FreeLibrary after you have called InitCommonControls.
-
 
494
                // Isn't that a contradiction?
-
 
495
                //FreeLibrary(libComctl32);
-
 
496
        }
-
 
497
 
-
 
498
        // Make "FoundrySlider" a subclass of "msctls_trackbar32" then
-
 
499
        return MakeSimpleSubclass(targetClass, "msctls_trackbar32");
-
 
500
}
-
 
501
 
-
 
502
Boolean Slider_Init_None(LPCSTR targetClass) {
-
 
503
        // Make "FoundrySlider" a subclass of "STATIC" (making it invisible)
-
 
504
        return MakeSimpleSubclass(targetClass, "STATIC");
-
 
505
}
-
 
506
 
-
 
507
Boolean maindialog(FilterRecordPtr pb){
327
Boolean maindialog(FilterRecordPtr pb){
508
        PlatformData *p;
328
        PlatformData *p;
509
        INT_PTR res;
329
        INT_PTR res;
510
 
330
 
511
        // First try to use the sliders from PLUGIN.DLL (only Photoshop)
331
        // First try to use the sliders from PLUGIN.DLL (only Photoshop)