Recent

Author Topic: How to disable TMemo's drag-and-drop functionality  (Read 5409 times)

tomitomy

  • Sr. Member
  • ****
  • Posts: 251
How to disable TMemo's drag-and-drop functionality
« on: October 31, 2017, 01:19:25 pm »
Hi, how can I disable GTK2 TMemo's text drag and drop? I do not want the text in TMemo to be dragged because it has a bug in GTK2. Can someone help me?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to disable TMemo's drag-and-drop functionality
« Reply #1 on: October 31, 2017, 02:23:30 pm »
It is a bit of a hack, but given a memo named Memo1 on a form named Form1 you could do something like this:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   if Pos('Gtk2', Memo1.WidgetSetClass.ClassName) > 0 then
  4.     Memo1.DragMode:=dmManual
  5.   else Memo1.DragMode:=dmAutomatic;  
  6. end;

tomitomy

  • Sr. Member
  • ****
  • Posts: 251
Re: How to disable TMemo's drag-and-drop functionality
« Reply #2 on: October 31, 2017, 02:48:47 pm »
It is a bit of a hack, but given a memo named Memo1 on a form named Form1 you could do something like this:

Thank you howardpc, but the text can still be dragged.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How to disable TMemo's drag-and-drop functionality
« Reply #3 on: October 31, 2017, 02:58:48 pm »
Does adding this further line work for you?
Code: Pascal  [Select][+][-]
  1.   if Pos('Gtk2', WidgetSetClass.ClassName) > 0 then begin
  2.     SetDragMode(dmManual);
  3.     DragManager.DragImmediate:=False;
  4.   end;

tomitomy

  • Sr. Member
  • ****
  • Posts: 251
Re: How to disable TMemo's drag-and-drop functionality
« Reply #4 on: October 31, 2017, 03:33:22 pm »
Does adding this further line work for you?
Code: Pascal  [Select][+][-]
  1.   if Pos('Gtk2', WidgetSetClass.ClassName) > 0 then begin
  2.     SetDragMode(dmManual);
  3.     DragManager.DragImmediate:=False;
  4.   end;

Thank you howardpc, but the text is still draggable.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: How to disable TMemo's drag-and-drop functionality
« Reply #5 on: October 31, 2017, 05:49:09 pm »
DragMode is for dragging controls, it has nothing to do with "dragging" text inside TMemo.

tomitomy

  • Sr. Member
  • ****
  • Posts: 251
Re: How to disable TMemo's drag-and-drop functionality
« Reply #6 on: November 01, 2017, 12:36:08 pm »
DragMode is for dragging controls, it has nothing to do with "dragging" text inside TMemo.

Is there any way to implement, such as calling GTK2 API.

PatBayford

  • Full Member
  • ***
  • Posts: 125
Re: How to disable TMemo's drag-and-drop functionality
« Reply #7 on: November 02, 2017, 10:18:10 pm »
Would it not be more correct to write an On Drop handler, that does not allow the dropping of text, or, possibly, an OnDrag handler to prevent dragging?
Lazarus 1.8.0 FPC 3.0.2 SVN 56594 Windows 10 64bit (i386-win32-win32/win64)

tomitomy

  • Sr. Member
  • ****
  • Posts: 251
Re: How to disable TMemo's drag-and-drop functionality
« Reply #8 on: November 03, 2017, 02:43:11 am »
Would it not be more correct to write an On Drop handler, that does not allow the dropping of text, or, possibly, an OnDrag handler to prevent dragging?

Thank you PatBayford, I just tried the following code, the result is still the same.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Memo1StartDrag(Sender: TObject; var DragObject: TDragObject);
  2. begin
  3.   Memo1.EndDrag(False);
  4. end;
  5.  
  6. procedure TForm1.Memo1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
  7. begin
  8.   Accept := False;
  9. end;

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: How to disable TMemo's drag-and-drop functionality
« Reply #9 on: November 03, 2017, 06:42:45 am »
I take it you mean dragging out of TMemo rather than dragging in? On KDE (Qt) by default I can drag the Memo text out to an editor but I cannot drag text into the Memo.
keep it simple

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: How to disable TMemo's drag-and-drop functionality
« Reply #10 on: November 03, 2017, 07:04:41 am »
A somewhat nasty workaround is to capture the mouse when the button is down. This way the text cannot be dragged. The downside is that you also cannot select text with the mouse. But you can position the cursor and select the text from there using the keyboard.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Memo1MouseUp(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. begin
  4.   MouseCapture := false;
  5. end;
  6.  
  7. procedure TForm1.Memo1MouseDown(Sender: TObject; Button: TMouseButton;
  8.   Shift: TShiftState; X, Y: Integer);
  9. begin
  10.   MouseCapture := true;
  11. end;
keep it simple

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: How to disable TMemo's drag-and-drop functionality
« Reply #11 on: November 03, 2017, 07:09:33 am »
I take it you mean dragging out of TMemo rather than dragging in?

Tomitomy is trying to prevent this.

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: How to disable TMemo's drag-and-drop functionality
« Reply #12 on: November 03, 2017, 07:21:39 am »
I take it you mean dragging out of TMemo rather than dragging in?

Tomitomy is trying to prevent this.

I cannot reproduce this mouse action within TMemo on KDE, so it seems a LCL-GTK issue. When I try to drag selected text the cursor shows a small red circle until I leave the memo.

My above workaround prevents the mouse from selecting and dragging text.
keep it simple

tomitomy

  • Sr. Member
  • ****
  • Posts: 251
Re: How to disable TMemo's drag-and-drop functionality
« Reply #13 on: November 03, 2017, 10:34:32 am »
I cannot reproduce this mouse action within TMemo on KDE, so it seems a LCL-GTK issue. When I try to drag selected text the cursor shows a small red circle until I leave the memo.

My above workaround prevents the mouse from selecting and dragging text.

Thank you Munair, I tried your code, the result is still the same, GTK2's TMemo doesn't seem to be affected by these code.

 

TinyPortal © 2005-2018