mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-06 10:18:05 +02:00
bug #36281. Merged revision(s) 62516-62547 from branches/listviewsortindicator:
lcl: adding sortIndicator to the listview ........ win32: implementation of sortindicator ........ lcl: adding autosortindicator property for the listview ........ gtk2: sortindicator implementation ........ gtk2: reverting accidental changes (unrelated to sortindicator) ........ qt5: implementing sort indicator (seems like qt5 allows only 1 indicator per header) ........ cocoa: implementing sortIndicator ........ doc: adding short descriptions for SortIndicator and AutoSortIndicator ........ git-svn-id: trunk@62567 -
This commit is contained in:
parent
e7ab9b1d39
commit
556c5562fe
@ -18600,6 +18600,10 @@ Call ParentNode.CustomSort(nil) to sort only the child nodes of a single node.
|
||||
</element><element name="TCustomListView.OnDataHint"><short>Called for owner-data mode.</short>
|
||||
</element><element name="TCustomListView.OnDataStateChange"><short>Called for owner-data mode.</short>
|
||||
</element>
|
||||
<element name="TListColumn.SortIndicator"><short>Indicator of the sorting order. Serves only the visual purpose, doesn't affect the actual sorting order</short>
|
||||
</element><element name="TCustomListView.AutoSortIndicator"><short>If AutoSort is used on TListView, this property controls, if TListView should also automatically set SortIndicator for the selected sorting column</short><seealso><link id="TListColumn.SortIndicator"/>SortIndicator</link>
|
||||
</seealso>
|
||||
</element>
|
||||
</module>
|
||||
<!-- ComCtrls -->
|
||||
</package>
|
||||
|
@ -1187,6 +1187,8 @@ type
|
||||
|
||||
TWidth = 0..MaxInt;
|
||||
|
||||
TSortIndicator = (siNone, siAscending, siDescending);
|
||||
|
||||
TListColumn = class(TCollectionItem)
|
||||
private
|
||||
FAlignment: TAlignment;
|
||||
@ -1198,6 +1200,7 @@ type
|
||||
FWidth: TWidth;
|
||||
FImageIndex: TImageIndex;
|
||||
FTag: PtrInt;
|
||||
FSortIndicator: TSortIndicator;
|
||||
function GetWidth: TWidth;
|
||||
procedure WSCreateColumn;
|
||||
procedure WSDestroyColumn;
|
||||
@ -1211,6 +1214,7 @@ type
|
||||
procedure SetCaption(const AValue: TTranslateString);
|
||||
procedure SetAlignment(const AValue: TAlignment);
|
||||
procedure SetImageIndex(const AValue: TImageIndex);
|
||||
procedure SetSortIndicator(AValue: TSortIndicator);
|
||||
protected
|
||||
procedure SetIndex(AValue: Integer); override;
|
||||
function GetDisplayName: string; override;
|
||||
@ -1230,6 +1234,7 @@ type
|
||||
property Tag: PtrInt read FTag write FTag default 0;
|
||||
property Visible: Boolean read FVisible write SetVisible default true;
|
||||
property Width: TWidth read GetWidth write SetWidth default 50;
|
||||
property SortIndicator: TSortIndicator read FSortIndicator write SetSortIndicator default siNone;
|
||||
end;
|
||||
|
||||
|
||||
@ -1372,6 +1377,7 @@ type
|
||||
FEditor: TCustomListViewEditor;
|
||||
FAllocBy: Integer;
|
||||
FAutoSort: Boolean;
|
||||
FAutoSortIndicator: Boolean;
|
||||
FAutoWidthLastColumn: Boolean;
|
||||
FCanvas: TCanvas;
|
||||
FDefaultItemHeight: integer;
|
||||
@ -1536,6 +1542,7 @@ type
|
||||
protected
|
||||
property AllocBy: Integer read FAllocBy write SetAllocBy default 0;
|
||||
property AutoSort: Boolean read FAutoSort write FAutoSort default True;
|
||||
property AutoSortIndicator: Boolean read FAutoSortIndicator write FAutoSortIndicator default False;
|
||||
property AutoWidthLastColumn: Boolean read FAutoWidthLastColumn write SetAutoWidthLastColumn default False;
|
||||
property ColumnClick: Boolean index Ord(lvpColumnClick) read GetProperty write SetProperty default True;
|
||||
property Columns: TListColumns read FColumns write SetColumns;
|
||||
@ -1654,6 +1661,7 @@ type
|
||||
property AllocBy;
|
||||
property Anchors;
|
||||
property AutoSort;
|
||||
property AutoSortIndicator;
|
||||
property AutoWidthLastColumn: Boolean read FAutoWidthLastColumn write SetAutoWidthLastColumn default False; // resize last column to fit width of TListView
|
||||
property BorderSpacing;
|
||||
property BorderStyle;
|
||||
|
@ -209,6 +209,10 @@ end;
|
||||
{ TCustomListView ColClick }
|
||||
{------------------------------------------------------------------------------}
|
||||
procedure TCustomListView.ColClick(AColumn: TListColumn);
|
||||
const
|
||||
DirToIndicator : array [TSortDirection] of TSortIndicator = (siAscending, siDescending);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
if IsEditing then
|
||||
begin
|
||||
@ -226,8 +230,14 @@ begin
|
||||
if SortType <> stNone then
|
||||
begin
|
||||
if AColumn.Index <> SortColumn then begin
|
||||
if FAutoSortIndicator then
|
||||
for i:=0 to Columns.Count-1 do
|
||||
if (i <> AColumn.Index) and (Columns[i].SortIndicator <> siNone) then
|
||||
Columns[i].SortIndicator := siNone;
|
||||
|
||||
SortColumn := AColumn.Index;
|
||||
SortDirection := sdAscending;
|
||||
if FAutoSortIndicator then AColumn.SortIndicator := siAscending;
|
||||
end
|
||||
else
|
||||
begin
|
||||
@ -236,6 +246,7 @@ begin
|
||||
SortDirection := sdDescending
|
||||
else
|
||||
SortDirection := sdAscending;
|
||||
if FAutoSortIndicator then AColumn.SortIndicator := DirToIndicator[SortDirection];
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
@ -95,6 +95,8 @@ begin
|
||||
end;
|
||||
WSC.ColumnSetImage(LV, Index, Self, FImageIndex);
|
||||
WSC.ColumnSetVisible(LV, Index, Self, FVisible);
|
||||
if FSortIndicator<>siNone then
|
||||
WSC.ColumnSetSortIndicator(LV, Index, Self, FSortIndicator);
|
||||
end;
|
||||
|
||||
procedure TListColumn.WSDestroyColumn;
|
||||
@ -139,6 +141,19 @@ begin
|
||||
Result := FWidth;
|
||||
end;
|
||||
|
||||
procedure TListColumn.SetSortIndicator(AValue: TSortIndicator);
|
||||
var
|
||||
LV: TCustomListView;
|
||||
begin
|
||||
if FSortIndicator = AValue then Exit;
|
||||
FSortIndicator := AValue;
|
||||
Changed(False);
|
||||
if not WSUpdateAllowed then Exit;
|
||||
|
||||
LV := TListColumns(Collection).FOwner;
|
||||
TWSCustomListViewClass(LV.WidgetSetClass).ColumnSetSortIndicator(LV, Index, Self, FSortIndicator);
|
||||
end;
|
||||
|
||||
procedure TListColumn.SetAlignment(const AValue: TAlignment);
|
||||
var
|
||||
LV: TCustomListView;
|
||||
|
@ -158,6 +158,7 @@ type
|
||||
class procedure ColumnSetMinWidth(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AColumn: TListColumn; const AMinWidth: integer); override;
|
||||
class procedure ColumnSetWidth(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AColumn: TListColumn; const AWidth: Integer); override;
|
||||
class procedure ColumnSetVisible(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AColumn: TListColumn; const AVisible: Boolean); override;
|
||||
class procedure ColumnSetSortIndicator(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const ASortIndicator: TSortIndicator); override;
|
||||
|
||||
// Item
|
||||
class procedure ItemDelete(const ALV: TCustomListView; const AIndex: Integer); override;
|
||||
@ -1232,6 +1233,29 @@ begin
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
class procedure TCocoaWSCustomListView.ColumnSetSortIndicator(
|
||||
const ALV: TCustomListView; const AIndex: Integer;
|
||||
const AColumn: TListColumn; const ASortIndicator: TSortIndicator);
|
||||
var
|
||||
lTableLV: TCocoaTableListView;
|
||||
lNSColumn: NSTableColumn;
|
||||
begin
|
||||
if not CheckColumnParams(lTableLV, lNSColumn, ALV, AIndex) then Exit;
|
||||
|
||||
case ASortIndicator of
|
||||
siNone:
|
||||
lTableLV.setIndicatorImage_inTableColumn(nil, lNSColumn);
|
||||
siAscending:
|
||||
lTableLV.setIndicatorImage_inTableColumn(
|
||||
NSImage.imageNamed(NSSTR('NSAscendingSortIndicator')),
|
||||
lNSColumn);
|
||||
siDescending:
|
||||
lTableLV.setIndicatorImage_inTableColumn(
|
||||
NSImage.imageNamed(NSSTR('NSDescendingSortIndicator')),
|
||||
lNSColumn);
|
||||
end;
|
||||
end;
|
||||
|
||||
class procedure TCocoaWSCustomListView.ItemDelete(const ALV: TCustomListView;
|
||||
const AIndex: Integer);
|
||||
var
|
||||
|
@ -153,6 +153,9 @@ type
|
||||
class procedure ColumnSetMinWidth(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AColumn: TListColumn; const AMinWidth: integer); override;
|
||||
class procedure ColumnSetWidth(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AColumn: TListColumn; const AWidth: Integer); override;
|
||||
class procedure ColumnSetVisible(const ALV: TCustomListView; const AIndex: Integer; const {%H-}AColumn: TListColumn; const AVisible: Boolean); override;
|
||||
class procedure ColumnSetSortIndicator(const ALV: TCustomListView; const AIndex: Integer;
|
||||
const AColumn: TListColumn; const ASortIndicator: TSortIndicator);
|
||||
override;
|
||||
|
||||
// items
|
||||
class procedure ItemDelete(const ALV: TCustomListView; const AIndex: Integer); override;
|
||||
|
@ -1083,6 +1083,36 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
class procedure TGtk2WSCustomListView.ColumnSetSortIndicator(
|
||||
const ALV: TCustomListView; const AIndex: Integer;
|
||||
const AColumn: TListColumn; const ASortIndicator: TSortIndicator);
|
||||
const
|
||||
GtkOrder : array [ TSortIndicator] of TGtkSortType = (0, GTK_SORT_ASCENDING, GTK_SORT_DESCENDING);
|
||||
var
|
||||
Widgets: PTVWidgets;
|
||||
GtkColumn: PGtkTreeViewColumn;
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ALV, 'ColumnSetCaption')
|
||||
then Exit;
|
||||
|
||||
GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
|
||||
|
||||
if not GTK_IS_TREE_VIEW(Widgets^.MainView) then
|
||||
Exit;
|
||||
|
||||
GtkColumn := gtk_tree_view_get_column(PGtkTreeView(Widgets^.MainView), AIndex);
|
||||
if GtkColumn <> nil then
|
||||
begin
|
||||
if ASortIndicator = siNone then
|
||||
gtk_tree_view_column_set_sort_indicator(GtkColumn, false)
|
||||
else
|
||||
begin
|
||||
gtk_tree_view_column_set_sort_indicator(GtkColumn, true);
|
||||
gtk_tree_view_column_set_sort_order(GtkColumn, GtkOrder[ASortIndicator]);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
class procedure TGtk2WSCustomListView.ItemDelete(const ALV: TCustomListView;
|
||||
const AIndex: Integer);
|
||||
var
|
||||
|
@ -128,6 +128,9 @@ type
|
||||
class procedure ColumnSetMinWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AMinWidth: integer); override;
|
||||
class procedure ColumnMove(const ALV: TCustomListView; const AOldIndex, ANewIndex: Integer; const AColumn: TListColumn); override;
|
||||
|
||||
class procedure ColumnSetSortIndicator(const ALV: TCustomListView; const AIndex: Integer;
|
||||
const AColumn: TListColumn; const ASortIndicator: TSortIndicator);
|
||||
override;
|
||||
|
||||
{items}
|
||||
class procedure ItemInsert(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem); override;
|
||||
@ -865,6 +868,33 @@ begin
|
||||
QtTreeWidget.Header.moveSection(AOldIndex, ANewIndex);
|
||||
end;
|
||||
|
||||
class procedure TQtWSCustomListView.ColumnSetSortIndicator(
|
||||
const ALV: TCustomListView; const AIndex: Integer;
|
||||
const AColumn: TListColumn; const ASortIndicator: TSortIndicator);
|
||||
const
|
||||
QtSortOrder : array [TSortIndicator] of QtSortOrder = (QtAscendingOrder, QtAscendingOrder, QtDescendingOrder);
|
||||
var
|
||||
QtTreeWidget: TQtTreeWidget;
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ALV, 'ColumnSetCaption') then
|
||||
Exit;
|
||||
|
||||
if IsIconView(ALV) then
|
||||
exit;
|
||||
|
||||
QtTreeWidget := TQtTreeWidget(ALV.Handle);
|
||||
if Assigned(QtTreeWidget) then
|
||||
begin
|
||||
if ASortIndicator = siNone then
|
||||
QtTreeWidget.Header.SetSortIndicatorVisible(false)
|
||||
else
|
||||
begin
|
||||
QtTreeWidget.Header.SetSortIndicatorVisible(true);
|
||||
QtTreeWidget.Header.SetSortIndicator(AIndex, QtSortOrder[ASortIndicator]);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TQtWSCustomListView.ColumnSetAlignment
|
||||
Params: None
|
||||
|
@ -137,6 +137,7 @@ type
|
||||
class procedure ColumnSetMinWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AMinWidth: integer); override;
|
||||
class procedure ColumnSetWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AWidth: Integer); override;
|
||||
class procedure ColumnSetVisible(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AVisible: Boolean); override;
|
||||
class procedure ColumnSetSortIndicator(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AAndicator: TSortIndicator); override;
|
||||
|
||||
// items
|
||||
class procedure ItemDelete(const ALV: TCustomListView; const AIndex: Integer); override;
|
||||
|
@ -484,6 +484,28 @@ begin
|
||||
else ListView_SetColumnWidth(ALV.Handle, AIndex, 0);
|
||||
end;
|
||||
|
||||
class procedure TWin32WSCustomListView.ColumnSetSortIndicator(
|
||||
const ALV: TCustomListView; const AIndex: Integer;
|
||||
const AColumn: TListColumn; const AAndicator: TSortIndicator);
|
||||
var
|
||||
Hdr: HWND;
|
||||
Itm: THDITEM;
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ALV, 'ColumnSetSortIndicator')
|
||||
then Exit;
|
||||
|
||||
Hdr := ListView_GetHeader(ALV.Handle);
|
||||
FillChar(itm, sizeof(itm),0);
|
||||
itm.mask := HDI_FORMAT;
|
||||
Header_GetItem(Hdr, AIndex, Itm);
|
||||
case AAndicator of
|
||||
siNone: itm.fmt := itm.fmt and (not (HDF_SORTDOWN or HDF_SORTUP));
|
||||
siAscending: itm.fmt := (itm.fmt or HDF_SORTUP) and (not HDF_SORTDOWN);
|
||||
siDescending: itm.fmt := (itm.fmt or HDF_SORTDOWN) and (not HDF_SORTUP);
|
||||
end;
|
||||
Header_SetItem(Hdr, AIndex, Itm);
|
||||
end;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Item code
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -120,6 +120,7 @@ type
|
||||
class procedure ColumnSetMinWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AMinWidth: integer); virtual;
|
||||
class procedure ColumnSetWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AWidth: Integer); virtual;
|
||||
class procedure ColumnSetVisible(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AVisible: Boolean); virtual;
|
||||
class procedure ColumnSetSortIndicator(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const ASortIndicator: TSortIndicator); virtual;
|
||||
|
||||
// Item
|
||||
class procedure ItemDelete(const ALV: TCustomListView; const AIndex: Integer); virtual;
|
||||
@ -539,6 +540,13 @@ class procedure TWSCustomListView.ColumnSetVisible(const ALV: TCustomListView;
|
||||
begin
|
||||
end;
|
||||
|
||||
class procedure TWSCustomListView.ColumnSetSortIndicator(
|
||||
const ALV: TCustomListView; const AIndex: Integer;
|
||||
const AColumn: TListColumn; const ASortIndicator: TSortIndicator);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
class procedure TWSCustomListView.ItemDelete(const ALV: TCustomListView;
|
||||
const AIndex: Integer);
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user