📄 clocationexamplecontainer.cpp
字号:
// @param aMessage The event in string format
// ---------------------------------------------------------
//
void CLocationExampleContainer::MessageL(const TDesC& aMessage)
{
CAknInformationNote* note = new (ELeave) CAknInformationNote();
note->SetTextL(aMessage);
note->ExecuteLD();
}
// ---------------------------------------------------------
// CLocationExampleContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CLocationExampleContainer::SizeChanged()
{
// Make control use the whole client area
iListBox->SetRect(Rect());
if(iBgContext)
{
iBgContext->SetRect(Rect());
if ( &Window() )
{
iBgContext->SetParentPos( PositionRelativeToScreen() );
}
}
}
// ---------------------------------------------------------
// CLocationExampleContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CLocationExampleContainer::CountComponentControls() const
{
return 1; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CLocationExampleContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CLocationExampleContainer::ComponentControl(TInt aIndex) const
{
CCoeControl* control = NULL;
switch ( aIndex )
{
case 0:
control = iListBox;
break;
default:
control = NULL;
}
return control;
}
// ---------------------------------------------------------
// CLocationExampleContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CLocationExampleContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
// Skins http://newlc.com/Enable-Skin-support-in-your.html
MAknsSkinInstance* skin = AknsUtils::SkinInstance();
AknsDrawUtils::Background( skin, iBgContext, this, gc, aRect );
}
// -----------------------------------------------------------------------------
// CLocationExampleContainer::OfferKeyEventL
// Handles key events. Basically it just forwards them to listbox component.
// -----------------------------------------------------------------------------
//
TKeyResponse CLocationExampleContainer::OfferKeyEventL(const TKeyEvent &aKeyEvent, TEventCode aType)
{
// Center button
if (aKeyEvent.iCode == EKeyOK && aType == EEventKey)
{
ShowContextSensiveMenuL();
return EKeyWasConsumed;
}
return iListBox->OfferKeyEventL(aKeyEvent, aType);
}
// ---------------------------------------------------------
// CLocationExampleContainer::ShowContextSensiveMenuL
//
// ---------------------------------------------------------
//
void CLocationExampleContainer::ShowContextSensiveMenuL()
{
if (!iParent->MenuBar())
{
User::Leave(KErrNotFound);
}
// New menu
iParent->MenuBar()->SetMenuTitleResourceId(R_LOCATIONEXAMPLE_SPECIAL_MENUBAR);
if (iParent->MenuBar())
{
iParent->MenuBar()->StopDisplayingMenuBar();
}
if (iParent->MenuBar())
{
iParent->MenuBar()->TryDisplayMenuBarL();
}
// Back to original
iParent->MenuBar()->SetMenuTitleResourceId(R_LOCATIONEXAMPLE_MENUBAR1);
}
// -----------------------------------------------------------------------------
// CLocationExampleContainer::MopSupplyObject
// -----------------------------------------------------------------------------
//
TTypeUid::Ptr CLocationExampleContainer::MopSupplyObject(TTypeUid aId)
{
if (iBgContext )
{
return MAknsControlContext::SupplyMopObject( aId, iBgContext );
}
return CCoeControl::MopSupplyObject(aId);
}
// -----------------------------------------------------------------------------
// CLocationExampleContainer::ProcessPositionInfo
// Processes position info in to a string representation.
// -----------------------------------------------------------------------------
//
void CLocationExampleContainer::ProcessPositionInfoL(
const TPositionInfo& aPositionInfo )
{
// Get basic position data
TPosition position;
aPositionInfo.GetPosition(position);
TBuf<KDegreeLength> latitudeDegr;
GetDegreesString(position.Latitude(), latitudeDegr);
TBuf<KDegreeLength> longitudeDegr;
GetDegreesString(position.Longitude(), longitudeDegr);
AddItemInListL(*iTextLat, latitudeDegr);
AddItemInListL(*iTextLong, longitudeDegr);
}
// -----------------------------------------------------------------------------
// CLocationExampleContainer::GetDegreesString
// Changes latitude or longitude represented as degrees to a string of
// a form +DDD'MM''SS.SSSS
// -----------------------------------------------------------------------------
//
void CLocationExampleContainer::GetDegreesString(
const TReal64& aDegrees,TBuf<KDegreeLength>& aDegreesString) const
{
const TReal KSecondsInMinute = 60.0;
const TInt KNumWidth = 3;
// If the aDegree is a proper number
if ( !Math::IsNaN(aDegrees) )
{
// Integer part of the degrees
TInt intDegrees = static_cast<TInt>(aDegrees);
// Positive float of the degrees
TReal64 realDegrees = aDegrees;
// Convert to positive values
if ( intDegrees < 0 )
{
intDegrees = -intDegrees;
realDegrees = -realDegrees;
}
// Minutes
TReal64 realMinutes = (realDegrees - intDegrees) * KSecondsInMinute;
// Integer part of the minutes
TInt intMinutes = static_cast<TInt>(realMinutes);
// Seconds
TReal64 realSeconds = (realMinutes - intMinutes) * KSecondsInMinute;
TInt intSeconds = static_cast<TInt>((realMinutes - intMinutes) * KSecondsInMinute);
// Check the sign of the result
if ( aDegrees >= 0 )
{
aDegreesString.Append(KDelimPlus);
}
else
{
aDegreesString.Append(KDelimMinus);
}
// Add the degrees
TInt64 value = intDegrees;
aDegreesString.AppendNum(value);
// Add the separator
aDegreesString.Append(KDelimDegree);
// Add the minutes
value = intMinutes;
aDegreesString.AppendNum(value);
// Add the separator
aDegreesString.Append(KApostrophe);
// Add the seconds
value = intSeconds;
aDegreesString.AppendNum(value);
// Add the separator
aDegreesString.Append(KDelimQuot);
// Add the separator
aDegreesString.Append(KDelimDot);
// Get six last digits
realSeconds -= intSeconds;
realSeconds *= 1000;
// Add the seconds
aDegreesString.AppendNumFixedWidth(static_cast<TInt>(realSeconds), EDecimal, KNumWidth);
}
else
{
// The conversion can not be done, return NaN
aDegreesString = KNan;
}
}
// -----------------------------------------------------------------------------
// CLocationExampleContainer::HandleResourceChange
// Handle Dynamic Screen Size change and Skin Change events and update
// controls accordingly.
// -----------------------------------------------------------------------------
//
void CLocationExampleContainer::HandleResourceChange(TInt aType)
{
CCoeControl::HandleResourceChange(aType);
switch( aType )
{
case KAknsMessageSkinChange:
{
iListBox->DrawNow();
break;
}
case KEikDynamicLayoutVariantSwitch:
{
SetRect(iEikonEnv->EikAppUi()->ClientRect());
DrawNow();
break;
}
default:
{
break;
}
}
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -