Virtual TreeView update hint within cell on mouse move - delphi

I'm using a TVirtualStringTree as a grid which is working pretty well.
I'm using the treeviews hint functionality to show a hint when the user positions the mouse over a cell. I've had to change HintMode to hmHint as I want my hints to appear regardless of the cell text length.
What I'm trying to do now is to display a different hint depending on whereabouts the mouse is within the cell.
I can do this no problem before the hint is displayed by using the OnGetHint event. My problem is this event is only raised a next time when the user moves the mouse to another cell.
I can't see to find a way to update the hint while its displayed and the mouse is moved within the same cell
I've looked at suggestions for other controls, using the Application's OnShowHint event but they just seem to make the hint disappear and not show again.
Anyone got any ideas?
Thanks
Update
After some investigation here is what I have found in case it helps someone come up with a solution:
The CMHintShow method sets the CursoRect field of the HintInfo record to the bounds of the cell. This seems to stop the VCl from triggering the hint code again until the mouse moves out of this rect (TApplication.HintMouseMessage).
If i set the CursorRect to something smaller than the cell bounds the hint will update. I use VTs in a few places for different purposes, so I can't make these changes directly. Would be good to get a solution that doesn't require this change.

In TBaseVirtualTree.CMHintShow right near the top, the code reads:
if PtInRect(FLastHintRect, HintInfo.CursorPos) then
Exit;
If you comment this out then the behaviour is closer to what you are looking for. The hint window won't show again if you move the mouse within the same cell, but if you click then it will.
I can't seem to find any way to make the hint window show in the same cell without that mouse click though!

Related

Why OnHScrollChange is not fired in stringgrid in Firemonkey?

Why OnHScrollChange is not fired in stringgrid in Firemonkey? How should i catch the scrolling event in Stringgrid?
OnHScrollChange is fired when you scroll with the scrollbar thumbgrip or its buttons. It is however not fired by changing the selection with the left and right arrow keys, even if that would result in the thumbgrip of the scrollbar being moved.
If your question is about the latter situation, I kind of agree with you that it should trigger the OnHScrollChange, but then again, I have no idea of any design decisions. You may want to enter a report at Embarcadero's Quality Portal and see how they respond.
Another possibility is to use the OnViewportPositionChange event instead which fires however the viewport position changes. The caveat is that it fires also on vertical scrolling. If this is ok for you then that is your solution.

Check out whether or not Focus Rect is required (Delphi)

Imagine that we have a form with two buttons on it. I run the application and I click on the first button. nothing happens and no focus rectangle is displayed. But when I press a key, it shows a focus rect on the button and even if I click on the second one, it moves the focus rect to it. So it doesn't display the focus rect unless I press a key. I'm creating my own component and I need to know whether or not I should display the focus rect to draw it.
How do I know it?
I think it's not meant to display the focus rectangle by default, that's until a keyboard accelerator is used. Read UI State on MSDN, that suggests WM_QUERYUISTATE should be used to determine if keyboard accelerators or focus indicators should be drawn or not.

TStringGrid dirty hack - Restricting the selection to one single row

I have a heavily modified control based on TStringGrid. I want to allow the user to make selections in this grid but restrict the selection one single row (the current row).
Implementation:
When the user presses the left mouse button I am using a dirty hack: On OnMouseDown event I capture the mouse cursor and keep it on the current row. The user can move the mouse device up and down on its pad but the cursor will not go up or down. It will stay on the current row. When the user releases the button (OnMouseUp event), I release the capture.
However, this hack is as I said very dirty. There are several problems. For example, if the user presses the left mouse button (LMB) and then without releasing that button it presses the right button, the associated pop-up menu will pop but the mouse capture will never be released. So, the mouse will be locked in a screen region until the user will has the brilliant idea to click the LMB one more time to unlock the mouse. This may be a bug in D7. There is a separate post about it here: TStringGrid - OnMouseUp is not called!
There is a elegant way to do this?
Edit:
OnSelectCell is not working. OnSelectCell event is called only once when you click the cell. If you keep the button pressed and move the mouse to expand the selection, OnSelectCell will not be called again.
Indeed MoveCurrent appears only in TCustomGrid.MouseDown.
Use the OnSelectCell event and set the CanSelect var parameter depending on whether the ARow parameter is what you want.
A nice solution
Check the options property on TStringGrid
There is an Option called 'goRangeSelect'
Set this to false using the object inspector
Or programatically this can be done by
StringGrid1.Options - [goRangeSelect];
This answer is not elegant at all, but it works.
My solution is NOT to use the PopupMenu property of the StringGrid. Instead I implemented my own PopUpMenu property. Works almost perfect. There is on small problem, the bottom of the pop-up menu appears next to the cursor and not its top.

Cause 'hint' to refire on listview as I move over items

Sure I've seen this done before but off-hand I can't find any examples.
I've got a TListView, set in 'report' viewstyle. It has about half a dozen subitems, and one thing we'd like to do is have the 'hint' (tooltip) on the listview dynamically show another field of data. That is, each time you move the mouse over any given row, the 'hint' would show some text relevant to that particular row.
I'm partway there - I can do this using the OnInfoTip method, but unfortunately once a tip has appeared, Windows seems to decide that I don't need to see a hint for the listview again until I move the mouse away from the listview and then back 'over' it again. Simply moving the mouse down to the next row, all-the-time keeping the mouse over the control, doesn't persuade the program to display the new hint.
Just to be clear - I've got OnInfoTip working so that the program does display the right hint relevant to the item I first moved the mouse over. Changing the hint text isn't the issue. The problem is that moving the mouse to another item in the listview doesn't cause the software to show a new hint. (Hope that makes sense).
Is there some proper way of getting this behaviour to work, or am I going to end up doing something icky with mouseovers and then manually drawing a hintbox (etc)?
check the following link:
Display Custom Hints for TListView Sub Items
Edit:
I just checked it now on delphi7 it's showing the hint for every row dynamically after moving the mouse on the listview.
Offtopic: This is simple in Virtual Treeview component, it is build-in feature.
i was using the OnInfoTip event (i didn't need hints for the subitems). the hint was "flashing" (show/hide/show/hide/show/hide/show/hide). found the listview's ShowHint was false. set it to True and it worked as it should.

How to Detect that the Mouse is unmoved and button still pressed?

In Delphi, I've added a Scrollbar component (oriented vertical) to the right side of my form.
I've added a Scrollbar OnChange event so I can change the view of the form and the position of the scrollbar thumb when the user clicks on the UpArrow or DownArrow button with his mouse, and this works fine.
But the OnChange event only seems to get triggered when the mouse button is initially pressed on the arrow.
I notice all scrollbar controls repeat the command and continue scrolling while the mouse remains pressed on the arrow, and I'd like to implement this behavior.
So how can I easily detect if the user has not moved the mouse and continues to press the mouse button while the mouse remains over the arrow?
Conclusion. Somehow something in the scrollbar in my project got corrupted. After I deleted the ScrollBar, and added it again, the problem vanished.
This is one of those tricky ones that took me a lot of time to solve. Thanks for your help. I'm closing this question.
Use the OnScroll event.
The following code adds 'xxx' to a memo as long as the mouse is held down on the scrollbar arrow button. Tested with Delphi 6.
procedure TForm1.ScrollBar1Scroll(Sender: TObject; ScrollCode: TScrollCode;
var ScrollPos: Integer);
begin
Memo1.Lines.Add( 'xxx' );
end;
The usual way to handle auto-repeating is to enable a TTimer and check in the OnTimer() event handler whether the action needs to be performed again, and to deactivate the timer if not. If you need sample code, I seem to remember that the SynEdit control used a similar technique for autoscrolling in drag and drop operations.
If a component does not encapsulate the behaviour you are looking for and you can't easily simulate the behaviour with the methods available you should really subclass the closest component that does most of what you need and add the behaviours that are missing.
I know that some extra work is involved but it really is the better way to go. Now with Delphi, I seem to recall that subclassed components needed a bit of extra work as well to be able to be used from the IDE for form design, maybe this has changed since version 7.

Resources