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

📄 msgobservercontainer.cpp

📁 消息监视程序
💻 CPP
字号:
/**
*
* @brief Definition of CMsgObserverContainer
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDE FILES
#include "MsgObserverContainer.h"

#include <aknutils.h>  // AknTextUtils
#include <eiklabel.h>  // for example label control


const TInt KBorderWidth = 10;
const TInt KMaxLines = 12;

_LIT(KDefaultText, "(The message body will appear here)");


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

// ---------------------------------------------------------
// CMsgObserverContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CMsgObserverContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();

    iLabel = new (ELeave) CEikLabel;
    iLabel->SetContainerWindowL(*this);

    SetRect(aRect);
    ActivateL();

    const TInt lineWidth = iLabel->Rect().Width() - KBorderWidth;
    iLineWidthArray = new CArrayFixFlat<TInt>(KMaxLines);
    for (TInt i = 0; i < KMaxLines; i++)
        iLineWidthArray->AppendL(lineWidth);

    SetTextL(KDefaultText);
    }

// Destructor
CMsgObserverContainer::~CMsgObserverContainer()
    {
    delete iLabel;
    delete iLineWidthArray;
    }

// ---------------------------------------------------------
// CMsgObserverContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CMsgObserverContainer::SizeChanged()
    {
    TRect rect = Rect();
    rect.Shrink(KBorderWidth, KBorderWidth);
    iLabel->SetRect(rect);
    }

// ---------------------------------------------------------
// CMsgObserverContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CMsgObserverContainer::CountComponentControls() const
    {
    return ENumberOfControls;
    }

// ---------------------------------------------------------
// CMsgObserverContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CMsgObserverContainer::ComponentControl(TInt aIndex) const
    {
    switch (aIndex)
        {
        case EControlLabel:
            return iLabel;
        default:
            return NULL;
        }
    }

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

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


void CMsgObserverContainer::SetTextL(const TDesC& aText)
    {
    __ASSERT_DEBUG(iLineWidthArray, User::Invariant());
    __ASSERT_DEBUG(iLabel, User::Invariant());

    HBufC* buffer = HBufC::NewMaxLC(aText.Length() + KMaxLines); // To allow a \n at the end of each line
    TPtr bufferPtr = buffer->Des();
    AknTextUtils::WrapToStringL(aText, *iLineWidthArray, *(iLabel->Font()), bufferPtr);
    iLabel->SetTextL(*buffer);
    CleanupStack::PopAndDestroy(buffer);
    DrawDeferred();
    }


// End of File

⌨️ 快捷键说明

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