javauis/lcdui_akn/lcdui/src/CMIDTextFieldEdwin.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Wed, 15 Sep 2010 12:05:25 +0300
branchRCL_3
changeset 77 7cee158cb8cd
parent 66 2455ef1f5bbc
child 83 26b2b12093af
permissions -rw-r--r--
Revision: v2.2.13 Kit: 201036
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
66
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     1
/*
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     2
* Copyright (c) 2003-2006 Nokia Corporation and/or its subsidiary(-ies).
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     3
* All rights reserved.
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     8
*
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
     9
* Initial Contributors:
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    11
*
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    12
* Contributors:
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    13
*
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    14
* Description:  Implementation class for TextField
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    15
*
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    16
*/
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    17
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    18
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    19
#include <lafmain.h>
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    20
// LAF
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    21
// use in GetLayou and DoLayout functions
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    22
#include <aknlayoutscalable_avkon.cdl.h>  // LAF
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    23
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    24
#include "CMIDEdwin.h"
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    25
// using API for iTextFieldItem
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    26
#include "CMIDTextFieldItem.h"
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    27
#include "CMIDTextFieldEdwin.h"
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    28
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    29
// class CMIDTextFieldEdwin
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    30
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    31
CMIDTextFieldEdwin* CMIDTextFieldEdwin::NewL(TInt aConstraints,
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    32
        const TDesC& aText,
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    33
        TInt aMaxSize,
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    34
        MMIDDisplayable* aDisplayable,
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    35
        CMIDTextFieldItem* aTextFieldItem)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    36
{
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    37
    ASSERT(aTextFieldItem); // we expect that it always exist for TextField
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    38
    CMIDTextFieldEdwin* textBox = new(ELeave)CMIDTextFieldEdwin(aConstraints, aDisplayable, aTextFieldItem);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    39
    CleanupStack::PushL(textBox);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    40
    textBox->ConstructL(aText,aMaxSize);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    41
    CleanupStack::Pop(textBox);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    42
    return textBox;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    43
}
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    44
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    45
void CMIDTextFieldEdwin::ConstructL(const TDesC& aText,TInt aMaxSize)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    46
{
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    47
    // just call superclass, for now
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    48
    CMIDEdwin::ConstructL(aText, aMaxSize);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    49
}
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    50
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    51
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    52
// ----------------------------------------------------------------------------
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    53
// CMIDTextFieldEdwin::GetLayout()
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    54
// ----------------------------------------------------------------------------
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    55
TAknMultiLineTextLayout CMIDTextFieldEdwin::GetLayout(
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    56
    TRect& aRect, TInt aNumLines) const
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    57
{
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    58
    TAknMultiLineTextLayout         edwinLayout;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    59
    TAknTextComponentLayout         textLayout;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    60
    RArray<TAknTextComponentLayout> edwinLayoutLines;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    61
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    62
    // leave margins first
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    63
    TAknWindowComponentLayout  textPaneLayout =
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    64
        AknLayoutScalable_Avkon::form2_midp_text_pane(
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    65
            AknLayoutScalable_Avkon::form2_midp_text_pane_ParamLimits().LastRow());
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    66
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    67
    TAknLayoutRect layRect;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    68
    layRect.LayoutRect(aRect, textPaneLayout.LayoutLine());
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    69
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    70
    aRect = layRect.Rect();
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    71
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    72
    for (TInt i = 0; i < aNumLines; i++)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    73
    {
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    74
        textLayout = AknLayoutScalable_Avkon::form2_mdip_text_pane_t1(i);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    75
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    76
        TRAP_IGNORE(
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    77
            edwinLayoutLines.AppendL(textLayout));
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    78
    }
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    79
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    80
    edwinLayout = TAknTextComponentLayout::Multiline(edwinLayoutLines);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    81
    edwinLayoutLines.Reset();
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    82
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    83
    return edwinLayout;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    84
}
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    85
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    86
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    87
CMIDTextFieldEdwin::CMIDTextFieldEdwin(TUint aConstraints, MMIDDisplayable* aDisplayable, CMIDTextFieldItem* aTextFieldItem)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    88
        : CMIDEdwin(aConstraints, aDisplayable, aTextFieldItem)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    89
{
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    90
}
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    91
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    92
CMIDTextFieldEdwin::~CMIDTextFieldEdwin()
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    93
{
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    94
    // just calls superclass destructor
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    95
}
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    96
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    97
/**
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    98
 * Layouts a TextField.
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
    99
 *
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   100
 * The Edwin control is laid-out in 2 steps:
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   101
 * <p>
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   102
 * Firstly, we calculate how many lines of text are formatted by
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   103
 * layout-ing the Edwin with the maximum lines of text that could be visible on screen.
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   104
 * <p>
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   105
 * Secondly, we layout the Edwin according to the number of formatted lines.
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   106
 * In case there are more lines that could fit on screen, we limit the number of displayed lines
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   107
 * to the maximum that can fit on screen.
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   108
 *
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   109
 * In case of of background formatting mode (e.g. TextLength() >= 1900),
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   110
 * the number of formatted lines is unpredictable.
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   111
 * We ensure that the number of lines shown is maximum.
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   112
 */
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   113
void CMIDTextFieldEdwin::DoLayout(const TRect& aRect)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   114
{
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   115
    TAknMultiLineTextLayout layout;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   116
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   117
    /** The skin text color overrides the text color in LAF. */
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   118
    TAknsQsnTextColorsIndex skinTextColor;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   119
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   120
    if (iConstraints & MMIDTextField::EUneditable)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   121
    { // skinning colour groups for uneditable text
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   122
        skinTextColor = EAknsCIQsnTextColorsCG53;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   123
    }
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   124
    else
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   125
    { // skinning colour groups for editable text
77
7cee158cb8cd Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 66
diff changeset
   126
        // Set color for content text (logical color constants
7cee158cb8cd Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 66
diff changeset
   127
        // are defined in lcdui.h)
7cee158cb8cd Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 66
diff changeset
   128
        skinTextColor = IsFocused() ?
7cee158cb8cd Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 66
diff changeset
   129
                        TAknsQsnTextColorsIndex(KHighlightedItemTextColor)
7cee158cb8cd Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 66
diff changeset
   130
                        : TAknsQsnTextColorsIndex(KNonHighlightedItemTextColor);
66
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   131
    }
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   132
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   133
    TRect parentRect = aRect;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   134
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   135
    TAknLayoutScalableParameterLimits paneLimits =
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   136
        AknLayoutScalable_Avkon::form2_mdip_text_pane_t1_ParamLimits();
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   137
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   138
    TInt maxHeightInLines = paneLimits.LastRow();
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   139
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   140
    SetMaximumHeightInLines(maxHeightInLines);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   141
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   142
    // layout edwin with the maximum number of lines first
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   143
    // to see how many number of lines will be formatted
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   144
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   145
    layout = GetLayout(parentRect, maxHeightInLines);   // changes aRect
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   146
    AknLayoutUtils::LayoutEdwin(this, parentRect, layout, skinTextColor);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   147
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   148
    TInt numLayoutLines;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   149
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   150
    if (!IsPartialFormatting())
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   151
    {
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   152
        // check how many lines are formatted
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   153
        // to prepare the multi line layout structure
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   154
        TInt numFormattedLines = TextLayout()->NumFormattedLines();
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   155
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   156
        if (numFormattedLines > maxHeightInLines)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   157
        {
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   158
            numLayoutLines = maxHeightInLines; // restrict the number of visible lines
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   159
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   160
#ifdef RD_SCALABLE_UI_V2
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   161
            // set the correct scrolling rect for line by line scrolling
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   162
            // when text is longer than displayed
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   163
            SetThisScrollRect(this, parentRect, layout, numLayoutLines);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   164
#endif // RD_SCALABLE_UI_V2
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   165
        }
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   166
        else
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   167
        {
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   168
            numLayoutLines = numFormattedLines;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   169
        }
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   170
    }
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   171
    else
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   172
    {
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   173
        // partial formatting mode
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   174
        // the number of formatted lines is unpredictable
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   175
        // ensure that the number of lines shown is maximum
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   176
        numLayoutLines = maxHeightInLines;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   177
    }
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   178
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   179
    // previously, the control was laid out showing the maximum number of lines
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   180
    // lay out again only if the control should be smaller in height
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   181
    if (numLayoutLines < maxHeightInLines)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   182
    {
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   183
        // parentRect was changed in the previous GetLayout()
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   184
        parentRect = aRect;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   185
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   186
        layout = GetLayout(parentRect, numLayoutLines);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   187
        AknLayoutUtils::LayoutEdwin(this, parentRect, layout, skinTextColor);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   188
    }
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   189
}
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   190
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   191
#ifdef RD_SCALABLE_UI_V2
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   192
TRect CMIDTextFieldEdwin::LineRect(TRect aParentRect, TInt aLine, TAknMultiLineTextLayout aLayout)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   193
{
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   194
    TAknLayoutText text;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   195
    text.LayoutText(aParentRect, aLayout);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   196
    TRect rect = text.TextRect();
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   197
    rect.iTl.iY += aLayout.iBaselineSkip * aLine;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   198
    rect.iBr.iY += aLayout.iBaselineSkip * aLine;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   199
    return rect;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   200
}
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   201
#endif // RD_SCALABLE_UI_V2
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   202
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   203
#ifdef RD_SCALABLE_UI_V2
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   204
void CMIDTextFieldEdwin::SetThisScrollRect(CMIDTextFieldEdwin *aEdwin, TRect aParentRect, TAknMultiLineTextLayout aLayout, TInt aNumberOfLines)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   205
{
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   206
    TRect top = LineRect(aParentRect, 1, aLayout);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   207
    TRect bottom = LineRect(aParentRect, aNumberOfLines-2, aLayout);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   208
    TRect area = TRect(top.iTl, bottom.iBr);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   209
    aEdwin->CEikEdwin::SetScrollRect(area);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   210
}
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   211
#endif // RD_SCALABLE_UI_V2
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   212
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   213
void CMIDTextFieldEdwin::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   214
{
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   215
    switch (aEventType)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   216
    {
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   217
    case MCoeControlObserver::EEventStateChanged:
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   218
        iTextFieldItem->HandleControlEventL(aControl, aEventType);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   219
        break;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   220
    case MCoeControlObserver::EEventRequestFocus:
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   221
        iTextFieldItem->HandleControlEventL(this, MCoeControlObserver::EEventRequestFocus);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   222
        break;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   223
    default:
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   224
        break;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   225
    }
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   226
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   227
    CMIDEdwin::HandleControlEventL(aControl, aEventType);   // will update iStateChanged if needed
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   228
}
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   229
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   230
void CMIDTextFieldEdwin::PositionChanged()
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   231
{
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   232
    if (iTextFieldItem->Form())
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   233
    {
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   234
        TInt newYPos = iTextView->ViewRect().iTl.iY + iTextFieldItem->Form()->ScrollDelta();
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   235
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   236
        TRect rect;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   237
        rect.SetRect(TPoint(iTextView->ViewRect().iTl.iX, newYPos), iTextView->ViewRect().Size());
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   238
        iTextView->SetViewRect(rect);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   239
    }
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   240
}
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   241
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   242
/**
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   243
 * Need to recreate TextView here such that it uses the right window
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   244
 */
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   245
void CMIDTextFieldEdwin::SetContainerWindowL(const CCoeControl& aContainer)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   246
{
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   247
    CMIDEdwin::SetContainerWindowL(aContainer);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   248
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   249
    if (iTextView)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   250
    {
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   251
        delete iTextView;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   252
        iTextView = NULL;
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   253
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   254
        CreateTextViewL();
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   255
    }
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   256
}
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   257
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   258
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   259
void CMIDTextFieldEdwin::AddCommandToEdwinL(MMIDCommand& aCommand)
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   260
{
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   261
    STATIC_CAST(CMIDTextFieldItem*, iTextFieldItem)->AddCommandL(&aCommand);
2455ef1f5bbc Revert incorrect RCL_3 drop:
Pat Downey <patd@symbian.org>
parents:
diff changeset
   262
}