Recent

Author Topic: [SOLVED]Conflict between popupmenu and TCharToolset and is OnStartDrag working?  (Read 6866 times)

CM630

  • Hero Member
  • *****
  • Posts: 910
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Probably the title is not exact, but here is the case:
1. I use TChartToolset to zoom with the right mouse button.
2. I have added a popup menu for the TAChart.
After I zoom (drag) the popup menu is displayed, while my idea was that the popup menu shall be displayed only if I right click without dragging.
So I decided to try handling the case this way:

Code: [Select]
procedure TForm1.Chart1StartDrag(Sender: TObject; var DragObject: TDragObject);
begin
  popmChart.AutoPopup:=False;
end;
and later to  popmChart.AutoPopup:=True;  when reaching OnMouseUp or something like that.
To my surprise the program never gets inside the StartDrag procedure. I even tried
Code: [Select]
procedure TForm1.Chart1StartDrag(Sender: TObject; var DragObject: TDragObject);
begin
  ShowMessage ('drag');
end;
but the message is never displayed, no matter if I drag with the left or the right mouse button.
I should mention that I tried this also on a fresh project, without TChartToolset.
Is it me who is doing something wrong or there is something wrong in OnStartDrag?
Also, can someone offer me a more proper way to handle the case (no popup menu when dragging)?
« Last Edit: November 28, 2012, 08:52:14 am by paskal »
Лазар 2,0,8; W10 or W7 64bit; FPC3,2,0; rev 62944

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Conflict between popupmenu and TCharToolset and is OnStartDrag working?
« Reply #1 on: November 23, 2012, 12:04:03 pm »
1) Add ZoomDragTool and UserDefinedTool to the toolset, in this order
2) Assign Shift = [ssRight] for both tools
3) Remove zreClick from ZoomDragTool.RestoreExtentOn set
4) Set UserDefinedTool.OnAfterMouseUp to the following code:
Code: [Select]
  with Chart1.ClientToScreen(APoint) do
    PopupMenu1.PopUp(X, Y);
5) TZoomDragTool has a bug which will result in popup menu still showing after extent restoration by reverse drag. It is fixed in r39351

wp

  • Hero Member
  • *****
  • Posts: 7552
Re: Conflict between popupmenu and TCharToolset and is OnStartDrag working?
« Reply #2 on: November 23, 2012, 12:22:50 pm »
An interesting solution because it forces us to think within the ChartTools framework. Maybe we should document it somehow (demo, or maybe better, mini-tutorial?)
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

wp

  • Hero Member
  • *****
  • Posts: 7552
Re: Conflict between popupmenu and TCharToolset and is OnStartDrag working?
« Reply #3 on: November 23, 2012, 11:48:53 pm »
In my project, it is the PanDragTool which conflicts with the PopupMenu. However, the popup still shows up after dragging even with your code. From your code, I think that the popup menu no longer needs to be connected to the chart. But if I delete the chart's PopupMenu property the popupmenu does not show up any more at all.

It looks as if the right click is eaten by the PanDragTool before it reaches the UserdefinedTool. In the ZoomDragTool there is the RestoreExtentOn property which can be used to avoid that. But what to do with the PanDrag tool which does not have this property?
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Conflict between popupmenu and TCharToolset and is OnStartDrag working?
« Reply #4 on: November 24, 2012, 01:18:02 pm »
Quote
An interesting solution because it forces us to think within the ChartTools framework. Maybe we should document it somehow (demo, or maybe better, mini-tutorial?)

I have added a note to the docs.

As for demo/tutorial. Of course, I'd like to have as many of those as possible. It is probably easiest for the user to have a large number of very short demos each focusing on a specific aspect.
However, growing number of demos and tutorials need to be supported. Since our resources are limited, I try to balance between number and complexity of demos, and you do the same for tutorials.
So in this case, rather than a separate demo, maybe a "Popup" page in the "tools" demo would be right solution.
Similarly, if you'll see a possibility to incorporate this information in some existing or future tutorial, that would IMO be preferable to a separate tutorial for only this topic.

Quote
But what to do with the PanDrag tool which does not have this property?
Since r39360, set TPanDragTool.MinDragRadius to non-zero value.

wp

  • Hero Member
  • *****
  • Posts: 7552
Re: Conflict between popupmenu and TCharToolset and is OnStartDrag working?
« Reply #5 on: November 24, 2012, 05:19:37 pm »
Thank you, works fine. I'll probably add a popup to the Mandelbrot tutorial.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

CM630

  • Hero Member
  • *****
  • Posts: 910
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Conflict between popupmenu and TCharToolset and is OnStartDrag working?
« Reply #6 on: November 26, 2012, 10:57:40 am »
1) Add ZoomDragTool and UserDefinedTool to the toolset, in this order
2) Assign Shift = [ssRight] for both tools
3) Remove zreClick from ZoomDragTool.RestoreExtentOn set
4) Set UserDefinedTool.OnAfterMouseUp to the following code:
Code: [Select]
  with Chart1.ClientToScreen(APoint) do
    PopupMenu1.PopUp(X, Y);
5) TZoomDragTool has a bug which will result in popup menu still showing after extent restoration by reverse drag. It is fixed in r39351
Thanks, it works, but with a remark- PopupMenu1.AutoPopup shall be set to FALSE.

Still I have not understood why
Quote
...the program never gets inside the StartDrag procedure...
Лазар 2,0,8; W10 or W7 64bit; FPC3,2,0; rev 62944

wp

  • Hero Member
  • *****
  • Posts: 7552
Re: Conflict between popupmenu and TCharToolset and is OnStartDrag working?
« Reply #7 on: November 26, 2012, 12:38:20 pm »
Quote
...the program never gets inside the StartDrag procedure...
because ChartTools do not use this procedure
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

CM630

  • Hero Member
  • *****
  • Posts: 910
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Conflict between popupmenu and TCharToolset and is OnStartDrag working?
« Reply #8 on: November 26, 2012, 02:19:25 pm »
I should mention that I tried this also on a fresh project, without TChartToolset.
I meant that I created a brand new project, I added a Chart1 in the main form, I clicked on Chart1, then in the object explorer I clicked on Events and I created:
Code: [Select]
procedure TForm1.Chart1StartDrag(Sender: TObject; var DragObject: TDragObject);
begin
  ShowMessage ('drag');
end; 
Since in this case there is no ChartTool in the form, what does ChartTools to do with the whole case? Otherwise I could consider that it somehow overrides the event. And if this event cannot be used, why does it exist? If if it can be used somehow, it could be useful to know how.
Of course, I have to admit, that if there is an answer, I am not sure that I can understand it.
Лазар 2,0,8; W10 or W7 64bit; FPC3,2,0; rev 62944

wp

  • Hero Member
  • *****
  • Posts: 7552
Re: Conflict between popupmenu and TCharToolset and is OnStartDrag working?
« Reply #9 on: November 26, 2012, 02:46:13 pm »
Since TAChart has built-in tools the left mouse button is occupied by the built-in zoom tool. Turn off AllowZoom to free the left mouse button for drag and drop. Note also that you have to use DragMode = dmAutomatic, or you have to react on MouseDown or something to initiate dragging manually (BeginDrag). But that's standard (http://wiki.freepascal.org/LCL_Drag_Drop), nothing special with TAChart.

With these modifications, the simple program that you mention works as expected.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

CM630

  • Hero Member
  • *****
  • Posts: 910
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Conflict between popupmenu and TCharToolset and is OnStartDrag working?
« Reply #10 on: November 27, 2012, 07:41:41 am »
Thanks for the explanation. So the idea is that OnStartDrag is for dragging and dropping the controls. Also, it is not necessary to disable AllowZoom, just DragMode has to be set to Automatic.
Лазар 2,0,8; W10 or W7 64bit; FPC3,2,0; rev 62944

CM630

  • Hero Member
  • *****
  • Posts: 910
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Conflict between popupmenu and TCharToolset and is OnStartDrag working?
« Reply #11 on: November 27, 2012, 02:21:13 pm »
Okay, I have the following problem with the popup menu or the previously offered code:
Code: [Select]
with Chart[ChartIndex].ClientToScreen(APoint) do
    popmChart.PopUp(X, Y); 

I have several Charts. When the popup menu pops up it stays shown until I choose something from it or until I click somewhere else.
So if I right click on a chart and without selecting something from the popup menu (the menu remains shown) I right click on another chart the menu is shown on the first one.
The value of ChartIndex is acquired from the OnMouseMove events for the charts. The problem is that when the popupmenu is open, the OnMouseMove  event does not work. Also, OnMouseDown event does not work for the right mouse button so I have no way to detect on which chart was right-clicked.

ctMainUserDefinedTool1AfterMouseUp(ATool: TChartTool; APoint: TPoint); does not give the name of the waveform on which it was clicked (I use one chart toolset for all the Charts).

I tried to disable the SHIFT:=[ssRight] for the CustomTool, and to put the code into OnMouseDown event of the chart, but OnMouseDown appears to work only on a double click (probably it is overriden by the DragTool).
Any suggestion how to solve this case?
« Last Edit: November 27, 2012, 02:27:29 pm by paskal »
Лазар 2,0,8; W10 or W7 64bit; FPC3,2,0; rev 62944

Ask

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 687
Re: Conflict between popupmenu and TCharToolset and is OnStartDrag working?
« Reply #12 on: November 27, 2012, 02:43:13 pm »
Use TChartTool.Chart property

CM630

  • Hero Member
  • *****
  • Posts: 910
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Perfect!
Лазар 2,0,8; W10 or W7 64bit; FPC3,2,0; rev 62944

 

TinyPortal © 2005-2018