void HSSDisplayObject::setDAnchorY(HSSParserNode::p value)
{
    this->dAnchorY = value;
    HSSObservableProperty observedProperty = HSSObservablePropertyHeight;
    if(this->observedAnchorY != NULL)
    {
        this->observedAnchorY->removeObserver(this->observedAnchorYProperty, this);
    }
    HSSContainer::p parentContainer = this->getParent();
    const std::vector<HSSDisplayObject::p> * scope;
    if(parentContainer){
        scope = &(parentContainer->getChildren());
    } else {
        scope = NULL;
    }
    this->anchorY = this->_setLDProperty(
                                         &HSSDisplayObject::anchorYChanged,
                                         value,
                                         this->height,
                                         observedProperty,
                                         this,
                                         this->observedAnchorY,
                                         this->observedAnchorYProperty,
                                         scope
                                         );
    this->notifyObservers(HSSObservablePropertyAnchorY, &this->anchorY);
#if AXR_DEBUG_LEVEL > 0
    this->setDirty(true);
#endif
}
Exemple #2
0
std::vector< std::vector<HSSDisplayObject::p> > AXRController::selectAllHierarchical(const std::vector<HSSDisplayObject::p> & scope, HSSDisplayObject::p thisObj, bool negating, bool processing)
{
    std::vector< std::vector<HSSDisplayObject::p> > selections = this->selectOnLevel(scope, thisObj, negating, processing);
    
    unsigned i, j, k, size, size2, size3;
    for (i=0, size=selections.size(); i<size; i++) {
        
        std::vector<HSSDisplayObject::p> newSearch;
        for(j=0, size2=scope.size(); j<size2; j++){
            if(scope[j]->isA(HSSObjectTypeContainer)){
                HSSContainer::p theContainer = boost::static_pointer_cast<HSSContainer>(scope[j]);
                const std::vector<HSSDisplayObject::p> children = theContainer->getChildren();
                for(k=0, size3 = children.size(); k<size3; k++){
                    newSearch.push_back(children[k]);
                }
            }
        }
        
        std::vector< std::vector<HSSDisplayObject::p> > childSelection;
        if(newSearch.size() > 0){
            this->currentChainCount -= 1;
            this->readNextSelectorNode();
            childSelection = this->selectAllHierarchical(newSearch, thisObj, false, processing);
            for (j=0, size2=selections.size(); j<size2; j++) {
                //std::vector<HSSDisplayObject::p> & selection = selections[j];
                for (k=0, size3=childSelection.size(); k<size3; k++) {
                    selections[j].insert(selections[j].end(), childSelection[k].begin(), childSelection[k].end());
                }
            }
        }
    }
    
    return selections;
}
Exemple #3
0
std::vector< std::vector<HSSDisplayObject::p> > AXRController::selectHierarchical(const std::vector<HSSDisplayObject::p> & scope, HSSDisplayObject::p thisObj, bool negating, bool processing)
{
    std::vector< std::vector<HSSDisplayObject::p> > selections = this->selectOnLevel(scope, thisObj, negating, processing);
    unsigned i, size;
    for (i=0, size=selections.size(); i<size; i++) {
        std::vector<HSSDisplayObject::p> selection = selections[i];
        if(selection.size() > 0){
            if(!this->isAtEndOfSelector()){
                if(this->currentSelectorNode->isA(HSSParserNodeTypeCombinator)){
                    HSSCombinator::p combinator = boost::static_pointer_cast<HSSCombinator>(this->currentSelectorNode);
                    HSSCombinatorType combinatorType = combinator->getCombinatorType();
                    switch (combinatorType) {
                        case HSSCombinatorTypeChildren:
                        {
                            std::vector<HSSDisplayObject::p> newScope;
                            unsigned j, size2, k, size3;
                            for(j=0, size2 = selection.size(); j<size2; j++){
                                if(selection[j]->isA(HSSObjectTypeContainer)){
                                    HSSContainer::p theContainer = boost::static_pointer_cast<HSSContainer>(selection[j]);
                                    const std::vector<HSSDisplayObject::p> children = theContainer->getChildren();
                                    for(k=0, size3 = children.size(); k<size3; k++){
                                        newScope.push_back(children[k]);
                                    }
                                }
                            }
                            this->readNextSelectorNode();
                            return this->selectHierarchical(newScope, thisObj, false, processing);
                            break;
                        }
                            
                        case HSSCombinatorTypeDescendants:
                        {
                            std::vector<HSSDisplayObject::p> newScope;
                            unsigned j, size2, k, size3;
                            for(j=0, size2 = selection.size(); j<size2; j++){
                                if(selection[j]->isA(HSSObjectTypeContainer)){
                                    HSSContainer::p theContainer = boost::static_pointer_cast<HSSContainer>(selection[j]);
                                    const std::vector<HSSDisplayObject::p> children = theContainer->getChildren();
                                    for(k=0, size3 = children.size(); k<size3; k++){
                                        newScope.push_back(children[k]);
                                    }
                                }
                            }
                            
                            this->readNextSelectorNode();
                            return this->selectAllHierarchical(newScope, thisObj, false, processing);
                            break;
                        }
                            
                        default:
                            break;
                    }
                }
            }
        }
    }
    
    return selections;
}
void AXRController::add(HSSContainer::p & newContainer)
{
    if(!this->root){
        this->root = newContainer;
    } else {
        if(this->currentContext.size() != 0){
            HSSContainer::p theCurrent = this->currentContext.top();
            theCurrent->add(newContainer);
            
        } else {
            throw "tried to add a container to nonexistent current";
        }
    }
}
Exemple #5
0
void AXRController::setRoot(HSSContainer::p newRoot){
    this->root = newRoot;
    if(this->core->getParserHSS()->currentObjectContextSize() == 0){
        this->core->getParserHSS()->currentObjectContextAdd(newRoot);
    }
    newRoot->setRoot(true);
}
void AXRController::setRoot(HSSContainer::p newRoot){
    this->root = newRoot;
    HSSParser::p hssparser = AXRCore::getInstance()->getParserHSS();
    if(hssparser->currentObjectContextSize() == 0){
        hssparser->currentObjectContextAdd(newRoot);
    }
    newRoot->setRoot(true);
}
Exemple #7
0
void AXRController::add(HSSDisplayObject::p newElement)
{
    newElement->setController(this);
    
    if(!this->root){
        HSSContainer::p cont = HSSContainer::asContainer(newElement);
        if (cont){
            this->setRoot(cont);
        } else {
            std_log1("############## HSSController: cannot add non-controller as root");
        }
        
    } else {
        if(this->currentContext.size() != 0){
            HSSContainer::p theCurrent = this->currentContext.top();
            theCurrent->add(newElement);
            
        } else {
            std_log1("############## HSSController: tried to add a container to nonexistent current");
        }
    }
}
const std::vector<HSSDisplayObject::p> HSSParentFilter::apply(const std::vector<HSSDisplayObject::p> &scope, bool negating)
{
    if(scope.size() > 0){
        std::vector<HSSDisplayObject::p> ret;
        int size=scope.size();
        HSSContainer::p container;
        if (!negating)
            for (int i=0; i<size; i++){
				container = HSSContainer::asContainer(scope[i]);
                if (container && container->getChildren(false).size()>0)
                    ret.push_back(scope[i]);
			}

        else
            for (int i=0; i<size; i++){
			    container = HSSContainer::asContainer(scope[i]);
                if (container && container->getChildren(false).size()==0)
                    ret.push_back(scope[i]);
            }
        return ret;
    } else {
        return scope;
    }
}
Exemple #9
0
int main(int argc, char **argv) {


	SDL_Init( SDL_INIT_VIDEO );
	screen = SDL_SetVideoMode( WINDOW_WIDTH, WINDOW_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE );
	cr = cairosdl_create (screen);

	SDL_WM_SetCaption( WINDOW_TITLE, 0 );

	#ifdef __WIN32__
		HINSTANCE handle = ::GetModuleHandle(NULL);
		mainicon = ::LoadIcon(handle, "main");
		SDL_SysWMinfo wminfo;
		SDL_VERSION(&wminfo.version);
		if (SDL_GetWMInfo(&wminfo) == 1) ::SetClassLong(wminfo.window, GCL_HICON, (LONG) mainicon);
	#endif


	SDL_EnableKeyRepeat(300, 50);    
	SDL_EnableUNICODE(1);



	
	wrapper = new WinAxrWrapper();
	AXRCore::p core = wrapper->getCore();
	wrapper->hwnd = wminfo.window;

	wrapper->loadFile();


	SDL_Event event;
	while (SDL_WaitEvent(&event)) {
			if (event.type == SDL_QUIT) {
				break;
			} else if (event.type == SDL_MOUSEBUTTONDOWN) {
				AXRCore::p core = wrapper->getCore();
				HSSContainer::p root = core->getController()->getRoot();
				if (root) {
					HSSPoint thePoint;
					thePoint.x = event.button.x;
					thePoint.y = event.button.y;
					root->handleEvent(HSSEventTypeMouseDown, &thePoint);
				}
			} else if (event.type == SDL_MOUSEBUTTONUP) {
				AXRCore::p core = wrapper->getCore();
				HSSContainer::p root = core->getController()->getRoot();
				if (root) {
					HSSPoint thePoint;
					thePoint.x = event.button.x;
					thePoint.y = event.button.y;
					root->handleEvent(HSSEventTypeMouseUp, &thePoint);
				}
			} else if (event.type == SDL_MOUSEMOTION) {
				AXRCore::p core = wrapper->getCore();
				HSSContainer::p root = core->getController()->getRoot();
				if (root) {
					HSSPoint thePoint;
					thePoint.x = event.motion.x;
					thePoint.y = event.motion.y;
					root->handleEvent(HSSEventTypeMouseMove, &thePoint);
				}
			} else if (event.type == SDL_KEYDOWN) {
			} else if (event.type == SDL_KEYUP) {
				if(event.key.keysym.sym == SDLK_F5) {
					reload();
				} else if(event.key.keysym.sym == SDLK_o && (event.key.keysym.mod & KMOD_CTRL) ) {
					wrapper->loadFile();
				}
			} else if(event.type == SDL_VIDEORESIZE) {
				cairosdl_destroy (cr);
				screen = SDL_SetVideoMode (event.resize.w, event.resize.h, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE);
				SDL_SetAlpha(screen,SDL_SRCALPHA,CAIROSDL_AMASK);
				cr = cairosdl_create (screen);
				wrapper->setNeedsDisplay(true);
			} else {
			}
			render();

			SDL_Flip(screen);
			//SDL_Delay(1000/30);
	}
	SDL_Quit();
	#ifdef __WIN32__
		::DestroyIcon(mainicon);
	#endif
	return 0;
}
void HSSDisplayObject::setDHeight(HSSParserNode::p value)
{
    if(value->isA(HSSParserNodeTypeKeywordConstant)){
        
    } else {
        this->dHeight = value;
        HSSObservableProperty observedProperty = HSSObservablePropertyHeight;
        if(this->observedHeight != NULL)
        {
            this->observedHeight->removeObserver(this->observedHeightProperty, this);
            //we're cheating a bit here (maybe FIXME?)
        }
        HSSContainer::p parentContainer = this->getParent();
        if(parentContainer){
            this->height = this->_setLDProperty(
                                                &HSSDisplayObject::heightChanged,
                                                value,
                                                parentContainer->height,
                                                observedProperty,
                                                parentContainer.get(),
                                                this->observedHeight,
                                                this->observedHeightProperty,
                                                &(parentContainer->getChildren())
                                                );
        } else {
            this->height = this->_setLDProperty(
                                                NULL,
                                                value,
                                                150,
                                                observedProperty,
                                                this,
                                                this->observedHeight,
                                                this->observedHeightProperty,
                                                NULL
                                                );
        }
        
        this->notifyObservers(HSSObservablePropertyHeight, &this->height);
        this->setNeedsSurface(true);
        this->setDirty(true);
    }
    
    
    
//    //std_log1("setting height of "+this->name+":");
//    this->dHeight = value;
//    HSSParserNodeType nodeType = value->getType();
//    
//    if(observedHeight != NULL)
//    {
//        observedHeight->removeObserver(HSSObservablePropertyHeight, this);
//    }
//    
//    switch (nodeType) {
//        case HSSParserNodeTypeNumberConstant:
//        {
//            HSSNumberConstant::p heightValue = boost::static_pointer_cast<HSSNumberConstant>(value);
//            this->height = heightValue->getValue();
//            break;
//        }
//            
//        case HSSParserNodeTypePercentageConstant:
//        {
//            HSSPercentageConstant::p heightValue = boost::static_pointer_cast<HSSPercentageConstant>(value);
//            HSSContainer::p parentContainer = this->getParent();
//            if(parentContainer){
//                this->height = heightValue->getValue(parentContainer->height);
//                parentContainer->observe(HSSObservablePropertyHeight, this, new HSSValueChangedCallback<HSSDisplayObject>(this, &HSSDisplayObject::heightChanged));
//                this->observedHeight = parentContainer.get();
//            }
//            break;
//        }
//        
//        case HSSParserNodeTypeExpression:
//        {
//            HSSExpression::p heightExpression = boost::static_pointer_cast<HSSExpression>(value);
//            HSSContainer::p parentContainer = this->getParent();
//            if(parentContainer){
//                heightExpression->setPercentageBase(parentContainer->height);
//                heightExpression->setPercentageObserved(HSSObservablePropertyHeight, parentContainer.get());
//                heightExpression->setScope(&(parentContainer->getChildren()));
//                this->height = heightExpression->evaluate();
//                heightExpression->observe(HSSObservablePropertyHeight, this, new HSSValueChangedCallback<HSSDisplayObject>(this, &HSSDisplayObject::heightChanged));
//            } else {
//                heightExpression->setPercentageBase(this->height);
//                heightExpression->setPercentageObserved(HSSObservablePropertyHeight, this);
//                if(this->isA(HSSObjectTypeContainer)){
//                    HSSContainer * thisContainer = static_cast<HSSContainer *>(this);
//                    heightExpression->setScope(&(thisContainer->getChildren()));
//                }
//                this->height = heightExpression->evaluate();
//                heightExpression->observe(HSSObservablePropertyValue, this, new HSSValueChangedCallback<HSSDisplayObject>(this, &HSSDisplayObject::heightChanged));
//            }
//            break; 
//        }
//            
//        case HSSParserNodeTypeKeywordConstant:
//            
//            break;
//            
//        default:
//            throw "unknown parser node type while setting dHeight";
//            break;
//    }
//    
//    //fprintf(stderr, "%f\n", this->height);
//    this->notifyObservers(HSSObservablePropertyHeight, &this->height);
//    this->setNeedsSurface(true);
//    this->setDirty(true);
}
void HSSDisplayObject::setDWidth(HSSParserNode::p value)
{
    
    if(value->isA(HSSParserNodeTypeKeywordConstant)){
        
    } else {
        this->dWidth = value;
        HSSObservableProperty observedProperty = HSSObservablePropertyWidth;
        if(this->observedWidth != NULL)
        {
            this->observedWidth->removeObserver(this->observedWidthProperty, this);
        }
        HSSContainer::p parentContainer = this->getParent();
        if(parentContainer){
            this->width = this->_setLDProperty(
                                               &HSSDisplayObject::widthChanged,
                                               value,
                                               parentContainer->width,
                                               observedProperty,
                                               parentContainer.get(),
                                               this->observedWidth,
                                               this->observedWidthProperty,
                                               &(parentContainer->getChildren())
                                               );
        } else {
            this->width = this->_setLDProperty(
                                               NULL,
                                               value,
                                               150,
                                               observedProperty,
                                               this,
                                               this->observedWidth,
                                               this->observedWidthProperty,
                                               NULL
                                               );
        }
        
        
        this->notifyObservers(HSSObservablePropertyWidth, &this->width);
        this->setNeedsSurface(true);
        this->setDirty(true);
    }

    
//    //std_log1("setting width of "+this->name+":");
//    this->dWidth = value;
//    HSSParserNodeType nodeType = value->getType();
//    
//    if(observedWidth != NULL)
//    {
//        //std_log1("#################should unsubscribe observer here#########################");
//        observedWidth->removeObserver(HSSObservablePropertyWidth, this);
//    }
//    
//    switch (nodeType) {
//        case HSSParserNodeTypeNumberConstant:
//        {
//            HSSNumberConstant::p widthValue = boost::static_pointer_cast<HSSNumberConstant>(value);
//            this->width = widthValue->getValue();
//            break;
//        }
//            
//        case HSSParserNodeTypePercentageConstant:
//        {
//            HSSPercentageConstant::p widthValue = boost::static_pointer_cast<HSSPercentageConstant>(value);
//            HSSContainer::p parentContainer = this->getParent();
//            if(parentContainer){
//                this->width = widthValue->getValue(parentContainer->width);
//                parentContainer->observe(HSSObservablePropertyWidth, this, new HSSValueChangedCallback<HSSDisplayObject>(this, &HSSDisplayObject::widthChanged));
//                this->observedWidth = parentContainer.get();
//                
//            } else {
//                this->width = widthValue->getValue(this->width);
//            }
//            break;
//        }
//            
//        case HSSParserNodeTypeExpression:
//        {
//            HSSExpression::p widthExpression = boost::static_pointer_cast<HSSExpression>(value);
//            HSSContainer::p parentContainer = this->getParent();
//            if(parentContainer){
//                widthExpression->setPercentageBase(parentContainer->width);
//                widthExpression->setPercentageObserved(HSSObservablePropertyWidth, parentContainer.get());
//                widthExpression->setScope(&(parentContainer->getChildren()));
//                this->width = widthExpression->evaluate();
//                widthExpression->observe(HSSObservablePropertyWidth, this, new HSSValueChangedCallback<HSSDisplayObject>(this, &HSSDisplayObject::widthChanged));
//            } else {
//                widthExpression->setPercentageBase(this->width);
//                widthExpression->setPercentageObserved(HSSObservablePropertyWidth, this);
//                if(this->isA(HSSObjectTypeContainer)){
//                    HSSContainer * thisContainer = static_cast<HSSContainer *>(this);
//                    widthExpression->setScope(&(thisContainer->getChildren()));
//                }
//                this->width = widthExpression->evaluate();
//                widthExpression->observe(HSSObservablePropertyWidth, this, new HSSValueChangedCallback<HSSDisplayObject>(this, &HSSDisplayObject::widthChanged));
//            }
//            break; 
//        }
//            
//        case HSSParserNodeTypeKeywordConstant:
//            
//            break;
//            
//        default:
//            throw "unknown parser node type while setting dWidth";
//            break;
//    }
//    
//    //fprintf(stderr, "%f\n", this->width);
//    this->notifyObservers(HSSObservablePropertyWidth, &this->width);
//    this->setNeedsSurface(true);
//    this->setDirty(true);
}
Exemple #12
0
void AXRController::recursiveMatchRulesToDisplayObjects(const HSSRule::p & rule, const std::vector<HSSDisplayObject::p> & scope, HSSContainer::p container, bool applyingInstructions)
{
    HSSInstruction::p instruction = rule->getInstruction();
    if (instruction && applyingInstructions) {
        switch (instruction->getInstructionType()) {
            case HSSNewInstruction:
            {
                std::string elementName = rule->getSelectorChain()->subject()->getElementName();
                unsigned i;
                unsigned argssize = 1;
                HSSParserNode::p argument = instruction->getArgument();
                if(argument){
                    if (argument->isA(HSSParserNodeTypeNumberConstant)) {
                        HSSNumberConstant::p argnum = boost::static_pointer_cast<HSSNumberConstant>(argument);
                        argssize = (int)argnum->getValue();
                    }
                }
                
                for (i=0; i<argssize; i++) {
                    HSSContainer::p newContainer = HSSContainer::p(new HSSContainer());
                    newContainer->setName(elementName);
                    newContainer->setElementName(elementName);;
                    this->add(newContainer);
                    rule->setThisObj(newContainer);
                    newContainer->rulesAdd(rule, (rule->getActiveByDefault() ? HSSRuleStateOn : HSSRuleStateOff ));
                    std_log1("created "+newContainer->getElementName());
                    newContainer->setNeedsRereadRules(true);
                    newContainer->setNeedsSurface(true);
                    newContainer->setDirty(true);
                    unsigned i, size;
                    this->currentContext.push(newContainer);
                    for (i=0, size=rule->childrenSize(); i<size; i++) {
                        const HSSRule::p childRule = rule->childrenGet(i);
                        this->recursiveMatchRulesToDisplayObjects(childRule, newContainer->getChildren(), newContainer, applyingInstructions);
                    }
                    newContainer->setNeedsRereadRules(true);
                    //newContainer->fireEvent(HSSEventTypeLoad);
                    this->currentContext.pop();
                }
                
                break;
            }
                
            case HSSMoveInstruction:
            {
                HSSContainer::p parent = container->getParent();
                if (parent) {
                    std::vector<HSSDisplayObject::p> moveScope = parent->getChildren();
                    this->setSelectorChain(rule->getSelectorChain());
                    std::vector< std::vector<HSSDisplayObject::p> > selection = this->selectHierarchical(moveScope, container);
                    unsigned i, j, k, size, size2, size3;
                    
                    this->currentContext.push(container);
                    //move the children over
                    for (i=0, size=selection.size(); i<size; i++) {
                        std::vector<HSSDisplayObject::p> inner = selection[i];
                        for (j=0, size2=inner.size(); j<size2; j++) {
                            HSSDisplayObject::p theDO = inner[j];
                            if(theDO != container){
                                theDO->removeFromParent();
                                this->add(theDO);
                                rule->setThisObj(theDO);
                                std_log1("moved "+theDO->getElementName());
                                theDO->rulesAdd(rule, (rule->getActiveByDefault() ? HSSRuleStateOn : HSSRuleStateOff ));
                                theDO->setNeedsRereadRules(true);
                                theDO->setNeedsSurface(true);
                                theDO->setDirty(true);
                                
                                if(theDO->isA(HSSObjectTypeContainer)){
                                    HSSContainer::p theContainer = boost::static_pointer_cast<HSSContainer>(theDO);
                                    this->currentContext.push(theContainer);
                                    //assign more rules
                                    for (k=0, size3=rule->childrenSize(); k<size3; k++) {
                                        const HSSRule::p childRule = rule->childrenGet(k);
                                        this->recursiveMatchRulesToDisplayObjects(childRule, theContainer->getChildren(), theContainer, applyingInstructions);
                                    }
                                    this->currentContext.pop();
                                }
                                
                                theDO->setNeedsRereadRules(true);
                                //theDO->fireEvent(HSSEventTypeLoad);
                            }
                            
                        }
                    }
                    this->currentContext.pop();
                }
                
                break;
            }
                
            case HSSDeleteInstruction:
            {
                //select the items to be deleted
                this->setSelectorChain(rule->getSelectorChain());
                std::vector< std::vector<HSSDisplayObject::p> > selection = this->selectHierarchical(scope, container);
                unsigned i, j, size, size2;
                for (i=0, size=selection.size(); i<size; i++) {
                    std::vector<HSSDisplayObject::p> inner = selection[i];
                    for (j=0, size2=inner.size(); j<size2; j++) {
                        inner[j]->removeFromParent();
                    }
                }
                break;
            }
                                
            default:
                break;
        }
        
    } else {
        HSSSelectorChain::p selectorChain = rule->getSelectorChain();
        if(selectorChain){
            this->setSelectorChain(selectorChain);
            
            //if it starts with a combinator, adjust the scope and selector chain
            bool useAdjustedScope = false;
            std::vector<HSSDisplayObject::p> adjustedScope;
            if(this->currentSelectorNode->isA(HSSParserNodeTypeCombinator)){
                useAdjustedScope = true;
                adjustedScope.push_back(container);
                this->currentChain->prepend(HSSSelector::p(new HSSSelector(container->getElementName())));
                this->currentChainSize ++;
                this->currentSelectorNode = this->currentChain->get(0);
            }
            
            //we observe the parent for dom changes
            container->observe(HSSObservablePropertyTreeChange, HSSObservablePropertyValue, rule.get(), new HSSValueChangedCallback<HSSRule>(rule.get(), &HSSRule::treeChanged));
            rule->setObservedTreeChanger(container.get());
            rule->setThisObj(container);
            
            rule->setOriginalScope(scope);
            std::vector< std::vector<HSSDisplayObject::p> > selection = this->selectHierarchical((useAdjustedScope ? adjustedScope : scope), container);
            unsigned i, j, k, size, size2, size3;
            for (i=0, size=selection.size(); i<size; i++) {
                std::vector<HSSDisplayObject::p> inner = selection[i];
                for (j=0, size2=inner.size(); j<size2; j++) {
                    const HSSDisplayObject::p & displayObject = inner[j];
                    std_log1("match "+displayObject->getElementName());
                    displayObject->rulesAdd(rule, (rule->getActiveByDefault() ? HSSRuleStateOn : HSSRuleStateOff ));
                    
                    displayObject->setNeedsRereadRules(true);
                    displayObject->setNeedsSurface(true);
                    displayObject->setDirty(true);
                    
                    //if it is a container it may have children
                    if(displayObject->isA(HSSObjectTypeContainer)){
                        HSSContainer::p selectedContainer = boost::static_pointer_cast<HSSContainer>(displayObject);
                        this->currentContext.push(selectedContainer);
                        for (k=0, size3=rule->childrenSize(); k<size3; k++) {
                            const HSSRule::p childRule = rule->childrenGet(k);
                            this->recursiveMatchRulesToDisplayObjects(childRule, selectedContainer->getChildren(), selectedContainer, applyingInstructions);
                        }
                        this->currentContext.pop();
                    }
                    
                    displayObject->setNeedsRereadRules(true);
                }
            }
        }
    }
}
Exemple #13
0
void HSSRequest::fire()
{
    AXRDocument* document = this->getController()->document();

    //if there is no target
    if (this->target->empty())
    {
        document->loadXMLFile(this->src);
    }
    else
    {
        switch (this->mode)
        {
        default:
        {
            AXRController::p controller = AXRController::p(new AXRController(document));
            XMLParser::p xmlParser(new XMLParser(controller.data()));
            HSSParser::p hssParser(new HSSParser(controller.data()));
            AXRBuffer::p baseFile = document->getFile();
            AXRBuffer::p newFile;
            try
            {
                newFile = document->getFile(this->src);
            }
            catch (const AXRError &e)
            {
                e.raise();
            }

            if (newFile)
            {
                bool loadingSuccess = xmlParser->loadFile(newFile);
                if (!loadingSuccess)
                {
                    AXRError("AXRDocument", "Could not load the XML file").raise();
                }
                else
                {
                    HSSContainer::p root = qSharedPointerCast<HSSContainer > (controller->getRoot());

                    if (root)
                    {
                        std::vector<QUrl> loadSheets = controller->loadSheetsGet();
                        for (std::vector<QUrl>::iterator sheetsIt = loadSheets.begin(); sheetsIt != loadSheets.end(); ++sheetsIt)
                        {
                            AXRBuffer::p hssfile;
                            try
                            {
                                hssfile = document->getFile(*sheetsIt);
                            }
                            catch (const AXRError &e)
                            {
                                e.raise();
                                continue;
                            }

                            if (!hssParser->loadFile(hssfile))
                            {
                                AXRError("AXRDocument", "Could not load the HSS file").raise();
                            }
                        }

                        controller->matchRulesToContentTree();

                        HSSSimpleSelection::const_iterator targetIt, childIt;
                        for (targetIt = this->target->begin(); targetIt != this->target->end(); ++targetIt)
                        {
                            const HSSDisplayObject::p & theDO = *targetIt;
                            HSSContainer::p theContainer = HSSContainer::asContainer(theDO);
                            if (theContainer)
                            {
                                theContainer->clear();
                                for (childIt = root->getChildren()->begin(); childIt != root->getChildren()->end(); ++childIt)
                                {
                                    const HSSDisplayObject::p & theChild = *childIt;
                                    theContainer->add(theChild);
                                }
                            }
                        }

                        root->setNeedsRereadRules(true);
                        root->recursiveReadDefinitionObjects();
                        root->handleEvent(HSSEventTypeLoad, NULL);
                        document->setNeedsDisplay(true);
                    }
                }
            }

            //                AXRDocument::tp document = AXRDocument::getInstance();
            //                AXRWrapper * document = document->getWrapper();
            //                AXRBuffer::p baseFile = document->getFile();
            //
            //                bool loadingSuccess = document->loadFile(baseFile->basePath+this->src, this->src);
            //                if(loadingSuccess){
            //                    unsigned i, size;
            //                    for (i=0, size=this->target.size(); i<size; ++i) {
            //                        std_log1("Adding loaded file to target");
            //
            //                        if(this->target[i]->isA(HSSObjectTypeContainer)){
            //                            const HSSContainer::p & theCont = qSharedPointerCast<HSSContainer>(this->target[i]);
            //                            const HSSContainer::p & loadedRoot = fileController.getRoot();
            //                            theCont->add(loadedRoot);
            //
            //                            unsigned j, k, size2, size3;
            //                            HSSSimpleSelection::p scope = theCont->getChildren();
            //                            for (j=0, size2=fileController.rulesSize(); j<size2; ++j) {
            //                                HSSRule::p & theRule = fileController.rulesGet(j);
            //                                theRule->childrenAdd(theRule);
            //                            }
            //                            for (j=0, size2=theCont->rulesSize(); j<size2; ++j) {
            //                                HSSRule::p theRule = theCont->rulesGet(j);
            //                                for (k=0, size3=theRule->childrenSize(); k<size3; ++k) {
            //                                    HSSRule::p childRule = theRule->childrenGet(k);
            //                                    this->getController()->recursiveMatchRulesToDisplayObjects(childRule, scope, theCont);
            //                                }
            //                            }
            //
            //                            theCont->recursiveReadDefinitionObjects();
            //                            theCont->setNeedsLayout(true);
            //                        }
            //                    }
            //                }
            break;
        }
        }
    }
}