diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-06-23 11:40:18 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-06-23 11:40:18 +0000 |
commit | 987fecadc574ebd883e3b60605474e5ff797d9f3 (patch) | |
tree | 963d912d0c397015f200c5c34c58247e6bfe8157 /gui | |
parent | 0754cbcd4cbad38f68f67e1022287da0f51a3331 (diff) | |
download | fpGUI-987fecadc574ebd883e3b60605474e5ff797d9f3.tar.xz |
* Renamed all the VertScrollBar names that got screwed in a global Find-and-Replace a while back.
* Implemented keyboard navigation in the TFListBox (still experimental).
Diffstat (limited to 'gui')
-rw-r--r-- | gui/fpguigrid.inc | 20 | ||||
-rw-r--r-- | gui/fpguilayouts.inc | 2 | ||||
-rw-r--r-- | gui/fpguilistbox.inc | 125 | ||||
-rw-r--r-- | gui/fpguimemo.inc | 6 | ||||
-rw-r--r-- | gui/fpguiscrollbox.inc | 207 |
5 files changed, 223 insertions, 137 deletions
diff --git a/gui/fpguigrid.inc b/gui/fpguigrid.inc index b23a7fae..4747dea6 100644 --- a/gui/fpguigrid.inc +++ b/gui/fpguigrid.inc @@ -55,7 +55,7 @@ function GetRowHeights(ARow: Integer): Integer; procedure SetRowHeights(ARow, AHeight: Integer); procedure HorzScrollBarScroll(Sender: TObject; var APosition: Integer); - procedure VerTFScrollBarScroll(Sender: TObject; var APosition: Integer); + procedure VertScrollBarScroll(Sender: TObject; var APosition: Integer); protected ScrollingSupport: TScrollingSupport; procedure Paint(Canvas: TFCanvas); override; @@ -173,7 +173,7 @@ begin FCanExpandHeight := True; ScrollingSupport := TScrollingSupport.Create(Self); ScrollingSupport.HorzScrollBar.OnScroll := @HorzScrollBarScroll; - ScrollingSupport.VerTFScrollBar.OnScroll := @VerTFScrollBarScroll; + ScrollingSupport.VertScrollBar.OnScroll := @VertScrollBarScroll; FDefaultColWidth := 64; FDefaultRowHeight := 24; @@ -279,7 +279,7 @@ begin Inc(y); if y = FixedRows then - Inc(y, ScrollingSupport.VerTFScrollBar.Position); + Inc(y, ScrollingSupport.VertScrollBar.Position); end; @@ -301,7 +301,7 @@ begin Inc(y); if y = FixedRows then - Inc(y, ScrollingSupport.VerTFScrollBar.Position); + Inc(y, ScrollingSupport.VertScrollBar.Position); end; x := 0; @@ -430,7 +430,7 @@ begin for i := OldRowCount to FRowCount - 1 do FRowHeights^[i] := FDefaultRowHeight; - ScrollingSupport.VerTFScrollBar.Max := RowCount - FixedRows - 1; + ScrollingSupport.VertScrollBar.Max := RowCount - FixedRows - 1; RowHeightsChanged; SizeChanged(FColCount, OldRowCount); @@ -451,7 +451,7 @@ begin if AFixedRows <> FixedRows then begin FFixedRows := AFixedRows; - ScrollingSupport.VerTFScrollBar.Max := RowCount - FixedRows - 1; + ScrollingSupport.VertScrollBar.Max := RowCount - FixedRows - 1; end; end; @@ -536,18 +536,18 @@ begin end; end; -procedure TFCustomGrid.VerTFScrollBarScroll(Sender: TObject; +procedure TFCustomGrid.VertScrollBarScroll(Sender: TObject; var APosition: Integer); var i, Delta: Integer; r: TRect; begin Delta := 0; - if APosition > ScrollingSupport.VerTFScrollBar.Position then - for i := ScrollingSupport.VerTFScrollBar.Position to APosition - 1 do + if APosition > ScrollingSupport.VertScrollBar.Position then + for i := ScrollingSupport.VertScrollBar.Position to APosition - 1 do Dec(Delta, RowHeights[i + FixedRows] + 1) else - for i := APosition to ScrollingSupport.VerTFScrollBar.Position - 1 do + for i := APosition to ScrollingSupport.VertScrollBar.Position - 1 do Inc(Delta, RowHeights[i + FixedRows] + 1); // Scroll the grid body diff --git a/gui/fpguilayouts.inc b/gui/fpguilayouts.inc index 72f8ee92..cf5d76fe 100644 --- a/gui/fpguilayouts.inc +++ b/gui/fpguilayouts.inc @@ -849,7 +849,7 @@ begin if FHorzAlign = horzFill then w := Min(BoundsSize.cx, item.Widget.MaxSize.cx); end; - item.Widget.SetBounds(Point(xpos, ypos), gfxbase.Size(w, h)); + item.Widget.SetBounds(Point(xpos, ypos), Size(w, h)); end; FreeMem(sizes); diff --git a/gui/fpguilistbox.inc b/gui/fpguilistbox.inc index cbba2067..abea4016 100644 --- a/gui/fpguilistbox.inc +++ b/gui/fpguilistbox.inc @@ -20,6 +20,8 @@ {$IFDEF read_interface} + { TFCustomListBox } + TFCustomListBox = class(TFWidget) private FHotTrack: Boolean; @@ -36,12 +38,12 @@ procedure Paint(Canvas: TFCanvas); override; function ProcessEvent(Event: TEventObj): Boolean; override; function DistributeEvent(Event: TEventObj): Boolean; override; -// procedure EvKeyPressed(Key: Word; Shift: TShiftState); override; + procedure EvKeyPressed(Key: Word; Shift: TShiftState); override; procedure CalcSizes; override; procedure Resized; override; procedure RecalcWidth; procedure UpdateScrollBars; - procedure RedrawItem(AIndex: Integer); + function RedrawItem(AIndex: Integer): TRect; property CanExpandWidth default True; property CanExpandHeight default True; property HotTrack: Boolean read FHotTrack write FHotTrack default False; @@ -125,10 +127,8 @@ begin FCanExpandHeight := True; ScrollingSupport := TScrollingSupport.Create(Self); - ScrollingSupport.HorzScrollBar.OnScroll := - @ScrollingSupport.DefHorzScrollHandler; - ScrollingSupport.VerTFScrollBar.OnScroll := - @ScrollingSupport.DefVertScrollHandler; + ScrollingSupport.HorzScrollBar.OnScroll := @ScrollingSupport.DefHorzScrollHandler; + ScrollingSupport.VertScrollBar.OnScroll := @ScrollingSupport.DefVertScrollHandler; Items := TFListBoxStrings.Create(Self); FItemIndex := -1; UpdateScrollBars; @@ -141,9 +141,6 @@ begin inherited Destroy; end; - -// protected methods - procedure TFCustomListBox.Paint(Canvas: TFCanvas); var i, StartIndex, EndIndex: Integer; @@ -160,7 +157,7 @@ begin Canvas.FillRect(ScrollingSupport.ClientRect); Style.SetUIColor(Canvas, clWindowText); - with ScrollingSupport.VerTFScrollBar do + with ScrollingSupport.VertScrollBar do begin StartIndex := Position div ItemHeight; EndIndex := (Position + PageSize) div ItemHeight; @@ -228,11 +225,100 @@ begin inherited DistributeEvent(Event); end; +procedure TFCustomListBox.EvKeyPressed(Key: Word; Shift: TShiftState); +var + mshift: TShiftState; + HorzScrollBar: TFScrollBar; + VertScrollBar: TFScrollBar; + r: TRect; +begin +// writeln('Before FItemIndex=' + IntToStr(FItemIndex)); + HorzScrollBar := ScrollingSupport.HorzScrollBar; + VertScrollBar := ScrollingSupport.VertScrollBar; + + mshift := Shift * [ssShift, ssAlt, ssCtrl, ssMeta, ssSuper, ssHyper, ssAltGr]; + if mshift = [] then + case Key of +// keyLeft: +// HorzScrollBar.ButtonUpClick(nil); +// keyRight: +// HorzScrollBar.ButtonDownClick(nil); + keyUp: + begin +// writeln('keyup'); + if FItemIndex > 0 then + begin + RedrawItem(ItemIndex); + Dec(FItemIndex); + r := RedrawItem(ItemIndex); + // we should only call this when focus rect is out of view + if not PtInRect(ScrollingSupport.ClientRect, Point(r.Left, r.Top)) then + begin + VertScrollBar.ButtonUpClick(nil); + end; + end; + end; + keyDown: + begin +// writeln('keydown'); + if FItemIndex < (Items.Count - 1) then + begin + RedrawItem(ItemIndex); + Inc(FItemIndex); + r := RedrawItem(ItemIndex); + // we should only call this when focus rect is out of view + if not PtInRect(ScrollingSupport.ClientRect, Point(r.Left, r.Bottom)) then + begin + VertScrollBar.ButtonDownClick(nil); + end; + end; + end; + keyPageUp: + VertScrollBar.PageUp; + keyPageDown: + VertScrollBar.PageDown; + keyHome: + begin + RedrawItem(ItemIndex); + FItemIndex := 0; + RedrawItem(ItemIndex); + VertScrollBar.Position := 0; + end; + keyEnd: + begin + RedrawItem(ItemIndex); + FItemIndex := (Items.Count - 1); + RedrawItem(ItemIndex); + VertScrollBar.Position := VertScrollBar.Max - VertScrollBar.PageSize; + end; + keyReturn: + begin + if Assigned(OnClick) then + OnClick(Self); + end; + end + else if mshift = [ssShift] then + case Key of + keyPageUp: + HorzScrollBar.PageUp; + keyPageDown: + HorzScrollBar.PageDown; + keyHome: + HorzScrollBar.Position := 0; + keyEnd: + HorzScrollBar.Position := HorzScrollBar.Max - HorzScrollBar.PageSize; + end + else + inherited EvKeyPressed(Key, Shift); + +// writeln('After FItemIndex=' + IntToStr(FItemIndex)); +end; + procedure TFCustomListBox.CalcSizes; begin ScrollingSupport.CalcSizes; ItemHeight := FindForm.Wnd.Canvas.FontCellHeight; - ScrollingSupport.VerTFScrollBar.SmallChange := ItemHeight; + ScrollingSupport.VertScrollBar.SmallChange := ItemHeight; RecalcWidth; end; @@ -265,21 +351,20 @@ begin Size(FMaxItemWidth, Items.Count * ItemHeight - 1)); end; -procedure TFCustomListBox.RedrawItem(AIndex: Integer); +function TFCustomListBox.RedrawItem(AIndex: Integer): TRect; var ItemRect: TRect; begin if AIndex < 0 then - exit; //==> + Exit; //==> ItemRect := ScrollingSupport.ClientRect; - Inc(ItemRect.Top, AIndex * ItemHeight - - ScrollingSupport.VerTFScrollBar.Position); + Inc(ItemRect.Top, AIndex * ItemHeight - ScrollingSupport.VertScrollBar.Position); if (ItemRect.Top > ScrollingSupport.ClientRect.Bottom) or (ItemRect.Top + ItemHeight <= ScrollingSupport.ClientRect.Top) then - exit; - ItemRect.Bottom := Min(ItemRect.Top + ItemHeight, - ScrollingSupport.ClientRect.Bottom); + Exit; //==> + ItemRect.Bottom := Min(ItemRect.Top + ItemHeight, ScrollingSupport.ClientRect.Bottom); Redraw(ItemRect); + Result := ItemRect; end; @@ -318,11 +403,11 @@ begin if not PtInRect(ScrollingSupport.ClientRect, Event.Position) then begin Result := False; - exit; + Exit; //==> end; Index := (Event.Position.y - ScrollingSupport.ClientRect.Top + - ScrollingSupport.VerTFScrollBar.Position) div ItemHeight; + ScrollingSupport.VertScrollBar.Position) div ItemHeight; if (Index >= 0) and (Index < Items.Count) and ((Index <> ItemIndex) or (HotTrack and Event.InheritsFrom(TMouseReleasedEventObj))) then begin diff --git a/gui/fpguimemo.inc b/gui/fpguimemo.inc index 7fec6cad..f1774c17 100644 --- a/gui/fpguimemo.inc +++ b/gui/fpguimemo.inc @@ -164,7 +164,7 @@ begin Canvas.FillRect(FScrollingSupport.ClientRect); Style.SetUIColor(Canvas, clWindowText); - with FScrollingSupport.VerTFScrollBar do + with FScrollingSupport.VertScrollBar do begin StartIndex := Position div FItemHeight; EndIndex := (Position + PageSize) div FItemHeight; @@ -234,7 +234,7 @@ procedure TFCustomMemo.CalcSizes; begin FScrollingSupport.CalcSizes; FItemHeight := FindForm.Wnd.Canvas.FontCellHeight; - FScrollingSupport.VerTFScrollBar.SmallChange := FItemHeight; + FScrollingSupport.VertScrollBar.SmallChange := FItemHeight; RecalcWidth; end; @@ -275,7 +275,7 @@ begin FScrollingSupport := TScrollingSupport.Create(Self); FScrollingSupport.HorzScrollBar.OnScroll := @FScrollingSupport.DefHorzScrollHandler; - FScrollingSupport.VerTFScrollBar.OnScroll := @FScrollingSupport.DefVertScrollHandler; + FScrollingSupport.VertScrollBar.OnScroll := @FScrollingSupport.DefVertScrollHandler; FLines := TFMemoStrings.Create(self); // SetBounds(10, 10, 180, 90); diff --git a/gui/fpguiscrollbox.inc b/gui/fpguiscrollbox.inc index 9c66b987..d374da10 100644 --- a/gui/fpguiscrollbox.inc +++ b/gui/fpguiscrollbox.inc @@ -26,9 +26,11 @@ FBorders: TRect; FClientRect: TRect; FVirtualSize: TSize; - FHorzScrollBar, FVerTFScrollBar: TFScrollBar; + FHorzScrollBar, FVertScrollBar: TFScrollBar; FOnClientRectChange: TNotifyEvent; function EvMouseWheel(Event: TMouseWheelEventObj): Boolean; + procedure EvKeyPressed(Key: Word; Shift: TShiftState); + protected public constructor Create(AParent: TFWidget); destructor Destroy; override; @@ -45,7 +47,7 @@ property Borders: TRect read FBorders; property ClientRect: TRect read FClientRect; property HorzScrollBar: TFScrollBar read FHorzScrollBar; - property VerTFScrollBar: TFScrollBar read FVerTFScrollBar; + property VertScrollBar: TFScrollBar read FVertScrollBar; property OnClientRectChange: TNotifyEvent read FOnClientRectChange write FOnClientRectChange; end; @@ -56,7 +58,6 @@ procedure Paint(Canvas: TFCanvas); override; function ProcessEvent(Event: TEventObj): Boolean; override; function DistributeEvent(Event: TEventObj): Boolean; override; -// procedure EvKeyPressed(Key: Word; Shift: TShiftState); override; procedure CalcSizes; override; procedure Resized; override; public @@ -87,11 +88,11 @@ begin HorzScrollBar.Embedded := True; HorzScrollBar.SetEmbeddedParent(Parent); - FVerTFScrollBar := TFScrollBar.Create(Parent); - VerTFScrollBar.Name := '_Scrolling_VertBar'; - VerTFScrollBar.Orientation := Vertical; - VerTFScrollBar.Embedded := True; - VerTFScrollBar.SetEmbeddedParent(Parent); + FVertScrollBar := TFScrollBar.Create(Parent); + VertScrollBar.Name := '_Scrolling_VertBar'; + VertScrollBar.Orientation := Vertical; + VertScrollBar.Embedded := True; + VertScrollBar.SetEmbeddedParent(Parent); end; destructor TScrollingSupport.Destroy; @@ -101,7 +102,7 @@ end; function TScrollingSupport.ProcessEvent(Event: TEventObj): Boolean; var - HorzScrollBarHeight, VerTFScrollBarWidth: Integer; + HorzScrollBarHeight, VertScrollBarWidth: Integer; Canvas: TFCanvas; begin if Event.InheritsFrom(TPaintEventObj) then @@ -111,20 +112,22 @@ begin else HorzScrollBarHeight := 0; - if VerTFScrollBar.Visible then - VerTFScrollBarWidth := VerTFScrollBar.MinSize.cx + if VertScrollBar.Visible then + VertScrollBarWidth := VertScrollBar.MinSize.cx else - VerTFScrollBarWidth := 0; + VertScrollBarWidth := 0; Canvas := TPaintEventObj(Event).Canvas; Parent.Style.DrawScrollBoxBorder(Canvas, Rect(0, 0, Parent.Width, Parent.Height)); - Parent.Style.DrawWindowBackground(Canvas, Rect(VerTFScrollBar.Left, - HorzScrollBar.Top, VerTFScrollBar.Left + VerTFScrollBarWidth, + Parent.Style.DrawWindowBackground(Canvas, Rect(VertScrollBar.Left, + HorzScrollBar.Top, VertScrollBar.Left + VertScrollBarWidth, HorzScrollBar.Top + HorzScrollBarHeight)); Result := False; end else if Event.InheritsFrom(TMouseWheelEventObj) then Result := EvMouseWheel(TMouseWheelEventObj(Event)) + else if Event.InheritsFrom(TMouseWheelEventObj) then + Result := EvMouseWheel(TMouseWheelEventObj(Event)) else Result := False; end; @@ -132,7 +135,7 @@ end; function TScrollingSupport.DistributeEvent(Event: TEventObj): Boolean; begin Result := Event.SendToChild(HorzScrollBar) or - Event.SendToChild(VerTFScrollBar); + Event.SendToChild(VertScrollBar); end; function TScrollingSupport.SendToChild(AChild: TFWidget; @@ -146,7 +149,7 @@ begin Canvas := TPaintEventObj(Event).Canvas; OldMatrix := Canvas.Matrix; Canvas.AppendTranslation(Point(ClientRect.Left - HorzScrollBar.Position, - ClientRect.Top - VerTFScrollBar.Position)); + ClientRect.Top - VertScrollBar.Position)); Result := Event.SendToChild(AChild); Canvas.Matrix := OldMatrix; end else if Event.InheritsFrom(TPaintEventObj) then @@ -154,8 +157,7 @@ begin Canvas := TPaintEventObj(Event).Canvas; Canvas.SaveState; try - Canvas.AppendTranslation(Point(-HorzScrollBar.Position, - -VerTFScrollBar.Position)); + Canvas.AppendTranslation(Point(-HorzScrollBar.Position, -VertScrollBar.Position)); if Canvas.IntersectClipRect(ClientRect) {and Canvas.IntersectClipRect( Rect(AChild.Left + ClientRect.Left, AChild.Top + ClientRect.Top, AChild.Left + AChild.Width + ClientRect.Left, @@ -166,7 +168,7 @@ begin Inc(Event.RefCount); Result := AChild.SendEvent(Event);} Canvas.AppendTranslation(ClientRect.TopLeft); - Result := Event.SendToChild(AChild); + Result := Event.SendToChild(AChild); end else Result := False; finally @@ -181,16 +183,16 @@ begin FBorders := Parent.Style.GetScrollBoxBorders; with Parent, Borders do begin - FMinSize := HorzScrollBar.MinSize + VerTFScrollBar.MinSize + + FMinSize := HorzScrollBar.MinSize + VertScrollBar.MinSize + TopLeft + BottomRight; - FDefSize := HorzScrollBar.DefSize + VerTFScrollBar.DefSize + + FDefSize := HorzScrollBar.DefSize + VertScrollBar.DefSize + TopLeft + BottomRight; end; end; procedure TScrollingSupport.Resized; var - HorzScrollBarHeight, VerTFScrollBarWidth: Integer; + HorzScrollBarHeight, VertScrollBarWidth: Integer; procedure CalcScrollBarSizes; begin @@ -199,10 +201,10 @@ var else HorzScrollBarHeight := 0; - if VerTFScrollBar.Visible then - VerTFScrollBarWidth := VerTFScrollBar.MinSize.cx + if VertScrollBar.Visible then + VertScrollBarWidth := VertScrollBar.MinSize.cx else - VerTFScrollBarWidth := 0; + VertScrollBarWidth := 0; end; var @@ -210,15 +212,15 @@ var HorzBarVisible, VertBarVisible, LastHorzBarVisible, LastVertBarVisible: Boolean; begin - HorzBarVisible := HorzScrollBar.Visible; - VertBarVisible := VerTFScrollBar.Visible; - LastHorzBarVisible := not HorzBarVisible; + HorzBarVisible := HorzScrollBar.Visible; + VertBarVisible := VertScrollBar.Visible; + LastHorzBarVisible := not HorzBarVisible; if FVirtualSize <> gfxbase.Size(0, 0) then - with gfxbase.Size(ClientRect) do + with Size(ClientRect) do begin - HorzScrollBar.PageSize := cx; - VerTFScrollBar.PageSize := cy; + HorzScrollBar.PageSize := cx; + VertScrollBar.PageSize := cy; end; FBorders := Parent.Style.GetScrollBoxBorders; @@ -232,22 +234,20 @@ begin CalcScrollBarSizes; HorzScrollBar.SetBounds( Point(Left, Parent.Height - HorzScrollBar.MinSize.cy - Bottom), - gfxbase.Size(Parent.Width - VerTFScrollBarWidth - Left - Right, - HorzScrollBar.MinSize.cy)); - VerTFScrollBar.SetBounds( - Point(Parent.Width - VerTFScrollBar.MinSize.cx - Right, Top), - gfxbase.Size(VerTFScrollBar.MinSize.cx, - Parent.Height - HorzScrollBarHeight - Top - Bottom)); - - ClientRect.Left := Left; - ClientRect.Top := Top; - ClientRect.Right := Parent.Width - Right - VerTFScrollBarWidth; + Size(Parent.Width - VertScrollBarWidth - Left - Right, HorzScrollBar.MinSize.cy)); + VertScrollBar.SetBounds( + Point(Parent.Width - VertScrollBar.MinSize.cx - Right, Top), + Size(VertScrollBar.MinSize.cx, Parent.Height - HorzScrollBarHeight - Top - Bottom)); + + ClientRect.Left := Left; + ClientRect.Top := Top; + ClientRect.Right := Parent.Width - Right - VertScrollBarWidth; ClientRect.Bottom := Parent.Height - Bottom - HorzScrollBarHeight; if Assigned(OnClientRectChange) then OnClientRectChange(Self); HorzBarVisible := HorzScrollBar.Visible; - VertBarVisible := VerTFScrollBar.Visible; + VertBarVisible := VertScrollBar.Visible; end; end; end; @@ -255,29 +255,28 @@ end; function TScrollingSupport.CalcClientSize(AHorzBarVisible, AVertBarVisible: Boolean): TSize; begin - FBorders := Parent.Style.GetScrollBoxBorders; - Result := Parent.BoundsSize - Borders.TopLeft - Borders.BottomRight; + FBorders := Parent.Style.GetScrollBoxBorders; + Result := Parent.BoundsSize - Borders.TopLeft - Borders.BottomRight; if AVertBarVisible then - Dec(Result.cx, VerTFScrollBar.MinSize.cx); + Dec(Result.cx, VertScrollBar.MinSize.cx); if AHorzBarVisible then Dec(Result.cy, HorzScrollBar.MinSize.cy); end; procedure TScrollingSupport.SetVirtualSize(const ASize: TSize); begin - FVirtualSize := ASize; - HorzScrollBar.Max := FVirtualSize.cx; - VerTFScrollBar.Max := FVirtualSize.cy; + FVirtualSize := ASize; + HorzScrollBar.Max := FVirtualSize.cx; + VertScrollBar.Max := FVirtualSize.cy; end; function TScrollingSupport.ScrollPos: TPoint; begin Result.x := HorzScrollBar.Position; - Result.y := VerTFScrollBar.Position; + Result.y := VertScrollBar.Position; end; -procedure TScrollingSupport.DefHorzScrollHandler(Sender: TObject; - var APosition: Integer); +procedure TScrollingSupport.DefHorzScrollHandler(Sender: TObject; var APosition: Integer); var Delta: Integer; r: TRect; @@ -297,7 +296,7 @@ var Delta: Integer; r: TRect; begin - Delta := VerTFScrollBar.Position - APosition; + Delta := VertScrollBar.Position - APosition; r := ClientRect; if Delta < 0 then // Scrolling downwards Dec(r.Top, Delta) @@ -311,23 +310,65 @@ var mshift: TShiftState; begin if Parent.DistributeEvent(Event) then - exit; + Exit; //==> mshift := Event.Shift * [ssShift, ssAlt, ssCtrl, ssMeta, ssSuper, ssHyper, ssAltGr]; - if not VerTFScrollBar.Visible then + if not VertScrollBar.Visible then Include(mshift, ssShift); if mshift = [] then - VerTFScrollBar.Position := VerTFScrollBar.Position + - Round(Event.WheelDelta * VerTFScrollBar.SmallChange) + VertScrollBar.Position := VertScrollBar.Position + + Round(Event.WheelDelta * VertScrollBar.SmallChange) else if mshift = [ssShift] then HorzScrollBar.Position := HorzScrollBar.Position + - Round(Event.WheelDelta * VerTFScrollBar.SmallChange); + Round(Event.WheelDelta * VertScrollBar.SmallChange); Result := True; end; +procedure TScrollingSupport.EvKeyPressed(Key: Word; Shift: TShiftState); +var + mshift: TShiftState; +begin +{ + mshift := Shift * [ssShift, ssAlt, ssCtrl, ssMeta, ssSuper, ssHyper, ssAltGr]; + if mshift = [] then + case Key of + keyLeft: + HorzScrollBar.ButtonUpClick(nil); + keyRight: + HorzScrollBar.ButtonDownClick(nil); + keyUp: + VertScrollBar.ButtonUpClick(nil); + keyDown: + VertScrollBar.ButtonDownClick(nil); + keyPageUp: + VertScrollBar.PageUp; + keyPageDown: + VertScrollBar.PageDown; + keyHome: + VertScrollBar.Position := 0; + keyEnd: + VertScrollBar.Position := VertScrollBar.Max - VertScrollBar.PageSize; + end + else if mshift = [ssShift] then + case Key of + keyPageUp: + HorzScrollBar.PageUp; + keyPageDown: + HorzScrollBar.PageDown; + keyHome: + HorzScrollBar.Position := 0; + keyEnd: + HorzScrollBar.Position := HorzScrollBar.Max - HorzScrollBar.PageSize; + end + else + inherited EvKeyPressed(Key, Shift); +} +end; + + // =================================================================== // TFCustomScrollBox @@ -336,10 +377,10 @@ end; constructor TFCustomScrollBox.Create(AOwner: TComponent); begin inherited Create(AOwner); - WidgetStyle := WidgetStyle + [wsClickable, wsOpaque]; - FCanExpandWidth := True; - FCanExpandHeight := True; - ScrollingSupport := TScrollingSupport.Create(Self); + WidgetStyle := WidgetStyle + [wsClickable, wsOpaque]; + FCanExpandWidth := True; + FCanExpandHeight := True; + ScrollingSupport := TScrollingSupport.Create(Self); end; destructor TFCustomScrollBox.Destroy; @@ -356,8 +397,8 @@ begin Assert(Canvas = Canvas); { Style.DrawWindowBackground(Canvas, Rect(HorzScrollBar.Left, - VerTFScrollBar.Top, HorzScrollBar.Left + HorzScrollBar.Width, - VerTFScrollBar.Top + VerTFScrollBar.Height));} + VertScrollBar.Top, HorzScrollBar.Left + HorzScrollBar.Width, + VertScrollBar.Top + VertScrollBar.Height));} end; function TFCustomScrollBox.ProcessEvent(Event: TEventObj): Boolean; @@ -382,46 +423,6 @@ begin ScrollingSupport.Resized; end; -{ !!!: Move to TScrollingSupport as soon as this is a real event -procedure TFCustomScrollBox.EvKeyPressed(Key: Word; Shift: TShiftState); -var - mshift: TShiftState; -begin - mshift := Shift * [ssShift, ssAlt, ssCtrl, ssMeta, ssSuper, ssHyper, ssAltGr]; - if mshift = [] then - case Key of - keyLeft: - HorzScrollBar.ButtonUpClick(nil); - keyRight: - HorzScrollBar.ButtonDownClick(nil); - keyUp: - VerTFScrollBar.ButtonUpClick(nil); - keyDown: - VerTFScrollBar.ButtonDownClick(nil); - keyPageUp: - VerTFScrollBar.PageUp; - keyPageDown: - VerTFScrollBar.PageDown; - keyHome: - VerTFScrollBar.Position := 0; - keyEnd: - VerTFScrollBar.Position := VerTFScrollBar.Max - VerTFScrollBar.PageSize; - end - else if mshift = [ssShift] then - case Key of - keyPageUp: - HorzScrollBar.PageUp; - keyPageDown: - HorzScrollBar.PageDown; - keyHome: - HorzScrollBar.Position := 0; - keyEnd: - HorzScrollBar.Position := HorzScrollBar.Max - HorzScrollBar.PageSize; - end - else - inherited EvKeyPressed(Key, Shift); -end;} - {$ENDIF read_implementation} |