Recent

Author Topic: Draggin selected text out f a TMemo  (Read 5914 times)

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Draggin selected text out f a TMemo
« Reply #15 on: April 12, 2019, 06:37:23 pm »
So it's a Win 7 problem, it would seem?

I need to drag the selected text.
So it needs to be done, in the MuseDown Event - that is the beginning af a drag operation.

Figure, I can copy text and positions on mouseup, and if the next mousedown is inside the selected text, I can start a drag operation.
Thats my working theory at the moment, anyway...  8)
Trying to create a component, that will do that...
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: Draggin selected text out f a TMemo
« Reply #16 on: April 12, 2019, 07:34:01 pm »
[...] So it needs to be done, in the MouseDown Event - that is the beginning af a drag operation.

Figure, I can copy text and positions on mouseup, and if the next mousedown is inside the selected text, I can start a drag operation.

You may as well react to the OnClick Event to copy the text and positions and use OnMouseDown/Up to set a flag telling which kind of "click" event it is. Also, in the OnMouseDown handler you could then check if you're starting a drag operation vs. a normal click (p.e. when starting a new selection).

But if you're going to create a new component I would rather derive it from TCustomMemo or even TCustomEdit. That would allow you to override some of the needed private methods.

It'll be quite some work any way you do it. :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Draggin selected text out f a TMemo
« Reply #17 on: April 13, 2019, 11:01:39 am »
Quote
You may as well react to the OnClick Event to copy the text and positions and use OnMouseDown/Up to set a flag telling which kind of "click" event it is.
To that end, mouseup and click are the same.
Actually not sure the click will be called, if there is a mouse move between mousedown and mouse up...

Quote
It'll be quite some work any way you do it. :)

For sure.
Got the TMemo functioning, right up to the drag start.
But I can see I will need a TDragObject, that can play with Windoze versions, as I will need to drop on windows component.
Not sure that I will be able to do this.
Seems dragging and dropping in Lazarus' version, only supports dragging controls, not simple text.
Not giving up yet tho.

On a somewhat different note - it seems the problem with the selection values not existing, is only when debuggng.
I.e I have a line
FSelText := Seltext;
When debugging it says SelText does not exist.
But singlestepping past it, FSelText has the correct value.

Attached the component as far as it is  8)
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

jamie

  • Hero Member
  • *****
  • Posts: 7702
Re: Draggin selected text out f a TMemo
« Reply #18 on: April 13, 2019, 03:17:40 pm »
The problem is very simple, I have done this myself...

During the MOUSEUP, test for the LEFT mouse and then create a Tstringlist of the selected text if any.

During the next MOUSEDOWN, you can always test this strlingList for content, if there is content then you can
manual start the drag and while you are at it, create a custom Cursor via a tbitmap with the text painted on it as your dragger image.

 When the drag is complete, procress the data in the Stringlist and then clear that list..
The only true wisdom is knowing you know nothing

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Draggin selected text out f a TMemo
« Reply #19 on: April 13, 2019, 03:27:08 pm »
Quote
The problem is very simple, I have done this myself...
During the MOUSEUP, test for the LEFT mouse and then create a Tstringlist of the selected text if any.

Does Win accept the drop?

I need the start and length as well - checking if the next mousedown is within the selected text.
Difference between starting a new selection or dragging the current selection.

Havent studied Lazarus' way all the much.
But windows needs a texxt to insert, not a component.
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: Draggin selected text out f a TMemo
« Reply #20 on: April 13, 2019, 04:01:18 pm »
@jamie: There are lots of not very complex workarounds if all you want is to drag and drop inside your own application.

Where the thing becomes somewhat complex is when you want to do it across any two applications, say a memo in your program and Notepad.AFAIK there are only two common ways of doing that:
  • Using the system API, as a vulgar C program would do :)
  • Using the clipboard as intermediary, which poses its own difficulties
It can be done, of course, but as I said: it's not as simple as it seems at first glance.

I would really love to be proved wrong ;)

Difference between starting a new selection or dragging the current selection.

You also need to differentiate between dragging the selection or a simple click inside it: for example, the user may have selected more than she wanted and wants to start a more constrained selection inside the one already there. Lots of possibilities there...
« Last Edit: April 13, 2019, 04:06:53 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Draggin selected text out f a TMemo
« Reply #21 on: April 29, 2019, 02:22:23 pm »
An update.

I Found a package, that seems to have what I need and someting more.
Written for Delphi, but carried to Free Pascal:
https://forum.lazarus.freepascal.org/index.php?topic=38761
Download @ https://packages.lazarus-ide.org/DragDrop.zip
But read forum - there are corrections, I don't think is included in the zip.

Otherwise, I have attached the TMyMemo, that will allow dragging of text out of it, and dropping on other win applications.
Still a problem with highlighting of the text in the memo, when dragging starts is wrong. Can't make it go away, and can't make the copied/moved text eihter.
Still working on it - and I will be working on having the TMemo accept dragged text from other win applications as well.
« Last Edit: April 29, 2019, 02:31:47 pm by Birger52 »
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Draggin selected text out f a TMemo
« Reply #22 on: May 01, 2019, 01:51:15 pm »
Slightly altered version, that handles hilight when dragging, and also deselecting when dragging is not initiated.

Wanted to impement a DropTextSource into the TMemo as well - compiles fine, but this gives runtime error:
EInvalidOperation - Control '' has no parent window.
All component I use have a name, and all of them has a parent window.
Also tried to insert the DropTextSource on the form, and give TextMemo as the target of the drop - this gives another run-time error:
EInvalidOperation - Control of class TMyMemo can't have a class TWinControlProxy as a child.

I have the DropTextSource in the form, and the TPanel that is parent of TMyMemo as the Target - then drag and drop functions - also to and from other Windoze apps. (Win7 64bit)
One thing that does not, is selection between Copy and Move.
Copy is what I need and use, and it is functioning.
Move does not (- havent tried from Win to my app), but it doesn't function internally in lazarus app either.
Could be usefull for composing texts...
« Last Edit: May 01, 2019, 01:57:41 pm by Birger52 »
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

 

TinyPortal © 2005-2018