|
1 /* |
|
2 * Copyright (c) 2006-2008 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: AVKON input blocker. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "akninputblock.h" |
|
20 #include <eikenv.h> |
|
21 #include <eikappui.h> |
|
22 #include <eikbtgpc.h> |
|
23 #include <avkon.rsg> |
|
24 #include <eikcba.h> |
|
25 #include <avkon.hrh> |
|
26 |
|
27 //Define command for MSK. |
|
28 const TInt KBlockCBAMSKEmptyID = -100; |
|
29 |
|
30 EXPORT_C CAknInputBlock* CAknInputBlock::NewLC() |
|
31 { |
|
32 CAknInputBlock* self = new(ELeave) CAknInputBlock; |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 return self; |
|
36 } |
|
37 |
|
38 EXPORT_C CAknInputBlock* CAknInputBlock::NewCancelHandlerLC(MAknInputBlockCancelHandler* aHandlerToCancel) |
|
39 { |
|
40 CAknInputBlock* self = NewLC(); |
|
41 self->SetCancelHandler(aHandlerToCancel); |
|
42 return self; |
|
43 } |
|
44 |
|
45 EXPORT_C CAknInputBlock* CAknInputBlock::NewCancelActiveLC(CActive* aActiveObjectToCancel) |
|
46 { |
|
47 CAknInputBlock* self = NewLC(); |
|
48 self->SetCancelActive(aActiveObjectToCancel); |
|
49 return self; |
|
50 } |
|
51 |
|
52 EXPORT_C CAknInputBlock* CAknInputBlock::NewCancelDeleteLC(CBase* aObjectToDelete) |
|
53 { |
|
54 CAknInputBlock* self = NewLC(); |
|
55 self->SetCancelDelete(aObjectToDelete); |
|
56 return self; |
|
57 } |
|
58 |
|
59 EXPORT_C CAknInputBlock::~CAknInputBlock() |
|
60 { |
|
61 iAppUi->RemoveFromStack(this); |
|
62 if (CapturesPointer()) |
|
63 SetPointerCapture(EFalse); |
|
64 delete iCba; |
|
65 Cancel(); |
|
66 } |
|
67 |
|
68 EXPORT_C void CAknInputBlock::SetCancelHandler(MAknInputBlockCancelHandler* aHandlerToCancel) |
|
69 { |
|
70 iHandlerToCancel = aHandlerToCancel; |
|
71 } |
|
72 |
|
73 EXPORT_C void CAknInputBlock::SetCancelActive(CActive* aActiveObjectToCancel) |
|
74 { |
|
75 iActiveObjectToCancel = aActiveObjectToCancel; |
|
76 } |
|
77 |
|
78 EXPORT_C void CAknInputBlock::SetCancelDelete(CBase* aObjectToDelete) |
|
79 { |
|
80 iObjectToDelete = aObjectToDelete; |
|
81 } |
|
82 |
|
83 EXPORT_C void CAknInputBlock::Cancel() |
|
84 { |
|
85 // move ownership to stack in case this is deleted |
|
86 MAknInputBlockCancelHandler* handlerToCancel = iHandlerToCancel; |
|
87 iHandlerToCancel = NULL; |
|
88 |
|
89 CActive* activeObjectToCancel = iActiveObjectToCancel; |
|
90 iActiveObjectToCancel = NULL; |
|
91 |
|
92 CBase* objectToDelete = iObjectToDelete; |
|
93 iObjectToDelete = NULL; |
|
94 |
|
95 if (handlerToCancel) |
|
96 { |
|
97 handlerToCancel->AknInputBlockCancel(); |
|
98 } |
|
99 |
|
100 if (activeObjectToCancel) |
|
101 { |
|
102 activeObjectToCancel->Cancel(); |
|
103 } |
|
104 |
|
105 if (objectToDelete) |
|
106 { |
|
107 delete objectToDelete; |
|
108 } |
|
109 } |
|
110 |
|
111 CAknInputBlock::CAknInputBlock() |
|
112 : iAppUi(iEikonEnv->EikAppUi()) |
|
113 { |
|
114 } |
|
115 |
|
116 |
|
117 void CAknInputBlock::ConstructL() |
|
118 { |
|
119 CreateWindowL(); |
|
120 SetExtent(TPoint(0,0), TSize(0,0)); |
|
121 ActivateL(); |
|
122 iAppUi->AddToStackL(this, ECoeStackPriorityDialog); |
|
123 |
|
124 iCba = CEikButtonGroupContainer::NewL( |
|
125 CEikButtonGroupContainer::ECba, |
|
126 CEikButtonGroupContainer::EHorizontal, |
|
127 this, |
|
128 R_AVKON_SOFTKEYS_EMPTY); |
|
129 |
|
130 iCba->ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition(ECoeWinPriorityNeverAtFront); |
|
131 |
|
132 static_cast<CEikCba*>( iCba->ButtonGroup() )->SetButtonGroupFlags( |
|
133 iCba->ButtonGroup()->ButtonGroupFlags() | EAknCBAFlagRespondWhenInvisible ); |
|
134 |
|
135 //Set the msk command to consume the EKeyOk event. |
|
136 TBuf<5> tmp(_L("")); |
|
137 iCba->SetCommandL( CEikButtonGroupContainer::EMiddleSoftkeyPosition, KBlockCBAMSKEmptyID, tmp ); |
|
138 iCba->MakeVisible( EFalse ); |
|
139 iCba->SetBoundingRect(TRect(iEikonEnv->ScreenDevice()->SizeInPixels())); |
|
140 } |
|
141 |
|
142 |
|
143 TKeyResponse CAknInputBlock::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) |
|
144 { |
|
145 if (aType == EEventKey && aKeyEvent.iCode == EKeyEscape) |
|
146 { |
|
147 #ifdef _DEBUG |
|
148 if (!IsCancellable()) |
|
149 RDebug::Print(_L("CAknInputBlock received Escape key while not cancellable")); |
|
150 #endif |
|
151 Cancel(); |
|
152 } |
|
153 return (aKeyEvent.iScanCode == EStdKeyYes ? EKeyWasNotConsumed : EKeyWasConsumed); |
|
154 } |
|
155 |
|
156 void CAknInputBlock::ProcessCommandL(TInt /*aCommandId*/) |
|
157 { |
|
158 } |
|
159 |
|
160 void CAknInputBlock::FocusChanged(TDrawNow /*aDrawNow*/) |
|
161 { |
|
162 if (IsFocused()) |
|
163 { |
|
164 SetPointerCapture(ETrue); |
|
165 ClaimPointerGrab(ETrue); |
|
166 } |
|
167 else |
|
168 { |
|
169 SetPointerCapture(EFalse); |
|
170 } |
|
171 } |
|
172 |
|
173 bool CAknInputBlock::IsCancellable() const |
|
174 { |
|
175 bool cancellable = |
|
176 iHandlerToCancel || |
|
177 iActiveObjectToCancel || |
|
178 iObjectToDelete; |
|
179 return cancellable; |
|
180 } |