|
1 /* |
|
2 * Copyright (c) 2009 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 * |
|
16 */ |
|
17 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
18 #include <uikon/eikdefmacros.h> |
|
19 #endif |
|
20 #include "eikccpu.h" |
|
21 #include <eikedwin.h> |
|
22 #include <eikbtgpc.h> |
|
23 #include <aknenv.h> |
|
24 #include <avkon.rsg> |
|
25 #include <avkon.hrh> |
|
26 #include <eikappui.h> |
|
27 |
|
28 const TInt ELeftSoftkeyIndex = 0; |
|
29 const TInt ERightSoftkeyIndex = 2; |
|
30 const TInt ENullCommandId = -1; |
|
31 |
|
32 |
|
33 // |
|
34 // CAknCcpuSupport |
|
35 // |
|
36 |
|
37 enum TAknCcpuSupportFlags |
|
38 { |
|
39 EFocused |
|
40 }; |
|
41 |
|
42 EXPORT_C CAknCcpuSupport::CAknCcpuSupport(MEikCcpuEditor* aEditor) |
|
43 : iEditor(aEditor) |
|
44 { |
|
45 } |
|
46 |
|
47 EXPORT_C CAknCcpuSupport::~CAknCcpuSupport() |
|
48 { |
|
49 if (iMenu) |
|
50 iMenu->RemoveEditMenuObserver(this); |
|
51 delete iCba; |
|
52 iEikonEnv->EikAppUi()->RemoveFromStack(this); |
|
53 } |
|
54 |
|
55 EXPORT_C void CAknCcpuSupport::ConstructL() |
|
56 { |
|
57 iEikonEnv->EikAppUi()->AddToStackL(this, ECoeStackPriorityFep-1, ECoeStackFlagRefusesFocus); |
|
58 HandleFocusChangeL(); |
|
59 } |
|
60 |
|
61 EXPORT_C void CAknCcpuSupport::HandleSelectionChangeL() |
|
62 { |
|
63 if (iCba) |
|
64 UpdateCBALabelsL(); |
|
65 } |
|
66 |
|
67 EXPORT_C void CAknCcpuSupport::HandleFocusChangeL() |
|
68 { |
|
69 TBool focused = iEditor->CcpuIsFocused(); |
|
70 if (COMPARE_BOOLS(focused, iFlags[EFocused])) |
|
71 return; |
|
72 |
|
73 iFlags.Assign(EFocused, focused); |
|
74 |
|
75 if (focused) |
|
76 { |
|
77 MopGetObject(iMenu); |
|
78 |
|
79 if (iMenu) |
|
80 iMenu->SetEditMenuObserver(this); |
|
81 } |
|
82 else |
|
83 { |
|
84 if (iMenu) |
|
85 { |
|
86 iMenu->RemoveEditMenuObserver(this); |
|
87 iMenu = NULL; |
|
88 } |
|
89 } |
|
90 |
|
91 if (iCba && !focused) |
|
92 { |
|
93 // something has caused loss of focus while shift is pressed - drop everything. |
|
94 delete iCba; |
|
95 iCba = NULL; |
|
96 } |
|
97 } |
|
98 |
|
99 EXPORT_C TKeyResponse CAknCcpuSupport::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
100 { |
|
101 if (!iFlags[EFocused]) |
|
102 return EKeyWasNotConsumed; |
|
103 |
|
104 if (aKeyEvent.iCode == EKeyF21) // FEP generates F21 on long shift press |
|
105 { |
|
106 if (aType == EEventKey) |
|
107 { |
|
108 delete iCba; |
|
109 iCba = NULL; |
|
110 iCba = CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::ECba, CEikButtonGroupContainer::EHorizontal, this, R_AVKON_SOFTKEYS_EMPTY); |
|
111 iCba->SetBoundingRect(iEikonEnv->EikAppUi()->ApplicationRect()); |
|
112 UpdateCBALabelsL(); |
|
113 } |
|
114 return EKeyWasConsumed; |
|
115 } |
|
116 else if (aType == EEventKey && |
|
117 aKeyEvent.iCode == EKeyF18 && |
|
118 (aKeyEvent.iModifiers & EModifierCtrl)) |
|
119 { |
|
120 // FEP requests Ccpu actions with CTRL + F18 |
|
121 // Requested action is encoded in iScanCode. |
|
122 ProcessCommandL(aKeyEvent.iScanCode); |
|
123 return EKeyWasConsumed; |
|
124 } |
|
125 else if ((aKeyEvent.iScanCode == EStdKeyLeftShift || aKeyEvent.iScanCode == EStdKeyRightShift) && aType == EEventKeyUp) |
|
126 { |
|
127 delete iCba; |
|
128 iCba = NULL; |
|
129 } |
|
130 |
|
131 return EKeyWasNotConsumed; |
|
132 } |
|
133 |
|
134 EXPORT_C void CAknCcpuSupport::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane) |
|
135 { |
|
136 if (aResourceId == R_AVKON_EDIT_MODE_MENU || |
|
137 aResourceId == R_AVKON_EDIT_TEXT_MENU) |
|
138 { |
|
139 aMenuPane->SetItemDimmed(EEikCmdEditCut,!iEditor->CcpuCanCut()); |
|
140 aMenuPane->SetItemDimmed(EEikCmdEditCopy,!iEditor->CcpuCanCopy()); |
|
141 aMenuPane->SetItemDimmed(EEikCmdEditPaste,!iEditor->CcpuCanPaste()); |
|
142 } |
|
143 } |
|
144 |
|
145 EXPORT_C void CAknCcpuSupport::ProcessCommandL(TInt aCommandId) |
|
146 { |
|
147 switch (aCommandId) |
|
148 { |
|
149 case EEikCmdEditCut: |
|
150 iEditor->CcpuCutL(); |
|
151 break; |
|
152 case EEikCmdEditCopy: |
|
153 iEditor->CcpuCopyL(); |
|
154 break; |
|
155 case EEikCmdEditPaste: |
|
156 iEditor->CcpuPasteL(); |
|
157 break; |
|
158 case EEikCmdEditUndo: |
|
159 iEditor->CcpuUndoL(); |
|
160 break; |
|
161 default: |
|
162 break; |
|
163 } |
|
164 } |
|
165 |
|
166 void CAknCcpuSupport::UpdateCBALabelsL() |
|
167 { |
|
168 TBool change = EFalse; |
|
169 |
|
170 if (iEditor->CcpuCanCopy()) |
|
171 change = UpdateCBALabelL(ELeftSoftkeyIndex, EEikCmdEditCopy, R_TEXT_SOFTKEY_COPY) || change; |
|
172 else |
|
173 change = UpdateCBALabelL(ELeftSoftkeyIndex, ENullCommandId, R_TEXT_SOFTKEY_EMPTY) || change; |
|
174 |
|
175 if (iEditor->CcpuCanPaste()) |
|
176 change = UpdateCBALabelL(ERightSoftkeyIndex, EEikCmdEditPaste, R_TEXT_SOFTKEY_PASTE) || change; |
|
177 else |
|
178 change = UpdateCBALabelL(ERightSoftkeyIndex, ENullCommandId, R_TEXT_SOFTKEY_EMPTY) || change; |
|
179 |
|
180 if (change) |
|
181 iCba->DrawNow(); |
|
182 } |
|
183 |
|
184 TBool CAknCcpuSupport::UpdateCBALabelL(TInt aPosition, TInt aCommandId, TInt aTextResId) |
|
185 { |
|
186 if (iCba->ButtonGroup()->CommandId(aPosition) != aCommandId) |
|
187 { |
|
188 HBufC* buf = iEikonEnv->AllocReadResourceLC(aTextResId); |
|
189 iCba->SetCommandL(aPosition, aCommandId, *buf); |
|
190 CleanupStack::PopAndDestroy(buf); |
|
191 return ETrue; |
|
192 } |
|
193 return EFalse; |
|
194 } |
|
195 |
|
196 void CAknCcpuSupport::SetEmphasis(CCoeControl* /*aMenuControl*/,TBool /*aEmphasis*/) |
|
197 { |
|
198 } |
|
199 |
|
200 EXPORT_C void CAknCcpuSupport::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
201 { |
|
202 CAknControl::HandlePointerEventL(aPointerEvent); |
|
203 } |
|
204 |
|
205 EXPORT_C void* CAknCcpuSupport::ExtensionInterface( TUid /*aInterface*/ ) |
|
206 { |
|
207 return NULL; |
|
208 } |
|
209 |
|
210 |