org.symbian.tools.wrttools/projecttemplates/WRTKit/UI/TextEntryControl.js
author Eugene Ostroukhov <eugeneo@symbian.org>
Tue, 16 Mar 2010 18:01:11 -0700
changeset 273 b1f63c2c240c
parent 211 7b148352159e
permissions -rw-r--r--
Bug 2072 - Update .js files with EPL
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    17
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    18
///////////////////////////////////////////////////////////////////////////////
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    19
// The TextEntryControl class is an abstract base class for the single and multi-
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    20
// line text entry controls TextField and TextArea. Don't use TextEntryControl
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    21
// directly.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    22
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    23
// Constructor.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    24
function TextEntryControl(id, caption) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    25
    if (id != UI_NO_INIT_ID) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    26
        this.init(id, caption);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    27
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    28
}
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    29
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    30
// TextEntryControl inherits from Control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    31
TextEntryControl.prototype = new Control(UI_NO_INIT_ID);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    32
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    33
// Reference to the peer HTML element.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    34
TextEntryControl.prototype.peerElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    35
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    36
// Initializer - called from constructor.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    37
TextEntryControl.prototype.init = function(id, caption) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    38
    uiLogger.debug("TextEntryControl.init(" + id + ", " + caption + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    39
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    40
    // call superclass initializer
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    41
    Control.prototype.init.call(this, id, caption);
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    42
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    43
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    44
// Common event listeners hookup function called from subclasses.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    45
TextEntryControl.prototype.bindTextEntryControlListeners = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    46
    var self = this;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    47
    this.peerElement.addEventListener("focus", function() { self.focusStateChanged(true); }, false);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    48
    this.peerElement.addEventListener("blur", function() { self.focusStateChanged(false); }, false);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    49
    this.peerElement.addEventListener("mouseover", function() { self.hoverStateChanged(true); }, false);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    50
    this.peerElement.addEventListener("mouseout", function() { self.hoverStateChanged(false); }, false);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    51
    this.peerElement.addEventListener("change", function() { self.valueChanged(); }, false);
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    52
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    53
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    54
// Returns the enabled state.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    55
// Override this in subclasses as required to implement the state change.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    56
TextEntryControl.prototype.isEnabled = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    57
    return !this.peerElement.readOnly;
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    58
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    59
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    60
// Sets the enabled state.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    61
// Override this in subclasses as required to implement the state change.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    62
TextEntryControl.prototype.setEnabled = function(enabled) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    63
    uiLogger.debug("TextEntryControl.setEnabled(" + enabled + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    64
    this.peerElement.readOnly = !enabled;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    65
    // update the style
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    66
    this.updateStyleFromState();
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    67
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    68
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    69
// Returns the control text.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    70
TextEntryControl.prototype.getText = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    71
    return this.peerElement.value;
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    72
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    74
// Sets the text for the control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    75
TextEntryControl.prototype.setText = function(text) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    76
    this.peerElement.value = text;
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    77
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    78
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    79
// Returns the focusable state for the control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    80
TextEntryControl.prototype.isFocusable = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    81
    // text entry controls are always focusable
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    82
    return true;
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    83
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    84
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    85
// Sets the focused state for the control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    86
// Note: This may not always succeed.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    87
TextEntryControl.prototype.setFocused = function(focused) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    88
    uiLogger.debug("TextEntryControl.setFocused(" + focused + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    89
    if (focused) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    90
        this.peerElement.focus();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    91
    } else {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    92
        this.peerElement.blur();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    93
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
    94
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    95
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    96
// Callback for value change events.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    97
TextEntryControl.prototype.valueChanged = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    98
    uiLogger.debug("TextEntryControl.valueChanged()");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    99
    // notify event listeners
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   100
    this.fireEvent(this.createEvent("ValueChanged", this.peerElement.value));
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   101
};