Added wrt files, prior to converting into Qt/C++.
[ptas] / wrt / misc / rss / WRTKit / UI / FormButton.js
diff --git a/wrt/misc/rss/WRTKit/UI/FormButton.js b/wrt/misc/rss/WRTKit/UI/FormButton.js
new file mode 100644 (file)
index 0000000..fdf59bf
--- /dev/null
@@ -0,0 +1,177 @@
+/*\r
+© Copyright 2008 Nokia Corporation. All rights reserved.\r
+\r
+IMPORTANT:  The Nokia software ("WRTKit and Example Widget files") is supplied to you by Nokia\r
+Corporation (“Nokia”) in consideration of your agreement to the following terms. Your use, installation\r
+and/or redistribution of the WRTKit and Example Widget files constitutes acceptance of these terms. If\r
+you do not agree with these terms, please do not use, install, or redistribute the WRTKit and Example\r
+Widget files.\r
+\r
+In consideration of your agreement to abide by the following terms, and subject to these terms, Nokia\r
+grants you a personal, non-exclusive license, under Nokia’s copyrights in the WRTKit and Example\r
+Widget files, to use, reproduce, and redistribute the WRTKit and Example files, in text form (for HTML,\r
+CSS, or JavaScript files) or binary form (for associated images), for the sole purpose of creating S60\r
+Widgets.\r
+\r
+If you redistribute the WRTKit and Example files, you must retain this entire notice in all such\r
+redistributions of the WRTKit and Example files.\r
+\r
+You may not use the name, trademarks, service marks or logos of Nokia to endorse or promote products\r
+that include the WRTKit and Example files without the prior written explicit agreement with Nokia.\r
+Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by\r
+Nokia herein, including but not limited to any patent rights that may be infringed by your products that\r
+incorporate the WRTKit and Example files or by other works in which the WRTKit and Example files\r
+may be incorporated.\r
+\r
+The WRTKit and Example files are provided on an "AS IS" basis.  NOKIA MAKES NO\r
+WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED\r
+WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A\r
+PARTICULAR PURPOSE, REGARDING THE EXAMPLES OR ITS USE AND OPERATION\r
+ALONE OR IN COMBINATION WITH YOUR PRODUCTS.\r
+\r
+IN NO EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR\r
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR\r
+DISTRIBUTION OF THE EXAMPLES, HOWEVER CAUSED AND WHETHER UNDER THEORY\r
+OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE,\r
+EVEN IF NOKIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+*/\r
+\r
+///////////////////////////////////////////////////////////////////////////////\r
+// The FormButton class implements a button control for use in form-style UIs.\r
+\r
+// Constructor.\r
+function FormButton(id, text) {\r
+    if (id != UI_NO_INIT_ID) {\r
+        this.init(id, text);\r
+    }\r
+}\r
+\r
+// FormButton inherits from ActionControl.\r
+FormButton.prototype = new ActionControl(UI_NO_INIT_ID);\r
+\r
+// Button table element.\r
+FormButton.prototype.tableElement = null;\r
+\r
+// Button table row element.\r
+FormButton.prototype.tableRowElement = null;\r
+\r
+// Button table left cell element.\r
+FormButton.prototype.tableLeftCellElement = null;\r
+\r
+// Button table center cell element.\r
+FormButton.prototype.tableCenterCellElement = null;\r
+\r
+// Button text element.\r
+FormButton.prototype.textElement = null;\r
+\r
+// Button table right cell element.\r
+FormButton.prototype.tableRightCellElement = null;\r
+\r
+// Initializer - called from constructor.\r
+FormButton.prototype.init = function(id, text) {\r
+    uiLogger.debug("FormButton.init(" + id + ", " + text + ")");\r
+    \r
+    // call superclass initializer\r
+    ActionControl.prototype.init.call(this, id, null);\r
+    \r
+    // remove caption element\r
+    this.assemblyElement.removeChild(this.captionElement);\r
+    \r
+    // construct the button\r
+    this.buttonElement = document.createElement("div");\r
+    this.tableElement = document.createElement("table");\r
+    this.tableRowElement = document.createElement("tr");\r
+    this.tableLeftCellElement = document.createElement("td");\r
+    this.tableCenterCellElement = document.createElement("td");\r
+    this.linkElement = document.createElement("a");\r
+    this.linkElement.href = "JavaScript:void(0)";\r
+    this.textElement = document.createElement("span");\r
+    this.tableRightCellElement = document.createElement("td");\r
+    this.tableElement.appendChild(this.tableRowElement);\r
+    this.tableRowElement.appendChild(this.tableLeftCellElement);\r
+    this.tableRowElement.appendChild(this.tableCenterCellElement);\r
+    this.tableCenterCellElement.appendChild(this.linkElement);\r
+    this.linkElement.appendChild(this.textElement);\r
+    this.tableRowElement.appendChild(this.tableRightCellElement);\r
+    this.buttonElement.appendChild(this.tableElement);\r
+    this.controlElement.appendChild(this.buttonElement);\r
+    \r
+    // set the text\r
+    this.setText(text);\r
+    \r
+    // bind event listeners\r
+    this.bindActionControlListeners();\r
+    \r
+    // update the style\r
+    this.updateStyleFromState();\r
+}\r
+\r
+// Sets the enabled state.\r
+FormButton.prototype.setEnabled = function(enabled) {\r
+    uiLogger.debug("FormButton.setEnabled(" + enabled + ")");\r
+    \r
+    // bail out early if there is no change in state\r
+    if (this.enabled == enabled) {\r
+        return;\r
+    }\r
+    \r
+    // set the enabled state\r
+    this.enabled = enabled;\r
+    \r
+    if (this.enabled) {\r
+        // diabled -> enabled\r
+        this.tableCenterCellElement.removeChild(this.textElement);\r
+        this.tableCenterCellElement.appendChild(this.linkElement);\r
+        this.linkElement.appendChild(this.textElement);\r
+    } else {\r
+        // enabled -> diabled\r
+        this.linkElement.removeChild(this.textElement);\r
+        this.tableCenterCellElement.removeChild(this.linkElement);\r
+        this.tableCenterCellElement.appendChild(this.textElement);\r
+    }\r
+    \r
+    // update the style\r
+    this.updateStyleFromState();\r
+}\r
+\r
+// Returns the button text.\r
+FormButton.prototype.getText = function() {\r
+    return this.textElement.innerHTML;\r
+}\r
+\r
+// Sets the button text.\r
+FormButton.prototype.setText = function(text) {\r
+    uiLogger.debug("FormButton.setText(" + text + ")");\r
+    this.textElement.innerHTML = (text == null) ? "" : text;;\r
+}\r
+\r
+// Updates the style of the control to reflects the state of the control.\r
+FormButton.prototype.updateStyleFromState = function() {\r
+    uiLogger.debug("FormButton.updateStyleFromState()");\r
+    \r
+    // determine the state name\r
+    var stateName = this.getStyleStateName();\r
+    \r
+    // set root element class name\r
+    this.setClassName(this.rootElement, "Control");\r
+    \r
+    // set the control assembly class names\r
+    this.setClassName(this.assemblyElement, "ControlAssembly ControlAssemblyNormal");\r
+    \r
+    // control element\r
+    this.setClassName(this.controlElement, "ControlElement FormButtonControlElement");\r
+    \r
+    // set the button table class names\r
+    this.setClassName(this.buttonElement, "FormButton");\r
+    this.setClassName(this.tableElement, "FormButtonTable");\r
+    this.setClassName(this.tableRowElement, "FormButtonRow");\r
+    this.setClassName(this.tableLeftCellElement, "FormButtonLeftCell FormButtonLeftCell" + stateName);\r
+    this.setClassName(this.tableCenterCellElement, "FormButtonCenterCell FormButtonLeftCell" + stateName);\r
+    this.setClassName(this.tableRightCellElement, "FormButtonRightCell FormButtonLeftCell" + stateName);\r
+    \r
+    // set the button text class name\r
+    this.setClassName(this.textElement, "FormButtonText FormButtonText" + stateName);\r
+}\r