org.symbian.tools.wrttools/projecttemplates/WRTKit/UI/TextEntryControl.js
changeset 309 c01f5ab28a11
parent 308 c521df56b15d
child 310 e9484be98cfe
equal deleted inserted replaced
308:c521df56b15d 309:c01f5ab28a11
     1 /**
       
     2  * Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the License "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  * 
       
    12  * Contributors:
       
    13  * 
       
    14  * Description:
       
    15  * 
       
    16  */
       
    17 
       
    18 ///////////////////////////////////////////////////////////////////////////////
       
    19 // The TextEntryControl class is an abstract base class for the single and multi-
       
    20 // line text entry controls TextField and TextArea. Don't use TextEntryControl
       
    21 // directly.
       
    22 
       
    23 // Constructor.
       
    24 function TextEntryControl(id, caption) {
       
    25     if (id != UI_NO_INIT_ID) {
       
    26         this.init(id, caption);
       
    27     }
       
    28 }
       
    29 
       
    30 // TextEntryControl inherits from Control.
       
    31 TextEntryControl.prototype = new Control(UI_NO_INIT_ID);
       
    32 
       
    33 // Reference to the peer HTML element.
       
    34 TextEntryControl.prototype.peerElement = null;
       
    35 
       
    36 // Initializer - called from constructor.
       
    37 TextEntryControl.prototype.init = function(id, caption) {
       
    38     uiLogger.debug("TextEntryControl.init(" + id + ", " + caption + ")");
       
    39     
       
    40     // call superclass initializer
       
    41     Control.prototype.init.call(this, id, caption);
       
    42 };
       
    43 
       
    44 // Common event listeners hookup function called from subclasses.
       
    45 TextEntryControl.prototype.bindTextEntryControlListeners = function() {
       
    46     var self = this;
       
    47     this.peerElement.addEventListener("focus", function() { self.focusStateChanged(true); }, false);
       
    48     this.peerElement.addEventListener("blur", function() { self.focusStateChanged(false); }, false);
       
    49     this.peerElement.addEventListener("mouseover", function() { self.hoverStateChanged(true); }, false);
       
    50     this.peerElement.addEventListener("mouseout", function() { self.hoverStateChanged(false); }, false);
       
    51     this.peerElement.addEventListener("change", function() { self.valueChanged(); }, false);
       
    52 };
       
    53 
       
    54 // Returns the enabled state.
       
    55 // Override this in subclasses as required to implement the state change.
       
    56 TextEntryControl.prototype.isEnabled = function() {
       
    57     return !this.peerElement.readOnly;
       
    58 };
       
    59 
       
    60 // Sets the enabled state.
       
    61 // Override this in subclasses as required to implement the state change.
       
    62 TextEntryControl.prototype.setEnabled = function(enabled) {
       
    63     uiLogger.debug("TextEntryControl.setEnabled(" + enabled + ")");
       
    64     this.peerElement.readOnly = !enabled;
       
    65     // update the style
       
    66     this.updateStyleFromState();
       
    67 };
       
    68 
       
    69 // Returns the control text.
       
    70 TextEntryControl.prototype.getText = function() {
       
    71     return this.peerElement.value;
       
    72 };
       
    73 
       
    74 // Sets the text for the control.
       
    75 TextEntryControl.prototype.setText = function(text) {
       
    76     this.peerElement.value = text;
       
    77 };
       
    78 
       
    79 // Returns the focusable state for the control.
       
    80 TextEntryControl.prototype.isFocusable = function() {
       
    81     // text entry controls are always focusable
       
    82     return true;
       
    83 };
       
    84 
       
    85 // Sets the focused state for the control.
       
    86 // Note: This may not always succeed.
       
    87 TextEntryControl.prototype.setFocused = function(focused) {
       
    88     uiLogger.debug("TextEntryControl.setFocused(" + focused + ")");
       
    89     if (focused) {
       
    90         this.peerElement.focus();
       
    91     } else {
       
    92         this.peerElement.blur();
       
    93     }
       
    94 };
       
    95 
       
    96 // Callback for value change events.
       
    97 TextEntryControl.prototype.valueChanged = function() {
       
    98     uiLogger.debug("TextEntryControl.valueChanged()");
       
    99     // notify event listeners
       
   100     this.fireEvent(this.createEvent("ValueChanged", this.peerElement.value));
       
   101 };