<commit_before>#include "pch.h"
#include "Core\Event.h"
#include "Systems\UILayoutSystem.h"

#include "Components\UIPanelComponent.h"
#include "Components\BoundsComponent.h"
#include "Components\ScreenPositionComponent.h"

using namespace Windows::ApplicationModel;

using namespace PinnedDownClient::Systems;
using namespace PinnedDownClient::Components;

UILayoutSystem::UILayoutSystem()
{
}

void UILayoutSystem::InitSystem(std::shared_ptr<PinnedDownClient::GameInfrastructure> game)
{
	GameSystem::InitSystem(game);

	this->uiFactory = std::make_shared<UIFactory>(game);

	this->game->eventManager->AddListener(std::shared_ptr<IEventListener>(this), AppWindowChangedEvent::AppWindowChangedEventType);
	this->game->eventManager->AddListener(std::shared_ptr<IEventListener>(this), AppWindowSizeChangedEvent::AppWindowSizeChangedEventType);
	this->game->eventManager->AddListener(std::shared_ptr<IEventListener>(this), EntityInitializedEvent::EntityInitializedEventType);

	this->CreateRootPanel();
}

void UILayoutSystem::CreateRootPanel()
{
	// Create panel entity.
	int entityId = this->uiFactory->CreatePanel();
	this->uiFactory->FinishUIWidget(entityId);

	// Set root panel.
	Panel panel = Panel();
	panel.entityId = entityId;
	panel.boundsComponent = this->game->entityManager->GetComponent<BoundsComponent>(entityId, BoundsComponent::BoundsComponentType);
	panel.screenPositionComponent = this->game->entityManager->GetComponent<ScreenPositionComponent>(entityId, ScreenPositionComponent::ScreenPositionComponentType);
	this->rootPanel = panel;
}

void UILayoutSystem::OnEvent(Event & newEvent)
{
	if (newEvent.GetEventType() == AppWindowChangedEvent::AppWindowChangedEventType)
	{
		AppWindowChangedEvent appWindowChangedEvent = static_cast<AppWindowChangedEvent&>(newEvent);
		this->OnAppWindowChanged(appWindowChangedEvent);
	}
	else if (newEvent.GetEventType() == AppWindowSizeChangedEvent::AppWindowSizeChangedEventType)
	{
		AppWindowSizeChangedEvent appWindowSizeChangedEvent = static_cast<AppWindowSizeChangedEvent&>(newEvent);
		this->OnAppWindowSizeChanged(appWindowSizeChangedEvent);
	}
	else if (newEvent.GetEventType() == EntityInitializedEvent::EntityInitializedEventType)
	{
		EntityInitializedEvent entityInitializedEvent = static_cast<EntityInitializedEvent&>(newEvent);
		this->OnEntityInitialized(entityInitializedEvent);
	}
	else if (newEvent.GetEventType() == EntityRemovedEvent::EntityRemovedEventType)
	{
		EntityRemovedEvent entityRemovedEvent = static_cast<EntityRemovedEvent&>(newEvent);
		this->OnEntityRemoved(entityRemovedEvent);
	}
}

void UILayoutSystem::OnAppWindowChanged(AppWindowChangedEvent appWindowChangedEvent)
{
	// Resize root panel.
	auto window = appWindowChangedEvent.appWindow;
	auto newSize = Vector2F(window->Bounds.Width, window->Bounds.Height);
	this->ResizeRootPanel(newSize);
}

void UILayoutSystem::OnAppWindowSizeChanged(AppWindowSizeChangedEvent appWindowSizeChangedEvent)
{
	// Resize root panel.
	auto newSize = appWindowSizeChangedEvent.size;
	this->ResizeRootPanel(newSize);
}

void UILayoutSystem::OnEntityInitialized(EntityInitializedEvent entityInitializedEvent)
{
	auto entityId = entityInitializedEvent.entityId;
	auto anchorComponent = this->game->entityManager->GetComponent<UIAnchorComponent>(entityId, UIAnchorComponent::UIAnchorComponentType);
	auto boundsComponent = this->game->entityManager->GetComponent<BoundsComponent>(entityId, BoundsComponent::BoundsComponentType);
	auto screenPositionComponent = this->game->entityManager->GetComponent<ScreenPositionComponent>(entityId, ScreenPositionComponent::ScreenPositionComponentType);

	if (anchorComponent != nullptr
		&& boundsComponent != nullptr
		&& screenPositionComponent != nullptr)
	{
		// Add anchor.
		Anchor anchor = Anchor();
		anchor.entityId = entityId;
		anchor.anchorComponent = anchorComponent;
		anchor.boundsComponent = boundsComponent;
		anchor.screenPositionComponent = screenPositionComponent;

		this->anchors.push_back(anchor);
	}
}

void UILayoutSystem::OnEntityRemoved(EntityRemovedEvent entityRemovedEvent)
{
	// Remove anchor.
	for (std::list<Anchor>::iterator iterator = this->anchors.begin(); iterator != this->anchors.end(); ++iterator)
	{
		Anchor& anchor = *iterator;

		if (anchor.entityId == entityRemovedEvent.entityId)
		{
			this->anchors.erase(iterator);
			return;
		}
	}
}

void UILayoutSystem::Update(StepTimer const& timer)
{
	// Update anchors.
	for (std::list<Anchor>::iterator iterator = this->anchors.begin(); iterator != this->anchors.end(); iterator++)
	{
		Anchor& anchor = *iterator;

		HorizontalAnchor& left = anchor.anchorComponent->left;
		VerticalAnchor& top = anchor.anchorComponent->top;

		auto x = 0.0f;
		auto y = 0.0f;

		// Check for anchor target.
		std::shared_ptr<ScreenPositionComponent> targetPosition;
		std::shared_ptr<BoundsComponent> targetBounds;

		if (anchor.anchorComponent->target != 0)
		{
			targetPosition = this->game->entityManager->GetComponent<ScreenPositionComponent>(anchor.anchorComponent->target, ScreenPositionComponent::ScreenPositionComponentType);
			targetBounds = this->game->entityManager->GetComponent<BoundsComponent>(anchor.anchorComponent->target, BoundsComponent::BoundsComponentType);
		}
		else
		{
			targetPosition = this->rootPanel.screenPositionComponent;
			targetBounds = this->rootPanel.boundsComponent;
		}

		// Consider position.
		x += targetPosition->position.x;
		y += targetPosition->position.y;

		// Consider bounds.
		if (left.type == HorizontalAnchorType::Right)
		{
			x += targetBounds->bounds.x - anchor.boundsComponent->bounds.x;
		}
		else if (left.type == HorizontalAnchorType::HorizontalCenter)
		{
			x += (targetBounds->bounds.x - anchor.boundsComponent->bounds.x) / 2;
		}

		if (top.type == VerticalAnchorType::Bottom)
		{
			y += targetBounds->bounds.y - anchor.boundsComponent->bounds.y;
		}
		else if (top.type == VerticalAnchorType::VerticalCenter)
		{
			y += (targetBounds->bounds.y - anchor.boundsComponent->bounds.y) / 2;
		}

		// Add relative offset.
		x += left.offset;
		y += top.offset;

		// Update screen position.
		anchor.screenPositionComponent->position = Vector2F(x, y);
	}
}

void UILayoutSystem::ResizeRootPanel(Vector2F newSize)
{
	this->rootPanel.boundsComponent->bounds = newSize;
}<commit_msg>FIXED: UI - Layout system correctly removes anchors whose entities have been removed.<commit_after>#include "pch.h"
#include "Core\Event.h"
#include "Systems\UILayoutSystem.h"

#include "Components\UIPanelComponent.h"
#include "Components\BoundsComponent.h"
#include "Components\ScreenPositionComponent.h"

using namespace Windows::ApplicationModel;

using namespace PinnedDownClient::Systems;
using namespace PinnedDownClient::Components;

UILayoutSystem::UILayoutSystem()
{
}

void UILayoutSystem::InitSystem(std::shared_ptr<PinnedDownClient::GameInfrastructure> game)
{
	GameSystem::InitSystem(game);

	this->uiFactory = std::make_shared<UIFactory>(game);

	this->game->eventManager->AddListener(std::shared_ptr<IEventListener>(this), AppWindowChangedEvent::AppWindowChangedEventType);
	this->game->eventManager->AddListener(std::shared_ptr<IEventListener>(this), AppWindowSizeChangedEvent::AppWindowSizeChangedEventType);
	this->game->eventManager->AddListener(std::shared_ptr<IEventListener>(this), EntityInitializedEvent::EntityInitializedEventType);
	this->game->eventManager->AddListener(std::shared_ptr<IEventListener>(this), EntityRemovedEvent::EntityRemovedEventType);

	this->CreateRootPanel();
}

void UILayoutSystem::CreateRootPanel()
{
	// Create panel entity.
	int entityId = this->uiFactory->CreatePanel();
	this->uiFactory->FinishUIWidget(entityId);

	// Set root panel.
	Panel panel = Panel();
	panel.entityId = entityId;
	panel.boundsComponent = this->game->entityManager->GetComponent<BoundsComponent>(entityId, BoundsComponent::BoundsComponentType);
	panel.screenPositionComponent = this->game->entityManager->GetComponent<ScreenPositionComponent>(entityId, ScreenPositionComponent::ScreenPositionComponentType);
	this->rootPanel = panel;
}

void UILayoutSystem::OnEvent(Event & newEvent)
{
	if (newEvent.GetEventType() == AppWindowChangedEvent::AppWindowChangedEventType)
	{
		AppWindowChangedEvent appWindowChangedEvent = static_cast<AppWindowChangedEvent&>(newEvent);
		this->OnAppWindowChanged(appWindowChangedEvent);
	}
	else if (newEvent.GetEventType() == AppWindowSizeChangedEvent::AppWindowSizeChangedEventType)
	{
		AppWindowSizeChangedEvent appWindowSizeChangedEvent = static_cast<AppWindowSizeChangedEvent&>(newEvent);
		this->OnAppWindowSizeChanged(appWindowSizeChangedEvent);
	}
	else if (newEvent.GetEventType() == EntityInitializedEvent::EntityInitializedEventType)
	{
		EntityInitializedEvent entityInitializedEvent = static_cast<EntityInitializedEvent&>(newEvent);
		this->OnEntityInitialized(entityInitializedEvent);
	}
	else if (newEvent.GetEventType() == EntityRemovedEvent::EntityRemovedEventType)
	{
		EntityRemovedEvent entityRemovedEvent = static_cast<EntityRemovedEvent&>(newEvent);
		this->OnEntityRemoved(entityRemovedEvent);
	}
}

void UILayoutSystem::OnAppWindowChanged(AppWindowChangedEvent appWindowChangedEvent)
{
	// Resize root panel.
	auto window = appWindowChangedEvent.appWindow;
	auto newSize = Vector2F(window->Bounds.Width, window->Bounds.Height);
	this->ResizeRootPanel(newSize);
}

void UILayoutSystem::OnAppWindowSizeChanged(AppWindowSizeChangedEvent appWindowSizeChangedEvent)
{
	// Resize root panel.
	auto newSize = appWindowSizeChangedEvent.size;
	this->ResizeRootPanel(newSize);
}

void UILayoutSystem::OnEntityInitialized(EntityInitializedEvent entityInitializedEvent)
{
	auto entityId = entityInitializedEvent.entityId;
	auto anchorComponent = this->game->entityManager->GetComponent<UIAnchorComponent>(entityId, UIAnchorComponent::UIAnchorComponentType);
	auto boundsComponent = this->game->entityManager->GetComponent<BoundsComponent>(entityId, BoundsComponent::BoundsComponentType);
	auto screenPositionComponent = this->game->entityManager->GetComponent<ScreenPositionComponent>(entityId, ScreenPositionComponent::ScreenPositionComponentType);

	if (anchorComponent != nullptr
		&& boundsComponent != nullptr
		&& screenPositionComponent != nullptr)
	{
		// Add anchor.
		Anchor anchor = Anchor();
		anchor.entityId = entityId;
		anchor.anchorComponent = anchorComponent;
		anchor.boundsComponent = boundsComponent;
		anchor.screenPositionComponent = screenPositionComponent;

		this->anchors.push_back(anchor);
	}
}

void UILayoutSystem::OnEntityRemoved(EntityRemovedEvent entityRemovedEvent)
{
	// Remove anchor.
	for (std::list<Anchor>::iterator iterator = this->anchors.begin(); iterator != this->anchors.end(); ++iterator)
	{
		Anchor& anchor = *iterator;

		if (anchor.entityId == entityRemovedEvent.entityId)
		{
			this->anchors.erase(iterator);
			return;
		}
	}
}

void UILayoutSystem::Update(StepTimer const& timer)
{
	// Update anchors.
	for (std::list<Anchor>::iterator iterator = this->anchors.begin(); iterator != this->anchors.end(); iterator++)
	{
		Anchor& anchor = *iterator;

		HorizontalAnchor& left = anchor.anchorComponent->left;
		VerticalAnchor& top = anchor.anchorComponent->top;

		auto x = 0.0f;
		auto y = 0.0f;

		// Check for anchor target.
		std::shared_ptr<ScreenPositionComponent> targetPosition;
		std::shared_ptr<BoundsComponent> targetBounds;

		if (anchor.anchorComponent->target != 0)
		{
			targetPosition = this->game->entityManager->GetComponent<ScreenPositionComponent>(anchor.anchorComponent->target, ScreenPositionComponent::ScreenPositionComponentType);
			targetBounds = this->game->entityManager->GetComponent<BoundsComponent>(anchor.anchorComponent->target, BoundsComponent::BoundsComponentType);
		}
		else
		{
			targetPosition = this->rootPanel.screenPositionComponent;
			targetBounds = this->rootPanel.boundsComponent;
		}

		// Consider position.
		x += targetPosition->position.x;
		y += targetPosition->position.y;

		// Consider bounds.
		if (left.type == HorizontalAnchorType::Right)
		{
			x += targetBounds->bounds.x - anchor.boundsComponent->bounds.x;
		}
		else if (left.type == HorizontalAnchorType::HorizontalCenter)
		{
			x += (targetBounds->bounds.x - anchor.boundsComponent->bounds.x) / 2;
		}

		if (top.type == VerticalAnchorType::Bottom)
		{
			y += targetBounds->bounds.y - anchor.boundsComponent->bounds.y;
		}
		else if (top.type == VerticalAnchorType::VerticalCenter)
		{
			y += (targetBounds->bounds.y - anchor.boundsComponent->bounds.y) / 2;
		}

		// Add relative offset.
		x += left.offset;
		y += top.offset;

		// Update screen position.
		anchor.screenPositionComponent->position = Vector2F(x, y);
	}
}

void UILayoutSystem::ResizeRootPanel(Vector2F newSize)
{
	this->rootPanel.boundsComponent->bounds = newSize;
}<|endoftext|>


<commit_before>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    itkAzimuthElevationToCartesianTransformTest.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

Copyright (c) 2001 Insight Consortium
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.

 * Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

 * The name of the Insight Consortium, nor the names of any consortium members,
   nor of any contributors, may be used to endorse or promote products derived
   from this software without specific prior written permission.

  * Modified source versions must be plainly marked as such, and must not be
    misrepresented as being the original software.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=========================================================================*/

#include <iostream>

#include "itkAzimuthElevationToCartesianTransform.h"

typedef  itk::Point<double,3>   PointType;

void PrintPoint( const PointType & p )
{
  for( unsigned int i=0; i<PointType::PointDimension; i++)
  {
    std::cout << p[i] << ", ";
  }
  std::cout << std::endl;
}

int main(
    int argc,
    char *argv[])
{

    const double ACCEPTABLE_ERROR = 1E-10;

    typedef itk::RT3DTransform<> RT3DTransformType;

    RT3DTransformType::Pointer transform = RT3DTransformType::New();
    transform->SetRT3DParameters(1,5,45,45);
    PointType p;
    p[0] = 3;
    p[1] = 3;
    p[2] = 25;

    std::cout<< "original values of (theta,phi,r) p = "<<std::endl;
    PrintPoint(p);

    transform->SetForwardAzimuthElevationToCartesian();

    PointType answer = transform->TransformPoint(p);
    PrintPoint(answer);

    PointType answerBackwards = transform->BackTransformPoint(answer);
    PrintPoint(answerBackwards);

    transform->SetForwardCartesianToAzimuthElevation();
    PointType reverseDirectionAnswer = transform->BackTransformPoint(answerBackwards);
    PrintPoint(reverseDirectionAnswer);

    PointType reverseDirectionAnswerBackwards = transform->TransformPoint(reverseDirectionAnswer);
    PrintPoint(reverseDirectionAnswerBackwards);
    transform->Print(std::cout);

    bool same=true;
    for (unsigned int i=0; i < p.PointDimension && same; i++)
      {
      same = ((abs(p[i] - answerBackwards[i]) < ACCEPTABLE_ERROR) &&
      (abs(p[i] - reverseDirectionAnswerBackwards[i]) < ACCEPTABLE_ERROR) &&
      (abs(answer[i] - reverseDirectionAnswer[i]) < ACCEPTABLE_ERROR)) ;
      }
    if (!same)
      {
      std::cout << "itkRT3DTransformTest failed" <<std::endl;
      return EXIT_FAILURE;
      }
    std::cout << "itkRT3DTransformTest passed" <<std::endl;
    return EXIT_SUCCESS;
}
<commit_msg>FIX: Fixed test to reflect name change of RT3D to AzimuthElevationToCartesian<commit_after>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    itkAzimuthElevationToCartesianTransformTest.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

Copyright (c) 2001 Insight Consortium
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.

 * Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

 * The name of the Insight Consortium, nor the names of any consortium members,
   nor of any contributors, may be used to endorse or promote products derived
   from this software without specific prior written permission.

  * Modified source versions must be plainly marked as such, and must not be
    misrepresented as being the original software.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=========================================================================*/

#include <iostream>

#include "itkAzimuthElevationToCartesianTransform.h"

typedef  itk::Point<double,3>   PointType;

void PrintPoint( const PointType & p )
{
  for( unsigned int i=0; i<PointType::PointDimension; i++)
  {
    std::cout << p[i] << ", ";
  }
  std::cout << std::endl;
}

int main(
    int argc,
    char *argv[])
{

    const double ACCEPTABLE_ERROR = 1E-10;

    typedef itk::AzimuthElevationToCartesianTransform<> AzimuthElevationToCartesianTransformType;

    AzimuthElevationToCartesianTransformType::Pointer transform = AzimuthElevationToCartesianTransformType::New();
    transform->SetAzimuthElevationToCartesianParameters(1,5,45,45);
    PointType p;
    p[0] = 3;
    p[1] = 3;
    p[2] = 25;

    std::cout<< "original values of (theta,phi,r) p = "<<std::endl;
    PrintPoint(p);

    transform->SetForwardAzimuthElevationToCartesian();

    PointType answer = transform->TransformPoint(p);
    PrintPoint(answer);

    PointType answerBackwards = transform->BackTransformPoint(answer);
    PrintPoint(answerBackwards);

    transform->SetForwardCartesianToAzimuthElevation();
    PointType reverseDirectionAnswer = transform->BackTransformPoint(answerBackwards);
    PrintPoint(reverseDirectionAnswer);

    PointType reverseDirectionAnswerBackwards = transform->TransformPoint(reverseDirectionAnswer);
    PrintPoint(reverseDirectionAnswerBackwards);
    transform->Print(std::cout);

    bool same=true;
    for (unsigned int i=0; i < p.PointDimension && same; i++)
      {
      same = ((abs(p[i] - answerBackwards[i]) < ACCEPTABLE_ERROR) &&
      (abs(p[i] - reverseDirectionAnswerBackwards[i]) < ACCEPTABLE_ERROR) &&
      (abs(answer[i] - reverseDirectionAnswer[i]) < ACCEPTABLE_ERROR)) ;
      }
    if (!same)
      {
      std::cout << "itkAzimuthElevationToCartesianTransformTest failed" <<std::endl;
      return EXIT_FAILURE;
      }
    std::cout << "itkAzimuthElevationToCartesianTransformTest passed" <<std::endl;
    return EXIT_SUCCESS;
}
<|endoftext|>


<commit_before>/****************************************************************************
 *
 * Copyright 2018 Samsung Electronics All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 *
 ****************************************************************************/

#include "libcxx_tc_common.h"
#include "tc_thread.hpp"

extern "C"
{
	int tc_thread_main(void)
	{
		tc_libcxx_thread_thread_lock_algorithm_lock();
		tc_libcxx_thread_thread_lock_algorithm_try_lock();
		tc_libcxx_thread_thread_lock_guard_adopt_lock();
		tc_libcxx_thread_thread_lock_guard_mutex();
		tc_libcxx_thread_thread_lock_guard_types();
		tc_libcxx_thread_thread_lock_unique_cons_default();
		tc_libcxx_thread_thread_lock_unique_cons_move_assign();
		tc_libcxx_thread_thread_lock_unique_cons_move_ctor();
		tc_libcxx_thread_thread_lock_unique_cons_mutex();
		tc_libcxx_thread_thread_lock_unique_cons_mutex_adopt_lock();
		tc_libcxx_thread_thread_lock_unique_cons_mutex_defer_lock();
		tc_libcxx_thread_thread_lock_unique_cons_mutex_duration();
		tc_libcxx_thread_thread_lock_unique_cons_mutex_time_point();
		tc_libcxx_thread_thread_lock_unique_cons_mutex_try_to_lock();
		tc_libcxx_thread_thread_lock_unique_locking_lock();
		tc_libcxx_thread_thread_lock_unique_locking_try_lock();
		tc_libcxx_thread_thread_lock_unique_locking_try_lock_for();
		tc_libcxx_thread_thread_lock_unique_locking_try_lock_until();
		tc_libcxx_thread_thread_lock_unique_locking_unlock();
		tc_libcxx_thread_thread_lock_unique_mod_member_swap();
		tc_libcxx_thread_thread_lock_unique_mod_nonmember_swap();
		tc_libcxx_thread_thread_lock_unique_mod_release();
		tc_libcxx_thread_thread_lock_unique_obs_mutex();
		tc_libcxx_thread_thread_lock_unique_obs_op_bool();
		tc_libcxx_thread_thread_lock_unique_obs_owns_lock();
		tc_libcxx_thread_thread_lock_unique_types();
		tc_libcxx_thread_thread_lock_types();
		tc_libcxx_thread_thread_mutex_class_default();
		tc_libcxx_thread_thread_mutex_class_lock();
		tc_libcxx_thread_thread_mutex_class_try_lock();
		tc_libcxx_thread_thread_mutex_recursive_default();
		tc_libcxx_thread_thread_mutex_recursive_lock();
		tc_libcxx_thread_thread_mutex_recursive_try_lock();
		tc_libcxx_thread_thread_timedmutex_class_default();
		tc_libcxx_thread_thread_timedmutex_class_lock();
		tc_libcxx_thread_thread_timedmutex_class_try_lock();
		tc_libcxx_thread_thread_timedmutex_class_try_lock_for();
		tc_libcxx_thread_thread_timedmutex_class_try_lock_until();
		tc_libcxx_thread_thread_timedmutex_recursive_default();
		tc_libcxx_thread_thread_timedmutex_recursive_lock();
		tc_libcxx_thread_thread_timedmutex_recursive_try_lock();
		tc_libcxx_thread_thread_timedmutex_recursive_try_lock_for();
		tc_libcxx_thread_thread_timedmutex_recursive_try_lock_until();
		tc_libcxx_thread_thread_once_callonce_call_once();
		tc_libcxx_thread_thread_once_onceflag_default();
		return 0;
	}
}
<commit_msg>external/libcxx-test: Update Thread Testcases<commit_after>/****************************************************************************
 *
 * Copyright 2018 Samsung Electronics All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 *
 ****************************************************************************/

#include "libcxx_tc_common.h"
#include "tc_thread.hpp"

extern "C"
{
	int tc_thread_main(void)
	{
		tc_libcxx_thread_thread_lock_algorithm_lock();
		tc_libcxx_thread_thread_lock_algorithm_try_lock();
		tc_libcxx_thread_thread_lock_guard_adopt_lock();
		tc_libcxx_thread_thread_lock_guard_mutex();
		tc_libcxx_thread_thread_lock_guard_types();
		tc_libcxx_thread_thread_lock_unique_cons_default();
		tc_libcxx_thread_thread_lock_unique_cons_move_assign();
		tc_libcxx_thread_thread_lock_unique_cons_move_ctor();
		tc_libcxx_thread_thread_lock_unique_cons_mutex();
		tc_libcxx_thread_thread_lock_unique_cons_mutex_adopt_lock();
		tc_libcxx_thread_thread_lock_unique_cons_mutex_defer_lock();
		tc_libcxx_thread_thread_lock_unique_cons_mutex_duration();
		tc_libcxx_thread_thread_lock_unique_cons_mutex_time_point();
		tc_libcxx_thread_thread_lock_unique_locking_lock();
		tc_libcxx_thread_thread_lock_unique_locking_try_lock();
		tc_libcxx_thread_thread_lock_unique_locking_try_lock_for();
		tc_libcxx_thread_thread_lock_unique_locking_try_lock_until();
		tc_libcxx_thread_thread_lock_unique_locking_unlock();
		tc_libcxx_thread_thread_lock_unique_mod_member_swap();
		tc_libcxx_thread_thread_lock_unique_mod_nonmember_swap();
		tc_libcxx_thread_thread_lock_unique_mod_release();
		tc_libcxx_thread_thread_lock_unique_obs_mutex();
		tc_libcxx_thread_thread_lock_unique_obs_op_bool();
		tc_libcxx_thread_thread_lock_unique_obs_owns_lock();
		tc_libcxx_thread_thread_lock_unique_types();
		tc_libcxx_thread_thread_lock_types();
		tc_libcxx_thread_thread_mutex_class_default();
		tc_libcxx_thread_thread_mutex_class_lock();
		tc_libcxx_thread_thread_mutex_recursive_default();
		tc_libcxx_thread_thread_mutex_recursive_lock();
		tc_libcxx_thread_thread_timedmutex_class_default();
		tc_libcxx_thread_thread_timedmutex_class_lock();
		tc_libcxx_thread_thread_timedmutex_class_try_lock_for();
		tc_libcxx_thread_thread_timedmutex_class_try_lock_until();
		tc_libcxx_thread_thread_timedmutex_recursive_default();
		tc_libcxx_thread_thread_timedmutex_recursive_lock();
		tc_libcxx_thread_thread_timedmutex_recursive_try_lock_for();
		tc_libcxx_thread_thread_timedmutex_recursive_try_lock_until();
		tc_libcxx_thread_thread_once_callonce_call_once();
		tc_libcxx_thread_thread_once_onceflag_default();
		return 0;
	}
}
<|endoftext|>


<commit_before>/* For lseek64() */
#define _LARGEFILE64_SOURCE

#include <cstdio> // DEBUG

#include <limits.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

#include <mycpp/native_file.h>
#include <mycpp/util.h>
#include <mycpp/io.h>

#define DEBUG(a) ;

namespace MyCpp {

IOResult
NativeFile::read (MemoryDesc const &mem,
		  Size *nread)
    throw (IOException,
	   InternalException)
{
    if (nread != NULL)
	*nread = 0;

    if (mem.getMemory () == NULL ||
	mem.getLength () == 0)
    {
	DEBUG (
	    fprintf (stderr, "MyCpp.NativeFile.read: no destination\n");
	    fflush (stderr);
	)
	return IOResultNormal;
    }

    ssize_t ret;

    /* According to POSIX, if we pass a value larger than SSIZE_MAX
     * to read, then the result is implementation-defined. */
    Size len;
    if (mem.getLength () > SSIZE_MAX)
	len = SSIZE_MAX;
    else
	len = mem.getLength ();

    rw_lock.readerLock ();
    if (fd == -1) {
	rw_lock.readerUnlock ();
	throw InternalException ();
    }

    abortIf ((Size) (size_t) len != len);
    DEBUG (
	fprintf (stderr, "MyCpp.NativeFile.read: len: %lu\n", (unsigned long) len);
	fflush (stderr);
    )
    ret = ::read (fd, mem.getMemory (), (size_t) len);
    rw_lock.readerUnlock ();

    if (ret == -1) {
	if (errno == EINTR)
	    return IOResultNormal;

	throw IOException (errnoToString (errno));
    } else
    if (ret < 0) {
	throw IOException ();
    } else
    if (ret == 0) {
	return IOResultEof;
    }

    if ((Size) ret > len)
	throw InternalException (String::forData ("Unexpectedly large return value from read()"));

    if (nread != NULL)
	*nread = (Size) ret;

    return IOResultNormal;
}

IOResult
NativeFile::write (ConstMemoryDesc const &mem,
		   Size *nwritten)
    throw (IOException,
	   InternalException)
{
    if (nwritten != NULL)
	*nwritten = 0;

    if (mem.getMemory () == NULL ||
	mem.getLength () == 0)
    {
	return IOResultNormal;
    }

    ssize_t ret;

    /* According to POSIX, if we pass a value larger than SSIZE_MAX
     * to write, then the result is implementation-defined. */
    Size len;
    if (mem.getLength () > SSIZE_MAX)
	len = SSIZE_MAX;
    else
	len = mem.getLength ();

    rw_lock.readerLock ();
    if (fd == -1) {
	rw_lock.readerUnlock ();
	throw InternalException ();
    }

    abortIf ((Size) (size_t) len != len);
    ret = ::write (fd, mem.getMemory (), (size_t) len);
    rw_lock.readerUnlock ();

    if (ret == -1) {
	if (errno == EINTR)
	    return IOResultNormal;

	if (errno == EPIPE)
	    return IOResultEof;

      /* DEBUG */
	errf->print ("MyCpp.NativeFile.write_raw: ret == -1").pendl ();
      /* (DEBUG) */

	throw IOException (errnoToString (errno));
    } else
    if (ret < 0) {
      /* DEBUG */
	errf->print ("MyCpp.NativeFile.write_raw: ret < 0").pendl ();
      /* (DEBUG) */

	throw IOException ();
    }

    if ((Size) ret > len)
	throw InternalException (String::forData ("Unexpectedly large return value from write()"));

    if (nwritten != NULL)
	*nwritten = (Size) ret;

    return IOResultNormal;
}

void
NativeFile::seek (Int64      offset,
		  SeekOrigin origin)
    throw (IOException,
	   InternalException)
{
    int whence = 0;

    switch (origin) {
    case SeekOrigin::SeekBeg:
	whence = SEEK_SET;
	break;
    case SeekOrigin::SeekCur:
	whence = SEEK_CUR;
	break;
    case SeekOrigin::SeekEnd:
	whence = SEEK_END;
	break;
    }

    rw_lock.readerLock ();
    if (fd == -1) {
	rw_lock.readerUnlock ();
	throw InternalException ();
    }

    /* NOTE: lseek64() seems to be glibc-specific. */
    if (lseek64 (fd, (off64_t) offset, whence) == (off64_t) -1) {
	rw_lock.readerUnlock ();
	throw IOException (errnoToString (errno));
    }
    rw_lock.readerUnlock ();
}

Uint64
NativeFile::tell ()
    throw (InternalException)
{
    off_t ret;

    rw_lock.readerLock ();
    if (fd == -1) {
	rw_lock.readerUnlock ();
	throw InternalException ();
    }

    /* I couldn't find a suitable syscall to read file offset
     * as an unsigned 64-bit number. Hence, there is no way
     * of reading really large file offsets. We are limited
     * by Int64 type, not Uint64. */
    ret = lseek (fd, 0, SEEK_CUR);
    rw_lock.readerUnlock ();

    if (ret == (off_t) -1)
	throw InternalException (errnoToString (errno));

    if (ret < 0)
	throw InternalException (
		String::forPrintTask (
		    (Pr ("Unexpected return value from lseek(): "))
		    (Pr ((long long) ret))));

    Uint64 ret64 = (Uint64) ret;

    /* Uint64 must be able to hold any value of type 'off_t',
     * or at least the file position should not be too large if one
     * wants to get it with MyCpp.NativeFile.tell() . */
    if ((off_t) ret64 != ret)
	throw InternalException (
		String::forData ("Integer overflow"));

    return ret64;
}

void
NativeFile::flush ()
    throw (IOException,
	   InternalException)
{
    /* Nothing to do here. */
}

void
NativeFile::sync ()
    throw (IOException,
	   InternalException)
{
    do {
	int ret;

	rw_lock.readerLock ();
	if (fd == -1) {
	    rw_lock.readerUnlock ();
	    throw InternalException ();
	}

	ret = fsync (fd);
	rw_lock.readerUnlock ();

	if (ret == -1) {
	    if (errno == EINTR)
		continue;

	    throw IOException (errnoToString (errno));
	}

	if (ret != 0) {
	    throw IOException (
		    String::forPrintTask (
			(Pr ("Unexpected return value from fsync(): "))
			(Pr ((long) ret))));
	}

	break;
    } while (true);
}

void
NativeFile::close (bool /* flush_data */)
    throw (IOException,
	   InternalException)
{
    rw_lock.writerLock ();
    if (fd == -1) {
	rw_lock.writerUnlock ();
	// NOTE: Multiple invocations of close() are allowed.
	// Multiple threads should be able to close() the file at will.
	return;
    }

    int tmp_fd = fd;
    fd = -1;
    rw_lock.writerUnlock ();

    for (;;) {
	int res = ::close (tmp_fd);

	// FIXME res == -1 (+ unexpected != 0)
	if (res != 0) {
	    if (errno == EINTR)
		continue;

	    throw IOException ();
	}

	break;
    }
}

NativeFile::NativeFile (const char    *filename,
			unsigned long  openFlags,
			AccessMode     accessMode)
    throw (IOException,
	   InternalException)
{
    should_close = true;

    int flags = O_RDONLY;

    switch (accessMode) {
    case AccessMode::ReadOnly:
	flags = O_RDONLY;
	break;
    case AccessMode::WriteOnly:
	flags = O_WRONLY;
	break;
    case AccessMode::ReadWrite:
	flags = O_RDWR;
	break;
    }

    if (openFlags & OpenFlags::Create)
	flags |= O_CREAT;
    /* TODO Specify behavior for "Truncate & O_RDONLY" combination. */
    if (openFlags & OpenFlags::Truncate)
	flags |= O_TRUNC;

    for (;;) {
	/* NOTE: man 2 open does not mention EINTR as a possible return
	 * value, while man 3 open _does_. This means that EINTR should
	 * be handled for all invocations of open() in MyCpp (and all
	 * over MyNC). */
	fd = open (filename,
		   /* O_DIRECT is not what I actually thought it to be. */
		   flags /*| O_DIRECT*/,
		   S_IRUSR | S_IWUSR);
	if (fd == -1) {
	    if (errno == EINTR)
		continue;

	    throw IOException (errnoToString (errno));
	}

	break;
    }
}

NativeFile::NativeFile (int fd,
			bool should_close)
{
    this->fd = fd;
    this->should_close = should_close;
}

NativeFile::~NativeFile ()
{
    if (fd != -1 &&
	should_close)
    {
	errf->print ("MyCpp.NativeFile.~(): WARNING: file has not been closed").pendl ();
	for (;;) {
	    int res = ::close (fd);
	    if (res == -1) {
		if (errno == EINTR)
		    continue;

		errf->print ("MyCpp.NativeFile.~(): WARNING: close() failed").pendl ();
	    } else
	    if (res != 0) {
		errf->print ("MyCpp.NativeFile.~(): WARNING: unexpected return value from close()").pendl ();
	    }

	    break;
	}
    }
}

}

<commit_msg>Consider lseek64() to be Linux-specific.<commit_after>#ifdef __linux__
/* For lseek64() */
#define _LARGEFILE64_SOURCE
#endif

#include <cstdio> // DEBUG

#include <limits.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

#include <mycpp/native_file.h>
#include <mycpp/util.h>
#include <mycpp/io.h>

#define DEBUG(a) ;

namespace MyCpp {

IOResult
NativeFile::read (MemoryDesc const &mem,
		  Size *nread)
    throw (IOException,
	   InternalException)
{
    if (nread != NULL)
	*nread = 0;

    if (mem.getMemory () == NULL ||
	mem.getLength () == 0)
    {
	DEBUG (
	    fprintf (stderr, "MyCpp.NativeFile.read: no destination\n");
	    fflush (stderr);
	)
	return IOResultNormal;
    }

    ssize_t ret;

    /* According to POSIX, if we pass a value larger than SSIZE_MAX
     * to read, then the result is implementation-defined. */
    Size len;
    if (mem.getLength () > SSIZE_MAX)
	len = SSIZE_MAX;
    else
	len = mem.getLength ();

    rw_lock.readerLock ();
    if (fd == -1) {
	rw_lock.readerUnlock ();
	throw InternalException ();
    }

    abortIf ((Size) (size_t) len != len);
    DEBUG (
	fprintf (stderr, "MyCpp.NativeFile.read: len: %lu\n", (unsigned long) len);
	fflush (stderr);
    )
    ret = ::read (fd, mem.getMemory (), (size_t) len);
    rw_lock.readerUnlock ();

    if (ret == -1) {
	if (errno == EINTR)
	    return IOResultNormal;

	throw IOException (errnoToString (errno));
    } else
    if (ret < 0) {
	throw IOException ();
    } else
    if (ret == 0) {
	return IOResultEof;
    }

    if ((Size) ret > len)
	throw InternalException (String::forData ("Unexpectedly large return value from read()"));

    if (nread != NULL)
	*nread = (Size) ret;

    return IOResultNormal;
}

IOResult
NativeFile::write (ConstMemoryDesc const &mem,
		   Size *nwritten)
    throw (IOException,
	   InternalException)
{
    if (nwritten != NULL)
	*nwritten = 0;

    if (mem.getMemory () == NULL ||
	mem.getLength () == 0)
    {
	return IOResultNormal;
    }

    ssize_t ret;

    /* According to POSIX, if we pass a value larger than SSIZE_MAX
     * to write, then the result is implementation-defined. */
    Size len;
    if (mem.getLength () > SSIZE_MAX)
	len = SSIZE_MAX;
    else
	len = mem.getLength ();

    rw_lock.readerLock ();
    if (fd == -1) {
	rw_lock.readerUnlock ();
	throw InternalException ();
    }

    abortIf ((Size) (size_t) len != len);
    ret = ::write (fd, mem.getMemory (), (size_t) len);
    rw_lock.readerUnlock ();

    if (ret == -1) {
	if (errno == EINTR)
	    return IOResultNormal;

	if (errno == EPIPE)
	    return IOResultEof;

      /* DEBUG */
	errf->print ("MyCpp.NativeFile.write_raw: ret == -1").pendl ();
      /* (DEBUG) */

	throw IOException (errnoToString (errno));
    } else
    if (ret < 0) {
      /* DEBUG */
	errf->print ("MyCpp.NativeFile.write_raw: ret < 0").pendl ();
      /* (DEBUG) */

	throw IOException ();
    }

    if ((Size) ret > len)
	throw InternalException (String::forData ("Unexpectedly large return value from write()"));

    if (nwritten != NULL)
	*nwritten = (Size) ret;

    return IOResultNormal;
}

void
NativeFile::seek (Int64      offset,
		  SeekOrigin origin)
    throw (IOException,
	   InternalException)
{
    int whence = 0;

    switch (origin) {
    case SeekOrigin::SeekBeg:
	whence = SEEK_SET;
	break;
    case SeekOrigin::SeekCur:
	whence = SEEK_CUR;
	break;
    case SeekOrigin::SeekEnd:
	whence = SEEK_END;
	break;
    }

    rw_lock.readerLock ();
    if (fd == -1) {
	rw_lock.readerUnlock ();
	throw InternalException ();
    }

#ifdef __linux__
    /* NOTE: lseek64() seems to be glibc-specific. */
    if (lseek64 (fd, (off64_t) offset, whence) == (off64_t) -1) {
#else
    if (lseek (fd, (off_t) offset, whence) == (off_t) -1) {
#endif
	rw_lock.readerUnlock ();
	throw IOException (errnoToString (errno));
    }
    rw_lock.readerUnlock ();
}

Uint64
NativeFile::tell ()
    throw (InternalException)
{
    off_t ret;

    rw_lock.readerLock ();
    if (fd == -1) {
	rw_lock.readerUnlock ();
	throw InternalException ();
    }

    /* I couldn't find a suitable syscall to read file offset
     * as an unsigned 64-bit number. Hence, there is no way
     * of reading really large file offsets. We are limited
     * by Int64 type, not Uint64. */
    ret = lseek (fd, 0, SEEK_CUR);
    rw_lock.readerUnlock ();

    if (ret == (off_t) -1)
	throw InternalException (errnoToString (errno));

    if (ret < 0)
	throw InternalException (
		String::forPrintTask (
		    (Pr ("Unexpected return value from lseek(): "))
		    (Pr ((long long) ret))));

    Uint64 ret64 = (Uint64) ret;

    /* Uint64 must be able to hold any value of type 'off_t',
     * or at least the file position should not be too large if one
     * wants to get it with MyCpp.NativeFile.tell() . */
    if ((off_t) ret64 != ret)
	throw InternalException (
		String::forData ("Integer overflow"));

    return ret64;
}

void
NativeFile::flush ()
    throw (IOException,
	   InternalException)
{
    /* Nothing to do here. */
}

void
NativeFile::sync ()
    throw (IOException,
	   InternalException)
{
    do {
	int ret;

	rw_lock.readerLock ();
	if (fd == -1) {
	    rw_lock.readerUnlock ();
	    throw InternalException ();
	}

	ret = fsync (fd);
	rw_lock.readerUnlock ();

	if (ret == -1) {
	    if (errno == EINTR)
		continue;

	    throw IOException (errnoToString (errno));
	}

	if (ret != 0) {
	    throw IOException (
		    String::forPrintTask (
			(Pr ("Unexpected return value from fsync(): "))
			(Pr ((long) ret))));
	}

	break;
    } while (true);
}

void
NativeFile::close (bool /* flush_data */)
    throw (IOException,
	   InternalException)
{
    rw_lock.writerLock ();
    if (fd == -1) {
	rw_lock.writerUnlock ();
	// NOTE: Multiple invocations of close() are allowed.
	// Multiple threads should be able to close() the file at will.
	return;
    }

    int tmp_fd = fd;
    fd = -1;
    rw_lock.writerUnlock ();

    for (;;) {
	int res = ::close (tmp_fd);

	// FIXME res == -1 (+ unexpected != 0)
	if (res != 0) {
	    if (errno == EINTR)
		continue;

	    throw IOException ();
	}

	break;
    }
}

NativeFile::NativeFile (const char    *filename,
			unsigned long  openFlags,
			AccessMode     accessMode)
    throw (IOException,
	   InternalException)
{
    should_close = true;

    int flags = O_RDONLY;

    switch (accessMode) {
    case AccessMode::ReadOnly:
	flags = O_RDONLY;
	break;
    case AccessMode::WriteOnly:
	flags = O_WRONLY;
	break;
    case AccessMode::ReadWrite:
	flags = O_RDWR;
	break;
    }

    if (openFlags & OpenFlags::Create)
	flags |= O_CREAT;
    /* TODO Specify behavior for "Truncate & O_RDONLY" combination. */
    if (openFlags & OpenFlags::Truncate)
	flags |= O_TRUNC;

    for (;;) {
	/* NOTE: man 2 open does not mention EINTR as a possible return
	 * value, while man 3 open _does_. This means that EINTR should
	 * be handled for all invocations of open() in MyCpp (and all
	 * over MyNC). */
	fd = open (filename,
		   /* O_DIRECT is not what I actually thought it to be. */
		   flags /*| O_DIRECT*/,
		   S_IRUSR | S_IWUSR);
	if (fd == -1) {
	    if (errno == EINTR)
		continue;

	    throw IOException (errnoToString (errno));
	}

	break;
    }
}

NativeFile::NativeFile (int fd,
			bool should_close)
{
    this->fd = fd;
    this->should_close = should_close;
}

NativeFile::~NativeFile ()
{
    if (fd != -1 &&
	should_close)
    {
	errf->print ("MyCpp.NativeFile.~(): WARNING: file has not been closed").pendl ();
	for (;;) {
	    int res = ::close (fd);
	    if (res == -1) {
		if (errno == EINTR)
		    continue;

		errf->print ("MyCpp.NativeFile.~(): WARNING: close() failed").pendl ();
	    } else
	    if (res != 0) {
		errf->print ("MyCpp.NativeFile.~(): WARNING: unexpected return value from close()").pendl ();
	    }

	    break;
	}
    }
}

}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: bastypes.hxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-07 20:18:21 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef _BASTYPES_HXX
#define _BASTYPES_HXX

#ifndef _SVHEADER_HXX
#include <svheader.hxx>
#endif

#include <iderid.hxx>

class ModulWindow;
class SfxRequest;
class SvTreeListBox;
class SvLBoxEntry;
class ScrollBar;
class SbModule;
class BasicManager;
class SfxItemSet;

#ifndef _SV_DOCKWIN_HXX //autogen
#include <vcl/dockwin.hxx>
#endif

#ifndef _SV_TOOLBOX_HXX //autogen
#include <vcl/toolbox.hxx>
#endif

#ifndef _SB_SBSTAR_HXX //autogen
#include <basic/sbstar.hxx>
#endif

#include <iderid.hxx>

#include <tools/table.hxx>

#include <svtools/tabbar.hxx>

#ifndef _COM_SUN_STAR_SCRIPT_XLIBRARYCONTAINER_HPP_
#include <com/sun/star/script/XLibraryContainer.hpp>
#endif

#include <hash_map>

#define LINE_SEP_CR     0x0D
#define LINE_SEP        0x0A

// Implementation: baside2b.cxx
sal_Int32 searchEOL( const ::rtl::OUString& rStr, sal_Int32 fromIndex );

// Bedeutung von bToBeKilled:
// Wenn in Reschedule-Schleife, darf ich das Fenster nicht zerstoeren.
// Es muss erst aus der Reschedule-Schleife Fallen, um sich dann
// selbst zu zerstoeren.
// Geht so leider nicht: Destroying Window with living Child!

struct BasicStatus
{
//  BOOL    bCompiled       : 1;
    BOOL    bIsRunning      : 1;
    BOOL    bError          : 1;
    BOOL    bIsInReschedule : 1;
    USHORT  nBasicFlags;

    BasicStatus()   {
            bIsRunning = FALSE; bError = FALSE;
            nBasicFlags = 0; bIsInReschedule = FALSE; }
};

struct BreakPoint
{
    BOOL    bEnabled;
    BOOL    bTemp;
    ULONG   nLine;
    ULONG   nStopAfter;
    ULONG   nHitCount;

    BreakPoint( ULONG nL )  { nLine = nL; nStopAfter = 0; nHitCount = 0; bEnabled = TRUE; bTemp = FALSE; }

};

class BasicDockingWindow : public DockingWindow
{
    friend class BasicToolBox;

    Rectangle       aFloatingPosAndSize;

protected:
    virtual BOOL    Docking( const Point& rPos, Rectangle& rRect );
    virtual void    EndDocking( const Rectangle& rRect, BOOL bFloatMode );
    virtual void    ToggleFloatingMode();
    virtual BOOL    PrepareToggleFloatingMode();
    virtual void    StartDocking();

public:
    BasicDockingWindow( Window* pParent );
};

class BasicToolBox : public ToolBox
{
public:
                    BasicToolBox( Window* pParent, IDEResId nRes );

    virtual void    MouseButtonDown( const MouseEvent& rMEvt );
};

DECLARE_LIST( BreakPL, BreakPoint* )
class BreakPointList : public BreakPL
{
private:
    void operator =(BreakPointList); // not implemented

public:
    BreakPointList();

    BreakPointList(BreakPointList const & rList);

    ~BreakPointList();

    void reset();

    void transfer(BreakPointList & rList);

    void        InsertSorted( BreakPoint* pBrk );
    BreakPoint* FindBreakPoint( ULONG nLine );
    void        AdjustBreakPoints( ULONG nLine, BOOL bInserted );
    void        SetBreakPointsInBasic( SbModule* pModule );
    void        ResetHitCount();
};

// helper class for sorting TabBar
class TabBarSortHelper
{
public:
    USHORT          nPageId;
    String          aPageText;

    bool operator<(const TabBarSortHelper& rComp) const { return (aPageText.CompareIgnoreCaseToAscii( rComp.aPageText ) == COMPARE_LESS); }
};

class BasicIDETabBar : public TabBar
{
protected:
    virtual void    MouseButtonDown( const MouseEvent& rMEvt );
    virtual void    Command( const CommandEvent& rCEvt );

    virtual long    AllowRenaming();
    virtual void    EndRenaming();

public:
                    BasicIDETabBar( Window* pParent );

    void            Sort();
};

#define BASWIN_OK               0x00
#define BASWIN_RUNNINGBASIC     0x01
#define BASWIN_TOBEKILLED       0x02
#define BASWIN_SUSPENDED        0x04
#define BASWIN_INRESCHEDULE     0x08

class Printer;
class SfxUndoManager;
class SfxObjectShell;
class BasicEntryDescriptor;

class IDEBaseWindow : public Window
{
private:
    ScrollBar*      pShellHScrollBar;
    ScrollBar*      pShellVScrollBar;

    DECL_LINK( ScrollHdl, ScrollBar * );
    BYTE            nStatus;

    SfxObjectShell* m_pShell;
    String          m_aLibName;
    String          m_aName;

protected:
    virtual void    DoScroll( ScrollBar* pCurScrollBar );

public:
                    TYPEINFO();
                    IDEBaseWindow( Window* pParent, SfxObjectShell* pShell, String aLibName, String aName );
    virtual         ~IDEBaseWindow();

    void            Init();
    virtual void    DoInit();
    virtual void    Deactivating();
    void            GrabScrollBars( ScrollBar* pHScroll, ScrollBar* pVScroll );

    ScrollBar*      GetHScrollBar() const { return pShellHScrollBar; }
    ScrollBar*      GetVScrollBar() const { return pShellVScrollBar; }

    virtual void    ExecuteCommand( SfxRequest& rReq );
    virtual void    GetState( SfxItemSet& );
    virtual long    Notify( NotifyEvent& rNEvt );

    virtual void    StoreData();
    virtual void    UpdateData();
    virtual void    PrintData( Printer* pPrinter );
    virtual BOOL    CanClose();

    virtual String  GetTitle();
    String          CreateQualifiedName();
    virtual BasicEntryDescriptor CreateEntryDescriptor() = 0;

    virtual BOOL    IsModified();
    virtual BOOL    IsPasteAllowed();

    virtual BOOL    AllowUndo();

    virtual void    SetReadOnly( BOOL bReadOnly );
    virtual BOOL    IsReadOnly();

    BYTE            GetStatus()             { return nStatus; }
    void            SetStatus( BYTE n )     { nStatus = n; }
    void            AddStatus( BYTE n )     { nStatus = nStatus | n; }
    void            ClearStatus( BYTE n )   { nStatus = nStatus & ~n; }

    virtual Window* GetLayoutWindow();

    virtual SfxUndoManager* GetUndoManager();

    virtual USHORT  GetSearchOptions();

    virtual void    BasicStarted();
    virtual void    BasicStopped();

    BOOL            IsSuspended() const
                        { return ( nStatus & BASWIN_SUSPENDED ) ? TRUE : FALSE; }

    SfxObjectShell* GetShell() const { return m_pShell; }
    void            SetShell( SfxObjectShell* pShell ) { m_pShell = pShell; }
    const String&   GetLibName() const { return m_aLibName; }
    void            SetLibName( const String& aLibName ) { m_aLibName = aLibName; }
    const String&   GetName() const { return m_aName; }
    void            SetName( const String& aName ) { m_aName = aName; }
};

class LibInfoKey
{
private:
    SfxObjectShell* m_pShell;
    String          m_aLibName;

public:
    LibInfoKey();
    LibInfoKey( SfxObjectShell* pShell, const String& rLibName );
    ~LibInfoKey();

    LibInfoKey( const LibInfoKey& rKey );
    LibInfoKey& operator=( const LibInfoKey& rKey );

    bool operator==( const LibInfoKey& rKey ) const;

    SfxObjectShell* GetShell() const { return m_pShell; }
    const String&   GetLibName() const { return m_aLibName; }
};

class LibInfoItem
{
private:
    SfxObjectShell* m_pShell;
    String          m_aLibName;
    String          m_aCurrentName;
    USHORT          m_nCurrentType;

public:
    LibInfoItem();
    LibInfoItem( SfxObjectShell* pShell, const String& rLibName, const String& rCurrentName, USHORT nCurrentType );
    ~LibInfoItem();

    LibInfoItem( const LibInfoItem& rItem );
    LibInfoItem& operator=( const LibInfoItem& rItem );

    SfxObjectShell* GetShell() const { return m_pShell; }
    const String&   GetLibName() const { return m_aLibName; }
    const String&   GetCurrentName() const { return m_aCurrentName; }
    USHORT          GetCurrentType() const { return m_nCurrentType; }
};

class LibInfos
{
private:

    struct LibInfoKeyHash
    {
        size_t operator()( const LibInfoKey& rKey ) const
        {
            size_t nHash = (size_t) rKey.GetShell();
            nHash += (size_t) ::rtl::OUString( rKey.GetLibName() ).hashCode();
            return nHash;
        }
    };

    typedef ::std::hash_map< LibInfoKey, LibInfoItem*, LibInfoKeyHash, ::std::equal_to< LibInfoKey > > LibInfoMap;
    LibInfoMap  m_aLibInfoMap;

public:
                    LibInfos();
                    ~LibInfos();

    void            InsertInfo( LibInfoItem* pItem );
    void            RemoveInfo( const LibInfoKey& rKey );

    LibInfoItem*    GetInfo( const LibInfoKey& rKey );
};

void            CutLines( ::rtl::OUString& rStr, sal_Int32 nStartLine, sal_Int32 nLines, BOOL bEraseTrailingEmptyLines = FALSE );
String          CreateMgrAndLibStr( const String& rMgrName, const String& rLibName );
ULONG           CalcLineCount( SvStream& rStream );

BOOL            QueryReplaceMacro( const String& rName, Window* pParent = 0 );
BOOL            QueryDelMacro( const String& rName, Window* pParent = 0 );
BOOL            QueryDelDialog( const String& rName, Window* pParent = 0 );
BOOL            QueryDelModule( const String& rName, Window* pParent = 0 );
BOOL            QueryDelLib( const String& rName, BOOL bRef = FALSE, Window* pParent = 0 );
BOOL            QueryPassword( const ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >& xLibContainer, const String& rLibName, String& rPassword, BOOL bRepeat = FALSE, BOOL bNewTitle = FALSE );

#endif  // _BASTYPES_HXX
<commit_msg>INTEGRATION: CWS basmgr02 (1.8.144); FILE MERGED 2007/02/21 09:33:04 fs 1.8.144.1: #i73331# encapsulate (nearly) all usages of SfxObjectShell in the ScriptDocument class<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: bastypes.hxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: obo $ $Date: 2007-03-15 16:02:04 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/
#ifndef _BASTYPES_HXX
#define _BASTYPES_HXX

#ifndef _SVHEADER_HXX
#include <svheader.hxx>
#endif

#include <iderid.hxx>

#include "scriptdocument.hxx"

class ModulWindow;
class SfxRequest;
class SvTreeListBox;
class SvLBoxEntry;
class ScrollBar;
class SbModule;
class BasicManager;
class SfxItemSet;

#ifndef _SV_DOCKWIN_HXX //autogen
#include <vcl/dockwin.hxx>
#endif

#ifndef _SV_TOOLBOX_HXX //autogen
#include <vcl/toolbox.hxx>
#endif

#ifndef _SB_SBSTAR_HXX //autogen
#include <basic/sbstar.hxx>
#endif

#include <iderid.hxx>

#include <tools/table.hxx>

#include <svtools/tabbar.hxx>

#ifndef _COM_SUN_STAR_SCRIPT_XLIBRARYCONTAINER_HPP_
#include <com/sun/star/script/XLibraryContainer.hpp>
#endif

#include <hash_map>

#define LINE_SEP_CR     0x0D
#define LINE_SEP        0x0A

// Implementation: baside2b.cxx
sal_Int32 searchEOL( const ::rtl::OUString& rStr, sal_Int32 fromIndex );

// Bedeutung von bToBeKilled:
// Wenn in Reschedule-Schleife, darf ich das Fenster nicht zerstoeren.
// Es muss erst aus der Reschedule-Schleife Fallen, um sich dann
// selbst zu zerstoeren.
// Geht so leider nicht: Destroying Window with living Child!

struct BasicStatus
{
//  BOOL    bCompiled       : 1;
    BOOL    bIsRunning      : 1;
    BOOL    bError          : 1;
    BOOL    bIsInReschedule : 1;
    USHORT  nBasicFlags;

    BasicStatus()   {
            bIsRunning = FALSE; bError = FALSE;
            nBasicFlags = 0; bIsInReschedule = FALSE; }
};

struct BreakPoint
{
    BOOL    bEnabled;
    BOOL    bTemp;
    ULONG   nLine;
    ULONG   nStopAfter;
    ULONG   nHitCount;

    BreakPoint( ULONG nL )  { nLine = nL; nStopAfter = 0; nHitCount = 0; bEnabled = TRUE; bTemp = FALSE; }

};

class BasicDockingWindow : public DockingWindow
{
    friend class BasicToolBox;

    Rectangle       aFloatingPosAndSize;

protected:
    virtual BOOL    Docking( const Point& rPos, Rectangle& rRect );
    virtual void    EndDocking( const Rectangle& rRect, BOOL bFloatMode );
    virtual void    ToggleFloatingMode();
    virtual BOOL    PrepareToggleFloatingMode();
    virtual void    StartDocking();

public:
    BasicDockingWindow( Window* pParent );
};

class BasicToolBox : public ToolBox
{
public:
                    BasicToolBox( Window* pParent, IDEResId nRes );

    virtual void    MouseButtonDown( const MouseEvent& rMEvt );
};

DECLARE_LIST( BreakPL, BreakPoint* )
class BreakPointList : public BreakPL
{
private:
    void operator =(BreakPointList); // not implemented

public:
    BreakPointList();

    BreakPointList(BreakPointList const & rList);

    ~BreakPointList();

    void reset();

    void transfer(BreakPointList & rList);

    void        InsertSorted( BreakPoint* pBrk );
    BreakPoint* FindBreakPoint( ULONG nLine );
    void        AdjustBreakPoints( ULONG nLine, BOOL bInserted );
    void        SetBreakPointsInBasic( SbModule* pModule );
    void        ResetHitCount();
};

// helper class for sorting TabBar
class TabBarSortHelper
{
public:
    USHORT          nPageId;
    String          aPageText;

    bool operator<(const TabBarSortHelper& rComp) const { return (aPageText.CompareIgnoreCaseToAscii( rComp.aPageText ) == COMPARE_LESS); }
};

class BasicIDETabBar : public TabBar
{
protected:
    virtual void    MouseButtonDown( const MouseEvent& rMEvt );
    virtual void    Command( const CommandEvent& rCEvt );

    virtual long    AllowRenaming();
    virtual void    EndRenaming();

public:
                    BasicIDETabBar( Window* pParent );

    void            Sort();
};

#define BASWIN_OK               0x00
#define BASWIN_RUNNINGBASIC     0x01
#define BASWIN_TOBEKILLED       0x02
#define BASWIN_SUSPENDED        0x04
#define BASWIN_INRESCHEDULE     0x08

class Printer;
class SfxUndoManager;
class BasicEntryDescriptor;

class IDEBaseWindow : public Window
{
private:
    ScrollBar*      pShellHScrollBar;
    ScrollBar*      pShellVScrollBar;

    DECL_LINK( ScrollHdl, ScrollBar * );
    BYTE            nStatus;

    ScriptDocument      m_aDocument;
    String              m_aLibName;
    String              m_aName;

protected:
    virtual void    DoScroll( ScrollBar* pCurScrollBar );

public:
                    TYPEINFO();
                    IDEBaseWindow( Window* pParent, const ScriptDocument& rDocument, String aLibName, String aName );
    virtual         ~IDEBaseWindow();

    void            Init();
    virtual void    DoInit();
    virtual void    Deactivating();
    void            GrabScrollBars( ScrollBar* pHScroll, ScrollBar* pVScroll );

    ScrollBar*      GetHScrollBar() const { return pShellHScrollBar; }
    ScrollBar*      GetVScrollBar() const { return pShellVScrollBar; }

    virtual void    ExecuteCommand( SfxRequest& rReq );
    virtual void    GetState( SfxItemSet& );
    virtual long    Notify( NotifyEvent& rNEvt );

    virtual void    StoreData();
    virtual void    UpdateData();
    virtual void    PrintData( Printer* pPrinter );
    virtual BOOL    CanClose();

    virtual String  GetTitle();
    String          CreateQualifiedName();
    virtual BasicEntryDescriptor CreateEntryDescriptor() = 0;

    virtual BOOL    IsModified();
    virtual BOOL    IsPasteAllowed();

    virtual BOOL    AllowUndo();

    virtual void    SetReadOnly( BOOL bReadOnly );
    virtual BOOL    IsReadOnly();

    BYTE            GetStatus()             { return nStatus; }
    void            SetStatus( BYTE n )     { nStatus = n; }
    void            AddStatus( BYTE n )     { nStatus = nStatus | n; }
    void            ClearStatus( BYTE n )   { nStatus = nStatus & ~n; }

    virtual Window* GetLayoutWindow();

    virtual SfxUndoManager* GetUndoManager();

    virtual USHORT  GetSearchOptions();

    virtual void    BasicStarted();
    virtual void    BasicStopped();

    BOOL            IsSuspended() const
                        { return ( nStatus & BASWIN_SUSPENDED ) ? TRUE : FALSE; }

    const ScriptDocument&
                    GetDocument() const { return m_aDocument; }
    void            SetDocument( const ScriptDocument& rDocument ) { m_aDocument = rDocument; }
    bool            IsDocument( const ScriptDocument& rDocument ) const { return rDocument == m_aDocument; }
    const String&   GetLibName() const { return m_aLibName; }
    void            SetLibName( const String& aLibName ) { m_aLibName = aLibName; }
    const String&   GetName() const { return m_aName; }
    void            SetName( const String& aName ) { m_aName = aName; }
};

class LibInfoKey
{
private:
    ScriptDocument      m_aDocument;
    String              m_aLibName;

public:
    LibInfoKey();
    LibInfoKey( const ScriptDocument& rDocument, const String& rLibName );
    ~LibInfoKey();

    LibInfoKey( const LibInfoKey& rKey );
    LibInfoKey& operator=( const LibInfoKey& rKey );

    bool operator==( const LibInfoKey& rKey ) const;

    const ScriptDocument&
                    GetDocument() const { return m_aDocument; }
    const String&   GetLibName() const { return m_aLibName; }
};

class LibInfoItem
{
private:
    ScriptDocument      m_aDocument;
    String              m_aLibName;
    String              m_aCurrentName;
    USHORT              m_nCurrentType;

public:
    LibInfoItem();
    LibInfoItem( const ScriptDocument& rDocument, const String& rLibName, const String& rCurrentName, USHORT nCurrentType );
    ~LibInfoItem();

    LibInfoItem( const LibInfoItem& rItem );
    LibInfoItem& operator=( const LibInfoItem& rItem );

    const ScriptDocument&
                    GetDocument() const { return m_aDocument; }
    const String&   GetLibName() const { return m_aLibName; }
    const String&   GetCurrentName() const { return m_aCurrentName; }
    USHORT          GetCurrentType() const { return m_nCurrentType; }
};

class LibInfos
{
private:

    struct LibInfoKeyHash
    {
        size_t operator()( const LibInfoKey& rKey ) const
        {
            size_t nHash = (size_t) rKey.GetDocument().hashCode();
            nHash += (size_t) ::rtl::OUString( rKey.GetLibName() ).hashCode();
            return nHash;
        }
    };

    typedef ::std::hash_map< LibInfoKey, LibInfoItem*, LibInfoKeyHash, ::std::equal_to< LibInfoKey > > LibInfoMap;
    LibInfoMap  m_aLibInfoMap;

public:
                    LibInfos();
                    ~LibInfos();

    void            InsertInfo( LibInfoItem* pItem );
    void            RemoveInfo( const LibInfoKey& rKey );

    LibInfoItem*    GetInfo( const LibInfoKey& rKey );
};

void            CutLines( ::rtl::OUString& rStr, sal_Int32 nStartLine, sal_Int32 nLines, BOOL bEraseTrailingEmptyLines = FALSE );
String          CreateMgrAndLibStr( const String& rMgrName, const String& rLibName );
ULONG           CalcLineCount( SvStream& rStream );

BOOL            QueryReplaceMacro( const String& rName, Window* pParent = 0 );
BOOL            QueryDelMacro( const String& rName, Window* pParent = 0 );
BOOL            QueryDelDialog( const String& rName, Window* pParent = 0 );
BOOL            QueryDelModule( const String& rName, Window* pParent = 0 );
BOOL            QueryDelLib( const String& rName, BOOL bRef = FALSE, Window* pParent = 0 );
BOOL            QueryPassword( const ::com::sun::star::uno::Reference< ::com::sun::star::script::XLibraryContainer >& xLibContainer, const String& rLibName, String& rPassword, BOOL bRepeat = FALSE, BOOL bNewTitle = FALSE );

#endif  // _BASTYPES_HXX
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: dlgedobj.hxx,v $
 *
 *  $Revision: 1.15 $
 *
 *  last change: $Author: vg $ $Date: 2003-03-26 12:51:16 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _BASCTL_DLGEDOBJ_HXX
#define _BASCTL_DLGEDOBJ_HXX

#ifndef _SVDOUNO_HXX
#include <svx/svdouno.hxx>
#endif

#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
#include <comphelper/processfactory.hxx>
#endif

#ifndef _COM_SUN_STAR_BEANS_XPROPERTYCHANGELISTENER_HPP_
#include <com/sun/star/beans/XPropertyChangeListener.hpp>
#endif

#ifndef _COM_SUN_STAR_CONTAINER_XCONTAINERLISTENER_HPP_
#include <com/sun/star/container/XContainerListener.hpp>
#endif

#include <vector>

class DlgEdForm;

//============================================================================
// DlgEdObj
//============================================================================

class DlgEdObj: public SdrUnoObj
{
    friend class DlgEditor;
    friend class DlgEdFactory;
    friend class DlgEdPropListenerImpl;
    friend class DlgEdForm;

private:
    sal_Bool        bIsListening;
    DlgEdForm*      pDlgEdForm;
    ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener> m_xPropertyChangeListener;
    ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener> m_xContainerListener;

protected:
    DlgEdObj();
    DlgEdObj(const ::rtl::OUString& rModelName);
    DlgEdObj(const ::rtl::OUString& rModelName,
             const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSFac);

    virtual void     WriteData(SvStream& rOut) const;                           // not working yet
    virtual void     ReadData(const SdrObjIOHeader& rHead, SvStream& rIn);      // not working yet

    virtual void NbcMove( const Size& rSize );
    virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact);
    virtual FASTBOOL EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd);

    DECL_LINK(OnCreate, void* );

    void StartListening();
    void EndListening(sal_Bool bRemoveListener = sal_True);
    sal_Bool    isListening() const { return bIsListening; }

public:
    TYPEINFO();

    virtual ~DlgEdObj();
    virtual void SetPage(SdrPage* pNewPage);

    virtual void SetDlgEdForm( DlgEdForm* pForm ) { pDlgEdForm = pForm; }
    virtual DlgEdForm* GetDlgEdForm() const { return pDlgEdForm; }

    virtual sal_uInt32 GetObjInventor() const;
    virtual sal_uInt16 GetObjIdentifier() const;

    virtual SdrObject*  Clone() const;                                          // not working yet
    virtual SdrObject*  Clone(SdrPage* pPage, SdrModel* pModel) const;          // not working yet
    virtual void        operator= (const SdrObject& rObj);                      // not working yet
    virtual void clonedFrom(const DlgEdObj* _pSource);                          // not working yet

    virtual sal_Bool        supportsService( const sal_Char* _pServiceName ) const;
    virtual ::rtl::OUString GetDefaultName() const;
    virtual ::rtl::OUString GetUniqueName() const;

    virtual sal_Int32   GetStep() const;
    virtual void        UpdateStep();

    virtual void SetDefaults();
    virtual void SetRectFromProps();
    virtual void SetPropsFromRect();

    virtual void SAL_CALL NameChange( const  ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL TabIndexChange( const  ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException);

    // PropertyChangeListener
    virtual void SAL_CALL _propertyChange( const  ::com::sun::star::beans::PropertyChangeEvent& evt ) throw(::com::sun::star::uno::RuntimeException);

    // ContainerListener
    virtual void SAL_CALL _elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL _elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL _elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);

    virtual void SetLayer(SdrLayerID nLayer);
    virtual SdrObject* CheckHit(const Point& rPnt,USHORT nTol,const SetOfByte*) const;
};

//============================================================================
// DlgEdForm
//============================================================================

class DlgEdForm: public DlgEdObj
{
    friend class DlgEditor;
    friend class DlgEdFactory;

private:
    DlgEditor* pDlgEditor;
    ::std::vector<DlgEdObj*> pChilds;

protected:
    DlgEdForm(const ::rtl::OUString& rModelName);
    DlgEdForm(const ::rtl::OUString& rModelName,
              const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSFac);
    DlgEdForm();

    virtual void NbcMove( const Size& rSize );
    virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact);
    virtual FASTBOOL EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd);

public:
    TYPEINFO();

    virtual ~DlgEdForm();

    virtual void SetDlgEditor( DlgEditor* pEditor ) { pDlgEditor = pEditor; }
    virtual DlgEditor* GetDlgEditor() const { return pDlgEditor; }

    virtual void AddChild( DlgEdObj* pDlgEdObj );
    virtual void RemoveChild( DlgEdObj* pDlgEdObj );
    virtual ::std::vector<DlgEdObj*> GetChilds() const { return pChilds; }

    virtual void UpdateStep();

    virtual void SetRectFromProps();
    virtual void SetPropsFromRect();

    virtual void SortByTabIndex();

    virtual SdrObject* CheckHit(const Point& rPnt,USHORT nTol,const SetOfByte*) const;
};

#endif // _BASCTL_DLGEDOBJ_HXX

<commit_msg>INTEGRATION: CWS vcl07 (1.13.12.1.10); FILE MERGED 2003/03/14 15:17:53 tbe 1.13.12.1.10.1: #107814# don't sort control model container by tab index anymore<commit_after>/*************************************************************************
 *
 *  $RCSfile: dlgedobj.hxx,v $
 *
 *  $Revision: 1.16 $
 *
 *  last change: $Author: vg $ $Date: 2003-04-11 17:39:10 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef _BASCTL_DLGEDOBJ_HXX
#define _BASCTL_DLGEDOBJ_HXX

#ifndef _SVDOUNO_HXX
#include <svx/svdouno.hxx>
#endif

#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
#include <comphelper/processfactory.hxx>
#endif

#ifndef _COM_SUN_STAR_BEANS_XPROPERTYCHANGELISTENER_HPP_
#include <com/sun/star/beans/XPropertyChangeListener.hpp>
#endif

#ifndef _COM_SUN_STAR_CONTAINER_XCONTAINERLISTENER_HPP_
#include <com/sun/star/container/XContainerListener.hpp>
#endif

#include <vector>

class DlgEdForm;

//============================================================================
// DlgEdObj
//============================================================================

class DlgEdObj: public SdrUnoObj
{
    friend class DlgEditor;
    friend class DlgEdFactory;
    friend class DlgEdPropListenerImpl;
    friend class DlgEdForm;

private:
    sal_Bool        bIsListening;
    DlgEdForm*      pDlgEdForm;
    ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener> m_xPropertyChangeListener;
    ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener> m_xContainerListener;

protected:
    DlgEdObj();
    DlgEdObj(const ::rtl::OUString& rModelName);
    DlgEdObj(const ::rtl::OUString& rModelName,
             const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSFac);

    virtual void     WriteData(SvStream& rOut) const;                           // not working yet
    virtual void     ReadData(const SdrObjIOHeader& rHead, SvStream& rIn);      // not working yet

    virtual void NbcMove( const Size& rSize );
    virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact);
    virtual FASTBOOL EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd);

    DECL_LINK(OnCreate, void* );

    void StartListening();
    void EndListening(sal_Bool bRemoveListener = sal_True);
    sal_Bool    isListening() const { return bIsListening; }

public:
    TYPEINFO();

    virtual ~DlgEdObj();
    virtual void SetPage(SdrPage* pNewPage);

    virtual void SetDlgEdForm( DlgEdForm* pForm ) { pDlgEdForm = pForm; }
    virtual DlgEdForm* GetDlgEdForm() const { return pDlgEdForm; }

    virtual sal_uInt32 GetObjInventor() const;
    virtual sal_uInt16 GetObjIdentifier() const;

    virtual SdrObject*  Clone() const;                                          // not working yet
    virtual SdrObject*  Clone(SdrPage* pPage, SdrModel* pModel) const;          // not working yet
    virtual void        operator= (const SdrObject& rObj);                      // not working yet
    virtual void clonedFrom(const DlgEdObj* _pSource);                          // not working yet

    virtual sal_Bool        supportsService( const sal_Char* _pServiceName ) const;
    virtual ::rtl::OUString GetDefaultName() const;
    virtual ::rtl::OUString GetUniqueName() const;

    virtual sal_Int32   GetStep() const;
    virtual void        UpdateStep();

    virtual void SetDefaults();
    virtual void SetRectFromProps();
    virtual void SetPropsFromRect();

    virtual void SAL_CALL NameChange( const  ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL TabIndexChange( const  ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException);

    // PropertyChangeListener
    virtual void SAL_CALL _propertyChange( const  ::com::sun::star::beans::PropertyChangeEvent& evt ) throw(::com::sun::star::uno::RuntimeException);

    // ContainerListener
    virtual void SAL_CALL _elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL _elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL _elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException);

    virtual void SetLayer(SdrLayerID nLayer);
    virtual SdrObject* CheckHit(const Point& rPnt,USHORT nTol,const SetOfByte*) const;
};

//============================================================================
// DlgEdForm
//============================================================================

class DlgEdForm: public DlgEdObj
{
    friend class DlgEditor;
    friend class DlgEdFactory;

private:
    DlgEditor* pDlgEditor;
    ::std::vector<DlgEdObj*> pChilds;

protected:
    DlgEdForm(const ::rtl::OUString& rModelName);
    DlgEdForm(const ::rtl::OUString& rModelName,
              const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxSFac);
    DlgEdForm();

    virtual void NbcMove( const Size& rSize );
    virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact);
    virtual FASTBOOL EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd);

public:
    TYPEINFO();

    virtual ~DlgEdForm();

    virtual void SetDlgEditor( DlgEditor* pEditor ) { pDlgEditor = pEditor; }
    virtual DlgEditor* GetDlgEditor() const { return pDlgEditor; }

    virtual void AddChild( DlgEdObj* pDlgEdObj );
    virtual void RemoveChild( DlgEdObj* pDlgEdObj );
    virtual ::std::vector<DlgEdObj*> GetChilds() const { return pChilds; }

    virtual void UpdateStep();

    virtual void SetRectFromProps();
    virtual void SetPropsFromRect();

    virtual void UpdateTabIndices();

    virtual SdrObject* CheckHit(const Point& rPnt,USHORT nTol,const SetOfByte*) const;
};

#endif // _BASCTL_DLGEDOBJ_HXX

<|endoftext|>