examples/sfexamples/findme/src/FindMeAppView.cpp

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:  Application view implementation
00015 // 
00016 // 
00017 
00018 
00019 // INCLUDE FILES
00020 #include <coemain.h>
00021 #include "FindMeAppView.h"
00022 
00023 #include <aknnotewrappers.h>
00024 
00025 
00026 // Degrees sign delimeter used in formatting methods
00027 _LIT(KDelimDegree,"\xb0"); // "°" symbol
00028 
00029 // Dot delimeter used in formatting methods
00030 _LIT(KDelimDot,"\x2e"); // "." symbol
00031 
00032 // Plus sign delimeter used in formatting methods
00033 _LIT(KDelimPlus,"\x2b"); // "+" symbol
00034 
00035 // Minus sign delimeter used in formatting methods
00036 _LIT(KDelimMinus,"\x2d"); // "-" symbol
00037 
00038 // Quotation sign delimeter used in formatting methods
00039 _LIT(KDelimQuot,"\x22"); // "\"" symbol
00040 
00041 // Apostrophe sign delimeter used in formatting methods
00042 _LIT(KApostrophe,"\x27"); // "'" symbol
00043 
00044 // Not-a-number string
00045 _LIT(KNan,"NaN");
00046 
00047 
00048 // ============================ MEMBER FUNCTIONS ===============================
00049 
00050 // -----------------------------------------------------------------------------
00051 // CFindMeAppView::NewL()
00052 // Two-phased constructor.
00053 // -----------------------------------------------------------------------------
00054 //
00055 CFindMeAppView* CFindMeAppView::NewL( const TRect& aRect )
00056         {
00057         CFindMeAppView* self = CFindMeAppView::NewLC( aRect );
00058         CleanupStack::Pop( self );
00059         return self;
00060         }
00061 
00062 // -----------------------------------------------------------------------------
00063 // CFindMeAppView::NewLC()
00064 // Two-phased constructor.
00065 // -----------------------------------------------------------------------------
00066 //
00067 CFindMeAppView* CFindMeAppView::NewLC( const TRect& aRect )
00068         {
00069         CFindMeAppView* self = new ( ELeave ) CFindMeAppView;
00070         CleanupStack::PushL( self );
00071         self->ConstructL( aRect );
00072         return self;
00073         }
00074 
00075 // -----------------------------------------------------------------------------
00076 // CFindMeAppView::ConstructL()
00077 // Symbian 2nd phase constructor can leave.
00078 // -----------------------------------------------------------------------------
00079 //
00080 void CFindMeAppView::ConstructL( const TRect& aRect )
00081         {
00082         // Create a window for this application view
00083         CreateWindowL();
00084 
00085         // Set the windows size
00086         SetRect( aRect );
00087 
00088         // Activate the window, which makes it ready to be drawn
00089         ActivateL();
00090         
00091         iMyPos = CFindMeActive::NewL(this);
00092         }
00093 
00094 // -----------------------------------------------------------------------------
00095 // CFindMeAppView::CFindMeAppView()
00096 // C++ default constructor can NOT contain any code, that might leave.
00097 // -----------------------------------------------------------------------------
00098 //
00099 CFindMeAppView::CFindMeAppView() : iPosDataFound(EFalse)
00100         {
00101         // No implementation required
00102         }
00103 
00104 
00105 // -----------------------------------------------------------------------------
00106 // CFindMeAppView::~CFindMeAppView()
00107 // Destructor.
00108 // -----------------------------------------------------------------------------
00109 //
00110 CFindMeAppView::~CFindMeAppView()
00111         {
00112         delete iMyPos;
00113         }
00114 
00115 
00116 // -----------------------------------------------------------------------------
00117 // CFindMeAppView::Draw()
00118 // Draws the display.
00119 // -----------------------------------------------------------------------------
00120 //
00121 void CFindMeAppView::Draw( const TRect& /*aRect*/ ) const
00122         {
00123         // Get the standard graphics context
00124         CWindowGc& gc = SystemGc();
00125 
00126         // Gets the control's extent
00127         TRect drawRect( Rect());
00128 
00129         // Clears the screen
00130         gc.Clear( drawRect );
00131         
00132         // If there is new location information found.
00133         if( iPosDataFound )
00134                 {
00135                 // Get the position information and store it in a TPosition object. 
00136                 TPosition pos;
00137                 iMyPos->iPositionInfo.GetPosition(pos);
00138                 
00139                 TBuf<20> lat;
00140                 GetDegreesString(pos.Latitude(),lat);
00141                 TBuf<20> lon;
00142                 GetDegreesString(pos.Longitude(),lon);
00143                 
00144                 // Prepare for writing the lat and long to the screen.
00145             // In this example, we use one of the standard font styles
00146                 const CFont* fontUsed = CEikonEnv::Static()->LegendFont();
00147                 gc.UseFont(fontUsed);
00148                 gc.SetPenColor(KRgbBlack);
00149                 gc.DrawText(lat, TPoint(25, 25));
00150                 gc.DrawText(lon, TPoint(25, 50));
00151                 gc.DiscardFont();
00152         }
00153         }
00154 
00155 // -----------------------------------------------------------------------------
00156 // CFindMeAppView::SizeChanged()
00157 // Called by framework when the view size is changed.
00158 // -----------------------------------------------------------------------------
00159 //
00160 void CFindMeAppView::SizeChanged()
00161         {  
00162         DrawNow();
00163         }
00164 
00165 
00166 // -----------------------------------------------------------------------------
00167 // CFindMeAppView::PrintPos()
00168 // Prints the position of the device in screen
00169 // -----------------------------------------------------------------------------
00170 //
00171 void CFindMeAppView::PrintPos()
00172         {
00173         iPosDataFound = ETrue;
00174         DrawNow();
00175         iPosDataFound = EFalse;
00176         }
00177 
00178 // -----------------------------------------------------------------------------
00179 // CFindMeAppView::GetDegreesString
00180 //
00181 //  Taken from Nokia LocationRefAppForS60 example
00182 //
00183 // Changes latitude or longitude represented as degrees to a string of 
00184 // a form +DDD'MM''SS.SSSS
00185 // -----------------------------------------------------------------------------
00186 //
00187 void CFindMeAppView::GetDegreesString( const TReal64& aDegrees,
00188                                                                            TBuf<20>& aDegreesString) const
00189     {
00190     const TReal KSecondsInMinute = 60.0;
00191     const TInt KNumWidth = 3;
00192     
00193     // If the aDegree is a proper number
00194     if ( !Math::IsNaN(aDegrees) )
00195         {
00196         // Integer part of the degrees
00197         TInt intDegrees = static_cast<TInt>(aDegrees);
00198 
00199         // Positive float of the degrees
00200         TReal64 realDegrees = aDegrees;
00201         
00202         // Convert to positive values
00203         if ( intDegrees < 0 )
00204             {
00205             intDegrees = -intDegrees;
00206             realDegrees = -realDegrees;
00207             }
00208 
00209         // Minutes
00210         TReal64 realMinutes = (realDegrees - intDegrees) * KSecondsInMinute;
00211           
00212         // Integer part of the minutes
00213         TInt intMinutes = static_cast<TInt>(realMinutes);
00214 
00215         // Seconds
00216         TReal64 realSeconds = (realMinutes - intMinutes) * KSecondsInMinute;
00217         TInt intSeconds = static_cast<TInt>((realMinutes - intMinutes) * KSecondsInMinute);
00218 
00219         // Check the sign of the result
00220         if ( aDegrees >= 0 )
00221             {
00222             aDegreesString.Append(KDelimPlus); 
00223             }
00224         else
00225             {
00226             aDegreesString.Append(KDelimMinus);
00227             }
00228 
00229         // Add the degrees
00230         TInt64 value = intDegrees;
00231         aDegreesString.AppendNum(value);
00232 
00233         // Add the separator
00234         aDegreesString.Append(KDelimDegree);
00235     
00236         // Add the minutes
00237         value = intMinutes;
00238         aDegreesString.AppendNum(value);
00239 
00240         // Add the separator
00241         aDegreesString.Append(KApostrophe);
00242         
00243         // Add the seconds
00244         value = intSeconds;
00245         aDegreesString.AppendNum(value);
00246 
00247         // Add the separator
00248         aDegreesString.Append(KDelimQuot);
00249 
00250         // Add the separator
00251         aDegreesString.Append(KDelimDot);
00252         
00253         // Get six last digits
00254         realSeconds -= intSeconds;
00255         realSeconds *= 1000;
00256         
00257         // Add the seconds
00258         aDegreesString.AppendNumFixedWidth(static_cast<TInt>(realSeconds), EDecimal, KNumWidth);
00259         }
00260     else
00261         {
00262         // The conversion can not be done, return NaN
00263         aDegreesString = KNan;
00264         }
00265     }
00266 
00267 // End of File

Generated by  doxygen 1.6.2