void UITextField::InitFromXIB(XIBObject* obj) { UIControl::InitFromXIB(obj); _shadowOffset = obj->GetSize("IBUIShadowOffset", 0.0, 0.0f); _text = obj->GetString("IBUIText", NULL); _textColor = obj->FindMember("IBUITextColor"); _placeholder = obj->GetString("IBUIPlaceholder", NULL); _borderStyle = obj->GetInt("IBUIBorderStyle", 0); _font = (UIFont*)obj->FindMember("IBUIFontDescription"); if (!_font) { _font = (UIFont*)obj->FindMember("IBUIFont"); } XIBObject* inputTraits = obj->FindMember("IBUITextInputTraits"); if (inputTraits) { _autoCorrectionType = inputTraits->GetInt("IBUIAutocorrectionType", 0); _returnKeyType = inputTraits->GetInt("IBUIReturnKeyType", 0); } _clearsOnBeginEditing = obj->GetBool("IBUIClearsOnBeginEditing", false); if (_clearsOnBeginEditing) { _clearButtonOffset.width = 3.0f; _clearButtonOffset.height = 1.0f; } obj->_outputClassName = "UITextField"; }
XIBObject* ObjectConverter::ConverterForObject(const char* className, pugi::xml_node node) { XIBObject* ret = NULL; // NOTE: Legacy XIBs (pre-XCode5) are not really under active expansion. Developers can upgrade their XIBs to modern XIB format using ibtool IS_CONVERTER(ret, className, "IBCocoaTouchEventConnection", UIRuntimeEventConnection) IS_CONVERTER(ret, className, "IBCocoaTouchOutletConnection", UIRuntimeOutletConnection) IS_CONVERTER(ret, className, "IBCocoaTouchOutletCollectionConnection", UIRuntimeOutletCollectionConnection) IS_CONVERTER(ret, className, "IBUICustomObject", ObjectConverterSwapper) IS_CONVERTER(ret, className, "IBProxyObject", UIProxyObject) IS_CONVERTER(ret, className, "IBUIView", UIView) IS_CONVERTER(ret, className, "IBUIViewController", UIViewController) IS_CONVERTER(ret, className, "NSColor", UIColor) IS_CONVERTER(ret, className, "IBUIFontDescription", UIFont) IS_CONVERTER(ret, className, "NSFont", UIFont) IS_CONVERTER(ret, className, "IBUIButton", UIButton) IS_CONVERTER(ret, className, "NSCustomResource", UICustomResource) IS_CONVERTER(ret, className, "NSImage", UICustomResource) IS_CONVERTER(ret, className, "IBUIWindow", UIWindow) IS_CONVERTER(ret, className, "IBUIScrollView", UIScrollView) IS_CONVERTER(ret, className, "IBUITableView", UITableView) IS_CONVERTER(ret, className, "IBUINavigationBar", UINavigationBar) IS_CONVERTER(ret, className, "IBUINavigationItem", UINavigationItem) IS_CONVERTER(ret, className, "IBUIBarButtonItem", UIBarButtonItem) IS_CONVERTER(ret, className, "IBUIImageView", UIImageView) IS_CONVERTER(ret, className, "IBUILabel", UILabel) IS_CONVERTER(ret, className, "IBUIAccessibilityConfiguration", UIRuntimeAccessibilityConfiguration) IS_CONVERTER(ret, className, "IBUITableViewCell", UITableViewCell) IS_CONVERTER(ret, className, "IBUITextField", UITextField) IS_CONVERTER(ret, className, "IBUITextView", UITextView) IS_CONVERTER(ret, className, "IBUIPickerView", UIPickerView) IS_CONVERTER(ret, className, "IBUIPageControl", UIPageControl) IS_CONVERTER(ret, className, "IBUIActivityIndicatorView", UIActivityIndicatorView) IS_CONVERTER(ret, className, "IBUISwitch", UISwitch) IS_CONVERTER(ret, className, "IBUIWebView", UIWebView) IS_CONVERTER(ret, className, "IBUITabBarController", UITabBarController) IS_CONVERTER(ret, className, "IBUINavigationController", UINavigationController) IS_CONVERTER(ret, className, "IBUITableViewController", UITableViewController) IS_CONVERTER(ret, className, "IBUITabBar", UITabBar) IS_CONVERTER(ret, className, "IBUITabBarItem", UITabBarItem) IS_CONVERTER(ret, className, "IBUIToolbar", UIToolbar) IS_CONVERTER(ret, className, "IBUISegmentedControl", UISegmentedControl) IS_CONVERTER(ret, className, "IBUIDatePicker", UIDatePicker) IS_CONVERTER(ret, className, "IBUISearchBar", UISearchBar) IS_CONVERTER(ret, className, "IBMKMapView", MKMapView) IS_CONVERTER(ret, className, "IBUISearchDisplayController", UISearchDisplayController) IS_CONVERTER(ret, className, "IBUISlider", UISlider) IS_CONVERTER(ret, className, "IBNSLayoutConstraint", NSLayoutConstraint) // Stubbed implementation IS_CONVERTER(ret, className, "IBUIProgressView", UIProgressView) IS_CONVERTER(ret, className, "IBUIPongPressGestureRecognizer", UIPongPressGestureRecognizer) if (ret == NULL) { ret = new XIBObject(); } ret->ScanXIBNode(node); return ret; }
void UIViewController::InitFromStory(XIBObject *obj) { ObjectConverterSwapper::InitFromStory(obj); _view = (UIView *) obj->FindMember("view"); if ( _connections ) { for ( int i = 0; i < _connections->count(); i ++ ) { XIBObject *curObj = _connections->objectAtIndex(i); if ( strcmp(curObj->_className, "segue") == 0 ) { const char *pDest = curObj->getAttrib("destination"); const char *pKind = curObj->getAttrib("kind"); XIBObject *newController = findReference(pDest); if ( newController && strcmp(pKind, "relationship") == 0 ) { ((UIViewController *) newController)->_parentViewController = this; _childViewControllers->AddMember(NULL, newController); _viewControllers->AddMember(NULL, newController); } } } } _tabBarItem = (UITabBarItem *) FindMember("tabBarItem"); _navigationItem = (UINavigationItem *) obj->FindMember("navigationItem"); _outputClassName = "UIViewController"; }
XIBObject *ObjectConverter::ConverterForStoryObject(const char *className, pugi::xml_node node) { XIBObject *ret = NULL; IS_CONVERTER(ret, className, "objects", XIBArray) IS_CONVERTER(ret, className, "subviews", XIBArray) IS_CONVERTER(ret, className, "constraints", XIBArray) IS_CONVERTER(ret, className, "variation", XIBVariation) IS_CONVERTER(ret, className, "items", XIBArray) IS_CONVERTER(ret, className, "connections", XIBArray) IS_CONVERTER(ret, className, "string", XIBObjectString) IS_CONVERTER(ret, className, "viewController", UIViewController) IS_CONVERTER(ret, className, "placeholder", UIProxyObject) IS_CONVERTER(ret, className, "tabBarController", UITabBarController) IS_CONVERTER(ret, className, "navigationItem", UINavigationItem) IS_CONVERTER(ret, className, "navigationBar", UINavigationBar) IS_CONVERTER(ret, className, "navigationController", UINavigationController) IS_CONVERTER(ret, className, "tabBarItem", UITabBarItem) IS_CONVERTER(ret, className, "tabBar", UITabBar) IS_CONVERTER(ret, className, "view", UIView) IS_CONVERTER(ret, className, "scrollView", UIScrollView) IS_CONVERTER(ret, className, "label", UILabel) IS_CONVERTER(ret, className, "toolbar", UIToolbar) IS_CONVERTER(ret, className, "color", UIColor) IS_CONVERTER(ret, className, "barButtonItem", UIBarButtonItem) IS_CONVERTER(ret, className, "outlet", UIRuntimeOutletConnection) IS_CONVERTER(ret, className, "segue", UIStoryboardSegue) IS_CONVERTER(ret, className, "fontDescription", UIFont) IS_CONVERTER(ret, className, "tableViewController", UITableViewController) IS_CONVERTER(ret, className, "tableView", UITableView) IS_CONVERTER(ret, className, "textField", UITextField) IS_CONVERTER(ret, className, "textView", UITextView) IS_CONVERTER(ret, className, "button", UIButton) IS_CONVERTER(ret, className, "webView", UIWebView) IS_CONVERTER(ret, className, "searchBar", UISearchBar) IS_CONVERTER(ret, className, "searchDisplayController", UISearchDisplayController) IS_CONVERTER(ret, className, "activityIndicatorView", UIActivityIndicatorView) IS_CONVERTER(ret, className, "imageView", UIImageView) IS_CONVERTER(ret, className, "action", UIRuntimeEventConnection) IS_CONVERTER(ret, className, "switch", UISwitch) IS_CONVERTER(ret, className, "constraint", NSLayoutConstraint) IS_CONVERTER(ret, className, "layoutGuides", XIBVariation) IS_CONVERTER(ret, className, "viewControllerLayoutGuide", _UILayoutGuide) IS_CONVERTER(ret, className, "datePicker", UIDatePicker) IS_CONVERTER(ret, className, "slider", UISlider) if ( ret == NULL ) { #ifdef _DEBUG printf("Unrecognized tag <%s>\n", className); #endif ret = new XIBObject(); } ret->ScanStoryObjects(node); return ret; }
XIBObject *ObjectConverter::ConverterForObject(const char *className, pugi::xml_node node) { XIBObject *ret = NULL; IS_CONVERTER(ret, className, "IBCocoaTouchEventConnection", UIRuntimeEventConnection) IS_CONVERTER(ret, className, "IBCocoaTouchOutletConnection", UIRuntimeOutletConnection) IS_CONVERTER(ret, className, "IBCocoaTouchOutletCollectionConnection", UIRuntimeOutletCollectionConnection) IS_CONVERTER(ret, className, "IBUICustomObject", ObjectConverterSwapper) IS_CONVERTER(ret, className, "IBProxyObject", UIProxyObject) IS_CONVERTER(ret, className, "IBUIView", UIView) IS_CONVERTER(ret, className, "IBUIViewController", UIViewController) IS_CONVERTER(ret, className, "NSColor", UIColor) IS_CONVERTER(ret, className, "IBUIFontDescription", UIFont) IS_CONVERTER(ret, className, "NSFont", UIFont) IS_CONVERTER(ret, className, "IBUIButton", UIButton) IS_CONVERTER(ret, className, "NSCustomResource", UICustomResource) IS_CONVERTER(ret, className, "NSImage", UICustomResource) IS_CONVERTER(ret, className, "IBUIWindow", UIWindow) IS_CONVERTER(ret, className, "IBUIScrollView", UIScrollView) IS_CONVERTER(ret, className, "IBUITableView", UITableView) IS_CONVERTER(ret, className, "IBUINavigationBar", UINavigationBar) IS_CONVERTER(ret, className, "IBUINavigationItem", UINavigationItem) IS_CONVERTER(ret, className, "IBUIBarButtonItem", UIBarButtonItem) IS_CONVERTER(ret, className, "IBUIImageView", UIImageView) IS_CONVERTER(ret, className, "IBUILabel", UILabel) IS_CONVERTER(ret, className, "IBUIAccessibilityConfiguration", UIRuntimeAccessibilityConfiguration) IS_CONVERTER(ret, className, "IBUITableViewCell", UITableViewCell) IS_CONVERTER(ret, className, "IBUITextField", UITextField) IS_CONVERTER(ret, className, "IBUITextView", UITextView) IS_CONVERTER(ret, className, "IBUIPickerView", UIPickerView) IS_CONVERTER(ret, className, "IBUIPageControl", UIPageControl) IS_CONVERTER(ret, className, "IBUIActivityIndicatorView", UIActivityIndicatorView) IS_CONVERTER(ret, className, "IBUISwitch", UISwitch) IS_CONVERTER(ret, className, "IBUIWebView", UIWebView) IS_CONVERTER(ret, className, "IBUITabBarController", UITabBarController) IS_CONVERTER(ret, className, "IBUINavigationController", UINavigationController) IS_CONVERTER(ret, className, "IBUITableViewController", UITableViewController) IS_CONVERTER(ret, className, "IBUITabBar", UITabBar) IS_CONVERTER(ret, className, "IBUITabBarItem", UITabBarItem) IS_CONVERTER(ret, className, "IBUIToolbar", UIToolbar) IS_CONVERTER(ret, className, "IBUISegmentedControl", UISegmentedControl) IS_CONVERTER(ret, className, "IBUIDatePicker", UIDatePicker) IS_CONVERTER(ret, className, "IBUISearchBar", UISearchBar) IS_CONVERTER(ret, className, "IBMKMapView", MKMapView) IS_CONVERTER(ret, className, "IBUISearchDisplayController", UISearchDisplayController) IS_CONVERTER(ret, className, "IBUISlider", UISlider) IS_CONVERTER(ret, className, "IBNSLayoutConstraint", NSLayoutConstraint) if ( ret == NULL ) { ret = new XIBObject(); } ret->ScanXIBNode(node); return ret; }
void NIBWriter::ExportController(const char *controllerId) { char szFilename[255]; XIBObject* controller = XIBObject::findReference(controllerId); UIViewController* uiViewController = dynamic_cast<UIViewController*>(controller); if (!uiViewController) { //object isn't really a controller printf("Object %s is not a controller\n", controller->stringValue()); return; } const char* controllerIdentifier = uiViewController->_storyboardIdentifier; if (controllerIdentifier == NULL) { //not all viewcontrollers will have a storyboard identifier. If they don't use the controller Id for the key. controllerIdentifier = controllerId; } // Check if we've already written out the controller if (_g_exportedControllers.find(controllerId) != _g_exportedControllers.end()) { return; } sprintf(szFilename, "%s.nib", controllerIdentifier); _g_exportedControllers[controllerIdentifier] = controllerIdentifier; XIBArray *objects = (XIBArray *) controller->_parent; printf("Writing %s\n", GetOutputFilename(szFilename).c_str()); FILE *fpOut = fopen(GetOutputFilename(szFilename).c_str(), "wb"); NIBWriter *writer = new NIBWriter(fpOut, NULL, NULL); XIBObject *firstResponderProxy = writer->AddProxy("IBFirstResponder"); XIBObject *ownerProxy = writer->AddProxy("IBFilesOwner"); XIBObject *storyboard = writer->AddProxy("UIStoryboardPlaceholder"); XIBArray *arr = (XIBArray *) objects; for ( int i = 0; i < arr->count(); i ++ ) { XIBObject *curObj = arr->objectAtIndex(i); writer->ExportObject(curObj); if ( curObj->getAttrib("sceneMemberID") ) { if ( strcmp(curObj->getAttrib("sceneMemberID"), "viewController") == 0 ) { writer->AddOutletConnection(ownerProxy, curObj, "sceneViewController"); } } } writer->WriteObjects(); fclose(fpOut); }
void UITextView::InitFromXIB(XIBObject *obj) { UIScrollView::InitFromXIB(obj); _shadowOffset = obj->GetSize("IBUIShadowOffset", 0, 0.0f); _text = obj->GetString("IBUIText", NULL); _textColor = obj->FindMember("IBUITextColor"); _font = (UIFont *) obj->FindMember("IBUIFontDescription"); _editable = obj->GetBool("IBUIEditable", true); _dataDetectorTypes = obj->GetInt("IBUIDataDetectorTypes", 0); if ( !_font ) _font = (UIFont *) obj->FindMember("IBUIFont"); _textAlignment = 0; XIBObject *inputTraits = obj->FindMember("IBUITextInputTraits"); if ( inputTraits ) { _autoCorrectionType = inputTraits->GetInt("IBUIAutocorrectionType", 0); _returnKeyType = inputTraits->GetInt("IBUIReturnKeyType", 0); } obj->_outputClassName = "UITextView"; }
void NIBWriter::ExportController(const char *controllerId) { static std::vector<char *> _exportedControllers; for ( std::vector<char *>::iterator cur = _exportedControllers.begin(); cur != _exportedControllers.end(); cur ++ ) { if ( strcmp(*cur, controllerId) == 0 ) { return; } } _exportedControllers.push_back(strdup(controllerId)); XIBObject *controller = XIBObject::findReference(controllerId); XIBArray *objects = (XIBArray *) controller->_parent; char szFilename[255]; sprintf(szFilename, "UIViewController-%s.nib", controllerId); printf("Writing %s\n", szFilename); FILE *fpOut = fopen(szFilename, "wb"); NIBWriter *writer = new NIBWriter(fpOut, NULL, NULL); XIBObject *firstResponderProxy = writer->AddProxy("IBFirstResponder"); XIBObject *ownerProxy = writer->AddProxy("IBFilesOwner"); XIBObject *storyboard = writer->AddProxy("UIStoryboardPlaceholder"); XIBArray *arr = (XIBArray *) objects; for ( int i = 0; i < arr->count(); i ++ ) { XIBObject *curObj = arr->objectAtIndex(i); writer->ExportObject(curObj); if ( curObj->getAttrib("sceneMemberID") ) { if ( strcmp(curObj->getAttrib("sceneMemberID"), "viewController") == 0 ) { writer->AddOutletConnection(ownerProxy, curObj, "sceneViewController"); } } } writer->WriteObjects(); fclose(fpOut); }
XIBObject *GetButtonContent(NIBWriter *writer, XIBObject *obj, char *mode) { XIBObject *buttonContent = new XIBObject(); buttonContent->_className = "UIButtonContent"; buttonContent->_outputClassName = "UIButtonContent"; buttonContent->_needsConversion = false; char szName[255]; XIBObject *findObj; sprintf(szName, "IBUI%sTitle", mode); findObj = obj->FindMember(szName); if ( findObj ) { buttonContent->AddOutputMember(writer, "UITitle", findObj); } sprintf(szName, "IBUI%sImage", mode); findObj = obj->FindMember(szName); if ( findObj ) { buttonContent->AddOutputMember(writer, "UIImage", findObj); } sprintf(szName, "IBUI%sBackgroundImage", mode); findObj = obj->FindMember(szName); if ( findObj ) { buttonContent->AddOutputMember(writer, "UIBackgroundImage", findObj); } sprintf(szName, "IBUI%sTitleShadowColor", mode); findObj = obj->FindMember(szName); if ( findObj ) { buttonContent->AddOutputMember(writer, "UIShadowColor", findObj); } sprintf(szName, "IBUI%sTitleColor", mode); findObj = obj->FindMember(szName); if ( findObj ) { buttonContent->AddOutputMember(writer, "UITitleColor", findObj); } else { if ( strcmp(mode, "Normal") != 0 && buttonContent->_outputMembers.size() > 0 ) { //findObj = obj->FindMember("IBUINormalTitleColor"); //buttonContent->AddOutputMember(writer, "UITitleColor", findObj); } else if ( strcmp(mode, "Normal") == 0 ) { UIColor *color = new UIColor(4, 4, 0.0f, 0.0f, 0.0f, 0.0f, "whiteColor"); buttonContent->AddOutputMember(writer, "UITitleColor", color->CreateObject(writer)); } } return buttonContent; }
static XIBObject* GetButtonContentStoryboard(NIBWriter* writer, XIBObject* obj, char* mode) { XIBObject* buttonContent = new XIBObject(); buttonContent->_className = "UIButtonContent"; buttonContent->_outputClassName = "UIButtonContent"; buttonContent->_needsConversion = false; obj = obj->FindMemberAndHandle(mode); if (!obj) { return buttonContent; } if (obj->getAttrib("image") != NULL) { UICustomResource* image = new UICustomResource(); image->_imageName = obj->getAttrAndHandle("image"); buttonContent->AddOutputMember(writer, "UIImage", image); } if (obj->getAttrib("backgroundImage") != NULL) { UICustomResource* image = new UICustomResource(); image->_imageName = obj->getAttrAndHandle("backgroundImage"); buttonContent->AddOutputMember(writer, "UIBackgroundImage", image); } if (obj->getAttrib("title") != NULL) { buttonContent->AddOutputMember(writer, "UITitle", new XIBObjectString(obj->getAttrAndHandle("title"))); } if (obj->FindMember("titleShadowColor") != NULL) { buttonContent->AddOutputMember(writer, "UIShadowColor", obj->FindMemberAndHandle("titleShadowColor")); } if (obj->FindMember("titleColor") != NULL) { buttonContent->AddOutputMember(writer, "UITitleColor", obj->FindMemberAndHandle("titleColor")); } else if (strcmp(mode, "normal") == 0) { UIColor* color = new UIColor(0, 4, 0.0f, 0.47f, 0.84f, 1.0f, NULL); color->_isStory = true; buttonContent->AddOutputMember(writer, "UITitleColor", color); } return buttonContent; }
void ConvertXIBToNib(FILE* fpOut, pugi::xml_document& doc) { pugi::xml_node dataNode = doc.first_element_by_path("/archive/data"); XIBObject* root = new XIBObject(); root->ScanXIBNode(dataNode); XIBObject::ParseAllXIBMembers(); XIBObject* Objects = root->FindMember("IBDocument.Objects"); XIBObject* objectRecords = Objects->FindMember("objectRecords"); XIBDictionary* properties = (XIBDictionary*)Objects->FindMember("flattenedProperties"); XIBObject* orderedObjects = objectRecords->FindMember("orderedObjects"); // Go through each ordered object to find replacements for (memberList::iterator cur = orderedObjects->_members.begin(); cur != orderedObjects->_members.end(); cur++) { XIBMember* curMember = *cur; XIBObject* curObject = curMember->_obj; if (strcmp(curObject->ClassName(), "IBObjectRecord") == 0) { XIBObject* obj = curObject->FindMember("object"); if (obj) { XIBObject* objectId = curObject->FindMember("objectID"); if (!objectId) { objectId = curObject->FindMember("id"); } int objId = objectId->intValue(); // Attempt to find any associated custom class name char szPropName[255]; sprintf(szPropName, "%d.CustomClassName", objId); const char* pClassName = obj->ClassName(); XIBObject* customName = properties->ObjectForKey(szPropName); if (customName) { const char* pCustomName = customName->stringValue(); obj->SetSwappedClassName(pCustomName); } for (memberList::iterator prop = properties->_members.begin(); prop != properties->_members.end(); prop++) { char szMeta[255]; sprintf(szMeta, "%d.", objId); if (strncmp(szMeta, (*prop)->_name, strlen(szMeta)) == 0) { obj->AddMember(&(*prop)->_name[strlen(szMeta)], (*prop)->_obj); } } } } } // Create connections list XIBArray* connections = new XIBArray(); XIBObject* connectionrecords = Objects->FindMember("connectionRecords"); for (memberList::iterator cur = connectionrecords->_members.begin(); cur != connectionrecords->_members.end(); cur++) { XIBMember* curMember = *cur; XIBObject* curObject = curMember->_obj; if (strcmp(curObject->ClassName(), "IBConnectionRecord") == 0) { XIBObject* obj = curObject->FindMember("connection"); if (obj) { connections->AddMember(NULL, obj); } } } // Sort connection records alphabetically using stable, uh, bubble sort for (;;) { bool didSwap = false; for (memberList::iterator cur = connections->_members.begin(); cur != connections->_members.end(); cur++) { if ((cur + 1) == connections->_members.end()) break; XIBMember* curMember = (*cur); XIBMember* nextMember = (*(cur + 1)); if (curMember->_name != NULL) continue; // Event connections first if (strcmp(curMember->_obj->_className, "IBCocoaTouchOutletConnection") == 0 && strcmp(nextMember->_obj->_className, "IBCocoaTouchEventConnection") == 0) { *cur = nextMember; *(cur + 1) = curMember; didSwap = true; continue; } if (strcmp(curMember->_obj->_className, nextMember->_obj->_className) == 0) { const char* label1 = curMember->_obj->FindMember("label")->stringValue(); const char* label2 = nextMember->_obj->FindMember("label")->stringValue(); if (strcmp(label1, label2) > 0) { *cur = nextMember; *(cur + 1) = curMember; didSwap = true; } } } if (!didSwap) break; } // Construct root object XIBObject* rootObjects = root->FindMember("IBDocument.RootObjects"); rootObjects->_className = "NSArray"; connections->_className = "NSArray"; XIBArray* allObjects = new XIBArray(); XIBArray* accessibilityObjects = new XIBAccessibilityArray(); XIBArray* visibleWindows = new XIBArray(); XIBObject* nibRoot = new XIBArray(); nibRoot->_className = "NSObject"; nibRoot->_members.clear(); nibRoot->AddMember("UINibTopLevelObjectsKey", rootObjects); nibRoot->AddMember("UINibObjectsKey", allObjects); nibRoot->AddMember("UINibConnectionsKey", connections); nibRoot->AddMember("UINibVisibleWindowsKey", visibleWindows); nibRoot->AddMember("UINibAccessibilityConfigurationsKey", accessibilityObjects); nibRoot->AddMember("UINibKeyValuePairsKey", new XIBArray()); NIBWriter* writer = new NIBWriter(fpOut); writer->_allUIObjects = allObjects; writer->_visibleWindows = visibleWindows; writer->AddOutputObject(nibRoot); writer->WriteData(); }
XIBObject* ObjectConverter::ConverterForStoryObject(const char* className, pugi::xml_node node) { XIBObject* ret = NULL; IS_CONVERTER(ret, className, "objects", XIBArray) IS_CONVERTER(ret, className, "subviews", XIBArray) IS_CONVERTER(ret, className, "constraints", XIBArray) IS_CONVERTER(ret, className, "variation", XIBVariation) IS_CONVERTER(ret, className, "items", XIBArray) IS_CONVERTER(ret, className, "connections", XIBArray) IS_CONVERTER(ret, className, "string", XIBObjectString) IS_CONVERTER(ret, className, "viewController", UIViewController) IS_CONVERTER(ret, className, "splitViewController", UIViewController) IS_CONVERTER(ret, className, "placeholder", UIProxyObject) IS_CONVERTER(ret, className, "tabBarController", UITabBarController) IS_CONVERTER(ret, className, "navigationItem", UINavigationItem) IS_CONVERTER(ret, className, "navigationBar", UINavigationBar) IS_CONVERTER(ret, className, "navigationController", UINavigationController) IS_CONVERTER(ret, className, "tabBarItem", UITabBarItem) IS_CONVERTER(ret, className, "tabBar", UITabBar) IS_CONVERTER(ret, className, "view", UIView) IS_CONVERTER(ret, className, "scrollView", UIScrollView) IS_CONVERTER(ret, className, "label", UILabel) IS_CONVERTER(ret, className, "toolbar", UIToolbar) IS_CONVERTER(ret, className, "color", UIColor) IS_CONVERTER(ret, className, "barButtonItem", UIBarButtonItem) IS_CONVERTER(ret, className, "outlet", UIRuntimeOutletConnection) IS_CONVERTER(ret, className, "outletCollection", UIRuntimeOutletCollectionConnection) IS_CONVERTER(ret, className, "segue", UIStoryboardSegue) IS_CONVERTER(ret, className, "fontDescription", UIFont) IS_CONVERTER(ret, className, "tableViewController", UITableViewController) IS_CONVERTER(ret, className, "tableView", UITableView) IS_CONVERTER(ret, className, "tableViewCell", UITableViewCell) IS_CONVERTER(ret, className, "tableViewCellContentView", UITableViewCellContentView) IS_CONVERTER(ret, className, "textField", UITextField) IS_CONVERTER(ret, className, "textView", UITextView) IS_CONVERTER(ret, className, "button", UIButton) IS_CONVERTER(ret, className, "webView", UIWebView) IS_CONVERTER(ret, className, "searchBar", UISearchBar) IS_CONVERTER(ret, className, "searchDisplayController", UISearchDisplayController) IS_CONVERTER(ret, className, "activityIndicatorView", UIActivityIndicatorView) IS_CONVERTER(ret, className, "imageView", UIImageView) IS_CONVERTER(ret, className, "action", UIRuntimeEventConnection) IS_CONVERTER(ret, className, "switch", UISwitch) IS_CONVERTER(ret, className, "constraint", NSLayoutConstraint) IS_CONVERTER(ret, className, "layoutGuides", XIBVariation) IS_CONVERTER(ret, className, "viewControllerLayoutGuide", _UILayoutGuide) IS_CONVERTER(ret, className, "datePicker", UIDatePicker) IS_CONVERTER(ret, className, "slider", UISlider) IS_CONVERTER(ret, className, "collectionReusableView", UICollectionReusableView) IS_CONVERTER(ret, className, "collectionViewCell", UICollectionViewCell) IS_CONVERTER(ret, className, "collectionView", UICollectionView) IS_CONVERTER(ret, className, "collectionViewController", UICollectionViewController) IS_CONVERTER(ret, className, "pickerView", UIPickerView) IS_CONVERTER(ret, className, "segmentedControl", UISegmentedControl) IS_CONVERTER(ret, className, "stepper", UIStepper) IS_CONVERTER(ret, className, "panGestureRecognizer", UIPanGestureRecognizer) IS_CONVERTER(ret, className, "swipeGestureRecognizer", UISwipeGestureRecognizer) IS_CONVERTER(ret, className, "tapGestureRecognizer", UITapGestureRecognizer) IS_CONVERTER(ret, className, "window", UIWindow) // Stubbed mapping - full functionality is not provided but these stubs will unblock the import process IS_CONVERTER(ret, className, "pageControl", UIPageControl) IS_CONVERTER(ret, className, "mapView", MKMapView) IS_CONVERTER(ret, className, "stackView", UIStackView) IS_CONVERTER(ret, className, "progressView", UIProgressView) IS_CONVERTER(ret, className, "pongPressGestureRecognizer", UIPongPressGestureRecognizer) IS_CONVERTER(ret, className, "customObject", ObjectConverterSwapper) if (ret == NULL) { TELEMETRY_EVENT_DATA(L"UnRecognizedTag", className); ret = new XIBObject(); } ret->ScanStoryObjects(node); return ret; }
void UIView::InitFromStory(XIBObject *obj) { ObjectConverterSwapper::InitFromStory(obj); _subviews = (XIBArray *) obj->FindMemberClass("subviews"); if ( !_subviews ) _subviews = new XIBArray(); _constraints = (XIBArray *)obj->FindMemberClass("constraints"); if (!_constraints) _constraints = new XIBArray(); if ( getAttrib("opaque") ) { const char *pVal = getAttrib("opaque"); if ( strcmp(pVal, "NO") == 0 ) _opaque = false; } if ( getAttrib("multipleTouchEnabled") ) { if ( strcmp(getAttrib("multipleTouchEnabled"), "YES") == 0 ) _multipleTouchEnabled = true; } if ( getAttrib("clipsSubviews") ) { if ( strcmp(getAttrib("clipsSubviews"), "YES") == 0 ) _clipsToBounds = true; } if ( getAttrib("userInteractionEnabled") ) { if ( strcmp(getAttrib("userInteractionEnabled"), "NO") == 0 ) _userInteractionDisabled = true; } if ( getAttrib("clearsContextBeforeDrawing") ) { if ( strcmp(getAttrib("clearsContextBeforeDrawing"), "NO") == 0 ) _clearsContextBeforeDrawing = false; } if ( getAttrib("contentMode") ) { const char *mode = getAttrib("contentMode"); if ( strcmp(mode, "left") == 0 ) { _contentMode = UIViewContentModeLeft; } else if ( strcmp(mode, "scaleToFill") == 0 ) { _contentMode = UIViewContentModeScaleToFill; } else if ( strcmp(mode, "center") == 0 ) { _contentMode = UIViewContentModeCenter; } else if ( strcmp(mode, "redraw") == 0 ) { _contentMode = UIViewContentModeRedraw; } else if ( strcmp(mode, "scaleAspectFill") == 0 ) { _contentMode = UIViewContentModeScaleAspectFill; } else if ( strcmp(mode, "scaleAspectFit") == 0 ) { _contentMode = UIViewContentModeScaleAspectFit; } else { assert(0); } } if ( getAttrib("hidden") ) { if ( strcmp(getAttrib("hidden"), "YES") == 0 ) _hidden = true; } XIBObject *frameRect = FindMember("frame"); if ( frameRect ) { _bounds.x = 0; _bounds.y = 0; _bounds.width = strtod(frameRect->getAttrib("width"), NULL); _bounds.height = strtod(frameRect->getAttrib("height"), NULL); _center.x = strtod(frameRect->getAttrib("x"), NULL); _center.y = strtod(frameRect->getAttrib("y"), NULL); _center.x += _bounds.width / 2.0f; _center.y += _bounds.height / 2.0f; } XIBObject *resizeMask = FindMember("autoresizingMask"); if ( resizeMask ) { if ( resizeMask->getAttrib("widthSizable") ) _autoresizingMask |= (int) UIViewAutoresizingFlexibleWidth; if ( resizeMask->getAttrib("heightSizable") ) _autoresizingMask |= (int) UIViewAutoresizingFlexibleHeight; if ( resizeMask->getAttrib("flexibleMinX") ) _autoresizingMask |= (int) UIViewAutoresizingFlexibleLeftMargin; if ( resizeMask->getAttrib("flexibleMaxX") ) _autoresizingMask |= (int) UIViewAutoresizingFlexibleRightMargin; if ( resizeMask->getAttrib("flexibleMinY") ) _autoresizingMask |= (int) UIViewAutoresizingFlexibleTopMargin; if ( resizeMask->getAttrib("flexibleMaxY") ) _autoresizingMask |= (int) UIViewAutoresizingFlexibleBottomMargin; } _backgroundColor = (UIColor *) FindMember("backgroundColor"); if (getAttrib("translatesAutoresizingMaskIntoConstraints")) { if (strcmp(getAttrib("translatesAutoresizingMaskIntoConstraints"), "NO") == 0) _translatesAutoresizeToConstraints = false; } _outputClassName = "UIView"; }
void NIBWriter::WriteObjects() { XIBObject *nibRoot = new XIBArray(); nibRoot->_className = "NSObject"; nibRoot->_members.clear(); nibRoot->AddMember("UINibTopLevelObjectsKey", _topObjects); nibRoot->AddMember("UINibObjectsKey", _allUIObjects); nibRoot->AddMember("UINibConnectionsKey", _connections); nibRoot->AddMember("UINibVisibleWindowsKey", _visibleWindows); nibRoot->AddMember("UINibAccessibilityConfigurationsKey", _accessibilityObjects); nibRoot->AddMember("UINibKeyValuePairsKey", new XIBArray()); AddOutputObject(nibRoot); // Sort connection records alphabetically using stable, uh, bubble sort for ( ;; ) { bool didSwap = false; for ( memberList::iterator cur = _connections->_outputMembers.begin(); cur != _connections->_outputMembers.end(); cur ++ ) { if ( (cur + 1) == _connections->_outputMembers.end() ) break; XIBMember *curMember = (*cur); XIBMember *nextMember = (*(cur + 1)); if ( strcmp(curMember->_name, "UINibEncoderEmptyKey") != 0 ) continue; // Event connections first if ( strcmp(curMember->_obj->_className, "UIRuntimeOutletConnection") == 0 && strcmp(nextMember->_obj->_className, "UIRuntimeEventConnection") == 0 ) { *cur = nextMember; *(cur + 1) = curMember; didSwap = true; continue; } if ( strcmp(curMember->_obj->_className, nextMember->_obj->_className) == 0 ) { const char *label1, *label2; if ( strcmp(curMember->_obj->_className, "UIRuntimeEventConnection") == 0 ) { UIRuntimeEventConnection *conn1 = (UIRuntimeEventConnection *) curMember->_obj; UIRuntimeEventConnection *conn2 = (UIRuntimeEventConnection *) nextMember->_obj; label1 = conn1->_label; label2 = conn2->_label; } else { UIRuntimeOutletConnection *conn1 = (UIRuntimeOutletConnection *) curMember->_obj; UIRuntimeOutletConnection *conn2 = (UIRuntimeOutletConnection *) nextMember->_obj; label1 = conn1->_label; label2 = conn2->_label; } if ( strcmp(label1, label2) > 0 ) { *cur = nextMember; *(cur + 1) = curMember; didSwap = true; } } } if ( !didSwap ) break; } WriteData(); }