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

📄 datagramtestappview.cpp

📁 symbian下面收发消息的APIs
💻 CPP
字号:
/*
* ==============================================================================
*  Name        : DatagramTestappview.cpp
*  Part of     : DatagramTest
*  Interface   : 
*  Description : 
*  Version     : 
*
*  Copyright (c) 2007 Symbian Ltd.  All rights reserved.
* ==============================================================================
*/

// INCLUDE FILES
#include <coemain.h>
#include <eikedwin.h>
#include "DatagramTestAppView.h"

#include <aknnotewrappers.h> 

_LIT(KMessageSent,"Message Sent:");
_LIT(KMessageReceived,"Message Received:");
// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// CDatagramTestAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CDatagramTestAppView* CDatagramTestAppView::NewL( const TRect& aRect )
    {
    CDatagramTestAppView* self = CDatagramTestAppView::NewLC( aRect );
    CleanupStack::Pop( self );
    return self;
    }

// -----------------------------------------------------------------------------
// CDatagramTestAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CDatagramTestAppView* CDatagramTestAppView::NewLC( const TRect& aRect )
    {
    CDatagramTestAppView* self = new ( ELeave ) CDatagramTestAppView;
    CleanupStack::PushL( self );
    self->ConstructL( aRect );
    return self;
    }

// -----------------------------------------------------------------------------
// CDatagramTestAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CDatagramTestAppView::ConstructL( const TRect& aRect )
    {
    // Create a window for this application view
    CreateWindowL();
    
    // Set up a read-only editor window for displaying messages
    iEdwin = new ( ELeave ) CEikEdwin();
    iEdwin->SetContainerWindowL( *this );
    
    TInt edwinFlags = CEikEdwin::ENoAutoSelection;
    edwinFlags |= CEikEdwin::EJustAutoCurEnd;
    edwinFlags |= CEikEdwin::EReadOnly;
    edwinFlags |= CEikEdwin::EInclusiveSizeFixed;
    iEdwin->ConstructL( edwinFlags );
    iEdwin->CreateScrollBarFrameL();
	iEdwin->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);

    // Set the windows size
    SetRect( aRect );

    // Activate the window, which makes it ready to be drawn
    ActivateL();
    }

// -----------------------------------------------------------------------------
// CDatagramTestAppView::CDatagramTestAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CDatagramTestAppView::CDatagramTestAppView()
    {
    // No implementation required
    }


void CDatagramTestAppView::MsgReceivedL(TDesC& aMsg)
	{
	AddMessageL( KMessageReceived );
	AddMessageL( aMsg );
	}
	
void CDatagramTestAppView::MsgSentL(TDesC& aMsg)
	{
	AddMessageL( KMessageSent );	
	AddMessageL( aMsg );		
	}	




// -----------------------------------------------------------------------------
// CDatagramTestAppView::~CDatagramTestAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CDatagramTestAppView::~CDatagramTestAppView()
    {
    delete iEdwin;
    }


// -----------------------------------------------------------------------------
// CDatagramTestAppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CDatagramTestAppView::Draw( const TRect& /*aRect*/ ) const
    {
    // Get the standard graphics context
/*    CWindowGc& gc = SystemGc();

    // Gets the control's extent
    TRect drawRect( Rect());

    // Clears the screen
    gc.Clear( drawRect );
  */  
  	}

// -----------------------------------------------------------------------------
// CDatagramTestAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CDatagramTestAppView::SizeChanged()
    {
    iEdwin->SetRect( Rect() );  
    //DrawNow();
    }
    
    
 // -----------------------------------------------------------------------------
// CDatagramTestAppView::ComponentControl
// Return component control
// -----------------------------------------------------------------------------   
TInt CDatagramTestAppView::CountComponentControls() const
    {
    return 1; // return nbr of controls inside this container
    }

// -----------------------------------------------------------------------------
// CDatagramTestAppView::ComponentControl
// Return component control
// -----------------------------------------------------------------------------
//
CCoeControl* CDatagramTestAppView::ComponentControl(TInt aIndex) const
    {
    switch ( aIndex )
        {
        case 0:
            return iEdwin;

        default:
            return NULL;
        }
    }  
    
    
// ---------------------------------------------------------
// CDatagramTestAppView::HandleResourceChange()
// Called by framework when layout is changed.
// ---------------------------------------------------------
//
void CDatagramTestAppView::HandleResourceChange(TInt aType)
    {
    CCoeControl::HandleResourceChange(aType);

    // ADDED FOR SCALABLE UI SUPPORT
    // *****************************
    if ( aType==KEikDynamicLayoutVariantSwitch )
        {
        TRect rect;
        AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
        SetRect(rect);
        }
    
    // Redraw the editor window
    iEdwin->DrawNow();
    }
    
    
// -----------------------------------------------------------------------------
// CDatagramTestAppView::AddMessageL
// Add message to editor window in the container - at beginning
// -----------------------------------------------------------------------------
//
void CDatagramTestAppView::AddMessageL( const TDesC& aMsg ) const
    {
    
    CPlainText* text = iEdwin->Text();
    text->InsertL( text->DocumentLength(), aMsg );
    text->InsertL( text->DocumentLength(), CEditableText::ELineBreak );
    
    iEdwin->HandleTextChangedL();
    iEdwin->SetSelectionL( text->DocumentLength(), text->DocumentLength() );
    iEdwin->SetFocus( ETrue );
    }    
      
// End of File

⌨️ 快捷键说明

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