You're not pumping events while inside the while-loop.
Edit: to clarify a bit. Set a boolean variable when you get a mousedown event, then unset it when you get the mouseup event - and do the dragging while the variable is set, instead of doing loops like the one you posted.