From: Remko B. <rem...@us...> - 2004-04-28 01:33:59
|
Update of /cvsroot/jvcl/dev/JVCL3/run In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26571 Modified Files: JvCaptionButton.pas Log Message: Mantis 1644 Index: JvCaptionButton.pas =================================================================== RCS file: /cvsroot/jvcl/dev/JVCL3/run/JvCaptionButton.pas,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** JvCaptionButton.pas 27 Apr 2004 07:58:07 -0000 1.22 --- JvCaptionButton.pas 28 Apr 2004 01:33:50 -0000 1.23 *************** *** 47,51 **** * Only tested on XP. - -----------------------------------------------------------------------------} // $Id$ --- 47,50 ---- *************** *** 305,308 **** --- 304,320 ---- {$IFDEF JVCLThemesEnabled} + { TransparentBlt is included in Windows 98 and later } + + const + Msimg32DLLName = 'Msimg32.dll'; + TransparentBltName = 'TransparentBlt'; + + type + TTransparentBlt = function(hdcDest: HDC; nXOriginDest, nYOriginDest, nWidthDest, hHeightDest: Integer; + hdcSrc: HDC; nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc: Integer; crTransparent: UINT): BOOL; stdcall; + + var + _TransparentBlt: TTransparentBlt = nil; + type TGlobalXPData = class *************** *** 314,317 **** --- 326,340 ---- FBitmapValid: Boolean; FClientCount: Integer; + FMsimg32Handle: THandle; + FTriedLoadMsimg32Dll: Boolean; + + { See http://www.truelaunchbar.com/spec/skins.html } + FSizingMargins: TMargins; + // FContentMargins: TMargins; + protected + procedure LoadMsimg32Dll; + procedure UnloadMsimg32Dll; + + function CanDrawTransparent: Boolean; public constructor Create; virtual; *************** *** 405,408 **** --- 428,551 ---- end; + function TransparentBltStretch(DestDC: HDC; const DestRect: TRect; + SourceDC: HDC; const SourceRect: TRect; const SizingMargins: TMargins; + const TransparentColor: TColor): Boolean; + var + ESourceWidth, ESourceHeight: Integer; + EDestWidth, EDestHeight: Integer; + LastOriginSource: TPoint; + LastOriginDest: TPoint; + begin + { Source Dest + + |--------------| |--------------------| + | A | B | C | | A | B | C | + |-- |------|---| |-- |------------|---| + | | | | | | | | + | D | E | F | | | | | + | | | | => | D | E | F | + |---|------|---| | | | | + | G | H | I | | | | | + |--------------| |--------------------| + | G | H | I | + |-- |------------|---| + } + ESourceWidth := SourceRect.Right - SourceRect.Left - SizingMargins.cxLeftWidth - SizingMargins.cxRightWidth; + ESourceHeight := SourceRect.Bottom - SourceRect.Top - SizingMargins.cyTopHeight - SizingMargins.cyBottomHeight; + EDestWidth := DestRect.Right - DestRect.Left - SizingMargins.cxLeftWidth - SizingMargins.cxRightWidth; + EDestHeight := DestRect.Bottom - DestRect.Top - SizingMargins.cyTopHeight - SizingMargins.cyBottomHeight; + + GetWindowOrgEx(SourceDC, LastOriginSource); + SetWindowOrgEx(SourceDC, LastOriginSource.X - SourceRect.Left, LastOriginSource.Y - SourceRect.Top, nil); + GetWindowOrgEx(DestDC, LastOriginDest); + SetWindowOrgEx(DestDC, LastOriginDest.X - DestRect.Left, LastOriginDest.Y - DestRect.Top, nil); + + { A } + _TransparentBlt( + DestDC, + 0, 0, SizingMargins.cxLeftWidth, SizingMargins.cyTopHeight, + SourceDC, + 0, 0, SizingMargins.cxLeftWidth, SizingMargins.cyTopHeight, + TransparentColor + ); + + { B } + _TransparentBlt( + DestDC, + SizingMargins.cxLeftWidth, 0, EDestWidth, SizingMargins.cyTopHeight, + SourceDC, + SizingMargins.cxLeftWidth, 0, ESourceWidth, SizingMargins.cyTopHeight, + TransparentColor + ); + + { C } + _TransparentBlt( + DestDC, + EDestWidth + SizingMargins.cxLeftWidth, 0, SizingMargins.cxRightWidth, SizingMargins.cyTopHeight, + SourceDC, + ESourceWidth + SizingMargins.cxLeftWidth, 0, SizingMargins.cxRightWidth, SizingMargins.cyTopHeight, + TransparentColor + ); + + { D } + _TransparentBlt( + DestDC, + 0, 0 + SizingMargins.cyTopHeight, SizingMargins.cxLeftWidth, EDestHeight, + SourceDC, + 0, 0 + SizingMargins.cyTopHeight, SizingMargins.cxLeftWidth, ESourceHeight, + TransparentColor + ); + + { E } + _TransparentBlt( + DestDC, + SizingMargins.cxLeftWidth, SizingMargins.cyTopHeight, EDestWidth, EDestHeight, + SourceDC, + SizingMargins.cxLeftWidth, SizingMargins.cyTopHeight, ESourceWidth, ESourceHeight, + TransparentColor + ); + + { F } + _TransparentBlt( + DestDC, + EDestWidth + SizingMargins.cxLeftWidth, SizingMargins.cyTopHeight, SizingMargins.cxRightWidth, EDestHeight, + SourceDC, + ESourceWidth + SizingMargins.cxLeftWidth, SizingMargins.cyTopHeight, SizingMargins.cxRightWidth, ESourceHeight, + TransparentColor + ); + + { G } + _TransparentBlt( + DestDC, + 0, EDestHeight + SizingMargins.cyTopHeight, SizingMargins.cxLeftWidth, SizingMargins.cyBottomHeight, + SourceDC, + 0, ESourceHeight + SizingMargins.cyTopHeight, SizingMargins.cxLeftWidth, SizingMargins.cyBottomHeight, + TransparentColor + ); + + { H } + _TransparentBlt( + DestDC, + SizingMargins.cxLeftWidth, EDestWidth + SizingMargins.cyTopHeight, EDestWidth, SizingMargins.cyBottomHeight, + SourceDC, + SizingMargins.cxLeftWidth, ESourceWidth + SizingMargins.cyTopHeight, ESourceWidth, SizingMargins.cyBottomHeight, + TransparentColor + ); + + { I } + _TransparentBlt( + DestDC, + EDestWidth + SizingMargins.cxLeftWidth, EDestHeight + SizingMargins.cyTopHeight, + SizingMargins.cxRightWidth, SizingMargins.cyTopHeight, + SourceDC, + ESourceWidth + SizingMargins.cxLeftWidth, ESourceHeight + SizingMargins.cyTopHeight, + SizingMargins.cxRightWidth, SizingMargins.cyTopHeight, + TransparentColor + ); + + SetWindowOrgEx(SourceDC, LastOriginSource.X, LastOriginSource.Y, nil); + SetWindowOrgEx(DestDC, LastOriginDest.X, LastOriginDest.Y, nil); + end; + //=== TGlobalXPData ========================================================== *************** *** 412,415 **** --- 555,565 ---- end; + function TGlobalXPData.CanDrawTransparent: Boolean; + begin + if not FTriedLoadMsimg32Dll then + LoadMsimg32Dll; + Result := Assigned(_TransparentBlt); + end; + constructor TGlobalXPData.Create; begin *************** *** 421,424 **** --- 571,575 ---- destructor TGlobalXPData.Destroy; begin + UnloadMsimg32Dll; FButtons.Free; inherited Destroy; *************** *** 428,437 **** const DrawRect: TRect); begin ! if FBitmapValid then ! // We could call TransparentBlt() for windows systems >= 98 ! StretchBltTransparent(HDC, DrawRect.Left, DrawRect.Top, DrawRect.Right - DrawRect.Left, DrawRect.Bottom - ! DrawRect.Top, ! FButtons.Canvas.Handle, 0, FButtonHeight * (State - 1), ! FButtonWidth, FButtonHeight, FButtons.Palette, clFuchsia) else DrawSimple(HDC, State, DrawRect); --- 579,600 ---- const DrawRect: TRect); begin ! if FBitmapValid and CanDrawTransparent then ! begin ! // Same Rect? ! if (DrawRect.Right - DrawRect.Left = FButtonWidth) and ! (DrawRect.Bottom - DrawRect.Top = FButtonHeight) then ! begin ! _TransparentBlt(HDC, DrawRect.Left, DrawRect.Top, ! DrawRect.Right - DrawRect.Left, DrawRect.Bottom - DrawRect.Top, ! FButtons.Canvas.Handle, 0, FButtonHeight * (State - 1), ! FButtonWidth, FButtonHeight, {FButtons.Palette,} clFuchsia) ! end ! else ! begin ! TransparentBltStretch(HDC, DrawRect, ! FButtons.Canvas.Handle, Bounds(0, FButtonHeight * (State - 1), ! FButtonWidth, FButtonHeight), FSizingMargins, clFuchsia) ! end ! end else DrawSimple(HDC, State, DrawRect); *************** *** 473,476 **** --- 636,647 ---- end; + procedure TGlobalXPData.LoadMsimg32Dll; + begin + FTriedLoadMsimg32Dll := True; + FMsimg32Handle := Windows.LoadLibrary(Msimg32DLLName); + if FMsimg32Handle > 0 then + _TransparentBlt := GetProcAddress(FMsimg32Handle, TransparentBltName); + end; + procedure TGlobalXPData.RemoveClient; begin *************** *** 484,488 **** --- 655,669 ---- end; + procedure TGlobalXPData.UnloadMsimg32Dll; + begin + _TransparentBlt := nil; + if FMsimg32Handle > 0 then + FreeLibrary(FMsimg32Handle); + FMsimg32Handle := 0; + end; + procedure TGlobalXPData.Update; + var + Details: TThemedElementDetails; begin FIsThemed := ThemeServices.ThemesAvailable and IsThemeActive and IsAppThemed; *************** *** 496,499 **** --- 677,690 ---- FButtonWidth := FButtons.Width; FButtonHeight := FButtons.Height div 8; + + Details := ThemeServices.GetElementDetails(twMinButtonNormal); + // with Details do + // if GetThemeMargins(ThemeServices.Theme[Element], 0, Part, State, + // TMT_CONTENTMARGINS, nil, FContentMargins) <> S_OK then + // FillChar(FContentMargins, SizeOf(FContentMargins), 0); + with Details do + if GetThemeMargins(ThemeServices.Theme[Element], 0, Part, State, + TMT_SIZINGMARGINS, nil, FSizingMargins) <> S_OK then + FillChar(FSizingMargins, SizeOf(FSizingMargins), 0); end; end; *************** *** 1146,1149 **** --- 1337,1347 ---- end; + {$IFDEF JVCLThemesEnabled} + function TJvCaptionButton.GetIsThemed: Boolean; + begin + Result := GlobalXPData.IsThemed; + end; + {$ENDIF JVCLThemesEnabled} + function TJvCaptionButton.GetParentForm: TCustomForm; begin *************** *** 1484,1487 **** --- 1682,1687 ---- begin inherited Loaded; + + CreateToolTip(ParentFormHandle); Redraw(rkTotalCaptionBar); end; *************** *** 2005,2015 **** end; - {$IFDEF JVCLThemesEnabled} - function TJvCaptionButton.GetIsThemed: Boolean; - begin - Result := GlobalXPData.IsThemed; - end; - {$ENDIF JVCLThemesEnabled} - //=== TJvCaptionButtonActionLink ============================================= --- 2205,2208 ---- |