diff --git a/X2UtSettingsForm.pas b/X2UtSettingsForm.pas index 2382b61..8b6c7d9 100644 --- a/X2UtSettingsForm.pas +++ b/X2UtSettingsForm.pas @@ -21,40 +21,42 @@ implementation type THackCustomForm = class(TCustomForm); -procedure ReadFormPos; +procedure ReadFormPos(const AFactory: TX2SettingsFactory; + const ASection: String; const AForm: TCustomForm); begin with AFactory[ASection] do - try - if ReadBool('Maximized', (AForm.WindowState = wsMaximized)) then - AForm.WindowState := wsMaximized - else with THackCustomForm(AForm) do begin - WindowState := wsNormal; - Position := poDesigned; - Left := ReadInteger('Left', Left); - Top := ReadInteger('Top', Top); - Width := ReadInteger('Width', Width); - Height := ReadInteger('Height', Height); - end; - finally - Free(); + try + if ReadBool('Maximized', (AForm.WindowState = wsMaximized)) then + AForm.WindowState := wsMaximized + else with THackCustomForm(AForm) do begin + WindowState := wsNormal; + Position := poDesigned; + Left := ReadInteger('Left', Left); + Top := ReadInteger('Top', Top); + Width := ReadInteger('Width', Width); + Height := ReadInteger('Height', Height); end; + finally + Free(); + end; end; -procedure WriteFormPos; +procedure WriteFormPos(const AFactory: TX2SettingsFactory; + const ASection: String; const AForm: TCustomForm); begin with AFactory[ASection] do - try - WriteBool('Maximized', (AForm.WindowState = wsMaximized)); - if AForm.WindowState <> wsMaximized then - with THackCustomForm(AForm) do begin - WriteInteger('Left', Left); - WriteInteger('Top', Top); - WriteInteger('Width', Width); - WriteInteger('Height', Height); - end; - finally - Free(); - end; + try + WriteBool('Maximized', (AForm.WindowState = wsMaximized)); + if AForm.WindowState <> wsMaximized then + with THackCustomForm(AForm) do begin + WriteInteger('Left', Left); + WriteInteger('Top', Top); + WriteInteger('Width', Width); + WriteInteger('Height', Height); + end; + finally + Free(); + end; end; end. diff --git a/X2UtSettingsVirtualTree.pas b/X2UtSettingsVirtualTree.pas new file mode 100644 index 0000000..63dc148 --- /dev/null +++ b/X2UtSettingsVirtualTree.pas @@ -0,0 +1,81 @@ +{ + :: X2UtSettingsVirtualTree provides functions to read and write VirtualTree + :: settings. + :: + :: Last changed: $Date: 2004-07-22 16:52:09 +0200 (Thu, 22 Jul 2004) $ + :: Revision: $Rev: 25 $ + :: Author: $Author: psycho $ +} +unit X2UtSettingsVirtualTree; + +interface +uses + VirtualTrees, + X2UtSettings; + + procedure ReadVTHeader(const AFactory: TX2SettingsFactory; + const ASection: String; const AHeader: TVTHeader); + procedure WriteVTHeader(const AFactory: TX2SettingsFactory; + const ASection: String; const AHeader: TVTHeader); + +implementation +uses + SysUtils; + +procedure ReadVTHeader(const AFactory: TX2SettingsFactory; + const ASection: String; const AHeader: TVTHeader); +var + iColumn: Integer; + sColumn: String; + +begin + with AFactory[ASection] do + try + AHeader.SortColumn := ReadInteger('SortColumn', AHeader.SortColumn); + if ReadBool('SortAscending', AHeader.SortDirection = sdAscending) then + AHeader.SortDirection := sdAscending + else + AHeader.SortDirection := sdDescending; + + for iColumn := 0 to Pred(AHeader.Columns.Count) do + with AHeader.Columns[iColumn] do + begin + sColumn := IntToStr(iColumn) + '.'; + Position := ReadInteger(sColumn + 'Position', Position); + Width := ReadInteger(sColumn + 'Width', Width); + if ReadBool(sColumn + 'Visible', coVisible in Options) then + Options := Options + [coVisible] + else + Options := Options - [coVisible]; + end; + finally + Free(); + end; +end; + +procedure WriteVTHeader(const AFactory: TX2SettingsFactory; + const ASection: String; const AHeader: TVTHeader); +var + iColumn: Integer; + sColumn: String; + +begin + with AFactory[ASection] do + try + WriteInteger('SortColumn', AHeader.SortColumn); + WriteBool('SortAscending', AHeader.SortDirection = sdAscending); + + for iColumn := 0 to Pred(AHeader.Columns.Count) do + with AHeader.Columns[iColumn] do + begin + sColumn := IntToStr(iColumn) + '.'; + WriteInteger(sColumn + 'Position', Position); + WriteInteger(sColumn + 'Width', Width); + WriteBool(sColumn + 'Visible', coVisible in Options); + end; + finally + Free(); + end; +end; + +end. diff --git a/X2UtVirtualTree.pas b/X2UtVirtualTree.pas index 40d1cab..d42b451 100644 --- a/X2UtVirtualTree.pas +++ b/X2UtVirtualTree.pas @@ -22,18 +22,20 @@ uses //:: SortColumn for the second time, so be sure not to rely on that. procedure SortColumn(const AHeader: TVTHeader; const AColumn: TColumnIndex; - const ASortColor: TColor = clNone); + const ASortColor: TColor = clNone; + const AApplySort: Boolean = True); //:$ Calculates the position of an image in a virtual string tree. function CalcImagePos(const ATree: TVirtualStringTree; const ANode: PVirtualNode; - const AItemRect: TRect): TPoint; + const ACellRect: TRect): TPoint; implementation procedure SortColumn(const AHeader: TVTHeader; const AColumn: TColumnIndex; - const ASortColor: TColor = clNone); + const ASortColor: TColor; + const AApplySort: Boolean); begin with AHeader do begin @@ -45,12 +47,13 @@ begin Tag := 0; end; - if SortColumn = AColumn then - SortDirection := TSortDirection(1 - Integer(SortDirection)) - else begin - SortColumn := AColumn; - SortDirection := sdAscending; - end; + if AApplySort then + if SortColumn = AColumn then + SortDirection := TSortDirection(1 - Integer(SortDirection)) + else begin + SortColumn := AColumn; + SortDirection := sdAscending; + end; if ASortColor <> clNone then with Columns[SortColumn] do @@ -63,16 +66,19 @@ end; function CalcImagePos(const ATree: TVirtualStringTree; const ANode: PVirtualNode; - const AItemRect: TRect): TPoint; + const ACellRect: TRect): TPoint; var pNode: PVirtualNode; begin - Result := AItemRect.TopLeft; + Result := ACellRect.TopLeft; with ATree do begin pNode := ANode; + if Assigned(pNode) and not (toShowRoot in ATree.TreeOptions.PaintOptions) then + pNode := pNode^.Parent; + while Assigned(pNode) and (pNode <> ATree.RootNode) do begin Inc(Result.X, Indent);