idlehomescreen/xmluirendering/uiengine/src/xnwidgetextensionadapter.cpp
branchRCL_3
changeset 9 f966699dea19
parent 5 c743ef5928ba
child 15 ff572dfe6d86
equal deleted inserted replaced
5:c743ef5928ba 9:f966699dea19
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 */
    14 */
    15 
    15 
    16 
    16 // System includes
    17 #include <e32base.h>
    17 #include <e32base.h>
    18 #include <e32const.h>
    18 #include <e32const.h>
    19 #include <coecntrl.h>
    19 #include <coecntrl.h>
    20 #include <coemain.h>
    20 #include <coemain.h>
    21 
       
    22 #include <AknUtils.h>
    21 #include <AknUtils.h>
    23 
    22 
       
    23 // User includes
    24 #include "xnwidgetextensionadapter.h"
    24 #include "xnwidgetextensionadapter.h"
    25 #include "xncontroladapter.h"
    25 #include "xncontroladapter.h"
    26 
    26 
    27 #include "xncomponentnodeimpl.h"
    27 #include "xncomponentnodeimpl.h"
    28 #include "xncomponent.h"
    28 #include "xncomponent.h"
    44 #include "xnappuiadapter.h"
    44 #include "xnappuiadapter.h"
    45 #include "xnviewmanager.h"
    45 #include "xnviewmanager.h"
    46 #include "xnviewdata.h"
    46 #include "xnviewdata.h"
    47 #include "xnplugindata.h"
    47 #include "xnplugindata.h"
    48 
    48 
    49 
    49 // Constants
    50 _LIT8( KPopUpText, "popup" );
    50 _LIT8( KPopup, "popup" );
    51 _LIT8( KPositionHint, "_s60-position-hint" );
    51 _LIT8( KPositionHint, "_s60-position-hint" );
    52 _LIT8( KWidgetNodeName, "widget" );
    52 _LIT8( KWidgetNodeName, "widget" );
    53 _LIT8( KParentIdName, "parentid" );
    53 _LIT8( KParentIdName, "parentid" );
    54 _LIT8( KDisplay, "display" );
    54 _LIT8( KDisplay, "display" );
    55 _LIT8( KNone, "none" );
    55 _LIT8( KNone, "none" );
       
    56 
    56 // ============================ MEMBER FUNCTIONS ===============================
    57 // ============================ MEMBER FUNCTIONS ===============================
    57 
    58 
    58 // -----------------------------------------------------------------------------
    59 // -----------------------------------------------------------------------------
    59 // CXnWidgetExtensionAdapter::NewL
    60 // CXnWidgetExtensionAdapter::NewL
    60 // Two-phased constructor. Can leave.
    61 // Two-phased constructor. Can leave.
    76 // Destructor.
    77 // Destructor.
    77 // -----------------------------------------------------------------------------
    78 // -----------------------------------------------------------------------------
    78 //
    79 //
    79 CXnWidgetExtensionAdapter::~CXnWidgetExtensionAdapter()
    80 CXnWidgetExtensionAdapter::~CXnWidgetExtensionAdapter()
    80     {
    81     {
       
    82     if ( iAppUiAdapter )
       
    83         {
       
    84         iAppUiAdapter->UiStateListener().RemoveObserver( *this );
       
    85         }
    81     }
    86     }
    82 
    87 
    83 // -----------------------------------------------------------------------------
    88 // -----------------------------------------------------------------------------
    84 // CXnWidgetExtensionAdapter::CXnWidgetExtensionAdapter
    89 // CXnWidgetExtensionAdapter::CXnWidgetExtensionAdapter
    85 // C++ default constructor. Must not leave.
    90 // C++ default constructor. Must not leave.
    95 // 2nd phase constructor. Can leave.
   100 // 2nd phase constructor. Can leave.
    96 // -----------------------------------------------------------------------------
   101 // -----------------------------------------------------------------------------
    97 //    
   102 //    
    98 void CXnWidgetExtensionAdapter::ConstructL()
   103 void CXnWidgetExtensionAdapter::ConstructL()
    99     {
   104     {
       
   105     iAppUiAdapter = static_cast< CXnAppUiAdapter* >( iAvkonAppUi );
       
   106     
   100     CreateWindowL();
   107     CreateWindowL();
       
   108     
   101     Window().SetRequiredDisplayMode( EColor16MA );
   109     Window().SetRequiredDisplayMode( EColor16MA );
   102 
   110 
   103     // this adapter handles both widgetextension and popup nodes
   111     // this adapter handles both widgetextension and popup nodes
   104     // we have to decide which one of them is the recent one    
   112     // we have to decide which one of them is the recent one    
   105  
   113  
   106     CXnType* typeInfo = iNode.Node().Type();
   114     CXnType* typeInfo = iNode.Node().Type();
   107     const TDesC8& type = typeInfo->Type();
   115     const TDesC8& type = typeInfo->Type();
   108 
   116 
   109     if ( ( type != KPopUpText ) &&
   117     if ( type == KPopup )          
   110          ( Window().SetTransparencyAlphaChannel() == KErrNone ) )
   118         {
   111         {
   119         CXnProperty* prop( iNode.Node().GetPropertyL( 
   112         Window().SetBackgroundColor( ~0 );     
   120             XnPropertyNames::popup::KPopupType ) );
   113         }
   121                        
       
   122         if ( prop && prop->StringValue() == 
       
   123             XnPropertyNames::popup::popuptype::KPermanent )
       
   124             {
       
   125             iPermanent = ETrue;
       
   126             }        
       
   127         }
       
   128     else
       
   129         {
       
   130         if ( Window().SetTransparencyAlphaChannel() == KErrNone )
       
   131             {
       
   132             Window().SetBackgroundColor( ~0 );
       
   133             }                     
       
   134         }
       
   135     
   114     iUiEngine = iNode.Node().UiEngine();
   136     iUiEngine = iNode.Node().UiEngine();
   115     CXnControlAdapter::ConstructL( iNode );
   137     CXnControlAdapter::ConstructL( iNode );
   116     EnableDragEvents();   
   138     
   117 
   139     EnableDragEvents();      
   118     iAppUiAdapter = static_cast< CXnAppUiAdapter* >( iAvkonAppUi );
       
   119 
       
   120     }
   140     }
   121 
   141 
   122 // -----------------------------------------------------------------------------
   142 // -----------------------------------------------------------------------------
   123 // CXnWidgetExtensionAdapter::MakeVisible
   143 // CXnWidgetExtensionAdapter::MakeVisible
   124 // 
   144 // 
   125 // -----------------------------------------------------------------------------
   145 // -----------------------------------------------------------------------------
   126 // 
   146 // 
   127 void CXnWidgetExtensionAdapter::MakeVisible( TBool aVisible )
   147 void CXnWidgetExtensionAdapter::MakeVisible( TBool aVisible )
   128     {
   148     {   
   129    
       
   130     TBool visible( IsVisible() ? ETrue : EFalse );
   149     TBool visible( IsVisible() ? ETrue : EFalse );
       
   150     
   131     if ( visible == aVisible )
   151     if ( visible == aVisible )
   132         {
   152         {
   133         return;
   153         return;
   134         }
   154         }
   135 
   155 
   141     plugin.SetIsDisplayingPopup( aVisible, &iNode.Node() );
   161     plugin.SetIsDisplayingPopup( aVisible, &iNode.Node() );
   142     
   162     
   143     CXnType* typeInfo = iNode.Node().Type();
   163     CXnType* typeInfo = iNode.Node().Type();
   144     const TDesC8& type = typeInfo->Type();
   164     const TDesC8& type = typeInfo->Type();
   145 
   165 
   146     if ( type != KPopUpText )
   166     TBool popup( type == KPopup );
       
   167     
       
   168     if ( !popup )
   147         {
   169         {
   148         DrawableWindow()->FadeBehind( aVisible );
   170         DrawableWindow()->FadeBehind( aVisible );
   149         }
   171         }
   150     
   172     else
   151     if ( aVisible && type == KPopUpText )
   173         {
       
   174         if ( !iPermanent )
       
   175             {
       
   176             if ( aVisible )
       
   177                 {
       
   178                 iAppUiAdapter->UiStateListener().AddObserver( *this );
       
   179                 }
       
   180             else
       
   181                 {
       
   182                 iAppUiAdapter->UiStateListener().RemoveObserver( *this );
       
   183                 }            
       
   184             }
       
   185         }
       
   186     
       
   187     if ( aVisible && popup )
   152         {        
   188         {        
   153         // read position-hint property and set-up its variable
   189         // read position-hint property and set-up its variable
   154         CXnProperty* positionHintProp = NULL;
   190         CXnProperty* positionHintProp = NULL;
   155         TRAP_IGNORE( positionHintProp = iNode.Node().GetPropertyL( KPositionHint ) );
   191         TRAP_IGNORE( positionHintProp = iNode.Node().GetPropertyL( KPositionHint ) );
   156                    
   192                    
   212 // 
   248 // 
   213 // -----------------------------------------------------------------------------
   249 // -----------------------------------------------------------------------------
   214 //    
   250 //    
   215 void CXnWidgetExtensionAdapter::HandlePointerEventL( 
   251 void CXnWidgetExtensionAdapter::HandlePointerEventL( 
   216     const TPointerEvent& aPointerEvent )
   252     const TPointerEvent& aPointerEvent )
   217     {    
   253     {        
   218     
       
   219     CXnType* typeInfo = iNode.Node().Type();
   254     CXnType* typeInfo = iNode.Node().Type();
   220     const TDesC8& type = typeInfo->Type();
   255     const TDesC8& type = typeInfo->Type();
   221     
   256     
   222     // in case of popup, we have to make sure that 
   257     // in case of popup, we have to make sure that 
   223     // it will be closed after tapping outside of the
   258     // it will be closed after tapping outside of the
   224     // area of itself and its parent
   259     // area of itself and its parent
   225     if ( type == KPopUpText )
   260     if ( type == KPopup )
   226         {
   261         {        
   227         
       
   228         // check if the tap was inside of popup
   262         // check if the tap was inside of popup
   229         TRect popupRect = this->Rect();
   263         TRect popupRect = this->Rect();
   230         popupRect.Move(this->Position() );
   264         popupRect.Move(this->Position() );
   231         TBool isInPopupWindow = popupRect.Contains(
   265         TBool isInPopupWindow = popupRect.Contains(
   232                 aPointerEvent.iParentPosition );
   266                 aPointerEvent.iParentPosition );
   233 
   267 
   234         if ( !isInPopupWindow )
   268         if ( !isInPopupWindow )
   235             {
   269             {            
   236             
       
   237             // if tap was outside of window, check if tap was 
   270             // if tap was outside of window, check if tap was 
   238             // inside of the parrent
   271             // inside of the parrent
   239             CXnProperty* parentIdProp = iNode.Node().GetPropertyL(
   272             CXnProperty* parentIdProp( iNode.Node().GetPropertyL(
   240                     KParentIdName );
   273                     KParentIdName ) );
   241             
   274             
   242             if ( parentIdProp )
   275             if ( parentIdProp )
   243                 {                
   276                 {                
   244                 const TDesC8& parentIdVal = parentIdProp->StringValue();
   277                 const TDesC8& parentIdVal = parentIdProp->StringValue();
   245                 CXnNode* parentN(iUiEngine->FindNodeByIdL( parentIdVal,
   278                 CXnNode* parentN(iUiEngine->FindNodeByIdL( parentIdVal,
   256                         {
   289                         {
   257                         // tap was neither in popup nor in its parent -
   290                         // tap was neither in popup nor in its parent -
   258                         // we can close it
   291                         // we can close it
   259                         if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
   292                         if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
   260                             {
   293                             {
   261                             CXnDomStringPool* sp =
   294                             HidePopupL();
   262                                 iNode.Node().DomNode()->StringPool();
       
   263                             CXnProperty* prop = CXnProperty::NewL( KDisplay, KNone,
       
   264                             CXnDomPropertyValue::EString, *sp );
       
   265                             CleanupStack::PushL( prop );
       
   266                             iNode.Node().SetPropertyL( prop );
       
   267                             CleanupStack::Pop( prop );
       
   268                             return;
   295                             return;
   269                             }
   296                             }
   270                         }
   297                         }
   271                     else
   298                     else
   272                         {
   299                         {
   280                         parentN->Control()->HandlePointerEventL( newPointerEvent );
   307                         parentN->Control()->HandlePointerEventL( newPointerEvent );
   281                         return;
   308                         return;
   282                         }
   309                         }
   283                     }
   310                     }
   284                 }
   311                 }
       
   312             else
       
   313                 {
       
   314                 HidePopupL();
       
   315                 }
   285             }
   316             }
   286         }
   317         }
   287     
   318     
   288     CXnControlAdapter::HandlePointerEventL( aPointerEvent );
   319     CXnControlAdapter::HandlePointerEventL( aPointerEvent );    
   289     
       
   290     }
   320     }
   291 
   321 
   292 // -----------------------------------------------------------------------------
   322 // -----------------------------------------------------------------------------
   293 // CXnWidgetExtensionAdapter::Draw
   323 // CXnWidgetExtensionAdapter::Draw
   294 // 
   324 // 
   295 // -----------------------------------------------------------------------------
   325 // -----------------------------------------------------------------------------
   296 //    
   326 //    
   297 void CXnWidgetExtensionAdapter::Draw( const TRect& aRect ) const
   327 void CXnWidgetExtensionAdapter::Draw( const TRect& aRect ) const
   298     {
   328     {
   299         CXnControlAdapter::Draw( aRect );
   329     CXnControlAdapter::Draw( aRect );
   300     }
   330     }
   301 
   331 
   302 // -----------------------------------------------------------------------------
   332 // -----------------------------------------------------------------------------
   303 // CalculatePosition
   333 // CalculatePosition
   304 // This is used only for popup element with position hint
   334 // This is used only for popup element with position hint
   305 // -----------------------------------------------------------------------------
   335 // -----------------------------------------------------------------------------
   306 void CXnWidgetExtensionAdapter::CalculatePosition() 
   336 void CXnWidgetExtensionAdapter::CalculatePosition() 
   307     {
   337     {
   308 
       
   309     // widget's rectangle
   338     // widget's rectangle
   310     TRect controlRect;
   339     TRect controlRect;
   311 
   340 
   312     // get popup's window size
   341     // get popup's window size
   313     TRect popupRect = this->Rect();
   342     TRect popupRect = this->Rect();
   511         }
   540         }
   512     if ( rect.iBr.iX > contentRect.iBr.iX )
   541     if ( rect.iBr.iX > contentRect.iBr.iX )
   513         {
   542         {
   514         rect.Move( contentRect.iBr.iX - rect.iBr.iX, 0 );
   543         rect.Move( contentRect.iBr.iX - rect.iBr.iX, 0 );
   515         }
   544         }
       
   545     
   516     this->SetRect( rect );
   546     this->SetRect( rect );
   517     }
   547     }
   518 
   548 
       
   549 
       
   550 // -----------------------------------------------------------------------------
       
   551 // CXnWidgetExtensionAdapter::NotifyForegroundChanged
       
   552 // 
       
   553 // -----------------------------------------------------------------------------
       
   554 //    
       
   555 void CXnWidgetExtensionAdapter::NotifyForegroundChanged( 
       
   556     TForegroundStatus aStatus )
       
   557     {
       
   558     if ( aStatus != EForeground )
       
   559         {
       
   560         TRAP_IGNORE( HidePopupL() );
       
   561         }    
       
   562     }
       
   563 
       
   564 // -----------------------------------------------------------------------------
       
   565 // CXnWidgetExtensionAdapter::NotifyLightStatusChanged
       
   566 // 
       
   567 // -----------------------------------------------------------------------------
       
   568 //    
       
   569 void CXnWidgetExtensionAdapter::NotifyLightStatusChanged( TBool aLightsOn )
       
   570     {
       
   571     if ( !aLightsOn )
       
   572         {
       
   573         TRAP_IGNORE( HidePopupL() );
       
   574         }    
       
   575     }
       
   576    
       
   577 // -----------------------------------------------------------------------------
       
   578 // CXnWidgetExtensionAdapter::NotifyInCallStateChaged
       
   579 // 
       
   580 // -----------------------------------------------------------------------------
       
   581 //    
       
   582 void CXnWidgetExtensionAdapter::NotifyInCallStateChaged( TBool /*aInCall*/ )
       
   583     {    
       
   584     }
       
   585 
       
   586 // -----------------------------------------------------------------------------
       
   587 // CXnWidgetExtensionAdapter::HidePopupL
       
   588 // 
       
   589 // -----------------------------------------------------------------------------
       
   590 //    
       
   591 void CXnWidgetExtensionAdapter::HidePopupL()
       
   592     {
       
   593     if ( IsVisible() )
       
   594         {
       
   595         CXnDomStringPool* sp( iNode.Node().DomNode()->StringPool() );
       
   596             
       
   597         CXnProperty* prop = CXnProperty::NewL( 
       
   598             KDisplay, KNone, CXnDomPropertyValue::EString, *sp );
       
   599         
       
   600         CleanupStack::PushL( prop );
       
   601         
       
   602         iNode.Node().SetPropertyL( prop );
       
   603         
       
   604         CleanupStack::Pop( prop );        
       
   605         }
       
   606     }
       
   607 
   519 //  End of File  
   608 //  End of File