|
1 /* |
|
2 * Copyright (c) 2005-2005 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: Interface for controlling stylus popup menu. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <aknpreviewpopupcontroller.h> |
|
20 #include <eikmobs.h> |
|
21 #include <aknutils.h> |
|
22 #include <barsread.h> |
|
23 |
|
24 #include "aistyluspopupmenu.h" |
|
25 #include "aistyluspopupmenucontent.h" |
|
26 |
|
27 const TInt KDefaultPopUpShowDelay = 0; |
|
28 const TInt KDefaultPopUpHideDelay = 10000000; // 10 seconds |
|
29 |
|
30 |
|
31 // ======== MEMBER FUNCTIONS ======== |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // Default constructor |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 CAiStylusPopUpMenu::CAiStylusPopUpMenu( MEikMenuObserver* aObserver, |
|
38 const TPoint& aPoint, |
|
39 CAknPreviewPopUpController* aPopup ) |
|
40 : iPosition ( aPoint ), |
|
41 iMenuObserver( aObserver ), |
|
42 iPreviewPopup( aPopup ) |
|
43 { |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CAiStylusPopUpMenu::ConstructL |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 void CAiStylusPopUpMenu::ConstructL() |
|
51 { |
|
52 iContent = CAiStylusPopUpMenuContent::NewL(); |
|
53 |
|
54 iController = CAknPreviewPopUpController::NewL( *iContent, |
|
55 CAknPreviewPopUpController::ELayoutSubMenu ); |
|
56 iController->SetPopUpShowDelay( KDefaultPopUpShowDelay ); |
|
57 iController->SetPopUpHideDelay( KDefaultPopUpHideDelay ); |
|
58 iController->SetPosition( iPosition ); |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------------------------- |
|
62 // CAiStylusPopUpMenu::NewL |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 CAiStylusPopUpMenu* CAiStylusPopUpMenu::NewL( |
|
66 MEikMenuObserver* aObserver, const TPoint& aPoint, |
|
67 CAknPreviewPopUpController* aPopup ) |
|
68 { |
|
69 if( !AknLayoutUtils::PenEnabled() ) |
|
70 { |
|
71 return NULL; |
|
72 } |
|
73 |
|
74 CAiStylusPopUpMenu* self = CAiStylusPopUpMenu::NewLC( aObserver, |
|
75 aPoint, |
|
76 aPopup ); |
|
77 CleanupStack::Pop( self ); |
|
78 return self; |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // CAiStylusPopUpMenu::NewL |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 CAiStylusPopUpMenu* CAiStylusPopUpMenu::NewL( |
|
86 MEikMenuObserver* aObserver, const TPoint& aPoint ) |
|
87 { |
|
88 if( !AknLayoutUtils::PenEnabled() ) |
|
89 { |
|
90 return NULL; |
|
91 } |
|
92 |
|
93 CAiStylusPopUpMenu* self = CAiStylusPopUpMenu::NewLC( aObserver, |
|
94 aPoint, NULL ); |
|
95 CleanupStack::Pop( self ); |
|
96 return self; |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // CAiStylusPopUpMenu::NewLC |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 CAiStylusPopUpMenu* CAiStylusPopUpMenu::NewLC( |
|
104 MEikMenuObserver* aObserver, const TPoint& aPoint, |
|
105 CAknPreviewPopUpController* aPopup ) |
|
106 { |
|
107 if( !AknLayoutUtils::PenEnabled() ) |
|
108 { |
|
109 return NULL; |
|
110 } |
|
111 |
|
112 CAiStylusPopUpMenu* self = new ( ELeave ) CAiStylusPopUpMenu( aObserver, |
|
113 aPoint, |
|
114 aPopup ); |
|
115 CleanupStack::PushL( self ); |
|
116 self->ConstructL(); |
|
117 return self; |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // Destructor |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 CAiStylusPopUpMenu::~CAiStylusPopUpMenu() |
|
125 { |
|
126 if ( AknLayoutUtils::PenEnabled() ) |
|
127 { |
|
128 delete iController; |
|
129 delete iContent; |
|
130 } |
|
131 } |
|
132 |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // CAiStylusPopUpMenu::AddMenuItemL |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 void CAiStylusPopUpMenu::AddMenuItemL( const TDesC& aItem, |
|
139 const TInt aCommandId ) |
|
140 { |
|
141 if(AknLayoutUtils::PenEnabled()) |
|
142 { |
|
143 iContent->AddMenuItemL( aItem, aCommandId, *this ); |
|
144 } |
|
145 } |
|
146 |
|
147 |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // CAiStylusPopUpMenu::RemoveMenuItem |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 void CAiStylusPopUpMenu::RemoveMenuItem( const TInt aCommandId ) |
|
154 { |
|
155 if(AknLayoutUtils::PenEnabled()) |
|
156 { |
|
157 iContent->RemoveMenuItem( aCommandId ); |
|
158 } |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // CAiStylusPopUpMenu::SetItemDimmed |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 void CAiStylusPopUpMenu::SetItemDimmed( const TInt aCommandId, const TBool aDimmed ) |
|
166 { |
|
167 if(AknLayoutUtils::PenEnabled()) |
|
168 { |
|
169 iContent->SetItemDimmed( aCommandId, aDimmed ); |
|
170 } |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // CAiStylusPopUpMenu::ShowMenu |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 void CAiStylusPopUpMenu::ShowMenu() |
|
178 { |
|
179 if(AknLayoutUtils::PenEnabled()) |
|
180 { |
|
181 iController->ShowPopUp(); |
|
182 } |
|
183 } |
|
184 |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // CAiStylusPopUpMenu::SetPosition |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 void CAiStylusPopUpMenu::SetPosition( const TPoint& aPoint ) |
|
191 { |
|
192 if(AknLayoutUtils::PenEnabled()) |
|
193 { |
|
194 iController->SetPosition( aPoint ); |
|
195 } |
|
196 } |
|
197 |
|
198 // --------------------------------------------------------------------------- |
|
199 // CAiStylusPopUpMenu::ConstructFromResourceL |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 void CAiStylusPopUpMenu::ConstructFromResourceL( TResourceReader& |
|
203 aReader ) |
|
204 { |
|
205 if(!AknLayoutUtils::PenEnabled()) |
|
206 { |
|
207 return; |
|
208 } |
|
209 |
|
210 TInt count = aReader.ReadInt16(); |
|
211 if ( count > KAiStylusMenuMaxItems ) |
|
212 { |
|
213 // Only allowed number of items read from resources. |
|
214 count = KAiStylusMenuMaxItems; |
|
215 } |
|
216 TInt commandId; |
|
217 for ( TInt i = 0; i < count; i++ ) |
|
218 { |
|
219 TPtrC text = aReader.ReadTPtrC(); |
|
220 commandId = aReader.ReadInt32(); |
|
221 iContent->AddMenuItemL( text, commandId, *this ); |
|
222 aReader.ReadInt32(); // extension link |
|
223 iController->UpdateContentSize(); |
|
224 } |
|
225 } |
|
226 |
|
227 // --------------------------------------------------------------------------- |
|
228 // From class MCoeControlObserver. |
|
229 // Handles stylus tap events by forwarding the event to the observer. |
|
230 // --------------------------------------------------------------------------- |
|
231 // |
|
232 void CAiStylusPopUpMenu::HandleControlEventL( CCoeControl* aControl, |
|
233 TCoeEvent aEventType ) |
|
234 { |
|
235 if(!AknLayoutUtils::PenEnabled()) |
|
236 { |
|
237 return; |
|
238 } |
|
239 |
|
240 if ( aControl && aEventType == EEventStateChanged ) |
|
241 { |
|
242 if ( iPreviewPopup ) |
|
243 { |
|
244 iPreviewPopup->HidePopUp(); |
|
245 } |
|
246 iController->HidePopUp(); |
|
247 iMenuObserver->ProcessCommandL( iContent->CommandId( aControl ) ); |
|
248 } |
|
249 } |
|
250 |