Manually scroll RichViewEdit

General TRichView support forum. Please post your questions here
Post Reply
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Manually scroll RichViewEdit

Post by Marsianin »

I need to manually scroll RVE for some amount of lines (OnMouseWheel).
And this doesn't works for TRichView:

Code: Select all

SendMessage(RichViewEdit1.Handle,EM_LINESCROLL,0,WheelDelta);
RVE.ScrollBy works unexpectedly...
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Increase or decrease value of VScrollPos property.
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

It scrolls a lot not by line.
How can I scroll by line using WheelDelta from OnMouseWheel?
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

As I said, TRichViewEdit cannot scroll by lines, only by pixels.
All lines have different heights: one line can be 5 pixels in height, another line can be 500 pixels.

Increasing VScrollPos by 1 scrolls to minimal possible value (defined in VSmallStep).
You can decrease value of VSmallStep (before formatting), but if VScrollMax (= Document Height / VSmallStep) will exceed 32000, VSmallStep will be increased automatically
(this is because of the scrollbar range limitation).
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

But how wheel works for RVE when scrolls it for the fixed amount of lines?

Also line is a line even if it contains different font sizes you should measure line height by the highest symbol/picture and scroll is a just one line. I think.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

In the current version, TRichView does not scroll by the fixed amount of lines.
Sorry, I think that this type of scrolling is not worth implementing.
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

But it's common for all Windows controls.
If you open Windows Control Panel - Mouse - Wheel Tab you will see:

-----------------------------------------
Vertical Scrolling
Roll the wheel one notch to scroll:
The following number of lines at a time.
-----------------------------------------

So what is the better way to implement this wheel scrolling for RVE?

The problem why I need it is simple - RichViewEdit locks wheel when active so it scrolls RVE even if cursor is under another control. I don't like this behavior and want to scroll that control under which cursor is and not important if it focused or not.
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

Post by Marsianin »

Any suggestions on how to scroll by line?
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I think this setting should not be understood literally. Mouse wheel works in all scrollable controls, but not all controls have lines at all.

I tested Wordpad, MS Word, editor in Outlook Express. Only Wordpad seems to do mouse wheel scrolling by lines. Other editors scroll by the fixed amount.

PS: Mouse wheel scrolls the focused control: this is the default behavior of Windows (focused control receives mouse wheel messages). RichViewEdit does not capture mouse wheel input.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I can explain how to get information about lines.

RichView.RVData.DrawItems is a collection of drawing items (DLines.pas).
Each nontext item corresponds to one drawing item.
If text item is placed on one line, it corresponds to one drawing item. If it is placed on N lines, there is one drawing item for each line.

Items in the collection have the following main properties:
Left, Top - coordinates relative to the top left corner of the scrollable area
Width, Height
FromNewLine - true if this item starts a new line
ItemNo - index of item corresponding to this drawing item.

Now you know how information about lines are stored. You can compare coordinates with VScrollPos*VSmallStep (top of visible area) and VScrollPos*VSmallStep+ClientHeight (bottom of visible area) and scroll by assigning new value of VScrollPos.

PS: What do you want to do with tables? Without a special processing, table has one drawing item and will be treated as one line.
JonRobertson
Posts: 164
Joined: Tue Nov 08, 2011 5:11 pm

Post by JonRobertson »

Marsianin wrote:RichViewEdit locks wheel when active so it scrolls RVE even if cursor is under another control. I don't like this behavior and want to scroll that control under which cursor is and not important if it focused or not.
Sergey Tkachenko wrote:Mouse wheel scrolls the focused control: this is the default behavior of Windows (focused control receives mouse wheel messages). RichViewEdit does not capture mouse wheel input.
That may be the default behavior of Windows, but it is not the default behavior of many apps. Take the Delphi IDE for example. It is intuitive to move the mouse over a window that you want to scroll and use the mouse wheel without clicking to give the window focus. In Firefox, while editing this message, the memo box always has focus. But the mouse wheel scrolls the main window if the mouse is outside the edit box and scrolls the edit box if the mouse cursor is within the memo box.

We've done this on our forms using TForm.OnMouseWheel. You can check the coordinates of the mouse and determine based on coordinates which control you want the mouse wheel to scroll.

Unfortunately when a TSRichViewEdit has focus, TForm.OnMouseWheel does not receive wheel messages. I'm currently looking for a solution to this and came across this post from Marsianin.

Update: It looks like I need to override TCustomForm.MouseWheelHandler because it dispatches the MouseWheel message to any focused control. Which isn't what we want. But I no longer think the behavior is influenced by RichView.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Yes, I believe this problem must be solved on the application level, not on the level of specific controls.
Post Reply