screengrabber/src/SGMainView.cpp
changeset 0 d6fe6244b863
equal deleted inserted replaced
-1:000000000000 0:d6fe6244b863
       
     1 /*
       
     2 * Copyright (c) 2009 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include  <aknViewAppUi.h>
       
    22 #include  <avkon.hrh>
       
    23 #include  <apgtask.h>
       
    24 #include  <aknmessagequerydialog.h> 
       
    25 
       
    26 #include  <screengrabber.rsg>
       
    27 #include  "SG.hrh"
       
    28 #include  "SGMainView.h"
       
    29 #include  "SGMainContainer.h"
       
    30 #include  "SGSettingListView.h"
       
    31 #include  "SGDocument.h" 
       
    32 #include  "SGModel.h"
       
    33 
       
    34 #ifdef SCREENGRABBER_SCREEN_RESOLUTION_CHANGE_SUPPORT
       
    35  #include <AknSgcc.h>
       
    36  #include <AknLayoutConfig.h>
       
    37  #include <e32property.h>
       
    38  #include <UikonInternalPSKeys.h>
       
    39 #endif
       
    40 
       
    41 // ================= MEMBER FUNCTIONS =======================
       
    42 
       
    43 // ---------------------------------------------------------
       
    44 // CScreenGrabberMainView::ConstructL(const TRect& aRect)
       
    45 // EPOC two-phased constructor
       
    46 // ---------------------------------------------------------
       
    47 //
       
    48 void CScreenGrabberMainView::ConstructL()
       
    49     {
       
    50     BaseConstructL( R_SCREENGRABBER_VIEW1 );
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------
       
    54 // CScreenGrabberMainView::~CScreenGrabberMainView()
       
    55 // ---------------------------------------------------------
       
    56 //
       
    57 CScreenGrabberMainView::~CScreenGrabberMainView()
       
    58     {
       
    59     if ( iContainer )
       
    60         {
       
    61         AppUi()->RemoveFromViewStack( *this, iContainer );
       
    62         }
       
    63 
       
    64     delete iContainer;
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------
       
    68 // TUid CScreenGrabberMainView::Id()
       
    69 // ---------------------------------------------------------
       
    70 //
       
    71 TUid CScreenGrabberMainView::Id() const
       
    72     {
       
    73     return KMainViewUID;
       
    74     }
       
    75 
       
    76 
       
    77 
       
    78 #ifdef SCREENGRABBER_SCREEN_RESOLUTION_CHANGE_SUPPORT
       
    79 
       
    80 // ---------------------------------------------------------
       
    81 // TUid CScreenGrabberMainView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
       
    82 // ---------------------------------------------------------
       
    83 //
       
    84 
       
    85 void CScreenGrabberMainView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
       
    86     {
       
    87     if (aResourceId == R_SCREENGRABBER_RESOLUTION_SUBMENU)
       
    88         {
       
    89         // generate list of supported screen resolutions
       
    90         TInt state = 0;
       
    91         TInt width = 0;
       
    92         TInt height = 0;
       
    93         TInt screenMode = 0;
       
    94         
       
    95         const CAknLayoutConfig& config = CAknSgcClient::LayoutConfig();
       
    96         const CAknLayoutConfig::THardwareStateArray& hwStates = config.HardwareStates();
       
    97         const CAknLayoutConfig::TScreenModeArray& screenModes = config.ScreenModes();
       
    98 
       
    99         CWsScreenDevice* screenDevice = CEikonEnv::Static()->ScreenDevice();
       
   100         TInt currentHwState = screenDevice->CurrentScreenMode();
       
   101             
       
   102         for (TInt i=0; i<hwStates.Count(); i++)
       
   103             {
       
   104             // get an entry entry
       
   105             const CAknLayoutConfig::THardwareState& hwState = hwStates.At(i);
       
   106             screenMode = hwState.ScreenMode();
       
   107             const CAknLayoutConfig::TScreenMode& mode = screenModes.Find(screenMode);
       
   108             
       
   109             // get more info
       
   110             state = hwState.StateNumber();
       
   111             width = mode.PixelsTwipsAndRotation().iPixelSize.iWidth;
       
   112             height = mode.PixelsTwipsAndRotation().iPixelSize.iHeight;
       
   113             
       
   114             // generate new menu text
       
   115             TBuf<64> menuText;
       
   116             menuText.Format(_L("%dx%d  (%d)"), width, height, state);
       
   117             
       
   118             // create new menu item
       
   119             CEikMenuPaneItem::SData menuItem;
       
   120             menuItem.iFlags = 0;
       
   121             menuItem.iText = menuText;
       
   122             menuItem.iCommandId = EScreenGrabberCmdScreenResolutionItem1 + state;
       
   123             menuItem.iCascadeId = 0;
       
   124             aMenuPane->AddMenuItemL(menuItem);
       
   125             }
       
   126         }
       
   127     }
       
   128 
       
   129 #endif
       
   130     
       
   131 // ---------------------------------------------------------
       
   132 // CScreenGrabberMainView::HandleCommandL(TInt aCommand)
       
   133 // ---------------------------------------------------------
       
   134 //
       
   135 void CScreenGrabberMainView::HandleCommandL(TInt aCommand)
       
   136     {   
       
   137     switch ( aCommand )
       
   138         {
       
   139         case EScreenGrabberCmdSendToBackground:
       
   140             {
       
   141             TApaTask selfTask(iEikonEnv->WsSession());
       
   142             selfTask.SetWgId(iEikonEnv->RootWin().Identifier());
       
   143             selfTask.SendToBackground();
       
   144             break;
       
   145             }
       
   146 
       
   147 #ifdef SCREENGRABBER_SCREEN_RESOLUTION_CHANGE_SUPPORT
       
   148         case EScreenGrabberCmdScreenResolutionItem1:
       
   149         case EScreenGrabberCmdScreenResolutionItem2:
       
   150         case EScreenGrabberCmdScreenResolutionItem3:
       
   151         case EScreenGrabberCmdScreenResolutionItem4:
       
   152         case EScreenGrabberCmdScreenResolutionItem5:
       
   153         case EScreenGrabberCmdScreenResolutionItem6:
       
   154         case EScreenGrabberCmdScreenResolutionItem7:
       
   155         case EScreenGrabberCmdScreenResolutionItem8:
       
   156         case EScreenGrabberCmdScreenResolutionItem9:
       
   157         case EScreenGrabberCmdScreenResolutionItem10:
       
   158         case EScreenGrabberCmdScreenResolutionItem11:
       
   159         case EScreenGrabberCmdScreenResolutionItem12:
       
   160             {
       
   161             // change resolution
       
   162             const CAknLayoutConfig& config = CAknSgcClient::LayoutConfig();
       
   163             const CAknLayoutConfig::THardwareStateArray& hwStates = config.HardwareStates();
       
   164             const CAknLayoutConfig::TScreenModeArray& screenModes = config.ScreenModes();
       
   165         
       
   166             const CAknLayoutConfig::THardwareState& hwState = hwStates.At(aCommand-EScreenGrabberCmdScreenResolutionItem1);
       
   167             TInt screenMode = hwState.ScreenMode();
       
   168             TInt state = hwState.StateNumber();
       
   169             
       
   170             CWsScreenDevice* screenDevice = CEikonEnv::Static()->ScreenDevice();
       
   171             TInt err = RProperty::Define(KPSUidUikon, KUikLayoutState, RProperty::EInt);
       
   172             err = RProperty::Set(KPSUidUikon, KUikLayoutState, state);
       
   173 
       
   174             screenDevice->SetScreenMode(screenMode);
       
   175 
       
   176             break;
       
   177             }
       
   178 #endif
       
   179             
       
   180         case EScreenGrabberCmdSettings:
       
   181             {
       
   182             AppUi()->ActivateLocalViewL( KSettingListViewUID );
       
   183             break;
       
   184             }
       
   185 
       
   186         case EScreenGrabberCmdAbout:
       
   187             {
       
   188 	        CAknMessageQueryDialog* dialog = new (ELeave) CAknMessageQueryDialog;
       
   189             dialog->ExecuteLD(R_SCREENGRABBER_ABOUT_DIALOG);
       
   190             }
       
   191             break;
       
   192         
       
   193         case EAknSoftkeyExit:
       
   194             {
       
   195             AppUi()->HandleCommandL( EEikCmdExit );
       
   196             break;
       
   197             }
       
   198 
       
   199         default:
       
   200             {
       
   201             AppUi()->HandleCommandL( aCommand );
       
   202             break;
       
   203             }
       
   204         }
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------
       
   208 // CScreenGrabberMainView::HandleClientRectChange()
       
   209 // ---------------------------------------------------------
       
   210 //
       
   211 void CScreenGrabberMainView::HandleClientRectChange()
       
   212     {
       
   213     if ( iContainer )
       
   214         {
       
   215         iContainer->SetRect( ClientRect() );
       
   216         }
       
   217     }
       
   218 
       
   219 // ---------------------------------------------------------
       
   220 // CScreenGrabberMainView::DoActivateL(...)
       
   221 // ---------------------------------------------------------
       
   222 //
       
   223 void CScreenGrabberMainView::DoActivateL(
       
   224    const TVwsViewId& /*aPrevViewId*/,TUid /*aCustomMessageId*/,
       
   225    const TDesC8& /*aCustomMessage*/)
       
   226     {
       
   227     if (!iContainer)
       
   228         {
       
   229         iContainer = new (ELeave) CScreenGrabberMainContainer;
       
   230         iContainer->SetMopParent(this);
       
   231         iContainer->ConstructL( ClientRect() );
       
   232         AppUi()->AddToStackL( *this, iContainer );
       
   233         } 
       
   234    }
       
   235 
       
   236 // ---------------------------------------------------------
       
   237 // CScreenGrabberMainView::HandleCommandL(TInt aCommand)
       
   238 // ---------------------------------------------------------
       
   239 //
       
   240 void CScreenGrabberMainView::DoDeactivate()
       
   241     {
       
   242     if ( iContainer )
       
   243         {
       
   244         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   245         }
       
   246     
       
   247     delete iContainer;
       
   248     iContainer = NULL;
       
   249     }
       
   250 
       
   251 // End of File
       
   252