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 #include <eikdialg.h> |
27 |
28 const TInt KLeftSoftkeyIndex = 0; |
28 const TInt ELeftSoftkeyIndex = 0; |
29 const TInt KRightSoftkeyIndex = 2; |
29 const TInt ERightSoftkeyIndex = 2; |
30 const TInt KNullCommandId = -1; |
30 const TInt ENullCommandId = -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 } |
|
65 |
32 |
66 // |
33 // |
67 // CAknCcpuSupport |
34 // CAknCcpuSupport |
68 // |
35 // |
69 |
36 |
70 enum TAknCcpuSupportFlags |
37 enum TAknCcpuSupportFlags |
71 { |
38 { |
72 EFocused |
39 EFocused |
73 }; |
40 }; |
74 |
41 |
75 EXPORT_C CAknCcpuSupport::CAknCcpuSupport( MEikCcpuEditor* aEditor ) |
42 EXPORT_C CAknCcpuSupport::CAknCcpuSupport(MEikCcpuEditor* aEditor) |
76 : iEditor( aEditor ) |
43 : iEditor(aEditor) |
77 { |
44 { |
78 } |
45 } |
79 |
46 |
80 EXPORT_C CAknCcpuSupport::~CAknCcpuSupport() |
47 EXPORT_C CAknCcpuSupport::~CAknCcpuSupport() |
81 { |
48 { |
82 if ( iMenu ) |
49 if (iMenu) |
83 { |
|
84 iMenu->RemoveEditMenuObserver(this); |
50 iMenu->RemoveEditMenuObserver(this); |
85 } |
51 delete iCba; |
86 TRAP_IGNORE( DeleteCBAL() ); |
52 iEikonEnv->EikAppUi()->RemoveFromStack(this); |
87 iEikonEnv->EikAppUi()->RemoveFromStack( this ); |
|
88 delete iExtention; |
|
89 } |
53 } |
90 |
54 |
91 EXPORT_C void CAknCcpuSupport::ConstructL() |
55 EXPORT_C void CAknCcpuSupport::ConstructL() |
92 { |
56 { |
93 iExtention = new ( ELeave ) CAknCcpuSupportExtension; |
57 iEikonEnv->EikAppUi()->AddToStackL(this, ECoeStackPriorityFep-1, ECoeStackFlagRefusesFocus); |
94 iEikonEnv->EikAppUi()->AddToStackL( this, ECoeStackPriorityFep-1, ECoeStackFlagRefusesFocus ); |
|
95 HandleFocusChangeL(); |
58 HandleFocusChangeL(); |
96 } |
59 } |
97 |
60 |
98 EXPORT_C void CAknCcpuSupport::HandleSelectionChangeL() |
61 EXPORT_C void CAknCcpuSupport::HandleSelectionChangeL() |
99 { |
62 { |
100 if ( iExtention->iCba ) |
63 if (iCba) |
101 { |
|
102 UpdateCBALabelsL(); |
64 UpdateCBALabelsL(); |
103 } |
|
104 } |
65 } |
105 |
66 |
106 EXPORT_C void CAknCcpuSupport::HandleFocusChangeL() |
67 EXPORT_C void CAknCcpuSupport::HandleFocusChangeL() |
107 { |
68 { |
108 TBool focused = iEditor->CcpuIsFocused(); |
69 TBool focused = iEditor->CcpuIsFocused(); |
109 if ( COMPARE_BOOLS( focused, iFlags[EFocused] ) ) |
70 if (COMPARE_BOOLS(focused, iFlags[EFocused])) |
110 { |
|
111 return; |
71 return; |
112 } |
72 |
113 |
73 iFlags.Assign(EFocused, focused); |
114 iFlags.Assign( EFocused, focused ); |
74 |
115 |
75 if (focused) |
116 if ( focused ) |
76 { |
117 { |
77 MopGetObject(iMenu); |
118 MopGetObject( iMenu ); |
78 |
119 if ( iMenu ) |
79 if (iMenu) |
120 { |
80 iMenu->SetEditMenuObserver(this); |
121 iMenu->SetEditMenuObserver( this ); |
|
122 } |
|
123 } |
81 } |
124 else |
82 else |
125 { |
83 { |
126 if ( iMenu ) |
84 if (iMenu) |
127 { |
85 { |
128 iMenu->RemoveEditMenuObserver( this ); |
86 iMenu->RemoveEditMenuObserver(this); |
129 iMenu = NULL; |
87 iMenu = NULL; |
130 } |
88 } |
131 } |
89 } |
132 |
90 |
133 if ( iExtention->iCba && !focused ) |
91 if (iCba && !focused) |
134 { |
92 { |
135 // something has caused loss of focus while shift is pressed - drop everything. |
93 // something has caused loss of focus while shift is pressed - drop everything. |
136 DeleteCBAL(); |
94 delete iCba; |
137 } |
95 iCba = NULL; |
138 } |
96 } |
139 |
97 } |
140 EXPORT_C TKeyResponse CAknCcpuSupport::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) |
98 |
141 { |
99 EXPORT_C TKeyResponse CAknCcpuSupport::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
142 if ( !iFlags[EFocused] ) |
100 { |
143 { |
101 if (!iFlags[EFocused]) |
144 return EKeyWasNotConsumed; |
102 return EKeyWasNotConsumed; |
145 } |
103 |
146 |
104 if (aKeyEvent.iCode == EKeyF21) // FEP generates F21 on long shift press |
147 if ( aKeyEvent.iCode == EKeyF21 ) // FEP generates F21 on long shift press |
105 { |
148 { |
106 if (aType == EEventKey) |
149 if ( aType == EEventKey ) |
107 { |
150 { |
108 delete iCba; |
151 DeleteCBAL(); |
109 iCba = NULL; |
152 CEikAppUi* eikAppUi = (CEikAppUi *)CCoeEnv::Static()->AppUi(); |
110 iCba = CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::ECba, CEikButtonGroupContainer::EHorizontal, this, R_AVKON_SOFTKEYS_EMPTY); |
153 if( eikAppUi && eikAppUi->IsDisplayingDialog() && eikAppUi->TopFocusedControl() ) |
111 iCba->SetBoundingRect(iEikonEnv->EikAppUi()->ApplicationRect()); |
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 } |
|
203 UpdateCBALabelsL(); |
112 UpdateCBALabelsL(); |
204 } |
113 } |
205 return EKeyWasConsumed; |
114 return EKeyWasConsumed; |
206 } |
115 } |
207 else if ( aType == EEventKey && |
116 else if (aType == EEventKey && |
208 aKeyEvent.iCode == EKeyF18 && |
117 aKeyEvent.iCode == EKeyF18 && |
209 ( aKeyEvent.iModifiers & EModifierCtrl ) ) |
118 (aKeyEvent.iModifiers & EModifierCtrl)) |
210 { |
119 { |
211 // FEP requests Ccpu actions with CTRL + F18 |
120 // FEP requests Ccpu actions with CTRL + F18 |
212 // Requested action is encoded in iScanCode. |
121 // Requested action is encoded in iScanCode. |
213 ProcessCommandL( aKeyEvent.iScanCode ); |
122 ProcessCommandL(aKeyEvent.iScanCode); |
214 return EKeyWasConsumed; |
123 return EKeyWasConsumed; |
215 } |
124 } |
216 else if ( ( aKeyEvent.iScanCode == EStdKeyLeftShift || |
125 else if ((aKeyEvent.iScanCode == EStdKeyLeftShift || aKeyEvent.iScanCode == EStdKeyRightShift) && aType == EEventKeyUp) |
217 aKeyEvent.iScanCode == EStdKeyRightShift ) && |
126 { |
218 aType == EEventKeyUp ) |
127 delete iCba; |
219 { |
128 iCba = NULL; |
220 DeleteCBAL(); |
|
221 } |
129 } |
222 |
130 |
223 return EKeyWasNotConsumed; |
131 return EKeyWasNotConsumed; |
224 } |
132 } |
225 |
133 |
226 EXPORT_C void CAknCcpuSupport::DynInitMenuPaneL( TInt aResourceId,CEikMenuPane* aMenuPane ) |
134 EXPORT_C void CAknCcpuSupport::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane) |
227 { |
135 { |
228 if ( aResourceId == R_AVKON_EDIT_MODE_MENU || |
136 if (aResourceId == R_AVKON_EDIT_MODE_MENU || |
229 aResourceId == R_AVKON_EDIT_TEXT_MENU ) |
137 aResourceId == R_AVKON_EDIT_TEXT_MENU) |
230 { |
138 { |
231 aMenuPane->SetItemDimmed( EEikCmdEditCut,!iEditor->CcpuCanCut() ); |
139 aMenuPane->SetItemDimmed(EEikCmdEditCut,!iEditor->CcpuCanCut()); |
232 aMenuPane->SetItemDimmed( EEikCmdEditCopy,!iEditor->CcpuCanCopy() ); |
140 aMenuPane->SetItemDimmed(EEikCmdEditCopy,!iEditor->CcpuCanCopy()); |
233 aMenuPane->SetItemDimmed( EEikCmdEditPaste,!iEditor->CcpuCanPaste() ); |
141 aMenuPane->SetItemDimmed(EEikCmdEditPaste,!iEditor->CcpuCanPaste()); |
234 } |
142 } |
235 } |
143 } |
236 |
144 |
237 EXPORT_C void CAknCcpuSupport::ProcessCommandL( TInt aCommandId ) |
145 EXPORT_C void CAknCcpuSupport::ProcessCommandL(TInt aCommandId) |
238 { |
146 { |
239 switch ( aCommandId ) |
147 switch (aCommandId) |
240 { |
148 { |
241 case EEikCmdEditCut: |
149 case EEikCmdEditCut: |
242 iEditor->CcpuCutL(); |
150 iEditor->CcpuCutL(); |
243 break; |
151 break; |
244 case EEikCmdEditCopy: |
152 case EEikCmdEditCopy: |
257 |
165 |
258 void CAknCcpuSupport::UpdateCBALabelsL() |
166 void CAknCcpuSupport::UpdateCBALabelsL() |
259 { |
167 { |
260 TBool change = EFalse; |
168 TBool change = EFalse; |
261 |
169 |
262 if ( iEditor->CcpuCanCopy() ) |
170 if (iEditor->CcpuCanCopy()) |
263 { |
171 change = UpdateCBALabelL(ELeftSoftkeyIndex, EEikCmdEditCopy, R_TEXT_SOFTKEY_COPY) || change; |
264 change = UpdateCBALabelL( KLeftSoftkeyIndex, EEikCmdEditCopy, R_TEXT_SOFTKEY_COPY ) || change; |
|
265 } |
|
266 else |
172 else |
267 { |
173 change = UpdateCBALabelL(ELeftSoftkeyIndex, ENullCommandId, R_TEXT_SOFTKEY_EMPTY) || change; |
268 change = UpdateCBALabelL( KLeftSoftkeyIndex, KNullCommandId, R_TEXT_SOFTKEY_EMPTY ) || change; |
174 |
269 } |
175 if (iEditor->CcpuCanPaste()) |
270 |
176 change = UpdateCBALabelL(ERightSoftkeyIndex, EEikCmdEditPaste, R_TEXT_SOFTKEY_PASTE) || change; |
271 if ( iEditor->CcpuCanPaste() ) |
|
272 { |
|
273 change = UpdateCBALabelL( KRightSoftkeyIndex, EEikCmdEditPaste, R_TEXT_SOFTKEY_PASTE ) || change; |
|
274 } |
|
275 else |
177 else |
276 { |
178 change = UpdateCBALabelL(ERightSoftkeyIndex, ENullCommandId, R_TEXT_SOFTKEY_EMPTY) || change; |
277 change = UpdateCBALabelL( KRightSoftkeyIndex, KNullCommandId, R_TEXT_SOFTKEY_EMPTY ) || change; |
179 |
278 } |
180 if (change) |
279 |
181 iCba->DrawNow(); |
280 if ( change ) |
182 } |
281 { |
183 |
282 iExtention->iCba->DrawNow(); |
184 TBool CAknCcpuSupport::UpdateCBALabelL(TInt aPosition, TInt aCommandId, TInt aTextResId) |
283 } |
185 { |
284 } |
186 if (iCba->ButtonGroup()->CommandId(aPosition) != aCommandId) |
285 |
187 { |
286 TBool CAknCcpuSupport::UpdateCBALabelL( TInt aPosition, TInt aCommandId, TInt aTextResId ) |
188 HBufC* buf = iEikonEnv->AllocReadResourceLC(aTextResId); |
287 { |
189 iCba->SetCommandL(aPosition, aCommandId, *buf); |
288 if ( iExtention->iCba->ButtonGroup()->CommandId(aPosition) != aCommandId ) |
190 CleanupStack::PopAndDestroy(buf); |
289 { |
|
290 HBufC* buf = iEikonEnv->AllocReadResourceLC( aTextResId ); |
|
291 iExtention->iCba->SetCommandL( aPosition, aCommandId, *buf ); |
|
292 CleanupStack::PopAndDestroy( buf ); |
|
293 return ETrue; |
191 return ETrue; |
294 } |
192 } |
295 return EFalse; |
193 return EFalse; |
296 } |
194 } |
297 |
195 |
298 void CAknCcpuSupport::SetEmphasis( CCoeControl* /*aMenuControl*/, TBool /*aEmphasis*/ ) |
196 void CAknCcpuSupport::SetEmphasis(CCoeControl* /*aMenuControl*/,TBool /*aEmphasis*/) |
299 { |
197 { |
300 } |
198 } |
301 |
199 |
302 EXPORT_C void CAknCcpuSupport::HandlePointerEventL( const TPointerEvent& aPointerEvent ) |
200 EXPORT_C void CAknCcpuSupport::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
303 { |
201 { |
304 CAknControl::HandlePointerEventL( aPointerEvent ); |
202 CAknControl::HandlePointerEventL(aPointerEvent); |
305 } |
203 } |
306 |
204 |
307 EXPORT_C void* CAknCcpuSupport::ExtensionInterface( TUid /*aInterface*/ ) |
205 EXPORT_C void* CAknCcpuSupport::ExtensionInterface( TUid /*aInterface*/ ) |
308 { |
206 { |
309 return NULL; |
207 return NULL; |
310 } |
208 } |
311 void CAknCcpuSupport::DeleteCBAL() |
209 |
312 { |
210 |
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 |
|