photosgallery/viewframework/uiutilities/src/glxscreenfurniture.cpp
changeset 0 4e91876724a2
child 18 bcb43dc84c44
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     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:    Screenfurniture interface. Used to show/hide UI or 
       
    15 * 				 enable/disable induvidual screenfurniture items.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "glxscreenfurniture.h"
       
    23 
       
    24 #include <glxtracer.h>
       
    25 #include <glxresourceutilities.h>                // for CGlxResourceUtilities
       
    26 #include <glxuiutilities.rsg>
       
    27 #include <data_caging_path_literals.hrh>
       
    28 #include <glxcommandhandlers.hrh>
       
    29 #include <StringLoader.h>
       
    30 
       
    31 _LIT(KGlxUiUtilitiesResource,"glxuiutilities.rsc");
       
    32 
       
    33 // CONSTANTS AND FORWARD DECLARATIONS
       
    34 const TInt KSfNoView = 0;
       
    35 const TInt KGlxFloatingToolbarXPosOffset = 80;
       
    36 const TInt KGlxFloatingToolbarYPosOffset = 120;
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // NewL
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 EXPORT_C CGlxScreenFurniture* CGlxScreenFurniture::NewL(
       
    43         CGlxUiUtility& aParentUtility)
       
    44     {
       
    45     TRACER("CGlxScreenFurniture::NewL()");
       
    46     
       
    47     CGlxScreenFurniture* self = CGlxScreenFurniture::NewLC(aParentUtility);
       
    48     CleanupStack::Pop(self);
       
    49     return self;
       
    50     }
       
    51     
       
    52 // -----------------------------------------------------------------------------
       
    53 // NewLC
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 EXPORT_C CGlxScreenFurniture* CGlxScreenFurniture::NewLC(
       
    57         CGlxUiUtility& aParentUtility)
       
    58     {
       
    59     TRACER("CGlxScreenFurniture::NewLC()");
       
    60         
       
    61     CGlxScreenFurniture* self = new(ELeave) CGlxScreenFurniture(aParentUtility);
       
    62     CleanupStack::PushL(self);
       
    63     self->ConstructL();
       
    64     return self;
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // Constructor
       
    69 // -----------------------------------------------------------------------------
       
    70 //  
       
    71 CGlxScreenFurniture::CGlxScreenFurniture(CGlxUiUtility& aParentUtility) : iParentUtility(aParentUtility)
       
    72     {
       
    73     TRACER("CGlxScreenFurniture::CGlxScreenFurniture()");
       
    74     
       
    75     }
       
    76 
       
    77 //------------------------------------------------------------------------------
       
    78 // Destructor
       
    79 //------------------------------------------------------------------------------
       
    80 //
       
    81 CGlxScreenFurniture::~CGlxScreenFurniture()
       
    82 	{
       
    83 	TRACER("CGlxScreenFurniture::~CGlxScreenFurniture");
       
    84 		
       
    85 	if ( iResourceOffset )
       
    86 	    {
       
    87 	    CCoeEnv::Static()->DeleteResourceFile(iResourceOffset);
       
    88 	    }
       
    89 	    
       
    90 	delete iToolbar;
       
    91 	
       
    92 	}
       
    93     
       
    94 // -----------------------------------------------------------------------------
       
    95 // ConstructL
       
    96 // -----------------------------------------------------------------------------
       
    97 //  
       
    98 void CGlxScreenFurniture::ConstructL()
       
    99     {
       
   100     TRACER("CGlxScreenFurniture::ConstructL()");
       
   101     
       
   102     // No view is active at the time of ScreenFurniture object construction
       
   103     iActiveView = KSfNoView; 
       
   104     
       
   105     // Load resource
       
   106     TParse parse;
       
   107     parse.Set(KGlxUiUtilitiesResource, &KDC_APP_RESOURCE_DIR, NULL);
       
   108     TFileName resourceFile;
       
   109     resourceFile.Append(parse.FullName());
       
   110     CGlxResourceUtilities::GetResourceFilenameL(resourceFile);  
       
   111     iResourceOffset = CCoeEnv::Static()->AddResourceFileL(resourceFile);
       
   112 
       
   113     // Create the fullscreen floating toolbar (used only for non-touch)
       
   114     iToolbar = CAknToolbar::NewL(R_GLX_FULLSCREEN_FLOATING_TOOLBAR); 
       
   115     iToolbar->SetOrientation(EAknOrientationVertical);        
       
   116     iToolbar->SetWithSliding(EFalse);
       
   117     
       
   118     // Set ScreenFurniture to observe the toolbar events
       
   119     SetToolbarObserver(this);
       
   120     }
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // SetActiveView
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 EXPORT_C void CGlxScreenFurniture::SetActiveView( TInt aViewId)
       
   127     {
       
   128     TRACER("CGlxScreenFurniture::SetActiveView()");
       
   129     
       
   130     iActiveView = aViewId;
       
   131     
       
   132     // Calculate toolbar position and display toolbar on the screen 
       
   133     // as soon as the calling view is activated.
       
   134     SetToolbarPosition();    
       
   135     SetToolbarVisibility(ETrue);
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // ViewDeactivated
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 EXPORT_C void CGlxScreenFurniture::ViewDeactivated( TInt aViewId)
       
   143     {
       
   144     TRACER("CGlxScreenFurniture::ViewDeactivated()");
       
   145     
       
   146     if ( aViewId == iActiveView )
       
   147         {        
       
   148         iActiveView = KSfNoView;
       
   149         SetToolbarVisibility(EFalse);
       
   150         }
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // SetVisibility
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 EXPORT_C void CGlxScreenFurniture::SetToolbarVisibility( TBool aVisible )
       
   158     {
       
   159     TRACER("CGlxScreenFurniture::SetToolbarVisibility()");
       
   160     
       
   161     if( aVisible )
       
   162         {                      
       
   163       // @TODO: Abhijit : Uncomment the following lines after the Avkon fix in week 02 MCL  
       
   164       //  iToolbar->SetFocus( ETrue, EDrawNow );        
       
   165       //  iToolbar->SetToolbarVisibility( aVisible, ETrue );        
       
   166         }
       
   167     else
       
   168         {        
       
   169       //  iToolbar->SetToolbarVisibility( aVisible, EFalse );        
       
   170         }
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // SetVisibility
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 EXPORT_C void CGlxScreenFurniture::SetToolbarItemVisibility( TInt aCommand, 
       
   178         TBool aVisible )
       
   179     {
       
   180     TRACER("CGlxScreenFurniture::SetToolbarItemVisibility()");
       
   181     
       
   182     iToolbar->HideItem(aCommand,!aVisible,EFalse);
       
   183     }
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // SetItemDimmedL
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 EXPORT_C void CGlxScreenFurniture::SetToolbarItemDimmed( TInt aCommand, 
       
   190         TBool aDimmed )
       
   191     {
       
   192     TRACER("CGlxScreenFurniture::SetToolbarItemDimmed()");
       
   193     
       
   194     iToolbar->SetItemDimmed(aCommand,aDimmed,ETrue);
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // SetFocusL
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 EXPORT_C void CGlxScreenFurniture::SetFocusL( TInt aCommand )
       
   202     {
       
   203     TRACER("CGlxScreenFurniture::SetFocusL()");
       
   204     
       
   205     iToolbar->SetFocusedItemL( aCommand );
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 //       PLACEMENT OF FLOATING TOOLBAR ON THE SCREEN 
       
   210 //
       
   211 // |<------xOffset---------->|      
       
   212 //
       
   213 // --------------------------------   ---       ---      
       
   214 // |                         |    |    |      yOffset
       
   215 // |                      ---.--- |    |        --- 
       
   216 // |                         |    | dispHeight          
       
   217 // |                              |    |         
       
   218 // |                              |    |         
       
   219 // --------------------------------   ---          
       
   220 //                                                  
       
   221 // |<-------- dispWidth --------->|                    
       
   222 //
       
   223 //
       
   224 // -----------------------------------------------------------------------------
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // SetPosition
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 EXPORT_C void CGlxScreenFurniture::SetToolbarPosition()
       
   231     {
       
   232     TRACER("CGlxScreenFurniture::SetToolbarPosition()");
       
   233     
       
   234     TSize displaySize(iParentUtility.DisplaySize());
       
   235     TInt dispWidth = displaySize.iWidth;
       
   236     TInt dispHeight = displaySize.iHeight;
       
   237 
       
   238     // Please refer to the figure above for a detailed description
       
   239     TInt xOffset = dispWidth - KGlxFloatingToolbarXPosOffset;
       
   240     TInt yOffset = (dispHeight/2) - KGlxFloatingToolbarYPosOffset;
       
   241     iToolbar->SetPosition(TPoint( xOffset, yOffset ) );
       
   242    
       
   243     }
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // SetTooltipL
       
   247 // -----------------------------------------------------------------------------
       
   248 //
       
   249 EXPORT_C void CGlxScreenFurniture::SetTooltipL( TInt aCommand, 
       
   250         CAknButton::TTooltipPosition aToolTipPos, const TDesC& aToolTipText )
       
   251     {
       
   252     TRACER("CGlxScreenFurniture::SetTooltipL()");
       
   253     
       
   254     // Get the button reference of the command specified
       
   255     CAknButton* toolbarButton = static_cast<CAknButton*>
       
   256                                 (iToolbar->ControlOrNull(aCommand));
       
   257                                 
       
   258     if( toolbarButton )
       
   259         {
       
   260         if( aToolTipText != KNullDesC )
       
   261             {
       
   262             // Set tooltip text
       
   263             toolbarButton->State()->SetHelpTextL(aToolTipText);
       
   264             }
       
   265         toolbarButton->SetTooltipPosition( aToolTipPos );
       
   266         }
       
   267     }
       
   268 
       
   269 // -----------------------------------------------------------------------------
       
   270 // OfferToolbarEventL
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 void CGlxScreenFurniture::OfferToolbarEventL( TInt aCommand )
       
   274     {
       
   275     TRACER("CGlxScreenFurniture::OfferToolbarEventL()");
       
   276     
       
   277     // This class does not have access to a CEikonEnv and hence 
       
   278     // pls ignore the code scanner warning - Using CEikonEnv::Static
       
   279     MEikCommandObserver* commandObserver = CEikonEnv::Static()->EikAppUi();
       
   280     commandObserver->ProcessCommandL( aCommand );    
       
   281     }
       
   282 
       
   283 // -----------------------------------------------------------------------------
       
   284 // SetToolbarObserver
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 void CGlxScreenFurniture::SetToolbarObserver( MAknToolbarObserver* aObserver )
       
   288     {
       
   289     TRACER("CGlxScreenFurniture::SetToolbarObserver()");
       
   290     
       
   291     // Add ScreenFurniture to ToolbarObserver
       
   292     iToolbar->SetToolbarObserver(aObserver);    
       
   293     }
       
   294 
       
   295 // -----------------------------------------------------------------------------
       
   296 // ChangeMskIdL
       
   297 // -----------------------------------------------------------------------------
       
   298 //    
       
   299 EXPORT_C void CGlxScreenFurniture::ModifySoftkeyIdL(CEikButtonGroupContainer::TCommandPosition aPosition, 
       
   300         TInt aCommandId, TInt aResourceId, const TDesC& aText)
       
   301     {
       
   302     TRACER("CGlxScreenFurniture::ChangeMskIdL(TInt aCommandId, TDesC& aText)"); 
       
   303     if (!AknLayoutUtils::PenEnabled())
       
   304         {
       
   305         CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   306         if (!aResourceId)
       
   307             {
       
   308             cba->SetCommandL(aPosition, aCommandId, aText );
       
   309             cba->DrawNow();
       
   310             }
       
   311         else
       
   312             {
       
   313             HBufC* textbuf =  StringLoader::LoadLC(aResourceId);
       
   314             TPtr msktext = textbuf->Des();
       
   315             cba->SetCommandL(aPosition, aCommandId, msktext );
       
   316             cba->DrawNow();
       
   317             CleanupStack::PopAndDestroy(textbuf);
       
   318             }
       
   319         }
       
   320     }
       
   321