00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 #include <coemain.h>
00021 #include "FindMeAppView.h"
00022 
00023 #include <aknnotewrappers.h>
00024 
00025 
00026 
00027 _LIT(KDelimDegree,"\xb0"); 
00028 
00029 
00030 _LIT(KDelimDot,"\x2e"); 
00031 
00032 
00033 _LIT(KDelimPlus,"\x2b"); 
00034 
00035 
00036 _LIT(KDelimMinus,"\x2d"); 
00037 
00038 
00039 _LIT(KDelimQuot,"\x22"); 
00040 
00041 
00042 _LIT(KApostrophe,"\x27"); 
00043 
00044 
00045 _LIT(KNan,"NaN");
00046 
00047 
00048 
00049 
00050 
00051 
00052 
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 
00064 
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 
00077 
00078 
00079 
00080 void CFindMeAppView::ConstructL( const TRect& aRect )
00081         {
00082         
00083         CreateWindowL();
00084 
00085         
00086         SetRect( aRect );
00087 
00088         
00089         ActivateL();
00090         
00091         iMyPos = CFindMeActive::NewL(this);
00092         }
00093 
00094 
00095 
00096 
00097 
00098 
00099 CFindMeAppView::CFindMeAppView() : iPosDataFound(EFalse)
00100         {
00101         
00102         }
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 CFindMeAppView::~CFindMeAppView()
00111         {
00112         delete iMyPos;
00113         }
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 void CFindMeAppView::Draw( const TRect&  ) const
00122         {
00123         
00124         CWindowGc& gc = SystemGc();
00125 
00126         
00127         TRect drawRect( Rect());
00128 
00129         
00130         gc.Clear( drawRect );
00131         
00132         
00133         if( iPosDataFound )
00134                 {
00135                 
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                 
00145             
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 
00157 
00158 
00159 
00160 void CFindMeAppView::SizeChanged()
00161         {  
00162         DrawNow();
00163         }
00164 
00165 
00166 
00167 
00168 
00169 
00170 
00171 void CFindMeAppView::PrintPos()
00172         {
00173         iPosDataFound = ETrue;
00174         DrawNow();
00175         iPosDataFound = EFalse;
00176         }
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 
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     
00194     if ( !Math::IsNaN(aDegrees) )
00195         {
00196         
00197         TInt intDegrees = static_cast<TInt>(aDegrees);
00198 
00199         
00200         TReal64 realDegrees = aDegrees;
00201         
00202         
00203         if ( intDegrees < 0 )
00204             {
00205             intDegrees = -intDegrees;
00206             realDegrees = -realDegrees;
00207             }
00208 
00209         
00210         TReal64 realMinutes = (realDegrees - intDegrees) * KSecondsInMinute;
00211           
00212         
00213         TInt intMinutes = static_cast<TInt>(realMinutes);
00214 
00215         
00216         TReal64 realSeconds = (realMinutes - intMinutes) * KSecondsInMinute;
00217         TInt intSeconds = static_cast<TInt>((realMinutes - intMinutes) * KSecondsInMinute);
00218 
00219         
00220         if ( aDegrees >= 0 )
00221             {
00222             aDegreesString.Append(KDelimPlus); 
00223             }
00224         else
00225             {
00226             aDegreesString.Append(KDelimMinus);
00227             }
00228 
00229         
00230         TInt64 value = intDegrees;
00231         aDegreesString.AppendNum(value);
00232 
00233         
00234         aDegreesString.Append(KDelimDegree);
00235     
00236         
00237         value = intMinutes;
00238         aDegreesString.AppendNum(value);
00239 
00240         
00241         aDegreesString.Append(KApostrophe);
00242         
00243         
00244         value = intSeconds;
00245         aDegreesString.AppendNum(value);
00246 
00247         
00248         aDegreesString.Append(KDelimQuot);
00249 
00250         
00251         aDegreesString.Append(KDelimDot);
00252         
00253         
00254         realSeconds -= intSeconds;
00255         realSeconds *= 1000;
00256         
00257         
00258         aDegreesString.AppendNumFixedWidth(static_cast<TInt>(realSeconds), EDecimal, KNumWidth);
00259         }
00260     else
00261         {
00262         
00263         aDegreesString = KNan;
00264         }
00265     }
00266 
00267