|
1 /* |
|
2 * Copyright (c) 2006 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 * Composite view extension. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <Pbk2Commands.rsg> |
|
22 #include <coemain.h> |
|
23 #include <barsread.h> |
|
24 #include <eikmenup.h> |
|
25 #include "CxSPViewManager.h" |
|
26 #include "ForEachUtil.h" |
|
27 #include "MxSPView.h" |
|
28 #include "CxSPCommandInfo.h" |
|
29 #include "ExtensionManager.hrh" |
|
30 |
|
31 // CONSTANTS |
|
32 const TInt KExtensionGranularity = 1; |
|
33 |
|
34 // ==================== MEMBER FUNCTIONS ==================== |
|
35 CxSPViewManager::CxSPViewManager() : |
|
36 iViews(KExtensionGranularity), |
|
37 iNewCommands( EExtensionManagerFirstFreeCommand ) |
|
38 { |
|
39 } |
|
40 |
|
41 CxSPViewManager::~CxSPViewManager() |
|
42 { |
|
43 const TInt count = iViews.Count(); |
|
44 for (TInt i=0; i<count; ++i) |
|
45 { |
|
46 Release( iViews[i] ); |
|
47 } |
|
48 iViews.Reset(); |
|
49 iCommandIdMap.ResetAndDestroy(); |
|
50 iCommandIdMap.Close(); |
|
51 } |
|
52 |
|
53 CxSPViewManager* CxSPViewManager::NewL() |
|
54 { |
|
55 CxSPViewManager* self = new (ELeave) CxSPViewManager; |
|
56 return self; |
|
57 } |
|
58 |
|
59 void CxSPViewManager::AppendL( MxSPView* aView, TUint32 aId ) |
|
60 { |
|
61 iViews.AppendL( aView ); |
|
62 TInt res = aView->CommandInfoResource(); |
|
63 if( res != KErrNotFound ) |
|
64 { |
|
65 TResourceReader reader; |
|
66 CCoeEnv::Static()->CreateResourceReaderLC( reader, res ); |
|
67 TInt resCount = reader.ReadInt16(); |
|
68 for( TInt j = 0; j < resCount; j++ ) |
|
69 { |
|
70 CxSPCommandInfo* commandInfo = NULL; |
|
71 commandInfo = CxSPCommandInfo::NewLC( reader, |
|
72 aId, |
|
73 iNewCommands ); |
|
74 User::LeaveIfError( iCommandIdMap.Append( commandInfo ) ); |
|
75 CleanupStack::Pop(); // commandInfo |
|
76 } |
|
77 CleanupStack::PopAndDestroy(); // reader |
|
78 aView->RegisterCommandMapper( *this ); |
|
79 } |
|
80 } |
|
81 |
|
82 void CxSPViewManager::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane ) |
|
83 { |
|
84 if( aResourceId == R_PHONEBOOK2_NAMESLIST_MAIN_MENU ) |
|
85 { |
|
86 ForEachL(iViews, |
|
87 VoidMemberFunction(&MxSPView::DynInitNamesListMainMenuPaneL), |
|
88 aResourceId, |
|
89 aMenuPane); |
|
90 } |
|
91 |
|
92 ForEachL(iViews, |
|
93 VoidMemberFunction(&MxSPView::DynInitMenuPaneL), |
|
94 aResourceId, |
|
95 aMenuPane); |
|
96 } |
|
97 |
|
98 |
|
99 TBool CxSPViewManager::HandleCommandL(TInt aCommandId, MPbk2ContactUiControl* aUiControl) |
|
100 { |
|
101 typedef TBool (MxSPView::* HandleCommandPtr) |
|
102 (TInt,MPbk2ContactUiControl*); |
|
103 HandleCommandPtr handleFunc = &MxSPView::HandleCommandL; |
|
104 return TryEachL(iViews, |
|
105 MemberFunction(handleFunc), |
|
106 aCommandId, |
|
107 aUiControl); |
|
108 } |
|
109 |
|
110 TInt CxSPViewManager::GetOldCommand( TUint32 aId, TInt aNewCommand, |
|
111 TInt& aOldCommand ) const |
|
112 { |
|
113 TInt mapCount = iCommandIdMap.Count(); |
|
114 TInt err( KErrNotFound ); |
|
115 for( TInt i = 0; i < mapCount && err; i++ ) |
|
116 { |
|
117 CxSPCommandInfo* info = iCommandIdMap[i]; |
|
118 if( info->Id() == aId && info->NewCommandId() == aNewCommand ) |
|
119 { |
|
120 aOldCommand = info->OldCommandId(); |
|
121 err = KErrNone; |
|
122 } |
|
123 } |
|
124 return err; |
|
125 } |
|
126 |
|
127 TInt CxSPViewManager::GetNewCommand( TUint32 aId, TInt aOldCommand, |
|
128 TInt& aNewCommand ) const |
|
129 { |
|
130 TInt mapCount = iCommandIdMap.Count(); |
|
131 TInt err( KErrNotFound ); |
|
132 for( TInt i = 0; i < mapCount && err; i++ ) |
|
133 { |
|
134 CxSPCommandInfo* info = iCommandIdMap[i]; |
|
135 if( info->Id() == aId && info->OldCommandId() == aOldCommand ) |
|
136 { |
|
137 aNewCommand = info->NewCommandId(); |
|
138 err = KErrNone; |
|
139 } |
|
140 } |
|
141 return err; |
|
142 } |
|
143 |
|
144 |
|
145 // End of File |