<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: unoshcol.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 06:15:37 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

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

#ifndef _COM_SUN_STAR_DOCUMENT_EVENTOBJECT_HPP_
#include <com/sun/star/document/EventObject.hpp>
#endif

#include "unoshcol.hxx"
#include "unoprov.hxx"

using namespace ::rtl;
using namespace ::cppu;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::drawing;

/***********************************************************************
*                                                                      *
***********************************************************************/
SvxShapeCollection::SvxShapeCollection() throw()
: maShapeContainer( maMutex ), mrBHelper( maMutex )
{
}

//----------------------------------------------------------------------
SvxShapeCollection::~SvxShapeCollection() throw()
{
}

//----------------------------------------------------------------------
Reference< uno::XInterface > SvxShapeCollection_NewInstance() throw()
{
    Reference< drawing::XShapes > xShapes( new SvxShapeCollection() );
    Reference< uno::XInterface > xRef( xShapes, UNO_QUERY );
    return xRef;
}

// XInterface
void SvxShapeCollection::release() throw()
{
    uno::Reference< uno::XInterface > x( xDelegator );
    if (! x.is())
    {
        if (osl_decrementInterlockedCount( &m_refCount ) == 0)
        {
            if (! mrBHelper.bDisposed)
            {
                uno::Reference< uno::XInterface > xHoldAlive( (uno::XWeak*)this );
                // First dispose
                try
                {
                    dispose();
                }
                catch(::com::sun::star::uno::Exception&)
                {
                    // release should not throw exceptions
                }

                // only the alive ref holds the object
                OSL_ASSERT( m_refCount == 1 );
                // destroy the object if xHoldAlive decrement the refcount to 0
                return;
            }
        }
        // restore the reference count
        osl_incrementInterlockedCount( &m_refCount );
    }
    OWeakAggObject::release();
}

// XComponent
void SvxShapeCollection::disposing() throw()
{
    maShapeContainer.clear();
}

// XComponent
void SvxShapeCollection::dispose()
    throw(::com::sun::star::uno::RuntimeException)
{
    // An frequently programming error is to release the last
    // reference to this object in the disposing message.
    // Make it rubust, hold a self Reference.
    uno::Reference< lang::XComponent > xSelf( this );

    // Guard dispose against multible threading
    // Remark: It is an error to call dispose more than once
    sal_Bool bDoDispose = sal_False;
    {
    osl::MutexGuard aGuard( mrBHelper.rMutex );
    if( !mrBHelper.bDisposed && !mrBHelper.bInDispose )
    {
        // only one call go into this section
        mrBHelper.bInDispose = sal_True;
        bDoDispose = sal_True;
    }
    }

    // Do not hold the mutex because we are broadcasting
    if( bDoDispose )
    {
        // Create an event with this as sender
        try
        {
            uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( (lang::XComponent *)this ) );
            document::EventObject aEvt;
            aEvt.Source = xSource;
            // inform all listeners to release this object
            // The listener container are automaticly cleared
            mrBHelper.aLC.disposeAndClear( aEvt );
            // notify subclasses to do their dispose
            disposing();
        }
        catch(::com::sun::star::uno::Exception& e)
        {
            // catch exception and throw again but signal that
            // the object was disposed. Dispose should be called
            // only once.
            mrBHelper.bDisposed = sal_True;
            mrBHelper.bInDispose = sal_False;
            throw e;
        }

        // the values bDispose and bInDisposing must set in this order.
        // No multithread call overcome the "!rBHelper.bDisposed && !rBHelper.bInDispose" guard.
        mrBHelper.bDisposed = sal_True;
        mrBHelper.bInDispose = sal_False;
    }
    else
    {
        // in a multithreaded environment, it can't be avoided, that dispose is called twice.
        // However this condition is traced, because it MAY indicate an error.
        OSL_TRACE( "OComponentHelper::dispose() - dispose called twice" );
    }
}

// XComponent
void SAL_CALL SvxShapeCollection::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
{
    mrBHelper.addListener( ::getCppuType( &aListener ) , aListener );
}

// XComponent
void SAL_CALL SvxShapeCollection::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
{
    mrBHelper.removeListener( ::getCppuType( &aListener ) , aListener );
}

// XShapes
//----------------------------------------------------------------------
void SAL_CALL SvxShapeCollection::add( const Reference< drawing::XShape >& xShape ) throw( uno::RuntimeException )
{
    maShapeContainer.addInterface( xShape );
}

//----------------------------------------------------------------------
void SAL_CALL SvxShapeCollection::remove( const uno::Reference< drawing::XShape >& xShape ) throw( uno::RuntimeException )
{
    maShapeContainer.removeInterface( xShape );
}

//----------------------------------------------------------------------
sal_Int32 SAL_CALL SvxShapeCollection::getCount() throw( uno::RuntimeException )
{
    return maShapeContainer.getLength();
}

//----------------------------------------------------------------------
uno::Any SAL_CALL SvxShapeCollection::getByIndex( sal_Int32 Index )
    throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
{
    if( Index < 0 || Index >= getCount() )
        throw lang::IndexOutOfBoundsException();

    uno::Sequence< Reference< uno::XInterface> > xElements( maShapeContainer.getElements() );

    return uno::makeAny( Reference< XShape>(static_cast< drawing::XShape* >( xElements.getArray()[Index].get())) );
}

// XElementAccess

//----------------------------------------------------------------------
uno::Type SAL_CALL SvxShapeCollection::getElementType() throw( uno::RuntimeException )
{
    return ::getCppuType(( const Reference< drawing::XShape >*)0);
}

//----------------------------------------------------------------------
sal_Bool SAL_CALL SvxShapeCollection::hasElements() throw( uno::RuntimeException )
{
    return getCount() != 0;
}

//----------------------------------------------------------------------
// XServiceInfo
//----------------------------------------------------------------------
OUString SAL_CALL SvxShapeCollection::getImplementationName()
    throw( uno::RuntimeException )
{
    return getImplementationName_Static();
}

OUString SvxShapeCollection::getImplementationName_Static()
{
    return OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.SvxShapeCollection") );
}

sal_Bool SAL_CALL SvxShapeCollection::supportsService( const OUString& ServiceName )
    throw( uno::RuntimeException )
{
    return SvxServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
}

uno::Sequence< OUString > SAL_CALL SvxShapeCollection::getSupportedServiceNames() throw( uno::RuntimeException )
{
    return getSupportedServiceNames_Static();
}

uno::Sequence< OUString > SvxShapeCollection::getSupportedServiceNames_Static()
{
    uno::Sequence< OUString > aSeq(2);
    aSeq.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Shapes") );
    aSeq.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ShapeCollection") );
    return aSeq;
}

Reference< XInterface > SAL_CALL SvxShapeCollection_createInstance( const Reference< ::com::sun::star::lang::XMultiServiceFactory >& )
{
    return *( new SvxShapeCollection() );
}

<commit_msg>INTEGRATION: CWS vgbugs07 (1.8.352); FILE MERGED 2007/06/04 13:27:37 vg 1.8.352.1: #i76605# Remove -I .../inc/module hack introduced by hedaburemove01<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: unoshcol.cxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: hr $ $Date: 2007-06-27 19:27:22 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

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

#ifndef _COM_SUN_STAR_DOCUMENT_EVENTOBJECT_HPP_
#include <com/sun/star/document/EventObject.hpp>
#endif

#include "unoshcol.hxx"
#include <svx/unoprov.hxx>

using namespace ::rtl;
using namespace ::cppu;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::drawing;

/***********************************************************************
*                                                                      *
***********************************************************************/
SvxShapeCollection::SvxShapeCollection() throw()
: maShapeContainer( maMutex ), mrBHelper( maMutex )
{
}

//----------------------------------------------------------------------
SvxShapeCollection::~SvxShapeCollection() throw()
{
}

//----------------------------------------------------------------------
Reference< uno::XInterface > SvxShapeCollection_NewInstance() throw()
{
    Reference< drawing::XShapes > xShapes( new SvxShapeCollection() );
    Reference< uno::XInterface > xRef( xShapes, UNO_QUERY );
    return xRef;
}

// XInterface
void SvxShapeCollection::release() throw()
{
    uno::Reference< uno::XInterface > x( xDelegator );
    if (! x.is())
    {
        if (osl_decrementInterlockedCount( &m_refCount ) == 0)
        {
            if (! mrBHelper.bDisposed)
            {
                uno::Reference< uno::XInterface > xHoldAlive( (uno::XWeak*)this );
                // First dispose
                try
                {
                    dispose();
                }
                catch(::com::sun::star::uno::Exception&)
                {
                    // release should not throw exceptions
                }

                // only the alive ref holds the object
                OSL_ASSERT( m_refCount == 1 );
                // destroy the object if xHoldAlive decrement the refcount to 0
                return;
            }
        }
        // restore the reference count
        osl_incrementInterlockedCount( &m_refCount );
    }
    OWeakAggObject::release();
}

// XComponent
void SvxShapeCollection::disposing() throw()
{
    maShapeContainer.clear();
}

// XComponent
void SvxShapeCollection::dispose()
    throw(::com::sun::star::uno::RuntimeException)
{
    // An frequently programming error is to release the last
    // reference to this object in the disposing message.
    // Make it rubust, hold a self Reference.
    uno::Reference< lang::XComponent > xSelf( this );

    // Guard dispose against multible threading
    // Remark: It is an error to call dispose more than once
    sal_Bool bDoDispose = sal_False;
    {
    osl::MutexGuard aGuard( mrBHelper.rMutex );
    if( !mrBHelper.bDisposed && !mrBHelper.bInDispose )
    {
        // only one call go into this section
        mrBHelper.bInDispose = sal_True;
        bDoDispose = sal_True;
    }
    }

    // Do not hold the mutex because we are broadcasting
    if( bDoDispose )
    {
        // Create an event with this as sender
        try
        {
            uno::Reference< uno::XInterface > xSource( uno::Reference< uno::XInterface >::query( (lang::XComponent *)this ) );
            document::EventObject aEvt;
            aEvt.Source = xSource;
            // inform all listeners to release this object
            // The listener container are automaticly cleared
            mrBHelper.aLC.disposeAndClear( aEvt );
            // notify subclasses to do their dispose
            disposing();
        }
        catch(::com::sun::star::uno::Exception& e)
        {
            // catch exception and throw again but signal that
            // the object was disposed. Dispose should be called
            // only once.
            mrBHelper.bDisposed = sal_True;
            mrBHelper.bInDispose = sal_False;
            throw e;
        }

        // the values bDispose and bInDisposing must set in this order.
        // No multithread call overcome the "!rBHelper.bDisposed && !rBHelper.bInDispose" guard.
        mrBHelper.bDisposed = sal_True;
        mrBHelper.bInDispose = sal_False;
    }
    else
    {
        // in a multithreaded environment, it can't be avoided, that dispose is called twice.
        // However this condition is traced, because it MAY indicate an error.
        OSL_TRACE( "OComponentHelper::dispose() - dispose called twice" );
    }
}

// XComponent
void SAL_CALL SvxShapeCollection::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
{
    mrBHelper.addListener( ::getCppuType( &aListener ) , aListener );
}

// XComponent
void SAL_CALL SvxShapeCollection::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException)
{
    mrBHelper.removeListener( ::getCppuType( &aListener ) , aListener );
}

// XShapes
//----------------------------------------------------------------------
void SAL_CALL SvxShapeCollection::add( const Reference< drawing::XShape >& xShape ) throw( uno::RuntimeException )
{
    maShapeContainer.addInterface( xShape );
}

//----------------------------------------------------------------------
void SAL_CALL SvxShapeCollection::remove( const uno::Reference< drawing::XShape >& xShape ) throw( uno::RuntimeException )
{
    maShapeContainer.removeInterface( xShape );
}

//----------------------------------------------------------------------
sal_Int32 SAL_CALL SvxShapeCollection::getCount() throw( uno::RuntimeException )
{
    return maShapeContainer.getLength();
}

//----------------------------------------------------------------------
uno::Any SAL_CALL SvxShapeCollection::getByIndex( sal_Int32 Index )
    throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
{
    if( Index < 0 || Index >= getCount() )
        throw lang::IndexOutOfBoundsException();

    uno::Sequence< Reference< uno::XInterface> > xElements( maShapeContainer.getElements() );

    return uno::makeAny( Reference< XShape>(static_cast< drawing::XShape* >( xElements.getArray()[Index].get())) );
}

// XElementAccess

//----------------------------------------------------------------------
uno::Type SAL_CALL SvxShapeCollection::getElementType() throw( uno::RuntimeException )
{
    return ::getCppuType(( const Reference< drawing::XShape >*)0);
}

//----------------------------------------------------------------------
sal_Bool SAL_CALL SvxShapeCollection::hasElements() throw( uno::RuntimeException )
{
    return getCount() != 0;
}

//----------------------------------------------------------------------
// XServiceInfo
//----------------------------------------------------------------------
OUString SAL_CALL SvxShapeCollection::getImplementationName()
    throw( uno::RuntimeException )
{
    return getImplementationName_Static();
}

OUString SvxShapeCollection::getImplementationName_Static()
{
    return OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.SvxShapeCollection") );
}

sal_Bool SAL_CALL SvxShapeCollection::supportsService( const OUString& ServiceName )
    throw( uno::RuntimeException )
{
    return SvxServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
}

uno::Sequence< OUString > SAL_CALL SvxShapeCollection::getSupportedServiceNames() throw( uno::RuntimeException )
{
    return getSupportedServiceNames_Static();
}

uno::Sequence< OUString > SvxShapeCollection::getSupportedServiceNames_Static()
{
    uno::Sequence< OUString > aSeq(2);
    aSeq.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.Shapes") );
    aSeq.getArray()[1] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ShapeCollection") );
    return aSeq;
}

Reference< XInterface > SAL_CALL SvxShapeCollection_createInstance( const Reference< ::com::sun::star::lang::XMultiServiceFactory >& )
{
    return *( new SvxShapeCollection() );
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: unoedhlp.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 01:10:29 $
 *
 *  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
 *
 ************************************************************************/

#pragma hdrstop

#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif

#include "unoedhlp.hxx"
#include "editdata.hxx"
#include "editeng.hxx"

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

TYPEINIT1( SvxEditSourceHint, TextHint );

SvxEditSourceHint::SvxEditSourceHint( ULONG _nId ) :
    TextHint( _nId ),
    mnStart( 0 ),
    mnEnd( 0 )
{
}

SvxEditSourceHint::SvxEditSourceHint( ULONG _nId, ULONG nValue, ULONG nStart, ULONG nEnd ) :
    TextHint( _nId, nValue ),
    mnStart( nStart),
    mnEnd( nEnd )
{
}

ULONG SvxEditSourceHint::GetValue() const
{
    return TextHint::GetValue();
}

ULONG SvxEditSourceHint::GetStartValue() const
{
    return mnStart;
}

ULONG SvxEditSourceHint::GetEndValue() const
{
    return mnEnd;
}

void SvxEditSourceHint::SetValue( ULONG n )
{
    TextHint::SetValue( n );
}

void SvxEditSourceHint::SetStartValue( ULONG n )
{
    mnStart = n;
}

void SvxEditSourceHint::SetEndValue( ULONG n )
{
    mnEnd = n;
}

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

::std::auto_ptr<SfxHint> SvxEditSourceHelper::EENotification2Hint( EENotify* aNotify )
{
    if( aNotify )
    {
        switch( aNotify->eNotificationType )
        {
            case EE_NOTIFY_TEXTMODIFIED:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_MODIFIED, aNotify->nParagraph ) );

            case EE_NOTIFY_PARAGRAPHINSERTED:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAINSERTED, aNotify->nParagraph ) );

            case EE_NOTIFY_PARAGRAPHREMOVED:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAREMOVED, aNotify->nParagraph ) );

            case EE_NOTIFY_PARAGRAPHSMOVED:
                return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_PARASMOVED, aNotify->nParagraph, aNotify->nParam1, aNotify->nParam2 ) );

            case EE_NOTIFY_TEXTHEIGHTCHANGED:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_TEXTHEIGHTCHANGED, aNotify->nParagraph ) );

            case EE_NOTIFY_TEXTVIEWSCROLLED:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_VIEWSCROLLED ) );

            case EE_NOTIFY_TEXTVIEWSELECTIONCHANGED:
                return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_SELECTIONCHANGED ) );

            case EE_NOTIFY_BLOCKNOTIFICATION_START:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_START, 0 ) );

            case EE_NOTIFY_BLOCKNOTIFICATION_END:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_END, 0 ) );

            case EE_NOTIFY_INPUT_START:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_START, 0 ) );

            case EE_NOTIFY_INPUT_END:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_END, 0 ) );

            default:
                DBG_ERROR( "SvxEditSourceHelper::EENotification2Hint unknown notification" );
                break;
        }
    }

    return ::std::auto_ptr<SfxHint>( new SfxHint() );
}

sal_Bool SvxEditSourceHelper::GetAttributeRun( USHORT& nStartIndex, USHORT& nEndIndex, const EditEngine& rEE, USHORT nPara, USHORT nIndex )
{
    EECharAttribArray aCharAttribs;

    rEE.GetCharAttribs( nPara, aCharAttribs );

    // find closest index in front of nIndex
    USHORT nAttr, nCurrIndex;
    sal_Int32 nClosestStartIndex;
    for( nAttr=0, nClosestStartIndex=0; nAttr<aCharAttribs.Count(); ++nAttr )
    {
        nCurrIndex = aCharAttribs[nAttr].nStart;

        if( nCurrIndex > nIndex )
            break; // aCharAttribs array is sorted in increasing order for nStart values

        if( nCurrIndex > nClosestStartIndex )
        {
            nClosestStartIndex = nCurrIndex;
        }
    }

    // find closest index behind of nIndex
    sal_Int32 nClosestEndIndex;
    for( nAttr=0, nClosestEndIndex=rEE.GetTextLen(nPara); nAttr<aCharAttribs.Count(); ++nAttr )
    {
        nCurrIndex = aCharAttribs[nAttr].nEnd;

        if( nCurrIndex > nIndex &&
            nCurrIndex < nClosestEndIndex )
        {
            nClosestEndIndex = nCurrIndex;
        }
    }

    nStartIndex = static_cast<USHORT>( nClosestStartIndex );
    nEndIndex = static_cast<USHORT>( nClosestEndIndex );

    return sal_True;
}

Point SvxEditSourceHelper::EEToUserSpace( const Point& rPoint, const Size& rEESize, bool bIsVertical )
{
    return bIsVertical ? Point( -rPoint.Y() + rEESize.Height(), rPoint.X() ) : rPoint;
}

Point SvxEditSourceHelper::UserSpaceToEE( const Point& rPoint, const Size& rEESize, bool bIsVertical )
{
    return bIsVertical ? Point( rPoint.Y(), -rPoint.X() + rEESize.Height() ) : rPoint;
}

Rectangle SvxEditSourceHelper::EEToUserSpace( const Rectangle& rRect, const Size& rEESize, bool bIsVertical )
{
    // #106775# Don't touch rect if not vertical
    return bIsVertical ? Rectangle( EEToUserSpace(rRect.BottomLeft(), rEESize, bIsVertical),
                                    EEToUserSpace(rRect.TopRight(), rEESize, bIsVertical) ) : rRect;
}

Rectangle SvxEditSourceHelper::UserSpaceToEE( const Rectangle& rRect, const Size& rEESize, bool bIsVertical )
{
    // #106775# Don't touch rect if not vertical
    return bIsVertical ? Rectangle( UserSpaceToEE(rRect.TopRight(), rEESize, bIsVertical),
                                    UserSpaceToEE(rRect.BottomLeft(), rEESize, bIsVertical) ) : rRect;
}
<commit_msg>INTEGRATION: CWS warnings01 (1.7.220); FILE MERGED 2006/02/17 16:21:31 cl 1.7.220.1: warning free code changes<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: unoedhlp.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-19 17:01:10 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif

#include "unoedhlp.hxx"
#include "editdata.hxx"
#include "editeng.hxx"

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

TYPEINIT1( SvxEditSourceHint, TextHint );

SvxEditSourceHint::SvxEditSourceHint( ULONG _nId ) :
    TextHint( _nId ),
    mnStart( 0 ),
    mnEnd( 0 )
{
}

SvxEditSourceHint::SvxEditSourceHint( ULONG _nId, ULONG nValue, ULONG nStart, ULONG nEnd ) :
    TextHint( _nId, nValue ),
    mnStart( nStart),
    mnEnd( nEnd )
{
}

ULONG SvxEditSourceHint::GetValue() const
{
    return TextHint::GetValue();
}

ULONG SvxEditSourceHint::GetStartValue() const
{
    return mnStart;
}

ULONG SvxEditSourceHint::GetEndValue() const
{
    return mnEnd;
}

void SvxEditSourceHint::SetValue( ULONG n )
{
    TextHint::SetValue( n );
}

void SvxEditSourceHint::SetStartValue( ULONG n )
{
    mnStart = n;
}

void SvxEditSourceHint::SetEndValue( ULONG n )
{
    mnEnd = n;
}

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

::std::auto_ptr<SfxHint> SvxEditSourceHelper::EENotification2Hint( EENotify* aNotify )
{
    if( aNotify )
    {
        switch( aNotify->eNotificationType )
        {
            case EE_NOTIFY_TEXTMODIFIED:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_MODIFIED, aNotify->nParagraph ) );

            case EE_NOTIFY_PARAGRAPHINSERTED:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAINSERTED, aNotify->nParagraph ) );

            case EE_NOTIFY_PARAGRAPHREMOVED:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAREMOVED, aNotify->nParagraph ) );

            case EE_NOTIFY_PARAGRAPHSMOVED:
                return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_PARASMOVED, aNotify->nParagraph, aNotify->nParam1, aNotify->nParam2 ) );

            case EE_NOTIFY_TEXTHEIGHTCHANGED:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_TEXTHEIGHTCHANGED, aNotify->nParagraph ) );

            case EE_NOTIFY_TEXTVIEWSCROLLED:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_VIEWSCROLLED ) );

            case EE_NOTIFY_TEXTVIEWSELECTIONCHANGED:
                return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_SELECTIONCHANGED ) );

            case EE_NOTIFY_BLOCKNOTIFICATION_START:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_START, 0 ) );

            case EE_NOTIFY_BLOCKNOTIFICATION_END:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_END, 0 ) );

            case EE_NOTIFY_INPUT_START:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_START, 0 ) );

            case EE_NOTIFY_INPUT_END:
                return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_END, 0 ) );

            default:
                DBG_ERROR( "SvxEditSourceHelper::EENotification2Hint unknown notification" );
                break;
        }
    }

    return ::std::auto_ptr<SfxHint>( new SfxHint() );
}

sal_Bool SvxEditSourceHelper::GetAttributeRun( USHORT& nStartIndex, USHORT& nEndIndex, const EditEngine& rEE, USHORT nPara, USHORT nIndex )
{
    EECharAttribArray aCharAttribs;

    rEE.GetCharAttribs( nPara, aCharAttribs );

    // find closest index in front of nIndex
    USHORT nAttr, nCurrIndex;
    sal_Int32 nClosestStartIndex;
    for( nAttr=0, nClosestStartIndex=0; nAttr<aCharAttribs.Count(); ++nAttr )
    {
        nCurrIndex = aCharAttribs[nAttr].nStart;

        if( nCurrIndex > nIndex )
            break; // aCharAttribs array is sorted in increasing order for nStart values

        if( nCurrIndex > nClosestStartIndex )
        {
            nClosestStartIndex = nCurrIndex;
        }
    }

    // find closest index behind of nIndex
    sal_Int32 nClosestEndIndex;
    for( nAttr=0, nClosestEndIndex=rEE.GetTextLen(nPara); nAttr<aCharAttribs.Count(); ++nAttr )
    {
        nCurrIndex = aCharAttribs[nAttr].nEnd;

        if( nCurrIndex > nIndex &&
            nCurrIndex < nClosestEndIndex )
        {
            nClosestEndIndex = nCurrIndex;
        }
    }

    nStartIndex = static_cast<USHORT>( nClosestStartIndex );
    nEndIndex = static_cast<USHORT>( nClosestEndIndex );

    return sal_True;
}

Point SvxEditSourceHelper::EEToUserSpace( const Point& rPoint, const Size& rEESize, bool bIsVertical )
{
    return bIsVertical ? Point( -rPoint.Y() + rEESize.Height(), rPoint.X() ) : rPoint;
}

Point SvxEditSourceHelper::UserSpaceToEE( const Point& rPoint, const Size& rEESize, bool bIsVertical )
{
    return bIsVertical ? Point( rPoint.Y(), -rPoint.X() + rEESize.Height() ) : rPoint;
}

Rectangle SvxEditSourceHelper::EEToUserSpace( const Rectangle& rRect, const Size& rEESize, bool bIsVertical )
{
    // #106775# Don't touch rect if not vertical
    return bIsVertical ? Rectangle( EEToUserSpace(rRect.BottomLeft(), rEESize, bIsVertical),
                                    EEToUserSpace(rRect.TopRight(), rEESize, bIsVertical) ) : rRect;
}

Rectangle SvxEditSourceHelper::UserSpaceToEE( const Rectangle& rRect, const Size& rEESize, bool bIsVertical )
{
    // #106775# Don't touch rect if not vertical
    return bIsVertical ? Rectangle( UserSpaceToEE(rRect.TopRight(), rEESize, bIsVertical),
                                    UserSpaceToEE(rRect.BottomLeft(), rEESize, bIsVertical) ) : rRect;
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: visiturl.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: jp $ $Date: 2001-08-31 11:07:56 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#ifdef PRECOMPILED
#include "core_pch.hxx"
#endif

#pragma hdrstop

#ifndef _SFXDOCFILE_HXX //autogen
#include <sfx2/docfile.hxx>
#endif
#ifndef _INETHIST_HXX //autogen
#include <svtools/inethist.hxx>
#endif
#ifndef _URLOBJ_HXX //autogen
#include <tools/urlobj.hxx>
#endif

#ifndef _FMTINFMT_HXX //autogen
#include <fmtinfmt.hxx>
#endif
#ifndef _TXTINET_HXX //autogen
#include <txtinet.hxx>
#endif
#ifndef _DOC_HXX
#include <doc.hxx>
#endif
#ifndef _VISITURL_HXX
#include <visiturl.hxx>
#endif
#ifndef _HINTS_HXX
#include <hints.hxx>
#endif
#ifndef _NDTXT_HXX
#include <ndtxt.hxx>
#endif
#ifndef _EDITSH_HXX
#include <editsh.hxx>
#endif
#ifndef _DOCSH_HXX
#include <docsh.hxx>
#endif

SwURLStateChanged::SwURLStateChanged( const SwDoc* pD )
    : pDoc( pD )
{
    StartListening( *INetURLHistory::GetOrCreate() );
}

SwURLStateChanged::~SwURLStateChanged()
{
    EndListening( *INetURLHistory::GetOrCreate() );
}

void SwURLStateChanged::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
{
    if( rHint.ISA( INetURLHistoryHint ) && pDoc->GetRootFrm() )
    {
        // diese URL wurde veraendert:
        const INetURLObject* pIURL = ((INetURLHistoryHint&)rHint).GetObject();
        String sURL( pIURL->GetMainURL( INetURLObject::NO_DECODE ) ), sBkmk;

        SwEditShell* pESh = pDoc->GetEditShell();

        if( pDoc->GetDocShell() && pDoc->GetDocShell()->GetMedium() &&
            // falls das unser Doc ist, kann es auch lokale Spruenge geben!
            sURL == pDoc->GetDocShell()->GetMedium()->GetName() )
            (sBkmk = pIURL->GetMark()).Insert( INET_MARK_TOKEN, 0 );

        BOOL bAction = FALSE, bUnLockView = FALSE;
        const SwFmtINetFmt* pItem;
        const SwTxtINetFmt* pTxtAttr;
        const SwTxtNode* pTxtNd;
        USHORT n, nMaxItems = pDoc->GetAttrPool().GetItemCount( RES_TXTATR_INETFMT );
        for( n = 0; n < nMaxItems; ++n )
            if( 0 != (pItem = (SwFmtINetFmt*)pDoc->GetAttrPool().GetItem(
                RES_TXTATR_INETFMT, n ) ) &&
                ( pItem->GetValue() == sURL ||
                    ( sBkmk.Len() && pItem->GetValue() == sBkmk )) &&
                0 != ( pTxtAttr = pItem->GetTxtINetFmt()) &&
                0 != ( pTxtNd = pTxtAttr->GetpTxtNode() ) )
            {
                if( !bAction && pESh )
                {
                    pESh->StartAllAction();
                    bAction = TRUE;
                    bUnLockView = !pESh->IsViewLocked();
                    pESh->LockView( TRUE );
                }
                ((SwTxtINetFmt*)pTxtAttr)->SetValidVis( FALSE );
                const SwTxtAttr* pAttr = pTxtAttr;
                SwUpdateAttr aUpdateAttr( *pAttr->GetStart(),
                                          *pAttr->GetEnd(),
                                          RES_FMT_CHG );
                ((SwTxtNode*)pTxtNd)->SwCntntNode::Modify( &aUpdateAttr,
                                                            &aUpdateAttr );
            }

        if( bAction )
            pESh->EndAllAction();
         if( bUnLockView )
             pESh->LockView( FALSE );
    }
}

    // erfrage ob die URL besucht war. Uebers Doc, falls nur ein Bookmark
    // angegeben ist. Dann muss der Doc. Name davor gesetzt werden!
BOOL SwDoc::IsVisitedURL( const String& rURL ) const
{
#ifdef DEBUG
    static long nTmp = 0;
    ++nTmp;
#endif

    BOOL bRet = FALSE;
    if( rURL.Len() )
    {
        INetURLHistory *pHist = INetURLHistory::GetOrCreate();
        if( '#' == rURL.GetChar( 0 ) && pDocShell && pDocShell->GetMedium() )
        {
            INetURLObject aIObj( pDocShell->GetMedium()->GetURLObject() );
            aIObj.SetMark( rURL.Copy( 1 ) );
            bRet = pHist->QueryUrl( aIObj );
        }
        else
            bRet = pHist->QueryUrl( rURL );

        // dann  wollen wird auch ueber Statusaenderungen in der History
        // informiert werden!
        if( !pURLStateChgd )
        {
            SwDoc* pD = (SwDoc*)this;
            pD->pURLStateChgd = new SwURLStateChanged( this );
        }
    }
    return bRet;
}

<commit_msg>INTEGRATION: CWS dbgmacros1 (1.2.170); FILE MERGED 2003/04/10 09:01:06 kso 1.2.170.1: #108413# - debug macro unification.<commit_after>/*************************************************************************
 *
 *  $RCSfile: visiturl.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: vg $ $Date: 2003-04-15 16:49:09 $
 *
 *  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): _______________________________________
 *
 *
 ************************************************************************/

#ifdef PRECOMPILED
#include "core_pch.hxx"
#endif

#pragma hdrstop

#ifndef _SFXDOCFILE_HXX //autogen
#include <sfx2/docfile.hxx>
#endif
#ifndef _INETHIST_HXX //autogen
#include <svtools/inethist.hxx>
#endif
#ifndef _URLOBJ_HXX //autogen
#include <tools/urlobj.hxx>
#endif

#ifndef _FMTINFMT_HXX //autogen
#include <fmtinfmt.hxx>
#endif
#ifndef _TXTINET_HXX //autogen
#include <txtinet.hxx>
#endif
#ifndef _DOC_HXX
#include <doc.hxx>
#endif
#ifndef _VISITURL_HXX
#include <visiturl.hxx>
#endif
#ifndef _HINTS_HXX
#include <hints.hxx>
#endif
#ifndef _NDTXT_HXX
#include <ndtxt.hxx>
#endif
#ifndef _EDITSH_HXX
#include <editsh.hxx>
#endif
#ifndef _DOCSH_HXX
#include <docsh.hxx>
#endif

SwURLStateChanged::SwURLStateChanged( const SwDoc* pD )
    : pDoc( pD )
{
    StartListening( *INetURLHistory::GetOrCreate() );
}

SwURLStateChanged::~SwURLStateChanged()
{
    EndListening( *INetURLHistory::GetOrCreate() );
}

void SwURLStateChanged::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
{
    if( rHint.ISA( INetURLHistoryHint ) && pDoc->GetRootFrm() )
    {
        // diese URL wurde veraendert:
        const INetURLObject* pIURL = ((INetURLHistoryHint&)rHint).GetObject();
        String sURL( pIURL->GetMainURL( INetURLObject::NO_DECODE ) ), sBkmk;

        SwEditShell* pESh = pDoc->GetEditShell();

        if( pDoc->GetDocShell() && pDoc->GetDocShell()->GetMedium() &&
            // falls das unser Doc ist, kann es auch lokale Spruenge geben!
            sURL == pDoc->GetDocShell()->GetMedium()->GetName() )
            (sBkmk = pIURL->GetMark()).Insert( INET_MARK_TOKEN, 0 );

        BOOL bAction = FALSE, bUnLockView = FALSE;
        const SwFmtINetFmt* pItem;
        const SwTxtINetFmt* pTxtAttr;
        const SwTxtNode* pTxtNd;
        USHORT n, nMaxItems = pDoc->GetAttrPool().GetItemCount( RES_TXTATR_INETFMT );
        for( n = 0; n < nMaxItems; ++n )
            if( 0 != (pItem = (SwFmtINetFmt*)pDoc->GetAttrPool().GetItem(
                RES_TXTATR_INETFMT, n ) ) &&
                ( pItem->GetValue() == sURL ||
                    ( sBkmk.Len() && pItem->GetValue() == sBkmk )) &&
                0 != ( pTxtAttr = pItem->GetTxtINetFmt()) &&
                0 != ( pTxtNd = pTxtAttr->GetpTxtNode() ) )
            {
                if( !bAction && pESh )
                {
                    pESh->StartAllAction();
                    bAction = TRUE;
                    bUnLockView = !pESh->IsViewLocked();
                    pESh->LockView( TRUE );
                }
                ((SwTxtINetFmt*)pTxtAttr)->SetValidVis( FALSE );
                const SwTxtAttr* pAttr = pTxtAttr;
                SwUpdateAttr aUpdateAttr( *pAttr->GetStart(),
                                          *pAttr->GetEnd(),
                                          RES_FMT_CHG );
                ((SwTxtNode*)pTxtNd)->SwCntntNode::Modify( &aUpdateAttr,
                                                            &aUpdateAttr );
            }

        if( bAction )
            pESh->EndAllAction();
         if( bUnLockView )
             pESh->LockView( FALSE );
    }
}

    // erfrage ob die URL besucht war. Uebers Doc, falls nur ein Bookmark
    // angegeben ist. Dann muss der Doc. Name davor gesetzt werden!
BOOL SwDoc::IsVisitedURL( const String& rURL ) const
{
#if OSL_DEBUG_LEVEL > 1
    static long nTmp = 0;
    ++nTmp;
#endif

    BOOL bRet = FALSE;
    if( rURL.Len() )
    {
        INetURLHistory *pHist = INetURLHistory::GetOrCreate();
        if( '#' == rURL.GetChar( 0 ) && pDocShell && pDocShell->GetMedium() )
        {
            INetURLObject aIObj( pDocShell->GetMedium()->GetURLObject() );
            aIObj.SetMark( rURL.Copy( 1 ) );
            bRet = pHist->QueryUrl( aIObj );
        }
        else
            bRet = pHist->QueryUrl( rURL );

        // dann  wollen wird auch ueber Statusaenderungen in der History
        // informiert werden!
        if( !pURLStateChgd )
        {
            SwDoc* pD = (SwDoc*)this;
            pD->pURLStateChgd = new SwURLStateChanged( this );
        }
    }
    return bRet;
}

<|endoftext|>


<commit_before>#ifndef BLUETOE_ENCRYPTION_HPP
#define BLUETOE_ENCRYPTION_HPP

#include <bluetoe/options.hpp>
#include <bluetoe/meta_types.hpp>

namespace bluetoe {

    template < typename ... Options >
    class server;

    template < typename ... Options >
    class service;

    template < typename ... Options >
    class characteristic;

    namespace details {
        struct requires_encryption_meta_type {};
        struct no_encryption_required_meta_type {};
        struct may_require_encryption_meta_type {};
    };

    /**
     * @brief defines that access to characteristic(s) require an encrypted link without
     *        MITM Protection.
     *
     * Can be used on server, service or characteristic level to define that the access
     * to a characteristic requires an encrypted link. If the link is not encrypted,
     * when accessing the characteristic, Bluetoe replies with an ATT Insufficient Authorization
     * error, if the requesting device is not paired and ATT Insufficient Encryption, if the
     * device is paired, but the link is not encrypted.
     * (see table 10.2 Vol 3, Part C, 10.3.1)
     *
     * If applied to a server or service definition, this definition applies to all containing
     * characteristics, where it can be overridden.
     *
     * Example
     * @code
    char simple_value = 0;
    constexpr char name[] = "This is the name of the characteristic";

    using server = bluetoe::server<
        // By default, require encryption for all characteristics of
        // all services.
        bluetoe::requires_encryption,
        // Service A
        bluetoe::service<
            // But for this service, no encryption is required
            bluetoe::no_encryption_required,
            service_uuid_a,
            ...
        >,
        // Service B
        bluetoe::service<
            service_uuid_b,
            bluetoe::characteristic<
                char_uuid,
                // For all characteristics of this service, but this characteristic,
                // encryption is required
                bluetoe::no_encryption_required
            >,
            ...
        >,
        // Service C
    >;
     * @endcode
     *
     * @sa characteristic
     * @sa service
     * @sa server
     * @sa no_encryption_required
     * @sa may_require_encryption
     */
    struct requires_encryption {
        /** @cond HIDDEN_SYMBOLS */
        struct meta_type :
            details::requires_encryption_meta_type,
            details::valid_server_option_meta_type,
            details::valid_service_option_meta_type,
            details::valid_characteristic_option_meta_type {};
        /** @endcond */
    };

    /**
     * @brief defines that access to characteristic(s) does not require an encrypted link.
     *
     * If applied to a server or service definition, this definition applies to all containing
     * characteristics, where it can be overridden.
     *
     * If no characteristic in the entire server requires encryption, Bluetoe will leave out
     * the support code for encryption.
     *
     * @sa requires_encryption
     * @sa may_require_encryption
     */
    struct no_encryption_required {
        /** @cond HIDDEN_SYMBOLS */
        struct meta_type :
            details::no_encryption_required_meta_type,
            details::valid_server_option_meta_type,
            details::valid_service_option_meta_type,
            details::valid_characteristic_option_meta_type {};
        /** @endcond */
    };

    /**
     * @brief defines that a characteristic may require encyption
     *
     * The declaration forces bluetoe add the required code for encrypting
     * links. Basecally this means that a custom characterstic read or write handler
     * may require encryption under specific circumstances.
     *
     * This option can be passed to a server, service or a characteristic declaration.
     *
     * @sa requires_encryption
     * @sa no_encryption_required
     */
    struct may_require_encryption {
        /** @cond HIDDEN_SYMBOLS */
        struct meta_type :
            details::may_require_encryption_meta_type,
            details::valid_server_option_meta_type,
            details::valid_service_option_meta_type,
            details::valid_characteristic_option_meta_type {};
        /** @endcond */
    };

    namespace details {

        template < typename Server, bool Default = false >
        struct requires_encryption_support_t
        {
            static bool constexpr value = Default;
        };

        template < typename ... Options, typename T >
        struct requires_encryption_support_t< std::tuple< T, Options... >, false >
        {
            static bool constexpr value =
                requires_encryption_support_t< T, false >::value
             || requires_encryption_support_t< std::tuple< Options... >, false >::value;
        };

        template < typename ... Options, typename T >
        struct requires_encryption_support_t< std::tuple< T, Options... >, true >
        {
            static bool constexpr value =
                requires_encryption_support_t< T, true >::value
             && requires_encryption_support_t< std::tuple< Options... >, true >::value;
        };

        template < bool Default, typename ... Options >
        struct encryption_default
        {
            static bool constexpr require_encryption =
                details::has_option< requires_encryption, Options... >::value
             || details::has_option< may_require_encryption, Options... >::value;

            static bool constexpr require_not_encryption =
                 details::has_option< no_encryption_required, Options... >::value;

            // require !require default | value
            //    true    false   false |  true
            //   false     true   false | false
            //   false    false   false | false
            //    true    false    true |  true
            //   false     true    true | false
            //   false    false    true |  true
            static bool constexpr value =
                ( require_encryption && !require_not_encryption )
             || ( !require_encryption && !require_not_encryption && Default );

        };

        template < typename ... Options, bool Default >
        struct requires_encryption_support_t< bluetoe::server< Options... >, Default > {
            static bool constexpr default_val = encryption_default< Default, Options... >::value;

            static bool constexpr value =
                requires_encryption_support_t<
                    typename bluetoe::server< Options... >::services,
                    default_val >::value;
        };

        template < typename ... Options, bool Default >
        struct requires_encryption_support_t< bluetoe::service< Options... >, Default > {
            static bool constexpr default_val = encryption_default< Default, Options... >::value;

            static bool constexpr value =
                requires_encryption_support_t<
                    typename bluetoe::service< Options... >::characteristics,
                    default_val >::value;
        };

        template < typename ... Options, bool Default >
        struct requires_encryption_support_t< bluetoe::characteristic< Options... >, Default > {
            // @TODO the default for a characteristic should always be true
            static bool constexpr value = encryption_default< Default, Options... >::value;
        };

        template < typename Characteristic, typename Service, typename Server >
        struct characteristic_requires_encryption;

        template < typename ... CharacteristicOptions, typename ... ServiceOptions, typename ... ServerOptions >
        struct characteristic_requires_encryption<
            bluetoe::characteristic< CharacteristicOptions... >,
            bluetoe::service< ServiceOptions... >,
            bluetoe::server< ServerOptions... > >
        {
            // @TODO the default for a characteristic should always be true
            static bool constexpr server_requires_encryption  = encryption_default< false, ServerOptions... >::value;
            static bool constexpr service_requires_encryption = encryption_default< server_requires_encryption, ServiceOptions... >::value;

            static bool constexpr value                       = encryption_default< service_requires_encryption, CharacteristicOptions... >::value;
        };
    }

} // namespace bluetoe

#endif
<commit_msg>; removed<commit_after>#ifndef BLUETOE_ENCRYPTION_HPP
#define BLUETOE_ENCRYPTION_HPP

#include <bluetoe/options.hpp>
#include <bluetoe/meta_types.hpp>

namespace bluetoe {

    template < typename ... Options >
    class server;

    template < typename ... Options >
    class service;

    template < typename ... Options >
    class characteristic;

    namespace details {
        struct requires_encryption_meta_type {};
        struct no_encryption_required_meta_type {};
        struct may_require_encryption_meta_type {};
    }

    /**
     * @brief defines that access to characteristic(s) require an encrypted link without
     *        MITM Protection.
     *
     * Can be used on server, service or characteristic level to define that the access
     * to a characteristic requires an encrypted link. If the link is not encrypted,
     * when accessing the characteristic, Bluetoe replies with an ATT Insufficient Authorization
     * error, if the requesting device is not paired and ATT Insufficient Encryption, if the
     * device is paired, but the link is not encrypted.
     * (see table 10.2 Vol 3, Part C, 10.3.1)
     *
     * If applied to a server or service definition, this definition applies to all containing
     * characteristics, where it can be overridden.
     *
     * Example
     * @code
    char simple_value = 0;
    constexpr char name[] = "This is the name of the characteristic";

    using server = bluetoe::server<
        // By default, require encryption for all characteristics of
        // all services.
        bluetoe::requires_encryption,
        // Service A
        bluetoe::service<
            // But for this service, no encryption is required
            bluetoe::no_encryption_required,
            service_uuid_a,
            ...
        >,
        // Service B
        bluetoe::service<
            service_uuid_b,
            bluetoe::characteristic<
                char_uuid,
                // For all characteristics of this service, but this characteristic,
                // encryption is required
                bluetoe::no_encryption_required
            >,
            ...
        >,
        // Service C
    >;
     * @endcode
     *
     * @sa characteristic
     * @sa service
     * @sa server
     * @sa no_encryption_required
     * @sa may_require_encryption
     */
    struct requires_encryption {
        /** @cond HIDDEN_SYMBOLS */
        struct meta_type :
            details::requires_encryption_meta_type,
            details::valid_server_option_meta_type,
            details::valid_service_option_meta_type,
            details::valid_characteristic_option_meta_type {};
        /** @endcond */
    };

    /**
     * @brief defines that access to characteristic(s) does not require an encrypted link.
     *
     * If applied to a server or service definition, this definition applies to all containing
     * characteristics, where it can be overridden.
     *
     * If no characteristic in the entire server requires encryption, Bluetoe will leave out
     * the support code for encryption.
     *
     * @sa requires_encryption
     * @sa may_require_encryption
     */
    struct no_encryption_required {
        /** @cond HIDDEN_SYMBOLS */
        struct meta_type :
            details::no_encryption_required_meta_type,
            details::valid_server_option_meta_type,
            details::valid_service_option_meta_type,
            details::valid_characteristic_option_meta_type {};
        /** @endcond */
    };

    /**
     * @brief defines that a characteristic may require encyption
     *
     * The declaration forces bluetoe add the required code for encrypting
     * links. Basecally this means that a custom characterstic read or write handler
     * may require encryption under specific circumstances.
     *
     * This option can be passed to a server, service or a characteristic declaration.
     *
     * @sa requires_encryption
     * @sa no_encryption_required
     */
    struct may_require_encryption {
        /** @cond HIDDEN_SYMBOLS */
        struct meta_type :
            details::may_require_encryption_meta_type,
            details::valid_server_option_meta_type,
            details::valid_service_option_meta_type,
            details::valid_characteristic_option_meta_type {};
        /** @endcond */
    };

    namespace details {

        template < typename Server, bool Default = false >
        struct requires_encryption_support_t
        {
            static bool constexpr value = Default;
        };

        template < typename ... Options, typename T >
        struct requires_encryption_support_t< std::tuple< T, Options... >, false >
        {
            static bool constexpr value =
                requires_encryption_support_t< T, false >::value
             || requires_encryption_support_t< std::tuple< Options... >, false >::value;
        };

        template < typename ... Options, typename T >
        struct requires_encryption_support_t< std::tuple< T, Options... >, true >
        {
            static bool constexpr value =
                requires_encryption_support_t< T, true >::value
             && requires_encryption_support_t< std::tuple< Options... >, true >::value;
        };

        template < bool Default, typename ... Options >
        struct encryption_default
        {
            static bool constexpr require_encryption =
                details::has_option< requires_encryption, Options... >::value
             || details::has_option< may_require_encryption, Options... >::value;

            static bool constexpr require_not_encryption =
                 details::has_option< no_encryption_required, Options... >::value;

            // require !require default | value
            //    true    false   false |  true
            //   false     true   false | false
            //   false    false   false | false
            //    true    false    true |  true
            //   false     true    true | false
            //   false    false    true |  true
            static bool constexpr value =
                ( require_encryption && !require_not_encryption )
             || ( !require_encryption && !require_not_encryption && Default );

        };

        template < typename ... Options, bool Default >
        struct requires_encryption_support_t< bluetoe::server< Options... >, Default > {
            static bool constexpr default_val = encryption_default< Default, Options... >::value;

            static bool constexpr value =
                requires_encryption_support_t<
                    typename bluetoe::server< Options... >::services,
                    default_val >::value;
        };

        template < typename ... Options, bool Default >
        struct requires_encryption_support_t< bluetoe::service< Options... >, Default > {
            static bool constexpr default_val = encryption_default< Default, Options... >::value;

            static bool constexpr value =
                requires_encryption_support_t<
                    typename bluetoe::service< Options... >::characteristics,
                    default_val >::value;
        };

        template < typename ... Options, bool Default >
        struct requires_encryption_support_t< bluetoe::characteristic< Options... >, Default > {
            // @TODO the default for a characteristic should always be true
            static bool constexpr value = encryption_default< Default, Options... >::value;
        };

        template < typename Characteristic, typename Service, typename Server >
        struct characteristic_requires_encryption;

        template < typename ... CharacteristicOptions, typename ... ServiceOptions, typename ... ServerOptions >
        struct characteristic_requires_encryption<
            bluetoe::characteristic< CharacteristicOptions... >,
            bluetoe::service< ServiceOptions... >,
            bluetoe::server< ServerOptions... > >
        {
            // @TODO the default for a characteristic should always be true
            static bool constexpr server_requires_encryption  = encryption_default< false, ServerOptions... >::value;
            static bool constexpr service_requires_encryption = encryption_default< server_requires_encryption, ServiceOptions... >::value;

            static bool constexpr value                       = encryption_default< service_requires_encryption, CharacteristicOptions... >::value;
        };
    }

} // namespace bluetoe

#endif
<|endoftext|>


<commit_before><commit_msg>Translate German comments, fix some English ones<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: splittbl.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: rt $ $Date: 2007-04-26 09:20:21 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

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

#ifdef SW_DLLIMPLEMENTATION
#undef SW_DLLIMPLEMENTATION
#endif

#ifndef _WRTSH_HXX //autogen
#include <wrtsh.hxx>
#endif
#ifndef _SPLITTBL_HXX
#include <splittbl.hxx>
#endif
#include <splittbl.hrc>
#include <table.hrc>
#ifndef _TBLENUM_HXX
#include <tblenum.hxx>
#endif
/*-----------------17.03.98 10:56-------------------

--------------------------------------------------*/
SwSplitTblDlg::SwSplitTblDlg( Window *pParent, SwWrtShell &rSh ) :
    SvxStandardDialog(pParent, SW_RES(DLG_SPLIT_TABLE)),
    aOKPB(                  this, SW_RES(PB_OK      )),
    aCancelPB(              this, SW_RES(PB_CANCEL  )),
    aHelpPB(                this, SW_RES(PB_HELP        )),
    aSplitFL(               this, SW_RES(FL_SPLIT    )),
    aCntntCopyRB(           this, SW_RES(RB_CNTNT   )),
    aBoxAttrCopyWithParaRB( this, SW_RES(RB_BOX_PARA    )),
    aBoxAttrCopyNoParaRB(   this, SW_RES(RB_BOX_NOPARA)),
    aBorderCopyRB(          this, SW_RES(RB_BORDER  )),
    rShell(rSh)
{
    FreeResource();
    aCntntCopyRB.Check();
}

/*-----------------17.03.98 10:56-------------------

--------------------------------------------------*/
void SwSplitTblDlg::Apply()
{
    USHORT nSplit = HEADLINE_CNTNTCOPY;
    if(aBoxAttrCopyWithParaRB.IsChecked())
        nSplit = HEADLINE_BOXATRCOLLCOPY;
    if(aBoxAttrCopyNoParaRB.IsChecked())
        nSplit = HEADLINE_BOXATTRCOPY;
    else if(aBorderCopyRB.IsChecked())
        nSplit = HEADLINE_BORDERCOPY;

    rShell.SplitTable( nSplit );

}

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

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

#ifdef SW_DLLIMPLEMENTATION
#undef SW_DLLIMPLEMENTATION
#endif

#include <wrtsh.hxx>
#include <splittbl.hxx>
#include <splittbl.hrc>
#include <table.hrc>
#include <tblenum.hxx>
/*-----------------17.03.98 10:56-------------------

--------------------------------------------------*/
SwSplitTblDlg::SwSplitTblDlg( Window *pParent, SwWrtShell &rSh ) :
    SvxStandardDialog(pParent, SW_RES(DLG_SPLIT_TABLE)),
    aOKPB(                  this, SW_RES(PB_OK      )),
    aCancelPB(              this, SW_RES(PB_CANCEL  )),
    aHelpPB(                this, SW_RES(PB_HELP        )),
    aSplitFL(               this, SW_RES(FL_SPLIT    )),
    aCntntCopyRB(           this, SW_RES(RB_CNTNT   )),
    aBoxAttrCopyWithParaRB( this, SW_RES(RB_BOX_PARA    )),
    aBoxAttrCopyNoParaRB(   this, SW_RES(RB_BOX_NOPARA)),
    aBorderCopyRB(          this, SW_RES(RB_BORDER  )),
    rShell(rSh)
{
    FreeResource();
    aCntntCopyRB.Check();
}

/*-----------------17.03.98 10:56-------------------

--------------------------------------------------*/
void SwSplitTblDlg::Apply()
{
    USHORT nSplit = HEADLINE_CNTNTCOPY;
    if(aBoxAttrCopyWithParaRB.IsChecked())
        nSplit = HEADLINE_BOXATRCOLLCOPY;
    if(aBoxAttrCopyNoParaRB.IsChecked())
        nSplit = HEADLINE_BOXATTRCOPY;
    else if(aBorderCopyRB.IsChecked())
        nSplit = HEADLINE_BORDERCOPY;

    rShell.SplitTable( nSplit );

}

<|endoftext|>


<commit_before><commit_msg>refactor AutoFmtPreview to use RenderContext<commit_after><|endoftext|>


<commit_before>/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#include "paddle/fluid/framework/ir/graph.h"
#include "paddle/fluid/framework/program_desc.h"
#include "paddle/fluid/framework/var_desc.h"

namespace paddle {
namespace framework {

// NOTE(paddle-dev): This graph contains circle.
Graph::Graph(const ProgramDesc &program) : program_(program) {
  VLOG(3) << "block in program:" << program_.Size();
  std::unordered_map<std::string, VarDesc *> all_vars;
  for (auto *var : program.Block(0).AllVars()) {
    all_vars.emplace(var->Name(), var);
  }

  std::map<std::string, ir::Node *> var_nodes;
  for (auto *op : program.Block(0).AllOps()) {
    ir::Node *node = CreateOpNode(op);

    for (auto &each_var_name : op->InputArgumentNames()) {
      ir::Node *var = nullptr;
      if (var_nodes.find(each_var_name) != var_nodes.end()) {
        var = var_nodes.at(each_var_name);
      } else if (all_vars.count(each_var_name) != 0) {
        var = CreateVarNode(all_vars.at(each_var_name));
        var_nodes[each_var_name] = var;
      } else {
        // TODO(paddle-dev): Seems some assumption doesn't hold?
        LOG(ERROR) << op->Type()
                   << " input var not in all_var list: " << each_var_name;
        var = CreateEmptyNode(each_var_name, ir::Node::Type::kVariable);
        var_nodes[each_var_name] = var;
      }
      node->inputs.push_back(var);
      var->outputs.push_back(node);
    }

    for (auto &each_var_name : op->OutputArgumentNames()) {
      ir::Node *var = nullptr;
      if (var_nodes.find(each_var_name) != var_nodes.end()) {
        var = var_nodes.at(each_var_name);
      } else {
        var = CreateVarNode(all_vars.at(each_var_name));
        var_nodes[each_var_name] = var;
      }
      node->outputs.push_back(var);
      var->inputs.push_back(node);
    }
  }
}
}  // namespace framework
}  // namespace paddle
<commit_msg>disable warning<commit_after>/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#include "paddle/fluid/framework/ir/graph.h"
#include "paddle/fluid/framework/program_desc.h"
#include "paddle/fluid/framework/var_desc.h"

namespace paddle {
namespace framework {

// NOTE(paddle-dev): This graph contains circle.
Graph::Graph(const ProgramDesc &program) : program_(program) {
  VLOG(3) << "block in program:" << program_.Size();
  std::unordered_map<std::string, VarDesc *> all_vars;
  for (auto *var : program.Block(0).AllVars()) {
    all_vars.emplace(var->Name(), var);
  }

  std::map<std::string, ir::Node *> var_nodes;
  for (auto *op : program.Block(0).AllOps()) {
    ir::Node *node = CreateOpNode(op);

    for (auto &each_var_name : op->InputArgumentNames()) {
      ir::Node *var = nullptr;
      if (var_nodes.find(each_var_name) != var_nodes.end()) {
        var = var_nodes.at(each_var_name);
      } else if (all_vars.count(each_var_name) != 0) {
        var = CreateVarNode(all_vars.at(each_var_name));
        var_nodes[each_var_name] = var;
      } else {
        // TODO(paddle-dev): Seems some assumption doesn't hold?
        VLOG(3) << op->Type()
                << " input var not in all_var list: " << each_var_name;
        var = CreateEmptyNode(each_var_name, ir::Node::Type::kVariable);
        var_nodes[each_var_name] = var;
      }
      node->inputs.push_back(var);
      var->outputs.push_back(node);
    }

    for (auto &each_var_name : op->OutputArgumentNames()) {
      ir::Node *var = nullptr;
      if (var_nodes.find(each_var_name) != var_nodes.end()) {
        var = var_nodes.at(each_var_name);
      } else {
        var = CreateVarNode(all_vars.at(each_var_name));
        var_nodes[each_var_name] = var;
      }
      node->outputs.push_back(var);
      var->inputs.push_back(node);
    }
  }
}
}  // namespace framework
}  // namespace paddle
<|endoftext|>


<commit_before>// -*- Mode:C++ -*-

/**************************************************************************************************/
/*                                                                                */
/* Copyright (C) 2015 University of Hull                                                          */
/*                                                                                */
/**************************************************************************************************/
/*                                                                                */
/*  module     :  scene/test/loader_mtl.cpp                                                       */
/*  project    :                                                                                */
/*  description:                                                                                */
/*                                                                                */
/**************************************************************************************************/

// includes, system

#include <array>          // std::array<>
#include <glm/gtx/io.hpp> // glm::io::*

// includes, project

#include <loader/mtl.hpp>

#define UKACHULLDCS_USE_TRACE
#undef UKACHULLDCS_USE_TRACE
#include <support/trace.hpp>

// internal unnamed namespace

namespace {

  // types, internal (class, enum, struct, union, typedef)

  // variables, internal

  std::array<std::string const, 3> const materials = {
    {
      { "# Wavefront material file\n" },

      { "newmtl coating_black\n"
        "Ka 0.150000 0.150000 0.150000\n"
        "Kd 0.082353 0.082353 0.082353\n"
        "Ks 0.016471 0.016471 0.016471\n"
        "illum 2\n"
        "Ns 8\n" },

      { "newmtl seats\n"
        "#Ka 0.150000 0.150000 0.150000\n"
        "#Kd 0.480392 0.480392 0.431372\n"
        "#Ks 0.096078 0.096078 0.086274\n"
        "#illum 2\n"
        "#Ns 8\n"
        "Ka 0.150000 0.150000 0.150000\n"
        "Kd 1 1 1\n"
        "Ks 0.226471 0.226471 0.226471\n"
        "illum 2\n"
        "Ns 8\n"
        "map_Kd leather_coarse.png\n" },
    }
  };

  // functions, internal

} // namespace {

#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE(test_scene_loader_mtl_size)
{
  std::stringstream str;

  for (auto m : materials) {
    str << m << '\n';
  }

  // 'mtl::load' returns list of materials + dflt material
  BOOST_CHECK(materials.size() == scene::file::mtl::load(str).size());
}

BOOST_AUTO_TEST_CASE(test_scene_loader_mtl_properties)
{
  std::stringstream str;

  for (auto m : materials) {
    str << m << '\n';
  }

  using namespace scene::file;

  mtl::list_type const result(mtl::load(str));

  BOOST_CHECK("coating_black"                         == result[1]->name.get());
  BOOST_CHECK(glm::vec3(0.150000, 0.150000, 0.150000) == result[1]->ambient.get());
  BOOST_CHECK(glm::vec3(0.082353, 0.082353, 0.082353) == result[1]->diffuse.get());
  BOOST_CHECK(glm::vec3(0.016471, 0.016471, 0.016471) == result[1]->specular.get());
  BOOST_CHECK(8                                       == result[1]->shininess.get());
}
<commit_msg>update: material tests<commit_after>// -*- Mode:C++ -*-

/**************************************************************************************************/
/*                                                                                */
/* Copyright (C) 2015 University of Hull                                                          */
/*                                                                                */
/**************************************************************************************************/
/*                                                                                */
/*  module     :  scene/test/loader_mtl.cpp                                                       */
/*  project    :                                                                                */
/*  description:                                                                                */
/*                                                                                */
/**************************************************************************************************/

// includes, system

#include <array>          // std::array<>
#include <glm/gtx/io.hpp> // glm::io::*

// includes, project

#include <loader/mtl.hpp>

#define UKACHULLDCS_USE_TRACE
#undef UKACHULLDCS_USE_TRACE
#include <support/trace.hpp>

// internal unnamed namespace

namespace {

  // types, internal (class, enum, struct, union, typedef)

  // variables, internal

  std::array<std::string const, 17> const materials = {
    {
      { "# Wavefront material file\n"
        "# Material examples from [http://www.fileformat.info/format/material/]\n" },

      { "newmtl 01_neon_green\n"
        "Kd 0.0000 1.0000 0.0000\n"
        "illum 0\n" },

      { "newmtl 02_flat_green\n"
        "Ka 0.0000 1.0000 0.0000\n"
        "Kd 0.0000 1.0000 0.0000\n"
        "illum 1\n" },

      { "newmtl 03_dissolved_green\n"
        "Ka 0.0000 1.0000 0.0000\n"
        "Kd 0.0000 1.0000 0.0000\n"
        "d 0.8000\n"
        "illum 1\n" },

      { "newmtl 04_shiny_green\n"
        "Ka 0.0000 1.0000 0.0000\n"
        "Kd 0.0000 1.0000 0.0000\n"
        "Ks 1.0000 1.0000 1.0000\n"
        "Ns 200.0000\n"
        "illum 1\n" },

      { "newmtl 05_green_mirror\n"
        "Ka 0.0000 1.0000 0.0000\n"
        "Kd 0.0000 1.0000 0.0000\n"
        "Ks 0.0000 1.0000 0.0000\n"
        "Ns 200.0000\n"
        "illum 3\n" },

      { "newmtl 06_fake_windshield\n"
        "Ka 0.0000 0.0000 0.0000\n"
        "Kd 0.0000 0.0000 0.0000\n"
        "Ks 0.9000 0.9000 0.9000\n"
        "d 0.1000\n"
        "Ns 200\n"
        "illum 4\n" },

      { "newmtl 07_fresnel_blue\n"
        "Ka 0.0000 0.0000 0.0000\n"
        "Kd 0.0000 0.0000 0.0000\n"
        "Ks 0.6180 0.8760 0.1430\n"
        "Ns 200\n"
        "illum 5\n" },

      { "newmtl 08_real_windshield\n"
        "Ka 0.0000 0.0000 0.0000\n"
        "Kd 0.0000 0.0000 0.0000\n"
        "Ks 0.0000 0.0000 0.0000\n"
        "Tf 1.0000 1.0000 1.0000\n"
        "Ns 200\n"
        "Ni 1.2000\n"
        "illum 6\n" },

      { "newmtl 09_fresnel_windshield\n"
        "Ka 0.0000 0.0000 1.0000\n"
        "Kd 0.0000 0.0000 1.0000\n"
        "Ks 0.6180 0.8760 0.1430\n"
        "Tf 1.0000 1.0000 1.0000\n"
        "Ns 200\n"
        "Ni 1.2000\n"
        "illum 7\n" },

      { "newmtl 10_tin\n"
        "Ka spectral tin.rfl\n"
        "Kd spectral tin.rfl\n"
        "Ks spectral tin.rfl\n"
        "Ns 200\n"
        "illum 3\n" },

      { "newmtl 11_pine_wood\n"
        "Ka spectral ident.rfl 1\n"
        "Kd spectral ident.rfl 1\n"
        "illum 1\n"
        "map_Ka pine.mpc\n"
        "map_Kd pine.mpc\n" },

      { "newmtl 12_bumpy_leather\n"
        "Ka spectral ident.rfl 1\n"
        "Kd spectral ident.rfl 1\n"
        "Ks spectral ident.rfl 1\n"
        "illum 2\n"
        "map_Ka brown.mpc\n"
        "map_Kd brown.mpc\n"
        "map_Ks brown.mpc\n"
        "bump -bm 2.000 leath.mpb\n" },

      { "newmtl 13_frosted_window\n"
        "Ka 0.2 0.2 0.2\n"
        "Kd 0.6 0.6 0.6\n"
        "Ks 0.1 0.1 0.1\n"
        "d 1\n"
        "Ns 200\n"
        "illum 2\n"
        "map_d -mm 0.200 0.800 window.mps\n" },

      { "newmtl 14_shifted_logo\n"
        "Ka spectral ident.rfl 1\n"
        "Kd spectral ident.rfl 1\n"
        "Ks spectral ident.rfl 1\n"
        "illum 2\n"
        "map_Ka -o 0.200 0.000 0.000 logo.mpc\n"
        "map_Kd -o 0.200 0.000 0.000 logo.mpc\n"
        "map_Ks -o 0.200 0.000 0.000 logo.mpc\n" },

      { "newmtl 15_scaled_logo\n"
        "Ka spectral ident.rfl 1\n"
        "Kd spectral ident.rfl 1\n"
        "Ks spectral ident.rfl 1\n"
        "illum 2\n"
        "map_Ka -s 1.200 1.200 0.000 logo.mpc\n"
        "map_Kd -s 1.200 1.200 0.000 logo.mpc\n"
        "map_Ks -s 1.200 1.200 0.000 logo.mpc\n" },

      { "newmtl 16_chrome_with_spherical_reflection_map\n"
        "Ka 0 0 0\n"
        "Kd 0 0 0\n"
        "Ks .7 .7 .7\n"
        "illum 1\n"
        "refl -type sphere chrome.rla\n" },
    }
  };

  // functions, internal

} // namespace {

#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE(test_scene_loader_mtl_size)
{
  std::stringstream str;

  for (auto m : materials) {
    str << m << '\n';
  }

  // 'mtl::load' returns list of materials + dflt material
  BOOST_CHECK(materials.size() == scene::file::mtl::load(str).size());
}

BOOST_AUTO_TEST_CASE(test_scene_loader_mtl_properties)
{
  std::stringstream str;

  for (auto m : materials) {
    str << m << '\n';
  }

  using namespace scene::file;

  mtl::list_type const result(mtl::load(str));

  BOOST_CHECK("01_neon_green"          == result[1]->name.get());
  BOOST_CHECK(glm::vec3(0.0, 1.0, 0.0) == result[1]->diffuse.get());
}
<|endoftext|>


<commit_before>#include "coordsys.h"
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <tuple>

PYBIND11_MAKE_OPAQUE(std::vector<batoid::Vec3>);
PYBIND11_MAKE_OPAQUE(std::vector<batoid::Ray>);

namespace py = pybind11;

namespace batoid {
    void pyExportCoordSys(py::module& m) {
        py::class_<CoordSys, std::shared_ptr<CoordSys>>(m, "CoordSys")
            .def(py::init<>())
            .def(py::init<Vec3,Rot3>())
            .def_readonly("origin", &CoordSys::origin, "Global origin")
            .def_readonly("rotation", &CoordSys::rotation, "Unit vector rotation matrix")
            .def_property_readonly("x", &CoordSys::getX)
            .def_property_readonly("y", &CoordSys::getY)
            .def_property_readonly("z", &CoordSys::getZ)
            .def("__repr__", &CoordSys::repr)
            .def("shiftGlobal", &CoordSys::shiftGlobal)
            .def("shiftLocal", &CoordSys::shiftLocal)
            .def("rotateGlobal", (CoordSys (CoordSys::*) (const Rot3&) const) &CoordSys::rotateGlobal)
            .def("rotateGlobal", (CoordSys (CoordSys::*) (const Rot3&, const Vec3&, std::shared_ptr<CoordSys>) const) &CoordSys::rotateGlobal)
            .def("rotateLocal", (CoordSys (CoordSys::*) (const Rot3&) const) &CoordSys::rotateLocal)
            .def("rotateLocal", (CoordSys (CoordSys::*) (const Rot3&, const Vec3&, std::shared_ptr<CoordSys>) const) &CoordSys::rotateLocal);
    }

    std::tuple<py::array_t<double>, py::array_t<double>, py::array_t<double>>
    numpyApplyForward(const CoordTransform& ct,
                      py::array_t<double> xs,
                      py::array_t<double> ys,
                      py::array_t<double> zs) {
        auto bufX = xs.request();
        auto bufY = ys.request();
        auto bufZ = zs.request();
        if (bufX.ndim != bufY.ndim || bufX.ndim != bufZ.ndim)
            throw std::runtime_error("Dimensions must match");
        if (bufX.size != bufY.size || bufX.size != bufZ.size)
            throw std::runtime_error("Sizes much match");
        auto resultX = py::array_t<double>(bufX.shape, bufX.strides);
        auto resultY = py::array_t<double>(bufY.shape, bufY.strides);
        auto resultZ = py::array_t<double>(bufZ.shape, bufZ.strides);
        auto bufXOut = resultX.request();
        auto bufYOut = resultY.request();
        auto bufZOut = resultZ.request();

        double *ptrX = (double *) bufX.ptr;
        double *ptrY = (double *) bufY.ptr;
        double *ptrZ = (double *) bufZ.ptr;
        double *ptrXOut = (double *)  bufXOut.ptr;
        double *ptrYOut = (double *)  bufYOut.ptr;
        double *ptrZOut = (double *)  bufZOut.ptr;

        auto v = Vec3();
        for (size_t idx = 0; idx < bufX.size; idx++) {
            v = ct.applyForward(Vec3(ptrX[idx], ptrY[idx], ptrZ[idx]));
            ptrXOut[idx] = v.x;
            ptrYOut[idx] = v.y;
            ptrZOut[idx] = v.z;
        }
        return std::make_tuple(resultX, resultY, resultZ);
    }

    void pyExportCoordTransform(py::module& m) {
        py::class_<CoordTransform, std::shared_ptr<CoordTransform>>(m, "CoordTransform")
            .def(py::init<std::shared_ptr<CoordSys>,std::shared_ptr<CoordSys>>())
            .def("applyForward", (Vec3 (CoordTransform::*)(const Vec3&) const) &CoordTransform::applyForward)
            .def("applyReverse", (Vec3 (CoordTransform::*)(const Vec3&) const) &CoordTransform::applyReverse)
            .def("applyForward", [](const CoordTransform& ct, py::array_t<double> xs, py::array_t<double> ys, py::array_t<double> zs){
                return numpyApplyForward(ct, xs, ys, zs);
            })
            .def("applyForward", (Ray (CoordTransform::*)(const Ray&) const) &CoordTransform::applyForward)
            .def("applyReverse", (Ray (CoordTransform::*)(const Ray&) const) &CoordTransform::applyReverse)
            .def("applyForward", (std::vector<Ray> (CoordTransform::*)(const std::vector<Ray>&) const) &CoordTransform::applyForward)
            .def("applyReverse", (std::vector<Ray> (CoordTransform::*)(const std::vector<Ray>&) const) &CoordTransform::applyReverse)
            .def_readonly("source", &CoordTransform::source)
            .def_readonly("destination", &CoordTransform::destination);
    }
}
<commit_msg>Use correct size typedef<commit_after>#include "coordsys.h"
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <tuple>

PYBIND11_MAKE_OPAQUE(std::vector<batoid::Vec3>);
PYBIND11_MAKE_OPAQUE(std::vector<batoid::Ray>);

namespace py = pybind11;

namespace batoid {
    void pyExportCoordSys(py::module& m) {
        py::class_<CoordSys, std::shared_ptr<CoordSys>>(m, "CoordSys")
            .def(py::init<>())
            .def(py::init<Vec3,Rot3>())
            .def_readonly("origin", &CoordSys::origin, "Global origin")
            .def_readonly("rotation", &CoordSys::rotation, "Unit vector rotation matrix")
            .def_property_readonly("x", &CoordSys::getX)
            .def_property_readonly("y", &CoordSys::getY)
            .def_property_readonly("z", &CoordSys::getZ)
            .def("__repr__", &CoordSys::repr)
            .def("shiftGlobal", &CoordSys::shiftGlobal)
            .def("shiftLocal", &CoordSys::shiftLocal)
            .def("rotateGlobal", (CoordSys (CoordSys::*) (const Rot3&) const) &CoordSys::rotateGlobal)
            .def("rotateGlobal", (CoordSys (CoordSys::*) (const Rot3&, const Vec3&, std::shared_ptr<CoordSys>) const) &CoordSys::rotateGlobal)
            .def("rotateLocal", (CoordSys (CoordSys::*) (const Rot3&) const) &CoordSys::rotateLocal)
            .def("rotateLocal", (CoordSys (CoordSys::*) (const Rot3&, const Vec3&, std::shared_ptr<CoordSys>) const) &CoordSys::rotateLocal);
    }

    std::tuple<py::array_t<double>, py::array_t<double>, py::array_t<double>>
    numpyApplyForward(const CoordTransform& ct,
                      py::array_t<double> xs,
                      py::array_t<double> ys,
                      py::array_t<double> zs) {
        auto bufX = xs.request();
        auto bufY = ys.request();
        auto bufZ = zs.request();
        if (bufX.ndim != bufY.ndim || bufX.ndim != bufZ.ndim)
            throw std::runtime_error("Dimensions must match");
        if (bufX.size != bufY.size || bufX.size != bufZ.size)
            throw std::runtime_error("Sizes much match");
        auto resultX = py::array_t<double>(bufX.shape, bufX.strides);
        auto resultY = py::array_t<double>(bufY.shape, bufY.strides);
        auto resultZ = py::array_t<double>(bufZ.shape, bufZ.strides);
        auto bufXOut = resultX.request();
        auto bufYOut = resultY.request();
        auto bufZOut = resultZ.request();

        double *ptrX = (double *) bufX.ptr;
        double *ptrY = (double *) bufY.ptr;
        double *ptrZ = (double *) bufZ.ptr;
        double *ptrXOut = (double *)  bufXOut.ptr;
        double *ptrYOut = (double *)  bufYOut.ptr;
        double *ptrZOut = (double *)  bufZOut.ptr;

        auto v = Vec3();
        for (ssize_t idx = 0; idx < bufX.size; idx++) {
            v = ct.applyForward(Vec3(ptrX[idx], ptrY[idx], ptrZ[idx]));
            ptrXOut[idx] = v.x;
            ptrYOut[idx] = v.y;
            ptrZOut[idx] = v.z;
        }
        return std::make_tuple(resultX, resultY, resultZ);
    }

    void pyExportCoordTransform(py::module& m) {
        py::class_<CoordTransform, std::shared_ptr<CoordTransform>>(m, "CoordTransform")
            .def(py::init<std::shared_ptr<CoordSys>,std::shared_ptr<CoordSys>>())
            .def("applyForward", (Vec3 (CoordTransform::*)(const Vec3&) const) &CoordTransform::applyForward)
            .def("applyReverse", (Vec3 (CoordTransform::*)(const Vec3&) const) &CoordTransform::applyReverse)
            .def("applyForward", [](const CoordTransform& ct, py::array_t<double> xs, py::array_t<double> ys, py::array_t<double> zs){
                return numpyApplyForward(ct, xs, ys, zs);
            })
            .def("applyForward", (Ray (CoordTransform::*)(const Ray&) const) &CoordTransform::applyForward)
            .def("applyReverse", (Ray (CoordTransform::*)(const Ray&) const) &CoordTransform::applyReverse)
            .def("applyForward", (std::vector<Ray> (CoordTransform::*)(const std::vector<Ray>&) const) &CoordTransform::applyForward)
            .def("applyReverse", (std::vector<Ray> (CoordTransform::*)(const std::vector<Ray>&) const) &CoordTransform::applyReverse)
            .def_readonly("source", &CoordTransform::source)
            .def_readonly("destination", &CoordTransform::destination);
    }
}
<|endoftext|>