Пример #1
0
const TiXmlElement* TiXmlNode::FirstChildElement( const char * _value ) const
{
	const TiXmlNode* node;

	for (	node = FirstChild( _value );
			node;
			node = node->NextSibling( _value ) )
	{
		if ( node->ToElement() )
			return node->ToElement();
	}
	return 0;
}
Пример #2
0
TiXmlElement* TiXmlNode::FirstChildElement()
{
	TiXmlNode* node;

	for (	node = FirstChild();
			node;
			node = node->NextSibling() )
	{
		if ( node->ToElement() )
			return node->ToElement();
	}
	return 0;
}
Пример #3
0
void TiXmlDocument::StreamOut( TIXML_OSTREAM * out ) const
{
	TiXmlNode* node;
	for ( node=FirstChild(); node; node=node->NextSibling() )
	{
		node->StreamOut( out );

		// Special rule for streams: stop after the root element.
		// The stream in code will only read one element, so don't
		// write more than one.
		if ( node->ToElement() )
			break;
	}
}
Пример #4
0
	bool XMLDocument::Accept(XMLVisitor* visitor) const
	{
		if (visitor->VisitEnter(*this))
		{
			for (const XMLNode* node = FirstChild(); node; node = node->NextSibling())
			{
				if (!node->Accept(visitor))
				{
					break;
				}
			}
		}
		return visitor->VisitExit(*this);
	}
Пример #5
0
const char * XmlNode::GetText() const
{
	const TiXmlNode * childNode = FirstChild();
	if ( childNode == NULL )
	{
		return NULL;
	}
	IE_ASSERT( childNode->Type() == TEXT );

	const TiXmlText * text = childNode->ToText();
	IE_ASSERT( text );

	return text->Value();
}
Пример #6
0
void XMLParagraph::DeleteLeaf(size_t nLeaf)
{
    auto pNode   = LeafRef(nLeaf).Node();
    auto pParent = pNode->Parent();

    while(pParent && (pParent->FirstChild() == pParent->LastChild())){
        pNode   = pParent;
        pParent = pParent->Parent();
    }

    if(pParent){
        pParent->DeleteChild(pNode);
    }
}
Пример #7
0
void CookiePath::BuildCookieEditorListL(CookieDomain* domain)
{
	Cookie *ck = (Cookie*)cookie_list.First();
	if( ck )
	{
		ck->BuildCookieEditorListL(domain, this);
	}
	
	CookiePath *cp = (CookiePath*)FirstChild();
	while(cp)
	{
		cp->BuildCookieEditorListL(domain);
		cp = cp->Suc();
	}
}
Пример #8
0
	Node * Node::FindEditChildByAttrib (	std::string const & childName, 
											std::string const & attrName, 
											std::string const & attrValue)
	{
		XML::Node::ChildIter it = FirstChild ();
		XML::Node::ChildIter last = LastChild ();
		while (it != last)
		{
			XML::Node * child = *it;
			if (child->GetName () == childName && child->FindAttribValue (attrName) == attrValue)
				return child;
			++it;
		}
		return 0;
	}
Пример #9
0
void CookiePath::IterateAllCookies()
{
	Cookie* ck = static_cast<Cookie*>( cookie_list.First() );
	OpCookieIteratorListener* listener = g_cookie_API->GetCookieIteratorListener();
	while( ck )
	{
		listener->OnIterateCookies(*ck);
		ck = ck->Suc();
	}

	CookiePath* cp = static_cast<CookiePath*>( FirstChild() );
	while (cp)
	{
		cp->IterateAllCookies();
		cp = cp->Suc();
	}
}
Пример #10
0
OP_STATUS CookiePath::RemoveCookieList(char * pathstr, char * namestr)
{
	char* pathstrcopy = pathstr;

	if(path.HasContent() && pathstr && *pathstr)
	{
		int p_len = path.Length();
		if(path.Compare(pathstr,p_len) != 0)
			return OpStatus::OK;

		pathstr += p_len; // Remove first part, if path found
		if(*pathstr == '/') pathstr++;
	}

	Cookie *ck = (Cookie*)cookie_list.First();
	while(ck)
	{
		Cookie * next = ck->Suc();
		if(pathstr && *pathstr)	// if a path was specified test against it, otherwise delete it
		{
			OpString8 fullpath;
			RETURN_IF_ERROR(GetFullPath(fullpath));	// get the full path
			//the internal root part does not start with /, so get rid of it
			fullpath.Delete(0,1);
			int pathlen = fullpath.Length();
			if(pathlen && fullpath.Compare(pathstrcopy, pathlen) == 0)	//compare against the full path length since we want subpaths
			{
				OP_DELETE(ck);
			}
		}
		else if((!namestr || !*namestr) || (ck->Name().Compare(namestr) == 0))	// remove it if no Name value was set or if the Name value equals 
		{
			ck->Out();
			OP_DELETE(ck);
		}
		ck = next;
	}
	
	CookiePath *cp = (CookiePath*)FirstChild();
	while(cp)
	{
		cp->RemoveCookieList(pathstr, namestr);
		cp = cp->Suc();
	}
    return OpStatus::OK;
}
Пример #11
0
int TiXmlDocument::Printe( char * xmlstr, int totallen, int depth, int& len ) 
{
	char tempstr[MAX_XML_SIZE] = {0};
	TiXmlNode* node = NULL;
	for ( node = FirstChild(); node; node = node->NextSibling() )
	{
		//#ifdef _PUTSTRING
		if ( node->Printe( xmlstr, totallen, depth, len ) < 0 )
		{
			return -2;
		}
		//#endif
		sprintf( tempstr, "\n" );
		SAFE_STRCAT;
	}

	return 0;
}
Пример #12
0
void CookiePath::GetMemUsed(DebugUrlMemory &debug)
{
	debug.memory_cookies += sizeof(*this) + path.Length();

	Cookie *ck = (Cookie *) cookie_list.First();
	while(ck)
	{
		ck->GetMemUsed(debug);
		ck = ck->Suc();
	}

	CookiePath *cp = (CookiePath *) FirstChild();
	while(cp)
	{
		cp->GetMemUsed(debug);
		cp = cp->Suc();
	}
}
Пример #13
0
BOOL CookiePath::HasCookies(time_t this_time)
{
	Cookie* ck = (Cookie*) cookie_list.First();
	while (ck)
	{
		if (!ck->DiscardAtExit() && ck->Expires() > this_time)
			return TRUE;
		ck = ck->Suc();
	}
	CookiePath* cp = (CookiePath*) FirstChild();
	while (cp)
	{
		if (cp->HasCookies(this_time))
			return TRUE;
		cp = cp->Suc();
	}
	return FALSE;
}
Пример #14
0
Cookie* CookiePath::GetLeastRecentlyUsed(time_t last_used, time_t this_time)
{
	time_t new_last_used = last_used;
	Cookie* ck = 0;
	Cookie *ck_unused = NULL;
	Cookie* new_ck = (Cookie*) cookie_list.First();
	while (new_ck)
	{
		Cookie* next_ck = new_ck->Suc();
		if (new_ck->Expires() && new_ck->Expires() < this_time)
		{
			OP_DELETE(new_ck);
		}
		else if (new_ck->GetLastUsed() <= new_last_used && !new_ck->ProtectedCookie())
		{
			if(new_ck->GetLastUsed())
			{
				new_last_used = new_ck->GetLastUsed();
				ck = new_ck;
			}
			else if(!ck_unused)
				ck_unused = new_ck;
		}
		new_ck = next_ck;
	}

	CookiePath* cp = (CookiePath*) FirstChild();
	while (cp)
	{
		new_ck = cp->GetLeastRecentlyUsed(new_last_used, this_time);
		if (new_ck)
		{
			if(new_ck->GetLastUsed())
			{
				ck = new_ck;
				new_last_used = ck->GetLastUsed();
			}
			else
				ck_unused = new_ck;
		}
		cp = cp->Suc();
	}
	return (ck ? ck : ck_unused);
}
Пример #15
0
nsFrameList::Slice
nsFrameList::InsertFrames(nsIFrame* aParent, nsIFrame* aPrevSibling,
                          nsFrameList& aFrameList)
{
  NS_PRECONDITION(aFrameList.NotEmpty(), "Unexpected empty list");

  if (aParent) {
    aFrameList.ApplySetParent(aParent);
  }

  NS_ASSERTION(IsEmpty() ||
               FirstChild()->GetParent() == aFrameList.FirstChild()->GetParent(),
               "frame to add has different parent");
  NS_ASSERTION(!aPrevSibling ||
               aPrevSibling->GetParent() == aFrameList.FirstChild()->GetParent(),
               "prev sibling has different parent");
#ifdef DEBUG_FRAME_LIST
  // ContainsFrame is O(N)
  NS_ASSERTION(!aPrevSibling || ContainsFrame(aPrevSibling),
               "prev sibling is not on this list");
#endif

  nsIFrame* firstNewFrame = aFrameList.FirstChild();
  nsIFrame* nextSibling;
  if (aPrevSibling) {
    nextSibling = aPrevSibling->GetNextSibling();
    aPrevSibling->SetNextSibling(firstNewFrame);
  }
  else {
    nextSibling = mFirstChild;
    mFirstChild = firstNewFrame;
  }

  nsIFrame* lastNewFrame = aFrameList.LastChild();
  lastNewFrame->SetNextSibling(nextSibling);
  if (!nextSibling) {
    mLastChild = lastNewFrame;
  }

  VerifyList();

  aFrameList.Clear();
  return Slice(*this, firstNewFrame, nextSibling);
}
Пример #16
0
void CookiePath::DeleteAllCookies()
{
	Cookie* ck = (Cookie*) cookie_list.First();

	while (ck)
	{
		Cookie *ck1 = ck->Suc();

		OP_DELETE(ck);

		ck = ck1;
	}
	CookiePath* cp = (CookiePath*) FirstChild();
	while (cp)
	{
		cp->DeleteAllCookies();
		cp = cp->Suc();
	}
}
Пример #17
0
void CookiePath::DebugWriteCookies(FILE* fp)
{
	fprintf(fp, "   ");
	DebugWritePath(fp);
	fprintf(fp, ": \n");
	Cookie* ck = (Cookie*) cookie_list.First();
	while (ck)
	{
		fprintf(fp, "      %s=%s; %lu; %d; %lu %s\n", ck->Name(), ck->Value(), ck->Expires(), ck->Secure(), ck->GetLastUsed(), (ck->DiscardAtExit() ? "; Discard on exit" : ""));
		ck = ck->Suc();
	}

	CookiePath* cp = (CookiePath*) FirstChild();
	while (cp)
	{
		cp->DebugWriteCookies(fp);
		cp = cp->Suc();
	}
}
Пример #18
0
NS_IMETHODIMP
inDeepTreeWalker::NextNode(nsIDOMNode **_retval)
{
  // First try our kids
  FirstChild(_retval);

  if (*_retval) {
    return NS_OK;
  }

  // Now keep trying next siblings up the parent chain, but if we
  // discover there's nothing else restore our state.
#ifdef DEBUG
  nsIDOMNode* origCurrentNode = mCurrentNode;
#endif
  uint32_t lastChildCallsToMake = 0;
  while (1) {
    NextSibling(_retval);

    if (*_retval) {
      return NS_OK;
    }

    nsCOMPtr<nsIDOMNode> parent;
    ParentNode(getter_AddRefs(parent));
    if (!parent) {
      // Nowhere else to go; we're done.  Restore our state.
      while (lastChildCallsToMake--) {
        nsCOMPtr<nsIDOMNode> dummy;
        LastChild(getter_AddRefs(dummy));
      }
      NS_ASSERTION(mCurrentNode == origCurrentNode,
                   "Didn't go back to the right node?");
      *_retval = nullptr;
      return NS_OK;
    }
    ++lastChildCallsToMake;
  }

  NS_NOTREACHED("how did we get here?");
  return NS_OK;
}
Пример #19
0
	void Node::Write (std::ostream & out, unsigned indent) const
	{
		WriteOpeningTag (out, indent);
		if (!_closed)
		{
			for (ConstChildIter it = FirstChild (); it != LastChild (); ++it)
			{
				XML::Node * child = *it;
				if (child->GetName ().empty ()) // text
				{
					out << Indentation (indent) << child->GetAttribValue ("Text") << std::endl;
				}
				else
				{
					child->Write (out, indent + 2);
				}
			}
		}
		WriteClosingTag (out, indent);
	}
Пример #20
0
void CookiePath::RemoveNonPersistentCookies()
{
	time_t this_time = (time_t) (g_op_time_info->GetTimeUTC()/1000.0);
	Cookie* ck = (Cookie*) cookie_list.First();

	while (ck)
	{
		Cookie *ck1 = ck->Suc();
		if (!ck->Persistent(this_time))
		{
			OP_DELETE(ck);
		}
		ck = ck1;
	}
	CookiePath* cp = (CookiePath*) FirstChild();
	while (cp)
	{
		cp->RemoveNonPersistentCookies();
		cp = cp->Suc();
	}
}
Пример #21
0
// Return TRUE if empty
BOOL CookiePath::FreeUnusedResources()
{
	BOOL ret = cookie_list.Empty();

	CookiePath* next_cp = (CookiePath*) FirstChild();
	while (next_cp)
	{
		CookiePath* cp =next_cp;
		next_cp = cp->Suc();

		if(cp->FreeUnusedResources())
		{
			cp->Out();
			OP_DELETE(cp);
		}
		else
			ret = FALSE;
	}

	return ret;
}
Пример #22
0
OP_STATUS CookiePath::BuildCookieList(Cookie ** cookieArray, int * pos, char * pathstr, CookieDomain *domainHolder, BOOL is_export, BOOL match_subpaths/*=FALSE*/)
{
	char* pathstrcopy = pathstr;
	if(!match_subpaths && path.HasContent() && pathstr && *pathstr)
	{
		int p_len = path.Length();
		if(path.Compare(pathstr,p_len) != 0)
			return OpStatus::OK;

		pathstr += p_len; // Remove first part, if path found
		if(*pathstr == '/') pathstr++;
	}

	Cookie *ck = (Cookie*)cookie_list.First();
	if( ck )
	{
		if(match_subpaths && pathstrcopy && *pathstrcopy)	//if a path was specified
		{
			OpString8 fullpath;
			RETURN_IF_ERROR(GetFullPath(fullpath));	// get the full path
			//the internal root part does not start with /, so get rid of it
			fullpath.Delete(0,1);
			int pathlen = fullpath.Length();
			if(!pathlen || (pathlen && fullpath.Compare(pathstrcopy, pathlen) == 0))	//compare against the full path length since we want subpaths, root has null length
				ck->BuildCookieList(cookieArray, pos, domainHolder, this, is_export);
		}
		else
			ck->BuildCookieList(cookieArray, pos, domainHolder, this, is_export);
	}
	
	CookiePath *cp = (CookiePath*)FirstChild();
	while(cp)
	{
		cp->BuildCookieList(cookieArray, pos, pathstr, domainHolder, is_export, match_subpaths);
		cp = cp->Suc();
	}

    return OpStatus::OK;
}
Пример #23
0
static PNODE TreeGetLeftmost(PNODE pThisNode,
	unsigned nCurrentLevel,
	unsigned nSearchDepth)
{
	/*------------------------------------------------------
	* Determine the leftmost descendant of a node at a
	* given depth. This is implemented using a post-order
	* walk of the subtree under pThisNode, down to the
	* level of nSearchDepth. If we've searched to the
	* proper distance, return the currently leftmost node.
	* Otherwise, recursively look at the progressively
	* lower levels.
	*----------------------------------------------------*/

	PNODE pLeftmost;    /* leftmost descendant at level   */
	PNODE pRightmost;   /* rightmost offspring in search  */

	if (nCurrentLevel == nSearchDepth)
		pLeftmost = pThisNode; /*  searched far enough.    */
	else if (IsLeaf(pThisNode))
		pLeftmost = 0;  /* This node has no descendants    */
	else {  /* Do a post-order walk of the subtree.        */
		for (pLeftmost = TreeGetLeftmost(pRightmost =
			FirstChild(pThisNode),
			nCurrentLevel + 1,
			nSearchDepth)

			;
			(pLeftmost == 0) && (HasRightSibling(pRightmost))
			;
			pLeftmost = TreeGetLeftmost(pRightmost =
				RightSibling(pRightmost),
				nCurrentLevel + 1,
				nSearchDepth)
			) { /* Nothing inside this for-loop. */
		}
	}
	return (pLeftmost);
}
Пример #24
0
const XmlNode * XmlDocument::GetNode( const char * tagName, unsigned int idx ) const
{
	const TiXmlNode * node = FirstChild( tagName );
	if ( node->Type() != ELEMENT )
	{
		node = node->NextSiblingElement( tagName );
		if ( node == NULL )
		{
			return NULL;
		}
	}

	for ( unsigned int i = 0; i < idx; ++i )
	{
		node = node->NextSiblingElement( tagName );
		if ( node == NULL )
		{
			return NULL;
		}
	}

	return reinterpret_cast<const XmlNode*>( node );
}
Пример #25
0
// 태그가 일치하는 자식의 개수를 반환한다.
unsigned int XmlNode::GetNodeCount( const char * tagName ) const
{
	unsigned int nodeCount = 0;

	const TiXmlNode * node = FirstChild( tagName );
	if ( node == NULL )
	{
		return 0;
	}

	if ( node->Type() != ELEMENT )
	{
		node = node->NextSiblingElement( tagName );
	}

	while ( node )
	{
		++nodeCount;
		node = node->NextSiblingElement( tagName );
	}

	return nodeCount;
}
Пример #26
0
// pth must not start with '/'
CookiePath* CookiePath::GetCookiePathL(const char* pth, BOOL create, BOOL &is_full_path)
{
	if (pth && *pth)
	{
		is_full_path = FALSE;
		char* tmp = (char*) (*pth != '?' ? op_strpbrk(pth, "/?") : NULL);
		char save_c = 0;
		if (tmp)
		{
			save_c = *tmp;
			*tmp = '\0';
		}

		int test = 1;
		BOOL is_prefix = FALSE;
		CookiePath* cp = LastChild();

		if(create)
		{
			while (cp && test>0)
			{
				test = UriUnescape::strcmp(cp->PathPart().CStr(), pth, UriUnescape::Safe);
				if (test > 0)
					cp = cp->Pred();
			}
		}
		else
		{
			int len1 = op_strlen(pth);
			int clen;

			while(cp && test>0)
			{
				clen = cp->PathPart().Length();

				if(clen < len1 && UriUnescape::isstrprefix(cp->PathPart().CStr(), pth, UriUnescape::All))
				{
					is_prefix = TRUE;
					test = 0;
				}
				else
					test = UriUnescape::strcmp(cp->PathPart().CStr(), pth, UriUnescape::Safe);
				if (test > 0)
					cp = cp->Pred();

			}
		}

		CookiePath* next_cp = cp;
		if (test != 0 || !cp)
		{
			if (!create)
			{
				if (tmp)
					*tmp = save_c;

				return this;
			}

			next_cp = CookiePath::CreateL(pth);

			if (cp)
				next_cp->Follow(cp);
			else if (FirstChild())
				next_cp->Precede(FirstChild());
			else
				next_cp->Under(this);
		}

		BOOL local_is_full_path = FALSE;
		if (tmp)
		{
			*tmp = save_c;
			if(save_c == '/')
				local_is_full_path = TRUE;
		}

		const char* next_path = (tmp && !is_prefix) ? (save_c == '?' ? tmp : tmp+1) : 0;
		CookiePath* return_cp = next_cp->GetCookiePathL(next_path, create, is_full_path);

		if(return_cp == next_cp && tmp && local_is_full_path && !is_prefix)
			is_full_path = TRUE;

		return return_cp;
	}
	else
	{
		return this;
	}
}
Пример #27
0
GlowWidget::AutoPackError GlowQuickPanelWidget::OnAutoPack(
	int hSize,
	int vSize,
	AutoPackOptions hOption,
	AutoPackOptions vOption,
	int& leftMargin,
	int& rightMargin,
	int& topMargin,
	int& bottomMargin)
{
	GLOW_DEBUGSCOPE("GlowQuickPanelWidget::OnAutoPack");
	
	int position = (_arrangement == vertical) ? _vmargin : _hmargin;
	int size = 0;
	int minWidth = position;
	
	// Arrange widgets with default alignment
	for (GlowComponent* child = FirstChild(); child != 0; child = child->Next())
	{
		// Get next widget
		GlowWidget* widget = dynamic_cast<GlowWidget*>(child);
		if (widget == 0 || !widget->IsVisible() || widget->IsClosing())
		{
			continue;
		}
		
		// Handle the label of the panel (if any) differently.
		if (widget == _label)
		{
			if (GetStyle() == GlowPanelWidget::etchedStyle)
			{
				// Etched style: label is half in and half out of the panel
				widget->AutoPack(_hmargin, unspecifiedPos, 0, unspecifiedPos,
					leftPos | preferredSize, centerPos | preferredSize);
				topMargin = widget->Height()/2;
				if (_arrangement == vertical)
				{
					position += widget->Height()/2;
				}
			}
			else
			{
				// Other style: label is completely out of the panel
				widget->AutoPack(_hmargin, unspecifiedPos, unspecifiedPos, 0,
					leftPos | preferredSize, bottomPos | preferredSize);
				topMargin = widget->Height();
			}
			minWidth = widget->Width()+_hmargin+_hmargin;
			continue;
		}
		
		int leftMargin = 0, rightMargin = 0, topMargin = 0, bottomMargin = 0;
		if (_arrangement == horizontal)
		{
			widget->AutoPack(position, unspecifiedPos, _vmargin, unspecifiedPos,
				leftPos | preferredSize, topPos | preferredSize,
				leftMargin, rightMargin, topMargin, bottomMargin);
			size = GLOW_STD::max(size, widget->Height()+topMargin+bottomMargin);
			position += widget->Width()+leftMargin+rightMargin+_spacing;
		}
		else
		{
			widget->AutoPack(_hmargin, unspecifiedPos, position, unspecifiedPos,
				leftPos | preferredSize, topPos | preferredSize,
				leftMargin, rightMargin, topMargin, bottomMargin);
			size = GLOW_STD::max(size, widget->Width()+leftMargin+rightMargin);
			position += widget->Height()+topMargin+bottomMargin+_spacing;
		}
	}
	
	// Preferred width and height
	int pwidth = 0, pheight = 0;
	if (_arrangement == horizontal)
	{
		pwidth = GLOW_STD::max(minWidth, position-_spacing+_hmargin);
		pheight = size+_vmargin+_vmargin;
	}
	else
	{
		pwidth = GLOW_STD::max(minWidth, size+_hmargin+_hmargin);
		pheight = position-_spacing+_vmargin;
	}
	
	// Panel width
	int hnew = Width();
	if (hOption == forcedSize || hOption == expandPreferredSize)
	{
		hnew = hSize;
	}
	else if (hOption == preferredSize)
	{
		hnew = pwidth;
	}
	if (hnew < pwidth)
	{
		return hAutoPackError;
	}
	
	// Panel height
	int vnew = Height();
	if (vOption == forcedSize || vOption == expandPreferredSize)
	{
		vnew = vSize-topMargin;  // because of label
	}
	else if (vOption == preferredSize)
	{
		vnew = pheight;
	}
	if (vnew < pheight)
	{
		return vAutoPackError;
	}
	
	// Update size
	if (_arrangement == horizontal)
	{
		size = vnew-_vmargin-_vmargin;
	}
	else
	{
		size = hnew-_hmargin-_hmargin;
	}
	
	// Now align contents
	int i=0;
	for (GlowComponent* child = FirstChild(); child != 0; child = child->Next(), ++i)
	{
		GlowWidget* widget = dynamic_cast<GlowWidget*>(child);
		if (widget == 0 || widget == _label || !widget->IsVisible())
		{
			continue;
		}
		
		if (_arrangement == horizontal)
		{
			// Horizontal arrangement
			AutoPackOptions vOption = (_alignment & alignExpand) ?
				expandPreferredSize : preferredSize;
			
			if ((_alignment & 3) == alignBottom)
			{
				vOption |= bottomPos;
			}
			else if ((_alignment & 3) == alignCenter)
			{
				vOption |= centerPos;
			}
			else
			{
				vOption |= topPos;
			}
			widget->AutoPack(unspecifiedPos, unspecifiedPos,
				_vmargin, _vmargin+size, noMove | noReshape, vOption);
		}
		else
		{
			// Vertical arrangement
			AutoPackOptions hOption = (_alignment & alignExpand) ?
				expandPreferredSize : preferredSize;
			
			if ((_alignment & 3) == alignLeft)
			{
				hOption |= leftPos;
			}
			else if ((_alignment & 3) == alignCenter)
			{
				hOption |= centerPos;
			}
			else
			{
				hOption |= rightPos;
			}
			widget->AutoPack(_hmargin, _hmargin+size,
				unspecifiedPos, unspecifiedPos, hOption, noMove | noReshape);
		}
	}
	
	Reshape(hnew, vnew);
	
	return noAutoPackError;
}
Пример #28
0
GlowWidget::AutoPackError GlowQuickRadioGroupWidget::OnAutoPack(
	int hSize,
	int vSize,
	AutoPackOptions hOption,
	AutoPackOptions vOption,
	int& leftMargin,
	int& rightMargin,
	int& topMargin,
	int& bottomMargin)
{
	GLOW_DEBUGSCOPE("GlowQuickRadioGroupWidget::OnAutoPack");
	
	// Pack buttons
	int position = 0;
	int size = 0;
	for (GlowComponent* child = FirstChild(); child != 0; child = child->Next())
	{
		GlowRadioButtonWidget* button = dynamic_cast<GlowRadioButtonWidget*>(child);
		if (button != 0 && button->IsVisible() && !button->IsClosing())
		{
			if (_arrangement == GlowQuickPalette::horizontal)
			{
				button->AutoPack(position, unspecifiedPos, 0, unspecifiedPos,
					leftPos | preferredSize, topPos | preferredSize);
				if (size < button->Height())
				{
					size = button->Height();
				}
				position += button->Width()+_spacing;
			}
			else
			{
				button->AutoPack(0, unspecifiedPos, position, unspecifiedPos,
					leftPos | preferredSize, topPos | preferredSize);
				if (size < button->Width())
				{
					size = button->Width();
				}
				position += button->Height()+_spacing;
			}
		}
	}
	
	// Preferred width and height
	int pwidth = 0, pheight = 0;
	if (_arrangement == GlowQuickPalette::horizontal)
	{
		pwidth = position-_spacing;
		pheight = size;
	}
	else
	{
		pwidth = size;
		pheight = position-_spacing;
	}
	
	int hnew = Width();
	if (hSize != unspecifiedSize && hSize < pwidth)
	{
		return hAutoPackError;
	}
	if (hOption == forcedSize || hOption == expandPreferredSize)
	{
		hnew = hSize;
	}
	else if (hOption == preferredSize)
	{
		hnew = pwidth;
	}
	
	int vnew = Height();
	if (vSize != unspecifiedSize && vSize < pheight)
	{
		return vAutoPackError;
	}
	if (vOption == forcedSize || vOption == expandPreferredSize)
	{
		vnew = vSize;
	}
	else if (vOption == preferredSize)
	{
		vnew = pheight;
	}
	
	Reshape(hnew, vnew);
	
	return noAutoPackError;
}
Пример #29
0
bool XMLTransformationReader::readOperations(TiXmlElement* element, std::vector<DimensionDesc>& dimensions)
{
  const char *tagName = element->Value();
//  const char *name = element->Attribute("name");

  if (!tagName || strcmp("operations", tagName) != 0)
  {
    _log->error("Invalid tag '%v' for operations tag", tagName);

    return false;
  }

  for (TiXmlElement* cElement = element->FirstChildElement(); cElement; cElement = cElement->NextSiblingElement())
  {

    const char *child = cElement->Value();
    if (!child)
    {
      _log->error("Invalid child '%v' of operations", child);
      return nullptr;
    }
    else if (strcmp("dimension", child) == 0)
    {
      auto e = cElement->FirstChildElement();
      const char *eName = e->Value();

      DimensionDesc desc;
      desc.name = std::string(cElement->Attribute("name"));

      if (strcmp("use", eName) == 0)
      {
        desc.type = XMLDimensionOperations::XML_USE;
        desc.sourceId = std::stoi(e->Attribute("id"));
        desc.path = std::string(e->Attribute("path"));
      }
      else if (strcmp("default", eName) == 0)
      {
        desc.type = XMLDimensionOperations::XML_DEFAULT;
        desc.value = std::string(e->Attribute("value"));
      }
      else if (strcmp("formula", eName) == 0)
      {
        desc.type = XMLDimensionOperations::XML_FORMULA;
        desc.formula = std::string(e->Attribute("formula"));

	const auto fc = e->FirstChild();
	if (fc != nullptr) { /* If there are multiple variables defined */
          for (auto velem = fc; velem != nullptr; velem = velem->NextSiblingElement()) {
            auto e = velem->ToElement();
            desc.varmap[std::string(e->Attribute("name"))] =
              std::make_pair(std::string(e->Attribute("path")),
                             std::stoi(e->Attribute("id"))); 
          }
	} else {
          desc.varmap[std::string(e->Attribute("varname"))] =
            std::make_pair(std::string(e->Attribute("path")),
                           std::stoi(e->Attribute("id"))); 
	}
      }
      else if (strcmp("operations", eName) == 0)
      {
        desc.type = XMLDimensionOperations::XML_COMPLEX;
        bool result = this->readOperations(e, desc.dims);

        if (false == result)
          return false;
      }
      else
      {
        _log->warn("Unknown child '%v' in dimension '%v', will be ignored", child, desc.name);
      }

      dimensions.push_back(desc);
    }
  }

  return true;
}
Пример #30
0
Файл: tkBusy.c Проект: das/tk
static Busy *
CreateBusy(
    Tcl_Interp *interp,		/* Interpreter to report error to */
    Tk_Window tkRef)		/* Window hosting the busy window */
{
    Busy *busyPtr;
    int length, x, y;
    const char *fmt;
    char *name;
    Tk_Window tkBusy, tkChild, tkParent;
    Window parent;
    Tk_FakeWin *winPtr;

    busyPtr = (Busy *) ckalloc(sizeof(Busy));
    x = y = 0;
    length = strlen(Tk_Name(tkRef));
    name = ckalloc(length + 6);
    if (Tk_IsTopLevel(tkRef)) {
        fmt = "_Busy";		/* Child */
        tkParent = tkRef;
    } else {
        Tk_Window tkwin;

        fmt = "%s_Busy";	/* Sibling */
        tkParent = Tk_Parent(tkRef);
        for (tkwin = tkRef; (tkwin != NULL) && !Tk_IsTopLevel(tkwin);
                tkwin = Tk_Parent(tkwin)) {
            if (tkwin == tkParent) {
                break;
            }
            x += Tk_X(tkwin) + Tk_Changes(tkwin)->border_width;
            y += Tk_Y(tkwin) + Tk_Changes(tkwin)->border_width;
        }
    }
    for (tkChild = FirstChild(tkParent); tkChild != NULL;
            tkChild = NextChild(tkChild)) {
        Tk_MakeWindowExist(tkChild);
    }
    sprintf(name, fmt, Tk_Name(tkRef));
    tkBusy = Tk_CreateWindow(interp, tkParent, name, NULL);
    ckfree(name);

    if (tkBusy == NULL) {
        return NULL;
    }
    Tk_MakeWindowExist(tkRef);
    busyPtr->display = Tk_Display(tkRef);
    busyPtr->interp = interp;
    busyPtr->tkRef = tkRef;
    busyPtr->tkParent = tkParent;
    busyPtr->tkBusy = tkBusy;
    busyPtr->width = Tk_Width(tkRef);
    busyPtr->height = Tk_Height(tkRef);
    busyPtr->x = Tk_X(tkRef);
    busyPtr->y = Tk_Y(tkRef);
    busyPtr->cursor = None;
    Tk_SetClass(tkBusy, "Busy");
    busyPtr->optionTable = Tk_CreateOptionTable(interp, busyOptionSpecs);
    if (Tk_InitOptions(interp, (char *) busyPtr, busyPtr->optionTable,
                       tkBusy) != TCL_OK) {
        Tk_DestroyWindow(tkBusy);
        return NULL;
    }
    SetWindowInstanceData(tkBusy, busyPtr);
    winPtr = (Tk_FakeWin *) tkRef;

    TkpCreateBusy(winPtr, tkRef, &parent, tkParent, busyPtr);

    MakeTransparentWindowExist(tkBusy, parent);

    Tk_MoveResizeWindow(tkBusy, x, y, busyPtr->width, busyPtr->height);

    /*
     * Only worry if the busy window is destroyed.
     */

    Tk_CreateEventHandler(tkBusy, StructureNotifyMask, BusyEventProc,
                          busyPtr);

    /*
     * Indicate that the busy window's geometry is being managed. This will
     * also notify us if the busy window is ever packed.
     */

    Tk_ManageGeometry(tkBusy, &busyMgrInfo, busyPtr);
    if (busyPtr->cursor != None) {
        Tk_DefineCursor(tkBusy, busyPtr->cursor);
    }

    /*
     * Track the reference window to see if it is resized or destroyed.
     */

    Tk_CreateEventHandler(tkRef, StructureNotifyMask, RefWinEventProc,
                          busyPtr);
    return busyPtr;
}