📄 bioexample.cpp
字号:
/*
BIOexample.CPP - source file for BIOexample application
C++ implementation
*/
// Include Files
#include <eiklabel.h> // for CEikLabel
#include <e32std.h> // for TPckgBuf
#include <smut.h> // for KUidMsgTypeSMS
#include <txtrich.h> // for CRichText
#include <eikenv.h> // for CEikonEnv
#include <editwatc.h> // for TEditorParameters
#include <txtfmlyr.h> // for CParaFormatLayer, CCharFormatLayer
#include <sendui.h> // for CSendAppUi
#include "BIOexample.h" // own header
#include "BIOexample.hrh" // own enumerations
// Constants
const TUid KUidBIOexampleApp = { 0x101F402A }; // BIOexample application UID
const TUid KUidExampleMessageType = { 0x1000ffff }; // example BIO message type UID
_LIT(KBIOExampleTag, "//BIOEX #"); // Our BIO message identifier tag + '#' (defined also in bioexamplebif.rss)
_LIT(KBIOExampleFrom, "From: ");
_LIT(KBIOExampleMessage, "Message: ");
const TInt KEditorTextLimit = 160;
//
// CBIOexampleContainer
//
CBIOexampleContainer::~CBIOexampleContainer()
{
delete iComponentControl;
delete iSender;
}
void CBIOexampleContainer::ConstructL(TDes& aText, TDes& aSender)
{
ConstructContainerControlL(); // Construct self
ConstructComponentControlL(aText, aSender); // Construct component control(s)
}
TInt CBIOexampleContainer::CountComponentControls() const
{
return 2; // iComponentControl is always there
}
CCoeControl* CBIOexampleContainer::ComponentControl(TInt aIndex) const
{
if(aIndex==0)
return iComponentControl;
if(aIndex==1)
return iSender;
return NULL;
}
void CBIOexampleContainer::ConstructContainerControlL()
{
CreateWindowL(); // Makes the control window owning
}
void CBIOexampleContainer::ConstructComponentControlL(TDes& aText, TDes& aSender)
{
iComponentControl=new(ELeave)CEikLabel; // Create a CEikLabel object
iComponentControl->SetTextL(aText); // Set label text
iSender = new(ELeave)CEikLabel;
iSender->SetTextL(aSender);
}
void CBIOexampleContainer::SizeChanged()
{
TSize controlSize=iComponentControl->MinimumSize(); // Ask iComponentControl's size
TSize containerSize=Rect().Size(); // containerSize is CBIOexampleContainer's own size and can be found in the size of its rectangle.
TPoint controlPosition((containerSize.iWidth-controlSize.iWidth)/2,
(containerSize.iHeight-controlSize.iHeight)/2); // Calculate a position for control that places it to the center of CBIOexampleContainer
TRect controlRect(controlPosition,controlSize);
iComponentControl->SetRect(controlRect); // Set iComponentControl a rect in which it is supposed to appear.
controlSize=iSender->MinimumSize();
controlPosition.SetXY((containerSize.iWidth-controlSize.iWidth)/2,
((containerSize.iHeight-controlSize.iHeight)/2) + controlSize.iHeight );
TRect senderRect(controlPosition,controlSize);
iSender->SetRect(senderRect);
}
void CBIOexampleContainer::Draw(const TRect& /*aRect*/) const
{
CGraphicsContext& gc=SystemGc(); // Get the graphics context in which to draw.
gc.SetBrushStyle(CGraphicsContext::ESolidBrush); // Set brush style to solid. Initial value in a graphics context is ENullBrush.
gc.DrawRect(Rect()); // Draw a rectangle.
}
TKeyResponse CBIOexampleContainer::OfferKeyEventL(const TKeyEvent& /*aKeyEvent*/, TEventCode /*aType*/)
{
TKeyResponse response=EKeyWasNotConsumed; // not consuming any keys
return response;
}
//
// CBIOexampleAppUi
//
/*
-------------------------------------------------------------------------------
~CBIOexampleAppUi
Description: Destructor
Return value: N/A
-------------------------------------------------------------------------------
*/
CBIOexampleAppUi::~CBIOexampleAppUi()
{
delete iContainerControl;
iId = NULL;
delete paraFormatLayer;
delete charFormatLayer;
delete messageBodyContent;
delete sendAppUi;
}
/*
-------------------------------------------------------------------------------
ProcessCommandParametersL();
Description: Processing the command line parameters (when message is opened
from the messaging application, TMsvId of the message is passed
in command line parameters)
Return value: TBool
-------------------------------------------------------------------------------
*/
TBool CBIOexampleAppUi::ProcessCommandParametersL(TApaCommand /*aCommand*/,TFileName& /*aDocumentName*/,const TDesC8& aTail)
{
// Only aTail parameter is of interest to us, it contains TEditorParameters object that contains
// the TMsvId as one attribute.
// Checking the length of comm line params
if (aTail.Length() > 0) // we have comm line params => program was started from Messaging application
{
iNormalStart = EFalse;
// --- reading command line parameters ---
// Get the parameters passed by the launching MTMUI
TPckgBuf<TEditorParameters> paramPack; // the params are read into a TPckgBuf template (see SDK documentation for more info)
paramPack.Copy(aTail);
TEditorParameters params(paramPack());
// saving the message id
iId = ¶ms.iId;
}
else
{
// no command line params => program started manually
iNormalStart = ETrue;
}
CompleteConstructL(); // complete construction with the command line parameters.
return EFalse;
}
/*
-------------------------------------------------------------------------------
ConstructL();
Description: 2nd phase Constructor. Setting up attributes, construction
continues in CompleteConstructL() below.
Return value: N/A
-------------------------------------------------------------------------------
*/
void CBIOexampleAppUi::ConstructL()
{
BaseConstructL();
iNormalStart = ETrue; // at this point we suppose that no comm line params have been given
iId = NULL; // set message id to NULL as default
// for message sending
paraFormatLayer=CParaFormatLayer::NewL();
charFormatLayer=CCharFormatLayer::NewL();
messageBodyContent=CRichText::NewL(paraFormatLayer, charFormatLayer);
// create sendAppUi
sendAppUi=CSendAppUi::NewL(EBIOexampleCmdSend); // New Send ui object (number 'EBIOexampleCmdSend' is tied
// to our menu item "Send message" in "Messaging"
}
/*
-------------------------------------------------------------------------------
CompleteContructL();
Description: Continuing construction... (after processing command line params)
Return value: N/A
-------------------------------------------------------------------------------
*/
void CBIOexampleAppUi::CompleteConstructL()
{
TBuf<KEditorTextLimit> text, sender; // for reading & presenting the message sender & body
sender.Append(KBIOExampleFrom); // insert field description ("From: ")
// First check if app has been started from the messaging app or "the normal way", manually...
if(iNormalStart == EFalse) // we have comm line params and will open up message with the given TMsvId
{
// read the message into descriptors
ReadMessageL(text, sender);
// read message text and locate "//BIOEX #" header part
TInt pos;
User::LeaveIfError(pos = text.Locate('#')); // # is in the message only to test string handling here (it could be omitted)
pos++;
text.Delete(0, pos); // delete message header tag
// insert field description in front
text.Insert(0, KBIOExampleMessage); // "Message: "
// Delete message from messaging server
DeleteMessageL(*iId);
iId = NULL;
}
else // no comm line params, opening "empty" application
{
text.Append(KBIOExampleMessage); // "Message: "
text.Append(_L("No message loaded")); // "Message: No message loaded"
sender.Append(_L("N/A")); // "From: N/A"
}
// Then construct the UI components
iContainerControl = new(ELeave) CBIOexampleContainer;
iContainerControl->ConstructL(text, sender); // Construct a view control with message text and sender number (in normal start these are empty)
iContainerControl->SetRect(ClientRect()); // Sets view control's extent to the space available
iContainerControl->ActivateL(); // Activate the view control
CCoeAppUi::AddToStackL(iContainerControl); // Add container to Control Stack to make it automatically receive key events.
}
/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -