landmarksui/uicontrols/src/CLmkEditorListField.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     1 /*
       
     2 * Copyright (c) 2002 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:    Methods for landmark editor text field.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 // INCLUDE FILES
       
    25 #include <eikedwin.h>
       
    26 #include <AknUtils.h>
       
    27 #include <eikcapc.h>
       
    28 #include <AknPopupField.h>
       
    29 #include <StringLoader.h>
       
    30 #include <lmkui.rsg>
       
    31 #include "LmkConsts.h"
       
    32 #include "CLmkDbUtils.h"
       
    33 #include "MLmkEditorUiBuilder.h"
       
    34 #include "CLmkEditorListField.h"
       
    35 
       
    36 // CONSTANTS
       
    37 _LIT(KEmptyCatName, " ");
       
    38 
       
    39 /// Unnamed namespace for local definitions
       
    40 namespace {
       
    41 const TInt KNumberOfLines( 4 );
       
    42 }  // namespace
       
    43 
       
    44 // ================= MEMBER FUNCTIONS =======================
       
    45 
       
    46 // ----------------------------------------------------
       
    47 // CLmkEditorListField::CLmkEditorListField
       
    48 // ----------------------------------------------------
       
    49 //
       
    50 CLmkEditorListField::CLmkEditorListField
       
    51         ( MLmkFieldData& aField,
       
    52 		  MLmkEditorUiBuilder& aUiBuilder ) :
       
    53     CLmkEditorFieldBase( aField, aUiBuilder )
       
    54     {
       
    55     }
       
    56 
       
    57 // ----------------------------------------------------
       
    58 // CLmkEditorListField::ConstructL
       
    59 // ----------------------------------------------------
       
    60 //
       
    61 void CLmkEditorListField::ConstructL()
       
    62     {
       
    63 
       
    64     // Create and insert a line in the dialog
       
    65     iControl = static_cast<CEikEdwin*>( iUiBuilder.CreateLineL(
       
    66             FieldLabel(), LandmarkItemField().UniqueFieldIdentity(),
       
    67             EEikCtEdwin ) );
       
    68 
       
    69     // ctrl is now owned by the dialog
       
    70     AknEditUtils::ConstructEditingL( iControl,
       
    71                                      KMaxCategoryNameFieldLen,
       
    72                                      KNumberOfLines,
       
    73             EEikEdwinDisplayOnly | EEikEdwinResizable
       
    74             | EEikEdwinNoAutoSelection, EEikEdwinIgnoreVirtualCursor
       
    75             | EEikEdwinAvkonDisableCursor,
       
    76             EFalse, EFalse, EFalse );
       
    77 
       
    78     // Get text
       
    79     HBufC* textBuf = HBufC::NewLC( KMaxCategoryNameFieldLen);
       
    80     TPtr text= textBuf->Des();
       
    81     RArray<TPosLmItemId>& categories = LandmarkItemField().Categories();
       
    82     TInt count( categories.Count() );
       
    83 
       
    84     HBufC* catName;
       
    85     //if only one category
       
    86     if ( count == 1 )
       
    87         {
       
    88         catName = CLmkDbUtils::CategoryNameL( iUiBuilder.Database(),
       
    89                                     categories[0] );
       
    90         }
       
    91     else
       
    92         {
       
    93         if (count > 1)
       
    94 	        {
       
    95 	        catName = StringLoader::LoadL( R_LMK_CATEGORIES_LIST_FORMAT,
       
    96 	                                       count,
       
    97 	                                       const_cast< CEikonEnv *>( iEnv ));
       
    98 	        }
       
    99 	    else // No Category, Don't display the string
       
   100 		    {
       
   101 		    catName	=  HBufC::NewL(20);
       
   102 			*catName = KEmptyCatName;
       
   103 		    }
       
   104         }
       
   105     text.Append( *catName );
       
   106     delete catName;
       
   107     catName = NULL;
       
   108     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( text );
       
   109     iControl->SetAknEditorCase( EAknEditorTextCase );
       
   110 
       
   111     // Set formatted text to editor control
       
   112    	iControl->SetTextL( &text );
       
   113     // SetTextL method above copied the text to the control,
       
   114     // so it is safe to destroy the buffer
       
   115     CleanupStack::PopAndDestroy( textBuf );
       
   116 
       
   117 	// readonly and no cursor
       
   118 	iControl->AddFlagToUserFlags( CEikEdwin::EReadOnly | CEikEdwin::EDisplayOnly |
       
   119                                   CEikEdwin::EAvkonDisableCursor );
       
   120 
       
   121     // CreateTextViewL() is flagged as deprecated but if it is not
       
   122     // called here the ActivateL() below crashes sometimes.
       
   123     iControl->CreateTextViewL();
       
   124     iCaptionedCtrl = iUiBuilder.LineControl( ControlId() );
       
   125     }
       
   126 
       
   127 // ----------------------------------------------------
       
   128 // CLmkEditorListField::NewL
       
   129 // ----------------------------------------------------
       
   130 //
       
   131 CLmkEditorListField* CLmkEditorListField::NewL
       
   132         ( MLmkFieldData& aField,
       
   133 		 MLmkEditorUiBuilder& aUiBuilder  )
       
   134     {
       
   135     CLmkEditorListField* self =
       
   136         new(ELeave) CLmkEditorListField( aField, aUiBuilder );
       
   137     CleanupStack::PushL( self );
       
   138     self->ConstructL();
       
   139     CleanupStack::Pop( self );
       
   140     return self;
       
   141     }
       
   142 
       
   143 // ----------------------------------------------------
       
   144 // CLmkEditorListField::~CLmkEditorListField
       
   145 // ----------------------------------------------------
       
   146 //
       
   147 CLmkEditorListField::~CLmkEditorListField()
       
   148     {
       
   149     }
       
   150 
       
   151 // ----------------------------------------------------
       
   152 // CLmkEditorListField::SaveFieldL
       
   153 // ----------------------------------------------------
       
   154 //
       
   155 TBool CLmkEditorListField::SaveFieldL()
       
   156     {
       
   157     return ETrue;
       
   158     }
       
   159 
       
   160 // ----------------------------------------------------
       
   161 // CLmkEditorListField::ActivateL
       
   162 // ----------------------------------------------------
       
   163 //
       
   164 void CLmkEditorListField::ActivateL()
       
   165     {
       
   166     iCaptionedCtrl->ActivateL();
       
   167     }
       
   168 
       
   169 // ----------------------------------------------------
       
   170 // CLmkEditorListField::UpdateL
       
   171 // ----------------------------------------------------
       
   172 //
       
   173 void CLmkEditorListField::UpdateL()
       
   174     {
       
   175     HBufC* textBuf = HBufC::NewLC( KMaxCategoryNameFieldLen );
       
   176     TPtr text= textBuf->Des();
       
   177     RArray<TPosLmItemId> categories = LandmarkItemField().Categories();
       
   178     TInt count( categories.Count() );
       
   179 
       
   180     HBufC* catName;
       
   181     if ( count == 1 )
       
   182         {
       
   183         catName = CLmkDbUtils::CategoryNameL( iUiBuilder.Database(),
       
   184                                     categories[0] );
       
   185         }
       
   186     else
       
   187         {
       
   188    		if ( count > 1 )
       
   189 	        {
       
   190 	        catName = StringLoader::LoadL( R_LMK_CATEGORIES_LIST_FORMAT,
       
   191 		                                   count,
       
   192 		                                   const_cast< CEikonEnv *>( iEnv ) );
       
   193 		    }
       
   194 		else // No Category, Don't display the string
       
   195 		    {
       
   196 		    catName	=  HBufC::NewL(20);
       
   197 			*catName = KEmptyCatName;
       
   198 		    }
       
   199         }
       
   200 
       
   201     text.Append( *catName );
       
   202     delete catName;
       
   203     catName = NULL;
       
   204     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( text );
       
   205     iControl->SetTextL( &text );
       
   206     iControl->DrawDeferred();
       
   207     CleanupStack::PopAndDestroy( textBuf );
       
   208 
       
   209     HBufC* label;
       
   210     if ( count > 1 )
       
   211         {
       
   212         label = iEnv->AllocReadResourceL( R_LMK_CATEGORIES_LABEL );
       
   213         }
       
   214     else
       
   215         {
       
   216         label = iEnv->AllocReadResourceL( R_LMK_CATEGORY_LABEL );
       
   217         }
       
   218 
       
   219     CleanupStack::PushL( label );
       
   220     LandmarkItemField().SetLabel( label );
       
   221     SetFieldLabelL( label );
       
   222     CleanupStack::PopAndDestroy();
       
   223     }
       
   224 
       
   225 // Added newly............ for supporting Single Category Name in Editor
       
   226 
       
   227 // ----------------------------------------------------
       
   228 // CLmkEditorListField::ConstructL
       
   229 // ----------------------------------------------------
       
   230 //
       
   231 void CLmkEditorListField::ConstructL(const TDesC& aCategoryName)
       
   232     {
       
   233 
       
   234     // Create and insert a line in the dialog
       
   235     iControl = static_cast<CEikEdwin*>( iUiBuilder.CreateLineL(
       
   236             FieldLabel(), LandmarkItemField().UniqueFieldIdentity(),
       
   237             EEikCtEdwin ) );
       
   238 
       
   239     // ctrl is now owned by the dialog
       
   240     AknEditUtils::ConstructEditingL( iControl,
       
   241                                      KMaxCategoryNameFieldLen,
       
   242                                      KNumberOfLines,
       
   243             EEikEdwinDisplayOnly | EEikEdwinResizable
       
   244             | EEikEdwinNoAutoSelection, EEikEdwinIgnoreVirtualCursor
       
   245             | EEikEdwinAvkonDisableCursor,
       
   246             EFalse, EFalse, EFalse );
       
   247 
       
   248     // Get text
       
   249     HBufC* textBuf = HBufC::NewLC( KMaxCategoryNameFieldLen );
       
   250     TPtr text= textBuf->Des();
       
   251     RArray<TPosLmItemId>& categories = LandmarkItemField().Categories();
       
   252     TInt count( categories.Count() );
       
   253 
       
   254     HBufC* catName;
       
   255     //if only one category
       
   256     if ( count == 1 )
       
   257         {
       
   258 		text.Append(aCategoryName);
       
   259         }
       
   260     else
       
   261         {
       
   262         if ( count > 1 )
       
   263 	        {
       
   264 	        catName = StringLoader::LoadL( R_LMK_CATEGORIES_LIST_FORMAT,
       
   265 	                                       count,
       
   266 	                                       const_cast< CEikonEnv *>( iEnv ));
       
   267 			text.Append( *catName );
       
   268 			delete catName;
       
   269 			catName = NULL;
       
   270 	        }
       
   271 	    else // No Category, Don't display the string
       
   272 		    {
       
   273 		    catName	=  HBufC::NewL(20);
       
   274 			*catName = KEmptyCatName;
       
   275 		    }
       
   276         }
       
   277 
       
   278     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( text );
       
   279     iControl->SetAknEditorCase( EAknEditorTextCase );
       
   280 
       
   281     // Set formatted text to editor control
       
   282    	iControl->SetTextL( &text );
       
   283     // SetTextL method above copied the text to the control,
       
   284     // so it is safe to destroy the buffer
       
   285     CleanupStack::PopAndDestroy( textBuf );
       
   286 
       
   287 	// readonly and no cursor
       
   288 	iControl->AddFlagToUserFlags( CEikEdwin::EReadOnly | CEikEdwin::EDisplayOnly |
       
   289                                   CEikEdwin::EAvkonDisableCursor );
       
   290 
       
   291     // CreateTextViewL() is flagged as deprecated but if it is not
       
   292     // called here the ActivateL() below crashes sometimes.
       
   293     iControl->CreateTextViewL();
       
   294     iCaptionedCtrl = iUiBuilder.LineControl( ControlId() );
       
   295     }
       
   296 
       
   297 // ----------------------------------------------------
       
   298 // CLmkEditorListField::NewL
       
   299 // ----------------------------------------------------
       
   300 //
       
   301 CLmkEditorListField* CLmkEditorListField::NewL
       
   302         ( MLmkFieldData& aField,
       
   303 		 MLmkEditorUiBuilder& aUiBuilder,
       
   304 		 const TDesC& aCategoryName  )
       
   305     {
       
   306     CLmkEditorListField* self =
       
   307         new(ELeave) CLmkEditorListField( aField, aUiBuilder );
       
   308     CleanupStack::PushL( self );
       
   309     self->ConstructL(aCategoryName);
       
   310     CleanupStack::Pop( self );
       
   311     return self;
       
   312     }
       
   313 
       
   314 // ----------------------------------------------------
       
   315 // CLmkEditorListField::Control
       
   316 // ----------------------------------------------------
       
   317 //
       
   318 
       
   319 CEikEdwin* CLmkEditorListField::Control()
       
   320 	{
       
   321 	return iControl;
       
   322 	}
       
   323 // End of File
       
   324