uifw/AvKon/src/AknQueryValuePhone.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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: 
       
    15 *
       
    16 */
       
    17 
       
    18 // AknQueryValuePhone.cpp
       
    19 //
       
    20 // Copyright (c) 2001 Symbian Ltd.  All rights reserved.
       
    21 //
       
    22 
       
    23 #include "eikenv.h"
       
    24 
       
    25 #include <eikmfne.h>
       
    26 #include <avkon.hrh>
       
    27 #include <avkon.rsg>
       
    28 #include "AknQueryValuePhone.h"
       
    29 #include "AknQueryDialog.h"
       
    30 #include "akntextsettingpage.h"
       
    31 
       
    32 #include "AknPanic.h"
       
    33 
       
    34 //-------------------------------------------------
       
    35 // class CAknQueryValuePhone
       
    36 //-------------------------------------------------
       
    37 
       
    38 /**
       
    39  * First stage of two stage construction.
       
    40  */
       
    41 EXPORT_C CAknQueryValuePhone* CAknQueryValuePhone::NewL()
       
    42 	{
       
    43 	CAknQueryValuePhone* self = NewLC();
       
    44 	CleanupStack::Pop();
       
    45 	return self;
       
    46 	}
       
    47 
       
    48 /**
       
    49  * First stage of two stage construction.
       
    50  */
       
    51 EXPORT_C CAknQueryValuePhone* CAknQueryValuePhone::NewLC()
       
    52 	{
       
    53 	CAknQueryValuePhone* self = new(ELeave) CAknQueryValuePhone;
       
    54 	CleanupStack::PushL(self);
       
    55 	self->ConstructL();
       
    56 	return self;
       
    57 	}
       
    58 
       
    59 /**
       
    60  * Destructor.
       
    61  */
       
    62 EXPORT_C CAknQueryValuePhone::~CAknQueryValuePhone()
       
    63 	{
       
    64 	delete iText;
       
    65 	}
       
    66 
       
    67 /**
       
    68  * Set the array.
       
    69  * 
       
    70  * @param aArray pointer to array, ownership is not passed
       
    71  */
       
    72 EXPORT_C void CAknQueryValuePhone::SetArrayL(const CAknQueryValuePhoneArray* aArray)
       
    73 	{
       
    74 	iArray = aArray;
       
    75 	}
       
    76 
       
    77 /**
       
    78  * Set the string used for the query caption to be a string other than the default.
       
    79  *
       
    80  * @param aResourceId		resource id of string to use for caption.
       
    81  *
       
    82  */
       
    83 EXPORT_C void CAknQueryValuePhone::SetQueryCaption(TInt aResourceId)
       
    84 	{
       
    85 	iQueryCaptionId = aResourceId;
       
    86 	}
       
    87 
       
    88 /**
       
    89  * Return the current value, which may have been set by the user
       
    90  *
       
    91  * @return The current value, ownership is not passed
       
    92  *
       
    93  */
       
    94 EXPORT_C HBufC* CAknQueryValuePhone::Value() const
       
    95 	{
       
    96 	return iText;
       
    97 	}
       
    98 
       
    99 /**
       
   100  * Returns the array as a descriptor array
       
   101  * 
       
   102  * @return descriptor array, ownership is not passed
       
   103  */
       
   104 EXPORT_C const MDesCArray* CAknQueryValuePhone::MdcArray() const
       
   105 	{
       
   106 	return iArray;
       
   107 	}
       
   108 
       
   109 /**
       
   110  * Returns the current value as text
       
   111  * 
       
   112  * @return	descriptor representing current value, new 
       
   113  * descriptor is created and left on cleanup stack, ownership passed back to client
       
   114  */
       
   115 EXPORT_C HBufC* CAknQueryValuePhone::CurrentValueTextLC()
       
   116 	{
       
   117 	HBufC* buf = HBufC::NewMaxLC(iText->Length());
       
   118 	TPtr ptr = buf->Des();
       
   119 	ptr = *iText;
       
   120 	return buf;
       
   121 	}
       
   122 
       
   123 /**
       
   124  * Returns the index in the array of the current value. 
       
   125  * If there are duplicates, returns the index of the first match.
       
   126  * If there are no matches, returns zero;
       
   127  *
       
   128  * @return index in array of current value
       
   129  */
       
   130 EXPORT_C TInt CAknQueryValuePhone::CurrentValueIndex() const
       
   131 	{
       
   132 	return iCurrentIndex;
       
   133 	}
       
   134 
       
   135 /**
       
   136  * Changes the current value to correspond to a value in the array.
       
   137  *
       
   138  * @param aIndex	index in array of value to set as current
       
   139  */
       
   140 EXPORT_C void CAknQueryValuePhone::SetCurrentValueIndex(const TInt aIndex)
       
   141 	{
       
   142 	iCurrentIndex = aIndex;
       
   143 	const CAknQueryValuePhoneArray::TextArray* textArray = iArray->Array();
       
   144 	if (IsValidIndex(aIndex))
       
   145 	    {
       
   146 	    TPtrC newPtr = textArray->MdcaPoint(aIndex); 
       
   147 	    TPtr currentPtr = iText->Des();
       
   148 	    currentPtr = newPtr;
       
   149 	    }
       
   150 	}
       
   151 
       
   152 /**
       
   153  * Creates a dialog containing a query control. If the value is edited and the Dialog
       
   154  * OK'd, the new value will be set as the current value. Otherwise the current value 
       
   155  * remains unchanged.
       
   156  *
       
   157  * @return	ETrue if current value was altered; EFalse otherwise
       
   158  */
       
   159 EXPORT_C TBool CAknQueryValuePhone::CreateEditorL()
       
   160 	{
       
   161 	TBool result = EFalse;
       
   162 	TInt keyPressed;
       
   163 
       
   164 	HBufC* queryString = CEikonEnv::Static()->AllocReadResourceLC(iQueryCaptionId);
       
   165 	TPtr textPtr = iText->Des();
       
   166 
       
   167 	if ( iFlags.IsSet( ESettingPageModeBitIndex ) )
       
   168 		{
       
   169 		CAknTextSettingPage* dlg =  new ( ELeave ) CAknTextSettingPage ( queryString, 
       
   170 			EAknSettingPageNoOrdinalDisplayed, EEikCtEdwin,
       
   171 			R_AVKON_DEFAULT_SETTING_PAGE_TEXT_EDITOR, 0, textPtr );
       
   172 		result =  dlg->ExecuteLD( );
       
   173 
       
   174 		if ( result )
       
   175 			keyPressed = EAknSoftkeyOk;
       
   176 		else
       
   177 			keyPressed = EAknSoftkeyCancel;
       
   178 		}
       
   179 	else
       
   180 		{
       
   181 		CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL(textPtr);
       
   182 		keyPressed = dlg->ExecuteLD(R_AVKON_DIALOG_QUERY_VALUE_PHONE,*queryString);
       
   183 		}
       
   184 
       
   185 	CleanupStack::PopAndDestroy(); // queryString
       
   186 
       
   187 	switch(keyPressed)
       
   188 		{
       
   189 	case EAknSoftkeyOk:
       
   190 		result = ETrue;
       
   191 		if ( iFlags.IsSet( EAutoAppendBitIndex ) )
       
   192 			{
       
   193 			AppendValueIfNewL();
       
   194 			}
       
   195 		CalculateCurrentIndex();
       
   196 		break;
       
   197 	case EAknSoftkeyCancel:
       
   198 		// fall through
       
   199 	case EAknSoftkeyBack:
       
   200 		// fall through
       
   201 	default:
       
   202 		result = EFalse;
       
   203 		break;
       
   204 		}
       
   205 
       
   206 	return result;
       
   207 	}
       
   208 
       
   209 /**
       
   210  * Two stage construction
       
   211  *
       
   212  */
       
   213 void CAknQueryValuePhone::ConstructL()
       
   214 	{
       
   215 	iQueryCaptionId = R_AVKON_TBUF_POPUP_FIELD_DEFAULT_PHONE_QUERY_PROMPT;
       
   216 	iText = HBufC::NewL(CAknQueryValuePhoneArray::KSafeSizeOfDescriptorForPhoneFormat);
       
   217 	}
       
   218 
       
   219 /**
       
   220  * Constructor. Does nothing.
       
   221  *
       
   222  */
       
   223 CAknQueryValuePhone::CAknQueryValuePhone()
       
   224 	{
       
   225 	}
       
   226 
       
   227 /**
       
   228  * Search for the current value in the list, and set the curent index 
       
   229  * to be the found index. If not found, set current index to 1 after the size of the array.
       
   230  *
       
   231  */
       
   232 void CAknQueryValuePhone::CalculateCurrentIndex()
       
   233 	{
       
   234 	// ensure that if the new value is not in the list, the current index is set to the beginning
       
   235 	TInt index = 0; 
       
   236 	const CAknQueryValuePhoneArray::TextArray* textArray = iArray->Array();
       
   237 	TInt length = textArray->MdcaCount();
       
   238 	// search through array to find match for current value
       
   239 	TBool match = EFalse;
       
   240 	for(TInt i = 0; i < length; i++)
       
   241 		{
       
   242 		TInt res = textArray->MdcaPoint(i).Compare(*iText);
       
   243 		if(res == 0)
       
   244 			{
       
   245 			index = i;
       
   246 			match = ETrue;
       
   247 			break;
       
   248 			}
       
   249 		}
       
   250 	if(!match)
       
   251 		index = length;
       
   252 	iCurrentIndex = index;
       
   253 	}
       
   254 
       
   255 /**
       
   256  * Append the current value if it is new
       
   257  *
       
   258  *
       
   259  */
       
   260 void CAknQueryValuePhone::AppendValueIfNewL()
       
   261 	{
       
   262 	const CAknQueryValuePhoneArray::TextArray* array = iArray->Array();
       
   263 	CalculateCurrentIndex();
       
   264 	if ( iCurrentIndex == array->MdcaCount() )
       
   265 		{
       
   266 		CAknQueryValuePhoneArray::TextArray* array = iArray->Array();
       
   267 		array->AppendL(*iText);
       
   268 		}
       
   269 	}
       
   270 
       
   271 EXPORT_C void CAknQueryValuePhone::Reserved_MAknQueryValue()
       
   272 	{
       
   273 
       
   274 	};
       
   275 
       
   276 
       
   277 //-------------------------------------------------
       
   278 // class CAknQueryValuePhoneArray
       
   279 //-------------------------------------------------
       
   280 
       
   281 /**
       
   282  * NewL.
       
   283  *
       
   284  */
       
   285 EXPORT_C CAknQueryValuePhoneArray* CAknQueryValuePhoneArray::NewL()
       
   286 	{
       
   287 	CAknQueryValuePhoneArray* self = NewLC();
       
   288 	CleanupStack::Pop();
       
   289 	return self;
       
   290 	}
       
   291 
       
   292 /**
       
   293  * NewLC.
       
   294  *
       
   295  */
       
   296 EXPORT_C CAknQueryValuePhoneArray* CAknQueryValuePhoneArray::NewLC()
       
   297 	{
       
   298 	CAknQueryValuePhoneArray* self = new(ELeave) CAknQueryValuePhoneArray;
       
   299 	CleanupStack::PushL(self);
       
   300 	self->ConstructL();
       
   301 	return self;
       
   302 	}
       
   303 
       
   304 /**
       
   305  * Destructor.
       
   306  */
       
   307 EXPORT_C CAknQueryValuePhoneArray::~CAknQueryValuePhoneArray()
       
   308 	{
       
   309 	}
       
   310 
       
   311 /**
       
   312  * Set the array of values. 
       
   313  * Note that client can use any implementation of array class, but must pass in a 
       
   314  * TArray generated from it (by calling the Array() method on the array class)
       
   315  *
       
   316  * @param array of values, ownership is passed
       
   317  */
       
   318 EXPORT_C void CAknQueryValuePhoneArray::SetArray(TextArray& aArray)
       
   319 	{
       
   320 	iArray = &aArray;
       
   321 
       
   322 	}
       
   323 
       
   324 /**
       
   325  * Get the array of values as a TArray. 
       
   326  * Note that client can use any implementation of array class, but the array is 
       
   327  * treated as a TArray.
       
   328  *
       
   329  * @return array of values, ownership is not passed
       
   330  */
       
   331 EXPORT_C CAknQueryValuePhoneArray::TextArray* CAknQueryValuePhoneArray::Array() const
       
   332 	{
       
   333 	return iArray;
       
   334 	}
       
   335 
       
   336 /**
       
   337  * Return the size of a maximal time string formated using the format string 
       
   338  * that was supplied during construction of this instance.
       
   339  * Two versions to eliminate compiler warnings.
       
   340  *
       
   341  * @return length of formatted string.
       
   342  */
       
   343 #ifdef __WINS__
       
   344 EXPORT_C const TInt CAknQueryValuePhoneArray::FormattedStringSize() const
       
   345 	{
       
   346 	return iFormattedStringSize;
       
   347 	}
       
   348 #else
       
   349 EXPORT_C TInt CAknQueryValuePhoneArray::FormattedStringSize() const
       
   350 	{
       
   351 	return iFormattedStringSize;
       
   352 	}
       
   353 #endif // __WINS__
       
   354 
       
   355 
       
   356 /**
       
   357  * Reports count of contained array
       
   358  *
       
   359  * @return count of contained array
       
   360  */
       
   361 EXPORT_C TInt CAknQueryValuePhoneArray::MdcaCount() const
       
   362 	{
       
   363 	return iArray->MdcaCount();
       
   364 	}
       
   365 
       
   366 /**
       
   367  * Returns array element, pass through to contained descriptor array
       
   368  *
       
   369  * @param index of element to return
       
   370  * @return descriptor representing array element, ownership is not passed
       
   371  */
       
   372 EXPORT_C TPtrC CAknQueryValuePhoneArray::MdcaPoint(TInt aIndex) const
       
   373 	{
       
   374 	return iArray->MdcaPoint(aIndex);
       
   375 	}
       
   376 
       
   377 /**
       
   378  * Constructor.
       
   379  */
       
   380 CAknQueryValuePhoneArray::CAknQueryValuePhoneArray()
       
   381 	{
       
   382 
       
   383 	}
       
   384 
       
   385 /**
       
   386  * ConstructL
       
   387  *
       
   388  * @param aResourceId	id of a resource containing a time format string
       
   389  */
       
   390 void CAknQueryValuePhoneArray::ConstructL()
       
   391 	{
       
   392 	iFormattedStringSize = KSafeSizeOfDescriptorForPhoneFormat;
       
   393 	}
       
   394 
       
   395 // End of File