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

#ifndef _LINGUISTIC_CONVDICLIST_HXX_
#define _LINGUISTIC_CONVDICLIST_HXX_

#ifndef _COM_SUN_STAR_LINGUISTIC2_XCONVERSIONDICTIONARYLIST_HPP_
#include <com/sun/star/linguistic2/XConversionDictionaryList.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_
#include <com/sun/star/lang/XComponent.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
#include <com/sun/star/lang/XServiceInfo.hpp>
#endif

#ifndef _CPPUHELPER_IMPLBASE3_HXX_
#include <cppuhelper/implbase3.hxx>
#endif
#ifndef _CPPUHELPER_INTERFACECONTAINER_H_
#include <cppuhelper/interfacecontainer.h>
#endif

#ifndef _SVARRAY_HXX
#include <svtools/svarray.hxx>
#endif
#ifndef _TOOLS_DEBUG_HXX //autogen wg. DBG_ASSERT
#include <tools/debug.hxx>
#endif

#include "misc.hxx"
#include "lngopt.hxx"

class ConvDicNameContainer;

///////////////////////////////////////////////////////////////////////////

class ConvDicList :
    public cppu::WeakImplHelper3
    <
        ::com::sun::star::linguistic2::XConversionDictionaryList,
        ::com::sun::star::lang::XComponent,
        ::com::sun::star::lang::XServiceInfo
    >
{

    class MyAppExitListener : public linguistic::AppExitListener
    {
        ConvDicList & rMyDicList;

    public:
        MyAppExitListener( ConvDicList &rDicList ) : rMyDicList( rDicList ) {}
        virtual void    AtExit();
    };

    ::cppu::OInterfaceContainerHelper       aEvtListeners;

    ConvDicNameContainer                   *pNameContainer;
    ::com::sun::star::uno::Reference<
        ::com::sun::star::container::XNameContainer >   xNameContainer;

    MyAppExitListener                      *pExitListener;
    ::com::sun::star::uno::Reference< ::com::sun::star::frame::
                XTerminateListener >        xExitListener;

    BOOL                                    bDisposing;

    // disallow copy-constructor and assignment-operator for now
    ConvDicList( const ConvDicList & );
    ConvDicList & operator = (const ConvDicList &);

    ConvDicNameContainer &  GetNameContainer();

public:
    ConvDicList();
    virtual ~ConvDicList();

    // XConversionDictionaryList
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > SAL_CALL getDictionaryContainer(  ) throw (::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XConversionDictionary > SAL_CALL addNewDictionary( const ::rtl::OUString& aName, const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nConversionDictionaryType ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL queryConversions( const ::rtl::OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nConversionDictionaryType, ::com::sun::star::linguistic2::ConversionDirection eDirection, sal_Int32 nTextConversionOptions ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
    virtual sal_Int16 SAL_CALL queryMaxCharCount( const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nConversionDictionaryType, ::com::sun::star::linguistic2::ConversionDirection eDirection ) throw (::com::sun::star::uno::RuntimeException);

    // XComponent
    virtual void SAL_CALL dispose(  ) throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);

    // XServiceInfo
    virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
    virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException);

    static inline ::rtl::OUString
        getImplementationName_Static() throw();
    static com::sun::star::uno::Sequence< ::rtl::OUString >
        getSupportedServiceNames_Static() throw();

    // non UNO-specific
    void                    FlushDics();
};

inline ::rtl::OUString ConvDicList::getImplementationName_Static() throw()
{
    return A2OU( "com.sun.star.lingu2.ConvDicList" );
}

///////////////////////////////////////////////////////////////////////////

#endif

<commit_msg>INTEGRATION: CWS ooo19126 (1.2.52); FILE MERGED 2005/09/05 17:29:35 rt 1.2.52.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: convdiclist.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-07 19:49:07 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _LINGUISTIC_CONVDICLIST_HXX_
#define _LINGUISTIC_CONVDICLIST_HXX_

#ifndef _COM_SUN_STAR_LINGUISTIC2_XCONVERSIONDICTIONARYLIST_HPP_
#include <com/sun/star/linguistic2/XConversionDictionaryList.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_
#include <com/sun/star/lang/XComponent.hpp>
#endif
#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_
#include <com/sun/star/lang/XServiceInfo.hpp>
#endif

#ifndef _CPPUHELPER_IMPLBASE3_HXX_
#include <cppuhelper/implbase3.hxx>
#endif
#ifndef _CPPUHELPER_INTERFACECONTAINER_H_
#include <cppuhelper/interfacecontainer.h>
#endif

#ifndef _SVARRAY_HXX
#include <svtools/svarray.hxx>
#endif
#ifndef _TOOLS_DEBUG_HXX //autogen wg. DBG_ASSERT
#include <tools/debug.hxx>
#endif

#include "misc.hxx"
#include "lngopt.hxx"

class ConvDicNameContainer;

///////////////////////////////////////////////////////////////////////////

class ConvDicList :
    public cppu::WeakImplHelper3
    <
        ::com::sun::star::linguistic2::XConversionDictionaryList,
        ::com::sun::star::lang::XComponent,
        ::com::sun::star::lang::XServiceInfo
    >
{

    class MyAppExitListener : public linguistic::AppExitListener
    {
        ConvDicList & rMyDicList;

    public:
        MyAppExitListener( ConvDicList &rDicList ) : rMyDicList( rDicList ) {}
        virtual void    AtExit();
    };

    ::cppu::OInterfaceContainerHelper       aEvtListeners;

    ConvDicNameContainer                   *pNameContainer;
    ::com::sun::star::uno::Reference<
        ::com::sun::star::container::XNameContainer >   xNameContainer;

    MyAppExitListener                      *pExitListener;
    ::com::sun::star::uno::Reference< ::com::sun::star::frame::
                XTerminateListener >        xExitListener;

    BOOL                                    bDisposing;

    // disallow copy-constructor and assignment-operator for now
    ConvDicList( const ConvDicList & );
    ConvDicList & operator = (const ConvDicList &);

    ConvDicNameContainer &  GetNameContainer();

public:
    ConvDicList();
    virtual ~ConvDicList();

    // XConversionDictionaryList
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > SAL_CALL getDictionaryContainer(  ) throw (::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XConversionDictionary > SAL_CALL addNewDictionary( const ::rtl::OUString& aName, const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nConversionDictionaryType ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL queryConversions( const ::rtl::OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nConversionDictionaryType, ::com::sun::star::linguistic2::ConversionDirection eDirection, sal_Int32 nTextConversionOptions ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
    virtual sal_Int16 SAL_CALL queryMaxCharCount( const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nConversionDictionaryType, ::com::sun::star::linguistic2::ConversionDirection eDirection ) throw (::com::sun::star::uno::RuntimeException);

    // XComponent
    virtual void SAL_CALL dispose(  ) throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);

    // XServiceInfo
    virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
    virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException);

    static inline ::rtl::OUString
        getImplementationName_Static() throw();
    static com::sun::star::uno::Sequence< ::rtl::OUString >
        getSupportedServiceNames_Static() throw();

    // non UNO-specific
    void                    FlushDics();
};

inline ::rtl::OUString ConvDicList::getImplementationName_Static() throw()
{
    return A2OU( "com.sun.star.lingu2.ConvDicList" );
}

///////////////////////////////////////////////////////////////////////////

#endif

<|endoftext|>


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

#include "LIEF/VDEX.hpp"
#include "LIEF/VDEX/File.hpp"
#include "LIEF/DEX/File.hpp"

#include "LIEF/OAT/Binary.hpp"
#include "LIEF/OAT/hash.hpp"
#include "logging.hpp"
#include "visitors/json.hpp"

namespace LIEF {
namespace OAT {

Binary::Binary() = default;
Binary::~Binary() = default;

const Header& Binary::header() const {
  return header_;
}

Header& Binary::header() {
  return const_cast<Header&>(static_cast<const Binary*>(this)->header());
}

Binary::it_dex_files Binary::dex_files() {
  if (vdex_ != nullptr) {
    return vdex_->dex_files_;
  }
  return dex_files_;
}

Binary::it_const_dex_files Binary::dex_files() const {
  if (vdex_ != nullptr) {
    return vdex_->dex_files_;
  }
  return dex_files_;
}

Binary::it_oat_dex_files Binary::oat_dex_files() {
  return oat_dex_files_;
}

Binary::it_const_oat_dex_files Binary::oat_dex_files() const {
  return oat_dex_files_;
}

Binary::it_const_classes Binary::classes() const {
  return classes_list_;
}

Binary::it_classes Binary::classes() {
  return classes_list_;
}

bool Binary::has_class(const std::string& class_name) const {
  return classes_.find(DEX::Class::fullname_normalized(class_name)) != std::end(classes_);
}

const Class* Binary::get_class(const std::string& class_name) const {
  auto it = classes_.find(DEX::Class::fullname_normalized(class_name));
  if (it == std::end(classes_)) {
    return nullptr;
  }
  return it->second;
}

Class* Binary::get_class(const std::string& class_name) {
  return const_cast<Class*>(static_cast<const Binary*>(this)->get_class(class_name));
}

const Class* Binary::get_class(size_t index) const {
  if (index >= classes_.size()) {
    return nullptr;
  }

  const auto it = std::find_if(std::begin(classes_), std::end(classes_),
      [index] (const std::pair<std::string, Class*>& p) {
        return p.second->index() == index;
      });

  if (it == std::end(classes_)) {
    return nullptr;
  }
  return it->second;
}

Class* Binary::get_class(size_t index) {
  return const_cast<Class*>(static_cast<const Binary*>(this)->get_class(index));
}

Binary::it_const_methods Binary::methods() const {
  return methods_;
}

Binary::it_methods Binary::methods() {
  return methods_;
}

Binary::dex2dex_info_t Binary::dex2dex_info() const {
  dex2dex_info_t info;

  for (const DEX::File& dex_file : dex_files()) {
    info.emplace(&dex_file, dex_file.dex2dex_info());
  }
  return info;
}

std::string Binary::dex2dex_json_info() {

#if defined(LIEF_JSON_SUPPORT)
  json mapping = json::object();

  for (const DEX::File& dex_file : dex_files()) {
    json dex2dex = json::parse(dex_file.dex2dex_json_info());
    mapping[dex_file.name()] = dex2dex;
  }

  return mapping.dump();
#else
  return "";
#endif

}

void Binary::add_class(std::unique_ptr<Class> cls) {
  classes_.emplace(cls->fullname(), cls.get());
  classes_list_.push_back(std::move(cls));
}

void Binary::accept(Visitor& visitor) const {
  visitor.visit(*this);
}

bool Binary::operator==(const Binary& rhs) const {
  if (this == &rhs) {
    return true;
  }
  size_t hash_lhs = Hash::hash(*this);
  size_t hash_rhs = Hash::hash(rhs);
  return hash_lhs == hash_rhs;
}

bool Binary::operator!=(const Binary& rhs) const {
  return !(*this == rhs);
}

std::ostream& operator<<(std::ostream& os, const Binary& binary) {

  os << "Header" << std::endl;
  os << "======" << std::endl;
  os << binary.header() << std::endl;

  if (binary.oat_dex_files().size() > 0) {
    os << "Dex Files" << std::endl;
    os << "=========" << std::endl;

    for (const DexFile& dex : binary.oat_dex_files()) {
      os << dex << std::endl;
    }
  }

  std::cout << "Number of classes: " << std::dec << binary.classes().size() << std::endl;
  std::cout << "Number of methods: " << std::dec << binary.methods().size() << std::endl;

  return os;
}

}
}
<commit_msg>Fix std::cout<commit_after>/* Copyright 2017 - 2022 R. Thomas
 * Copyright 2017 - 2022 Quarkslab
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <fstream>

#include "LIEF/VDEX.hpp"
#include "LIEF/VDEX/File.hpp"
#include "LIEF/DEX/File.hpp"

#include "LIEF/OAT/Binary.hpp"
#include "LIEF/OAT/hash.hpp"
#include "logging.hpp"
#include "visitors/json.hpp"

namespace LIEF {
namespace OAT {

Binary::Binary() = default;
Binary::~Binary() = default;

const Header& Binary::header() const {
  return header_;
}

Header& Binary::header() {
  return const_cast<Header&>(static_cast<const Binary*>(this)->header());
}

Binary::it_dex_files Binary::dex_files() {
  if (vdex_ != nullptr) {
    return vdex_->dex_files_;
  }
  return dex_files_;
}

Binary::it_const_dex_files Binary::dex_files() const {
  if (vdex_ != nullptr) {
    return vdex_->dex_files_;
  }
  return dex_files_;
}

Binary::it_oat_dex_files Binary::oat_dex_files() {
  return oat_dex_files_;
}

Binary::it_const_oat_dex_files Binary::oat_dex_files() const {
  return oat_dex_files_;
}

Binary::it_const_classes Binary::classes() const {
  return classes_list_;
}

Binary::it_classes Binary::classes() {
  return classes_list_;
}

bool Binary::has_class(const std::string& class_name) const {
  return classes_.find(DEX::Class::fullname_normalized(class_name)) != std::end(classes_);
}

const Class* Binary::get_class(const std::string& class_name) const {
  auto it = classes_.find(DEX::Class::fullname_normalized(class_name));
  if (it == std::end(classes_)) {
    return nullptr;
  }
  return it->second;
}

Class* Binary::get_class(const std::string& class_name) {
  return const_cast<Class*>(static_cast<const Binary*>(this)->get_class(class_name));
}

const Class* Binary::get_class(size_t index) const {
  if (index >= classes_.size()) {
    return nullptr;
  }

  const auto it = std::find_if(std::begin(classes_), std::end(classes_),
      [index] (const std::pair<std::string, Class*>& p) {
        return p.second->index() == index;
      });

  if (it == std::end(classes_)) {
    return nullptr;
  }
  return it->second;
}

Class* Binary::get_class(size_t index) {
  return const_cast<Class*>(static_cast<const Binary*>(this)->get_class(index));
}

Binary::it_const_methods Binary::methods() const {
  return methods_;
}

Binary::it_methods Binary::methods() {
  return methods_;
}

Binary::dex2dex_info_t Binary::dex2dex_info() const {
  dex2dex_info_t info;

  for (const DEX::File& dex_file : dex_files()) {
    info.emplace(&dex_file, dex_file.dex2dex_info());
  }
  return info;
}

std::string Binary::dex2dex_json_info() {

#if defined(LIEF_JSON_SUPPORT)
  json mapping = json::object();

  for (const DEX::File& dex_file : dex_files()) {
    json dex2dex = json::parse(dex_file.dex2dex_json_info());
    mapping[dex_file.name()] = dex2dex;
  }

  return mapping.dump();
#else
  return "";
#endif

}

void Binary::add_class(std::unique_ptr<Class> cls) {
  classes_.emplace(cls->fullname(), cls.get());
  classes_list_.push_back(std::move(cls));
}

void Binary::accept(Visitor& visitor) const {
  visitor.visit(*this);
}

bool Binary::operator==(const Binary& rhs) const {
  if (this == &rhs) {
    return true;
  }
  size_t hash_lhs = Hash::hash(*this);
  size_t hash_rhs = Hash::hash(rhs);
  return hash_lhs == hash_rhs;
}

bool Binary::operator!=(const Binary& rhs) const {
  return !(*this == rhs);
}

std::ostream& operator<<(std::ostream& os, const Binary& binary) {

  os << "Header" << std::endl;
  os << "======" << std::endl;
  os << binary.header() << std::endl;

  if (binary.oat_dex_files().size() > 0) {
    os << "Dex Files" << std::endl;
    os << "=========" << std::endl;

    for (const DexFile& dex : binary.oat_dex_files()) {
      os << dex << std::endl;
    }
  }

  os << "Number of classes: " << std::dec << binary.classes().size() << std::endl;
  os << "Number of methods: " << std::dec << binary.methods().size() << std::endl;

  return os;
}

}
}
<|endoftext|>


<commit_before>
//@HEADER
// ***************************************************
//
// HPCG: High Performance Conjugate Gradient Benchmark
//
// Contact:
// Michael A. Heroux ( maherou@sandia.gov)
// Jack Dongarra     (dongarra@eecs.utk.edu)
// Piotr Luszczek    (luszczek@eecs.utk.edu)
//
// ***************************************************
//@HEADER

/*!
 @file Output_File.hpp

 HPCG output file classes
 */

#ifndef OUTPUTFILE_HPP
#define OUTPUTFILE_HPP

#include <list>
#include <string>

//! The OutputFile class for the uniform collecting and reporting of performance data for HPCG

/*!

  The OutputFile class facilitates easy collecting and reporting of
  key-value-formatted data that can be then registered with the HPCG results
  collection website. The keys may have hierarchy key1::key2::key3=val with
  double colon :: as a seperator. A sample output may look like this (note how
  "major" and "micro" keys repeat with different ancestor keys):

\code

version=3.2.1alpha
version::major=3
version::minor=2
version::micro=1
version::release=alpha
axis=xyz
axis::major=x
axis::minor=y

\endcode

*/
class OutputFile {
protected:
  std::list<OutputFile *> descendants; //!< descendant elements
  std::string name; //!< name of the benchmark
  std::string version; //!< version of the benchmark
  std::string key; //!< the key under which the element is stored
  std::string value; //!< the value of the stored element
  std::string eol = "\n"; //!< end-of-line character sequence in the output file
  std::string keySeparator = "::"; //!< character sequence to separate keys in the output file

  //! Recursively generate output string from descendant list, and their descendants and so on
  std::string generateRecursive(std::string prefix);

public:
  static OutputFile * allocKeyVal(const std::string & key, const std::string & value);

  //! Constructor: accepts name and version as strings that are used to create a file name for printing results.
  /*!
    This constructor accepts and name and version number for the benchmark that
    are used to form a file name information for results that are generated by
    the generate() method.
    \param name (in) string containing name of the benchmark
    \param version (in) string containing the version of the benchmark
  */
  OutputFile(const std::string & name, const std::string & version);

  //! Default constructor: no-arguments accepted, should be used for descendant nodes
  /*!
    This no-argument constructor can be used for descendant nodes to provide
    key1::key2::key3=val output. Unlike the root node, descendant nodes do not
    have name and version but only store key-value pairs.
  */
  OutputFile(void);

  ~OutputFile();

  //! Create and add a descendant element with value of type "string"
  /*!
  Create and add a descendant element identified by "key" and associated with
  "value".  The element is added at the end of a list of previously added
  elements.

  @param[in] key   The key that identifies the added element and under which the element is stored
  @param[in] value The value stored by the element
  */
  void add(const std::string & key, const std::string & value);

  //! Create and add a descendant element with value of type "double"
  /*!
  Create and add a descendant element identified by "key" and associated with
  "value".  The element is added at the end of a list of previously added
  elements.

  @param[in] key   The key that identifies the added element and under which the element is stored
  @param[in] value The value stored by the element
  */
   void add(const std::string & key, double value);

  //! Create and add a descendant element with value of type "int"
  /*!
  Create and add a descendant element identified by "key" and associated with
  "value".  The element is added at the end of a list of previously added
  elements.

  @param[in] key   The key that identifies the added element and under which the element is stored
  @param[in] value The value stored by the element
  */
   void add(const std::string & key, int value);

#ifndef HPCG_NO_LONG_LONG
  //! Create and add a descendant element with value of type "long long"
  /*!
  Create and add a descendant element identified by "key" and associated with
  "value".  The element is added at the end of a list of previously added
  elements.

  @param[in] key   The key that identifies the added element and under which the element is stored
  @param[in] value The value stored by the element
  */
   void add(const std::string & key, long long value);
#endif

  //! Create and add a descendant element with value of type "size_t"
  /*!
  Create and add a descendant element identified by "key" and associated with
  "value".  The element is added at the end of a list of previously added
  elements.

  @param[in] key   The key that identifies the added element and under which the element is stored
  @param[in] value The value stored by the element
  */
   void add(const std::string & key, size_t value);

  //! Key-Value setter method
  /*!
  Set the key and the value of this element.

  @param[in] key   The key that identifies this element and under which the element is stored
  @param[in] value The value stored by the element
  */
  void setKeyValue(const std::string & key, const std::string & value);

  //! Get the element in the list with the given key or return NULL if not found
  OutputFile * get(const std::string & key);

  //! Generate output string with results based on the stored key-value hierarchy
  std::string generate(void);
};

#endif // OUTPUTFILE_HPP
<commit_msg>Fix spelling error<commit_after>
//@HEADER
// ***************************************************
//
// HPCG: High Performance Conjugate Gradient Benchmark
//
// Contact:
// Michael A. Heroux ( maherou@sandia.gov)
// Jack Dongarra     (dongarra@eecs.utk.edu)
// Piotr Luszczek    (luszczek@eecs.utk.edu)
//
// ***************************************************
//@HEADER

/*!
 @file Output_File.hpp

 HPCG output file classes
 */

#ifndef OUTPUTFILE_HPP
#define OUTPUTFILE_HPP

#include <list>
#include <string>

//! The OutputFile class for the uniform collecting and reporting of performance data for HPCG

/*!

  The OutputFile class facilitates easy collecting and reporting of
  key-value-formatted data that can be then registered with the HPCG results
  collection website. The keys may have hierarchy key1::key2::key3=val with
  double colon :: as a separator. A sample output may look like this (note how
  "major" and "micro" keys repeat with different ancestor keys):

\code

version=3.2.1alpha
version::major=3
version::minor=2
version::micro=1
version::release=alpha
axis=xyz
axis::major=x
axis::minor=y

\endcode

*/
class OutputFile {
protected:
  std::list<OutputFile *> descendants; //!< descendant elements
  std::string name; //!< name of the benchmark
  std::string version; //!< version of the benchmark
  std::string key; //!< the key under which the element is stored
  std::string value; //!< the value of the stored element
  std::string eol = "\n"; //!< end-of-line character sequence in the output file
  std::string keySeparator = "::"; //!< character sequence to separate keys in the output file

  //! Recursively generate output string from descendant list, and their descendants and so on
  std::string generateRecursive(std::string prefix);

public:
  static OutputFile * allocKeyVal(const std::string & key, const std::string & value);

  //! Constructor: accepts name and version as strings that are used to create a file name for printing results.
  /*!
    This constructor accepts and name and version number for the benchmark that
    are used to form a file name information for results that are generated by
    the generate() method.
    \param name (in) string containing name of the benchmark
    \param version (in) string containing the version of the benchmark
  */
  OutputFile(const std::string & name, const std::string & version);

  //! Default constructor: no-arguments accepted, should be used for descendant nodes
  /*!
    This no-argument constructor can be used for descendant nodes to provide
    key1::key2::key3=val output. Unlike the root node, descendant nodes do not
    have name and version but only store key-value pairs.
  */
  OutputFile(void);

  ~OutputFile();

  //! Create and add a descendant element with value of type "string"
  /*!
  Create and add a descendant element identified by "key" and associated with
  "value".  The element is added at the end of a list of previously added
  elements.

  @param[in] key   The key that identifies the added element and under which the element is stored
  @param[in] value The value stored by the element
  */
  void add(const std::string & key, const std::string & value);

  //! Create and add a descendant element with value of type "double"
  /*!
  Create and add a descendant element identified by "key" and associated with
  "value".  The element is added at the end of a list of previously added
  elements.

  @param[in] key   The key that identifies the added element and under which the element is stored
  @param[in] value The value stored by the element
  */
   void add(const std::string & key, double value);

  //! Create and add a descendant element with value of type "int"
  /*!
  Create and add a descendant element identified by "key" and associated with
  "value".  The element is added at the end of a list of previously added
  elements.

  @param[in] key   The key that identifies the added element and under which the element is stored
  @param[in] value The value stored by the element
  */
   void add(const std::string & key, int value);

#ifndef HPCG_NO_LONG_LONG
  //! Create and add a descendant element with value of type "long long"
  /*!
  Create and add a descendant element identified by "key" and associated with
  "value".  The element is added at the end of a list of previously added
  elements.

  @param[in] key   The key that identifies the added element and under which the element is stored
  @param[in] value The value stored by the element
  */
   void add(const std::string & key, long long value);
#endif

  //! Create and add a descendant element with value of type "size_t"
  /*!
  Create and add a descendant element identified by "key" and associated with
  "value".  The element is added at the end of a list of previously added
  elements.

  @param[in] key   The key that identifies the added element and under which the element is stored
  @param[in] value The value stored by the element
  */
   void add(const std::string & key, size_t value);

  //! Key-Value setter method
  /*!
  Set the key and the value of this element.

  @param[in] key   The key that identifies this element and under which the element is stored
  @param[in] value The value stored by the element
  */
  void setKeyValue(const std::string & key, const std::string & value);

  //! Get the element in the list with the given key or return NULL if not found
  OutputFile * get(const std::string & key);

  //! Generate output string with results based on the stored key-value hierarchy
  std::string generate(void);
};

#endif // OUTPUTFILE_HPP
<|endoftext|>


<commit_before>#include "stdafx.h"
#include "NetworkServer.hpp"

NetworkWorker* NetworkWorker::singleton = nullptr;
NetworkWorker::NetworkWorker()
{
	if(singleton) exit(-1);
	singleton = this;
}

AnnVect3 NetworkWorker::getDistantPosition()
{
	return distantPosition;
}

void NetworkWorker::setLocalPositon(AnnVect3 position)
{
	localPosiion = position;
}

NetworkServer::NetworkServer() : NetworkWorker(),
	port(ANVPORT)
{
	//Singleton check

	myType = SERVER;

}

NetworkWorker* NetworkWorker::getSingleton()
{
	return singleton;
}

workerType NetworkWorker::getType()
{
	return myType;
}

int NetworkServer::initialize(int port)
{
	std::stringstream ss;
	if(port < netNS::MIN_PORT)
	{
		AnnDebug() << "Invalid port number";
		return netNS::NET_ERROR;
	}
	// ------ init network stuff -------
	error = net.createServer(port, netNS::UDP);
	if(error != netNS::NET_OK)
	{
		AnnDebug() << net.getError(error);
		return netNS::NET_ERROR;
	}

	for (int i=0; i<MAX_CLIENT; i++)
	{
		player[i].setConnected(false);
		player[i].setActive(false);
	}

	AnnDebug() << "---- Server ----";
	net.getLocalIP(localIP);
	ss << "Server IP: " << localIP;
	AnnDebug() << ss.str();
	ss.str("");
	ss << "Port: " << port;
	AnnDebug() << ss.str();
	return netNS::NET_OK;
}

// --- Do network communications ---
void NetworkServer::communicate(float frameTime)
{
	// communicate with client
	doClientCommunication();
	// Calculate elapsed time for network communications
	netTime += frameTime;
	if(netTime < netNS::NET_TIMER)
		return;

	netTime -= netNS::NET_TIMER;
	// check for inactive clients, called every NET_TIMER seconds
	checkNetworkTimeout();
}

// --- Check for network timeout ---

void NetworkServer::checkNetworkTimeout()
{
	std::stringstream ss;
	for (int i=0; i<MAX_CLIENT; i++)
	{
		if (player[i].getConnected())
		{
			player[i].incTimeout();
			// if communication timout
			if (player[i].getTimeout() > netNS::MAX_ERRORS)
			{
				player[i].setActive(false);
				ss << "***** Player " << i << " disconnected. *****";
				AnnDebug() << ss.str();
			}
		}
	}
}

void NetworkServer::doClientCommunication()
{
	int playN;
	int size;
	prepareDataForClient();
	for (int i=0; i<MAX_CLIENT; i++)
	{
		size = sizeof(toServerData);
		if(net.readData((char*) &toServerData, size, remoteIP, port) == netNS::NET_OK)
		{
					AnnDebug() << "Got " << size << " bytes from the network";
			if(size > 0)
			{
				/*AnnDebug() << "there are things here...";
				//AnnDebug() << (char*) &toServerData;
				AnnDebug() << "player n : " << toServerData.playerN;
				AnnDebug() << "x " << toServerData.x;
				AnnDebug() << "y " << toServerData.y;
				AnnDebug() << "z " << toServerData.z;*/
				playN = toServerData.playerN;
				if (playN == 255)
				{
					clientWantToJoin();
				}
				else
				{
					AnnDebug() << "got this : " << toServerData.ClientPaddlePos;
					if (player[playN].getConnected())
					{
						if (player[playN].getActive());
							//player[playN].setButtons(toServerData.buttons);
						size = sizeof(toClientData);
						// send player the latest game data
						net.sendData((char*) &toClientData, size, player[i].getNetIP(), port);
						player[playN].setTimeout(0);
						player[playN].setCommWarnings(0);
					}
				}
			}
		}
		else    // No more incomming data ? break !!
		{
			break;
		}
	}
}

void NetworkServer::prepareDataForClient()
{
	/*for (int i=0; i<MAX_CLIENT; i++)
	{
		toClientData.player[i].playerData = player[i].getNetData();
	}*/

	//toClientData.puckPosition = AnnVect3(5,5,5);
	//toClientData.serverPaddlePos = AnnVect3(10, 10, 10);
	toClientData.postition = AnnVect3(3,2,1);
}

//========================================================================
// Client is requesting to join game
//========================================================================

void NetworkServer::clientWantToJoin()
{
	std::stringstream ss;
	int size;
	int status;
	connectResponse.number = 255;
	if (playerCount == 0)
	{
		roundOver = true; // this needs to reset the game states !! I don't know how :/
		// score system goes here (TODO)
	}
	AnnDebug() << "Player requesting to join.";
	// find available player position to use
	for(int i=0; i<MAX_CLIENT; i++) // search all player position
	{
		if (player[i].getConnected() == false) // if this position available
		{
			player[i].setConnected(true);
			player[i].setTimeout(0);
			player[i].setCommWarnings(0);
			player[i].setNetIP(remoteIP); // save player's IP
			player[i].setCommErrors(0); // clear old errors
			// send SERVER_ID adn player number to client
			strcpy_s(connectResponse.response, netNS::SERVER_ID);
			connectResponse.number = (UCHAR)i;
			size = sizeof(connectResponse);
			status = net.sendData((char*) &connectResponse, size, remoteIP, port);
			if (status == netNS::NET_ERROR)
			{
				AnnDebug() << net.getError(status); // display error
				return;
			}
			toServerData.playerN = i; // clear join request from
									 //  input buffer
			ss << "Connected player as number: " << i;
			AnnDebug() << ss.str(); // found available player
			return;
		}
	}
	// send SERVER_FULL to client
	strcpy_s(connectResponse.response, netNS::SERVER_FULL);
	size = sizeof(connectResponse);
	status = net.sendData((char*)&connectResponse, size, remoteIP, port);
	AnnDebug() << "server full.";
}

void NetworkServer::update()
{
	countDownTimer = COUNT_DOWN;
    countDownOn = true;
    roundOver = false;

	// set the state to indicate new round
    toClientData.gameState |= ROUND_START_BIT;

	float frameTime = AnnEngine::Instance()->getTimeFromStartUp();
	communicate(frameTime);
}

<commit_msg>server side of sync test<commit_after>#include "stdafx.h"
#include "NetworkServer.hpp"

NetworkWorker* NetworkWorker::singleton = nullptr;
NetworkWorker::NetworkWorker()
{
	if(singleton) exit(-1);
	singleton = this;
}

AnnVect3 NetworkWorker::getDistantPosition()
{
	return distantPosition;
}

void NetworkWorker::setLocalPositon(AnnVect3 position)
{
	localPosiion = position;
}

NetworkServer::NetworkServer() : NetworkWorker(),
	port(ANVPORT)
{
	//Singleton check

	myType = SERVER;

}

NetworkWorker* NetworkWorker::getSingleton()
{
	return singleton;
}

workerType NetworkWorker::getType()
{
	return myType;
}

int NetworkServer::initialize(int port)
{
	std::stringstream ss;
	if(port < netNS::MIN_PORT)
	{
		AnnDebug() << "Invalid port number";
		return netNS::NET_ERROR;
	}
	// ------ init network stuff -------
	error = net.createServer(port, netNS::UDP);
	if(error != netNS::NET_OK)
	{
		AnnDebug() << net.getError(error);
		return netNS::NET_ERROR;
	}

	for (int i=0; i<MAX_CLIENT; i++)
	{
		player[i].setConnected(false);
		player[i].setActive(false);
	}

	AnnDebug() << "---- Server ----";
	net.getLocalIP(localIP);
	ss << "Server IP: " << localIP;
	AnnDebug() << ss.str();
	ss.str("");
	ss << "Port: " << port;
	AnnDebug() << ss.str();
	return netNS::NET_OK;
}

// --- Do network communications ---
void NetworkServer::communicate(float frameTime)
{
	// communicate with client
	doClientCommunication();
	// Calculate elapsed time for network communications
	netTime += frameTime;
	if(netTime < netNS::NET_TIMER)
		return;

	netTime -= netNS::NET_TIMER;
	// check for inactive clients, called every NET_TIMER seconds
	checkNetworkTimeout();
}

// --- Check for network timeout ---

void NetworkServer::checkNetworkTimeout()
{
	std::stringstream ss;
	for (int i=0; i<MAX_CLIENT; i++)
	{
		if (player[i].getConnected())
		{
			player[i].incTimeout();
			// if communication timout
			if (player[i].getTimeout() > netNS::MAX_ERRORS)
			{
				player[i].setActive(false);
				ss << "***** Player " << i << " disconnected. *****";
				AnnDebug() << ss.str();
			}
		}
	}
}

void NetworkServer::doClientCommunication()
{
	int playN;
	int size;
	prepareDataForClient();
	for (int i=0; i<MAX_CLIENT; i++)
	{
		size = sizeof(toServerData);
		if(net.readData((char*) &toServerData, size, remoteIP, port) == netNS::NET_OK)
		{
					AnnDebug() << "Got " << size << " bytes from the network";
			if(size > 0)
			{
				/*AnnDebug() << "there are things here...";
				//AnnDebug() << (char*) &toServerData;
				AnnDebug() << "player n : " << toServerData.playerN;
				AnnDebug() << "x " << toServerData.x;
				AnnDebug() << "y " << toServerData.y;
				AnnDebug() << "z " << toServerData.z;*/
				playN = toServerData.playerN;
				if (playN == 255)
				{
					clientWantToJoin();
				}
				else
				{
					AnnDebug() << "got this : " << toServerData.ClientPaddlePos;
					distantPosition = toServerData.ClientPaddlePos;
					if (player[playN].getConnected())
					{
						if (player[playN].getActive());
							//player[playN].setButtons(toServerData.buttons);
						size = sizeof(toClientData);
						// send player the latest game data
						net.sendData((char*) &toClientData, size, player[i].getNetIP(), port);
						player[playN].setTimeout(0);
						player[playN].setCommWarnings(0);
					}
				}
			}
		}
		else    // No more incomming data ? break !!
		{
			break;
		}
	}
}

void NetworkServer::prepareDataForClient()
{
	/*for (int i=0; i<MAX_CLIENT; i++)
	{
		toClientData.player[i].playerData = player[i].getNetData();
	}*/

	//toClientData.puckPosition = AnnVect3(5,5,5);
	//toClientData.serverPaddlePos = AnnVect3(10, 10, 10);
	toClientData.postition = localPosiion;
}

//========================================================================
// Client is requesting to join game
//========================================================================

void NetworkServer::clientWantToJoin()
{
	std::stringstream ss;
	int size;
	int status;
	connectResponse.number = 255;
	if (playerCount == 0)
	{
		roundOver = true; // this needs to reset the game states !! I don't know how :/
		// score system goes here (TODO)
	}
	AnnDebug() << "Player requesting to join.";
	// find available player position to use
	for(int i=0; i<MAX_CLIENT; i++) // search all player position
	{
		if (player[i].getConnected() == false) // if this position available
		{
			player[i].setConnected(true);
			player[i].setTimeout(0);
			player[i].setCommWarnings(0);
			player[i].setNetIP(remoteIP); // save player's IP
			player[i].setCommErrors(0); // clear old errors
			// send SERVER_ID adn player number to client
			strcpy_s(connectResponse.response, netNS::SERVER_ID);
			connectResponse.number = (UCHAR)i;
			size = sizeof(connectResponse);
			status = net.sendData((char*) &connectResponse, size, remoteIP, port);
			if (status == netNS::NET_ERROR)
			{
				AnnDebug() << net.getError(status); // display error
				return;
			}
			toServerData.playerN = i; // clear join request from
									 //  input buffer
			ss << "Connected player as number: " << i;
			AnnDebug() << ss.str(); // found available player
			return;
		}
	}
	// send SERVER_FULL to client
	strcpy_s(connectResponse.response, netNS::SERVER_FULL);
	size = sizeof(connectResponse);
	status = net.sendData((char*)&connectResponse, size, remoteIP, port);
	AnnDebug() << "server full.";
}

void NetworkServer::update()
{
	countDownTimer = COUNT_DOWN;
    countDownOn = true;
    roundOver = false;

	// set the state to indicate new round
    toClientData.gameState |= ROUND_START_BIT;

	float frameTime = AnnEngine::Instance()->getTimeFromStartUp();
	communicate(frameTime);
}

<|endoftext|>


<commit_before><commit_msg>we need to copy the formula cell as well<commit_after><|endoftext|>


<commit_before><commit_msg>Another Windows build fix - too much C++11 for MSVC 2012...<commit_after><|endoftext|>


<commit_before>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
 *
 * The contents of this file are subject to the Mozilla Public 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.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Initial Developer of the Original Code is
 *       Novell Inc.
 * Portions created by the Initial Developer are Copyright (C) 2010 the
 * Initial Developer. All Rights Reserved.
 *
 * Contributor(s): Amelia Wang <amwang@novell.com>
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
 * instead of those above.
 */

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

#undef SC_DLLIMPLEMENTATION

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

#include "datafdlg.hxx"
#include "scresid.hxx"
#include "datafdlg.hrc"
#include "viewdata.hxx"
//#include "document.hxx"
#include "docsh.hxx"
#include "refundo.hxx"
#include "undodat.hxx"

#define HDL(hdl)            LINK( this, ScDataFormDlg, hdl )

//zhangyun
ScDataFormDlg::ScDataFormDlg( Window* pParent, ScTabViewShell*  pTabViewShellOri) :
    ModalDialog     ( pParent, ScResId( RID_SCDLG_DATAFORM ) ),
    //
    aBtnNew          ( this, ScResId( BTN_DATAFORM_NEW ) ),
    aBtnDelete          ( this, ScResId( BTN_DATAFORM_DELETE ) ),
    aBtnRestore          ( this, ScResId( BTN_DATAFORM_RESTORE ) ),
    aBtnLast          ( this, ScResId( BTN_DATAFORM_LAST ) ),
    aBtnNext          ( this, ScResId( BTN_DATAFORM_NEXT ) ),
    aBtnClose          ( this, ScResId( BTN_DATAFORM_CLOSE ) ),
    aSlider         ( this, ScResId( WND_DATAFORM_SCROLLBAR ) ),
    aFixedText          ( this, ScResId( LAB_DATAFORM_RECORDNO ) )
{
    pTabViewShell = pTabViewShellOri;
    FreeResource();
    //read header form current document, and add new controls
    DBG_ASSERT( pTabViewShell, "pTabViewShell is NULL! :-/" );
    ScViewData* pViewData = pTabViewShell->GetViewData();

    pDoc = pViewData->GetDocument();
    if (pDoc)
    {
        ScRange aRange;
        pViewData->GetSimpleArea( aRange );
        ScAddress aStart = aRange.aStart;
        ScAddress aEnd = aRange.aEnd;

        nStartCol = aStart.Col();
        nEndCol = aEnd.Col();
        nStartRow   = aStart.Row();
        nEndRow = aEnd.Row();

        nTab = pViewData->GetTabNo();
        //if there is no selection
        if ((nStartCol == nEndCol) && (nStartRow == nEndRow))
            bNoSelection = TRUE;

        if (bNoSelection)
        {
            //find last not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_COLS;i++)
            {
                String  aColName;
                nEndCol++;
                pDoc->GetString( nEndCol, nStartRow, nTab, aColName );
                int nColWidth = pDoc->GetColWidth( nEndCol, nTab );
                if ( aColName.Len() == 0 && nColWidth)
                {
                    nEndCol--;
                    break;
                }
            }

            //find first not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_COLS;i++)
            {
                String  aColName;
                if (nStartCol <= 0)
                    break;
                nStartCol--;

                pDoc->GetString( nStartCol, nStartRow, nTab, aColName );
                int nColWidth = pDoc->GetColWidth( nEndCol, nTab );
                if ( aColName.Len() == 0 && nColWidth)
                {
                    nStartCol++;
                    break;
                }
            }

            //skip leading hide column
            for (int i=1;i<=MAX_DATAFORM_COLS;i++)
            {
                String  aColName;
                int nColWidth = pDoc->GetColWidth( nStartCol, nTab );
                if (nColWidth)
                    break;
                nStartCol++;
            }

            if (nEndCol < nStartCol)
                nEndCol = nStartCol;

            //find last not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_ROWS;i++)
            {
                String  aColName;
                nEndRow++;
                pDoc->GetString( nStartCol, nEndRow, nTab, aColName );
                if ( aColName.Len() == 0 )
                {
                    nEndRow--;
                    break;
                }
            }

            //find first not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_ROWS;i++)
            {
                String  aColName;
                if (nStartRow <= 0)
                    break;
                nStartRow--;

                pDoc->GetString( nStartCol, nStartRow, nTab, aColName );
                if ( aColName.Len() == 0 )
                {
                    nStartRow++;
                    break;
                }
            }

            if (nEndRow < nStartRow)
                nEndRow = nStartRow;
        }

        aCurrentRow = nStartRow + 1;

        String  aFieldName;

        int nTop = 12;

        Size    nFixedSize(FIXED_WIDTH, CTRL_HEIGHT );
        Size    nEditSize(EDIT_WIDTH, CTRL_HEIGHT );

        //pFtArray = new FixedText(this);
        aColLength = nEndCol - nStartCol + 1;

        //new the controls
        pFixedTexts = new FixedText*[aColLength];
        pEdits = new Edit*[aColLength];

        for(sal_uInt16 nIndex = 0; nIndex < aColLength; nIndex++)
        {
            pDoc->GetString( nIndex + nStartCol, nStartRow, nTab, aFieldName );
            int nColWidth = pDoc->GetColWidth( nIndex + nStartCol, nTab );
            if (nColWidth)
            {
                pFixedTexts[nIndex] = new FixedText(this);
                pEdits[nIndex] = new Edit(this, WB_BORDER);

                pFixedTexts[nIndex]->SetSizePixel(nFixedSize);
                pEdits[nIndex]->SetSizePixel(nEditSize);
                pFixedTexts[nIndex]->SetPosPixel(Point(FIXED_LEFT, nTop));
                pEdits[nIndex]->SetPosPixel(Point(EDIT_LEFT, nTop));
                //pFixedTexts[nIndex]->SetText(String::CreateFromAscii("W4W-Filter Nr. "));
                pFixedTexts[nIndex]->SetText(aFieldName);
                pFixedTexts[nIndex]->Show();
                pEdits[nIndex]->Show();

                nTop += LINE_HEIGHT;
            }
            else
            {
                pFixedTexts[nIndex] = NULL;
                pEdits[nIndex] = NULL;
            }
        pEdits[nIndex]->SetModifyHdl( HDL(Impl_DataModifyHdl) );
        }

        Size nDialogSize = this->GetSizePixel();
        if (nTop > nDialogSize.Height())
        {
            nDialogSize.setHeight(nTop);
            this->SetSizePixel(nDialogSize);
        }
        Size nScrollSize = aSlider.GetSizePixel();
        nScrollSize.setHeight(nDialogSize.Height()-20);
        aSlider.SetSizePixel(nScrollSize);
    }

    FillCtrls(aCurrentRow);

    aSlider.SetPageSize( 10 );
    aSlider.SetVisibleSize( 1 );
    aSlider.SetLineSize( 1 );
    aSlider.SetRange( Range( 0, nEndRow - nStartRow + 1) );
    aSlider.Show();

    aBtnNew.SetClickHdl     ( HDL(Impl_NewHdl)    );
    aBtnLast.SetClickHdl    ( HDL(Impl_LastHdl)    );
    aBtnNext.SetClickHdl    ( HDL(Impl_NextHdl)    );

    aBtnRestore.SetClickHdl     ( HDL(Impl_RestoreHdl)    );
    aBtnDelete.SetClickHdl  ( HDL(Impl_DeleteHdl)    );
    aBtnClose.SetClickHdl   ( HDL(Impl_CloseHdl)    );

    aSlider.SetEndScrollHdl( HDL( Impl_ScrollHdl ) );

    SetButtonState();

    //end
    //FreeResource();
}

ScDataFormDlg::~ScDataFormDlg()
{
    for(sal_uInt16 i = 0; i < aColLength; i++)
    {
        if (pEdits[i])
            delete pEdits[i];
        if (pFixedTexts[i])
            delete pFixedTexts[i];
    }
    if (pEdits)
        delete pEdits;
    if (pFixedTexts)
        delete pFixedTexts;
}

void ScDataFormDlg::FillCtrls(SCROW /*nCurrentRow*/)
{
    //ScViewData*   pViewData = pTabViewShell->GetViewData();

    String  aFieldName;
    for (sal_uInt16 i = 0; i < aColLength; ++i)
    {
        if (pEdits[i])
        {
            if (aCurrentRow<=nEndRow)
            {
                pDoc->GetString( i + nStartCol, aCurrentRow, nTab, aFieldName );
                pEdits[i]->SetText(aFieldName);
            }
            else
                pEdits[i]->SetText(String());
        }
    }
    char sRecordStr[256];
    if (aCurrentRow<=nEndRow)
        aFixedText.SetText(String::CreateFromAscii(sRecordStr));
    else
        aFixedText.SetText(String::CreateFromAscii("New Record"));

    aSlider.SetThumbPos(aCurrentRow-nStartRow-1);
}

IMPL_LINK( ScDataFormDlg, Impl_DataModifyHdl, Edit*, pEdit)
{
    if ( pEdit->IsModified() )
        aBtnRestore.Enable( TRUE );
    return 0;
}

IMPL_LINK( ScDataFormDlg, Impl_NewHdl, PushButton*, EMPTYARG )
{
    ScViewData* pViewData = pTabViewShell->GetViewData();
    ScDocShell* pDocSh = pViewData->GetDocShell();
    if ( pDoc )
    {
        sal_Bool bHasData = sal_False;
        for(sal_uInt16 i = 0; i < aColLength; i++)
            if (pEdits[i])
                if ( pEdits[i]->GetText().Len() != 0 )
                {
                    bHasData = sal_True;
                    break;
                }

        if ( bHasData )
        {
            pTabViewShell->DataFormPutData( aCurrentRow , nStartRow , nStartCol , nEndRow , nEndCol , pEdits , aColLength );
            aCurrentRow++;
            if (aCurrentRow >= nEndRow + 2)
            {
                    nEndRow ++ ;
                    aSlider.SetRange( Range( 0, nEndRow - nStartRow + 1) );
            }
            SetButtonState();
            FillCtrls(aCurrentRow);
            pDocSh->SetDocumentModified();
            pDocSh->PostPaintGridAll();
            }
    }
    return 0;
}

IMPL_LINK( ScDataFormDlg, Impl_LastHdl, PushButton*, EMPTYARG )
{
    if (pDoc)
    {
        if ( aCurrentRow > nStartRow +1 )
            aCurrentRow--;

        SetButtonState();
        FillCtrls(aCurrentRow);
    }
    return 0;
}

IMPL_LINK( ScDataFormDlg, Impl_NextHdl, PushButton*, EMPTYARG )
{
    if (pDoc)
    {
        if ( aCurrentRow <= nEndRow)
            aCurrentRow++;

        SetButtonState();
        FillCtrls(aCurrentRow);
    }
    return 0;
}

IMPL_LINK( ScDataFormDlg, Impl_RestoreHdl, PushButton*, EMPTYARG )
{
    if (pDoc)
    {
        FillCtrls(aCurrentRow);
    }
    return 0;
}

IMPL_LINK( ScDataFormDlg, Impl_DeleteHdl, PushButton*, EMPTYARG )
{
    ScViewData* pViewData = pTabViewShell->GetViewData();
    ScDocShell* pDocSh = pViewData->GetDocShell();
    if (pDoc)
    {
        ScRange aRange(nStartCol, aCurrentRow, nTab, nEndCol, aCurrentRow, nTab);
        pDoc->DeleteRow(aRange);
        nEndRow--;

        SetButtonState();
        pDocSh->GetUndoManager()->Clear();

        FillCtrls(aCurrentRow);
        pDocSh->SetDocumentModified();
        pDocSh->PostPaintGridAll();
    }
    return 0;
}

IMPL_LINK( ScDataFormDlg, Impl_CloseHdl, PushButton*, EMPTYARG )
{
    EndDialog( );
    return 0;
}

IMPL_LINK( ScDataFormDlg, Impl_ScrollHdl, ScrollBar*, EMPTYARG )
{
    long nOffset = aSlider.GetThumbPos();
    aCurrentRow = nStartRow + nOffset + 1;
    SetButtonState();
    FillCtrls(aCurrentRow);
    return 0;
}

void ScDataFormDlg::SetButtonState()
{
    if ( aCurrentRow > nEndRow )
    {
        aBtnDelete.Enable( FALSE );
        aBtnLast.Enable( TRUE );
        aBtnNext.Enable( FALSE );
    }
    else
    {
        aBtnDelete.Enable( TRUE );
        aBtnNext.Enable( TRUE );
    }
    if ( 1 == aCurrentRow )
        aBtnLast.Enable( FALSE );

    aBtnRestore.Enable( FALSE );
    if ( pEdits )
        pEdits[0]->GrabFocus();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<commit_msg>Display correct record information in Data Form dialog. (fdo#32196)<commit_after>/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
 *
 * The contents of this file are subject to the Mozilla Public 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.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Initial Developer of the Original Code is
 *       Novell Inc.
 * Portions created by the Initial Developer are Copyright (C) 2010 the
 * Initial Developer. All Rights Reserved.
 *
 * Contributor(s): Amelia Wang <amwang@novell.com>
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
 * instead of those above.
 */

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

#undef SC_DLLIMPLEMENTATION

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

#include "datafdlg.hxx"
#include "scresid.hxx"
#include "datafdlg.hrc"
#include "viewdata.hxx"
//#include "document.hxx"
#include "docsh.hxx"
#include "refundo.hxx"
#include "undodat.hxx"

#include "rtl/ustrbuf.hxx"

#define HDL(hdl)            LINK( this, ScDataFormDlg, hdl )

using ::rtl::OUStringBuffer;

//zhangyun
ScDataFormDlg::ScDataFormDlg( Window* pParent, ScTabViewShell*  pTabViewShellOri) :
    ModalDialog     ( pParent, ScResId( RID_SCDLG_DATAFORM ) ),
    //
    aBtnNew          ( this, ScResId( BTN_DATAFORM_NEW ) ),
    aBtnDelete          ( this, ScResId( BTN_DATAFORM_DELETE ) ),
    aBtnRestore          ( this, ScResId( BTN_DATAFORM_RESTORE ) ),
    aBtnLast          ( this, ScResId( BTN_DATAFORM_LAST ) ),
    aBtnNext          ( this, ScResId( BTN_DATAFORM_NEXT ) ),
    aBtnClose          ( this, ScResId( BTN_DATAFORM_CLOSE ) ),
    aSlider         ( this, ScResId( WND_DATAFORM_SCROLLBAR ) ),
    aFixedText          ( this, ScResId( LAB_DATAFORM_RECORDNO ) )
{
    pTabViewShell = pTabViewShellOri;
    FreeResource();
    //read header form current document, and add new controls
    DBG_ASSERT( pTabViewShell, "pTabViewShell is NULL! :-/" );
    ScViewData* pViewData = pTabViewShell->GetViewData();

    pDoc = pViewData->GetDocument();
    if (pDoc)
    {
        ScRange aRange;
        pViewData->GetSimpleArea( aRange );
        ScAddress aStart = aRange.aStart;
        ScAddress aEnd = aRange.aEnd;

        nStartCol = aStart.Col();
        nEndCol = aEnd.Col();
        nStartRow   = aStart.Row();
        nEndRow = aEnd.Row();

        nTab = pViewData->GetTabNo();
        //if there is no selection
        if ((nStartCol == nEndCol) && (nStartRow == nEndRow))
            bNoSelection = TRUE;

        if (bNoSelection)
        {
            //find last not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_COLS;i++)
            {
                String  aColName;
                nEndCol++;
                pDoc->GetString( nEndCol, nStartRow, nTab, aColName );
                int nColWidth = pDoc->GetColWidth( nEndCol, nTab );
                if ( aColName.Len() == 0 && nColWidth)
                {
                    nEndCol--;
                    break;
                }
            }

            //find first not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_COLS;i++)
            {
                String  aColName;
                if (nStartCol <= 0)
                    break;
                nStartCol--;

                pDoc->GetString( nStartCol, nStartRow, nTab, aColName );
                int nColWidth = pDoc->GetColWidth( nEndCol, nTab );
                if ( aColName.Len() == 0 && nColWidth)
                {
                    nStartCol++;
                    break;
                }
            }

            //skip leading hide column
            for (int i=1;i<=MAX_DATAFORM_COLS;i++)
            {
                String  aColName;
                int nColWidth = pDoc->GetColWidth( nStartCol, nTab );
                if (nColWidth)
                    break;
                nStartCol++;
            }

            if (nEndCol < nStartCol)
                nEndCol = nStartCol;

            //find last not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_ROWS;i++)
            {
                String  aColName;
                nEndRow++;
                pDoc->GetString( nStartCol, nEndRow, nTab, aColName );
                if ( aColName.Len() == 0 )
                {
                    nEndRow--;
                    break;
                }
            }

            //find first not blank cell in row
            for (int i=1;i<=MAX_DATAFORM_ROWS;i++)
            {
                String  aColName;
                if (nStartRow <= 0)
                    break;
                nStartRow--;

                pDoc->GetString( nStartCol, nStartRow, nTab, aColName );
                if ( aColName.Len() == 0 )
                {
                    nStartRow++;
                    break;
                }
            }

            if (nEndRow < nStartRow)
                nEndRow = nStartRow;
        }

        aCurrentRow = nStartRow + 1;

        String  aFieldName;

        int nTop = 12;

        Size    nFixedSize(FIXED_WIDTH, CTRL_HEIGHT );
        Size    nEditSize(EDIT_WIDTH, CTRL_HEIGHT );

        //pFtArray = new FixedText(this);
        aColLength = nEndCol - nStartCol + 1;

        //new the controls
        pFixedTexts = new FixedText*[aColLength];
        pEdits = new Edit*[aColLength];

        for(sal_uInt16 nIndex = 0; nIndex < aColLength; nIndex++)
        {
            pDoc->GetString( nIndex + nStartCol, nStartRow, nTab, aFieldName );
            int nColWidth = pDoc->GetColWidth( nIndex + nStartCol, nTab );
            if (nColWidth)
            {
                pFixedTexts[nIndex] = new FixedText(this);
                pEdits[nIndex] = new Edit(this, WB_BORDER);

                pFixedTexts[nIndex]->SetSizePixel(nFixedSize);
                pEdits[nIndex]->SetSizePixel(nEditSize);
                pFixedTexts[nIndex]->SetPosPixel(Point(FIXED_LEFT, nTop));
                pEdits[nIndex]->SetPosPixel(Point(EDIT_LEFT, nTop));
                //pFixedTexts[nIndex]->SetText(String::CreateFromAscii("W4W-Filter Nr. "));
                pFixedTexts[nIndex]->SetText(aFieldName);
                pFixedTexts[nIndex]->Show();
                pEdits[nIndex]->Show();

                nTop += LINE_HEIGHT;
            }
            else
            {
                pFixedTexts[nIndex] = NULL;
                pEdits[nIndex] = NULL;
            }
        pEdits[nIndex]->SetModifyHdl( HDL(Impl_DataModifyHdl) );
        }

        Size nDialogSize = this->GetSizePixel();
        if (nTop > nDialogSize.Height())
        {
            nDialogSize.setHeight(nTop);
            this->SetSizePixel(nDialogSize);
        }
        Size nScrollSize = aSlider.GetSizePixel();
        nScrollSize.setHeight(nDialogSize.Height()-20);
        aSlider.SetSizePixel(nScrollSize);
    }

    FillCtrls(aCurrentRow);

    aSlider.SetPageSize( 10 );
    aSlider.SetVisibleSize( 1 );
    aSlider.SetLineSize( 1 );
    aSlider.SetRange( Range( 0, nEndRow - nStartRow + 1) );
    aSlider.Show();

    aBtnNew.SetClickHdl     ( HDL(Impl_NewHdl)    );
    aBtnLast.SetClickHdl    ( HDL(Impl_LastHdl)    );
    aBtnNext.SetClickHdl    ( HDL(Impl_NextHdl)    );

    aBtnRestore.SetClickHdl     ( HDL(Impl_RestoreHdl)    );
    aBtnDelete.SetClickHdl  ( HDL(Impl_DeleteHdl)    );
    aBtnClose.SetClickHdl   ( HDL(Impl_CloseHdl)    );

    aSlider.SetEndScrollHdl( HDL( Impl_ScrollHdl ) );

    SetButtonState();

    //end
    //FreeResource();
}

ScDataFormDlg::~ScDataFormDlg()
{
    for(sal_uInt16 i = 0; i < aColLength; i++)
    {
        if (pEdits[i])
            delete pEdits[i];
        if (pFixedTexts[i])
            delete pFixedTexts[i];
    }
    if (pEdits)
        delete pEdits;
    if (pFixedTexts)
        delete pFixedTexts;
}

void ScDataFormDlg::FillCtrls(SCROW /*nCurrentRow*/)
{
    //ScViewData*   pViewData = pTabViewShell->GetViewData();

    String  aFieldName;
    for (sal_uInt16 i = 0; i < aColLength; ++i)
    {
        if (pEdits[i])
        {
            if (aCurrentRow<=nEndRow)
            {
                pDoc->GetString( i + nStartCol, aCurrentRow, nTab, aFieldName );
                pEdits[i]->SetText(aFieldName);
            }
            else
                pEdits[i]->SetText(String());
        }
    }

    if (aCurrentRow <= nEndRow)
    {
        OUStringBuffer aBuf;
        aBuf.append(static_cast<sal_Int32>(aCurrentRow - nStartRow));
        aBuf.appendAscii(" / ");
        aBuf.append(static_cast<sal_Int32>(nEndRow - nStartRow));
        aFixedText.SetText(aBuf.makeStringAndClear());
    }
    else
        aFixedText.SetText(String::CreateFromAscii("New Record"));

    aSlider.SetThumbPos(aCurrentRow-nStartRow-1);
}

IMPL_LINK( ScDataFormDlg, Impl_DataModifyHdl, Edit*, pEdit)
{
    if ( pEdit->IsModified() )
        aBtnRestore.Enable( TRUE );
    return 0;
}

IMPL_LINK( ScDataFormDlg, Impl_NewHdl, PushButton*, EMPTYARG )
{
    ScViewData* pViewData = pTabViewShell->GetViewData();
    ScDocShell* pDocSh = pViewData->GetDocShell();
    if ( pDoc )
    {
        sal_Bool bHasData = sal_False;
        for(sal_uInt16 i = 0; i < aColLength; i++)
            if (pEdits[i])
                if ( pEdits[i]->GetText().Len() != 0 )
                {
                    bHasData = sal_True;
                    break;
                }

        if ( bHasData )
        {
            pTabViewShell->DataFormPutData( aCurrentRow , nStartRow , nStartCol , nEndRow , nEndCol , pEdits , aColLength );
            aCurrentRow++;
            if (aCurrentRow >= nEndRow + 2)
            {
                    nEndRow ++ ;
                    aSlider.SetRange( Range( 0, nEndRow - nStartRow + 1) );
            }
            SetButtonState();
            FillCtrls(aCurrentRow);
            pDocSh->SetDocumentModified();
            pDocSh->PostPaintGridAll();
            }
    }
    return 0;
}

IMPL_LINK( ScDataFormDlg, Impl_LastHdl, PushButton*, EMPTYARG )
{
    if (pDoc)
    {
        if ( aCurrentRow > nStartRow +1 )
            aCurrentRow--;

        SetButtonState();
        FillCtrls(aCurrentRow);
    }
    return 0;
}

IMPL_LINK( ScDataFormDlg, Impl_NextHdl, PushButton*, EMPTYARG )
{
    if (pDoc)
    {
        if ( aCurrentRow <= nEndRow)
            aCurrentRow++;

        SetButtonState();
        FillCtrls(aCurrentRow);
    }
    return 0;
}

IMPL_LINK( ScDataFormDlg, Impl_RestoreHdl, PushButton*, EMPTYARG )
{
    if (pDoc)
    {
        FillCtrls(aCurrentRow);
    }
    return 0;
}

IMPL_LINK( ScDataFormDlg, Impl_DeleteHdl, PushButton*, EMPTYARG )
{
    ScViewData* pViewData = pTabViewShell->GetViewData();
    ScDocShell* pDocSh = pViewData->GetDocShell();
    if (pDoc)
    {
        ScRange aRange(nStartCol, aCurrentRow, nTab, nEndCol, aCurrentRow, nTab);
        pDoc->DeleteRow(aRange);
        nEndRow--;

        SetButtonState();
        pDocSh->GetUndoManager()->Clear();

        FillCtrls(aCurrentRow);
        pDocSh->SetDocumentModified();
        pDocSh->PostPaintGridAll();
    }
    return 0;
}

IMPL_LINK( ScDataFormDlg, Impl_CloseHdl, PushButton*, EMPTYARG )
{
    EndDialog( );
    return 0;
}

IMPL_LINK( ScDataFormDlg, Impl_ScrollHdl, ScrollBar*, EMPTYARG )
{
    long nOffset = aSlider.GetThumbPos();
    aCurrentRow = nStartRow + nOffset + 1;
    SetButtonState();
    FillCtrls(aCurrentRow);
    return 0;
}

void ScDataFormDlg::SetButtonState()
{
    if ( aCurrentRow > nEndRow )
    {
        aBtnDelete.Enable( FALSE );
        aBtnLast.Enable( TRUE );
        aBtnNext.Enable( FALSE );
    }
    else
    {
        aBtnDelete.Enable( TRUE );
        aBtnNext.Enable( TRUE );
    }
    if ( 1 == aCurrentRow )
        aBtnLast.Enable( FALSE );

    aBtnRestore.Enable( FALSE );
    if ( pEdits )
        pEdits[0]->GrabFocus();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: inscodlg.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: kz $ $Date: 2006-07-21 14:06: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_sc.hxx"

#undef SC_DLLIMPLEMENTATION

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

#include "inscodlg.hxx"
#include "scresid.hxx"
#include "miscdlgs.hrc"

//==================================================================

BOOL   ScInsertContentsDlg::bPreviousAllCheck = TRUE;
USHORT ScInsertContentsDlg::nPreviousChecks   = (IDF_DATETIME | IDF_STRING  |
                                                 IDF_NOTE     | IDF_FORMULA |
                                                 IDF_ATTRIB   | IDF_OBJECTS);
USHORT ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_NOFUNC;
USHORT ScInsertContentsDlg::nPreviousChecks2 = 0;
USHORT ScInsertContentsDlg::nPreviousMoveMode = INS_NONE;   // enum InsCellCmd

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

ScInsertContentsDlg::ScInsertContentsDlg( Window*       pParent,
                                          USHORT        nCheckDefaults,
                                          const String* pStrTitle )

 :  ModalDialog     ( pParent, ScResId( RID_SCDLG_INSCONT ) ),
    //
    aBtnOk          ( this, ScResId( BTN_OK ) ),
    aBtnCancel      ( this, ScResId( BTN_CANCEL ) ),
    aBtnHelp        ( this, ScResId( BTN_HELP ) ),
    aBtnInsAll      ( this, ScResId( BTN_INSALL ) ),
    aBtnInsStrings  ( this, ScResId( BTN_INSSTRINGS ) ),
    aBtnInsNumbers  ( this, ScResId( BTN_INSNUMBERS ) ),
    aBtnInsDateTime ( this, ScResId( BTN_INSDATETIME ) ),
    aBtnInsFormulas ( this, ScResId( BTN_INSFORMULAS ) ),
    aBtnInsNotes    ( this, ScResId( BTN_INSNOTES ) ),
    aBtnInsAttrs    ( this, ScResId( BTN_INSATTRS ) ),
    aBtnInsObjects  ( this, ScResId( BTN_INSOBJECTS ) ),
    aFlFrame        ( this, ScResId( FL_FRAME ) ),
    aBtnSkipEmptyCells( this, ScResId(BTN_SKIP_EMPTY ) ),
    aBtnTranspose   ( this, ScResId( BTN_TRANSPOSE ) ),
    aBtnLink        ( this, ScResId( BTN_LINK ) ),
    aFlOptions      ( this, ScResId( FL_OPTIONS ) ),
    aRbNoOp         ( this, ScResId( BTN_OP_NOOP ) ),
    aRbAdd          ( this, ScResId( BTN_OP_ADD ) ),
    aRbSub          ( this, ScResId( BTN_OP_SUB  ) ),
    aRbMul          ( this, ScResId( BTN_OP_MUL  ) ),
    aRbDiv          ( this, ScResId( BTN_OP_DIV  ) ),
    aFlOperation    ( this, ScResId( FL_OPERATION ) ),
    aRbMoveNone     ( this, ScResId( BTN_MV_NONE ) ),
    aRbMoveDown     ( this, ScResId( BTN_MV_DOWN ) ),
    aRbMoveRight    ( this, ScResId( BTN_MV_RIGHT ) ),
    aFlMove         ( this, ScResId( FL_MOVE ) ),
    aFlSep1         ( this, ScResId( FL_SEP1 ) ),
    aFlSep2         ( this, ScResId( FL_SEP2 ) ),
    bOtherDoc       ( FALSE ),
    bFillMode       ( FALSE ),
    bChangeTrack    ( FALSE ),
    bMoveDownDisabled( FALSE ),
    bMoveRightDisabled( FALSE )
{
    if ( pStrTitle )
        SetText( *pStrTitle );

    if ( nCheckDefaults != 0 )
    {
        ScInsertContentsDlg::nPreviousChecks = nCheckDefaults;
        ScInsertContentsDlg::bPreviousAllCheck = FALSE;
        ScInsertContentsDlg::nPreviousChecks2 = 0;
    }

    aBtnInsAll.Check     ( ScInsertContentsDlg::bPreviousAllCheck );
    aBtnInsStrings.Check ( IS_SET( IDF_STRING,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsNumbers.Check ( IS_SET( IDF_VALUE,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsDateTime.Check( IS_SET( IDF_DATETIME,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsFormulas.Check( IS_SET( IDF_FORMULA,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsNotes.Check   ( IS_SET( IDF_NOTE,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsAttrs.Check   ( IS_SET( IDF_ATTRIB,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsObjects.Check ( IS_SET( IDF_OBJECTS,
                                   ScInsertContentsDlg::nPreviousChecks ) );

    switch( ScInsertContentsDlg::nPreviousFormulaChecks )
    {
        case PASTE_NOFUNC: aRbNoOp.Check(TRUE); break;
        case PASTE_ADD:    aRbAdd.Check(TRUE); break;
        case PASTE_SUB:    aRbSub.Check(TRUE); break;
        case PASTE_MUL:    aRbMul.Check(TRUE); break;
        case PASTE_DIV:    aRbDiv.Check(TRUE); break;
    }

    switch( ScInsertContentsDlg::nPreviousMoveMode )
    {
        case INS_NONE:       aRbMoveNone.Check(TRUE); break;
        case INS_CELLSDOWN:  aRbMoveDown.Check(TRUE); break;
        case INS_CELLSRIGHT: aRbMoveRight.Check(TRUE); break;
    }

    aBtnSkipEmptyCells.Check( ( ScInsertContentsDlg::nPreviousChecks2 & INS_CONT_NOEMPTY ) != 0);
    aBtnTranspose.Check( ( ScInsertContentsDlg::nPreviousChecks2    & INS_CONT_TRANS ) != 0);
    aBtnLink.Check( ( ScInsertContentsDlg::nPreviousChecks2             & INS_CONT_LINK  ) != 0);

    DisableChecks( aBtnInsAll.IsChecked() );

    aFlSep1.SetStyle( aFlSep1.GetStyle() | WB_VERT );
    aFlSep2.SetStyle( aFlSep2.GetStyle() | WB_VERT );

    aBtnInsAll.SetClickHdl( LINK( this, ScInsertContentsDlg, InsAllHdl ) );
    aBtnLink.SetClickHdl( LINK( this, ScInsertContentsDlg, LinkBtnHdl ) );

    //-------------
    FreeResource();
}

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

USHORT ScInsertContentsDlg::GetInsContentsCmdBits() const
{
    ScInsertContentsDlg::nPreviousChecks = 0;

    if ( aBtnInsStrings.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks = IDF_STRING;
    if ( aBtnInsNumbers.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks |= IDF_VALUE;
    if ( aBtnInsDateTime.IsChecked())
        ScInsertContentsDlg::nPreviousChecks |= IDF_DATETIME;
    if ( aBtnInsFormulas.IsChecked())
        ScInsertContentsDlg::nPreviousChecks |= IDF_FORMULA;
    if ( aBtnInsNotes.IsChecked()   )
        ScInsertContentsDlg::nPreviousChecks |= IDF_NOTE;
    if ( aBtnInsAttrs.IsChecked()   )
        ScInsertContentsDlg::nPreviousChecks |= IDF_ATTRIB;
    if ( aBtnInsObjects.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks |= IDF_OBJECTS;

    ScInsertContentsDlg::bPreviousAllCheck = aBtnInsAll.IsChecked();

    return ( (ScInsertContentsDlg::bPreviousAllCheck)
                ? IDF_ALL
                : ScInsertContentsDlg::nPreviousChecks );
}

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

InsCellCmd ScInsertContentsDlg::GetMoveMode()
{
    if ( aRbMoveDown.IsChecked() )
        return INS_CELLSDOWN;
    if ( aRbMoveRight.IsChecked() )
        return INS_CELLSRIGHT;

    return INS_NONE;
}

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

void ScInsertContentsDlg::DisableChecks( BOOL bInsAllChecked )
{
    if ( bInsAllChecked )
    {
        aBtnInsStrings.Disable();
        aBtnInsNumbers.Disable();
        aBtnInsDateTime.Disable();
        aBtnInsFormulas.Disable();
        aBtnInsNotes.Disable();
        aBtnInsAttrs.Disable();
        aBtnInsObjects.Disable();
    }
    else
    {
        aBtnInsStrings.Enable();
        aBtnInsNumbers.Enable();
        aBtnInsDateTime.Enable();
        aBtnInsFormulas.Enable();
        aBtnInsNotes.Enable();
        aBtnInsAttrs.Enable();

        //  "Objects" is disabled for "Fill Tables"
        if ( bFillMode )
            aBtnInsObjects.Disable();
        else
            aBtnInsObjects.Enable();
    }
}

// Link in anderes Dokument -> alles andere disabled

void ScInsertContentsDlg::TestModes()
{
    if ( bOtherDoc && aBtnLink.IsChecked() )
    {
        aBtnSkipEmptyCells.Disable();
        aBtnTranspose.Disable();
        aRbNoOp.Disable();
        aRbAdd.Disable();
        aRbSub.Disable();
        aRbMul.Disable();
        aRbDiv.Disable();
        aFlOperation.Disable();

        aRbMoveNone.Disable();
        aRbMoveDown.Disable();
        aRbMoveRight.Disable();
        aFlMove.Disable();

        aFlFrame.Disable();
        aBtnInsAll.Disable();
        DisableChecks(TRUE);
    }
    else
    {
        aBtnSkipEmptyCells.Enable();
        aBtnTranspose.Enable(!bFillMode);
        aRbNoOp.Enable();
        aRbAdd.Enable();
        aRbSub.Enable();
        aRbMul.Enable();
        aRbDiv.Enable();
        aFlOperation.Enable();

        aRbMoveNone.Enable(!bFillMode && !bChangeTrack && !(bMoveDownDisabled && bMoveRightDisabled));
        aRbMoveDown.Enable(!bFillMode && !bChangeTrack && !bMoveDownDisabled);
        aRbMoveRight.Enable(!bFillMode && !bChangeTrack && !bMoveRightDisabled);
        aFlMove.Enable(!bFillMode && !bChangeTrack && !(bMoveDownDisabled && bMoveRightDisabled));

        aFlFrame.Enable();
        aBtnInsAll.Enable();
        DisableChecks( aBtnInsAll.IsChecked() );
    }
}

void ScInsertContentsDlg::SetOtherDoc( BOOL bSet )
{
    if ( bSet != bOtherDoc )
    {
        bOtherDoc = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(TRUE);
    }
}

void ScInsertContentsDlg::SetFillMode( BOOL bSet )
{
    if ( bSet != bFillMode )
    {
        bFillMode = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(TRUE);
    }
}

void ScInsertContentsDlg::SetChangeTrack( BOOL bSet )
{
    if ( bSet != bChangeTrack )
    {
        bChangeTrack = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(TRUE);
    }
}

void ScInsertContentsDlg::SetCellShiftDisabled( int nDisable )
{
    BOOL bDown = ((nDisable & SC_CELL_SHIFT_DISABLE_DOWN) != 0);
    BOOL bRight = ((nDisable & SC_CELL_SHIFT_DISABLE_RIGHT) != 0);
    if ( bDown != bMoveDownDisabled || bRight != bMoveRightDisabled )
    {
        bMoveDownDisabled = bDown;
        bMoveRightDisabled = bRight;
        TestModes();
        if ( bMoveDownDisabled && aRbMoveDown.IsChecked() )
            aRbMoveNone.Check(TRUE);
        if ( bMoveRightDisabled && aRbMoveRight.IsChecked() )
            aRbMoveNone.Check(TRUE);
    }
}

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

IMPL_LINK( ScInsertContentsDlg, InsAllHdl, void*, EMPTY_ARG )
{
    DisableChecks( aBtnInsAll.IsChecked() );

    return 0;
}

IMPL_LINK( ScInsertContentsDlg, LinkBtnHdl, void*, EMPTY_ARG )
{
    TestModes();

    return 0;
}

__EXPORT ScInsertContentsDlg::~ScInsertContentsDlg()
{
    ScInsertContentsDlg::nPreviousChecks2 = 0;
    if(aBtnSkipEmptyCells.IsChecked())
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_NOEMPTY;
    if( aBtnTranspose.IsChecked())
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_TRANS;
    if( aBtnLink.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_LINK;

    if (!bFillMode)     // im FillMode ist None gecheckt und alle 3 disabled
    {
        if ( aRbMoveNone.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_NONE;
        else if ( aRbMoveDown.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_CELLSDOWN;
        else if ( aRbMoveRight.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_CELLSRIGHT;
    }
}

USHORT  ScInsertContentsDlg::GetFormulaCmdBits() const
{
    ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_NOFUNC;
    if(aRbAdd.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_ADD;
    else if(aRbSub.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_SUB;
    else if(aRbMul.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_MUL;
    else if(aRbDiv.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_DIV;
    // Bits fuer Checkboxen ausblenden
    return ScInsertContentsDlg::nPreviousFormulaChecks;
}

<commit_msg>INTEGRATION: CWS calcwarnings (1.6.110); FILE MERGED 2006/12/12 17:03:17 nn 1.6.110.2: #i69284# warning-free: ui, unxlngi6 2006/12/01 08:53:35 nn 1.6.110.1: #i69284# warning-free: ui, wntmsci10<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: inscodlg.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: vg $ $Date: 2007-02-27 13:31:50 $
 *
 *  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_sc.hxx"

#undef SC_DLLIMPLEMENTATION

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

#include "inscodlg.hxx"
#include "scresid.hxx"
#include "miscdlgs.hrc"

//==================================================================

BOOL   ScInsertContentsDlg::bPreviousAllCheck = TRUE;
USHORT ScInsertContentsDlg::nPreviousChecks   = (IDF_DATETIME | IDF_STRING  |
                                                 IDF_NOTE     | IDF_FORMULA |
                                                 IDF_ATTRIB   | IDF_OBJECTS);
USHORT ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_NOFUNC;
USHORT ScInsertContentsDlg::nPreviousChecks2 = 0;
USHORT ScInsertContentsDlg::nPreviousMoveMode = INS_NONE;   // enum InsCellCmd

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

ScInsertContentsDlg::ScInsertContentsDlg( Window*       pParent,
                                          USHORT        nCheckDefaults,
                                          const String* pStrTitle )

 :  ModalDialog     ( pParent, ScResId( RID_SCDLG_INSCONT ) ),
    //
    aFlFrame        ( this, ScResId( FL_FRAME ) ),
    aBtnInsAll      ( this, ScResId( BTN_INSALL ) ),
    aBtnInsStrings  ( this, ScResId( BTN_INSSTRINGS ) ),
    aBtnInsNumbers  ( this, ScResId( BTN_INSNUMBERS ) ),
    aBtnInsDateTime ( this, ScResId( BTN_INSDATETIME ) ),
    aBtnInsFormulas ( this, ScResId( BTN_INSFORMULAS ) ),
    aBtnInsNotes    ( this, ScResId( BTN_INSNOTES ) ),
    aBtnInsAttrs    ( this, ScResId( BTN_INSATTRS ) ),
    aBtnInsObjects  ( this, ScResId( BTN_INSOBJECTS ) ),
    aFlSep1         ( this, ScResId( FL_SEP1 ) ),
    aFlOptions      ( this, ScResId( FL_OPTIONS ) ),
    aBtnSkipEmptyCells( this, ScResId(BTN_SKIP_EMPTY ) ),
    aBtnTranspose   ( this, ScResId( BTN_TRANSPOSE ) ),
    aBtnLink        ( this, ScResId( BTN_LINK ) ),
    aFlOperation    ( this, ScResId( FL_OPERATION ) ),
    aRbNoOp         ( this, ScResId( BTN_OP_NOOP ) ),
    aRbAdd          ( this, ScResId( BTN_OP_ADD ) ),
    aRbSub          ( this, ScResId( BTN_OP_SUB  ) ),
    aRbMul          ( this, ScResId( BTN_OP_MUL  ) ),
    aRbDiv          ( this, ScResId( BTN_OP_DIV  ) ),
    aFlSep2         ( this, ScResId( FL_SEP2 ) ),
    aFlMove         ( this, ScResId( FL_MOVE ) ),
    aRbMoveNone     ( this, ScResId( BTN_MV_NONE ) ),
    aRbMoveDown     ( this, ScResId( BTN_MV_DOWN ) ),
    aRbMoveRight    ( this, ScResId( BTN_MV_RIGHT ) ),
    aBtnOk          ( this, ScResId( BTN_OK ) ),
    aBtnCancel      ( this, ScResId( BTN_CANCEL ) ),
    aBtnHelp        ( this, ScResId( BTN_HELP ) ),
    bOtherDoc       ( FALSE ),
    bFillMode       ( FALSE ),
    bChangeTrack    ( FALSE ),
    bMoveDownDisabled( FALSE ),
    bMoveRightDisabled( FALSE )
{
    if ( pStrTitle )
        SetText( *pStrTitle );

    if ( nCheckDefaults != 0 )
    {
        ScInsertContentsDlg::nPreviousChecks = nCheckDefaults;
        ScInsertContentsDlg::bPreviousAllCheck = FALSE;
        ScInsertContentsDlg::nPreviousChecks2 = 0;
    }

    aBtnInsAll.Check     ( ScInsertContentsDlg::bPreviousAllCheck );
    aBtnInsStrings.Check ( IS_SET( IDF_STRING,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsNumbers.Check ( IS_SET( IDF_VALUE,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsDateTime.Check( IS_SET( IDF_DATETIME,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsFormulas.Check( IS_SET( IDF_FORMULA,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsNotes.Check   ( IS_SET( IDF_NOTE,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsAttrs.Check   ( IS_SET( IDF_ATTRIB,
                                   ScInsertContentsDlg::nPreviousChecks ) );
    aBtnInsObjects.Check ( IS_SET( IDF_OBJECTS,
                                   ScInsertContentsDlg::nPreviousChecks ) );

    switch( ScInsertContentsDlg::nPreviousFormulaChecks )
    {
        case PASTE_NOFUNC: aRbNoOp.Check(TRUE); break;
        case PASTE_ADD:    aRbAdd.Check(TRUE); break;
        case PASTE_SUB:    aRbSub.Check(TRUE); break;
        case PASTE_MUL:    aRbMul.Check(TRUE); break;
        case PASTE_DIV:    aRbDiv.Check(TRUE); break;
    }

    switch( ScInsertContentsDlg::nPreviousMoveMode )
    {
        case INS_NONE:       aRbMoveNone.Check(TRUE); break;
        case INS_CELLSDOWN:  aRbMoveDown.Check(TRUE); break;
        case INS_CELLSRIGHT: aRbMoveRight.Check(TRUE); break;
    }

    aBtnSkipEmptyCells.Check( ( ScInsertContentsDlg::nPreviousChecks2 & INS_CONT_NOEMPTY ) != 0);
    aBtnTranspose.Check( ( ScInsertContentsDlg::nPreviousChecks2    & INS_CONT_TRANS ) != 0);
    aBtnLink.Check( ( ScInsertContentsDlg::nPreviousChecks2             & INS_CONT_LINK  ) != 0);

    DisableChecks( aBtnInsAll.IsChecked() );

    aFlSep1.SetStyle( aFlSep1.GetStyle() | WB_VERT );
    aFlSep2.SetStyle( aFlSep2.GetStyle() | WB_VERT );

    aBtnInsAll.SetClickHdl( LINK( this, ScInsertContentsDlg, InsAllHdl ) );
    aBtnLink.SetClickHdl( LINK( this, ScInsertContentsDlg, LinkBtnHdl ) );

    //-------------
    FreeResource();
}

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

USHORT ScInsertContentsDlg::GetInsContentsCmdBits() const
{
    ScInsertContentsDlg::nPreviousChecks = 0;

    if ( aBtnInsStrings.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks = IDF_STRING;
    if ( aBtnInsNumbers.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks |= IDF_VALUE;
    if ( aBtnInsDateTime.IsChecked())
        ScInsertContentsDlg::nPreviousChecks |= IDF_DATETIME;
    if ( aBtnInsFormulas.IsChecked())
        ScInsertContentsDlg::nPreviousChecks |= IDF_FORMULA;
    if ( aBtnInsNotes.IsChecked()   )
        ScInsertContentsDlg::nPreviousChecks |= IDF_NOTE;
    if ( aBtnInsAttrs.IsChecked()   )
        ScInsertContentsDlg::nPreviousChecks |= IDF_ATTRIB;
    if ( aBtnInsObjects.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks |= IDF_OBJECTS;

    ScInsertContentsDlg::bPreviousAllCheck = aBtnInsAll.IsChecked();

    return ( (ScInsertContentsDlg::bPreviousAllCheck)
                ? IDF_ALL
                : ScInsertContentsDlg::nPreviousChecks );
}

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

InsCellCmd ScInsertContentsDlg::GetMoveMode()
{
    if ( aRbMoveDown.IsChecked() )
        return INS_CELLSDOWN;
    if ( aRbMoveRight.IsChecked() )
        return INS_CELLSRIGHT;

    return INS_NONE;
}

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

void ScInsertContentsDlg::DisableChecks( BOOL bInsAllChecked )
{
    if ( bInsAllChecked )
    {
        aBtnInsStrings.Disable();
        aBtnInsNumbers.Disable();
        aBtnInsDateTime.Disable();
        aBtnInsFormulas.Disable();
        aBtnInsNotes.Disable();
        aBtnInsAttrs.Disable();
        aBtnInsObjects.Disable();
    }
    else
    {
        aBtnInsStrings.Enable();
        aBtnInsNumbers.Enable();
        aBtnInsDateTime.Enable();
        aBtnInsFormulas.Enable();
        aBtnInsNotes.Enable();
        aBtnInsAttrs.Enable();

        //  "Objects" is disabled for "Fill Tables"
        if ( bFillMode )
            aBtnInsObjects.Disable();
        else
            aBtnInsObjects.Enable();
    }
}

// Link in anderes Dokument -> alles andere disabled

void ScInsertContentsDlg::TestModes()
{
    if ( bOtherDoc && aBtnLink.IsChecked() )
    {
        aBtnSkipEmptyCells.Disable();
        aBtnTranspose.Disable();
        aRbNoOp.Disable();
        aRbAdd.Disable();
        aRbSub.Disable();
        aRbMul.Disable();
        aRbDiv.Disable();
        aFlOperation.Disable();

        aRbMoveNone.Disable();
        aRbMoveDown.Disable();
        aRbMoveRight.Disable();
        aFlMove.Disable();

        aFlFrame.Disable();
        aBtnInsAll.Disable();
        DisableChecks(TRUE);
    }
    else
    {
        aBtnSkipEmptyCells.Enable();
        aBtnTranspose.Enable(!bFillMode);
        aRbNoOp.Enable();
        aRbAdd.Enable();
        aRbSub.Enable();
        aRbMul.Enable();
        aRbDiv.Enable();
        aFlOperation.Enable();

        aRbMoveNone.Enable(!bFillMode && !bChangeTrack && !(bMoveDownDisabled && bMoveRightDisabled));
        aRbMoveDown.Enable(!bFillMode && !bChangeTrack && !bMoveDownDisabled);
        aRbMoveRight.Enable(!bFillMode && !bChangeTrack && !bMoveRightDisabled);
        aFlMove.Enable(!bFillMode && !bChangeTrack && !(bMoveDownDisabled && bMoveRightDisabled));

        aFlFrame.Enable();
        aBtnInsAll.Enable();
        DisableChecks( aBtnInsAll.IsChecked() );
    }
}

void ScInsertContentsDlg::SetOtherDoc( BOOL bSet )
{
    if ( bSet != bOtherDoc )
    {
        bOtherDoc = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(TRUE);
    }
}

void ScInsertContentsDlg::SetFillMode( BOOL bSet )
{
    if ( bSet != bFillMode )
    {
        bFillMode = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(TRUE);
    }
}

void ScInsertContentsDlg::SetChangeTrack( BOOL bSet )
{
    if ( bSet != bChangeTrack )
    {
        bChangeTrack = bSet;
        TestModes();
        if ( bSet )
            aRbMoveNone.Check(TRUE);
    }
}

void ScInsertContentsDlg::SetCellShiftDisabled( int nDisable )
{
    BOOL bDown = ((nDisable & SC_CELL_SHIFT_DISABLE_DOWN) != 0);
    BOOL bRight = ((nDisable & SC_CELL_SHIFT_DISABLE_RIGHT) != 0);
    if ( bDown != bMoveDownDisabled || bRight != bMoveRightDisabled )
    {
        bMoveDownDisabled = bDown;
        bMoveRightDisabled = bRight;
        TestModes();
        if ( bMoveDownDisabled && aRbMoveDown.IsChecked() )
            aRbMoveNone.Check(TRUE);
        if ( bMoveRightDisabled && aRbMoveRight.IsChecked() )
            aRbMoveNone.Check(TRUE);
    }
}

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

IMPL_LINK( ScInsertContentsDlg, InsAllHdl, void*, EMPTYARG )
{
    DisableChecks( aBtnInsAll.IsChecked() );

    return 0;
}

IMPL_LINK( ScInsertContentsDlg, LinkBtnHdl, void*, EMPTYARG )
{
    TestModes();

    return 0;
}

__EXPORT ScInsertContentsDlg::~ScInsertContentsDlg()
{
    ScInsertContentsDlg::nPreviousChecks2 = 0;
    if(aBtnSkipEmptyCells.IsChecked())
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_NOEMPTY;
    if( aBtnTranspose.IsChecked())
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_TRANS;
    if( aBtnLink.IsChecked() )
        ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_LINK;

    if (!bFillMode)     // im FillMode ist None gecheckt und alle 3 disabled
    {
        if ( aRbMoveNone.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_NONE;
        else if ( aRbMoveDown.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_CELLSDOWN;
        else if ( aRbMoveRight.IsChecked() )
            ScInsertContentsDlg::nPreviousMoveMode = INS_CELLSRIGHT;
    }
}

USHORT  ScInsertContentsDlg::GetFormulaCmdBits() const
{
    ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_NOFUNC;
    if(aRbAdd.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_ADD;
    else if(aRbSub.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_SUB;
    else if(aRbMul.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_MUL;
    else if(aRbDiv.IsChecked())
        ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_DIV;
    // Bits fuer Checkboxen ausblenden
    return ScInsertContentsDlg::nPreviousFormulaChecks;
}

<|endoftext|>