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

#include "PresentationViewShell.hxx"

#ifndef _SFXREQUEST_HXX //autogen
#include <sfx2/request.hxx>
#endif
#ifndef _SFX_TOPFRM_HXX
#include <sfx2/topfrm.hxx>
#endif
#ifndef _SFX_DISPATCH_HXX
#include <sfx2/dispatch.hxx>
#endif

#include <sfx2/objface.hxx>

#include <svx/svxids.hrc>
#include <sfx2/app.hxx>
#ifndef SD_FRAME_VIEW
#include "FrameView.hxx"
#endif
#include "sdresid.hxx"
#include "DrawDocShell.hxx"
#ifndef _SD_SLIDESHOW_HXX
#include "slideshow.hxx"
#endif
#include "sdattr.hxx"
#include "sdpage.hxx"
#include "drawdoc.hxx"
#ifndef SD_DRAW_VIEW_HXX
#include "drawview.hxx"
#endif
#include "app.hrc"
#include "strings.hrc"
#include "glob.hrc"
#include "PaneManager.hxx"
#ifndef SD_VIEW_SHELL_BASE_HXX
#include "ViewShellBase.hxx"
#endif
#ifndef SD_FACTORY_IDS_HXX
#include "FactoryIds.hxx"
#endif

// #110496#
#include "slideshow.hxx"
#include "fupoor.hxx"
#include "Window.hxx"

#define PresentationViewShell
using namespace sd;
#include "sdslots.hxx"

namespace sd {

// -------------------
// - PresentationViewShell -
// -------------------

SFX_IMPL_INTERFACE( PresentationViewShell, DrawViewShell, SdResId( STR_PRESVIEWSHELL ) )
{
    SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS | SFX_VISIBILITY_STANDARD |
                                SFX_VISIBILITY_FULLSCREEN | SFX_VISIBILITY_SERVER,
                                SdResId(RID_DRAW_TOOLBOX));
    SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_APPLICATION | SFX_VISIBILITY_DESKTOP | SFX_VISIBILITY_STANDARD | SFX_VISIBILITY_CLIENT | SFX_VISIBILITY_VIEWER | SFX_VISIBILITY_READONLYDOC,
                                SdResId(RID_DRAW_VIEWER_TOOLBOX) );
    SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OPTIONS | SFX_VISIBILITY_STANDARD |
                                SFX_VISIBILITY_SERVER,
                                SdResId(RID_DRAW_OPTIONS_TOOLBOX));
    SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_COMMONTASK | SFX_VISIBILITY_STANDARD |
                                SFX_VISIBILITY_SERVER,
                                SdResId(RID_DRAW_COMMONTASK_TOOLBOX));
}

TYPEINIT1( PresentationViewShell, DrawViewShell );

PresentationViewShell::PresentationViewShell (
    SfxViewFrame* pFrame,
    ViewShellBase& rViewShellBase,
    ::Window* pParentWindow,
    FrameView* pFrameView)
    : DrawViewShell (
        pFrame,
        rViewShellBase,
        pParentWindow,
        PK_STANDARD,
        pFrameView),
    mbShowStarted( sal_False )
{
    if( GetDocSh() && GetDocSh()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
        maOldVisArea = GetDocSh()->GetVisArea( ASPECT_CONTENT );
    meShellType = ST_PRESENTATION;
}

PresentationViewShell::PresentationViewShell (
    SfxViewFrame* pFrame,
    ::Window* pParentWindow,
    const DrawViewShell& rShell)
    : DrawViewShell (pFrame, pParentWindow, rShell),
      mbShowStarted( sal_False )
{
    if( GetDocSh() && GetDocSh()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
        maOldVisArea = GetDocSh()->GetVisArea( ASPECT_CONTENT );
    meShellType = ST_PRESENTATION;
}

PresentationViewShell::~PresentationViewShell (void)
{
    if( GetDocSh() && GetDocSh()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED && !maOldVisArea.IsEmpty() )
        GetDocSh()->SetVisArea( maOldVisArea );

    if( GetViewFrame() && GetViewFrame()->GetTopFrame() )
    {
        WorkWindow* pWorkWindow = (WorkWindow*) GetViewFrame()->GetTopFrame()->GetWindow().GetParent();

        if( pWorkWindow )
            pWorkWindow->StartPresentationMode( FALSE, mpSlideShow ? mpSlideShow->isAlwaysOnTop() : 0 );
    }

    if( mpSlideShow )
    {
        mpSlideShow->deactivate();
        mpSlideShow->stopShow();
        mpSlideShow->dispose();
        delete mpSlideShow;
        mpSlideShow = NULL;
    }
}

void PresentationViewShell::FinishInitialization (
    FrameView* pFrameView,
    SfxRequest& rRequest,
    USHORT nPageNumber)
{
    DrawViewShell::Init();

    // Use the frame view that comes form the view shell that initiated our
    // creation.
    if (pFrameView != NULL)
    {
        GetFrameView()->Disconnect();
        SetFrameView (pFrameView);
        pFrameView->Connect();
    }
    SetRuler(false);
    SwitchPage (nPageNumber);
    WriteFrameViewData();

    mpSlideShow = new sd::Slideshow( this, GetView(), GetDoc() );
    mpSlideShow->setRehearseTimings(
        rRequest.GetSlot() == SID_REHEARSE_TIMINGS );
    GetActiveWindow()->GrabFocus();

    // Start the show.
    if (mpSlideShow->startShow(0))
        mbShowStarted = sal_True;
    else
    {
        delete mpSlideShow;
        mpSlideShow = 0;
    }

    GetViewFrame()->Show();

    Activate(TRUE);
}

SvxRuler* PresentationViewShell::CreateHRuler(::sd::Window* pWin, BOOL bIsFirst)
{
    return NULL;
}

SvxRuler* PresentationViewShell::CreateVRuler(::sd::Window* pWin)
{
    return NULL;
}

void PresentationViewShell::Activate( BOOL bIsMDIActivate )
{
    DrawViewShell::Activate( bIsMDIActivate );

    if( bIsMDIActivate )
    {
        ::sd::View*     pView = GetView();
        SfxBoolItem aItem( SID_NAVIGATOR_INIT, TRUE );

        GetViewFrame()->GetDispatcher()->Execute( SID_NAVIGATOR_INIT, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aItem, 0L );

        if( mpSlideShow)
            mpSlideShow->activate();

        if( pFuActual )
            pFuActual->Activate();

        if( pView )
            pView->ShowMarkHdl( NULL );
    }

    if( bIsMDIActivate )
        ReadFrameViewData( pFrameView );
    GetDocSh()->Connect( this );

    if( mpSlideShow && !mbShowStarted )
    {
        if (mpSlideShow->startShow(0))
            mbShowStarted = sal_True;
        else {
            delete mpSlideShow;
            mpSlideShow = 0;
        }
    }
}

void PresentationViewShell::Paint( const Rectangle& rRect, ::sd::Window* pWin )
{
    // allow paints only if show is already started
    if( mbShowStarted && mpSlideShow )
        mpSlideShow->paint(rRect);
}

void PresentationViewShell::CreateFullScreenShow (
    ViewShell* pOriginShell,
    SfxRequest& rRequest)
{
    SdDrawDocument* pDoc = pOriginShell->GetDoc();
    SdPage* pCurrentPage = pOriginShell->GetActualPage();

    SFX_REQUEST_ARG (rRequest, pAlwaysOnTop, SfxBoolItem,
        ATTR_PRESENT_ALWAYS_ON_TOP, FALSE);
    bool bAlwaysOnTop =
        ((rRequest.GetSlot() !=  SID_REHEARSE_TIMINGS) && pAlwaysOnTop )
        ? pAlwaysOnTop->GetValue()
        : pDoc->getPresentationSettings().mbAlwaysOnTop;

    WorkWindow* pWorkWindow = new WorkWindow (
        NULL,
        WB_HIDE | WB_CLIPCHILDREN);
    pWorkWindow->StartPresentationMode (
        TRUE,
        bAlwaysOnTop ? PRESENTATION_HIDEALLAPPS : 0);
    pWorkWindow->SetBackground(Wallpaper(COL_BLACK));
    if (pWorkWindow->IsVisible())
    {
        // The new frame is created hidden.  To make it visible and activate
        // the new view shell--a prerequisite to process slot calls and
        // initialize its panes--a GrabFocus() has to be called later on.
        SfxTopFrame* pNewFrame = SfxTopFrame::Create (
            pDoc->GetDocSh(),
            pWorkWindow,
            PRESENTATION_FACTORY_ID,
            TRUE);
        pNewFrame->SetPresentationMode (TRUE);

        ViewShellBase* pBase = static_cast<ViewShellBase*>(
            pNewFrame->GetCurrentViewFrame()->GetViewShell());
        if (pBase != NULL)
        {
            // Get the page where the show is to be started.  This normally
            // is the current page of the shell from which the show has been
            // started.  This, however, may be NULL, e.g. when started from
            // the slide sorter and that has an empty selection.
            USHORT nStartPage = 0;
            if (pCurrentPage != NULL)
                nStartPage = (pCurrentPage->GetPageNum() - 1) / 2;

//            pBase->GetViewFrame()->Show();
            // The following GrabFocus() is responsible for activating the
            // new view shell.  Without it the screen remains blank (under
            // Windows and some Linux variants.)
            pBase->GetWindow()->GrabFocus();

            PresentationViewShell* pShell = PTR_CAST(PresentationViewShell, pBase->GetMainViewShell());
            if (pShell != NULL)
                pShell->FinishInitialization (
                    pOriginShell->GetFrameView(),
                    rRequest,
                    nStartPage);
        }
    }
}

} // end of namespace sd
<commit_msg>INTEGRATION: CWS ooo19126 (1.26.154); FILE MERGED 2005/09/05 13:25:59 rt 1.26.154.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: presvish.cxx,v $
 *
 *  $Revision: 1.27 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 07:15: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
 *
 ************************************************************************/

#include "PresentationViewShell.hxx"

#ifndef _SFXREQUEST_HXX //autogen
#include <sfx2/request.hxx>
#endif
#ifndef _SFX_TOPFRM_HXX
#include <sfx2/topfrm.hxx>
#endif
#ifndef _SFX_DISPATCH_HXX
#include <sfx2/dispatch.hxx>
#endif

#include <sfx2/objface.hxx>

#include <svx/svxids.hrc>
#include <sfx2/app.hxx>
#ifndef SD_FRAME_VIEW
#include "FrameView.hxx"
#endif
#include "sdresid.hxx"
#include "DrawDocShell.hxx"
#ifndef _SD_SLIDESHOW_HXX
#include "slideshow.hxx"
#endif
#include "sdattr.hxx"
#include "sdpage.hxx"
#include "drawdoc.hxx"
#ifndef SD_DRAW_VIEW_HXX
#include "drawview.hxx"
#endif
#include "app.hrc"
#include "strings.hrc"
#include "glob.hrc"
#include "PaneManager.hxx"
#ifndef SD_VIEW_SHELL_BASE_HXX
#include "ViewShellBase.hxx"
#endif
#ifndef SD_FACTORY_IDS_HXX
#include "FactoryIds.hxx"
#endif

// #110496#
#include "slideshow.hxx"
#include "fupoor.hxx"
#include "Window.hxx"

#define PresentationViewShell
using namespace sd;
#include "sdslots.hxx"

namespace sd {

// -------------------
// - PresentationViewShell -
// -------------------

SFX_IMPL_INTERFACE( PresentationViewShell, DrawViewShell, SdResId( STR_PRESVIEWSHELL ) )
{
    SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_TOOLS | SFX_VISIBILITY_STANDARD |
                                SFX_VISIBILITY_FULLSCREEN | SFX_VISIBILITY_SERVER,
                                SdResId(RID_DRAW_TOOLBOX));
    SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_APPLICATION | SFX_VISIBILITY_DESKTOP | SFX_VISIBILITY_STANDARD | SFX_VISIBILITY_CLIENT | SFX_VISIBILITY_VIEWER | SFX_VISIBILITY_READONLYDOC,
                                SdResId(RID_DRAW_VIEWER_TOOLBOX) );
    SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OPTIONS | SFX_VISIBILITY_STANDARD |
                                SFX_VISIBILITY_SERVER,
                                SdResId(RID_DRAW_OPTIONS_TOOLBOX));
    SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_COMMONTASK | SFX_VISIBILITY_STANDARD |
                                SFX_VISIBILITY_SERVER,
                                SdResId(RID_DRAW_COMMONTASK_TOOLBOX));
}

TYPEINIT1( PresentationViewShell, DrawViewShell );

PresentationViewShell::PresentationViewShell (
    SfxViewFrame* pFrame,
    ViewShellBase& rViewShellBase,
    ::Window* pParentWindow,
    FrameView* pFrameView)
    : DrawViewShell (
        pFrame,
        rViewShellBase,
        pParentWindow,
        PK_STANDARD,
        pFrameView),
    mbShowStarted( sal_False )
{
    if( GetDocSh() && GetDocSh()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
        maOldVisArea = GetDocSh()->GetVisArea( ASPECT_CONTENT );
    meShellType = ST_PRESENTATION;
}

PresentationViewShell::PresentationViewShell (
    SfxViewFrame* pFrame,
    ::Window* pParentWindow,
    const DrawViewShell& rShell)
    : DrawViewShell (pFrame, pParentWindow, rShell),
      mbShowStarted( sal_False )
{
    if( GetDocSh() && GetDocSh()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
        maOldVisArea = GetDocSh()->GetVisArea( ASPECT_CONTENT );
    meShellType = ST_PRESENTATION;
}

PresentationViewShell::~PresentationViewShell (void)
{
    if( GetDocSh() && GetDocSh()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED && !maOldVisArea.IsEmpty() )
        GetDocSh()->SetVisArea( maOldVisArea );

    if( GetViewFrame() && GetViewFrame()->GetTopFrame() )
    {
        WorkWindow* pWorkWindow = (WorkWindow*) GetViewFrame()->GetTopFrame()->GetWindow().GetParent();

        if( pWorkWindow )
            pWorkWindow->StartPresentationMode( FALSE, mpSlideShow ? mpSlideShow->isAlwaysOnTop() : 0 );
    }

    if( mpSlideShow )
    {
        mpSlideShow->deactivate();
        mpSlideShow->stopShow();
        mpSlideShow->dispose();
        delete mpSlideShow;
        mpSlideShow = NULL;
    }
}

void PresentationViewShell::FinishInitialization (
    FrameView* pFrameView,
    SfxRequest& rRequest,
    USHORT nPageNumber)
{
    DrawViewShell::Init();

    // Use the frame view that comes form the view shell that initiated our
    // creation.
    if (pFrameView != NULL)
    {
        GetFrameView()->Disconnect();
        SetFrameView (pFrameView);
        pFrameView->Connect();
    }
    SetRuler(false);
    SwitchPage (nPageNumber);
    WriteFrameViewData();

    mpSlideShow = new sd::Slideshow( this, GetView(), GetDoc() );
    mpSlideShow->setRehearseTimings(
        rRequest.GetSlot() == SID_REHEARSE_TIMINGS );
    GetActiveWindow()->GrabFocus();

    // Start the show.
    if (mpSlideShow->startShow(0))
        mbShowStarted = sal_True;
    else
    {
        delete mpSlideShow;
        mpSlideShow = 0;
    }

    GetViewFrame()->Show();

    Activate(TRUE);
}

SvxRuler* PresentationViewShell::CreateHRuler(::sd::Window* pWin, BOOL bIsFirst)
{
    return NULL;
}

SvxRuler* PresentationViewShell::CreateVRuler(::sd::Window* pWin)
{
    return NULL;
}

void PresentationViewShell::Activate( BOOL bIsMDIActivate )
{
    DrawViewShell::Activate( bIsMDIActivate );

    if( bIsMDIActivate )
    {
        ::sd::View*     pView = GetView();
        SfxBoolItem aItem( SID_NAVIGATOR_INIT, TRUE );

        GetViewFrame()->GetDispatcher()->Execute( SID_NAVIGATOR_INIT, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aItem, 0L );

        if( mpSlideShow)
            mpSlideShow->activate();

        if( pFuActual )
            pFuActual->Activate();

        if( pView )
            pView->ShowMarkHdl( NULL );
    }

    if( bIsMDIActivate )
        ReadFrameViewData( pFrameView );
    GetDocSh()->Connect( this );

    if( mpSlideShow && !mbShowStarted )
    {
        if (mpSlideShow->startShow(0))
            mbShowStarted = sal_True;
        else {
            delete mpSlideShow;
            mpSlideShow = 0;
        }
    }
}

void PresentationViewShell::Paint( const Rectangle& rRect, ::sd::Window* pWin )
{
    // allow paints only if show is already started
    if( mbShowStarted && mpSlideShow )
        mpSlideShow->paint(rRect);
}

void PresentationViewShell::CreateFullScreenShow (
    ViewShell* pOriginShell,
    SfxRequest& rRequest)
{
    SdDrawDocument* pDoc = pOriginShell->GetDoc();
    SdPage* pCurrentPage = pOriginShell->GetActualPage();

    SFX_REQUEST_ARG (rRequest, pAlwaysOnTop, SfxBoolItem,
        ATTR_PRESENT_ALWAYS_ON_TOP, FALSE);
    bool bAlwaysOnTop =
        ((rRequest.GetSlot() !=  SID_REHEARSE_TIMINGS) && pAlwaysOnTop )
        ? pAlwaysOnTop->GetValue()
        : pDoc->getPresentationSettings().mbAlwaysOnTop;

    WorkWindow* pWorkWindow = new WorkWindow (
        NULL,
        WB_HIDE | WB_CLIPCHILDREN);
    pWorkWindow->StartPresentationMode (
        TRUE,
        bAlwaysOnTop ? PRESENTATION_HIDEALLAPPS : 0);
    pWorkWindow->SetBackground(Wallpaper(COL_BLACK));
    if (pWorkWindow->IsVisible())
    {
        // The new frame is created hidden.  To make it visible and activate
        // the new view shell--a prerequisite to process slot calls and
        // initialize its panes--a GrabFocus() has to be called later on.
        SfxTopFrame* pNewFrame = SfxTopFrame::Create (
            pDoc->GetDocSh(),
            pWorkWindow,
            PRESENTATION_FACTORY_ID,
            TRUE);
        pNewFrame->SetPresentationMode (TRUE);

        ViewShellBase* pBase = static_cast<ViewShellBase*>(
            pNewFrame->GetCurrentViewFrame()->GetViewShell());
        if (pBase != NULL)
        {
            // Get the page where the show is to be started.  This normally
            // is the current page of the shell from which the show has been
            // started.  This, however, may be NULL, e.g. when started from
            // the slide sorter and that has an empty selection.
            USHORT nStartPage = 0;
            if (pCurrentPage != NULL)
                nStartPage = (pCurrentPage->GetPageNum() - 1) / 2;

//            pBase->GetViewFrame()->Show();
            // The following GrabFocus() is responsible for activating the
            // new view shell.  Without it the screen remains blank (under
            // Windows and some Linux variants.)
            pBase->GetWindow()->GrabFocus();

            PresentationViewShell* pShell = PTR_CAST(PresentationViewShell, pBase->GetMainViewShell());
            if (pShell != NULL)
                pShell->FinishInitialization (
                    pOriginShell->GetFrameView(),
                    rRequest,
                    nStartPage);
        }
    }
}

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


<commit_before>// Copyright Daniel Wallin, Arvid Norberg 2006. Use, modification and distribution is
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <libtorrent/session.hpp>
#include <libtorrent/torrent.hpp>
#include <libtorrent/storage.hpp>
#include <boost/python.hpp>
#include "gil.hpp"

using namespace boost::python;
using namespace libtorrent;

extern char const* session_status_doc;
extern char const* session_status_has_incoming_connections_doc;
extern char const* session_status_upload_rate_doc;
extern char const* session_status_download_rate_doc;
extern char const* session_status_payload_upload_rate_doc;
extern char const* session_status_payload_download_rate_doc;
extern char const* session_status_total_download_doc;
extern char const* session_status_total_upload_doc;
extern char const* session_status_total_payload_download_doc;
extern char const* session_status_total_payload_upload_doc;
extern char const* session_status_num_peers_doc;
extern char const* session_status_dht_nodes_doc;
extern char const* session_status_cache_nodes_doc;
extern char const* session_status_dht_torrents_doc;

extern char const* session_doc;
extern char const* session_init_doc;
extern char const* session_listen_on_doc;
extern char const* session_is_listening_doc;
extern char const* session_listen_port_doc;
extern char const* session_status_m_doc;
extern char const* session_start_dht_doc;
extern char const* session_stop_dht_doc;
extern char const* session_dht_state_doc;
extern char const* session_add_torrent_doc;
extern char const* session_remove_torrent_doc;
extern char const* session_set_download_rate_limit_doc;
extern char const* session_download_rate_limit_doc;
extern char const* session_set_upload_rate_limit_doc;
extern char const* session_upload_rate_limit_doc;
extern char const* session_set_max_uploads_doc;
extern char const* session_set_max_connections_doc;
extern char const* session_set_max_half_open_connections_doc;
extern char const* session_num_connections_doc;
extern char const* session_set_settings_doc;
extern char const* session_set_pe_settings_doc;
extern char const* session_get_pe_settings_doc;
extern char const* session_set_severity_level_doc;
extern char const* session_pop_alert_doc;
extern char const* session_start_upnp_doc;
extern char const* session_stop_upnp_doc;
extern char const* session_start_natpmp_doc;
extern char const* session_stop_natpmp_doc;

namespace
{

  bool listen_on(session& s, int min_, int max_, char const* interface)
  {
      allow_threading_guard guard;
      return s.listen_on(std::make_pair(min_, max_), interface);
  }

  struct invoke_extension_factory
  {
      invoke_extension_factory(object const& callback)
        : cb(callback)
      {}

      boost::shared_ptr<torrent_plugin> operator()(torrent* t, void*)
      {
          lock_gil lock;
          return extract<boost::shared_ptr<torrent_plugin> >(cb(ptr(t)))();
      }

      object cb;
  };

  void add_extension(session& s, object const& e)
  {
      allow_threading_guard guard;
      s.add_extension(invoke_extension_factory(e));
  }

  torrent_handle add_torrent(session& s, torrent_info const& ti
    , boost::filesystem::path const& save, entry const& resume
    , storage_mode_t storage_mode, bool paused)
  {
    allow_threading_guard guard;
    return s.add_torrent(ti, save, resume, storage_mode, paused, default_storage_constructor);
  }

} // namespace unnamed

void bind_session()
{
    class_<session_status>("session_status", session_status_doc)
        .def_readonly(
            "has_incoming_connections", &session_status::has_incoming_connections
          , session_status_has_incoming_connections_doc
        )
        .def_readonly(
            "upload_rate", &session_status::upload_rate
          , session_status_upload_rate_doc
        )
        .def_readonly(
            "download_rate", &session_status::download_rate
          , session_status_download_rate_doc
        )
        .def_readonly(
            "payload_upload_rate", &session_status::payload_upload_rate
          , session_status_payload_upload_rate_doc
        )
        .def_readonly(
            "payload_download_rate", &session_status::payload_download_rate
          , session_status_payload_download_rate_doc
        )
        .def_readonly(
            "total_download", &session_status::total_download
          , session_status_total_download_doc
        )
        .def_readonly(
            "total_upload", &session_status::total_upload
          , session_status_total_upload_doc
        )
        .def_readonly(
            "total_payload_download", &session_status::total_payload_download
          , session_status_total_payload_download_doc
        )
        .def_readonly(
            "total_payload_upload", &session_status::total_payload_upload
          , session_status_total_payload_upload_doc
        )
        .def_readonly(
            "num_peers", &session_status::num_peers
          , session_status_num_peers_doc
        )
#ifndef TORRENT_DISABLE_DHT
        .def_readonly(
            "dht_nodes", &session_status::dht_nodes
          , session_status_dht_nodes_doc
        )
        .def_readonly(
            "dht_cache_nodes", &session_status::dht_node_cache
          , session_status_cache_nodes_doc
        )
        .def_readonly(
            "dht_torrents", &session_status::dht_torrents
          , session_status_dht_torrents_doc
        )
#endif
        ;

    enum_<storage_mode_t>("storage_mode_t")
        .value("storage_mode_allocate", storage_mode_allocate)
        .value("storage_mode_compact", storage_mode_compact)
        .value("storage_mode_sparse", storage_mode_sparse)
    ;

    enum_<session::options_t>("options_t")
        .value("none", session::none)
        .value("delete_files", session::delete_files)
    ;

    class_<session, boost::noncopyable>("session", session_doc, no_init)
        .def(
            init<fingerprint>(arg("fingerprint")=fingerprint("LT",0,1,0,0), session_init_doc)
        )
        .def(
            "listen_on", &listen_on
          , (arg("min"), "max", arg("interface") = (char const*)0)
          , session_listen_on_doc
        )
        .def("is_listening", allow_threads(&session::is_listening), session_is_listening_doc)
        .def("listen_port", allow_threads(&session::listen_port), session_listen_port_doc)
        .def("status", allow_threads(&session::status), session_status_m_doc)
#ifndef TORRENT_DISABLE_DHT
        .def("start_dht", allow_threads(&session::start_dht), session_start_dht_doc)
        .def("stop_dht", allow_threads(&session::stop_dht), session_stop_dht_doc)
        .def("dht_state", allow_threads(&session::dht_state), session_dht_state_doc)
#endif
        .def(
            "add_torrent", &add_torrent
          , (
                arg("resume_data") = entry(), arg("compact_mode") = true
                , arg("paused") = false
            )
          , session_add_torrent_doc
        )
        .def("remove_torrent", allow_threads(&session::remove_torrent), session_remove_torrent_doc)
        .def(
            "set_download_rate_limit", allow_threads(&session::set_download_rate_limit)
          , session_set_download_rate_limit_doc
        )
        .def(
            "download_rate_limit", allow_threads(&session::download_rate_limit)
          , session_download_rate_limit_doc
        )

        .def(
            "set_upload_rate_limit", allow_threads(&session::set_upload_rate_limit)
          , session_set_upload_rate_limit_doc
        )
        .def(
            "upload_rate_limit", allow_threads(&session::upload_rate_limit)
          , session_upload_rate_limit_doc
        )

        .def(
            "set_max_uploads", allow_threads(&session::set_max_uploads)
          , session_set_max_uploads_doc
        )
        .def(
            "set_max_connections", allow_threads(&session::set_max_connections)
          , session_set_max_connections_doc
        )
        .def(
            "set_max_half_open_connections", allow_threads(&session::set_max_half_open_connections)
          , session_set_max_half_open_connections_doc
        )
        .def(
            "num_connections", allow_threads(&session::num_connections)
          , session_num_connections_doc
        )
        .def("set_settings", allow_threads(&session::set_settings), session_set_settings_doc)
        .def("set_pe_settings", allow_threads(&session::set_pe_settings), session_set_pe_settings_doc)
        .def("get_pe_settings", allow_threads(&session::get_pe_settings), return_value_policy<copy_const_reference>())
        .def(
            "set_severity_level", allow_threads(&session::set_severity_level)
          , session_set_severity_level_doc
        )
        .def("pop_alert", allow_threads(&session::pop_alert), session_pop_alert_doc)
        .def("add_extension", &add_extension)
        .def("set_peer_proxy", allow_threads(&session::set_peer_proxy))
        .def("set_tracker_proxy", allow_threads(&session::set_tracker_proxy))
        .def("set_web_seed_proxy", allow_threads(&session::set_web_seed_proxy))
#ifndef TORRENT_DISABLE_DHT
        .def("set_dht_proxy", allow_threads(&session::set_dht_proxy))
#endif
        .def("start_upnp", allow_threads(&session::start_upnp), session_start_upnp_doc)
        .def("stop_upnp", allow_threads(&session::stop_upnp), session_stop_upnp_doc)
        .def("start_natpmp", allow_threads(&session::start_natpmp), session_start_natpmp_doc)
        .def("stop_natpmp", allow_threads(&session::stop_natpmp), session_stop_natpmp_doc)
        ;

    register_ptr_to_python<std::auto_ptr<alert> >();
}

<commit_msg>python binding fix<commit_after>// Copyright Daniel Wallin, Arvid Norberg 2006. Use, modification and distribution is
// subject to the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <libtorrent/session.hpp>
#include <libtorrent/torrent.hpp>
#include <libtorrent/storage.hpp>
#include <boost/python.hpp>
#include "gil.hpp"

using namespace boost::python;
using namespace libtorrent;

extern char const* session_status_doc;
extern char const* session_status_has_incoming_connections_doc;
extern char const* session_status_upload_rate_doc;
extern char const* session_status_download_rate_doc;
extern char const* session_status_payload_upload_rate_doc;
extern char const* session_status_payload_download_rate_doc;
extern char const* session_status_total_download_doc;
extern char const* session_status_total_upload_doc;
extern char const* session_status_total_payload_download_doc;
extern char const* session_status_total_payload_upload_doc;
extern char const* session_status_num_peers_doc;
extern char const* session_status_dht_nodes_doc;
extern char const* session_status_cache_nodes_doc;
extern char const* session_status_dht_torrents_doc;

extern char const* session_doc;
extern char const* session_init_doc;
extern char const* session_listen_on_doc;
extern char const* session_is_listening_doc;
extern char const* session_listen_port_doc;
extern char const* session_status_m_doc;
extern char const* session_start_dht_doc;
extern char const* session_stop_dht_doc;
extern char const* session_dht_state_doc;
extern char const* session_add_torrent_doc;
extern char const* session_remove_torrent_doc;
extern char const* session_set_download_rate_limit_doc;
extern char const* session_download_rate_limit_doc;
extern char const* session_set_upload_rate_limit_doc;
extern char const* session_upload_rate_limit_doc;
extern char const* session_set_max_uploads_doc;
extern char const* session_set_max_connections_doc;
extern char const* session_set_max_half_open_connections_doc;
extern char const* session_num_connections_doc;
extern char const* session_set_settings_doc;
extern char const* session_set_pe_settings_doc;
extern char const* session_get_pe_settings_doc;
extern char const* session_set_severity_level_doc;
extern char const* session_pop_alert_doc;
extern char const* session_start_upnp_doc;
extern char const* session_stop_upnp_doc;
extern char const* session_start_natpmp_doc;
extern char const* session_stop_natpmp_doc;

namespace
{

  bool listen_on(session& s, int min_, int max_, char const* interface)
  {
      allow_threading_guard guard;
      return s.listen_on(std::make_pair(min_, max_), interface);
  }

  struct invoke_extension_factory
  {
      invoke_extension_factory(object const& callback)
        : cb(callback)
      {}

      boost::shared_ptr<torrent_plugin> operator()(torrent* t, void*)
      {
          lock_gil lock;
          return extract<boost::shared_ptr<torrent_plugin> >(cb(ptr(t)))();
      }

      object cb;
  };

  void add_extension(session& s, object const& e)
  {
      allow_threading_guard guard;
      s.add_extension(invoke_extension_factory(e));
  }

  torrent_handle add_torrent(session& s, torrent_info const& ti
    , boost::filesystem::path const& save, entry const& resume
    , storage_mode_t storage_mode, bool paused)
  {
    allow_threading_guard guard;
    return s.add_torrent(ti, save, resume, storage_mode, paused, default_storage_constructor);
  }

} // namespace unnamed

void bind_session()
{
    class_<session_status>("session_status", session_status_doc)
        .def_readonly(
            "has_incoming_connections", &session_status::has_incoming_connections
          , session_status_has_incoming_connections_doc
        )
        .def_readonly(
            "upload_rate", &session_status::upload_rate
          , session_status_upload_rate_doc
        )
        .def_readonly(
            "download_rate", &session_status::download_rate
          , session_status_download_rate_doc
        )
        .def_readonly(
            "payload_upload_rate", &session_status::payload_upload_rate
          , session_status_payload_upload_rate_doc
        )
        .def_readonly(
            "payload_download_rate", &session_status::payload_download_rate
          , session_status_payload_download_rate_doc
        )
        .def_readonly(
            "total_download", &session_status::total_download
          , session_status_total_download_doc
        )
        .def_readonly(
            "total_upload", &session_status::total_upload
          , session_status_total_upload_doc
        )
        .def_readonly(
            "total_payload_download", &session_status::total_payload_download
          , session_status_total_payload_download_doc
        )
        .def_readonly(
            "total_payload_upload", &session_status::total_payload_upload
          , session_status_total_payload_upload_doc
        )
        .def_readonly(
            "num_peers", &session_status::num_peers
          , session_status_num_peers_doc
        )
#ifndef TORRENT_DISABLE_DHT
        .def_readonly(
            "dht_nodes", &session_status::dht_nodes
          , session_status_dht_nodes_doc
        )
        .def_readonly(
            "dht_cache_nodes", &session_status::dht_node_cache
          , session_status_cache_nodes_doc
        )
        .def_readonly(
            "dht_torrents", &session_status::dht_torrents
          , session_status_dht_torrents_doc
        )
#endif
        ;

    enum_<storage_mode_t>("storage_mode_t")
        .value("storage_mode_allocate", storage_mode_allocate)
        .value("storage_mode_compact", storage_mode_compact)
        .value("storage_mode_sparse", storage_mode_sparse)
    ;

    enum_<session::options_t>("options_t")
        .value("none", session::none)
        .value("delete_files", session::delete_files)
    ;

    class_<session, boost::noncopyable>("session", session_doc, no_init)
        .def(
            init<fingerprint>(arg("fingerprint")=fingerprint("LT",0,1,0,0), session_init_doc)
        )
        .def(
            "listen_on", &listen_on
          , (arg("min"), "max", arg("interface") = (char const*)0)
          , session_listen_on_doc
        )
        .def("is_listening", allow_threads(&session::is_listening), session_is_listening_doc)
        .def("listen_port", allow_threads(&session::listen_port), session_listen_port_doc)
        .def("status", allow_threads(&session::status), session_status_m_doc)
#ifndef TORRENT_DISABLE_DHT
        .def("start_dht", allow_threads(&session::start_dht), session_start_dht_doc)
        .def("stop_dht", allow_threads(&session::stop_dht), session_stop_dht_doc)
        .def("dht_state", allow_threads(&session::dht_state), session_dht_state_doc)
#endif
        .def(
            "add_torrent", &add_torrent
          , (
                arg("resume_data") = entry(), arg("storage_mode") = storage_mode_sparse,
                arg("paused") = false
            )
          , session_add_torrent_doc
        )
        .def("remove_torrent", allow_threads(&session::remove_torrent), session_remove_torrent_doc)
        .def(
            "set_download_rate_limit", allow_threads(&session::set_download_rate_limit)
          , session_set_download_rate_limit_doc
        )
        .def(
            "download_rate_limit", allow_threads(&session::download_rate_limit)
          , session_download_rate_limit_doc
        )

        .def(
            "set_upload_rate_limit", allow_threads(&session::set_upload_rate_limit)
          , session_set_upload_rate_limit_doc
        )
        .def(
            "upload_rate_limit", allow_threads(&session::upload_rate_limit)
          , session_upload_rate_limit_doc
        )

        .def(
            "set_max_uploads", allow_threads(&session::set_max_uploads)
          , session_set_max_uploads_doc
        )
        .def(
            "set_max_connections", allow_threads(&session::set_max_connections)
          , session_set_max_connections_doc
        )
        .def(
            "set_max_half_open_connections", allow_threads(&session::set_max_half_open_connections)
          , session_set_max_half_open_connections_doc
        )
        .def(
            "num_connections", allow_threads(&session::num_connections)
          , session_num_connections_doc
        )
        .def("set_settings", allow_threads(&session::set_settings), session_set_settings_doc)
        .def("set_pe_settings", allow_threads(&session::set_pe_settings), session_set_pe_settings_doc)
        .def("get_pe_settings", allow_threads(&session::get_pe_settings), return_value_policy<copy_const_reference>())
        .def(
            "set_severity_level", allow_threads(&session::set_severity_level)
          , session_set_severity_level_doc
        )
        .def("pop_alert", allow_threads(&session::pop_alert), session_pop_alert_doc)
        .def("add_extension", &add_extension)
        .def("set_peer_proxy", allow_threads(&session::set_peer_proxy))
        .def("set_tracker_proxy", allow_threads(&session::set_tracker_proxy))
        .def("set_web_seed_proxy", allow_threads(&session::set_web_seed_proxy))
#ifndef TORRENT_DISABLE_DHT
        .def("set_dht_proxy", allow_threads(&session::set_dht_proxy))
#endif
        .def("start_upnp", allow_threads(&session::start_upnp), session_start_upnp_doc)
        .def("stop_upnp", allow_threads(&session::stop_upnp), session_stop_upnp_doc)
        .def("start_natpmp", allow_threads(&session::start_natpmp), session_start_natpmp_doc)
        .def("stop_natpmp", allow_threads(&session::stop_natpmp), session_stop_natpmp_doc)
        ;

    register_ptr_to_python<std::auto_ptr<alert> >();
}

<|endoftext|>


<commit_before><commit_msg>Parse it as a single address.<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: pfuncache.hxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: obo $ $Date: 2004-06-04 11:37:48 $
 *
 *  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 SC_PFUNCACHE_HXX
#define SC_PFUNCACHE_HXX

#ifndef SC_RANGELST_HXX
#include "rangelst.hxx"
#endif

class ScDocShell;
class ScMarkData;

/** Possible types of selection for print functions */

enum ScPrintSelectionMode
{
    SC_PRINTSEL_INVALID,
    SC_PRINTSEL_DOCUMENT,
    SC_PRINTSEL_CURSOR,
    SC_PRINTSEL_RANGE
};

/** Stores the selection in the ScPrintFuncCache so it is only used
    for the same selection again. */

class ScPrintSelectionStatus
{
    ScPrintSelectionMode    eMode;
    ScRangeList             aRanges;

public:
            ScPrintSelectionStatus() : eMode(SC_PRINTSEL_INVALID) {}
            ~ScPrintSelectionStatus() {}

    void    SetMode(ScPrintSelectionMode eNew)  { eMode = eNew; }
    void    SetRanges(const ScRangeList& rNew)  { aRanges = rNew; }

    BOOL    operator==(const ScPrintSelectionStatus& rOther) const
            { return eMode == rOther.eMode && aRanges == rOther.aRanges; }
};

/** Stores the data for printing that is needed from several sheets,
    so it doesn't have to be calculated for rendering each page. */

class ScPrintFuncCache
{
    ScPrintSelectionStatus  aSelection;
    ScDocShell*             pDocSh;
    long                    nTotalPages;
    long                    nPages[MAXTABCOUNT];
    long                    nFirstAttr[MAXTABCOUNT];

public:
            ScPrintFuncCache( ScDocShell* pD, const ScMarkData& rMark,
                                const ScPrintSelectionStatus& rStatus );
            ~ScPrintFuncCache();

    BOOL    IsSameSelection( const ScPrintSelectionStatus& rStatus ) const;

    long    GetPageCount() const                { return nTotalPages; }
    long    GetFirstAttr( SCTAB nTab ) const    { return nFirstAttr[nTab]; }
    SCTAB   GetTabForPage( long nPage ) const;
    long    GetTabStart( SCTAB nTab ) const;
    long    GetDisplayStart( SCTAB nTab ) const;
};

#endif

<commit_msg>INTEGRATION: CWS pdf02 (1.2.158); FILE MERGED 2004/10/01 11:57:01 nn 1.2.158.1: #i34865# handle internal links in PDF export<commit_after>/*************************************************************************
 *
 *  $RCSfile: pfuncache.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: pjunck $ $Date: 2004-10-28 09:56:48 $
 *
 *  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 SC_PFUNCACHE_HXX
#define SC_PFUNCACHE_HXX

#include <vector>

#ifndef _SV_GEN_HXX
#include <tools/gen.hxx>
#endif

#ifndef SC_RANGELST_HXX
#include "rangelst.hxx"
#endif

class ScDocShell;
class ScMarkData;

/** Possible types of selection for print functions */

enum ScPrintSelectionMode
{
    SC_PRINTSEL_INVALID,
    SC_PRINTSEL_DOCUMENT,
    SC_PRINTSEL_CURSOR,
    SC_PRINTSEL_RANGE
};

/** Stores the selection in the ScPrintFuncCache so it is only used
    for the same selection again. */

class ScPrintSelectionStatus
{
    ScPrintSelectionMode    eMode;
    ScRangeList             aRanges;

public:
            ScPrintSelectionStatus() : eMode(SC_PRINTSEL_INVALID) {}
            ~ScPrintSelectionStatus() {}

    void    SetMode(ScPrintSelectionMode eNew)  { eMode = eNew; }
    void    SetRanges(const ScRangeList& rNew)  { aRanges = rNew; }

    BOOL    operator==(const ScPrintSelectionStatus& rOther) const
            { return eMode == rOther.eMode && aRanges == rOther.aRanges; }
};

/** The range that is printed on a page (excluding repeated columns/rows),
    and its position on the page, used to find hyperlink targets. */

struct ScPrintPageLocation
{
    long        nPage;
    ScRange     aCellRange;
    Rectangle   aRectangle;     // pixels

    ScPrintPageLocation() :
        nPage(-1) {}            // default: invalid

    ScPrintPageLocation( long nP, const ScRange& rRange, const Rectangle& rRect ) :
        nPage(nP), aCellRange(rRange), aRectangle(rRect) {}
};

/** Stores the data for printing that is needed from several sheets,
    so it doesn't have to be calculated for rendering each page. */

class ScPrintFuncCache
{
    ScPrintSelectionStatus  aSelection;
    ScDocShell*             pDocSh;
    long                    nTotalPages;
    long                    nPages[MAXTABCOUNT];
    long                    nFirstAttr[MAXTABCOUNT];
    std::vector<ScPrintPageLocation> aLocations;
    bool                    bLocInitialized;

public:
            ScPrintFuncCache( ScDocShell* pD, const ScMarkData& rMark,
                                const ScPrintSelectionStatus& rStatus );
            ~ScPrintFuncCache();

    BOOL    IsSameSelection( const ScPrintSelectionStatus& rStatus ) const;

    void    InitLocations( const ScMarkData& rMark, OutputDevice* pDev );
    bool    FindLocation( const ScAddress& rCell, ScPrintPageLocation& rLocation ) const;

    long    GetPageCount() const                { return nTotalPages; }
    long    GetFirstAttr( SCTAB nTab ) const    { return nFirstAttr[nTab]; }
    SCTAB   GetTabForPage( long nPage ) const;
    long    GetTabStart( SCTAB nTab ) const;
    long    GetDisplayStart( SCTAB nTab ) const;
};

#endif

<|endoftext|>


<commit_before><commit_msg>coverity#1226486 Dereference null return value<commit_after><|endoftext|>


<commit_before>#include "unittest/gtest.hpp"
#include "clustering/immediate_consistency/branch/broadcaster.hpp"
#include "clustering/immediate_consistency/branch/listener.hpp"
#include "clustering/immediate_consistency/branch/replier.hpp"
#include "unittest/dummy_metadata_controller.hpp"
#include "unittest/dummy_protocol.hpp"
#include "unittest/clustering_utils.hpp"
#include "unittest/unittest_utils.hpp"

namespace unittest {

namespace {

void run_with_broadcaster(
        boost::function<void(
            mailbox_cluster_t *,
            boost::shared_ptr<metadata_readwrite_view_t<namespace_branch_metadata_t<dummy_protocol_t> > >,
            boost::scoped_ptr<broadcaster_t<dummy_protocol_t> > *,
            test_store_t *,
            boost::scoped_ptr<listener_t<dummy_protocol_t> > *
            )> fun)
{
    /* Set up a cluster so mailboxes can be created */
    simple_mailbox_cluster_t cluster;

    /* Set up a metadata meeting-place */
    namespace_branch_metadata_t<dummy_protocol_t> initial_metadata;
    dummy_metadata_controller_t<namespace_branch_metadata_t<dummy_protocol_t> > metadata_controller(initial_metadata);

    /* Set up a broadcaster and initial listener */
    test_store_t initial_store;
    cond_t interruptor;
    boost::scoped_ptr<listener_t<dummy_protocol_t> > initial_listener;
    boost::scoped_ptr<broadcaster_t<dummy_protocol_t> > broadcaster(
        new broadcaster_t<dummy_protocol_t>(
            &cluster,
            metadata_controller.get_view(),
            &initial_store.store,
            &interruptor,
            &initial_listener
        ));

    fun(&cluster, metadata_controller.get_view(), &broadcaster, &initial_store, &initial_listener);
}

void run_in_thread_pool_with_broadcaster(
        boost::function<void(
            mailbox_cluster_t *,
            boost::shared_ptr<metadata_readwrite_view_t<namespace_branch_metadata_t<dummy_protocol_t> > >,
            boost::scoped_ptr<broadcaster_t<dummy_protocol_t> > *,
            test_store_t *,
            boost::scoped_ptr<listener_t<dummy_protocol_t> > *
            )> fun)
{
    run_in_thread_pool(boost::bind(&run_with_broadcaster, fun));
}

/* `let_stuff_happen()` delays for some time to let events occur */
void let_stuff_happen() {
    nap(1000);
}

}   /* anonymous namespace */

/* The `ReadWrite` test just sends some reads and writes via the broadcaster to a
single mirror. */

void run_read_write_test(mailbox_cluster_t *cluster,
        boost::shared_ptr<metadata_readwrite_view_t<namespace_branch_metadata_t<dummy_protocol_t> > > metadata_view,
        boost::scoped_ptr<broadcaster_t<dummy_protocol_t> > *broadcaster,
        UNUSED test_store_t *store,
        boost::scoped_ptr<listener_t<dummy_protocol_t> > *initial_listener)
{
    /* Set up a replier so the broadcaster can handle operations */
    EXPECT_FALSE((*initial_listener)->get_outdated_signal()->is_pulsed());
    replier_t<dummy_protocol_t> replier(cluster, metadata_view, initial_listener->get());

    order_source_t order_source;

    /* Send some writes via the broadcaster to the mirror */
    std::map<std::string, std::string> values_inserted;
    for (int i = 0; i < 10; i++) {
        dummy_protocol_t::write_t w;
        std::string key = std::string(1, 'a' + rand() % 26);
        w.values[key] = values_inserted[key] = strprintf("%d", i);
        (*broadcaster)->write(w, order_source.check_in("unittest"));
    }

    /* Now send some reads */
    for (std::map<std::string, std::string>::iterator it = values_inserted.begin();
            it != values_inserted.end(); it++) {
        dummy_protocol_t::read_t r;
        r.keys.keys.insert((*it).first);
        dummy_protocol_t::read_response_t resp = (*broadcaster)->read(r, order_source.check_in("unittest"));
        EXPECT_EQ((*it).second, resp.values[(*it).first]);
    }
}
TEST(ClusteringBranch, ReadWrite) {
    run_in_thread_pool_with_broadcaster(&run_read_write_test);
}

/* The `Backfill` test starts up a node with one mirror, inserts some data, and
then adds another mirror. */

void run_backfill_test(mailbox_cluster_t *cluster,
        boost::shared_ptr<metadata_readwrite_view_t<namespace_branch_metadata_t<dummy_protocol_t> > > metadata_view,
        boost::scoped_ptr<broadcaster_t<dummy_protocol_t> > *broadcaster,
        test_store_t *store1,
        boost::scoped_ptr<listener_t<dummy_protocol_t> > *initial_listener)
{
    /* Set up a replier so the broadcaster can handle operations */
    EXPECT_FALSE((*initial_listener)->get_outdated_signal()->is_pulsed());
    replier_t<dummy_protocol_t> replier(cluster, metadata_view, initial_listener->get());

    order_source_t order_source;

    /* Start sending operations to the broadcaster */
    inserter_t inserter(
        boost::bind(&broadcaster_t<dummy_protocol_t>::write, broadcaster->get(), _1, _2),
        &order_source);
    nap(100);

    /* Set up a second mirror */
    test_store_t store2;
    cond_t interruptor;
    listener_t<dummy_protocol_t> listener2(
        cluster, metadata_view,
        &store2.store,
        (*broadcaster)->get_branch_id(),
        replier.get_backfiller_id(),
        &interruptor);

    EXPECT_FALSE((*initial_listener)->get_outdated_signal()->is_pulsed());
    EXPECT_FALSE(listener2.get_outdated_signal()->is_pulsed());

    nap(100);

    /* Stop the inserter, then let any lingering writes finish */
    inserter.stop();
    /* Let any lingering writes finish */
    let_stuff_happen();

    /* Confirm that both mirrors have all of the writes */
    for (std::map<std::string, std::string>::iterator it = inserter.values_inserted.begin();
            it != inserter.values_inserted.end(); it++) {
        EXPECT_EQ((*it).second, store1->underlying_store.values[(*it).first]);
        EXPECT_EQ((*it).second, store2.underlying_store.values[(*it).first]);
    }
}
TEST(ClusteringBranch, Backfill) {
    run_in_thread_pool_with_broadcaster(&run_backfill_test);
}

}   /* namespace unittest */
<commit_msg>Commented out the ClusteringBranch.ReadWrite test since #479 is still not fixed.<commit_after>#include "unittest/gtest.hpp"
#include "clustering/immediate_consistency/branch/broadcaster.hpp"
#include "clustering/immediate_consistency/branch/listener.hpp"
#include "clustering/immediate_consistency/branch/replier.hpp"
#include "unittest/dummy_metadata_controller.hpp"
#include "unittest/dummy_protocol.hpp"
#include "unittest/clustering_utils.hpp"
#include "unittest/unittest_utils.hpp"

namespace unittest {

namespace {

void run_with_broadcaster(
        boost::function<void(
            mailbox_cluster_t *,
            boost::shared_ptr<metadata_readwrite_view_t<namespace_branch_metadata_t<dummy_protocol_t> > >,
            boost::scoped_ptr<broadcaster_t<dummy_protocol_t> > *,
            test_store_t *,
            boost::scoped_ptr<listener_t<dummy_protocol_t> > *
            )> fun)
{
    /* Set up a cluster so mailboxes can be created */
    simple_mailbox_cluster_t cluster;

    /* Set up a metadata meeting-place */
    namespace_branch_metadata_t<dummy_protocol_t> initial_metadata;
    dummy_metadata_controller_t<namespace_branch_metadata_t<dummy_protocol_t> > metadata_controller(initial_metadata);

    /* Set up a broadcaster and initial listener */
    test_store_t initial_store;
    cond_t interruptor;
    boost::scoped_ptr<listener_t<dummy_protocol_t> > initial_listener;
    boost::scoped_ptr<broadcaster_t<dummy_protocol_t> > broadcaster(
        new broadcaster_t<dummy_protocol_t>(
            &cluster,
            metadata_controller.get_view(),
            &initial_store.store,
            &interruptor,
            &initial_listener
        ));

    fun(&cluster, metadata_controller.get_view(), &broadcaster, &initial_store, &initial_listener);
}

void run_in_thread_pool_with_broadcaster(
        boost::function<void(
            mailbox_cluster_t *,
            boost::shared_ptr<metadata_readwrite_view_t<namespace_branch_metadata_t<dummy_protocol_t> > >,
            boost::scoped_ptr<broadcaster_t<dummy_protocol_t> > *,
            test_store_t *,
            boost::scoped_ptr<listener_t<dummy_protocol_t> > *
            )> fun)
{
    run_in_thread_pool(boost::bind(&run_with_broadcaster, fun));
}

/* `let_stuff_happen()` delays for some time to let events occur */
void let_stuff_happen() {
    nap(1000);
}

}   /* anonymous namespace */

/* The `ReadWrite` test just sends some reads and writes via the broadcaster to a
single mirror. */

void run_read_write_test(mailbox_cluster_t *cluster,
        boost::shared_ptr<metadata_readwrite_view_t<namespace_branch_metadata_t<dummy_protocol_t> > > metadata_view,
        boost::scoped_ptr<broadcaster_t<dummy_protocol_t> > *broadcaster,
        UNUSED test_store_t *store,
        boost::scoped_ptr<listener_t<dummy_protocol_t> > *initial_listener)
{
    /* Set up a replier so the broadcaster can handle operations */
    EXPECT_FALSE((*initial_listener)->get_outdated_signal()->is_pulsed());
    replier_t<dummy_protocol_t> replier(cluster, metadata_view, initial_listener->get());

    order_source_t order_source;

    /* Send some writes via the broadcaster to the mirror */
    std::map<std::string, std::string> values_inserted;
    for (int i = 0; i < 10; i++) {
        dummy_protocol_t::write_t w;
        std::string key = std::string(1, 'a' + rand() % 26);
        w.values[key] = values_inserted[key] = strprintf("%d", i);
        (*broadcaster)->write(w, order_source.check_in("unittest"));
    }

    /* Now send some reads */
    for (std::map<std::string, std::string>::iterator it = values_inserted.begin();
            it != values_inserted.end(); it++) {
        dummy_protocol_t::read_t r;
        r.keys.keys.insert((*it).first);
        dummy_protocol_t::read_response_t resp = (*broadcaster)->read(r, order_source.check_in("unittest"));
        EXPECT_EQ((*it).second, resp.values[(*it).first]);
    }
}
// TODO(sam): TODO(tim): @sam @tim Tim needs to fix the bug that
// causes this test to fail.  See issue #479.

// TEST(ClusteringBranch, ReadWrite) {
//     run_in_thread_pool_with_broadcaster(&run_read_write_test);
// }

/* The `Backfill` test starts up a node with one mirror, inserts some data, and
then adds another mirror. */

void run_backfill_test(mailbox_cluster_t *cluster,
        boost::shared_ptr<metadata_readwrite_view_t<namespace_branch_metadata_t<dummy_protocol_t> > > metadata_view,
        boost::scoped_ptr<broadcaster_t<dummy_protocol_t> > *broadcaster,
        test_store_t *store1,
        boost::scoped_ptr<listener_t<dummy_protocol_t> > *initial_listener)
{
    /* Set up a replier so the broadcaster can handle operations */
    EXPECT_FALSE((*initial_listener)->get_outdated_signal()->is_pulsed());
    replier_t<dummy_protocol_t> replier(cluster, metadata_view, initial_listener->get());

    order_source_t order_source;

    /* Start sending operations to the broadcaster */
    inserter_t inserter(
        boost::bind(&broadcaster_t<dummy_protocol_t>::write, broadcaster->get(), _1, _2),
        &order_source);
    nap(100);

    /* Set up a second mirror */
    test_store_t store2;
    cond_t interruptor;
    listener_t<dummy_protocol_t> listener2(
        cluster, metadata_view,
        &store2.store,
        (*broadcaster)->get_branch_id(),
        replier.get_backfiller_id(),
        &interruptor);

    EXPECT_FALSE((*initial_listener)->get_outdated_signal()->is_pulsed());
    EXPECT_FALSE(listener2.get_outdated_signal()->is_pulsed());

    nap(100);

    /* Stop the inserter, then let any lingering writes finish */
    inserter.stop();
    /* Let any lingering writes finish */
    let_stuff_happen();

    /* Confirm that both mirrors have all of the writes */
    for (std::map<std::string, std::string>::iterator it = inserter.values_inserted.begin();
            it != inserter.values_inserted.end(); it++) {
        EXPECT_EQ((*it).second, store1->underlying_store.values[(*it).first]);
        EXPECT_EQ((*it).second, store2.underlying_store.values[(*it).first]);
    }
}
TEST(ClusteringBranch, Backfill) {
    run_in_thread_pool_with_broadcaster(&run_backfill_test);
}

}   /* namespace unittest */
<|endoftext|>


<commit_before>#include "glyphcellrenderer.h"
#include "wxcontext.h"

#include <wx/dcclient.h>
#include <wx/graphics.h>
#include <wx/settings.h>

#include <memory>

GlyphCellRenderer::GlyphCellRenderer(const std::map<wxString, SvgGlyph> &glyphs, int fontSize): glyphs(glyphs), fontSize(fontSize)
{
    labelFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
    glyphColor = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
    hlColor = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
    labelColor = glyphColor.ChangeLightness(150);
}

wxGridCellRenderer *GlyphCellRenderer::Clone() const
{
	return nullptr;
}

void GlyphCellRenderer::SetHighlightCell(const wxGridCellCoords &coords)
{
    hlCellCoords = coords;
}

const wxGridCellCoords &GlyphCellRenderer::GetHighlightCell() const
{
    return hlCellCoords;
}

void GlyphCellRenderer::Draw(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected)
{
    wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, false);

	wxString value = grid.GetTable()->GetValue(row, col);
    wxString label;

	auto it = glyphs.find(value);
	if (it == glyphs.end()) return;

    const SvgGlyph &glyph = it->second;

    if (!glyph.IsOk())
        return;

    label.Printf("%04x", glyph.unicode[0]);

    std::unique_ptr<wxGraphicsContext> gc(wxGraphicsContext::Create(static_cast<wxPaintDC&>(dc)));

    wxRect newRect = rect;

    // Oh, crap
    if (gc->GetRenderer()->GetName() == L"cairo")
    {
        newRect.x += dc.GetDeviceOrigin().x;
        newRect.y += dc.GetDeviceOrigin().y;
    }

    std::map<wxString, wxBitmap>::iterator findIt = glyphCache.find(glyph.unicode);

    if (findIt == glyphCache.end())
    {
        bool result;
        std::tie(findIt, result) = glyphCache.emplace(glyph.unicode, GetBitmapForGlyph(glyph, fontSize, glyphColor));

        if (!result) return;
    }

    if (hlCellCoords.GetCol() == col && hlCellCoords.GetRow() == row)
    {
        gc->SetPen(wxPen(hlColor, 1));
        gc->DrawRoundedRectangle(newRect.x + 1, newRect.y + 1, newRect.width - 2, newRect.height - 2, 5);
    }

    newRect.height -= labelFont.GetPixelSize().GetHeight() + 2 * padding;

    const wxBitmap &glyphBitmap = findIt->second;

    gc->DrawBitmap(glyphBitmap,
        newRect.x + (newRect.width - glyphBitmap.GetWidth()) / 2,
        newRect.y + (newRect.height - glyphBitmap.GetHeight()) / 2,
        glyphBitmap.GetWidth(), glyphBitmap.GetHeight());

    double width, height, descent, externalLeading;

    gc->SetFont(labelFont, labelColor);
    gc->GetTextExtent(label, &width, &height, &descent, &externalLeading);
    gc->DrawText(label, newRect.x + (newRect.width - width) / 2, newRect.y + newRect.height + padding);
}

wxSize GlyphCellRenderer::GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col)
{
    return wxSize(fontSize + padding, fontSize + labelFont.GetPixelSize().GetHeight() + 3 * padding);
}
<commit_msg>get rid of wxGraphicsRenderer::GetName method usage<commit_after>#include "glyphcellrenderer.h"
#include "wxcontext.h"

#include <wx/dcclient.h>
#include <wx/graphics.h>
#include <wx/settings.h>

#include <memory>

GlyphCellRenderer::GlyphCellRenderer(const std::map<wxString, SvgGlyph> &glyphs, int fontSize): glyphs(glyphs), fontSize(fontSize)
{
    labelFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
    glyphColor = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
    hlColor = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
    labelColor = glyphColor.ChangeLightness(150);
}

wxGridCellRenderer *GlyphCellRenderer::Clone() const
{
	return nullptr;
}

void GlyphCellRenderer::SetHighlightCell(const wxGridCellCoords &coords)
{
    hlCellCoords = coords;
}

const wxGridCellCoords &GlyphCellRenderer::GetHighlightCell() const
{
    return hlCellCoords;
}

void GlyphCellRenderer::Draw(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, const wxRect &rect, int row, int col, bool isSelected)
{
    wxGridCellRenderer::Draw(grid, attr, dc, rect, row, col, false);

	wxString value = grid.GetTable()->GetValue(row, col);
    wxString label;

	auto it = glyphs.find(value);
	if (it == glyphs.end()) return;

    const SvgGlyph &glyph = it->second;

    if (!glyph.IsOk())
        return;

    label.Printf("%04x", glyph.unicode[0]);

    std::unique_ptr<wxGraphicsContext> gc(wxGraphicsContext::Create(static_cast<wxPaintDC&>(dc)));

    wxRect newRect = rect;

    // replace with gc->GetRenderer()->GetName() == L"cairo" after wx 3.1
    bool isCairo = false;

    #if wxUSE_CAIRO
        isCairo = true;
    #endif

    // Oh, crap
    if (isCairo)
    {
        newRect.x += dc.GetDeviceOrigin().x;
        newRect.y += dc.GetDeviceOrigin().y;
    }

    std::map<wxString, wxBitmap>::iterator findIt = glyphCache.find(glyph.unicode);

    if (findIt == glyphCache.end())
    {
        bool result;
        std::tie(findIt, result) = glyphCache.emplace(glyph.unicode, GetBitmapForGlyph(glyph, fontSize, glyphColor));

        if (!result) return;
    }

    if (hlCellCoords.GetCol() == col && hlCellCoords.GetRow() == row)
    {
        gc->SetPen(wxPen(hlColor, 1));
        gc->DrawRoundedRectangle(newRect.x + 1, newRect.y + 1, newRect.width - 2, newRect.height - 2, 5);
    }

    newRect.height -= labelFont.GetPixelSize().GetHeight() + 2 * padding;

    const wxBitmap &glyphBitmap = findIt->second;

    gc->DrawBitmap(glyphBitmap,
        newRect.x + (newRect.width - glyphBitmap.GetWidth()) / 2,
        newRect.y + (newRect.height - glyphBitmap.GetHeight()) / 2,
        glyphBitmap.GetWidth(), glyphBitmap.GetHeight());

    double width, height, descent, externalLeading;

    gc->SetFont(labelFont, labelColor);
    gc->GetTextExtent(label, &width, &height, &descent, &externalLeading);
    gc->DrawText(label, newRect.x + (newRect.width - width) / 2, newRect.y + newRect.height + padding);
}

wxSize GlyphCellRenderer::GetBestSize(wxGrid &grid, wxGridCellAttr &attr, wxDC &dc, int row, int col)
{
    return wxSize(fontSize + padding, fontSize + labelFont.GetPixelSize().GetHeight() + 3 * padding);
}
<|endoftext|>


<commit_before>#include "Patch.hpp"
#include <Utils/Util.hpp>

using namespace AnvilCommon;
using namespace AnvilEldorado::Patches;

void ApplyAfterTagsLoaded()
{
	// TODO: Perform any actions that need to be done after tags are loaded here.
}

__declspec(naked) void TagsLoadedHook()
{
	__asm
	{
		call ApplyAfterTagsLoaded
		push 0x6D617467
		push 0x5030EF
		ret
	}
}

void AnvilPatch::Patch_Tags()
{
	// Enable Tag Editing
	Utils::Util::PatchAddressInFile(0x101A5B, "\xEB", 1);
	Utils::Util::PatchAddressInFile(0x102874, "\x90\x90", 2);
	Utils::Util::PatchAddressInFile(0x1030AA, "\x90\x90", 2);

	// Used to call Patches::ApplyAfterTagsLoaded when tags have loaded
	Utils::Util::ApplyHook(0x5030EA, TagsLoadedHook);
}<commit_msg>Fixed address of TagsLoadedHook in AnvilEldorado<commit_after>#include "Patch.hpp"
#include <Utils/Util.hpp>

using namespace AnvilCommon;
using namespace AnvilEldorado::Patches;

void ApplyAfterTagsLoaded()
{
	// TODO: Perform any actions that need to be done after tags are loaded here.
}

__declspec(naked) void TagsLoadedHook()
{
	__asm
	{
		call ApplyAfterTagsLoaded
		push 0x6D617467
		push 0x5030EF
		ret
	}
}

void AnvilPatch::Patch_Tags()
{
	// Enable Tag Editing
	Utils::Util::PatchAddressInFile(0x101A5B, "\xEB", 1);
	Utils::Util::PatchAddressInFile(0x102874, "\x90\x90", 2);
	Utils::Util::PatchAddressInFile(0x1030AA, "\x90\x90", 2);

	// Used to call Patches::ApplyAfterTagsLoaded when tags have loaded
	Utils::Util::ApplyHook(0x1030EA, TagsLoadedHook);
}
<|endoftext|>


<commit_before>// This file is distributed under the MIT license.
// See the LICENSE file for details.

#include <cstring>
#include <iostream>
#include <ostream>
#include <vector>

#include <visionaray/gl/compositing.h>
#include <visionaray/gl/handle.h>
#include <visionaray/gl/program.h>
#include <visionaray/gl/shader.h>
#include <visionaray/gl/util.h>
#include <visionaray/pixel_format.h>

namespace visionaray
{
namespace gl
{

#if !defined(VSNRAY_OPENGL_LEGACY)

//-------------------------------------------------------------------------------------------------
// Shader program to display color texture w/o depth compositing
//

struct color_program
{
    color_program();
   ~color_program();

    // The program
    gl::program prog;

    // The vertex shader
    gl::shader vert;

    // The fragment shader
    gl::shader frag;

    // Attribute location of vertex
    GLint vertex_loc;

    // Attribute location of texture coordinate
    GLint tex_coord_loc;

    // Uniform location of color texture
    GLint color_loc;

    void enable(gl::texture const& color_texture) const;
    void disable() const;
};

//-------------------------------------------------------------------------------------------------
// color program implementation
//

color_program::color_program()
    : prog(glCreateProgram())
    , vert(glCreateShader(GL_VERTEX_SHADER))
    , frag(glCreateShader(GL_FRAGMENT_SHADER))
{
    vert.set_source(R"(
        in vec2 vertex;
        in vec2 tex_coord;

        varying out vec2 uv;

        void main(void)
        {
            gl_Position = vec4(vertex, 0.0, 1.0);
            uv = tex_coord;
        }
        )");

    vert.compile();
    if (!vert.check_compiled())
    {
        return;
    }

    frag.set_source(R"(
        varying in vec2 uv;
        uniform sampler2D color_tex;

        void main(void)
        {
            gl_FragColor = texture2D(color_tex, uv);
        }
        )");

    frag.compile();
    if (!frag.check_compiled())
    {
        return;
    }

    prog.attach_shader(vert);
    prog.attach_shader(frag);

    prog.link();
    if (!prog.check_linked())
    {
        return;
    }

    vertex_loc    = glGetAttribLocation(prog.get(), "vertex");
    tex_coord_loc = glGetAttribLocation(prog.get(), "tex_coord");
    color_loc     = glGetUniformLocation(prog.get(), "color_tex");
}

color_program::~color_program()
{
    prog.detach_shader(vert);
    prog.detach_shader(frag);
}

void color_program::enable(gl::texture const& color_texture) const
{
    prog.enable();

    glUniform1i(color_loc, 0);
    glActiveTexture(GL_TEXTURE0 + 0);
    glBindTexture(GL_TEXTURE_2D, color_texture.get());
}

void color_program::disable() const
{
    prog.disable();
}

//-------------------------------------------------------------------------------------------------
// Shader program to composite depth textures
//

struct depth_program
{
    depth_program();
   ~depth_program();

    // The program
    gl::program prog;

    // The vertex shader
    gl::shader vert;

    // The fragment shader
    gl::shader frag;

    // Attribute location of vertex
    GLint vertex_loc;

    // Attribute location of texture coordinate
    GLint tex_coord_loc;

    // Uniform location of color texture
    GLint color_loc;

    // Uniform location of depth texture
    GLint depth_loc;

    void enable(gl::texture const& color_texture, gl::texture const& depth_texture) const;
    void disable() const;
};

//-------------------------------------------------------------------------------------------------
// depth program implementation
//

depth_program::depth_program()
    : prog(glCreateProgram())
    , vert(glCreateShader(GL_VERTEX_SHADER))
    , frag(glCreateShader(GL_FRAGMENT_SHADER))
{
    vert.set_source(R"(
        in vec2 vertex;
        in vec2 tex_coord;

        varying out vec2 uv;

        void main(void)
        {
            gl_Position = vec4(vertex, 0.0, 1.0);
            uv = tex_coord;
        }
        )");

    vert.compile();
    if (!vert.check_compiled())
    {
        return;
    }

    frag.set_source(R"(
        varying in vec2 uv;
        uniform sampler2D color_tex;
        uniform sampler2D depth_tex;

        void main(void)
        {
            gl_FragColor = texture2D(color_tex, uv);
            gl_FragDepth = texture2D(depth_tex, uv).x;
        }
        )");

    frag.compile();
    if (!frag.check_compiled())
    {
        return;
    }

    prog.attach_shader(vert);
    prog.attach_shader(frag);

    prog.link();
    if (!prog.check_linked())
    {
        return;
    }

    vertex_loc    = glGetAttribLocation(prog.get(), "vertex");
    tex_coord_loc = glGetAttribLocation(prog.get(), "tex_coord");
    color_loc     = glGetUniformLocation(prog.get(), "color_tex");
    depth_loc     = glGetUniformLocation(prog.get(), "depth_tex");
}

depth_program::~depth_program()
{
    prog.detach_shader(frag);
}

void depth_program::enable(
        gl::texture const& color_texture,
        gl::texture const& depth_texture
        ) const
{
    prog.enable();

    glUniform1i(color_loc, 0);
    glActiveTexture(GL_TEXTURE0 + 0);
    glBindTexture(GL_TEXTURE_2D, color_texture.get());

    glUniform1i(depth_loc, 1);
    glActiveTexture(GL_TEXTURE0 + 1);
    glBindTexture(GL_TEXTURE_2D, depth_texture.get());
}

void depth_program::disable() const
{
    prog.disable();
}

#endif // !VSNRAY_OPENGL_LEGACY

//-------------------------------------------------------------------------------------------------
// depth compositor private implementation
//

struct depth_compositor::impl
{
#if !defined(VSNRAY_OPENGL_LEGACY)
    impl()
        : vertex_buffer(create_buffer())
        , tex_coord_buffer(create_buffer())
    {
        GLfloat verts[8] = {
                -1.0f, -1.0f,
                 1.0f, -1.0f,
                 1.0f,  1.0f,
                -1.0f,  1.0f
                };

        glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer.get());
        glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(float), verts, GL_STATIC_DRAW);

        GLfloat tex_coords[8] = {
                0.0f, 0.0f,
                1.0f, 0.0f,
                1.0f, 1.0f,
                0.0f, 1.0f
                };

        glBindBuffer(GL_ARRAY_BUFFER, tex_coord_buffer.get());
        glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(float), tex_coords, GL_STATIC_DRAW);
    }

    // Shader program to only display color texture w/o depth compositing
    color_program color_prog;

    // Shader program for depth compositing
    depth_program depth_prog;

    // Quad vertex buffer
    gl::buffer vertex_buffer;

    // Quad texture coordinate buffer
    gl::buffer tex_coord_buffer;

    // GL color texture handle
    gl::texture color_texture;

    // GL color texture handle
    gl::texture depth_texture;
#else
    pixel_format_info color_info;
    pixel_format_info depth_info;

    GLvoid const* depth_buffer = nullptr;
    GLvoid const* color_buffer = nullptr;

    int width;
    int height;
#endif
};

//-------------------------------------------------------------------------------------------------
// depth compositor public interface
//

depth_compositor::depth_compositor()
    : impl_(new impl)
{
}

depth_compositor::~depth_compositor()
{
}

void depth_compositor::composite_textures() const
{
#if !defined(VSNRAY_OPENGL_LEGACY)
    // Store OpenGL state
    GLint active_texture = GL_TEXTURE0;
    GLboolean depth_test = GL_FALSE;
    glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
    glGetBooleanv(GL_DEPTH_TEST, &depth_test);

    glEnable(GL_DEPTH_TEST);

    impl_->depth_prog.enable(impl_->color_texture, impl_->depth_texture);

    glBindBuffer(GL_ARRAY_BUFFER, impl_->vertex_buffer.get());
    glVertexAttribPointer(impl_->depth_prog.vertex_loc, 2, GL_FLOAT, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(impl_->depth_prog.vertex_loc);

    glBindBuffer(GL_ARRAY_BUFFER, impl_->tex_coord_buffer.get());
    glVertexAttribPointer(impl_->depth_prog.tex_coord_loc, 2, GL_FLOAT, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(impl_->depth_prog.tex_coord_loc);

    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

    glDisableVertexAttribArray(impl_->depth_prog.tex_coord_loc);
    glDisableVertexAttribArray(impl_->depth_prog.vertex_loc);

    impl_->depth_prog.disable();

    // Restore OpenGL state
    glActiveTexture(active_texture);
    if (depth_test)
    {
        glEnable(GL_DEPTH_TEST);
    }
    else
    {
        glDisable(GL_DEPTH_TEST);
    }
#else
    glPushAttrib( GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_ENABLE_BIT );

    glEnable(GL_STENCIL_TEST);
    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
    glStencilFunc(GL_ALWAYS, 1, 1);
    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

    gl::blend_pixels(
            impl_->width,
            impl_->height,
            impl_->depth_info.format,
            impl_->depth_info.type,
            impl_->depth_buffer
            );

    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
    glStencilFunc(GL_EQUAL, 1, 1);
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
    glDisable(GL_DEPTH_TEST);

    gl::blend_pixels(
            impl_->width,
            impl_->height,
            impl_->color_info.format,
            impl_->color_info.type,
            impl_->color_buffer
            );

    glPopAttrib();
#endif
}

void depth_compositor::display_color_texture() const
{
#if !defined(VSNRAY_OPENGL_LEGACY)
    // Store OpenGL state
    GLint active_texture = GL_TEXTURE0;
    glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);

    impl_->color_prog.enable(impl_->color_texture);

    glBindBuffer(GL_ARRAY_BUFFER, impl_->vertex_buffer.get());
    glVertexAttribPointer(impl_->color_prog.vertex_loc, 2, GL_FLOAT, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(impl_->color_prog.vertex_loc);

    glBindBuffer(GL_ARRAY_BUFFER, impl_->tex_coord_buffer.get());
    glVertexAttribPointer(impl_->color_prog.tex_coord_loc, 2, GL_FLOAT, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(impl_->color_prog.tex_coord_loc);

    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

    glDisableVertexAttribArray(impl_->color_prog.tex_coord_loc);
    glDisableVertexAttribArray(impl_->color_prog.vertex_loc);

    impl_->color_prog.disable();

    // Restore OpenGL state
    glActiveTexture(active_texture);
#else
    gl::blend_pixels(
            impl_->width,
            impl_->height,
            impl_->color_info.format,
            impl_->color_info.type,
            impl_->color_buffer
            );
#endif
}

void depth_compositor::setup_color_texture(pixel_format_info info, GLsizei w, GLsizei h)
{
#if !defined(VSNRAY_OPENGL_LEGACY)
    impl_->color_texture.reset( create_texture() );

    glBindTexture(GL_TEXTURE_2D, impl_->color_texture.get());

    alloc_texture(info, w, h);
#else
    impl_->color_info = info;
    impl_->width = w;
    impl_->height = h;
#endif
}

void depth_compositor::setup_depth_texture(pixel_format_info info, GLsizei w, GLsizei h)
{
#if !defined(VSNRAY_OPENGL_LEGACY)
    impl_->depth_texture.reset( create_texture() );

    glBindTexture(GL_TEXTURE_2D, impl_->depth_texture.get());

    alloc_texture(info, w, h);
#else
    impl_->depth_info = info;
    impl_->width = w;
    impl_->height = h;
#endif
}

void depth_compositor::update_color_texture(
        pixel_format_info   info,
        GLsizei             w,
        GLsizei             h,
        GLvoid const*       data
        ) const
{
#if !defined(VSNRAY_OPENGL_LEGACY)
    glBindTexture(GL_TEXTURE_2D, impl_->color_texture.get());

    gl::update_texture( info, w, h, data );
#else
    impl_->color_info = info;
    impl_->width = w;
    impl_->height = h;
    impl_->color_buffer = data;
#endif
}

void depth_compositor::update_depth_texture(
        pixel_format_info   info,
        GLsizei             w,
        GLsizei             h,
        GLvoid const*       data
        ) const
{
#if !defined(VSNRAY_OPENGL_LEGACY)
    glBindTexture(GL_TEXTURE_2D, impl_->depth_texture.get());

    gl::update_texture( info, w, h, data );
#else
    impl_->depth_info = info;
    impl_->width = w;
    impl_->height = h;
    impl_->depth_buffer = data;
#endif
}

} // gl
} // visionaray
<commit_msg>No duplicate storage qualifiers in shader<commit_after>// This file is distributed under the MIT license.
// See the LICENSE file for details.

#include <cstring>
#include <iostream>
#include <ostream>
#include <vector>

#include <visionaray/gl/compositing.h>
#include <visionaray/gl/handle.h>
#include <visionaray/gl/program.h>
#include <visionaray/gl/shader.h>
#include <visionaray/gl/util.h>
#include <visionaray/pixel_format.h>

namespace visionaray
{
namespace gl
{

#if !defined(VSNRAY_OPENGL_LEGACY)

//-------------------------------------------------------------------------------------------------
// Shader program to display color texture w/o depth compositing
//

struct color_program
{
    color_program();
   ~color_program();

    // The program
    gl::program prog;

    // The vertex shader
    gl::shader vert;

    // The fragment shader
    gl::shader frag;

    // Attribute location of vertex
    GLint vertex_loc;

    // Attribute location of texture coordinate
    GLint tex_coord_loc;

    // Uniform location of color texture
    GLint color_loc;

    void enable(gl::texture const& color_texture) const;
    void disable() const;
};

//-------------------------------------------------------------------------------------------------
// color program implementation
//

color_program::color_program()
    : prog(glCreateProgram())
    , vert(glCreateShader(GL_VERTEX_SHADER))
    , frag(glCreateShader(GL_FRAGMENT_SHADER))
{
    vert.set_source(R"(
        attribute vec2 vertex;
        attribute vec2 tex_coord;

        varying vec2 uv;

        void main(void)
        {
            gl_Position = vec4(vertex, 0.0, 1.0);
            uv = tex_coord;
        }
        )");

    vert.compile();
    if (!vert.check_compiled())
    {
        return;
    }

    frag.set_source(R"(
        varying vec2 uv;
        uniform sampler2D color_tex;

        void main(void)
        {
            gl_FragColor = texture2D(color_tex, uv);
        }
        )");

    frag.compile();
    if (!frag.check_compiled())
    {
        return;
    }

    prog.attach_shader(vert);
    prog.attach_shader(frag);

    prog.link();
    if (!prog.check_linked())
    {
        return;
    }

    vertex_loc    = glGetAttribLocation(prog.get(), "vertex");
    tex_coord_loc = glGetAttribLocation(prog.get(), "tex_coord");
    color_loc     = glGetUniformLocation(prog.get(), "color_tex");
}

color_program::~color_program()
{
    prog.detach_shader(vert);
    prog.detach_shader(frag);
}

void color_program::enable(gl::texture const& color_texture) const
{
    prog.enable();

    glUniform1i(color_loc, 0);
    glActiveTexture(GL_TEXTURE0 + 0);
    glBindTexture(GL_TEXTURE_2D, color_texture.get());
}

void color_program::disable() const
{
    prog.disable();
}

//-------------------------------------------------------------------------------------------------
// Shader program to composite depth textures
//

struct depth_program
{
    depth_program();
   ~depth_program();

    // The program
    gl::program prog;

    // The vertex shader
    gl::shader vert;

    // The fragment shader
    gl::shader frag;

    // Attribute location of vertex
    GLint vertex_loc;

    // Attribute location of texture coordinate
    GLint tex_coord_loc;

    // Uniform location of color texture
    GLint color_loc;

    // Uniform location of depth texture
    GLint depth_loc;

    void enable(gl::texture const& color_texture, gl::texture const& depth_texture) const;
    void disable() const;
};

//-------------------------------------------------------------------------------------------------
// depth program implementation
//

depth_program::depth_program()
    : prog(glCreateProgram())
    , vert(glCreateShader(GL_VERTEX_SHADER))
    , frag(glCreateShader(GL_FRAGMENT_SHADER))
{
    vert.set_source(R"(
        in vec2 vertex;
        in vec2 tex_coord;

        varying out vec2 uv;

        void main(void)
        {
            gl_Position = vec4(vertex, 0.0, 1.0);
            uv = tex_coord;
        }
        )");

    vert.compile();
    if (!vert.check_compiled())
    {
        return;
    }

    frag.set_source(R"(
        varying in vec2 uv;
        uniform sampler2D color_tex;
        uniform sampler2D depth_tex;

        void main(void)
        {
            gl_FragColor = texture2D(color_tex, uv);
            gl_FragDepth = texture2D(depth_tex, uv).x;
        }
        )");

    frag.compile();
    if (!frag.check_compiled())
    {
        return;
    }

    prog.attach_shader(vert);
    prog.attach_shader(frag);

    prog.link();
    if (!prog.check_linked())
    {
        return;
    }

    vertex_loc    = glGetAttribLocation(prog.get(), "vertex");
    tex_coord_loc = glGetAttribLocation(prog.get(), "tex_coord");
    color_loc     = glGetUniformLocation(prog.get(), "color_tex");
    depth_loc     = glGetUniformLocation(prog.get(), "depth_tex");
}

depth_program::~depth_program()
{
    prog.detach_shader(frag);
}

void depth_program::enable(
        gl::texture const& color_texture,
        gl::texture const& depth_texture
        ) const
{
    prog.enable();

    glUniform1i(color_loc, 0);
    glActiveTexture(GL_TEXTURE0 + 0);
    glBindTexture(GL_TEXTURE_2D, color_texture.get());

    glUniform1i(depth_loc, 1);
    glActiveTexture(GL_TEXTURE0 + 1);
    glBindTexture(GL_TEXTURE_2D, depth_texture.get());
}

void depth_program::disable() const
{
    prog.disable();
}

#endif // !VSNRAY_OPENGL_LEGACY

//-------------------------------------------------------------------------------------------------
// depth compositor private implementation
//

struct depth_compositor::impl
{
#if !defined(VSNRAY_OPENGL_LEGACY)
    impl()
        : vertex_buffer(create_buffer())
        , tex_coord_buffer(create_buffer())
    {
        GLfloat verts[8] = {
                -1.0f, -1.0f,
                 1.0f, -1.0f,
                 1.0f,  1.0f,
                -1.0f,  1.0f
                };

        glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer.get());
        glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(float), verts, GL_STATIC_DRAW);

        GLfloat tex_coords[8] = {
                0.0f, 0.0f,
                1.0f, 0.0f,
                1.0f, 1.0f,
                0.0f, 1.0f
                };

        glBindBuffer(GL_ARRAY_BUFFER, tex_coord_buffer.get());
        glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(float), tex_coords, GL_STATIC_DRAW);
    }

    // Shader program to only display color texture w/o depth compositing
    color_program color_prog;

    // Shader program for depth compositing
    depth_program depth_prog;

    // Quad vertex buffer
    gl::buffer vertex_buffer;

    // Quad texture coordinate buffer
    gl::buffer tex_coord_buffer;

    // GL color texture handle
    gl::texture color_texture;

    // GL color texture handle
    gl::texture depth_texture;
#else
    pixel_format_info color_info;
    pixel_format_info depth_info;

    GLvoid const* depth_buffer = nullptr;
    GLvoid const* color_buffer = nullptr;

    int width;
    int height;
#endif
};

//-------------------------------------------------------------------------------------------------
// depth compositor public interface
//

depth_compositor::depth_compositor()
    : impl_(new impl)
{
}

depth_compositor::~depth_compositor()
{
}

void depth_compositor::composite_textures() const
{
#if !defined(VSNRAY_OPENGL_LEGACY)
    // Store OpenGL state
    GLint active_texture = GL_TEXTURE0;
    GLboolean depth_test = GL_FALSE;
    glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
    glGetBooleanv(GL_DEPTH_TEST, &depth_test);

    glEnable(GL_DEPTH_TEST);

    impl_->depth_prog.enable(impl_->color_texture, impl_->depth_texture);

    glBindBuffer(GL_ARRAY_BUFFER, impl_->vertex_buffer.get());
    glVertexAttribPointer(impl_->depth_prog.vertex_loc, 2, GL_FLOAT, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(impl_->depth_prog.vertex_loc);

    glBindBuffer(GL_ARRAY_BUFFER, impl_->tex_coord_buffer.get());
    glVertexAttribPointer(impl_->depth_prog.tex_coord_loc, 2, GL_FLOAT, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(impl_->depth_prog.tex_coord_loc);

    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

    glDisableVertexAttribArray(impl_->depth_prog.tex_coord_loc);
    glDisableVertexAttribArray(impl_->depth_prog.vertex_loc);

    impl_->depth_prog.disable();

    // Restore OpenGL state
    glActiveTexture(active_texture);
    if (depth_test)
    {
        glEnable(GL_DEPTH_TEST);
    }
    else
    {
        glDisable(GL_DEPTH_TEST);
    }
#else
    glPushAttrib( GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_ENABLE_BIT );

    glEnable(GL_STENCIL_TEST);
    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
    glStencilFunc(GL_ALWAYS, 1, 1);
    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

    gl::blend_pixels(
            impl_->width,
            impl_->height,
            impl_->depth_info.format,
            impl_->depth_info.type,
            impl_->depth_buffer
            );

    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
    glStencilFunc(GL_EQUAL, 1, 1);
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
    glDisable(GL_DEPTH_TEST);

    gl::blend_pixels(
            impl_->width,
            impl_->height,
            impl_->color_info.format,
            impl_->color_info.type,
            impl_->color_buffer
            );

    glPopAttrib();
#endif
}

void depth_compositor::display_color_texture() const
{
#if !defined(VSNRAY_OPENGL_LEGACY)
    // Store OpenGL state
    GLint active_texture = GL_TEXTURE0;
    glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);

    impl_->color_prog.enable(impl_->color_texture);

    glBindBuffer(GL_ARRAY_BUFFER, impl_->vertex_buffer.get());
    glVertexAttribPointer(impl_->color_prog.vertex_loc, 2, GL_FLOAT, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(impl_->color_prog.vertex_loc);

    glBindBuffer(GL_ARRAY_BUFFER, impl_->tex_coord_buffer.get());
    glVertexAttribPointer(impl_->color_prog.tex_coord_loc, 2, GL_FLOAT, GL_FALSE, 0, 0);
    glEnableVertexAttribArray(impl_->color_prog.tex_coord_loc);

    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

    glDisableVertexAttribArray(impl_->color_prog.tex_coord_loc);
    glDisableVertexAttribArray(impl_->color_prog.vertex_loc);

    impl_->color_prog.disable();

    // Restore OpenGL state
    glActiveTexture(active_texture);
#else
    gl::blend_pixels(
            impl_->width,
            impl_->height,
            impl_->color_info.format,
            impl_->color_info.type,
            impl_->color_buffer
            );
#endif
}

void depth_compositor::setup_color_texture(pixel_format_info info, GLsizei w, GLsizei h)
{
#if !defined(VSNRAY_OPENGL_LEGACY)
    impl_->color_texture.reset( create_texture() );

    glBindTexture(GL_TEXTURE_2D, impl_->color_texture.get());

    alloc_texture(info, w, h);
#else
    impl_->color_info = info;
    impl_->width = w;
    impl_->height = h;
#endif
}

void depth_compositor::setup_depth_texture(pixel_format_info info, GLsizei w, GLsizei h)
{
#if !defined(VSNRAY_OPENGL_LEGACY)
    impl_->depth_texture.reset( create_texture() );

    glBindTexture(GL_TEXTURE_2D, impl_->depth_texture.get());

    alloc_texture(info, w, h);
#else
    impl_->depth_info = info;
    impl_->width = w;
    impl_->height = h;
#endif
}

void depth_compositor::update_color_texture(
        pixel_format_info   info,
        GLsizei             w,
        GLsizei             h,
        GLvoid const*       data
        ) const
{
#if !defined(VSNRAY_OPENGL_LEGACY)
    glBindTexture(GL_TEXTURE_2D, impl_->color_texture.get());

    gl::update_texture( info, w, h, data );
#else
    impl_->color_info = info;
    impl_->width = w;
    impl_->height = h;
    impl_->color_buffer = data;
#endif
}

void depth_compositor::update_depth_texture(
        pixel_format_info   info,
        GLsizei             w,
        GLsizei             h,
        GLvoid const*       data
        ) const
{
#if !defined(VSNRAY_OPENGL_LEGACY)
    glBindTexture(GL_TEXTURE_2D, impl_->depth_texture.get());

    gl::update_texture( info, w, h, data );
#else
    impl_->depth_info = info;
    impl_->width = w;
    impl_->height = h;
    impl_->depth_buffer = data;
#endif
}

} // gl
} // visionaray
<|endoftext|>