|
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 |
|
126 skinTextColor = EAknsCIQsnTextColorsCG8; |
|
127 } |
|
128 |
|
129 TRect parentRect = aRect; |
|
130 |
|
131 TAknLayoutScalableParameterLimits paneLimits = |
|
132 AknLayoutScalable_Avkon::form2_mdip_text_pane_t1_ParamLimits(); |
|
133 |
|
134 TInt maxHeightInLines = paneLimits.LastRow(); |
|
135 |
|
136 SetMaximumHeightInLines(maxHeightInLines); |
|
137 |
|
138 // layout edwin with the maximum number of lines first |
|
139 // to see how many number of lines will be formatted |
|
140 |
|
141 layout = GetLayout(parentRect, maxHeightInLines); // changes aRect |
|
142 AknLayoutUtils::LayoutEdwin(this, parentRect, layout, skinTextColor); |
|
143 |
|
144 TInt numLayoutLines; |
|
145 |
|
146 if (!IsPartialFormatting()) |
|
147 { |
|
148 // check how many lines are formatted |
|
149 // to prepare the multi line layout structure |
|
150 TInt numFormattedLines = TextLayout()->NumFormattedLines(); |
|
151 |
|
152 if (numFormattedLines > maxHeightInLines) |
|
153 { |
|
154 numLayoutLines = maxHeightInLines; // restrict the number of visible lines |
|
155 |
|
156 #ifdef RD_SCALABLE_UI_V2 |
|
157 // set the correct scrolling rect for line by line scrolling |
|
158 // when text is longer than displayed |
|
159 SetThisScrollRect(this, parentRect, layout, numLayoutLines); |
|
160 #endif // RD_SCALABLE_UI_V2 |
|
161 } |
|
162 else |
|
163 { |
|
164 numLayoutLines = numFormattedLines; |
|
165 } |
|
166 } |
|
167 else |
|
168 { |
|
169 // partial formatting mode |
|
170 // the number of formatted lines is unpredictable |
|
171 // ensure that the number of lines shown is maximum |
|
172 numLayoutLines = maxHeightInLines; |
|
173 } |
|
174 |
|
175 // previously, the control was laid out showing the maximum number of lines |
|
176 // lay out again only if the control should be smaller in height |
|
177 if (numLayoutLines < maxHeightInLines) |
|
178 { |
|
179 // parentRect was changed in the previous GetLayout() |
|
180 parentRect = aRect; |
|
181 |
|
182 layout = GetLayout(parentRect, numLayoutLines); |
|
183 AknLayoutUtils::LayoutEdwin(this, parentRect, layout, skinTextColor); |
|
184 } |
|
185 } |
|
186 |
|
187 #ifdef RD_SCALABLE_UI_V2 |
|
188 TRect CMIDTextFieldEdwin::LineRect(TRect aParentRect, TInt aLine, TAknMultiLineTextLayout aLayout) |
|
189 { |
|
190 TAknLayoutText text; |
|
191 text.LayoutText(aParentRect, aLayout); |
|
192 TRect rect = text.TextRect(); |
|
193 rect.iTl.iY += aLayout.iBaselineSkip * aLine; |
|
194 rect.iBr.iY += aLayout.iBaselineSkip * aLine; |
|
195 return rect; |
|
196 } |
|
197 #endif // RD_SCALABLE_UI_V2 |
|
198 |
|
199 #ifdef RD_SCALABLE_UI_V2 |
|
200 void CMIDTextFieldEdwin::SetThisScrollRect(CMIDTextFieldEdwin *aEdwin, TRect aParentRect, TAknMultiLineTextLayout aLayout, TInt aNumberOfLines) |
|
201 { |
|
202 TRect top = LineRect(aParentRect, 1, aLayout); |
|
203 TRect bottom = LineRect(aParentRect, aNumberOfLines-2, aLayout); |
|
204 TRect area = TRect(top.iTl, bottom.iBr); |
|
205 aEdwin->CEikEdwin::SetScrollRect(area); |
|
206 } |
|
207 #endif // RD_SCALABLE_UI_V2 |
|
208 |
|
209 void CMIDTextFieldEdwin::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType) |
|
210 { |
|
211 switch (aEventType) |
|
212 { |
|
213 case MCoeControlObserver::EEventStateChanged: |
|
214 iTextFieldItem->HandleControlEventL(aControl, aEventType); |
|
215 break; |
|
216 case MCoeControlObserver::EEventRequestFocus: |
|
217 iTextFieldItem->HandleControlEventL(this, MCoeControlObserver::EEventRequestFocus); |
|
218 break; |
|
219 default: |
|
220 break; |
|
221 } |
|
222 |
|
223 CMIDEdwin::HandleControlEventL(aControl, aEventType); // will update iStateChanged if needed |
|
224 } |
|
225 |
|
226 void CMIDTextFieldEdwin::PositionChanged() |
|
227 { |
|
228 if (iTextFieldItem->Form()) |
|
229 { |
|
230 TInt newYPos = iTextView->ViewRect().iTl.iY + iTextFieldItem->Form()->ScrollDelta(); |
|
231 |
|
232 TRect rect; |
|
233 rect.SetRect(TPoint(iTextView->ViewRect().iTl.iX, newYPos), iTextView->ViewRect().Size()); |
|
234 iTextView->SetViewRect(rect); |
|
235 } |
|
236 } |
|
237 |
|
238 /** |
|
239 * Need to recreate TextView here such that it uses the right window |
|
240 */ |
|
241 void CMIDTextFieldEdwin::SetContainerWindowL(const CCoeControl& aContainer) |
|
242 { |
|
243 CMIDEdwin::SetContainerWindowL(aContainer); |
|
244 |
|
245 if (iTextView) |
|
246 { |
|
247 delete iTextView; |
|
248 iTextView = NULL; |
|
249 |
|
250 CreateTextViewL(); |
|
251 } |
|
252 } |
|
253 |
|
254 |
|
255 void CMIDTextFieldEdwin::AddCommandsToEdwinL(RPointerArray<MMIDCommand>& aArray) |
|
256 { |
|
257 for (TInt i = 0; i < aArray.Count(); i++) |
|
258 { |
|
259 STATIC_CAST(CMIDTextFieldItem*, iTextFieldItem)->AddCommandL(aArray[i]); |
|
260 } |
|
261 } |