⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newapp11container2.cpp

📁 一个很不错的Symbian程序源代码,里面有图片和一些对话框
💻 CPP
字号:
/*
============================================================================
 Name        : CNewApp11Container2 from NewApp11Container2.cpp
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : Container control implementation
============================================================================
*/

// INCLUDE FILES
#include "NewApp11Container2.h"

#include <eiklabel.h>  // for example label control
#include<BARSREAD.H>
#include<NewApp11.rsg>

#include<ToUnicode.h>
#include<COEINPUT.H>
#include <aknedsts.h> 
#include<gdi.h>

#include <avkon.hrh>
#include<eikseced.h>

#include <COEFONT.H>
#include <EIKDEF.H>
#include <aknglobalnote.h>
#include "Sockets.pan"

#include <eikgted.h> 

// ================= MEMBER FUNCTIONS =======================

// ---------------------------------------------------------
// CNewApp11Container2::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//


TText8 *  CNewApp11Container2::TestInputMethod()
{
	static TInt iFirstT9 = 0;

	TText8 * prsrc = NULL;
	MAknEditingStateIndicator * ei = CAknEnv::Static()->EditingStateIndicator() ;
    if (!ei)   return NULL;
    CAknIndicatorContainer *ic = ei->IndicatorContainer();        
    if (!ic)   return NULL;
    
	if(ic->IndicatorState(S_uid(EAknNaviPaneEditorIndicatorT9) ))
        {
			if(iFirstT9 == 0)
			{
				iFirstT9 = 1;
				prsrc = (TText8 *) "拼音";
			}
			else
			{
				iFirstT9 = 0;
				prsrc=(TText8 *) "笔划";
			}
                //to do ... if input method = T9 (即拼音和笔画)
        }
        else if(ic->IndicatorState(S_uid(EAknNaviPaneEditorIndicatorLowerCase)))
        {
		   iFirstT9 = 0;
			prsrc=(TText8 *) "abc";
        }
        else if(ic->IndicatorState(S_uid(EAknNaviPaneEditorIndicatorUpperCase)))
        {
           iFirstT9 = 0;
			prsrc=(TText8 *) "ABC";
        }
        else if(ic->IndicatorState(S_uid(EAknNaviPaneEditorIndicatorTextCase)))
        {
              iFirstT9 = 0;
			prsrc=(TText8 *) "Abc";
        }
        else if(ic->IndicatorState(S_uid(EAknNaviPaneEditorIndicatorNumberCase)))
        {
           iFirstT9 = 0;
			prsrc=(TText8 *) "123";
        }
		return  prsrc;
}





void CNewApp11Container2::ConstructL(const TRect& aRect)
    {
    CreateWindowL();


    TResourceReader reader;
	// r_aknexeditor_nicky_edwin
	iCoeEnv->CreateResourceReaderLC( reader, R_AKNEXEDITOR_NICKY_EDWIN  );
    //iCoeEnv->CreateResourceReaderLC( reader, R_EXSC_VIEW4_EDITOR );
    iEdwin = new ( ELeave ) CEikEdwin;
    iEdwin->SetAknEditorFlags( EAknEditorFlagEnableScrollBars );
    iEdwin->SetContainerWindowL( *this );
    iEdwin->ConstructFromResourceL( reader );
    CleanupStack::PopAndDestroy();  // Resource reader
   

	iEdwin->SetObserver( this );
    iEdwin->SetBorder( TGulBorder::ESingleBlack );
	

   	
     iEdwin->SetAknEditorInputMode(EAknEditorAllInputModes);
     iEdwin->SetAknEditorAllowedInputModes(EAknEditorAllInputModes);

	iEdwin->SetAknEditorCurrentInputMode(EAknEditorTextInputMode);
	iEdwin->SetAknEditorPermittedCaseModes(EAknEditorLowerCase);

	
	_LIT(EWriteInfoabc, "abc");
	iWriteInfo.Append(EWriteInfoabc);
    iEdwin->SetExtent( TPoint( 60, 270 ), TSize(120, 20) );
	 HBufC * test = HBufC::NewL(20);
	 test->Des().Copy(_L("test"));
	 iEdwin->SetTextL(test);
	 delete test;


	// iEdwin->SetAknEditorInputMode(EAknEditorTextInputMode);
	// iEdwin->SetAknEditorPermittedCaseModes(EAknEditorLowerCase);
	 iWriteMode = 0;
  //  iEdwin->SetSelectionL(aShowText.Length(),0);
     iEdwin->SetFocus(ETrue);
     iEdwin->MakeVisible(ETrue);


	 iCoeEnv->CreateResourceReaderLC( reader, R_OUTPUT_VIEW_RTEXTED ); 

  // iCoeEnv->CreateResourceReaderLC( reader, R_AKNEXEDITOR_NICKY_EDWIN )  ; 
	 iOutputWindow = new ( ELeave ) CEikRichTextEditor();

    iOutputWindow->SetContainerWindowL( *this );
    iOutputWindow->ConstructFromResourceL( reader );
    CleanupStack::PopAndDestroy();  // Resource reader

    iOutputWindow->SetExtent( TPoint( 3,50 ),TSize(235, 220) );
	iStatusWindow = new ( ELeave ) CEikLabel;
    iStatusWindow->SetContainerWindowL( *this );

	_LIT(EInitData, "aaaaaa");
	TBuf<50> uninitialised(EInitData);
    iStatusWindow->SetTextL( uninitialised );
    iStatusWindow->SetExtent( TPoint(10, 5),  TSize( 190,40 ) );

    SetRect(aRect);
    ActivateL();
    }

// Destructor
CNewApp11Container2::~CNewApp11Container2()
    {

    delete iEdwin;
    iEdwin = NULL;

    }

// ---------------------------------------------------------
// CNewApp11Container2::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CNewApp11Container2::SizeChanged()
    {
    // TODO: Add here control resize code etc.
    iEdwin->SetExtent( TPoint( 60, 270 ), TSize(120, 20) );
    iStatusWindow->SetExtent( TPoint(10, 5), TSize( 190,40 ) );

    }

// ---------------------------------------------------------
// CNewApp11Container2::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CNewApp11Container2::CountComponentControls() const
    {
    return 3; // return nbr of controls inside this container
    }

// ---------------------------------------------------------
// CNewApp11Container2::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CNewApp11Container2::ComponentControl(TInt aIndex) const
    {
    switch ( aIndex )
        {
   case 0:
         return iEdwin;
   case 1:
	   return iOutputWindow;
   case 2:
	   return iStatusWindow;
   default:
       return NULL;
        }
    }

// ---------------------------------------------------------
// CNewApp11Container2::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CNewApp11Container2::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    // TODO: Add your drawing code here
    // example code...
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );

	gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( 210 );
	TRect  aaRect;
	aaRect.iTl = TPoint(5,270);
	aaRect.iBr = TPoint(30,290);
    gc.DrawRect(aaRect);
	TInt colorRed = 25;
	gc.SetPenColor(colorRed);
	const CFont *myFont = iEikonEnv->NormalFont();
	gc.UseFont(myFont);
	TPoint textPoint(5, 290);
	TPoint textPoint1(30,180);

		TBufC<40> aa(iEditContent);
		TPtr f = aa.Des();
		TText8 *psrc = (TText8*) &f;


		ToUnicode unicode;
		unicode.ConvertAA();
		HBufC *pOut = unicode.ConvertL(psrc);
		gc.DrawText( iEditContent,textPoint1);


    gc.DrawText(iWriteInfo, textPoint);
	gc.DiscardFont();
    }

// ---------------------------------------------------------
// CNewApp11Container2::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//   
void CNewApp11Container2::HandleControlEventL(CCoeControl * aControl,TCoeEvent aEventType)
    {
    // TODO: Add your control event handler code here

		TBuf<40>   buf;
		if(aControl == iEdwin)
		{	
			iEdwin->GetText(buf);
			if(iEditContent.Compare(buf) == 0 )
			{
				return;;
			}
			iEditContent = buf;
			DrawNow();
			return;
		}
		return;
    }


  TKeyResponse CNewApp11Container2::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType )
  {
	if(aKeyEvent.iScanCode == EStdKeyHash)
	{
		if (aType==EEventKey ||  aType==EEventKeyDown){
			return EKeyWasConsumed;
		}
		//#号键
		iWriteMode = (iWriteMode+1)%3;
		if(iWriteMode == 0)
		{	// abc

			 iEdwin->SetAknEditorCurrentInputMode(EAknEditorTextInputMode);
			 iEdwin->SetAknEditorPermittedCaseModes(EAknEditorLowerCase);
			 _LIT(EWriteInfoabc, "abc");
			 iWriteInfo.Delete(0, iWriteInfo.Length() );
			 iWriteInfo.Append(EWriteInfoabc);
			 DrawNow();
		}
		else if(iWriteMode == 1)
		{	//中文 EAknEditorNullInputMode
			//iEdwin->SetAknEditorCurrentInputMode(EAknEditorTextInputMode);
			TText8 *aa  = (TText8*)"拼音";
			ToUnicode unicode;

			iWriteInfo.Delete(0,iWriteInfo.Length() );
			iWriteInfo.Append(*unicode.ConvertL(aa));
			iEdwin->SetAknEditorCurrentInputMode(EAknEditorNullInputMode);
			iEdwin->SetFocus( ETrue );
			DrawNow();
		}
		else
		{	//数据
			_LIT(EWriteInfoabc, "123");
			iWriteInfo.Delete(0,iWriteInfo.Length() );
			iWriteInfo.Append(EWriteInfoabc);
			iEdwin->SetAknEditorCurrentInputMode(EAknEditorNumericInputMode);
			DrawNow();
		}
		return EKeyWasConsumed;

	}
	if ( iEdwin )
        {
        if ( iEdwin->IsFocused() )
            {
            return iEdwin->OfferKeyEventL( aKeyEvent, aType );
            }
        }
    return EKeyWasNotConsumed;
    }



  // ADD BY LUXM
  // -----------------------------------------------------------------------------
// CSocketsAppView::PrintNotify()
// Displays text on console.
// -----------------------------------------------------------------------------
//
void CNewApp11Container2::PrintNotify( const TDesC& aDes, TUint aFontStyle )
    {
    // Display these characters in the main output window,
    // in the specified style
    SetFontStyle( aFontStyle );

    for ( TInt i = 0; i < aDes.Length(); i++ )
        {
         TRAPD( error, KeyEventL( aDes[i] ) );
        if( error != KErrNone )
            {
            User::Panic ( KPanicSockets, ESocketsAppView );
            }
        }
    }

// -----------------------------------------------------------------------------
// CSocketsAppView::PrintNotify()
// Displays text on console.
// -----------------------------------------------------------------------------
//
void CNewApp11Container2::PrintNotify( const TDesC8& aDes, TUint aFontStyle )
    {
    // Display these characters in the main output window,
    // in the specified style
    SetFontStyle( aFontStyle );

    for ( TInt i = 0; i < aDes.Length(); i++ )
        {
        TRAPD( error, KeyEventL( aDes[i] ) );
        if( error != KErrNone )
            {
            User::Panic ( KPanicSockets, ESocketsAppView );
            }
        }

}

	// -----------------------------------------------------------------------------
// CSocketsAppView::ErrorNotify()
// Notifies user of an error.
// -----------------------------------------------------------------------------
//
void CNewApp11Container2::ErrorNotify( const TDesC& aErrMessage, TInt aErrCode )
    {
    _LIT( KNewLine, "\n" );

    TRAPD( error,

    HBufC* errorTitleCode = HBufC::NewLC( 50 );
    errorTitleCode->Des().Append( aErrMessage );
    errorTitleCode->Des().Append( KNewLine );
    errorTitleCode->Des().AppendNum( aErrCode );

    CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
    globalNote->ShowNoteL( EAknGlobalErrorNote, *errorTitleCode );
    CleanupStack::PopAndDestroy( globalNote );
    CleanupStack::PopAndDestroy( errorTitleCode );
   )

    if( error != KErrNone )
        {
        User::Panic ( KPanicSockets, ESocketsAppView );
        }
    }

// -----------------------------------------------------------------------------
// CSocketsAppView::SetStatus()
// Changes 'status' display.
// -----------------------------------------------------------------------------
//
void CNewApp11Container2::SetStatus( const TDesC& aStatus )
    {
    // Update contents of status window
    TRAPD( error, iStatusWindow->SetTextL( aStatus ) );
    if( error != KErrNone )
        {
        User::Panic ( KPanicSockets, ESocketsAppView );
        }

    iStatusWindow->DrawDeferred();
    }


	// -----------------------------------------------------------------------------
// CSocketsAppView::SetFontStyle()
// Changes font style for subsequent text.
// -----------------------------------------------------------------------------
//
void CNewApp11Container2::SetFontStyle( TUint aFontStyle )
    {
    // Set current main window style to match that requested
    UpdateFontAttribute( aFontStyle, CEikGlobalTextEditor::EBold );
    UpdateFontAttribute( aFontStyle, CEikGlobalTextEditor::EItalic );
    UpdateFontAttribute( aFontStyle, CEikGlobalTextEditor::EUnderline );
    }

// -----------------------------------------------------------------------------
// CSocketsAppView::UpdateFontAttribute()
// Set or clear an individual font attribute.
// -----------------------------------------------------------------------------
//
void CNewApp11Container2::UpdateFontAttribute( TUint aFontStyle, TInt aAttribute )
    {
    // Ensure an individual attribute is on or off as requested
    if ( ( aFontStyle & aAttribute ) != ( iFontStyle & aAttribute ) )
        {
        // Note: This function 'toggles' styles based on the bits set in
        //       supplied mask, i.e. supplying the same bit twice toggles
        //       that style on then off again
        TRAPD( error, iOutputWindow->BoldItalicUnderlineEventL( aAttribute ) );
        if( error != KErrNone )
            {
            User::Panic ( KPanicSockets, ESocketsAppView );
            }
        iFontStyle ^= aAttribute;
        }
    }
void  CNewApp11Container2::KeyEventL( TInt aCode )
    {
    // Add this 'keypress' to the main output window
    TKeyEvent event;
    event.iCode = aCode;
    event.iScanCode = aCode;
    iOutputWindow->SetFocus( ETrue );
    iOutputWindow->OfferKeyEventL( event, EEventKey );
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -