|
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: IMSSoftkeyControl.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <StringLoader.h> // StringLoader |
|
22 |
|
23 #include "IMSSoftkeyControl.h" |
|
24 #include "ImumPanic.h" |
|
25 #include "ImumUtilsLogging.h" |
|
26 |
|
27 // EXTERNAL DATA STRUCTURES |
|
28 // EXTERNAL FUNCTION PROTOTYPES |
|
29 // CONSTANTS |
|
30 enum TIMCSoftkeyErrors |
|
31 { |
|
32 EIMCLeftSoftkeyFailure = 0, |
|
33 EIMCMiddleSoftkeyFailure, |
|
34 EIMCRightSoftkeyFailure |
|
35 }; |
|
36 |
|
37 // MACROS |
|
38 // LOCAL CONSTANTS AND MACROS |
|
39 // MODULE DATA STRUCTURES |
|
40 // LOCAL FUNCTION PROTOTYPES |
|
41 // FORWARD DECLARATIONS |
|
42 |
|
43 // ============================ MEMBER FUNCTIONS =============================== |
|
44 |
|
45 // ---------------------------------------------------------------------------- |
|
46 // CIMSSoftkeyControl::CIMSSoftkeyControl() |
|
47 // ---------------------------------------------------------------------------- |
|
48 // |
|
49 CIMSSoftkeyControl::CIMSSoftkeyControl( |
|
50 CEikButtonGroupContainer& aSoftkeys ) |
|
51 : |
|
52 iSoftkeys( aSoftkeys ), |
|
53 iFlags( 0 ) |
|
54 { |
|
55 IMUM_CONTEXT( CIMSSoftkeyControl::CIMSSoftkeyControl, 0, KLogUi ); |
|
56 |
|
57 } |
|
58 |
|
59 // ---------------------------------------------------------------------------- |
|
60 // CIMSSoftkeyControl::~CIMSSoftkeyControl() |
|
61 // ---------------------------------------------------------------------------- |
|
62 // |
|
63 CIMSSoftkeyControl::~CIMSSoftkeyControl() |
|
64 { |
|
65 IMUM_CONTEXT( CIMSSoftkeyControl::~CIMSSoftkeyControl, 0, KLogUi ); |
|
66 |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // CIMSSoftkeyControl::ConstructL() |
|
71 // ---------------------------------------------------------------------------- |
|
72 // |
|
73 void CIMSSoftkeyControl::ConstructL() |
|
74 { |
|
75 IMUM_CONTEXT( CIMSSoftkeyControl::ConstructL, 0, KLogUi ); |
|
76 |
|
77 } |
|
78 |
|
79 // ---------------------------------------------------------------------------- |
|
80 // CIMSSoftkeyControl::NewL() |
|
81 // ---------------------------------------------------------------------------- |
|
82 // |
|
83 CIMSSoftkeyControl* CIMSSoftkeyControl::NewL( |
|
84 CEikButtonGroupContainer& aSoftkeys ) |
|
85 { |
|
86 IMUM_STATIC_CONTEXT( CIMSSoftkeyControl::NewL, 0, utils, KLogUi ); |
|
87 |
|
88 CIMSSoftkeyControl* self = NewLC( aSoftkeys ); |
|
89 CleanupStack::Pop( self ); |
|
90 |
|
91 return self; |
|
92 } |
|
93 |
|
94 // ---------------------------------------------------------------------------- |
|
95 // CIMSSoftkeyControl::NewLC() |
|
96 // ---------------------------------------------------------------------------- |
|
97 // |
|
98 CIMSSoftkeyControl* CIMSSoftkeyControl::NewLC( |
|
99 CEikButtonGroupContainer& aSoftkeys ) |
|
100 { |
|
101 IMUM_STATIC_CONTEXT( CIMSSoftkeyControl::NewLC, 0, utils, KLogUi ); |
|
102 |
|
103 CIMSSoftkeyControl* self = new ( ELeave ) CIMSSoftkeyControl( aSoftkeys ); |
|
104 CleanupStack::PushL( self ); |
|
105 self->ConstructL(); |
|
106 |
|
107 return self; |
|
108 } |
|
109 |
|
110 |
|
111 // ---------------------------------------------------------------------------- |
|
112 // CIMSSoftkeyControl::ChangeObserver() |
|
113 // ---------------------------------------------------------------------------- |
|
114 // |
|
115 TInt CIMSSoftkeyControl::ChangeObserver( |
|
116 const TBool aOn, |
|
117 const TISCObservedKeys aSoftkey, |
|
118 MEikCommandObserver& aCommandObserver ) |
|
119 { |
|
120 IMUM_CONTEXT( CIMSSoftkeyControl::ChangeObserver, 0, KLogUi ); |
|
121 |
|
122 TInt error = KErrNone; |
|
123 |
|
124 if ( aOn ) |
|
125 { |
|
126 error = SetObserver( aSoftkey, aCommandObserver ); |
|
127 } |
|
128 else |
|
129 { |
|
130 RemoveObserver( aSoftkey ); |
|
131 } |
|
132 |
|
133 return error; |
|
134 } |
|
135 |
|
136 // ---------------------------------------------------------------------------- |
|
137 // CIMSSoftkeyControl::SetObserver() |
|
138 // ---------------------------------------------------------------------------- |
|
139 // |
|
140 TInt CIMSSoftkeyControl::SetObserver( |
|
141 const TISCObservedKeys aSoftkey, |
|
142 MEikCommandObserver& aCommandObserver ) |
|
143 { |
|
144 IMUM_CONTEXT( CIMSSoftkeyControl::SetObserver, 0, KLogUi ); |
|
145 |
|
146 TRAPD( error, |
|
147 iSoftkeys.UpdateCommandObserverL( aSoftkey, aCommandObserver ) ); |
|
148 iFlags.SetFlag( aSoftkey ); |
|
149 |
|
150 return error; |
|
151 } |
|
152 |
|
153 // ---------------------------------------------------------------------------- |
|
154 // CIMSSoftkeyControl::SetObserver() |
|
155 // ---------------------------------------------------------------------------- |
|
156 // |
|
157 TInt CIMSSoftkeyControl::SetObserver( |
|
158 const TBool aLeftSoftkey, |
|
159 const TBool aRightSoftkey, |
|
160 const TBool aMiddleSoftkey, |
|
161 MEikCommandObserver& aCommandObserver ) |
|
162 { |
|
163 IMUM_CONTEXT( CIMSSoftkeyControl::SetObserver, 0, KLogUi ); |
|
164 |
|
165 // Set observer for the left softkey |
|
166 TInt error = ChangeObserver( |
|
167 aLeftSoftkey, EISCLeftSoftkey, aCommandObserver ); |
|
168 __ASSERT_DEBUG( error == KErrNone, |
|
169 User::Panic( KIMCSoftkeyControllerPanic, EIMCLeftSoftkeyFailure ) ); |
|
170 |
|
171 // Set observer for the right softkey |
|
172 if ( error == KErrNone ) |
|
173 { |
|
174 error = ChangeObserver( |
|
175 aRightSoftkey, EISCRightSoftkey, aCommandObserver ); |
|
176 |
|
177 __ASSERT_DEBUG( error == KErrNone, User::Panic( |
|
178 KIMCSoftkeyControllerPanic, EIMCRightSoftkeyFailure ) ); |
|
179 } |
|
180 |
|
181 // Set observer for the middle softkey |
|
182 if ( error == KErrNone ) |
|
183 { |
|
184 error = ChangeObserver( |
|
185 aMiddleSoftkey, EISCMiddleSoftkey, aCommandObserver ); |
|
186 __ASSERT_DEBUG( error == KErrNone, User::Panic( |
|
187 KIMCSoftkeyControllerPanic, EIMCMiddleSoftkeyFailure ) ); |
|
188 } |
|
189 |
|
190 return error; |
|
191 } |
|
192 |
|
193 // ---------------------------------------------------------------------------- |
|
194 // CIMSSoftkeyControl::RemoveObserver() |
|
195 // ---------------------------------------------------------------------------- |
|
196 // |
|
197 void CIMSSoftkeyControl::RemoveObserver( |
|
198 const TISCObservedKeys aSoftkey ) |
|
199 { |
|
200 IMUM_CONTEXT( CIMSSoftkeyControl::RemoveObserver, 0, KLogUi ); |
|
201 |
|
202 iSoftkeys.RemoveCommandObserver( aSoftkey ); |
|
203 iFlags.ClearFlag( aSoftkey ); |
|
204 } |
|
205 |
|
206 // ---------------------------------------------------------------------------- |
|
207 // CIMSSoftkeyControl::operator()() |
|
208 // ---------------------------------------------------------------------------- |
|
209 // |
|
210 CEikButtonGroupContainer& CIMSSoftkeyControl::operator()() |
|
211 { |
|
212 IMUM_CONTEXT( CIMSSoftkeyControl::operator, 0, KLogUi ); |
|
213 |
|
214 return iSoftkeys; |
|
215 } |
|
216 |
|
217 // ---------------------------------------------------------------------------- |
|
218 // CMuiuDynamicSettingsDialog::DefineCustomSoftkeyL() |
|
219 // ---------------------------------------------------------------------------- |
|
220 // |
|
221 void CIMSSoftkeyControl::DefineCustomSoftkeyL( |
|
222 const TInt aLabelResource, |
|
223 const TISCObservedKeys aSoftkeyPos, |
|
224 const TInt aSoftkeyCmd, |
|
225 MEikCommandObserver* aCommandObserver ) |
|
226 { |
|
227 IMUM_CONTEXT( CIMSSoftkeyControl::DefineCustomSoftkeyL, 0, KLogUi ); |
|
228 |
|
229 // Define buttons 'Options' and 'Start' |
|
230 HBufC* options = StringLoader::LoadL( aLabelResource ); |
|
231 CleanupStack::PushL( options ); |
|
232 DefineCustomSoftkeyL( |
|
233 *options, aSoftkeyPos, aSoftkeyCmd, aCommandObserver ); |
|
234 CleanupStack::PopAndDestroy( options ); |
|
235 options = NULL; |
|
236 } |
|
237 |
|
238 |
|
239 // ---------------------------------------------------------------------------- |
|
240 // CMuiuDynamicSettingsDialog::DefineCustomSoftkeyL() |
|
241 // ---------------------------------------------------------------------------- |
|
242 // |
|
243 void CIMSSoftkeyControl::DefineCustomSoftkeyL( |
|
244 const TDesC& aSoftkeyLabel, |
|
245 const TISCObservedKeys aSoftkeyPos, |
|
246 const TInt aSoftkeyCmd, |
|
247 MEikCommandObserver* aCommandObserver ) |
|
248 { |
|
249 IMUM_CONTEXT( CIMSSoftkeyControl::DefineCustomSoftkeyL, 0, KLogUi ); |
|
250 |
|
251 // Make sure there is matching command for the position |
|
252 if ( iSoftkeys.PositionById( aSoftkeyCmd ) > KErrNotFound ) |
|
253 { |
|
254 // First, remove the observer for the key |
|
255 if ( iFlags.Flag( aSoftkeyPos ) ) |
|
256 { |
|
257 RemoveObserver( aSoftkeyPos ); |
|
258 } |
|
259 |
|
260 // Remove the key information and then add new command |
|
261 iSoftkeys.RemoveCommandFromStack( aSoftkeyPos, aSoftkeyCmd ); |
|
262 iSoftkeys.AddCommandToStackL( aSoftkeyPos, aSoftkeyCmd, aSoftkeyLabel ); |
|
263 |
|
264 if ( aCommandObserver ) |
|
265 { |
|
266 // Set as observer and set the flags |
|
267 SetObserver( aSoftkeyPos, *aCommandObserver ); |
|
268 } |
|
269 } |
|
270 } |
|
271 |
|
272 // ---------------------------------------------------------------------------- |
|
273 // CIMSSoftkeyControl::MSKLabelling() |
|
274 // ---------------------------------------------------------------------------- |
|
275 // |
|
276 TBool CIMSSoftkeyControl::MSKLabelling() |
|
277 { |
|
278 IMUM_CONTEXT( CIMSSoftkeyControl::MSKLabelling, 0, KLogUi ); |
|
279 |
|
280 return iFlags.Flag( EISCAllowMiddleSoftkeyLabelChange ); |
|
281 } |
|
282 |
|
283 // ---------------------------------------------------------------------------- |
|
284 // CIMSSoftkeyControl::SetMSKLabelling() |
|
285 // ---------------------------------------------------------------------------- |
|
286 // |
|
287 void CIMSSoftkeyControl::SetMSKLabelling( const TBool aNewState ) |
|
288 { |
|
289 IMUM_CONTEXT( CIMSSoftkeyControl::SetMSKLabelling, 0, KLogUi ); |
|
290 |
|
291 return iFlags.ChangeFlag( EISCAllowMiddleSoftkeyLabelChange, aNewState ); |
|
292 } |
|
293 |
|
294 // ---------------------------------------------------------------------------- |
|
295 // CIMSSoftkeyControl::UpdateMiddleSoftkeyLabelL() |
|
296 // ---------------------------------------------------------------------------- |
|
297 // |
|
298 void CIMSSoftkeyControl::UpdateMiddleSoftkeyLabelL( |
|
299 const TInt aLabelResource, |
|
300 const TInt aCommandId, |
|
301 MEikCommandObserver* aCommandObserver ) |
|
302 { |
|
303 IMUM_CONTEXT( CIMSSoftkeyControl::UpdateMiddleSoftkeyLabelL, 0, KLogUi ); |
|
304 |
|
305 // If labelling allowed, change the label for the middle soft key |
|
306 if ( MSKLabelling() && iPreviousMskLabelResource != aLabelResource ) |
|
307 { |
|
308 iPreviousMskLabelResource = aLabelResource; |
|
309 DefineCustomSoftkeyL( |
|
310 aLabelResource, |
|
311 EISCMiddleSoftkey, |
|
312 aCommandId, |
|
313 aCommandObserver ); |
|
314 } |
|
315 } |
|
316 |
|
317 // ---------------------------------------------------------------------------- |
|
318 // CIMSSoftkeyControl::SetVisibility() |
|
319 // ---------------------------------------------------------------------------- |
|
320 // |
|
321 void CIMSSoftkeyControl::SetVisibility( |
|
322 const TBool aVisible, |
|
323 MEikCommandObserver* aCommandObserver ) |
|
324 { |
|
325 IMUM_CONTEXT( CIMSSoftkeyControl::SetVisibility, 0, KLogUi ); |
|
326 IMUM_IN(); |
|
327 if ( !aVisible ) |
|
328 { |
|
329 TBufC<1> dummy; |
|
330 TRAP_IGNORE( DefineCustomSoftkeyL( dummy, EISCLeftSoftkey, 0, aCommandObserver ) ); |
|
331 TRAP_IGNORE( DefineCustomSoftkeyL( dummy, EISCRightSoftkey, 0, aCommandObserver ) ); |
|
332 TRAP_IGNORE( DefineCustomSoftkeyL( dummy, EISCMiddleSoftkey, 0, aCommandObserver ) ); |
|
333 } |
|
334 |
|
335 IMUM_OUT(); |
|
336 } |
|
337 |
|
338 // End of File |