Hello Manuel
Well, I guess this will teach me to recommend some solution without trying it myself first... sorry about that. I had forgotten the behavior of snapped cursors during a zoom.
I tested your code, and although I wasn't able to reproduce the symptom you describe (GetGlobalMouseState always returned 1 for left or right), I can see how it's possible for it to happen. I think it's a matter of timing. By the time your callback is called, it's possible that the user has already released the mouse button, in which case the function will return 0. Did you experiment with long clicks, so that button is definitely still down at the time you call the function?
In any case, it is probably not a good idea to rely on length of clicks in the code, so I'd suggest doing something different, and simpler:
The extended mouse events in the toolbox allow you to receive an event when the user releases the mouse. The function call looks like this:
EnableExtendedMouseEvents (panelHandle, PANEL_GRAPH, 0.1);
After calling the function, you will receive mouse-up events in the graph's callback. Thus, you can rearrange your code so that you don't have to code the mouse loop yourself. Simply enable a timer when the mouse-down happens, and disable it when the mouse up happens. For example:
case EVENT_LEFT_CLICK:
SetCtrlAttribute (panel, PANEL_TIMER, ATTR_ENABLED, 1);
break;
case EVENT_LEFT_MOUSE_UP:
SetCtrlAttribute (panel, PANEL_TIMER, ATTR_ENABLED, 0);
break;
The scaling then takes place in the timer callback:
case EVENT_TIMER_TICK:
GetAxisScalingMode (panel, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_MANUAL, &min, &max);
oldRange = max - min;
newRange = oldrange / 1.1;
offset = (oldRange - newRange) / 2.0;
min += offset;
max -= offset;
SetAxisScalingMode (panel, PANEL_GRAPH, VAL_BOTTOM_XAXIS, VAL_MANUAL, min, max);
break;
Notice that the scaling is a bit more complicated than what you had previously. You can't simply apply a scaling factor to min and max, since these may be negative, or zero. You need to scale the range up or down, not the individual end-points. In the code above, the range is being reduced by 10% in each iteration. This is accomplished by adding half of the difference to the min, and subtracting the other half from the max.
You can control the speed of the zoom by setting the timer interval accordingly. Also, remember to start out with the timer disabled.
If you want to use right-clicks for zooming out, you can still use this solution. You would have to set some flag that will tell the timer callback to zoom out instead.
Luis