|
1 /* |
|
2 * Copyright (c) 2002-2004 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: Edit mode for widget drag and drop. |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <AknUtils.h> |
|
20 #include <gulgcmap.h> |
|
21 #include <barsread.h> |
|
22 |
|
23 #ifdef RD_TACTILE_FEEDBACK |
|
24 #include <touchfeedback.h> |
|
25 #endif // RD_TACTILE_FEEDBACK |
|
26 |
|
27 // User includes |
|
28 #include "xnappuiadapter.h" |
|
29 #include "xnviewmanager.h" |
|
30 #include "xnviewadapter.h" |
|
31 #include "xnviewdata.h" |
|
32 #include "xnnodeimpl.h" |
|
33 #include "xndomnode.h" |
|
34 #include "xnnode.h" |
|
35 #include "xnproperty.h" |
|
36 #include "xnuiengine.h" |
|
37 #include "xncontroladapter.h" |
|
38 #include "xnpopupcontroladapter.h" |
|
39 #include "xnviewcontroladapter.h" |
|
40 #include "xnfocuscontrol.h" |
|
41 #include "xneditor.h" |
|
42 #include "xntype.h" |
|
43 #include "xnmenu.h" |
|
44 #include "xnbackgroundmanager.h" |
|
45 |
|
46 #include "xneditmode.h" |
|
47 |
|
48 // Constants |
|
49 _LIT8( KMenu, "menu" ); |
|
50 |
|
51 // ============================ LOCAL FUNCTIONS ================================ |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CopyBitmap |
|
55 // Copies a data from source bitmap to target bitmap. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 static TInt CopyBitmap( CFbsBitmap& aTarget, const CFbsBitmap& aSource, |
|
59 TPoint aSourcePoint ) |
|
60 { |
|
61 TSize targetSize( aTarget.SizeInPixels() ); |
|
62 TSize sourceSize( aSource.SizeInPixels() ); |
|
63 |
|
64 TInt lineLength( targetSize.iWidth ); |
|
65 TInt maxSourceLineLength( sourceSize.iWidth - aSourcePoint.iX ); |
|
66 |
|
67 if ( lineLength > maxSourceLineLength ) |
|
68 { |
|
69 lineLength = maxSourceLineLength; |
|
70 } |
|
71 |
|
72 TInt rowCount( targetSize.iHeight ); |
|
73 TInt maxSourceRowCount( sourceSize.iHeight - aSourcePoint.iY ); |
|
74 |
|
75 if ( rowCount > maxSourceRowCount ) |
|
76 { |
|
77 rowCount = maxSourceRowCount; |
|
78 } |
|
79 |
|
80 // Get bitmap display mode |
|
81 TDisplayMode displayMode( aSource.DisplayMode() ); |
|
82 |
|
83 // Create buffer for a scan line |
|
84 HBufC8* scanLine = HBufC8::New( aSource.ScanLineLength( |
|
85 lineLength, displayMode ) ); |
|
86 |
|
87 if ( !scanLine ) |
|
88 { |
|
89 return KErrNoMemory; |
|
90 } |
|
91 |
|
92 TPtr8 scanPtr( scanLine->Des() ); |
|
93 |
|
94 // Copy all rows to destination bitmap |
|
95 for ( TInt row = 0; row < rowCount; row++ ) |
|
96 { |
|
97 aSource.GetScanLine( scanPtr, |
|
98 TPoint( aSourcePoint.iX, aSourcePoint.iY + row ), |
|
99 lineLength, displayMode ); |
|
100 |
|
101 aTarget.SetScanLine( scanPtr, row ); |
|
102 } |
|
103 |
|
104 delete scanLine; |
|
105 |
|
106 return KErrNone; |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // SetVisibilityL |
|
111 // Sets node either visible or hidden |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 static void SetVisibilityL( CXnNode& aNode, const TDesC8& aVisibility ) |
|
115 { |
|
116 CXnUiEngine* engine( aNode.UiEngine() ); |
|
117 |
|
118 CXnDomStringPool* sp( aNode.DomNode()->StringPool() ); |
|
119 |
|
120 CXnProperty* prop = CXnProperty::NewL( |
|
121 XnPropertyNames::style::common::KVisibility, |
|
122 aVisibility, |
|
123 CXnDomPropertyValue::EString, *sp ); |
|
124 CleanupStack::PushL( prop ); |
|
125 |
|
126 aNode.SetPropertyL( prop ); |
|
127 |
|
128 CleanupStack::Pop( prop ); |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // ResolveMenuIdL |
|
133 // Resolves <menu> element and its id based on aMenuBar <menubar> element |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 static HBufC* ResolveMenuIdL( CXnNode& aMenuBar ) |
|
137 { |
|
138 HBufC* retval( NULL ); |
|
139 |
|
140 RPointerArray< CXnNode >& children( aMenuBar.Children() ); |
|
141 |
|
142 for ( TInt i = 0; i < children.Count(); i++ ) |
|
143 { |
|
144 CXnNode* child( children[i] ); |
|
145 |
|
146 if ( child->Type()->Type() == KMenu ) |
|
147 { |
|
148 CXnProperty* prop( |
|
149 child->GetPropertyL( XnPropertyNames::common::KId ) ); |
|
150 |
|
151 if ( prop ) |
|
152 { |
|
153 // Ownership is passed to the caller |
|
154 retval = prop->StringValueL(); |
|
155 } |
|
156 |
|
157 break; |
|
158 } |
|
159 } |
|
160 |
|
161 return retval; |
|
162 } |
|
163 |
|
164 #ifdef RD_TACTILE_FEEDBACK |
|
165 // ----------------------------------------------------------------------------- |
|
166 // Feedback |
|
167 // Gives instant touch feedback |
|
168 // ----------------------------------------------------------------------------- |
|
169 // |
|
170 static void Feedback( TTouchLogicalFeedback aType ) |
|
171 { |
|
172 MTouchFeedback* fb( MTouchFeedback::Instance() ); |
|
173 |
|
174 if ( fb ) |
|
175 { |
|
176 fb->InstantFeedback( aType ); |
|
177 } |
|
178 } |
|
179 #endif // RD_TACTILE_FEEDBACK |
|
180 |
|
181 // ============================ MEMBER FUNCTIONS =============================== |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CXnEditMode::CXnEditMode |
|
185 // C++ default constructor can NOT contain any code, that |
|
186 // might leave. |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 CXnEditMode::CXnEditMode( CXnUiEngine& aUiEngine ) |
|
190 : iUiEngine( aUiEngine ), |
|
191 iViewManager( *iUiEngine.ViewManager() ), |
|
192 iState( CXnEditMode::ENone ), |
|
193 iStylusDownPos( TPoint::EUninitialized ), |
|
194 iPreviousPos( TPoint::EUninitialized ), |
|
195 iDrawPos( TPoint::EUninitialized ), |
|
196 iLastDrawRect( TRect::EUninitialized ) |
|
197 { |
|
198 } |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CXnEditMode::ConstructL |
|
202 // Symbian 2nd phase constructor can leave. |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 void CXnEditMode::ConstructL() |
|
206 { |
|
207 CreateWindowL(); |
|
208 |
|
209 ActivateL(); |
|
210 |
|
211 Window().SetRequiredDisplayMode( EColor16MA ); |
|
212 |
|
213 if ( Window().SetTransparencyAlphaChannel() == KErrNone ) |
|
214 { |
|
215 Window().SetBackgroundColor( ~0 ); |
|
216 } |
|
217 |
|
218 EnableDragEvents(); |
|
219 |
|
220 CCoeControl::MakeVisible( EFalse ); |
|
221 |
|
222 TRect rect; |
|
223 |
|
224 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, rect ); |
|
225 |
|
226 iMainpane = new ( ELeave ) CFbsBitmap; |
|
227 User::LeaveIfError( iMainpane->Create( TSize(), EColor16MA ) ); |
|
228 |
|
229 iWidget = new ( ELeave ) CFbsBitmap; |
|
230 User::LeaveIfError( iWidget->Create( TSize(), EColor16MA ) ); |
|
231 |
|
232 iBmpDevice = CFbsBitmapDevice::NewL( iMainpane ); |
|
233 |
|
234 iBmpGc = CFbsBitGc::NewL(); |
|
235 |
|
236 iBmpGc->Activate( iBmpDevice ); |
|
237 |
|
238 iMapGc = CWindowToBitmapMappingGc::NewL( |
|
239 *static_cast< CWsScreenDevice* >( SystemGc().Device() ), *iBmpGc ); |
|
240 |
|
241 SetRect( rect ); |
|
242 } |
|
243 |
|
244 // ----------------------------------------------------------------------------- |
|
245 // CXnEditMode::NewL |
|
246 // Two-phased constructor. |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 CXnEditMode* CXnEditMode::NewL( CXnUiEngine& aEngine ) |
|
250 { |
|
251 CXnEditMode* self = new ( ELeave ) CXnEditMode( aEngine ); |
|
252 CleanupStack::PushL( self ); |
|
253 self->ConstructL(); |
|
254 CleanupStack::Pop( self ); |
|
255 return self; |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CXnEditMode::~CXnEditMode |
|
260 // Destructor |
|
261 // ----------------------------------------------------------------------------- |
|
262 // |
|
263 CXnEditMode::~CXnEditMode() |
|
264 { |
|
265 TRAP_IGNORE( StopDragL() ); |
|
266 |
|
267 delete iMapGc; |
|
268 delete iBmpGc; |
|
269 delete iBmpDevice; |
|
270 delete iMainpane; |
|
271 delete iWidget; |
|
272 } |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // CXnEditMode::UpdateScreen |
|
276 // Updates invalid parts of the screen. All drawing must be done from here |
|
277 // ----------------------------------------------------------------------------- |
|
278 // |
|
279 void CXnEditMode::UpdateScreen() |
|
280 { |
|
281 if ( iState == CXnEditMode::EDragging ) |
|
282 { |
|
283 if ( !iWidget || iDrawPos == TPoint::EUninitialized ) |
|
284 { |
|
285 return; |
|
286 } |
|
287 |
|
288 TRect drawRect( iDrawPos, iWidget->SizeInPixels() ); |
|
289 |
|
290 if ( iLastDrawRect != TRect::EUninitialized ) |
|
291 { |
|
292 drawRect.BoundingRect( iLastDrawRect ); |
|
293 } |
|
294 |
|
295 iLastDrawRect = drawRect; |
|
296 |
|
297 DrawNow( drawRect ); |
|
298 } |
|
299 else |
|
300 { |
|
301 if ( iLastDrawRect != TRect::EUninitialized ) |
|
302 { |
|
303 DrawNow( iLastDrawRect ); |
|
304 } |
|
305 |
|
306 iDrawPos.SetXY( 0, 0 ); |
|
307 iLastDrawRect = TRect::EUninitialized; |
|
308 } |
|
309 } |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CXnEditMode::Draw |
|
313 // |
|
314 // ----------------------------------------------------------------------------- |
|
315 // |
|
316 void CXnEditMode::Draw( const TRect& aRect ) const |
|
317 { |
|
318 CWindowGc& gc( SystemGc() ); |
|
319 |
|
320 gc.SetClippingRect( Rect() ); |
|
321 |
|
322 gc.Clear( aRect ); |
|
323 |
|
324 if ( iWidget && iState == CXnEditMode::EDragging ) |
|
325 { |
|
326 gc.BitBlt( iDrawPos, iWidget ); |
|
327 } |
|
328 |
|
329 gc.Reset(); |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CXnEditMode::MakeVisible |
|
334 // |
|
335 // ----------------------------------------------------------------------------- |
|
336 // |
|
337 void CXnEditMode::MakeVisible( TBool aVisible ) |
|
338 { |
|
339 CXnAppUiAdapter& appui( iUiEngine.AppUiAdapter() ); |
|
340 CXnViewControlAdapter* control = |
|
341 static_cast< CXnViewControlAdapter* >( |
|
342 appui.ViewManager().ActiveViewData().ViewNode()->Control() ); |
|
343 RWindow& window( Window() ); |
|
344 |
|
345 TBool visible( IsVisible() ? ETrue : EFalse ); |
|
346 if ( aVisible == visible ) |
|
347 { |
|
348 if( aVisible ) |
|
349 { |
|
350 // If a new Homescreen page has been added in Edit mode, bring the control back to the front |
|
351 control->DrawableWindow()->SetPointerGrab( EFalse ); |
|
352 |
|
353 window.SetOrdinalPosition( 0 ); |
|
354 window.SetPointerGrab( ETrue ); |
|
355 window.ClaimPointerGrab(); |
|
356 } |
|
357 |
|
358 return; |
|
359 } |
|
360 |
|
361 CCoeControl::MakeVisible( aVisible ); |
|
362 |
|
363 // Remove focus |
|
364 appui.HideFocus(); |
|
365 |
|
366 if ( aVisible ) |
|
367 { |
|
368 control->DrawableWindow()->SetPointerGrab( EFalse ); |
|
369 |
|
370 window.SetOrdinalPosition( 0 ); |
|
371 window.SetPointerGrab( ETrue ); |
|
372 window.ClaimPointerGrab(); |
|
373 |
|
374 TRAP_IGNORE( appui.HandleEnterEditModeL( ETrue ) ); |
|
375 } |
|
376 else |
|
377 { |
|
378 window.SetPointerGrab( EFalse ); |
|
379 |
|
380 control->DrawableWindow()->SetPointerGrab( ETrue ); |
|
381 |
|
382 TRAP_IGNORE( appui.HandleEnterEditModeL( EFalse ) ); |
|
383 } |
|
384 |
|
385 // Update background |
|
386 appui.ViewAdapter().BgManager().DrawNow(); |
|
387 } |
|
388 |
|
389 // ----------------------------------------------------------------------------- |
|
390 // CXnEditMode::HandlePointerEventL |
|
391 // |
|
392 // ----------------------------------------------------------------------------- |
|
393 // |
|
394 void CXnEditMode::HandlePointerEventL( const TPointerEvent& aPointerEvent ) |
|
395 { |
|
396 if ( !AknLayoutUtils::PenEnabled() ) |
|
397 { |
|
398 return; |
|
399 } |
|
400 |
|
401 if ( aPointerEvent.iType != TPointerEvent::EButton1Down && |
|
402 iStylusDownPos == TPoint::EUninitialized ) |
|
403 { |
|
404 return; |
|
405 } |
|
406 |
|
407 // For performance reasons, discard the event if delta between previous |
|
408 // event is within 'KOffset'. |
|
409 TInt KOffset( 5 ); |
|
410 TRect rect( |
|
411 aPointerEvent.iPosition.iX - KOffset, |
|
412 aPointerEvent.iPosition.iY - KOffset, |
|
413 aPointerEvent.iPosition.iX + KOffset, |
|
414 aPointerEvent.iPosition.iY + KOffset ); |
|
415 |
|
416 if ( aPointerEvent.iType == TPointerEvent::EDrag && |
|
417 rect.Contains( iPreviousPos ) ) |
|
418 { |
|
419 return; |
|
420 } |
|
421 |
|
422 RPointerArray< CXnPluginData >& plugins( |
|
423 iViewManager.ActiveViewData().PluginData() ); |
|
424 |
|
425 CXnNode* node( NULL ); |
|
426 |
|
427 for ( TInt i = 0; i < plugins.Count(); i++ ) |
|
428 { |
|
429 CXnPluginData* data( plugins[i] ); |
|
430 |
|
431 CXnNode* plugin( data->Owner()->LayoutNode() ); |
|
432 |
|
433 CXnControlAdapter* ctrl( plugin->Control() ); |
|
434 |
|
435 if ( ctrl->IsVisible() && |
|
436 ctrl->Rect().Contains( aPointerEvent.iPosition ) ) |
|
437 { |
|
438 node = plugin; |
|
439 break; |
|
440 } |
|
441 } |
|
442 |
|
443 if ( !node ) |
|
444 { |
|
445 if ( iTargetNode ) |
|
446 { |
|
447 iTargetNode->UnsetStateL( XnPropertyNames::style::common::KFocus ); |
|
448 } |
|
449 |
|
450 iTargetNode = NULL; |
|
451 } |
|
452 |
|
453 if ( node && node != iTargetNode ) |
|
454 { |
|
455 if ( !node->IsStateSet( XnPropertyNames::style::common::KEdit ) ) |
|
456 { |
|
457 // Not in edit state |
|
458 node = NULL; |
|
459 } |
|
460 else |
|
461 { |
|
462 iTargetNode = node; |
|
463 |
|
464 iUiEngine.DisableRenderUiLC(); |
|
465 |
|
466 if ( aPointerEvent.iType == TPointerEvent::EButton1Down ) |
|
467 { |
|
468 iUiEngine.AppUiAdapter().ShowFocus(); |
|
469 |
|
470 node->SetStateL( XnPropertyNames::style::common::KFocus ); |
|
471 #ifdef RD_TACTILE_FEEDBACK |
|
472 Feedback( ETouchFeedbackBasic ); |
|
473 #endif |
|
474 } |
|
475 else if ( aPointerEvent.iType == TPointerEvent::EDrag ) |
|
476 { |
|
477 if ( iState == CXnEditMode::EDragging ) |
|
478 { |
|
479 node->SetStateL( XnPropertyNames::style::common::KFocus ); |
|
480 #ifdef RD_TACTILE_FEEDBACK |
|
481 Feedback( ETouchFeedbackSensitive ); |
|
482 #endif |
|
483 } |
|
484 else if ( iDraggingNode && |
|
485 !iDraggingNode->MarginRect().Contains( aPointerEvent.iPosition ) ) |
|
486 { |
|
487 iDraggingNode->UnsetStateL( |
|
488 XnPropertyNames::style::common::KFocus ); |
|
489 |
|
490 iDraggingNode = NULL; |
|
491 } |
|
492 } |
|
493 |
|
494 CleanupStack::PopAndDestroy(); |
|
495 } |
|
496 } |
|
497 |
|
498 if ( aPointerEvent.iType == TPointerEvent::EButton1Down ) |
|
499 { |
|
500 iDragged = EFalse; |
|
501 |
|
502 if ( node ) |
|
503 { |
|
504 CXnPluginData* plugin( iUiEngine.ViewManager()-> |
|
505 ActiveViewData().Plugin( node ) ); |
|
506 |
|
507 if ( plugin && plugin->Occupied() ) |
|
508 { |
|
509 StartDragL( *plugin ); |
|
510 |
|
511 iDrawPos = iDraggingNode->BorderRect().iTl; |
|
512 |
|
513 iStylusDownPos = iPreviousPos = aPointerEvent.iPosition; |
|
514 } |
|
515 else |
|
516 { |
|
517 iDraggingNode = node; |
|
518 |
|
519 iStylusDownPos = iPreviousPos = aPointerEvent.iPosition; |
|
520 } |
|
521 } |
|
522 } |
|
523 else if ( aPointerEvent.iType == TPointerEvent::EDrag ) |
|
524 { |
|
525 const TInt KDragTreshold( 30 ); |
|
526 |
|
527 TInt dx( Abs( aPointerEvent.iPosition.iX - iStylusDownPos.iX ) ); |
|
528 TInt dy( Abs( aPointerEvent.iPosition.iY - iStylusDownPos.iY ) ); |
|
529 |
|
530 TBool dragged( iDragged ); |
|
531 |
|
532 if ( dx > KDragTreshold || dy > KDragTreshold ) |
|
533 { |
|
534 iDragged = ETrue; |
|
535 |
|
536 if ( !dragged && iDragged && iDraggingNode && |
|
537 iState == CXnEditMode::EDragging ) |
|
538 { |
|
539 // Hide the node which will be dragged from layout tree |
|
540 SetVisibilityL( *iDraggingNode, |
|
541 XnPropertyNames::style::common::visibility::KHidden ); |
|
542 |
|
543 iUiEngine.RenderUIL(); |
|
544 } |
|
545 } |
|
546 |
|
547 if ( iDragged && iWidget && iDraggingNode && iState == CXnEditMode::EDragging ) |
|
548 { |
|
549 // Resolve draw position |
|
550 TPoint dp( iPreviousPos - aPointerEvent.iPosition ); |
|
551 |
|
552 iDrawPos -= dp; |
|
553 |
|
554 UpdateScreen(); |
|
555 } |
|
556 |
|
557 // Update previous position |
|
558 iPreviousPos = aPointerEvent.iPosition; |
|
559 } |
|
560 else if ( aPointerEvent.iType == TPointerEvent::EButton1Up ) |
|
561 { |
|
562 #ifdef RD_TACTILE_FEEDBACK |
|
563 MTouchFeedback* feedback( MTouchFeedback::Instance() ); |
|
564 feedback->InstantFeedback( this,ETouchFeedbackBasic, |
|
565 ETouchFeedbackVibra, |
|
566 aPointerEvent ); |
|
567 #endif |
|
568 // Cancel |
|
569 if ( !iTargetNode || !iDraggingNode || |
|
570 iDraggingNode == iTargetNode || |
|
571 !iTargetNode->MarginRect().Contains( aPointerEvent.iPosition ) ) |
|
572 { |
|
573 CXnNode* node( iDraggingNode ); |
|
574 |
|
575 iUiEngine.DisableRenderUiLC(); |
|
576 |
|
577 StopDragL(); |
|
578 |
|
579 iUiEngine.RenderUIL(); |
|
580 |
|
581 CleanupStack::PopAndDestroy(); // DisableRenderUiLC |
|
582 |
|
583 UpdateScreen(); |
|
584 |
|
585 if ( node && !iDragged ) |
|
586 { |
|
587 CXnPluginData* plugin( iUiEngine.ViewManager()-> |
|
588 ActiveViewData().Plugin( node ) ); |
|
589 |
|
590 if ( plugin && plugin->Occupied() ) |
|
591 { |
|
592 CXnNode* popup( iUiEngine.StylusPopupNode() ); |
|
593 |
|
594 if ( popup ) |
|
595 { |
|
596 CXnPopupControlAdapter* control = |
|
597 static_cast< CXnPopupControlAdapter* >( |
|
598 popup->Control() ); |
|
599 |
|
600 if ( control ) |
|
601 { |
|
602 control->TryDisplayingStylusPopupL( *node ); |
|
603 } |
|
604 } |
|
605 } |
|
606 else |
|
607 { |
|
608 // empty slot, start add widget query |
|
609 iUiEngine.Editor()->SetTargetPlugin( node ); |
|
610 iUiEngine.Editor()->AddWidgetL(); |
|
611 } |
|
612 } |
|
613 } |
|
614 else // Reorder |
|
615 { |
|
616 if ( iDraggingNode && iTargetNode ) |
|
617 { |
|
618 iUiEngine.DisableRenderUiLC(); |
|
619 |
|
620 CXnNode* parent1( iDraggingNode->Parent() ); |
|
621 CXnNode* parent2( iTargetNode->Parent() ); |
|
622 |
|
623 if ( parent1 == parent2 ) |
|
624 { |
|
625 parent1->ReorderNodesL( iDraggingNode, iTargetNode ); |
|
626 |
|
627 // Update plugin positions to HSPS |
|
628 iUiEngine.Editor()->ReorderWidgetsL( |
|
629 iUiEngine.Plugins() ); |
|
630 } |
|
631 |
|
632 StopDragL(); |
|
633 |
|
634 iUiEngine.RenderUIL(); |
|
635 |
|
636 CleanupStack::PopAndDestroy(); // DisableRenderUiLC |
|
637 |
|
638 UpdateScreen(); |
|
639 } |
|
640 } |
|
641 |
|
642 iUiEngine.AppUiAdapter().HideFocus(); |
|
643 } |
|
644 } |
|
645 |
|
646 // ----------------------------------------------------------------------------- |
|
647 // CXnEditMode::OfferKeyEventL |
|
648 // |
|
649 // ----------------------------------------------------------------------------- |
|
650 // |
|
651 TKeyResponse CXnEditMode::OfferKeyEventL( const TKeyEvent& aKeyEvent, |
|
652 TEventCode aType ) |
|
653 { |
|
654 if ( IsVisible() && aType == EEventKey ) |
|
655 { |
|
656 CXnNode* focused( iUiEngine.FocusedNode() ); |
|
657 |
|
658 if ( focused && ( aKeyEvent.iScanCode == EStdKeyDevice3 || |
|
659 aKeyEvent.iCode == EKeyEnter ) ) |
|
660 { |
|
661 CXnPluginData* plugin( iUiEngine.ViewManager()-> |
|
662 ActiveViewData().Plugin( focused ) ); |
|
663 |
|
664 if ( plugin && plugin->Occupied() ) |
|
665 { |
|
666 // Open context menu |
|
667 CXnNode* menubar( iUiEngine.MenuBarNode() ); |
|
668 |
|
669 if ( menubar ) |
|
670 { |
|
671 HBufC* id( ResolveMenuIdL( *menubar ) ); |
|
672 CleanupStack::PushL( id ); |
|
673 |
|
674 if ( id ) |
|
675 { |
|
676 XnMenuInterface::MXnMenuInterface* menuIf( NULL ); |
|
677 |
|
678 XnComponentInterface::MakeInterfaceL( |
|
679 menuIf, menubar->AppIfL() ); |
|
680 |
|
681 if ( menuIf ) |
|
682 { |
|
683 menuIf->TryDisplayingMenuBarL( *id, ETrue ); |
|
684 iUiEngine.Editor()->SetTargetPlugin( focused ); |
|
685 } |
|
686 } |
|
687 |
|
688 CleanupStack::PopAndDestroy( id ); |
|
689 } |
|
690 } |
|
691 else |
|
692 { |
|
693 // empty slot, start add widget query |
|
694 iUiEngine.Editor()->SetTargetPlugin( focused ); |
|
695 iUiEngine.Editor()->AddWidgetL(); |
|
696 } |
|
697 |
|
698 return EKeyWasConsumed; |
|
699 } |
|
700 } |
|
701 |
|
702 return EKeyWasNotConsumed; |
|
703 } |
|
704 |
|
705 // ----------------------------------------------------------------------------- |
|
706 // CXnEditMode::SizeChanged |
|
707 // |
|
708 // ----------------------------------------------------------------------------- |
|
709 // |
|
710 void CXnEditMode::SizeChanged() |
|
711 { |
|
712 TSize size( Rect().Size() ); |
|
713 |
|
714 iBmpDevice->Resize( size ); |
|
715 |
|
716 // Needs to be called if the device is resized |
|
717 iBmpGc->Resized(); |
|
718 |
|
719 iMainpane->Resize( size ); |
|
720 } |
|
721 |
|
722 // ----------------------------------------------------------------------------- |
|
723 // CXnEditMode::StartDragL() |
|
724 // |
|
725 // ----------------------------------------------------------------------------- |
|
726 // |
|
727 void CXnEditMode::StartDragL( const CXnPluginData& aPlugin ) |
|
728 { |
|
729 CXnNode* node( aPlugin.Owner()->LayoutNode() ); |
|
730 |
|
731 CXnControlAdapter* control( node->Control() ); |
|
732 |
|
733 CXnControlAdapter* parent( |
|
734 aPlugin.Parent()->Node()->LayoutNode()->Control() ); |
|
735 |
|
736 TRect rect( control->Rect() ); |
|
737 |
|
738 // Clear first with alpha |
|
739 TRgb rgb( TRgb::Color16MA( 0 ) ); |
|
740 rgb.SetAlpha( 64 ); |
|
741 |
|
742 iMapGc->SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha ); |
|
743 |
|
744 iMapGc->SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
745 iMapGc->SetBrushColor( rgb ); |
|
746 |
|
747 iMapGc->Clear(); |
|
748 |
|
749 iState = CXnEditMode::EShootContent; |
|
750 |
|
751 CWindowGc* gc( control->CustomGc() ); |
|
752 |
|
753 parent->SetCustomGc( iMapGc ); |
|
754 |
|
755 control->DrawNow( rect ); |
|
756 |
|
757 parent->SetCustomGc( gc ); |
|
758 |
|
759 if ( iWidget->SizeInPixels() != rect.Size() ) |
|
760 { |
|
761 iWidget->Resize( rect.Size() ); |
|
762 } |
|
763 |
|
764 iState = CXnEditMode::EDragging; |
|
765 |
|
766 iDraggingNode = node; |
|
767 |
|
768 User::LeaveIfError( CopyBitmap( *iWidget, *iMainpane, rect.iTl ) ); |
|
769 } |
|
770 |
|
771 // ----------------------------------------------------------------------------- |
|
772 // CXnEditMode::StopDragL() |
|
773 // ----------------------------------------------------------------------------- |
|
774 // |
|
775 void CXnEditMode::StopDragL() |
|
776 { |
|
777 if ( iDraggingNode && iState == CXnEditMode::EDragging ) |
|
778 { |
|
779 SetVisibilityL( *iDraggingNode, |
|
780 XnPropertyNames::style::common::visibility::KVisible ); |
|
781 |
|
782 iDraggingNode->SetStateL( XnPropertyNames::style::common::KFocus ); |
|
783 iDraggingNode->Parent()->SetDirtyL( XnDirtyLevel::ELayoutAndRender ); |
|
784 } |
|
785 |
|
786 iDraggingNode = NULL; |
|
787 iTargetNode = NULL; |
|
788 |
|
789 iPreviousPos.SetXY( 0, 0 ); |
|
790 iStylusDownPos.SetXY( 0, 0 ); |
|
791 |
|
792 iState = CXnEditMode::EDragAndDrop; |
|
793 } |
|
794 |
|
795 // ----------------------------------------------------------------------------- |
|
796 // CXnEditMode::HandleScreenDeviceChangedL |
|
797 // ----------------------------------------------------------------------------- |
|
798 // |
|
799 void CXnEditMode::HandleScreenDeviceChangedL() |
|
800 { |
|
801 if ( iState != CXnEditMode::ENone ) |
|
802 { |
|
803 if ( iState == CXnEditMode::EDragging ) |
|
804 { |
|
805 IgnoreEventsUntilNextPointerUp(); |
|
806 } |
|
807 |
|
808 StopDragL(); |
|
809 } |
|
810 |
|
811 UpdateScreen(); |
|
812 } |
|
813 |
|
814 // ----------------------------------------------------------------------------- |
|
815 // CXnEditMode::HandleScreenDeviceChangedL |
|
816 // ----------------------------------------------------------------------------- |
|
817 // |
|
818 void CXnEditMode::SetClientRect( TRect aRect ) |
|
819 { |
|
820 SetRect( aRect ); |
|
821 } |
|
822 |
|
823 // ----------------------------------------------------------------------------- |
|
824 // CXnEditMode::SetEditModeL() |
|
825 // ----------------------------------------------------------------------------- |
|
826 // |
|
827 void CXnEditMode::SetEditModeL( CXnEditMode::TEditState aState ) |
|
828 { |
|
829 // Enter to edit mode |
|
830 if ( aState == CXnEditMode::EDragAndDrop ) |
|
831 { |
|
832 iState = aState; |
|
833 |
|
834 MakeVisible( ETrue ); |
|
835 } |
|
836 |
|
837 // Exit from edit mode |
|
838 else if ( aState == CXnEditMode::ENone ) |
|
839 { |
|
840 iDraggingNode = NULL; |
|
841 iTargetNode = NULL; |
|
842 |
|
843 iUiEngine.Editor()->SetTargetPlugin( NULL ); |
|
844 |
|
845 iState = aState; |
|
846 |
|
847 MakeVisible( EFalse ); |
|
848 } |
|
849 } |
|
850 |
|
851 // ----------------------------------------------------------------------------- |
|
852 // CXnEditMode::EditState() |
|
853 // |
|
854 // ----------------------------------------------------------------------------- |
|
855 // |
|
856 CXnEditMode::TEditState CXnEditMode::EditState() const |
|
857 { |
|
858 return iState; |
|
859 } |
|
860 |
|
861 // ----------------------------------------------------------------------------- |
|
862 // CXnEditMode::StopDraggingL() |
|
863 // ----------------------------------------------------------------------------- |
|
864 // |
|
865 void CXnEditMode::StopDraggingL() |
|
866 { |
|
867 if( iState == CXnEditMode::EDragging ) |
|
868 { |
|
869 StopDragL(); |
|
870 UpdateScreen(); |
|
871 } |
|
872 } |
|
873 |
|
874 // End of file |