|
1 /* |
|
2 * Copyright (c) 2002 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 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 |
|
20 // INCLUDE FILES |
|
21 #include "BrowserSelectElementDlg.h" |
|
22 #include "BrowserSelectElementListBox.h" |
|
23 #include "BrowserSelectElementModel.h" |
|
24 #include "BrowserDialogsProviderAsyncExit.h" |
|
25 |
|
26 #include <aknsfld.h> |
|
27 #include <aknkeys.h> |
|
28 #include <eikcapc.h> |
|
29 |
|
30 // CONSTANTS |
|
31 #include "BrowserDialogsProviderConstants.h" |
|
32 |
|
33 // ================= MEMBER FUNCTIONS ========================================= |
|
34 |
|
35 // C++ default constructor can NOT contain any code, that |
|
36 // might leave. |
|
37 // |
|
38 CBrowserSelectElementDlg::CBrowserSelectElementDlg ( |
|
39 const TBrCtlSelectOptionType aBrCtlSelectOptionType, |
|
40 CArrayFix<TBrCtlSelectOptionData>& aOptionsOrg ) : |
|
41 iContentValid( ETrue ), |
|
42 iBrCtlSelectOptionType ( aBrCtlSelectOptionType ), |
|
43 iOptionsOrg( aOptionsOrg ) |
|
44 { |
|
45 } |
|
46 |
|
47 CBrowserSelectElementDlg::~CBrowserSelectElementDlg() |
|
48 { |
|
49 delete iListBox; |
|
50 delete iHistoryList; |
|
51 delete iAsyncExit; |
|
52 } |
|
53 //----------------------------------------------------------------------------- |
|
54 // CBrowserSelectElementDlg::NewL |
|
55 //----------------------------------------------------------------------------- |
|
56 // |
|
57 CBrowserSelectElementDlg* CBrowserSelectElementDlg::NewL( |
|
58 const TDesC& aTitle, |
|
59 const TBrCtlSelectOptionType aBrCtlSelectOptionType, |
|
60 CArrayFix<TBrCtlSelectOptionData>& aOptionsOrg ) |
|
61 { |
|
62 CBrowserSelectElementDlg* self = new ( ELeave ) CBrowserSelectElementDlg( |
|
63 aBrCtlSelectOptionType, |
|
64 aOptionsOrg ); |
|
65 CleanupStack::PushL( self ); |
|
66 |
|
67 self->ConstructL( aTitle ); |
|
68 |
|
69 CleanupStack::Pop(); |
|
70 |
|
71 return self; |
|
72 } |
|
73 |
|
74 //----------------------------------------------------------------------------- |
|
75 // CBrowserSelectElementDlg::ConstructL |
|
76 //----------------------------------------------------------------------------- |
|
77 // |
|
78 void CBrowserSelectElementDlg::ConstructL( const TDesC& aTitle ) |
|
79 { |
|
80 // Create the active object for this object |
|
81 iAsyncExit = CBrowserDialogsProviderAsyncExit::NewL( *this ); |
|
82 |
|
83 // Resource |
|
84 TInt resource = R_AVKON_SOFTKEYS_OK_CANCEL__MARK; |
|
85 if (iBrCtlSelectOptionType == ESelectTypeSingle ) |
|
86 { |
|
87 // It was decided that Radio Buttons add little value and unnecessary |
|
88 // complexity to the code, ESelectTypeSingle is no longer supported. |
|
89 iBrCtlSelectOptionType = ESelectTypeNone; |
|
90 } |
|
91 else if ( iBrCtlSelectOptionType == ESelectTypeOkOnly ) |
|
92 { |
|
93 resource = R_AVKON_SOFTKEYS_OK_EMPTY__OK; |
|
94 } |
|
95 |
|
96 // Construct listbox and popup |
|
97 if ( iBrCtlSelectOptionType != ESelectTypeNone ) |
|
98 { |
|
99 iListBox = |
|
100 new ( ELeave ) CBrowserSelectElementListBox( |
|
101 iBrCtlSelectOptionType, |
|
102 iOptionsOrg ); |
|
103 CAknPopupList::ConstructL( iListBox, resource, |
|
104 AknPopupLayouts::EMenuWindow ); |
|
105 iListBox->ConstructL( *this ); |
|
106 iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue ); |
|
107 iListBox->CreateScrollBarFrameL( ETrue ); |
|
108 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL |
|
109 ( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
110 iListBox->SetObserver( this ); |
|
111 |
|
112 SetTitleL( aTitle ); |
|
113 EnableFind(); |
|
114 STATIC_CAST ( CBrowserSelectElementModel*, |
|
115 iListBox->Model() )->Filter()->SetObserver( this ); |
|
116 } |
|
117 else |
|
118 { |
|
119 CDesCArrayFlat* items = |
|
120 new ( ELeave ) CDesCArrayFlat ( KGranularityMedium ); |
|
121 |
|
122 CleanupStack::PushL(items); |
|
123 for ( TInt i = 0; i<iOptionsOrg.Count(); i++ ) |
|
124 { |
|
125 items->AppendL( iOptionsOrg.At(i).Text() ); |
|
126 } |
|
127 |
|
128 // create listbox |
|
129 iHistoryList = new ( ELeave ) CAknSinglePopupMenuStyleListBox; |
|
130 |
|
131 // create popup |
|
132 CAknPopupList::ConstructL( iHistoryList, |
|
133 R_AVKON_SOFTKEYS_SELECT_CANCEL__SELECT, |
|
134 AknPopupLayouts::EMenuWindow ); |
|
135 |
|
136 |
|
137 |
|
138 iHistoryList->ConstructL( this, EAknListBoxSelectionList ); |
|
139 iHistoryList->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue ); |
|
140 iHistoryList->CreateScrollBarFrameL( ETrue ); |
|
141 iHistoryList->ScrollBarFrame()->SetScrollBarVisibilityL |
|
142 ( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
143 |
|
144 CTextListBoxModel* model = iHistoryList->Model(); |
|
145 TBool hasItems = iOptionsOrg.Count(); |
|
146 if ( hasItems ) |
|
147 { |
|
148 model->SetItemTextArray( items ); |
|
149 model->SetOwnershipType( ELbmOwnsItemArray ); |
|
150 CleanupStack::Pop( items );//ownership is taken by model |
|
151 } |
|
152 else |
|
153 { |
|
154 CleanupStack::PopAndDestroy( items ); |
|
155 } |
|
156 |
|
157 iHistoryList->HandleItemAdditionL(); |
|
158 if ( hasItems ) |
|
159 { |
|
160 iHistoryList->SetCurrentItemIndex( 0 ); |
|
161 } |
|
162 SetTitleL( aTitle ); |
|
163 } |
|
164 } |
|
165 |
|
166 //----------------------------------------------------------------------------- |
|
167 // CBrowserSelectElementDlg::HandleListBoxEventL |
|
168 //----------------------------------------------------------------------------- |
|
169 // |
|
170 void CBrowserSelectElementDlg::HandleListBoxEventL |
|
171 ( CEikListBox* aListBox, TListBoxEvent aEventType ) |
|
172 { |
|
173 TBool penSelect = EFalse; |
|
174 |
|
175 if(AknLayoutUtils::PenEnabled()) |
|
176 { |
|
177 if(aEventType == EEventItemDoubleClicked) |
|
178 { |
|
179 penSelect = ETrue; |
|
180 } |
|
181 } |
|
182 |
|
183 if ( (aEventType == EEventEnterKeyPressed || penSelect ) && |
|
184 ( ( iBrCtlSelectOptionType != ESelectTypeMultiple ) || |
|
185 iOptionsOrg.At( aListBox->CurrentItemIndex() ).HasOnPick() ) |
|
186 ) |
|
187 { |
|
188 if (!iAsyncExit->IsActive()) |
|
189 iAsyncExit->Start(); |
|
190 } |
|
191 } |
|
192 |
|
193 //----------------------------------------------------------------------------- |
|
194 // CBrowserSelectElementDlg::HandleControlEventL |
|
195 //----------------------------------------------------------------------------- |
|
196 // |
|
197 void CBrowserSelectElementDlg::HandleControlEventL |
|
198 ( CCoeControl* aControl, TCoeEvent aEventType ) |
|
199 { |
|
200 if ( ( aControl == ListBox() && |
|
201 aEventType == MCoeControlObserver::EEventRequestCancel ) ) |
|
202 { |
|
203 AttemptExitL( EFalse ); |
|
204 } |
|
205 //Some text has been written to findbox, in filtered selectioncase |
|
206 //highlight selectable item. |
|
207 else if ( aControl == ((CCoeControl*)FindBox()) && |
|
208 aEventType == MCoeControlObserver::EEventStateChanged) |
|
209 { |
|
210 STATIC_CAST ( CBrowserSelectElementListBox*, |
|
211 ListBox() )->HighlightSelectableItem(); |
|
212 } |
|
213 } |
|
214 |
|
215 //----------------------------------------------------------------------------- |
|
216 // CBrowserSelectElementDlg::AttemptExitL |
|
217 //----------------------------------------------------------------------------- |
|
218 // |
|
219 void CBrowserSelectElementDlg::AttemptExitL( TBool aAccept ) |
|
220 { |
|
221 // This block comes from aknPopup.cpp. |
|
222 // See CAknPopupList::RemoveFindFiltering() |
|
223 // It had to be duplicated here because the method was private. |
|
224 if ( FindBox() ) |
|
225 { |
|
226 // this removes filtering from popup list so that listboxes |
|
227 // state is valid for application to read. |
|
228 TInt currentItemIndex = ListBox()->CurrentItemIndex(); |
|
229 TInt realCurrentItemIndex = |
|
230 currentItemIndex >= 0 ? |
|
231 STATIC_CAST( CAknFilteredTextListBoxModel*, |
|
232 ListBox()->Model())->Filter()->FilteredItemIndex(currentItemIndex) |
|
233 : KErrNotFound; |
|
234 |
|
235 FindBox()->SetSearchTextL( KNullDesC ); |
|
236 STATIC_CAST( CAknFilteredTextListBoxModel*, |
|
237 ListBox()->Model() )->Filter()->HandleOfferkeyEventL(); |
|
238 |
|
239 if ( realCurrentItemIndex >= 0 ) |
|
240 { |
|
241 ListBox()->SetCurrentItemIndex(realCurrentItemIndex); |
|
242 } |
|
243 } |
|
244 |
|
245 if( aAccept && iContentValid ) |
|
246 { |
|
247 StoreSelections(); |
|
248 } |
|
249 |
|
250 CAknPopupList::AttemptExitL( aAccept ); |
|
251 } |
|
252 |
|
253 //----------------------------------------------------------------------------- |
|
254 // CBrowserSelectElementDlg::DestroyPopupL() |
|
255 //----------------------------------------------------------------------------- |
|
256 // |
|
257 void CBrowserSelectElementDlg::DestroyPopupL() |
|
258 { |
|
259 iContentValid = ETrue; |
|
260 AttemptExitL( ETrue ); |
|
261 } |
|
262 |
|
263 |
|
264 //----------------------------------------------------------------------------- |
|
265 // CBrowserSelectElementDlg::StoreSelections |
|
266 //----------------------------------------------------------------------------- |
|
267 // |
|
268 void CBrowserSelectElementDlg::StoreSelections() |
|
269 { |
|
270 if( iContentValid ) |
|
271 { |
|
272 // unset selection |
|
273 for ( TInt ii = 0; ii < iOptionsOrg.Count(); ++ii ) |
|
274 { |
|
275 iOptionsOrg.At( ii ).SetIsSelected( EFalse ); |
|
276 } |
|
277 |
|
278 // set user selection |
|
279 if ( iBrCtlSelectOptionType == ESelectTypeMultiple ) |
|
280 { |
|
281 const CArrayFix<TInt>* selection; |
|
282 if ( iBrCtlSelectOptionType == ESelectTypeNone ) |
|
283 { |
|
284 selection = iHistoryList->SelectionIndexes(); |
|
285 } |
|
286 else |
|
287 { |
|
288 selection = iListBox->SelectionIndexes(); |
|
289 } |
|
290 |
|
291 for ( TInt ii=0; ii<selection->Count(); ++ii ) |
|
292 { |
|
293 iOptionsOrg.At( selection->At( ii ) ).SetIsSelected(ETrue); |
|
294 } |
|
295 } |
|
296 else |
|
297 { |
|
298 TInt currIndex; |
|
299 if ( iBrCtlSelectOptionType == ESelectTypeNone ) |
|
300 { |
|
301 currIndex = iHistoryList->CurrentItemIndex(); |
|
302 } |
|
303 else |
|
304 { |
|
305 currIndex = iListBox->CurrentItemIndex(); |
|
306 } |
|
307 if ( currIndex >= 0 ) |
|
308 { |
|
309 iOptionsOrg.At( currIndex ).SetIsSelected( ETrue ); |
|
310 } |
|
311 } |
|
312 } |
|
313 } |
|
314 // End of File |