3838#import " UIViewControllerInternal.h"
3939#import " UIApplicationInternal.h"
4040
41- // TODO: Rename UIEmptyController to UIEmptyView
42- #import " UIEmptyController.h"
43-
41+ #import " UIEmptyView.h"
4442#import " UIViewInternal.h"
4543#import " UIViewControllerInternal.h"
4644#import " UIStoryboardInternal.h"
5149#import " UWP/WindowsUIXaml.h"
5250#import " UWP/WindowsFoundation.h"
5351
52+ #import " StringHelpers.h"
53+
5454#include " COMIncludes.h"
5555#include " WinString.h"
5656#include " RoApi.h"
@@ -695,7 +695,7 @@ - (instancetype)initWithCoder:(NSCoder*)coder {
695695 }
696696
697697 priv->_childViewControllers = [coder decodeObjectForKey: @" UIChildViewControllers" ];
698- // assert(nibName != nil);
698+
699699 priv->_edgesForExtendedLayout = [coder decodeIntForKey: @" UIKeyEdgesForExtendedLayout" ];
700700
701701 return self;
@@ -762,30 +762,33 @@ - (NSBundle*)nibBundle {
762762 @Status Interoperable
763763*/
764764- (instancetype )initWithNibName : (NSString *)strNib bundle : (NSBundle *)bundle {
765- if (!priv) {
766- priv = (UIViewControllerPriv*)IwCalloc (1 , sizeof (UIViewControllerPriv));
767- priv->_curOrientation = UIInterfaceOrientationPortrait;
768- priv->_contentSizeForViewInPopover .width = 320 .0f ;
769- priv->_contentSizeForViewInPopover .height = 1100 .0f ;
770- }
765+ if (self = [super init ]) {
766+ if (!priv) {
767+ priv = (UIViewControllerPriv*)IwCalloc (1 , sizeof (UIViewControllerPriv));
768+ priv->_curOrientation = UIInterfaceOrientationPortrait;
769+ priv->_contentSizeForViewInPopover .width = 320 .0f ;
770+ priv->_contentSizeForViewInPopover .height = 1100 .0f ;
771+ }
771772
772- if (bundle == nil ) {
773- priv->nibBundle = [NSBundle mainBundle ];
774- } else {
775- priv->nibBundle = bundle;
776- }
773+ if (bundle == nil ) {
774+ priv->nibBundle = [NSBundle mainBundle ];
775+ } else {
776+ priv->nibBundle = bundle;
777+ }
777778
778- if ([strNib length ] > 0 ) {
779- priv->nibName = [strNib copy ];
780- } else {
781- priv->nibName = nil ;
782- }
779+ if ([strNib length ] > 0 ) {
780+ priv->nibName . attach ( [strNib copy ]) ;
781+ } else {
782+ priv->nibName = nil ;
783+ }
783784
784- // TODO: Check to see if we have a XAML class file locally in the project
785- // 1. Find local XAML files (*.xaml.cpp) - assume the filename as the class name
786- // 2. Set priv->_xamlClass = filename (e.g. <ClassName>.xaml.cpp)
787- // 3. Set priv->_xamlPage = filename (NOT SURE IF PAGE WILL WORK WITHOUT THE CODE-BEHIND METHODS)
788- // 4. Remove initWithXAMLClass and initWithXAMLPage
785+ // Load the XAML version if found. First prepend the auto-generated XAML namespace to the XAML class name
786+ NSString * xamlClassName = [NSString stringWithFormat: @" IslandwoodAutoGenNamespace.%@ " , strNib];
787+ auto xamlType = [self _returnXamlType: xamlClassName];
788+ if (xamlType.Get () != nullptr ) {
789+ priv->_xamlClassName = xamlClassName;
790+ }
791+ }
789792
790793 return self;
791794}
@@ -794,25 +797,9 @@ - (instancetype)initWithNibName:(NSString*)strNib bundle:(NSBundle*)bundle {
794797 @Status Interoperable
795798*/
796799- (instancetype )init {
797- [super init ];
798-
799800 return [self initWithNibName: nil bundle: nil ];
800801}
801802
802- - (instancetype )initWithXAMLClass : (NSString *)className {
803- self = [self initWithNibName: nil bundle: nil ];
804- priv->_xamlClassName = className;
805-
806- return self;
807- }
808-
809- - (instancetype )initWithXAMLPage : (NSString *)pageName {
810- self = [self initWithNibName: nil bundle: nil ];
811- priv->_xamlPageName = pageName;
812-
813- return self;
814- }
815-
816803/* *
817804 @Status Interoperable
818805*/
@@ -821,7 +808,7 @@ - (void)loadView {
821808 return ;
822809 }
823810
824- if (priv->_xamlClassName != nil || priv-> _xamlPageName != nil ) {
811+ if (priv->_xamlClassName != nil ) {
825812 [self _loadXamlPage ];
826813 return ;
827814 }
@@ -919,7 +906,7 @@ - (void)loadView {
919906 frame = [self _modalPresentationFormSheetFrame ];
920907 }
921908
922- UIView* view = [[[UIEmptyController alloc ] initWithFrame: frame] autorelease ];
909+ UIView* view = [[[UIEmptyView alloc ] initWithFrame: frame] autorelease ];
923910 [view setAutoresizingMask: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
924911 [self setView: view];
925912 }
@@ -942,20 +929,6 @@ - (void)_doResizeToScreen {
942929 frame = [self _modalPresentationFormSheetFrame ];
943930 }
944931
945- /*
946- // TODO: Remove if this is no longer applicable
947- UIInterfaceOrientation curOrientation = (UIInterfaceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
948- switch (curOrientation) {
949- case UIInterfaceOrientationLandscapeLeft:
950- case UIInterfaceOrientationLandscapeRight: {
951- float temp = frame.size.width;
952- frame.size.width = frame.size.height;
953- frame.size.height = temp;
954- }
955- break;
956- }
957- */
958-
959932 [priv->view setFrame: frame];
960933 }
961934}
@@ -978,7 +951,7 @@ - (UIView*)view {
978951 frame = [self _modalPresentationFormSheetFrame ];
979952 }
980953
981- UIView* view = [[[UIEmptyController alloc ] initWithFrame: frame] autorelease ];
954+ UIView* view = [[[UIEmptyView alloc ] initWithFrame: frame] autorelease ];
982955 [self setView: view];
983956 }
984957 }
@@ -1804,8 +1777,23 @@ - (BOOL)isEditing {
18041777 return priv->_isEditing ;
18051778}
18061779
1780+ - (Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Markup::IXamlType>)_returnXamlType : (NSString *)xamlClassName {
1781+ Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Markup::IXamlMetadataProvider> xamlMetaProvider = nullptr ;
1782+ auto inspApplicationCurrent = [WXApplication.current comObj ];
1783+ inspApplicationCurrent.As (&xamlMetaProvider);
1784+
1785+ auto hClassName = Strings::NarrowToWide<HSTRING>(xamlClassName);
1786+ Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Markup::IXamlType> xamlType = nullptr ;
1787+ HRESULT hr = xamlMetaProvider->GetXamlTypeByFullName (hClassName.Get (), xamlType.GetAddressOf ());
1788+ if (SUCCEEDED (hr) && xamlType.Get () != nullptr ) {
1789+ return xamlType;
1790+ }
1791+
1792+ return nullptr ;
1793+ }
1794+
18071795- (void )_loadXamlPage {
1808- if (priv->_xamlClassName == nil && priv-> _xamlPageName == nil ) {
1796+ if (priv->_xamlClassName == nil ) {
18091797 return ;
18101798 }
18111799
@@ -1815,50 +1803,20 @@ - (void)_loadXamlPage {
18151803 }
18161804
18171805 // Create a template UIView
1818- UIView* view = [[[UIEmptyController alloc ] initWithFrame: frame] autorelease ];
1806+ UIView* view = [[[UIEmptyView alloc ] initWithFrame: frame] autorelease ];
18191807 [view setAutoresizingMask: UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
18201808 [self setView: view];
18211809
1822- // If we find a XAML class or page, attempt to load it
1823- if (priv->_xamlClassName != nil ) {
1824- Microsoft::WRL::ComPtr<IInspectable> pageObj;
1825- Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Markup::IXamlType> xamlType;
1826- Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Markup::IXamlMetadataProvider> xamlMeta;
1827- Microsoft::WRL::ComPtr<IInspectable> insp = [WXApplication.current comObj ];
1828- insp.As (&xamlMeta);
1829-
1830- uint32_t classNameLen = [priv->_xamlClassName length ];
1831- unichar * className = (unichar *)IwMalloc (sizeof (unichar ) * (classNameLen + 1 ));
1832- auto freeClassName = wil::ScopeExit ([&]() {
1833- IwFree (className);
1834- });
1835-
1836- HSTRING hClassName;
1837- auto freeHClassName = wil::ScopeExit ([&]() {
1838- WindowsDeleteString (hClassName);
1839- });
1840-
1841- // Copy the string into className and null terminate it
1842- [priv->_xamlClassName getCharacters: className];
1843- className[classNameLen] = ' \0 ' ;
1844-
1845- WindowsCreateString ((LPCWSTR)className, classNameLen, &hClassName);
1846- xamlMeta->GetXamlTypeByFullName (hClassName, &xamlType);
1847- xamlType->ActivateInstance (&pageObj);
1848-
1849- priv->_page = (WXCPage*)NSAllocateObject ([WXCPage class ], 0 , NULL );
1850- [priv->_page setComObj: pageObj];
1851- } else {
1852- // TODO: If we load a XAML page, are we bypassing the code-gen methods to trigger events (e.g. *.xaml.cpp) and forward them to an
1853- // UIView-class object
1854- priv->_page = [WXCPage make ];
1855- WFUri* location = [WFUri makeUri: [NSString stringWithFormat: @" ms-appx:///%@ " , (NSString *)priv->_xamlPageName]];
1856- [WXApplication loadComponentWithResourceLocation: priv->_page
1857- resourceLocator: location
1858- componentResourceLocation: WUXCPComponentResourceLocationApplication];
1859- }
1810+ // Activate an instance of the XAML class and its page
1811+ Microsoft::WRL::ComPtr<IInspectable> pageObj = nullptr ;
1812+ auto xamlType = [self _returnXamlType: priv->_xamlClassName];
1813+ xamlType->ActivateInstance (pageObj.GetAddressOf ());
1814+
1815+ priv->_page = (WXCPage*)NSAllocateObject ([WXCPage class ], 0 , NULL );
1816+ [priv->_page setComObj: pageObj];
18601817
1861- unsigned int propListCount;
1818+ // Walk the list of outlets and assign them to the corresponding XAML UIElement
1819+ unsigned int propListCount = 0 ;
18621820 objc_property_t * props = (objc_property_t *)class_copyPropertyList ([self class ], &propListCount);
18631821 auto freeProps = wil::ScopeExit ([&]() {
18641822 IwFree (props);
0 commit comments