LCL: Improve the column sort feature of TStringGrid. User defined glyphs are retained after sorting.

git-svn-id: trunk@30645 -
This commit is contained in:
juha 2011-05-09 19:49:46 +00:00
parent bf205acf8a
commit 16c323b485

View File

@ -365,6 +365,7 @@ type
FAlignment: ^TAlignment; FAlignment: ^TAlignment;
FFont: TFont; FFont: TFont;
FImageIndex: Integer; FImageIndex: Integer;
FOldImageIndex: Integer;
FImageLayout: TButtonLayout; FImageLayout: TButtonLayout;
FIsDefaultTitleFont: boolean; FIsDefaultTitleFont: boolean;
FLayout: ^TTextLayout; FLayout: ^TTextLayout;
@ -3253,17 +3254,23 @@ begin
// Remove glyph from previous column. // Remove glyph from previous column.
ColOfs := FSortColumn - FFixedCols; ColOfs := FSortColumn - FFixedCols;
if (ColOfs > -1) and (ColOfs < FColumns.Count ) then if (ColOfs > -1) and (ColOfs < FColumns.Count ) then
FColumns[ColOfs].Title.ImageIndex := -1; with FColumns[ColOfs].Title do
ImageIndex := FOldImageIndex;
end; end;
FSortColumn := index; FSortColumn := index;
ColOfs := index - FFixedCols; // For accessing FColumns[]. // Show the sort glyph only if clicked column has a TGridColumn defined.
// Show the right sort glyph. ColOfs := index - FFixedCols;
if (ColOfs > -1) and (ColOfs < FColumns.Count) if (ColOfs > -1) and (ColOfs < FColumns.Count)
and (FAscImgInd < TitleImageList.Count) and (FAscImgInd < TitleImageList.Count)
and (FDescImgInd < TitleImageList.Count) then and (FDescImgInd < TitleImageList.Count) then
case FSortOrder of with FColumns[ColOfs].Title do begin
soAscending: FColumns[ColOfs].Title.ImageIndex := FAscImgInd; // Save previous ImageIndex of the clicked column.
soDescending: FColumns[ColOfs].Title.ImageIndex := FDescImgInd; if (ImageIndex <> FAscImgInd) and (ImageIndex <> FDescImgInd) then
FOldImageIndex := ImageIndex;
case FSortOrder of // Show the right sort glyph.
soAscending: ImageIndex := FAscImgInd;
soDescending: ImageIndex := FDescImgInd;
end;
end; end;
Sort(True, index, FFixedRows, RowCount-1); Sort(True, index, FFixedRows, RowCount-1);
end; end;
@ -10064,6 +10071,7 @@ begin
FillTitleDefaultFont; FillTitleDefaultFont;
FFont.OnChange := @FontChanged; FFont.OnChange := @FontChanged;
FImageIndex := -1; FImageIndex := -1;
FOldImageIndex := -1;
FImageLayout := blGlyphRight; FImageLayout := blGlyphRight;
end; end;