22 #include <eikbtgpc.h> |
22 #include <eikbtgpc.h> |
23 #include <aknenv.h> |
23 #include <aknenv.h> |
24 #include <avkon.rsg> |
24 #include <avkon.rsg> |
25 #include <avkon.hrh> |
25 #include <avkon.hrh> |
26 #include <eikappui.h> |
26 #include <eikappui.h> |
27 |
27 #include <eikdialg.h> |
28 const TInt ELeftSoftkeyIndex = 0; |
28 const TInt KLeftSoftkeyIndex = 0; |
29 const TInt ERightSoftkeyIndex = 2; |
29 const TInt KRightSoftkeyIndex = 2; |
30 const TInt ENullCommandId = -1; |
30 const TInt KNullCommandId = -1; |
31 |
31 |
|
32 // declare the function IsCbaEmbeddedInDialog |
|
33 TBool IsCbaEmbeddedInDialog( const TInt& aFlags ); |
|
34 |
|
35 /** |
|
36 * Internal extension class for CAknCcpuSupport. |
|
37 * |
|
38 * @since 9.2 |
|
39 * |
|
40 * @internal |
|
41 */ |
|
42 NONSHARABLE_CLASS( CAknCcpuSupportExtension ) : public CBase |
|
43 { |
|
44 public: // Construction and destruction |
|
45 |
|
46 CAknCcpuSupportExtension(); |
|
47 ~CAknCcpuSupportExtension(); |
|
48 |
|
49 public: // Data |
|
50 TBool iIsCbaEmded; |
|
51 // Owned |
|
52 CEikButtonGroupContainer* iCba; |
|
53 // not owned |
|
54 CEikButtonGroupContainer* iDialogCba; |
|
55 }; |
|
56 |
|
57 CAknCcpuSupportExtension::CAknCcpuSupportExtension() |
|
58 { |
|
59 } |
|
60 |
|
61 CAknCcpuSupportExtension::~CAknCcpuSupportExtension() |
|
62 { |
|
63 delete iCba; |
|
64 } |
32 |
65 |
33 // |
66 // |
34 // CAknCcpuSupport |
67 // CAknCcpuSupport |
35 // |
68 // |
36 |
69 |
37 enum TAknCcpuSupportFlags |
70 enum TAknCcpuSupportFlags |
38 { |
71 { |
39 EFocused |
72 EFocused |
40 }; |
73 }; |
41 |
74 |
42 EXPORT_C CAknCcpuSupport::CAknCcpuSupport(MEikCcpuEditor* aEditor) |
75 EXPORT_C CAknCcpuSupport::CAknCcpuSupport( MEikCcpuEditor* aEditor ) |
43 : iEditor(aEditor) |
76 : iEditor( aEditor ) |
44 { |
77 { |
45 } |
78 } |
46 |
79 |
47 EXPORT_C CAknCcpuSupport::~CAknCcpuSupport() |
80 EXPORT_C CAknCcpuSupport::~CAknCcpuSupport() |
48 { |
81 { |
49 if (iMenu) |
82 if ( iMenu ) |
|
83 { |
50 iMenu->RemoveEditMenuObserver(this); |
84 iMenu->RemoveEditMenuObserver(this); |
51 delete iCba; |
85 } |
52 iEikonEnv->EikAppUi()->RemoveFromStack(this); |
86 TRAP_IGNORE( DeleteCBAL() ); |
|
87 iEikonEnv->EikAppUi()->RemoveFromStack( this ); |
|
88 delete iExtention; |
53 } |
89 } |
54 |
90 |
55 EXPORT_C void CAknCcpuSupport::ConstructL() |
91 EXPORT_C void CAknCcpuSupport::ConstructL() |
56 { |
92 { |
57 iEikonEnv->EikAppUi()->AddToStackL(this, ECoeStackPriorityFep-1, ECoeStackFlagRefusesFocus); |
93 iExtention = new ( ELeave ) CAknCcpuSupportExtension; |
|
94 iEikonEnv->EikAppUi()->AddToStackL( this, ECoeStackPriorityFep-1, ECoeStackFlagRefusesFocus ); |
58 HandleFocusChangeL(); |
95 HandleFocusChangeL(); |
59 } |
96 } |
60 |
97 |
61 EXPORT_C void CAknCcpuSupport::HandleSelectionChangeL() |
98 EXPORT_C void CAknCcpuSupport::HandleSelectionChangeL() |
62 { |
99 { |
63 if (iCba) |
100 if ( iExtention->iCba ) |
|
101 { |
64 UpdateCBALabelsL(); |
102 UpdateCBALabelsL(); |
|
103 } |
65 } |
104 } |
66 |
105 |
67 EXPORT_C void CAknCcpuSupport::HandleFocusChangeL() |
106 EXPORT_C void CAknCcpuSupport::HandleFocusChangeL() |
68 { |
107 { |
69 TBool focused = iEditor->CcpuIsFocused(); |
108 TBool focused = iEditor->CcpuIsFocused(); |
70 if (COMPARE_BOOLS(focused, iFlags[EFocused])) |
109 if ( COMPARE_BOOLS( focused, iFlags[EFocused] ) ) |
|
110 { |
71 return; |
111 return; |
72 |
112 } |
73 iFlags.Assign(EFocused, focused); |
113 |
74 |
114 iFlags.Assign( EFocused, focused ); |
75 if (focused) |
115 |
76 { |
116 if ( focused ) |
77 MopGetObject(iMenu); |
117 { |
78 |
118 MopGetObject( iMenu ); |
79 if (iMenu) |
119 if ( iMenu ) |
80 iMenu->SetEditMenuObserver(this); |
120 { |
|
121 iMenu->SetEditMenuObserver( this ); |
|
122 } |
81 } |
123 } |
82 else |
124 else |
83 { |
125 { |
84 if (iMenu) |
126 if ( iMenu ) |
85 { |
127 { |
86 iMenu->RemoveEditMenuObserver(this); |
128 iMenu->RemoveEditMenuObserver( this ); |
87 iMenu = NULL; |
129 iMenu = NULL; |
88 } |
130 } |
89 } |
131 } |
90 |
132 |
91 if (iCba && !focused) |
133 if ( iExtention->iCba && !focused ) |
92 { |
134 { |
93 // something has caused loss of focus while shift is pressed - drop everything. |
135 // something has caused loss of focus while shift is pressed - drop everything. |
94 delete iCba; |
136 DeleteCBAL(); |
95 iCba = NULL; |
137 } |
96 } |
138 } |
97 } |
139 |
98 |
140 EXPORT_C TKeyResponse CAknCcpuSupport::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) |
99 EXPORT_C TKeyResponse CAknCcpuSupport::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
141 { |
100 { |
142 if ( !iFlags[EFocused] ) |
101 if (!iFlags[EFocused]) |
143 { |
102 return EKeyWasNotConsumed; |
144 return EKeyWasNotConsumed; |
103 |
145 } |
104 if (aKeyEvent.iCode == EKeyF21) // FEP generates F21 on long shift press |
146 |
105 { |
147 if ( aKeyEvent.iCode == EKeyF21 ) // FEP generates F21 on long shift press |
106 if (aType == EEventKey) |
148 { |
107 { |
149 if ( aType == EEventKey ) |
108 delete iCba; |
150 { |
109 iCba = NULL; |
151 DeleteCBAL(); |
110 iCba = CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::ECba, CEikButtonGroupContainer::EHorizontal, this, R_AVKON_SOFTKEYS_EMPTY); |
152 CEikAppUi* eikAppUi = (CEikAppUi *)CCoeEnv::Static()->AppUi(); |
111 iCba->SetBoundingRect(iEikonEnv->EikAppUi()->ApplicationRect()); |
153 if( eikAppUi && eikAppUi->IsDisplayingDialog() && eikAppUi->TopFocusedControl() ) |
|
154 { |
|
155 CEikDialog* dlg = eikAppUi->TopFocusedControl()->MopGetObject( dlg ); |
|
156 if ( dlg && IsCbaEmbeddedInDialog( dlg->DialogFlags() ) ) |
|
157 { |
|
158 CEikButtonGroupContainer* currentCba = dlg->MopGetObject( currentCba ); |
|
159 |
|
160 if ( currentCba ) |
|
161 { |
|
162 CEikCba* dlgcba = static_cast<CEikCba*>( currentCba->ButtonGroup() ); |
|
163 TUint flags( 0 ); |
|
164 flags |= CEikButtonGroupContainer::EIsEmbedded | CEikButtonGroupContainer::EAddToStack; |
|
165 iExtention->iCba = CEikButtonGroupContainer::NewL( |
|
166 CEikButtonGroupContainer::ECba, |
|
167 CEikButtonGroupContainer::EHorizontal, |
|
168 this, R_AVKON_SOFTKEYS_EMPTY, flags ); |
|
169 |
|
170 CEikCba* cba = static_cast<CEikCba*>( |
|
171 iExtention->iCba->ButtonGroup() ); |
|
172 |
|
173 if( !iExtention->iIsCbaEmded ) |
|
174 { |
|
175 currentCba->AddCommandToStackL( KLeftSoftkeyIndex, -1, KNullDesC, NULL, NULL ); |
|
176 currentCba->AddCommandToStackL( KRightSoftkeyIndex, -1, KNullDesC, NULL, NULL ); |
|
177 currentCba->ActivateL(); |
|
178 currentCba->DrawNow(); |
|
179 iExtention->iDialogCba = currentCba; |
|
180 iExtention->iIsCbaEmded = ETrue; |
|
181 } |
|
182 |
|
183 cba->SetButtonGroupFlags( ~( EEikCbaFlagTransparent | EEikCbaFlagOutlineFont ) ); |
|
184 TRect dlgRect(dlg->Rect()); |
|
185 TRect cbaRect(currentCba->Rect()); |
|
186 iExtention->iCba->SetRect( currentCba->Rect()); |
|
187 iExtention->iCba->SetPosition( |
|
188 TPoint( dlg->DrawableWindow()->Position().iX, |
|
189 dlg->DrawableWindow()->Position().iY + dlgRect.Height() - cbaRect.Height() ) ); |
|
190 iExtention->iCba->SetBoundingRect( dlg->Rect() ); |
|
191 |
|
192 } |
|
193 } |
|
194 } |
|
195 if( !iExtention->iCba )//if iCba was not create in the above branch but was deleted by DeleteCBA |
|
196 { |
|
197 iExtention->iCba = CEikButtonGroupContainer::NewL( |
|
198 CEikButtonGroupContainer::ECba, |
|
199 CEikButtonGroupContainer::EHorizontal, |
|
200 this, R_AVKON_SOFTKEYS_EMPTY ); |
|
201 iExtention->iCba->SetBoundingRect( iEikonEnv->EikAppUi()->ApplicationRect() ); |
|
202 } |
112 UpdateCBALabelsL(); |
203 UpdateCBALabelsL(); |
113 } |
204 } |
114 return EKeyWasConsumed; |
205 return EKeyWasConsumed; |
115 } |
206 } |
116 else if (aType == EEventKey && |
207 else if ( aType == EEventKey && |
117 aKeyEvent.iCode == EKeyF18 && |
208 aKeyEvent.iCode == EKeyF18 && |
118 (aKeyEvent.iModifiers & EModifierCtrl)) |
209 ( aKeyEvent.iModifiers & EModifierCtrl ) ) |
119 { |
210 { |
120 // FEP requests Ccpu actions with CTRL + F18 |
211 // FEP requests Ccpu actions with CTRL + F18 |
121 // Requested action is encoded in iScanCode. |
212 // Requested action is encoded in iScanCode. |
122 ProcessCommandL(aKeyEvent.iScanCode); |
213 ProcessCommandL( aKeyEvent.iScanCode ); |
123 return EKeyWasConsumed; |
214 return EKeyWasConsumed; |
124 } |
215 } |
125 else if ((aKeyEvent.iScanCode == EStdKeyLeftShift || aKeyEvent.iScanCode == EStdKeyRightShift) && aType == EEventKeyUp) |
216 else if ( ( aKeyEvent.iScanCode == EStdKeyLeftShift || |
126 { |
217 aKeyEvent.iScanCode == EStdKeyRightShift ) && |
127 delete iCba; |
218 aType == EEventKeyUp ) |
128 iCba = NULL; |
219 { |
|
220 DeleteCBAL(); |
129 } |
221 } |
130 |
222 |
131 return EKeyWasNotConsumed; |
223 return EKeyWasNotConsumed; |
132 } |
224 } |
133 |
225 |
134 EXPORT_C void CAknCcpuSupport::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane) |
226 EXPORT_C void CAknCcpuSupport::DynInitMenuPaneL( TInt aResourceId,CEikMenuPane* aMenuPane ) |
135 { |
227 { |
136 if (aResourceId == R_AVKON_EDIT_MODE_MENU || |
228 if ( aResourceId == R_AVKON_EDIT_MODE_MENU || |
137 aResourceId == R_AVKON_EDIT_TEXT_MENU) |
229 aResourceId == R_AVKON_EDIT_TEXT_MENU ) |
138 { |
230 { |
139 aMenuPane->SetItemDimmed(EEikCmdEditCut,!iEditor->CcpuCanCut()); |
231 aMenuPane->SetItemDimmed( EEikCmdEditCut,!iEditor->CcpuCanCut() ); |
140 aMenuPane->SetItemDimmed(EEikCmdEditCopy,!iEditor->CcpuCanCopy()); |
232 aMenuPane->SetItemDimmed( EEikCmdEditCopy,!iEditor->CcpuCanCopy() ); |
141 aMenuPane->SetItemDimmed(EEikCmdEditPaste,!iEditor->CcpuCanPaste()); |
233 aMenuPane->SetItemDimmed( EEikCmdEditPaste,!iEditor->CcpuCanPaste() ); |
142 } |
234 } |
143 } |
235 } |
144 |
236 |
145 EXPORT_C void CAknCcpuSupport::ProcessCommandL(TInt aCommandId) |
237 EXPORT_C void CAknCcpuSupport::ProcessCommandL( TInt aCommandId ) |
146 { |
238 { |
147 switch (aCommandId) |
239 switch ( aCommandId ) |
148 { |
240 { |
149 case EEikCmdEditCut: |
241 case EEikCmdEditCut: |
150 iEditor->CcpuCutL(); |
242 iEditor->CcpuCutL(); |
151 break; |
243 break; |
152 case EEikCmdEditCopy: |
244 case EEikCmdEditCopy: |
165 |
257 |
166 void CAknCcpuSupport::UpdateCBALabelsL() |
258 void CAknCcpuSupport::UpdateCBALabelsL() |
167 { |
259 { |
168 TBool change = EFalse; |
260 TBool change = EFalse; |
169 |
261 |
170 if (iEditor->CcpuCanCopy()) |
262 if ( iEditor->CcpuCanCopy() ) |
171 change = UpdateCBALabelL(ELeftSoftkeyIndex, EEikCmdEditCopy, R_TEXT_SOFTKEY_COPY) || change; |
263 { |
|
264 change = UpdateCBALabelL( KLeftSoftkeyIndex, EEikCmdEditCopy, R_TEXT_SOFTKEY_COPY ) || change; |
|
265 } |
172 else |
266 else |
173 change = UpdateCBALabelL(ELeftSoftkeyIndex, ENullCommandId, R_TEXT_SOFTKEY_EMPTY) || change; |
267 { |
174 |
268 change = UpdateCBALabelL( KLeftSoftkeyIndex, KNullCommandId, R_TEXT_SOFTKEY_EMPTY ) || change; |
175 if (iEditor->CcpuCanPaste()) |
269 } |
176 change = UpdateCBALabelL(ERightSoftkeyIndex, EEikCmdEditPaste, R_TEXT_SOFTKEY_PASTE) || change; |
270 |
|
271 if ( iEditor->CcpuCanPaste() ) |
|
272 { |
|
273 change = UpdateCBALabelL( KRightSoftkeyIndex, EEikCmdEditPaste, R_TEXT_SOFTKEY_PASTE ) || change; |
|
274 } |
177 else |
275 else |
178 change = UpdateCBALabelL(ERightSoftkeyIndex, ENullCommandId, R_TEXT_SOFTKEY_EMPTY) || change; |
276 { |
179 |
277 change = UpdateCBALabelL( KRightSoftkeyIndex, KNullCommandId, R_TEXT_SOFTKEY_EMPTY ) || change; |
180 if (change) |
278 } |
181 iCba->DrawNow(); |
279 |
182 } |
280 if ( change ) |
183 |
281 { |
184 TBool CAknCcpuSupport::UpdateCBALabelL(TInt aPosition, TInt aCommandId, TInt aTextResId) |
282 iExtention->iCba->DrawNow(); |
185 { |
283 } |
186 if (iCba->ButtonGroup()->CommandId(aPosition) != aCommandId) |
284 } |
187 { |
285 |
188 HBufC* buf = iEikonEnv->AllocReadResourceLC(aTextResId); |
286 TBool CAknCcpuSupport::UpdateCBALabelL( TInt aPosition, TInt aCommandId, TInt aTextResId ) |
189 iCba->SetCommandL(aPosition, aCommandId, *buf); |
287 { |
190 CleanupStack::PopAndDestroy(buf); |
288 if ( iExtention->iCba->ButtonGroup()->CommandId(aPosition) != aCommandId ) |
|
289 { |
|
290 HBufC* buf = iEikonEnv->AllocReadResourceLC( aTextResId ); |
|
291 iExtention->iCba->SetCommandL( aPosition, aCommandId, *buf ); |
|
292 CleanupStack::PopAndDestroy( buf ); |
191 return ETrue; |
293 return ETrue; |
192 } |
294 } |
193 return EFalse; |
295 return EFalse; |
194 } |
296 } |
195 |
297 |
196 void CAknCcpuSupport::SetEmphasis(CCoeControl* /*aMenuControl*/,TBool /*aEmphasis*/) |
298 void CAknCcpuSupport::SetEmphasis( CCoeControl* /*aMenuControl*/, TBool /*aEmphasis*/ ) |
197 { |
299 { |
198 } |
300 } |
199 |
301 |
200 EXPORT_C void CAknCcpuSupport::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
302 EXPORT_C void CAknCcpuSupport::HandlePointerEventL( const TPointerEvent& aPointerEvent ) |
201 { |
303 { |
202 CAknControl::HandlePointerEventL(aPointerEvent); |
304 CAknControl::HandlePointerEventL( aPointerEvent ); |
203 } |
305 } |
204 |
306 |
205 EXPORT_C void* CAknCcpuSupport::ExtensionInterface( TUid /*aInterface*/ ) |
307 EXPORT_C void* CAknCcpuSupport::ExtensionInterface( TUid /*aInterface*/ ) |
206 { |
308 { |
207 return NULL; |
309 return NULL; |
208 } |
310 } |
209 |
311 void CAknCcpuSupport::DeleteCBAL() |
210 |
312 { |
|
313 if ( iExtention->iCba ) |
|
314 { |
|
315 delete iExtention->iCba; |
|
316 iExtention->iCba = NULL; |
|
317 } |
|
318 if ( iExtention->iIsCbaEmded ) |
|
319 { |
|
320 CEikAppUi* eikAppUi = (CEikAppUi *)CCoeEnv::Static()->AppUi(); |
|
321 if( eikAppUi && eikAppUi->IsDisplayingDialog() && eikAppUi->TopFocusedControl() ) |
|
322 { |
|
323 CEikDialog* dlg = eikAppUi->TopFocusedControl()->MopGetObject( dlg ); |
|
324 if ( dlg ) |
|
325 { |
|
326 CEikButtonGroupContainer* currentCba = dlg->MopGetObject( currentCba ); |
|
327 CEikCba* dlgcba = static_cast<CEikCba*>( |
|
328 currentCba->ButtonGroup() ); |
|
329 if ( currentCba && iExtention->iDialogCba == currentCba ) |
|
330 { |
|
331 currentCba->RemoveCommandFromStack( KLeftSoftkeyIndex, -1 ); |
|
332 currentCba->RemoveCommandFromStack( KRightSoftkeyIndex, -1 ); |
|
333 currentCba->DrawNow(); |
|
334 currentCba->ActivateL(); |
|
335 iExtention->iDialogCba = NULL; |
|
336 iExtention->iIsCbaEmded = EFalse; |
|
337 } |
|
338 } |
|
339 } |
|
340 } |
|
341 } |
|
342 |
|
343 /** |
|
344 * To detect if CBA is embedded in the diaplog. |
|
345 * @param aFlags it should be CEikDialog::DialogFlags() |
|
346 * @return if an CBA is embedded in the dialog return ETrue |
|
347 * else return EFalse |
|
348 */ |
|
349 TBool IsCbaEmbeddedInDialog( const TInt& aFlags ) |
|
350 { |
|
351 return !( aFlags & EEikDialogFlagFillAppClientRect ) && |
|
352 !( aFlags & EEikDialogFlagFillScreen ) && |
|
353 !( aFlags & EEikDialogFlagVirtualInput ) && |
|
354 !( aFlags & EEikDialogFlagNoEmbeddedSoftkeys ); |
|
355 } |
|
356 |
|
357 |