* Start handle rework. Splitup of internal WS referencedata and public widgetsetspecific references (handle/pointer/XID/...)

git-svn-id: trunk@13178 -
This commit is contained in:
marc 2007-12-06 01:17:52 +00:00
parent 6910f76cfd
commit 425f7eb912
12 changed files with 235 additions and 109 deletions

1
.gitattributes vendored
View File

@ -3277,6 +3277,7 @@ lcl/widgetset/wsmaskedit.pp svneol=native#text/pascal
lcl/widgetset/wsmenus.pp svneol=native#text/pascal lcl/widgetset/wsmenus.pp svneol=native#text/pascal
lcl/widgetset/wspairsplitter.pp svneol=native#text/pascal lcl/widgetset/wspairsplitter.pp svneol=native#text/pascal
lcl/widgetset/wsproc.pp svneol=native#text/pascal lcl/widgetset/wsproc.pp svneol=native#text/pascal
lcl/widgetset/wsreferences.pp svneol=native#text/pascal
lcl/widgetset/wsspin.pp svneol=native#text/pascal lcl/widgetset/wsspin.pp svneol=native#text/pascal
lcl/widgetset/wsstdctrls.pp svneol=native#text/pascal lcl/widgetset/wsstdctrls.pp svneol=native#text/pascal
lcl/widgetset/wstoolwin.pp svneol=native#text/pascal lcl/widgetset/wstoolwin.pp svneol=native#text/pascal

View File

@ -51,7 +51,8 @@ interface
uses uses
SysUtils, Classes, FPCAdds, LCLStrConsts, LCLIntf, LResources, LCLType, SysUtils, Classes, FPCAdds, LCLStrConsts, LCLIntf, LResources, LCLType,
LCLProc, Graphics, GraphType, LCLClasses, IntfGraphics, FPReadBMP; LCLProc, Graphics, GraphType, LCLClasses, IntfGraphics, FPReadBMP,
WSReferences;
type type
TImageIndex = type integer; TImageIndex = type integer;
@ -105,8 +106,9 @@ type
TDrawingStyle = (dsFocus, dsSelected, dsNormal, dsTransparent); TDrawingStyle = (dsFocus, dsSelected, dsNormal, dsTransparent);
TImageType = (itImage, itMask); TImageType = (itImage, itMask);
TCustomImageList = class(TLCLHandleComponent) TCustomImageList = class(TLCLReferenceComponent)
private private
FReference: TWSCustomImageListReference;
FDrawingStyle: TDrawingStyle; FDrawingStyle: TDrawingStyle;
FData: array of TRGBAQuad; FData: array of TRGBAQuad;
FImageType: TImageType; FImageType: TImageType;
@ -125,11 +127,13 @@ type
FUpdateCount: integer; FUpdateCount: integer;
procedure AllocData(ACount: Integer); procedure AllocData(ACount: Integer);
function GetReference: TWSCustomImageListReference;
procedure InternalInsert(AIndex: Integer; AImage, AMask: HBitmap; procedure InternalInsert(AIndex: Integer; AImage, AMask: HBitmap;
AWidth, AHeight: Integer); AWidth, AHeight: Integer);
procedure InternalMove(ACurIndex, ANewIndex: Cardinal; AIgnoreCurrent: Boolean); procedure InternalMove(ACurIndex, ANewIndex: Cardinal; AIgnoreCurrent: Boolean);
procedure InternalReplace(AIndex: Integer; AImage, AMask: HBitmap); procedure InternalReplace(AIndex: Integer; AImage, AMask: HBitmap);
function InternalSetImage(AIndex: Integer; AImage: TRawImage): PRGBAQuad; function InternalSetImage(AIndex: Integer; AImage: TRawImage): PRGBAQuad;
procedure NotifyChangeLink; procedure NotifyChangeLink;
procedure SetBkColor(const Value: TColor); procedure SetBkColor(const Value: TColor);
procedure SetDrawingStyle(const AValue: TDrawingStyle); procedure SetDrawingStyle(const AValue: TDrawingStyle);
@ -140,11 +144,13 @@ type
protected protected
procedure CheckIndex(AIndex: Integer; AForInsert: Boolean = False); procedure CheckIndex(AIndex: Integer; AForInsert: Boolean = False);
procedure GetImages(Index: Integer; const Image, Mask: TBitmap); procedure GetImages(Index: Integer; const Image, Mask: TBitmap);
function GetReferenceHandle: THandle; override;
procedure Initialize; virtual; procedure Initialize; virtual;
procedure DefineProperties(Filer: TFiler); override; procedure DefineProperties(Filer: TFiler); override;
procedure SetWidthHeight(NewWidth,NewHeight: integer); virtual; procedure SetWidthHeight(NewWidth,NewHeight: integer); virtual;
function WSCreateHandle(AParams: TCreateParams): TLCLIntfHandle; override; function WSCreateReference(AParams: TCreateParams): PWSReference; override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
@ -205,6 +211,7 @@ type
property Bitmap: TBitmap read FBitmap; property Bitmap: TBitmap read FBitmap;
property MaskBitmap: TBitmap read FMaskBitmap; property MaskBitmap: TBitmap read FMaskBitmap;
{$endif} {$endif}
property Reference: TWSCustomImageListReference read GetReference;
property ShareImages: Boolean read FShareImages write SetShareImages; property ShareImages: Boolean read FShareImages write SetShareImages;
property ImageType: TImageType read FImageType write FImageType default itImage; property ImageType: TImageType read FImageType write FImageType default itImage;
end; end;

View File

@ -463,7 +463,7 @@ procedure TCustomImageList.Draw(ACanvas: TCanvas; AX, AY, AIndex: Integer;
begin begin
if (FCount = 0) or (AIndex >= FCount) then Exit; if (FCount = 0) or (AIndex >= FCount) then Exit;
HandleNeeded; ReferenceNeeded;
TWSCustomImageListClass(WidgetSetClass).Draw(Self, AIndex, ACanvas, Rect(AX, AY, FWidth, FHeight), TWSCustomImageListClass(WidgetSetClass).Draw(Self, AIndex, ACanvas, Rect(AX, AY, FWidth, FHeight),
BkColor, BlendColor, ADrawEffect, DrawingStyle, ImageType); BkColor, BlendColor, ADrawEffect, DrawingStyle, ImageType);
end; end;
@ -567,6 +567,17 @@ begin
Image.Data := @FData[Index * FWidth * FHeight]; Image.Data := @FData[Index * FWidth * FHeight];
end; end;
function TCustomImageList.GetReference: TWSCustomImageListReference;
begin
if not FReference.Allocated then ReferenceNeeded;
Result := FReference;
end;
function TCustomImageList.GetReferenceHandle: THandle;
begin
Result := FReference.Handle;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
procedure TCustomImageList.GetInternalImage(Index: integer; var Image, procedure TCustomImageList.GetInternalImage(Index: integer; var Image,
Mask: TBitmap); Mask: TBitmap);
@ -1347,9 +1358,10 @@ end;
Instructs the widgtset to create an imagelist Instructs the widgtset to create an imagelist
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TCustomImageList.WSCreateHandle(AParams: TCreateParams): TLCLIntfHandle; function TCustomImageList.WSCreateReference(AParams: TCreateParams): PWSReference;
begin begin
Result := TWSCustomImageListClass(WidgetSetClass).CreateHandle(Self, FCount, FAllocBy, FWidth, FHeight, @FData[0]); FReference := TWSCustomImageListClass(WidgetSetClass).CreateReference(Self, FCount, FAllocBy, FWidth, FHeight, @FData[0]);
Result := @FReference;
end; end;
{****************************************************************************** {******************************************************************************

View File

@ -527,7 +527,7 @@ class function TWin32WSDragImageList.BeginDrag(
begin begin
// No check to Handle should be done, because if there is no handle (no needed) // No check to Handle should be done, because if there is no handle (no needed)
// we must create it here. This is normal for imagelist (we can never need handle) // we must create it here. This is normal for imagelist (we can never need handle)
Result := ImageList_BeginDrag(ADragImageList.Handle, AIndex, X, Y); Result := ImageList_BeginDrag(ADragImageList.Reference.Handle, AIndex, X, Y);
end; end;
class function TWin32WSDragImageList.DragMove(const ADragImageList: TDragImageList; class function TWin32WSDragImageList.DragMove(const ADragImageList: TDragImageList;

View File

@ -737,7 +737,7 @@ begin
then Exit; then Exit;
if AValue <> nil then if AValue <> nil then
SendMessage(ALV.Handle, LVM_SETIMAGELIST, LIST_MAP[AList], AValue.Handle) SendMessage(ALV.Handle, LVM_SETIMAGELIST, LIST_MAP[AList], AValue.Reference._Handle)
else else
SendMessage(ALV.Handle, LVM_SETIMAGELIST, LIST_MAP[AList], 0); SendMessage(ALV.Handle, LVM_SETIMAGELIST, LIST_MAP[AList], 0);
end; end;

View File

@ -441,7 +441,7 @@ begin
Result := Params.Window; Result := Params.Window;
if TCustomNoteBook(AWinControl).Images <> nil then if TCustomNoteBook(AWinControl).Images <> nil then
SendMessage(Result, TCM_SETIMAGELIST, 0, TCustomNoteBook(AWinControl).Images.Handle); SendMessage(Result, TCM_SETIMAGELIST, 0, TCustomNoteBook(AWinControl).Images.Reference._Handle);
// although we may be child of tabpage, cut the paint chain // although we may be child of tabpage, cut the paint chain
// to improve speed and possible paint anomalities // to improve speed and possible paint anomalities
@ -635,7 +635,7 @@ begin
Exit; Exit;
if AImageList <> nil then if AImageList <> nil then
SendMessage(ANoteBook.Handle, TCM_SETIMAGELIST, 0, AImageList.Handle) SendMessage(ANoteBook.Handle, TCM_SETIMAGELIST, 0, AImageList.Reference._Handle)
else else
SendMessage(ANoteBook.Handle, TCM_SETIMAGELIST, 0, 0); SendMessage(ANoteBook.Handle, TCM_SETIMAGELIST, 0, 0);
end; end;

View File

@ -36,7 +36,7 @@ uses
Windows, SysUtils, Classes, ImgList, GraphType, Graphics, LCLType, Windows, SysUtils, Classes, ImgList, GraphType, Graphics, LCLType,
Win32Extra, Win32Int, Win32Proc, InterfaceBase, Win32Extra, Win32Int, Win32Proc, InterfaceBase,
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
WSImgList, WSLCLClasses, WSProc; WSImgList, WSLCLClasses, WSProc, WSReferences;
type type
@ -48,10 +48,10 @@ type
class procedure AddData(AListHandle: TLCLIntfHandle; ACount, AReplaceIndex, AWidth, AHeight: Integer; AData: PRGBAQuad); class procedure AddData(AListHandle: TLCLIntfHandle; ACount, AReplaceIndex, AWidth, AHeight: Integer; AData: PRGBAQuad);
public public
class procedure Clear(AList: TCustomImageList); override; class procedure Clear(AList: TCustomImageList); override;
class function CreateHandle(AList: TCustomImageList; ACount, AGrow, AWidth, class function CreateReference(AList: TCustomImageList; ACount, AGrow, AWidth,
AHeight: Integer; AData: PRGBAQuad): TLCLIntfHandle; override; AHeight: Integer; AData: PRGBAQuad): TWSCustomImageListReference; override;
class procedure Delete(AList: TCustomImageList; AIndex: Integer); override; class procedure Delete(AList: TCustomImageList; AIndex: Integer); override;
class procedure DestroyHandle(AComponent: TComponent); override; class procedure DestroyReference(AComponent: TComponent); override;
class procedure Draw(AList: TCustomImageList; AIndex: Integer; ACanvas: TCanvas; class procedure Draw(AList: TCustomImageList; AIndex: Integer; ACanvas: TCanvas;
ABounds: TRect; ABkColor, ABlendColor: TColor; ADrawEffect: TGraphicsDrawEffect; AStyle: TDrawingStyle; AImageType: TImageType); override; ABounds: TRect; ABkColor, ABlendColor: TColor; ADrawEffect: TGraphicsDrawEffect; AStyle: TDrawingStyle; AImageType: TImageType); override;
class procedure DrawToDC(AList: TCustomImageList; AIndex: Integer; ADC: HDC; class procedure DrawToDC(AList: TCustomImageList; AIndex: Integer; ADC: HDC;
@ -220,13 +220,13 @@ end;
class procedure TWin32WSCustomImageList.Clear(AList: TCustomImageList); class procedure TWin32WSCustomImageList.Clear(AList: TCustomImageList);
begin begin
if not WSCheckHandleAllocated(AList, 'Clear') if not WSCheckReferenceAllocated(AList, 'Clear')
then Exit; then Exit;
ImageList_SetImageCount(HImageList(AList.Handle), 0); ImageList_SetImageCount(AList.Reference._Handle, 0);
end; end;
class function TWin32WSCustomImageList.CreateHandle(AList: TCustomImageList; class function TWin32WSCustomImageList.CreateReference(AList: TCustomImageList;
ACount, AGrow, AWidth, AHeight: Integer; AData: PRGBAQuad): TLCLIntfHandle; ACount, AGrow, AWidth, AHeight: Integer; AData: PRGBAQuad): TWSCustomImageListReference;
var var
Flags: DWord; Flags: DWord;
begin begin
@ -245,30 +245,30 @@ begin
FLAGS := ILC_COLOR or ILC_MASK; FLAGS := ILC_COLOR or ILC_MASK;
end; end;
end; end;
Result := ImageList_Create(AWidth, AHeight, Flags, ACount, AGrow); Result._Init(ImageList_Create(AWidth, AHeight, Flags, ACount, AGrow));
if Result <> 0 if Result.Allocated
then AddData(Result, ACount, -1, AWidth, AHeight, AData); then AddData(Result._Handle, ACount, -1, AWidth, AHeight, AData);
end; end;
class procedure TWin32WSCustomImageList.Delete(AList: TCustomImageList; class procedure TWin32WSCustomImageList.Delete(AList: TCustomImageList;
AIndex: Integer); AIndex: Integer);
begin begin
if not WSCheckHandleAllocated(AList, 'Delete') if not WSCheckReferenceAllocated(AList, 'Delete')
then Exit; then Exit;
ImageList_Remove(HImageList(AList.Handle), AIndex); ImageList_Remove(AList.Reference._Handle, AIndex);
end; end;
class procedure TWin32WSCustomImageList.DestroyHandle(AComponent: TComponent); class procedure TWin32WSCustomImageList.DestroyReference(AComponent: TComponent);
begin begin
if not WSCheckHandleAllocated(TCustomImageList(AComponent), 'DestroyHandle') if not WSCheckReferenceAllocated(TCustomImageList(AComponent), 'DestroyReference')
then Exit; then Exit;
ImageList_Destroy(TCustomImageList(AComponent).Handle); ImageList_Destroy(TCustomImageList(AComponent).Reference._Handle);
end; end;
class procedure TWin32WSCustomImageList.Draw(AList: TCustomImageList; AIndex: Integer; class procedure TWin32WSCustomImageList.Draw(AList: TCustomImageList; AIndex: Integer;
ACanvas: TCanvas; ABounds: TRect; ABkColor, ABlendColor: TColor; ADrawEffect: TGraphicsDrawEffect; AStyle: TDrawingStyle; AImageType: TImageType); ACanvas: TCanvas; ABounds: TRect; ABkColor, ABlendColor: TColor; ADrawEffect: TGraphicsDrawEffect; AStyle: TDrawingStyle; AImageType: TImageType);
begin begin
if not WSCheckHandleAllocated(AList, 'Draw') if not WSCheckReferenceAllocated(AList, 'Draw')
then Exit; then Exit;
DrawToDC(AList, AIndex, ACanvas.Handle, ABounds, ABkColor, ABlendColor, ADrawEffect, AStyle, AImageType); DrawToDC(AList, AIndex, ACanvas.Handle, ABounds, ABkColor, ABlendColor, ADrawEffect, AStyle, AImageType);
end; end;
@ -286,7 +286,7 @@ var
begin begin
if ADrawEffect = gdeNormal then if ADrawEffect = gdeNormal then
begin begin
ImageList_DrawEx(HImageList(AList.Handle), AIndex, ADC, ABounds.Left, ImageList_DrawEx(AList.Reference._Handle, AIndex, ADC, ABounds.Left,
ABounds.Top, ABounds.Right, ABounds.Bottom, ColorToImagelistColor(ABkColor), ABounds.Top, ABounds.Right, ABounds.Bottom, ColorToImagelistColor(ABkColor),
ColorToImagelistColor(ABlendColor), DRAWINGSTYLEMAP[AStyle] or IMAGETPYEMAP[AImageType]); ColorToImagelistColor(ABlendColor), DRAWINGSTYLEMAP[AStyle] or IMAGETPYEMAP[AImageType]);
end end
@ -296,7 +296,7 @@ begin
// if it is manifested exe then use winXP algoriphm of gray painting // if it is manifested exe then use winXP algoriphm of gray painting
FillChar(DrawParams, SizeOf(DrawParams), 0); FillChar(DrawParams, SizeOf(DrawParams), 0);
DrawParams.cbSize := SizeOf(DrawParams); DrawParams.cbSize := SizeOf(DrawParams);
DrawParams.himlL := HImageList(AList.Handle); DrawParams.himlL := AList.Reference._Handle;
DrawParams.i := AIndex; DrawParams.i := AIndex;
DrawParams.hdcDst := ADC; DrawParams.hdcDst := ADC;
DrawParams.x := ABounds.Left; DrawParams.x := ABounds.Left;
@ -346,10 +346,10 @@ var
ImageList: HImageList; ImageList: HImageList;
Count: Integer; Count: Integer;
begin begin
if not WSCheckHandleAllocated(AList, 'Insert') if not WSCheckReferenceAllocated(AList, 'Insert')
then Exit; then Exit;
ImageList := HImageList(AList.Handle); ImageList := AList.Reference._Handle;
Count := ImageList_GetImageCount(ImageList); Count := ImageList_GetImageCount(ImageList);
if (AIndex <= Count) and (AIndex >= 0) then if (AIndex <= Count) and (AIndex >= 0) then
@ -366,13 +366,13 @@ var
n: integer; n: integer;
Handle: THandle; Handle: THandle;
begin begin
if not WSCheckHandleAllocated(AList, 'Move') if not WSCheckReferenceAllocated(AList, 'Move')
then Exit; then Exit;
if ACurIndex = ANewIndex if ACurIndex = ANewIndex
then Exit; then Exit;
Handle := AList.Handle; Handle := AList.Reference._Handle;
if ACurIndex < ANewIndex if ACurIndex < ANewIndex
then begin then begin
for n := ACurIndex to ANewIndex - 1 do for n := ACurIndex to ANewIndex - 1 do
@ -390,10 +390,10 @@ var
ImageList: HImageList; ImageList: HImageList;
Count: Integer; Count: Integer;
begin begin
if not WSCheckHandleAllocated(AList, 'Replace') if not WSCheckReferenceAllocated(AList, 'Replace')
then Exit; then Exit;
ImageList := HImageList(AList.Handle); ImageList := AList.Reference._Handle;
Count := ImageList_GetImageCount(ImageList); Count := ImageList_GetImageCount(ImageList);
if (AIndex < Count) and (AIndex >= 0) if (AIndex < Count) and (AIndex >= 0)

View File

@ -29,7 +29,7 @@ unit LCLClasses;
interface interface
uses uses
Classes, WSLCLClasses, LCLType, LCLProc; Classes, WSLCLClasses, WSReferences, LCLType, LCLProc;
type type
@ -51,25 +51,30 @@ type
{ TLCLHandleComponent } { TLCLHandleComponent }
// A base class for all components having a handle // A base class for all components having a handle
TLCLHandleComponent = class(TLCLComponent) { TLCLReferenceComponent }
TLCLReferenceComponent = class(TLCLComponent)
private private
FHandle: TLCLIntfHandle; FReferencePtr: PWSReference;
FCreating: Boolean; // Set if we are creating the handle FCreating: Boolean; // Set if we are creating the handle
function GetHandle: TLCLIntfHandle; function GetHandle: THandle;
function GetHandleAllocated: Boolean; function GetReferenceAllocated: Boolean;
protected protected
procedure CreateParams(var AParams: TCreateParams); virtual; procedure CreateParams(var AParams: TCreateParams); virtual;
procedure DestroyHandle; procedure DestroyReference;
procedure HandleCreated; virtual; // gets called after the Handle is created function GetReferenceHandle: THandle; virtual; abstract;
procedure HandleDestroying; virtual; // gets called before the Handle is destroyed procedure ReferenceCreated; virtual; // gets called after the Handle is created
procedure HandleNeeded; procedure ReferenceDestroying; virtual; // gets called before the Handle is destroyed
function WSCreateHandle(AParams: TCreateParams): TLCLIntfHandle; virtual; procedure ReferenceNeeded;
procedure WSDestroyHandle; virtual; function WSCreateReference(AParams: TCreateParams): PWSReference; virtual;
procedure WSDestroyReference; virtual;
protected protected
public public
destructor Destroy; override; destructor Destroy; override;
property Handle: TLCLIntfHandle read GetHandle; property Handle: TLCLIntfHandle read GetHandle; deprecated;
property HandleAllocated: Boolean read GetHandleAllocated; property HandleAllocated: Boolean read GetReferenceAllocated;
property ReferenceAllocated: Boolean read GetReferenceAllocated;
end; end;
implementation implementation
@ -110,85 +115,86 @@ procedure TLCLComponent.RemoveAllHandlersOfObject(AnObject: TObject);
begin begin
end; end;
{ TLCLHandleComponent } { TLCLReferenceComponent }
procedure TLCLHandleComponent.CreateParams(var AParams: TCreateParams); procedure TLCLReferenceComponent.CreateParams(var AParams: TCreateParams);
begin begin
end; end;
destructor TLCLHandleComponent.Destroy; destructor TLCLReferenceComponent.Destroy;
begin begin
DestroyHandle; DestroyReference;
inherited Destroy; inherited Destroy;
end; end;
procedure TLCLHandleComponent.DestroyHandle; procedure TLCLReferenceComponent.DestroyReference;
begin begin
if FHandle <> 0 then if ReferenceAllocated then
begin begin
HandleDestroying; ReferenceDestroying;
WSDestroyHandle; WSDestroyReference;
FHandle := 0; FReferencePtr^._Clear;
FReferencePtr := nil;
end; end;
end; end;
function TLCLHandleComponent.GetHandle: TLCLIntfHandle; function TLCLReferenceComponent.GetHandle: THandle;
begin begin
if FHandle = 0 then HandleNeeded; ReferenceNeeded;
Result := FHandle; Result := GetReferenceHandle;
end; end;
function TLCLHandleComponent.GetHandleAllocated: Boolean; function TLCLReferenceComponent.GetReferenceAllocated: Boolean;
begin begin
Result := FHandle <> 0; Result := (FReferencePtr <> nil) and FReferencePtr^.Allocated;
end; end;
procedure TLCLHandleComponent.HandleCreated; procedure TLCLReferenceComponent.ReferenceCreated;
begin begin
end; end;
procedure TLCLHandleComponent.HandleDestroying; procedure TLCLReferenceComponent.ReferenceDestroying;
begin begin
end; end;
procedure TLCLHandleComponent.HandleNeeded; procedure TLCLReferenceComponent.ReferenceNeeded;
var var
Params: TCreateParams; Params: TCreateParams;
begin begin
if FHandle <> 0 then Exit; if ReferenceAllocated then Exit;
if FCreating if FCreating
then begin then begin
// raise some error ? // raise some error ?
DebugLn('TLCLHandleComponent: Circulair handle creation'); DebugLn('TLCLReferenceComponent: Circulair reference creation');
Exit; Exit;
end; end;
CreateParams(Params); CreateParams(Params);
FCreating := True; FCreating := True;
try try
FHandle := WSCreateHandle(Params); FReferencePtr := WSCreateReference(Params);
if FHandle = 0 if not ReferenceAllocated
then begin then begin
// raise some error ? // raise some error ?
DebugLn('TLCLHandleComponent: Handle creation failed'); DebugLn('TLCLHandleComponent: Reference creation failed');
Exit; Exit;
end; end;
finally finally
FCreating := False; FCreating := False;
end; end;
HandleCreated; ReferenceCreated;
end; end;
function TLCLHandleComponent.WSCreateHandle(AParams: TCreateParams): TLCLIntfHandle; function TLCLReferenceComponent.WSCreateReference(AParams: TCreateParams): PWSReference;
begin begin
// this function should be overriden in derrived class // this function should be overriden in derrived class
Result := 0; Result := nil;
end; end;
procedure TLCLHandleComponent.WSDestroyHandle; procedure TLCLReferenceComponent.WSDestroyReference;
begin begin
TWSLCLHandleComponentClass(WidgetSetClass).DestroyHandle(Self); TWSLCLReferenceComponentClass(WidgetSetClass).DestroyReference(Self);
end; end;
end. end.

View File

@ -41,18 +41,18 @@ interface
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
uses uses
Classes, Contnrs, GraphType, Graphics, IntfGraphics, ImgList, LCLType, LCLIntf, Classes, Contnrs, GraphType, Graphics, IntfGraphics, ImgList, LCLType, LCLIntf,
WSLCLClasses, WSProc; WSLCLClasses, WSProc, WSReferences;
type type
{ TWSCustomImageList } { TWSCustomImageList }
TWSCustomImageList = class(TWSLCLHandleComponent) TWSCustomImageList = class(TWSLCLReferenceComponent)
class procedure Clear(AList: TCustomImageList); virtual; class procedure Clear(AList: TCustomImageList); virtual;
class function CreateHandle(AList: TCustomImageList; ACount, AGrow, AWidth, class function CreateReference(AList: TCustomImageList; ACount, AGrow, AWidth,
AHeight: Integer; AData: PRGBAQuad): TLCLIntfHandle; virtual; AHeight: Integer; AData: PRGBAQuad): TWSCustomImageListReference; virtual;
class procedure Delete(AList: TCustomImageList; AIndex: Integer); virtual; class procedure Delete(AList: TCustomImageList; AIndex: Integer); virtual;
class procedure DestroyHandle(AComponent: TComponent); override; class procedure DestroyReference(AComponent: TComponent); override;
class procedure Draw(AList: TCustomImageList; AIndex: Integer; ACanvas: TCanvas; class procedure Draw(AList: TCustomImageList; AIndex: Integer; ACanvas: TCanvas;
ABounds: TRect; ABkColor, ABlendColor: TColor; ADrawEffect: TGraphicsDrawEffect; AStyle: TDrawingStyle; AImageType: TImageType); virtual; ABounds: TRect; ABkColor, ABlendColor: TColor; ADrawEffect: TGraphicsDrawEffect; AStyle: TDrawingStyle; AImageType: TImageType); virtual;
@ -145,18 +145,21 @@ end;
class procedure TWSCustomImageList.Clear(AList: TCustomImageList); class procedure TWSCustomImageList.Clear(AList: TCustomImageList);
begin begin
if not WSCheckHandleAllocated(AList, 'Clear') if not WSCheckReferenceAllocated(AList, 'Clear')
then Exit; then Exit;
TDefaultImageListImplementor(AList.Handle).Clear; TDefaultImageListImplementor(AList.Reference.Ptr).Clear;
end; end;
class function TWSCustomImageList.CreateHandle(AList: TCustomImageList; ACount, class function TWSCustomImageList.CreateReference(AList: TCustomImageList; ACount,
AGrow, AWidth, AHeight: Integer; AData: PRGBAQuad): TLCLIntfHandle; AGrow, AWidth, AHeight: Integer; AData: PRGBAQuad): TWSCustomImageListReference;
var var
impl: TDefaultImageListImplementor;
ABitmap: TBitmap; ABitmap: TBitmap;
i: integer; i: integer;
begin begin
Result := TLCLIntfHandle(TDefaultImageListImplementor.Create(AList)); impl := TDefaultImageListImplementor.Create(AList);
Result._Init(impl);
if AData <> nil then if AData <> nil then
begin begin
@ -164,7 +167,7 @@ begin
for i := 0 to ACount - 1 do for i := 0 to ACount - 1 do
begin begin
ABitmap := InternalCreateBitmap(AList, AWidth, AHeight, @AData[AWidth * AHeight * i]); ABitmap := InternalCreateBitmap(AList, AWidth, AHeight, @AData[AWidth * AHeight * i]);
TDefaultImageListImplementor(Result).Add(ABitmap); impl.Add(ABitmap);
end; end;
end; end;
end; end;
@ -172,25 +175,25 @@ end;
class procedure TWSCustomImageList.Delete(AList: TCustomImageList; class procedure TWSCustomImageList.Delete(AList: TCustomImageList;
AIndex: Integer); AIndex: Integer);
begin begin
if not WSCheckHandleAllocated(AList, 'Delete') if not WSCheckReferenceAllocated(AList, 'Delete')
then Exit; then Exit;
TDefaultImageListImplementor(AList.Handle).Delete(AIndex); TDefaultImageListImplementor(AList.Reference.Ptr).Delete(AIndex);
end; end;
class procedure TWSCustomImageList.DestroyHandle(AComponent: TComponent); class procedure TWSCustomImageList.DestroyReference(AComponent: TComponent);
begin begin
if not WSCheckHandleAllocated(TCustomImageList(AComponent), 'DestroyHandle') if not WSCheckReferenceAllocated(TCustomImageList(AComponent), 'DestroyReference')
then Exit; then Exit;
TDefaultImageListImplementor(TCustomImageList(AComponent).Handle).Free; TObject(TCustomImageList(AComponent).Reference.Ptr).Free;
end; end;
class procedure TWSCustomImageList.Draw(AList: TCustomImageList; AIndex: Integer; class procedure TWSCustomImageList.Draw(AList: TCustomImageList; AIndex: Integer;
ACanvas: TCanvas; ABounds: TRect; ABkColor, ABlendColor: TColor; ADrawEffect: TGraphicsDrawEffect; AStyle: TDrawingStyle; AImageType: TImageType); ACanvas: TCanvas; ABounds: TRect; ABkColor, ABlendColor: TColor; ADrawEffect: TGraphicsDrawEffect; AStyle: TDrawingStyle; AImageType: TImageType);
begin begin
if not WSCheckHandleAllocated(AList, 'Draw') if not WSCheckReferenceAllocated(AList, 'Draw')
then Exit; then Exit;
TDefaultImageListImplementor(AList.Handle).Draw(AIndex, ACanvas, ABounds, ADrawEffect, AStyle); TDefaultImageListImplementor(AList.Reference.Ptr).Draw(AIndex, ACanvas, ABounds, ADrawEffect, AStyle);
end; end;
class procedure TWSCustomImageList.Insert(AList: TCustomImageList; class procedure TWSCustomImageList.Insert(AList: TCustomImageList;
@ -200,10 +203,10 @@ var
ACount: Integer; ACount: Integer;
ABitmap: TBitmap; ABitmap: TBitmap;
begin begin
if not WSCheckHandleAllocated(AList, 'Insert') if not WSCheckReferenceAllocated(AList, 'Insert')
then Exit; then Exit;
AImageList := TDefaultImageListImplementor(AList.Handle); AImageList := TDefaultImageListImplementor(AList.Reference.Ptr);
ACount := AImageList.Count; ACount := AImageList.Count;
if (AIndex <= ACount) and (AIndex >= 0) then if (AIndex <= ACount) and (AIndex >= 0) then
@ -218,13 +221,13 @@ end;
class procedure TWSCustomImageList.Move(AList: TCustomImageList; ACurIndex, class procedure TWSCustomImageList.Move(AList: TCustomImageList; ACurIndex,
ANewIndex: Integer); ANewIndex: Integer);
begin begin
if not WSCheckHandleAllocated(AList, 'Move') if not WSCheckReferenceAllocated(AList, 'Move')
then Exit; then Exit;
if ACurIndex = ANewIndex if ACurIndex = ANewIndex
then Exit; then Exit;
TDefaultImageListImplementor(AList.Handle).Move(ACurIndex, ANewIndex); TDefaultImageListImplementor(AList.Reference.Ptr).Move(ACurIndex, ANewIndex);
end; end;
class procedure TWSCustomImageList.Replace(AList: TCustomImageList; class procedure TWSCustomImageList.Replace(AList: TCustomImageList;
@ -232,11 +235,11 @@ class procedure TWSCustomImageList.Replace(AList: TCustomImageList;
var var
ABitmap: TBitmap; ABitmap: TBitmap;
begin begin
if not WSCheckHandleAllocated(AList, 'Replace') if not WSCheckReferenceAllocated(AList, 'Replace')
then Exit; then Exit;
ABitmap := InternalCreateBitmap(AList, AList.Width, AList.Height, AData); ABitmap := InternalCreateBitmap(AList, AList.Width, AList.Height, AData);
TDefaultImageListImplementor(AList.Handle)[AIndex] := ABitmap; TDefaultImageListImplementor(AList.Reference.Ptr)[AIndex] := ABitmap;
end; end;
initialization initialization

View File

@ -68,10 +68,10 @@ type
{ TWSLCLHandleComponent } { TWSLCLHandleComponent }
TWSLCLHandleComponent = class(TWSLCLComponent) TWSLCLReferenceComponent = class(TWSLCLComponent)
class procedure DestroyHandle(AComponent: TComponent); virtual; class procedure DestroyReference(AComponent: TComponent); virtual;
end; end;
TWSLCLHandleComponentClass = class of TWSLCLHandleComponent; TWSLCLReferenceComponentClass = class of TWSLCLReferenceComponent;
function FindWSComponentClass(const AComponent: TComponentClass): TWSLCLComponentClass; function FindWSComponentClass(const AComponent: TComponentClass): TWSLCLComponentClass;
@ -411,7 +411,7 @@ end;
{ TWSLCLHandleComponent } { TWSLCLHandleComponent }
class procedure TWSLCLHandleComponent.DestroyHandle(AComponent: TComponent); class procedure TWSLCLReferenceComponent.DestroyReference(AComponent: TComponent);
begin begin
end; end;

View File

@ -32,23 +32,23 @@ uses
LCLClasses, LCLProc, Controls; LCLClasses, LCLProc, Controls;
function WSCheckHandleAllocated(const AComponent: TLCLHandleComponent; function WSCheckReferenceAllocated(const AComponent: TLCLReferenceComponent;
const AProcName: String): Boolean; const AProcName: String): Boolean;
function WSCheckHandleAllocated(const AWincontrol: TWinControl; function WSCheckHandleAllocated(const AWincontrol: TWinControl;
const AProcName: String): Boolean; const AProcName: String): Boolean;
implementation implementation
function WSCheckHandleAllocated(const AComponent: TLCLHandleComponent; function WSCheckReferenceAllocated(const AComponent: TLCLReferenceComponent;
const AProcName: String): Boolean; const AProcName: String): Boolean;
procedure Warn; procedure Warn;
begin begin
DebugLn('[WARNING] %s called without handle for %s(%s)', [AProcName, AComponent.Name, AComponent.ClassName]); DebugLn('[WARNING] %s called without reference for %s(%s)', [AProcName, AComponent.Name, AComponent.ClassName]);
end; end;
begin begin
Result := AComponent.HandleAllocated; Result := AComponent.ReferenceAllocated;
if Result then Exit; if Result then Exit;
Warn; Warn;
end; end;

View File

@ -0,0 +1,97 @@
{ $Id$}
{
*****************************************************************************
* wsreferences.pp *
* --------------- *
* *
* *
*****************************************************************************
*****************************************************************************
* *
* This file is part of the Lazarus Component Library (LCL) *
* *
* See the file COPYING.modifiedLGPL, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
}
unit WSReferences;
{$mode objfpc}{$H+}
interface
//uses
// Types;
type
{ TWSReference }
{
Abstract (temporary) base object for all references to WS classes.
This reference replaces the functionality of a Handle.
An object is choosen to disallow assignments of different types of handles
}
PWSReference = ^TWSReference;
TWSReference = object
private
function GetAllocated: Boolean; inline;
protected
FRef: record
case Byte of
0: (Ptr: Pointer);
1: (Handle: THandle);
end;
public
// NOTE: These _Methods are temporary and for widgetset use only.
// They can be removed anytime, without notice
procedure _Clear;
procedure _Init(APtr: Pointer);
procedure _Init(AHandle: THandle);
property _Handle: THandle read FRef.Handle;
//----
property Allocated: Boolean read GetAllocated;
property Ptr: Pointer read FRef.Ptr;
end;
TWSCustomImageListReference = object(TWSReference)
public
property Handle: Thandle read FRef.Handle;
end;
implementation
{ TWSReference }
procedure TWSReference._Clear;
begin
FRef.Ptr := nil;
end;
procedure TWSReference._Init(APtr: Pointer);
begin
FRef.Ptr := APtr;
end;
procedure TWSReference._Init(AHandle: THandle);
begin
FRef.Handle := AHandle;
end;
function TWSReference.GetAllocated: Boolean;
begin
Result := FRef.Ptr <> nil;
end;
end.