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

00001 /*
00002 Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 
00031 #include "ControlFrameworkAppUi.h"
00032 #include "ControlFrameworkView.h"
00033 #include "ControlFramework.hrh"
00034 #include "uikon.hrh"
00035 
00036 
00037 CControlFrameworkAppUi::CControlFrameworkAppUi()
00038         {
00039         }
00040 
00041 CControlFrameworkAppUi::~CControlFrameworkAppUi()
00042         {
00043         // Deregister the view(s) from the view server, remove the view(s) from the control stack
00044         // and delete them
00045         TInt view = iAppViews.Count();
00046         while (view--)
00047                 {
00048                 CControlFrameworkView* v = iAppViews[view];
00049                 RemoveFromStack(v);
00050                 DeregisterView(*v);
00051                 }
00052         iAppViews.ResetAndDestroy();
00053         }
00054 
00055 // Second phase constructor of the application UI.
00056 // It creates and owns a single view. The view is not fully constructed 
00057 // (via ViewConstructL()) until the first time the view is activated,
00058 // to improve application startup time.
00059 void CControlFrameworkAppUi::ConstructL()
00060         {
00061         BaseConstructL(CEikAppUi::EStandardApp);
00062         
00063         // Create the view
00064         CControlFrameworkView* view = CControlFrameworkView::NewLC(*this);
00065         AddViewL(view);
00066         CleanupStack::Pop(view);
00067         }
00068 
00069 
00070 // Called by the UI framework when a command has been issued 
00071 // by one of the toolbar buttons.
00072 void CControlFrameworkAppUi::HandleCommandL(TInt aCommandId)
00073         {
00074         CControlFrameworkView& view = *iAppViews[EExampleView];
00075         switch (aCommandId)
00076                 {
00077                 // command IDs are defined in the hrh file.
00078                 case ECmdToggleBoldFont:
00079                         view.ToggleBold();
00080                         break;
00081                 
00082                 case ECmdToggleItalicFont:      
00083                         view.ToggleItalic();
00084                         break;
00085                 
00086                 case ECmdToggleUnderline: 
00087                         view.ToggleUnderline();
00088                         break;
00089                         
00090                 case ECmdToggleStrikethrough: 
00091                         view.ToggleStrikethrough();
00092                         break;
00093                                 
00094                 default:                                
00095                 case EEikCmdExit:
00096                         Exit();
00097                 }
00098         }
00099 
00100 
00101 static void CleanupRemoveFromStack(TAny* aView)
00102         { 
00103         static_cast<CEikAppUi*>(CCoeEnv::Static()->AppUi())->RemoveFromStack(static_cast<CControlFrameworkView*>(aView)); 
00104         }
00105 
00106 static void CleanupDeregisterView(TAny* aView) 
00107         { 
00108         static_cast<CEikAppUi*>(CCoeEnv::Static()->AppUi())->DeregisterView(*static_cast<CControlFrameworkView*>(aView)); 
00109         }
00110 
00111 // Adds the view to the app UI's control stack and registers it with the view server. 
00112 // Takes ownership of the view.
00113 void CControlFrameworkAppUi::AddViewL(CControlFrameworkView* aView)
00114         {
00115         ASSERT(aView);
00116         ASSERT(KErrNotFound == iAppViews.Find(aView));
00117                 
00118         RegisterViewL(*aView); // Call RegisterViewL before AddToStackL to avoid panic in destructor if AddToStackL leaves 
00119         CleanupStack::PushL(TCleanupItem(CleanupDeregisterView,aView)); 
00120         
00121         AddToStackL(*aView, aView); 
00122         CleanupStack::PushL(TCleanupItem(CleanupRemoveFromStack, aView)); 
00123         
00124         iAppViews.AppendL(aView); 
00125         CleanupStack::Pop(2); 
00126         }

Generated by  doxygen 1.6.2