author | Eugene Ostroukhov <eugeneo@symbian.org> |
Tue, 16 Mar 2010 18:01:11 -0700 | |
changeset 273 | b1f63c2c240c |
parent 211 | 7b148352159e |
permissions | -rw-r--r-- |
210
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
1 |
/** |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
2 |
* Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies). |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
3 |
* All rights reserved. |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
8 |
* |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
9 |
* Initial Contributors: |
273
b1f63c2c240c
Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
211
diff
changeset
|
10 |
* Nokia Corporation - initial contribution. |
b1f63c2c240c
Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
211
diff
changeset
|
11 |
* |
210
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
12 |
* Contributors: |
273
b1f63c2c240c
Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
211
diff
changeset
|
13 |
* |
b1f63c2c240c
Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
211
diff
changeset
|
14 |
* Description: |
b1f63c2c240c
Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
211
diff
changeset
|
15 |
* |
210
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
16 |
*/ |
73 | 17 |
|
18 |
/////////////////////////////////////////////////////////////////////////////// |
|
19 |
// The ListView class implements a vertical list view that hosts controls |
|
20 |
// as child components. |
|
21 |
||
22 |
// Constructor. |
|
23 |
function ListView(id, caption) { |
|
24 |
if (id != UI_NO_INIT_ID) { |
|
25 |
this.init(id, caption); |
|
26 |
} |
|
27 |
} |
|
28 |
||
29 |
// ListView inherits from View. |
|
30 |
ListView.prototype = new View(UI_NO_INIT_ID); |
|
31 |
||
32 |
// The caption of this view; null if none. |
|
33 |
ListView.prototype.caption = null; |
|
34 |
||
35 |
// The caption element of this view. |
|
36 |
ListView.prototype.captionElement = null; |
|
37 |
||
38 |
// The caption text element of this view. |
|
39 |
ListView.prototype.captionTextElement = null; |
|
40 |
||
41 |
// Root HTML element for controls. |
|
42 |
ListView.prototype.listElement = null; |
|
43 |
||
44 |
// List of controls in the view. |
|
45 |
ListView.prototype.controls = null; |
|
46 |
||
47 |
// Initializer for ListView. |
|
48 |
ListView.prototype.init = function(id, caption) { |
|
49 |
uiLogger.debug("ListView.init(" + id + ", " + caption + ")"); |
|
50 |
||
51 |
// call superclass initializer |
|
52 |
View.prototype.init.call(this, id); |
|
53 |
||
54 |
// init control array |
|
55 |
this.controls = []; |
|
56 |
||
57 |
// set style class name for root element |
|
58 |
this.rootElement.className = "ListView"; |
|
59 |
||
60 |
// create caption and caption text elements |
|
61 |
this.captionElement = document.createElement("div"); |
|
62 |
this.captionElement.className = "ListViewCaption"; |
|
63 |
this.captionTextElement = document.createElement("div"); |
|
64 |
this.captionTextElement.className = "ListViewCaptionText"; |
|
65 |
this.captionElement.appendChild(this.captionTextElement); |
|
66 |
this.rootElement.appendChild(this.captionElement); |
|
67 |
||
68 |
// create root element for controls and add to the view root element |
|
69 |
this.listElement = document.createElement("div"); |
|
70 |
this.listElement.className = "ListViewControlList"; |
|
71 |
this.rootElement.appendChild(this.listElement); |
|
72 |
||
73 |
// set the caption |
|
74 |
this.setCaption(caption); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
75 |
}; |
73 | 76 |
|
77 |
// Returns the caption; null if none. |
|
78 |
ListView.prototype.getCaption = function() { |
|
79 |
return this.caption; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
80 |
}; |
73 | 81 |
|
82 |
// Sets the caption; null if none. |
|
83 |
ListView.prototype.setCaption = function(caption) { |
|
84 |
uiLogger.debug("ListView.setCaption(" + caption + ")"); |
|
85 |
||
86 |
// set the display style |
|
87 |
this.captionElement.style.display = (caption == null) ? "none" : "block"; |
|
88 |
||
89 |
// set the caption |
|
90 |
this.caption = caption; |
|
91 |
this.captionTextElement.innerHTML = (caption == null) ? "" : caption; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
92 |
}; |
73 | 93 |
|
94 |
// Returns an array of controls in the view. |
|
95 |
ListView.prototype.getControls = function() { |
|
96 |
return this.controls; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
97 |
}; |
73 | 98 |
|
99 |
// Adds a control to the view. |
|
100 |
ListView.prototype.addControl = function(control) { |
|
101 |
uiLogger.debug("ListView.addControl(" + control + ")"); |
|
102 |
||
103 |
// add the control to the controls array and attach it to the list element |
|
104 |
this.controls.push(control); |
|
105 |
this.listElement.appendChild(control.rootElement); |
|
106 |
control.view = this; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
107 |
}; |
73 | 108 |
|
109 |
// Inserts a control to the view before the specified control. |
|
110 |
ListView.prototype.insertControl = function(control, beforeControl) { |
|
111 |
uiLogger.debug("ListView.insertControl(" + control + ", " + beforeControl + ")"); |
|
112 |
||
113 |
// iterate through current controls |
|
114 |
for (var i = 0; i < this.controls.length; i++) { |
|
115 |
// is this the control we should insert before? |
|
116 |
if (this.controls[i] == beforeControl) { |
|
117 |
// we found the control to insert before - insert here and connect to list element |
|
118 |
this.controls.splice(i, 0, control); |
|
119 |
this.listElement.insertBefore(control.rootElement, beforeControl.rootElement); |
|
120 |
control.view = this; |
|
121 |
return; |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
// the control wasn't found so we'll add it last |
|
126 |
this.addControl(control); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
127 |
}; |
73 | 128 |
|
129 |
// Removes a control from the view. |
|
130 |
ListView.prototype.removeControl = function(control) { |
|
131 |
uiLogger.debug("ListView.removeControl(" + control + ")"); |
|
132 |
||
133 |
// iterate through current controls |
|
134 |
for (var i = 0; i < this.controls.length; i++) { |
|
135 |
// is this the control we should remove? |
|
136 |
if (this.controls[i] == control) { |
|
137 |
// we found the control to remove - remove it from the list element |
|
138 |
this.controls.splice(i, 1); |
|
139 |
this.listElement.removeChild(control.rootElement); |
|
140 |
control.view = null; |
|
141 |
} |
|
142 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
143 |
}; |
73 | 144 |
|
145 |
// Attempts to focus the first focusable control. |
|
146 |
ListView.prototype.focusFirstControl = function() { |
|
147 |
uiLogger.debug("ListView.focusFirstControl()"); |
|
148 |
for (var i = 0; i < this.controls.length; i++) { |
|
149 |
// is this control focusable? |
|
150 |
var control = this.controls[i]; |
|
151 |
if (control.isFocusable()) { |
|
152 |
control.setFocused(true); |
|
153 |
break; |
|
154 |
} |
|
155 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
156 |
}; |
73 | 157 |
|
158 |
// Attempts to reset all control focus states. |
|
159 |
// Override in subclasses as required. |
|
160 |
ListView.prototype.resetControlFocusStates = function() { |
|
161 |
uiLogger.debug("ListView.resetControlFocusStates()"); |
|
162 |
for (var i = 0; i < this.controls.length; i++) { |
|
163 |
this.controls[i].resetFocusState(); |
|
164 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
165 |
}; |