testexecfw/statsrv/device/source/statapi/src/msgwin.cpp
changeset 0 3e07fef1e154
equal deleted inserted replaced
-1:000000000000 0:3e07fef1e154
       
     1 /*
       
     2 * Copyright (c) 2005-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  /********************************************************************************
       
    21  *
       
    22  * System Includes
       
    23  *
       
    24  ********************************************************************************/
       
    25 #include <e32std.h>
       
    26 #include <e32base.h>
       
    27 #include <eikenv.h>
       
    28 
       
    29 /********************************************************************************
       
    30  *
       
    31  * Local Includes
       
    32  *
       
    33  ********************************************************************************/
       
    34 #include "MsgWin.h"
       
    35 
       
    36 /********************************************************************************
       
    37  *
       
    38  * TMsgWinDesOverflow
       
    39  *
       
    40  * Locally defined class to allow us to handle a text buffer overflow
       
    41  * within the call to 'AppendFormat' used to format the text for
       
    42  * the message window.
       
    43  *
       
    44  * If the overflow occurs the overridden method 'Overflow' is called.
       
    45  *
       
    46  ********************************************************************************/
       
    47 class TMsgWinDesOverflow : public TDesOverflow
       
    48 {
       
    49 public:
       
    50 	// From base interface class TDesOverflow.
       
    51 	/* virtual */ void Overflow( TDes &aDes );
       
    52 };
       
    53 
       
    54 /********************************************************************************
       
    55  *
       
    56  * TMsgWinDesOverflow -- Overflow implementation
       
    57  *
       
    58  * Called if the buffer overflowed in the call to AppendFormat.
       
    59  * We replace the last few character with ellipses to indicate there
       
    60  * was more text that could not be shown.
       
    61  * The user has lost the end of their text anyway so changing the last few
       
    62  * characters will not make things worse.
       
    63  *
       
    64  ********************************************************************************/
       
    65 void TMsgWinDesOverflow::Overflow( TDes &aDes )
       
    66 {
       
    67 	_LIT( ellipses, "..." );
       
    68 	const TInt ellipsesLength = ellipses.operator const TDesC&().Length();
       
    69 
       
    70 	TInt textLength = aDes.MaxLength();
       
    71 	aDes.Replace( textLength - ellipsesLength, ellipsesLength, ellipses );
       
    72 }
       
    73 
       
    74 /********************************************************************************
       
    75  *
       
    76  * TMsgWin::Show
       
    77  *
       
    78  * Format the text the user passed and show a simple message window.
       
    79  * If the text was too long for our fixed buffer then we handle
       
    80  * the buffer overflow.
       
    81  *
       
    82  ********************************************************************************/
       
    83 void TMsgWin::Show( TPtrC text, ... )
       
    84 {
       
    85 	static const TInt defLength = 64;
       
    86 	TBuf<defLength> buffer(  _L("") );
       
    87 
       
    88 	VA_LIST list;
       
    89 	VA_START( list, text );
       
    90 
       
    91 	buffer.Zero();
       
    92 
       
    93 	// Use locally defined call for handling overflows.
       
    94 	TMsgWinDesOverflow	overflowHandler;
       
    95 	buffer.AppendFormatList( text, list, &overflowHandler);
       
    96 
       
    97 	VA_END(list);
       
    98 
       
    99 	CEikonEnv::Static()->AlertWin( buffer, _L("") );
       
   100 }