org.symbian.tools.wrttools/projecttemplates/WRTKit/UI/SelectionMenu.js
changeset 102 30e0796f3ebb
parent 73 c56c874eef47
child 210 0f7abfd6ae62
equal deleted inserted replaced
101:15f3b303bbb1 102:30e0796f3ebb
    82     this.peerElement.addEventListener("focus", function() { self.focusStateChanged(true); }, false);
    82     this.peerElement.addEventListener("focus", function() { self.focusStateChanged(true); }, false);
    83     this.peerElement.addEventListener("blur", function() { self.focusStateChanged(false); }, false);
    83     this.peerElement.addEventListener("blur", function() { self.focusStateChanged(false); }, false);
    84     this.peerElement.addEventListener("mouseover", function() { self.hoverStateChanged(true); }, false);
    84     this.peerElement.addEventListener("mouseover", function() { self.hoverStateChanged(true); }, false);
    85     this.peerElement.addEventListener("mouseout", function() { self.hoverStateChanged(false); }, false);
    85     this.peerElement.addEventListener("mouseout", function() { self.hoverStateChanged(false); }, false);
    86     this.peerElement.addEventListener("change", function() { self.selectionChanged(); }, false);
    86     this.peerElement.addEventListener("change", function() { self.selectionChanged(); }, false);
    87 }
    87 };
    88 
    88 
    89 // Returns the enabled state.
    89 // Returns the enabled state.
    90 SelectionMenu.prototype.isEnabled = function() {
    90 SelectionMenu.prototype.isEnabled = function() {
    91     return !this.peerElement.disabled;
    91     return !this.peerElement.disabled;
    92 }
    92 };
    93 
    93 
    94 // Sets the enabled state.
    94 // Sets the enabled state.
    95 SelectionMenu.prototype.setEnabled = function(enabled) {
    95 SelectionMenu.prototype.setEnabled = function(enabled) {
    96     uiLogger.debug("SelectionMenu.setEnabled(" + enabled + ")");
    96     uiLogger.debug("SelectionMenu.setEnabled(" + enabled + ")");
    97     this.peerElement.disabled = !enabled;
    97     this.peerElement.disabled = !enabled;
    98 }
    98 };
    99 
    99 
   100 // Sets the focused state for the control.
   100 // Sets the focused state for the control.
   101 // Note: This may not always succeed.
   101 // Note: This may not always succeed.
   102 SelectionMenu.prototype.setFocused = function(focused) {
   102 SelectionMenu.prototype.setFocused = function(focused) {
   103     uiLogger.debug("SelectionMenu.setFocused(" + focused + ")");
   103     uiLogger.debug("SelectionMenu.setFocused(" + focused + ")");
   104     if (focused) {
   104     if (focused) {
   105         this.peerElement.focus();
   105         this.peerElement.focus();
   106     } else {
   106     } else {
   107         this.peerElement.blur();
   107         this.peerElement.blur();
   108     }
   108     }
   109 }
   109 };
   110 
   110 
   111 // Sets the currently selected options. Pass a single option in a single selection
   111 // Sets the currently selected options. Pass a single option in a single selection
   112 // control or an array of selected controls in a multiple selection control. To
   112 // control or an array of selected controls in a multiple selection control. To
   113 // deselect all options pass null in a single selection control and an empty array
   113 // deselect all options pass null in a single selection control and an empty array
   114 // in a multiple selection control.
   114 // in a multiple selection control.
   119     // iterate through the options and set the selected state
   119     // iterate through the options and set the selected state
   120     // on the corresponding option element
   120     // on the corresponding option element
   121     for (var i = 0; i < this.options.length; i++) {
   121     for (var i = 0; i < this.options.length; i++) {
   122         this.optionElements[i].selected = this.isSelected(this.options[i]);
   122         this.optionElements[i].selected = this.isSelected(this.options[i]);
   123     }
   123     }
   124 }
   124 };
   125 
   125 
   126 // Sets the options in the control.
   126 // Sets the options in the control.
   127 SelectionMenu.prototype.setOptions = function(options) {
   127 SelectionMenu.prototype.setOptions = function(options) {
   128     // call superclass setOptions()
   128     // call superclass setOptions()
   129     SelectionControl.prototype.setOptions.call(this, options);
   129     SelectionControl.prototype.setOptions.call(this, options);
   130     this.updateOptionElements();
   130     this.updateOptionElements();
   131 }
   131 };
   132 
   132 
   133 // Updates the option elements for the peer select element.
   133 // Updates the option elements for the peer select element.
   134 SelectionMenu.prototype.updateOptionElements = function() {
   134 SelectionMenu.prototype.updateOptionElements = function() {
   135     // start by removing all current options from the select element
   135     // start by removing all current options from the select element
   136     while (this.peerElement.firstChild != null) {
   136     while (this.peerElement.firstChild != null) {
   156         this.peerElement.appendChild(optionElement);
   156         this.peerElement.appendChild(optionElement);
   157     }
   157     }
   158     
   158     
   159     // update the style
   159     // update the style
   160     this.updateStyleFromState();    
   160     this.updateStyleFromState();    
   161 }
   161 };
   162 
   162 
   163 // Callback for selection change events.
   163 // Callback for selection change events.
   164 SelectionMenu.prototype.selectionChanged = function() {
   164 SelectionMenu.prototype.selectionChanged = function() {
   165     uiLogger.debug("SelectionControl.selectionChanged()");
   165     uiLogger.debug("SelectionControl.selectionChanged()");
   166     
   166     
   177         }
   177         }
   178     }
   178     }
   179     
   179     
   180     // notify event listeners
   180     // notify event listeners
   181     this.fireEvent(this.createEvent("SelectionChanged", this.getSelected()));
   181     this.fireEvent(this.createEvent("SelectionChanged", this.getSelected()));
   182 }
   182 };
   183 
   183 
   184 // Updates the style of the control to reflects the state of the control.
   184 // Updates the style of the control to reflects the state of the control.
   185 SelectionMenu.prototype.updateStyleFromState = function() {
   185 SelectionMenu.prototype.updateStyleFromState = function() {
   186     uiLogger.debug("SelectionMenu.updateStyleFromState()");
   186     uiLogger.debug("SelectionMenu.updateStyleFromState()");
   187     
   187     
   199     this.setClassName(this.peerElement, "SelectionMenu SelectionMenu" + peerStateName);
   199     this.setClassName(this.peerElement, "SelectionMenu SelectionMenu" + peerStateName);
   200     for (var i = 0; i < this.options.length; i++) {
   200     for (var i = 0; i < this.options.length; i++) {
   201         var option = this.optionElements[i];
   201         var option = this.optionElements[i];
   202         this.setClassName(option, "SelectionMenuOption SelectionMenuOption" + peerStateName);
   202         this.setClassName(option, "SelectionMenuOption SelectionMenuOption" + peerStateName);
   203     }
   203     }
   204 }
   204 };