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