<commit_before>//   Copyright 2015 Patrick Putnam
//
//   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.
#ifndef CLOTHO_ROW_GROUPED_WEIGHT_ACCUMULATOR_HPP_
#define CLOTHO_ROW_GROUPED_WEIGHT_ACCUMULATOR_HPP_

#include "clotho/data_spaces/association_matrix/row_grouped_association_matrix.hpp"
#include <iostream>

#include "clotho/utility/debruijn_bit_walker.hpp"

#include <unordered_map>

namespace clotho {
namespace genetics {

template < class AlleleSpace, class BlockType, unsigned char P >
class weight_accumulator< AlleleSpace, association_matrix< BlockType, row_grouped< P > > > {
public:
    typedef AlleleSpace                                         allele_type;
    typedef association_matrix< BlockType, row_grouped< P > >     association_type;

    typedef typename allele_type::weight_type                   weight_type;
    typedef typename allele_type::weight_pointer                weight_pointer;

    typedef typename association_type::block_type               block_type;
    typedef typename association_type::raw_block_pointer        block_pointer;

    typedef clotho::utility::debruijn_bit_walker< block_type >  bit_walker_type;

    void operator()( allele_type & alls, association_type & seqs, weight_pointer res, size_t trait_count ) {
        size_t  M = seqs.row_count();

        std::unordered_map< block_pointer, size_t > analyzed;

        size_t i = 0;
        while( i < M ) {

            block_pointer start = seqs.begin_row( i );

            if( analyzed.find( start ) == analyzed.end() ) {
                analyzed[ start ] = i;
                block_pointer end = seqs.end_row(i);

                size_t j = 0;
                while( start != end ) {

                    block_type b = *start;

                    while( b ) {
                        size_t b_idx = j + bit_walker_type::unset_next_index( b );

                        weight_pointer t_start = alls.begin_trait_weight( b_idx );
                        weight_pointer t_end = alls.end_trait_weight( b_idx );

                        size_t a = i * trait_count;
                        while( t_start != t_end ) {
                            res[ a++ ] += *t_start++;
                        }
                    }
                    start += row_grouped< P >::GROUP_SIZE;

                    j += association_type::bit_helper_type::BITS_PER_BLOCK;
                }

            } else {
                size_t src = analyzed[ start ] * trait_count;
                size_t a = i * trait_count;

                size_t x = 0;
                while( x < trait_count ) {
                    res[ a + x ] = res[ src + x ];
                    ++x;
                }
            }

            ++i;
        }
    }

};

template < class AlleleSpace, class BlockType >
class weight_accumulator< AlleleSpace, association_matrix< BlockType, row_grouped< 1 > > > {
public:
    typedef AlleleSpace                                         allele_type;
    typedef association_matrix< BlockType, row_grouped< 1 > >     association_type;

    typedef typename allele_type::weight_type                   weight_type;
    typedef typename allele_type::weight_pointer                weight_pointer;

    typedef typename association_type::row_vector               row_vector;
    typedef typename row_vector::block_type                     block_type;
    typedef typename association_type::raw_block_pointer        block_pointer;

    typedef clotho::utility::debruijn_bit_walker< block_type >  bit_walker_type;

    void operator()( allele_type & alls, association_type & seqs, weight_pointer res, size_t trait_count ) {
        size_t  M = seqs.row_count();

        std::unordered_map< block_pointer, size_t > analyzed;

        size_t i = 0;
        while( i < M ) {

            block_pointer start = seqs.begin_row( i );

            if( analyzed.find( start ) == analyzed.end() ) {
                analyzed[ start ] = i;

                block_pointer end = seqs.end_row(i);

                size_t j = 0;
                while( start != end ) {
                    block_type b = *start++;

                    while( b ) {
                        size_t b_idx = j + bit_walker_type::unset_next_index( b );

                        weight_pointer t_start = alls.begin_trait_weight( b_idx );
                        weight_pointer t_end = alls.end_trait_weight( b_idx );

                        size_t a = i * trait_count;
                        while( t_start != t_end ) {
                            res[ a++ ] += *t_start++;
                        }
                    }

                    j += association_type::bit_helper_type::BITS_PER_BLOCK;
                }

            } else {
                size_t src = analyzed[ start ] * trait_count;
                size_t a = i * trait_count;

                size_t x = 0;
                while( x < trait_count ) {
                    res[ a + x ] = res[ src + x ];
                    ++x;
                }
            }
            ++i;
        }

#ifdef DEBUGGING
        std::cerr << "Weights accumulated for: " << analyzed.size() << std::endl;
#endif  // DEBUGGING
    }
};
}   // namespace genetics
}   // namespace clotho

#endif  // CLOTHO_ROW_GROUPED_WEIGHT_ACCUMULATOR_HPP_

<commit_msg>Reverting to original method<commit_after>//   Copyright 2015 Patrick Putnam
//
//   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.
#ifndef CLOTHO_ROW_GROUPED_WEIGHT_ACCUMULATOR_HPP_
#define CLOTHO_ROW_GROUPED_WEIGHT_ACCUMULATOR_HPP_

#include "clotho/data_spaces/association_matrix/row_grouped_association_matrix.hpp"
#include <iostream>

#include "clotho/utility/debruijn_bit_walker.hpp"

namespace clotho {
namespace genetics {

template < class AlleleSpace, class BlockType, unsigned char P >
class weight_accumulator< AlleleSpace, association_matrix< BlockType, row_grouped< P > > > {
public:
    typedef AlleleSpace                                         allele_type;
    typedef association_matrix< BlockType, row_grouped< P > >     association_type;

    typedef typename allele_type::weight_type                   weight_type;
    typedef typename allele_type::weight_pointer                weight_pointer;

    typedef typename association_type::block_type               block_type;
    typedef typename association_type::raw_block_pointer        block_pointer;

    typedef clotho::utility::debruijn_bit_walker< block_type >  bit_walker_type;

    void operator()( allele_type & alls, association_type & seqs, weight_pointer res, size_t trait_count ) {
        size_t  M = seqs.row_count();

        size_t i = 0;
        while( i < M ) {

            block_pointer start = seqs.begin_row( i );
            block_pointer end = seqs.end_row(i);

            size_t j = 0;
            while( start != end ) {

                block_type b = *start;

                while( b ) {
                    size_t b_idx = j + bit_walker_type::unset_next_index( b );

                    weight_pointer t_start = alls.begin_trait_weight( b_idx );
                    weight_pointer t_end = alls.end_trait_weight( b_idx );

                    size_t a = i * trait_count;
                    while( t_start != t_end ) {
                        res[ a++ ] += *t_start++;
                    }
                }
                start += row_grouped< P >::GROUP_SIZE;

                j += association_type::bit_helper_type::BITS_PER_BLOCK;
            }

            ++i;
        }
    }

};

template < class AlleleSpace, class BlockType >
class weight_accumulator< AlleleSpace, association_matrix< BlockType, row_grouped< 1 > > > {
public:
    typedef AlleleSpace                                         allele_type;
    typedef association_matrix< BlockType, row_grouped< 1 > >     association_type;

    typedef typename allele_type::weight_type                   weight_type;
    typedef typename allele_type::weight_pointer                weight_pointer;

    typedef typename association_type::block_type               block_type;
    typedef typename association_type::raw_block_pointer        block_pointer;

    typedef clotho::utility::debruijn_bit_walker< block_type >  bit_walker_type;

    void operator()( allele_type & alls, association_type & seqs, weight_pointer res, size_t trait_count ) {
        size_t  M = seqs.row_count();

        size_t i = 0;
        while( i < M ) {

            block_pointer start = seqs.begin_row( i );
            block_pointer end = seqs.end_row(i);

            size_t j = 0;
            while( start != end ) {
                block_type b = *start++;

                while( b ) {
                    size_t b_idx = j + bit_walker_type::unset_next_index( b );

                    weight_pointer t_start = alls.begin_trait_weight( b_idx );
                    weight_pointer t_end = alls.end_trait_weight( b_idx );

                    size_t a = i * trait_count;
                    while( t_start != t_end ) {
                        res[ a++ ] += *t_start++;
                    }
                }

                j += association_type::bit_helper_type::BITS_PER_BLOCK;
            }

            ++i;
        }
    }

};
}   // namespace genetics
}   // namespace clotho

#endif  // CLOTHO_ROW_GROUPED_WEIGHT_ACCUMULATOR_HPP_

<|endoftext|>


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

  This source file is part of the tomviz project.

  Copyright Kitware, Inc.

  This source code is released under the New BSD License, (the "License").

  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 "ModuleVolume.h"

#include "DataSource.h"
#include "Utilities.h"

#include <vtkColorTransferFunction.h>
#include <vtkImageData.h>
#include <vtkImageShiftScale.h>
#include <vtkNew.h>
#include <vtkPiecewiseFunction.h>
#include <vtkSmartPointer.h>
#include <vtkGPUVolumeRayCastMapper.h>
#include <vtkTrivialProducer.h>
#include <vtkVector.h>
#include <vtkView.h>
#include <vtkVolume.h>
#include <vtkVolumeProperty.h>

#include <pqProxiesWidget.h>
#include <vtkPVRenderView.h>
#include <vtkSMPVRepresentationProxy.h>
#include <vtkSMParaViewPipelineControllerWithRendering.h>
#include <vtkSMPropertyHelper.h>
#include <vtkSMSessionProxyManager.h>
#include <vtkSMSourceProxy.h>
#include <vtkSMViewProxy.h>

#include <QCheckBox>
#include <QVBoxLayout>

namespace tomviz {

using pugi::xml_attribute;
using pugi::xml_node;

ModuleVolume::ModuleVolume(QObject* parentObject) : Superclass(parentObject)
{
}

ModuleVolume::~ModuleVolume()
{
  this->finalize();
}

QIcon ModuleVolume::icon() const
{
  return QIcon(":/pqWidgets/Icons/pqVolumeData16.png");
}

bool ModuleVolume::initialize(DataSource* data, vtkSMViewProxy* vtkView)
{
  if (!this->Superclass::initialize(data, vtkView)) {
    return false;
  }

  connect(data, SIGNAL(dataChanged()), SLOT(dataChanged()));

  vtkNew<vtkImageShiftScale> t;

  vtkTrivialProducer* trv =
    vtkTrivialProducer::SafeDownCast(data->producer()->GetClientSideObject());
  vtkImageData* im = vtkImageData::SafeDownCast(trv->GetOutputDataObject(0));

  t->SetInputData(im);

  m_volumeMapper->SetInputConnection(t->GetOutputPort());
  m_volume->SetMapper(m_volumeMapper.Get());
  m_volume->SetProperty(m_volumeProperty.Get());

  this->updateColorMap();

  m_view = vtkPVRenderView::SafeDownCast(vtkView->GetClientSideView());
  m_view->AddPropToRenderer(m_volume.Get());

  return true;
}

void ModuleVolume::updateColorMap()
{
  m_volumeProperty->SetScalarOpacity(
    vtkPiecewiseFunction::SafeDownCast(opacityMap()->GetClientSideObject()));
  m_volumeProperty->SetColor(
    vtkColorTransferFunction::SafeDownCast(colorMap()->GetClientSideObject()));

  // BUG: volume mappers don't update property when LUT is changed and has an
  // older Mtime. Fix for now by forcing the LUT to update.
  vtkObject::SafeDownCast(this->colorMap()->GetClientSideObject())->Modified();
}

bool ModuleVolume::finalize()
{
  if (m_view) {
    m_view->RemovePropFromRenderer(m_volume.Get());
  }

  return true;
}

bool ModuleVolume::setVisibility(bool val)
{
  m_volume->SetVisibility(val ? 1 : 0);
  return true;
}

bool ModuleVolume::visibility() const
{
  return m_volume->GetVisibility() != 0;
}

bool ModuleVolume::serialize(pugi::xml_node& ns) const
{
  xml_node rootNode = ns.append_child("properties");
  xml_node visibilityNode = rootNode.append_child("visibility");
  visibilityNode.append_attribute("enabled") = visibility();
  xml_node lightingNode = rootNode.append_child("lighting");
  lightingNode.append_attribute("enabled") = m_volumeProperty->GetShade() == 1;
  xml_node maxIntensityNode = rootNode.append_child("maxIntensity");
  bool maxIntensity =
    m_volumeMapper->GetBlendMode() == vtkVolumeMapper::MAXIMUM_INTENSITY_BLEND;
  maxIntensityNode.append_attribute("enabled") = maxIntensity;
  return Module::serialize(ns);
}

bool ModuleVolume::deserialize(const pugi::xml_node& ns)
{
  xml_node rootNode = ns.child("properties");
  if (!rootNode) {
    return false;
  }

  xml_node node = rootNode.child("visibility");
  if (node) {
    xml_attribute att = node.attribute("enabled");
    if (att) {
      setVisibility(att.as_bool());
    }
  }
  node = rootNode.child("lighting");
  if (node) {
    xml_attribute att = node.attribute("enabled");
    if (att) {
      setLighting(att.as_bool());
    }
  }
  node = rootNode.child("maxIntensity");
  if (node) {
    xml_attribute att = node.attribute("enabled");
    if (att) {
      setMaximumIntensity(att.as_bool());
    }
  }

  return Module::deserialize(ns);
}

void ModuleVolume::addToPanel(QWidget* panel)
{
  if (panel->layout()) {
    delete panel->layout();
  }

  QVBoxLayout* layout = new QVBoxLayout;
  QCheckBox* lighting = new QCheckBox("Enable lighting");
  layout->addWidget(lighting);
  panel->setLayout(layout);
  QCheckBox* maxIntensity = new QCheckBox("Maximum intensity");
  layout->addWidget(maxIntensity);
  QCheckBox* jittering = new QCheckBox("Jittering");
  layout->addWidget(jittering);
  layout->addStretch();

  lighting->setChecked(m_volumeProperty->GetShade() == 1);
  maxIntensity->setChecked(m_volumeMapper->GetBlendMode() ==
                           vtkVolumeMapper::MAXIMUM_INTENSITY_BLEND);
  jittering->setChecked(m_volumeMapper->GetUseJittering() == 1);

  connect(lighting, SIGNAL(clicked(bool)), SLOT(setLighting(bool)));
  connect(maxIntensity, SIGNAL(clicked(bool)), SLOT(setMaximumIntensity(bool)));
  connect(jittering, SIGNAL(clicked(bool)), SLOT(setJittering(bool)));
}

void ModuleVolume::dataSourceMoved(double newX, double newY, double newZ)
{
  vtkVector3d pos(newX, newY, newZ);
  m_volume->SetPosition(pos.GetData());
}

bool ModuleVolume::isProxyPartOfModule(vtkSMProxy*)
{
  return false;
}

void ModuleVolume::dataChanged()
{
  // The volume was not updating, ensure it does, this involves ensuring we are
  // using the right input as the threaded operators cause new object creation.
  auto data = qobject_cast<DataSource*>(sender());
  if (!data) {
    return;
  }
  auto trv =
    vtkTrivialProducer::SafeDownCast(data->producer()->GetClientSideObject());
  auto im = vtkImageData::SafeDownCast(trv->GetOutputDataObject(0));
  m_volumeMapper->GetInputAlgorithm()->SetInputDataObject(im);
}

std::string ModuleVolume::getStringForProxy(vtkSMProxy*)
{
  qWarning("Unknown proxy passed to module volume in save animation");
  return "";
}

vtkSMProxy* ModuleVolume::getProxyForString(const std::string&)
{
  return nullptr;
}

void ModuleVolume::setLighting(bool val)
{
  m_volumeProperty->SetShade(val ? 1 : 0);
  m_volumeProperty->SetAmbient(0.0);
  m_volumeProperty->SetDiffuse(1.0);
  m_volumeProperty->SetSpecularPower(100.0);
  emit renderNeeded();
}

void ModuleVolume::setMaximumIntensity(bool val)
{
  if (val) {
    m_volumeMapper->SetBlendMode(vtkVolumeMapper::MAXIMUM_INTENSITY_BLEND);
  } else {
    m_volumeMapper->SetBlendMode(vtkVolumeMapper::COMPOSITE_BLEND);
  }
  emit renderNeeded();
}

void ModuleVolume::setJittering(bool val)
{
  m_volumeMapper->SetUseJittering(val ? 1 : 0);
  emit renderNeeded();
}

} // end of namespace tomviz
<commit_msg>Save/restore whether jittering was enabled<commit_after>/******************************************************************************

  This source file is part of the tomviz project.

  Copyright Kitware, Inc.

  This source code is released under the New BSD License, (the "License").

  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 "ModuleVolume.h"

#include "DataSource.h"
#include "Utilities.h"

#include <vtkColorTransferFunction.h>
#include <vtkGPUVolumeRayCastMapper.h>
#include <vtkImageData.h>
#include <vtkImageShiftScale.h>
#include <vtkNew.h>
#include <vtkPiecewiseFunction.h>
#include <vtkSmartPointer.h>
#include <vtkTrivialProducer.h>
#include <vtkVector.h>
#include <vtkView.h>
#include <vtkVolume.h>
#include <vtkVolumeProperty.h>

#include <pqProxiesWidget.h>
#include <vtkPVRenderView.h>
#include <vtkSMPVRepresentationProxy.h>
#include <vtkSMParaViewPipelineControllerWithRendering.h>
#include <vtkSMPropertyHelper.h>
#include <vtkSMSessionProxyManager.h>
#include <vtkSMSourceProxy.h>
#include <vtkSMViewProxy.h>

#include <QCheckBox>
#include <QVBoxLayout>

namespace tomviz {

using pugi::xml_attribute;
using pugi::xml_node;

ModuleVolume::ModuleVolume(QObject* parentObject) : Superclass(parentObject)
{
}

ModuleVolume::~ModuleVolume()
{
  this->finalize();
}

QIcon ModuleVolume::icon() const
{
  return QIcon(":/pqWidgets/Icons/pqVolumeData16.png");
}

bool ModuleVolume::initialize(DataSource* data, vtkSMViewProxy* vtkView)
{
  if (!this->Superclass::initialize(data, vtkView)) {
    return false;
  }

  connect(data, SIGNAL(dataChanged()), SLOT(dataChanged()));

  vtkNew<vtkImageShiftScale> t;

  vtkTrivialProducer* trv =
    vtkTrivialProducer::SafeDownCast(data->producer()->GetClientSideObject());
  vtkImageData* im = vtkImageData::SafeDownCast(trv->GetOutputDataObject(0));

  t->SetInputData(im);

  m_volumeMapper->SetInputConnection(t->GetOutputPort());
  m_volume->SetMapper(m_volumeMapper.Get());
  m_volume->SetProperty(m_volumeProperty.Get());

  this->updateColorMap();

  m_view = vtkPVRenderView::SafeDownCast(vtkView->GetClientSideView());
  m_view->AddPropToRenderer(m_volume.Get());

  return true;
}

void ModuleVolume::updateColorMap()
{
  m_volumeProperty->SetScalarOpacity(
    vtkPiecewiseFunction::SafeDownCast(opacityMap()->GetClientSideObject()));
  m_volumeProperty->SetColor(
    vtkColorTransferFunction::SafeDownCast(colorMap()->GetClientSideObject()));

  // BUG: volume mappers don't update property when LUT is changed and has an
  // older Mtime. Fix for now by forcing the LUT to update.
  vtkObject::SafeDownCast(this->colorMap()->GetClientSideObject())->Modified();
}

bool ModuleVolume::finalize()
{
  if (m_view) {
    m_view->RemovePropFromRenderer(m_volume.Get());
  }

  return true;
}

bool ModuleVolume::setVisibility(bool val)
{
  m_volume->SetVisibility(val ? 1 : 0);
  return true;
}

bool ModuleVolume::visibility() const
{
  return m_volume->GetVisibility() != 0;
}

bool ModuleVolume::serialize(pugi::xml_node& ns) const
{
  xml_node rootNode = ns.append_child("properties");
  xml_node visibilityNode = rootNode.append_child("visibility");
  visibilityNode.append_attribute("enabled") = visibility();
  xml_node lightingNode = rootNode.append_child("lighting");
  lightingNode.append_attribute("enabled") = m_volumeProperty->GetShade() == 1;
  xml_node maxIntensityNode = rootNode.append_child("maxIntensity");
  bool maxIntensity =
    m_volumeMapper->GetBlendMode() == vtkVolumeMapper::MAXIMUM_INTENSITY_BLEND;
  maxIntensityNode.append_attribute("enabled") = maxIntensity;
  xml_node jitteringNode = rootNode.append_child("jittering");
  jitteringNode.append_attribute("enabled") =
    m_volumeMapper->GetUseJittering() == 1;
  return Module::serialize(ns);
}

bool ModuleVolume::deserialize(const pugi::xml_node& ns)
{
  xml_node rootNode = ns.child("properties");
  if (!rootNode) {
    return false;
  }

  xml_node node = rootNode.child("visibility");
  if (node) {
    xml_attribute att = node.attribute("enabled");
    if (att) {
      setVisibility(att.as_bool());
    }
  }
  node = rootNode.child("lighting");
  if (node) {
    xml_attribute att = node.attribute("enabled");
    if (att) {
      setLighting(att.as_bool());
    }
  }
  node = rootNode.child("maxIntensity");
  if (node) {
    xml_attribute att = node.attribute("enabled");
    if (att) {
      setMaximumIntensity(att.as_bool());
    }
  }
  node = rootNode.child("jittering");
  if (node) {
    xml_attribute att = node.attribute("enabled");
    if (att) {
      setJittering(att.as_bool());
    }
  }

  return Module::deserialize(ns);
}

void ModuleVolume::addToPanel(QWidget* panel)
{
  if (panel->layout()) {
    delete panel->layout();
  }

  QVBoxLayout* layout = new QVBoxLayout;
  QCheckBox* lighting = new QCheckBox("Enable lighting");
  layout->addWidget(lighting);
  panel->setLayout(layout);
  QCheckBox* maxIntensity = new QCheckBox("Maximum intensity");
  layout->addWidget(maxIntensity);
  QCheckBox* jittering = new QCheckBox("Jittering");
  layout->addWidget(jittering);
  layout->addStretch();

  lighting->setChecked(m_volumeProperty->GetShade() == 1);
  maxIntensity->setChecked(m_volumeMapper->GetBlendMode() ==
                           vtkVolumeMapper::MAXIMUM_INTENSITY_BLEND);
  jittering->setChecked(m_volumeMapper->GetUseJittering() == 1);

  connect(lighting, SIGNAL(clicked(bool)), SLOT(setLighting(bool)));
  connect(maxIntensity, SIGNAL(clicked(bool)), SLOT(setMaximumIntensity(bool)));
  connect(jittering, SIGNAL(clicked(bool)), SLOT(setJittering(bool)));
}

void ModuleVolume::dataSourceMoved(double newX, double newY, double newZ)
{
  vtkVector3d pos(newX, newY, newZ);
  m_volume->SetPosition(pos.GetData());
}

bool ModuleVolume::isProxyPartOfModule(vtkSMProxy*)
{
  return false;
}

void ModuleVolume::dataChanged()
{
  // The volume was not updating, ensure it does, this involves ensuring we are
  // using the right input as the threaded operators cause new object creation.
  auto data = qobject_cast<DataSource*>(sender());
  if (!data) {
    return;
  }
  auto trv =
    vtkTrivialProducer::SafeDownCast(data->producer()->GetClientSideObject());
  auto im = vtkImageData::SafeDownCast(trv->GetOutputDataObject(0));
  m_volumeMapper->GetInputAlgorithm()->SetInputDataObject(im);
}

std::string ModuleVolume::getStringForProxy(vtkSMProxy*)
{
  qWarning("Unknown proxy passed to module volume in save animation");
  return "";
}

vtkSMProxy* ModuleVolume::getProxyForString(const std::string&)
{
  return nullptr;
}

void ModuleVolume::setLighting(bool val)
{
  m_volumeProperty->SetShade(val ? 1 : 0);
  m_volumeProperty->SetAmbient(0.0);
  m_volumeProperty->SetDiffuse(1.0);
  m_volumeProperty->SetSpecularPower(100.0);
  emit renderNeeded();
}

void ModuleVolume::setMaximumIntensity(bool val)
{
  if (val) {
    m_volumeMapper->SetBlendMode(vtkVolumeMapper::MAXIMUM_INTENSITY_BLEND);
  } else {
    m_volumeMapper->SetBlendMode(vtkVolumeMapper::COMPOSITE_BLEND);
  }
  emit renderNeeded();
}

void ModuleVolume::setJittering(bool val)
{
  m_volumeMapper->SetUseJittering(val ? 1 : 0);
  emit renderNeeded();
}

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


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: linksrc.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 16:18:58 $
 *
 *  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_sfx2.hxx"

#include "linksrc.hxx"
#include "lnkbase.hxx"
//#include <sot/exchange.hxx>
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Sequence.hxx>

#include <tools/debug.hxx>
#include <vcl/timer.hxx>
#include <svtools/svarray.hxx>

using namespace ::com::sun::star::uno;

namespace sfx2
{

TYPEINIT0( SvLinkSource )

/************** class SvLinkSourceTimer *********************************/
class SvLinkSourceTimer : public Timer
{
    SvLinkSource *  pOwner;
    virtual void    Timeout();
public:
            SvLinkSourceTimer( SvLinkSource * pOwn );
};

SvLinkSourceTimer::SvLinkSourceTimer( SvLinkSource * pOwn )
    : pOwner( pOwn )
{
}

void SvLinkSourceTimer::Timeout()
{
    // sicher gegen zerstoeren im Handler
    SvLinkSourceRef aAdv( pOwner );
    pOwner->SendDataChanged();
}

static void StartTimer( SvLinkSourceTimer ** ppTimer, SvLinkSource * pOwner,
                        ULONG nTimeout )
{
    if( !*ppTimer )
    {
        *ppTimer = new SvLinkSourceTimer( pOwner );
        (*ppTimer)->SetTimeout( nTimeout );
        (*ppTimer)->Start();
    }
}

struct SvLinkSource_Entry_Impl
{
    SvBaseLinkRef       xSink;
    String              aDataMimeType;
    USHORT              nAdviseModes;
    BOOL                bIsDataSink;

    SvLinkSource_Entry_Impl( SvBaseLink* pLink, const String& rMimeType,
                                USHORT nAdvMode )
        : xSink( pLink ), aDataMimeType( rMimeType ),
            nAdviseModes( nAdvMode ), bIsDataSink( TRUE )
    {}

    SvLinkSource_Entry_Impl( SvBaseLink* pLink )
        : xSink( pLink ), nAdviseModes( 0 ), bIsDataSink( FALSE )
    {}

    ~SvLinkSource_Entry_Impl();
};

SvLinkSource_Entry_Impl::~SvLinkSource_Entry_Impl()
{
}

typedef SvLinkSource_Entry_Impl* SvLinkSource_Entry_ImplPtr;
SV_DECL_PTRARR_DEL( SvLinkSource_Array_Impl, SvLinkSource_Entry_ImplPtr, 4, 4 )
SV_IMPL_PTRARR( SvLinkSource_Array_Impl, SvLinkSource_Entry_ImplPtr );

class SvLinkSource_EntryIter_Impl
{
    SvLinkSource_Array_Impl aArr;
    const SvLinkSource_Array_Impl& rOrigArr;
    USHORT nPos;
public:
    SvLinkSource_EntryIter_Impl( const SvLinkSource_Array_Impl& rArr );
    ~SvLinkSource_EntryIter_Impl();
    SvLinkSource_Entry_Impl* Curr()
                            { return nPos < aArr.Count() ? aArr[ nPos ] : 0; }
    SvLinkSource_Entry_Impl* Next();
};

SvLinkSource_EntryIter_Impl::SvLinkSource_EntryIter_Impl(
        const SvLinkSource_Array_Impl& rArr )
    : rOrigArr( rArr ), nPos( 0 )
{
    aArr.Insert( &rArr, 0 );
}
SvLinkSource_EntryIter_Impl::~SvLinkSource_EntryIter_Impl()
{
    aArr.Remove( 0, aArr.Count() );
}

SvLinkSource_Entry_Impl* SvLinkSource_EntryIter_Impl::Next()
{
    SvLinkSource_Entry_ImplPtr pRet = 0;
    if( nPos + 1 < aArr.Count() )
    {
        ++nPos;
        if( rOrigArr.Count() == aArr.Count() &&
            rOrigArr[ nPos ] == aArr[ nPos ] )
            pRet = aArr[ nPos ];
        else
        {
            // then we must search the current (or the next) in the orig
            do {
                pRet = aArr[ nPos ];
                if( USHRT_MAX != rOrigArr.GetPos( pRet ))
                    break;
                pRet = 0;
                ++nPos;
            } while( nPos < aArr.Count() );

            if( nPos >= aArr.Count() )
                pRet = 0;
        }
    }
    return pRet;
}

struct SvLinkSource_Impl
{
    SvLinkSource_Array_Impl aArr;
    String              aDataMimeType;
    SvLinkSourceTimer * pTimer;
    ULONG               nTimeout;
    com::sun::star::uno::Reference<com::sun::star::io::XInputStream>
    m_xInputStreamToLoadFrom;
    sal_Bool m_bIsReadOnly;

    SvLinkSource_Impl() : pTimer( 0 ), nTimeout( 3000 ) {}
    ~SvLinkSource_Impl();

    void Closed();
};

SvLinkSource_Impl::~SvLinkSource_Impl()
{
    delete pTimer;
}

SvLinkSource::SvLinkSource()
     : pImpl( new SvLinkSource_Impl )
{
}

SvLinkSource::~SvLinkSource()
{
    delete pImpl;
}

SvLinkSource::StreamToLoadFrom SvLinkSource::getStreamToLoadFrom()
{
    return StreamToLoadFrom(
        pImpl->m_xInputStreamToLoadFrom,
        pImpl->m_bIsReadOnly);
}

void SvLinkSource::setStreamToLoadFrom(const com::sun::star::uno::Reference<com::sun::star::io::XInputStream>& xInputStream,sal_Bool bIsReadOnly )
{
    pImpl->m_xInputStreamToLoadFrom = xInputStream;
    pImpl->m_bIsReadOnly = bIsReadOnly;
}

void  SvLinkSource::Closed()
{
    SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
    for( SvLinkSource_Entry_Impl* p = aIter.Curr(); p; p = aIter.Next() )
        if( !p->bIsDataSink )
            p->xSink->Closed();
}

ULONG SvLinkSource::GetUpdateTimeout() const
{
    return pImpl->nTimeout;
}

void SvLinkSource::SetUpdateTimeout( ULONG nTimeout )
{
    pImpl->nTimeout = nTimeout;
    if( pImpl->pTimer )
        pImpl->pTimer->SetTimeout( nTimeout );
}

void SvLinkSource::SendDataChanged()
{
    SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
    for( SvLinkSource_Entry_ImplPtr p = aIter.Curr(); p; p = aIter.Next() )
    {
        if( p->bIsDataSink )
        {
            String sDataMimeType( pImpl->aDataMimeType );
            if( !sDataMimeType.Len() )
                sDataMimeType = p->aDataMimeType;

            Any aVal;
            if( ( p->nAdviseModes & ADVISEMODE_NODATA ) ||
                GetData( aVal, sDataMimeType, TRUE ) )
            {
                p->xSink->DataChanged( sDataMimeType, aVal );

                if( p->nAdviseModes & ADVISEMODE_ONLYONCE )
                {
                    USHORT nFndPos = pImpl->aArr.GetPos( p );
                    if( USHRT_MAX != nFndPos )
                        pImpl->aArr.DeleteAndDestroy( nFndPos );
                }

            }
        }
    }
    if( pImpl->pTimer )
    {
        delete pImpl->pTimer;
        pImpl->pTimer = NULL;
    }
    pImpl->aDataMimeType.Erase();
}

void SvLinkSource::NotifyDataChanged()
{
    if( pImpl->nTimeout )
        StartTimer( &pImpl->pTimer, this, pImpl->nTimeout ); // Timeout neu
    else
    {
        SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
        for( SvLinkSource_Entry_ImplPtr p = aIter.Curr(); p; p = aIter.Next() )
            if( p->bIsDataSink )
            {
                Any aVal;
                if( ( p->nAdviseModes & ADVISEMODE_NODATA ) ||
                    GetData( aVal, p->aDataMimeType, TRUE ) )
                {
                    p->xSink->DataChanged( p->aDataMimeType, aVal );

                    if( p->nAdviseModes & ADVISEMODE_ONLYONCE )
                    {
                        USHORT nFndPos = pImpl->aArr.GetPos( p );
                        if( USHRT_MAX != nFndPos )
                            pImpl->aArr.DeleteAndDestroy( nFndPos );
                    }
                }
            }

            if( pImpl->pTimer )
            {
                delete pImpl->pTimer;
                pImpl->pTimer = NULL;
            }
    }
}

// notify the sink, the mime type is not
// a selection criterion
void SvLinkSource::DataChanged( const String & rMimeType,
                                const ::com::sun::star::uno::Any & rVal )
{
    if( pImpl->nTimeout && !rVal.hasValue() )
    {   // nur wenn keine Daten mitgegeben wurden
        // fire all data to the sink, independent of the requested format
        pImpl->aDataMimeType = rMimeType;
        StartTimer( &pImpl->pTimer, this, pImpl->nTimeout ); // Timeout neu
    }
    else
    {
        SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
        for( SvLinkSource_Entry_ImplPtr p = aIter.Curr(); p; p = aIter.Next() )
        {
            if( p->bIsDataSink )
            {
                p->xSink->DataChanged( rMimeType, rVal );

                if( p->nAdviseModes & ADVISEMODE_ONLYONCE )
                {
                    USHORT nFndPos = pImpl->aArr.GetPos( p );
                    if( USHRT_MAX != nFndPos )
                        pImpl->aArr.DeleteAndDestroy( nFndPos );
                }
            }
        }

        if( pImpl->pTimer )
        {
            delete pImpl->pTimer;
            pImpl->pTimer = NULL;
        }
    }
}

// only one link is correct
void SvLinkSource::AddDataAdvise( SvBaseLink * pLink, const String& rMimeType,
                                    USHORT nAdviseModes )
{
    SvLinkSource_Entry_ImplPtr pNew = new SvLinkSource_Entry_Impl(
                    pLink, rMimeType, nAdviseModes );
    pImpl->aArr.Insert( pNew, pImpl->aArr.Count() );
}

void SvLinkSource::RemoveAllDataAdvise( SvBaseLink * pLink )
{
    SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
    for( SvLinkSource_Entry_ImplPtr p = aIter.Curr(); p; p = aIter.Next() )
        if( p->bIsDataSink && &p->xSink == pLink )
        {
            USHORT nFndPos = pImpl->aArr.GetPos( p );
            if( USHRT_MAX != nFndPos )
                pImpl->aArr.DeleteAndDestroy( nFndPos );
        }
}

// only one link is correct
void SvLinkSource::AddConnectAdvise( SvBaseLink * pLink )
{
    SvLinkSource_Entry_ImplPtr pNew = new SvLinkSource_Entry_Impl( pLink );
    pImpl->aArr.Insert( pNew, pImpl->aArr.Count() );
}

void SvLinkSource::RemoveConnectAdvise( SvBaseLink * pLink )
{
    SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
    for( SvLinkSource_Entry_ImplPtr p = aIter.Curr(); p; p = aIter.Next() )
        if( !p->bIsDataSink && &p->xSink == pLink )
        {
            USHORT nFndPos = pImpl->aArr.GetPos( p );
            if( USHRT_MAX != nFndPos )
                pImpl->aArr.DeleteAndDestroy( nFndPos );
        }
}

BOOL SvLinkSource::HasDataLinks( const SvBaseLink* pLink ) const
{
    BOOL bRet = FALSE;
    const SvLinkSource_Entry_Impl* p;
    for( USHORT n = 0, nEnd = pImpl->aArr.Count(); n < nEnd; ++n )
        if( ( p = pImpl->aArr[ n ] )->bIsDataSink &&
            ( !pLink || &p->xSink == pLink ) )
        {
            bRet = TRUE;
            break;
        }
    return bRet;
}

// TRUE => waitinmg for data
BOOL SvLinkSource::IsPending() const
{
    return FALSE;
}

// TRUE => data complete loaded
BOOL SvLinkSource::IsDataComplete() const
{
    return TRUE;
}

BOOL SvLinkSource::Connect( SvBaseLink* )
{
    return TRUE;
}

BOOL SvLinkSource::GetData( ::com::sun::star::uno::Any & ,
                        const String & , BOOL )
{
    return FALSE;
}

String SvLinkSource::Edit( Window *, SvBaseLink * )
{
    return String();
}

}

<commit_msg>INTEGRATION: CWS asyncdialogs (1.5.94); FILE MERGED 2006/09/20 20:25:13 pb 1.5.94.4: RESYNC: (1.6-1.7); FILE MERGED 2006/07/14 10:42:17 pb 1.5.94.3: fix: #i57125# warning free code 2006/07/12 20:46:49 pb 1.5.94.2: RESYNC: (1.5-1.6); FILE MERGED 2006/03/22 07:31:30 pb 1.5.94.1: fix: #i57125# now Edit() asynchron<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: linksrc.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: vg $ $Date: 2006-11-22 10:55:33 $
 *
 *  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_sfx2.hxx"

#include "linksrc.hxx"
#include "lnkbase.hxx"
//#include <sot/exchange.hxx>
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Sequence.hxx>

#include <tools/debug.hxx>
#include <vcl/timer.hxx>
#include <svtools/svarray.hxx>

using namespace ::com::sun::star::uno;

namespace sfx2
{

TYPEINIT0( SvLinkSource )

/************** class SvLinkSourceTimer *********************************/
class SvLinkSourceTimer : public Timer
{
    SvLinkSource *  pOwner;
    virtual void    Timeout();
public:
            SvLinkSourceTimer( SvLinkSource * pOwn );
};

SvLinkSourceTimer::SvLinkSourceTimer( SvLinkSource * pOwn )
    : pOwner( pOwn )
{
}

void SvLinkSourceTimer::Timeout()
{
    // sicher gegen zerstoeren im Handler
    SvLinkSourceRef aAdv( pOwner );
    pOwner->SendDataChanged();
}

static void StartTimer( SvLinkSourceTimer ** ppTimer, SvLinkSource * pOwner,
                        ULONG nTimeout )
{
    if( !*ppTimer )
    {
        *ppTimer = new SvLinkSourceTimer( pOwner );
        (*ppTimer)->SetTimeout( nTimeout );
        (*ppTimer)->Start();
    }
}

struct SvLinkSource_Entry_Impl
{
    SvBaseLinkRef       xSink;
    String              aDataMimeType;
    USHORT              nAdviseModes;
    BOOL                bIsDataSink;

    SvLinkSource_Entry_Impl( SvBaseLink* pLink, const String& rMimeType,
                                USHORT nAdvMode )
        : xSink( pLink ), aDataMimeType( rMimeType ),
            nAdviseModes( nAdvMode ), bIsDataSink( TRUE )
    {}

    SvLinkSource_Entry_Impl( SvBaseLink* pLink )
        : xSink( pLink ), nAdviseModes( 0 ), bIsDataSink( FALSE )
    {}

    ~SvLinkSource_Entry_Impl();
};

SvLinkSource_Entry_Impl::~SvLinkSource_Entry_Impl()
{
}

typedef SvLinkSource_Entry_Impl* SvLinkSource_Entry_ImplPtr;
SV_DECL_PTRARR_DEL( SvLinkSource_Array_Impl, SvLinkSource_Entry_ImplPtr, 4, 4 )
SV_IMPL_PTRARR( SvLinkSource_Array_Impl, SvLinkSource_Entry_ImplPtr );

class SvLinkSource_EntryIter_Impl
{
    SvLinkSource_Array_Impl aArr;
    const SvLinkSource_Array_Impl& rOrigArr;
    USHORT nPos;
public:
    SvLinkSource_EntryIter_Impl( const SvLinkSource_Array_Impl& rArr );
    ~SvLinkSource_EntryIter_Impl();
    SvLinkSource_Entry_Impl* Curr()
                            { return nPos < aArr.Count() ? aArr[ nPos ] : 0; }
    SvLinkSource_Entry_Impl* Next();
};

SvLinkSource_EntryIter_Impl::SvLinkSource_EntryIter_Impl(
        const SvLinkSource_Array_Impl& rArr )
    : rOrigArr( rArr ), nPos( 0 )
{
    aArr.Insert( &rArr, 0 );
}
SvLinkSource_EntryIter_Impl::~SvLinkSource_EntryIter_Impl()
{
    aArr.Remove( 0, aArr.Count() );
}

SvLinkSource_Entry_Impl* SvLinkSource_EntryIter_Impl::Next()
{
    SvLinkSource_Entry_ImplPtr pRet = 0;
    if( nPos + 1 < aArr.Count() )
    {
        ++nPos;
        if( rOrigArr.Count() == aArr.Count() &&
            rOrigArr[ nPos ] == aArr[ nPos ] )
            pRet = aArr[ nPos ];
        else
        {
            // then we must search the current (or the next) in the orig
            do {
                pRet = aArr[ nPos ];
                if( USHRT_MAX != rOrigArr.GetPos( pRet ))
                    break;
                pRet = 0;
                ++nPos;
            } while( nPos < aArr.Count() );

            if( nPos >= aArr.Count() )
                pRet = 0;
        }
    }
    return pRet;
}

struct SvLinkSource_Impl
{
    SvLinkSource_Array_Impl aArr;
    String              aDataMimeType;
    SvLinkSourceTimer * pTimer;
    ULONG               nTimeout;
    com::sun::star::uno::Reference<com::sun::star::io::XInputStream>
    m_xInputStreamToLoadFrom;
    sal_Bool m_bIsReadOnly;

    SvLinkSource_Impl() : pTimer( 0 ), nTimeout( 3000 ) {}
    ~SvLinkSource_Impl();

    void Closed();
};

SvLinkSource_Impl::~SvLinkSource_Impl()
{
    delete pTimer;
}

SvLinkSource::SvLinkSource()
     : pImpl( new SvLinkSource_Impl )
{
}

SvLinkSource::~SvLinkSource()
{
    delete pImpl;
}

SvLinkSource::StreamToLoadFrom SvLinkSource::getStreamToLoadFrom()
{
    return StreamToLoadFrom(
        pImpl->m_xInputStreamToLoadFrom,
        pImpl->m_bIsReadOnly);
}

void SvLinkSource::setStreamToLoadFrom(const com::sun::star::uno::Reference<com::sun::star::io::XInputStream>& xInputStream,sal_Bool bIsReadOnly )
{
    pImpl->m_xInputStreamToLoadFrom = xInputStream;
    pImpl->m_bIsReadOnly = bIsReadOnly;
}

void  SvLinkSource::Closed()
{
    SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
    for( SvLinkSource_Entry_Impl* p = aIter.Curr(); p; p = aIter.Next() )
        if( !p->bIsDataSink )
            p->xSink->Closed();
}

ULONG SvLinkSource::GetUpdateTimeout() const
{
    return pImpl->nTimeout;
}

void SvLinkSource::SetUpdateTimeout( ULONG nTimeout )
{
    pImpl->nTimeout = nTimeout;
    if( pImpl->pTimer )
        pImpl->pTimer->SetTimeout( nTimeout );
}

void SvLinkSource::SendDataChanged()
{
    SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
    for( SvLinkSource_Entry_ImplPtr p = aIter.Curr(); p; p = aIter.Next() )
    {
        if( p->bIsDataSink )
        {
            String sDataMimeType( pImpl->aDataMimeType );
            if( !sDataMimeType.Len() )
                sDataMimeType = p->aDataMimeType;

            Any aVal;
            if( ( p->nAdviseModes & ADVISEMODE_NODATA ) ||
                GetData( aVal, sDataMimeType, TRUE ) )
            {
                p->xSink->DataChanged( sDataMimeType, aVal );

                if( p->nAdviseModes & ADVISEMODE_ONLYONCE )
                {
                    USHORT nFndPos = pImpl->aArr.GetPos( p );
                    if( USHRT_MAX != nFndPos )
                        pImpl->aArr.DeleteAndDestroy( nFndPos );
                }

            }
        }
    }
    if( pImpl->pTimer )
    {
        delete pImpl->pTimer;
        pImpl->pTimer = NULL;
    }
    pImpl->aDataMimeType.Erase();
}

void SvLinkSource::NotifyDataChanged()
{
    if( pImpl->nTimeout )
        StartTimer( &pImpl->pTimer, this, pImpl->nTimeout ); // Timeout neu
    else
    {
        SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
        for( SvLinkSource_Entry_ImplPtr p = aIter.Curr(); p; p = aIter.Next() )
            if( p->bIsDataSink )
            {
                Any aVal;
                if( ( p->nAdviseModes & ADVISEMODE_NODATA ) ||
                    GetData( aVal, p->aDataMimeType, TRUE ) )
                {
                    p->xSink->DataChanged( p->aDataMimeType, aVal );

                    if( p->nAdviseModes & ADVISEMODE_ONLYONCE )
                    {
                        USHORT nFndPos = pImpl->aArr.GetPos( p );
                        if( USHRT_MAX != nFndPos )
                            pImpl->aArr.DeleteAndDestroy( nFndPos );
                    }
                }
            }

            if( pImpl->pTimer )
            {
                delete pImpl->pTimer;
                pImpl->pTimer = NULL;
            }
    }
}

// notify the sink, the mime type is not
// a selection criterion
void SvLinkSource::DataChanged( const String & rMimeType,
                                const ::com::sun::star::uno::Any & rVal )
{
    if( pImpl->nTimeout && !rVal.hasValue() )
    {   // nur wenn keine Daten mitgegeben wurden
        // fire all data to the sink, independent of the requested format
        pImpl->aDataMimeType = rMimeType;
        StartTimer( &pImpl->pTimer, this, pImpl->nTimeout ); // Timeout neu
    }
    else
    {
        SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
        for( SvLinkSource_Entry_ImplPtr p = aIter.Curr(); p; p = aIter.Next() )
        {
            if( p->bIsDataSink )
            {
                p->xSink->DataChanged( rMimeType, rVal );

                if( p->nAdviseModes & ADVISEMODE_ONLYONCE )
                {
                    USHORT nFndPos = pImpl->aArr.GetPos( p );
                    if( USHRT_MAX != nFndPos )
                        pImpl->aArr.DeleteAndDestroy( nFndPos );
                }
            }
        }

        if( pImpl->pTimer )
        {
            delete pImpl->pTimer;
            pImpl->pTimer = NULL;
        }
    }
}

// only one link is correct
void SvLinkSource::AddDataAdvise( SvBaseLink * pLink, const String& rMimeType,
                                    USHORT nAdviseModes )
{
    SvLinkSource_Entry_ImplPtr pNew = new SvLinkSource_Entry_Impl(
                    pLink, rMimeType, nAdviseModes );
    pImpl->aArr.Insert( pNew, pImpl->aArr.Count() );
}

void SvLinkSource::RemoveAllDataAdvise( SvBaseLink * pLink )
{
    SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
    for( SvLinkSource_Entry_ImplPtr p = aIter.Curr(); p; p = aIter.Next() )
        if( p->bIsDataSink && &p->xSink == pLink )
        {
            USHORT nFndPos = pImpl->aArr.GetPos( p );
            if( USHRT_MAX != nFndPos )
                pImpl->aArr.DeleteAndDestroy( nFndPos );
        }
}

// only one link is correct
void SvLinkSource::AddConnectAdvise( SvBaseLink * pLink )
{
    SvLinkSource_Entry_ImplPtr pNew = new SvLinkSource_Entry_Impl( pLink );
    pImpl->aArr.Insert( pNew, pImpl->aArr.Count() );
}

void SvLinkSource::RemoveConnectAdvise( SvBaseLink * pLink )
{
    SvLinkSource_EntryIter_Impl aIter( pImpl->aArr );
    for( SvLinkSource_Entry_ImplPtr p = aIter.Curr(); p; p = aIter.Next() )
        if( !p->bIsDataSink && &p->xSink == pLink )
        {
            USHORT nFndPos = pImpl->aArr.GetPos( p );
            if( USHRT_MAX != nFndPos )
                pImpl->aArr.DeleteAndDestroy( nFndPos );
        }
}

BOOL SvLinkSource::HasDataLinks( const SvBaseLink* pLink ) const
{
    BOOL bRet = FALSE;
    const SvLinkSource_Entry_Impl* p;
    for( USHORT n = 0, nEnd = pImpl->aArr.Count(); n < nEnd; ++n )
        if( ( p = pImpl->aArr[ n ] )->bIsDataSink &&
            ( !pLink || &p->xSink == pLink ) )
        {
            bRet = TRUE;
            break;
        }
    return bRet;
}

// TRUE => waitinmg for data
BOOL SvLinkSource::IsPending() const
{
    return FALSE;
}

// TRUE => data complete loaded
BOOL SvLinkSource::IsDataComplete() const
{
    return TRUE;
}

BOOL SvLinkSource::Connect( SvBaseLink* )
{
    return TRUE;
}

BOOL SvLinkSource::GetData( ::com::sun::star::uno::Any &, const String &, BOOL )
{
    return FALSE;
}

void SvLinkSource::Edit( Window *, SvBaseLink *, const Link& )
{
}

}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: sfxhelp.cxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: pb $ $Date: 2000-12-08 10:18:04 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#include "sfxhelp.hxx"

#pragma hdrstop

#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_
#include <com/sun/star/uno/Reference.h>
#endif
#ifndef _COM_SUN_STAR_FRAME_XFRAME_HPP_
#include <com/sun/star/frame/XFrame.hpp>
#endif
#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
#include <comphelper/processfactory.hxx>
#endif
#ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
#include <com/sun/star/awt/XWindow.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_POSSIZE_HPP_
#include <com/sun/star/awt/PosSize.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_XTASK_HPP_
#include <com/sun/star/frame/XTask.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_XTASKSSUPPLIER_HPP_
#include <com/sun/star/frame/XTasksSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_XURLTRANSFORMER_HPP_
#include <com/sun/star/util/XURLTransformer.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_XDISPATCH_HPP_
#include <com/sun/star/frame/XDispatch.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_XDISPATCHPROVIDER_HPP_
#include <com/sun/star/frame/XDispatchProvider.hpp>
#endif
#include <com/sun/star/frame/FrameSearchFlag.hpp>
#include <toolkit/helper/vclunohelper.hxx>

#include "sfxsids.hrc"
#include "app.hxx"
#include "viewfrm.hxx"
#include "msgpool.hxx"
#include "newhelp.hxx"
#include "objsh.hxx"
#include "docfac.hxx"
#include "sfxresid.hxx"
#include "app.hrc"

using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::util;

SfxHelp_Impl::SfxHelp_Impl()
{
}

SfxHelp_Impl::~SfxHelp_Impl()
{
}

String SfxHelp_Impl::GetHelpModuleName( ULONG nHelpId )
{
    String aModuleName;
    SfxViewFrame *pViewFrame = SfxViewFrame::Current();
    if ( pViewFrame )
    {
        // Wenn es ein Slot ist, kann es sein, da\s internes InPlace vorliegt
        // und eine Container-SlotId gefragt ist
        if (nHelpId >= (ULONG) SID_SFX_START && nHelpId <= (ULONG) SHRT_MAX)
        {
            if ( pViewFrame->GetParentViewFrame_Impl() )
            {
                // Ist es ein ContainerSlot ?
                const SfxSlot* pSlot = SFX_APP()->GetSlotPool(pViewFrame).GetSlot( (USHORT) nHelpId );
                if ( !pSlot || pSlot->IsMode( SFX_SLOT_CONTAINER ) )
                    pViewFrame = pViewFrame->GetParentViewFrame_Impl();
            }
        }

        if( pViewFrame->GetObjectShell() )
            aModuleName = String::CreateFromAscii( pViewFrame->GetObjectShell()->GetFactory().GetShortName() );
    }

    return aModuleName;
}

BOOL SfxHelp_Impl::Start( ULONG nHelpId )
{
    Reference < XTasksSupplier > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
                DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );

    Reference < XTask > xActiveTask = xDesktop->getActiveTask();
    if ( !xActiveTask.is() )
        return FALSE;

    // build up the help URL
    String aHelpModuleName = GetHelpModuleName( nHelpId );
    String aHelpURL(String::CreateFromAscii("vnd.sun.star.help://") );
    aHelpURL += aHelpModuleName;
    if ( !nHelpId )
        aHelpURL += String( DEFINE_CONST_UNICODE("/start") );
    else
    {
        aHelpURL += '/';
        aHelpURL += String::CreateFromInt32( nHelpId );
    }

    // try to find the help frame
    Reference < XDispatchProvider > xFrame(
        xActiveTask->findFrame( ::rtl::OUString::createFromAscii( "OFFICE_HELP" ),
        FrameSearchFlag::GLOBAL ), UNO_QUERY );
    ::com::sun::star::util::URL aURL;
    aURL.Complete = aHelpURL;
    Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
            DEFINE_CONST_UNICODE("com.sun.star.util.URLTransformer" )), UNO_QUERY );
    xTrans->parseStrict( aURL );

    Sequence < PropertyValue > aProps;
    sal_Int32 nFlag = FrameSearchFlag::GLOBAL;
    if ( aTicket.Len() )
    {
        // if there is a ticket, we are inside a plugin, so a request including the URL must be posted
        if ( !xFrame.is() )
            // must be created on dispatch
            nFlag |= FrameSearchFlag::CREATE;
    }
    else
    {
        // otherwise the URL can be dispatched to the help frame
        if ( !xFrame.is() )
        {
            Reference < XFrame > xTask = xActiveTask->findFrame( DEFINE_CONST_UNICODE( "_blank" ), 0 );
            xFrame = Reference < XDispatchProvider >( xTask, UNO_QUERY );
            Window* pWin = VCLUnoHelper::GetWindow( xTask->getContainerWindow() );
            pWin->SetText( String( SfxResId( STR_HELP_WINDOW_TITLE ) ) );
            SfxHelpWindow_Impl* pHlpWin = new SfxHelpWindow_Impl( xTask, pWin, WB_DOCKBORDER );
            pHlpWin->Show();
            Reference< ::com::sun::star::awt::XWindow > xWindow = VCLUnoHelper::GetInterface( pHlpWin );
            xWindow->setPosSize( 50, 50, 300, 200, ::com::sun::star::awt::PosSize::SIZE );
            if ( !xTask->setComponent( xWindow, Reference < XController >() ) )
                return FALSE;
            else
            {
                pHlpWin->setContainerWindow( xTask->getContainerWindow() );
                pHlpWin->SetFactory( aHelpModuleName );
                xTask->getContainerWindow()->setVisible( sal_True );
            }
        }
    }

    Reference < XDispatch > xDispatch = xFrame->queryDispatch( aURL,
                            DEFINE_CONST_UNICODE("OFFICE_HELP"), FrameSearchFlag::ALL );
    if ( xDispatch.is() )
    {
        xDispatch->dispatch( aURL, aProps );
    }

    return TRUE;
}

/*-----------------22.11.2000 10:59-----------------
 * old code
BOOL SfxHelp_Impl::ImplStart( ULONG nHelpId, BOOL bCheckHelpFile, BOOL bChangeHelpFile, BOOL bHelpAgent )
{
    static BOOL bInHelpRequest = FALSE;
    if ( bInHelpRequest || !nHelpId || ( nHelpId == SID_EXTENDEDHELP ) )
    {
        if ( bInHelpRequest )
            Sound::Beep();
        return FALSE;
    }

    if ( Help::IsRightHelp() )
    {
        if( ImplGetHelpMode() & HELPTEXTMODE_NOHELPAGENT )
            return FALSE;

        if ( ( nHelpId == HELP_INDEX ) || !CheckHelpFile( TRUE ) )
            return FALSE;

        bInHelpRequest = TRUE;
        SetCurrentHelpFile( nHelpId );
        StartHelpPI( nHelpId, FALSE, FALSE );
        bInHelpRequest = FALSE;
        return TRUE;
    }

    bInHelpRequest = TRUE;

    if( ImplGetHelpMode() & HELPTEXTMODE_NOCONTEXTHELP )
    {
        if( nHelpId < 20000 || nHelpId > 20006 )
            nHelpId = HELP_INDEX;
    }

    if ( bChangeHelpFile )
        SetCurrentHelpFile( nHelpId );

    BOOL bDone = FALSE;
    if ( !bCheckHelpFile || CheckHelpFile( TRUE ) )
    {
        SfxViewFrame* pFrame = SfxViewFrame::Current();
        if ( !bHelpAgent || ( nHelpId == HELP_INDEX ) )
//              !Application::IsInModalMode() &&
//              Application::GetAppWindow()->IsEnabled() &&
//              !SearchFocusWindowParent() &&   // kein Dialog aktiv
//              ( !pFrame || !pFrame->GetObjectShell()->IsInModalMode() ) )
        {
            SfxHelpViewShell* pViewShell = GetHelpViewShell( TRUE );
            if ( pViewShell )
                bDone = pViewShell->ShowHelp( GetHelpFile(), nHelpId );
        }
        else
        {
            StartHelpPI( nHelpId, TRUE, FALSE );
            SfxHelpPI* pHelpPI= SFX_APP()->GetHelpPI();
            if ( pHelpPI )
            {
                if ( !pHelpPI->IsFloatingMode() )
                {
                    pHelpPI->SetFloatingMode( TRUE );
                    bForcedFloatingPI = TRUE;
                }
                if ( pHelpPI->GetFloatingWindow() )
                    pHelpPI->GetFloatingWindow()->ToTop();
                CheckPIPosition();
                bDone = TRUE;
            }
        }
    }
    bInHelpRequest = FALSE;
    return bDone;
    return FALSE;
}
*/

struct HelpFileInfo;
class SfxHelp
{
public:
    static  BOOL            ShowHelp( ULONG nId, BOOL bShowInHelpAgent, const char* pFileName = 0, BOOL bQuiet = FALSE );
    static  BOOL            ShowHelp( const String& rKeyword, BOOL bShowInHelpAgent, const char* pFileName = 0 );
    static  void            ShowHint( ULONG nId );
    static  void            SetCustomHelpFile( const String& rName );
    static  USHORT          GetHelpFileInfoCount();
    static  HelpFileInfo*   GetHelpFileInfo( USHORT n );
};

BOOL SfxHelp::ShowHelp( ULONG nId, BOOL bShowInHelpAgent, const char* pFileName, BOOL bQuiet )
{
    return FALSE;
}

BOOL SfxHelp::ShowHelp( const String& rKeyword, BOOL bShowInHelpAgent, const char* pFileName )
{
    return FALSE;
}

void SfxHelp::ShowHint( ULONG nId )
{
}

void SfxHelp::SetCustomHelpFile( const String& rName )
{
}

USHORT SfxHelp::GetHelpFileInfoCount()
{
    return 0;
}

HelpFileInfo* SfxHelp::GetHelpFileInfo( USHORT n )
{
    return NULL;
}

class SfxHelpPI
{
public:
    void            LoadTopic( const String& rFileName, ULONG nId );
    void            LoadTopic( ULONG nId );
    void            LoadTopic( const String& rKeyword );
    void            ResetTopic();
    BOOL            Close();
//    BOOL            IsConstructed() const { return ( pHelpPI != 0 ); }
    String          GetExtraInfo() const;
//    HelpPI*         GetHelpPI() const { return pHelpPI; }
//    virtual void    FillInfo( SfxChildWinInfo& ) const;
    void            SetTip( ULONG nId );
    void            SetTipText( const String& rText );
//    BOOL            IsInShowMe() const { return bInShowMe; }
//    BOOL            IsTopicJustRequested() const { return aTopicJustRequestedTimer.IsActive(); }
//    void            SetTopicJustRequested( BOOL bOn ) { if( bOn )
//                                                            aTopicJustRequestedTimer.Start();
//                                                        else
//                                                            aTopicJustRequestedTimer.Stop(); }
};

void SfxHelpPI::LoadTopic( const String& rFileName, ULONG nId ) {}
void SfxHelpPI::LoadTopic( ULONG nId ) {}
void SfxHelpPI::LoadTopic( const String& rKeyword ) {}
void SfxHelpPI::ResetTopic() {}
//    BOOL            IsConstructed() const { return ( pHelpPI != 0 ); }
//    HelpPI*         GetHelpPI() const { return pHelpPI; }
//    virtual void    FillInfo( SfxChildWinInfo& ) const;
void SfxHelpPI::SetTip( ULONG nId ) {}
void SfxHelpPI::SetTipText( const String& rText ) {}

class SfxHelpPIWrapper
{
public:
    static USHORT GetChildWindowId();
};

USHORT SfxHelpPIWrapper::GetChildWindowId()
{
    return 0;
}

class SfxHelpTipsWrapper
{
public:
    static USHORT GetChildWindowId();
};

USHORT SfxHelpTipsWrapper::GetChildWindowId()
{
    return 0;
}
<commit_msg>fix: #81637# when the HelpWindow starts show always start page<commit_after>/*************************************************************************
 *
 *  $RCSfile: sfxhelp.cxx,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: pb $ $Date: 2000-12-08 16:19:17 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#include "sfxhelp.hxx"

#pragma hdrstop

#ifndef _COM_SUN_STAR_UNO_REFERENCE_H_
#include <com/sun/star/uno/Reference.h>
#endif
#ifndef _COM_SUN_STAR_FRAME_XFRAME_HPP_
#include <com/sun/star/frame/XFrame.hpp>
#endif
#ifndef _UNOTOOLS_PROCESSFACTORY_HXX
#include <comphelper/processfactory.hxx>
#endif
#ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
#include <com/sun/star/awt/XWindow.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_POSSIZE_HPP_
#include <com/sun/star/awt/PosSize.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_XTASK_HPP_
#include <com/sun/star/frame/XTask.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_XTASKSSUPPLIER_HPP_
#include <com/sun/star/frame/XTasksSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_XURLTRANSFORMER_HPP_
#include <com/sun/star/util/XURLTransformer.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_XDISPATCH_HPP_
#include <com/sun/star/frame/XDispatch.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_XDISPATCHPROVIDER_HPP_
#include <com/sun/star/frame/XDispatchProvider.hpp>
#endif
#include <com/sun/star/frame/FrameSearchFlag.hpp>
#include <toolkit/helper/vclunohelper.hxx>

#include "sfxsids.hrc"
#include "app.hxx"
#include "viewfrm.hxx"
#include "msgpool.hxx"
#include "newhelp.hxx"
#include "objsh.hxx"
#include "docfac.hxx"
#include "sfxresid.hxx"
#include "app.hrc"

using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::util;

SfxHelp_Impl::SfxHelp_Impl()
{
}

SfxHelp_Impl::~SfxHelp_Impl()
{
}

String SfxHelp_Impl::GetHelpModuleName( ULONG nHelpId )
{
    String aModuleName;
    SfxViewFrame *pViewFrame = SfxViewFrame::Current();
    if ( pViewFrame )
    {
        // Wenn es ein Slot ist, kann es sein, da\s internes InPlace vorliegt
        // und eine Container-SlotId gefragt ist
        if (nHelpId >= (ULONG) SID_SFX_START && nHelpId <= (ULONG) SHRT_MAX)
        {
            if ( pViewFrame->GetParentViewFrame_Impl() )
            {
                // Ist es ein ContainerSlot ?
                const SfxSlot* pSlot = SFX_APP()->GetSlotPool(pViewFrame).GetSlot( (USHORT) nHelpId );
                if ( !pSlot || pSlot->IsMode( SFX_SLOT_CONTAINER ) )
                    pViewFrame = pViewFrame->GetParentViewFrame_Impl();
            }
        }

        if( pViewFrame->GetObjectShell() )
            aModuleName = String::CreateFromAscii( pViewFrame->GetObjectShell()->GetFactory().GetShortName() );
    }

    return aModuleName;
}

BOOL SfxHelp_Impl::Start( ULONG nHelpId )
{
    Reference < XTasksSupplier > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
                DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );

    Reference < XTask > xActiveTask = xDesktop->getActiveTask();
    if ( !xActiveTask.is() )
        return FALSE;

    // try to find the help frame
    Reference < XDispatchProvider > xFrame(
        xActiveTask->findFrame( ::rtl::OUString::createFromAscii( "OFFICE_HELP" ),
        FrameSearchFlag::GLOBAL ), UNO_QUERY );

    Sequence < PropertyValue > aProps;
    sal_Int32 nFlag = FrameSearchFlag::GLOBAL;
    String aHelpModuleName = GetHelpModuleName( nHelpId );
    sal_Bool bNewWin = sal_False;
    if ( aTicket.Len() )
    {
        // if there is a ticket, we are inside a plugin, so a request including the URL must be posted
        if ( !xFrame.is() )
            // must be created on dispatch
            nFlag |= FrameSearchFlag::CREATE;
    }
    else
    {
        // otherwise the URL can be dispatched to the help frame
        if ( !xFrame.is() )
        {
            bNewWin = sal_True;
            Reference < XFrame > xTask = xActiveTask->findFrame( DEFINE_CONST_UNICODE( "_blank" ), 0 );
            xFrame = Reference < XDispatchProvider >( xTask, UNO_QUERY );
            Window* pWin = VCLUnoHelper::GetWindow( xTask->getContainerWindow() );
            pWin->SetText( String( SfxResId( STR_HELP_WINDOW_TITLE ) ) );
            SfxHelpWindow_Impl* pHlpWin = new SfxHelpWindow_Impl( xTask, pWin, WB_DOCKBORDER );
            pHlpWin->Show();
            Reference< ::com::sun::star::awt::XWindow > xWindow = VCLUnoHelper::GetInterface( pHlpWin );
            xWindow->setPosSize( 50, 50, 300, 200, ::com::sun::star::awt::PosSize::SIZE );
            if ( !xTask->setComponent( xWindow, Reference < XController >() ) )
                return FALSE;
            else
            {
                pHlpWin->setContainerWindow( xTask->getContainerWindow() );
                pHlpWin->SetFactory( aHelpModuleName );
                xTask->getContainerWindow()->setVisible( sal_True );
            }
        }
    }

    // build up the help URL
    String aHelpURL(String::CreateFromAscii("vnd.sun.star.help://") );
    aHelpURL += aHelpModuleName;
    if ( !nHelpId || bNewWin )
        aHelpURL += String( DEFINE_CONST_UNICODE("/start") );
    else
    {
        aHelpURL += '/';
        aHelpURL += String::CreateFromInt32( nHelpId );
    }
    ::com::sun::star::util::URL aURL;
    aURL.Complete = aHelpURL;
    Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
            DEFINE_CONST_UNICODE("com.sun.star.util.URLTransformer" )), UNO_QUERY );
    xTrans->parseStrict( aURL );
    Reference < XDispatch > xDispatch = xFrame->queryDispatch( aURL,
                            DEFINE_CONST_UNICODE("OFFICE_HELP"), FrameSearchFlag::ALL );
    if ( xDispatch.is() )
    {
        xDispatch->dispatch( aURL, aProps );
    }

    return TRUE;
}

/*-----------------22.11.2000 10:59-----------------
 * old code
BOOL SfxHelp_Impl::ImplStart( ULONG nHelpId, BOOL bCheckHelpFile, BOOL bChangeHelpFile, BOOL bHelpAgent )
{
    static BOOL bInHelpRequest = FALSE;
    if ( bInHelpRequest || !nHelpId || ( nHelpId == SID_EXTENDEDHELP ) )
    {
        if ( bInHelpRequest )
            Sound::Beep();
        return FALSE;
    }

    if ( Help::IsRightHelp() )
    {
        if( ImplGetHelpMode() & HELPTEXTMODE_NOHELPAGENT )
            return FALSE;

        if ( ( nHelpId == HELP_INDEX ) || !CheckHelpFile( TRUE ) )
            return FALSE;

        bInHelpRequest = TRUE;
        SetCurrentHelpFile( nHelpId );
        StartHelpPI( nHelpId, FALSE, FALSE );
        bInHelpRequest = FALSE;
        return TRUE;
    }

    bInHelpRequest = TRUE;

    if( ImplGetHelpMode() & HELPTEXTMODE_NOCONTEXTHELP )
    {
        if( nHelpId < 20000 || nHelpId > 20006 )
            nHelpId = HELP_INDEX;
    }

    if ( bChangeHelpFile )
        SetCurrentHelpFile( nHelpId );

    BOOL bDone = FALSE;
    if ( !bCheckHelpFile || CheckHelpFile( TRUE ) )
    {
        SfxViewFrame* pFrame = SfxViewFrame::Current();
        if ( !bHelpAgent || ( nHelpId == HELP_INDEX ) )
//              !Application::IsInModalMode() &&
//              Application::GetAppWindow()->IsEnabled() &&
//              !SearchFocusWindowParent() &&   // kein Dialog aktiv
//              ( !pFrame || !pFrame->GetObjectShell()->IsInModalMode() ) )
        {
            SfxHelpViewShell* pViewShell = GetHelpViewShell( TRUE );
            if ( pViewShell )
                bDone = pViewShell->ShowHelp( GetHelpFile(), nHelpId );
        }
        else
        {
            StartHelpPI( nHelpId, TRUE, FALSE );
            SfxHelpPI* pHelpPI= SFX_APP()->GetHelpPI();
            if ( pHelpPI )
            {
                if ( !pHelpPI->IsFloatingMode() )
                {
                    pHelpPI->SetFloatingMode( TRUE );
                    bForcedFloatingPI = TRUE;
                }
                if ( pHelpPI->GetFloatingWindow() )
                    pHelpPI->GetFloatingWindow()->ToTop();
                CheckPIPosition();
                bDone = TRUE;
            }
        }
    }
    bInHelpRequest = FALSE;
    return bDone;
    return FALSE;
}
*/

struct HelpFileInfo;
class SfxHelp
{
public:
    static  BOOL            ShowHelp( ULONG nId, BOOL bShowInHelpAgent, const char* pFileName = 0, BOOL bQuiet = FALSE );
    static  BOOL            ShowHelp( const String& rKeyword, BOOL bShowInHelpAgent, const char* pFileName = 0 );
    static  void            ShowHint( ULONG nId );
    static  void            SetCustomHelpFile( const String& rName );
    static  USHORT          GetHelpFileInfoCount();
    static  HelpFileInfo*   GetHelpFileInfo( USHORT n );
};

BOOL SfxHelp::ShowHelp( ULONG nId, BOOL bShowInHelpAgent, const char* pFileName, BOOL bQuiet )
{
    return FALSE;
}

BOOL SfxHelp::ShowHelp( const String& rKeyword, BOOL bShowInHelpAgent, const char* pFileName )
{
    return FALSE;
}

void SfxHelp::ShowHint( ULONG nId )
{
}

void SfxHelp::SetCustomHelpFile( const String& rName )
{
}

USHORT SfxHelp::GetHelpFileInfoCount()
{
    return 0;
}

HelpFileInfo* SfxHelp::GetHelpFileInfo( USHORT n )
{
    return NULL;
}

class SfxHelpPI
{
public:
    void            LoadTopic( const String& rFileName, ULONG nId );
    void            LoadTopic( ULONG nId );
    void            LoadTopic( const String& rKeyword );
    void            ResetTopic();
    BOOL            Close();
//    BOOL            IsConstructed() const { return ( pHelpPI != 0 ); }
    String          GetExtraInfo() const;
//    HelpPI*         GetHelpPI() const { return pHelpPI; }
//    virtual void    FillInfo( SfxChildWinInfo& ) const;
    void            SetTip( ULONG nId );
    void            SetTipText( const String& rText );
//    BOOL            IsInShowMe() const { return bInShowMe; }
//    BOOL            IsTopicJustRequested() const { return aTopicJustRequestedTimer.IsActive(); }
//    void            SetTopicJustRequested( BOOL bOn ) { if( bOn )
//                                                            aTopicJustRequestedTimer.Start();
//                                                        else
//                                                            aTopicJustRequestedTimer.Stop(); }
};

void SfxHelpPI::LoadTopic( const String& rFileName, ULONG nId ) {}
void SfxHelpPI::LoadTopic( ULONG nId ) {}
void SfxHelpPI::LoadTopic( const String& rKeyword ) {}
void SfxHelpPI::ResetTopic() {}
//    BOOL            IsConstructed() const { return ( pHelpPI != 0 ); }
//    HelpPI*         GetHelpPI() const { return pHelpPI; }
//    virtual void    FillInfo( SfxChildWinInfo& ) const;
void SfxHelpPI::SetTip( ULONG nId ) {}
void SfxHelpPI::SetTipText( const String& rText ) {}

class SfxHelpPIWrapper
{
public:
    static USHORT GetChildWindowId();
};

USHORT SfxHelpPIWrapper::GetChildWindowId()
{
    return 0;
}

class SfxHelpTipsWrapper
{
public:
    static USHORT GetChildWindowId();
};

USHORT SfxHelpTipsWrapper::GetChildWindowId()
{
    return 0;
}
<|endoftext|>