📄 richtexttestcontainer.cpp
字号:
/*
========================================================================
Name : RichtextTestContainer.cpp
Author :
Copyright : Your copyright notice
Description :
========================================================================
*/
// [[[ begin generated region: do not modify [Generated System Includes]
#include <barsread.h>
#include <stringloader.h>
#include <gdi.h>
#include <eikgted.h>
#include <eikenv.h>
#include <eiklabel.h>
#include <aknviewappui.h>
#include <eikappui.h>
#include <txtfrmat.h>
#include <eikrted.h>
#include <txtrich.h>
#include <gulcolor.h>
#include <RichtextTest.rsg>
// ]]] end generated region [Generated System Includes]
// [[[ begin generated region: do not modify [Generated User Includes]
#include "RichtextTestContainer.h"
#include "RichtextTestContainerView.h"
#include "RichtextTest.hrh"
#include "RichtextTestContainer.hrh"
// ]]] end generated region [Generated User Includes]
// [[[ begin generated region: do not modify [Generated Constants]
// ]]] end generated region [Generated Constants]
/**
* First phase of Symbian two-phase construction. Should not
* contain any code that could leave.
*/
CRichtextTestContainer::CRichtextTestContainer()
{
// [[[ begin generated region: do not modify [Generated Contents]
iRichText1 = NULL;
iLabel1 = NULL;
// ]]] end generated region [Generated Contents]
}
/**
* Destroy child controls.
*/
CRichtextTestContainer::~CRichtextTestContainer()
{
// [[[ begin generated region: do not modify [Generated Contents]
delete iRichText1;
iRichText1 = NULL;
delete iLabel1;
iLabel1 = NULL;
// ]]] end generated region [Generated Contents]
}
/**
* Construct the control (first phase).
* Creates an instance and initializes it.
* Instance is not left on cleanup stack.
* @param aRect bounding rectangle
* @param aParent owning parent, or NULL
* @param aCommandObserver command observer
* @return initialized instance of CRichtextTestContainer
*/
CRichtextTestContainer* CRichtextTestContainer::NewL(
const TRect& aRect,
const CCoeControl* aParent,
MEikCommandObserver* aCommandObserver )
{
CRichtextTestContainer* self = CRichtextTestContainer::NewLC(
aRect,
aParent,
aCommandObserver );
CleanupStack::Pop( self );
return self;
}
/**
* Construct the control (first phase).
* Creates an instance and initializes it.
* Instance is left on cleanup stack.
* @param aRect The rectangle for this window
* @param aParent owning parent, or NULL
* @param aCommandObserver command observer
* @return new instance of CRichtextTestContainer
*/
CRichtextTestContainer* CRichtextTestContainer::NewLC(
const TRect& aRect,
const CCoeControl* aParent,
MEikCommandObserver* aCommandObserver )
{
CRichtextTestContainer* self = new ( ELeave ) CRichtextTestContainer();
CleanupStack::PushL( self );
self->ConstructL( aRect, aParent, aCommandObserver );
return self;
}
/**
* Construct the control (second phase).
* Creates a window to contain the controls and activates it.
* @param aRect bounding rectangle
* @param aCommandObserver command observer
* @param aParent owning parent, or NULL
*/
void CRichtextTestContainer::ConstructL(
const TRect& aRect,
const CCoeControl* aParent,
MEikCommandObserver* aCommandObserver )
{
if ( aParent == NULL )
{
CreateWindowL();
}
else
{
SetContainerWindowL( *aParent );
}
iFocusControl = NULL;
iCommandObserver = aCommandObserver;
InitializeControlsL();
SetRect( aRect );
ActivateL();
// [[[ begin generated region: do not modify [Post-ActivateL initializations]
SetRichText1FormattingL();
// ]]] end generated region [Post-ActivateL initializations]
}
/**
* Return the number of controls in the container (override)
* @return count
*/
TInt CRichtextTestContainer::CountComponentControls() const
{
return ( int ) ELastControl;
}
/**
* Get the control with the given index (override)
* @param aIndex Control index [0...n) (limited by #CountComponentControls)
* @return Pointer to control
*/
CCoeControl* CRichtextTestContainer::ComponentControl( TInt aIndex ) const
{
// [[[ begin generated region: do not modify [Generated Contents]
switch ( aIndex )
{
case ERichText1:
return iRichText1;
case ELabel1:
return iLabel1;
}
// ]]] end generated region [Generated Contents]
// handle any user controls here...
return NULL;
}
/**
* Handle resizing of the container. This implementation will lay out
* full-sized controls like list boxes for any screen size, and will layout
* labels, editors, etc. to the size they were given in the UI designer.
* This code will need to be modified to adjust arbitrary controls to
* any screen size.
*/
void CRichtextTestContainer::SizeChanged()
{
CCoeControl::SizeChanged();
LayoutControls();
// [[[ begin generated region: do not modify [Generated Contents]
// ]]] end generated region [Generated Contents]
}
// [[[ begin generated function: do not modify
/**
* Layout components as specified in the UI Designer
*/
void CRichtextTestContainer::LayoutControls()
{
iRichText1->SetExtent( TPoint( 0, -2 ), TSize( 237, 221 ) );
iLabel1->SetExtent( TPoint( 81, 89 ), TSize( 83, 27 ) );
}
// ]]] end generated function
/**
* Handle key events.
*/
TKeyResponse CRichtextTestContainer::OfferKeyEventL(
const TKeyEvent& aKeyEvent,
TEventCode aType )
{
// [[[ begin generated region: do not modify [Generated Contents]
// ]]] end generated region [Generated Contents]
if ( iFocusControl != NULL
&& iFocusControl->OfferKeyEventL( aKeyEvent, aType ) == EKeyWasConsumed )
{
return EKeyWasConsumed;
}
return CCoeControl::OfferKeyEventL( aKeyEvent, aType );
}
// [[[ begin generated function: do not modify
/**
* Initialize each control upon creation.
*/
void CRichtextTestContainer::InitializeControlsL()
{
iRichText1 = new ( ELeave ) CEikRichTextEditor;
iRichText1->SetContainerWindowL( *this );
{
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC( reader, R_RICHTEXT_TEST_CONTAINER_RICH_TEXT1 );
iRichText1->ConstructFromResourceL( reader );
CleanupStack::PopAndDestroy(); // reader internal state
}
{
HBufC* text = StringLoader::LoadLC( R_RICHTEXT_TEST_CONTAINER_RICH_TEXT1_2 );
iRichText1->SetTextL( text );
CleanupStack::PopAndDestroy( text );
}
iLabel1 = new ( ELeave ) CEikLabel;
iLabel1->SetContainerWindowL( *this );
{
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC( reader, R_RICHTEXT_TEST_CONTAINER_LABEL1 );
iLabel1->ConstructFromResourceL( reader );
CleanupStack::PopAndDestroy(); // reader internal state
}
iRichText1->SetFocus( ETrue );
iFocusControl = iRichText1;
}
// ]]] end generated function
/**
* Handle global resource changes, such as scalable UI or skin events (override)
*/
void CRichtextTestContainer::HandleResourceChange( TInt aType )
{
CCoeControl::HandleResourceChange( aType );
SetRect( iAvkonViewAppUi->View( TUid::Uid( ERichtextTestContainerViewId ) )->ClientRect() );
// [[[ begin generated region: do not modify [Generated Contents]
// ]]] end generated region [Generated Contents]
}
/**
* Draw container contents.
*/
void CRichtextTestContainer::Draw( const TRect& aRect ) const
{
// [[[ begin generated region: do not modify [Generated Contents]
CWindowGc& gc = SystemGc();
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbWhite);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
// ]]] end generated region [Generated Contents]
}
void CRichtextTestContainer::SetRichText1FormattingL()
{
// [[[ begin generated region: do not modify [Generated GlobalText formatting]
// ]]] end generated region [Generated GlobalText formatting]
}
void CRichtextTestContainer::SetFont(const CFont* cfont)
{
/*
TCursorSelection cs = iRichText1->Selection();
SetSelectionL(cs.iCursorPos, cs.iAnchorPos-1);
*/
TFontSpec fontspec = cfont->FontSpecInTwips();
TCharFormat charFormat( fontspec.iTypeface.iName, fontspec.iHeight );
TCharFormatMask charFormatMask;
charFormatMask.SetAttrib(EAttFontTypeface);
charFormatMask.SetAttrib(EAttFontHeight);
iRichText1->ApplyCharFormatL(charFormat, charFormatMask);
Echo(R_TYPE_DIALOG_TBUF_INDICATOR_FONT);
}
void CRichtextTestContainer::SetColor(TRgb aColor)
{
TCharFormat charFormat;
TCharFormatMask charFormatMask;
charFormat.iFontPresentation.iTextColor = aColor;
charFormatMask.SetAttrib(EAttColor);
iRichText1->ApplyCharFormatL(charFormat, charFormatMask);
// iRtEd->SetBackgroundColorL(aColor);
// It is possible to change the background color - if foreground and background
// color is same, the text became invisible.
}
void CRichtextTestContainer::Echo(TInt aMessage)
{
TBuf<32> buf;
CEikonEnv::Static()->ReadResource(buf, aMessage);
iLabel1->SetTextL(buf);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -