Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
66075ce
GCC/MINGW: non compatible fixes to make it compilable
dkimitsa Nov 22, 2017
3fdf411
fixed: nil object type
dkimitsa Nov 22, 2017
90da0a6
fixed: written proper NIB header values
dkimitsa Nov 22, 2017
c5908ff
fixed: class entry and class name output to nib
dkimitsa Nov 22, 2017
804ea0d
fixed2: connections now handled in one place: ObjectConverter otherwi…
dkimitsa Nov 22, 2017
f497bf8
fixed: structs migrated from float to double as in recent nib
dkimitsa Nov 22, 2017
240739d
fixed: wrong limit check when writing integers
dkimitsa Nov 22, 2017
9188701
fixed: UIColor copy creation (instead of copy self was modified)
dkimitsa Nov 22, 2017
9e50b65
added: support for key-value pairs and user defined attributes
dkimitsa Nov 22, 2017
cbcb3bb
UIColor: added NSColorSpace and friends required by iOS to accept color
dkimitsa Nov 28, 2017
f9a3299
Storyboard segue: added limited support for all types of segue, fixed…
dkimitsa Nov 29, 2017
4a84ff0
Massive changes:
dkimitsa Feb 2, 2018
60265b2
Work on warnings as there was many of these in XCode which was very d…
dkimitsa Feb 2, 2018
6cdaceb
NSLayoutConstraint fixed to use Double values as apple doesn't accept…
dkimitsa Feb 6, 2018
be686f4
Added UIAdjustsFontSizeToFit=true when there is any adjustment as oth…
dkimitsa Feb 6, 2018
73bd004
UILineBreakMode attribute reworked in UILabel, also it was added to U…
dkimitsa Feb 6, 2018
974b17b
fixed bug: multiplier was not initialized in constraint and was corru…
dkimitsa Feb 6, 2018
37a372f
fixed priority read out for NSLayoutConstraint
dkimitsa Feb 6, 2018
4ff2f38
fixed UITableViewCell: it wasn't properly read for storyboard parsing
dkimitsa Feb 6, 2018
bc8909d
NSLayoutConstraint -- relation was not parsed
dkimitsa Feb 7, 2018
2e7297b
Changes to skip NSLayoutConstaint marked as placeholder
dkimitsa Feb 7, 2018
b7a3e13
fixed hugging priority and compression resistance as these are handle…
dkimitsa Feb 7, 2018
53562af
NSLayoutConstraint: fixed multiplier parsing if it present in form of…
dkimitsa Feb 8, 2018
80f3104
UIButton: added support for Tint color
dkimitsa Feb 8, 2018
b1fabf6
added support for UITextInputTraits which enables lot of configuratio…
dkimitsa Feb 8, 2018
e66e96a
optimized structures (UIRect etc), UIEdgeInsets moved to common location
dkimitsa Feb 8, 2018
075905b
UITableView: rowHeight is now being read out
dkimitsa Feb 8, 2018
09691b7
added UICollectionViewFlowLayout which is required for UICollectionVi…
dkimitsa Feb 8, 2018
5c1cf8b
UIPoint is updated with isValid method, also UIView changed to proces…
dkimitsa Feb 9, 2018
fca4ea4
UISegmentedControl fixed
dkimitsa Feb 9, 2018
533e2e3
Fixed UIView.contentStretch was not parsed from xib
dkimitsa Feb 9, 2018
d96c7ce
UIControl fixed to parse enabled/selected/highlighted attributes
dkimitsa Feb 13, 2018
32aea2c
UISwitch: added parsing of on/off state
dkimitsa Feb 13, 2018
c0996e7
included math.h to fix INFINITY was not declared on Linux
dkimitsa Feb 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 20 additions & 71 deletions tools/vsimporter/xib2nib/src/NIBWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
#include "UIProxyObject.h"
#include <assert.h>
#include <map>
#include "UIViewController.h"
#include "..\WBITelemetry\WBITelemetry.h"
#include "../WBITelemetry/WBITelemetry.h"

int curPlaceholder = 1;

Expand Down Expand Up @@ -79,7 +78,8 @@ XIBObject* NIBWriter::AddOutputObject(XIBObject* pObj) {
}

typedef struct {
int _a, _b;
int _numHeaders;
int _sizeDw;
int _numObjects; // 2
int _objectsOffset; // 3
int _numKeyNames; // 4
Expand Down Expand Up @@ -129,6 +129,8 @@ NIBWriter::NIBWriter(FILE* out) {
_baseObject = NULL;
_connections = NULL;
_visibleWindows = NULL;
_minimumDeploymentTarget = DEPLOYMENT_TARGET_RECENT;
_wasLimitedByDeplymentTarget = false;
fpOut = out;
}

Expand All @@ -138,6 +140,8 @@ NIBWriter::NIBWriter(FILE* out, XIBDictionary* externalReferences, XIBObject* ba
_baseObject = NULL;
_connections = NULL;
_visibleWindows = NULL;
_minimumDeploymentTarget = DEPLOYMENT_TARGET_RECENT;
_wasLimitedByDeplymentTarget = false;
fpOut = out;

curPlaceholder = 1;
Expand All @@ -147,6 +151,7 @@ NIBWriter::NIBWriter(FILE* out, XIBDictionary* externalReferences, XIBObject* ba
_connections = new XIBArray();
_topObjects = new XIBArray();
_visibleWindows = new XIBArray();
_keyValuePairs = new XIBArray();
_accessibilityObjects = new XIBAccessibilityArray();
}

Expand All @@ -165,7 +170,7 @@ void NIBWriter::WriteObjects() {
nibRoot->AddMember("UINibConnectionsKey", _connections);
nibRoot->AddMember("UINibVisibleWindowsKey", _visibleWindows);
nibRoot->AddMember("UINibAccessibilityConfigurationsKey", _accessibilityObjects);
nibRoot->AddMember("UINibKeyValuePairsKey", new XIBArray());
nibRoot->AddMember("UINibKeyValuePairsKey", _keyValuePairs);

AddOutputObject(nibRoot);
// Sort connection records alphabetically using stable, uh, bubble sort
Expand Down Expand Up @@ -233,6 +238,10 @@ void NIBWriter::AddOutletConnection(XIBObject* src, XIBObject* dst, char* propNa
}

XIBObject* NIBWriter::AddProxy(char* propName) {
XIBObject* existingProxy = NIBWriter::FindProxy(propName);
if (existingProxy)
return existingProxy;

UIProxyObject* newProxy = new UIProxyObject();
newProxy->_identifier = strdup(propName);
_allUIObjects->AddMember(NULL, newProxy);
Expand Down Expand Up @@ -290,67 +299,6 @@ XIBObject* NIBWriter::GetProxyFor(XIBObject* obj) {
return newProxy;
}

std::map<std::string, std::string> _g_exportedControllers;

void NIBWriter::ExportAllControllers() {
for (const char* cur : UIViewController::_viewControllerNames) {
ExportController(cur);
}
}

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 NIBWriter::WriteData() {
fwrite("NIBArchive", 10, 1, fpOut);
Expand Down Expand Up @@ -379,11 +327,9 @@ void NIBWriter::WriteData() {
for (int i = 0; i < classNames._numStrings; i++) {
char* pName = classNames._stringTable[i];
int len = strlen(pName) + 1;
WriteInt(len, 2);
if (len == 0x1b) {
int filler = 6;
fwrite(&filler, 1, 4, fpOut);
}
WriteInt(len, 1);
int tp = 0x80;
fwrite(&tp, 1, 1, fpOut);
fwrite(pName, 1, len, fpOut);

header._numClassNames++;
Expand All @@ -402,7 +348,7 @@ void NIBWriter::WriteData() {

for (int i = 0; i < keyNames._numStrings; i++) {
char* pName = keyNames._stringTable[i];
int len = strlen(pName) + 1;
int len = strlen(pName);
WriteInt(len, 1);
fwrite(pName, 1, len, fpOut);

Expand Down Expand Up @@ -451,6 +397,9 @@ void NIBWriter::WriteData() {
header._numObjects++;
}

header._numHeaders = 1;
header._sizeDw = 9;

fseek(fpOut, headerPos, SEEK_SET);
fwrite(&header, sizeof(header), 1, fpOut);
}
11 changes: 8 additions & 3 deletions tools/vsimporter/xib2nib/src/NIBWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#define NIBOBJ_NULL 0x09
#define NIBOBJ_UID 0x0A

#define DEPLOYMENT_TARGET_IOS9 0x090000
#define DEPLOYMENT_TARGET_IOS11 0x0B0000
#define DEPLOYMENT_TARGET_RECENT DEPLOYMENT_TARGET_IOS11

class ProxiedObject {
public:
XIBObject *_obj, *_proxyObj;
Expand All @@ -48,20 +52,21 @@ class NIBWriter {
FILE* fpOut;

public:
uint32_t _minimumDeploymentTarget;
bool _wasLimitedByDeplymentTarget;
XIBObject* _allUIObjects;
XIBObject* _connections;
XIBObject* _baseObject;
XIBObject* _topObjects;
XIBObject* _accessibilityObjects;
XIBObject* _visibleWindows;
XIBObject* _keyValuePairs;

XIBDictionary* _externalReferencesDictionary;

NIBWriter(FILE* out);
NIBWriter(FILE* out, XIBDictionary* externalRefsDict, XIBObject* base);

static void ExportController(const char* controllerId);
static void ExportAllControllers();
void ExportObject(XIBObject* obj);
void WriteObjects();
XIBObject* AddOutputObject(XIBObject* pObj);
Expand All @@ -76,4 +81,4 @@ class NIBWriter {
XIBObject* GetProxyFor(XIBObject* obj);
};

#endif
#endif
101 changes: 71 additions & 30 deletions tools/vsimporter/xib2nib/src/NSLayoutConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

#include "NSLayoutConstraint.h"
#include "UIView.h"
#include "UILayoutGuide.h"

#include <assert.h>
#include <string>
#include <map>

std::map<std::string, NSLayoutAttribute> storyToLayout = { { "left", NSLayoutAttributeLeft },
Expand All @@ -41,17 +43,24 @@ std::map<std::string, NSLayoutAttribute> storyToLayout = { { "left", NSLayoutAtt
{ "centerXWithinMargins", NSLayoutAttributeCenterXWithinMargins },
{ "centerYWithinMargins", NSLayoutAttributeCenterYWithinMargins } };

static std::map<std::string, NSLayoutRelation> storyToRelation = {
{ "greaterThanOrEqual", NSLayoutRelationGreaterThanOrEqual },
{ "lessThanOrEqual", NSLayoutRelationLessThanOrEqual }};

NSLayoutConstraint::NSLayoutConstraint() {
_firstItem = NULL;
_secondItem = NULL;
_firstAttribute = NSLayoutAttributeNotAnAttribute;
_secondAttribute = NSLayoutAttributeNotAnAttribute;
_relation = NSLayoutRelationEqual;
_multiplier = 1.0f;
_multiplier = 1.0;
_priority = NSLayoutPriorityRequired;
_constant = 0.0f;
_symbolicConstant = 0.0f;
_constant = 0.0;
_symbolicConstant = 0.0;
_hasSymbolicConstant = false;
_layoutIdentifier = NULL;
_placeholder = false;
_exportDefaultValues = false;
}

void NSLayoutConstraint::InitFromXIB(XIBObject* obj) {
Expand All @@ -69,10 +78,10 @@ void NSLayoutConstraint::InitFromXIB(XIBObject* obj) {
_multiplier = obj->FindMember("multiplier")->floatValue();
}
if (obj->FindMember("priority")) {
_priority = obj->FindMember("priority")->floatValue();
_priority = obj->FindMember("priority")->intValue();
}
if (obj->FindMember("constant") && obj->FindMember("constant")->FindMember("value")) {
if (obj->FindMember("constant")->ClassName() == "IBLayoutConstant") {
if (strcmp(obj->FindMember("constant")->ClassName(), "IBLayoutConstant") == 0) {
_constant = obj->FindMember("constant")->FindMember("value")->floatValue();
} else {
_hasSymbolicConstant = true;
Expand All @@ -92,77 +101,109 @@ void NSLayoutConstraint::InitFromStory(XIBObject* obj) {
ObjectConverterSwapper::InitFromStory(obj);

const char* attr;
if (attr = obj->getAttrAndHandle("firstAttribute")) {
if ((attr = obj->getAttrAndHandle("firstAttribute"))) {
if (storyToLayout.find(attr) != storyToLayout.end()) {
_firstAttribute = storyToLayout[attr];
}
}
if (attr = obj->getAttrAndHandle("secondAttribute")) {
if ((attr = obj->getAttrAndHandle("secondAttribute"))) {
if (storyToLayout.find(attr) != storyToLayout.end()) {
_secondAttribute = storyToLayout[attr];
}
}

if (attr = obj->getAttrAndHandle("constant")) {
if ((attr = obj->getAttrAndHandle("constant"))) {
if (obj->getAttrAndHandle("symbolic") && strcmp(obj->getAttrAndHandle("symbolic"), "YES") == 0) {
_hasSymbolicConstant = true;
_symbolicConstant = strtod(attr, NULL);
} else {
_constant = strtod(attr, NULL);
}
}
if (attr = obj->getAttrAndHandle("priority")) {
_priority = strtod(attr, NULL);
if ((attr = obj->getAttrAndHandle("priority"))) {
_priority = std::stoi(attr, NULL);
}

if (attr = obj->getAttrAndHandle("multiplier")) {
_priority = strtod(attr, NULL);
if ((attr = obj->getAttrAndHandle("multiplier"))) {
char *separator;
_multiplier = strtod(attr, &separator);
if (*separator == ':') {
// it is multiplier in form of "100:200"
double div = strtod(separator + 1, NULL);
_multiplier /= div;
}
}

if (attr = getAttrAndHandle("secondItem")) {
if ((attr = getAttrAndHandle("secondItem"))) {
_secondItem = findReference(attr);
assert(_secondItem);
}
if (attr = getAttrAndHandle("firstItem")) {

if ((attr = getAttrAndHandle("firstItem"))) {
_firstItem = findReference(attr);
assert(_firstItem);
}

if ((attr = obj->getAttrAndHandle("relation"))) {
if (storyToRelation.find(attr) != storyToRelation.end()) {
_relation = storyToRelation[attr];
}
}

if ((attr = obj->getAttrAndHandle("placeholder"))) {
_placeholder = strcmp(attr, "YES") == 0;
}

_outputClassName = "NSLayoutConstraint";
}

void NSLayoutConstraint::Awaken() {
if (!_firstItem) {
// Alludes to superview.
if (_secondItem && _secondItem->_parent) {
_firstItem = dynamic_cast<UIView*>(_secondItem->_parent->_parent);
assert(_firstItem);
} else {
_firstItem = dynamic_cast<UIView*>(_parent->_parent);
assert(_firstItem);
}
_firstItem = dynamic_cast<UIView*>(_parent->_parent);
assert(_firstItem);
}
}

void NSLayoutConstraint::ConvertStaticMappings(NIBWriter* writer, XIBObject* obj) {
AddInt(writer, "NSFirstAttribute", _firstAttribute);
AddInt(writer, "NSSecondAttribute", _secondAttribute);
if (_secondAttribute)
AddInt(writer, "NSSecondAttribute", _secondAttribute);

AddInt(writer, "NSRelation", _relation);
if (_exportDefaultValues || _relation != NSLayoutRelationEqual)
AddInt(writer, "NSRelation", _relation);

if (_firstItem)
AddOutputMember(writer, "NSFirstItem", _firstItem);
AddOutputMember(writer, "NSFirstItem", substituteItemUnsupported(writer, _firstItem));
if (_secondItem)
AddOutputMember(writer, "NSSecondItem", _secondItem);
AddOutputMember(writer, "NSSecondItem", substituteItemUnsupported(writer, _secondItem));

AddOutputMember(writer, "NSMultiplier", new XIBObjectFloat(_multiplier));
AddInt(writer, "NSPriority", _priority);
if (_exportDefaultValues || _multiplier != 1.0f)
AddOutputMember(writer, "NSMultiplier", new XIBObjectDouble(_multiplier));
if (_exportDefaultValues || _priority != NSLayoutPriorityRequired)
AddInt(writer, "NSPriority", _priority);

if (_hasSymbolicConstant) {
AddOutputMember(writer, "NSSymbolicConstant", new XIBObjectFloat(_symbolicConstant));
AddOutputMember(writer, "NSSymbolicConstant", new XIBObjectDouble(_symbolicConstant));
} else {
AddOutputMember(writer, "NSConstant", new XIBObjectFloat(_constant));
if (_exportDefaultValues || _constant != 0)
AddOutputMember(writer, "NSConstant", new XIBObjectDouble(_constant));
}

if (_layoutIdentifier)
AddString(writer, "NSLayoutIdentifier", _layoutIdentifier);

ObjectConverterSwapper::ConvertStaticMappings(writer, obj);
}
}

XIBObject* NSLayoutConstraint::substituteItemUnsupported(NIBWriter* writer, XIBObject* item){
if (writer->_minimumDeploymentTarget < DEPLOYMENT_TARGET_IOS11 && (strcmp(item->_outputClassName, "UILayoutGuide") == 0)) {
writer->_wasLimitedByDeplymentTarget = true;
// constraint to layout guide that is not supported, replace them to view
UILayoutGuide *guide = (UILayoutGuide*)item;
if (guide->_owningView)
return guide->_owningView;
}

return item;
}
Loading