Changed zouba directory heirarchy.
[ptas] / zouba / misc / rss / WRTKit / UI / TextEntryControl.js
1 /*\r
2 © Copyright 2008 Nokia Corporation. All rights reserved.\r
3 \r
4 IMPORTANT:  The Nokia software ("WRTKit and Example Widget files") is supplied to you by Nokia\r
5 Corporation (“Nokia”) in consideration of your agreement to the following terms. Your use, installation\r
6 and/or redistribution of the WRTKit and Example Widget files constitutes acceptance of these terms. If\r
7 you do not agree with these terms, please do not use, install, or redistribute the WRTKit and Example\r
8 Widget files.\r
9 \r
10 In consideration of your agreement to abide by the following terms, and subject to these terms, Nokia\r
11 grants you a personal, non-exclusive license, under Nokia’s copyrights in the WRTKit and Example\r
12 Widget files, to use, reproduce, and redistribute the WRTKit and Example files, in text form (for HTML,\r
13 CSS, or JavaScript files) or binary form (for associated images), for the sole purpose of creating S60\r
14 Widgets.\r
15 \r
16 If you redistribute the WRTKit and Example files, you must retain this entire notice in all such\r
17 redistributions of the WRTKit and Example files.\r
18 \r
19 You may not use the name, trademarks, service marks or logos of Nokia to endorse or promote products\r
20 that include the WRTKit and Example files without the prior written explicit agreement with Nokia.\r
21 Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by\r
22 Nokia herein, including but not limited to any patent rights that may be infringed by your products that\r
23 incorporate the WRTKit and Example files or by other works in which the WRTKit and Example files\r
24 may be incorporated.\r
25 \r
26 The WRTKit and Example files are provided on an "AS IS" basis.  NOKIA MAKES NO\r
27 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED\r
28 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A\r
29 PARTICULAR PURPOSE, REGARDING THE EXAMPLES OR ITS USE AND OPERATION\r
30 ALONE OR IN COMBINATION WITH YOUR PRODUCTS.\r
31 \r
32 IN NO EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR\r
33 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
34 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
35 INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR\r
36 DISTRIBUTION OF THE EXAMPLES, HOWEVER CAUSED AND WHETHER UNDER THEORY\r
37 OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE,\r
38 EVEN IF NOKIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
39 \r
40 */\r
41 \r
42 ///////////////////////////////////////////////////////////////////////////////\r
43 // The TextEntryControl class is an abstract base class for the single and multi-\r
44 // line text entry controls TextField and TextArea. Don't use TextEntryControl\r
45 // directly.\r
46 \r
47 // Constructor.\r
48 function TextEntryControl(id, caption) {\r
49     if (id != UI_NO_INIT_ID) {\r
50         this.init(id, caption);\r
51     }\r
52 }\r
53 \r
54 // TextEntryControl inherits from Control.\r
55 TextEntryControl.prototype = new Control(UI_NO_INIT_ID);\r
56 \r
57 // Reference to the peer HTML element.\r
58 TextEntryControl.prototype.peerElement = null;\r
59 \r
60 // Initializer - called from constructor.\r
61 TextEntryControl.prototype.init = function(id, caption) {\r
62     uiLogger.debug("TextEntryControl.init(" + id + ", " + caption + ")");\r
63     \r
64     // call superclass initializer\r
65     Control.prototype.init.call(this, id, caption);\r
66 }\r
67 \r
68 // Common event listeners hookup function called from subclasses.\r
69 TextEntryControl.prototype.bindTextEntryControlListeners = function() {\r
70     var self = this;\r
71     this.peerElement.addEventListener("focus", function() { self.focusStateChanged(true); }, false);\r
72     this.peerElement.addEventListener("blur", function() { self.focusStateChanged(false); }, false);\r
73     this.peerElement.addEventListener("mouseover", function() { self.hoverStateChanged(true); }, false);\r
74     this.peerElement.addEventListener("mouseout", function() { self.hoverStateChanged(false); }, false);\r
75     this.peerElement.addEventListener("change", function() { self.valueChanged(); }, false);\r
76 }\r
77 \r
78 // Returns the enabled state.\r
79 // Override this in subclasses as required to implement the state change.\r
80 TextEntryControl.prototype.isEnabled = function() {\r
81     return !this.peerElement.readOnly;\r
82 }\r
83 \r
84 // Sets the enabled state.\r
85 // Override this in subclasses as required to implement the state change.\r
86 TextEntryControl.prototype.setEnabled = function(enabled) {\r
87     uiLogger.debug("TextEntryControl.setEnabled(" + enabled + ")");\r
88     this.peerElement.readOnly = !enabled;\r
89     // update the style\r
90     this.updateStyleFromState();\r
91 }\r
92 \r
93 // Returns the control text.\r
94 TextEntryControl.prototype.getText = function() {\r
95     return this.peerElement.value;\r
96 }\r
97 \r
98 // Sets the text for the control.\r
99 TextEntryControl.prototype.setText = function(text) {\r
100     this.peerElement.value = text;\r
101 }\r
102 \r
103 // Returns the focusable state for the control.\r
104 TextEntryControl.prototype.isFocusable = function() {\r
105     // text entry controls are always focusable\r
106     return true;\r
107 }\r
108 \r
109 // Sets the focused state for the control.\r
110 // Note: This may not always succeed.\r
111 TextEntryControl.prototype.setFocused = function(focused) {\r
112     uiLogger.debug("TextEntryControl.setFocused(" + focused + ")");\r
113     if (focused) {\r
114         this.peerElement.focus();\r
115     } else {\r
116         this.peerElement.blur();\r
117     }\r
118 }\r
119 \r
120 // Callback for value change events.\r
121 TextEntryControl.prototype.valueChanged = function() {\r
122     uiLogger.debug("TextEntryControl.valueChanged()");\r
123     // notify event listeners\r
124     this.fireEvent(this.createEvent("ValueChanged", this.peerElement.value));\r
125 }\r