|
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: Command context base class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <cvtlogger.h> |
|
20 |
|
21 #include "cvtuicmdcontext.h" |
|
22 #include "cvtuicmdvalidatorbase.h" |
|
23 #include "cvtuicmdvalidationactionbase.h" |
|
24 #include "mvtuicommandmanager.h" |
|
25 |
|
26 // ======== LOCAL FUNCTIONS ======== |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // Compare routine used by InsertInOrder() and FindInOrder() to sort validator |
|
30 // instances by priority. |
|
31 // --------------------------------------------------------------------------- |
|
32 // |
|
33 TInt ValidatorPriCmpFunc( const CVtUiCmdValidatorBase& aV1, |
|
34 const CVtUiCmdValidatorBase& aV2 ) |
|
35 { |
|
36 return aV1.Priority() - aV2.Priority(); |
|
37 } |
|
38 |
|
39 // ======== MEMBER FUNCTIONS ======== |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CVtUiCmdContext::~CVtUiCmdContext |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CVtUiCmdContext::~CVtUiCmdContext() |
|
46 { |
|
47 __VTPRINTENTER( "CmdCtx.~" ) |
|
48 iValidators.Reset(); |
|
49 __VTPRINTEXIT( "CmdCtx.~" ) |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // CVtUiCmdContext::ReferencePriority |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 TInt CVtUiCmdContext::ReferencePriority() const |
|
57 { |
|
58 __VTPRINTENTER( "CmdCtx.ReferencePriority" ) |
|
59 __VTPRINTEXITR( "CmdCtx.ReferencePriority %d", iReferencePriority ) |
|
60 return iReferencePriority; |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // CVtUiCmdContext::ContextType |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 TVtUiCmdContextType CVtUiCmdContext::ContextType() const |
|
68 { |
|
69 __VTPRINTENTER( "CmdCtx.ContextType" ) |
|
70 __VTPRINTEXITR( "CmdCtx.ContextType %d", iContextType ) |
|
71 return iContextType; |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 // CVtUiCmdContext::AddValidator |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 TInt CVtUiCmdContext::AddValidator( CVtUiCmdValidatorBase& aValidator ) |
|
79 { |
|
80 __VTPRINTENTER( "CmdCtx.AddValidator" ) |
|
81 TInt result( KErrNone ); |
|
82 if ( !aValidator.ValidatesContext( iContextType ) ) |
|
83 { |
|
84 result = KErrNotSupported; |
|
85 } |
|
86 else |
|
87 { |
|
88 result = iValidators.InsertInOrderAllowRepeats( &aValidator, |
|
89 TLinearOrder< CVtUiCmdValidatorBase >( ::ValidatorPriCmpFunc ) ); |
|
90 } |
|
91 __VTPRINTEXITR( "CmdCtx.AddValidator %d", result ) |
|
92 return result; |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // CVtUiCmdContext::RemoveValidator |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 void CVtUiCmdContext::RemoveValidator( const CVtUiCmdValidatorBase& aValidator ) |
|
100 { |
|
101 __VTPRINTENTER( "CmdCtx.RemoveValidator" ) |
|
102 TInt idx( iValidators.FindInOrder( &aValidator, |
|
103 TLinearOrder< CVtUiCmdValidatorBase >( ::ValidatorPriCmpFunc ) ) ); |
|
104 |
|
105 if ( idx != KErrNotFound ) |
|
106 { |
|
107 iValidators.Remove( idx ); |
|
108 } |
|
109 __VTPRINTEXIT( "CmdCtx.RemoveValidator" ) |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CVtUiCmdContext::CVtUiCmdContext |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 CVtUiCmdContext::CVtUiCmdContext( MVtUiCommandManager& aCommandManager, |
|
117 TVtUiCmdContextType aCtxType, TInt aReferencePriority ) |
|
118 : iCommandManager( aCommandManager ), |
|
119 iReferencePriority( aReferencePriority ), iContextType( aCtxType ) |
|
120 { |
|
121 __VTPRINTENTER( "CmdCtx.ctor" ) |
|
122 __VTPRINTEXIT( "CmdCtx.ctor" ) |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // CVtUiCmdContext::ValidateMenuItemsL |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void CVtUiCmdContext::ValidateMenuItemsL( |
|
130 CVtUiCmdValidationActionBase& aAction ) |
|
131 { |
|
132 __VTPRINTENTER( "CmdCtx.ValidateMenuItemsL" ) |
|
133 __VTPRINT2( DEBUG_GEN, " count = %d", iValidators.Count() ) |
|
134 for ( TInt i = iValidators.Count() - 1; i >= 0; i-- ) |
|
135 { |
|
136 iValidators[ i ]->ValidateMenuItemsL( aAction, iReferencePriority ); |
|
137 } |
|
138 __VTPRINTEXIT( "CmdCtx.ValidateMenuItemsL" ) |
|
139 } |
|
140 |
|
141 // --------------------------------------------------------------------------- |
|
142 // CVtUiCmdContext::ValidateSoftkeyItemsL |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 void CVtUiCmdContext::ValidateSoftkeyItemsL( |
|
146 CVtUiCmdValidationActionBase& aAction ) |
|
147 { |
|
148 __VTPRINTENTER( "CmdCtx.ValidateSoftkeyItemsL" ) |
|
149 __VTPRINT2( DEBUG_GEN, " count = %d", iValidators.Count() ) |
|
150 for ( TInt i = iValidators.Count() - 1; i >= 0; i-- ) |
|
151 { |
|
152 iValidators[ i ]->ValidateSoftkeyItemsL( aAction, iReferencePriority ); |
|
153 } |
|
154 __VTPRINTEXIT( "CmdCtx.ValidateSoftkeyItemsL" ) |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // CVtUiCmdContext::ValidateToolbarItemsL |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 void CVtUiCmdContext::ValidateToolbarItemsL( |
|
162 CVtUiCmdValidationActionBase& aAction ) |
|
163 { |
|
164 __VTPRINTENTER( "CmdCtx.ValidateToolbarItemsL" ) |
|
165 __VTPRINT2( DEBUG_GEN, " count = %d", iValidators.Count() ) |
|
166 for ( TInt i = iValidators.Count() - 1; i >= 0; i-- ) |
|
167 { |
|
168 iValidators[ i ]->ValidateToolbarItemsL( aAction, iReferencePriority ); |
|
169 } |
|
170 __VTPRINTEXIT( "CmdCtx.ValidateToolbarItemsL" ) |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // CVtUiCmdContext::CustomValidationL |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 void CVtUiCmdContext::CustomValidationL( |
|
178 CVtUiCmdCustomValidationActionBase& aAction ) |
|
179 { |
|
180 __VTPRINTENTER( "CmdCtx.CustomValidationL" ) |
|
181 __VTPRINT2( DEBUG_GEN, " count = %d", iValidators.Count() ) |
|
182 for ( TInt i = iValidators.Count() - 1; i >= 0; i-- ) |
|
183 { |
|
184 iValidators[ i ]->CustomValidationL( aAction, iReferencePriority ); |
|
185 } |
|
186 __VTPRINTEXIT( "CmdCtx.CustomValidationL" ) |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // CVtUiCmdContext::RegisterCommandContextL |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 void CVtUiCmdContext::RegisterCommandContextL() |
|
194 { |
|
195 __VTPRINTENTER( "CmdCtx.RegisterCommandContextL" ) |
|
196 User::LeaveIfError( iCommandManager.RegisterCommandContext( *this ) ); |
|
197 __VTPRINTEXIT( "CmdCtx.RegisterCommandContextL" ) |
|
198 } |
|
199 |
|
200 // --------------------------------------------------------------------------- |
|
201 // CVtUiCmdContext::UnregisterCommandContext |
|
202 // --------------------------------------------------------------------------- |
|
203 // |
|
204 void CVtUiCmdContext::UnregisterCommandContext() |
|
205 { |
|
206 __VTPRINTENTER( "CmdCtx.UnregisterCommandContext" ) |
|
207 iCommandManager.UnregisterCommandContext( *this ); |
|
208 __VTPRINTEXIT( "CmdCtx.UnregisterCommandContext" ) |
|
209 } |