<commit_before>#ifndef __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CONTINUOUS__BETA_HPP__
#define __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CONTINUOUS__BETA_HPP__

#include <stan/agrad.hpp>
#include <stan/prob/traits.hpp>
#include <stan/math/error_handling.hpp>
#include <stan/math/special_functions.hpp>
#include <stan/prob/constants.hpp>

namespace stan {

  namespace prob {

    /**
     * The log of the beta density for the specified scalar(s) given the specified
     * sample size(s). y, alpha, or beta can each either be scalar or std::vector.
     * Any vector inputs must be the same length.
     *
     * <p> The result log probability is defined to be the sum of
     * the log probabilities for each observation/alpha/beta triple.
     *
     * Prior sample sizes, alpha and beta, must be greater than 0.
     *
     * @param y (Sequence of) scalar(s).
     * @param alpha (Sequence of) prior sample size(s).
     * @param beta (Sequence of) prior sample size(s).
     * @return The log of the product of densities.
     * @tparam T_y Type of scalar outcome.
     * @tparam T_scale_succ Type of prior scale for successes.
     * @tparam T_scale_fail Type of prior scale for failures.
     * @error_policy
     *    @li alpha must be positive and finite.
     *    @li beta must be positive and finite.
     */
    template <bool Prop,
              typename T_y, typename T_scale_succ, typename T_scale_fail,
              class Policy>
    typename return_type<T_y,T_scale_succ,T_scale_fail>::type
    beta_log(const T_y& y, const T_scale_succ& alpha, const T_scale_fail& beta,
             const Policy&) {
      static const char* function = "stan::prob::beta_log(%1%)";

      using stan::math::check_positive;
      using stan::math::check_finite;
      using stan::math::check_not_nan;
      using stan::math::check_consistent_sizes;
      using stan::math::multiply_log;
      using stan::math::log1m;
      using stan::math::value_of;
      using stan::prob::include_summand;

      // check if no variables are involved and prop-to
      if (!include_summand<Prop,T_y,T_scale_succ,T_scale_fail>::value)
	return 0.0;

      // check if any vectors are zero length
      if (!(stan::length(y)
            && stan::length(alpha)
            && stan::length(beta)))
        return 0.0;

      // set up return value accumulator

      double logp(0.0);

      // validate args (here done over var, which should be OK)
      if (!check_finite(function, alpha,
                        "First shape parameter",
                        &logp, Policy()))
        return logp;
      if (!check_positive(function, alpha,
                          "First shape parameter",
                          &logp, Policy()))
        return logp;
      if (!check_finite(function, beta,
                          "Second shape parameter",
                          &logp, Policy()))
        return logp;
      if (!check_positive(function, beta,
                          "Second shape parameter",
                          &logp, Policy()))
        return logp;
      if (!check_not_nan(function, y, "Random variable", &logp, Policy()))
        return logp;
      if (!(check_consistent_sizes(function,
                                   y,alpha,beta,
				   "Random variable","First shape parameter","Second shape parameter",
                                   &logp, Policy())))
        return logp;

      // set up template expressions wrapping scalars into vector views
      VectorView<const T_y> y_vec(y);
      VectorView<const T_scale_succ> alpha_vec(alpha);
      VectorView<const T_scale_fail> beta_vec(beta);
      size_t N = max_size(y, alpha, beta);
      agrad::OperandsAndPartials<T_y, T_scale_succ, T_scale_fail>
        operands_and_partials(y, alpha, beta, y_vec, alpha_vec, beta_vec);

      for (size_t n = 0; n < N; n++) {
	// pull out values of arguments
	const double y_dbl = value_of(y_vec[n]);
	const double alpha_dbl = value_of(alpha_vec[n]);
	const double beta_dbl = value_of(beta_vec[n]);

	// reusable subexpressions values
	if (y_dbl < 0 || y_dbl > 1)
	  return 0.0;

	const double log_y = log(y_dbl);
	const double log1m_y = log1m(y_dbl);
	// log probability
	if (include_summand<Prop,T_scale_succ,T_scale_fail>::value)
	  logp += lgamma(alpha_dbl + beta_dbl);
	if (include_summand<Prop,T_scale_succ>::value)
	  logp -= lgamma(alpha_dbl);
	if (include_summand<Prop,T_scale_fail>::value)
	  logp -= lgamma(beta_dbl);
	if (include_summand<Prop,T_y,T_scale_succ>::value)
	  logp += (alpha_dbl-1.0) * log_y;
	if (include_summand<Prop,T_y,T_scale_fail>::value)
	  logp += (beta_dbl-1.0) * log1m_y;

	// gradients
	const double digamma_alpha_beta = boost::math::digamma(alpha_dbl + beta_dbl);
	const double digamma_alpha = boost::math::digamma(alpha_dbl);
	const double digamma_beta = boost::math::digamma(beta_dbl);

	if (!is_constant<typename is_vector<T_y>::type>::value)
	  operands_and_partials.d_x1[n] += (alpha_dbl-1)/y_dbl + (beta_dbl-1)/(y_dbl-1);
	if (!is_constant<typename is_vector<T_scale_succ>::type>::value)
	  operands_and_partials.d_x2[n] += log_y + digamma_alpha_beta - digamma_alpha;
	if (!is_constant<typename is_vector<T_scale_fail>::type>::value)
	  operands_and_partials.d_x3[n] += log1m_y + digamma_alpha_beta - digamma_beta;
      }
      return operands_and_partials.to_var(logp);
    }

    template <bool Prop,
              typename T_y, typename T_scale_succ, typename T_scale_fail>
    inline
    typename return_type<T_y,T_scale_succ,T_scale_fail>::type
    beta_log(const T_y& y, const T_scale_succ& alpha, const T_scale_fail& beta) {
      return beta_log<Prop>(y,alpha,beta,stan::math::default_policy());
    }

    template <typename T_y, typename T_scale_succ, typename T_scale_fail,
              class Policy>
    typename return_type<T_y,T_scale_succ,T_scale_fail>::type
    beta_log(const T_y& y, const T_scale_succ& alpha, const T_scale_fail& beta,
             const Policy&) {
      return beta_log<false>(y,alpha,beta,Policy());
    }

    template <typename T_y, typename T_scale_succ, typename T_scale_fail>
    inline
    typename return_type<T_y,T_scale_succ,T_scale_fail>::type
    beta_log(const T_y& y, const T_scale_succ& alpha, const T_scale_fail& beta) {
      return beta_log<false>(y,alpha,beta,stan::math::default_policy());
    }

    /**
     * Calculates the beta cumulative distribution function for the given
     * variate and scale variables.
     *
     * @param y A scalar variate.
     * @param alpha Prior sample size.
     * @param beta Prior sample size.
     * @return The beta cdf evaluated at the specified arguments.
     * @tparam T_y Type of y.
     * @tparam T_scale_succ Type of alpha.
     * @tparam T_scale_fail Type of beta.
     * @tparam Policy Error-handling policy.
     */
    template <typename T_y, typename T_scale_succ, typename T_scale_fail,
              class Policy>
    typename return_type<T_y,T_scale_succ,T_scale_fail>::type
    beta_cdf(const T_y& y, const T_scale_succ& alpha, const T_scale_fail& beta,
	     const Policy&) {
      static const char* function = "stan::prob::beta_cdf(%1%)";

      using stan::math::check_positive;
      using stan::math::check_finite;
      using stan::math::check_not_nan;
      using boost::math::tools::promote_args;

      typename promote_args<T_y,T_scale_succ,T_scale_fail>::type lp;
      if (!check_finite(function, alpha,
                        "First shape parameter",
                        &lp, Policy()))
        return lp;
      if (!check_positive(function, alpha,
                          "First shape parameter",
                          &lp, Policy()))
        return lp;
      if (!check_finite(function, beta,
                          "Second shape parameter",
                          &lp, Policy()))
        return lp;
      if (!check_positive(function, beta,
                          "Second shape parameter",
                          &lp, Policy()))
        return lp;
      if (!check_not_nan(function, y, "Random variable", &lp, Policy()))
        return lp;

      if (y < 0.0)
        return 0;
      if (y > 1.0)
        return 1.0;

      return stan::math::ibeta(alpha, beta, y);
    }

    template <typename T_y, typename T_scale_succ, typename T_scale_fail>
    typename return_type<T_y,T_scale_succ,T_scale_fail>::type
    beta_cdf(const T_y& y, const T_scale_succ& alpha, const T_scale_fail& beta) {
      return beta_cdf(y,alpha,beta,stan::math::default_policy());
    }
  }
}
#endif
<commit_msg>reordering includes<commit_after>#ifndef __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CONTINUOUS__BETA_HPP__
#define __STAN__PROB__DISTRIBUTIONS__UNIVARIATE__CONTINUOUS__BETA_HPP__

#include <stan/agrad.hpp>
#include <stan/math/error_handling.hpp>
#include <stan/math/special_functions.hpp>
#include <stan/meta/traits.hpp>
#include <stan/prob/constants.hpp>
#include <stan/prob/traits.hpp>

namespace stan {

  namespace prob {

    /**
     * The log of the beta density for the specified scalar(s) given the specified
     * sample size(s). y, alpha, or beta can each either be scalar or std::vector.
     * Any vector inputs must be the same length.
     *
     * <p> The result log probability is defined to be the sum of
     * the log probabilities for each observation/alpha/beta triple.
     *
     * Prior sample sizes, alpha and beta, must be greater than 0.
     *
     * @param y (Sequence of) scalar(s).
     * @param alpha (Sequence of) prior sample size(s).
     * @param beta (Sequence of) prior sample size(s).
     * @return The log of the product of densities.
     * @tparam T_y Type of scalar outcome.
     * @tparam T_scale_succ Type of prior scale for successes.
     * @tparam T_scale_fail Type of prior scale for failures.
     * @error_policy
     *    @li alpha must be positive and finite.
     *    @li beta must be positive and finite.
     */
    template <bool Prop,
              typename T_y, typename T_scale_succ, typename T_scale_fail,
              class Policy>
    typename return_type<T_y,T_scale_succ,T_scale_fail>::type
    beta_log(const T_y& y, const T_scale_succ& alpha, const T_scale_fail& beta,
             const Policy&) {
      static const char* function = "stan::prob::beta_log(%1%)";

      using stan::math::check_positive;
      using stan::math::check_finite;
      using stan::math::check_not_nan;
      using stan::math::check_consistent_sizes;
      using stan::math::multiply_log;
      using stan::math::log1m;
      using stan::math::value_of;
      using stan::prob::include_summand;

      // check if no variables are involved and prop-to
      if (!include_summand<Prop,T_y,T_scale_succ,T_scale_fail>::value)
	return 0.0;

      // check if any vectors are zero length
      if (!(stan::length(y)
            && stan::length(alpha)
            && stan::length(beta)))
        return 0.0;

      // set up return value accumulator

      double logp(0.0);

      // validate args (here done over var, which should be OK)
      if (!check_finite(function, alpha,
                        "First shape parameter",
                        &logp, Policy()))
        return logp;
      if (!check_positive(function, alpha,
                          "First shape parameter",
                          &logp, Policy()))
        return logp;
      if (!check_finite(function, beta,
                          "Second shape parameter",
                          &logp, Policy()))
        return logp;
      if (!check_positive(function, beta,
                          "Second shape parameter",
                          &logp, Policy()))
        return logp;
      if (!check_not_nan(function, y, "Random variable", &logp, Policy()))
        return logp;
      if (!(check_consistent_sizes(function,
                                   y,alpha,beta,
				   "Random variable","First shape parameter","Second shape parameter",
                                   &logp, Policy())))
        return logp;

      // set up template expressions wrapping scalars into vector views
      VectorView<const T_y> y_vec(y);
      VectorView<const T_scale_succ> alpha_vec(alpha);
      VectorView<const T_scale_fail> beta_vec(beta);
      size_t N = max_size(y, alpha, beta);
      agrad::OperandsAndPartials<T_y, T_scale_succ, T_scale_fail>
        operands_and_partials(y, alpha, beta, y_vec, alpha_vec, beta_vec);

      for (size_t n = 0; n < N; n++) {
	// pull out values of arguments
	const double y_dbl = value_of(y_vec[n]);
	const double alpha_dbl = value_of(alpha_vec[n]);
	const double beta_dbl = value_of(beta_vec[n]);

	// reusable subexpressions values
	if (y_dbl < 0 || y_dbl > 1)
	  return 0.0;

	const double log_y = log(y_dbl);
	const double log1m_y = log1m(y_dbl);
	// log probability
	if (include_summand<Prop,T_scale_succ,T_scale_fail>::value)
	  logp += lgamma(alpha_dbl + beta_dbl);
	if (include_summand<Prop,T_scale_succ>::value)
	  logp -= lgamma(alpha_dbl);
	if (include_summand<Prop,T_scale_fail>::value)
	  logp -= lgamma(beta_dbl);
	if (include_summand<Prop,T_y,T_scale_succ>::value)
	  logp += (alpha_dbl-1.0) * log_y;
	if (include_summand<Prop,T_y,T_scale_fail>::value)
	  logp += (beta_dbl-1.0) * log1m_y;

	// gradients
	const double digamma_alpha_beta = boost::math::digamma(alpha_dbl + beta_dbl);
	const double digamma_alpha = boost::math::digamma(alpha_dbl);
	const double digamma_beta = boost::math::digamma(beta_dbl);

	if (!is_constant<typename is_vector<T_y>::type>::value)
	  operands_and_partials.d_x1[n] += (alpha_dbl-1)/y_dbl + (beta_dbl-1)/(y_dbl-1);
	if (!is_constant<typename is_vector<T_scale_succ>::type>::value)
	  operands_and_partials.d_x2[n] += log_y + digamma_alpha_beta - digamma_alpha;
	if (!is_constant<typename is_vector<T_scale_fail>::type>::value)
	  operands_and_partials.d_x3[n] += log1m_y + digamma_alpha_beta - digamma_beta;
      }
      return operands_and_partials.to_var(logp);
    }

    template <bool Prop,
              typename T_y, typename T_scale_succ, typename T_scale_fail>
    inline
    typename return_type<T_y,T_scale_succ,T_scale_fail>::type
    beta_log(const T_y& y, const T_scale_succ& alpha, const T_scale_fail& beta) {
      return beta_log<Prop>(y,alpha,beta,stan::math::default_policy());
    }

    template <typename T_y, typename T_scale_succ, typename T_scale_fail,
              class Policy>
    typename return_type<T_y,T_scale_succ,T_scale_fail>::type
    beta_log(const T_y& y, const T_scale_succ& alpha, const T_scale_fail& beta,
             const Policy&) {
      return beta_log<false>(y,alpha,beta,Policy());
    }

    template <typename T_y, typename T_scale_succ, typename T_scale_fail>
    inline
    typename return_type<T_y,T_scale_succ,T_scale_fail>::type
    beta_log(const T_y& y, const T_scale_succ& alpha, const T_scale_fail& beta) {
      return beta_log<false>(y,alpha,beta,stan::math::default_policy());
    }

    /**
     * Calculates the beta cumulative distribution function for the given
     * variate and scale variables.
     *
     * @param y A scalar variate.
     * @param alpha Prior sample size.
     * @param beta Prior sample size.
     * @return The beta cdf evaluated at the specified arguments.
     * @tparam T_y Type of y.
     * @tparam T_scale_succ Type of alpha.
     * @tparam T_scale_fail Type of beta.
     * @tparam Policy Error-handling policy.
     */
    template <typename T_y, typename T_scale_succ, typename T_scale_fail,
              class Policy>
    typename return_type<T_y,T_scale_succ,T_scale_fail>::type
    beta_cdf(const T_y& y, const T_scale_succ& alpha, const T_scale_fail& beta,
	     const Policy&) {
      static const char* function = "stan::prob::beta_cdf(%1%)";

      using stan::math::check_positive;
      using stan::math::check_finite;
      using stan::math::check_not_nan;
      using boost::math::tools::promote_args;

      typename promote_args<T_y,T_scale_succ,T_scale_fail>::type lp;
      if (!check_finite(function, alpha,
                        "First shape parameter",
                        &lp, Policy()))
        return lp;
      if (!check_positive(function, alpha,
                          "First shape parameter",
                          &lp, Policy()))
        return lp;
      if (!check_finite(function, beta,
                          "Second shape parameter",
                          &lp, Policy()))
        return lp;
      if (!check_positive(function, beta,
                          "Second shape parameter",
                          &lp, Policy()))
        return lp;
      if (!check_not_nan(function, y, "Random variable", &lp, Policy()))
        return lp;

      if (y < 0.0)
        return 0;
      if (y > 1.0)
        return 1.0;

      return stan::math::ibeta(alpha, beta, y);
    }

    template <typename T_y, typename T_scale_succ, typename T_scale_fail>
    typename return_type<T_y,T_scale_succ,T_scale_fail>::type
    beta_cdf(const T_y& y, const T_scale_succ& alpha, const T_scale_fail& beta) {
      return beta_cdf(y,alpha,beta,stan::math::default_policy());
    }
  }
}
#endif
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: grviewsh.cxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: kz $ $Date: 2006-12-12 19:18:03 $
 *
 *  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
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sd.hxx"

#include "GraphicViewShell.hxx"
#include "LayerTabBar.hxx"
#include "FrameView.hxx"
#include <sfx2/objsh.hxx>
#include <sfx2/viewfrm.hxx>
#include <vcl/scrbar.hxx>

#ifndef _SV_SALBTYPE_HXX
#include <vcl/salbtype.hxx>     // FRound
#endif

namespace sd {

static const int TABCONTROL_INITIAL_SIZE = 350;

/*************************************************************************
|*
|* Standard-Konstruktor
|*
\************************************************************************/

GraphicViewShell::GraphicViewShell (
    SfxViewFrame* pFrame,
    ViewShellBase& rViewShellBase,
    ::Window* pParentWindow,
    FrameView* pFrameView)
    : DrawViewShell (
        pFrame,
        rViewShellBase,
        pParentWindow,
        PK_STANDARD,
        pFrameView)
{
    ConstructGraphicViewShell();
}

/*************************************************************************
|*
|* Copy-Konstruktor
|*
\************************************************************************/

GraphicViewShell::GraphicViewShell (
    SfxViewFrame* pFrame,
    ::Window* pParentWindow,
    const DrawViewShell& rShell)
    : DrawViewShell (pFrame, pParentWindow, rShell)
{
    ConstructGraphicViewShell();
}

GraphicViewShell::~GraphicViewShell (void)
{
}

void GraphicViewShell::ConstructGraphicViewShell(void)
{
    meShellType = ST_DRAW;

    mpLayerTabBar.reset (new LayerTabBar(this,GetParentWindow()));
    mpLayerTabBar->SetSplitHdl(LINK(this,GraphicViewShell,TabBarSplitHandler));

    // pb: #i67363# no layer tabbar on preview mode
    if ( !GetObjectShell()->IsPreview() )
        mpLayerTabBar->Show();
}

void GraphicViewShell::ChangeEditMode (
    EditMode eMode,
    bool )
{
    // There is no page tab that could be shown instead of the layer tab.
    // Therefore we have it allways visible regardless of what the caller
    // said. (We have to change the callers behaviour, of course.)
    DrawViewShell::ChangeEditMode (eMode, true);
}

void GraphicViewShell::ArrangeGUIElements (void)
{
    if (mpLayerTabBar.get()!=NULL && mpLayerTabBar->IsVisible())
    {
        Size aSize = mpLayerTabBar->GetSizePixel();
        const Size aFrameSize (
            GetViewFrame()->GetWindow().GetOutputSizePixel());

        if (aSize.Width() == 0)
        {
            if (mpFrameView->GetTabCtrlPercent() == 0.0)
                aSize.Width() = TABCONTROL_INITIAL_SIZE;
            else
                aSize.Width() = FRound(aFrameSize.Width()
                    * mpFrameView->GetTabCtrlPercent());
        }
        aSize.Height() = GetParentWindow()->GetSettings().GetStyleSettings()
            .GetScrollBarSize();

        Point aPos (0, maViewSize.Height() - aSize.Height());

        mpLayerTabBar->SetPosSizePixel (aPos, aSize);

        if (aFrameSize.Width() > 0)
            mpFrameView->SetTabCtrlPercent (
                (double) maTabControl.GetSizePixel().Width()
                / aFrameSize.Width());
        else
            mpFrameView->SetTabCtrlPercent( 0.0 );
    }

    DrawViewShell::ArrangeGUIElements();
}

IMPL_LINK(GraphicViewShell, TabBarSplitHandler, TabBar*, pTabBar)
{
    const long int nMax = maViewSize.Width()
        - maScrBarWH.Width()
        - pTabBar->GetPosPixel().X();

    Size aTabSize = pTabBar->GetSizePixel();
    aTabSize.Width() = Min(pTabBar->GetSplitSize(), (long)(nMax-1));

    pTabBar->SetSizePixel (aTabSize);

    Point aPos = pTabBar->GetPosPixel();
    aPos.X() += aTabSize.Width();

    Size aScrSize (nMax - aTabSize.Width(), maScrBarWH.Height());
    mpHorizontalScrollBar->SetPosSizePixel(aPos, aScrSize);

    return 0;
}

} // end of namespace sd
<commit_msg>INTEGRATION: CWS changefileheader (1.9.298); FILE MERGED 2008/04/01 15:36:35 thb 1.9.298.2: #i85898# Stripping all external header guards 2008/03/31 13:59:13 rt 1.9.298.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: grviewsh.cxx,v $
 * $Revision: 1.10 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sd.hxx"

#include "GraphicViewShell.hxx"
#include "LayerTabBar.hxx"
#include "FrameView.hxx"
#include <sfx2/objsh.hxx>
#include <sfx2/viewfrm.hxx>
#include <vcl/scrbar.hxx>
#include <vcl/salbtype.hxx>     // FRound

namespace sd {

static const int TABCONTROL_INITIAL_SIZE = 350;

/*************************************************************************
|*
|* Standard-Konstruktor
|*
\************************************************************************/

GraphicViewShell::GraphicViewShell (
    SfxViewFrame* pFrame,
    ViewShellBase& rViewShellBase,
    ::Window* pParentWindow,
    FrameView* pFrameView)
    : DrawViewShell (
        pFrame,
        rViewShellBase,
        pParentWindow,
        PK_STANDARD,
        pFrameView)
{
    ConstructGraphicViewShell();
}

/*************************************************************************
|*
|* Copy-Konstruktor
|*
\************************************************************************/

GraphicViewShell::GraphicViewShell (
    SfxViewFrame* pFrame,
    ::Window* pParentWindow,
    const DrawViewShell& rShell)
    : DrawViewShell (pFrame, pParentWindow, rShell)
{
    ConstructGraphicViewShell();
}

GraphicViewShell::~GraphicViewShell (void)
{
}

void GraphicViewShell::ConstructGraphicViewShell(void)
{
    meShellType = ST_DRAW;

    mpLayerTabBar.reset (new LayerTabBar(this,GetParentWindow()));
    mpLayerTabBar->SetSplitHdl(LINK(this,GraphicViewShell,TabBarSplitHandler));

    // pb: #i67363# no layer tabbar on preview mode
    if ( !GetObjectShell()->IsPreview() )
        mpLayerTabBar->Show();
}

void GraphicViewShell::ChangeEditMode (
    EditMode eMode,
    bool )
{
    // There is no page tab that could be shown instead of the layer tab.
    // Therefore we have it allways visible regardless of what the caller
    // said. (We have to change the callers behaviour, of course.)
    DrawViewShell::ChangeEditMode (eMode, true);
}

void GraphicViewShell::ArrangeGUIElements (void)
{
    if (mpLayerTabBar.get()!=NULL && mpLayerTabBar->IsVisible())
    {
        Size aSize = mpLayerTabBar->GetSizePixel();
        const Size aFrameSize (
            GetViewFrame()->GetWindow().GetOutputSizePixel());

        if (aSize.Width() == 0)
        {
            if (mpFrameView->GetTabCtrlPercent() == 0.0)
                aSize.Width() = TABCONTROL_INITIAL_SIZE;
            else
                aSize.Width() = FRound(aFrameSize.Width()
                    * mpFrameView->GetTabCtrlPercent());
        }
        aSize.Height() = GetParentWindow()->GetSettings().GetStyleSettings()
            .GetScrollBarSize();

        Point aPos (0, maViewSize.Height() - aSize.Height());

        mpLayerTabBar->SetPosSizePixel (aPos, aSize);

        if (aFrameSize.Width() > 0)
            mpFrameView->SetTabCtrlPercent (
                (double) maTabControl.GetSizePixel().Width()
                / aFrameSize.Width());
        else
            mpFrameView->SetTabCtrlPercent( 0.0 );
    }

    DrawViewShell::ArrangeGUIElements();
}

IMPL_LINK(GraphicViewShell, TabBarSplitHandler, TabBar*, pTabBar)
{
    const long int nMax = maViewSize.Width()
        - maScrBarWH.Width()
        - pTabBar->GetPosPixel().X();

    Size aTabSize = pTabBar->GetSizePixel();
    aTabSize.Width() = Min(pTabBar->GetSplitSize(), (long)(nMax-1));

    pTabBar->SetSizePixel (aTabSize);

    Point aPos = pTabBar->GetPosPixel();
    aPos.X() += aTabSize.Width();

    Size aScrSize (nMax - aTabSize.Width(), maScrBarWH.Height());
    mpHorizontalScrollBar->SetPosSizePixel(aPos, aScrSize);

    return 0;
}

} // end of namespace sd
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: tabcontr.cxx,v $
 *
 *  $Revision: 1.19 $
 *
 *  last change: $Author: kz $ $Date: 2006-12-12 19:22:49 $
 *
 *  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
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sd.hxx"

#include "TabControl.hxx"

#include <sfx2/viewfrm.hxx>

#ifndef _SVDLAYER_HXX
#include <svx/svdlayer.hxx>
#endif
#ifndef _SVDPAGV_HXX //autogen
#include <svx/svdpagv.hxx>
#endif
#ifndef _SFXDISPATCH_HXX //autogen
#include <sfx2/dispatch.hxx>
#endif

#include "sdattr.hxx"
#include "app.hxx"
#include "app.hrc"
#include "glob.hrc"
#include "res_bmp.hrc"
#ifndef SD_DRAW_VIEW_SHELL_HXX
#include "DrawViewShell.hxx"
#endif
#ifndef SD_GRAPHIC_VIEW_SHELL_HXX
#include "GraphicViewShell.hxx"
#endif
#include "helpids.h"
#ifndef SD_VIEW_HXX
#include "View.hxx"
#endif
#include "sdpage.hxx"
#include "drawdoc.hxx"
#ifndef SD_WINDOW_HXX
#include "Window.hxx"
#endif
#include "unmodpg.hxx"
#include "DrawDocShell.hxx"
#include "sdresid.hxx"

namespace sd {

#define SWITCH_TIMEOUT  20

// -----------------------------------------
// - SdTabControl::SdPageObjsTransferable -
// -----------------------------------------

TabControl::TabControlTransferable::~TabControlTransferable()
{
}

// -----------------------------------------------------------------------------

void TabControl::TabControlTransferable::AddSupportedFormats()
{
    AddFormat( SOT_FORMATSTR_ID_STARDRAW_TABBAR );
}

// -----------------------------------------------------------------------------

sal_Bool TabControl::TabControlTransferable::GetData( const ::com::sun::star::datatransfer::DataFlavor& )
{
    return sal_False;
}

// -----------------------------------------------------------------------------

void TabControl::TabControlTransferable::DragFinished( sal_Int8 nDropAction )
{
    mrParent.DragFinished( nDropAction );
}

/*************************************************************************
|*
|* Standard-Konstruktor
|*
\************************************************************************/

TabControl::TabControl(DrawViewShell* pViewSh, Window* pParent) :
    TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_SIZEABLE | WB_DRAG) ),
    DragSourceHelper( this ),
    DropTargetHelper( this ),
    pDrViewSh(pViewSh),
    bInternalMove(FALSE)
{
    EnableEditMode();
    SetSizePixel(Size(0, 0));
    SetMaxPageWidth( 150 );
    SetHelpId( HID_SD_TABBAR_PAGES );
}

/*************************************************************************
|*
|* Destruktor
|*
\************************************************************************/

TabControl::~TabControl()
{
}

/*************************************************************************
|*
\************************************************************************/

void TabControl::Select()
{
    SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
    pDispatcher->Execute(SID_SWITCHPAGE, SFX_CALLMODE_ASYNCHRON |
                            SFX_CALLMODE_RECORD);
}

/*************************************************************************
|*
\************************************************************************/

void  TabControl::MouseButtonDown(const MouseEvent& rMEvt)
{
    if (rMEvt.IsLeft()
        && !rMEvt.IsMod1()
        && !rMEvt.IsMod2()
        && !rMEvt.IsShift())
    {
        Point aPos = PixelToLogic( rMEvt.GetPosPixel() );
        USHORT aPageId = GetPageId(aPos);

        if (aPageId == 0)
        {
            SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();

            pDispatcher->Execute(SID_INSERTPAGE_QUICK,
                                SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
        }
    }

    // A single left click with pressed control key on a tab page first
    // switches to that page before the usual handling (copying with drag
    // and drop) takes place.
    else if (rMEvt.IsLeft() && rMEvt.IsMod1() && !rMEvt.IsMod2() && !rMEvt.IsShift())
    {
        pDrViewSh->SwitchPage (GetPageId (rMEvt.GetPosPixel()) - 1);
    }

    // When only the right button is pressed then first process a
    // synthesized left button click to make the page the current one
    // whose tab has been clicked.  When then the actual right button
    // click is processed the resulting context menu relates to the
    // now current page.
    if (rMEvt.IsRight() && ! rMEvt.IsLeft())
    {
        MouseEvent aSyntheticEvent (
            rMEvt.GetPosPixel(),
            rMEvt.GetClicks(),
            rMEvt.GetMode(),
            MOUSE_LEFT,
            rMEvt.GetModifier());
        TabBar::MouseButtonDown(aSyntheticEvent);
    }

    TabBar::MouseButtonDown(rMEvt);
}

/*************************************************************************
|*
\************************************************************************/

void TabControl::DoubleClick()
{
    if (GetCurPageId() != 0)
    {
        SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
        pDispatcher->Execute( SID_MODIFYPAGE,
                        SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
    }
}

/*************************************************************************
|*
|* StartDrag-Request
|*
\************************************************************************/

void TabControl::StartDrag( sal_Int8, const Point& )
{
    bInternalMove = TRUE;

    // object is delete by reference mechanismn
    ( new TabControl::TabControlTransferable( *this ) )->StartDrag( this, DND_ACTION_COPYMOVE );
}

/*************************************************************************
|*
|* DragFinished
|*
\************************************************************************/

void TabControl::DragFinished( sal_Int8 )
{
    bInternalMove = FALSE;
}

/*************************************************************************
|*
|* AcceptDrop-Event
|*
\************************************************************************/

sal_Int8 TabControl::AcceptDrop( const AcceptDropEvent& rEvt )
{
    sal_Int8 nRet = DND_ACTION_NONE;

    if( rEvt.mbLeaving )
        EndSwitchPage();

    if( !pDrViewSh->GetDocSh()->IsReadOnly() )
    {
        SdDrawDocument* pDoc = pDrViewSh->GetDoc();
        Point           aPos( rEvt.maPosPixel );

        if( bInternalMove )
        {
            if( rEvt.mbLeaving || ( pDrViewSh->GetEditMode() == EM_MASTERPAGE ) )
                HideDropPos();
            else
            {
                ShowDropPos( aPos );
                nRet = rEvt.mnAction;
            }
        }
        else
        {
            HideDropPos();

            sal_Int32 nPageId = GetPageId( aPos ) - 1;

            if( ( nPageId >= 0 ) && pDoc->GetPage( (USHORT)nPageId ) )
            {
                nRet = pDrViewSh->AcceptDrop( rEvt, *this, NULL, (USHORT)nPageId, SDRLAYER_NOTFOUND );
                SwitchPage( aPos );
            }
        }
    }

    return nRet;
}

/*************************************************************************
|*
|* ExecuteDrop-Event
|*
\************************************************************************/

sal_Int8 TabControl::ExecuteDrop( const ExecuteDropEvent& rEvt )
{
    SdDrawDocument* pDoc = pDrViewSh->GetDoc();
    Point           aPos( rEvt.maPosPixel );
    sal_Int8        nRet = DND_ACTION_NONE;

    if( bInternalMove )
    {
        USHORT nPageId = ShowDropPos( aPos ) - 1;

        switch (rEvt.mnAction)
        {
            case DND_ACTION_MOVE:
                if( pDrViewSh->IsSwitchPageAllowed() && pDoc->MovePages( nPageId ) )
                {
                    SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
                    pDispatcher->Execute(SID_SWITCHPAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
                }
                break;

            case DND_ACTION_COPY:
            {
                // Copying the selected page to the place that rEvt points
                // takes place in three steps:
                // 1. Create a copy of the selected page.  This copy will
                // lie directly behind the selected page.
                // 2. Move the copy to the desired place.
                // 3. Select the copy.
                if (pDrViewSh->IsSwitchPageAllowed())
                {
                    // 1. Create a copy.
                    USHORT nPageNumOfCopy = pDoc->DuplicatePage (GetCurPageId() - 1);
                    // 2. Move page.  For this first switch to the copy:
                    // MovePages operates on the currently selected page(s).
                    pDrViewSh->SwitchPage (nPageNumOfCopy);
                    // Adapt target page id when necessary, i.e. page copy
                    // has been inserted in front of the target page.
                    USHORT nPageNum = nPageId;
                    if ((nPageNumOfCopy <= nPageNum) && (nPageNum != (USHORT)-1))
                        nPageNum += 1;
                    if (pDoc->MovePages(nPageNum))
                    {
                        // 3. Switch to the copy that has been moved to its
                        // final destination.  Use an asynchron slot call to
                        // be executed after the still pending ones.
                        if (nPageNumOfCopy >= nPageNum || (nPageNum == (USHORT)-1))
                            nPageNum += 1;
                        SetCurPageId (GetPageId(nPageNum));
                        SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
                        pDispatcher->Execute(SID_SWITCHPAGE,
                            SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
                    }
                }

                break;
            }
        }

        nRet = rEvt.mnAction;
    }
    else
    {
        sal_Int32 nPageId = GetPageId( aPos ) - 1;

        if( ( nPageId >= 0 ) && pDoc->GetPage( (USHORT)nPageId ) )
        {
            nRet = pDrViewSh->ExecuteDrop( rEvt, *this, NULL, (USHORT)nPageId, SDRLAYER_NOTFOUND );
        }
    }

    HideDropPos();
    EndSwitchPage();

    return nRet;
}

/*************************************************************************
|*
\************************************************************************/

void TabControl::Command(const CommandEvent& rCEvt)
{
    USHORT nCmd = rCEvt.GetCommand();

    if ( nCmd == COMMAND_CONTEXTMENU )
    {
        BOOL bGraphicShell = pDrViewSh->ISA(GraphicViewShell);
        USHORT nResId = bGraphicShell ? RID_GRAPHIC_PAGETAB_POPUP :
                                        RID_DRAW_PAGETAB_POPUP;
        SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
        pDispatcher->ExecutePopup( SdResId( nResId ) );
    }
}

/*************************************************************************
|*
\************************************************************************/

long TabControl::StartRenaming()
{
    BOOL bOK = FALSE;

    if (pDrViewSh->GetPageKind() == PK_STANDARD)
    {
        bOK = TRUE;

        ::sd::View* pView = pDrViewSh->GetView();

        if ( pView->IsTextEdit() )
            pView->SdrEndTextEdit();
    }

    return( bOK );
}

/*************************************************************************
|*
\************************************************************************/

long TabControl::AllowRenaming()
{
    BOOL bOK = TRUE;

    String aNewName( GetEditText() );
    String aCompareName( GetPageText( GetEditPageId() ) );

    if( aCompareName != aNewName )
    {
        // Seite umbenennen
        if( pDrViewSh->GetDocSh()->CheckPageName( this, aNewName ) )
        {
            SetEditText( aNewName );
            EndRenaming();
        }
        else
        {
            bOK = FALSE;
        }
    }
    return( bOK );
}

/*************************************************************************
|*
\************************************************************************/

void TabControl::EndRenaming()
{
    if( !IsEditModeCanceled() )
        pDrViewSh->RenameSlide( GetEditPageId(), GetEditText() );
}

/*************************************************************************
|*
\************************************************************************/

void TabControl::ActivatePage()
{
    if ( /*IsInSwitching && */ pDrViewSh->IsSwitchPageAllowed() )
    {
        SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
        pDispatcher->Execute(SID_SWITCHPAGE,
                             SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
    }
}

/*************************************************************************
|*
\************************************************************************/

long TabControl::DeactivatePage()
{
    return pDrViewSh->IsSwitchPageAllowed();
}

void TabControl::SendActivatePageEvent (void)
{
    CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED,
        reinterpret_cast<void*>(GetCurPageId()));
}

void TabControl::SendDeactivatePageEvent (void)
{
    CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED,
        reinterpret_cast<void*>(GetCurPageId()));
}

} // end of namespace sd
<commit_msg>INTEGRATION: CWS changefileheader (1.19.298); FILE MERGED 2008/04/01 15:36:41 thb 1.19.298.3: #i85898# Stripping all external header guards 2008/04/01 12:39:43 thb 1.19.298.2: #i85898# Stripping all external header guards 2008/03/31 13:59:14 rt 1.19.298.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: tabcontr.cxx,v $
 * $Revision: 1.20 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sd.hxx"

#include "TabControl.hxx"

#include <sfx2/viewfrm.hxx>
#include <svx/svdlayer.hxx>
#include <svx/svdpagv.hxx>
#include <sfx2/dispatch.hxx>

#include "sdattr.hxx"
#include "app.hxx"
#include "app.hrc"
#include "glob.hrc"
#include "res_bmp.hrc"
#include "DrawViewShell.hxx"
#include "GraphicViewShell.hxx"
#include "helpids.h"
#include "View.hxx"
#include "sdpage.hxx"
#include "drawdoc.hxx"
#include "Window.hxx"
#include "unmodpg.hxx"
#include "DrawDocShell.hxx"
#include "sdresid.hxx"

namespace sd {

#define SWITCH_TIMEOUT  20

// -----------------------------------------
// - SdTabControl::SdPageObjsTransferable -
// -----------------------------------------

TabControl::TabControlTransferable::~TabControlTransferable()
{
}

// -----------------------------------------------------------------------------

void TabControl::TabControlTransferable::AddSupportedFormats()
{
    AddFormat( SOT_FORMATSTR_ID_STARDRAW_TABBAR );
}

// -----------------------------------------------------------------------------

sal_Bool TabControl::TabControlTransferable::GetData( const ::com::sun::star::datatransfer::DataFlavor& )
{
    return sal_False;
}

// -----------------------------------------------------------------------------

void TabControl::TabControlTransferable::DragFinished( sal_Int8 nDropAction )
{
    mrParent.DragFinished( nDropAction );
}

/*************************************************************************
|*
|* Standard-Konstruktor
|*
\************************************************************************/

TabControl::TabControl(DrawViewShell* pViewSh, Window* pParent) :
    TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_SIZEABLE | WB_DRAG) ),
    DragSourceHelper( this ),
    DropTargetHelper( this ),
    pDrViewSh(pViewSh),
    bInternalMove(FALSE)
{
    EnableEditMode();
    SetSizePixel(Size(0, 0));
    SetMaxPageWidth( 150 );
    SetHelpId( HID_SD_TABBAR_PAGES );
}

/*************************************************************************
|*
|* Destruktor
|*
\************************************************************************/

TabControl::~TabControl()
{
}

/*************************************************************************
|*
\************************************************************************/

void TabControl::Select()
{
    SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
    pDispatcher->Execute(SID_SWITCHPAGE, SFX_CALLMODE_ASYNCHRON |
                            SFX_CALLMODE_RECORD);
}

/*************************************************************************
|*
\************************************************************************/

void  TabControl::MouseButtonDown(const MouseEvent& rMEvt)
{
    if (rMEvt.IsLeft()
        && !rMEvt.IsMod1()
        && !rMEvt.IsMod2()
        && !rMEvt.IsShift())
    {
        Point aPos = PixelToLogic( rMEvt.GetPosPixel() );
        USHORT aPageId = GetPageId(aPos);

        if (aPageId == 0)
        {
            SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();

            pDispatcher->Execute(SID_INSERTPAGE_QUICK,
                                SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
        }
    }

    // A single left click with pressed control key on a tab page first
    // switches to that page before the usual handling (copying with drag
    // and drop) takes place.
    else if (rMEvt.IsLeft() && rMEvt.IsMod1() && !rMEvt.IsMod2() && !rMEvt.IsShift())
    {
        pDrViewSh->SwitchPage (GetPageId (rMEvt.GetPosPixel()) - 1);
    }

    // When only the right button is pressed then first process a
    // synthesized left button click to make the page the current one
    // whose tab has been clicked.  When then the actual right button
    // click is processed the resulting context menu relates to the
    // now current page.
    if (rMEvt.IsRight() && ! rMEvt.IsLeft())
    {
        MouseEvent aSyntheticEvent (
            rMEvt.GetPosPixel(),
            rMEvt.GetClicks(),
            rMEvt.GetMode(),
            MOUSE_LEFT,
            rMEvt.GetModifier());
        TabBar::MouseButtonDown(aSyntheticEvent);
    }

    TabBar::MouseButtonDown(rMEvt);
}

/*************************************************************************
|*
\************************************************************************/

void TabControl::DoubleClick()
{
    if (GetCurPageId() != 0)
    {
        SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
        pDispatcher->Execute( SID_MODIFYPAGE,
                        SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
    }
}

/*************************************************************************
|*
|* StartDrag-Request
|*
\************************************************************************/

void TabControl::StartDrag( sal_Int8, const Point& )
{
    bInternalMove = TRUE;

    // object is delete by reference mechanismn
    ( new TabControl::TabControlTransferable( *this ) )->StartDrag( this, DND_ACTION_COPYMOVE );
}

/*************************************************************************
|*
|* DragFinished
|*
\************************************************************************/

void TabControl::DragFinished( sal_Int8 )
{
    bInternalMove = FALSE;
}

/*************************************************************************
|*
|* AcceptDrop-Event
|*
\************************************************************************/

sal_Int8 TabControl::AcceptDrop( const AcceptDropEvent& rEvt )
{
    sal_Int8 nRet = DND_ACTION_NONE;

    if( rEvt.mbLeaving )
        EndSwitchPage();

    if( !pDrViewSh->GetDocSh()->IsReadOnly() )
    {
        SdDrawDocument* pDoc = pDrViewSh->GetDoc();
        Point           aPos( rEvt.maPosPixel );

        if( bInternalMove )
        {
            if( rEvt.mbLeaving || ( pDrViewSh->GetEditMode() == EM_MASTERPAGE ) )
                HideDropPos();
            else
            {
                ShowDropPos( aPos );
                nRet = rEvt.mnAction;
            }
        }
        else
        {
            HideDropPos();

            sal_Int32 nPageId = GetPageId( aPos ) - 1;

            if( ( nPageId >= 0 ) && pDoc->GetPage( (USHORT)nPageId ) )
            {
                nRet = pDrViewSh->AcceptDrop( rEvt, *this, NULL, (USHORT)nPageId, SDRLAYER_NOTFOUND );
                SwitchPage( aPos );
            }
        }
    }

    return nRet;
}

/*************************************************************************
|*
|* ExecuteDrop-Event
|*
\************************************************************************/

sal_Int8 TabControl::ExecuteDrop( const ExecuteDropEvent& rEvt )
{
    SdDrawDocument* pDoc = pDrViewSh->GetDoc();
    Point           aPos( rEvt.maPosPixel );
    sal_Int8        nRet = DND_ACTION_NONE;

    if( bInternalMove )
    {
        USHORT nPageId = ShowDropPos( aPos ) - 1;

        switch (rEvt.mnAction)
        {
            case DND_ACTION_MOVE:
                if( pDrViewSh->IsSwitchPageAllowed() && pDoc->MovePages( nPageId ) )
                {
                    SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
                    pDispatcher->Execute(SID_SWITCHPAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
                }
                break;

            case DND_ACTION_COPY:
            {
                // Copying the selected page to the place that rEvt points
                // takes place in three steps:
                // 1. Create a copy of the selected page.  This copy will
                // lie directly behind the selected page.
                // 2. Move the copy to the desired place.
                // 3. Select the copy.
                if (pDrViewSh->IsSwitchPageAllowed())
                {
                    // 1. Create a copy.
                    USHORT nPageNumOfCopy = pDoc->DuplicatePage (GetCurPageId() - 1);
                    // 2. Move page.  For this first switch to the copy:
                    // MovePages operates on the currently selected page(s).
                    pDrViewSh->SwitchPage (nPageNumOfCopy);
                    // Adapt target page id when necessary, i.e. page copy
                    // has been inserted in front of the target page.
                    USHORT nPageNum = nPageId;
                    if ((nPageNumOfCopy <= nPageNum) && (nPageNum != (USHORT)-1))
                        nPageNum += 1;
                    if (pDoc->MovePages(nPageNum))
                    {
                        // 3. Switch to the copy that has been moved to its
                        // final destination.  Use an asynchron slot call to
                        // be executed after the still pending ones.
                        if (nPageNumOfCopy >= nPageNum || (nPageNum == (USHORT)-1))
                            nPageNum += 1;
                        SetCurPageId (GetPageId(nPageNum));
                        SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
                        pDispatcher->Execute(SID_SWITCHPAGE,
                            SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
                    }
                }

                break;
            }
        }

        nRet = rEvt.mnAction;
    }
    else
    {
        sal_Int32 nPageId = GetPageId( aPos ) - 1;

        if( ( nPageId >= 0 ) && pDoc->GetPage( (USHORT)nPageId ) )
        {
            nRet = pDrViewSh->ExecuteDrop( rEvt, *this, NULL, (USHORT)nPageId, SDRLAYER_NOTFOUND );
        }
    }

    HideDropPos();
    EndSwitchPage();

    return nRet;
}

/*************************************************************************
|*
\************************************************************************/

void TabControl::Command(const CommandEvent& rCEvt)
{
    USHORT nCmd = rCEvt.GetCommand();

    if ( nCmd == COMMAND_CONTEXTMENU )
    {
        BOOL bGraphicShell = pDrViewSh->ISA(GraphicViewShell);
        USHORT nResId = bGraphicShell ? RID_GRAPHIC_PAGETAB_POPUP :
                                        RID_DRAW_PAGETAB_POPUP;
        SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
        pDispatcher->ExecutePopup( SdResId( nResId ) );
    }
}

/*************************************************************************
|*
\************************************************************************/

long TabControl::StartRenaming()
{
    BOOL bOK = FALSE;

    if (pDrViewSh->GetPageKind() == PK_STANDARD)
    {
        bOK = TRUE;

        ::sd::View* pView = pDrViewSh->GetView();

        if ( pView->IsTextEdit() )
            pView->SdrEndTextEdit();
    }

    return( bOK );
}

/*************************************************************************
|*
\************************************************************************/

long TabControl::AllowRenaming()
{
    BOOL bOK = TRUE;

    String aNewName( GetEditText() );
    String aCompareName( GetPageText( GetEditPageId() ) );

    if( aCompareName != aNewName )
    {
        // Seite umbenennen
        if( pDrViewSh->GetDocSh()->CheckPageName( this, aNewName ) )
        {
            SetEditText( aNewName );
            EndRenaming();
        }
        else
        {
            bOK = FALSE;
        }
    }
    return( bOK );
}

/*************************************************************************
|*
\************************************************************************/

void TabControl::EndRenaming()
{
    if( !IsEditModeCanceled() )
        pDrViewSh->RenameSlide( GetEditPageId(), GetEditText() );
}

/*************************************************************************
|*
\************************************************************************/

void TabControl::ActivatePage()
{
    if ( /*IsInSwitching && */ pDrViewSh->IsSwitchPageAllowed() )
    {
        SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
        pDispatcher->Execute(SID_SWITCHPAGE,
                             SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
    }
}

/*************************************************************************
|*
\************************************************************************/

long TabControl::DeactivatePage()
{
    return pDrViewSh->IsSwitchPageAllowed();
}

void TabControl::SendActivatePageEvent (void)
{
    CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED,
        reinterpret_cast<void*>(GetCurPageId()));
}

void TabControl::SendDeactivatePageEvent (void)
{
    CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED,
        reinterpret_cast<void*>(GetCurPageId()));
}

} // end of namespace sd
<|endoftext|>


<commit_before>#define CATCH_CONFIG_MAIN

#include <catch.hpp>

#include <Plugins/RoutingServices/CrowFlyRoutingService/CrowFlyRoutingService.h>
#include <Engine/SceneManager/SceneManager.h>
#include <Engine/SceneManager/Scene.h>
#include <Engine/SceneManager/Operation.h>
#include <Engine/Concepts/Basic/Capacity.h>
#include <Engine/SceneManager/Vehicle.h>
#include <Engine/SceneManager/Performer.h>
#include <Engine/SceneManager/Schedule.h>
#include <Engine/Concepts/Basic/RoutingProfile.h>
#include <Tests/Utils/Concepts/MakeLocation.h>
#include <Utils/Units/DurationUnits.h>
#include <Tests/Utils/Concepts/MakeTimeWindow.h>
#include <Utils/Collections/Algorithms.h>
#include <Engine/SceneManager/Run.h>
#include <Engine/SceneManager/Stop.h>
#include <engine/SceneManager/ScheduleActualization/Algorithms/StopDurationActualizationAlgorithm.h>
#include <Engine/SceneManager/ScheduleActualization/Algorithms/StopArrivalTimeActualizationAlgorithm.h>

#include <Tests/ConceptStreamOperators.h>

TEST_CASE("ScheduleActualizers - StopDurationActualizationAlgorithm", "[integration][schedule_actualizers]")
{
    using namespace Scheduler;

    CrowFlyRoutingService routing_service;

    SceneManager sm;

    sm.setRoutingService(&routing_service);

    Location start_location = make_location(0, 0);
    Location end_location = make_location(0, 0.5);

    Location loc1 = make_location(0, 0.1);
    Location loc2 = make_location(0, 0.2);
    Location loc3 = make_location(0, 0.3);
    Location loc4 = make_location(0, 0.4);

    Scene* s = sm.createScene();

    Performer* performer = s->createPerformer();
    Vehicle* vehicle = s->createVehicle();

    Schedule* schedule = s->createSchedule(performer);
    schedule->setDepotLocation(start_location);
    schedule->setShiftEndLocation(end_location);

    schedule->getScheduleActualizer()->createAlgorithm<StopDurationActualizationAlgorithm>();

    Run* r = schedule->createRun(start_location, end_location);
    r->setVehicle(vehicle);

    SECTION("Simple duration check")
    {

        Duration dur = Units::minutes(10);

        Operation* sop = s->createFreeOperation();
        sop->setDuration(dur);
        sop->setLocation(start_location);

        Operation* sop2 = s->createFreeOperation();
        sop2->setDuration(dur);
        sop2->setLocation(start_location);

        Operation* op1 = s->createFreeOperation();
        op1->setDuration(dur);
        op1->setLocation(loc1);

        Operation* op2 = s->createFreeOperation();
        op2->setDuration(dur);
        op2->setLocation(loc2);

        Operation* op3 = s->createFreeOperation();
        op3->setDuration(dur);
        op3->setLocation(loc3);

        Operation* op4 = s->createFreeOperation();
        op4->setDuration(dur);
        op4->setLocation(loc4);

        Operation* eop = s->createFreeOperation();
        eop->setDuration(dur);
        eop->setLocation(end_location);

        r->allocateStartOperation(sop);
        r->allocateStartOperation(sop2);
        r->allocateEndOperation(eop);

        Stop *s1 = r->getStartStop();
        Stop *s2 = r->allocateWorkOperation(op1, 0);
        Stop *s3 = r->allocateWorkOperation(op2, 1);
        Stop *s4 = r->allocateWorkOperation(op3, 2);
        Stop *s5 = r->allocateWorkOperation(op4, 3);
        Stop *s6 = r->getEndStop();

        REQUIRE(s1->getDuration() == dur);
        REQUIRE(s2->getDuration() == dur);
        REQUIRE(s3->getDuration() == dur);
        REQUIRE(s4->getDuration() == dur);
        REQUIRE(s5->getDuration() == dur);
        REQUIRE(s6->getDuration() == dur);
    }

    sm.destroyScene(s);
}

TEST_CASE("ScheduleActualizers - StopArrivalTimeActualizationAlgorithm", "[integration][schedule_actualizers]")
{
    using namespace Scheduler;

    CrowFlyRoutingService routing_service;

    SceneManager sm;

    sm.setRoutingService(&routing_service);

    Location start_location = make_location(0, 0);
    Location end_location = make_location(0, 0.5);

    Location loc1 = make_location(0, 0.1);
    Location loc2 = make_location(0, 0.2);
    Location loc3 = make_location(0, 0.3);
    Location loc4 = make_location(0, 0.4);

    Scene* s = sm.createScene();

    Duration dur = Units::minutes(10);

    Operation* op1 = s->createFreeOperation();
    op1->setDuration(dur);
    op1->setLocation(loc1);

    Operation* op2 = s->createFreeOperation();
    op2->setDuration(dur);
    op2->setLocation(loc2);

    Operation* op3 = s->createFreeOperation();
    op3->setDuration(dur);
    op3->setLocation(loc3);

    Operation* op4 = s->createFreeOperation();
    op4->setDuration(dur);
    op4->setLocation(loc4);

    Performer* performer = s->createPerformer();
    Vehicle* vehicle = s->createVehicle();

    Schedule* schedule = s->createSchedule(performer);
    schedule->setDepotLocation(start_location);
    schedule->setShiftEndLocation(end_location);

    Run* r = schedule->createRun(start_location, end_location);
    r->setVehicle(vehicle);

    Route r1 = routing_service.calculateRoute(start_location, loc1, vehicle->getRoutingProfile());
    Route r2 = routing_service.calculateRoute(loc1, loc2, vehicle->getRoutingProfile());
    Route r3 = routing_service.calculateRoute(loc2, loc3, vehicle->getRoutingProfile());
    Route r4 = routing_service.calculateRoute(loc3, loc4, vehicle->getRoutingProfile());
    Route r5 = routing_service.calculateRoute(loc4, end_location, vehicle->getRoutingProfile());

    schedule->getScheduleActualizer()->createAlgorithm<StopDurationActualizationAlgorithm>();
    schedule->getScheduleActualizer()->createAlgorithm<StopArrivalTimeActualizationAlgorithm>();

    SECTION("Broad time windows")
    {
        Stop *s1 = r->getStartStop();
        Stop *s2 = r->allocateWorkOperation(op1, 0);
        Stop *s3 = r->allocateWorkOperation(op2, 1);
        Stop *s4 = r->allocateWorkOperation(op3, 2);
        Stop *s5 = r->allocateWorkOperation(op4, 3);
        Stop *s6 = r->getEndStop();

        TimeWindow estimated_allocation_1;
        estimated_allocation_1.setStartTime(TimePoint(0));
        estimated_allocation_1.setEndTime(TimePoint(0));

        TimeWindow estimated_allocation_2;
        estimated_allocation_2.setStartTime(estimated_allocation_1.getEndTime() + r1.getDuration());
        estimated_allocation_2.setEndTime(estimated_allocation_2.getStartTime() + dur);

        TimeWindow estimated_allocation_3;
        estimated_allocation_3.setStartTime(estimated_allocation_2.getEndTime() + r2.getDuration());
        estimated_allocation_3.setEndTime(estimated_allocation_3.getStartTime() + dur);

        TimeWindow estimated_allocation_4;
        estimated_allocation_4.setStartTime(estimated_allocation_3.getEndTime() + r3.getDuration());
        estimated_allocation_4.setEndTime(estimated_allocation_4.getStartTime() + dur);

        TimeWindow estimated_allocation_5;
        estimated_allocation_5.setStartTime(estimated_allocation_4.getEndTime() + r4.getDuration());
        estimated_allocation_5.setEndTime(estimated_allocation_5.getStartTime() + dur);

        TimeWindow estimated_allocation_6;
        estimated_allocation_6.setStartTime(estimated_allocation_5.getEndTime() + r5.getDuration());
        estimated_allocation_6.setEndTime(estimated_allocation_6.getStartTime());

        REQUIRE(s1->getAllocationTime() == estimated_allocation_1);
        REQUIRE(s2->getAllocationTime() == estimated_allocation_2);
        REQUIRE(s3->getAllocationTime() == estimated_allocation_3);
        REQUIRE(s4->getAllocationTime() == estimated_allocation_4);
        REQUIRE(s5->getAllocationTime() == estimated_allocation_5);
        REQUIRE(s6->getAllocationTime() == estimated_allocation_6);
    }

    sm.destroyScene(s);
}<commit_msg>close #15 Tests are added and working<commit_after>#define CATCH_CONFIG_MAIN

#include <catch.hpp>

#include <Plugins/RoutingServices/CrowFlyRoutingService/CrowFlyRoutingService.h>
#include <Engine/SceneManager/SceneManager.h>
#include <Engine/SceneManager/Scene.h>
#include <Engine/SceneManager/Operation.h>
#include <Engine/Concepts/Basic/Capacity.h>
#include <Engine/SceneManager/Vehicle.h>
#include <Engine/SceneManager/Performer.h>
#include <Engine/SceneManager/Schedule.h>
#include <Engine/Concepts/Basic/RoutingProfile.h>
#include <Tests/Utils/Concepts/MakeLocation.h>
#include <Utils/Units/DurationUnits.h>
#include <Tests/Utils/Concepts/MakeTimeWindow.h>
#include <Utils/Collections/Algorithms.h>
#include <Engine/SceneManager/Run.h>
#include <Engine/SceneManager/Stop.h>
#include <engine/SceneManager/ScheduleActualization/Algorithms/StopDurationActualizationAlgorithm.h>
#include <Engine/SceneManager/ScheduleActualization/Algorithms/StopArrivalTimeActualizationAlgorithm.h>

#include <Tests/ConceptStreamOperators.h>

TEST_CASE("ScheduleActualizers - StopDurationActualizationAlgorithm", "[integration][schedule_actualizers]")
{
    using namespace Scheduler;

    CrowFlyRoutingService routing_service;

    SceneManager sm;

    sm.setRoutingService(&routing_service);

    Location start_location = make_location(0, 0);
    Location end_location = make_location(0, 0.5);

    Location loc1 = make_location(0, 0.1);
    Location loc2 = make_location(0, 0.2);
    Location loc3 = make_location(0, 0.3);
    Location loc4 = make_location(0, 0.4);

    Scene* s = sm.createScene();

    Performer* performer = s->createPerformer();
    Vehicle* vehicle = s->createVehicle();

    Schedule* schedule = s->createSchedule(performer);
    schedule->setDepotLocation(start_location);
    schedule->setShiftEndLocation(end_location);

    schedule->getScheduleActualizer()->createAlgorithm<StopDurationActualizationAlgorithm>();

    Run* r = schedule->createRun(start_location, end_location);
    r->setVehicle(vehicle);

    SECTION("Simple duration check")
    {

        Duration dur = Units::minutes(10);

        Operation* sop = s->createFreeOperation();
        sop->setDuration(dur);
        sop->setLocation(start_location);

        Operation* sop2 = s->createFreeOperation();
        sop2->setDuration(dur);
        sop2->setLocation(start_location);

        Operation* op1 = s->createFreeOperation();
        op1->setDuration(dur);
        op1->setLocation(loc1);

        Operation* op2 = s->createFreeOperation();
        op2->setDuration(dur);
        op2->setLocation(loc2);

        Operation* op3 = s->createFreeOperation();
        op3->setDuration(dur);
        op3->setLocation(loc3);

        Operation* op4 = s->createFreeOperation();
        op4->setDuration(dur);
        op4->setLocation(loc4);

        Operation* eop = s->createFreeOperation();
        eop->setDuration(dur);
        eop->setLocation(end_location);

        r->allocateStartOperation(sop);
        r->allocateStartOperation(sop2);
        r->allocateEndOperation(eop);

        Stop *s1 = r->getStartStop();
        Stop *s2 = r->allocateWorkOperation(op1, 0);
        Stop *s3 = r->allocateWorkOperation(op2, 1);
        Stop *s4 = r->allocateWorkOperation(op3, 2);
        Stop *s5 = r->allocateWorkOperation(op4, 3);
        Stop *s6 = r->getEndStop();

        REQUIRE(s1->getDuration() == dur*2);
        REQUIRE(s2->getDuration() == dur);
        REQUIRE(s3->getDuration() == dur);
        REQUIRE(s4->getDuration() == dur);
        REQUIRE(s5->getDuration() == dur);
        REQUIRE(s6->getDuration() == dur);
    }

    sm.destroyScene(s);
}

TEST_CASE("ScheduleActualizers - StopArrivalTimeActualizationAlgorithm", "[integration][schedule_actualizers]")
{
    using namespace Scheduler;

    CrowFlyRoutingService routing_service;

    SceneManager sm;

    sm.setRoutingService(&routing_service);

    Location start_location = make_location(0, 0);
    Location end_location = make_location(0, 0.5);

    Location loc1 = make_location(0, 0.1);
    Location loc2 = make_location(0, 0.2);
    Location loc3 = make_location(0, 0.3);
    Location loc4 = make_location(0, 0.4);

    Scene* s = sm.createScene();

    Duration dur = Units::minutes(10);

    Operation* op1 = s->createFreeOperation();
    op1->setDuration(dur);
    op1->setLocation(loc1);

    Operation* op2 = s->createFreeOperation();
    op2->setDuration(dur);
    op2->setLocation(loc2);

    Operation* op3 = s->createFreeOperation();
    op3->setDuration(dur);
    op3->setLocation(loc3);

    Operation* op4 = s->createFreeOperation();
    op4->setDuration(dur);
    op4->setLocation(loc4);

    Performer* performer = s->createPerformer();
    Vehicle* vehicle = s->createVehicle();

    Schedule* schedule = s->createSchedule(performer);
    schedule->setDepotLocation(start_location);
    schedule->setShiftEndLocation(end_location);

    Run* r = schedule->createRun(start_location, end_location);
    r->setVehicle(vehicle);

    Route r1 = routing_service.calculateRoute(start_location, loc1, vehicle->getRoutingProfile());
    Route r2 = routing_service.calculateRoute(loc1, loc2, vehicle->getRoutingProfile());
    Route r3 = routing_service.calculateRoute(loc2, loc3, vehicle->getRoutingProfile());
    Route r4 = routing_service.calculateRoute(loc3, loc4, vehicle->getRoutingProfile());
    Route r5 = routing_service.calculateRoute(loc4, end_location, vehicle->getRoutingProfile());

    schedule->getScheduleActualizer()->createAlgorithm<StopDurationActualizationAlgorithm>();
    schedule->getScheduleActualizer()->createAlgorithm<StopArrivalTimeActualizationAlgorithm>();

    TimeWindow estimated_allocation_1;
    TimeWindow estimated_allocation_2;
    TimeWindow estimated_allocation_3;
    TimeWindow estimated_allocation_4;
    TimeWindow estimated_allocation_5;
    TimeWindow estimated_allocation_6;

    SECTION("Broad time windows") {
        estimated_allocation_1.setStartTime(TimePoint(0));
        estimated_allocation_1.setEndTime(TimePoint(0));

        estimated_allocation_2.setStartTime(estimated_allocation_1.getEndTime() + r1.getDuration());
        estimated_allocation_2.setEndTime(estimated_allocation_2.getStartTime() + dur);

        estimated_allocation_3.setStartTime(estimated_allocation_2.getEndTime() + r2.getDuration());
        estimated_allocation_3.setEndTime(estimated_allocation_3.getStartTime() + dur);

        estimated_allocation_4.setStartTime(estimated_allocation_3.getEndTime() + r3.getDuration());
        estimated_allocation_4.setEndTime(estimated_allocation_4.getStartTime() + dur);

        estimated_allocation_5.setStartTime(estimated_allocation_4.getEndTime() + r4.getDuration());
        estimated_allocation_5.setEndTime(estimated_allocation_5.getStartTime() + dur);

        estimated_allocation_6.setStartTime(estimated_allocation_5.getEndTime() + r5.getDuration());
        estimated_allocation_6.setEndTime(estimated_allocation_6.getStartTime());
    }

    SECTION("Narrow time windows")
    {
        op1->setTimeWindows({make_time_window(770, 1370)});
        op2->setTimeWindows({make_time_window(2140, 2740)});
        op3->setTimeWindows({make_time_window(3510, 4110)});
        op4->setTimeWindows({make_time_window(4880, 5480)});

        estimated_allocation_1.setStartTime(TimePoint(100));
        estimated_allocation_1.setEndTime(TimePoint(100));

        estimated_allocation_2.setStartTime(TimePoint(770));
        estimated_allocation_2.setEndTime(estimated_allocation_2.getStartTime() + dur);

        estimated_allocation_3.setStartTime(TimePoint(2140));
        estimated_allocation_3.setEndTime(estimated_allocation_3.getStartTime() + dur);

        estimated_allocation_4.setStartTime(TimePoint(3510));
        estimated_allocation_4.setEndTime(estimated_allocation_4.getStartTime() + dur);

        estimated_allocation_5.setStartTime(TimePoint(4880));
        estimated_allocation_5.setEndTime(estimated_allocation_5.getStartTime() + dur);

        estimated_allocation_6.setStartTime(estimated_allocation_5.getEndTime() + r5.getDuration());
        estimated_allocation_6.setEndTime(estimated_allocation_6.getStartTime());
    }

    SECTION("Narrow time windows with budget")
    {
        op1->setTimeWindows({make_time_window(770, 20000)});
        op2->setTimeWindows({make_time_window(2140, 20000)});
        op3->setTimeWindows({make_time_window(3510, 20000)});
        op4->setTimeWindows({make_time_window(4880, 20000)});

        estimated_allocation_1.setStartTime(TimePoint(400));
        estimated_allocation_1.setEndTime(estimated_allocation_1.getStartTime());

        estimated_allocation_2.setStartTime(TimePoint(1070));
        estimated_allocation_2.setEndTime(estimated_allocation_2.getStartTime() + dur);

        estimated_allocation_3.setStartTime(TimePoint(2340));
        estimated_allocation_3.setEndTime(estimated_allocation_3.getStartTime() + dur);

        estimated_allocation_4.setStartTime(TimePoint(3610));
        estimated_allocation_4.setEndTime(estimated_allocation_4.getStartTime() + dur);

        estimated_allocation_5.setStartTime(TimePoint(4880));
        estimated_allocation_5.setEndTime(estimated_allocation_5.getStartTime() + dur);

        estimated_allocation_6.setStartTime(estimated_allocation_5.getEndTime() + r5.getDuration());
        estimated_allocation_6.setEndTime(estimated_allocation_6.getStartTime());
    }

    SECTION("Narrow time windows with budget gap")
    {
        op1->setTimeWindows({make_time_window(770, 20000)});
        op2->setTimeWindows({make_time_window(2140, 2740)}); // <== This stop can't be shifted to compensate waiting due to its time window
        op3->setTimeWindows({make_time_window(3510, 20000)});
        op4->setTimeWindows({make_time_window(4880, 20000)});

        estimated_allocation_1.setStartTime(TimePoint(200));
        estimated_allocation_1.setEndTime(estimated_allocation_1.getStartTime());

        estimated_allocation_2.setStartTime(TimePoint(870));
        estimated_allocation_2.setEndTime(estimated_allocation_2.getStartTime() + dur);

        estimated_allocation_3.setStartTime(TimePoint(2140));
        estimated_allocation_3.setEndTime(estimated_allocation_3.getStartTime() + dur);

        estimated_allocation_4.setStartTime(TimePoint(3510));
        estimated_allocation_4.setEndTime(estimated_allocation_4.getStartTime() + dur);

        estimated_allocation_5.setStartTime(TimePoint(4880));
        estimated_allocation_5.setEndTime(estimated_allocation_5.getStartTime() + dur);

        estimated_allocation_6.setStartTime(estimated_allocation_5.getEndTime() + r5.getDuration());
        estimated_allocation_6.setEndTime(estimated_allocation_6.getStartTime());
    }

    Stop *s1 = r->getStartStop();
    Stop *s2 = r->allocateWorkOperation(op1, 0);
    Stop *s3 = r->allocateWorkOperation(op2, 1);
    Stop *s4 = r->allocateWorkOperation(op3, 2);
    Stop *s5 = r->allocateWorkOperation(op4, 3);
    Stop *s6 = r->getEndStop();

    CAPTURE(s1->getAllocationTime());
    CAPTURE(s2->getAllocationTime());
    CAPTURE(s3->getAllocationTime());
    CAPTURE(s4->getAllocationTime());
    CAPTURE(s5->getAllocationTime());
    CAPTURE(s6->getAllocationTime());

    REQUIRE(s1->getAllocationTime() == estimated_allocation_1);
    REQUIRE(s2->getAllocationTime() == estimated_allocation_2);
    REQUIRE(s3->getAllocationTime() == estimated_allocation_3);
    REQUIRE(s4->getAllocationTime() == estimated_allocation_4);
    REQUIRE(s5->getAllocationTime() == estimated_allocation_5);
    REQUIRE(s6->getAllocationTime() == estimated_allocation_6);

    sm.destroyScene(s);
}<|endoftext|>


<commit_before>/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 2000 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. 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.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xalan" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
 * ITS 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.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.ibm.com.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */
#include "XalanToXercesTranscoderWrapper.hpp"

#include <cassert>

#include <util/TransService.hpp>
#include <util/XMLException.hpp>

XalanToXercesTranscoderWrapper::XalanToXercesTranscoderWrapper(XMLTranscoder*	theTranscoder) :
	XalanOutputTranscoder(),
	m_transcoder(theTranscoder)
{
}

XalanToXercesTranscoderWrapper::~XalanToXercesTranscoderWrapper()
{
	delete m_transcoder;
}

XalanToXercesTranscoderWrapper::eCode
XalanToXercesTranscoderWrapper::transcode(
			const XalanDOMChar*		theSourceData,
			unsigned int			theSourceCount,
			XalanXMLByte*			theTarget,
			unsigned int			theTargetSize,
			unsigned int&			theSourceCharsTranscoded,
			unsigned int&			theTargetBytesUsed)
{
	eCode	theCode = XalanTranscodingServices::OK;

	try
	{
		theTargetBytesUsed = m_transcoder->transcodeTo(
			theSourceData,
			theSourceCount,
			theTarget,
			theTargetSize,
			theSourceCharsTranscoded,
			XMLTranscoder::UnRep_Throw);
	}
	catch(const XMLException&)
	{
		theSourceCharsTranscoded = 0;
		theTargetBytesUsed = 0;
		theCode = XalanTranscodingServices::InternalFailure;
	}

	return theCode;
}
<commit_msg>Used replace character instead of throwing an exception when unable to transcode a character.<commit_after>/*
 * The Apache Software License, Version 1.1
 *
 *
 * Copyright (c) 2000 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. 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.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Xalan" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 APACHE SOFTWARE FOUNDATION OR
 * ITS 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.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation and was
 * originally based on software copyright (c) 1999, International
 * Business Machines, Inc., http://www.ibm.com.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */
#include "XalanToXercesTranscoderWrapper.hpp"

#include <cassert>

#include <util/TransService.hpp>
#include <util/XMLException.hpp>

XalanToXercesTranscoderWrapper::XalanToXercesTranscoderWrapper(XMLTranscoder*	theTranscoder) :
	XalanOutputTranscoder(),
	m_transcoder(theTranscoder)
{
}

XalanToXercesTranscoderWrapper::~XalanToXercesTranscoderWrapper()
{
	delete m_transcoder;
}

XalanToXercesTranscoderWrapper::eCode
XalanToXercesTranscoderWrapper::transcode(
			const XalanDOMChar*		theSourceData,
			unsigned int			theSourceCount,
			XalanXMLByte*			theTarget,
			unsigned int			theTargetSize,
			unsigned int&			theSourceCharsTranscoded,
			unsigned int&			theTargetBytesUsed)
{
	eCode	theCode = XalanTranscodingServices::OK;

	try
	{
		theTargetBytesUsed = m_transcoder->transcodeTo(
			theSourceData,
			theSourceCount,
			theTarget,
			theTargetSize,
			theSourceCharsTranscoded,
			// $$$ ToDo: Eventually, we're going to want to
			// replace this with UnRep_Throw, and let the
			// caller try to recover.
//			XMLTranscoder::UnRep_Throw);
			XMLTranscoder::UnRep_RepChar);
	}
	catch(const XMLException&)
	{
		theSourceCharsTranscoded = 0;
		theTargetBytesUsed = 0;
		theCode = XalanTranscodingServices::InternalFailure;
	}

	return theCode;
}
<|endoftext|>


<commit_before>
#ifdef NDA_CODE_AMD_MANTLE
// NDACodeStripper v0.17: 1181 lines removed
#endif
<commit_msg>Mantle backend updated to match D3D11 behaviour.<commit_after>
#ifdef NDA_CODE_AMD_MANTLE
// NDACodeStripper v0.17: 1328 lines removed
#endif
<|endoftext|>