From 6631e22123edb5cc06fee86529265cb5512c23b6 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Mon, 17 Oct 2011 02:51:37 +0300 Subject: [PATCH] [ios] Added framework * to Search View Controller for direct access to Search functions --- iphone/Maps/Classes/MapViewController.mm | 7 ++--- iphone/Maps/Classes/SearchVC.h | 9 +++--- iphone/Maps/Classes/SearchVC.mm | 39 ++++++++++++------------ 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 3dc6ecffc0..7fc0bb1c92 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -94,10 +94,7 @@ storage::Storage m_storage; - (IBAction)OnSearchClicked:(id)sender { - SearchVC * searchVC = [[[SearchVC alloc] initWithNibName:@"Search" bundle:nil] autorelease]; - [searchVC setSearchFunc:bind(&framework_t::Search, m_framework, _1, _2) - andShowRectFunc:bind(&framework_t::ShowRect, m_framework, _1) - andGetViewportCenterFunc:bind(&framework_t::GetViewportCenter, m_framework)]; + SearchVC * searchVC = [[[SearchVC alloc] initWithFramework:m_framework] autorelease]; [self presentModalViewController:searchVC animated:YES]; } @@ -281,7 +278,7 @@ NSInteger compareAddress(id l, id r, void * context) EAGLView * v = (EAGLView*)self.view; boost::shared_ptr wh = [v windowHandle]; boost::shared_ptr rb = [v renderBuffer]; - shared_ptr drawer = [(EAGLView*)self.view drawer]; + shared_ptr drawer = [v drawer]; shared_ptr pe(new PaintEvent(drawer.get())); if (wh->needRedraw()) diff --git a/iphone/Maps/Classes/SearchVC.h b/iphone/Maps/Classes/SearchVC.h index 0ca1f81311..1af94b5940 100644 --- a/iphone/Maps/Classes/SearchVC.h +++ b/iphone/Maps/Classes/SearchVC.h @@ -2,6 +2,7 @@ #import #include "../../map/framework.hpp" +#include "../../map/feature_vec_model.hpp" #include "../../std/vector.hpp" #include "../../std/function.hpp" @@ -9,13 +10,12 @@ namespace search { class Result; } -typedef function SearchF; -typedef function ShowRectF; -typedef function GetViewportCenterF; +typedef Framework framework_t; @interface SearchVC : UIViewController { + framework_t * m_framework; vector m_results; CLLocationManager * m_locationManager; UISearchBar * m_searchBar; @@ -25,7 +25,6 @@ typedef function GetViewportCenterF; @property (nonatomic, retain) IBOutlet UISearchBar * m_searchBar; @property (nonatomic, retain) IBOutlet UITableView * m_table; -- (void)setSearchFunc:(SearchF)s andShowRectFunc:(ShowRectF)r - andGetViewportCenterFunc:(GetViewportCenterF)c; +- (id)initWithFramework:(framework_t *)framework; @end diff --git a/iphone/Maps/Classes/SearchVC.mm b/iphone/Maps/Classes/SearchVC.mm index 7b2ec7085b..d457fff8c0 100644 --- a/iphone/Maps/Classes/SearchVC.mm +++ b/iphone/Maps/Classes/SearchVC.mm @@ -8,9 +8,6 @@ #include "../../search/result.hpp" SearchVC * g_searchVC = nil; -SearchF g_searchF; -ShowRectF g_showRectF; -GetViewportCenterF g_getViewportCenterF; volatile int g_queryId = 0; @interface Wrapper : NSObject @@ -64,20 +61,22 @@ static void OnSearchResultCallback(search::Result const & res, int queryId) @synthesize m_searchBar; @synthesize m_table; -- (void)setSearchFunc:(SearchF)s andShowRectFunc:(ShowRectF)r - andGetViewportCenterFunc:(GetViewportCenterF)c +- (id)initWithFramework:(framework_t *)framework { - g_searchF = s; - g_showRectF = r; - g_getViewportCenterF = c; - m_locationManager = [[CLLocationManager alloc] init]; - m_locationManager.delegate = self; - // filter out unnecessary events - m_locationManager.headingFilter = 3; - m_locationManager.distanceFilter = 1.0; - [m_locationManager startUpdatingLocation]; - if ([CLLocationManager headingAvailable]) - [m_locationManager startUpdatingHeading]; + if ((self = [super initWithNibName:@"Search" bundle:nil])) + { + m_framework = framework; + m_locationManager = [[CLLocationManager alloc] init]; + m_locationManager.delegate = self; + // filter out unnecessary events + m_locationManager.headingFilter = 3; + m_locationManager.distanceFilter = 1.0; + [m_locationManager startUpdatingLocation]; + if ([CLLocationManager headingAvailable]) + [m_locationManager startUpdatingHeading]; + } + + return self; } - (void)clearResults @@ -154,7 +153,7 @@ static void OnSearchResultCallback(search::Result const & res, int queryId) if ([searchText length] > 0) { - g_searchF([[searchText precomposedStringWithCompatibilityMapping] UTF8String], + m_framework->Search([[searchText precomposedStringWithCompatibilityMapping] UTF8String], bind(&OnSearchResultCallback, _1, g_queryId)); } } @@ -202,7 +201,7 @@ static void OnSearchResultCallback(search::Result const & res, int queryId) } } - m2::PointD const center = g_getViewportCenterF(); + m2::PointD const center = m_framework->GetViewportCenter(); return ang::AngleTo(center, pt); } @@ -215,7 +214,7 @@ static void OnSearchResultCallback(search::Result const & res, int queryId) return ms::DistanceOnEarth(loc.coordinate.latitude, loc.coordinate.longitude, ptLat, ptLon); else { - m2::PointD const center = g_getViewportCenterF(); + m2::PointD const center = m_framework->GetViewportCenter(); return ms::DistanceOnEarth(MercatorBounds::YToLat(center.y), MercatorBounds::XToLon(center.x), ptLat, ptLon); } @@ -286,7 +285,7 @@ static void OnSearchResultCallback(search::Result const & res, int queryId) { // Zoom to the feature case search::Result::RESULT_FEATURE: - g_showRectF(res.GetFeatureRect()); + m_framework->ShowRect(res.GetFeatureRect()); [self searchBarCancelButtonClicked:m_searchBar]; break;