Need help with a listener that moves a shell

doob doobnet at gmail.com
Sun Mar 11 06:57:17 PDT 2007


What I try to do is a listener that moves a shell by holding down the middle mouse button. I want this because I use the style DWT.NONE on the shell. I manged to do this in java and swt but the same code doesn't work as expected in d with dwt. The code:

private class MouseListenerMiddle : Listener
{
        private int startX = 0;
        private int startY = 0;
                
        public void handleEvent (Event e)
        {
                if (e.type == DWT.MouseDown && e.button == 2)
                {
                        startX = e.x;
                        startY = e.y;
                }
                
                if (e.type == DWT.MouseMove && (e.stateMask & DWT.BUTTON2) != 0)
                {
                        Point p = shell.toDisplay(e.x, e.y);
                        p.x -= startX;
                        p.y -= startY;
                        shell.setLocation(p);
                }
        }
}

I can describe the problem with an example:
If you have the mouse pointer 100 pixels to the right of the top left corner of a window and moves the window you expect that the mouse pointer always is 100 pixels to the right of the top left corner but now it isn't. The top left corner of the window moves to the mouse pointer all the time.


More information about the Digitalmars-d-dwt mailing list