|
1 /* |
|
2 * Copyright (c) 2002 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: Methods for landmark editor text field. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 // INCLUDE FILES |
|
25 #include <featmgr.h> |
|
26 #include <eikedwin.h> |
|
27 #include <AknUtils.h> |
|
28 #include <eikcapc.h> |
|
29 #include "landmarks.hrh" |
|
30 #include "CLmkEditorTextField.h" |
|
31 #include "MLmkEditorUiBuilder.h" |
|
32 #include "CLmkUiUtils.h" |
|
33 #include "LmkConsts.h" |
|
34 #include "CLmkFields.h" |
|
35 // CONSTANTS |
|
36 /// Unnamed namespace for local definitions |
|
37 namespace { |
|
38 const TInt KNumberOfLines( 8 ); |
|
39 } // namespace |
|
40 |
|
41 // ================= MEMBER FUNCTIONS ======================= |
|
42 |
|
43 // ---------------------------------------------------- |
|
44 // CLmkEditorTextField::CLmkEditorTextField |
|
45 // ---------------------------------------------------- |
|
46 // |
|
47 CLmkEditorTextField::CLmkEditorTextField |
|
48 ( MLmkFieldData& aField, |
|
49 MLmkEditorUiBuilder& aUiBuilder ) : |
|
50 CLmkEditorFieldBase( aField, aUiBuilder ) |
|
51 { |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------- |
|
55 // CLmkEditorTextField::ConstructL |
|
56 // ---------------------------------------------------- |
|
57 // |
|
58 void CLmkEditorTextField::ConstructL() |
|
59 { |
|
60 // Create and insert a line in the dialog |
|
61 iControl = static_cast<CEikEdwin*>( iUiBuilder.CreateLineL( |
|
62 FieldLabel(), LandmarkItemField().UniqueFieldIdentity(), |
|
63 EEikCtEdwin ) ); |
|
64 // ctrl is now owned by the dialog |
|
65 AknEditUtils::ConstructEditingL( iControl, |
|
66 LandmarkItemField().FieldLength(), |
|
67 KNumberOfLines, |
|
68 EAknEditorTextCase | EAknEditorCharactersUpperCase |
|
69 | EAknEditorCharactersLowerCase, EAknEditorAlignLeft, |
|
70 ETrue, ETrue, EFalse ); |
|
71 |
|
72 // Set Edwin properties for numeric editor (Phone number field) |
|
73 if (ETextPhoneNumberFieldEditor == iLmkItemField.EditorType()) |
|
74 { |
|
75 iControl->SetAknEditorNumericKeymap(EAknEditorStandardNumberModeKeymap); |
|
76 iControl->SetAknEditorInputMode(EAknEditorNumericInputMode); |
|
77 iControl->SetAknEditorAllowedInputModes(EAknEditorNumericInputMode); |
|
78 iControl->SetAknEditorSpecialCharacterTable(0); |
|
79 } |
|
80 |
|
81 // Set the editor case for URI editor |
|
82 if ( ETextUriFieldEditor == iLmkItemField.EditorType() ) |
|
83 { |
|
84 iControl->SetAknEditorCase( EAknEditorLowerCase ); |
|
85 iControl->SetAknEditorFlags( EAknEditorFlagLatinInputModesOnly ); |
|
86 } |
|
87 else |
|
88 { |
|
89 iControl->SetAknEditorCase( EAknEditorTextCase ); |
|
90 } |
|
91 |
|
92 // Get text |
|
93 HBufC* textBuf = HBufC::NewLC( LandmarkItemField().TextData().Length() ); |
|
94 TPtr text= textBuf->Des(); |
|
95 text = LandmarkItemField().TextData(); |
|
96 |
|
97 // No Japanese input modes tolerated in Japanese variant, |
|
98 // set the allowed onces manually |
|
99 // Only for postal/zip code field |
|
100 |
|
101 if (LandmarkItemField().FieldType() == EPostCode) |
|
102 { |
|
103 iControl->SetAknEditorInputMode(EAknEditorNumericInputMode); |
|
104 iControl->SetAknEditorAllowedInputModes(EAknEditorAllInputModes); |
|
105 if (FeatureManager::FeatureSupported(KFeatureIdJapanese)) |
|
106 { |
|
107 iControl->SetAknEditorFlags(EAknEditorFlagLatinInputModesOnly); |
|
108 } |
|
109 else |
|
110 { |
|
111 AknTextUtils::DisplayTextLanguageSpecificNumberConversion(text); |
|
112 } |
|
113 } |
|
114 else |
|
115 { |
|
116 AknTextUtils::DisplayTextLanguageSpecificNumberConversion(text); |
|
117 } |
|
118 |
|
119 |
|
120 if(LandmarkItemField().FieldType() == EWebAddress && text.Length() > 0) |
|
121 { |
|
122 //only for web address field |
|
123 TInt position; |
|
124 if((position = IsWebUrlProtocolPreFixedL(text))!= |
|
125 KErrNotFound) |
|
126 { |
|
127 TrimPrefixesFromWebUrlL( text, position +1 ); |
|
128 } |
|
129 } |
|
130 |
|
131 TPtrC ptr (text); |
|
132 SetControlTextL(ptr); |
|
133 |
|
134 // SetTextL method above copied the text to the control, |
|
135 // so it is safe to destroy the buffer |
|
136 CleanupStack::PopAndDestroy( textBuf ); |
|
137 |
|
138 LoadBitmapToFieldL(iUiBuilder); |
|
139 |
|
140 // Place cursor to the end of the line |
|
141 iControl->AddFlagToUserFlags( CEikEdwin::EJustAutoCurEnd ); |
|
142 |
|
143 // CreateTextViewL() is flagged as deprecated but if it is not |
|
144 // called here the ActivateL() below crashes sometimes. |
|
145 iControl->CreateTextViewL(); |
|
146 iCaptionedCtrl = iUiBuilder.LineControl( ControlId() ); |
|
147 iCaptionedCtrl->SetTakesEnterKey( ETrue ); |
|
148 } |
|
149 |
|
150 // ---------------------------------------------------- |
|
151 // CLmkEditorTextField::NewL |
|
152 // ---------------------------------------------------- |
|
153 // |
|
154 CLmkEditorTextField* CLmkEditorTextField::NewL |
|
155 ( MLmkFieldData& aField, |
|
156 MLmkEditorUiBuilder& aUiBuilder ) |
|
157 { |
|
158 CLmkEditorTextField* self = |
|
159 new(ELeave) CLmkEditorTextField( aField, aUiBuilder ); |
|
160 CleanupStack::PushL( self ); |
|
161 self->ConstructL(); |
|
162 CleanupStack::Pop( self ); |
|
163 return self; |
|
164 } |
|
165 |
|
166 // ---------------------------------------------------- |
|
167 // CLmkEditorTextField::~CLmkEditorTextField |
|
168 // ---------------------------------------------------- |
|
169 // |
|
170 CLmkEditorTextField::~CLmkEditorTextField() |
|
171 { |
|
172 delete iText; |
|
173 delete iUrlPrefix; |
|
174 } |
|
175 |
|
176 // ---------------------------------------------------- |
|
177 // CLmkEditorTextField::SaveFieldL |
|
178 // ---------------------------------------------------- |
|
179 // |
|
180 TBool CLmkEditorTextField::SaveFieldL() |
|
181 { |
|
182 TBool result = EFalse; |
|
183 HBufC* text = iControl->GetTextInHBufL(); |
|
184 if ( text ) |
|
185 { |
|
186 if ( LandmarkItemField().FieldType() == EWebAddress ) |
|
187 { |
|
188 TInt totalLength = text->Length(); |
|
189 if (totalLength > 0) |
|
190 { |
|
191 if(CLmkUiUtils::FindIfWebAddrFieldIsEmpty(text->Des())) |
|
192 { |
|
193 //nothing is there after :// e.g http:// |
|
194 // do not save |
|
195 text->Des().Zero(); |
|
196 LandmarkItemField().SetText( text ); |
|
197 text = NULL; |
|
198 result = ETrue; |
|
199 |
|
200 } |
|
201 else |
|
202 { |
|
203 //something is there after :// e.g http://www.ebay.com |
|
204 |
|
205 if( iText && *iText != *text) |
|
206 { |
|
207 // store the text |
|
208 // Prepend the webaddress text with "http://" by default |
|
209 TInt httpProtoPos = text->Find( KProtocol ); |
|
210 if ( httpProtoPos == KErrNotFound) |
|
211 { |
|
212 if(text->Length() <= KMaxUrlFieldLenWithDefaultProtocol) |
|
213 { |
|
214 text = text->ReAllocL( KHttp().Length() + text->Length() ); |
|
215 text->Des().Insert(0, KHttp); |
|
216 } |
|
217 } |
|
218 |
|
219 if( isUrlPrefixed ) |
|
220 { |
|
221 TPtr text1= text->Des(); |
|
222 if(IsWebUrlProtocolPreFixedL(text1)== KErrNotFound) |
|
223 { |
|
224 //insert the pre-fix back to the url, if it was removed. |
|
225 //since for ui , prefixes are not shown, but prefixes are |
|
226 //retained in its original form. |
|
227 text = text->ReAllocL( iUrlPrefix->Length() + text->Length() ); |
|
228 text->Des().Insert(0, iUrlPrefix->Des()); |
|
229 } |
|
230 } |
|
231 LandmarkItemField().SetText( text ); |
|
232 text = NULL; |
|
233 result = ETrue; |
|
234 } |
|
235 }//else |
|
236 }//end of if statement |
|
237 }// not a web address field |
|
238 else |
|
239 { |
|
240 if ( LandmarkItemField().TextData() != *text ) |
|
241 { |
|
242 // store the text |
|
243 LandmarkItemField().SetText( text ); |
|
244 text = NULL; |
|
245 result = ETrue; |
|
246 } |
|
247 } |
|
248 delete text; |
|
249 } |
|
250 else |
|
251 { |
|
252 // Ensure field text is empty |
|
253 if ( LandmarkItemField().TextData().Length() > 0) |
|
254 { |
|
255 text = HBufC::New(0); |
|
256 LandmarkItemField().SetText( text ); |
|
257 result = ETrue; |
|
258 } |
|
259 } |
|
260 |
|
261 return result; |
|
262 } |
|
263 |
|
264 // ---------------------------------------------------- |
|
265 // CLmkEditorTextField::ActivateL |
|
266 // ---------------------------------------------------- |
|
267 // |
|
268 void CLmkEditorTextField::ActivateL() |
|
269 { |
|
270 iCaptionedCtrl->ActivateL(); |
|
271 } |
|
272 |
|
273 |
|
274 // ---------------------------------------------------- |
|
275 // CLmkEditorTextField::Control |
|
276 // ---------------------------------------------------- |
|
277 // |
|
278 CEikEdwin* CLmkEditorTextField::Control() |
|
279 { |
|
280 return iControl; |
|
281 } |
|
282 |
|
283 // ---------------------------------------------------- |
|
284 // CLmkEditorTextField::Control |
|
285 // ---------------------------------------------------- |
|
286 // |
|
287 CEikCaptionedControl* CLmkEditorTextField::CaptionedControl() |
|
288 { |
|
289 return iCaptionedCtrl; |
|
290 } |
|
291 |
|
292 // ---------------------------------------------------- |
|
293 // CLmkEditorTextField::IsWebUrlProtocolPreFixedL() |
|
294 // ---------------------------------------------------- |
|
295 // |
|
296 TInt CLmkEditorTextField::IsWebUrlProtocolPreFixedL( TPtr& aWebUrl ) |
|
297 { |
|
298 TChar ch = '/'; |
|
299 // e.g image/jpeg/http://www.google.com |
|
300 TInt protocolPos = aWebUrl.Find(KProtocol); |
|
301 TInt posPrefix = KErrNotFound; |
|
302 if( protocolPos != KErrNotFound) |
|
303 { |
|
304 //find the left string from ':" character e.g image/jpeg/http |
|
305 TPtrC ptrPrefix = aWebUrl.Left( protocolPos ); |
|
306 //search '/' from right handside. |
|
307 posPrefix = ptrPrefix.LocateReverse(ch); |
|
308 if( posPrefix != KErrNotFound) |
|
309 { |
|
310 /*if( !iUrlPrefix ) |
|
311 {*/ |
|
312 delete iUrlPrefix; |
|
313 iUrlPrefix = NULL; |
|
314 //prefix e.g image/jpeg. |
|
315 iUrlPrefix = HBufC::NewL( posPrefix + 1 ); |
|
316 iUrlPrefix->Des().Copy(ptrPrefix.Left( posPrefix + 1 )); |
|
317 //} |
|
318 isUrlPrefixed = ETrue; |
|
319 } |
|
320 } |
|
321 //returns the position of the prefix. |
|
322 return posPrefix; |
|
323 } |
|
324 |
|
325 // ---------------------------------------------------- |
|
326 // CLmkEditorTextField::TrimPrefixesFromWebUrlL() |
|
327 // ---------------------------------------------------- |
|
328 // |
|
329 void CLmkEditorTextField::TrimPrefixesFromWebUrlL( TPtr& aWebUrl, |
|
330 TInt aTrimPos ) |
|
331 { |
|
332 //deletes the prefix from url |
|
333 //e.g deletes "image/jpeg" from image/jpeg/http://www.google.com |
|
334 aWebUrl.Delete(0,aTrimPos); |
|
335 } |
|
336 // ---------------------------------------------------- |
|
337 // CLmkEditorTextField::SetControlTextL() |
|
338 // ---------------------------------------------------- |
|
339 // |
|
340 void CLmkEditorTextField::SetControlTextL( TPtrC& aText) |
|
341 { |
|
342 TPtrC dispTxt; |
|
343 dispTxt.Set(aText); |
|
344 // Set formatted text to editor control |
|
345 if ( LandmarkItemField().FieldType() == EWebAddress && |
|
346 aText.Length() == 0 && (!iUiBuilder.EditMode())) |
|
347 { |
|
348 //only for web address field |
|
349 // Insert http:// prefix to URL field only in edit mode |
|
350 dispTxt.Set(KHttp()); |
|
351 } |
|
352 else |
|
353 { |
|
354 //if it is editor, remove the enter character, if at all present. |
|
355 if (iUiBuilder.EditMode()) |
|
356 { |
|
357 TPtr des1 = CLmkFields::RemoveEnterCharacter( aText ); |
|
358 dispTxt.Set(des1); |
|
359 } |
|
360 } |
|
361 |
|
362 if( !iText ) |
|
363 { |
|
364 //currently this member is used only for url field. |
|
365 //it can be used for other fields also, later. |
|
366 iText = HBufC::NewL( dispTxt.Length() ); |
|
367 } |
|
368 else if( dispTxt.Length() > iText->Length()) |
|
369 { |
|
370 iText = iText->ReAllocL( dispTxt.Length() ); |
|
371 } |
|
372 iText->Des().Copy( dispTxt); |
|
373 iControl->SetTextL( &dispTxt ); |
|
374 iControl->DrawDeferred(); |
|
375 } |
|
376 // ---------------------------------------------------- |
|
377 // CLmkEditorTextField::SetEditableL() |
|
378 // ---------------------------------------------------- |
|
379 // |
|
380 void CLmkEditorTextField::SetEditableL( TBool aEditable ) |
|
381 { |
|
382 if(iCaptionedCtrl) |
|
383 iCaptionedCtrl->SetEditableL(aEditable); |
|
384 } |
|
385 // End of File |
|
386 |