diff options
Diffstat (limited to 'docview/components/richtext/RichTextView.pas')
-rw-r--r-- | docview/components/richtext/RichTextView.pas | 164 |
1 files changed, 90 insertions, 74 deletions
diff --git a/docview/components/richtext/RichTextView.pas b/docview/components/richtext/RichTextView.pas index ec1af338..e32c71ee 100644 --- a/docview/components/richtext/RichTextView.pas +++ b/docview/components/richtext/RichTextView.pas @@ -14,7 +14,6 @@ Uses fpg_imagelist, RichTextStyleUnit, RichTextLayoutUnit, -// RichTextDocumentUnit, CanvasFontManager; { @@ -50,9 +49,10 @@ Type TLinkEvent = procedure( Sender: TRichTextView; Link: string ) of object; - TRichTextView = Class( TfpgWidget ) + TRichTextView = class(TfpgWidget) private FPopupMenu: TfpgPopupMenu; + FScrollDistance: integer; procedure FVScrollbarScroll(Sender: TObject; position: integer); procedure FHScrollbarScroll(Sender: TObject; position: integer); procedure ShowDefaultPopupMenu(const x, y: integer; const shiftstate: TShiftState); virtual; @@ -64,6 +64,7 @@ Type Procedure SmoothScrollMIClick( Sender: TObject ); Procedure DebugMIClick( Sender: TObject ); Procedure DefaultMenuPopup( Sender: TObject ); + procedure SetScrollDistance(const AValue: integer); protected FFontManager: TCanvasFontManager; FRichTextSettings: TRichTextSettings; @@ -80,12 +81,12 @@ Type FOnClickLink: TLinkEvent; FDefaultMenu: TfpgPopupMenu; - FSelectAllMI: TfpgMenuItem; - FCopyMI: TfpgMenuItem; - FRefreshMI: TfpgMenuItem; - FWordWrapMI: TfpgMenuItem; - FSmoothScrollMI: TfpgMenuItem; - FDebugMI: TfpgMenuItem; + FSelectAllMI: TfpgMenuItem; + FCopyMI: TfpgMenuItem; + FRefreshMI: TfpgMenuItem; + FWordWrapMI: TfpgMenuItem; + FSmoothScrollMI: TfpgMenuItem; + FDebugMI: TfpgMenuItem; // Internal layout data FNeedVScroll, FNeedHScroll: boolean; @@ -138,6 +139,7 @@ Type procedure HandleMouseScroll(x, y: integer; shiftstate: TShiftState; delta: smallint); override; procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override; procedure HandleLMouseUp(x, y: integer; shiftstate: TShiftState); override; + procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); override; //procedure ScanEvent( Var KeyCode: TKeyCode; // RepeatCount: Byte ); override; @@ -244,8 +246,7 @@ Type PreserveSelection: boolean ); procedure MakeRowVisible( Row: longint ); - procedure MakeRowAndColumnVisible( Row: longint; - Column: longint ); + procedure MakeRowAndColumnVisible(Row: longint; Column: longint); // These two methods set selection start and end, // and redraw the screen, but do not set up cursor. @@ -367,6 +368,7 @@ Type property RichTextSettings: TRichTextSettings read FRichTextSettings; property ScrollBarWidth: longint read FScrollBarWidth write SetScrollBarWidth default 15; property SmoothScroll: boolean read FSmoothScroll write FSmoothScroll; + property ScrollDistance: integer read FScrollDistance write SetScrollDistance default 75; property UseDefaultMenu: boolean read FUseDefaultMenu write FUseDefaultMenu default True; property Debug: boolean read FDebug write SetDebug default False; property Images: TfpgImageList read FImages write SetImages; @@ -395,9 +397,6 @@ Type //Property OnSetupShow; //Property OnScan; - Protected - //Property Font; - End; @@ -407,7 +406,6 @@ uses SysUtils ,ACLStringUtility ,nvUtilities -// ControlScrolling, ControlsUtility, ,RichTextDocumentUnit ,RichTextDisplayUnit ; @@ -516,16 +514,12 @@ begin FSelectionEnd := -1; FSelectionStart := -1; - - // clear display of selection - { TODO -oGraeme : Draw must not be called here } -// Draw( StartLine, EndLine ); - Canvas.SetClipRect(OldClip); end; FSelectionEnd := -1; FSelectionStart := -1; + Repaint; end; Function TRichTextView.GetTextEnd: longint; @@ -539,7 +533,9 @@ begin FDefaultMenu.OnShow := @DefaultMenuPopup; FSelectAllMI := FDefaultMenu.AddMenuItem('Select &All', '', @SelectAllMIClick); + FSelectAllMI.Enabled := False; // TODO: implement me FCopyMI := FDefaultMenu.AddMenuItem('&Copy', '', @CopyMIClick); + FCopyMI.Enabled := False; // TODO: implement me FDefaultMenu.AddMenuItem('-', '', nil); FRefreshMI := FDefaultMenu.AddMenuItem('&Refresh', '', @RefreshMIClick); FDefaultMenu.AddMenuItem('-', '', nil); @@ -588,6 +584,17 @@ begin FDebugMI.Checked := Debug; end; +procedure TRichTextView.SetScrollDistance(const AValue: integer); +begin + if FScrollDistance = AValue then + exit; + FScrollDistance := AValue; + if Assigned(FVScrollBar) then + FVScrollBar.ScrollStep := FScrollDistance; + if Assigned(FHScrollBar) then + FHScrollBar.ScrollStep := FScrollDistance; +end; + constructor TRichTextView.Create(AOwner: TComponent); begin inherited Create(AOwner); @@ -755,14 +762,28 @@ procedure TRichTextView.HandleLMouseDown(x, y: integer; shiftstate: TShiftState) var Line: longint; Offset: longint; - Link: string; + Link: TfpgString; Position: TTextPosition; Shift: boolean; begin inherited HandleLMouseDown(x, y, shiftstate); + Offset := 0; Position := FindPoint( X, Y, Line, Offset, Link ); FClickedLink := Link; // writeln('Pos=', Ord(Position), ' link=', Link); + + if Position in [tpAboveTextArea, tpBelowTextArea] then + // not on the control (this probably won't happen) + exit; + + // if shift is pressed then keep the same selection start. + Shift := ssShift in ShiftState; + RemoveCursor; + + if not Shift then + ClearSelection; + + SetCursorPosition(Offset, Line, Shift); end; procedure TRichTextView.HandleLMouseUp(x, y: integer; shiftstate: TShiftState); @@ -774,6 +795,37 @@ begin FClickedLink := ''; // reset link end; +procedure TRichTextView.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); +var + Line: longint; + Offset: longint; + Link: TfpgString; + Position: TTextPosition; +begin + inherited HandleMouseMove(x, y, btnstate, shiftstate); + Position := FindPoint(X, Y, Line, Offset, Link); + + if Link <> FLastLinkOver then + begin + if Link <> '' then + begin + if Assigned(FOnOverLink) then + FOnOverLink(Self, Link) + end + else + begin + if Assigned(FOnNotOverLink) then + FOnNotOverLink(Self, FLastLinkOver); + end; + FLastLinkOver := Link; + end; + + if Link <> '' then + MouseCursor := mcHand + else + MouseCursor := mcDefault; // TODO: later this should be IBeam when RichView supports editing +end; + Destructor TRichTextView.Destroy; Begin FDefaultMenu.Free; @@ -1054,13 +1106,9 @@ begin TextHeight := GetTextAreaHeight; -// YToFind := Height - YToFind; - - //if FBorderStyle = bsSingle then - //begin - // dec( YToFind, 2 ); - // dec( XToFind, 2 ); - //end; + // Should we take into account Border Styles? + XToFind := XToFind - FRichTextSettings.Margins.Left; + YToFind := YToFind - FRichTextSettings.Margins.Top; if YToFind < 3 then begin @@ -1212,12 +1260,12 @@ begin FVScrollBar.Max := 0; end; - FHScrollBar.ScrollStep := 25; // pixels - FHScrollBar.PageSize := AvailableWidth - FHScrollbar.ScrollStep; // slightly less than width - FHScrollBar.SliderSize := AvailableWidth / MaxDisplayWidth; - FVScrollBar.ScrollStep := 25; // not used (line up/down calculated explicitly) - FVScrollBar.PageSize := AvailableHeight - FVScrollBar.ScrollStep; - FVScrollBar.SliderSize := AvailableHeight / FLayout.Height; + FHScrollBar.ScrollStep := FScrollDistance; // pixels + FHScrollBar.PageSize := AvailableWidth - FHScrollbar.ScrollStep; // slightly less than width + FHScrollBar.SliderSize := AvailableWidth / MaxDisplayWidth; + FVScrollBar.ScrollStep := FScrollDistance; // pixels + FVScrollBar.PageSize := AvailableHeight - FVScrollBar.ScrollStep; + FVScrollBar.SliderSize := AvailableHeight / FLayout.Height; // Physical horizontal scroll setup FHScrollbar.Visible := FNeedHScroll; @@ -1429,7 +1477,7 @@ begin Result := 0; end; -Function TRichTextView.GetLineUpPosition: longint; +function TRichTextView.GetLineUpPosition: longint; var FirstVisibleLine: longint; Offset: longint; @@ -1438,8 +1486,7 @@ begin Result := GetLineUpPositionFrom( FirstVisibleLine, Offset ); end; -Function TRichTextView.GetLineUpPositionFrom( FirstVisibleLine: longint; - Offset: longint ): longint; +function TRichTextView.GetLineUpPositionFrom( FirstVisibleLine: longint; Offset: longint ): longint; begin // we should never have scrolled all lines off the top!! assert( FirstVisibleLine <> -1 ); @@ -1456,15 +1503,13 @@ begin end; // scroll so that top line is fully visible... - Result := FVScrollBar.Position - - Offset; + Result := FVScrollBar.Position - Offset; if Offset < (FLayout.FLines^[ FirstVisibleLine ].Height div 2) then // more than half the line was already displayed so if FirstVisibleLine > 0 then // AND to make next line up visible dec( Result, FLayout.FLines^[ FirstVisibleLine - 1 ].Height ); - end; Function Sign( arg: longint ): longint; @@ -1533,54 +1578,26 @@ end; *) Procedure TRichTextView.DoVerticalScroll( NewY: longint ); -//var -// ScrollDistance: longint; begin FYScroll := 0 - NewY; - if not Visible then begin FLastYScroll := FYScroll; exit; end; - -// ScrollDistance := FYScroll - FLastYScroll; - - { TODO -ograeme -cscrolling : Implement vertical scrolling here } - //ScrollControlRect( Self, - // GetTextAreaRect, - // 0, - // ScrollDistance, - // Color, - // FSmoothScroll ); - FLastYScroll := FYScroll; RePaint; SetupCursor; end; Procedure TRichTextView.DoHorizontalScroll( NewX: longint ); -var - ScrollDistance: longint; begin FXScroll := NewX; - if not Visible then begin FLastXScroll := FXScroll; exit; end; - -// ScrollDistance := FXScroll - FLastXScroll; - - { TODO -ograemeg -cscrolling : Implement horizontal scrolling } - //ScrollControlRect( Self, - // GetTextAreaRect, - // - ScrollDistance, - // 0, - // Color, - // FSmoothScroll ); - FLastXScroll := FXScroll; RePaint; SetupCursor; @@ -1631,7 +1648,7 @@ begin s := Text; // Warning: Hack Alert! replace some strange Bell character found in some INF files // s := SubstituteChar(s, Chr($07), Chr($20) ); - s := StringReplace(s, Chr($07), '•', [rfReplaceAll, rfIgnoreCase]); + s := StringReplace(s, Chr($07), #$E2#$80#$A2, [rfReplaceAll, rfIgnoreCase]); // u+2022 small bullet //// Hack Alert #2: replace strange table chars with something we can actually see // s := SubstituteChar(s, Chr(218), Char('+') ); // top-left corner @@ -2405,8 +2422,9 @@ end; Procedure TRichTextView.SelectAll; begin ClearSelection; - SelectionStart := FLayout.GetCharIndex( FText ); - SelectionEnd := FLayout.GetTextEnd; + FSelectionStart := FLayout.GetCharIndex( FText ); + FSelectionEnd := FLayout.GetTextEnd; + Repaint; end; (* @@ -2781,21 +2799,19 @@ begin end; end; -procedure TRichTextView.MakeRowAndColumnVisible( Row: longint; - Column: longint ); +procedure TRichTextView.MakeRowAndColumnVisible(Row: longint; Column: longint); var X: Longint; begin MakeRowVisible( Row ); FLayout.GetXFromOffset( Column, Row, X ); - if X > FXScroll + GetTextAreaWidth then + if X > (FXScroll + GetTextAreaWidth) then // off the right SetHorizontalPosition( X - GetTextAreaWidth + 5 ) else if X < FXScroll then // off to left SetHorizontalPosition( X ); - end; function TRichTextView.LinkFromIndex( const CharIndexToFind: longint): string; |