idlehomescreen/xmluirendering/uiengine/src/xnbgcontrol.cpp
branchRCL_3
changeset 17 b8fae6b8a148
parent 12 9674c1a575e9
child 18 d05a55b217df
equal deleted inserted replaced
12:9674c1a575e9 17:b8fae6b8a148
     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:  Background appearance drawer
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <aknappui.h>
       
    20 
       
    21 // User includes
       
    22 #include "xnappuiadapter.h"
       
    23 #include "xnuiengine.h"
       
    24 #include "xneditmode.h"
       
    25 
       
    26 #include "xnbgcontrol.h"
       
    27 
       
    28 // Constants
       
    29 
       
    30 // ============================ LOCAL FUNCTIONS ================================
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 // -----------------------------------------------------------------------------
       
    34 // CXnBgControl::NewL()
       
    35 // Two-phased constructor.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CXnBgControl* CXnBgControl::NewL()
       
    39     {
       
    40     CXnBgControl* self = CXnBgControl::NewLC();
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CXnBgControl::NewLC()
       
    47 // Two-phased constructor.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CXnBgControl* CXnBgControl::NewLC()
       
    51     {
       
    52     CXnBgControl* self = new ( ELeave ) CXnBgControl();
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55     return self;
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CXnBgControl::~CXnBgControl()
       
    60 // C++ default destructor.
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CXnBgControl::~CXnBgControl()
       
    64     {  
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CXnBgControl::CXnBgControl()
       
    69 // C++ default constructor.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CXnBgControl::CXnBgControl()
       
    73     :   iHitpoint( TPoint( -1,-1 ) )
       
    74     {  
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CXnBgControl::ConstructL()
       
    79 // 2nd phase constructor
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CXnBgControl::ConstructL()
       
    83     {   
       
    84     CreateWindowL();
       
    85 
       
    86     TRgb backgroundColour = KRgbWhite;
       
    87     if( KErrNone == Window().SetTransparencyAlphaChannel() )      
       
    88         {       
       
    89         backgroundColour.SetAlpha( 0 );       
       
    90         }   
       
    91     Window().SetBackgroundColor( backgroundColour );
       
    92     
       
    93     EnableDragEvents();
       
    94     
       
    95     Window().SetPointerGrab( ETrue );
       
    96     
       
    97     
       
    98     ActivateL();
       
    99 
       
   100     MakeVisible( ETrue );
       
   101     
       
   102     SetComponentsToInheritVisibility( ETrue );
       
   103     
       
   104     static_cast< CXnAppUiAdapter* >( iAvkonAppUi )
       
   105             ->UiStateListener().AddObserver( *this );
       
   106     
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CXnBgControl::CountComponentControls()
       
   111 // 
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 TInt CXnBgControl::CountComponentControls() const
       
   115     {
       
   116     if ( iControl )
       
   117         {
       
   118         return 1;
       
   119         }
       
   120     
       
   121     return 0;
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CXnBgControl::ComponentControl()
       
   126 // 
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 CCoeControl* CXnBgControl::ComponentControl( TInt aIndex ) const
       
   130     {
       
   131     if ( aIndex == 0 )
       
   132         {
       
   133         return iControl;
       
   134         }
       
   135     
       
   136     return NULL;
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CXnBgControl::SizeChanged()
       
   141 // 
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CXnBgControl::SizeChanged()
       
   145     {
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CXnBgControl::Draw()
       
   150 // 
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void CXnBgControl::Draw( const TRect& aRect ) const
       
   154     {    
       
   155     CXnAppUiAdapter* appui( 
       
   156         static_cast< CXnAppUiAdapter* >( iAvkonAppUi ) );
       
   157 
       
   158     TInt state( appui->UiEngine().EditMode()->EditState() );
       
   159     
       
   160     CWindowGc& gc( SystemGc() );
       
   161     
       
   162     if ( state == CXnEditMode::EShootContent )
       
   163         {
       
   164         // No background needed for dragging widget screenshot        
       
   165         }
       
   166     else
       
   167         {        
       
   168         gc.Clear( aRect );        
       
   169         }          
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // CXnBgControl::SetCompoundControl()
       
   174 // 
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 void CXnBgControl::HandlePointerEventL( const TPointerEvent& aPointerEvent )
       
   178     {
       
   179     switch( aPointerEvent.iType )
       
   180         {
       
   181         case TPointerEvent::EButton1Down:
       
   182             iHitpoint = aPointerEvent.iPosition;
       
   183             break;
       
   184             
       
   185         case TPointerEvent::EButton1Up:
       
   186             break;
       
   187             
       
   188         default:
       
   189             break;
       
   190         }
       
   191     
       
   192     CXnAppUiAdapter* appui( static_cast< CXnAppUiAdapter* >( iAvkonAppUi ) );
       
   193     
       
   194     appui->UiEngine().DisableRenderUiLC();
       
   195             
       
   196     CCoeControl::HandlePointerEventL( aPointerEvent );
       
   197     
       
   198     appui->UiEngine().RenderUIL();
       
   199     
       
   200     CleanupStack::PopAndDestroy();
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CXnBgControl::SetCompoundControl()
       
   205 // 
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 void CXnBgControl::SetCompoundControl( CCoeControl* aControl )
       
   209     {
       
   210     if ( iControl == aControl )
       
   211         {
       
   212         return;
       
   213         }
       
   214     
       
   215     if ( iControl )
       
   216         {
       
   217         // Remove parents    
       
   218         iControl->SetParent( NULL );
       
   219         iControl->SetMopParent( NULL );
       
   220         
       
   221         iControl->MakeVisible( EFalse );
       
   222         }
       
   223     
       
   224     if ( aControl )
       
   225         {        
       
   226         // Set self as parent
       
   227         aControl->SetParent( this );
       
   228         aControl->SetMopParent( this );
       
   229         
       
   230         aControl->MakeVisible( ETrue );        
       
   231         }
       
   232     
       
   233     iControl = aControl;        
       
   234     }
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CXnBgControl::ResetGrabbingL()
       
   238 // Service for removing grabbing controls
       
   239 // -----------------------------------------------------------------------------
       
   240 //
       
   241 void CXnBgControl::ResetGrabbingL()
       
   242     {
       
   243     TPointerEvent event;
       
   244     event.iType = TPointerEvent::EButton1Up;
       
   245     
       
   246     RemoveGrabbingControL( this, event );
       
   247     
       
   248     iHitpoint.SetXY( -1, -1 );
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CXnBgControl::RemoveGrabbingControL()
       
   253 // Removes recursively grabbing controls
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 void CXnBgControl::RemoveGrabbingControL( const CCoeControl* aControl,
       
   257         const TPointerEvent& aEvent ) const
       
   258     {
       
   259     TInt count = aControl->CountComponentControls();
       
   260     
       
   261     for( TInt i = 0; i < count; i++ )
       
   262         {
       
   263         CCoeControl* child = aControl->ComponentControl( i );
       
   264         
       
   265         if( child && child->Rect().Contains( iHitpoint ) )
       
   266             {
       
   267             child->CCoeControl::HandlePointerEventL( aEvent ); 
       
   268             RemoveGrabbingControL( child, aEvent );
       
   269             }
       
   270         }
       
   271     }
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // CXnBgControl::NotifyForegroundChanged()
       
   275 // Notifies foreground changes.
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 void CXnBgControl::NotifyForegroundChanged( TForegroundStatus aStatus )
       
   279     {
       
   280     switch( aStatus )
       
   281         {
       
   282         case EForeground:
       
   283             break;
       
   284             
       
   285         case EUnknown:
       
   286         case EBackground:
       
   287         case EPartialForeground:  
       
   288         default:
       
   289             TRAP_IGNORE( ResetGrabbingL(); )
       
   290             break;
       
   291         }
       
   292     }
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CXnBgControl::NotifyLightStatusChanged()
       
   296 // Notifies primary display light status is changed.
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 void CXnBgControl::NotifyLightStatusChanged( TBool /*aLightsOn*/ )
       
   300     {
       
   301     
       
   302     }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CXnBgControl::NotifyInCallStateChaged()
       
   306 // Notifies in-call state is changed.
       
   307 // -----------------------------------------------------------------------------
       
   308 //
       
   309 void CXnBgControl::NotifyInCallStateChaged( TBool /*aInCall*/ )
       
   310     {
       
   311     
       
   312     }
       
   313 
       
   314 // End of file
       
   315