📄 btcon_appview.cpp
字号:
/*****************************************************************************
COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2005.
The software is the copyrighted work of Sony Ericsson Mobile Communications AB.
The use of the software is subject to the terms of the end-user license
agreement which accompanies or is included with the software. The software is
provided "as is" and Sony Ericsson specifically disclaim any warranty or
condition whatsoever regarding merchantability or fitness for a specific
purpose, title or non-infringement. No warranty of any kind is made in
relation to the condition, suitability, availability, accuracy, reliability,
merchantability and/or non-infringement of the software provided herein.
*****************************************************************************/
// BTCon_AppView.cpp
//
//
#include <e32math.h> // Math
#include <e32std.h> // Time
#include <eikcmbut.h> // CEikTextButton
#include <eiklabel.h> // CEikLabel
#include <eiktxlbx.h> // CEikTextListBox
#include <eiktxlbm.h> // CTextListBoxModel
#include <apgcli.h> // RApaLsSession
#include <apacmdln.h> // CApaCommandLine
#include <instapp.h> // KUninstallCommandLineTail
#include <apmstd.h> // TDataType
#include "BTCon.h"
#include "BTCon_AppView.h"
#include "BTCon_AppUi.h"
const TInt KTotalEditorControls(4);
_LIT(KHelloText, "Hello in Bluetooth example");
_LIT(KTextEditInfo, "Received:");
_LIT(KButtonCmdInfo, "Send message:");
_LIT(KTextHej, "Hej");
_LIT(KTextAloha, "Aloha");
_LIT(KTextBrum, "Brum");
_LIT(KReceived, "received: ");
CBTConAppView* CBTConAppView::NewL(const TRect& aRect)
{
CBTConAppView * self = new(ELeave) CBTConAppView;
CleanupStack::PushL(self);
self->ConstructL(aRect);
CleanupStack::Pop();
return self;
}
CBTConAppView::~CBTConAppView()
{
if(iListBox)
delete iListBox;
if(iButtonHej)
delete iButtonHej;
if(iButtonAloha)
delete iButtonAloha;
if(iButtonBrum)
delete iButtonBrum;
}
void CBTConAppView::UpdateEditText(const TDesC& aText)
{
CDesCArray* array = ((CDesCArray *)iListBox->Model()->ItemTextArray());
array->AppendL(aText);
iListBox->SetCurrentItemIndex(array->Count()-1);
// Handle the addition of items to the list box model.
iListBox->HandleItemAdditionL(); // This also redraws the list box.
iListBox->UpdateScrollBarsL();
}
void CBTConAppView::SetMyName(const TDesC& aText)
{
iMyName.Delete(0,iMyName.Length());
iMyName.Append(aText);
DrawNow();
}
void CBTConAppView::ClearList()
{
((CDesCArray *)iListBox->Model()->ItemTextArray())->Reset();
iListBox->SetCurrentItemIndex(0);
iListBox->HandleItemAdditionL();
iListBox->UpdateScrollBarsL();
}
void CBTConAppView::HandleControlEventL(CCoeControl* aControl,
TCoeEvent aEventType)
{
if( aEventType == EEventStateChanged )
{
if(aControl == iButtonHej )
iAppUi->SendMsgL(KTextHej);
else if(aControl == iButtonAloha )
iAppUi->SendMsgL(KTextAloha);
else if(aControl == iButtonBrum )
iAppUi->SendMsgL(KTextBrum);
}
}
void CBTConAppView::ConstructL(const TRect& aRect)
{
CreateWindowL();
SetRect(aRect);
iAppUi = static_cast<CBTConAppUi*>(iEikonEnv->EikAppUi());
BuildObjects();
ActivateL();
}
void CBTConAppView::Draw(const TRect& /*aRect*/) const
{
// Window graphics context
CWindowGc& gc = SystemGc();
// Start with a clear screen
gc.Clear();
TRect rect = Rect();
const CFont* font = iEikonEnv->LegendFont();
TInt fontHeight = font->HeightInPixels();
gc.UseFont(font);
gc.DrawText(iMyName,
rect,
fontHeight,
CGraphicsContext::ECenter);
rect.Move(2,0);
gc.DrawText(KTextEditInfo,
rect,
2*fontHeight,
CGraphicsContext::ELeft);
gc.DrawText(KButtonCmdInfo,
rect,
8*fontHeight + Size().iHeight/2,
CGraphicsContext::ELeft);
gc.DiscardFont();
}
void CBTConAppView::BuildObjects()
{
TTime time;
time.UniversalTime();
TInt64 randSeed(time.Int64());
// let it generate first few numbers, just to init
for( TInt i(0); i<20; ++i )
Math::Rand( randSeed );
TInt result = Math::Rand( randSeed );
iMyName.Num(result);
iMyName.Delete(5, iMyName.Length()-5);
iMyName.Insert(0,_L("My Name: "));
TInt fontHeight = iEikonEnv->LegendFont()->HeightInPixels();
iListBox = new (ELeave) CEikTextListBox;
iListBox->ConstructL(this, 0);
iListBox->SetContainerWindowL( *this );
// set look and behaviour:
// - set scrolling capabilities
iListBox->CreateScrollBarFrameL();
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto,
CEikScrollBarFrame::EAuto);
// - set listbox bordes
iListBox->SetBorder(TGulBorder::EDeepRaisedWithOutline);
// - set position
iListBox->SetExtent(TPoint(2, 2*fontHeight),
TSize(Size().iWidth-4, Size().iHeight - 7*fontHeight));
CDesCArray* array = ((CDesCArray *)iListBox->Model()->ItemTextArray());
// Set the item at index 0
iListBox->SetCurrentItemIndex(0);
// Set the list box control with a focus
iListBox->SetFocus(ETrue);
iListBox->ActivateL();
array->AppendL(KHelloText);
iButtonHej = new (ELeave) CEikTextButton;
iButtonHej->SetContainerWindowL(*this);
iButtonHej->SetTextL(_L("Hej"));
iButtonHej->SetExtent(TPoint(10, 8*fontHeight + 2 + Size().iHeight/2),
TSize(60,20));
iButtonHej->SetBehavior(EEikButtonReportsOnPointerDown);
iButtonHej->SetObserver(this);
iButtonAloha = new (ELeave) CEikTextButton;
iButtonAloha->SetContainerWindowL(*this);
iButtonAloha->SetTextL(_L("Aloha"));
iButtonAloha->SetExtent(TPoint(70, 8*fontHeight + 2 + Size().iHeight/2),
TSize(60,20));
iButtonAloha->SetBehavior(EEikButtonReportsOnPointerDown);
iButtonAloha->SetObserver(this);
iButtonBrum = new (ELeave) CEikTextButton;
iButtonBrum->SetContainerWindowL(*this);
iButtonBrum->SetTextL(_L("Brum"));
iButtonBrum->SetExtent(TPoint(130, 8*fontHeight + 2 + Size().iHeight/2),
TSize(60,20));
iButtonBrum->SetBehavior(EEikButtonReportsOnPointerDown);
iButtonBrum->SetObserver(this);
}
TInt CBTConAppView::CountComponentControls() const
{
return KTotalEditorControls;
}
CCoeControl* CBTConAppView::ComponentControl(TInt aIndex) const
{
switch (aIndex)
{
case 0 :
return iListBox;
case 1 :
return iButtonHej;
case 2 :
return iButtonAloha;
case 3 :
return iButtonBrum;
default:
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -