Imposing pan/zoom extents to grid size

Q: How can I limit pan and zoom operations to within the grid boundaries?

To explain, I'm using OCCT in a purely 2D mode: looking down onto X,Y and forcing Z=0.

i'm finding Pan and Zoom operations can get very excitable (esp on touchpads): resulting in the grid disappearing off into another dimension, never to be seen again. As a safety net I want to impose a restriction so that pan/zoom can never leave the extents of the grid

Anyone any ideas where to look?

thanks

Mat