63
|
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 "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 FILES
|
|
20 |
#include "CPbkSelectFieldDlg.h"
|
|
21 |
#include <avkon.rsg> // AVKON resources
|
|
22 |
#include <aknPopup.h> // CAknPopupList
|
|
23 |
#include <aknlists.h> // CAknSingleGraphicHeadingPopupMenuStyleListBox
|
|
24 |
#include <eikclbd.h> // CColumnListBoxData
|
|
25 |
#include <calslbs.h> // AknTextUtils
|
|
26 |
|
|
27 |
#include <PbkView.rsg> // View DLL resource Ids
|
|
28 |
#include "CPbkFieldListBoxModel.h"
|
|
29 |
#include "MPbkControlKeyObserver.h"
|
|
30 |
#include <CPbkIconArray.h>
|
|
31 |
#include "MPbkClipListBoxText.h"
|
|
32 |
#include "CPbkFieldAnalyzer.h"
|
|
33 |
|
|
34 |
#include <CPbkContactItem.h> // CPbkFieldArray
|
|
35 |
#include <CPbkExtGlobals.h>
|
|
36 |
#include <MPbkExtensionFactory.h>
|
|
37 |
#include <CPbkContactEngine.h>
|
|
38 |
|
|
39 |
// Unnamed namespace for local definitions
|
|
40 |
namespace {
|
|
41 |
|
|
42 |
// MODULE DATA STRUCTURES
|
|
43 |
#ifdef _DEBUG
|
|
44 |
enum TPanicCode
|
|
45 |
{
|
|
46 |
EPanicPostCond_Constructor = 1,
|
|
47 |
EPanicPreCond_ExecuteLD,
|
|
48 |
EPanicPreCond_AttemptExitL,
|
|
49 |
EPanicPreCond_ResetWhenDestroyed
|
|
50 |
};
|
|
51 |
|
|
52 |
void Panic(TPanicCode aReason)
|
|
53 |
{
|
|
54 |
_LIT(KPanicText, "CPbkSelectFieldDlg");
|
|
55 |
User::Panic(KPanicText, aReason);
|
|
56 |
}
|
|
57 |
#endif // _DEBUG
|
|
58 |
|
|
59 |
|
|
60 |
/**
|
|
61 |
* Creates and returns an icon array with phonebook
|
|
62 |
* default and extension icons.
|
|
63 |
*
|
|
64 |
* @return array filled with icons
|
|
65 |
*/
|
|
66 |
CPbkIconArray* CreateListBoxIconArrayL()
|
|
67 |
{
|
|
68 |
// create icon array with default icons
|
|
69 |
CPbkIconArray* iconArray = new (ELeave) CPbkIconArray(2);
|
|
70 |
CleanupStack::PushL(iconArray);
|
|
71 |
iconArray->ConstructFromResourceL(R_PBK_FIELDTYPE_ICONS);
|
|
72 |
|
|
73 |
// get extension factory for setting extension icons
|
|
74 |
CPbkExtGlobals* extGlobal = CPbkExtGlobals::InstanceL();
|
|
75 |
extGlobal->PushL();
|
|
76 |
MPbkExtensionFactory& factory = extGlobal->FactoryL();
|
|
77 |
factory.AddPbkFieldIconsL(NULL, iconArray);
|
|
78 |
CleanupStack::PopAndDestroy(extGlobal);
|
|
79 |
|
|
80 |
CleanupStack::Pop(); // iconArray
|
|
81 |
return iconArray;
|
|
82 |
}
|
|
83 |
|
|
84 |
} // namespace
|
|
85 |
|
|
86 |
|
|
87 |
/**
|
|
88 |
* Specialized CAknPopupList for CPbkSelectFieldDlg.
|
|
89 |
*/
|
|
90 |
NONSHARABLE_CLASS(CPbkSelectFieldDlg::CPopupList) :
|
|
91 |
public CAknPopupList
|
|
92 |
{
|
|
93 |
public: // New functions
|
|
94 |
/**
|
|
95 |
* Like CAknPopupList::NewL.
|
|
96 |
* @see CAknPopupList::NewL
|
|
97 |
*/
|
|
98 |
static CPopupList* NewL(
|
|
99 |
CEikListBox* aListBox,
|
|
100 |
TInt aCbaResource,
|
|
101 |
AknPopupLayouts::TAknPopupLayouts aType =
|
|
102 |
AknPopupLayouts::EMenuWindow);
|
|
103 |
|
|
104 |
/**
|
|
105 |
* Sets the listbox item to focus intially. By default focus is on
|
|
106 |
* the first item.
|
|
107 |
* @param aFocusIndex index of the listbox item to focus initially.
|
|
108 |
*/
|
|
109 |
inline void SetInitialFocus(TInt aFocusIndex);
|
|
110 |
|
|
111 |
/**
|
|
112 |
* Like CAknPopupList::AttemptExitL.
|
|
113 |
* @see CAknPopupList::AttemptExitL
|
|
114 |
*/
|
|
115 |
inline void AttemptExitL(TBool aAccept);
|
|
116 |
|
|
117 |
private: // from CAknPopupList
|
|
118 |
void SetupWindowLayout(AknPopupLayouts::TAknPopupLayouts aType);
|
|
119 |
|
|
120 |
private: // Implementation
|
|
121 |
inline CPopupList();
|
|
122 |
|
|
123 |
private: // Data
|
|
124 |
/// Own: focus index
|
|
125 |
TInt iFocusIndex;
|
|
126 |
};
|
|
127 |
|
|
128 |
/**
|
|
129 |
* Specialized listbox for CPbkSelectFieldDlg.
|
|
130 |
*/
|
|
131 |
NONSHARABLE_CLASS(CPbkSelectFieldDlg::CListBox) :
|
|
132 |
public CAknDoubleGraphicPopupMenuStyleListBox,
|
|
133 |
public MPbkClipListBoxText
|
|
134 |
{
|
|
135 |
public: // New functions
|
|
136 |
/**
|
|
137 |
* Constructor.
|
|
138 |
*/
|
|
139 |
inline CListBox();
|
|
140 |
|
|
141 |
/**
|
|
142 |
* Sets the observer aKeyObserver.
|
|
143 |
*/
|
|
144 |
inline void SetObserver(MPbkControlKeyObserver* aKeyObserver);
|
|
145 |
|
|
146 |
/**
|
|
147 |
* Returns CONE environment.
|
|
148 |
*/
|
|
149 |
inline CCoeEnv* CoeEnv();
|
|
150 |
|
|
151 |
private: // from CCoeControl
|
|
152 |
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
|
|
153 |
|
|
154 |
private: // from MPbkClipListBoxText
|
|
155 |
TBool ClipFromBeginning(TDes& aBuffer, TInt aItemIndex, TInt aSubCellNumber);
|
|
156 |
|
|
157 |
private: // Data
|
|
158 |
/// Ref: observer
|
|
159 |
MPbkControlKeyObserver* iKeyObserver;
|
|
160 |
};
|
|
161 |
|
|
162 |
|
|
163 |
// ================= MEMBER FUNCTIONS =======================
|
|
164 |
|
|
165 |
// CPbkSelectFieldDlg::CPopupList
|
|
166 |
inline CPbkSelectFieldDlg::CPopupList::CPopupList() :
|
|
167 |
iFocusIndex(-1)
|
|
168 |
{
|
|
169 |
// Initializes the focus to -1 which is surely an errornous value
|
|
170 |
}
|
|
171 |
|
|
172 |
CPbkSelectFieldDlg::CPopupList* CPbkSelectFieldDlg::CPopupList::NewL
|
|
173 |
(CEikListBox* aListBox,
|
|
174 |
TInt aCbaResource,
|
|
175 |
AknPopupLayouts::TAknPopupLayouts aType)
|
|
176 |
{
|
|
177 |
CPopupList* self = new(ELeave) CPopupList;
|
|
178 |
CleanupStack::PushL(self);
|
|
179 |
self->ConstructL(aListBox, aCbaResource, aType);
|
|
180 |
CleanupStack::Pop(); // self
|
|
181 |
return self;
|
|
182 |
}
|
|
183 |
|
|
184 |
inline void CPbkSelectFieldDlg::CPopupList::SetInitialFocus(TInt aFocusIndex)
|
|
185 |
{
|
|
186 |
iFocusIndex = aFocusIndex;
|
|
187 |
}
|
|
188 |
|
|
189 |
inline void CPbkSelectFieldDlg::CPopupList::AttemptExitL(TBool aAccept)
|
|
190 |
{
|
|
191 |
CAknPopupList::AttemptExitL(aAccept);
|
|
192 |
}
|
|
193 |
|
|
194 |
void CPbkSelectFieldDlg::CPopupList::SetupWindowLayout
|
|
195 |
(AknPopupLayouts::TAknPopupLayouts aType)
|
|
196 |
{
|
|
197 |
// Call base class
|
|
198 |
CAknPopupList::SetupWindowLayout(aType);
|
|
199 |
// Set initial focus
|
|
200 |
if (iFocusIndex >= 0)
|
|
201 |
{
|
|
202 |
ListBox()->SetCurrentItemIndex(iFocusIndex);
|
|
203 |
}
|
|
204 |
}
|
|
205 |
|
|
206 |
// CPbkSelectFieldDlg::CListBox
|
|
207 |
inline CPbkSelectFieldDlg::CListBox::CListBox()
|
|
208 |
{
|
|
209 |
}
|
|
210 |
|
|
211 |
inline void CPbkSelectFieldDlg::CListBox::SetObserver(MPbkControlKeyObserver* aKeyObserver)
|
|
212 |
{
|
|
213 |
iKeyObserver = aKeyObserver;
|
|
214 |
}
|
|
215 |
|
|
216 |
inline CCoeEnv* CPbkSelectFieldDlg::CListBox::CoeEnv()
|
|
217 |
{
|
|
218 |
return iCoeEnv;
|
|
219 |
}
|
|
220 |
|
|
221 |
TKeyResponse CPbkSelectFieldDlg::CListBox::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
|
|
222 |
{
|
|
223 |
if (iKeyObserver &&
|
|
224 |
iKeyObserver->PbkControlKeyEventL(aKeyEvent,aType) == EKeyWasConsumed)
|
|
225 |
{
|
|
226 |
return EKeyWasConsumed;
|
|
227 |
}
|
|
228 |
return CAknDoubleGraphicPopupMenuStyleListBox::OfferKeyEventL(aKeyEvent, aType);
|
|
229 |
}
|
|
230 |
|
|
231 |
TBool CPbkSelectFieldDlg::CListBox::ClipFromBeginning
|
|
232 |
(TDes& aBuffer, TInt aItemIndex, TInt aSubCellNumber)
|
|
233 |
{
|
|
234 |
return AknTextUtils::ClipToFit
|
|
235 |
(aBuffer,
|
|
236 |
AknTextUtils::EClipFromBeginning,
|
|
237 |
this,
|
|
238 |
aItemIndex,
|
|
239 |
aSubCellNumber);
|
|
240 |
}
|
|
241 |
|
|
242 |
EXPORT_C CPbkSelectFieldDlg::CPbkSelectFieldDlg()
|
|
243 |
{
|
|
244 |
__ASSERT_DEBUG(
|
|
245 |
!iListBox && !iPopupList && !iKeyObserver && !iDestroyedPtr,
|
|
246 |
Panic(EPanicPostCond_Constructor));
|
|
247 |
}
|
|
248 |
|
|
249 |
EXPORT_C TPbkContactItemField* CPbkSelectFieldDlg::ExecuteLD
|
|
250 |
(CPbkFieldArray& aArray,
|
|
251 |
TInt aCbaResourceId,
|
|
252 |
const TDesC& aHeading /*=KNullDesC*/,
|
|
253 |
TInt aFocusIndex /*=-1*/)
|
|
254 |
{
|
|
255 |
__ASSERT_DEBUG(!iListBox && !iPopupList, Panic(EPanicPreCond_ExecuteLD));
|
|
256 |
|
|
257 |
// "D" function semantics
|
|
258 |
CleanupStack::PushL(this);
|
|
259 |
TBool thisDestroyed = EFalse;
|
|
260 |
// Destructor will set thisDestroyed to ETrue if this object is destroyed
|
|
261 |
iDestroyedPtr = &thisDestroyed;
|
|
262 |
|
|
263 |
// Create a list box
|
|
264 |
iListBox = new(ELeave) CListBox;
|
|
265 |
|
|
266 |
// Create a popup list
|
|
267 |
CPopupList* popupList = CPopupList::NewL
|
|
268 |
(iListBox, aCbaResourceId, AknPopupLayouts::EMenuDoubleLargeGraphicWindow);
|
|
269 |
CleanupStack::PushL(popupList);
|
|
270 |
|
|
271 |
// Init list box
|
|
272 |
iListBox->ConstructL(popupList, CEikListBox::ELeftDownInViewRect);
|
|
273 |
iListBox->SetObserver(iKeyObserver);
|
|
274 |
|
|
275 |
// set title of popuplist
|
|
276 |
if(aHeading.Length() > 0)
|
|
277 |
{
|
|
278 |
popupList->SetTitleL(aHeading);
|
|
279 |
}
|
|
280 |
|
|
281 |
CPbkIconArray* iconArray = CreateListBoxIconArrayL();
|
|
282 |
iListBox->ItemDrawer()->ColumnData()->SetIconArray(iconArray);
|
|
283 |
|
|
284 |
HBufC* timeFormat = iListBox->CoeEnv()->AllocReadResourceLC(R_QTN_DATE_USUAL);
|
|
285 |
|
|
286 |
CPbkFieldListBoxModel::TParams params( aArray, *timeFormat, *iconArray);
|
|
287 |
|
|
288 |
CPbkFieldAnalyzer* fieldAnalyzer = NULL;
|
|
289 |
// IF the contact item is set, initialize and add the field analyzer into
|
|
290 |
// the param for list box model.
|
|
291 |
fieldAnalyzer = CPbkFieldAnalyzer::NewL( aArray );
|
|
292 |
params.iFieldAnalyzer = fieldAnalyzer;
|
|
293 |
CleanupStack::PushL( fieldAnalyzer );
|
|
294 |
|
|
295 |
CPbkFieldListBoxModel* listBoxModel = CPbkFieldListBoxModel::NewL(params);
|
|
296 |
|
|
297 |
CleanupStack::PopAndDestroy( fieldAnalyzer ); // fieldAnalyzer
|
|
298 |
params.iFieldAnalyzer = NULL;
|
|
299 |
|
|
300 |
CleanupStack::PopAndDestroy(); // timeFormat
|
|
301 |
listBoxModel->SetClipper(*iListBox);
|
|
302 |
iListBox->Model()->SetItemTextArray(listBoxModel);
|
|
303 |
iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
|
|
304 |
iListBox->Reset();
|
|
305 |
|
|
306 |
if (aFocusIndex >= 0 && aFocusIndex < iListBox->Model()->NumberOfItems())
|
|
307 |
{
|
|
308 |
popupList->SetInitialFocus(aFocusIndex);
|
|
309 |
}
|
|
310 |
|
|
311 |
iListBox->CreateScrollBarFrameL(ETrue);
|
|
312 |
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL
|
|
313 |
(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
|
|
314 |
|
|
315 |
TPbkContactItemField* result = NULL;
|
|
316 |
CleanupStack::Pop(); // listBox
|
|
317 |
iPopupList = popupList;
|
|
318 |
TInt dlgResult = 0;
|
|
319 |
TRAPD(err, dlgResult = iPopupList->ExecuteLD());
|
|
320 |
if (!thisDestroyed)
|
|
321 |
{
|
|
322 |
iPopupList = NULL;
|
|
323 |
}
|
|
324 |
if (err != KErrNone)
|
|
325 |
{
|
|
326 |
User::Leave(err);
|
|
327 |
}
|
|
328 |
|
|
329 |
if (thisDestroyed)
|
|
330 |
{
|
|
331 |
// this object has been destroyed
|
|
332 |
CleanupStack::Pop(); // this
|
|
333 |
}
|
|
334 |
else
|
|
335 |
{
|
|
336 |
if (dlgResult)
|
|
337 |
{
|
|
338 |
TInt index = iListBox->CurrentItemIndex();
|
|
339 |
result = &aArray[index];
|
|
340 |
}
|
|
341 |
CleanupStack::PopAndDestroy(); // this
|
|
342 |
}
|
|
343 |
|
|
344 |
return result;
|
|
345 |
}
|
|
346 |
|
|
347 |
EXPORT_C CPbkSelectFieldDlg::~CPbkSelectFieldDlg()
|
|
348 |
{
|
|
349 |
if (iSelfPtr)
|
|
350 |
{
|
|
351 |
*iSelfPtr = NULL;
|
|
352 |
}
|
|
353 |
if (iDestroyedPtr)
|
|
354 |
{
|
|
355 |
*iDestroyedPtr = ETrue;
|
|
356 |
}
|
|
357 |
if (iPopupList)
|
|
358 |
{
|
|
359 |
iPopupList->CancelPopup();
|
|
360 |
}
|
|
361 |
delete iListBox;
|
|
362 |
}
|
|
363 |
|
|
364 |
EXPORT_C void CPbkSelectFieldDlg::SetObserver(MPbkControlKeyObserver* aKeyObserver)
|
|
365 |
{
|
|
366 |
iKeyObserver = aKeyObserver;
|
|
367 |
}
|
|
368 |
|
|
369 |
EXPORT_C void CPbkSelectFieldDlg::AttemptExitL(TBool aAccept)
|
|
370 |
{
|
|
371 |
__ASSERT_DEBUG(iPopupList, Panic(EPanicPreCond_AttemptExitL));
|
|
372 |
|
|
373 |
iPopupList->AttemptExitL(aAccept);
|
|
374 |
}
|
|
375 |
|
|
376 |
EXPORT_C void CPbkSelectFieldDlg::ResetWhenDestroyed(CPbkSelectFieldDlg** aSelfPtr)
|
|
377 |
{
|
|
378 |
__ASSERT_DEBUG(!aSelfPtr || *aSelfPtr==this,
|
|
379 |
Panic(EPanicPreCond_ResetWhenDestroyed));
|
|
380 |
|
|
381 |
iSelfPtr = aSelfPtr;
|
|
382 |
}
|
|
383 |
// End of File
|