Added wrt files, prior to converting into Qt/C++.
[ptas] / wrt / zouba / WRTKit / UI / ActionControl.js
diff --git a/wrt/zouba/WRTKit/UI/ActionControl.js b/wrt/zouba/WRTKit/UI/ActionControl.js
new file mode 100644 (file)
index 0000000..f97c8e5
--- /dev/null
@@ -0,0 +1,144 @@
+/*\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 ActionControl class is an abstract base class for action controls like\r
+// buttons. Don't use ActionControl directly.\r
+\r
+// Constructor.\r
+function ActionControl(id, caption) {\r
+    if (id != UI_NO_INIT_ID) {\r
+        this.init(id, caption);\r
+    }\r
+}\r
+\r
+// ActionControl inherits from Control.\r
+ActionControl.prototype = new Control(UI_NO_INIT_ID);\r
+\r
+// Reference to the button element.\r
+ActionControl.prototype.buttonElement = null;\r
+\r
+// Reference to the link element.\r
+ActionControl.prototype.linkElement = null;\r
+\r
+// Enabled status.\r
+ActionControl.prototype.enabled = false;\r
+\r
+// Initializer - called from constructor.\r
+ActionControl.prototype.init = function(id, caption) {\r
+    uiLogger.debug("ActionControl.init(" + id + ", " + caption + ")");\r
+    \r
+    // call superclass initializer\r
+    Control.prototype.init.call(this, id, caption);\r
+    \r
+    // the control defaults to enabled\r
+    this.enabled = true;\r
+}\r
+\r
+// Common event listeners hookup function called from subclasses.\r
+ActionControl.prototype.bindActionControlListeners = function() {\r
+    var self = this;\r
+    this.linkElement.addEventListener("focus", function() { self.focusStateChanged(true); }, false);\r
+    this.linkElement.addEventListener("blur", function() { self.focusStateChanged(false); }, false);\r
+    this.buttonElement.addEventListener("mouseover", function() { self.hoverStateChanged(true); }, false);\r
+    this.buttonElement.addEventListener("mouseout", function() { self.hoverStateChanged(false); }, false);\r
+    this.buttonElement.addEventListener("mousedown", function(event) {\r
+                                                       self.controlClicked(event);\r
+                                                       event.stopPropagation();\r
+                                                       event.preventDefault();\r
+                                                   }, true);\r
+    this.buttonElement.addEventListener("keydown", function(event) {\r
+                                                    // center and enter trigger the action\r
+                                                    if (event.keyCode == 0 || event.keyCode == 13) {\r
+                                                        self.controlClicked();\r
+                                                        event.stopPropagation();\r
+                                                        event.preventDefault();\r
+                                                    }\r
+                                                 }, true);\r
+}\r
+\r
+// Returns the enabled state.\r
+ActionControl.prototype.isEnabled = function() {\r
+    return this.enabled;\r
+}\r
+\r
+// Sets the enabled state.\r
+ActionControl.prototype.setEnabled = function(enabled) {\r
+    uiLogger.debug("ActionControl.setEnabled(" + enabled + ")");\r
+    // switch the state\r
+    this.enabled = enabled;\r
+}\r
+\r
+// Sets the focused state for the control.\r
+// Note: This may not always succeed.\r
+ActionControl.prototype.setFocused = function(focused) {\r
+    uiLogger.debug("ActionControl.setFocused(" + focused + ")");\r
+    if (this.enabled) {\r
+        if (focused) {\r
+            this.linkElement.focus();\r
+        } else {\r
+            this.linkElement.blur();\r
+        }\r
+    }\r
+}\r
+\r
+// Callback for clicks.\r
+ActionControl.prototype.controlClicked = function(event) {\r
+    uiLogger.debug("ActionControl.controlClicked()");\r
+    \r
+    // if we're enabled then a click results in an action performed event\r
+    if (this.enabled) {\r
+        // focus when clicked\r
+        if (!this.focused) {\r
+            this.linkElement.focus();\r
+        }\r
+        \r
+        // notify event listeners\r
+        this.actionPerformed(event);\r
+    }\r
+}\r
+\r
+// Callback for action performed events.\r
+ActionControl.prototype.actionPerformed = function(event) {\r
+    uiLogger.debug("ActionControl.actionPerformed()");\r
+    // notify event listeners\r
+    this.fireEvent(this.createEvent("ActionPerformed", event));\r
+}\r