idlehomescreen/xmluirendering/uiengine/src/xneditmode.cpp
changeset 0 f72a12da539e
child 2 08c6ee43b396
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     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 <akntitle.h>
       
    22 #include <barsread.h>
       
    23 #include <xnuiengine.rsg>
       
    24 
       
    25 #ifdef RD_TACTILE_FEEDBACK
       
    26 #include <touchfeedback.h>
       
    27 #endif // RD_TACTILE_FEEDBACK
       
    28 
       
    29 // User includes
       
    30 #include "xnappuiadapter.h"
       
    31 #include "xnviewmanager.h"
       
    32 #include "xnviewadapter.h"
       
    33 #include "xnviewdata.h"
       
    34 #include "xnnodeimpl.h"
       
    35 #include "xndomnode.h"
       
    36 #include "xnnode.h"
       
    37 #include "xnproperty.h"
       
    38 #include "xnuiengine.h"
       
    39 #include "xncontroladapter.h"
       
    40 #include "xnpopupcontroladapter.h"
       
    41 #include "xnfocuscontrol.h"
       
    42 #include "xneditor.h"
       
    43 #include "xntype.h"
       
    44 #include "xnmenu.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 = TPoint::EUninitialized;
       
   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     TBool visible( IsVisible() ? ETrue : EFalse );
       
   340     
       
   341     if ( aVisible == visible )
       
   342         {
       
   343         return;
       
   344         }
       
   345         
       
   346     CCoeControl::MakeVisible( aVisible );
       
   347 
       
   348     CXnAppUiAdapter& appui( iUiEngine.AppUiAdapter() );
       
   349     
       
   350     // Remove focus
       
   351     appui.HideFocus();
       
   352     
       
   353     CCoeControl& bg( appui.ViewAdapter().BgControl() );
       
   354     
       
   355     if ( aVisible )
       
   356         {
       
   357         bg.DrawableWindow()->SetPointerGrab( EFalse );
       
   358         
       
   359         Window().SetOrdinalPosition( 0 );
       
   360         Window().SetPointerGrab( ETrue );
       
   361         Window().ClaimPointerGrab();               
       
   362         }
       
   363     else
       
   364         {
       
   365         Window().SetPointerGrab( EFalse );
       
   366         
       
   367         bg.DrawableWindow()->SetPointerGrab( ETrue );               
       
   368         }
       
   369     }
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CXnEditMode::HandlePointerEventL
       
   373 //
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 void CXnEditMode::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   377     {
       
   378     if ( !AknLayoutUtils::PenEnabled() )         
       
   379         {
       
   380         return;
       
   381         }
       
   382     
       
   383     if ( aPointerEvent.iType != TPointerEvent::EButton1Down &&
       
   384         iStylusDownPos == TPoint::EUninitialized )
       
   385         {
       
   386         return;
       
   387         }
       
   388     
       
   389     // For performance reasons, discard the event if delta between previous
       
   390     // event is within 'KOffset'.
       
   391     TInt KOffset( 5 );
       
   392     TRect rect(
       
   393         aPointerEvent.iPosition.iX - KOffset,
       
   394         aPointerEvent.iPosition.iY - KOffset,
       
   395         aPointerEvent.iPosition.iX + KOffset,
       
   396         aPointerEvent.iPosition.iY + KOffset );
       
   397         
       
   398     if ( aPointerEvent.iType == TPointerEvent::EDrag && 
       
   399         rect.Contains( iPreviousPos ) )
       
   400         {   
       
   401         return;                 
       
   402         }
       
   403     
       
   404     RPointerArray< CXnPluginData >& plugins( 
       
   405         iViewManager.ActiveViewData().PluginData() );
       
   406             
       
   407     CXnNode* node( NULL );
       
   408     
       
   409     for ( TInt i = 0; i < plugins.Count(); i++ )
       
   410         {   
       
   411         CXnPluginData* data( plugins[i] );
       
   412         
       
   413         CXnNode* plugin( data->Owner()->LayoutNode() );
       
   414         
       
   415         CXnControlAdapter* ctrl( plugin->Control() );
       
   416 
       
   417         if ( ctrl->IsVisible() && 
       
   418             ctrl->Rect().Contains( aPointerEvent.iPosition ) )        
       
   419             {                      
       
   420             node = plugin;
       
   421             break;
       
   422             }
       
   423         }
       
   424     
       
   425     if ( !node )
       
   426         {
       
   427         if ( iTargetNode )
       
   428             {
       
   429             iTargetNode->UnsetStateL( XnPropertyNames::style::common::KFocus );
       
   430             }
       
   431         
       
   432         iTargetNode = NULL;
       
   433         }
       
   434                
       
   435     if ( node && node != iTargetNode )
       
   436         {
       
   437         if ( !node->IsStateSet( XnPropertyNames::style::common::KEdit ) )
       
   438             {
       
   439             // Not in edit state
       
   440             node = NULL;
       
   441             }
       
   442         else
       
   443             {
       
   444             iTargetNode = node;
       
   445 
       
   446             iUiEngine.DisableRenderUiLC();
       
   447             
       
   448             if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   449                 {
       
   450                 iUiEngine.AppUiAdapter().ShowFocus();
       
   451                 
       
   452                 node->SetStateL( XnPropertyNames::style::common::KFocus );
       
   453 #ifdef RD_TACTILE_FEEDBACK                
       
   454                 Feedback( ETouchFeedbackBasic );
       
   455 #endif
       
   456                 }
       
   457             else if ( aPointerEvent.iType == TPointerEvent::EDrag )                     
       
   458                {
       
   459                if ( iState == CXnEditMode::EDragging )
       
   460                    {
       
   461                    node->SetStateL( XnPropertyNames::style::common::KFocus );               
       
   462     #ifdef RD_TACTILE_FEEDBACK               
       
   463                     Feedback( ETouchFeedbackSensitive );
       
   464     #endif                                   
       
   465                    }
       
   466                else if ( iDraggingNode && 
       
   467                    !iDraggingNode->MarginRect().Contains( aPointerEvent.iPosition ) )
       
   468                    {
       
   469                    iDraggingNode->UnsetStateL( 
       
   470                        XnPropertyNames::style::common::KFocus );
       
   471                    
       
   472                    iDraggingNode = NULL;
       
   473                    }                             
       
   474                }     
       
   475             
       
   476             CleanupStack::PopAndDestroy();
       
   477             }
       
   478         }
       
   479         
       
   480     if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   481         {        
       
   482         iDragged = EFalse;
       
   483                
       
   484         if ( node )
       
   485             {
       
   486             CXnPluginData& plugin( iUiEngine.ViewManager()->
       
   487                     ActiveViewData().Plugin( node ) );
       
   488             
       
   489             if ( plugin.Occupied() )
       
   490                 {
       
   491                 StartDragL( *node );
       
   492                                   
       
   493                 iDrawPos = iDraggingNode->BorderRect().iTl;
       
   494                 
       
   495                 iStylusDownPos = iPreviousPos = aPointerEvent.iPosition;
       
   496                 }  
       
   497             else
       
   498                 {
       
   499                 iDraggingNode = node;
       
   500                 
       
   501                 iStylusDownPos = iPreviousPos = aPointerEvent.iPosition;
       
   502                 }
       
   503             }
       
   504         }
       
   505     else if ( aPointerEvent.iType == TPointerEvent::EDrag )
       
   506         {
       
   507         const TInt KDragTreshold( 30 );
       
   508         
       
   509         TInt dx( Abs( aPointerEvent.iPosition.iX - iStylusDownPos.iX ) );
       
   510         TInt dy( Abs( aPointerEvent.iPosition.iY - iStylusDownPos.iY ) );
       
   511         
       
   512         TBool dragged( iDragged );
       
   513         
       
   514         if ( dx > KDragTreshold || dy > KDragTreshold )
       
   515             {
       
   516             iDragged = ETrue;
       
   517             
       
   518             if ( !dragged && iDragged && iDraggingNode && 
       
   519                 iState == CXnEditMode::EDragging )
       
   520                 {
       
   521                 // Hide the node which will be dragged from layout tree 
       
   522                 SetVisibilityL( *iDraggingNode,
       
   523                     XnPropertyNames::style::common::visibility::KHidden );
       
   524                 
       
   525                 iUiEngine.RenderUIL();                
       
   526                 }
       
   527             }
       
   528         
       
   529         if ( iDragged && iWidget && iDraggingNode && iState == CXnEditMode::EDragging )
       
   530             {                        
       
   531             // Resolve draw position
       
   532             TPoint dp( iPreviousPos - aPointerEvent.iPosition );
       
   533                                 
       
   534             iDrawPos -= dp;
       
   535                     
       
   536             // Update previous position
       
   537             iPreviousPos = aPointerEvent.iPosition;
       
   538             
       
   539             UpdateScreen();
       
   540             }
       
   541         }
       
   542     else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   543         {                                                                          
       
   544         // Cancel
       
   545         if ( !iTargetNode || !iDraggingNode ||                 
       
   546              iDraggingNode == iTargetNode ||
       
   547              !iTargetNode->MarginRect().Contains( aPointerEvent.iPosition ) )
       
   548             {                                
       
   549             CXnNode* node( iDraggingNode );
       
   550             
       
   551             iUiEngine.DisableRenderUiLC();
       
   552             
       
   553             StopDragL();
       
   554             
       
   555             iUiEngine.RenderUIL();
       
   556             
       
   557             CleanupStack::PopAndDestroy(); // DisableRenderUiLC
       
   558             
       
   559             UpdateScreen();
       
   560                         
       
   561             if ( node && !iDragged )
       
   562                 {
       
   563                 CXnPluginData& plugin( iUiEngine.ViewManager()->
       
   564                         ActiveViewData().Plugin( node ) );
       
   565 
       
   566                 if ( plugin.Occupied() )
       
   567                     {
       
   568                     CXnNode* popup( iUiEngine.StylusPopupNode() );
       
   569                     
       
   570                     if ( popup )
       
   571                         {
       
   572                         CXnPopupControlAdapter* control =
       
   573                             static_cast< CXnPopupControlAdapter* >(
       
   574                                     popup->Control() );
       
   575                        
       
   576                         if ( control )
       
   577                             {
       
   578                             control->TryDisplayingStylusPopupL( *node );
       
   579                             }
       
   580                         }
       
   581                     }
       
   582                 else
       
   583                     {
       
   584                     // empty slot, start add widget query
       
   585                     iUiEngine.Editor()->SetTargetPlugin( node );
       
   586                     iUiEngine.Editor()->AddWidgetL();
       
   587                     }
       
   588                 }
       
   589             }            
       
   590         else // Reorder
       
   591             {
       
   592             if ( iDraggingNode && iTargetNode )
       
   593                 {
       
   594                 iUiEngine.DisableRenderUiLC();
       
   595                 
       
   596                 CXnNode* parent1( iDraggingNode->Parent() );
       
   597                 CXnNode* parent2( iTargetNode->Parent() );
       
   598                 
       
   599                 if ( parent1 == parent2 )
       
   600                     {
       
   601                     parent1->ReorderNodesL( iDraggingNode, iTargetNode );
       
   602                     
       
   603                     // Update plugin positions to HSPS
       
   604                     iUiEngine.Editor()->ReorderWidgetsL( 
       
   605                             iUiEngine.Plugins() );                    
       
   606                     }
       
   607                                                
       
   608                 StopDragL();
       
   609                 
       
   610                 iUiEngine.RenderUIL();
       
   611                 
       
   612                 CleanupStack::PopAndDestroy(); // DisableRenderUiLC
       
   613                 
       
   614                 UpdateScreen();                    
       
   615                 }
       
   616             }
       
   617         
       
   618         iUiEngine.AppUiAdapter().HideFocus();
       
   619         }    
       
   620     }
       
   621 
       
   622 // -----------------------------------------------------------------------------
       
   623 // CXnEditMode::OfferKeyEventL
       
   624 //
       
   625 // -----------------------------------------------------------------------------
       
   626 //
       
   627 TKeyResponse CXnEditMode::OfferKeyEventL( const TKeyEvent& aKeyEvent, 
       
   628     TEventCode aType )
       
   629     {    
       
   630     if ( IsVisible() && aType == EEventKey )
       
   631         {
       
   632         CXnNode* focused( iUiEngine.FocusedNode() );
       
   633         
       
   634         if ( focused && ( aKeyEvent.iScanCode == EStdKeyDevice3 ||
       
   635             aKeyEvent.iScanCode == EStdKeyEnter ) )
       
   636             {
       
   637             CXnPluginData& plugin( iUiEngine.ViewManager()->
       
   638                     ActiveViewData().Plugin( focused ) );
       
   639             
       
   640             if ( plugin.Occupied() )
       
   641                 {
       
   642                 // Open context menu
       
   643                 CXnNode* menubar( iUiEngine.MenuBarNode() );
       
   644                 
       
   645                 if ( menubar )
       
   646                     {
       
   647                     HBufC* id( ResolveMenuIdL( *menubar ) );
       
   648                     CleanupStack::PushL( id );
       
   649                     
       
   650                     if ( id )
       
   651                         {
       
   652                         XnMenuInterface::MXnMenuInterface* menuIf( NULL );
       
   653                         
       
   654                         XnComponentInterface::MakeInterfaceL( 
       
   655                             menuIf, menubar->AppIfL() );
       
   656                         
       
   657                         if ( menuIf )
       
   658                             {
       
   659                             menuIf->TryDisplayingMenuBarL( *id );
       
   660                             iUiEngine.Editor()->SetTargetPlugin( focused );
       
   661                             }                        
       
   662                         }
       
   663                     
       
   664                     CleanupStack::PopAndDestroy( id );
       
   665                     }                                               
       
   666                 }
       
   667             else
       
   668                 {
       
   669                 // empty slot, start add widget query
       
   670                 iUiEngine.Editor()->SetTargetPlugin( focused );
       
   671                 iUiEngine.Editor()->AddWidgetL();                
       
   672                 } 
       
   673             
       
   674             return EKeyWasConsumed;
       
   675             }
       
   676         }
       
   677     
       
   678     return EKeyWasNotConsumed;
       
   679     }
       
   680 
       
   681 // -----------------------------------------------------------------------------
       
   682 // CXnEditMode::SizeChanged
       
   683 //
       
   684 // -----------------------------------------------------------------------------
       
   685 //
       
   686 void CXnEditMode::SizeChanged()
       
   687     {
       
   688     TSize size( Rect().Size() );
       
   689     
       
   690     iBmpDevice->Resize( size );
       
   691     
       
   692     // Needs to be called if the device is resized
       
   693     iBmpGc->Resized();
       
   694     
       
   695     iMainpane->Resize( size );    
       
   696     }
       
   697 
       
   698 // -----------------------------------------------------------------------------
       
   699 // CXnEditMode::StartDragL()
       
   700 //
       
   701 // -----------------------------------------------------------------------------
       
   702 //
       
   703 void CXnEditMode::StartDragL( CXnNode& aNode )
       
   704     {  
       
   705     CXnControlAdapter* control( aNode.Control() );
       
   706     
       
   707     TRect rect( control->Rect() );
       
   708     
       
   709     // Clear first with alpha 
       
   710     TRgb rgb( TRgb::Color16MA( 0 ) );
       
   711     rgb.SetAlpha( 64 );
       
   712         
       
   713     iMapGc->SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
   714     
       
   715     iMapGc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   716     iMapGc->SetBrushColor( rgb );
       
   717     
       
   718     iMapGc->Clear( rect );
       
   719                          
       
   720     iState = CXnEditMode::EShootContent;
       
   721         
       
   722     CWindowGc* gc( control->CustomGc() );
       
   723             
       
   724     control->SetCustomGc( iMapGc );
       
   725     
       
   726     control->DrawNow( rect );
       
   727         
       
   728     control->SetCustomGc( gc );
       
   729            
       
   730     if ( iWidget->SizeInPixels() != rect.Size() )
       
   731         {
       
   732         iWidget->Resize( rect.Size() );
       
   733         }
       
   734     
       
   735     User::LeaveIfError( CopyBitmap( *iWidget, *iMainpane, rect.iTl ) );
       
   736 
       
   737     iState = CXnEditMode::EDragging;
       
   738         
       
   739     iDraggingNode = &aNode;       
       
   740     }
       
   741 
       
   742 // -----------------------------------------------------------------------------
       
   743 // CXnEditMode::StopDragL()
       
   744 // -----------------------------------------------------------------------------
       
   745 //
       
   746 void CXnEditMode::StopDragL()
       
   747     {
       
   748     if ( iDraggingNode && iState == CXnEditMode::EDragging )
       
   749         {
       
   750         SetVisibilityL( *iDraggingNode,
       
   751             XnPropertyNames::style::common::visibility::KVisible );
       
   752                         
       
   753         iDraggingNode->SetStateL( XnPropertyNames::style::common::KFocus );
       
   754         iDraggingNode->Parent()->SetDirtyL( XnDirtyLevel::ELayoutAndRender );
       
   755         }
       
   756 
       
   757     iDraggingNode = iTargetNode = NULL;
       
   758      
       
   759     iPreviousPos = iStylusDownPos = TPoint::EUninitialized;
       
   760     
       
   761     iState = CXnEditMode::EDragAndDrop;
       
   762     }
       
   763 
       
   764 // -----------------------------------------------------------------------------
       
   765 // CXnEditMode::HandleScreenDeviceChangedL
       
   766 // -----------------------------------------------------------------------------
       
   767 //
       
   768 void CXnEditMode::HandleScreenDeviceChangedL()
       
   769     {
       
   770     if ( iState != CXnEditMode::ENone )
       
   771         {
       
   772         if ( iState == CXnEditMode::EDragging )
       
   773             {
       
   774             IgnoreEventsUntilNextPointerUp();
       
   775             }
       
   776         
       
   777         StopDragL();               
       
   778         }
       
   779 
       
   780     SetRect( iUiEngine.ClientRect() );
       
   781                        
       
   782     UpdateScreen();
       
   783     }
       
   784 
       
   785 // -----------------------------------------------------------------------------
       
   786 // CXnEditMode::SetEditModeL()
       
   787 // -----------------------------------------------------------------------------
       
   788 //
       
   789 void CXnEditMode::SetEditModeL( CXnEditMode::TEditState aState )
       
   790     {    
       
   791     // Enter to edit mode
       
   792     if ( aState == CXnEditMode::EDragAndDrop )
       
   793         {               
       
   794         iState = aState;
       
   795         
       
   796         iUiEngine.AppUiAdapter().HandleEnterEditModeL( ETrue );
       
   797         SetStatusPaneTitleL();
       
   798         
       
   799         MakeVisible( ETrue );               
       
   800         }
       
   801 
       
   802     // Exit from edit mode
       
   803     else if ( aState == CXnEditMode::ENone )
       
   804         {                
       
   805         iDraggingNode = NULL;
       
   806         iTargetNode = NULL;
       
   807         
       
   808         iState = aState;
       
   809                        
       
   810         iUiEngine.AppUiAdapter().HandleEnterEditModeL( EFalse );
       
   811         
       
   812         MakeVisible( EFalse );
       
   813         }   
       
   814     }
       
   815 
       
   816 // -----------------------------------------------------------------------------
       
   817 // CXnEditMode::EditState()
       
   818 //
       
   819 // -----------------------------------------------------------------------------
       
   820 //
       
   821 CXnEditMode::TEditState CXnEditMode::EditState() const
       
   822     {
       
   823     return iState;
       
   824     }
       
   825 
       
   826 // -----------------------------------------------------------------------------
       
   827 // CXnEditMode::SetStatusPaneTitleL()
       
   828 // -----------------------------------------------------------------------------
       
   829 //
       
   830 void CXnEditMode::SetStatusPaneTitleL()
       
   831     {
       
   832     TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
       
   833     CEikStatusPaneBase::TPaneCapabilities subPaneTitle = 
       
   834         iUiEngine.AppUiAdapter().StatusPane()->PaneCapabilities( titlePaneUid );
       
   835     if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
       
   836         {
       
   837         CAknTitlePane* title = static_cast< CAknTitlePane* >( 
       
   838             iUiEngine.AppUiAdapter().StatusPane()->ControlL( titlePaneUid ) );
       
   839         TResourceReader reader;
       
   840         CEikonEnv::Static()->CreateResourceReaderLC(
       
   841                 reader, R_QTN_HS_TITLE_EDITMODE );
       
   842         title->SetFromResourceL( reader );
       
   843         CleanupStack::PopAndDestroy(); // reader internal state
       
   844         }
       
   845     }
       
   846 
       
   847 // End of file