<commit_before>/*
 * Copyright (c) 2013 - 2016, Roland Bock
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 *   Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 *
 *   Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "detail/connection_handle.h"
#include "detail/prepared_statement_handle.h"
#include <iostream>
#include <sqlpp11/exception.h>
#include <sqlpp11/sqlite3/connection.h>

#ifdef SQLPP_DYNAMIC_LOADING
#include <sqlpp11/sqlite3/dynamic_libsqlite3.h>
#endif

namespace sqlpp
{
  namespace sqlite3
  {

#ifdef SQLPP_DYNAMIC_LOADING
  using namespace dynamic;
#endif

    namespace
    {
      detail::prepared_statement_handle_t prepare_statement(detail::connection_handle& handle,
                                                            const std::string& statement)
      {
        if (handle.config.debug)
          std::cerr << "Sqlite3 debug: Preparing: '" << statement << "'" << std::endl;

        detail::prepared_statement_handle_t result(nullptr, handle.config.debug);

        auto rc = sqlite3_prepare_v2(handle.sqlite, statement.c_str(), static_cast<int>(statement.size()),
                                     &result.sqlite_statement, nullptr);

        if (rc != SQLITE_OK)
        {
          throw sqlpp::exception("Sqlite3 error: Could not prepare statement: " +
                                 std::string(sqlite3_errmsg(handle.sqlite)) + " (statement was >>" + statement +
                                 "<<\n");
        }

        return result;
      }

      void execute_statement(detail::connection_handle& handle, detail::prepared_statement_handle_t& prepared)
      {
        auto rc = sqlite3_step(prepared.sqlite_statement);
        switch (rc)
        {
          case SQLITE_OK:
          case SQLITE_ROW:  // might occur if execute is called with a select
          case SQLITE_DONE:
            return;
          default:
            std::cerr << "Sqlite3 debug: sqlite3_step return code: " << rc << std::endl;
            throw sqlpp::exception("Sqlite3 error: Could not execute statement: " +
                                   std::string(sqlite3_errmsg(handle.sqlite)));
        }
      }
    }

    connection::connection(connection_config config) : _handle(new detail::connection_handle(std::move(config)))
    {
    }

    connection::~connection()
    {
    }

    ::sqlite3* connection::native_handle()
    {
      return _handle->sqlite;
    }

    bind_result_t connection::select_impl(const std::string& statement)
    {
      std::unique_ptr<detail::prepared_statement_handle_t> prepared(
          new detail::prepared_statement_handle_t(prepare_statement(*_handle, statement)));
      if (!prepared)
      {
        throw sqlpp::exception("Sqlite3 error: Could not store result set");
      }

      return {std::move(prepared)};
    }

    bind_result_t connection::run_prepared_select_impl(prepared_statement_t& prepared_statement)
    {
      return {prepared_statement._handle};
    }

    size_t connection::insert_impl(const std::string& statement)
    {
      auto prepared = prepare_statement(*_handle, statement);
      execute_statement(*_handle, prepared);

      return sqlite3_last_insert_rowid(_handle->sqlite);
    }

    prepared_statement_t connection::prepare_impl(const std::string& statement)
    {
      return {std::unique_ptr<detail::prepared_statement_handle_t>(
          new detail::prepared_statement_handle_t(prepare_statement(*_handle, statement)))};
    }

    size_t connection::run_prepared_insert_impl(prepared_statement_t& prepared_statement)
    {
      execute_statement(*_handle, *prepared_statement._handle.get());

      return sqlite3_last_insert_rowid(_handle->sqlite);
    }

    size_t connection::run_prepared_execute_impl(prepared_statement_t& prepared_statement)
    {
      execute_statement(*_handle, *prepared_statement._handle.get());

      return sqlite3_changes(_handle->sqlite);
    }

    size_t connection::execute(const std::string& statement)
    {
      auto prepared = prepare_statement(*_handle, statement);
      execute_statement(*_handle, prepared);
      return sqlite3_changes(_handle->sqlite);
    }

    size_t connection::update_impl(const std::string& statement)
    {
      auto prepared = prepare_statement(*_handle, statement);
      execute_statement(*_handle, prepared);
      return sqlite3_changes(_handle->sqlite);
    }

    size_t connection::run_prepared_update_impl(prepared_statement_t& prepared_statement)
    {
      execute_statement(*_handle, *prepared_statement._handle.get());

      return sqlite3_changes(_handle->sqlite);
    }

    size_t connection::remove_impl(const std::string& statement)
    {
      auto prepared = prepare_statement(*_handle, statement);
      execute_statement(*_handle, prepared);
      return sqlite3_changes(_handle->sqlite);
    }

    size_t connection::run_prepared_remove_impl(prepared_statement_t& prepared_statement)
    {
      execute_statement(*_handle, *prepared_statement._handle.get());

      return sqlite3_changes(_handle->sqlite);
    }

    std::string connection::escape(const std::string& s) const
    {
      std::string t;
      t.reserve(s.size());

      for (const char c : s)
      {
        if (c == '\'')
          t.push_back(c);
        t.push_back(c);
      }

      return t;
    }

    void connection::start_transaction(isolation_level isolation)
    {
      if (_transaction_active)
      {
        throw sqlpp::exception("Sqlite3 error: Cannot have more than one open transaction per connection");
      }
      if (isolation == sqlpp::isolation_level::undefined)
      {
          // use the current default, nothing to do
      } else if (isolation == sqlpp::isolation_level::read_uncommitted) {
          execute("pragma read_uncommitted = true;");
      } else {
          execute("pragma read_uncommitted = false;");
      }

      auto prepared = prepare_statement(*_handle, "BEGIN");
      execute_statement(*_handle, prepared);
      _transaction_active = true;
    }

    void connection::commit_transaction()
    {
      if (not _transaction_active)
      {
        throw sqlpp::exception("Sqlite3 error: Cannot commit a finished or failed transaction");
      }
      _transaction_active = false;
      auto prepared = prepare_statement(*_handle, "COMMIT");
      execute_statement(*_handle, prepared);
    }

    void connection::rollback_transaction(bool report)
    {
      if (not _transaction_active)
      {
        throw sqlpp::exception("Sqlite3 error: Cannot rollback a finished or failed transaction");
      }
      if (report)
      {
        std::cerr << "Sqlite3 warning: Rolling back unfinished transaction" << std::endl;
      }
      _transaction_active = false;
      auto prepared = prepare_statement(*_handle, "ROLLBACK");
      execute_statement(*_handle, prepared);
    }

    void connection::report_rollback_failure(const std::string message) noexcept
    {
      std::cerr << "Sqlite3 message:" << message << std::endl;
    }

    uint64_t connection::last_insert_id() noexcept
    {
      return sqlite3_last_insert_rowid(_handle->sqlite);
    }

    auto connection::attach(const connection_config& config, const std::string name) -> schema_t
    {
      auto prepared =
          prepare_statement(*_handle, "ATTACH '" + escape(config.path_to_database) + "' AS " + escape(name));
      execute_statement(*_handle, prepared);

      return {name};
    }
  }
}
<commit_msg>Cleaned up ugly start_transaction function a bit<commit_after>/*
 * Copyright (c) 2013 - 2016, Roland Bock
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 *   Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 *
 *   Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "detail/connection_handle.h"
#include "detail/prepared_statement_handle.h"
#include <iostream>
#include <sqlpp11/exception.h>
#include <sqlpp11/sqlite3/connection.h>

#ifdef SQLPP_DYNAMIC_LOADING
#include <sqlpp11/sqlite3/dynamic_libsqlite3.h>
#endif

namespace sqlpp
{
  namespace sqlite3
  {

#ifdef SQLPP_DYNAMIC_LOADING
  using namespace dynamic;
#endif

    namespace
    {
      detail::prepared_statement_handle_t prepare_statement(detail::connection_handle& handle,
                                                            const std::string& statement)
      {
        if (handle.config.debug)
          std::cerr << "Sqlite3 debug: Preparing: '" << statement << "'" << std::endl;

        detail::prepared_statement_handle_t result(nullptr, handle.config.debug);

        auto rc = sqlite3_prepare_v2(handle.sqlite, statement.c_str(), static_cast<int>(statement.size()),
                                     &result.sqlite_statement, nullptr);

        if (rc != SQLITE_OK)
        {
          throw sqlpp::exception("Sqlite3 error: Could not prepare statement: " +
                                 std::string(sqlite3_errmsg(handle.sqlite)) + " (statement was >>" + statement +
                                 "<<\n");
        }

        return result;
      }

      void execute_statement(detail::connection_handle& handle, detail::prepared_statement_handle_t& prepared)
      {
        auto rc = sqlite3_step(prepared.sqlite_statement);
        switch (rc)
        {
          case SQLITE_OK:
          case SQLITE_ROW:  // might occur if execute is called with a select
          case SQLITE_DONE:
            return;
          default:
            std::cerr << "Sqlite3 debug: sqlite3_step return code: " << rc << std::endl;
            throw sqlpp::exception("Sqlite3 error: Could not execute statement: " +
                                   std::string(sqlite3_errmsg(handle.sqlite)));
        }
      }
    }

    connection::connection(connection_config config) : _handle(new detail::connection_handle(std::move(config)))
    {
    }

    connection::~connection()
    {
    }

    ::sqlite3* connection::native_handle()
    {
      return _handle->sqlite;
    }

    bind_result_t connection::select_impl(const std::string& statement)
    {
      std::unique_ptr<detail::prepared_statement_handle_t> prepared(
          new detail::prepared_statement_handle_t(prepare_statement(*_handle, statement)));
      if (!prepared)
      {
        throw sqlpp::exception("Sqlite3 error: Could not store result set");
      }

      return {std::move(prepared)};
    }

    bind_result_t connection::run_prepared_select_impl(prepared_statement_t& prepared_statement)
    {
      return {prepared_statement._handle};
    }

    size_t connection::insert_impl(const std::string& statement)
    {
      auto prepared = prepare_statement(*_handle, statement);
      execute_statement(*_handle, prepared);

      return sqlite3_last_insert_rowid(_handle->sqlite);
    }

    prepared_statement_t connection::prepare_impl(const std::string& statement)
    {
      return {std::unique_ptr<detail::prepared_statement_handle_t>(
          new detail::prepared_statement_handle_t(prepare_statement(*_handle, statement)))};
    }

    size_t connection::run_prepared_insert_impl(prepared_statement_t& prepared_statement)
    {
      execute_statement(*_handle, *prepared_statement._handle.get());

      return sqlite3_last_insert_rowid(_handle->sqlite);
    }

    size_t connection::run_prepared_execute_impl(prepared_statement_t& prepared_statement)
    {
      execute_statement(*_handle, *prepared_statement._handle.get());

      return sqlite3_changes(_handle->sqlite);
    }

    size_t connection::execute(const std::string& statement)
    {
      auto prepared = prepare_statement(*_handle, statement);
      execute_statement(*_handle, prepared);
      return sqlite3_changes(_handle->sqlite);
    }

    size_t connection::update_impl(const std::string& statement)
    {
      auto prepared = prepare_statement(*_handle, statement);
      execute_statement(*_handle, prepared);
      return sqlite3_changes(_handle->sqlite);
    }

    size_t connection::run_prepared_update_impl(prepared_statement_t& prepared_statement)
    {
      execute_statement(*_handle, *prepared_statement._handle.get());

      return sqlite3_changes(_handle->sqlite);
    }

    size_t connection::remove_impl(const std::string& statement)
    {
      auto prepared = prepare_statement(*_handle, statement);
      execute_statement(*_handle, prepared);
      return sqlite3_changes(_handle->sqlite);
    }

    size_t connection::run_prepared_remove_impl(prepared_statement_t& prepared_statement)
    {
      execute_statement(*_handle, *prepared_statement._handle.get());

      return sqlite3_changes(_handle->sqlite);
    }

    std::string connection::escape(const std::string& s) const
    {
      std::string t;
      t.reserve(s.size());

      for (const char c : s)
      {
        if (c == '\'')
          t.push_back(c);
        t.push_back(c);
      }

      return t;
    }

    void connection::start_transaction(isolation_level level)
    {
      if (_transaction_active)
      {
        throw sqlpp::exception("Sqlite3 error: Cannot have more than one open transaction per connection");
      }

      switch (level)
      {
        case sqlpp::isolation_level::serializable:
        case sqlpp::isolation_level::repeatable_read:
        case sqlpp::isolation_level::read_committed:
          execute("pragma read_uncommitted = false;");
          break;
        case sqlpp::isolation_level::read_uncommitted:
          execute("pragma read_uncommitted = true;");
          break;
        case sqlpp::isolation_level::undefined:
          // do nothing here ...
          break;
      }

      auto prepared = prepare_statement(*_handle, "BEGIN");
      execute_statement(*_handle, prepared);
      _transaction_active = true;
    }

    void connection::commit_transaction()
    {
      if (not _transaction_active)
      {
        throw sqlpp::exception("Sqlite3 error: Cannot commit a finished or failed transaction");
      }
      _transaction_active = false;
      auto prepared = prepare_statement(*_handle, "COMMIT");
      execute_statement(*_handle, prepared);
    }

    void connection::rollback_transaction(bool report)
    {
      if (not _transaction_active)
      {
        throw sqlpp::exception("Sqlite3 error: Cannot rollback a finished or failed transaction");
      }
      if (report)
      {
        std::cerr << "Sqlite3 warning: Rolling back unfinished transaction" << std::endl;
      }
      _transaction_active = false;
      auto prepared = prepare_statement(*_handle, "ROLLBACK");
      execute_statement(*_handle, prepared);
    }

    void connection::report_rollback_failure(const std::string message) noexcept
    {
      std::cerr << "Sqlite3 message:" << message << std::endl;
    }

    uint64_t connection::last_insert_id() noexcept
    {
      return sqlite3_last_insert_rowid(_handle->sqlite);
    }

    auto connection::attach(const connection_config& config, const std::string name) -> schema_t
    {
      auto prepared =
          prepare_statement(*_handle, "ATTACH '" + escape(config.path_to_database) + "' AS " + escape(name));
      execute_statement(*_handle, prepared);

      return {name};
    }
  }
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: dlgegif.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-19 21:40:46 $
 *
 *  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 GCC
#pragma hdrstop
#endif
#include <tools/ref.hxx>
#include <svtools/FilterConfigItem.hxx>
#include <vcl/msgbox.hxx>
#include "dlgegif.hxx"
#include "dlgegif.hrc"
#include "strings.hrc"

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

DlgExportEGIF::DlgExportEGIF( FltCallDialogParameter& rPara ) :
                ModalDialog         ( rPara.pWindow, ResId( DLG_EXPORT_GIF, rPara.pResMgr ) ),
                rFltCallPara        ( rPara ),
                aCbxInterlaced      ( this, ResId( CBX_INTERLACED ) ),
                aCbxTranslucent     ( this, ResId( CBX_TRANSLUCENT ) ),
                aGrpMode            ( this, ResId( GRP_MODE ) ),
                aGrpDraw            ( this, ResId( GRP_DRAW ) ),
                aBtnOK              ( this, ResId( BTN_OK ) ),
                aBtnCancel          ( this, ResId( BTN_CANCEL ) ),
                aBtnHelp            ( this, ResId( BTN_HELP ) ),
                pMgr                ( rPara.pResMgr )
{
    FreeResource();

    String  aFilterConfigPath( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/Graphic/Export/GIF" ) );
    pConfigItem = new FilterConfigItem( aFilterConfigPath, &rPara.aFilterData );

    String aInterlaceStr( ResId( KEY_INTER, pMgr ) );
    String aTranslucentStr( ResId( KEY_TRANS, pMgr ) );
    // Config-Parameter lesen
    sal_Bool bInterlaced = pConfigItem->ReadInt32( aInterlaceStr, 1 ) != 0;
    sal_Bool bTranslucent = pConfigItem->ReadInt32( aTranslucentStr, 1 ) != 0;

    aCbxInterlaced.Check( bInterlaced );
    aCbxTranslucent.Check( bTranslucent );

    aBtnOK.SetClickHdl( LINK( this, DlgExportEGIF, OK ) );
}

DlgExportEGIF::~DlgExportEGIF()
{
    delete pConfigItem;
}

/*************************************************************************
|*
|* Speichert eingestellte Werte in ini-Datei
|*
\************************************************************************/

IMPL_LINK( DlgExportEGIF, OK, void *, EMPTYARG )
{

    // Config-Parameter schreiben
    String aInterlaceStr( ResId( KEY_INTER, pMgr ) );
    String aTranslucentStr( ResId( KEY_TRANS, pMgr ) );

    sal_Int32 nValue = 0;
    if ( aCbxInterlaced.IsChecked() )
        nValue++;
    pConfigItem->WriteInt32( aInterlaceStr, nValue );

    nValue = 0;
    if ( aCbxTranslucent.IsChecked() )
        nValue++;
    pConfigItem->WriteInt32( aTranslucentStr, nValue );
    rFltCallPara.aFilterData = pConfigItem->GetFilterData();
    EndDialog( RET_OK );

    return 0;
}

<commit_msg>INTEGRATION: CWS pchfix02 (1.6.28); FILE MERGED 2006/09/01 17:30:02 kaib 1.6.28.1: #i68856# Added header markers and pch files<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: dlgegif.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 15:40:55 $
 *
 *  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_goodies.hxx"
#ifndef GCC
#endif
#include <tools/ref.hxx>
#include <svtools/FilterConfigItem.hxx>
#include <vcl/msgbox.hxx>
#include "dlgegif.hxx"
#include "dlgegif.hrc"
#include "strings.hrc"

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

DlgExportEGIF::DlgExportEGIF( FltCallDialogParameter& rPara ) :
                ModalDialog         ( rPara.pWindow, ResId( DLG_EXPORT_GIF, rPara.pResMgr ) ),
                rFltCallPara        ( rPara ),
                aCbxInterlaced      ( this, ResId( CBX_INTERLACED ) ),
                aCbxTranslucent     ( this, ResId( CBX_TRANSLUCENT ) ),
                aGrpMode            ( this, ResId( GRP_MODE ) ),
                aGrpDraw            ( this, ResId( GRP_DRAW ) ),
                aBtnOK              ( this, ResId( BTN_OK ) ),
                aBtnCancel          ( this, ResId( BTN_CANCEL ) ),
                aBtnHelp            ( this, ResId( BTN_HELP ) ),
                pMgr                ( rPara.pResMgr )
{
    FreeResource();

    String  aFilterConfigPath( RTL_CONSTASCII_USTRINGPARAM( "Office.Common/Filter/Graphic/Export/GIF" ) );
    pConfigItem = new FilterConfigItem( aFilterConfigPath, &rPara.aFilterData );

    String aInterlaceStr( ResId( KEY_INTER, pMgr ) );
    String aTranslucentStr( ResId( KEY_TRANS, pMgr ) );
    // Config-Parameter lesen
    sal_Bool bInterlaced = pConfigItem->ReadInt32( aInterlaceStr, 1 ) != 0;
    sal_Bool bTranslucent = pConfigItem->ReadInt32( aTranslucentStr, 1 ) != 0;

    aCbxInterlaced.Check( bInterlaced );
    aCbxTranslucent.Check( bTranslucent );

    aBtnOK.SetClickHdl( LINK( this, DlgExportEGIF, OK ) );
}

DlgExportEGIF::~DlgExportEGIF()
{
    delete pConfigItem;
}

/*************************************************************************
|*
|* Speichert eingestellte Werte in ini-Datei
|*
\************************************************************************/

IMPL_LINK( DlgExportEGIF, OK, void *, EMPTYARG )
{

    // Config-Parameter schreiben
    String aInterlaceStr( ResId( KEY_INTER, pMgr ) );
    String aTranslucentStr( ResId( KEY_TRANS, pMgr ) );

    sal_Int32 nValue = 0;
    if ( aCbxInterlaced.IsChecked() )
        nValue++;
    pConfigItem->WriteInt32( aInterlaceStr, nValue );

    nValue = 0;
    if ( aCbxTranslucent.IsChecked() )
        nValue++;
    pConfigItem->WriteInt32( aTranslucentStr, nValue );
    rFltCallPara.aFilterData = pConfigItem->GetFilterData();
    EndDialog( RET_OK );

    return 0;
}

<|endoftext|>


<commit_before>#ifndef __FUTURE_HPP__
#define __FUTURE_HPP__

#include "SoftXMT.hpp"
#include "Delegate.hpp"
#include "Cache.hpp"

//TODO: special ArgsCache acquire, which
//uses args pointer field as a global address
//to the future and either
//1. flip the started bit
//2. or simply acquire RW instead of RO (and Cached not Incoherent)

// idea: if we had a need for futures that
// only mutate their arguments (essentially functional but could change the inputs as well)
// then we could allow multiple copies of
// the future to execute RW-shared mode, where only the first release writeback wins

// TODO: do something like this to force users to have
// the future fields but make them invisible
/*
class FutureArgs {
    private:
    GlobalAddress<Future> futurePtr;
    void (* user_fn_p)(A *);
};
class MyArgs : public FutureArgs {
    int i;
    int j;
}
// Additional possibility is method #2 above
    */

template < typename ArgsStruct >
class Future {
    private:
        struct future_args {
            GlobalAddress<Future> futureAddr;
            void (* user_fn_p)(ArgsStruct *);
            GlobalAddress< ArgsStruct > userArgs;

            future_args( Future< ArgsStruct > * future, ArgsStruct * userArgs, void (* fn_p)(ArgsStruct *) )
                : futureAddr( make_global( future ) )
                , userArgs( make_global( userArgs ) )
                , user_fn_p( fn_p )
            { }
        };

        struct future_done_args {
            Future< ArgsStruct > * futurePtr;
        };

        static void future_done_am( future_done_args * args, size_t args_size, void * payload, size_t payload_size ) {
            args->futurePtr->done = true;
            if ( args->futurePtr->waiter != NULL ) {
                SoftXMT_wake( args->futurePtr->waiter );
                args->futurePtr->waiter = NULL;
            }
        }

        static void future_function( future_args * args ) {
            // TODO test Global address calculations (so I can say address of 'started' instead)
            if ( SoftXMT_delegate_fetch_and_add_word( args->futureAddr, 1 ) == 0 ) {

                // grab the user arguments
                size_t args_size = sizeof(ArgsStruct);
                ArgsStruct argsbuf;
                typename Incoherent<ArgsStruct>::RO cached_args( args->userArgs, args_size, &argsbuf );
                cached_args.block_until_acquired();

                // call the user task
                args->user_fn_p( &argsbuf );
                cached_args.block_until_released();

                // call wake up AM on Node that has the Future
                future_done_args done_args = { args->futureAddr.pointer() };
                SoftXMT_call_on( args->futureAddr.node(), &future_done_am, &done_args );
            }
        }

    public:
        int64_t started;//MUST be first (because address)
        Thread * waiter;
        bool done;
        ArgsStruct * userArgs_lp;

        future_args task_args;

        // TODO: NOTE that this does not copy user arguments because we want to
        // preserve the same semantics as normal tasks.
        // --Unfortunately this means there are three communications to start
        // 1) Task.execute fetches args
        // 2) Future atomic started
        // 3) Bring in user arguments and start
        Future ( void (* fn_p)(ArgsStruct *), ArgsStruct * userArgs )
            : started( 0 )
              , waiter( NULL )
              , done( false )
              , userArgs_lp( userArgs )
              , task_args( this, userArgs, fn_p ) { }

        void touch( ) {
            // start if not started
            if ( SoftXMT_delegate_fetch_and_add_word( make_global(&started), 1 )==0 ) {
                task_args.user_fn_p( userArgs_lp );
                done = true;
            } else  {
                // otherwise block on done event
                while ( !done ) {
                    waiter = CURRENT_THREAD;
                    SoftXMT_suspend( );
                }
            }
        }

        void asPublicTask( ) {
            SoftXMT_publicTask( &future_function, &task_args );
        }
};

#endif
<commit_msg>add debug stuff to Future.hpp<commit_after>#ifndef __FUTURE_HPP__
#define __FUTURE_HPP__

#include "SoftXMT.hpp"
#include "Delegate.hpp"
#include "Cache.hpp"

//TODO: special ArgsCache acquire, which
//uses args pointer field as a global address
//to the future and either
//1. flip the started bit
//2. or simply acquire RW instead of RO (and Cached not Incoherent)

// idea: if we had a need for futures that
// only mutate their arguments (essentially functional but could change the inputs as well)
// then we could allow multiple copies of
// the future to execute RW-shared mode, where only the first release writeback wins

// TODO: do something like this to force users to have
// the future fields but make them invisible
/*
class FutureArgs {
    private:
    GlobalAddress<Future> futurePtr;
    void (* user_fn_p)(A *);
};
class MyArgs : public FutureArgs {
    int i;
    int j;
}
// Additional possibility is method #2 above
    */

//////////////////////////////////////////
#if DEBUG
static int64_t count_ = 0;
#endif

template < typename ArgsStruct >
class Future {
    private:
        int64_t started;
        Thread * waiter;
        bool done;
        ArgsStruct * userArgs_lp;

        struct future_args {
            GlobalAddress<Future> futureAddr;
            void (* user_fn_p)(ArgsStruct *);
            GlobalAddress< ArgsStruct > userArgs;

            future_args( Future< ArgsStruct > * future, ArgsStruct * userArgs, void (* fn_p)(ArgsStruct *) )
                : futureAddr( make_global( future ) )
                , userArgs( make_global( userArgs ) )
                , user_fn_p( fn_p )
            { }
        };

        future_args task_args;

        struct future_done_args {
            Future< ArgsStruct > * futurePtr;
        };

        static void future_done_am( future_done_args * args, size_t args_size, void * payload, size_t payload_size ) {
            args->futurePtr->done = true;
            if ( args->futurePtr->waiter != NULL ) {
                SoftXMT_wake( args->futurePtr->waiter );
                args->futurePtr->waiter = NULL;
            }
        }

        /////////////////
        //Custom delegate operation
        //TODO: use a generalized mechanism that abstracts all but function
        /////////////////
        struct started_memory_descriptor {
            Thread * t;
            GlobalAddress< Future<ArgsStruct> > address;
            int64_t data;
            bool done;
        };

        struct started_reply_args {
            GlobalAddress<started_memory_descriptor> descriptor;
        };

        static void started_reply_am( started_reply_args * args, size_t size, void * payload, size_t payload_size ) {
            assert( payload_size == sizeof(int64_t ) );
            args->descriptor.pointer()->data = *(static_cast<int64_t*>(payload));
            args->descriptor.pointer()->done = true;
            SoftXMT_wake( args->descriptor.pointer()->t );
        }

        struct started_request_args {
            GlobalAddress<started_memory_descriptor> descriptor;
            GlobalAddress< Future<ArgsStruct> > address;
        };

        static void started_request_am( started_request_args * args, size_t size, void * payload, size_t payload_size ) {
            Future< ArgsStruct > * fptr = args->address.pointer();

            DVLOG(5) << "dequeued request (node:" << args->descriptor.node()
                    << "): future ptr:" << (void*)fptr
                    << "(id:"<<fptr->id<<")";
            int64_t data = fptr->started;
            fptr->started = data + 1;

            // If future was already started in this case, it must have been started by touching thread.
            // Incrementing started again will tell the touching thread it can deallocate the Future
            if ( data > 0 ) {
                if ( fptr->done ) { //if it is done then toucher is waiting for the dequeue
                    SoftXMT_wake( fptr->waiter );
                    fptr->waiter = NULL;
                }
            }

            started_reply_args reply_args;
            reply_args.descriptor = args->descriptor;
            SoftXMT_call_on( args->descriptor.node(), &started_reply_am,
                    &reply_args, sizeof(reply_args),
                    &data, sizeof(data) );
        }

        static int64_t future_delegate_started( GlobalAddress< Future<ArgsStruct> > address ) {
            started_memory_descriptor md;
            md.address = address;
            md.data = 0;
            md.done = false;
            md.t = CURRENT_THREAD;
            started_request_args args;
            args.descriptor = make_global(&md);
            args.address = address;
            SoftXMT_call_on( address.node(), &started_request_am, &args );
            while( !md.done ) {
                SoftXMT_suspend();
            }
            return md.data;
        }
        //////////////////////////////////////

        static void future_function( future_args * args ) {
            // TODO #1: the make_global is just calculating location of Future->started
            //if ( SoftXMT_delegate_fetch_and_add_word( make_global( args->startedAddr, args->futureAddr.node() ), 1 ) == 0 ) {
            DVLOG(5) << CURRENT_THREAD->id << "args("<<(void*)args<<") will call started am " << args->futureAddr.pointer();
            if ( future_delegate_started( args->futureAddr ) == 0 ) {
                // grab the user arguments
                size_t args_size = sizeof(ArgsStruct);
                ArgsStruct argsbuf;
                typename Incoherent<ArgsStruct>::RO cached_args( args->userArgs, args_size, &argsbuf );
                cached_args.block_until_acquired();

                // call the user task
                args->user_fn_p( &argsbuf );
                cached_args.block_until_released();

                // call wake up AM on Node that has the Future
                future_done_args done_args = { args->futureAddr.pointer() };
                SoftXMT_call_on( args->futureAddr.node(), &future_done_am, &done_args );
            }
        }

    public:
#if DEBUG
        int64_t id;
#endif

        // TODO: NOTE that this does not copy user arguments because we want to
        // preserve the same semantics as normal tasks.
        // --Unfortunately this means there are three communications to start
        // 1) Task.execute fetches args
        // 2) Future atomic started
        // 3) Bring in user arguments and start
        Future ( void (* fn_p)(ArgsStruct *), ArgsStruct * userArgs )
            : started( 0 )
              , waiter( NULL )
              , done( false )
              , userArgs_lp( userArgs )
#if DEBUG
              , id( count_++ )
#endif
              , task_args( this, userArgs, fn_p ) {

           DVLOG(5) << CURRENT_THREAD->id << " creates Future:"<< (void*)this << " id:"<< id << " args:"<< &task_args;
        }

        void touch( ) {
            // start if not started
            if ( SoftXMT_delegate_fetch_and_add_word( make_global(&started), 1 )==0 ) {
                DVLOG(5) << CURRENT_THREAD->id << " gets to touch-go " << id;
                task_args.user_fn_p( userArgs_lp );
                done = true;
                while ( started < 2 ) { // wait until dequeued
                    DVLOG(5) << CURRENT_THREAD->id << " has to wait on dequeue " << id;
                    waiter = CURRENT_THREAD;
                    SoftXMT_suspend( );
                    DVLOG(5) << CURRENT_THREAD->id << " has woke on dequeue " << id;
                }
            } else  {
                // otherwise block on done event
                while ( !done ) {
                    waiter = CURRENT_THREAD;
                    SoftXMT_suspend( );
                }
            }
        }

        void asPublicTask( ) {
            SoftXMT_publicTask( &future_function, &task_args );
        }
};

#endif
<|endoftext|>


<commit_before>/*
 * File:   CGame.cpp
 * Author: yevgeniy.logachev
 */

#include "CGame.h"
#include "IRenderView.h"
#include "CSystem.h"
#include "IScene.h"
#include "CLoaderFile.h"
#include "IEventDispatcher.hpp"

#include "CRenderSystem.h"
#include "CAnimation2DSystem.h"
#include "CTransformationSystem.h"
#include "CUpdateSystem.h"
#include "CBatchingSystem.h"
#include "IRenderTarget.h"
#include "CThreadPool.h"

using namespace jam;

// *****************************************************************************
// Constants
// *****************************************************************************

// *****************************************************************************
// Public Methods
// *****************************************************************************

CGame::CGame(IRenderViewPtr render)
    : m_IsInitialized(false)
    , m_RenderView(render)
{
    CThreadPool::Get()->Initialize(5);

    CLoaderFile* loaderFile = new CLoaderFile();
    loaderFile->RegisterFileSystem(CSystem::GetBundlePath() + "media/");
    loaderFile->RegisterFileSystem(CSystem::GetBundlePath());

    ILoader::RegisterDefaultLoader(loaderFile);
}

CGame::~CGame()
{
    CThreadPool::Get()->Shutdown();
}

void CGame::Initialize()
{
    m_RenderView->CreateView();

    CRenderSystemPtr renderSystem(new CRenderSystem(m_RenderView->Renderer()));
    CAnimation2DSystemPtr animationSystem(new CAnimation2DSystem());
    CTransfromationSystemPtr transformationSystem(new CTransfromationSystem());
    CUpdateSystemPtr updateSystem(new CUpdateSystem());
    CBatchingSystemPtr batchingSystem(new CBatchingSystem(m_RenderView->Renderer()));
    AddSystem(updateSystem);
    AddSystem(animationSystem);
    AddSystem(batchingSystem);
    AddSystem(transformationSystem);
    AddSystem(renderSystem);

    m_IsInitialized = true;
}

void CGame::Shutdown()
{
    m_IsInitialized = false;
}

bool CGame::IsInitialized() const
{
    return m_IsInitialized;
}

IRenderViewPtr CGame::RenderView() const
{
    return m_RenderView;
}

void CGame::Update(unsigned long dt)
{
    if (!IsInitialized())
    {
        return;
    }

    CThreadPool::Get()->Update(dt);
    Dispatcher()->Update(dt);

    if (!m_Scenes.empty())
    {
        IScenePtr scene = m_Scenes.top();
        scene->Update(dt);
    }

    std::for_each(m_System.begin(), m_System.end(), [dt](const TSystemMap::value_type& system)
    {
        system.second->Update(dt);
    });
}

void CGame::Draw()
{
    CRenderSystemPtr renderSystem = nullptr;
    std::type_index key = SystemId<CRenderSystem>();
    TSystemMap::const_iterator it = m_System.find(key);
    if (it != m_System.end())
    {
        renderSystem = std::static_pointer_cast<CRenderSystem>(it->second);
    }

    if (renderSystem && !m_Scenes.empty())
    {
        IScenePtr scene = m_Scenes.top();

        m_RenderView->Begin();
        const IScene::TCamerasList& cameras = scene->Cameras();
        std::for_each(cameras.begin(), cameras.end(), [&](ICameraPtr camera)
        {
            renderSystem->Draw(camera);
        });
        m_RenderView->End();
    }
}

void CGame::PushScene(IScenePtr scene)
{
    assert(scene);
    if (!m_Scenes.empty())
    {
        m_Scenes.top()->Pause();
    }

    m_Scenes.push(scene);
    m_Scenes.top()->Start();
}

void CGame::PopScene()
{
    assert(!m_Scenes.empty());
    if (!m_Scenes.empty())
    {
        m_Scenes.top()->Stop();
        m_Scenes.pop();
    }
}

IScenePtr CGame::GetScene() const
{
    if (!m_Scenes.empty())
    {
        return m_Scenes.top();
    }

    return nullptr;
}

void CGame::AddSystem(ISystemPtr system)
{
    ISystem& s = *system.get();
    std::type_index key = std::type_index(typeid(s));
    m_System[key] = system;
}

void CGame::RemoveSystem(ISystemPtr system)
{
    ISystem& s = *system.get();
    std::type_index key = std::type_index(typeid(s));
    TSystemMap::const_iterator it = m_System.find(key);
    if (it != m_System.end())
    {
        m_System.erase(it);
    }
}

ISystemPtr CGame::GetSystem(const std::type_index& systemKey)
{
    TSystemMap::const_iterator it = m_System.find(systemKey);
    if (it != m_System.end())
    {
        return it->second;
    }

    return nullptr;
}

CRenderSystemPtr CGame::RenderSystem() const
{
    return m_RenderSystem;
}

// *****************************************************************************
// Protected Methods
// *****************************************************************************

// *****************************************************************************
// Private Methods
// *****************************************************************************

<commit_msg>Store render system in CGame<commit_after>/*
 * File:   CGame.cpp
 * Author: yevgeniy.logachev
 */

#include "CGame.h"
#include "IRenderView.h"
#include "CSystem.h"
#include "IScene.h"
#include "CLoaderFile.h"
#include "IEventDispatcher.hpp"

#include "CRenderSystem.h"
#include "CAnimation2DSystem.h"
#include "CTransformationSystem.h"
#include "CUpdateSystem.h"
#include "CBatchingSystem.h"
#include "IRenderTarget.h"
#include "CThreadPool.h"

using namespace jam;

// *****************************************************************************
// Constants
// *****************************************************************************

// *****************************************************************************
// Public Methods
// *****************************************************************************

CGame::CGame(IRenderViewPtr render)
    : m_IsInitialized(false)
    , m_RenderView(render)
{
    CThreadPool::Get()->Initialize(5);

    CLoaderFile* loaderFile = new CLoaderFile();
    loaderFile->RegisterFileSystem(CSystem::GetBundlePath() + "media/");
    loaderFile->RegisterFileSystem(CSystem::GetBundlePath());

    ILoader::RegisterDefaultLoader(loaderFile);
}

CGame::~CGame()
{
    CThreadPool::Get()->Shutdown();
}

void CGame::Initialize()
{
    m_RenderView->CreateView();

    m_RenderSystem.reset(new CRenderSystem(m_RenderView->Renderer()));
    CAnimation2DSystemPtr animationSystem(new CAnimation2DSystem());
    CTransfromationSystemPtr transformationSystem(new CTransfromationSystem());
    CUpdateSystemPtr updateSystem(new CUpdateSystem());
    CBatchingSystemPtr batchingSystem(new CBatchingSystem(m_RenderView->Renderer()));
    AddSystem(updateSystem);
    AddSystem(animationSystem);
    AddSystem(batchingSystem);
    AddSystem(transformationSystem);
    AddSystem(m_RenderSystem);

    m_IsInitialized = true;
}

void CGame::Shutdown()
{
    m_IsInitialized = false;
}

bool CGame::IsInitialized() const
{
    return m_IsInitialized;
}

IRenderViewPtr CGame::RenderView() const
{
    return m_RenderView;
}

void CGame::Update(unsigned long dt)
{
    if (!IsInitialized())
    {
        return;
    }

    CThreadPool::Get()->Update(dt);
    Dispatcher()->Update(dt);

    if (!m_Scenes.empty())
    {
        IScenePtr scene = m_Scenes.top();
        scene->Update(dt);
    }

    std::for_each(m_System.begin(), m_System.end(), [dt](const TSystemMap::value_type& system)
    {
        system.second->Update(dt);
    });
}

void CGame::Draw()
{
    CRenderSystemPtr renderSystem = RenderSystem();
    /*std::type_index key = SystemId<CRenderSystem>();
    TSystemMap::const_iterator it = m_System.find(key);
    if (it != m_System.end())
    {
        renderSystem = std::static_pointer_cast<CRenderSystem>(it->second);
    }*/

    if (renderSystem && !m_Scenes.empty())
    {
        IScenePtr scene = m_Scenes.top();

        m_RenderView->Begin();
        const IScene::TCamerasList& cameras = scene->Cameras();
        std::for_each(cameras.begin(), cameras.end(), [&](ICameraPtr camera)
        {
            renderSystem->Draw(camera);
        });
        m_RenderView->End();
    }
}

void CGame::PushScene(IScenePtr scene)
{
    assert(scene);
    if (!m_Scenes.empty())
    {
        m_Scenes.top()->Pause();
    }

    m_Scenes.push(scene);
    m_Scenes.top()->Start();
}

void CGame::PopScene()
{
    assert(!m_Scenes.empty());
    if (!m_Scenes.empty())
    {
        m_Scenes.top()->Stop();
        m_Scenes.pop();
    }
}

IScenePtr CGame::GetScene() const
{
    if (!m_Scenes.empty())
    {
        return m_Scenes.top();
    }

    return nullptr;
}

void CGame::AddSystem(ISystemPtr system)
{
    ISystem& s = *system.get();
    std::type_index key = std::type_index(typeid(s));
    m_System[key] = system;
}

void CGame::RemoveSystem(ISystemPtr system)
{
    ISystem& s = *system.get();
    std::type_index key = std::type_index(typeid(s));
    TSystemMap::const_iterator it = m_System.find(key);
    if (it != m_System.end())
    {
        m_System.erase(it);
    }
}

ISystemPtr CGame::GetSystem(const std::type_index& systemKey)
{
    TSystemMap::const_iterator it = m_System.find(systemKey);
    if (it != m_System.end())
    {
        return it->second;
    }

    return nullptr;
}

CRenderSystemPtr CGame::RenderSystem() const
{
    return m_RenderSystem;
}

// *****************************************************************************
// Protected Methods
// *****************************************************************************

// *****************************************************************************
// Private Methods
// *****************************************************************************

<|endoftext|>


<commit_before>#include <climits>
#include <vector>
using std::vector;
#include <string>
using std::string;
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>

#ifdef USE_GTEST
#include <gtest/gtest.h>
#endif

struct ListNode
{
    int val;
    ListNode *next;
    ListNode(int x)
        : val(x), next(NULL)
    {
    }
};
inline ListNode *create_list(vector<int> &nums)
{
    ListNode *res = NULL;
    ListNode *&node = res;
    for (int num : nums)
    {
        node = new ListNode(num);
        node = node->next;
    }

    return res;
}
inline void free_list(ListNode *l)
{
    while (l != NULL)
    {
        ListNode *tmp = l;
        l = l->next;
        delete tmp;
    }
}
struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x)
        : val(x), left(NULL), right(NULL)
    {
    }
    ~TreeNode()
    {
        if (left != NULL)
        {
            delete left;
            left = NULL;
        }
        if (right != NULL)
        {
            delete right;
            right = NULL;
        }
    }
};<commit_msg>update test<commit_after>#include <climits>
#include <vector>
using std::vector;
#include <string>
using std::string;
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>

#ifdef USE_GTEST
#include <gtest/gtest.h>
#endif

struct ListNode
{
    int val;
    ListNode *next;
    ListNode(int x)
        : val(x), next(NULL)
    {
    }
};
//这里参数不用引用是纯粹为了偷懒，因为gcc不能引用临时对象
inline ListNode *create_list(vector<int> nums)
{
    ListNode *res = NULL;
    ListNode *&node = res;
    for (int num : nums)
    {
        node = new ListNode(num);
        node = node->next;
    }

    return res;
}
inline void free_list(ListNode *l)
{
    while (l != NULL)
    {
        ListNode *tmp = l;
        l = l->next;
        delete tmp;
    }
}
struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x)
        : val(x), left(NULL), right(NULL)
    {
    }
    ~TreeNode()
    {
        if (left != NULL)
        {
            delete left;
            left = NULL;
        }
        if (right != NULL)
        {
            delete right;
            right = NULL;
        }
    }
};<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: bparr.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: hr $ $Date: 2006-08-14 15:17:05 $
 *
 *  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 _BPARR_HXX
#define _BPARR_HXX

#ifndef _SOLAR_H
#include <tools/solar.h>
#endif
#ifndef _DEBUG_HXX //autogen
#include <tools/debug.hxx>
#endif

struct BlockInfo;
class BigPtrArray;

class BigPtrEntry
{
    friend class BigPtrArray;
    BlockInfo* pBlock;
    USHORT nOffset;
public:
    virtual ~BigPtrEntry() {}
protected:
    BigPtrEntry() : pBlock(0), nOffset(0) {}

    inline ULONG GetPos() const;
    inline BigPtrArray& GetArray() const;
};
typedef BigPtrEntry* ElementPtr;

typedef BOOL (*FnForEach)( const ElementPtr&, void* pArgs );

// 1000 Eintrge pro Block = etwas weniger als 4K
#define MAXENTRY 1000

// Anzahl Eintraege, die bei der Kompression frei bleiben duerfen
// dieser Wert ist fuer den Worst Case, da wir MAXBLOCK mit ca 25%
// Overhead definiert haben, reichen 80% = 800 Eintraege vollkommen aus
// Will mann voellige Kompression haben, muss eben 100 angegeben werden.

#define COMPRESSLVL 80

struct BlockInfo {                  // Block-Info:
    BigPtrArray* pBigArr;           // in diesem Array steht der Block
    ElementPtr* pData;              // Datenblock
    ULONG nStart, nEnd;             // Start- und EndIndex
    USHORT nElem;                   // Anzahl Elemente
};

class BigPtrArray
{
    BlockInfo** ppInf;              // Block-Infos
    ULONG       nSize;              // Anzahl Elemente
    USHORT      nMaxBlock;          // akt. max Anzahl Bloecke
    USHORT      nBlock;             // Anzahl Bloecke
    USHORT      nCur;               // letzter Block

    USHORT      Index2Block( ULONG ) const; // Blocksuche
    BlockInfo*  InsBlock( USHORT );         // Block einfuegen
    void        BlockDel( USHORT );         // es wurden Bloecke geloescht
    void        UpdIndex( USHORT );         // Indexe neu berechnen

protected:
    // fuelle alle Bloecke auf.
    // Der short gibt in Prozent an, wie voll die Bloecke werden sollen.
    // Der ReturnWert besagt, das irgendetwas "getan" wurde
    USHORT Compress( short = COMPRESSLVL );

public:
    BigPtrArray();
    ~BigPtrArray();

    ULONG Count() const { return nSize; }

    void Insert( const ElementPtr& r, ULONG pos );
    void Remove( ULONG pos, ULONG n = 1 );
    void Move( ULONG from, ULONG to );
    void Replace( ULONG pos, const ElementPtr& r);

    ElementPtr operator[]( ULONG ) const;
    void ForEach( FnForEach fn, void* pArgs = NULL )
    {
        ForEach( 0, nSize, fn, pArgs );
    }
    void ForEach( ULONG nStart, ULONG nEnd, FnForEach fn, void* pArgs = NULL );
};

inline ULONG BigPtrEntry::GetPos() const
{
    DBG_ASSERT( this == pBlock->pData[ nOffset ], "Element nicht im Block" );
    return pBlock->nStart + nOffset;
}

inline BigPtrArray& BigPtrEntry::GetArray() const
{
    return *pBlock->pBigArr;
}

#endif
<commit_msg>INTEGRATION: CWS changefileheader (1.4.738); FILE MERGED 2008/04/01 15:56:06 thb 1.4.738.2: #i85898# Stripping all external header guards 2008/03/31 16:52:34 rt 1.4.738.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: bparr.hxx,v $
 * $Revision: 1.5 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _BPARR_HXX
#define _BPARR_HXX

#include <tools/solar.h>
#include <tools/debug.hxx>

struct BlockInfo;
class BigPtrArray;

class BigPtrEntry
{
    friend class BigPtrArray;
    BlockInfo* pBlock;
    USHORT nOffset;
public:
    virtual ~BigPtrEntry() {}
protected:
    BigPtrEntry() : pBlock(0), nOffset(0) {}

    inline ULONG GetPos() const;
    inline BigPtrArray& GetArray() const;
};
typedef BigPtrEntry* ElementPtr;

typedef BOOL (*FnForEach)( const ElementPtr&, void* pArgs );

// 1000 Eintrge pro Block = etwas weniger als 4K
#define MAXENTRY 1000

// Anzahl Eintraege, die bei der Kompression frei bleiben duerfen
// dieser Wert ist fuer den Worst Case, da wir MAXBLOCK mit ca 25%
// Overhead definiert haben, reichen 80% = 800 Eintraege vollkommen aus
// Will mann voellige Kompression haben, muss eben 100 angegeben werden.

#define COMPRESSLVL 80

struct BlockInfo {                  // Block-Info:
    BigPtrArray* pBigArr;           // in diesem Array steht der Block
    ElementPtr* pData;              // Datenblock
    ULONG nStart, nEnd;             // Start- und EndIndex
    USHORT nElem;                   // Anzahl Elemente
};

class BigPtrArray
{
    BlockInfo** ppInf;              // Block-Infos
    ULONG       nSize;              // Anzahl Elemente
    USHORT      nMaxBlock;          // akt. max Anzahl Bloecke
    USHORT      nBlock;             // Anzahl Bloecke
    USHORT      nCur;               // letzter Block

    USHORT      Index2Block( ULONG ) const; // Blocksuche
    BlockInfo*  InsBlock( USHORT );         // Block einfuegen
    void        BlockDel( USHORT );         // es wurden Bloecke geloescht
    void        UpdIndex( USHORT );         // Indexe neu berechnen

protected:
    // fuelle alle Bloecke auf.
    // Der short gibt in Prozent an, wie voll die Bloecke werden sollen.
    // Der ReturnWert besagt, das irgendetwas "getan" wurde
    USHORT Compress( short = COMPRESSLVL );

public:
    BigPtrArray();
    ~BigPtrArray();

    ULONG Count() const { return nSize; }

    void Insert( const ElementPtr& r, ULONG pos );
    void Remove( ULONG pos, ULONG n = 1 );
    void Move( ULONG from, ULONG to );
    void Replace( ULONG pos, const ElementPtr& r);

    ElementPtr operator[]( ULONG ) const;
    void ForEach( FnForEach fn, void* pArgs = NULL )
    {
        ForEach( 0, nSize, fn, pArgs );
    }
    void ForEach( ULONG nStart, ULONG nEnd, FnForEach fn, void* pArgs = NULL );
};

inline ULONG BigPtrEntry::GetPos() const
{
    DBG_ASSERT( this == pBlock->pData[ nOffset ], "Element nicht im Block" );
    return pBlock->nStart + nOffset;
}

inline BigPtrArray& BigPtrEntry::GetArray() const
{
    return *pBlock->pBigArr;
}

#endif
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: docsh.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: os $ $Date: 2001-02-12 11:27:26 $
 *
 *  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 _SWDOCSH_HXX
#define _SWDOCSH_HXX

#ifndef _TIMER_HXX //autogen
#include <vcl/timer.hxx>
#endif
#ifndef _SFX_OBJFAC_HXX //autogen
#include <sfx2/docfac.hxx>
#endif
#ifndef _SFX_INTERNO_HXX //autogen
#include <sfx2/interno.hxx>
#endif
#ifndef _SFX_OBJSH_HXX //autogen
#include <sfx2/objsh.hxx>
#endif
#ifndef SW_SWDLL_HXX
#include <swdll.hxx>
#endif
#ifndef _SHELLID_HXX
#include <shellid.hxx>
#endif

class   SwDoc;
class   Sw3Io;
class   SfxDocumentInfoDialog;
class   SfxStyleSheetBasePool;
class   FontList;
class   SwView;
class   SwWrtShell;
class   SwFEShell;
class   Reader;
class   SwReader;
class   SwCrsrShell;
class   SwSrcView;
class   SfxFileDialog;
class   PushButton;
class   FixedText;
class   SwPaM;
class   SwgReaderOption;

class SwDocShell: public SfxObjectShell, public SfxInPlaceObject,
                  public SfxListener
{
    SwDoc*                  pDoc;           // Document
    Sw3Io*                  pIo;            // Reader / Writer
    SfxStyleSheetBasePool*  pBasePool;      // Durchreiche fuer Formate
    FontList*               pFontList;      // aktuelle FontListe

    // Nix geht ohne die WrtShell (historische Gruende)
    // RuekwaertsPointer auf die View (historische Gruende)
    // Dieser gilt solange bis im Activate ein neuer gesetzt wird
    // oder dieser im Dtor der View geloescht wird
    //
    SwView*                 pView;
    SwWrtShell*             pWrtShell;

    Timer                   aFinishedTimer; // Timer fuers ueberpriefen der
                                            // Grafik-Links. Sind alle da,
                                            // dann ist Doc voll. geladen

    SvPersistRef            xOLEChildList;  // fuers RemoveOLEObjects

    // Methoden fuer den Zugriff aufs Doc
    void                    AddLink();
    void                    RemoveLink();

    // Hint abfangen fuer DocInfo
    virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint );

    // FileIO
    virtual BOOL            InitNew(SvStorage* pNewStor);
    virtual BOOL            Load(SvStorage* pStor);
    virtual BOOL            LoadFrom(SvStorage* pStor);
    virtual BOOL            ConvertFrom( SfxMedium &rMedium );
    virtual void            HandsOff();
    virtual BOOL            SaveAs(SvStorage * pNewStor );
    virtual BOOL            ConvertTo(SfxMedium &rMedium );
    virtual BOOL            SaveCompleted(SvStorage * pNewStor );
    virtual USHORT          PrepareClose( BOOL bUI = TRUE, BOOL bForBrowsing = FALSE );

    // DocInfo dem Doc melden
    //
    virtual SfxDocumentInfoDialog* CreateDocumentInfoDialog(
                                    Window *pParent, const SfxItemSet &);
    // Template-Btn
    Window*                 AddTemplateBtn(SfxFileDialog* pFileDlg);

    // OLE-Geraffel
    virtual void            Draw( OutputDevice*, const JobSetup&, USHORT);

    // Methoden fuer StyleSheets
    USHORT                  Edit( const String &rName, const String& rParent, USHORT nFamily,
                                    USHORT nMask, BOOL bNew,
                                    BOOL bColumn = FALSE,
                                    SwWrtShell* pActShell = 0,
                                    BOOL bBasic = FALSE );
    USHORT                  Delete(const String &rName, USHORT nFamily);
    USHORT                  ApplyStyles(const String &rName, USHORT nFamily, SwWrtShell* pShell = 0,
                                        USHORT nMode = 0 );
    USHORT                  DoWaterCan( const String &rName, USHORT nFamily);
    USHORT                  UpdateStyle(const String &rName, USHORT nFamily, SwWrtShell* pShell = 0);
    USHORT                  MakeByExample(const String &rName,
                                            USHORT nFamily, USHORT nMask, SwWrtShell* pShell = 0);

    void                    InitDraw();
    void                    SubInitNew();   // fuer InitNew und HtmlSourceModus
    inline void             SetWrtShell(SwWrtShell* pShell)
                                { pWrtShell = pShell; }

    void                    RemoveOLEObjects();

    DECL_STATIC_LINK( SwDocShell, IsLoadFinished, void* );
    DECL_LINK( SelTemplateHdl, PushButton * );

public:

    // aber selbst implementieren
    SFX_DECL_INTERFACE(SW_DOCSHELL);
    SFX_DECL_OBJECTFACTORY_DLL(SwDocShell, SW_DLL());
    TYPEINFO();

    static SfxInterface *_GetInterface() { return _GetInterfaceImpl(); }

    //Das Doc wird fuer SO-Datenaustausch benoetigt!
    SwDocShell(SfxObjectCreateMode eMode = SFX_CREATE_MODE_EMBEDDED);
    SwDocShell( SwDoc *pDoc, SfxObjectCreateMode eMode = SFX_CREATE_MODE_STANDARD );
    ~SwDocShell();

    // OLE 2.0-Benachrichtigung
    DECL_LINK( Ole2ModifiedHdl, void * );

    // OLE-Geraffel
    virtual void      SetVisArea( const Rectangle &rRect );
    virtual Rectangle GetVisArea( USHORT nAspect ) const;
    virtual Printer  *GetDocumentPrinter();
    virtual void      OnDocumentPrinterChanged( Printer * pNewPrinter );
    virtual ULONG     GetMiscStatus() const;

    virtual void            PrepareReload();
    virtual void            SetModified( BOOL = TRUE );

    // Dispatcher
    void                    Execute(SfxRequest &);
    void                    ExecStyleSheet(SfxRequest&);
    void                    ExecDB(SfxRequest&);

    void                    GetState(SfxItemSet &);
    void                    StateAlways(SfxItemSet &);
    void                    StateStyleSheet(SfxItemSet&, SwWrtShell* pSh = 0 );

    // Doc rausreichen aber VORSICHT
    inline SwDoc*           GetDoc() { return pDoc; }
    void                    UpdateFontList();
    void                    UpdateChildWindows();

    // DocumentInfo neu setzen
    BOOL                    SetDocumentInfo(const SfxDocumentInfo& rInfo);

    // globaler IO
    virtual BOOL            Save();
    inline BOOL                 SaveAsChilds( SvStorage *pStor );

    // fuer VorlagenPI
    virtual SfxStyleSheetBasePool*  GetStyleSheetPool();

    // Fuer Organizer
    virtual BOOL Insert(SfxObjectShell &rSource,
                        USHORT  nSourceIdx1,
                        USHORT  nSourceIdx2,
                        USHORT  nSourceIdx3,
                        USHORT& nIdx1,
                        USHORT& nIdx2,
                        USHORT& nIdx3,
                        USHORT& nRemovedIdx);

    virtual BOOL Remove(USHORT nIdx1,
                        USHORT nIdx2 = INDEX_IGNORE,
                        USHORT nIdx3 = INDEX_IGNORE);

    virtual Bitmap      GetStyleFamilyBitmap( SfxStyleFamily eFamily );

    // View setzen fuer Aktionen ueber Shell
    void          SetView(SwView* pVw);
    const SwView *GetView() const { return pView; }

    // Zugriff auf die zur SwView gehoerige SwWrtShell
          SwWrtShell *GetWrtShell()       { return pWrtShell; }
    const SwWrtShell *GetWrtShell() const { return pWrtShell; }

    // fuer die Core - die kennt die DocShell aber keine WrtShell!
          SwFEShell *GetFEShell();
    const SwFEShell *GetFEShell() const
                { return ((SwDocShell*)this)->GetFEShell(); }

    // Fuer Einfuegen Dokument
    Reader* StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr,
                            SwCrsrShell* pCrsrSh = 0, SwPaM* pPaM = 0);

    // Anforderung der pIo-Struktur fuer den Zugriff auf Substorages
    // und Streams
    Sw3Io* GetIoSystem() { return pIo; }

    virtual long DdeGetData( const String& rItem, SvData& rData );
    virtual long DdeSetData( const String& rItem, const SvData& rData );
    virtual SvPseudoObject* DdeCreateHotLink( const String& rItem );
    virtual void        FillClass( SvGlobalName * pClassName,
                                   ULONG * pClipFormat,
                                   String * pAppName,
                                   String * pLongUserName,
                                   String * pUserName,
                                   long nVersion = SOFFICE_FILEFORMAT_NOW ) const;
    virtual void    FillRegInfo( SvEmbeddedRegistryInfo * );

    virtual SvDataMemberObjectRef CreateSnapshot();

    virtual void LoadStyles( SfxObjectShell& rSource );

    // Seitenvorlagedialog anzeigen, ggf. auf Spaltenpage
    void    FormatPage( const String& rPage,
                        BOOL bColumn = FALSE,
                        SwWrtShell*     pActShell = 0 );

    // Timer starten fuers ueberpruefen der Grafik-Links. Sind alle
    // vollstaendig geladen, dann ist das Doc fertig
    void StartLoadFinishedTimer();

    // eine Uebertragung wird abgebrochen (wird aus dem SFX gerufen)
    virtual void CancelTransfers();

    // Doc aus Html-Source neu laden
    void    ReloadFromHtml( const String& rStreamName, SwSrcView* pSrcView );

    // embedded alle lokalen Links (Bereiche/Grafiken)
    BOOL EmbedAllLinks();

    //Activate wait cursor for all windows of this document
    //Optionally all dispatcher could be Locked
    //Usually locking should be done using the class: SwWaitObject!
    void EnterWait( BOOL bLockDispatcher );
    void LeaveWait( BOOL bLockDispatcher );

    void ToggleBrowserMode(BOOL bOn, SwView* pView = 0);

    ULONG LoadStylesFromFile( const String& rURL, SwgReaderOption& rOpt,
                                BOOL bUnoCall );
    void InvalidateModel();
    void ReactivateModel();

#if SUPD>620
    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >  GetEventNames();
#endif
};

inline BOOL SwDocShell::SaveAsChilds( SvStorage *pStor )
{
    return SfxInPlaceObject::SaveAsChilds( pStor );
}
#endif
<commit_msg>FILEFORMAT_CURRENT<commit_after>/*************************************************************************
 *
 *  $RCSfile: docsh.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: os $ $Date: 2001-02-13 14:58:22 $
 *
 *  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 _SWDOCSH_HXX
#define _SWDOCSH_HXX

#ifndef _TIMER_HXX //autogen
#include <vcl/timer.hxx>
#endif
#ifndef _SFX_OBJFAC_HXX //autogen
#include <sfx2/docfac.hxx>
#endif
#ifndef _SFX_INTERNO_HXX //autogen
#include <sfx2/interno.hxx>
#endif
#ifndef _SFX_OBJSH_HXX //autogen
#include <sfx2/objsh.hxx>
#endif
#ifndef SW_SWDLL_HXX
#include <swdll.hxx>
#endif
#ifndef _SHELLID_HXX
#include <shellid.hxx>
#endif

class   SwDoc;
class   Sw3Io;
class   SfxDocumentInfoDialog;
class   SfxStyleSheetBasePool;
class   FontList;
class   SwView;
class   SwWrtShell;
class   SwFEShell;
class   Reader;
class   SwReader;
class   SwCrsrShell;
class   SwSrcView;
class   SfxFileDialog;
class   PushButton;
class   FixedText;
class   SwPaM;
class   SwgReaderOption;

class SwDocShell: public SfxObjectShell, public SfxInPlaceObject,
                  public SfxListener
{
    SwDoc*                  pDoc;           // Document
    Sw3Io*                  pIo;            // Reader / Writer
    SfxStyleSheetBasePool*  pBasePool;      // Durchreiche fuer Formate
    FontList*               pFontList;      // aktuelle FontListe

    // Nix geht ohne die WrtShell (historische Gruende)
    // RuekwaertsPointer auf die View (historische Gruende)
    // Dieser gilt solange bis im Activate ein neuer gesetzt wird
    // oder dieser im Dtor der View geloescht wird
    //
    SwView*                 pView;
    SwWrtShell*             pWrtShell;

    Timer                   aFinishedTimer; // Timer fuers ueberpriefen der
                                            // Grafik-Links. Sind alle da,
                                            // dann ist Doc voll. geladen

    SvPersistRef            xOLEChildList;  // fuers RemoveOLEObjects

    // Methoden fuer den Zugriff aufs Doc
    void                    AddLink();
    void                    RemoveLink();

    // Hint abfangen fuer DocInfo
    virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint );

    // FileIO
    virtual BOOL            InitNew(SvStorage* pNewStor);
    virtual BOOL            Load(SvStorage* pStor);
    virtual BOOL            LoadFrom(SvStorage* pStor);
    virtual BOOL            ConvertFrom( SfxMedium &rMedium );
    virtual void            HandsOff();
    virtual BOOL            SaveAs(SvStorage * pNewStor );
    virtual BOOL            ConvertTo(SfxMedium &rMedium );
    virtual BOOL            SaveCompleted(SvStorage * pNewStor );
    virtual USHORT          PrepareClose( BOOL bUI = TRUE, BOOL bForBrowsing = FALSE );

    // DocInfo dem Doc melden
    //
    virtual SfxDocumentInfoDialog* CreateDocumentInfoDialog(
                                    Window *pParent, const SfxItemSet &);
    // Template-Btn
    Window*                 AddTemplateBtn(SfxFileDialog* pFileDlg);

    // OLE-Geraffel
    virtual void            Draw( OutputDevice*, const JobSetup&, USHORT);

    // Methoden fuer StyleSheets
    USHORT                  Edit( const String &rName, const String& rParent, USHORT nFamily,
                                    USHORT nMask, BOOL bNew,
                                    BOOL bColumn = FALSE,
                                    SwWrtShell* pActShell = 0,
                                    BOOL bBasic = FALSE );
    USHORT                  Delete(const String &rName, USHORT nFamily);
    USHORT                  ApplyStyles(const String &rName, USHORT nFamily, SwWrtShell* pShell = 0,
                                        USHORT nMode = 0 );
    USHORT                  DoWaterCan( const String &rName, USHORT nFamily);
    USHORT                  UpdateStyle(const String &rName, USHORT nFamily, SwWrtShell* pShell = 0);
    USHORT                  MakeByExample(const String &rName,
                                            USHORT nFamily, USHORT nMask, SwWrtShell* pShell = 0);

    void                    InitDraw();
    void                    SubInitNew();   // fuer InitNew und HtmlSourceModus
    inline void             SetWrtShell(SwWrtShell* pShell)
                                { pWrtShell = pShell; }

    void                    RemoveOLEObjects();

    DECL_STATIC_LINK( SwDocShell, IsLoadFinished, void* );
    DECL_LINK( SelTemplateHdl, PushButton * );

public:

    // aber selbst implementieren
    SFX_DECL_INTERFACE(SW_DOCSHELL);
    SFX_DECL_OBJECTFACTORY_DLL(SwDocShell, SW_DLL());
    TYPEINFO();

    static SfxInterface *_GetInterface() { return _GetInterfaceImpl(); }

    //Das Doc wird fuer SO-Datenaustausch benoetigt!
    SwDocShell(SfxObjectCreateMode eMode = SFX_CREATE_MODE_EMBEDDED);
    SwDocShell( SwDoc *pDoc, SfxObjectCreateMode eMode = SFX_CREATE_MODE_STANDARD );
    ~SwDocShell();

    // OLE 2.0-Benachrichtigung
    DECL_LINK( Ole2ModifiedHdl, void * );

    // OLE-Geraffel
    virtual void      SetVisArea( const Rectangle &rRect );
    virtual Rectangle GetVisArea( USHORT nAspect ) const;
    virtual Printer  *GetDocumentPrinter();
    virtual void      OnDocumentPrinterChanged( Printer * pNewPrinter );
    virtual ULONG     GetMiscStatus() const;

    virtual void            PrepareReload();
    virtual void            SetModified( BOOL = TRUE );

    // Dispatcher
    void                    Execute(SfxRequest &);
    void                    ExecStyleSheet(SfxRequest&);
    void                    ExecDB(SfxRequest&);

    void                    GetState(SfxItemSet &);
    void                    StateAlways(SfxItemSet &);
    void                    StateStyleSheet(SfxItemSet&, SwWrtShell* pSh = 0 );

    // Doc rausreichen aber VORSICHT
    inline SwDoc*           GetDoc() { return pDoc; }
    void                    UpdateFontList();
    void                    UpdateChildWindows();

    // DocumentInfo neu setzen
    BOOL                    SetDocumentInfo(const SfxDocumentInfo& rInfo);

    // globaler IO
    virtual BOOL            Save();
    inline BOOL                 SaveAsChilds( SvStorage *pStor );

    // fuer VorlagenPI
    virtual SfxStyleSheetBasePool*  GetStyleSheetPool();

    // Fuer Organizer
    virtual BOOL Insert(SfxObjectShell &rSource,
                        USHORT  nSourceIdx1,
                        USHORT  nSourceIdx2,
                        USHORT  nSourceIdx3,
                        USHORT& nIdx1,
                        USHORT& nIdx2,
                        USHORT& nIdx3,
                        USHORT& nRemovedIdx);

    virtual BOOL Remove(USHORT nIdx1,
                        USHORT nIdx2 = INDEX_IGNORE,
                        USHORT nIdx3 = INDEX_IGNORE);

    virtual Bitmap      GetStyleFamilyBitmap( SfxStyleFamily eFamily );

    // View setzen fuer Aktionen ueber Shell
    void          SetView(SwView* pVw);
    const SwView *GetView() const { return pView; }

    // Zugriff auf die zur SwView gehoerige SwWrtShell
          SwWrtShell *GetWrtShell()       { return pWrtShell; }
    const SwWrtShell *GetWrtShell() const { return pWrtShell; }

    // fuer die Core - die kennt die DocShell aber keine WrtShell!
          SwFEShell *GetFEShell();
    const SwFEShell *GetFEShell() const
                { return ((SwDocShell*)this)->GetFEShell(); }

    // Fuer Einfuegen Dokument
    Reader* StartConvertFrom(SfxMedium& rMedium, SwReader** ppRdr,
                            SwCrsrShell* pCrsrSh = 0, SwPaM* pPaM = 0);

    // Anforderung der pIo-Struktur fuer den Zugriff auf Substorages
    // und Streams
    Sw3Io* GetIoSystem() { return pIo; }

    virtual long DdeGetData( const String& rItem, SvData& rData );
    virtual long DdeSetData( const String& rItem, const SvData& rData );
    virtual SvPseudoObject* DdeCreateHotLink( const String& rItem );
    virtual void        FillClass( SvGlobalName * pClassName,
                                   ULONG * pClipFormat,
                                   String * pAppName,
                                   String * pLongUserName,
                                   String * pUserName,
                                   long nVersion = SOFFICE_FILEFORMAT_CURRENT ) const;
    virtual void    FillRegInfo( SvEmbeddedRegistryInfo * );

    virtual SvDataMemberObjectRef CreateSnapshot();

    virtual void LoadStyles( SfxObjectShell& rSource );

    // Seitenvorlagedialog anzeigen, ggf. auf Spaltenpage
    void    FormatPage( const String& rPage,
                        BOOL bColumn = FALSE,
                        SwWrtShell*     pActShell = 0 );

    // Timer starten fuers ueberpruefen der Grafik-Links. Sind alle
    // vollstaendig geladen, dann ist das Doc fertig
    void StartLoadFinishedTimer();

    // eine Uebertragung wird abgebrochen (wird aus dem SFX gerufen)
    virtual void CancelTransfers();

    // Doc aus Html-Source neu laden
    void    ReloadFromHtml( const String& rStreamName, SwSrcView* pSrcView );

    // embedded alle lokalen Links (Bereiche/Grafiken)
    BOOL EmbedAllLinks();

    //Activate wait cursor for all windows of this document
    //Optionally all dispatcher could be Locked
    //Usually locking should be done using the class: SwWaitObject!
    void EnterWait( BOOL bLockDispatcher );
    void LeaveWait( BOOL bLockDispatcher );

    void ToggleBrowserMode(BOOL bOn, SwView* pView = 0);

    ULONG LoadStylesFromFile( const String& rURL, SwgReaderOption& rOpt,
                                BOOL bUnoCall );
    void InvalidateModel();
    void ReactivateModel();

#if SUPD>620
    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >  GetEventNames();
#endif
};

inline BOOL SwDocShell::SaveAsChilds( SvStorage *pStor )
{
    return SfxInPlaceObject::SaveAsChilds( pStor );
}
#endif
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: dpage.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 01:42:44 $
 *
 *  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 _DPAGE_HXX
#define _DPAGE_HXX

#ifndef _FM_FMPAGE_HXX
#include <svx/fmpage.hxx>
#endif

#ifndef _SVDOBJ_HXX
#include <svx/svdobj.hxx>
#endif

class SdrPageGridFrameList;
class SwDrawDocument;
class SwDoc;

class SwDPage : public FmFormPage, public SdrObjUserCall
{
    SdrPageGridFrameList*   pGridLst;
    SwDoc&                  rDoc;

public:
    SwDPage(SwDrawDocument& rNewModel, BOOL bMasterPage=FALSE);
    ~SwDPage();

    // #i3694#
    // This GetOffset() method is not needed anymore, it even leads to errors.
    // virtual Point GetOffset() const;
    virtual SdrObject* ReplaceObject( SdrObject* pNewObj, ULONG nObjNum );

    virtual void    RequestBasic();

    virtual const SdrPageGridFrameList* GetGridFrameList(const SdrPageView* pPV,
                                    const Rectangle *pRect) const;

    virtual String GetLinkData( const String& rLinkName );
    virtual void SetLinkData( const String& rLinkName, const String& rLinkData );

    BOOL RequestHelp( Window* pWindow, SdrView* pView, const HelpEvent& rEvt );

    virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createUnoPage();
};

#endif     // _DPAGE_HXX

<commit_msg>INTEGRATION: CWS warnings01 (1.4.344); FILE MERGED 2006/05/15 12:30:43 sb 1.4.344.2: #i53898# Made code warning-free and/or compile at all after resync to SRC680m162. 2006/05/12 16:42:52 sb 1.4.344.1: #i53898# Made code warning-free and/or compile at all after resync to SRC680m162.<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: dpage.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-19 12:39:18 $
 *
 *  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 _DPAGE_HXX
#define _DPAGE_HXX

#ifndef _FM_FMPAGE_HXX
#include <svx/fmpage.hxx>
#endif

#ifndef _SVDOBJ_HXX
#include <svx/svdobj.hxx>
#endif

class SdrPageGridFrameList;
class SwDrawDocument;
class SwDoc;

class SwDPage : public FmFormPage, public SdrObjUserCall
{
    SdrPageGridFrameList*   pGridLst;
    SwDoc&                  rDoc;

public:
    SwDPage(SwDrawDocument& rNewModel, BOOL bMasterPage=FALSE);
    ~SwDPage();

    // #i3694#
    // This GetOffset() method is not needed anymore, it even leads to errors.
    // virtual Point GetOffset() const;
    virtual SdrObject* ReplaceObject( SdrObject* pNewObj, ULONG nObjNum );

    virtual const SdrPageGridFrameList* GetGridFrameList(const SdrPageView* pPV,
                                    const Rectangle *pRect) const;

    BOOL RequestHelp( Window* pWindow, SdrView* pView, const HelpEvent& rEvt );

    virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > createUnoPage();
};

#endif     // _DPAGE_HXX

<|endoftext|>