GoToolPanning : several questions

Hello,

I have 2 mode on my diagram :
- selector : showing arrow cursor and using GoToolRubberBand subclass
- panning : showing hand cursor and using GoToolPanning subclass
I'm registering these 2 tools to the view (clearing all others for the moment) in MouseMoveTools. The CanStart property is overriden and returning true according to the mode. Until here, it works fine.
1) When clicking with the middle button, the special cursor 'Pan' appears, and I want to avoid that. Any way to block that ?
2) In the 2 modes I want to authorize the other behavior using modifier key. I've tried it in using LastInput in the CanStart method. It seems that the modifiers keys (tried Shift and Alt) have special behavior for GoToolPanning ?
Below my code alternatively allowing CanStart from Panning or RubberBand.
Thanks for any hint
Bye
Didier
**********************************************************
Panning :
public override bool CanStart() {
return ((m_GridCtrl != null)
&& (((this.LastInput.Alt == false) && (m_GridCtrl.PointerMode == EPointerMode.Move))
|| ((this.LastInput.Alt == true) && (m_GridCtrl.PointerMode == EPointerMode.Selector))));
}
RubberBand :
public override bool CanStart() {
return ( (m_GridCtrl != null)
&&( ((this.LastInput.Alt==false)&&(m_GridCtrl.PointerMode == EPointerMode.Selector))
||((this.LastInput.Alt==true)&&(m_GridCtrl.PointerMode==EPointerMode.Move))));
}

  1. You may want to remove some of the other standard tools for the view, in particular in the GoView.MouseDownTools list, and maybe in the GoView.MouseUpTools list.
2) Yes, you're doing the right thing by overriding GoTool.CanStart. The standard implementation of GoToolPanning.CanStart does check GoInputEventArgs.Alt, .Control, .Shift, and .Buttons, but by overriding this predicate to do what you want, you should have complete control over when the tool can be started. I assume you have set GoToolPanning.AutoPan to false.

Hi,

I removed all tools in MouseDownTools, MousMoveTools, MouseUpTools and added my 2 customs.
1) Now I haven't any more the built pan on the middle button, thanks.
2) Still a problem when using the shift key for alternate mode. So far as I can see the CanStart is correctly called (Panning), and the panning start but is stopped by something in background when shift key is pressed. I can move a little bit when I go fast between the click down and move, but as said, after a short while, the panning is stopped.
Any idea of waht can casue this behavior ? (AutoPan is false)
Thanks
Didier

OK, I just tried:

[Serializable]
public class CustomPanning : GoToolPanning {
public CustomPanning(GoView v) : base(v) {
this.AutoPan = false;
}
public override bool CanStart() {
return !this.LastInput.Alt;
}
}
[Serializable]
public class CustomRubberBanding : GoToolRubberBanding {
public CustomRubberBanding(GoView v) : base(v) {}
public override bool CanStart() {
return this.LastInput.Alt;
}
}
Everything worked the way I expected, and as I think you are asking for. Other than exchanging which tool to use depending on what the default behavior should be (without the Alt modifier).

Hello,

Could you try the opposite :
- LastInput.Alt for Panning
- !LastInput.Alt for RubberBanding
With your sample it works, with the opoosite, when panning with alt pressed, it moves a little bit and exit from paning mode ... strange ...
Thanks
Bye
Didier

The problem is that there is a key event that is delivered after the mouse down event. The key data is RButton | ShiftKey | Alt. I do not know why this key event occurs – perhaps it is some convention relating to the Alt key. Certainly I’m not holding down the right mouse button.

Normally in Windows applications holding down the Alt key indicates that the next key down event is a system key event, and that is usually treated differently. For some reason this key event is generated/delivered after the mouse event. Maybe it's some convention that I hadn't heard of before.
Finally the reason for the behavior you see is that GoToolPanning overrides DoKeyDown to call StopTool(). Basically, when the user hits any key during a panning operation, the panning operation is supposed to stop. So the easy work-around is to override DoKeyDown to be a no-op.
So here are the updated tool definitions, with the CanStart conditions exchanged:
[Serializable]
public class CustomPanning : GoToolPanning {
public CustomPanning(GoView v) : base(v) {
this.AutoPan = false;
}
public override bool CanStart() {
return this.LastInput.Alt;
}
public override void DoKeyDown() {
// don't call StopTool()
}
}
[Serializable]
public class CustomRubberBanding : GoToolRubberBanding {
public CustomRubberBanding(GoView v) : base(v) { }
public override bool CanStart() {
return !this.LastInput.Alt;
}
}

Hello,

Ok, thanks a lot.
I've overrided DoKeyDown in GoToolPanning, and now it doesn't stop anymore my panning operation
In the GoView, I change the DefaultCursor when pressing Alt to reflect the operation that would be performed.
When making Panning without Alt key, the cursor is set to a hand and when panning, switching to the vertical/horizontal arrow (internal behavior from GoToolPanning). With the Alt Key, as in the sample, the cursor is not switching to the vertical/horizontal arrow (or very shortly). So I think something is managing the cursor internally in the GoToolPanning.
Gives it a way to override that ?
Thanks for your great help
Didier
PS : gives it a way forme to discover these things without the sources ? I think not, but ...

I guess the documentation for GoToolPanning doesn’t say what happens with cursors.

When AutoPan is false, Start() sets GoView.CursorName = "move".
When AutoPan is false, Stop() sets GoView.CursorName = "default".
You can override these methods to call the base method, and then set the GoView.CursorName to whatever you want, or set the GoView.Cursor directly.

Thanks you very much for your help.

That was my mistake : in the OnKeyDown, I was setting the cursor not checking if tool started, so reseting cursor while KeyDown is repeatitly received.
Override the methods as you said setting the cursors do the trick
By the way, I've added a variable in my CustomPanningTool isRunning (true at start, false at stop). It doesn't give built-in property to know if a tool is running ? (or started)
Many, many thanks
Bye
Didier

You can check the value of GoView.Tool to see what tool is currently running for that particular view.

In other words, only when the tool is running will those Do...() methods be called.