Пример #1
0
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";
}
Пример #2
0
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);
}
Пример #3
0
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);
}
Пример #4
0
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";
}