|
1 /* |
|
2 * Copyright (c) 2002-2005 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: Utility for selecting smile icon and converting |
|
15 * between smile id and smile string. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef CCASMILEICONUTILITY_H |
|
21 #define CCASMILEICONUTILITY_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include "mcaresourcechangeobserver.h" |
|
26 |
|
27 // FORWARD DECLARATIONS |
|
28 class CGulIcon; |
|
29 class CCASmileString; |
|
30 class CCASmileyInformation; |
|
31 |
|
32 class MCAAppUi; |
|
33 class MCASkinVariant; |
|
34 |
|
35 // CLASS DECLARATION |
|
36 |
|
37 /** |
|
38 * CCASmileIconUtility |
|
39 * |
|
40 * Utility for selecting smile icon and mapping |
|
41 * between smile icons and smile strings. |
|
42 */ |
|
43 class CCASmileIconUtility : public CBase, |
|
44 public MCAResourceChangeObserver |
|
45 { |
|
46 public: // Constructors and destructor |
|
47 |
|
48 /** |
|
49 * Two-phased constructor using default smile icon array. |
|
50 */ |
|
51 static CCASmileIconUtility* NewL( |
|
52 MCASkinVariant& aSkinVariant, |
|
53 MCAAppUi& aAppUi ); |
|
54 |
|
55 /** |
|
56 * Two-phased constructor with custom smile icon array. |
|
57 * @param aResourceId : Resource id of IM_SMILE_ARRAY. |
|
58 */ |
|
59 static CCASmileIconUtility* NewL( |
|
60 MCASkinVariant& aSkinVariant, |
|
61 MCAAppUi& aAppUi, |
|
62 TInt aResourceId ); |
|
63 |
|
64 /** |
|
65 * Destructor. |
|
66 */ |
|
67 virtual ~CCASmileIconUtility(); |
|
68 |
|
69 public: |
|
70 |
|
71 /** |
|
72 * Launch pop-up dialog for selecting smile icon. |
|
73 * @param aSelectedSmileIndex Returns selected smile icon index |
|
74 * @return (TInt) Return dialog value |
|
75 */ |
|
76 TInt LaunchSmileIconDialogL( TInt& aSelectedSmileIndex ); |
|
77 |
|
78 /** |
|
79 * Smile icon count. |
|
80 * @return (TInt) Smile icon count |
|
81 */ |
|
82 TInt SmileIconCount() const; |
|
83 |
|
84 /** |
|
85 * Return needed smile icon pointer from icon array. |
|
86 * @param aSmileIndex Smile icon index |
|
87 */ |
|
88 const CGulIcon* GetSmileIcon( TInt aSmileIndex ) const; |
|
89 |
|
90 /** |
|
91 * Return needed smile string reference from string array. |
|
92 * @param aSmileIndex Smile icon index |
|
93 */ |
|
94 const TDesC& GetSmileString( TInt aSmileIndex ) const; |
|
95 |
|
96 /** |
|
97 * Search smileys from buffer. Replace every found smiley with KPuaCodeSmileyIconPadding |
|
98 * @param aStr String to search smiles from. |
|
99 * @param aFixedStr, Target string where smileys are replaced with KPUaCodeSmileyIconPadding |
|
100 * @param aArray Array reference to icon array indexes in right order |
|
101 */ |
|
102 void SearchSmilesL( const TDesC& aStr, TDes& aFixedStr, |
|
103 RArray<TInt>* aArray ); |
|
104 |
|
105 /** |
|
106 * Search smileys from buffer. |
|
107 * @param aStr String to search smiles from. |
|
108 * @param aSmileyInfoArray Information of found smileys. |
|
109 * @param aFixedStr, Target string where smileys are replaced with KPUaCodeSmileyIconPadding |
|
110 * @param aStartPos, Absolute position of index 0 in source string. Used when position of smiley is calculated. |
|
111 */ |
|
112 void SearchSmilesL( const TDesC& aStr, RPointerArray< CCASmileyInformation >& aSmileyInfoArray, TDes* aFixedStr = NULL, TInt aStartPos = 0 ) const; |
|
113 |
|
114 /** |
|
115 * Compares two TSmileyInformation objects' position field. |
|
116 * @param aFirst Reference to the first TSmileyInformation |
|
117 * @param aSecond Reference to the second TSmileyInformation |
|
118 * @return (TInt) Positive if aFirst > aSecond, negative if opposite, |
|
119 * 0 if aFirst == aSecond |
|
120 */ |
|
121 static TInt Compare( const CCASmileyInformation& aFirst, |
|
122 const CCASmileyInformation& aSecond ); |
|
123 |
|
124 /** |
|
125 * Compares two CCASmileString objects' smiley length. |
|
126 * @param aFirst Reference to the first CCASmileString |
|
127 * @param aSecond Reference to the second CCASmileString |
|
128 * @return (TInt) Positive if aFirst(length) < aSecond(length), |
|
129 * negative if opposite, 0 if aFirst == aSecond |
|
130 */ |
|
131 static TInt CompareSmileyLengthReversed( |
|
132 const CCASmileString& aFirst, |
|
133 const CCASmileString& aSecond ); |
|
134 |
|
135 /** |
|
136 * Resizes all icons. |
|
137 * @param aSize new icon size |
|
138 */ |
|
139 void ResizeIcons( const TSize& aSize ); |
|
140 |
|
141 public: // From MCAResourceChangeObserver |
|
142 |
|
143 /** |
|
144 * Reload all icons on resource change |
|
145 */ |
|
146 void ResourceChangedL(); |
|
147 |
|
148 private: // Constructors and destructor |
|
149 |
|
150 /** |
|
151 * C++ constructor. |
|
152 */ |
|
153 CCASmileIconUtility( MCASkinVariant& aSkinVariant, |
|
154 MCAAppUi& aAppUi ); |
|
155 |
|
156 /** |
|
157 * Second-phased constructor |
|
158 */ |
|
159 void ConstructL( TInt aResourceId ); |
|
160 |
|
161 private: // New methods |
|
162 |
|
163 void ConstructFromResourceL( TInt aResourceId ); |
|
164 |
|
165 void ConstructSmileDialogIconArrayL( TInt aResourceId ); |
|
166 |
|
167 /** |
|
168 * Seek the first smiley which points to a given icon. |
|
169 * This is slow method, and it should only be used to |
|
170 * precalculate the index table. |
|
171 * @param aIconIndex index of icon in iIconArray |
|
172 * @return index of smiley in iStringArray |
|
173 */ |
|
174 TInt GetFirstSmileyIndex( TInt aIconIndex ) const; |
|
175 |
|
176 private: // Data |
|
177 |
|
178 // Own. Smiley icons |
|
179 RPointerArray<CGulIcon> iIconArray; |
|
180 |
|
181 // Own. Smiley strings with ref to icon array |
|
182 RPointerArray<CCASmileString> iStringArray; |
|
183 |
|
184 // Own. Temporary array for searching the smileys. |
|
185 // This should be empty when not searching. |
|
186 RPointerArray<CCASmileyInformation> iSmileArray; |
|
187 |
|
188 // Own. Icon reference to string smileys. |
|
189 // Using a precalculated array makes seeking a lot faster, |
|
190 RArray<TInt> iIconToSmileyPointers; |
|
191 |
|
192 // Cache length, so we don't need the seek this every time. |
|
193 TInt iLongestSmileyLength; |
|
194 |
|
195 // does not own |
|
196 MCASkinVariant& iSkinVariant; |
|
197 MCAAppUi& iAppUi; |
|
198 |
|
199 //Own. Smiley icons for SmileDialog |
|
200 RPointerArray<CGulIcon> iSmileDlgIconArray; |
|
201 }; |
|
202 |
|
203 #endif // CCASMILEICONUTILITY_H |