lazarus/lcl/include/listcolumn.inc
maxim 6587e40850 Merged revision(s) 51631 #d7e4677c9f, 51731 #e090cee919, 53722 #3a3af4fd12, 53739 #b1a91e3d7c, 53746 #f937a0c74b, 53757 #96b919c8c1 from trunk:
lcl: TCustomForm.ShowModal: recreate handle only if handle was allocated, don't use HandleNeeded
........
LCL: must call RecreateWnd() when modal finishes so next CreateHandle() can provide correct params on win32. issue #29744
........
LCL: TMemo: Fix for flickering on Windows. Issue #16140
........
LCL: TMemo: Fix for flickering on Windows, activating MemoWndProc. Issue #16140
........
LCL: TListView: Win32: use stored width, if there are no items to calculate the correct autosize width. Issue #29132
........
LCL: TListView: Win32: use caption width, if there are no items to calculate the correct autosize width. Issue #29132
........

git-svn-id: branches/fixes_1_6@53785 -
2016-12-27 22:31:57 +00:00

282 lines
7.5 KiB
PHP

{%MainUnit ../comctrls.pp}
{ $Id$
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
{------------------------------------------------------------------------------}
{ TListColumn }
{------------------------------------------------------------------------------}
procedure TListColumn.Assign(ASource: TPersistent);
var
Col: TListColumn;
begin
if ASource is TListColumn
then begin
Col := TListColumn(ASource);
FAlignment := Col.Alignment;
FAutoSize := Col.AutoSize;
FCaption := Col.Caption;
FMaxWidth := Col.MaxWidth;
FMinWidth := Col.MinWidth;
FVisible := Col.Visible;
FWidth := Col.Width;
Changed(False);
end
else inherited Assign(ASource);
end;
constructor TListColumn.Create(ACollection: TCollection);
begin
FAlignment := taLeftJustify;
FCaption := '';
FWidth := 50;
FVisible := True;
FMinWidth := 0;
FMaxWidth := 0;
FAutoSize := False;
FTag := 0;
FImageIndex := -1;
inherited Create(ACollection);
if not WSUpdateAllowed then Exit;
WSCreateColumn;
end;
destructor TListColumn.Destroy;
var
Columns: TListColumns;
idx: Integer;
UpdAllowed: Boolean;
LV: TCustomListView;
begin
idx := Index;
UpdAllowed := WSUpdateAllowed;
if Collection is TListColumns
then begin
Columns:=TListColumns(Collection);
if Columns.FItemNeedsUpdate=Self then Columns.FItemNeedsUpdate:=nil;
end;
inherited Destroy;
// MWE: I don't think a changed is needed here
//Changed(False);
if not UpdAllowed then Exit;
LV := Columns.FOwner;
TWSCustomListViewClass(LV.WidgetSetClass).ColumnDelete(LV, Idx);
end;
procedure TListColumn.WSCreateColumn;
var
LV: TCustomListView;
WSC: TWSCustomListViewClass;
begin
LV := TListColumns(Collection).FOwner;
WSC := TWSCustomListViewClass(LV.WidgetSetClass);
WSC.ColumnInsert(LV, Index, Self);
WSC.ColumnSetAlignment(LV, Index, Self, FAlignment);
WSC.ColumnSetAutosize(LV, Index, Self, FAutosize);
WSC.ColumnSetCaption(LV, Index, Self, FCaption);
WSC.ColumnSetMaxWidth(LV, Index, Self, FMaxWidth);
WSC.ColumnSetMinWidth(LV, Index, Self, FMinWidth);
if FAutoSize then begin
WSC.ColumnSetAutosize(LV, Index, Self, FAutosize);
end else begin
WSC.ColumnSetWidth(LV, Index, Self, FWidth);
end;
WSC.ColumnSetImage(LV, Index, Self, FImageIndex);
WSC.ColumnSetVisible(LV, Index, Self, FVisible);
end;
procedure TListColumn.WSDestroyColumn;
var
LV: TCustomListView;
begin
LV := TListColumns(Collection).FOwner;
TWSCustomListViewClass(LV.WidgetSetClass).ColumnDelete(LV, Index);
end;
function TListColumn.WSUpdateAllowed: Boolean;
begin
Result := (Collection <> nil)
and (TListColumns(Collection).FOwner <> nil)
and TListColumns(Collection).FOwner.HandleAllocated
and not (csReading in TListColumns(Collection).FOwner.ComponentState)
and not (csDestroying in TListColumns(Collection).FOwner.ComponentState);
end;
function TListColumn.WSReadAllowed: Boolean;
begin
Result := (Collection <> nil)
and (TListColumns(Collection).FOwner <> nil)
and TListColumns(Collection).FOwner.HandleAllocated
and ([csReading, csLoading] * TListColumns(Collection).FOwner.ComponentState = [])
and not (wcfInitializing in TCustomListView(TListColumns(Collection).FOwner).FWinControlFlags);
end;
function TListColumn.GetWidth: TWidth;
var
LV: TCustomListView;
WSWidth: integer;
begin
if WSReadAllowed
then begin
LV := TListColumns(Collection).FOwner;
WSWidth := TWSCustomListViewClass(LV.WidgetSetClass).ColumnGetWidth(LV, Index, Self);
// update stored width
if WSWidth >= 0 then
FWidth := WSWidth;
end;
Result := FWidth;
end;
procedure TListColumn.SetAlignment(const AValue: TAlignment);
var
LV: TCustomListView;
begin
if FAlignment = AValue then Exit;
FAlignment := AValue;
Changed(False);
if not WSUpdateAllowed then Exit;
LV := TListColumns(Collection).FOwner;
TWSCustomListViewClass(LV.WidgetSetClass).ColumnSetAlignment(LV, Index, Self, FAlignment);
end;
procedure TListColumn.SetCaption(const AValue: TTranslateString);
var
LV: TCustomListView;
begin
if AValue = FCaption then Exit;
FCaption := AValue;
Changed(False);
if not WSUpdateAllowed then Exit;
LV := TListColumns(Collection).FOwner;
TWSCustomListViewClass(LV.WidgetSetClass).ColumnSetCaption(LV, Index, Self, FCaption);
if FAutoSize then
TWSCustomListViewClass(LV.WidgetSetClass).ColumnSetAutosize(LV, Index, Self, FAutosize);
end;
procedure TListColumn.SetWidth(const AValue: TWidth);
var
LV: TCustomListView;
W: TWidth;
begin
W := AValue;
if (MinWidth > 0) and (W < MinWidth) then
W := MinWidth
else
if (MaxWidth > 0) and (W > MaxWidth) then
W := MaxWidth;
if FWidth = W then Exit;
FWidth := W;
Changed(False);
if not WSUpdateAllowed then Exit;
LV := TListColumns(Collection).FOwner;
if (LV <> nil) or (LV.WidgetsetClass <> nil) then // Avoids crash
TWSCustomListViewClass(LV.WidgetSetClass).ColumnSetWidth(LV, Index, Self, FWidth);
end;
procedure TListColumn.SetMaxWidth(const AValue: TWidth);
var
LV: TCustomListView;
begin
if FMaxWidth = AValue then Exit;
FMaxWidth := AValue;
Changed(False);
if not WSUpdateAllowed then Exit;
LV := TListColumns(Collection).FOwner;
TWSCustomListViewClass(LV.WidgetSetClass).ColumnSetMaxWidth(LV, Index, Self, FMaxWidth);
end;
procedure TListColumn.SetMinWidth(const AValue: TWidth);
var
LV: TCustomListView;
begin
if FMinWidth = AValue then Exit;
FMinWidth := AValue;
Changed(False);
if not WSUpdateAllowed then Exit;
LV := TListColumns(Collection).FOwner;
TWSCustomListViewClass(LV.WidgetSetClass).ColumnSetMinWidth(LV, Index, Self, FMinWidth);
end;
procedure TListColumn.SetAutoSize(const AValue: Boolean);
var
LV: TCustomListView;
begin
if FAutoSize = AValue then Exit;
FAutoSize := AValue;
Changed(False);
if not WSUpdateAllowed then Exit;
LV := TListColumns(Collection).FOwner;
TWSCustomListViewClass(LV.WidgetSetClass).ColumnSetAutosize(LV, Index, Self, FAutosize);
end;
procedure TListColumn.SetImageIndex(const AValue: TImageIndex);
var
LV: TCustomListView;
begin
if FImageIndex = AValue then Exit;
FImageIndex := AValue;
Changed(False);
if not WSUpdateAllowed then Exit;
LV := TListColumns(Collection).FOwner;
TWSCustomListViewClass(LV.WidgetSetClass).ColumnSetImage(LV, Index, Self, FImageIndex);
end;
procedure TListColumn.SetIndex(AValue: Integer);
var
OldIndex: Integer;
LV: TCustomListView;
begin
OldIndex := Index;
inherited;
if OldIndex = Index then Exit;
if not WSUpdateAllowed then Exit;
LV := TListColumns(Collection).FOwner;
TWSCustomListViewClass(LV.WidgetSetClass).ColumnMove(LV, OldIndex, Index, Self);
end;
function TListColumn.GetDisplayName: string;
begin
Result := Caption;
if Result = '' then Result := inherited GetDisplayName;
end;
function TListColumn.GetStoredWidth: Integer;
begin
Result := FWidth;
end;
procedure TListColumn.SetVisible(const AValue: Boolean);
var
LV: TCustomListView;
begin
if FVisible = AValue then Exit;
FVisible := AValue;
Changed(False);
if not WSUpdateAllowed then Exit;
LV := TListColumns(Collection).FOwner;
TWSCustomListViewClass(LV.WidgetSetClass).ColumnSetVisible(LV, Index, Self, FVisible);
end;