Implement "Lazy Double Click" for automatic edit... lazarus / 31-LCL ---------------------------------------------------------------------- Mike.Cornflake · 2014-09-25 11:29 I'm not actually sure of the correct term to use here, which limits my ability to search for existing answers :-( I want to replicate the functionality you get in a TreeView or ListView whereby the user can lazy double click on the caption and get an editor.  By lazy double click I mean there's a decent interval between the two mouse clicks that's long enough to differentiate between a double click requiring an action and a double click requiring a rename. I can implement this by capturing Now() in an onclick, and comparing this time in a subsequent onclick, but it strikes me this is a common enough experience that maybe there's a more correct way of handling this?  A message to receive? Anyone any ideas?  (and if I have to implement this by capturing now, anyone any idea what a constitutes a decent interval?) (And more specifically, I want to lazy double click on a TLabel, and when this happens I'll stick a TEdit there, and hide the TEdit either on loss of focus, or when the user hits ) ---------------------------------------------------------------------- engkin · 2014-09-25 17:44 I thought the editor in TreeView/ListView shows up if you click on a selected item. So practically it is not double clicking. Quote from: Mike.Cornflake on September 25, 2014, 01:29:21 pmA message to receive? Nope. ---------------------------------------------------------------------- Mike.Cornflake · 2014-09-25 18:17 Quote from: engkin on September 25, 2014, 07:44:24 pmI thought the editor in TreeView/ListView shows up if you click on a selected item. So practically it is not double clicking. Has something changed?  Yeah - Windows explorer exhibits the behaviour you described, but I swear it wasn't always so... Quote from: engkin on September 25, 2014, 07:44:24 pmQuote from: Mike.Cornflake on September 25, 2014, 01:29:21 pmA message to receive? Nope. Thanks for the confirmation RE: lack of message... ---------------------------------------------------------------------- engkin · 2014-09-25 18:49 Quote from: Mike.Cornflake on September 25, 2014, 08:17:50 pmHas something changed? No, just wanted to make sure that it has nothing to do with double clicking, lazy or not. Plus the interval needed for a double click is controled by the OS, at least on Windows. Quote from: Mike.Cornflake on September 25, 2014, 08:17:50 pmbut I swear it wasn't always so... Huh? Older versions of Windows, maybe? ---------------------------------------------------------------------- Mike.Cornflake · 2014-09-25 21:49 Quote from: engkin on September 25, 2014, 08:49:19 pmQuote from: Mike.Cornflake on September 25, 2014, 08:17:50 pmbut I swear it wasn't always so... Huh? Older versions of Windows, maybe? I'm beginning to think urban myth....  Looks like your interpretation of the intended behaviour is correct, but I'm not the only one to misunderstand... http://discuss.fogcreek.com/joelonsoftware2/default.asp?cmd=show&ixPos t=60940&ixReplies=16 http://blogs.msdn.com/b/oldnewthing/archive/2008/11/10/9056610.aspx I've been using Windows in one form or another since 1987.  Sigh...   Thanks for teaching me stuff :-) ---------------------------------------------------------------------- derek.john.evans · 2014-09-28 14:32 This is how I implemented this. It doesn't seem to be an interval issue. If you click on a selected item's caption, then it is interpreted as editing. The problem is, the default OnMouse... events are triggered after the TListView selects the item, so, its difficult to know if a item was selected before a mouse event or if it was selected because of the mouse event. Anyway, I got around this by using the onmousemove to adjust the TListView cursor, which makes for a "nicer" interface. If you move the mouse over a selected items caption, then you get an IBeam. Which is then used by the OnMouseClick event to determine its correct action. Seems to work. The project is attached. Cheers Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit unitmain; interface uses Classes, ComCtrls, Controls, Dialogs, Forms, LCLType, SysUtils; type   TFormMain = class(TForm)    ImageList: TImageList;    ListView: TListView;    StatusBar: TStatusBar;    procedure FormCreate(ASender: TObject);    procedure ListViewClick(ASender: TObject);    procedure ListViewDblClick(ASender: TObject);    procedure ListViewKeyDown(ASender: TObject; var AKey: Word; AShift: TShiftState);    procedure ListViewMouseMove(ASender: TObject; AShift: TShiftState; X, Y: Integer);  end; var FormMain: TFormMain; implementation {$R *.lfm} function ListViewEditCaption(const AListView: TListView): Boolean;begin  Result := Assigned(AListView.Selected);  if Result then  begin    AListView.ReadOnly := False;    Result := AListView.Selected.EditCaption;  end;end; procedure ListViewExplorerMouseMove(const AListView: TListView; const APoint: TPoint);var  LListItem: TListItem;begin  LListItem := AListView.GetItemAt(APoint.X, APoint.Y);  if Assigned(LListItem) then  begin    if LListItem.Selected and (htOnLabel in AListView.GetHitTestInfoAt(APoint.X, APoint.Y)) then    begin      AListView.Cursor := crIBeam;    end else begin      AListView.Cursor := crHandPoint;    end;  end else begin    AListView.Cursor := crDefault;  end;end; procedure ListViewExplorerClick(const AListView: TListView; const APoint: TPoint);begin  if Assigned(AListView.Selected) then  begin    if AListView.Cursor = crIBeam then    begin      ListViewEditCaption(AListView);    end else begin      AListView.ReadOnly := True;    end;  end;  ListViewExplorerMouseMove(AListView, APoint);end; procedure TFormMain.FormCreate(ASender: TObject);var  LIdx: Integer;begin  for LIdx := 1 to 10 do  begin    with ListView.Items.Add do    begin      Caption := 'Test #' + IntToStr(LIdx);      ImageIndex := 0;    end;  end;end; procedure TFormMain.ListViewClick(ASender: TObject);begin  ListViewExplorerClick(ASender as TListView, (ASender as TListView).ScreenToClient(Mouse.CursorPos));end; procedure TFormMain.ListViewMouseMove(ASender: TObject; AShift: TShiftState; X, Y: Integer);begin  ListViewExplorerMouseMove(ASender as TListView, Point(X, Y));end; procedure TFormMain.ListViewDblClick(ASender: TObject);begin  if Assigned(ListView.Selected) then  begin    ShowMessage(ListView.Selected.Caption);  end;end; procedure TFormMain.ListViewKeyDown(ASender: TObject; var AKey: Word; AShift: TShiftState);begin  if (AKey = VK_F2) and ListViewEditCaption(ASender as TListView) then  begin    AKey := VK_UNKNOWN;  end;end; end. ---------------------------------------------------------------------- Mike.Cornflake · 2014-09-28 14:36 Quote from: derek.john.evans on September 28, 2014, 04:32:43 pmThis is how I implemented this. Many thanks.  I like your idea with the cursor as well.   I'll be referencing this :-)