mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 04:55:58 +02:00
LCL: TCustomListView: Implemented OwnerDraw & OnDrawItem for delphi compatibility. Widgetsets are responsible to trigger OnDrawItem via CN_DRAWITEM message.Part of issue #25149
git-svn-id: trunk@43115 -
This commit is contained in:
parent
5f3d3ef662
commit
a439dbcfb6
@ -1253,6 +1253,8 @@ type
|
||||
TLVCustomDrawSubItemEvent=procedure(Sender: TCustomListView; Item: TListItem;
|
||||
SubItem: Integer; State: TCustomDrawState;
|
||||
var DefaultDraw: Boolean) of object;
|
||||
TLVDrawItemEvent = procedure(Sender: TCustomListView; AItem: TListItem; ARect: TRect;
|
||||
AState: TOwnerDrawState) of object;
|
||||
TLVAdvancedCustomDrawEvent = procedure(Sender: TCustomListView; const ARect: TRect;
|
||||
Stage: TCustomDrawStage; var DefaultDraw: Boolean) of object;
|
||||
TLVAdvancedCustomDrawItemEvent = procedure(Sender: TCustomListView; Item: TListItem;
|
||||
@ -1407,9 +1409,11 @@ type
|
||||
procedure SetViewStyle(const Avalue: TViewStyle);
|
||||
procedure UpdateScrollbars;
|
||||
procedure CNNotify(var AMessage: TLMNotify); message CN_NOTIFY;
|
||||
procedure CNDrawItem(var Message: TLMDrawListItem); message CN_DRAWITEM;
|
||||
procedure InvalidateSelected;
|
||||
private
|
||||
FOnCreateItemClass: TLVCreateItemClassEvent;
|
||||
FOnDrawItem: TLVDrawItemEvent;
|
||||
procedure HideEditor;
|
||||
procedure ShowEditor;
|
||||
procedure WMHScroll(var message : TLMHScroll); message LM_HSCROLL;
|
||||
@ -1454,6 +1458,7 @@ type
|
||||
function CustomDrawSubItem(AItem: TListItem; ASubItem: Integer; AState: TCustomDrawState; AStage: TCustomDrawStage): Boolean; virtual; //
|
||||
function IntfCustomDraw(ATarget: TCustomDrawTarget; AStage: TCustomDrawStage; AItem, ASubItem: Integer; AState: TCustomDrawState; const ARect: PRect): TCustomDrawResult;
|
||||
function GetUpdateCount: Integer;
|
||||
procedure DrawItem(AItem: TListItem; ARect: TRect; AState: TOwnerDrawState);
|
||||
|
||||
procedure DoGetOwnerData(Item: TListItem); virtual;
|
||||
function DoOwnerDataHint(AStartIndex, AEndIndex: Integer): Boolean; virtual;
|
||||
@ -1500,6 +1505,7 @@ type
|
||||
property OnCustomDraw: TLVCustomDrawEvent read FOnCustomDraw write FOnCustomDraw;
|
||||
property OnCustomDrawItem: TLVCustomDrawItemEvent read FOnCustomDrawItem write FOnCustomDrawItem;
|
||||
property OnCustomDrawSubItem: TLVCustomDrawSubItemEvent read FOnCustomDrawSubItem write FOnCustomDrawSubItem;
|
||||
property OnDrawItem: TLVDrawItemEvent read FOnDrawItem write FOnDrawItem; // Owner drawn item.Event triggers only when OwnerDraw=True and ListStyle=vsReport
|
||||
property OnAdvancedCustomDraw: TLVAdvancedCustomDrawEvent read FOnAdvancedCustomDraw write FOnAdvancedCustomDraw;
|
||||
property OnAdvancedCustomDrawItem: TLVAdvancedCustomDrawItemEvent read FOnAdvancedCustomDrawItem write FOnAdvancedCustomDrawItem;
|
||||
property OnAdvancedCustomDrawSubItem: TLVAdvancedCustomDrawSubItemEvent read FOnAdvancedCustomDrawSubItem write FOnAdvancedCustomDrawSubItem;
|
||||
@ -1600,7 +1606,7 @@ type
|
||||
property LargeImages;
|
||||
property MultiSelect;
|
||||
property OwnerData;
|
||||
// property OwnerDraw;
|
||||
property OwnerDraw; // should pass OnDrawItem only when ListStyle=vsReport and OwnerDraw=True
|
||||
property ParentColor default False;
|
||||
property ParentFont;
|
||||
property ParentShowHint;
|
||||
@ -1641,6 +1647,7 @@ type
|
||||
property OnDeletion;
|
||||
property OnDragDrop;
|
||||
property OnDragOver;
|
||||
property OnDrawItem;
|
||||
property OnEdited;
|
||||
property OnEditing;
|
||||
property OnEndDock;
|
||||
|
@ -368,6 +368,47 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomListView.DrawItem(AItem: TListItem; ARect: TRect;
|
||||
AState: TOwnerDrawState);
|
||||
begin
|
||||
if Assigned(FOnDrawItem) then FOnDrawItem(Self, AItem, ARect, AState)
|
||||
else
|
||||
begin
|
||||
FCanvas.FillRect(ARect);
|
||||
FCanvas.TextOut(ARect.Left + 2, ARect.Top, AItem.Caption);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomListView.CNDrawItem(var Message: TLMDrawListItem);
|
||||
var
|
||||
State: TOwnerDrawState;
|
||||
SaveIndex: Integer;
|
||||
begin
|
||||
if Assigned(FCanvas) then
|
||||
begin
|
||||
with Message.DrawListItemStruct^ do
|
||||
begin
|
||||
State := ItemState;
|
||||
SaveIndex := SaveDC(DC);
|
||||
FCanvas.Lock;
|
||||
try
|
||||
FCanvas.Handle := DC;
|
||||
FCanvas.Font := Font;
|
||||
FCanvas.Brush := Brush;
|
||||
if itemID = DWORD(-1) then
|
||||
FCanvas.FillRect(Area)
|
||||
else
|
||||
DrawItem(Items[itemID], Area, State);
|
||||
finally
|
||||
FCanvas.Handle := 0;
|
||||
FCanvas.Unlock;
|
||||
RestoreDC(DC, SaveIndex);
|
||||
end;
|
||||
end;
|
||||
Message.Result := 1;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCustomListView.InvalidateSelected;
|
||||
begin
|
||||
FSelected:=nil;
|
||||
@ -787,7 +828,7 @@ end;
|
||||
{------------------------------------------------------------------------------}
|
||||
{ TCustomListView SetViewStyle }
|
||||
{------------------------------------------------------------------------------}
|
||||
procedure TCustomListView.SetViewStyle(const AValue: TViewStyle);
|
||||
procedure TCustomListView.SetViewStyle(const Avalue: TViewStyle);
|
||||
begin
|
||||
if FViewStyle = AValue then Exit;
|
||||
FViewStyle := AValue;
|
||||
@ -1123,7 +1164,7 @@ begin
|
||||
Result := TWSCustomListViewClass(WidgetSetClass).GetHitTestInfoAt( Self, X, Y );
|
||||
end;
|
||||
|
||||
function TCustomListView.GetItemAt(x,y: Integer): TListItem;
|
||||
function TCustomListView.GetItemAt(x, y: integer): TListItem;
|
||||
var
|
||||
Item: Integer;
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user