mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-11 18:36:10 +02:00
lcl: graphic changes
- don't create dummy mask for icon if image.MaskBitsPerPixel = 0 - win32: create dummy mask for icon if no mask is present since windows cannot live without any mask - force Change at correct place of TIcon.AssignImage - clear not only saved stream on TRasterImage.LoadFromStream but all handles too since they are not valid after loading another data to an image git-svn-id: trunk@16397 -
This commit is contained in:
parent
41d7c28b6b
commit
196b1d0098
@ -1184,7 +1184,7 @@ type
|
|||||||
procedure Assign(Source: TPersistent); override;
|
procedure Assign(Source: TPersistent); override;
|
||||||
procedure Clear; override;
|
procedure Clear; override;
|
||||||
procedure BeginUpdate(ACanvasOnly: Boolean = False);
|
procedure BeginUpdate(ACanvasOnly: Boolean = False);
|
||||||
procedure EndUpdate;
|
procedure EndUpdate(AStreamIsValid: Boolean = False);
|
||||||
procedure FreeImage;
|
procedure FreeImage;
|
||||||
function BitmapHandleAllocated: boolean; virtual; abstract;
|
function BitmapHandleAllocated: boolean; virtual; abstract;
|
||||||
function MaskHandleAllocated: boolean; virtual; abstract;
|
function MaskHandleAllocated: boolean; virtual; abstract;
|
||||||
|
@ -311,12 +311,14 @@ begin
|
|||||||
else
|
else
|
||||||
if Source is TRasterImage
|
if Source is TRasterImage
|
||||||
then begin
|
then begin
|
||||||
|
BeginUpdate;
|
||||||
Clear;
|
Clear;
|
||||||
|
|
||||||
with TRasterImage(Source) do
|
with TRasterImage(Source) do
|
||||||
Self.Add(PixelFormat, Height, Width);
|
Self.Add(PixelFormat, Height, Width);
|
||||||
|
|
||||||
AssignImage(TRasterImage(Source));
|
AssignImage(TRasterImage(Source));
|
||||||
|
EndUpdate;
|
||||||
Exit;
|
Exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -620,7 +622,10 @@ begin
|
|||||||
if MaskHandleAllocated then exit;
|
if MaskHandleAllocated then exit;
|
||||||
|
|
||||||
ImagePtr := GetRawImagePtr;
|
ImagePtr := GetRawImagePtr;
|
||||||
if (ImagePtr = nil) or (ImagePtr^.Description.Format = ricfNone) then Exit;
|
if (ImagePtr = nil) or
|
||||||
|
(ImagePtr^.Description.Format = ricfNone) or
|
||||||
|
(ImagePtr^.Description.MaskBitsPerPixel = 0) then
|
||||||
|
Exit;
|
||||||
|
|
||||||
MaskImage.Init;
|
MaskImage.Init;
|
||||||
MaskImage.Description := ImagePtr^.Description.GetDescriptionFromMask;
|
MaskImage.Description := ImagePtr^.Description.GetDescriptionFromMask;
|
||||||
@ -1203,8 +1208,8 @@ begin
|
|||||||
if FSharedImage.FHandle <> 0 then Exit;
|
if FSharedImage.FHandle <> 0 then Exit;
|
||||||
|
|
||||||
IconInfo.fIcon := True;
|
IconInfo.fIcon := True;
|
||||||
IconInfo.hbmMask := MaskHandle;
|
|
||||||
IconInfo.hbmColor := BitmapHandle;
|
IconInfo.hbmColor := BitmapHandle;
|
||||||
|
IconInfo.hbmMask := MaskHandle;
|
||||||
FSharedImage.FHandle := WidgetSet.CreateIconIndirect(@IconInfo);
|
FSharedImage.FHandle := WidgetSet.CreateIconIndirect(@IconInfo);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ begin
|
|||||||
DestCanvas.Changed;
|
DestCanvas.Changed;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TRasterImage.EndUpdate;
|
procedure TRasterImage.EndUpdate(AStreamIsValid: Boolean = False);
|
||||||
begin
|
begin
|
||||||
if FUpdatecount = 0
|
if FUpdatecount = 0
|
||||||
then raise EInvalidGraphicOperation.Create(rsRasterImageEndUpdate);
|
then raise EInvalidGraphicOperation.Create(rsRasterImageEndUpdate);
|
||||||
@ -262,7 +262,8 @@ begin
|
|||||||
|
|
||||||
if not FUpdateCanvasOnly
|
if not FUpdateCanvasOnly
|
||||||
then FreeCanvasContext;
|
then FreeCanvasContext;
|
||||||
FreeSaveStream;
|
if not AStreamIsValid
|
||||||
|
then FreeSaveStream;
|
||||||
Changed(Self);
|
Changed(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -417,12 +418,11 @@ var
|
|||||||
WorkStream: TMemoryStream;
|
WorkStream: TMemoryStream;
|
||||||
OldPos, NewSize: Int64;
|
OldPos, NewSize: Int64;
|
||||||
begin
|
begin
|
||||||
|
BeginUpdate;
|
||||||
UnshareImage(False);
|
UnshareImage(False);
|
||||||
|
Clear; // clear old saved stream, allocated handles, etc
|
||||||
if ASize = 0
|
if ASize = 0
|
||||||
then begin
|
then Exit;
|
||||||
Clear;
|
|
||||||
Exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
WorkStream := nil;
|
WorkStream := nil;
|
||||||
try
|
try
|
||||||
@ -431,7 +431,6 @@ begin
|
|||||||
OldPos := AStream.Position;
|
OldPos := AStream.Position;
|
||||||
WorkStream.CopyFrom(AStream, ASize);
|
WorkStream.CopyFrom(AStream, ASize);
|
||||||
WorkStream.Position := 0;
|
WorkStream.Position := 0;
|
||||||
FreeSaveStream;
|
|
||||||
ReadStream(WorkStream, ASize);
|
ReadStream(WorkStream, ASize);
|
||||||
NewSize := WorkStream.Position;
|
NewSize := WorkStream.Position;
|
||||||
if NewSize < ASize
|
if NewSize < ASize
|
||||||
@ -448,8 +447,7 @@ begin
|
|||||||
// if something went wrong, free the workstream
|
// if something went wrong, free the workstream
|
||||||
WorkStream.Free;
|
WorkStream.Free;
|
||||||
end;
|
end;
|
||||||
if FUpdateCount = 0
|
EndUpdate(True);
|
||||||
then Changed(Self);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TRasterImage.GetRawImage: TRawImage;
|
function TRasterImage.GetRawImage: TRawImage;
|
||||||
|
@ -934,7 +934,7 @@ end;
|
|||||||
function TWin32WidgetSet.CreateIconIndirect(IconInfo: PIconInfo): HICON;
|
function TWin32WidgetSet.CreateIconIndirect(IconInfo: PIconInfo): HICON;
|
||||||
var
|
var
|
||||||
bmp: Windows.TBitmap;
|
bmp: Windows.TBitmap;
|
||||||
hbm: HBITMAP;
|
hbm1, hbm2: HBITMAP;
|
||||||
SrcDataSize, DataSize: PtrUInt;
|
SrcDataSize, DataSize: PtrUInt;
|
||||||
SrcData, Data: PByte;
|
SrcData, Data: PByte;
|
||||||
Res: Boolean;
|
Res: Boolean;
|
||||||
@ -965,19 +965,31 @@ begin
|
|||||||
|
|
||||||
if Res then
|
if Res then
|
||||||
begin
|
begin
|
||||||
hbm := CreateBitmap(bmp.bmWidth, bmp.bmHeight shl 1, bmp.bmPlanes, 1, Data);
|
hbm1 := CreateBitmap(bmp.bmWidth, bmp.bmHeight shl 1, bmp.bmPlanes, 1, Data);
|
||||||
IconInfo^.hbmColor := 0;
|
IconInfo^.hbmColor := 0;
|
||||||
IconInfo^.hbmMask := hbm;
|
IconInfo^.hbmMask := hbm1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
FreeMem(Data);
|
FreeMem(Data);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
hbm := 0;
|
hbm1 := 0;
|
||||||
|
|
||||||
|
if (IconInfo^.hbmMask = 0) and (IconInfo^.hbmColor <> 0) and (GetObject(IconInfo^.hbmColor, SizeOf(bmp), @bmp) = SizeOf(bmp)) then
|
||||||
|
begin
|
||||||
|
hbm2 := CreateBitmap(bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, 1, nil);
|
||||||
|
IconInfo^.hbmMask := hbm2;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
hbm2 := 0;
|
||||||
|
|
||||||
Result := Windows.CreateIconIndirect(IconInfo);
|
Result := Windows.CreateIconIndirect(IconInfo);
|
||||||
|
|
||||||
if hbm <> 0 then
|
if hbm1 <> 0 then
|
||||||
DeleteObject(hbm);
|
DeleteObject(hbm1);
|
||||||
|
|
||||||
|
if hbm2 <> 0 then
|
||||||
|
DeleteObject(hbm2);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWin32WidgetSet.CreatePatternBrush(ABitmap: HBITMAP): HBRUSH;
|
function TWin32WidgetSet.CreatePatternBrush(ABitmap: HBITMAP): HBRUSH;
|
||||||
|
Loading…
Reference in New Issue
Block a user