I was just wondering if someone know what timing I should use to activate
edit input, in a listview component I am making. I use GetTickCount to
compare mousedown event with mouseup event. If diffrense is greater then 200
then activate edit control... but I am not sure what time window uses as
standard. Any hint?
Kind Regards
Roy Magne Klever
I don't know the exact timing from the top of my head. It also depends
on if the item being clicked is the same as before or is it a new item.
IIRC when the same item is clicked twice after about 1 sec it should go
in editing mode, if within a second, the double click handler will
probably have already fired.
--
Pieter
> I don't know the exact timing from the top of my head. It also depends
> on if the item being clicked is the same as before or is it a new item.
My code is like this:
in MouseDownEvent:
FDownX:= x;
FDownY:= y;
FDownTick:= GetTickCount;
in MouseUpEvent:
if (GetTickCount - FDownTick > 225) and (FDownX = x) and (FDownY = y) then
EditCaption
> IIRC when the same item is clicked twice after about 1 sec it should go
> in editing mode, if within a second, the double click handler will
> probably have already fired.
hm... that complicates my check i guess but maybe my check is good enough,
it feels the same as clicking in other views...
Thanks for your input.
Kind Regards
Roy M Klever
> > I don't know the exact timing from the top of my head. It also
> > depends on if the item being clicked is the same as before or is it
> > a new item.
>
> [snip]
> in MouseUpEvent:
>
> if (GetTickCount - FDownTick > 225) and (FDownX = x) and (FDownY = y)
> then EditCaption
>
> > IIRC when the same item is clicked twice after about 1 sec it
> > should go in editing mode, if within a second, the double click
> > handler will probably have already fired.
>
> hm... that complicates my check i guess but maybe my check is good
> enough, it feels the same as clicking in other views...
>
Here are some Windows APIs which might be of interest:
- GetSystemMetrics
- SystemParametersInfo
procedure TForm1.FormCreate(Sender: TObject);
function MemoWriteInt(const Value: Integer): Integer;
begin
Result := Memo1.Lines.Add(IntToStr(Value));
end;
begin
MemoWriteInt( GetDoubleClickTime );
MemoWriteInt( GetSystemMetrics(SM_CXDRAG) );
MemoWriteInt( GetSystemMetrics(SM_CYDRAG) );
MemoWriteInt( GetSystemMetrics(SM_CXDOUBLECLK) );
MemoWriteInt( GetSystemMetrics(SM_CYDOUBLECLK) );
end;
On my system it outputs:
500
4
4
4
4
So this means that two mouse clicks within 500 msec are/should be
treated as double click. Anything beyond that time could be used to
start an editing action.
In your mouse position comparison you check for exact position. This is
not always that easy (think touch-pads found on lap-tops). I think you
need to keep some tolerance where the user is allowed to "move" the
mouse while holding down the mouse button.
Something like:
(Abs(FDownX - x) < GetSystemMetrics(SM_CXDRAG)) and
(Abs(FDownY - y) < GetSystemMetrics(SM_CYDRAG))
You can also use Mouse.DragOffset (default value 5) from Controls.pas.
--
Pieter
> FDownTick:= GetTickCount;
<snip>
> if (GetTickCount - FDownTick > 225) and (FDownX = x) and (FDownY = y)
> then EditCaption
GetTickCount() wraps back to 0 every 49.7 days that Windows has been running
continuously. You need to calculate the duration in order to account for
that, ie:
FDownTick := GetTickCount;
...
dwTicks := GetTickCount;
if dwTicks >= FDownTick then
dwElapsed := dwTicks - FDownTick
else
dwElapsed := $FFFFFFFF - FDownTick + dwTicks;
if (dwElapsed > 225) and (FDownX = x) and (FDownY = y) then
EditCaption
Otherwise, use high-performance counters instead, which do not wrap. Look
at QueryPerformanceCounter() and QueryPerformanceFrequency() for that.
Gambit
Thanks for your input, absolutt something to consider.
Thanks!
Kind Regard
Roy M Klever