// Path: src/main/java/com/tractionsoftware/gwt/user/client/util/MiscUtils.java
// public class MiscUtils {
// 
//     /**
//      * Note: It seems like NativeEvent.getCharCode() would be equivalent.
//      */
//     public static native char getCharCode(NativeEvent e)
//     /*-{
//       return e.charCode || e.keyCode;
//     }-*/;
// 
//     public static final String getComputedStyle(Element e, String camelName) {
// 	// sometimes IE throws an exception. thanks IE!
//         try {
//             return getStyleImpl().getComputedStyle(e, hyphenize(camelName), camelName);
//         }
//         catch (Exception xcp) {
//             return null;
//         }
//     }
// 
//     public static final int getComputedStyleInt(Element e, String camelName) {
//         String num = getComputedStyle(e, camelName);
// 	return num != null ? parseInt(num) : 0;
//     }
// 
//     public static final int parseInt(String val) {
// 	return parseInt(val, 10);
//     }
// 
//     public static final native int parseInt(String val, int radix)
//     /*-{
//       return parseInt(val, radix) || 0;
//     }-*/;
// 
//     // ----------------------------------------------------------------------
//     // DocumentStyleImpl.getComputedStyle from gwtquery
// 
//     private static DocumentStyleImpl styleImpl = null;
//     private static DocumentStyleImpl getStyleImpl() {
//         if (styleImpl == null) {
//             styleImpl = GWT.create(DocumentStyleImpl.class);
//         }
//         return styleImpl;
//     }
// 
//     /**
//      * Hyphenize style property names. for instance: fontName ->
//      * font-name
//      */
//     private static native String hyphenize(String name) /*-{
//         return name.replace(/([A-Z])/g, "-$1").toLowerCase();
//     }-*/;
// 
// }


import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.TextArea;
import com.tractionsoftware.gwt.user.client.util.MiscUtils;
/*
 * Copyright 2010 Traction Software, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.tractionsoftware.gwt.user.client.ui;



/**
 * This attaches to an input, listening for KeyDown/KeyUp, and
 * automatically resizing the text area. It does this using an
 * invisible textarea that matches the text of the input.
 */
public class AutoSizingTextArea extends AutoSizingBase<TextAreaWithSelection, TextArea> implements ResizeHandler {

    protected int divExtra = 0;
    protected HandlerRegistration resizeRegistration = null;

    public AutoSizingTextArea() {
	this(new TextAreaWithSelection());
    }
    private AutoSizingTextArea(TextAreaWithSelection box) {
	super(box, new TextArea());
    }
    public AutoSizingTextArea(TextAreaWithSelection box, int minSize, int maxSize) {
	super(box, new TextArea());
	setMinSize(minSize);
	setMaxSize(maxSize);
    }

    @Override
    protected void onLoad() {
	Element boxElement = box.getElement();

// Path: src/main/java/com/tractionsoftware/gwt/user/client/util/MiscUtils.java
// public class MiscUtils {
// 
//     /**
//      * Note: It seems like NativeEvent.getCharCode() would be equivalent.
//      */
//     public static native char getCharCode(NativeEvent e)
//     /*-{
//       return e.charCode || e.keyCode;
//     }-*/;
// 
//     public static final String getComputedStyle(Element e, String camelName) {
// 	// sometimes IE throws an exception. thanks IE!
//         try {
//             return getStyleImpl().getComputedStyle(e, hyphenize(camelName), camelName);
//         }
//         catch (Exception xcp) {
//             return null;
//         }
//     }
// 
//     public static final int getComputedStyleInt(Element e, String camelName) {
//         String num = getComputedStyle(e, camelName);
// 	return num != null ? parseInt(num) : 0;
//     }
// 
//     public static final int parseInt(String val) {
// 	return parseInt(val, 10);
//     }
// 
//     public static final native int parseInt(String val, int radix)
//     /*-{
//       return parseInt(val, radix) || 0;
//     }-*/;
// 
//     // ----------------------------------------------------------------------
//     // DocumentStyleImpl.getComputedStyle from gwtquery
// 
//     private static DocumentStyleImpl styleImpl = null;
//     private static DocumentStyleImpl getStyleImpl() {
//         if (styleImpl == null) {
//             styleImpl = GWT.create(DocumentStyleImpl.class);
//         }
//         return styleImpl;
//     }
// 
//     /**
//      * Hyphenize style property names. for instance: fontName ->
//      * font-name
//      */
//     private static native String hyphenize(String name) /*-{
//         return name.replace(/([A-Z])/g, "-$1").toLowerCase();
//     }-*/;
// 
// }


// Path: src/main/java/com/tractionsoftware/gwt/user/client/ui/AutoSizingTextArea.java
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.TextArea;
import com.tractionsoftware.gwt.user.client.util.MiscUtils;

/*
 * Copyright 2010 Traction Software, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.tractionsoftware.gwt.user.client.ui;



/**
 * This attaches to an input, listening for KeyDown/KeyUp, and
 * automatically resizing the text area. It does this using an
 * invisible textarea that matches the text of the input.
 */
public class AutoSizingTextArea extends AutoSizingBase<TextAreaWithSelection, TextArea> implements ResizeHandler {

    protected int divExtra = 0;
    protected HandlerRegistration resizeRegistration = null;

    public AutoSizingTextArea() {
	this(new TextAreaWithSelection());
    }
    private AutoSizingTextArea(TextAreaWithSelection box) {
	super(box, new TextArea());
    }
    public AutoSizingTextArea(TextAreaWithSelection box, int minSize, int maxSize) {
	super(box, new TextArea());
	setMinSize(minSize);
	setMaxSize(maxSize);
    }

    @Override
    protected void onLoad() {
	Element boxElement = box.getElement();

	int lineHeight = MiscUtils.getComputedStyleInt(boxElement, "lineHeight");