Modified:
trunk/user/src/com/google/gwt/user/client/ui/PasswordTextBox.java
trunk/user/src/com/google/gwt/user/client/ui/TextArea.java
trunk/user/src/com/google/gwt/user/client/ui/TextBox.java
trunk/user/src/com/google/gwt/user/client/ui/TextBoxBase.java
Log:
Fixes issue 1064 "Add read-only flag for TextBox". Also adds a new dependent style name called "-readonly".
Review by: knorton (desk)
Modified: trunk/user/src/com/google/gwt/user/client/ui/PasswordTextBox.java
==============================================================================
--- trunk/user/src/com/google/gwt/user/client/ui/PasswordTextBox.java (original)
+++ trunk/user/src/com/google/gwt/user/client/ui/PasswordTextBox.java Wed May 23 00:10:20 2007
@@ -1,5 +1,5 @@
/*
- * Copyright 2006 Google Inc.
+ * Copyright 2007 Google 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
@@ -26,7 +26,8 @@
*
* <h3>CSS Style Rules</h3>
* <ul class='css'>
- * <li>.gwt-PasswordTextBox { }</li>
+ * <li>.gwt-PasswordTextBox { primary style }</li>
+ * <li>.gwt-PasswordTextBox-readonly { dependent style set when the password text box is read-only }</li>
* </ul>
*
* <p>
Modified: trunk/user/src/com/google/gwt/user/client/ui/TextArea.java
==============================================================================
--- trunk/user/src/com/google/gwt/user/client/ui/TextArea.java (original)
+++ trunk/user/src/com/google/gwt/user/client/ui/TextArea.java Wed May 23 00:10:20 2007
@@ -1,5 +1,5 @@
/*
- * Copyright 2006 Google Inc.
+ * Copyright 2007 Google 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
@@ -26,7 +26,8 @@
*
* <h3>CSS Style Rules</h3>
* <ul class='css'>
- * <li>.gwt-TextArea { }</li>
+ * <li>.gwt-TextArea { primary style }</li>
+ * <li>.gwt-TextArea-readonly { dependent style set when the text area is read-only }</li>
* </ul>
*
* <p>
Modified: trunk/user/src/com/google/gwt/user/client/ui/TextBox.java
==============================================================================
--- trunk/user/src/com/google/gwt/user/client/ui/TextBox.java (original)
+++ trunk/user/src/com/google/gwt/user/client/ui/TextBox.java Wed May 23 00:10:20 2007
@@ -1,5 +1,5 @@
/*
- * Copyright 2006 Google Inc.
+ * Copyright 2007 Google 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
@@ -26,11 +26,13 @@
*
* <h3>CSS Style Rules</h3>
* <ul class='css'>
- * <li>.gwt-TextBox { }</li>
+ * <li>.gwt-TextBox { primary style }</li>
+ * <li>.gwt-TextBox-readonly { dependent style set when the text box is read-only }</li>
* </ul>
*
* <p>
- * <h3>Example</h3> {@example com.google.gwt.examples.TextBoxExample}
+ * <h3>Example</h3>
+ * {@example com.google.gwt.examples.TextBoxExample}
* </p>
*/
public class TextBox extends TextBoxBase {
Modified: trunk/user/src/com/google/gwt/user/client/ui/TextBoxBase.java
==============================================================================
--- trunk/user/src/com/google/gwt/user/client/ui/TextBoxBase.java (original)
+++ trunk/user/src/com/google/gwt/user/client/ui/TextBoxBase.java Wed May 23 00:10:20 2007
@@ -1,5 +1,5 @@
/*
- * Copyright 2006 Google Inc.
+ * Copyright 2007 Google 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
@@ -154,6 +154,16 @@
return DOM.getElementProperty(getElement(), "value");
}
+ /**
+ * Determines whether or not the widget is read-only.
+ *
+ * @return <code>true</code> if the widget is currently read-only,
+ * <code>false</code> if the widget is currently editable
+ */
+ public boolean isReadOnly() {
+ return DOM.getElementPropertyBoolean(getElement(), "readOnly");
+ }
+
public void onBrowserEvent(Event event) {
// Call the superclass' implementation first (because FocusWidget fires
// some events itself).
@@ -231,6 +241,22 @@
public void setName(String name) {
DOM.setElementProperty(getElement(), "name", name);
+ }
+
+ /**
+ * Turns read-only mode on or off.
+ *
+ * @param readOnly if <code>true</code>, the widget becomes read-only; if
+ * <code>false</code> the widget becomes editable
+ */
+ public void setReadOnly(boolean readOnly) {
+ DOM.setElementPropertyBoolean(getElement(), "readOnly", readOnly);
+ String readOnlyStyle = getStyleName() + "-readonly";
+ if (readOnly) {
+ addStyleName(readOnlyStyle);
+ } else {
+ removeStyleName(readOnlyStyle);
+ }
}
/**