Tuesday, November 1, 2011

Re: I can't get RichTextAre OnPaste Event hooking|sinking to work?

I found a nice hack to get the onpaste to work: I modified the source to try it.

  // my inherited RichTextArea
 
public WiseRichTextArea(boolean hideBorderUntilHover, boolean grow) {
   
super();
    setup
(hideBorderUntilHover, grow);
 
}

 
private void setup(boolean hideBorderUntilHover, boolean grow) {
   
this.hideBorderUntilHover = hideBorderUntilHover;
   
this.grow = grow;

    addStyleName
("gv-core-WiseRichTextArea");

    setUpEditHover
();  

    setupHandlers
();

    sinkEvents
(Event.ONPASTE);
 
}

 
@Override
 
public void onBrowserEvent(Event event) {
   
super.onBrowserEvent(event);
   
switch (event.getTypeInt()) {
   
case Event.ONPASTE:
     
System.out.println("Paste Detected");
     
Window.alert("Paste Works!!! Yippie!!!");
     
break;
   
}
 
}
My hack:
// RichTextAreaImplSafari.java source hack
 
@Override
 
protected native void hookEvents() /*-{
    var elem = this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem;
    var wnd = elem.contentWindow;

    elem.__gwt_handler = function(evt) {
      if (elem.__listener) {
        if (@com.google.gwt.user.client.impl.DOMImpl::isMyListener(Ljava/lang/Object;)(elem.__listener)) {
          @com.google.gwt.user.client.DOM::dispatchEvent(Lcom/google/gwt/user/client/Event;Lcom/google/gwt/user/client/Element;Lcom/google/gwt/user/client/EventListener;)(evt, elem, elem.__listener);
        }
      }
    };    

    wnd.addEventListener('keydown', elem.__gwt_handler, true);
    wnd.addEventListener('keyup', elem.__gwt_handler, true);
    wnd.addEventListener('keypress', elem.__gwt_handler, true);
    wnd.addEventListener('mousedown', elem.__gwt_handler, true);
    wnd.addEventListener('mouseup', elem.__gwt_handler, true);
    wnd.addEventListener('mousemove', elem.__gwt_handler, true);
    wnd.addEventListener('mouseover', elem.__gwt_handler, true);
    wnd.addEventListener('mouseout', elem.__gwt_handler, true);
    wnd.addEventListener('click', elem.__gwt_handler, true);

    // Whats needed . this works.
    wnd.addEventListener('paste', elem.__gwt_handler, true);

    // Focus/blur event handlers. For some reason, [add|remove]eventListener()
    // doesn't work on the iframe element (at least not for focus/blur). Don't
    // dispatch through the normal handler method, as some of the querying we do
    // there interferes with focus.
    wnd.onfocus = function(evt) {
      if (elem.__listener) {
        @com.google.gwt.user.client.DOM::dispatchEvent(Lcom/google/gwt/user/client/Event;Lcom/google/gwt/user/client/Element;Lcom/google/gwt/user/client/EventListener;)(evt, elem, elem.__listener);
      }
    };

    wnd.onblur = function(evt) {
      if (elem.__listener) {
        @com.google.gwt.user.client.DOM::dispatchEvent(Lcom/google/gwt/user/client/Event;Lcom/google/gwt/user/client/Element;Lcom/google/gwt/user/client/EventListener;)(evt, elem, elem.__listener);
      }
    };
  }-*/
;
I'll submit all the source tomorrow.

Brandon Donnelson
http://gwt-examples.googlecode.com





--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/DzOwaVQAk5IJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment