Changeset 40
- Timestamp:
- Nov 14, 2011, 7:35:37 AM (11 years ago)
- Location:
- trunk/Utilities/GpsLocationConverter
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Utilities/GpsLocationConverter/GpsLocationConverter_i.c
r39 r40 7 7 8 8 /* File created by MIDL compiler version 7.00.0555 */ 9 /* at Thu Nov 10 00:28:03 20119 /* at Mon Nov 14 17:34:23 2011 10 10 */ 11 11 /* Compiler settings for GpsLocationConverter.idl: -
trunk/Utilities/GpsLocationConverter/GpsLocationConverter_i.h
r39 r40 5 5 6 6 /* File created by MIDL compiler version 7.00.0555 */ 7 /* at Thu Nov 10 00:28:03 20117 /* at Mon Nov 14 17:34:23 2011 8 8 */ 9 9 /* Compiler settings for GpsLocationConverter.idl: -
trunk/Utilities/GpsLocationConverter/MainDialog.h
r39 r40 31 31 END_MSG_MAP() 32 32 33 public: 34 35 //////////////////////////////////////////////////////// 36 // CLocation 37 38 class CLocation 39 { 40 public: 41 42 //////////////////////////////////////////////////// 43 // CStrings 44 45 class CStrings 46 { 47 public: 48 CString m_psTexts[12]; 49 CString m_sGoogleMapsLocation; 50 CString m_sYandexMapsLocation; 51 CString m_sBingMapsLocation; 52 CString m_sYahooMapsLocation; 53 CString m_sOpenStreetMapLocation; 54 CString m_sWikiMapiaLocation; 55 56 public: 57 // CStrings 58 CStrings() throw() 59 { 60 } 61 CStrings(const CLocation& Location) 62 { 63 if(!Location.IsValid()) 64 return; 65 #pragma region Degrees 66 { 67 const CString sLatitude = _StringHelper::FormatNumber(Location.m_fLatitude, 6, FALSE); 68 const CString sLongitude = _StringHelper::FormatNumber(Location.m_fLongitude, 6, FALSE); 69 m_psTexts[0] = sLatitude; 70 m_psTexts[1] = sLongitude; 71 m_psTexts[2] = AtlFormatString(_T("%s, %s"), sLatitude, sLongitude); 72 m_psTexts[3] = AtlFormatString(_T("%s, %s"), sLongitude, sLatitude); 73 m_sGoogleMapsLocation = AtlFormatString(_T("http://maps.google.com/maps/?ll=%s,%s"), sLatitude, sLongitude); 74 m_sYandexMapsLocation = AtlFormatString(_T("http://maps.yandex.ru/?ll=%s,%s&z=%d"), sLongitude, sLatitude, 19); 75 m_sBingMapsLocation = AtlFormatString(_T("http://www.bing.com/maps/?v=2&cp=%s~%s&lvl=%d"), sLatitude, sLongitude, 17); 76 m_sYahooMapsLocation = AtlFormatString(_T("http://maps.yahoo.com/#lat=%s&lon=%s&zoom=%d"), sLatitude, sLongitude, 17); 77 m_sOpenStreetMapLocation = AtlFormatString(_T("http://www.openstreetmap.org/?lat=%s&lon=%s&zoom=%d"), sLatitude, sLongitude, 17); 78 m_sWikiMapiaLocation = AtlFormatString(_T("http://wikimapia.org/#lat=%s&lon=%s&z=%d"), sLatitude, sLongitude, 17); 79 } 80 #pragma endregion 81 #pragma region Degrees, Minutes 82 { 83 CString sLatitude, sLongitude; 84 #pragma region Latitude 85 sLatitude.Append((Location.m_fLatitude >= 0) ? _T("N ") : _T("S ")); 86 DOUBLE fPartialLatitude = abs(Location.m_fLatitude); 87 const INT nPartialLatitude = (INT) fPartialLatitude; 88 sLatitude.AppendFormat(_T("%02d "), nPartialLatitude); 89 const DOUBLE fPartialLatitudeMinute = (fPartialLatitude - nPartialLatitude) * 60; 90 const INT nPartialLatitudeMinute = (INT) fPartialLatitudeMinute; 91 sLatitude.AppendFormat(_T("%02d"), nPartialLatitudeMinute); 92 sLatitude.AppendFormat(_T(".%03d"), (INT) ((fPartialLatitudeMinute - nPartialLatitudeMinute) * 1000 + 0.5 - 1E-6)); 93 #pragma endregion 94 #pragma region Latitude 95 sLongitude.Append((Location.m_fLongitude >= 0) ? _T("E ") : _T("W ")); 96 DOUBLE fPartialLongitude = abs(Location.m_fLongitude); 97 const INT nPartialLongitude = (INT) fPartialLongitude; 98 sLongitude.AppendFormat(_T("%03d "), nPartialLongitude); 99 const DOUBLE fPartialLongitudeMinute = (fPartialLongitude - nPartialLongitude) * 60; 100 const INT nPartialLongitudeMinute = (INT) fPartialLongitudeMinute; 101 sLongitude.AppendFormat(_T("%02d"), nPartialLongitudeMinute); 102 sLongitude.AppendFormat(_T(".%03d"), (INT) ((fPartialLongitudeMinute - nPartialLongitudeMinute) * 1000 + 0.5 - 1E-6)); 103 #pragma endregion 104 m_psTexts[4] = sLatitude; 105 m_psTexts[5] = sLongitude; 106 m_psTexts[6] = AtlFormatString(_T("%s, %s"), sLatitude, sLongitude); 107 m_psTexts[7] = AtlFormatString(_T("%s, %s"), sLongitude, sLatitude); 108 } 109 #pragma endregion 110 #pragma region Degrees, Minutes, Seconds 111 { 112 CString sLatitude, sLongitude; 113 #pragma region Latitude 114 sLatitude.Append((Location.m_fLatitude >= 0) ? _T("N ") : _T("S ")); 115 DOUBLE fPartialLatitude = abs(Location.m_fLatitude); 116 const INT nPartialLatitude = (INT) fPartialLatitude; 117 sLatitude.AppendFormat(_T("%02d "), nPartialLatitude); 118 const DOUBLE fPartialLatitudeMinute = (fPartialLatitude - nPartialLatitude) * 60; 119 const INT nPartialLatitudeMinute = (INT) fPartialLatitudeMinute; 120 sLatitude.AppendFormat(_T("%02d "), nPartialLatitudeMinute); 121 const DOUBLE fPartialLatitudeSecond = (fPartialLatitudeMinute - nPartialLatitudeMinute) * 60; 122 const INT nPartialLatitudeSecond = (INT) fPartialLatitudeSecond; 123 sLatitude.AppendFormat(_T("%02d"), nPartialLatitudeSecond); 124 sLatitude.AppendFormat(_T(".%02d"), (INT) ((fPartialLatitudeSecond - nPartialLatitudeSecond) * 100 + 0.5 - 1E-6)); 125 #pragma endregion 126 #pragma region Latitude 127 sLongitude.Append((Location.m_fLongitude >= 0) ? _T("E ") : _T("W ")); 128 DOUBLE fPartialLongitude = abs(Location.m_fLongitude); 129 INT nPartialLongitude = (INT) fPartialLongitude; 130 sLongitude.AppendFormat(_T("%03d "), nPartialLongitude); 131 DOUBLE fPartialLongitudeMinute = (fPartialLongitude - nPartialLongitude) * 60; 132 INT nPartialLongitudeMinute = (INT) fPartialLongitudeMinute; 133 sLongitude.AppendFormat(_T("%02d "), nPartialLongitudeMinute); 134 const DOUBLE fPartialLongitudeSecond = (fPartialLongitudeMinute - nPartialLongitudeMinute) * 60; 135 const INT nPartialLongitudeSecond = (INT) fPartialLongitudeSecond; 136 sLongitude.AppendFormat(_T("%02d"), nPartialLongitudeSecond); 137 sLongitude.AppendFormat(_T(".%02d"), (INT) ((fPartialLongitudeSecond - nPartialLongitudeSecond) * 100 + 0.5 - 1E-6)); 138 #pragma endregion 139 m_psTexts[ 8] = sLatitude; 140 m_psTexts[ 9] = sLongitude; 141 m_psTexts[10] = AtlFormatString(_T("%s, %s"), sLatitude, sLongitude); 142 m_psTexts[11] = AtlFormatString(_T("%s, %s"), sLongitude, sLatitude); 143 } 144 #pragma endregion 145 } 146 }; 147 148 public: 149 BOOL m_bValid; 150 DOUBLE m_fLatitude; 151 DOUBLE m_fLongitude; 152 153 public: 154 // CLocation 155 CLocation() throw() : 156 m_bValid(FALSE) 157 { 158 } 159 CLocation(DOUBLE fLatitude, DOUBLE fLongitude) throw() : 160 m_fLatitude(fLatitude), 161 m_fLongitude(fLongitude), 162 m_bValid(TRUE) 163 { 164 } 165 BOOL IsValid() const throw() 166 { 167 return m_bValid; 168 } 169 VOID SetLocation(DOUBLE fLatitude, DOUBLE fLongitude) throw() 170 { 171 m_fLatitude = fLatitude; 172 m_fLongitude = fLongitude; 173 m_bValid = TRUE; 174 } 175 BOOL Parse(const CString& sText) 176 { 177 m_bValid = FALSE; 178 if(sText.GetLength() >= (4 << 10)) // 4K 179 return FALSE; 180 CRoReMatchContext MatchContext; 181 #pragma region Google Maps 182 static CAtlStaticRegExp<> g_ExpressionA(_T("^ *(http://)?[^/]*maps.google[^/]*/.+?") _T("ll={[\\.0-9]+},{[\\.0-9]+}"), FALSE); 183 if(g_ExpressionA.Match(sText, &MatchContext)) 184 { 185 DOUBLE fLatitude, fLongitude; 186 if(!AtlStringToDouble(MatchContext.GetMatchString(0), fLatitude) || !AtlStringToDouble(MatchContext.GetMatchString(1), fLongitude)) 187 return FALSE; 188 SetLocation(fLatitude, fLongitude); 189 return TRUE; 190 } 191 #pragma endregion 192 #pragma region Yandex Maps 193 static CAtlStaticRegExp<> g_ExpressionB(_T("^ *(http://)?[^/]*maps.yandex[^/]*/.+?") _T("ll={[\\.0-9]+}(,|(\\%2C)){[\\.0-9]+}"), FALSE); 194 if(g_ExpressionB.Match(sText, &MatchContext)) 195 { 196 DOUBLE fLatitude, fLongitude; 197 if(!AtlStringToDouble(MatchContext.GetMatchString(0), fLongitude) || !AtlStringToDouble(MatchContext.GetMatchString(1), fLatitude)) 198 return FALSE; 199 SetLocation(fLatitude, fLongitude); 200 return TRUE; 201 } 202 #pragma endregion 203 // TODO: Recognize Bing, Yahoo, OpenStreetMap and WikiMapia URLs 204 // NOTE: Russian Å is often confused with English E, so we take both 205 #pragma region Degrees and Minutes 206 #define LATITUDE_SYMBOL _T("{[NSCÞ]}") 207 #define LONGITUDE_SYMBOL _T("{[EWÂÇÅ]}") 208 #define VALUE _T("{[0-9]+}[^0-9]+?{[0-9]+\\.[0-9]+}") 209 #define OPTIONAL_WHITESPACE _T("[\t ]*") 210 #define SEPARATOR _T("[^0-9\\.]+?") 211 static CAtlStaticRegExp<> g_ExpressionD0(_T("^") OPTIONAL_WHITESPACE LATITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE SEPARATOR LONGITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE _T(""), FALSE); 212 static CAtlStaticRegExp<> g_ExpressionD1(_T("^") OPTIONAL_WHITESPACE LONGITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE SEPARATOR LATITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE _T(""), FALSE); 213 static CAtlStaticRegExp<> g_ExpressionD2(_T("^") OPTIONAL_WHITESPACE VALUE OPTIONAL_WHITESPACE LATITUDE_SYMBOL SEPARATOR VALUE OPTIONAL_WHITESPACE LONGITUDE_SYMBOL _T(""), FALSE); 214 static CAtlStaticRegExp<> g_ExpressionD3(_T("^") OPTIONAL_WHITESPACE VALUE OPTIONAL_WHITESPACE LATITUDE_SYMBOL SEPARATOR VALUE OPTIONAL_WHITESPACE LONGITUDE_SYMBOL _T(""), FALSE); 215 #undef LATITUDE_SYMBOL 216 #undef LONGITUDE_SYMBOL 217 #undef VALUE 218 #undef OPTIONAL_WHITESPACE 219 #undef SEPARATOR 220 INT nLayoutD = -1; 221 if(g_ExpressionD0.Match(sText, &MatchContext)) 222 nLayoutD = 0; 223 else if(g_ExpressionD1.Match(sText, &MatchContext)) 224 nLayoutD = 1; 225 else if(g_ExpressionD2.Match(sText, &MatchContext)) 226 nLayoutD = 2; 227 else if(g_ExpressionD3.Match(sText, &MatchContext)) 228 nLayoutD = 3; 229 if(nLayoutD >= 0) 230 { 231 static const SIZE_T g_pnMap[4][6] = 232 { 233 { 0, 1, 2, 3, 4, 5, }, 234 { 3, 4, 5, 0, 1, 2, }, 235 { 2, 0, 1, 5, 3, 4, }, 236 { 5, 3, 4, 2, 0, 1, }, 237 }; 238 const INT nLatitudeSign = (MatchContext.GetMatchString(g_pnMap[nLayoutD][0]).FindOneOf(_T("SsÞþ")) >= 0) ? -1 : 1; 239 const INT nLongitudeSign = (MatchContext.GetMatchString(g_pnMap[nLayoutD][3]).FindOneOf(_T("WwÇç")) >= 0) ? -1 : 1; 240 INT nLatitudeDegrees, nLongitudeDegrees; 241 DOUBLE fLatitudeMinutes, fLongitudeMinutes; 242 if(FALSE || 243 !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutD][1]), nLatitudeDegrees) || 244 !AtlStringToDouble(MatchContext.GetMatchString(g_pnMap[nLayoutD][2]), fLatitudeMinutes) || 245 !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutD][4]), nLongitudeDegrees) || 246 !AtlStringToDouble(MatchContext.GetMatchString(g_pnMap[nLayoutD][5]), fLongitudeMinutes) || 247 FALSE) 248 return FALSE; 249 _A(fLatitudeMinutes >= 0 && fLongitudeMinutes >= 0); 250 if(fLatitudeMinutes >= 60.0 || fLongitudeMinutes >= 60.0) 251 return FALSE; 252 const DOUBLE fLatitude = nLatitudeSign * (nLatitudeDegrees + fLatitudeMinutes / 60.0); 253 const DOUBLE fLongitude = nLongitudeSign * (nLongitudeDegrees + fLongitudeMinutes / 60.0); 254 SetLocation(fLatitude, fLongitude); 255 return TRUE; 256 } 257 #pragma endregion 258 #pragma region Degrees, Minutes and Seconds 259 #define LATITUDE_SYMBOL _T("{[NSCÞ]}") 260 #define LONGITUDE_SYMBOL _T("{[EWÂÇÅ]}") 261 #define VALUE _T("{[0-9]+}[^0-9]+?{[0-9]+}[^0-9\\.]+?{[0-9]+(\\.([0-9]+)?)?}") 262 #define OPTIONAL_WHITESPACE _T("[\t ]*") 263 #define SEPARATOR _T("[^0-9\\.]+?") 264 static CAtlStaticRegExp<> g_ExpressionE0(_T("^") OPTIONAL_WHITESPACE LATITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE SEPARATOR LONGITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE _T(""), FALSE); 265 static CAtlStaticRegExp<> g_ExpressionE1(_T("^") OPTIONAL_WHITESPACE LONGITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE SEPARATOR LATITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE _T(""), FALSE); 266 static CAtlStaticRegExp<> g_ExpressionE2(_T("^") OPTIONAL_WHITESPACE VALUE OPTIONAL_WHITESPACE LATITUDE_SYMBOL SEPARATOR VALUE OPTIONAL_WHITESPACE LONGITUDE_SYMBOL _T(""), FALSE); 267 static CAtlStaticRegExp<> g_ExpressionE3(_T("^") OPTIONAL_WHITESPACE VALUE OPTIONAL_WHITESPACE LONGITUDE_SYMBOL SEPARATOR VALUE OPTIONAL_WHITESPACE LATITUDE_SYMBOL _T(""), FALSE); 268 #undef LATITUDE_SYMBOL 269 #undef LONGITUDE_SYMBOL 270 #undef VALUE 271 #undef OPTIONAL_WHITESPACE 272 #undef SEPARATOR 273 INT nLayoutE = -1; 274 if(g_ExpressionE0.Match(sText, &MatchContext)) 275 nLayoutE = 0; 276 else if(g_ExpressionE1.Match(sText, &MatchContext)) 277 nLayoutE = 1; 278 else if(g_ExpressionE2.Match(sText, &MatchContext)) 279 nLayoutE = 2; 280 else if(g_ExpressionE3.Match(sText, &MatchContext)) 281 nLayoutE = 3; 282 if(nLayoutE >= 0) 283 { 284 static const SIZE_T g_pnMap[4][8] = 285 { 286 { 0, 1, 2, 3, 4, 5, 6, 7, }, 287 { 4, 5, 6, 7, 0, 1, 2, 3, }, 288 { 3, 0, 1, 2, 7, 4, 5, 6, }, 289 { 7, 4, 5, 6, 3, 0, 1, 2, }, 290 }; 291 const INT nLatitudeSign = (MatchContext.GetMatchString(g_pnMap[nLayoutE][0]).FindOneOf(_T("SsÞþ")) >= 0) ? -1 : 1; 292 const INT nLongitudeSign = (MatchContext.GetMatchString(g_pnMap[nLayoutE][4]).FindOneOf(_T("WwÇç")) >= 0) ? -1 : 1; 293 INT nLatitudeDegrees, nLongitudeDegrees; 294 INT nLatitudeMinutes, nLongitudeMinutes; 295 DOUBLE fLatitudeSeconds, fLongitudeSeconds; 296 if(FALSE || 297 !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutE][1]), nLatitudeDegrees) || 298 !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutE][2]), nLatitudeMinutes) || 299 !AtlStringToDouble(MatchContext.GetMatchString(g_pnMap[nLayoutE][3]), fLatitudeSeconds) || 300 !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutE][5]), nLongitudeDegrees) || 301 !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutE][6]), nLongitudeMinutes) || 302 !AtlStringToDouble(MatchContext.GetMatchString(g_pnMap[nLayoutE][7]), fLongitudeSeconds) || 303 FALSE) 304 return FALSE; 305 _A(nLatitudeMinutes >= 0 && nLongitudeMinutes >= 0); 306 if(nLatitudeMinutes >= 60 || nLongitudeMinutes >= 60) 307 return FALSE; 308 _A(fLatitudeSeconds >= 0 && fLongitudeSeconds >= 0); 309 if(fLatitudeSeconds >= 60 || fLongitudeSeconds >= 60) 310 return FALSE; 311 const DOUBLE fLatitude = nLatitudeSign * (nLatitudeDegrees + (nLatitudeMinutes + fLatitudeSeconds / 60.0) / 60.0); 312 const DOUBLE fLongitude = nLongitudeSign * (nLongitudeDegrees + (nLongitudeMinutes + fLongitudeSeconds / 60.0) / 60.0); 313 SetLocation(fLatitude, fLongitude); 314 return TRUE; 315 } 316 #pragma endregion 317 #pragma region Degrees, Latitude and Longitude 318 static CAtlStaticRegExp<> g_ExpressionC(_T("^ *") _T("{-?[0-9]+\\.[0-9]+}") _T("[^0-9\\.]+") _T("{-?[0-9]+\\.[0-9]+}"), FALSE); 319 if(g_ExpressionC.Match(sText, &MatchContext)) 320 { 321 DOUBLE fLatitude, fLongitude; 322 if(!AtlStringToDouble(MatchContext.GetMatchString(0), fLatitude) || !AtlStringToDouble(MatchContext.GetMatchString(1), fLongitude)) 323 return FALSE; 324 SetLocation(fLatitude, fLongitude); 325 return TRUE; 326 } 327 #pragma endregion 328 return FALSE; 329 } 330 }; 331 332 //////////////////////////////////////////////////////// 333 // CLocationArray 334 335 class CLocationArray : 336 public CRoArrayT<CLocation> 337 { 338 public: 339 // CLocationArray 340 SIZE_T GetValidCount() const throw() 341 { 342 SIZE_T nCount = 0; 343 for(SIZE_T nIndex = 0; nIndex < GetCount(); nIndex++) 344 if(GetAt(nIndex).IsValid()) 345 nCount++; 346 return nCount; 347 } 348 BOOL FindFirstValidIndex(SIZE_T* pnIndex = NULL) const throw() 349 { 350 for(SIZE_T nIndex = 0; nIndex < GetCount(); nIndex++) 351 if(GetAt(nIndex).IsValid()) 352 { 353 if(pnIndex) 354 *pnIndex = nIndex; 355 return TRUE; 356 } 357 return FALSE; 358 } 359 CString GetText(SIZE_T nTextIndex) const 360 { 361 //_A(nTextIndex < DIM(CLocation::CStrings::m_psTexts)); 362 CRoArrayT<CString> Array; 363 for(SIZE_T nIndex = 0; nIndex < GetCount(); nIndex++) 364 { 365 const CLocation& Location = GetAt(nIndex); 366 CString sText; 367 if(Location.IsValid()) 368 sText = CLocation::CStrings(Location).m_psTexts[nTextIndex]; 369 _W(Array.Add(sText) >= 0); 370 } 371 return _StringHelper::Join(Array, _T("\r\n")); 372 } 373 }; 374 33 375 private: 34 376 CRoIconStatic m_IntroductionStatic; … … 42 384 BOOL m_bSetClipboardTextActive; 43 385 CWindow m_NextClipboardViewerWindow; 386 CLocationArray m_LocationArray; 44 387 45 388 public: … … 48 391 { 49 392 } 50 VOID SetLocation(DOUBLE fLatitude, DOUBLE fLongitude) 51 { 52 CString psTexts[12]; 53 CString sGoogleMapsLocation, sYandexMapsLocation, sBingMapsLocation, sYahooMapsLocation, sOpenStreetMapLocation, sWikiMapiaLocation; 54 #pragma region Degrees 55 { 56 const CString sLatitude = _StringHelper::FormatNumber(fLatitude, 6, FALSE); 57 const CString sLongitude = _StringHelper::FormatNumber(fLongitude, 6, FALSE); 58 psTexts[0] = sLatitude; 59 psTexts[1] = sLongitude; 60 psTexts[2] = AtlFormatString(_T("%s, %s"), sLatitude, sLongitude); 61 psTexts[3] = AtlFormatString(_T("%s, %s"), sLongitude, sLatitude); 62 sGoogleMapsLocation = AtlFormatString(_T("http://maps.google.com/maps/?ll=%s,%s"), sLatitude, sLongitude); 63 sYandexMapsLocation = AtlFormatString(_T("http://maps.yandex.ru/?ll=%s,%s&z=%d"), sLongitude, sLatitude, 19); 64 sBingMapsLocation = AtlFormatString(_T("http://www.bing.com/maps/?v=2&cp=%s~%s&lvl=%d"), sLatitude, sLongitude, 17); 65 sYahooMapsLocation = AtlFormatString(_T("http://maps.yahoo.com/#lat=%s&lon=%s&zoom=%d"), sLatitude, sLongitude, 17); 66 sOpenStreetMapLocation = AtlFormatString(_T("http://www.openstreetmap.org/?lat=%s&lon=%s&zoom=%d"), sLatitude, sLongitude, 17); 67 sWikiMapiaLocation = AtlFormatString(_T("http://wikimapia.org/#lat=%s&lon=%s&z=%d"), sLatitude, sLongitude, 17); 68 } 69 #pragma endregion 70 #pragma region Degrees, Minutes 71 { 72 CString sLatitude, sLongitude; 73 #pragma region Latitude 74 sLatitude.Append((fLatitude >= 0) ? _T("N ") : _T("S ")); 75 DOUBLE fPartialLatitude = abs(fLatitude); 76 const INT nPartialLatitude = (INT) fPartialLatitude; 77 sLatitude.AppendFormat(_T("%02d "), nPartialLatitude); 78 const DOUBLE fPartialLatitudeMinute = (fPartialLatitude - nPartialLatitude) * 60; 79 const INT nPartialLatitudeMinute = (INT) fPartialLatitudeMinute; 80 sLatitude.AppendFormat(_T("%02d"), nPartialLatitudeMinute); 81 sLatitude.AppendFormat(_T(".%03d"), (INT) ((fPartialLatitudeMinute - nPartialLatitudeMinute) * 1000 + 0.5 - 1E-6)); 82 #pragma endregion 83 #pragma region Latitude 84 sLongitude.Append((fLongitude >= 0) ? _T("E ") : _T("W ")); 85 DOUBLE fPartialLongitude = abs(fLongitude); 86 const INT nPartialLongitude = (INT) fPartialLongitude; 87 sLongitude.AppendFormat(_T("%03d "), nPartialLongitude); 88 const DOUBLE fPartialLongitudeMinute = (fPartialLongitude - nPartialLongitude) * 60; 89 const INT nPartialLongitudeMinute = (INT) fPartialLongitudeMinute; 90 sLongitude.AppendFormat(_T("%02d"), nPartialLongitudeMinute); 91 sLongitude.AppendFormat(_T(".%03d"), (INT) ((fPartialLongitudeMinute - nPartialLongitudeMinute) * 1000 + 0.5 - 1E-6)); 92 #pragma endregion 93 psTexts[4] = sLatitude; 94 psTexts[5] = sLongitude; 95 psTexts[6] = AtlFormatString(_T("%s, %s"), sLatitude, sLongitude); 96 psTexts[7] = AtlFormatString(_T("%s, %s"), sLongitude, sLatitude); 97 } 98 #pragma endregion 99 #pragma region Degrees, Minutes, Seconds 100 { 101 CString sLatitude, sLongitude; 102 #pragma region Latitude 103 sLatitude.Append((fLatitude >= 0) ? _T("N ") : _T("S ")); 104 DOUBLE fPartialLatitude = abs(fLatitude); 105 const INT nPartialLatitude = (INT) fPartialLatitude; 106 sLatitude.AppendFormat(_T("%02d "), nPartialLatitude); 107 const DOUBLE fPartialLatitudeMinute = (fPartialLatitude - nPartialLatitude) * 60; 108 const INT nPartialLatitudeMinute = (INT) fPartialLatitudeMinute; 109 sLatitude.AppendFormat(_T("%02d "), nPartialLatitudeMinute); 110 const DOUBLE fPartialLatitudeSecond = (fPartialLatitudeMinute - nPartialLatitudeMinute) * 60; 111 const INT nPartialLatitudeSecond = (INT) fPartialLatitudeSecond; 112 sLatitude.AppendFormat(_T("%02d"), nPartialLatitudeSecond); 113 sLatitude.AppendFormat(_T(".%02d"), (INT) ((fPartialLatitudeSecond - nPartialLatitudeSecond) * 100 + 0.5 - 1E-6)); 114 #pragma endregion 115 #pragma region Latitude 116 sLongitude.Append((fLongitude >= 0) ? _T("E ") : _T("W ")); 117 DOUBLE fPartialLongitude = abs(fLongitude); 118 INT nPartialLongitude = (INT) fPartialLongitude; 119 sLongitude.AppendFormat(_T("%03d "), nPartialLongitude); 120 DOUBLE fPartialLongitudeMinute = (fPartialLongitude - nPartialLongitude) * 60; 121 INT nPartialLongitudeMinute = (INT) fPartialLongitudeMinute; 122 sLongitude.AppendFormat(_T("%02d "), nPartialLongitudeMinute); 123 const DOUBLE fPartialLongitudeSecond = (fPartialLongitudeMinute - nPartialLongitudeMinute) * 60; 124 const INT nPartialLongitudeSecond = (INT) fPartialLongitudeSecond; 125 sLongitude.AppendFormat(_T("%02d"), nPartialLongitudeSecond); 126 sLongitude.AppendFormat(_T(".%02d"), (INT) ((fPartialLongitudeSecond - nPartialLongitudeSecond) * 100 + 0.5 - 1E-6)); 127 #pragma endregion 128 psTexts[ 8] = sLatitude; 129 psTexts[ 9] = sLongitude; 130 psTexts[10] = AtlFormatString(_T("%s, %s"), sLatitude, sLongitude); 131 psTexts[11] = AtlFormatString(_T("%s, %s"), sLongitude, sLatitude); 132 } 133 #pragma endregion 393 VOID SetLocation(const CLocation& Location) 394 { 395 CLocation::CStrings Strings(Location); 134 396 for(SIZE_T nIndex = 0; nIndex < 12; nIndex++) 135 m_pStatics[nIndex].SetWindowText(AtlFormatString(_T("<A HREF=\"%s\">%s</A> (F%d)"), psTexts[nIndex], psTexts[nIndex], nIndex + 1)); 136 m_GoogleMapsStatic.SetWindowText(AtlFormatString(_T("<A TITLE=\"Open in Google Maps\" HREF=\"%s\">%s</A>"), sGoogleMapsLocation, sGoogleMapsLocation)); 137 m_YandexMapsStatic.SetWindowText(AtlFormatString(_T("<A TITLE=\"Open in Yandex Maps\" HREF=\"%s\">%s</A>"), sYandexMapsLocation, sYandexMapsLocation)); 138 m_BingMapsStatic.SetWindowText(AtlFormatString(_T("<A TITLE=\"Open in Bing Maps\" HREF=\"%s\">%s</A>"), sBingMapsLocation, sBingMapsLocation)); 139 m_YahooMapsStatic.SetWindowText(AtlFormatString(_T("<A TITLE=\"Open in Yahoo Maps\" HREF=\"%s\">%s</A>"), sYahooMapsLocation, sYahooMapsLocation)); 140 m_OpenStreetMapStatic.SetWindowText(AtlFormatString(_T("<A TITLE=\"Open in Open Street Map\" HREF=\"%s\">%s</A>"), sOpenStreetMapLocation, sOpenStreetMapLocation)); 141 m_WikiMapiaStatic.SetWindowText(AtlFormatString(_T("<A TITLE=\"Open in WikiMapia\" HREF=\"%s\">%s</A>"), sWikiMapiaLocation, sWikiMapiaLocation)); 142 } 143 BOOL SetText(const CString& sText) 144 { 145 if(sText.GetLength() >= 4096) 397 m_pStatics[nIndex].SetWindowText(AtlFormatString(_T("<A HREF=\"%s\">%s</A> (F%d)"), Strings.m_psTexts[nIndex], Strings.m_psTexts[nIndex], nIndex + 1)); 398 m_GoogleMapsStatic.SetWindowText(AtlFormatString(_T("<A TITLE=\"Open in Google Maps\" HREF=\"%s\">%s</A>"), Strings.m_sGoogleMapsLocation, Strings.m_sGoogleMapsLocation)); 399 m_YandexMapsStatic.SetWindowText(AtlFormatString(_T("<A TITLE=\"Open in Yandex Maps\" HREF=\"%s\">%s</A>"), Strings.m_sYandexMapsLocation, Strings.m_sYandexMapsLocation)); 400 m_BingMapsStatic.SetWindowText(AtlFormatString(_T("<A TITLE=\"Open in Bing Maps\" HREF=\"%s\">%s</A>"), Strings.m_sBingMapsLocation, Strings.m_sBingMapsLocation)); 401 m_YahooMapsStatic.SetWindowText(AtlFormatString(_T("<A TITLE=\"Open in Yahoo Maps\" HREF=\"%s\">%s</A>"), Strings.m_sYahooMapsLocation, Strings.m_sYahooMapsLocation)); 402 m_OpenStreetMapStatic.SetWindowText(AtlFormatString(_T("<A TITLE=\"Open in Open Street Map\" HREF=\"%s\">%s</A>"), Strings.m_sOpenStreetMapLocation, Strings.m_sOpenStreetMapLocation)); 403 m_WikiMapiaStatic.SetWindowText(AtlFormatString(_T("<A TITLE=\"Open in WikiMapia\" HREF=\"%s\">%s</A>"), Strings.m_sWikiMapiaLocation, Strings.m_sWikiMapiaLocation)); 404 } 405 BOOL Parse(CString sText) 406 { 407 CLocationArray LocationArray; 408 if(sText.GetLength() < 32 << 10) // 32 KB 409 { 410 if(sText.Find(_T('\n')) >= 0) 411 { 412 sText.Replace(_T("\r\n"), _T("\n")); 413 CRoArrayT<CString> Array; 414 if(_StringHelper::Split(sText, _T('\n'), Array)) 415 for(SIZE_T nIndex = 0; nIndex < Array.GetCount(); nIndex++) 416 { 417 CLocation Location; 418 Location.Parse(Array[nIndex]); 419 _W(LocationArray.Add(Location) >= 0); 420 } 421 if(!LocationArray.GetValidCount()) 422 LocationArray.RemoveAll(); 423 } else 424 { 425 CLocation Location; 426 if(Location.Parse(sText)) 427 _W(LocationArray.Add(Location) >= 0); 428 } 429 } 430 SIZE_T nFirstValidIndex; 431 if(!LocationArray.FindFirstValidIndex(&nFirstValidIndex)) 146 432 return FALSE; 147 CRoReMatchContext MatchContext; 148 #pragma region Google Maps 149 static CAtlStaticRegExp<> g_ExpressionA(_T("^ *(http://)?[^/]*maps.google[^/]*/.+?") _T("ll={[\\.0-9]+},{[\\.0-9]+}"), FALSE); 150 if(g_ExpressionA.Match(sText, &MatchContext)) 151 { 152 DOUBLE fLatitude, fLongitude; 153 if(!AtlStringToDouble(MatchContext.GetMatchString(0), fLatitude) || !AtlStringToDouble(MatchContext.GetMatchString(1), fLongitude)) 154 return FALSE; 155 SetLocation(fLatitude, fLongitude); 156 return TRUE; 157 } 158 #pragma endregion 159 #pragma region Yandex Maps 160 static CAtlStaticRegExp<> g_ExpressionB(_T("^ *(http://)?[^/]*maps.yandex[^/]*/.+?") _T("ll={[\\.0-9]+}(,|(\\%2C)){[\\.0-9]+}"), FALSE); 161 if(g_ExpressionB.Match(sText, &MatchContext)) 162 { 163 DOUBLE fLatitude, fLongitude; 164 if(!AtlStringToDouble(MatchContext.GetMatchString(0), fLongitude) || !AtlStringToDouble(MatchContext.GetMatchString(1), fLatitude)) 165 return FALSE; 166 SetLocation(fLatitude, fLongitude); 167 return TRUE; 168 } 169 #pragma endregion 170 // TODO: Recognize Bing, Yahoo, OpenStreetMap and WikiMapia URLs 171 // NOTE: Russian Å is often confused with English E, so we take both 172 #pragma region Degrees and Minutes 173 #define LATITUDE_SYMBOL _T("{[NSCÞ]}") 174 #define LONGITUDE_SYMBOL _T("{[EWÂÇÅ]}") 175 #define VALUE _T("{[0-9]+}[^0-9]+?{[0-9]+\\.[0-9]+}") 176 #define OPTIONAL_WHITESPACE _T("[\t ]*") 177 #define SEPARATOR _T("[^0-9\\.]+?") 178 static CAtlStaticRegExp<> g_ExpressionD0(_T("^") OPTIONAL_WHITESPACE LATITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE SEPARATOR LONGITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE _T(""), FALSE); 179 static CAtlStaticRegExp<> g_ExpressionD1(_T("^") OPTIONAL_WHITESPACE LONGITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE SEPARATOR LATITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE _T(""), FALSE); 180 static CAtlStaticRegExp<> g_ExpressionD2(_T("^") OPTIONAL_WHITESPACE VALUE OPTIONAL_WHITESPACE LATITUDE_SYMBOL SEPARATOR VALUE OPTIONAL_WHITESPACE LONGITUDE_SYMBOL _T(""), FALSE); 181 static CAtlStaticRegExp<> g_ExpressionD3(_T("^") OPTIONAL_WHITESPACE VALUE OPTIONAL_WHITESPACE LATITUDE_SYMBOL SEPARATOR VALUE OPTIONAL_WHITESPACE LONGITUDE_SYMBOL _T(""), FALSE); 182 #undef LATITUDE_SYMBOL 183 #undef LONGITUDE_SYMBOL 184 #undef VALUE 185 #undef OPTIONAL_WHITESPACE 186 #undef SEPARATOR 187 INT nLayoutD = -1; 188 if(g_ExpressionD0.Match(sText, &MatchContext)) 189 nLayoutD = 0; 190 else if(g_ExpressionD1.Match(sText, &MatchContext)) 191 nLayoutD = 1; 192 else if(g_ExpressionD2.Match(sText, &MatchContext)) 193 nLayoutD = 2; 194 else if(g_ExpressionD3.Match(sText, &MatchContext)) 195 nLayoutD = 3; 196 if(nLayoutD >= 0) 197 { 198 static const SIZE_T g_pnMap[4][6] = 199 { 200 { 0, 1, 2, 3, 4, 5, }, 201 { 3, 4, 5, 0, 1, 2, }, 202 { 2, 0, 1, 5, 3, 4, }, 203 { 5, 3, 4, 2, 0, 1, }, 204 }; 205 const INT nLatitudeSign = (MatchContext.GetMatchString(g_pnMap[nLayoutD][0]).FindOneOf(_T("SsÞþ")) >= 0) ? -1 : 1; 206 const INT nLongitudeSign = (MatchContext.GetMatchString(g_pnMap[nLayoutD][3]).FindOneOf(_T("WwÇç")) >= 0) ? -1 : 1; 207 INT nLatitudeDegrees, nLongitudeDegrees; 208 DOUBLE fLatitudeMinutes, fLongitudeMinutes; 209 if(FALSE || 210 !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutD][1]), nLatitudeDegrees) || 211 !AtlStringToDouble(MatchContext.GetMatchString(g_pnMap[nLayoutD][2]), fLatitudeMinutes) || 212 !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutD][4]), nLongitudeDegrees) || 213 !AtlStringToDouble(MatchContext.GetMatchString(g_pnMap[nLayoutD][5]), fLongitudeMinutes) || 214 FALSE) 215 return FALSE; 216 _A(fLatitudeMinutes >= 0 && fLongitudeMinutes >= 0); 217 if(fLatitudeMinutes >= 60.0 || fLongitudeMinutes >= 60.0) 218 return FALSE; 219 const DOUBLE fLatitude = nLatitudeSign * (nLatitudeDegrees + fLatitudeMinutes / 60.0); 220 const DOUBLE fLongitude = nLongitudeSign * (nLongitudeDegrees + fLongitudeMinutes / 60.0); 221 SetLocation(fLatitude, fLongitude); 222 return TRUE; 223 } 224 #pragma endregion 225 #pragma region Degrees, Minutes and Seconds 226 #define LATITUDE_SYMBOL _T("{[NSCÞ]}") 227 #define LONGITUDE_SYMBOL _T("{[EWÂÇÅ]}") 228 #define VALUE _T("{[0-9]+}[^0-9]+?{[0-9]+}[^0-9\\.]+?{[0-9]+(\\.([0-9]+)?)?}") 229 #define OPTIONAL_WHITESPACE _T("[\t ]*") 230 #define SEPARATOR _T("[^0-9\\.]+?") 231 static CAtlStaticRegExp<> g_ExpressionE0(_T("^") OPTIONAL_WHITESPACE LATITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE SEPARATOR LONGITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE _T(""), FALSE); 232 static CAtlStaticRegExp<> g_ExpressionE1(_T("^") OPTIONAL_WHITESPACE LONGITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE SEPARATOR LATITUDE_SYMBOL OPTIONAL_WHITESPACE VALUE _T(""), FALSE); 233 static CAtlStaticRegExp<> g_ExpressionE2(_T("^") OPTIONAL_WHITESPACE VALUE OPTIONAL_WHITESPACE LATITUDE_SYMBOL SEPARATOR VALUE OPTIONAL_WHITESPACE LONGITUDE_SYMBOL _T(""), FALSE); 234 static CAtlStaticRegExp<> g_ExpressionE3(_T("^") OPTIONAL_WHITESPACE VALUE OPTIONAL_WHITESPACE LONGITUDE_SYMBOL SEPARATOR VALUE OPTIONAL_WHITESPACE LATITUDE_SYMBOL _T(""), FALSE); 235 #undef LATITUDE_SYMBOL 236 #undef LONGITUDE_SYMBOL 237 #undef VALUE 238 #undef OPTIONAL_WHITESPACE 239 #undef SEPARATOR 240 INT nLayoutE = -1; 241 if(g_ExpressionE0.Match(sText, &MatchContext)) 242 nLayoutE = 0; 243 else if(g_ExpressionE1.Match(sText, &MatchContext)) 244 nLayoutE = 1; 245 else if(g_ExpressionE2.Match(sText, &MatchContext)) 246 nLayoutE = 2; 247 else if(g_ExpressionE3.Match(sText, &MatchContext)) 248 nLayoutE = 3; 249 if(nLayoutE >= 0) 250 { 251 static const SIZE_T g_pnMap[4][8] = 252 { 253 { 0, 1, 2, 3, 4, 5, 6, 7, }, 254 { 4, 5, 6, 7, 0, 1, 2, 3, }, 255 { 3, 0, 1, 2, 7, 4, 5, 6, }, 256 { 7, 4, 5, 6, 3, 0, 1, 2, }, 257 }; 258 const INT nLatitudeSign = (MatchContext.GetMatchString(g_pnMap[nLayoutE][0]).FindOneOf(_T("SsÞþ")) >= 0) ? -1 : 1; 259 const INT nLongitudeSign = (MatchContext.GetMatchString(g_pnMap[nLayoutE][4]).FindOneOf(_T("WwÇç")) >= 0) ? -1 : 1; 260 INT nLatitudeDegrees, nLongitudeDegrees; 261 INT nLatitudeMinutes, nLongitudeMinutes; 262 DOUBLE fLatitudeSeconds, fLongitudeSeconds; 263 if(FALSE || 264 !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutE][1]), nLatitudeDegrees) || 265 !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutE][2]), nLatitudeMinutes) || 266 !AtlStringToDouble(MatchContext.GetMatchString(g_pnMap[nLayoutE][3]), fLatitudeSeconds) || 267 !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutE][5]), nLongitudeDegrees) || 268 !AtlStringToInteger(MatchContext.GetMatchString(g_pnMap[nLayoutE][6]), nLongitudeMinutes) || 269 !AtlStringToDouble(MatchContext.GetMatchString(g_pnMap[nLayoutE][7]), fLongitudeSeconds) || 270 FALSE) 271 return FALSE; 272 _A(nLatitudeMinutes >= 0 && nLongitudeMinutes >= 0); 273 if(nLatitudeMinutes >= 60 || nLongitudeMinutes >= 60) 274 return FALSE; 275 _A(fLatitudeSeconds >= 0 && fLongitudeSeconds >= 0); 276 if(fLatitudeSeconds >= 60 || fLongitudeSeconds >= 60) 277 return FALSE; 278 const DOUBLE fLatitude = nLatitudeSign * (nLatitudeDegrees + (nLatitudeMinutes + fLatitudeSeconds / 60.0) / 60.0); 279 const DOUBLE fLongitude = nLongitudeSign * (nLongitudeDegrees + (nLongitudeMinutes + fLongitudeSeconds / 60.0) / 60.0); 280 SetLocation(fLatitude, fLongitude); 281 return TRUE; 282 } 283 #pragma endregion 284 #pragma region Degrees, Latitude and Longitude 285 static CAtlStaticRegExp<> g_ExpressionC(_T("^ *") _T("{-?[0-9]+\\.[0-9]+}") _T("[^0-9\\.]+") _T("{-?[0-9]+\\.[0-9]+}"), FALSE); 286 if(g_ExpressionC.Match(sText, &MatchContext)) 287 { 288 DOUBLE fLatitude, fLongitude; 289 if(!AtlStringToDouble(MatchContext.GetMatchString(0), fLatitude) || !AtlStringToDouble(MatchContext.GetMatchString(1), fLongitude)) 290 return FALSE; 291 SetLocation(fLatitude, fLongitude); 292 return TRUE; 293 } 294 #pragma endregion 295 return FALSE; 296 } 297 BOOL SetText(LPCTSTR pszText) 298 { 299 return SetText(CString(pszText)); 433 const CLocation& Location = LocationArray[nFirstValidIndex]; 434 SetLocation(Location); 435 SwapMemory(&m_LocationArray, &LocationArray); 436 return TRUE; 437 } 438 BOOL Parse(LPCTSTR pszText) 439 { 440 return Parse(CString(pszText)); 300 441 } 301 442 … … 356 497 __E(DataHandle); 357 498 CGlobalMemoryHandle::CLockT<WCHAR> pszData(DataHandle); 358 if( SetText(CW2CT(pszData)))499 if(Parse(CW2CT(pszData))) 359 500 { 360 501 FLASHWINFO FlashWindowInformation = { sizeof FlashWindowInformation, m_hWnd, FLASHW_CAPTION, 5 }; … … 396 537 { 397 538 CRoHyperStatic::NMANCHORCLICKED* pHeaderEx = (CRoHyperStatic::NMANCHORCLICKED*) pHeader; 539 CString sLocation = pHeaderEx->pszLocation; 540 #pragma region Update with Multiple Value Text 541 if(pHeaderEx->Header.idFrom >= IDC_MAIN_DEGREES_LATITUDE && pHeaderEx->Header.idFrom <= IDC_MAIN_DEGREESMINUTESSECONDS_LONGITUDELATITUDE) 542 if(m_LocationArray.GetValidCount() > 0) 543 sLocation = m_LocationArray.GetText(pHeaderEx->Header.idFrom - IDC_MAIN_DEGREES_LATITUDE); 544 #pragma endregion 398 545 m_bSetClipboardTextActive = TRUE; 399 SetClipboardText(m_hWnd, pHeaderEx->pszLocation);546 SetClipboardText(m_hWnd, sLocation); 400 547 m_bSetClipboardTextActive = FALSE; 401 548 pHeaderEx->bShellExecuteLocation = FALSE; … … 408 555 if(nIdentifier < 12) 409 556 { 557 #if TRUE 558 if(m_LocationArray.GetValidCount() > 0) 559 { 560 CRoArrayT<CString> Array; 561 for(SIZE_T nIndex = 0; nIndex < m_LocationArray.GetCount(); nIndex++) 562 { 563 const CLocation& Location = m_LocationArray[nIndex]; 564 CString sText; 565 if(Location.IsValid()) 566 sText = CLocation::CStrings(Location).m_psTexts[nIdentifier]; 567 _W(Array.Add(sText) >= 0); 568 } 569 m_bSetClipboardTextActive = TRUE; 570 SetClipboardText(m_hWnd, _StringHelper::Join(Array, _T("\r\n"))); 571 m_bSetClipboardTextActive = FALSE; 572 MessageBeep(MB_OK); 573 } 574 #else 410 575 CString sText; 411 576 m_pStatics[nIdentifier].GetWindowText(sText); … … 419 584 MessageBeep(MB_OK); 420 585 } 586 #endif 421 587 } 422 588 return 0;
Note: See TracChangeset
for help on using the changeset viewer.