1 /* |
|
2 * Copyright (c) 2004 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "AknReadingConverter.h" |
|
21 #include "AknJapaneseReading.h" |
|
22 #include "eikedwin.h" |
|
23 // LOCAL CONSTANTS AND MACROS |
|
24 |
|
25 // MODULE DATA STRUCTURES |
|
26 |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 inline CReadingConverter::CReadingConverter(CEikEdwin* aMainEditor, |
|
31 CEikEdwin* aReadingEditor) : |
|
32 iMainEditor(aMainEditor), |
|
33 iReadingEditor(aReadingEditor) |
|
34 { |
|
35 } |
|
36 |
|
37 inline void CReadingConverter::ConstructL() |
|
38 { |
|
39 CCoeEnv::Static()->AddFepObserverL(*this); |
|
40 } |
|
41 |
|
42 EXPORT_C CReadingConverter* CReadingConverter::NewL(CEikEdwin& aMainEditor, |
|
43 CEikEdwin& aReadingEditor) |
|
44 { |
|
45 CReadingConverter* self = |
|
46 new (ELeave) CReadingConverter( &aMainEditor, &aReadingEditor ); |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL(); |
|
49 CleanupStack::Pop(self); |
|
50 return self; |
|
51 } |
|
52 |
|
53 EXPORT_C CReadingConverter* CReadingConverter::NewL() |
|
54 { |
|
55 CReadingConverter* self = |
|
56 new (ELeave) CReadingConverter( NULL, NULL ); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 CleanupStack::Pop(self); |
|
60 return self; |
|
61 } |
|
62 |
|
63 CReadingConverter::~CReadingConverter() |
|
64 { |
|
65 delete iPreviousMainText; |
|
66 CCoeEnv::Static()->RemoveFepObserver(*this); |
|
67 } |
|
68 |
|
69 EXPORT_C void CReadingConverter::HandleCompletionOfTransactionL() |
|
70 { |
|
71 if (iMainEditor && iReadingEditor) |
|
72 { |
|
73 if (iMainEditor->IsFocused()) |
|
74 { |
|
75 TPtrC ptr = CAknJapaneseReading::ReadingTextL(); |
|
76 TInt newTextLength = ptr.Length(); |
|
77 if (newTextLength > 0) |
|
78 { |
|
79 TBool appendReading = ETrue; |
|
80 if (iPreviousMainText) |
|
81 { |
|
82 HBufC* currentMainText = iMainEditor->GetTextInHBufL(); |
|
83 if (currentMainText) |
|
84 { |
|
85 CleanupStack::PushL(currentMainText); |
|
86 if (currentMainText->Compare(*iPreviousMainText) == 0) |
|
87 { |
|
88 // If there is no differences between previous main test |
|
89 // and current its, there is nothing to append to Reading |
|
90 // field. |
|
91 appendReading = EFalse; |
|
92 } |
|
93 CleanupStack::PopAndDestroy(currentMainText); // currentMainText |
|
94 } |
|
95 else |
|
96 { |
|
97 // No buffer on Main editor in case of T9 insert word. |
|
98 appendReading = EFalse; |
|
99 } |
|
100 } |
|
101 |
|
102 if (appendReading) |
|
103 { |
|
104 TInt maxLength = iReadingEditor->MaxLength(); |
|
105 TInt oldTextLength = iReadingEditor->TextLength(); |
|
106 if ((maxLength > 0) && (maxLength < oldTextLength + newTextLength)) |
|
107 { |
|
108 newTextLength = maxLength - oldTextLength; |
|
109 } |
|
110 HBufC* text = HBufC::NewLC(oldTextLength + newTextLength); |
|
111 TPtr textPtr = text->Des(); |
|
112 iReadingEditor->GetText(textPtr); |
|
113 textPtr.Append(ptr.Ptr(), newTextLength); |
|
114 iReadingEditor->SetTextL(text); |
|
115 CleanupStack::PopAndDestroy(text); |
|
116 iReadingEditor->DrawNow(); |
|
117 // send EEventStateChanged event to observer |
|
118 iReadingEditor->UpdateAllFieldsL(); |
|
119 |
|
120 // Save current main editor text |
|
121 delete iPreviousMainText; |
|
122 iPreviousMainText = NULL; |
|
123 iPreviousMainText = HBufC::NewL(iMainEditor->TextLength()); |
|
124 TPtr prev = iPreviousMainText->Des(); |
|
125 iMainEditor->GetText(prev); |
|
126 } |
|
127 } |
|
128 else |
|
129 { |
|
130 if (iMainEditor->TextLength() == 0) |
|
131 { |
|
132 iReadingEditor->SetTextL(&KNullDesC); |
|
133 iReadingEditor->DrawNow(); |
|
134 // send EEventStateChanged event to observer |
|
135 iReadingEditor->UpdateAllFieldsL(); |
|
136 delete iPreviousMainText; |
|
137 iPreviousMainText = NULL; |
|
138 } |
|
139 } |
|
140 } |
|
141 } |
|
142 } |
|
143 |
|
144 EXPORT_C void CReadingConverter::SetMainEditor(CEikEdwin& aMainEditor) |
|
145 { |
|
146 iMainEditor = &aMainEditor; |
|
147 } |
|
148 |
|
149 EXPORT_C CEikEdwin& CReadingConverter::MainEditor() const |
|
150 { |
|
151 return *iMainEditor; |
|
152 } |
|
153 |
|
154 EXPORT_C void CReadingConverter::SetReadingEditor(CEikEdwin& aReadingEditor) |
|
155 { |
|
156 iReadingEditor = &aReadingEditor; |
|
157 } |
|
158 |
|
159 EXPORT_C CEikEdwin& CReadingConverter::ReadingEditor() const |
|
160 { |
|
161 return *iReadingEditor; |
|
162 } |
|
163 |
|