diff --git a/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi b/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi index 01b396867..45798e3c3 100644 --- a/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi +++ b/components/rx/Demos/RxDBGrid/RxDBGridDemo.lpi @@ -80,14 +80,14 @@ - + - + @@ -111,21 +111,21 @@ - + - + - + @@ -139,46 +139,46 @@ - + - + - + - + - + - + - + @@ -201,7 +201,7 @@ - + @@ -228,34 +228,34 @@ - + - + - + - + - + @@ -278,34 +278,34 @@ - + - + - + - + - + @@ -315,7 +315,7 @@ - + @@ -356,7 +356,7 @@ - + @@ -377,14 +377,14 @@ - + - + @@ -425,7 +425,7 @@ - + @@ -434,7 +434,7 @@ - + @@ -444,7 +444,7 @@ - + @@ -463,14 +463,14 @@ - + - + @@ -478,7 +478,7 @@ - + @@ -486,7 +486,7 @@ - + diff --git a/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm b/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm index e845e8fa0..79db7f3f8 100644 --- a/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm +++ b/components/rx/Demos/RxDBGrid/rxdbgridmainunit.lfm @@ -1,11 +1,11 @@ object RxDBGridMainForm: TRxDBGridMainForm - Left = 299 + Left = 232 Height = 786 - Top = 6 + Top = 47 Width = 1187 ActiveControl = Panel1 Caption = 'RxDBGrid Demo' - ClientHeight = 761 + ClientHeight = 764 ClientWidth = 1187 Menu = MainMenu1 OnCreate = FormCreate @@ -13,8 +13,8 @@ object RxDBGridMainForm: TRxDBGridMainForm LCLVersion = '0.9.31' object RxDBGrid1: TRxDBGrid Left = 0 - Height = 696 - Top = 65 + Height = 698 + Top = 66 Width = 1187 TitleButtons = True AutoSort = True @@ -208,28 +208,29 @@ object RxDBGridMainForm: TRxDBGridMainForm Options = [dgEditing, dgTitles, dgIndicator, dgColumnResize, dgColumnMove, dgColLines, dgRowLines, dgTabs, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit, dgMultiselect, dgHeaderPushedLook] ParentColor = False PopupMenu = PopupMenu1 + Scrollbars = ssVertical TabOrder = 0 TitleStyle = tsNative UseXORFeatures = True end object Panel1: TPanel Left = 0 - Height = 65 + Height = 66 Top = 0 Width = 1187 Align = alTop AutoSize = True - ClientHeight = 65 + ClientHeight = 66 ClientWidth = 1187 TabOrder = 1 object Label1: TLabel AnchorSideLeft.Control = Button2 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 - Left = 260 - Height = 18 + Left = 279 + Height = 14 Top = 7 - Width = 36 + Width = 29 BorderSpacing.Around = 6 Caption = 'Mode' ParentColor = False @@ -240,7 +241,7 @@ object RxDBGridMainForm: TRxDBGridMainForm Left = 7 Height = 29 Top = 7 - Width = 84 + Width = 93 Action = actCalcTotal AutoSize = True BorderSpacing.Around = 6 @@ -250,10 +251,10 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Control = Button1 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 - Left = 97 + Left = 106 Height = 29 Top = 7 - Width = 157 + Width = 167 Action = actOptimizeColumnsWidthAll AutoSize = True BorderSpacing.Around = 6 @@ -264,11 +265,11 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = CheckBox2 AnchorSideTop.Side = asrBottom - Left = 489 - Height = 22 + Left = 508 + Height = 23 Hint = 'Use filter line' - Top = 35 - Width = 81 + Top = 36 + Width = 79 BorderSpacing.Left = 6 Caption = 'Use filter' OnChange = CheckBox1Change @@ -278,12 +279,12 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Control = Label1 AnchorSideTop.Control = Label1 AnchorSideTop.Side = asrBottom - Left = 266 + Left = 285 Height = 27 - Top = 31 + Top = 27 Width = 217 BorderSpacing.Around = 6 - ItemHeight = 0 + ItemHeight = 19 ItemIndex = 0 Items.Strings = ( 'Edit mode' @@ -298,11 +299,11 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Control = ComboBox1 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 - Left = 489 - Height = 22 + Left = 508 + Height = 23 Hint = 'Auto fill column width' Top = 7 - Width = 129 + Width = 128 BorderSpacing.Around = 6 Caption = 'Auto fill columns' OnChange = CheckBox2Change @@ -312,10 +313,10 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Control = CheckBox2 AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = Panel1 - Left = 624 - Height = 22 + Left = 642 + Height = 23 Top = 7 - Width = 117 + Width = 116 BorderSpacing.Around = 6 Caption = 'Show indicator' Checked = True @@ -328,10 +329,10 @@ object RxDBGridMainForm: TRxDBGridMainForm AnchorSideLeft.Side = asrBottom AnchorSideTop.Control = CheckBox3 AnchorSideTop.Side = asrBottom - Left = 624 - Height = 22 - Top = 35 - Width = 114 + Left = 642 + Height = 23 + Top = 36 + Width = 110 BorderSpacing.Around = 6 Caption = 'Show headers' Checked = True diff --git a/components/rx/rxdbgrid.pas b/components/rx/rxdbgrid.pas index 2b4fc32a7..74b84d3a6 100644 --- a/components/rx/rxdbgrid.pas +++ b/components/rx/rxdbgrid.pas @@ -370,7 +370,7 @@ type FFilterListEditor: TFilterListCellEditor; - + FOldPosition: Integer; FVersion: integer; FPropertyStorageLink: TPropertyStorageLink; FRxDbGridLookupComboEditor: TCustomControl; @@ -412,8 +412,9 @@ type procedure UpdateJMenuStates; procedure UpdateJMenuKeys; function SortEngineOptions: TRxSortEngineOptions; - - + procedure WMVScroll(var Message : TLMVScroll); message LM_VScroll; + procedure GetScrollbarParams(out aRange, aPage, aPos: Integer); + procedure RestoreEditor; //storage procedure OnIniSave(Sender: TObject); procedure OnIniLoad(Sender: TObject); @@ -1015,7 +1016,6 @@ begin ); end; - procedure TRxDBGrid.SetTitleButtons(const AValue: boolean); begin if AValue then @@ -1024,6 +1024,105 @@ begin Options := Options - [dgHeaderPushedLook]; end; +procedure TRxDBGrid.GetScrollbarParams(out aRange, aPage, aPos: Integer); +begin + if (DataSource.DataSet<>nil) and DataSource.DataSet.Active then begin + if DataSource.DataSet.IsSequenced then begin + aRange := DataSource.DataSet.RecordCount + VisibleRowCount - 1; + aPage := VisibleRowCount; + if aPage<1 then aPage := 1; + if DataSource.DataSet.BOF then aPos := 0 else + if DataSource.DataSet.EOF then aPos := aRange + else + aPos := DataSource.DataSet.RecNo - 1; // RecNo is 1 based + if aPos<0 then aPos:=0; + end else begin + aRange := 6; + aPage := 2; + if DataSource.DataSet.EOF then aPos := 4 else + if DataSource.DataSet.BOF then aPos := 0 + else aPos := 2; + end; + end else begin + aRange := 0; + aPage := 0; + aPos := 0; + end; +end; + +procedure TRxDBGrid.RestoreEditor; +begin + if EditorMode then begin + EditorMode := False; + EditorMode := True; + end; +end; + +procedure TRxDBGrid.WMVScroll(var Message: TLMVScroll); +var + IsSeq: boolean; + aPos, aRange, aPage: Integer; + DeltaRec: integer; + + function MaxPos: Integer; + begin + if IsSeq then + result := DataSource.DataSet.RecordCount - 1 + else + result := 4; + end; + + procedure DsMoveBy(Delta: Integer); + begin + DataSource.DataSet.MoveBy(Delta); + GetScrollbarParams(aRange, aPage, aPos); + end; + + procedure DsGoto(BOF: boolean); + begin + if BOF then DataSource.DataSet.First + else DataSource.DataSet.Last; + GetScrollbarParams(aRange, aPage, aPos); + end; + +begin + if not DataSource.DataSet.Active then exit; + + {$ifdef dbgDBGrid} + DebugLn('VSCROLL: Code=',SbCodeToStr(Message.ScrollCode), + ' Position=', dbgs(Message.Pos),' OldPos=',Dbgs(FOldPosition)); + {$endif} + + IsSeq := DataSource.DataSet.IsSequenced; + case Message.ScrollCode of + SB_TOP: + DsGoto(True); + SB_BOTTOM: + DsGoto(False); + SB_PAGEUP: + DsMoveBy(-VisibleRowCount); + SB_LINEUP: + DsMoveBy(-1); + SB_LINEDOWN: + DsMoveBy(1); + SB_PAGEDOWN: + DsMoveBy(VisibleRowCount); + SB_THUMBPOSITION: + DsMoveBy(Message.Pos - FOldPosition) + else + Exit; + end; + + ScrollBarPosition(SB_VERT, aPos); + FOldPosition:=aPos; + + if EditorMode then + RestoreEditor; + {$ifdef dbgDBGrid} + DebugLn('---- Diff=',dbgs(DeltaRec), ' FinalPos=',dbgs(aPos)); + {$endif} +end; + procedure TRxDBGrid.SetAutoSort(const AValue: boolean); var S: string;