|
1 /* |
|
2 * Copyright (c) 2005,2006 Choe Hwanjin |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "OssHangulInputContext.h" |
|
19 #include "hangul.h" |
|
20 #include "OssKeyboard.h" |
|
21 #include "OssCombination.h" |
|
22 |
|
23 _LIT8(KHangulInputContextEventTranslate,"translate"); |
|
24 _LIT8(KHangulInputContextEventTransition,"transition"); |
|
25 |
|
26 /* |
|
27 LOCAL_C HBufC8* AllocStdBufLC(const TDesC8& aStr) |
|
28 { |
|
29 TInt len=aStr.Length()+1; |
|
30 HBufC8* buf=HBufC8::NewLC(len); |
|
31 TPtr8 ptr(buf->Des()); |
|
32 ptr.FillZ(len); |
|
33 ptr.Copy(aStr); |
|
34 return buf; |
|
35 }*/ |
|
36 |
|
37 |
|
38 LOCAL_C HBufC8* AllocStdBufL(const TDesC8& aStr) |
|
39 { |
|
40 TInt len=aStr.Length()+1; |
|
41 HBufC8* buf=HBufC8::NewL(len); |
|
42 TPtr8 ptr(buf->Des()); |
|
43 ptr.FillZ(len); |
|
44 ptr.Copy(aStr); |
|
45 return buf; |
|
46 } |
|
47 |
|
48 class TLocalStdBuf |
|
49 { |
|
50 public: |
|
51 |
|
52 TLocalStdBuf(const TDesC8& aStr) |
|
53 { |
|
54 TInt len=aStr.Length()+1; |
|
55 iBuf=HBufC8::New(len); |
|
56 if (iBuf!=NULL) |
|
57 { |
|
58 TPtr8 ptr(iBuf->Des()); |
|
59 ptr.FillZ(len); |
|
60 ptr.Copy(aStr); |
|
61 } |
|
62 } |
|
63 |
|
64 ~TLocalStdBuf() |
|
65 { |
|
66 delete iBuf; |
|
67 } |
|
68 |
|
69 const char* operator() () |
|
70 { |
|
71 return (const char*) iBuf->Ptr(); |
|
72 } |
|
73 |
|
74 private: |
|
75 |
|
76 HBufC8* iBuf; |
|
77 }; |
|
78 |
|
79 |
|
80 LOCAL_C TBool CBTranslate(HangulInputContext* ,int aAscII, ucschar* aStr, void* aSelf) |
|
81 { |
|
82 COssHangulInputContext* context=(COssHangulInputContext*)aSelf; |
|
83 return context->OnTranslate(aAscII,TPtrC(aStr)); |
|
84 } |
|
85 |
|
86 LOCAL_C TBool CBTransition(HangulInputContext* ,ucschar aChar, const ucschar* preedit, void* aSelf) |
|
87 { |
|
88 COssHangulInputContext* context=(COssHangulInputContext*)aSelf; |
|
89 return context->OnTransition(aChar,TPtrC(preedit)); |
|
90 } |
|
91 |
|
92 EXPORT_C COssHangulInputContext* COssHangulInputContext::NewLC( |
|
93 const TDesC8& aKeyboardType) |
|
94 { |
|
95 COssHangulInputContext* self = |
|
96 new (ELeave) COssHangulInputContext(); |
|
97 CleanupStack::PushL(self); |
|
98 self->ConstructL(aKeyboardType); |
|
99 return self; |
|
100 } |
|
101 |
|
102 EXPORT_C COssHangulInputContext* COssHangulInputContext::NewL( |
|
103 const TDesC8& aKeyboardType) |
|
104 { |
|
105 COssHangulInputContext* self = |
|
106 COssHangulInputContext::NewLC(aKeyboardType); |
|
107 CleanupStack::Pop(); // self; |
|
108 return self; |
|
109 } |
|
110 |
|
111 |
|
112 COssHangulInputContext::COssHangulInputContext() |
|
113 { |
|
114 } |
|
115 |
|
116 void COssHangulInputContext::ConstructL(const TDesC8& aKeyboardType) |
|
117 { |
|
118 // Null termination string for standard library |
|
119 //iKeyboardType=AllocStdBufLC(aKeyboardType); |
|
120 iKeyboardType=AllocStdBufL(aKeyboardType); |
|
121 iHic=hangul_ic_new((const char*)iKeyboardType->Ptr()); |
|
122 //CleanupStack::Pop(iKeyboardType); |
|
123 } |
|
124 |
|
125 EXPORT_C COssHangulInputContext::~COssHangulInputContext() |
|
126 { |
|
127 hangul_ic_delete(iHic); |
|
128 delete iKeyboardType; |
|
129 } |
|
130 |
|
131 EXPORT_C TBool COssHangulInputContext::Process(const TChar& aAscII) |
|
132 { |
|
133 return hangul_ic_process(iHic,aAscII); |
|
134 } |
|
135 |
|
136 EXPORT_C void COssHangulInputContext::Reset() |
|
137 { |
|
138 hangul_ic_reset(iHic); |
|
139 } |
|
140 |
|
141 EXPORT_C TBool COssHangulInputContext::BackSpace() |
|
142 { |
|
143 return hangul_ic_backspace(iHic); |
|
144 } |
|
145 |
|
146 EXPORT_C TBool COssHangulInputContext::IsEmpty() |
|
147 { |
|
148 return hangul_ic_is_empty(iHic); |
|
149 } |
|
150 |
|
151 EXPORT_C TBool COssHangulInputContext::HasChoseong() |
|
152 { |
|
153 return hangul_ic_has_choseong(iHic); |
|
154 } |
|
155 |
|
156 EXPORT_C TBool COssHangulInputContext::HasJungseong() |
|
157 { |
|
158 return hangul_ic_has_jungseong(iHic); |
|
159 } |
|
160 |
|
161 EXPORT_C TBool COssHangulInputContext::HasJongseong() |
|
162 { |
|
163 return hangul_ic_has_jongseong(iHic); |
|
164 } |
|
165 |
|
166 EXPORT_C void COssHangulInputContext::SetOutputMode(const TInt& aMode) |
|
167 { |
|
168 hangul_ic_set_output_mode(iHic,aMode); |
|
169 } |
|
170 |
|
171 EXPORT_C void COssHangulInputContext::SetKeyboard(const COssKeyboard& aOssKeyboard) |
|
172 { |
|
173 hangul_ic_set_keyboard(iHic,aOssKeyboard.iHangulKeyboard); |
|
174 } |
|
175 |
|
176 EXPORT_C void COssHangulInputContext::SelectKeyboard(const TDesC8& aId) |
|
177 { |
|
178 TLocalStdBuf buf(aId); |
|
179 hangul_ic_select_keyboard(iHic,buf()); |
|
180 } |
|
181 |
|
182 EXPORT_C void COssHangulInputContext::SetCombinationL(COssCombination& aOssCombination) |
|
183 { |
|
184 aOssCombination.PopulateListL(); |
|
185 hangul_ic_set_combination(iHic,aOssCombination.iHangulCombination); |
|
186 } |
|
187 |
|
188 EXPORT_C void COssHangulInputContext::AddEventObserver(MOssHangulInputEventObserver* aObserver) |
|
189 { |
|
190 __ASSERT_ALWAYS( |
|
191 iObservers.Find(aObserver)==KErrNotFound, |
|
192 User::Panic(_L("libhangul_symbian"),__LINE__)); |
|
193 |
|
194 hangul_ic_connect_callback( |
|
195 iHic, |
|
196 (const char *)KHangulInputContextEventTranslate().Ptr(), |
|
197 (void*)CBTranslate, |
|
198 this); |
|
199 |
|
200 hangul_ic_connect_callback( |
|
201 iHic, |
|
202 (const char *)KHangulInputContextEventTransition().Ptr(), |
|
203 (void*)CBTransition, |
|
204 this); |
|
205 |
|
206 iObservers.Append(aObserver); |
|
207 } |
|
208 |
|
209 EXPORT_C void COssHangulInputContext::RemoveEventObserver(MOssHangulInputEventObserver* aObserver) |
|
210 { |
|
211 TInt index(iObservers.Find(aObserver)); |
|
212 if (index!=KErrNotFound) |
|
213 { |
|
214 iObservers.Remove(index); |
|
215 } |
|
216 } |
|
217 |
|
218 EXPORT_C TPtrC COssHangulInputContext::GetPreeditString() |
|
219 { |
|
220 TPtrC ret(hangul_ic_get_preedit_string(iHic)); |
|
221 return ret; |
|
222 } |
|
223 |
|
224 EXPORT_C TPtrC COssHangulInputContext::GetCommitString() |
|
225 { |
|
226 TPtrC ret(hangul_ic_get_commit_string(iHic)); |
|
227 return ret; |
|
228 } |
|
229 |
|
230 EXPORT_C TPtrC COssHangulInputContext::Flush() |
|
231 { |
|
232 TPtrC ret(hangul_ic_flush(iHic)); |
|
233 return ret; |
|
234 } |
|
235 |
|
236 TBool COssHangulInputContext::OnTranslate(const TChar& aAscII,const TDesC& aUcsStr) |
|
237 { |
|
238 TBool ret(EFalse); |
|
239 for (TInt i=0;i<iObservers.Count();i++) |
|
240 { |
|
241 if (iObservers[i]->MOhieoOnTranslate(aAscII,aUcsStr)) ret=ETrue; |
|
242 } |
|
243 return ret; |
|
244 } |
|
245 |
|
246 TBool COssHangulInputContext::OnTransition(const TChar& aChar,const TDesC& aPreEdit) |
|
247 { |
|
248 TBool ret(EFalse); |
|
249 for (TInt i=0;i<iObservers.Count();i++) |
|
250 { |
|
251 if (iObservers[i]->MOhieoOnTransition(aChar,aPreEdit)) ret=ETrue; |
|
252 } |
|
253 return ret; |
|
254 } |
|
255 |