examples/AppFramework/UIControls/ControlFramework/src/ControlFrameworkAppUi.cpp

00001 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 //
00015 
00016 #include "ControlFrameworkAppUi.h"
00017 #include "ControlFrameworkView.h"
00018 #include "ControlFramework.hrh"
00019 #include "uikon.hrh"
00020 
00021 
00022 CControlFrameworkAppUi::CControlFrameworkAppUi()
00023         {
00024         }
00025 
00026 CControlFrameworkAppUi::~CControlFrameworkAppUi()
00027         {
00028         // Deregister the view(s) from the view server, remove the view(s) from the control stack
00029         // and delete them
00030         TInt view = iAppViews.Count();
00031         while (view--)
00032                 {
00033                 CControlFrameworkView* v = iAppViews[view];
00034                 RemoveFromStack(v);
00035                 DeregisterView(*v);
00036                 }
00037         iAppViews.ResetAndDestroy();
00038         }
00039 
00040 // Second phase constructor of the application UI.
00041 // It creates and owns a single view. The view is not fully constructed 
00042 // (via ViewConstructL()) until the first time the view is activated,
00043 // to improve application startup time.
00044 void CControlFrameworkAppUi::ConstructL()
00045         {
00046         BaseConstructL(CEikAppUi::EStandardApp);
00047         
00048         // Create the view
00049         CControlFrameworkView* view = CControlFrameworkView::NewLC(*this);
00050         AddViewL(view);
00051         CleanupStack::Pop(view);
00052         }
00053 
00054 
00055 // Called by the UI framework when a command has been issued 
00056 // by one of the toolbar buttons.
00057 void CControlFrameworkAppUi::HandleCommandL(TInt aCommandId)
00058         {
00059         CControlFrameworkView& view = *iAppViews[EExampleView];
00060         switch (aCommandId)
00061                 {
00062                 // command IDs are defined in the hrh file.
00063                 case ECmdToggleBoldFont:
00064                         view.ToggleBold();
00065                         break;
00066                 
00067                 case ECmdToggleItalicFont:      
00068                         view.ToggleItalic();
00069                         break;
00070                 
00071                 case ECmdToggleUnderline: 
00072                         view.ToggleUnderline();
00073                         break;
00074                         
00075                 case ECmdToggleStrikethrough: 
00076                         view.ToggleStrikethrough();
00077                         break;
00078                                 
00079                 default:                                
00080                 case EEikCmdExit:
00081                         Exit();
00082                 }
00083         }
00084 
00085 
00086 static void CleanupRemoveFromStack(TAny* aView)
00087         { 
00088         static_cast<CEikAppUi*>(CCoeEnv::Static()->AppUi())->RemoveFromStack(static_cast<CControlFrameworkView*>(aView)); 
00089         }
00090 
00091 static void CleanupDeregisterView(TAny* aView) 
00092         { 
00093         static_cast<CEikAppUi*>(CCoeEnv::Static()->AppUi())->DeregisterView(*static_cast<CControlFrameworkView*>(aView)); 
00094         }
00095 
00096 // Adds the view to the app UI's control stack and registers it with the view server. 
00097 // Takes ownership of the view.
00098 void CControlFrameworkAppUi::AddViewL(CControlFrameworkView* aView)
00099         {
00100         ASSERT(aView);
00101         ASSERT(KErrNotFound == iAppViews.Find(aView));
00102                 
00103         RegisterViewL(*aView); // Call RegisterViewL before AddToStackL to avoid panic in destructor if AddToStackL leaves 
00104         CleanupStack::PushL(TCleanupItem(CleanupDeregisterView,aView)); 
00105         
00106         AddToStackL(*aView, aView); 
00107         CleanupStack::PushL(TCleanupItem(CleanupRemoveFromStack, aView)); 
00108         
00109         iAppViews.AppendL(aView); 
00110         CleanupStack::Pop(2); 
00111         }

Generated by  doxygen 1.6.2