Author: [EMAIL PROTECTED]
Date: Tue Oct  7 07:54:14 2008
New Revision: 3724

Modified:
    trunk/user/src/com/google/gwt/user/client/ui/DialogBox.java
    trunk/user/src/com/google/gwt/user/client/ui/PopupPanel.java

Log:
Let users drag DialogBoxes off the screen in any direction, but only as  
long as
the mouse pointer stays in the window -- so you can't totally lose a  
DialogBox.

patch by: ajr
review by: rdayal
suggested by: jgw


Modified: trunk/user/src/com/google/gwt/user/client/ui/DialogBox.java
==============================================================================
--- trunk/user/src/com/google/gwt/user/client/ui/DialogBox.java (original)
+++ trunk/user/src/com/google/gwt/user/client/ui/DialogBox.java Tue Oct  7  
07:54:14 2008
@@ -15,9 +15,12 @@
   */
  package com.google.gwt.user.client.ui;

+import com.google.gwt.dom.client.Document;
  import com.google.gwt.user.client.DOM;
  import com.google.gwt.user.client.Element;
  import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.WindowResizeListener;

  /**
   * A form of popup that has a caption area at the top and can be dragged  
by the
@@ -69,6 +72,10 @@
    private boolean dragging;
    private int dragStartX, dragStartY;
    private MouseListenerCollection mouseListeners = new  
MouseListenerCollection();
+  private WindowResizeListener resizeListener;
+  private int windowWidth;
+  private int clientLeft;
+  private int clientTop;

    /**
     * Creates an empty dialog box. It should not be shown until its child  
widget
@@ -114,6 +121,10 @@
      // Set the style name
      setStyleName(DEFAULT_STYLENAME);
      sinkEvents(Event.MOUSEEVENTS);
+
+    windowWidth = Window.getClientWidth();
+    clientLeft = Document.get().getBodyOffsetLeft();
+    clientTop = Document.get().getBodyOffsetTop();
    }

    public String getHTML() {
@@ -125,6 +136,12 @@
    }

    @Override
+  public void hide() {
+    Window.removeWindowResizeListener(resizeListener);
+    super.hide();
+  }
+
+  @Override
    public void onBrowserEvent(Event event) {
      super.onBrowserEvent(event);

@@ -178,6 +195,14 @@
      if (dragging) {
        int absX = x + getAbsoluteLeft();
        int absY = y + getAbsoluteTop();
+
+      // if the mouse is off the screen to the left, right, or top, don't
+      // move the dialog box. This would let users lose dialog boxes, which
+      // would be bad for modal popups.
+      if (absX < clientLeft || absX >= windowWidth || absY < clientTop) {
+        return;
+      }
+
        setPopupPosition(absX - dragStartX, absY - dragStartY);
      }
    }
@@ -209,6 +234,19 @@
     */
    public void setText(String text) {
      caption.setText(text);
+  }
+
+  @Override
+  public void show() {
+    if (resizeListener == null) {
+      resizeListener = new WindowResizeListener() {
+        public void onWindowResized(int width, int height) {
+          windowWidth = width;
+        }
+      };
+    }
+    Window.addWindowResizeListener(resizeListener);
+    super.show();
    }

    @Override

Modified: trunk/user/src/com/google/gwt/user/client/ui/PopupPanel.java
==============================================================================
--- trunk/user/src/com/google/gwt/user/client/ui/PopupPanel.java        
(original)
+++ trunk/user/src/com/google/gwt/user/client/ui/PopupPanel.java        Tue Oct 
 7  
07:54:14 2008
@@ -573,17 +573,6 @@
     * @param top the top position, in pixels
     */
    public void setPopupPosition(int left, int top) {
-    // Keep the popup within the browser's client area, so that they can't  
get
-    // 'lost' and become impossible to interact with. Note that we don't  
attempt
-    // to keep popups pegged to the bottom and right edges, as they will  
then
-    // cause scrollbars to appear, so the user can't lose them.
-    if (left < 0) {
-      left = 0;
-    }
-    if (top < 0) {
-      top = 0;
-    }
-
      // Save the position of the popup
      leftPosition = left;
      topPosition = top;

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to