<commit_before>/**
 * Appcelerator Titanium Mobile
 * Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */

#include "NativeScrollViewObject.h"
#include "TiEvent.h"
#include "TiEventContainerFactory.h"
#include "TiUIBase.h"
#include <bb/cascades/ScrollView>
#include <bb/cascades/ScrollViewProperties>
#include <bb/cascades/ScrollMode>
#include <bb/cascades/Container>
#include <bb/cascades/Button>
#include <bb/cascades/AbsoluteLayout>
#include <bb/cascades/LayoutUpdateHandler>

NativeScrollViewContentObject::NativeScrollViewContentObject(TiObject* tiObject, NativeScrollViewObject* scrollView)
	: NativeControlObject(tiObject, N_TYPE_VIEW)
{
 	setContainer(bb::cascades::Container::create());
 	scrollView_ = scrollView;
}

void NativeScrollViewContentObject::updateLayout(QRectF rect)
{
    NativeControlObject::updateLayout(rect);
    scrollView_->setContentWidthAndHeight(rect.width(), rect.height());
}
NativeScrollViewObject::NativeScrollViewObject(TiObject* tiObject)
    : NativeControlObject(tiObject, N_TYPE_SCROLL_VIEW)
{
    scrollView_ = NULL;
}

NativeScrollViewObject::~NativeScrollViewObject()
{
}

NativeScrollViewObject* NativeScrollViewObject::createScrollView(TiObject* tiObject)
{
   return new NativeScrollViewObject(tiObject);
}

NATIVE_TYPE NativeScrollViewObject::getObjectType() const
{
    return N_TYPE_SCROLL_VIEW;
}

int NativeScrollViewObject::setLayout(TiObject *obj)
{
	std::string str = *String::Utf8Value(obj->getValue());

	int err;
	if (str == "vertical" && !contentHeightSet_) {
		TiObject height;
		height.setValue(String::New("UI.SIZE"));
		err = contentViewProxy_->setHeight(&height);
	}

	if (str == "horizontal" && !contentWidthSet_) {
		TiObject width;
		width.setValue(String::New("UI.SIZE"));
		err = contentViewProxy_->setWidth(&width);
	}
	err = contentViewProxy_->setLayout(obj);
	return err;
}
void NativeScrollViewObject::setContentWidthAndHeight(float width, float height)
{
    contentSize_.setHeight(height);
    contentSize_.setWidth(width);

    if(contentSize_.width() > scrollViewSize_.width() && contentSize_.height() <= scrollViewSize_.height())
    {
    	scrollViewProperties_->setScrollMode(bb::cascades::ScrollMode::Horizontal);
    }<commit_msg>Initialize content height/width set flags to false.<commit_after>/**
 * Appcelerator Titanium Mobile
 * Copyright (c) 2009-2012 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */

#include "NativeScrollViewObject.h"
#include "TiEvent.h"
#include "TiEventContainerFactory.h"
#include "TiUIBase.h"
#include <bb/cascades/ScrollView>
#include <bb/cascades/ScrollViewProperties>
#include <bb/cascades/ScrollMode>
#include <bb/cascades/Container>
#include <bb/cascades/Button>
#include <bb/cascades/AbsoluteLayout>
#include <bb/cascades/LayoutUpdateHandler>

NativeScrollViewContentObject::NativeScrollViewContentObject(TiObject* tiObject, NativeScrollViewObject* scrollView)
	: NativeControlObject(tiObject, N_TYPE_VIEW)
{
 	setContainer(bb::cascades::Container::create());
 	scrollView_ = scrollView;
}

void NativeScrollViewContentObject::updateLayout(QRectF rect)
{
    NativeControlObject::updateLayout(rect);
    scrollView_->setContentWidthAndHeight(rect.width(), rect.height());
}

NativeScrollViewObject::NativeScrollViewObject(TiObject* tiObject)
    : NativeControlObject(tiObject, N_TYPE_SCROLL_VIEW)
    , contentWidthSet_(false)
    , contentHeightSet_(false)
{
    scrollView_ = NULL;
}

NativeScrollViewObject::~NativeScrollViewObject()
{
}

NativeScrollViewObject* NativeScrollViewObject::createScrollView(TiObject* tiObject)
{
   return new NativeScrollViewObject(tiObject);
}

NATIVE_TYPE NativeScrollViewObject::getObjectType() const
{
    return N_TYPE_SCROLL_VIEW;
}

int NativeScrollViewObject::setLayout(TiObject *obj)
{
	std::string str = *String::Utf8Value(obj->getValue());

	int err;
	if (str == "vertical" && !contentHeightSet_) {
		TiObject height;
		height.setValue(String::New("UI.SIZE"));
		err = contentViewProxy_->setHeight(&height);
	}

	if (str == "horizontal" && !contentWidthSet_) {
		TiObject width;
		width.setValue(String::New("UI.SIZE"));
		err = contentViewProxy_->setWidth(&width);
	}
	err = contentViewProxy_->setLayout(obj);

	return err;
}
void NativeScrollViewObject::setContentWidthAndHeight(float width, float height)
{
    contentSize_.setHeight(height);
    contentSize_.setWidth(width);

    if(contentSize_.width() > scrollViewSize_.width() && contentSize_.height() <= scrollViewSize_.height())
    {
    	scrollViewProperties_->setScrollMode(bb::cascades::ScrollMode::Horizontal);
    }
{'fraction_non_alphanumeric': 0.12243203984229094, 'fraction_numerical': 0.003735214774849554, 'mean_word_length': 6.761674718196457, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 31, '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': '7539874', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1477, 'n_words': 266}