<commit_before>/***********************************************************************************************************************
 * PanelBorderLayout.cpp
 *
 *  Created on: Dec 15, 2010
 *      Author: <NAME>
 **********************************************************************************************************************/

#include "layouts/PanelBorderLayout.h"

namespace Visualization {

ITEM_COMMON_DEFINITIONS( PanelBorderLayout )

PanelBorderLayout::PanelBorderLayout(Item* parent, const PanelBorderLayoutStyle* style) :
	Layout(parent, style), top_(new PanelLayout(this, &style->topStyle())), left_(NULL), bottom_(NULL), right_(NULL), content_(NULL)
{
}

PanelBorderLayout::~PanelBorderLayout()
{
	SAFE_DELETE_ITEM(top_);
	SAFE_DELETE_ITEM(left_);
	SAFE_DELETE_ITEM(bottom_);
	SAFE_DELETE_ITEM(right_);
	SAFE_DELETE_ITEM(content_);
}

void PanelBorderLayout::setPanel(bool enable, PanelLayout*& panel, const PanelLayoutStyle& style)
{
	if ( enable && !panel ) panel = new PanelLayout(this, &style);
	if ( !enable && panel ) SAFE_DELETE_ITEM(panel);
	setUpdateNeeded();
}

void PanelBorderLayout::setContent(Item* content, bool deleteOldContent)
{
	if ( deleteOldContent && content_ ) SAFE_DELETE_ITEM(content_);
	if ( content ) content->setParentItem(this);
	content_ = content;
	setUpdateNeeded();
}

bool PanelBorderLayout::isEmpty() const
{
	return ( top_ == NULL || top_->isEmpty())
			&& ( left_ == NULL || left_->isEmpty())
			&& ( content_ == NULL || content_->isEmpty())
			&& ( right_ == NULL || right_->isEmpty())
			&& ( bottom_ == NULL || bottom_->isEmpty());
}

void PanelBorderLayout::updateGeometry(int, int)
{
	// Get content size
	int contentWidth = content_ ? content_->width() : 0;
	int contentHeight = content_ ? content_->height() : 0;

	// Compute middle sizes
	int middleWidth = contentWidth + style()->leftInnerMargin() + style()->rightInnerMargin();
	if ( left_ && !style()->isLeftProtrusionFixed()) middleWidth += left_->width() / 2;
	if ( right_ ) middleWidth += right_->width() / 2;

	if (style()->isLeftProtrusionFixed())
	{
		int extra = (left_ ? left_->width() : 0) - style()->leftProtrusion();
		if (extra > 0) middleWidth += extra;
	}

	int maxMiddleWidth = middleWidth;
	if ( top_ && top_->width() > maxMiddleWidth ) maxMiddleWidth = top_->width();
	if ( bottom_ && bottom_->width() > maxMiddleWidth ) maxMiddleWidth = bottom_->width();

	if ( left_ && left_->height() > contentHeight ) contentHeight = left_->height();
	if ( right_ && right_->height() > contentHeight ) contentHeight = right_->height();

	//Adjust the size of the content if necessary
	if (content_ && content_->sizeDependsOnParent())
		content_->changeGeometry(contentWidth + (maxMiddleWidth - middleWidth), contentHeight);

	//Adjust panels and/or the inner size
	if ( maxMiddleWidth > middleWidth ) contentWidth += maxMiddleWidth - middleWidth;
	if ( top_ && maxMiddleWidth > top_->width() ) top_->changeGeometry(maxMiddleWidth, 0);
	if ( bottom_ && maxMiddleWidth > bottom_->width() ) bottom_->changeGeometry(maxMiddleWidth, 0);
	if ( left_ && contentHeight > left_->height() ) left_->changeGeometry(0, contentHeight);<commit_msg>Fixed a bug where some elements would not be updated as needed.<commit_after>/***********************************************************************************************************************
 * PanelBorderLayout.cpp
 *
 *  Created on: Dec 15, 2010
 *      Author: <NAME>
 **********************************************************************************************************************/

#include "layouts/PanelBorderLayout.h"

namespace Visualization {

ITEM_COMMON_DEFINITIONS( PanelBorderLayout )

PanelBorderLayout::PanelBorderLayout(Item* parent, const PanelBorderLayoutStyle* style) :
	Layout(parent, style), top_(new PanelLayout(this, &style->topStyle())), left_(NULL), bottom_(NULL), right_(NULL), content_(NULL)
{
}

PanelBorderLayout::~PanelBorderLayout()
{
	SAFE_DELETE_ITEM(top_);
	SAFE_DELETE_ITEM(left_);
	SAFE_DELETE_ITEM(bottom_);
	SAFE_DELETE_ITEM(right_);
	SAFE_DELETE_ITEM(content_);
}

void PanelBorderLayout::setPanel(bool enable, PanelLayout*& panel, const PanelLayoutStyle& style)
{
	if ( enable && !panel ) panel = new PanelLayout(this, &style);
	if ( !enable && panel ) SAFE_DELETE_ITEM(panel);
	setUpdateNeeded();
}

void PanelBorderLayout::setContent(Item* content, bool deleteOldContent)
{
	if ( deleteOldContent && content_ ) SAFE_DELETE_ITEM(content_);
	if ( content ) content->setParentItem(this);
	content_ = content;
	setUpdateNeeded();
}

bool PanelBorderLayout::isEmpty() const
{
	return ( top_ == NULL || top_->isEmpty())
			&& ( left_ == NULL || left_->isEmpty())
			&& ( content_ == NULL || content_->isEmpty())
			&& ( right_ == NULL || right_->isEmpty())
			&& ( bottom_ == NULL || bottom_->isEmpty());
}

void PanelBorderLayout::updateGeometry(int, int)
{
	// Reset the size of all components. We need to do this in situations like the following:
	// - Content gets resized and is now wider than top or bottom.
	//	- Content gets resized and is now a little less wide than before.
	// - The top or bottom are not automatically updated by the generic update mechanism
	// - The border on the right ends up staying where it is since top or bottom is still considered to be as large as before.
	if (top_) top_->changeGeometry(0,0);
	if (left_) left_->changeGeometry(0,0);
	if (content_) content_->changeGeometry(0,0);
	if (right_) right_->changeGeometry(0,0);
	if (bottom_) bottom_->changeGeometry(0,0);

	// Get content size
	int contentWidth = content_ ? content_->width() : 0;
	int contentHeight = content_ ? content_->height() : 0;

	// Compute middle sizes
	int middleWidth = contentWidth + style()->leftInnerMargin() + style()->rightInnerMargin();
	if ( left_ && !style()->isLeftProtrusionFixed()) middleWidth += left_->width() / 2;
	if ( right_ ) middleWidth += right_->width() / 2;

	if (style()->isLeftProtrusionFixed())
	{
		int extra = (left_ ? left_->width() : 0) - style()->leftProtrusion();
		if (extra > 0) middleWidth += extra;
	}

	int maxMiddleWidth = middleWidth;
	if ( top_ && top_->width() > maxMiddleWidth ) maxMiddleWidth = top_->width();
	if ( bottom_ && bottom_->width() > maxMiddleWidth ) maxMiddleWidth = bottom_->width();

	if ( left_ && left_->height() > contentHeight ) contentHeight = left_->height();
	if ( right_ && right_->height() > contentHeight ) contentHeight = right_->height();

	//Adjust the size of the content if necessary
	if (content_ && content_->sizeDependsOnParent())
		content_->changeGeometry(contentWidth + (maxMiddleWidth - middleWidth), contentHeight);

	//Adjust panels and/or the inner size
	if ( maxMiddleWidth > middleWidth ) contentWidth += maxMiddleWidth - middleWidth;
	if ( top_ && maxMiddleWidth > top_->width() ) top_->changeGeometry(maxMiddleWidth, 0);
	if ( bottom_ && maxMiddleWidth > bottom_->width() ) bottom_->changeGeometry(maxMiddleWidth, 0);
	if ( left_ && contentHeight > left_->height() ) left_->changeGeometry(0, contentHeight);
{'fraction_non_alphanumeric': 0.20370898716119828, 'fraction_numerical': 0.005706134094151213, 'mean_word_length': 5.583098591549295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 94, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6535105', 'n_tokens_mistral': 2063, 'n_tokens_neox': 1967, 'n_words': 519}