lcl: allow to request true column width during listview destruction (based on patch of José Mejuto)

win32: use stored width while setting column width in interface
gtk2: use true column width, not the requested one
fixes issue #0014371

git-svn-id: trunk@25124 -
This commit is contained in:
paul 2010-05-02 06:45:23 +00:00
parent 0b8c73b16e
commit fa0ab5a8ad
4 changed files with 26 additions and 10 deletions

View File

@ -878,7 +878,8 @@ type
function GetWidth: TWidth;
procedure WSCreateColumn;
procedure WSDestroyColumn;
function WSUpdateAllowed: Boolean;
function WSUpdateAllowed: Boolean;
function WSReadAllowed: Boolean;
procedure SetVisible(const AValue: Boolean);
procedure SetAutoSize(const AValue: Boolean);
procedure SetMinWidth(const AValue: TWidth);
@ -890,6 +891,7 @@ type
protected
procedure SetIndex(AValue: Integer); override;
function GetDisplayName: string; override;
function GetStoredWidth: Integer;
public
constructor Create(ACollection: TCollection); override;
destructor Destroy; override;

View File

@ -116,20 +116,28 @@ begin
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 = []);
end;
function TListColumn.GetWidth: TWidth;
var
LV: TCustomListView;
WSWidth: integer;
begin
if WSUpdateAllowed
if WSReadAllowed
then begin
LV := TListColumns(Collection).FOwner;
WSWidth := TWSCustomListViewClass(LV.WidgetSetClass).ColumnGetWidth(LV, Index, Self);
if WSWidth < 0
then Result := FWidth
else Result := WSWidth;
end
else Result := FWidth;
// update stored width
if WSWidth >= 0 then
FWidth := WSWidth;
end;
Result := FWidth;
end;
procedure TListColumn.SetAlignment(const AValue: TAlignment);
@ -252,6 +260,11 @@ begin
if Result = '' then Result := inherited GetDisplayName;
end;
function TListColumn.GetStoredWidth: Integer;
begin
Result := FWidth;
end;
procedure TListColumn.SetVisible(const AValue: Boolean);
var
LV: TCustomListView;

View File

@ -580,7 +580,7 @@ begin
i := AColumn.Index;
GtkColumn := gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), i);
if GtkColumn <> nil then
Result := gtk_tree_view_column_get_fixed_width(GtkColumn);
Result := gtk_tree_view_column_get_width(GtkColumn);
end;
class procedure TGtk2WSCustomListView.ColumnInsert(const ALV: TCustomListView;

View File

@ -58,6 +58,7 @@ type
type
TCustomListViewAccess = class(TCustomListView);
TListColumnAccess = class(TListColumn);
////////////////////////////////////////////////////////////////////////////////
// Msg handlers
@ -398,7 +399,7 @@ begin
if AAutoSize
then ListView_SetColumnWidth(ALV.Handle, AIndex, AutoSizeWidth)
else ListView_SetColumnWidth(ALV.Handle, AIndex, AColumn.Width);
else ListView_SetColumnWidth(ALV.Handle, AIndex, TListColumnAccess(AColumn).GetStoredWidth);
end;
class procedure TWin32WSCustomListView.ColumnSetCaption(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const ACaption: String);
@ -490,7 +491,7 @@ begin
if AVisible
then if AColumn.AutoSize
then ListView_SetColumnWidth(ALV.Handle, AIndex, AutoSizeWidth)
else ListView_SetColumnWidth(ALV.Handle, AIndex, AColumn.Width)
else ListView_SetColumnWidth(ALV.Handle, AIndex, TListColumnAccess(AColumn).GetStoredWidth)
else ListView_SetColumnWidth(ALV.Handle, AIndex, 0);
end;