widgets/widgetapp/src/WidgetUiWindowView.cpp
changeset 0 dd21522fd290
child 16 a359256acfc6
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006 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 the License "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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <AknUtils.h>
       
    19 #include <eikmenub.h>
       
    20 #include <barsread.h>
       
    21 #include "WidgetUiWindowView.h"
       
    22 #include "WidgetUiWindowContainer.h"
       
    23 #include "WidgetUiWindowManager.h"
       
    24 #include "WidgetUiWindow.h"
       
    25 #include <WidgetUi.rsg>
       
    26 #include <Widgetmenu.rsg>
       
    27 #include <AknViewAppUi.h>
       
    28 #include <avkon.RSG>
       
    29 #include "WidgetUi.hrh"
       
    30 #include <aknenv.h>
       
    31 #include <aknindicatorcontainer.h>
       
    32 #include <aknnavi.h>
       
    33 #include <aknnavide.h>
       
    34 #include <aknEditStateIndicator.h>
       
    35 #include <stringloader.h>
       
    36 #include <e32math.h>
       
    37 #include <AknSgcc.h>
       
    38 #include <akntitle.h>
       
    39 #include <centralrepository.h>
       
    40 #include <BrowserUiSDKCRKeys.h>
       
    41 #ifdef RD_SCALABLE_UI_V2
       
    42 #include <LayoutMetaData.cdl.h> // For Layout_Meta_Data landscape/portrait status
       
    43 #include <akntoolbar.h>
       
    44 #endif
       
    45 
       
    46 // CONSTANTS
       
    47     const TInt KRightSoftkeyPosition = 2;
       
    48     const TInt KLeftSoftkeyPosition = 0;
       
    49 
       
    50 // EXTERNAL DATA STRUCTURES
       
    51 
       
    52 // EXTERNAL FUNCTION PROTOTYPES
       
    53 
       
    54 // MACROS
       
    55 
       
    56 // LOCAL CONSTANTS AND MACROS
       
    57 
       
    58 // MODULE DATA STRUCTURES
       
    59 
       
    60 // LOCAL FUNCTION PROTOTYPES
       
    61 
       
    62 // FORWARD DECLARATIONS
       
    63 
       
    64 // ============================= LOCAL FUNCTIONS ===============================
       
    65 
       
    66 
       
    67 // ============================ MEMBER FUNCTIONS ===============================
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CWidgetUiWindowView::CWidgetUiWindowView()
       
    71 // C++ default constructor can NOT contain any code, that
       
    72 // might leave.
       
    73 //
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CWidgetUiWindowView::CWidgetUiWindowView( CWidgetUiWindowManager& aWindowManager )
       
    77     : iWindowManager( aWindowManager ),
       
    78     iActivatedObjectVisible(ETrue),
       
    79     iIsOptionsMenuActivated(EFalse)
       
    80     {
       
    81     iPenEnabled = AknLayoutUtils::PenEnabled();
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CWidgetUiWindowView::ConstructL()
       
    86 // Symbian constructor
       
    87 //
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CWidgetUiWindowView::ConstructL( )
       
    91     {
       
    92     BaseConstructL( R_WIDGETUI_WINDOW_VIEW );
       
    93 
       
    94     ConstructMenuAndCbaEarlyL();
       
    95     Cba()->AddCommandSetToStackL(R_WIDGETUI_WINDOW_VIEW_SOFTKEYS);
       
    96 
       
    97     iContainer = CWidgetUiWindowContainer::NewL(TRect(), iWindowManager);
       
    98     iContainer->SetMopParent( this );
       
    99 #ifdef RD_SCALABLE_UI_V2
       
   100     if (iPenEnabled && AppUi()->CurrentFixedToolbar())
       
   101         {
       
   102         AppUi()->CurrentFixedToolbar()->SetToolbarVisibility(EFalse);
       
   103         }
       
   104 #endif
       
   105     ShowActivatedObject(EFalse);
       
   106 
       
   107     // Navipane
       
   108     iNaviCont = (CAknNavigationControlContainer*)StatusPane()->ControlL(
       
   109         TUid::Uid( EEikStatusPaneUidNavi ) );
       
   110     iNaviDecorator = iNaviCont->CreateEditorIndicatorContainerL();
       
   111     iIndiContainer = ( CAknIndicatorContainer* )iNaviDecorator->DecoratedControl();
       
   112 
       
   113     iNaviCont->PushL( *iNaviDecorator );
       
   114 
       
   115     CAknTitlePane* title =
       
   116         STATIC_CAST( CAknTitlePane*, StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   117     title->SetTextL( KNullDesC() );
       
   118 
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CWidgetUiWindowView::NewLC()
       
   123 // Two-phase constructor
       
   124 //
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 CWidgetUiWindowView* CWidgetUiWindowView::NewLC( CWidgetUiWindowManager& aWindowManager )
       
   128     {
       
   129     CWidgetUiWindowView* view = new (ELeave) CWidgetUiWindowView( aWindowManager );
       
   130     CleanupStack::PushL(view);
       
   131     view->ConstructL();
       
   132 
       
   133     return view;
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CWidgetUiWindowView::~CWidgetUiWindowView()
       
   138 // Destructor
       
   139 //
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 CWidgetUiWindowView::~CWidgetUiWindowView()
       
   143     {
       
   144     DoDeactivate();
       
   145     if (iNaviCont && iNaviDecorator)
       
   146         {
       
   147         iNaviCont->Pop( iNaviDecorator );
       
   148         }
       
   149     delete iNaviDecorator;
       
   150     delete iContainer;
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CWidgetUiWindowView::Container()
       
   155 // Called by framework when the view size is changed
       
   156 //
       
   157 // -----------------------------------------------------------------------------
       
   158 //
       
   159 CWidgetUiWindowContainer* CWidgetUiWindowView::Container()
       
   160     {
       
   161     return iContainer;
       
   162     }
       
   163 
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CWidgetUiWindowView::Id()
       
   167 // return Id
       
   168 //
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 TUid CWidgetUiWindowView::Id() const
       
   172     {
       
   173     return TUid::Uid( 50 );
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // CWidgetUiWindowView::HandleCommandL()
       
   178 // Handles user commands
       
   179 //
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 void CWidgetUiWindowView::HandleCommandL( TInt aCommand )
       
   183     {
       
   184     if (!iWindowManager.ActiveWindow() ||
       
   185         !iWindowManager.ActiveWindow()->Engine() || !iContainer)
       
   186         {
       
   187         return;
       
   188         }
       
   189 
       
   190     DeActivateOptionsMenu();
       
   191 
       
   192     TBrCtlDefs::TBrCtlElementType elementtype =
       
   193             iWindowManager.ActiveWindow()->Engine()->FocusedElementType();
       
   194 
       
   195     TBool editing = (elementtype == TBrCtlDefs::EElementActivatedInputBox) ||
       
   196                     (elementtype == TBrCtlDefs::EElementActivatedObjectBox);
       
   197 
       
   198     switch( aCommand )
       
   199         {
       
   200         case EAknCmdExit:
       
   201         case EEikCmdExit: // Options->Exit
       
   202         case EAknSoftkeyExit: // Right Softkey (Exit or JS defined)
       
   203             ShowActivatedObject(EFalse); // deactivates any open edit boxes
       
   204             iWindowManager.Exit( aCommand, iWindowManager.ActiveWindow()->Uid());
       
   205             break;
       
   206         case EAknSoftkeyCancel:
       
   207             // cancel must be handled before hiding status pane
       
   208             iContainer->HandleCommandL( (TInt)TBrCtlDefs::ECommandCancel + (TInt)TBrCtlDefs::ECommandIdBase );
       
   209             ShowActivatedObject(EFalse); // deactivates any open edit boxes
       
   210         	break;
       
   211         case EAknSoftkeyDone:
       
   212             // accept must be handled before hiding status pane
       
   213             iContainer->HandleCommandL( (TInt)TBrCtlDefs::ECommandAccept + (TInt)TBrCtlDefs::ECommandIdBase );
       
   214             ShowActivatedObject(EFalse); // deactivates any open edit boxes
       
   215         	break;
       
   216         case ECmdMsk:
       
   217             if (editing)
       
   218                 {
       
   219                 break; // ignore MSK if editing
       
   220                 }
       
   221             // fall through if not editing
       
   222         default:
       
   223             iContainer->HandleCommandL( aCommand );
       
   224         }
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CWidgetUiWindowView::DynInitMenuPaneL()
       
   229 // Dynamically initialises menu pane
       
   230 //
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void CWidgetUiWindowView::DynInitMenuPaneL( TInt aResourceId,
       
   234                                          CEikMenuPane* aMenuPane )
       
   235     {
       
   236     if (!iWindowManager.ActiveWindow())
       
   237         return;
       
   238     CBrCtlInterface* engine = iWindowManager.ActiveWindow()->Engine();
       
   239     if( engine && (aResourceId == R_WIDGETUI_MENU || aResourceId >= R_CASCADE_MENU_1) )
       
   240         {
       
   241         iIsOptionsMenuActivated = ETrue;
       
   242         engine->AddOptionMenuItemsL( *aMenuPane, aResourceId );
       
   243         }
       
   244     }
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // CWidgetUiWindowView::DoActivateL()
       
   248 //
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 void CWidgetUiWindowView::DoActivateL( const TVwsViewId& /*aPrevViewId*/,
       
   252                                     TUid /*aCustomMessageId*/,
       
   253                                     const TDesC8& /*aCustomMessage*/ )
       
   254     {
       
   255     StatusPane()->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_SMALL);
       
   256 
       
   257     //Cba()->MakeVisible(EFalse);
       
   258 
       
   259     iContainer->ActivateL();
       
   260     AppUi()->AddToStackL( *this, iContainer );
       
   261 
       
   262     //iContainer->SetRect(ClientRect());// resize without cba
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CWidgetUiWindowView::DoDeactivate()
       
   267 // Deactivate view
       
   268 //
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 void CWidgetUiWindowView::DoDeactivate()
       
   272     {
       
   273     AppUi()->RemoveFromStack( iContainer );
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // CWidgetUiContentView::HandleStatusPaneSizeChange
       
   278 // Handles change in the position or size of the status pane
       
   279 //
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 void CWidgetUiWindowView::HandleStatusPaneSizeChange()
       
   283     {
       
   284      // Don't update status pane if widget is in miniview state.
       
   285     if( iWindowManager.ActiveWindow() &&
       
   286         iWindowManager.ActiveWindow()->WidgetFullViewState() )
       
   287         {
       
   288         Redraw();
       
   289         }
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // CWidgetUiContentView::ShowActivatedObject
       
   294 // Show the StatusPane and Softkeys - needed for text boxes
       
   295 // Or just Softkeys for flash etc...
       
   296 //
       
   297 // ---------------------------------------------------------------------------
       
   298 //
       
   299 void CWidgetUiWindowView::ShowActivatedObject(TBool aVisible, TBool aShowStatusPane)
       
   300     {
       
   301     if (iActivatedObjectVisible == aVisible)
       
   302         {
       
   303         return;
       
   304         }
       
   305     iActivatedObjectVisible = aVisible;
       
   306     iStatusPaneVisible = (aVisible && aShowStatusPane);
       
   307 
       
   308     if ( iWindowManager.ActiveWindow() )
       
   309         {
       
   310         // Override Right Softkey with Cancel when editing
       
   311         if (iActivatedObjectVisible)
       
   312             {
       
   313             iCbaVisible = Cba()->IsVisible();// hold state
       
   314             TRAPD(err,Cba()->AddCommandToStackL(KRightSoftkeyPosition,R_WIDGETUI_WINDOW_VIEW_SOFTKEYS_CANCEL));
       
   315             if (err == KErrNone)
       
   316                 {
       
   317                 TRAP(err,Cba()->AddCommandToStackL(KLeftSoftkeyPosition,R_WIDGETUI_WINDOW_VIEW_SOFTKEYS_DONE));
       
   318                 }
       
   319             iWindowManager.ActiveWindow()->SetSoftkeysVisible(ETrue);
       
   320             }
       
   321         else
       
   322             {
       
   323             // remove the cancel softkey and hide softkeys if they were previously hidden
       
   324             Cba()->RemoveCommandFromStack(KRightSoftkeyPosition,EAknSoftkeyCancel);
       
   325             Cba()->RemoveCommandFromStack(KLeftSoftkeyPosition,EAknSoftkeyDone);
       
   326 
       
   327             iWindowManager.ActiveWindow()->SetSoftkeysVisible(iCbaVisible);
       
   328             }
       
   329         }
       
   330     UpdateStatusPane();
       
   331     }
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // CWidgetUiContentView::UpdateStatusPane
       
   335 // Show the StatusPane if needed
       
   336 //
       
   337 // ---------------------------------------------------------------------------
       
   338 //
       
   339 void CWidgetUiWindowView::UpdateStatusPane()
       
   340     {
       
   341 #ifdef RD_SCALABLE_UI_V2
       
   342     // no need for the status pane on touch phones
       
   343     if (PenEnabled())
       
   344         {
       
   345         TInt resId = StatusPane()->CurrentLayoutResId();
       
   346         if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   347             {
       
   348             TInt newResId = Cba()->IsVisible() ?
       
   349                   R_AVKON_WIDESCREEN_PANE_LAYOUT_USUAL_FLAT :
       
   350                   R_AVKON_WIDESCREEN_PANE_LAYOUT_USUAL_FLAT_NO_SOFTKEYS;
       
   351             if (resId != newResId)
       
   352                 {
       
   353                 StatusPane()->SwitchLayoutL(newResId);
       
   354                 }
       
   355             }
       
   356         else //Portrait
       
   357             {
       
   358             if (resId != R_AVKON_STATUS_PANE_LAYOUT_SMALL)
       
   359                 {
       
   360                 StatusPane()->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_SMALL);
       
   361                 }
       
   362             }
       
   363         StatusPane()->ApplyCurrentSettingsL();
       
   364         StatusPane()->MakeVisible(EFalse);
       
   365         return;
       
   366         }
       
   367 #endif
       
   368 
       
   369     TBool visible(iStatusPaneVisible);
       
   370 
       
   371     // non-touch: always show status pane in landscape if softkeys are visible
       
   372     if (!visible && Cba()->IsVisible() &&
       
   373         AknLayoutUtils::CbaLocation() != AknLayoutUtils::EAknCbaLocationBottom)
       
   374         {
       
   375         visible = ETrue;
       
   376         }
       
   377 
       
   378     StatusPane()->MakeVisible(visible);
       
   379 
       
   380     if (visible && StatusPane()->CurrentLayoutResId() != R_AVKON_STATUS_PANE_LAYOUT_USUAL_FLAT)
       
   381         {
       
   382         StatusPane()->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_USUAL_FLAT);
       
   383         StatusPane()->ApplyCurrentSettingsL();
       
   384         }
       
   385     }
       
   386 
       
   387 // ---------------------------------------------------------
       
   388 // CWidgetUiWindowView::Redraw
       
   389 // redraw/relayout when application returns from background
       
   390 // or status pane shows/hides
       
   391 //
       
   392 // ---------------------------------------------------------
       
   393 //
       
   394 void CWidgetUiWindowView::Redraw() const
       
   395     {
       
   396     if ( iContainer )
       
   397         {
       
   398         iContainer->SetRect( AppUi()->ClientRect() );
       
   399         }
       
   400     }
       
   401 
       
   402 // ---------------------------------------------------------------------------
       
   403 // CWidgetUiWindowView::StateChanged
       
   404 // ---------------------------------------------------------------------------
       
   405 //
       
   406 void CWidgetUiWindowView::StateChanged(
       
   407         TBrCtlDefs::TBrCtlState aState,
       
   408         TInt aValue )
       
   409     {
       
   410     switch(aState)
       
   411         {
       
   412         case TBrCtlDefs::EStateScriptLog:
       
   413             {
       
   414                 CRepository*  iRepository = CRepository::NewL( KCRUidBrowser );
       
   415                 if ( iRepository )
       
   416                     {
       
   417                     iRepository->Set( KBrowserNGScriptLog, aValue );
       
   418                     }
       
   419                 delete iRepository;
       
   420                 iRepository = NULL;
       
   421             }
       
   422         default:
       
   423             break;
       
   424         }
       
   425     }
       
   426 
       
   427 // ---------------------------------------------------------------------------
       
   428 // CWidgetUiWindowView::IsOptionsMenuActivated
       
   429 // ---------------------------------------------------------------------------
       
   430 //
       
   431 TBool CWidgetUiWindowView::IsOptionsMenuActivated()
       
   432  	{
       
   433  	return iIsOptionsMenuActivated;
       
   434  	}
       
   435 
       
   436 
       
   437 // ---------------------------------------------------------------------------
       
   438 // CWidgetUiWindowView::DeActivateOptionsMenu
       
   439 // ---------------------------------------------------------------------------
       
   440 //
       
   441 void CWidgetUiWindowView::DeActivateOptionsMenu()
       
   442  	{
       
   443  	iIsOptionsMenuActivated = EFalse;
       
   444  	}
       
   445 
       
   446 // End of File