locationlandmarksrefappfors60/Src/LandmarksInfoContainer.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2004-2007 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:  Implements the CLandmarksInfoContainer class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <aknsfld.h>
       
    21 #include <aknnavi.h>
       
    22 #include <aknlists.h> 
       
    23 #include <eikclbd.h>
       
    24 #include <akntitle.h>
       
    25 #include <aknview.h>
       
    26 #include <aknnavide.h>
       
    27 
       
    28 #include <lbspositioninfo.h>
       
    29 
       
    30 #include <lmrefapp.rsg>
       
    31 #include "LmRefApp.hrh"
       
    32 #include "LandmarksCommonData.h"
       
    33 #include "LandmarksInfoContainer.h"
       
    34 #include "LandmarksInfoModel.h"
       
    35 #include "LandmarksEditDialog.h"
       
    36 #include "LandmarksApplicationEngine.h"
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CLandmarksInfoContainer::CLandmarksInfoContainer(
       
    44     CAknView& aView,
       
    45     CLandmarksApplicationEngine& aEngine,
       
    46     CAknNavigationDecorator* aNaviDecorator)
       
    47 :   iView(aView),
       
    48     iEngine(aEngine), 
       
    49     iNaviDecorator(aNaviDecorator)
       
    50     {
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 void CLandmarksInfoContainer::ConstructL(const TRect& aRect)
       
    57     {
       
    58     CreateWindowL();
       
    59     CreateListBoxL();
       
    60 
       
    61     // Create data model.
       
    62     iModel = new (ELeave) CLandmarksInfoModel(iEngine);
       
    63 
       
    64     SetRect(aRect);
       
    65     ActivateL();
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CLandmarksInfoContainer::~CLandmarksInfoContainer()
       
    72     {
       
    73     iFields.Close();
       
    74     delete iListBox;
       
    75 	delete iLandmark;
       
    76     delete iModel;
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 TInt CLandmarksInfoContainer::CountComponentControls() const
       
    83     {
       
    84     TInt count = 0;
       
    85     if (iListBox)
       
    86         {
       
    87         count++;
       
    88         }
       
    89 
       
    90     return count; // Return the number of controls inside this container.
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 CCoeControl* CLandmarksInfoContainer::ComponentControl(TInt aIndex) const
       
    97     {
       
    98     switch (aIndex)
       
    99         {
       
   100         case 0:
       
   101             return iListBox; // Returns the pointer to listbox object.
       
   102         default:
       
   103             return NULL; // Exception : Returns NULL.
       
   104         }
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 TKeyResponse CLandmarksInfoContainer::OfferKeyEventL(
       
   111     const TKeyEvent& aKeyEvent, TEventCode aType)
       
   112     {
       
   113 	TKeyResponse response = EKeyWasNotConsumed;
       
   114 
       
   115     switch (aKeyEvent.iCode)
       
   116         {
       
   117         case EKeyUpArrow:
       
   118         case EKeyDownArrow:
       
   119             // Scrolling the listbox. Forward to iListBox.
       
   120             response = iListBox->OfferKeyEventL(aKeyEvent, aType);
       
   121             break;
       
   122 
       
   123         case EKeyLeftArrow:
       
   124         case EKeyRightArrow:
       
   125             // Eat these to disable switching views
       
   126             response = EKeyWasConsumed;
       
   127             break;
       
   128 
       
   129         case EKeyDevice3:
       
   130             EditLandmarkL();
       
   131             response = EKeyWasConsumed;
       
   132             break;
       
   133             
       
   134         default:
       
   135             // menu keys should be handled
       
   136             break;
       
   137         }
       
   138         
       
   139 	return response;
       
   140     }
       
   141     
       
   142 // -----------------------------------------------------------------------------
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CLandmarksInfoContainer::StoreTitlePaneL()
       
   146     {
       
   147     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
       
   148     iTitlePane = (CAknTitlePane*) statusPane->ControlL(
       
   149         TUid::Uid(EEikStatusPaneUidTitle));
       
   150 
       
   151     iOriginalTitle = iTitlePane->Text()->AllocL();
       
   152     }
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 void CLandmarksInfoContainer::RestoreTitlePane()
       
   158     {
       
   159     if (iTitlePane && iOriginalTitle)
       
   160         {
       
   161         iTitlePane->SetText(iOriginalTitle); // ownership is transferred
       
   162         }
       
   163     else
       
   164         {
       
   165         delete iOriginalTitle;
       
   166         }
       
   167     iOriginalTitle = NULL;
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CLandmarksInfoContainer::CreateListBoxL()
       
   174     {
       
   175     // Create a control to display a list of descriptors
       
   176     iListBox = new (ELeave) CAknSingleHeadingStyleListBox();
       
   177     iListBox->SetContainerWindowL(*this);
       
   178     iListBox->ConstructL(this, 0);
       
   179 
       
   180     // Create scrollbars
       
   181     CEikScrollBarFrame* scrollBar = iListBox->CreateScrollBarFrameL();
       
   182     scrollBar->SetScrollBarVisibilityL(
       
   183 		CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   184     }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 void CLandmarksInfoContainer::SizeChanged()
       
   190     {
       
   191 	// Set list box size.
       
   192 	iListBox->SetRect(Rect());
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 void CLandmarksInfoContainer::HandleResourceChange(TInt aType)
       
   199     {
       
   200     CCoeControl::HandleResourceChange(aType);
       
   201     if ( aType == KEikDynamicLayoutVariantSwitch )
       
   202         {
       
   203         SetRect(iView.ClientRect());
       
   204         }
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 void CLandmarksInfoContainer::LoadLandmarkL(TPosLmItemId aLandmarkId)
       
   211     {
       
   212 	delete iLandmark;
       
   213 	iLandmark = NULL;
       
   214 
       
   215     iLandmark = iEngine.LandmarkLC(aLandmarkId);
       
   216     CleanupStack::Pop(iLandmark);
       
   217 
       
   218     UpdateL();
       
   219     iListBox->View()->SetCurrentItemIndex(0);
       
   220     }
       
   221     
       
   222 // -----------------------------------------------------------------------------
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 void CLandmarksInfoContainer::EditLandmarkL()
       
   226     {
       
   227     // Create editor
       
   228     TBool isEdited = EFalse;
       
   229 
       
   230     TInt selectedLine = iListBox->View()->CurrentItemIndex();
       
   231     TInt activeField = 0;
       
   232     if (selectedLine >= 0 && selectedLine < iFields.Count())
       
   233         {
       
   234         activeField = iFields[selectedLine];
       
   235         }
       
   236     
       
   237     CLandmarksEditDialog* editDialog = CLandmarksEditDialog::NewLC(
       
   238         *iLandmark, EFalse, isEdited, iEngine, activeField);
       
   239 
       
   240     TInt err = editDialog->ExecuteLD(R_LMREFAPP_EDIT_DIALOG);
       
   241     CleanupStack::Pop(editDialog);
       
   242     User::LeaveIfError(err);
       
   243 
       
   244     UpdateL();
       
   245 
       
   246     // Commit if edited
       
   247     if (isEdited)
       
   248         {
       
   249         iEngine.CommitLandmarkL(*iLandmark);
       
   250     
       
   251         // move to first field
       
   252         iListBox->View()->SetCurrentItemIndex(0);
       
   253         }
       
   254     }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 void CLandmarksInfoContainer::UpdateL()
       
   260     {
       
   261     CDesCArray* infoArray = iModel->GetLandmarkInfoL(*iLandmark, iFields);
       
   262 
       
   263     CTextListBoxModel* model = iListBox->Model();
       
   264     model->SetItemTextArray(infoArray);
       
   265     model->SetOwnershipType(ELbmOwnsItemArray);
       
   266     iListBox->HandleItemAdditionL();
       
   267 
       
   268     UpdateTitleBarL();
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // -----------------------------------------------------------------------------
       
   273 //
       
   274 void CLandmarksInfoContainer::UpdateTitleBarL()
       
   275     {
       
   276     TPtrC ptr;
       
   277     if (iLandmark)
       
   278         {
       
   279         iLandmark->GetLandmarkName(ptr);
       
   280         iTitlePane->SetTextL(ptr);
       
   281         }
       
   282     else 
       
   283         {
       
   284         iTitlePane->SetTextL(*iOriginalTitle);
       
   285         }
       
   286     }
       
   287 
       
   288