|
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: Implement of touch input mode switch |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <peninputlayoutchoicelist.h> |
|
20 #include <peninputlayout.h> |
|
21 #include <AknIconUtils.h> |
|
22 #include <AknLayoutDef.h> |
|
23 #include <AknsDrawUtils.h> |
|
24 #include <AknUtils.h> |
|
25 #include <aknlayoutscalable_avkon.cdl.h> |
|
26 #include <barsread.h> |
|
27 #include <AknsUtils.h> |
|
28 #include <bautils.h> |
|
29 #include <AknFepGlobalEnums.h> |
|
30 #include <peninputcommonchoicelist.h> |
|
31 |
|
32 |
|
33 #define MIN_WORD_LENGTH 200 //temperarily added. |
|
34 const TInt KExtraMargine = 10; |
|
35 // --------------------------------------------------------------------------- |
|
36 // C++ constructor. |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 EXPORT_C CPeninputCommonChoiceList:: |
|
40 CPeninputCommonChoiceList( CFepUiLayout* aUiLayout, |
|
41 TInt aControlId, |
|
42 TAknsItemID aItemSkinID, |
|
43 TAknsItemID aBackgroundSkinID, |
|
44 ECommonChoiceListStyle aListStyle ) |
|
45 : CFepLayoutChoiceList( aUiLayout, aControlId ) |
|
46 { |
|
47 iItemSkinID = aItemSkinID; |
|
48 iBackgroundSkinID = aBackgroundSkinID; |
|
49 iListStyle = aListStyle; |
|
50 #ifdef RD_TACTILE_FEEDBACK |
|
51 //Advanced Tactile feedback REQ417-47932 |
|
52 if(aUiLayout) |
|
53 { |
|
54 if (aUiLayout->PenInputType() == EPluginInputModeFSQ|| |
|
55 aUiLayout->PenInputType() == EPluginInputModeVkb) |
|
56 { |
|
57 SetTactileFeedbackType(ETouchFeedbackBasicButton); |
|
58 aUiLayout->ChangeFeedbackType(reinterpret_cast<TInt>(this),ETouchFeedbackBasicButton); |
|
59 } |
|
60 else |
|
61 { |
|
62 SetTactileFeedbackType(ETouchFeedbackSensitiveInput); |
|
63 aUiLayout->ChangeFeedbackType(reinterpret_cast<TInt>(this),ETouchFeedbackSensitiveInput); |
|
64 } |
|
65 } |
|
66 #endif //RD_TACTILE_FEEDBACK |
|
67 } |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // Symbian Constructor |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 EXPORT_C CPeninputCommonChoiceList* CPeninputCommonChoiceList:: |
|
74 NewL( CFepUiLayout* aUiLayout, |
|
75 TInt aControlId, |
|
76 TAknsItemID aItemSkinID, |
|
77 TAknsItemID aBackgroundSkinID, |
|
78 ECommonChoiceListStyle aListStyle ) |
|
79 { |
|
80 CPeninputCommonChoiceList *self = new (ELeave) |
|
81 CPeninputCommonChoiceList( aUiLayout, |
|
82 aControlId, |
|
83 aItemSkinID, |
|
84 aBackgroundSkinID, |
|
85 aListStyle ); |
|
86 |
|
87 CleanupStack::PushL(self); |
|
88 self->ConstructL(); |
|
89 CleanupStack::Pop(); |
|
90 |
|
91 return self; |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // Destructor |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 EXPORT_C CPeninputCommonChoiceList::~CPeninputCommonChoiceList() |
|
99 { |
|
100 iItemRects.Close(); |
|
101 } |
|
102 |
|
103 EXPORT_C void CPeninputCommonChoiceList::AddItemRectL( const TRect& aRect ) |
|
104 { |
|
105 iItemRects.AppendL( aRect ); |
|
106 } |
|
107 |
|
108 EXPORT_C void CPeninputCommonChoiceList::RemoveAllItemsRect() |
|
109 { |
|
110 iItemRects.Reset(); |
|
111 } |
|
112 |
|
113 EXPORT_C void CPeninputCommonChoiceList:: |
|
114 SetTextLayout( const TAknTextLineLayout& aTextLayout ) |
|
115 { |
|
116 iTextLayout = aTextLayout; |
|
117 } |
|
118 |
|
119 TInt CPeninputCommonChoiceList::MaxWidthOfListItem() |
|
120 { |
|
121 if( iTextLayout.FontId() == 0 ) |
|
122 return 0; |
|
123 |
|
124 TInt maxLength = 0; |
|
125 const CFont* font = AknLayoutUtils::FontFromId(iTextLayout.FontId(), NULL); |
|
126 ASSERT( font ); |
|
127 |
|
128 for( TInt i = 0; i < ItemsCount(); i++ ) |
|
129 { |
|
130 TInt length = font->TextWidthInPixels( ItemByIndex(i)->iText ); |
|
131 maxLength = length > maxLength ? length : maxLength; |
|
132 } |
|
133 maxLength = maxLength > MIN_WORD_LENGTH ? maxLength : MIN_WORD_LENGTH; |
|
134 return maxLength; |
|
135 } |
|
136 |
|
137 EXPORT_C void CPeninputCommonChoiceList::ReCalcLayout() |
|
138 { |
|
139 if( iItemRects.Count() == 0 ) |
|
140 { |
|
141 return; |
|
142 } |
|
143 |
|
144 if( iListStyle == EAutoFitLength ) |
|
145 { |
|
146 TInt itemLength = MaxWidthOfListItem() + iTextLayout.il + iTextLayout.ir; |
|
147 TInt offsetLength = 0; |
|
148 offsetLength = Rect().Width() - iItemRects[0].Width(); |
|
149 |
|
150 if( itemLength + offsetLength + KExtraMargine > UiLayout()->Rect().Width() ) |
|
151 { |
|
152 itemLength = UiLayout()->Rect().Width() - KExtraMargine - offsetLength; |
|
153 } |
|
154 TRect rect; |
|
155 for( TInt i = 0; i < iItemRects.Count(); i++ ) |
|
156 { |
|
157 rect = iItemRects[i]; |
|
158 offsetLength = itemLength - rect.Width(); |
|
159 rect.SetRect(rect.iTl, TSize( itemLength, rect.Height() ) ); |
|
160 iItemRects[i] = rect; |
|
161 } |
|
162 rect = Rect(); |
|
163 rect.Resize( offsetLength, 0 ); |
|
164 SetRect( rect ); |
|
165 } |
|
166 } |
|
167 |
|
168 EXPORT_C void CPeninputCommonChoiceList::Draw() |
|
169 { |
|
170 if(!AbleToDraw()) |
|
171 return; |
|
172 |
|
173 DrawBackground(); |
|
174 |
|
175 //draw Item |
|
176 for(int ii = 0; ii < ItemsCount(); ++ii) |
|
177 { |
|
178 DrawItem(ii, CurrentFocusedIndex() == ii); |
|
179 } |
|
180 } |
|
181 |
|
182 void CPeninputCommonChoiceList::DrawBackground() |
|
183 { |
|
184 DrawOpaqueMaskBackground( Rect() ); |
|
185 if( iBackgroundSkinID.iMajor != EAknsMajorNone && |
|
186 iBackgroundSkinID.iMinor != EAknsMinorNone ) |
|
187 { |
|
188 TRect rtInnerRect( Rect() ); |
|
189 rtInnerRect.Shrink( 1, 1 ); |
|
190 CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc()); |
|
191 |
|
192 gc->Activate( BitmapDevice() ); |
|
193 gc->SetBrushColor( KRgbWhite ); |
|
194 gc->Clear( Rect() ); |
|
195 AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), |
|
196 *gc, |
|
197 Rect(), |
|
198 rtInnerRect, |
|
199 iBackgroundSkinID, |
|
200 KAknsIIDDefault ); |
|
201 } |
|
202 } |
|
203 |
|
204 void CPeninputCommonChoiceList::DrawItem( TInt aIndex, TBool aIsFocus ) |
|
205 { |
|
206 TRect rtFocusRect(iItemRects[aIndex]); |
|
207 rtFocusRect.Move( Rect().iTl ); |
|
208 |
|
209 if( aIsFocus ) |
|
210 { |
|
211 //draw focus bitmap |
|
212 TRect rtInnerRect( rtFocusRect ); |
|
213 rtInnerRect.Shrink( 7, 7 ); |
|
214 |
|
215 if( iItemSkinID.iMajor != EAknsMajorNone && |
|
216 iItemSkinID.iMinor != EAknsMinorNone) |
|
217 { |
|
218 CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc()); |
|
219 gc->Activate( BitmapDevice() ); |
|
220 AknsDrawUtils::DrawFrame( AknsUtils::SkinInstance(), |
|
221 *gc, |
|
222 rtFocusRect, |
|
223 rtInnerRect, |
|
224 iItemSkinID, |
|
225 KAknsIIDDefault ); |
|
226 } |
|
227 |
|
228 } |
|
229 |
|
230 // draw text |
|
231 TAknLayoutText textLayout; |
|
232 textLayout.LayoutText(rtFocusRect, iTextLayout); |
|
233 TRgb color( KRgbBlack ); // sane default for nonskinned case |
|
234 TAknsQsnTextColorsIndex clrIndex; |
|
235 clrIndex = aIsFocus ? EAknsCIQsnTextColorsCG10 : EAknsCIQsnTextColorsCG20; |
|
236 |
|
237 if ( AknsUtils::AvkonSkinEnabled() ) |
|
238 { |
|
239 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), |
|
240 color, KAknsIIDQsnTextColors, clrIndex ); |
|
241 } |
|
242 |
|
243 textLayout.DrawText(*BitGc(), ItemByIndex(aIndex)->iText, ETrue, color); |
|
244 } |
|
245 |
|
246 EXPORT_C void CPeninputCommonChoiceList::SetListColumnNumWithLafL( TInt aMaxCount) |
|
247 { |
|
248 if( iLastColumnNum == aMaxCount ) |
|
249 return; |
|
250 |
|
251 iLastColumnNum = aMaxCount; |
|
252 RemoveAllItemsRect(); |
|
253 |
|
254 TAknWindowLineLayout appWnd = AknLayoutScalable_Avkon::application_window(0).LayoutLine(); |
|
255 TAknWindowLineLayout mainPane = AknLayoutScalable_Avkon::main_pane(4).LayoutLine(); |
|
256 TAknLayoutRect mainPaneRect; |
|
257 mainPaneRect.LayoutRect(appWnd.Rect(), mainPane); |
|
258 |
|
259 TAknWindowLineLayout menuWnd = AknLayoutScalable_Avkon:: |
|
260 popup_menu_window(13).LayoutLine(); |
|
261 TAknWindowLineLayout choiceWnd = AknLayoutScalable_Avkon:: |
|
262 popup_submenu_window(aMaxCount - 1).LayoutLine(); |
|
263 TAknLayoutRect choiceRect; |
|
264 choiceRect.LayoutRect(mainPaneRect.Rect(), choiceWnd); |
|
265 |
|
266 TRect rectChoiseList( 0, 0 , |
|
267 choiceRect.Rect().Width(), |
|
268 choiceRect.Rect().Height()); |
|
269 // set list window rect |
|
270 SetRect( rectChoiseList ); |
|
271 |
|
272 TAknWindowLineLayout listPopupPane = AknLayoutScalable_Avkon:: |
|
273 listscroll_popup_sub_pane(0).LayoutLine(); |
|
274 TAknLayoutRect listPopupPaneRect; |
|
275 listPopupPaneRect.LayoutRect(rectChoiseList, listPopupPane); |
|
276 TAknWindowLineLayout listSubMenuPane = AknLayoutScalable_Avkon:: |
|
277 list_submenu_pane(1).LayoutLine(); |
|
278 TAknLayoutRect listSubMenuPaneRect; |
|
279 listSubMenuPaneRect.LayoutRect(listPopupPaneRect.Rect(), listSubMenuPane); |
|
280 |
|
281 TAknWindowLineLayout listSinglePane; |
|
282 TAknLayoutRect listSinglePaneRect; |
|
283 |
|
284 // set list item rect |
|
285 for( TInt i = 0; i < aMaxCount; i++ ) |
|
286 { |
|
287 listSinglePane = AknLayoutScalable_Avkon:: |
|
288 list_single_popup_submenu_pane(i, 0, 0).LayoutLine(); |
|
289 listSinglePaneRect.LayoutRect( listSubMenuPaneRect.Rect(), listSinglePane ); |
|
290 iItemRects.AppendL(listSinglePaneRect.Rect()); |
|
291 } |
|
292 |
|
293 // set list text layout |
|
294 SetTextLayout(AknLayoutScalable_Avkon::list_single_popup_submenu_pane_t1(0).LayoutLine()); |
|
295 } |
|
296 |
|
297 EXPORT_C void CPeninputCommonChoiceList::SetListSkinID( TAknsItemID aItemSkinID, |
|
298 TAknsItemID aBackgroundSkinID ) |
|
299 { |
|
300 iItemSkinID = aItemSkinID; |
|
301 iBackgroundSkinID = aBackgroundSkinID; |
|
302 } |
|
303 EXPORT_C TInt CPeninputCommonChoiceList::HitTest(const TPoint& aPoint) |
|
304 { |
|
305 TPoint pPoint(aPoint.iX - Rect().iTl.iX,aPoint.iY - Rect().iTl.iY); |
|
306 TInt arrayCount = iItemRects.Count(); |
|
307 TInt index = arrayCount; |
|
308 for(TInt i = 0; i < arrayCount; i++) |
|
309 { |
|
310 if(iItemRects[i].Contains(pPoint)) |
|
311 { |
|
312 index = i; |
|
313 } |
|
314 } |
|
315 if( index >= arrayCount ) |
|
316 { |
|
317 return EListOutside; |
|
318 } |
|
319 else |
|
320 { |
|
321 return index; |
|
322 } |
|
323 } |
|
324 // End Of File |