From: Andreas H. <ah...@us...> - 2004-06-03 15:34:23
|
Update of /cvsroot/jvcl/dev/JVCL3/run In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28559/run Modified Files: JvThemes.pas Log Message: Added VCL theming fix WM_PRINTCLIENT Index: JvThemes.pas =================================================================== RCS file: /cvsroot/jvcl/dev/JVCL3/run/JvThemes.pas,v retrieving revision 1.47 retrieving revision 1.48 diff -C2 -d -r1.47 -r1.48 *** JvThemes.pas 16 May 2004 06:25:26 -0000 1.47 --- JvThemes.pas 3 Jun 2004 15:34:11 -0000 1.48 *************** *** 1774,1782 **** end; - initialization - - finalization - FinalizeUnit(sUnitName); - {$ENDIF COMPILER7_UP} --- 1774,1777 ---- *************** *** 1797,1800 **** --- 1792,1906 ---- {$ENDIF JVCLThemesEnabled} + + {$IFDEF JVCLThemesEnabled} + + // copied from JclSysUtils.pas - keep them here + type + TDynamicIndexList = array [0..MaxInt div 16] of Word; + PDynamicIndexList = ^TDynamicIndexList; + TDynamicAddressList = array [0..MaxInt div 16] of Pointer; + PDynamicAddressList = ^TDynamicAddressList; + + function GetDynamicMethodCount(AClass: TClass): Integer; assembler; + asm + MOV EAX, [EAX].vmtDynamicTable + TEST EAX, EAX + JE @@Exit + MOVZX EAX, WORD PTR [EAX] + @@Exit: + end; + + function GetDynamicIndexList(AClass: TClass): PDynamicIndexList; assembler; + asm + MOV EAX, [EAX].vmtDynamicTable + ADD EAX, 2 + end; + + function GetDynamicAddressList(AClass: TClass): PDynamicAddressList; assembler; + asm + MOV EAX, [EAX].vmtDynamicTable + MOVZX EDX, WORD PTR [EAX] + ADD EAX, EDX + ADD EAX, EDX + ADD EAX, 2 + end; + + + var + OrgWinControlWMPaintClient: procedure(Instance: TObject; var Msg: TMessage); + + procedure FixedWMPaintClient(Instance: TObject; var Msg: TMessage); + var + idSave: Integer; + begin + if Msg.Msg = WM_PRINTCLIENT then + begin + idSave := SaveDC(HDC(Msg.WParam)); + try + OrgWinControlWMPaintClient(Instance, Msg); + finally + RestoreDC(HDC(Msg.WParam), idSave); + end; + end + else + OrgWinControlWMPaintClient(Instance, Msg); + end; + + function FindWMPrintClient: PPointer; + var + IdxList: PDynamicIndexList; + i: Integer; + begin + IdxList := GetDynamicIndexList(TWinControl); + for i := 0 to GetDynamicMethodCount(TWinControl) - 1 do + if IdxList[i] = WM_PRINTCLIENT then + begin + Result := @(GetDynamicAddressList(TWinControl)[i]); + Exit; + end; + Result := nil; + end; + + procedure InitializeWMPrintClientFix; + var + NewProc: Pointer; + Proc: PPointer; + n: Cardinal; + begin + Proc := FindWMPrintClient(); + if Proc <> nil then + begin + OrgWinControlWMPaintClient := Proc^; + NewProc := @FixedWMPaintClient; + WriteProcessMemory(GetCurrentProcess, Proc, @NewProc, SizeOf(NewProc), n); + end; + end; + + procedure FinalizeWMPrintClientFix; + var + NewProc: Pointer; + Proc: PPointer; + n: Cardinal; + begin + Proc := FindWMPrintClient(); + if Proc <> nil then + begin + NewProc := @OrgWinControlWMPaintClient; + WriteProcessMemory(GetCurrentProcess, Proc, @NewProc, SizeOf(NewProc), n); + end; + end; + + initialization + InitializeWMPrintClientFix; + + finalization + FinalizeWMPrintClientFix; + {$IFNDEF COMPILER7_UP} + FinalizeUnit(sUnitName); + {$ENDIF !COMPILER7UP} + + {$ENDIF JVCLThemesEnabled} + + end. |