wvuing/IMPSConnectionUI/UISrc/CCommandAbsorbingControl.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 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:  Command absorber to eat all key presses.
       
    15 *
       
    16 */
       
    17 
       
    18 //INCLUDE FILES
       
    19 #include <E32std.h>
       
    20 #include <eikappui.h>
       
    21 #include <eikenv.h>
       
    22 #include <eikbtgpc.h>
       
    23 
       
    24 #include "CCommandAbsorbingControl.h"
       
    25 #include "CnUiPanics.h"
       
    26 #include "impscommonuibuilddefinitions.h"
       
    27 
       
    28 
       
    29 // ================= CCommandFlush MEMBER FUNCTIONS =======================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CCommandAbsorbingControl::CCommandFlush::CCommandFlush()
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CCommandAbsorbingControl::CCommandFlush::CCommandFlush()
       
    36         : CActive( EPriorityLow )
       
    37     {
       
    38     CActiveScheduler::Add( this );
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CCommandAbsorbingControl::CCommandFlush::~CCommandFlush()
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CCommandAbsorbingControl::CCommandFlush::~CCommandFlush()
       
    46     {
       
    47     Cancel();
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CCommandAbsorbingControl::CCommandFlush::Flush()
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void CCommandAbsorbingControl::CCommandFlush::Flush()
       
    55     {
       
    56     if ( iWait.IsStarted() )
       
    57         {
       
    58         //only one flush at time
       
    59         return;
       
    60         }
       
    61 
       
    62     //issue one active scheduler round
       
    63     //actually it might be several because this is a low priority one
       
    64     //and it lets other higher ones proceed first...
       
    65     TRequestStatus *pS = &iStatus;
       
    66     User::RequestComplete( pS, KErrNone );
       
    67     SetActive();
       
    68 
       
    69     //wait with the scheduler loop
       
    70     // Code scanner warning "active object called without checking
       
    71     // whether it is active or cancelling it first" ignored because
       
    72     // CActiveSchedulerWait is not an active object
       
    73     iWait.Start(); // CSI: 10 # See above
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CCommandAbsorbingControl::CCommandFlush::RunL()
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CCommandAbsorbingControl::CCommandFlush::RunL()
       
    81     {
       
    82     Completed();
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CCommandAbsorbingControl::CCommandFlush::RunError()
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 TInt CCommandAbsorbingControl::CCommandFlush::RunError( TInt /*aError*/ )
       
    90     {
       
    91     Completed();
       
    92     return KErrNone;
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CCommandAbsorbingControl::CCommandFlush::DoCancel()
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CCommandAbsorbingControl::CCommandFlush::DoCancel()
       
   100     {
       
   101     Completed();
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CCommandAbsorbingControl::CCommandFlush::Completed()
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 void CCommandAbsorbingControl::CCommandFlush::Completed()
       
   109     {
       
   110     //break away from the waiting scheduler loop
       
   111     if ( iWait.IsStarted() )
       
   112         {
       
   113         iWait.AsyncStop();
       
   114         }
       
   115     }
       
   116 
       
   117 
       
   118 
       
   119 // ================= MEMBER FUNCTIONS =======================
       
   120 // Two-phased constructor.
       
   121 CCommandAbsorbingControl* CCommandAbsorbingControl::NewL()
       
   122     {
       
   123     CCommandAbsorbingControl* self = new ( ELeave ) CCommandAbsorbingControl();
       
   124 
       
   125     CleanupStack::PushL( self );
       
   126     self->ConstructL();
       
   127     CleanupStack::Pop( self );
       
   128 
       
   129     return self;
       
   130     }
       
   131 
       
   132 
       
   133 // Destructor
       
   134 CCommandAbsorbingControl::~CCommandAbsorbingControl()
       
   135     {
       
   136     StopAbsorbingIfNeeded();
       
   137     }
       
   138 
       
   139 
       
   140 // C++ default constructor can NOT contain any code, that
       
   141 // might leave.
       
   142 //
       
   143 CCommandAbsorbingControl::CCommandAbsorbingControl()
       
   144         : iAbsorbOn( EFalse )
       
   145     {
       
   146     }
       
   147 
       
   148 
       
   149 // Symbian OS default constructor can leave.
       
   150 void CCommandAbsorbingControl::ConstructL()
       
   151     {
       
   152     //if we don't have application ui,
       
   153     //then there is no need to consume commands
       
   154     iAppUi = CEikonEnv::Static()->EikAppUi();
       
   155     iCba = CEikButtonGroupContainer::Current();
       
   156     }
       
   157 
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CCommandAbsorbingControl::AbsorbCommandsLC()
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CCommandAbsorbingControl::AbsorbCommandsLC()
       
   164     {
       
   165     if ( !iAbsorbOn )
       
   166         {
       
   167         CleanupStack::PushL( TCleanupItem( CCommandAbsorbingControl::ClearCommandAbsorb,
       
   168                                            this ) );
       
   169 
       
   170         iAbsorbOn = ETrue;
       
   171         StartAbsorbingL();
       
   172         }
       
   173 
       
   174     else
       
   175         {
       
   176         //already absorbing commands, don't create a new
       
   177         //just push NULL object to meet the method semantics
       
   178         //this doesn't do actually any harm, just eats one slot from
       
   179         //CleanupStack but anyway it is simpler than letting the client
       
   180         //manage that it doesn't have anything to pop and destroy...
       
   181         CleanupStack::PushL( ( CBase* ) NULL );
       
   182         }
       
   183     }
       
   184 
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CCommandAbsorbingControl::FlushCommands()
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 void CCommandAbsorbingControl::FlushCommands()
       
   191     {
       
   192     if ( iAbsorbOn )
       
   193         {
       
   194         iCommandFlusher.Flush();
       
   195         }
       
   196     }
       
   197 
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CCommandAbsorbingControl::OfferKeyEventL()
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 TKeyResponse CCommandAbsorbingControl::OfferKeyEventL( const TKeyEvent& /*aKeyEvent*/,
       
   204                                                        TEventCode /*aType*/ )
       
   205     {
       
   206     return EKeyWasConsumed;
       
   207     }
       
   208 
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CCommandAbsorbingControl::StartAbsorbingL()
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 void CCommandAbsorbingControl::StartAbsorbingL()
       
   215     {
       
   216     if ( iAppUi )
       
   217         {
       
   218         //add self to eat key events
       
   219         iAppUi->AddToStackL( this, ECoeStackPriorityDialog );
       
   220         }
       
   221 
       
   222     if ( iCba )
       
   223         {
       
   224         //clear CBA
       
   225         MakeCbaVisible( EFalse );
       
   226         }
       
   227     }
       
   228 
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CCommandAbsorbingControl::StopAbsorbingIfNeeded()
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 void CCommandAbsorbingControl::StopAbsorbingIfNeeded()
       
   235     {
       
   236     if ( iAbsorbOn )
       
   237         {
       
   238         if ( iAppUi )
       
   239             {
       
   240             //remove self
       
   241             iAppUi->RemoveFromStack( this );
       
   242             }
       
   243 
       
   244         if ( iCba )
       
   245             {
       
   246             //make CBA visible
       
   247             MakeCbaVisible( ETrue );
       
   248             }
       
   249 
       
   250         iAbsorbOn = EFalse;
       
   251         }
       
   252     }
       
   253 
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CCommandAbsorbingControl::MakeCbaVisible()
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 void CCommandAbsorbingControl::MakeCbaVisible( TBool aVisible ) const
       
   260     {
       
   261     if ( iCba && iCba->ButtonGroup() )
       
   262         {
       
   263         TInt leftId( iCba->ButtonGroup()->CommandId( 0 ) );  //position 0 --> left
       
   264         TInt rightId( iCba->ButtonGroup()->CommandId( 2 ) ); //position 2 --> right
       
   265         TInt mskId = iCba->ButtonGroup()->CommandId( 3 );   // position 3 --> MSK
       
   266 
       
   267         iCba->MakeCommandVisible( leftId, aVisible );
       
   268         iCba->MakeCommandVisible( rightId, aVisible );
       
   269         iCba->MakeCommandVisible( mskId, aVisible );
       
   270 
       
   271         iCba->DrawNow();
       
   272         }
       
   273     }
       
   274 
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CCommandAbsorbingControl::ClearCommandAbsorb()
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 void CCommandAbsorbingControl::ClearCommandAbsorb( TAny* aCommandAbsorber )
       
   281     {
       
   282     __ASSERT_ALWAYS( aCommandAbsorber, CnUiPanic( EIMPSConn_NULLPtr ) );
       
   283 
       
   284     CCommandAbsorbingControl* self = static_cast< CCommandAbsorbingControl* >( aCommandAbsorber );
       
   285     self->StopAbsorbingIfNeeded();
       
   286     }
       
   287 
       
   288 
       
   289 //  End of File
       
   290 
       
   291 
       
   292 
       
   293 
       
   294 
       
   295