mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 01:36:16 +02:00
Win32, Qt, Qt5, Gtk2: add support for image list to TSpeedButton and TBitBtn. Issue #33645
git-svn-id: trunk@57696 -
This commit is contained in:
parent
135231e273
commit
49d41ac113
@ -24,7 +24,7 @@ uses
|
||||
glib2, gtk2, gdk2, gdk2pixbuf,
|
||||
// LCL
|
||||
////////////////////////////////////////////////////
|
||||
LCLType, Controls, Buttons, Graphics, GraphType, Classes,
|
||||
LCLType, Controls, Buttons, Graphics, GraphType, ImgList, Classes,
|
||||
{$IFDEF DebugLCLComponents}
|
||||
LazLoggerBase,
|
||||
{$ENDIF}
|
||||
@ -348,15 +348,17 @@ var
|
||||
AGlyph: TBitmap;
|
||||
AIndex: Integer;
|
||||
AEffect: TGraphicsDrawEffect;
|
||||
AImageRes: TScaledImageListResolution;
|
||||
begin
|
||||
ShowGlyph := ABitBtn.CanShowGlyph;
|
||||
if ShowGlyph then
|
||||
begin
|
||||
ImageWidget := BitBtnInfo^.ImageWidget;
|
||||
AGlyph := TBitmap.Create;
|
||||
AValue.GetImageIndexAndEffect(AButtonState, AIndex, AEffect);
|
||||
if (AIndex <> -1) and (AValue.Images <> nil) then
|
||||
AValue.Images.GetBitmap(AIndex, AGlyph, AEffect);
|
||||
AValue.GetImageIndexAndEffect(AButtonState, ABitBtn.Font.PixelsPerInch,
|
||||
ABitBtn.GetCanvasScaleFactor, AImageRes, AIndex, AEffect);
|
||||
if (AIndex <> -1) and (AImageRes.Resolution <> nil) then
|
||||
AImageRes.GetBitmap(AIndex, AGlyph, AEffect);
|
||||
ShowGlyph := not AGlyph.Empty;
|
||||
if ShowGlyph then
|
||||
begin
|
||||
|
@ -30,6 +30,7 @@ uses
|
||||
SysUtils, Types,
|
||||
// LCL
|
||||
Controls, LCLType, Forms, InterfaceBase, Buttons, Graphics, GraphType,
|
||||
ImgList,
|
||||
// Widgetset
|
||||
WSProc, WSButtons, WSLCLClasses;
|
||||
|
||||
@ -91,6 +92,7 @@ var
|
||||
AEffect: TGraphicsDrawEffect;
|
||||
Mode: QIconMode;
|
||||
ASize: TSize;
|
||||
AImageRes: TScaledImageListResolution;
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ABitBtn, 'SetGlyph') then
|
||||
Exit;
|
||||
@ -104,16 +106,18 @@ begin
|
||||
|
||||
for Mode := QIconNormal to QIconSelected do
|
||||
begin
|
||||
AValue.GetImageIndexAndEffect(IconModeToButtonState[Mode], AIndex, AEffect);
|
||||
AValue.Images.GetBitmap(AIndex, AGlyph, AEffect);
|
||||
AValue.GetImageIndexAndEffect(IconModeToButtonState[Mode],
|
||||
ABitBtn.Font.PixelsPerInch, ABitBtn.GetCanvasScaleFactor,
|
||||
AImageRes, AIndex, AEffect);
|
||||
AImageRes.GetBitmap(AIndex, AGlyph, AEffect);
|
||||
QPixmap_fromImage(APixmap, TQtImage(AGlyph.Handle).Handle);
|
||||
QIcon_addPixmap(AIcon, APixmap, Mode, QIconOn);
|
||||
end;
|
||||
QPixmap_destroy(APixmap);
|
||||
AGlyph.Free;
|
||||
|
||||
ASize.cx := AValue.Images.Width;
|
||||
ASize.cy := AValue.Images.Height;
|
||||
ASize.cx := AImageRes.Width;
|
||||
ASize.cy := AImageRes.Height;
|
||||
TQtBitBtn(ABitBtn.Handle).setIconSize(@ASize);
|
||||
end;
|
||||
|
||||
|
@ -29,6 +29,7 @@ uses
|
||||
SysUtils, Types,
|
||||
// LCL
|
||||
Controls, LCLType, Forms, InterfaceBase, Buttons, Graphics, GraphType,
|
||||
ImgList,
|
||||
// Widgetset
|
||||
WSProc, WSButtons, WSLCLClasses;
|
||||
|
||||
@ -90,6 +91,7 @@ var
|
||||
AEffect: TGraphicsDrawEffect;
|
||||
Mode: QIconMode;
|
||||
ASize: TSize;
|
||||
AImageRes: TScaledImageListResolution;
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ABitBtn, 'SetGlyph') then
|
||||
Exit;
|
||||
@ -103,16 +105,18 @@ begin
|
||||
|
||||
for Mode := QIconNormal to QIconSelected do
|
||||
begin
|
||||
AValue.GetImageIndexAndEffect(IconModeToButtonState[Mode], AIndex, AEffect);
|
||||
AValue.Images.GetBitmap(AIndex, AGlyph, AEffect);
|
||||
AValue.GetImageIndexAndEffect(IconModeToButtonState[Mode],
|
||||
ABitBtn.Font.PixelsPerInch, ABitBtn.GetCanvasScaleFactor,
|
||||
AImageRes, AIndex, AEffect);
|
||||
AImageRes.GetBitmap(AIndex, AGlyph, AEffect);
|
||||
QPixmap_fromImage(APixmap, TQtImage(AGlyph.Handle).Handle);
|
||||
QIcon_addPixmap(AIcon, APixmap, Mode, QIconOn);
|
||||
end;
|
||||
QPixmap_destroy(APixmap);
|
||||
AGlyph.Free;
|
||||
|
||||
ASize.cx := AValue.Images.Width;
|
||||
ASize.cy := AValue.Images.Height;
|
||||
ASize.cx := AImageRes.Width;
|
||||
ASize.cy := AImageRes.Height;
|
||||
TQtBitBtn(ABitBtn.Handle).setIconSize(@ASize);
|
||||
end;
|
||||
|
||||
|
@ -29,7 +29,7 @@ uses
|
||||
// uncomment only when needed for registration
|
||||
////////////////////////////////////////////////////
|
||||
Windows, CommCtrl, Classes, Buttons, Graphics, GraphType, Controls,
|
||||
LCLType, LCLMessageGlue, LMessages, LazUTF8, Themes,
|
||||
LCLType, LCLMessageGlue, LMessages, LazUTF8, Themes, ImgList,
|
||||
////////////////////////////////////////////////////
|
||||
WSProc, WSButtons, Win32WSControls, Win32WSImgList,
|
||||
UxTheme, Win32Themes;
|
||||
@ -134,6 +134,9 @@ var
|
||||
ButtonImageList: BUTTON_IMAGELIST;
|
||||
I: integer;
|
||||
ButtonCaptionW: widestring;
|
||||
AIndex: Integer;
|
||||
AImageRes: TScaledImageListResolution;
|
||||
AEffect: TGraphicsDrawEffect;
|
||||
|
||||
procedure DrawBitmap(AState: TButtonState; UseThemes, AlphaDraw: Boolean);
|
||||
const
|
||||
@ -151,8 +154,6 @@ var
|
||||
glyphWidth, glyphHeight: integer;
|
||||
OldBitmapHandle: HBITMAP; // Handle of the provious bitmap in hdcNewBitmap
|
||||
OldTextAlign: Integer;
|
||||
AIndex: Integer;
|
||||
AEffect: TGraphicsDrawEffect;
|
||||
TmpDC: HDC;
|
||||
PaintBuffer: HPAINTBUFFER;
|
||||
Options: DTTOpts;
|
||||
@ -201,13 +202,15 @@ var
|
||||
begin
|
||||
if (srcWidth <> 0) and (srcHeight <> 0) then
|
||||
begin
|
||||
TBitBtnAceess(BitBtn).FButtonGlyph.GetImageIndexAndEffect(AState, AIndex, AEffect);
|
||||
TWin32WSCustomImageListResolution.DrawToDC(TBitBtnAceess(BitBtn).FButtonGlyph.Images.ResolutionForPPI[0, 96, 1].Resolution, AIndex,
|
||||
TmpDC, Rect(XDestBitmap, YDestBitmap, glyphWidth, glyphHeight),
|
||||
TBitBtnAceess(BitBtn).FButtonGlyph.Images.BkColor,
|
||||
TBitBtnAceess(BitBtn).FButtonGlyph.Images.BlendColor, AEffect,
|
||||
TBitBtnAceess(BitBtn).FButtonGlyph.Images.DrawingStyle,
|
||||
TBitBtnAceess(BitBtn).FButtonGlyph.Images.ImageType);
|
||||
TBitBtnAceess(BitBtn).FButtonGlyph.GetImageIndexAndEffect(AState, BitBtn.Font.PixelsPerInch, 1,
|
||||
AImageRes, AIndex, AEffect);
|
||||
TWin32WSCustomImageListResolution.DrawToDC(
|
||||
AImageRes.Resolution,
|
||||
AIndex, TmpDC, Rect(XDestBitmap, YDestBitmap, glyphWidth, glyphHeight),
|
||||
AImageRes.Resolution.ImageList.BkColor,
|
||||
AImageRes.Resolution.ImageList.BlendColor, AEffect,
|
||||
AImageRes.Resolution.ImageList.DrawingStyle,
|
||||
AImageRes.Resolution.ImageList.ImageType);
|
||||
end;
|
||||
end else
|
||||
begin
|
||||
@ -217,7 +220,8 @@ var
|
||||
|
||||
if (srcWidth <> 0) and (srcHeight <> 0) then
|
||||
begin
|
||||
TBitBtnAceess(BitBtn).FButtonGlyph.GetImageIndexAndEffect(AState, AIndex, AEffect);
|
||||
TBitBtnAceess(BitBtn).FButtonGlyph.GetImageIndexAndEffect(AState, BitBtn.Font.PixelsPerInch, 1,
|
||||
AImageRes, AIndex, AEffect);
|
||||
if UseThemes and not AlphaDraw then
|
||||
begin
|
||||
// non-themed winapi wants white/other as background/picture-disabled colors
|
||||
@ -229,12 +233,13 @@ var
|
||||
if (AEffect = gdeDisabled) and not AlphaDraw then
|
||||
AEffect := gde1Bit;
|
||||
|
||||
TWin32WSCustomImageListResolution.DrawToDC(TBitBtnAceess(BitBtn).FButtonGlyph.Images.ResolutionForPPI[0, 96, 1].Resolution, AIndex,
|
||||
TmpDC, Rect(XDestBitmap, YDestBitmap, glyphWidth, glyphHeight),
|
||||
TBitBtnAceess(BitBtn).FButtonGlyph.Images.BkColor,
|
||||
TBitBtnAceess(BitBtn).FButtonGlyph.Images.BlendColor, AEffect,
|
||||
TBitBtnAceess(BitBtn).FButtonGlyph.Images.DrawingStyle,
|
||||
TBitBtnAceess(BitBtn).FButtonGlyph.Images.ImageType);
|
||||
TWin32WSCustomImageListResolution.DrawToDC(
|
||||
AImageRes.Resolution,
|
||||
AIndex, TmpDC, Rect(XDestBitmap, YDestBitmap, glyphWidth, glyphHeight),
|
||||
AImageRes.Resolution.ImageList.BkColor,
|
||||
AImageRes.Resolution.ImageList.BlendColor, AEffect,
|
||||
AImageRes.Resolution.ImageList.DrawingStyle,
|
||||
AImageRes.Resolution.ImageList.ImageType);
|
||||
end;
|
||||
end;
|
||||
if PaintBuffer = 0 then
|
||||
@ -297,10 +302,10 @@ begin
|
||||
|
||||
if BitBtn.CanShowGlyph then
|
||||
begin
|
||||
srcWidth := BitBtn.Glyph.Width;
|
||||
srcHeight := BitBtn.Glyph.Height;
|
||||
if BitBtn.NumGlyphs > 1 then
|
||||
srcWidth := srcWidth div BitBtn.NumGlyphs;
|
||||
TBitBtnAceess(BitBtn).FButtonGlyph.GetImageIndexAndEffect(Low(TButtonState), BitBtn.Font.PixelsPerInch, 1,
|
||||
AImageRes, AIndex, AEffect);
|
||||
srcWidth := AImageRes.Width;
|
||||
srcHeight := AImageRes.Height;
|
||||
if (srcWidth = 0) or (srcHeight = 0) then
|
||||
ASpacing := 0;
|
||||
end else
|
||||
|
Loading…
Reference in New Issue
Block a user