OnMouseWheelUp in FNCChat

Dear Friends,

In the FNCChat component, it appears that the OnMouseWheelUp and OnMouseWheelDown events do not fire when the "ChatWindow" have focus, the "ChatWindow" being the main part of the control where all the chat messages are shown.

The events DO fire if I click on the scrollbar and set focus on that, but not if I have the main window with all the messages.

I tried to use the OnVScroll event, but it only fires if the scrollbar is visible AND actually scrolls (which kinda makes sense), but it does not fire when the scrollbar have scrolled all the way to the top and i scroll upwards and that is excactly what I need - for automatically loading previous/older messages, or newer messages when i have scrolled all the way to the bottom and keeps on scrolling.

Delphi 10.4, FNC UI Pack (latest version), Windows 64-bit target, VCL application.

Hi,

TTMSFNCChat has a Reload mechanism, but detecting upward scrolling when the scroll position is already at the top is not possible with the current implementation. We'll need to look at this as soon as time permits, I put this on our TODO list for now.

Hi again,

Yes, I know and I have it enabled, but I'm kinda at a loss as how the "Reload" mechanism impacts the lack of OnMouseWheelUp and OnMouseWheelDown ?

If you meant to imply something with the reference to the Reload property, could you kindly explain what that is ?

You indicated that you want to load older messages so just wanted to mention Reload in case you were not aware. It could potentially be used as a workaround solution. For example: the top chat message presented as a "load older messages" button and calling StartReload programmatically when it's clicked.

OnMouseWheelUp and OnMouseWheelUp are not rooted because the underlying TTMSFNCTreeView is using these events. OnVScroll doesn't trigger for scrolling upwards for a similar reason - it's implemented that way in TTMSFNCTreeView. Unfortunately there's no out of the box solution for now, we'll see what can be done when we have some time to allocate on this.

I see.

Could the underlying TreeView component not forward those events to the FNCChat ?

..or can I hook into them somehow ?

I may not have explained myself properly, but the loading of older messages comes from the backend chat-server, where (when the user reaches the top of the list of displayed items) the application requests additional messages and when there are no more "old" messages, the backend signals to the application that the beginning of the archive have been reached.

But, that is why I need to be able to hook into the mousewheel events.

How does the position parameter in OnVScroll work ?

I can see that when the control have scrolled all the way to the top, the position is 0, bot how do I determine when I have reached the bottom ?

Right now, I'm using the "Header" and "Footer" for "Click here to load older" or "Click here to load more", but it's not quite as elegant as I wish it were..

You can access the OnMouseWheel events by using

type
  TTMSFNCChatOpen = class(TTMSFNCChat);

procedure TForm6.HandleMouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; var Handled: Boolean);
begin

end;

procedure TForm6.FormCreate(Sender: TObject);
begin
  TTMSFNCChatOpen(TMSFNCChat1).TreeView.OnMouseWheel := HandleMouseWheel;
end;

Hi Pieter,

Apparently the TreeView.OnMouseWheel event does not appear to be exposed and even if I do a variant on it and hook into the OnMouseWheelUp and Down events, nothing happens..

This malfunction does not have anything to do with you having the TTMSFNCCustomControlBaseCommon.HandleMouseWheel event defined but left with no actual code in it, does it ?

If you are using VCL, I suppose it's OnMouseWheelUp & OnMouseWheelDown?

Hi Pieter,

I supposed too as well, but it did no difference at all, unfortunately..

However..

After at good bit of debugging and stepping patiently through what actually happens when a control handles a mousewheel event, it appears that by setting Handled := True at last line of TTMSFNCCustomTreeView.HandleMouseWheel, any further processing of the event down the foodchain is blocked (as it should be of course).

But, by changing this to "False", all other controls down the foodchain receives this event, until someone finally sets it to "True".

So, by setting Handled := False at line 5924 in VCL.TMSFNCCustomTreeView, i suddenly start to receive the OnMouseWheel, OnMouseWheelUp and OnMouseWheelDown in both the owner form and the FNCChat controls, then after doing "my thing" in the OnMouseWheelUp event in FNCChat I set Handled := True and everybody is happy.

Thanks for reporting, we did some changes, next version address this. You'll be able to use events and handle the mousewheel actions.

You're welcome.

With the change I made all events fire as expected, so that will solve this challenge for now.

With the latest update to UI Pack, this "workaround" no longer works, so it's broken again.

Could you please post the changes you made, so I can apply them to the current version ?

Any news on this topic ?

The changes were made in TMS FNC Core at TTMSFNCCustomControl level. However, the following works as expected here:

procedure TForm1.FormCreate(Sender: TObject);
begin
  TTMSFNCChatOpen(TMSFNCChat1).TreeView.OnMouseWheelDown := HandleMouseWheelDown;
  TTMSFNCChatOpen(TMSFNCChat1).TreeView.OnMouseWheelUp := HandleMouseWheelUp;
end;

procedure TForm1.HandleMouseWheelDown(Sender: TObject; Shift: TShiftState;
  MousePos: TPoint; var Handled: Boolean);
begin
  TTMSFNCUtils.Log('Down');
end;

procedure TForm1.HandleMouseWheelUp(Sender: TObject; Shift: TShiftState;
  MousePos: TPoint; var Handled: Boolean);
begin
  TTMSFNCUtils.Log('Up');
end;

What are you doing differently?

I'm using the exported FNCChat.OnMouseWheelUp event, by basically double-clicking in the event on the Control.

Screenshot 2025-02-12 144517

On the same note, FNCChat.OnKeyDown doesn't work either, but that's probably the same remedy..

For the next version we are going to root the events so they can be used via TTMSFNCChat.OnMouseWheelDown/OnMouseWheelUp.

However, if we root the OnKeyUp/OnKeyDown events, they will be specifically for the chat messages part of the window. If you want something for the input area, that needs to be separately added (e.g. OnMemoKeyDown or OnInputKeyDown).

Sweet, I'm sure many other users will appreciate that as well :slight_smile:

With regards to KeyUp/Down I was more wondering from a practical perspective, for navigation purposes, be able to react to up/down arrow keys, to select the message above or below, scrolling through a list of messages..

Alternatively, call the OnMessageClick() event for when using the keyboard to select up or down in the list, I know it's not a click with the mouse, but it would make it possible to react, right now there's no way to support users who are navigating with the keyboard (I'm from the olden days of commandlines, so tend to do that)..

That should become possible with rooted OnKeyDown/OnKeyUp events.
Meanwhile we made the necessary changes internally, the next version will contain the improvements.

Perfect :slight_smile:

If I can get the MouseWheel events to work, I don't need the KeyPress event for now, but it sounds nice that it'll come in the next version.