2 © Copyright 2008 Nokia Corporation. All rights reserved.
\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
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
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
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
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
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
42 ///////////////////////////////////////////////////////////////////////////////
\r
43 // The FormButton class implements a button control for use in form-style UIs.
\r
46 function FormButton(id, text) {
\r
47 if (id != UI_NO_INIT_ID) {
\r
48 this.init(id, text);
\r
52 // FormButton inherits from ActionControl.
\r
53 FormButton.prototype = new ActionControl(UI_NO_INIT_ID);
\r
55 // Button table element.
\r
56 FormButton.prototype.tableElement = null;
\r
58 // Button table row element.
\r
59 FormButton.prototype.tableRowElement = null;
\r
61 // Button table left cell element.
\r
62 FormButton.prototype.tableLeftCellElement = null;
\r
64 // Button table center cell element.
\r
65 FormButton.prototype.tableCenterCellElement = null;
\r
67 // Button text element.
\r
68 FormButton.prototype.textElement = null;
\r
70 // Button table right cell element.
\r
71 FormButton.prototype.tableRightCellElement = null;
\r
73 // Initializer - called from constructor.
\r
74 FormButton.prototype.init = function(id, text) {
\r
75 uiLogger.debug("FormButton.init(" + id + ", " + text + ")");
\r
77 // call superclass initializer
\r
78 ActionControl.prototype.init.call(this, id, null);
\r
80 // remove caption element
\r
81 this.assemblyElement.removeChild(this.captionElement);
\r
83 // construct the button
\r
84 this.buttonElement = document.createElement("div");
\r
85 this.tableElement = document.createElement("table");
\r
86 this.tableRowElement = document.createElement("tr");
\r
87 this.tableLeftCellElement = document.createElement("td");
\r
88 this.tableCenterCellElement = document.createElement("td");
\r
89 this.linkElement = document.createElement("a");
\r
90 this.linkElement.href = "JavaScript:void(0)";
\r
91 this.textElement = document.createElement("span");
\r
92 this.tableRightCellElement = document.createElement("td");
\r
93 this.tableElement.appendChild(this.tableRowElement);
\r
94 this.tableRowElement.appendChild(this.tableLeftCellElement);
\r
95 this.tableRowElement.appendChild(this.tableCenterCellElement);
\r
96 this.tableCenterCellElement.appendChild(this.linkElement);
\r
97 this.linkElement.appendChild(this.textElement);
\r
98 this.tableRowElement.appendChild(this.tableRightCellElement);
\r
99 this.buttonElement.appendChild(this.tableElement);
\r
100 this.controlElement.appendChild(this.buttonElement);
\r
103 this.setText(text);
\r
105 // bind event listeners
\r
106 this.bindActionControlListeners();
\r
108 // update the style
\r
109 this.updateStyleFromState();
\r
112 // Sets the enabled state.
\r
113 FormButton.prototype.setEnabled = function(enabled) {
\r
114 uiLogger.debug("FormButton.setEnabled(" + enabled + ")");
\r
116 // bail out early if there is no change in state
\r
117 if (this.enabled == enabled) {
\r
121 // set the enabled state
\r
122 this.enabled = enabled;
\r
124 if (this.enabled) {
\r
125 // diabled -> enabled
\r
126 this.tableCenterCellElement.removeChild(this.textElement);
\r
127 this.tableCenterCellElement.appendChild(this.linkElement);
\r
128 this.linkElement.appendChild(this.textElement);
\r
130 // enabled -> diabled
\r
131 this.linkElement.removeChild(this.textElement);
\r
132 this.tableCenterCellElement.removeChild(this.linkElement);
\r
133 this.tableCenterCellElement.appendChild(this.textElement);
\r
136 // update the style
\r
137 this.updateStyleFromState();
\r
140 // Returns the button text.
\r
141 FormButton.prototype.getText = function() {
\r
142 return this.textElement.innerHTML;
\r
145 // Sets the button text.
\r
146 FormButton.prototype.setText = function(text) {
\r
147 uiLogger.debug("FormButton.setText(" + text + ")");
\r
148 this.textElement.innerHTML = (text == null) ? "" : text;;
\r
151 // Updates the style of the control to reflects the state of the control.
\r
152 FormButton.prototype.updateStyleFromState = function() {
\r
153 uiLogger.debug("FormButton.updateStyleFromState()");
\r
155 // determine the state name
\r
156 var stateName = this.getStyleStateName();
\r
158 // set root element class name
\r
159 this.setClassName(this.rootElement, "Control");
\r
161 // set the control assembly class names
\r
162 this.setClassName(this.assemblyElement, "ControlAssembly ControlAssemblyNormal");
\r
165 this.setClassName(this.controlElement, "ControlElement FormButtonControlElement");
\r
167 // set the button table class names
\r
168 this.setClassName(this.buttonElement, "FormButton");
\r
169 this.setClassName(this.tableElement, "FormButtonTable");
\r
170 this.setClassName(this.tableRowElement, "FormButtonRow");
\r
171 this.setClassName(this.tableLeftCellElement, "FormButtonLeftCell FormButtonLeftCell" + stateName);
\r
172 this.setClassName(this.tableCenterCellElement, "FormButtonCenterCell FormButtonLeftCell" + stateName);
\r
173 this.setClassName(this.tableRightCellElement, "FormButtonRightCell FormButtonLeftCell" + stateName);
\r
175 // set the button text class name
\r
176 this.setClassName(this.textElement, "FormButtonText FormButtonText" + stateName);
\r