locationlandmarksrefappfors60/Src/LandmarksCategoriesDialog.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-2005 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 *       Implements the CLandmarksCategoriesDialog class
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <e32std.h>
       
    22 #include <akntitle.h> 
       
    23 #include <aknappui.h>
       
    24 #include <eikmenup.h>
       
    25 
       
    26 #include "LmRefApp.hrh"
       
    27 #include <lmrefapp.rsg>
       
    28 #include "LandmarksLmCategoriesModel.h"
       
    29 #include "LandmarksApplicationEngine.h"
       
    30 #include "LandmarksCategoriesDialog.h"
       
    31 
       
    32 // ============================ MEMBER FUNCTIONS ===============================
       
    33 
       
    34 // -----------------------------------------------------------------------------
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CLandmarksCategoriesDialog::CLandmarksCategoriesDialog(
       
    38     TInt& aSelectedItem,
       
    39     CArrayFixFlat<TInt>* aMarkedItems,
       
    40     CDesCArray* aListItems)
       
    41     : 
       
    42     CAknMarkableListDialog(aSelectedItem, aMarkedItems, aListItems, -1, -1, NULL)
       
    43 	{
       
    44 	}
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CLandmarksCategoriesDialog::~CLandmarksCategoriesDialog()
       
    50 	{
       
    51     // Restore title pane. Ownership of iOriginalTitle transferred.
       
    52     if (iOriginalTitle && iTitlePane)
       
    53         {
       
    54         iTitlePane->SetText(iOriginalTitle);
       
    55         }
       
    56 	}
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 TInt CLandmarksCategoriesDialog::RunDialogL(
       
    62     CLandmarksLmCategoriesModel& aLmCategoriesModel)
       
    63     {
       
    64     // Create array of marked indeces
       
    65     CArrayFixFlat<TInt>* markedItems = aLmCategoriesModel.SelectedCategoriesL();
       
    66     CleanupStack::PushL(markedItems);
       
    67 
       
    68     // Create name array
       
    69     CDesCArray* listItems = aLmCategoriesModel.FormattedCategoryNamesL();
       
    70     CleanupStack::PushL(listItems);
       
    71 
       
    72     // Create the dialog
       
    73     TInt selectedItem = 0;
       
    74 
       
    75     CLandmarksCategoriesDialog* dialog = 
       
    76         new (ELeave) CLandmarksCategoriesDialog(
       
    77             selectedItem, markedItems, listItems);
       
    78     
       
    79 	dialog->PrepareLC(R_LMREFAPP_EDIT_CATEGORIES_DIALOG);
       
    80 
       
    81 	// pre-mark currently selected categories 
       
    82     CEikListBox* listBox = (CEikListBox*) dialog->Control(ESelectionListControl);
       
    83     for (TInt i = 0; i < markedItems->Count(); i++)
       
    84     {
       
    85         listBox->View()->SelectItemL((*markedItems)[i]);
       
    86     }
       
    87 
       
    88     TInt res = dialog->RunLD();
       
    89     if (res)
       
    90         {
       
    91         aLmCategoriesModel.SelectCategoriesL(*markedItems);
       
    92         }
       
    93         
       
    94     CleanupStack::PopAndDestroy(2, markedItems);
       
    95     return res;
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void CLandmarksCategoriesDialog::PostLayoutDynInitL()
       
   102     {
       
   103     CAknMarkableListDialog::PostLayoutDynInitL();
       
   104     
       
   105     // Save original title
       
   106     CEikStatusPane* statusPane = iAvkonAppUi->StatusPane();
       
   107     iTitlePane = (CAknTitlePane*) statusPane->ControlL(
       
   108         TUid::Uid(EEikStatusPaneUidTitle));
       
   109     iOriginalTitle = iTitlePane->Text()->AllocL();
       
   110 
       
   111     // Update title
       
   112     HBufC* title = iCoeEnv->AllocReadResourceAsDes16L(
       
   113         R_LMREFAPP_EDIT_CAT_TITLE);
       
   114     iTitlePane->SetText(title);
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 TKeyResponse CLandmarksCategoriesDialog::OfferKeyEventL(
       
   121     const TKeyEvent& aKeyEvent, 
       
   122     TEventCode aType)
       
   123     {
       
   124     if (aKeyEvent.iCode == EKeyDevice3)
       
   125         {
       
   126         // An item should be marked/unmarked.
       
   127         CEikListBox* listBox = (CEikListBox*) Control(ESelectionListControl);
       
   128         listBox->View()->ToggleItemL(listBox->View()->CurrentItemIndex());
       
   129         listBox->DrawDeferred();
       
   130         return EKeyWasConsumed;
       
   131         }
       
   132 
       
   133     return CAknMarkableListDialog::OfferKeyEventL(aKeyEvent, aType);
       
   134     }
       
   135 
       
   136