Recent

Author Topic: [Solved] How to get caretpos for RIGHT clicks  (Read 4646 times)

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 618
    • Double Dummy Solver - free download
[Solved] How to get caretpos for RIGHT clicks
« on: May 10, 2018, 11:41:33 pm »
CaretPos for TMemo and tRichMemo, perhaps all other TCustomEdit descendants, provides the x & y positions on left mouse clicks but not for right mouse clicks. Is there a way to get the x & y caret position for a right click?
« Last Edit: May 11, 2018, 07:11:49 pm by bobonwhidbey »
Lazarus 3.8 FPC 3.2.2 x86_64-win64-win32/win64

jamie

  • Hero Member
  • *****
  • Posts: 6991
Re: How to get caretpos for RIGHT clicks
« Reply #1 on: May 11, 2018, 12:47:06 am »
My OnMouseUp fires for any button on the mouse and the X,Y are reported the same..

maybe you have other code in the way prevented it?
The only true wisdom is knowing you know nothing

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 618
    • Double Dummy Solver - free download
Re: How to get caretpos for RIGHT clicks
« Reply #2 on: May 11, 2018, 02:17:44 am »
In the OnMouseUp event i am getting the X/Y positions for the last left mouse click, not the position for the right mouse click. This is in a RichMemo, but same problem in TMemo.
« Last Edit: May 11, 2018, 02:19:18 am by bobonwhidbey »
Lazarus 3.8 FPC 3.2.2 x86_64-win64-win32/win64

jamie

  • Hero Member
  • *****
  • Posts: 6991
Re: How to get caretpos for RIGHT clicks
« Reply #3 on: May 11, 2018, 04:44:54 am »
something has to be wrong with your setup..

 I just checked here on WIn10 Laz32..

 I can do a mouse up with left click, move the mouse to another location and do right click etc
and it all reports correctly..

 Where ever the mouse is when I release the right or left mouse button, it reports the current location of the cursor.

 Maybe we aren't doing about the same thing here ?

 Cursor and Caret are two different things..

 X,Y = Cursor location, the little blinker for editing is the caret..
The only true wisdom is knowing you know nothing

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 618
    • Double Dummy Solver - free download
Re: How to get caretpos for RIGHT clicks
« Reply #4 on: May 11, 2018, 06:51:48 am »
I think I see my problem, but I don't see the solution. When you left click on a Memo, the caretpos is the same as the cursor position. When you right click on a Memo, the caretpos remains unchanged, so the caret and the cursor are in different positions.

How do I determine which line I've RIGHT clicked on in a Memo?
Lazarus 3.8 FPC 3.2.2 x86_64-win64-win32/win64

balazsszekely

  • Guest
Re: How to get caretpos for RIGHT clicks
« Reply #5 on: May 11, 2018, 08:17:37 am »
Quote
How do I determine which line I've RIGHT clicked on in a Memo?
See attached project(windows only).

Thaddy

  • Hero Member
  • *****
  • Posts: 17414
  • Ceterum censeo Trumpum esse delendum (Tnx Charlie)
Re: How to get caretpos for RIGHT clicks
« Reply #6 on: May 11, 2018, 09:04:09 am »
@Getmem: that's platform dependent. It works on windows only afaik.
@bobonwhidbey:
You just lost functionality that a user might expect. A right-click usually is for something like popup-menu's or other information and should leave the caret alone.
It should not touch the caret position for a Tmemo, because it is an edittable control and needs to satisfy conventions. A left-click should. (or a single-button mouse double-click!)

Do you have a good reason for the loss of such possible functionality? Usually this kind of functionality is solved by a double left-click and then a right-click. e.g. select a word, spell-check.
If you have, I think I have a solution that is cross-platform.
« Last Edit: May 11, 2018, 09:13:25 am by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

balazsszekely

  • Guest
Re: How to get caretpos for RIGHT clicks
« Reply #7 on: May 11, 2018, 09:20:44 am »
@Thaddy
Quote
@Getmem: that's platform dependent. It works on windows only afaik.
You should read my previous post more carefully.

Thaddy

  • Hero Member
  • *****
  • Posts: 17414
  • Ceterum censeo Trumpum esse delendum (Tnx Charlie)
Re: How to get caretpos for RIGHT clicks
« Reply #8 on: May 11, 2018, 09:27:32 am »
I am bit bit cross-platform oriented... 8-) I didn't miss it.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

balazsszekely

  • Guest
Re: How to get caretpos for RIGHT clicks
« Reply #9 on: May 11, 2018, 09:34:45 am »
Quote
I am bit bit cross-platform oriented... 8-) I didn't miss it.
It's doable on other platforms too, but you need a lot more work. I'm kinda lazy now + I saw "Win10 64-bit / Lazarus 1.8.0RC4 / FPC 3.0.4 - 32bit" in OP's signature.

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 618
    • Double Dummy Solver - free download
Re: How to get caretpos for RIGHT clicks
« Reply #10 on: May 11, 2018, 06:17:41 pm »
GetMem's example worked perfectly - and was exactly what I was looking for when using a TMemo. However, when I try to apply that approach on a TRichMemo, I get the dreaded External SIGSEGV" error.

Code: Pascal  [Select][+][-]
  1.     CharPos := SendMessage(RichMemo1.Handle, EM_CHARFROMPOS, 0, MakeLParam(X, Y));

I had no problem independently defining the Handle or the MakeLParm; i.e.
var 
  H: HWND; 
  P : LPARAM

H := RichMemo1.Handle;
P := MakeLParam(X, Y)

Any idea why the SendMessage crashes?
Lazarus 3.8 FPC 3.2.2 x86_64-win64-win32/win64

balazsszekely

  • Guest
Re: How to get caretpos for RIGHT clicks
« Reply #11 on: May 11, 2018, 06:37:25 pm »
Please try attached project.

bobonwhidbey

  • Hero Member
  • *****
  • Posts: 618
    • Double Dummy Solver - free download
Re: [Solved] How to get caretpos for RIGHT clicks
« Reply #12 on: May 11, 2018, 07:14:03 pm »
Thank you GetMem.
Lazarus 3.8 FPC 3.2.2 x86_64-win64-win32/win64

 

TinyPortal © 2005-2018