|
1 /* |
|
2 * Copyright (c) 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: Popup control adapter |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <e32base.h> |
|
20 #include <e32const.h> |
|
21 #include <coecntrl.h> |
|
22 #include <AknUtils.h> |
|
23 #include <aknstyluspopupmenu.h> |
|
24 |
|
25 // User includes |
|
26 #include "xnappuiadapter.h" |
|
27 #include "xnproperty.h" |
|
28 #include "xncontroladapter.h" |
|
29 #include "xnnodepluginif.h" |
|
30 #include "xnnode.h" |
|
31 #include "xntype.h" |
|
32 #include "xnuiengine.h" |
|
33 #include "xneditor.h" |
|
34 #include "xnhittest.h" |
|
35 #include "xnfocuscontrol.h" |
|
36 |
|
37 #include "xnpopupcontroladapter.h" |
|
38 |
|
39 // Constants |
|
40 _LIT8( KMenuItem, "menuitem" ); |
|
41 _LIT8( KDynMenuItem, "dynmenuitem" ); |
|
42 _LIT8( KWidgetMenuItem, "widgetmenuitem" ); |
|
43 _LIT8( KMenuExtension, "menuextension" ); |
|
44 |
|
45 _LIT8( KSource, "source" ); |
|
46 _LIT8( KTarget, "target" ); |
|
47 |
|
48 // ============================ LOCAL FUNCTIONS =============================== |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // FindWidgetMenuItemL |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 CXnNode* FindWidgetMenuItemL( const TDesC8& aSource, |
|
55 CXnNode& aPlugin ) |
|
56 { |
|
57 if( aPlugin.Children().Count() == 0 ) |
|
58 { |
|
59 return NULL; |
|
60 } |
|
61 |
|
62 // Get <widget> element from the <plugin> element |
|
63 RPointerArray< CXnNode >& children( aPlugin.Children()[0]->Children() ); |
|
64 |
|
65 for ( TInt i = children.Count() - 1; i >= 0; i-- ) |
|
66 { |
|
67 if ( children[i]->Type()->Type() == KMenuExtension ) |
|
68 { |
|
69 RPointerArray< CXnNode >& items( children[i]->Children() ); |
|
70 |
|
71 for ( TInt i = 0; i < items.Count(); i++ ) |
|
72 { |
|
73 CXnProperty* prop( items[i]->GetPropertyL( KTarget ) ); |
|
74 |
|
75 if ( prop && prop->StringValue() == aSource ) |
|
76 { |
|
77 return items[i]; |
|
78 } |
|
79 } |
|
80 |
|
81 break; |
|
82 } |
|
83 } |
|
84 |
|
85 return NULL; |
|
86 } |
|
87 |
|
88 // ============================ MEMBER FUNCTIONS =============================== |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CXnPopupControlAdapter::NewL |
|
92 // Two-phased constructor. Can leave. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 CXnPopupControlAdapter* CXnPopupControlAdapter::NewL( CXnNodePluginIf& aNode ) |
|
96 { |
|
97 CXnPopupControlAdapter* self = |
|
98 new ( ELeave ) CXnPopupControlAdapter(); |
|
99 |
|
100 CleanupStack::PushL( self ); |
|
101 |
|
102 self->ConstructL( aNode ); |
|
103 |
|
104 CleanupStack::Pop( self ); |
|
105 |
|
106 return self; |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CXnPopupControlAdapter::~CXnPopupControlAdapter |
|
111 // Destructor. |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 CXnPopupControlAdapter::~CXnPopupControlAdapter() |
|
115 { |
|
116 delete iStylusPopupMenu; |
|
117 |
|
118 iMenuItems.Reset(); |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CXnPopupControlAdapter::CXnPopupControlAdapter |
|
123 // C++ default constructor. Must not leave. |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 CXnPopupControlAdapter::CXnPopupControlAdapter() |
|
127 { |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CXnPopupControlAdapter::ConstructL |
|
132 // 2nd phase constructor. Can leave. |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void CXnPopupControlAdapter::ConstructL( CXnNodePluginIf& aNode ) |
|
136 { |
|
137 CXnControlAdapter::ConstructL( aNode ); |
|
138 |
|
139 iNode = &aNode.Node(); |
|
140 iUiEngine = iNode->UiEngine(); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CXnPopupControlAdapter::ProcessCommandL |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 void CXnPopupControlAdapter::ProcessCommandL( TInt aCommandId ) |
|
148 { |
|
149 // Resolve selected item |
|
150 for ( TInt i = 0; aCommandId != KErrCancel && i < iMenuItems.Count(); i++ ) |
|
151 { |
|
152 if ( i == aCommandId ) |
|
153 { |
|
154 // Do the actual item selection |
|
155 iMenuItems[i]->SetStateL( |
|
156 XnPropertyNames::style::common::KActive ); |
|
157 |
|
158 break; |
|
159 } |
|
160 } |
|
161 |
|
162 iMenuItems.Reset(); |
|
163 iCommandId = 0; |
|
164 |
|
165 iMenuShown = EFalse; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CXnPopupControlAdapter::SetEmphasis |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 void CXnPopupControlAdapter::SetEmphasis( CCoeControl* /*aMenuControl*/, |
|
173 TBool /*aEmphasis*/ ) |
|
174 { |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CXnPopupControlAdapter::SetObserver |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 void CXnPopupControlAdapter::SetObserver( |
|
182 XnMenuInterface::MXnMenuObserver& aObserver ) |
|
183 { |
|
184 iObserver = &aObserver; |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CXnPopupControlAdapter::TryDisplayingStylusPopupL |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 void CXnPopupControlAdapter::TryDisplayingStylusPopupL( CXnNode& aPlugin ) |
|
192 { |
|
193 HideMenuL(); |
|
194 |
|
195 TPointerEvent event( iUiEngine->HitTest().PointerEvent() ); |
|
196 |
|
197 delete iStylusPopupMenu; |
|
198 iStylusPopupMenu = NULL; |
|
199 |
|
200 // Popup is positioned relatively to screen |
|
201 iStylusPopupMenu = CAknStylusPopUpMenu::NewL( this, event.iParentPosition ); |
|
202 |
|
203 RPointerArray< CXnNode >& children( iNode->Children() ); |
|
204 |
|
205 for ( TInt i = 0; i < children.Count(); i++ ) |
|
206 { |
|
207 PopulateMenuL( children[i], aPlugin ); |
|
208 } |
|
209 |
|
210 ShowMenuL( aPlugin, event.iParentPosition ); |
|
211 } |
|
212 |
|
213 // ----------------------------------------------------------------------------- |
|
214 // CXnPopupControlAdapter::HandleScreenDeviceChangedL |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 void CXnPopupControlAdapter::HandleScreenDeviceChangedL() |
|
218 { |
|
219 HideMenuL(); |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // CXnPopupControlAdapter::PopulateMenuL |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 void CXnPopupControlAdapter::PopulateMenuL( CXnNode* aItem, CXnNode& aPlugin ) |
|
227 { |
|
228 CXnNode* menuitem( NULL ); |
|
229 CXnProperty* prop( NULL ); |
|
230 |
|
231 TBool mappedItem( EFalse ); |
|
232 |
|
233 // Map widget menuitem first |
|
234 if ( aItem->Type()->Type() == KWidgetMenuItem ) |
|
235 { |
|
236 // Widget menuitem is shown if a widget defined by the "aPlugin" |
|
237 // defines a proper source - target menuitem pairing |
|
238 CXnProperty* source( aItem->GetPropertyL( KSource ) ); |
|
239 |
|
240 if ( source ) |
|
241 { |
|
242 CXnNode* widgetItem( |
|
243 FindWidgetMenuItemL( source->StringValue(), aPlugin ) ); |
|
244 |
|
245 if ( widgetItem ) |
|
246 { |
|
247 mappedItem = ETrue; |
|
248 |
|
249 // Get label from the view item |
|
250 prop = aItem->LabelL(); |
|
251 if ( !prop ) |
|
252 { |
|
253 // no localization in view, check from widget |
|
254 prop = widgetItem->LabelL(); |
|
255 } |
|
256 // Pretend the original item is this widget item |
|
257 aItem = widgetItem; |
|
258 } |
|
259 } |
|
260 } |
|
261 |
|
262 const TDesC8& type( aItem->Type()->Type() ); |
|
263 |
|
264 if ( type == KMenuItem ) |
|
265 { |
|
266 // By default plain menuitems are always shown |
|
267 menuitem = aItem; |
|
268 } |
|
269 else if ( type == KDynMenuItem && iObserver ) |
|
270 { |
|
271 // Let observer decide whether dynmenuitem is visible or not |
|
272 if ( iObserver->DynInitMenuItemL( aItem->AppIfL(), &aPlugin.AppIfL() ) ) |
|
273 { |
|
274 menuitem = aItem; |
|
275 } |
|
276 } |
|
277 |
|
278 if ( menuitem ) |
|
279 { |
|
280 CXnProperty* display = menuitem->DisplayL(); |
|
281 if ( display && display->StringValue() == XnPropertyNames::style::common::display::KNone ) |
|
282 { |
|
283 return; |
|
284 } |
|
285 |
|
286 if ( !mappedItem ) |
|
287 { |
|
288 prop = menuitem->LabelL(); |
|
289 } |
|
290 |
|
291 if ( prop ) |
|
292 { |
|
293 HBufC* label( prop->StringValueL() ); |
|
294 CleanupStack::PushL( label ); |
|
295 |
|
296 iStylusPopupMenu->AddMenuItemL( *label, iCommandId++ ); |
|
297 iMenuItems.AppendL( menuitem ); |
|
298 |
|
299 CleanupStack::PopAndDestroy( label ); |
|
300 } |
|
301 } |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CXnPopupControlAdapter::ShowMenuL |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 void CXnPopupControlAdapter::ShowMenuL( CXnNode& aPlugin, TPoint aPosition ) |
|
309 { |
|
310 if ( iMenuItems.Count() > 0 && !iMenuShown ) |
|
311 { |
|
312 iUiEngine->AppUiAdapter().HideFocus(); |
|
313 |
|
314 iUiEngine->Editor()->SetTargetPlugin( &aPlugin ); |
|
315 |
|
316 if ( AknLayoutUtils::LayoutMirrored() ) |
|
317 { |
|
318 iStylusPopupMenu->SetPosition( aPosition, |
|
319 CAknStylusPopUpMenu::EPositionTypeRightBottom ); |
|
320 } |
|
321 else |
|
322 { |
|
323 iStylusPopupMenu->SetPosition( aPosition, |
|
324 CAknStylusPopUpMenu::EPositionTypeLeftBottom ); |
|
325 } |
|
326 |
|
327 iStylusPopupMenu->ShowMenu(); |
|
328 iMenuShown = ETrue; |
|
329 } |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CXnPopupControlAdapter::HideMenuL |
|
334 // ----------------------------------------------------------------------------- |
|
335 // |
|
336 void CXnPopupControlAdapter::HideMenuL() |
|
337 { |
|
338 if ( iMenuShown ) |
|
339 { |
|
340 ProcessCommandL( KErrCancel ); |
|
341 |
|
342 delete iStylusPopupMenu; |
|
343 iStylusPopupMenu = NULL; |
|
344 |
|
345 iMenuShown = EFalse; |
|
346 } |
|
347 } |
|
348 |
|
349 // End of file |