|
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 |
|
19 #include "OssCombination.h" |
|
20 #include "hangul.h" |
|
21 |
|
22 TInt CombinationOrderFunction( |
|
23 const TOssCombinationItem& aFirst, |
|
24 const TOssCombinationItem& aSecond) |
|
25 { |
|
26 TUint keyFirst=aFirst.iFirst<<16|aFirst.iSecond; |
|
27 TUint keySecond=aSecond.iFirst<<16|aSecond.iSecond; |
|
28 return keyFirst-keySecond; |
|
29 } |
|
30 |
|
31 TBool TOssCombinationItem::operator == (const TOssCombinationItem& aCombination) const |
|
32 { |
|
33 return iFirst==aCombination.iFirst && iSecond==aCombination.iSecond; |
|
34 } |
|
35 |
|
36 EXPORT_C COssCombination* COssCombination::NewLC() |
|
37 { |
|
38 COssCombination* self = new (ELeave) COssCombination(); |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(); |
|
41 return self; |
|
42 } |
|
43 |
|
44 EXPORT_C COssCombination* COssCombination::NewL() |
|
45 { |
|
46 COssCombination* self = COssCombination::NewLC(); |
|
47 CleanupStack::Pop(); // self; |
|
48 return self; |
|
49 } |
|
50 |
|
51 COssCombination::COssCombination() |
|
52 : iHangulCombination(NULL) |
|
53 { |
|
54 } |
|
55 |
|
56 void COssCombination::ConstructL() |
|
57 { |
|
58 } |
|
59 |
|
60 EXPORT_C COssCombination::~COssCombination() |
|
61 { |
|
62 iCombinationList.Reset(); |
|
63 iCombinationList.Close(); |
|
64 if (iHangulCombination) |
|
65 hangul_combination_delete(iHangulCombination); |
|
66 } |
|
67 |
|
68 EXPORT_C TInt COssCombination::AddCombinationL( |
|
69 const TOssCombinationItem& aCombination) |
|
70 { |
|
71 TInt ret(KErrAlreadyExists); |
|
72 |
|
73 TInt index=FindCombination(aCombination); |
|
74 TLinearOrder<TOssCombinationItem> orderCombination(CombinationOrderFunction); |
|
75 |
|
76 if (index==KErrNotFound) |
|
77 { |
|
78 //iCombinationList.Append(aCombination); |
|
79 iCombinationList.InsertInOrderL(aCombination,orderCombination); |
|
80 ret=KErrNone; |
|
81 } |
|
82 |
|
83 return ret; |
|
84 } |
|
85 |
|
86 EXPORT_C TInt COssCombination::RemoveCombination( |
|
87 const TOssCombinationItem& aCombination) |
|
88 { |
|
89 TInt ret(KErrNotFound); |
|
90 |
|
91 TInt index=FindCombination(aCombination); |
|
92 if (index!=KErrNotFound) |
|
93 { |
|
94 iCombinationList.Remove(index); |
|
95 ret=KErrNone; |
|
96 } |
|
97 return ret; |
|
98 } |
|
99 |
|
100 EXPORT_C TInt COssCombination::FindCombination( |
|
101 const TOssCombinationItem& aCombination) |
|
102 { |
|
103 TInt ret(KErrNotFound); |
|
104 for (TInt i=0;i<iCombinationList.Count();i++) |
|
105 { |
|
106 if (iCombinationList[i]==aCombination) |
|
107 { |
|
108 ret=i; |
|
109 break; |
|
110 } |
|
111 } |
|
112 return ret; |
|
113 } |
|
114 |
|
115 TBool COssCombination::PopulateListL() |
|
116 { |
|
117 if (iHangulCombination) |
|
118 { |
|
119 hangul_combination_delete(iHangulCombination); |
|
120 iHangulCombination=NULL; |
|
121 } |
|
122 iHangulCombination=hangul_combination_new(); |
|
123 TUint cnt=iCombinationList.Count(); |
|
124 TText* listFirst=new (ELeave) TText[cnt]; |
|
125 TText* listSecond=new (ELeave) TText[cnt]; |
|
126 TText* listResult=new (ELeave) TText[cnt]; |
|
127 |
|
128 for (TInt i=0;i<cnt;i++) |
|
129 { |
|
130 listFirst[i]=iCombinationList[i].iFirst; |
|
131 listSecond[i]=iCombinationList[i].iSecond; |
|
132 listResult[i]=iCombinationList[i].iResult; |
|
133 } |
|
134 |
|
135 TBool ret=hangul_combination_set_data( |
|
136 iHangulCombination, |
|
137 listFirst, |
|
138 listSecond, |
|
139 listResult, |
|
140 cnt); |
|
141 |
|
142 delete[] listFirst; |
|
143 delete[] listSecond; |
|
144 delete[] listResult; |
|
145 return ret; |
|
146 } |