<commit_before>/*************************************************************************
 *
 * 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: DrawController.hxx,v $
 * $Revision: 1.18 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef SD_DRAW_CONTROLLER_HXX
#define SD_DRAW_CONTROLLER_HXX

#include "ViewShell.hxx"

#include <osl/mutex.hxx>
#include <cppuhelper/propshlp.hxx>
#include <sfx2/sfxbasecontroller.hxx>
#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <com/sun/star/view/XFormLayerAccess.hpp>
#include <com/sun/star/drawing/XDrawSubController.hpp>
#include <com/sun/star/drawing/XDrawView.hpp>
#include <com/sun/star/drawing/framework/XConfigurationController.hpp>
#include <com/sun/star/drawing/framework/XControllerManager.hpp>
#include <com/sun/star/drawing/framework/ModuleController.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
#include <comphelper/uno3.hxx>
#include <cppuhelper/implbase7.hxx>
#include <tools/weakbase.hxx>
#include <memory>
#include <vector>
#include <boost/scoped_ptr.hpp>

class SfxViewShell;
class SdXImpressDocument;

namespace css = ::com::sun::star;

namespace {

typedef ::cppu::ImplInheritanceHelper7 <
    SfxBaseController,
    ::com::sun::star::view::XSelectionSupplier,
    ::com::sun::star::lang::XServiceInfo,
    ::com::sun::star::drawing::XDrawView,
    ::com::sun::star::view::XSelectionChangeListener,
    ::com::sun::star::view::XFormLayerAccess,
    ::com::sun::star::drawing::framework::XControllerManager,
    ::com::sun::star::lang::XUnoTunnel
    > DrawControllerInterfaceBase;

class BroadcastHelperOwner
{
public:
    BroadcastHelperOwner (::osl::Mutex& rMutex) : maBroadcastHelper(rMutex) {};
    ::cppu::OBroadcastHelper maBroadcastHelper;
};

} // end of anonymous namespace.

namespace sd {

class DrawSubController;
class ViewShellBase;
class ViewShell;
class View;

/** The DrawController is the UNO controller for Impress and Draw.  It
    relies objects that implement the DrawSubController interface for view
    specific behaviour.  The life time of the DrawController is roughly that
    of ViewShellBase but note that the DrawController can (in the case of a
    reload) outlive the ViewShellBase.

    The implementation of the XControllerManager interface is not yet in its
    final form.
*/
class DrawController
    : public DrawControllerInterfaceBase,
      private BroadcastHelperOwner,
      public ::cppu::OPropertySetHelper
{
public:
    enum PropertyHandle {
        PROPERTY_WORKAREA = 0,
        PROPERTY_SUB_CONTROLLER = 1,
        PROPERTY_CURRENTPAGE = 2,
        PROPERTY_MASTERPAGEMODE = 3,
        PROPERTY_LAYERMODE = 4,
        PROPERTY_ACTIVE_LAYER = 5,
        PROPERTY_ZOOMTYPE = 6,
        PROPERTY_ZOOMVALUE = 7,
        PROPERTY_VIEWOFFSET = 8
    };

    /** Create a new DrawController object for the given ViewShellBase.
    */
    DrawController (ViewShellBase& rBase) throw();

    virtual ~DrawController (void) throw();

    /** Replace the currently used sub controller with the given one.  This
        new sub controller is used from now on for the view (that is the
        main view shell to be precise) specific tasks.  Call this method
        with a suitable sub controller whenever the view shell in the center
        pane is exchanged.
        @param pSubController
            The ViewShell specific sub controller or NULL when (temporarily
            while switching to another one) there is no ViewShell displayed
            in the center pane.
    */
    void SetSubController (
        const css::uno::Reference<css::drawing::XDrawSubController>& rxSubController);

    ::com::sun::star::awt::Rectangle GetVisArea (void) const;

    /** Call this method when the VisArea has changed.
    */
    void FireVisAreaChanged (const Rectangle& rVisArea) throw();

    /** Call this method when the selection has changed.
    */
    void FireSelectionChangeListener (void) throw();

    /** Call this method when the edit mode has changed.
    */
    void FireChangeEditMode (bool bMasterPageMode) throw();

    /** Call this method when the layer mode has changed.
    */
    void FireChangeLayerMode (bool bLayerMode) throw();

    /** Call this method when there is a new current page.
    */
    void FireSwitchCurrentPage (SdPage* pCurrentPage) throw();

    /** Return a pointer to the ViewShellBase object that the DrawController
        is connected to.
        @return
            The returned pointer is <NULL/> after a call to
            ReleaseViewShellBase().
    */
    ViewShellBase* GetViewShellBase (void);

    /** This method is typically called from the destructor of ViewShellBase
        to tell the DrawController that it and its members must not access
        the ViewShellBase anymore.
        After this call the DrawController is semi-disposed.
    */
    void ReleaseViewShellBase (void);

    static const ::com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId (void);

    DECLARE_XINTERFACE()
    DECLARE_XTYPEPROVIDER()

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

    // XController
    virtual ::sal_Bool SAL_CALL suspend( ::sal_Bool Suspend ) throw (::com::sun::star::uno::RuntimeException);

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

    // XSelectionSupplier
    virtual sal_Bool SAL_CALL select( const ::com::sun::star::uno::Any& aSelection ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Any SAL_CALL getSelection(  ) throw(::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL addSelectionChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL removeSelectionChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);

    // XPropertySet
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);

    // XFormLayerAccess
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormController > SAL_CALL getFormController( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& Form ) throw (::com::sun::star::uno::RuntimeException);
    virtual ::sal_Bool SAL_CALL isFormDesignMode(  ) throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL setFormDesignMode( ::sal_Bool DesignMode ) throw (::com::sun::star::uno::RuntimeException);

    // XControlAccess
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > SAL_CALL getControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& xModel ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);

    // XDrawView
    virtual void SAL_CALL
        setCurrentPage (
            const ::com::sun::star::uno::Reference<
            ::com::sun::star::drawing::XDrawPage >& xPage)
        throw(::com::sun::star::uno::RuntimeException);

    virtual ::com::sun::star::uno::Reference<
        ::com::sun::star::drawing::XDrawPage > SAL_CALL
        getCurrentPage (void)
        throw(::com::sun::star::uno::RuntimeException);

    // lang::XEventListener
    virtual void SAL_CALL
        disposing (const ::com::sun::star::lang::EventObject& rEventObject)
        throw (::com::sun::star::uno::RuntimeException);

    // view::XSelectionChangeListener
    virtual void  SAL_CALL
        selectionChanged (const ::com::sun::star::lang::EventObject& rEvent)
        throw (::com::sun::star::uno::RuntimeException);

    // XControllerManager

    virtual css::uno::Reference<css::drawing::framework::XConfigurationController> SAL_CALL
        getConfigurationController (void)
        throw (::com::sun::star::uno::RuntimeException);

    virtual css::uno::Reference<css::drawing::framework::XModuleController> SAL_CALL
        getModuleController (void)
        throw (::com::sun::star::uno::RuntimeException);

    // XUnoTunnel

    virtual sal_Int64 SAL_CALL getSomething (const com::sun::star::uno::Sequence<sal_Int8>& rId)
        throw (com::sun::star::uno::RuntimeException);

protected:
    /** This method must return the name to index table. This table
        contains all property names and types of this object.
     */
    virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();

    virtual void FillPropertyTable (
        ::std::vector< ::com::sun::star::beans::Property>& rProperties);

    /**
     * The same as getFastProperyValue, but return the value through
     * rValue and nHandle is always valid.
     */
    virtual void SAL_CALL getFastPropertyValue(
        ::com::sun::star::uno::Any& rValue,
        sal_Int32 nHandle ) const;

    /** Convert the value rValue and return the result in rConvertedValue and the
        old value in rOldValue.
        After this call the vetoable listeners are notified.

        @param rConvertedValue
            The converted value. Only set if return is true.
        @param rOldValue
            The old value. Only set if return is true.
        @param nHandle
            The handle of the proberty.
        @return
            <TRUE/> if the value is converted successfully.
        @throws IllegalArgumentException
     */
    virtual sal_Bool SAL_CALL convertFastPropertyValue(
        ::com::sun::star::uno::Any & rConvertedValue,
        ::com::sun::star::uno::Any & rOldValue,
        sal_Int32 nHandle,
        const ::com::sun::star::uno::Any& rValue )
        throw (::com::sun::star::lang::IllegalArgumentException);

    /** The same as setFastProperyValue, but no exception is thrown and nHandle
        is always valid. You must not broadcast the changes in this method.
     */
    virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
        sal_Int32 nHandle,
        const ::com::sun::star::uno::Any& rValue )
        throw (::com::sun::star::uno::Exception);

    /** When the called object has been disposed already this method throws
        a Disposed exception and does not return.
    */
    void ThrowIfDisposed (void) const
        throw (::com::sun::star::lang::DisposedException);

    using cppu::OPropertySetHelper::disposing;
    using cppu::OPropertySetHelper::getFastPropertyValue;

private:
    /** This pointer to the ViewShellBase can be NULL (after a call to
        ReleaseViewShellBase()).
    */
    ViewShellBase* mpBase;

    Rectangle maLastVisArea;
    ::tools::WeakReference<SdrPage> mpCurrentPage;
    bool mbMasterPageMode;
    bool mbLayerMode;

    /** This flag indicates whether the called DrawController is being
        disposed or already has been disposed.
    */
    bool mbDisposing;

    ::std::auto_ptr< ::cppu::IPropertyArrayHelper> mpPropertyArrayHelper;

    /** The current sub controller.  May be NULL.
    */
    css::uno::Reference<css::drawing::XDrawSubController> mxSubController;

    css::uno::Reference<
        css::drawing::framework::XConfigurationController> mxConfigurationController;
    css::uno::Reference<
        css::drawing::framework::XModuleController> mxModuleController;

    /** Send an event to all relevant property listeners that a
        property has changed its value.  The fire() method of the
        OPropertySetHelper is wrapped by this method to handle
        exceptions thrown by called listeners.
    */
    void FirePropertyChange (
        sal_Int32 nHandle,
        const ::com::sun::star::uno::Any& rNewValue,
        const ::com::sun::star::uno::Any& rOldValue);

    void ProvideFrameworkControllers (void);
    void DisposeFrameworkControllers (void);
};

} // end of namespace sd

#endif
<commit_msg>INTEGRATION: CWS hr50 (1.16.230); FILE MERGED 2008/04/14 13:05:57 hr 1.16.230.1: #i86574#: fix warning (gcc-4.2.3)<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: DrawController.hxx,v $
 * $Revision: 1.19 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef SD_DRAW_CONTROLLER_HXX
#define SD_DRAW_CONTROLLER_HXX

#include "ViewShell.hxx"

#include <osl/mutex.hxx>
#include <cppuhelper/propshlp.hxx>
#include <sfx2/sfxbasecontroller.hxx>
#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <com/sun/star/view/XFormLayerAccess.hpp>
#include <com/sun/star/drawing/XDrawSubController.hpp>
#include <com/sun/star/drawing/XDrawView.hpp>
#include <com/sun/star/drawing/framework/XConfigurationController.hpp>
#include <com/sun/star/drawing/framework/XControllerManager.hpp>
#include <com/sun/star/drawing/framework/ModuleController.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
#include <comphelper/uno3.hxx>
#include <cppuhelper/implbase7.hxx>
#include <tools/weakbase.hxx>
#include <memory>
#include <vector>
#include <boost/scoped_ptr.hpp>

class SfxViewShell;
class SdXImpressDocument;

namespace css = ::com::sun::star;

namespace sd {

typedef ::cppu::ImplInheritanceHelper7 <
    SfxBaseController,
    ::com::sun::star::view::XSelectionSupplier,
    ::com::sun::star::lang::XServiceInfo,
    ::com::sun::star::drawing::XDrawView,
    ::com::sun::star::view::XSelectionChangeListener,
    ::com::sun::star::view::XFormLayerAccess,
    ::com::sun::star::drawing::framework::XControllerManager,
    ::com::sun::star::lang::XUnoTunnel
    > DrawControllerInterfaceBase;

class BroadcastHelperOwner
{
public:
    BroadcastHelperOwner (::osl::Mutex& rMutex) : maBroadcastHelper(rMutex) {};
    ::cppu::OBroadcastHelper maBroadcastHelper;
};

class DrawSubController;
class ViewShellBase;
class ViewShell;
class View;

/** The DrawController is the UNO controller for Impress and Draw.  It
    relies objects that implement the DrawSubController interface for view
    specific behaviour.  The life time of the DrawController is roughly that
    of ViewShellBase but note that the DrawController can (in the case of a
    reload) outlive the ViewShellBase.

    The implementation of the XControllerManager interface is not yet in its
    final form.
*/
class DrawController
    : public DrawControllerInterfaceBase,
      private BroadcastHelperOwner,
      public ::cppu::OPropertySetHelper
{
public:
    enum PropertyHandle {
        PROPERTY_WORKAREA = 0,
        PROPERTY_SUB_CONTROLLER = 1,
        PROPERTY_CURRENTPAGE = 2,
        PROPERTY_MASTERPAGEMODE = 3,
        PROPERTY_LAYERMODE = 4,
        PROPERTY_ACTIVE_LAYER = 5,
        PROPERTY_ZOOMTYPE = 6,
        PROPERTY_ZOOMVALUE = 7,
        PROPERTY_VIEWOFFSET = 8
    };

    /** Create a new DrawController object for the given ViewShellBase.
    */
    DrawController (ViewShellBase& rBase) throw();

    virtual ~DrawController (void) throw();

    /** Replace the currently used sub controller with the given one.  This
        new sub controller is used from now on for the view (that is the
        main view shell to be precise) specific tasks.  Call this method
        with a suitable sub controller whenever the view shell in the center
        pane is exchanged.
        @param pSubController
            The ViewShell specific sub controller or NULL when (temporarily
            while switching to another one) there is no ViewShell displayed
            in the center pane.
    */
    void SetSubController (
        const css::uno::Reference<css::drawing::XDrawSubController>& rxSubController);

    ::com::sun::star::awt::Rectangle GetVisArea (void) const;

    /** Call this method when the VisArea has changed.
    */
    void FireVisAreaChanged (const Rectangle& rVisArea) throw();

    /** Call this method when the selection has changed.
    */
    void FireSelectionChangeListener (void) throw();

    /** Call this method when the edit mode has changed.
    */
    void FireChangeEditMode (bool bMasterPageMode) throw();

    /** Call this method when the layer mode has changed.
    */
    void FireChangeLayerMode (bool bLayerMode) throw();

    /** Call this method when there is a new current page.
    */
    void FireSwitchCurrentPage (SdPage* pCurrentPage) throw();

    /** Return a pointer to the ViewShellBase object that the DrawController
        is connected to.
        @return
            The returned pointer is <NULL/> after a call to
            ReleaseViewShellBase().
    */
    ViewShellBase* GetViewShellBase (void);

    /** This method is typically called from the destructor of ViewShellBase
        to tell the DrawController that it and its members must not access
        the ViewShellBase anymore.
        After this call the DrawController is semi-disposed.
    */
    void ReleaseViewShellBase (void);

    static const ::com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId (void);

    DECLARE_XINTERFACE()
    DECLARE_XTYPEPROVIDER()

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

    // XController
    virtual ::sal_Bool SAL_CALL suspend( ::sal_Bool Suspend ) throw (::com::sun::star::uno::RuntimeException);

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

    // XSelectionSupplier
    virtual sal_Bool SAL_CALL select( const ::com::sun::star::uno::Any& aSelection ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Any SAL_CALL getSelection(  ) throw(::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL addSelectionChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL removeSelectionChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);

    // XPropertySet
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);

    // XFormLayerAccess
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormController > SAL_CALL getFormController( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm >& Form ) throw (::com::sun::star::uno::RuntimeException);
    virtual ::sal_Bool SAL_CALL isFormDesignMode(  ) throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL setFormDesignMode( ::sal_Bool DesignMode ) throw (::com::sun::star::uno::RuntimeException);

    // XControlAccess
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > SAL_CALL getControl( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& xModel ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException);

    // XDrawView
    virtual void SAL_CALL
        setCurrentPage (
            const ::com::sun::star::uno::Reference<
            ::com::sun::star::drawing::XDrawPage >& xPage)
        throw(::com::sun::star::uno::RuntimeException);

    virtual ::com::sun::star::uno::Reference<
        ::com::sun::star::drawing::XDrawPage > SAL_CALL
        getCurrentPage (void)
        throw(::com::sun::star::uno::RuntimeException);

    // lang::XEventListener
    virtual void SAL_CALL
        disposing (const ::com::sun::star::lang::EventObject& rEventObject)
        throw (::com::sun::star::uno::RuntimeException);

    // view::XSelectionChangeListener
    virtual void  SAL_CALL
        selectionChanged (const ::com::sun::star::lang::EventObject& rEvent)
        throw (::com::sun::star::uno::RuntimeException);

    // XControllerManager

    virtual css::uno::Reference<css::drawing::framework::XConfigurationController> SAL_CALL
        getConfigurationController (void)
        throw (::com::sun::star::uno::RuntimeException);

    virtual css::uno::Reference<css::drawing::framework::XModuleController> SAL_CALL
        getModuleController (void)
        throw (::com::sun::star::uno::RuntimeException);

    // XUnoTunnel

    virtual sal_Int64 SAL_CALL getSomething (const com::sun::star::uno::Sequence<sal_Int8>& rId)
        throw (com::sun::star::uno::RuntimeException);

protected:
    /** This method must return the name to index table. This table
        contains all property names and types of this object.
     */
    virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();

    virtual void FillPropertyTable (
        ::std::vector< ::com::sun::star::beans::Property>& rProperties);

    /**
     * The same as getFastProperyValue, but return the value through
     * rValue and nHandle is always valid.
     */
    virtual void SAL_CALL getFastPropertyValue(
        ::com::sun::star::uno::Any& rValue,
        sal_Int32 nHandle ) const;

    /** Convert the value rValue and return the result in rConvertedValue and the
        old value in rOldValue.
        After this call the vetoable listeners are notified.

        @param rConvertedValue
            The converted value. Only set if return is true.
        @param rOldValue
            The old value. Only set if return is true.
        @param nHandle
            The handle of the proberty.
        @return
            <TRUE/> if the value is converted successfully.
        @throws IllegalArgumentException
     */
    virtual sal_Bool SAL_CALL convertFastPropertyValue(
        ::com::sun::star::uno::Any & rConvertedValue,
        ::com::sun::star::uno::Any & rOldValue,
        sal_Int32 nHandle,
        const ::com::sun::star::uno::Any& rValue )
        throw (::com::sun::star::lang::IllegalArgumentException);

    /** The same as setFastProperyValue, but no exception is thrown and nHandle
        is always valid. You must not broadcast the changes in this method.
     */
    virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
        sal_Int32 nHandle,
        const ::com::sun::star::uno::Any& rValue )
        throw (::com::sun::star::uno::Exception);

    /** When the called object has been disposed already this method throws
        a Disposed exception and does not return.
    */
    void ThrowIfDisposed (void) const
        throw (::com::sun::star::lang::DisposedException);

    using cppu::OPropertySetHelper::disposing;
    using cppu::OPropertySetHelper::getFastPropertyValue;

private:
    /** This pointer to the ViewShellBase can be NULL (after a call to
        ReleaseViewShellBase()).
    */
    ViewShellBase* mpBase;

    Rectangle maLastVisArea;
    ::tools::WeakReference<SdrPage> mpCurrentPage;
    bool mbMasterPageMode;
    bool mbLayerMode;

    /** This flag indicates whether the called DrawController is being
        disposed or already has been disposed.
    */
    bool mbDisposing;

    ::std::auto_ptr< ::cppu::IPropertyArrayHelper> mpPropertyArrayHelper;

    /** The current sub controller.  May be NULL.
    */
    css::uno::Reference<css::drawing::XDrawSubController> mxSubController;

    css::uno::Reference<
        css::drawing::framework::XConfigurationController> mxConfigurationController;
    css::uno::Reference<
        css::drawing::framework::XModuleController> mxModuleController;

    /** Send an event to all relevant property listeners that a
        property has changed its value.  The fire() method of the
        OPropertySetHelper is wrapped by this method to handle
        exceptions thrown by called listeners.
    */
    void FirePropertyChange (
        sal_Int32 nHandle,
        const ::com::sun::star::uno::Any& rNewValue,
        const ::com::sun::star::uno::Any& rOldValue);

    void ProvideFrameworkControllers (void);
    void DisposeFrameworkControllers (void);
};

} // end of namespace sd

#endif
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: MediaObjectBar.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: kz $ $Date: 2006-12-12 17:34:52 $
 *
 *  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 SD_MEDIA_OBJECT_BAR_HXX
#define SD_MEDIA_OBJECT_BAR_HXX

#ifndef _SFXMODULE_HXX //autogen
#include <sfx2/module.hxx>
#endif
#ifndef _SFX_SHELL_HXX //autogen
#include <sfx2/shell.hxx>
#endif
#ifndef _SD_GLOB_HXX
#include "glob.hxx"
#endif

namespace sd {

class View;
class ViewShell;

class MediaObjectBar
    : public SfxShell
{
public:
    TYPEINFO();
    SFX_DECL_INTERFACE( SD_IF_SDDRAWMEDIAOBJECTBAR )

    MediaObjectBar (ViewShell* pSdViewShell, ::sd::View* pSdView);
    virtual ~MediaObjectBar (void);

    void            GetState( SfxItemSet& rSet );
    void            Execute( SfxRequest& rReq );

protected:
    ::sd::View* mpView;
    ViewShell*  mpViewSh;
};

} // end of namespace sd

#endif
<commit_msg>INTEGRATION: CWS changefileheader (1.4.298); FILE MERGED 2008/04/01 15:35:12 thb 1.4.298.2: #i85898# Stripping all external header guards 2008/03/31 13:58:10 rt 1.4.298.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: MediaObjectBar.hxx,v $
 * $Revision: 1.5 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef SD_MEDIA_OBJECT_BAR_HXX
#define SD_MEDIA_OBJECT_BAR_HXX

#include <sfx2/module.hxx>
#include <sfx2/shell.hxx>
#include "glob.hxx"

namespace sd {

class View;
class ViewShell;

class MediaObjectBar
    : public SfxShell
{
public:
    TYPEINFO();
    SFX_DECL_INTERFACE( SD_IF_SDDRAWMEDIAOBJECTBAR )

    MediaObjectBar (ViewShell* pSdViewShell, ::sd::View* pSdView);
    virtual ~MediaObjectBar (void);

    void            GetState( SfxItemSet& rSet );
    void            Execute( SfxRequest& rReq );

protected:
    ::sd::View* mpView;
    ViewShell*  mpViewSh;
};

} // end of namespace sd

#endif
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: TestMenu.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: kz $ $Date: 2005-03-18 16:57:53 $
 *
 *  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 "TestMenu.hxx"

#include "taskpane/TaskPaneControlFactory.hxx"

#include <vcl/image.hxx>
#include <vcl/svapp.hxx>

namespace sd { namespace toolpanel {

/** This factory class is used to create instances of ColorMenu.  It can be
    extended so that its constructor stores arguments that later are passed
    to new ColorMenu objects.
*/
class ColorMenuFactory
    : public ControlFactory
{
protected:
    virtual TreeNode* InternalCreateControl (TreeNode* pTreeNode)
    {
        return new ColorMenu (pTreeNode);
    }
};

ColorMenu::ColorMenu (TreeNode* pParent)
    : Window (pParent->GetWindow()),
      TreeNode(pParent),
      maSet (this),
      mnPreferredColumnCount(2)
{
    WinBits aStyle =
        WB_ITEMBORDER
        | WB_DOUBLEBORDER
        | WB_NAMEFIELD
        | WB_FLATVALUESET
        | WB_TABSTOP
        | WB_VSCROLL;

    maSet.SetStyle (maSet.GetStyle() | aStyle);
    maSet.SetExtraSpacing(2);

    Fill ();
    maSet.Show();
    pParent->RequestResize();
}

ColorMenu::~ColorMenu (void)
{
}

::std::auto_ptr<ControlFactory> ColorMenu::CreateControlFactory (void)
{
    return ::std::auto_ptr<ControlFactory>(new ColorMenuFactory());
}

/** The preferred size depends on the preferred number of columns, the
    number of items, and the size of the items.
*/
Size ColorMenu::GetPreferredSize (void)
{
    Size aItemSize = maSet.CalcItemSizePixel (Size());
    Size aPreferredWindowSize = maSet.CalcWindowSizePixel (
        aItemSize,
        mnPreferredColumnCount,
        CalculateRowCount (aItemSize, mnPreferredColumnCount));
    return aPreferredWindowSize;
}

sal_Int32 ColorMenu::GetPreferredWidth (sal_Int32 nHeight)
{
    sal_Int32 nPreferredWidth = 0;
    if (maSet.GetItemCount() > 0)
    {
        Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
        Size aItemSize = maSet.CalcItemSizePixel (aImage.GetSizePixel());
        if (nHeight>0 && aItemSize.Height()>0)
        {
            int nRowCount = nHeight / aItemSize.Height();
            if (nRowCount <= 0)
                nRowCount = 1;
            int nColumnCount = (maSet.GetItemCount() + nRowCount-1)
                / nRowCount;
            nPreferredWidth = nColumnCount * aItemSize.Width();
        }
    }

    return nPreferredWidth;
}

sal_Int32 ColorMenu::GetPreferredHeight (sal_Int32 nWidth)
{
    sal_Int32 nPreferredHeight = 0;
    if (maSet.GetItemCount()>0)
    {
        Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
        Size aItemSize = maSet.CalcItemSizePixel (aImage.GetSizePixel());
        if (nWidth>0 && aItemSize.Width()>0)
        {
            int nColumnCount = nWidth / aItemSize.Width();
            if (nColumnCount <= 0)
                nColumnCount = 1;
            else if (nColumnCount > 4)
                nColumnCount = 4;
            int nRowCount = (maSet.GetItemCount() + nColumnCount-1)
                / nColumnCount;
            nPreferredHeight = nRowCount * aItemSize.Height();
        }
    }
    return nPreferredHeight;
}

bool ColorMenu::IsResizable (void)
{
    return true;
}

::Window* ColorMenu::GetWindow (void)
{
    return this;
}

void ColorMenu::Resize (void)
{
    ::Window::Resize();
    Size aWindowSize = GetOutputSizePixel();
    maSet.SetPosSizePixel (Point(0,0), aWindowSize);
    if (IsVisible() && aWindowSize.Width() > 0)
    {
        //        maSet.SetPosSizePixel (
        //            Point (0,0),
        //            aWindowSize);

        // Calculate the number of rows and columns.
        if (maSet.GetItemCount() > 0)
        {
            Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
            Size aItemSize = maSet.CalcItemSizePixel (
                aImage.GetSizePixel());
            int nColumnCount = aWindowSize.Width() / 30;
            if (nColumnCount < 1)
                nColumnCount = 1;
            else if (nColumnCount > 4)
                nColumnCount = 4;

            int nRowCount = CalculateRowCount (aItemSize, nColumnCount);

            maSet.SetColCount (nColumnCount);
            maSet.SetLineCount (nRowCount);
        }
    }

}

int ColorMenu::CalculateRowCount (const Size& rItemSize, int nColumnCount)
{
    int nRowCount = 0;

    if (maSet.GetItemCount()>0 && nColumnCount>0)
    {
        nRowCount = GetOutputSizePixel().Height() / 30;
        if (nRowCount < 1)
            nRowCount = 1;
    }

    return nRowCount;
}

void ColorMenu::Fill (void)
{
    const StyleSettings& rSettings (
        Application::GetSettings().GetStyleSettings());
    maSet.Clear();
    maSet.SetItemWidth (30);
    maSet.SetItemHeight (30);
    int i = 0;
    maSet.InsertItem (++i, rSettings.GetFaceColor());
    maSet.SetItemText (i, String::CreateFromAscii("FaceColor"));
    maSet.InsertItem (++i, rSettings.GetCheckedColor());
    maSet.SetItemText (i, String::CreateFromAscii("CheckedColor"));
    maSet.InsertItem (++i, rSettings.GetLightColor());
    maSet.SetItemText (i, String::CreateFromAscii("LightColor"));
    maSet.InsertItem (++i, rSettings.GetLightBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("LightBorderColor"));
    maSet.InsertItem (++i, rSettings.GetShadowColor());
    maSet.SetItemText (i, String::CreateFromAscii("ShadowColor"));
    maSet.InsertItem (++i, rSettings.GetDarkShadowColor());
    maSet.SetItemText (i, String::CreateFromAscii("DarkShadowColor"));
    maSet.InsertItem (++i, rSettings.GetButtonTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("ButtonTextColor"));
    maSet.InsertItem (++i, rSettings.GetRadioCheckTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("RadioCheckTextColor"));
    maSet.InsertItem (++i, rSettings.GetGroupTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("GroupTextColor"));
    maSet.InsertItem (++i, rSettings.GetLabelTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("LabelTextColor"));
    maSet.InsertItem (++i, rSettings.GetInfoTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("InfoTextColor"));
    maSet.InsertItem (++i, rSettings.GetWindowColor());
    maSet.SetItemText (i, String::CreateFromAscii("WindowColor"));
    maSet.InsertItem (++i, rSettings.GetWindowTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("WindowTextColor"));
    maSet.InsertItem (++i, rSettings.GetDialogColor());
    maSet.SetItemText (i, String::CreateFromAscii("DialogColor"));
    maSet.InsertItem (++i, rSettings.GetDialogTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("DialogTextColor"));
    maSet.InsertItem (++i, rSettings.GetWorkspaceColor());
    maSet.SetItemText (i, String::CreateFromAscii("WorkspaceColor"));
    maSet.InsertItem (++i, rSettings.GetFieldColor());
    maSet.SetItemText (i, String::CreateFromAscii("FieldColor"));
    maSet.InsertItem (++i, rSettings.GetFieldTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("FieldTextColor"));
    maSet.InsertItem (++i, rSettings.GetActiveColor());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveColor"));
    maSet.InsertItem (++i, rSettings.GetActiveColor2());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveColor2"));
    maSet.InsertItem (++i, rSettings.GetActiveTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveTextColor"));
    maSet.InsertItem (++i, rSettings.GetActiveBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveBorderColor"));
    maSet.InsertItem (++i, rSettings.GetDeactiveColor());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveColor"));
    maSet.InsertItem (++i, rSettings.GetDeactiveColor2());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveColor2"));
    maSet.InsertItem (++i, rSettings.GetDeactiveTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveTextColor"));
    maSet.InsertItem (++i, rSettings.GetDeactiveBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveBorderColor"));
    maSet.InsertItem (++i, rSettings.GetHighlightColor());
    maSet.SetItemText (i, String::CreateFromAscii("HighlightColor"));
    maSet.InsertItem (++i, rSettings.GetHighlightTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("HighlightTextColor"));
    maSet.InsertItem (++i, rSettings.GetDisableColor());
    maSet.SetItemText (i, String::CreateFromAscii("DisableColor"));
    maSet.InsertItem (++i, rSettings.GetHelpColor());
    maSet.SetItemText (i, String::CreateFromAscii("HelpColor"));
    maSet.InsertItem (++i, rSettings.GetHelpTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("HelpTextColor"));
    maSet.InsertItem (++i, rSettings.GetMenuColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuColor"));
    maSet.InsertItem (++i, rSettings.GetMenuBarColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuBarColor"));
    maSet.InsertItem (++i, rSettings.GetMenuBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuBorderColor"));
    maSet.InsertItem (++i, rSettings.GetMenuTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuTextColor"));
    maSet.InsertItem (++i, rSettings.GetMenuHighlightColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuHighlightColor"));
    maSet.InsertItem (++i, rSettings.GetMenuHighlightTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuHighlightTextColor"));
    maSet.InsertItem (++i, rSettings.GetLinkColor());
    maSet.SetItemText (i, String::CreateFromAscii("LinkColor"));
    maSet.InsertItem (++i, rSettings.GetVisitedLinkColor());
    maSet.SetItemText (i, String::CreateFromAscii("VisitedLinkColor"));
    maSet.InsertItem (++i, rSettings.GetHighlightLinkColor());
    maSet.SetItemText (i, String::CreateFromAscii("HighlightLinkColor"));
    maSet.InsertItem (++i, rSettings.GetFontColor());
    maSet.SetItemText (i, String::CreateFromAscii("FontColor"));
}

} } // end of namespace ::sd::toolpanel
<commit_msg>INTEGRATION: CWS ooo19126 (1.3.158); FILE MERGED 2005/09/05 13:24:48 rt 1.3.158.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: TestMenu.cxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 06:34:32 $
 *
 *  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 "TestMenu.hxx"

#include "taskpane/TaskPaneControlFactory.hxx"

#include <vcl/image.hxx>
#include <vcl/svapp.hxx>

namespace sd { namespace toolpanel {

/** This factory class is used to create instances of ColorMenu.  It can be
    extended so that its constructor stores arguments that later are passed
    to new ColorMenu objects.
*/
class ColorMenuFactory
    : public ControlFactory
{
protected:
    virtual TreeNode* InternalCreateControl (TreeNode* pTreeNode)
    {
        return new ColorMenu (pTreeNode);
    }
};

ColorMenu::ColorMenu (TreeNode* pParent)
    : Window (pParent->GetWindow()),
      TreeNode(pParent),
      maSet (this),
      mnPreferredColumnCount(2)
{
    WinBits aStyle =
        WB_ITEMBORDER
        | WB_DOUBLEBORDER
        | WB_NAMEFIELD
        | WB_FLATVALUESET
        | WB_TABSTOP
        | WB_VSCROLL;

    maSet.SetStyle (maSet.GetStyle() | aStyle);
    maSet.SetExtraSpacing(2);

    Fill ();
    maSet.Show();
    pParent->RequestResize();
}

ColorMenu::~ColorMenu (void)
{
}

::std::auto_ptr<ControlFactory> ColorMenu::CreateControlFactory (void)
{
    return ::std::auto_ptr<ControlFactory>(new ColorMenuFactory());
}

/** The preferred size depends on the preferred number of columns, the
    number of items, and the size of the items.
*/
Size ColorMenu::GetPreferredSize (void)
{
    Size aItemSize = maSet.CalcItemSizePixel (Size());
    Size aPreferredWindowSize = maSet.CalcWindowSizePixel (
        aItemSize,
        mnPreferredColumnCount,
        CalculateRowCount (aItemSize, mnPreferredColumnCount));
    return aPreferredWindowSize;
}

sal_Int32 ColorMenu::GetPreferredWidth (sal_Int32 nHeight)
{
    sal_Int32 nPreferredWidth = 0;
    if (maSet.GetItemCount() > 0)
    {
        Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
        Size aItemSize = maSet.CalcItemSizePixel (aImage.GetSizePixel());
        if (nHeight>0 && aItemSize.Height()>0)
        {
            int nRowCount = nHeight / aItemSize.Height();
            if (nRowCount <= 0)
                nRowCount = 1;
            int nColumnCount = (maSet.GetItemCount() + nRowCount-1)
                / nRowCount;
            nPreferredWidth = nColumnCount * aItemSize.Width();
        }
    }

    return nPreferredWidth;
}

sal_Int32 ColorMenu::GetPreferredHeight (sal_Int32 nWidth)
{
    sal_Int32 nPreferredHeight = 0;
    if (maSet.GetItemCount()>0)
    {
        Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
        Size aItemSize = maSet.CalcItemSizePixel (aImage.GetSizePixel());
        if (nWidth>0 && aItemSize.Width()>0)
        {
            int nColumnCount = nWidth / aItemSize.Width();
            if (nColumnCount <= 0)
                nColumnCount = 1;
            else if (nColumnCount > 4)
                nColumnCount = 4;
            int nRowCount = (maSet.GetItemCount() + nColumnCount-1)
                / nColumnCount;
            nPreferredHeight = nRowCount * aItemSize.Height();
        }
    }
    return nPreferredHeight;
}

bool ColorMenu::IsResizable (void)
{
    return true;
}

::Window* ColorMenu::GetWindow (void)
{
    return this;
}

void ColorMenu::Resize (void)
{
    ::Window::Resize();
    Size aWindowSize = GetOutputSizePixel();
    maSet.SetPosSizePixel (Point(0,0), aWindowSize);
    if (IsVisible() && aWindowSize.Width() > 0)
    {
        //        maSet.SetPosSizePixel (
        //            Point (0,0),
        //            aWindowSize);

        // Calculate the number of rows and columns.
        if (maSet.GetItemCount() > 0)
        {
            Image aImage = maSet.GetItemImage(maSet.GetItemId(0));
            Size aItemSize = maSet.CalcItemSizePixel (
                aImage.GetSizePixel());
            int nColumnCount = aWindowSize.Width() / 30;
            if (nColumnCount < 1)
                nColumnCount = 1;
            else if (nColumnCount > 4)
                nColumnCount = 4;

            int nRowCount = CalculateRowCount (aItemSize, nColumnCount);

            maSet.SetColCount (nColumnCount);
            maSet.SetLineCount (nRowCount);
        }
    }

}

int ColorMenu::CalculateRowCount (const Size& rItemSize, int nColumnCount)
{
    int nRowCount = 0;

    if (maSet.GetItemCount()>0 && nColumnCount>0)
    {
        nRowCount = GetOutputSizePixel().Height() / 30;
        if (nRowCount < 1)
            nRowCount = 1;
    }

    return nRowCount;
}

void ColorMenu::Fill (void)
{
    const StyleSettings& rSettings (
        Application::GetSettings().GetStyleSettings());
    maSet.Clear();
    maSet.SetItemWidth (30);
    maSet.SetItemHeight (30);
    int i = 0;
    maSet.InsertItem (++i, rSettings.GetFaceColor());
    maSet.SetItemText (i, String::CreateFromAscii("FaceColor"));
    maSet.InsertItem (++i, rSettings.GetCheckedColor());
    maSet.SetItemText (i, String::CreateFromAscii("CheckedColor"));
    maSet.InsertItem (++i, rSettings.GetLightColor());
    maSet.SetItemText (i, String::CreateFromAscii("LightColor"));
    maSet.InsertItem (++i, rSettings.GetLightBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("LightBorderColor"));
    maSet.InsertItem (++i, rSettings.GetShadowColor());
    maSet.SetItemText (i, String::CreateFromAscii("ShadowColor"));
    maSet.InsertItem (++i, rSettings.GetDarkShadowColor());
    maSet.SetItemText (i, String::CreateFromAscii("DarkShadowColor"));
    maSet.InsertItem (++i, rSettings.GetButtonTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("ButtonTextColor"));
    maSet.InsertItem (++i, rSettings.GetRadioCheckTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("RadioCheckTextColor"));
    maSet.InsertItem (++i, rSettings.GetGroupTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("GroupTextColor"));
    maSet.InsertItem (++i, rSettings.GetLabelTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("LabelTextColor"));
    maSet.InsertItem (++i, rSettings.GetInfoTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("InfoTextColor"));
    maSet.InsertItem (++i, rSettings.GetWindowColor());
    maSet.SetItemText (i, String::CreateFromAscii("WindowColor"));
    maSet.InsertItem (++i, rSettings.GetWindowTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("WindowTextColor"));
    maSet.InsertItem (++i, rSettings.GetDialogColor());
    maSet.SetItemText (i, String::CreateFromAscii("DialogColor"));
    maSet.InsertItem (++i, rSettings.GetDialogTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("DialogTextColor"));
    maSet.InsertItem (++i, rSettings.GetWorkspaceColor());
    maSet.SetItemText (i, String::CreateFromAscii("WorkspaceColor"));
    maSet.InsertItem (++i, rSettings.GetFieldColor());
    maSet.SetItemText (i, String::CreateFromAscii("FieldColor"));
    maSet.InsertItem (++i, rSettings.GetFieldTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("FieldTextColor"));
    maSet.InsertItem (++i, rSettings.GetActiveColor());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveColor"));
    maSet.InsertItem (++i, rSettings.GetActiveColor2());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveColor2"));
    maSet.InsertItem (++i, rSettings.GetActiveTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveTextColor"));
    maSet.InsertItem (++i, rSettings.GetActiveBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("ActiveBorderColor"));
    maSet.InsertItem (++i, rSettings.GetDeactiveColor());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveColor"));
    maSet.InsertItem (++i, rSettings.GetDeactiveColor2());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveColor2"));
    maSet.InsertItem (++i, rSettings.GetDeactiveTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveTextColor"));
    maSet.InsertItem (++i, rSettings.GetDeactiveBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("DeactiveBorderColor"));
    maSet.InsertItem (++i, rSettings.GetHighlightColor());
    maSet.SetItemText (i, String::CreateFromAscii("HighlightColor"));
    maSet.InsertItem (++i, rSettings.GetHighlightTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("HighlightTextColor"));
    maSet.InsertItem (++i, rSettings.GetDisableColor());
    maSet.SetItemText (i, String::CreateFromAscii("DisableColor"));
    maSet.InsertItem (++i, rSettings.GetHelpColor());
    maSet.SetItemText (i, String::CreateFromAscii("HelpColor"));
    maSet.InsertItem (++i, rSettings.GetHelpTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("HelpTextColor"));
    maSet.InsertItem (++i, rSettings.GetMenuColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuColor"));
    maSet.InsertItem (++i, rSettings.GetMenuBarColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuBarColor"));
    maSet.InsertItem (++i, rSettings.GetMenuBorderColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuBorderColor"));
    maSet.InsertItem (++i, rSettings.GetMenuTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuTextColor"));
    maSet.InsertItem (++i, rSettings.GetMenuHighlightColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuHighlightColor"));
    maSet.InsertItem (++i, rSettings.GetMenuHighlightTextColor());
    maSet.SetItemText (i, String::CreateFromAscii("MenuHighlightTextColor"));
    maSet.InsertItem (++i, rSettings.GetLinkColor());
    maSet.SetItemText (i, String::CreateFromAscii("LinkColor"));
    maSet.InsertItem (++i, rSettings.GetVisitedLinkColor());
    maSet.SetItemText (i, String::CreateFromAscii("VisitedLinkColor"));
    maSet.InsertItem (++i, rSettings.GetHighlightLinkColor());
    maSet.SetItemText (i, String::CreateFromAscii("HighlightLinkColor"));
    maSet.InsertItem (++i, rSettings.GetFontColor());
    maSet.SetItemText (i, String::CreateFromAscii("FontColor"));
}

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


<commit_before>/*************************************************************************
 *
 *  $RCSfile: ViewShellBase.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: obo $ $Date: 2004-01-20 12:40:45 $
 *
 *  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 "ViewShellBase.hxx"

#ifndef SD_DRAW_DOC_SHELL_HXX
#include "DrawDocShell.hxx"
#endif
#ifndef SD_VIEW_SHELL_HXX
#include "ViewShell.hxx"
#endif
#ifndef SD_SUB_SHELL_MANAGER_HXX
#include "SubShellManager.hxx"
#endif
#ifndef SD_OBJECT_BAR_MANAGER_HXX
#include "ObjectBarManager.hxx"
#endif
#ifndef SD_RESID_HXX
#include "sdresid.hxx"
#endif
#include "strings.hrc"
#ifndef _SFXREQUEST_HXX
#include <sfx2/request.hxx>
#endif
#include "app.hrc"
#ifndef _SFXENUMITEM_HXX
#include <svtools/eitem.hxx>
#endif
#ifndef _DRAWDOC_HXX
#include "drawdoc.hxx"
#endif
#ifndef _SFXAPP_HXX
#include <sfx2/app.hxx>
#endif
#include "glob.hrc"
#ifndef _SFXINTITEM_HXX
#include <svtools/intitem.hxx>
#endif
#ifndef _SFXDISPATCH_HXX
#include <sfx2/dispatch.hxx>
#endif
#ifndef _SFXEVENT_HXX
#include <sfx2/event.hxx>
#endif
#include <svx/svxids.hrc>
#ifndef SD_DRAW_CONTROLLER_HXX
#include "DrawController.hxx"
#endif
#ifndef SD_DRAW_VIEW_SHELL_HXX
#include "DrawViewShell.hxx"
#endif
#ifndef SD_DRAW_VIEW_HXX
#include "drawview.hxx"
#endif

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

namespace sd {

TYPEINIT1(ViewShellBase, SfxViewShell);

SFX_IMPL_VIEWFACTORY(ViewShellBase, SdResId(STR_DEFAULTVIEW))
{
    SFX_VIEW_REGISTRATION(DrawDocShell);
}

SFX_IMPL_INTERFACE(ViewShellBase, SfxViewShell, SdResId(STR_DRAWVIEWSHELL))
{
}

ViewShellBase::ViewShellBase (
    SfxViewFrame* pFrame,
    SfxViewShell* pOldShell,
    ViewShell::ShellType eDefaultSubShell)
    : SfxViewShell (pFrame,
        SFX_VIEW_MAXIMIZE_FIRST   |
        SFX_VIEW_OPTIMIZE_EACH    |
        SFX_VIEW_DISABLE_ACCELS   |
        SFX_VIEW_OBJECTSIZE_EMBEDDED |
        SFX_VIEW_CAN_PRINT           |
        SFX_VIEW_HAS_PRINTOPTIONS),
      mpDocShell (static_cast<DrawDocShell*>(
        GetViewFrame()->GetObjectShell())),
      mpDocument (mpDocShell->GetDoc()),
      mpController (NULL),
      maPrintManager (*this)
{
    Construct (eDefaultSubShell);
}

void ViewShellBase::Construct (
    ViewShell::ShellType eDefaultSubShell)
{
    // Now that this new object has (almost) finished its construction
    // we can pass it as argument to the SubShellManager constructor.
    mpSubShellManager = ::std::auto_ptr<SubShellManager>(
        new SubShellManager(*this));
    GetSubShellManager().SetMainSubShellType (eDefaultSubShell);

    StartListening(*GetViewFrame());
    StartListening(*GetDocShell());

    // Make sure that an instance of the controller exists.  Its
    // creation includes registration at the frame.
    GetDrawController();
}

ViewShellBase::~ViewShellBase (void)
{
    EndListening(*GetViewFrame());
    EndListening(*GetDocShell());
    mpSubShellManager.reset();
}

SubShellManager& ViewShellBase::GetSubShellManager (void) const
{
    return *mpSubShellManager.get();
}

ObjectBarManager& ViewShellBase::GetObjectBarManager (void) const
{
    return mpSubShellManager->GetObjectBarManager();
}

ViewShell* ViewShellBase::GetMainViewShell (SfxViewFrame* pViewFrame)
{
    ViewShell* pViewShell = NULL;

    if (pViewFrame != NULL)
    {
        // Get the view shell for the frame and cast it to
        // sd::ViewShellBase.
        SfxViewShell* pSfxViewShell = pViewFrame->GetViewShell();
        if (pSfxViewShell->ISA(::sd::ViewShellBase))
        {
            ViewShellBase* pSdViewShellBase =
                PTR_CAST(::sd::ViewShellBase, pSfxViewShell);
            if (pSdViewShellBase != NULL)
            {
                // Use the main sub shell manager to obtain the
                // desired view shell.
                pViewShell =
                    pSdViewShellBase->GetSubShellManager().GetMainSubShell();
            }
        }
    }

    return pViewShell;
}

void ViewShellBase::ExecuteModeChange (SfxRequest& rRequest)
{
    bool bIsActive = true;
    ViewShell::ShellType eType = ViewShell::ST_NONE;

    switch (rRequest.GetSlot())
    {
        case SID_SWITCH_SHELL:
        {
            SFX_REQUEST_ARG(rRequest, pMode, SfxInt32Item,
                SID_SWITCH_SHELL, FALSE);
            eType = static_cast<ViewShell::ShellType>(
                pMode->GetValue());
            switch (eType)
            {
                case ViewShell::ST_IMPRESS:
                case ViewShell::ST_HANDOUT:
                case ViewShell::ST_NOTES:
                case ViewShell::ST_SLIDE:
                case ViewShell::ST_OUTLINE:
                {
                    // Turn off effects.
                    ViewShell* pShell = GetSubShellManager().GetMainSubShell();
                    /*af the current shell will be destroyed in a short time
                         so calling SetAnimationMode() should not be
                         necessary.

                    if (pShell != NULL)
                        if (pShell->ISA(DrawViewShell))
                            static_cast<DrawView*>(pShell->GetDrawView())
                                ->SetAnimationMode(FALSE);
                        */
                    // AutoLayouts have to be ready.
                    GetDocument()->StopWorkStartupDelay();
                    GetSubShellManager().SetMainSubShellType (eType);
                    //          Invalidate ();
                    rRequest.Ignore ();
                }
                break;

                case ViewShell::ST_NONE:
                case ViewShell::ST_PRESENTATION:
                    GetSubShellManager().SetMainSubShellType (eType);
                    rRequest.Done ();
                    break;

                case ViewShell::ST_DRAW:
                case ViewShell::ST_PREVIEW:
                    break;
            }
        }
    }
}

void ViewShellBase::GetMenuState (SfxItemSet& rSet)
{
}

DrawController* ViewShellBase::GetDrawController (void)
{
    if (mpController == NULL)
    {
        ::osl::MutexGuard aGuard (maMutex);
        if (mpController == NULL)
            mpController = new DrawController (*this);
    }
    return mpController;
}

DrawDocShell* ViewShellBase::GetDocShell (void) const
{
    return mpDocShell;
}

SdDrawDocument* ViewShellBase::GetDocument (void) const
{
    return mpDocument;
}

void ViewShellBase::SFX_NOTIFY(SfxBroadcaster& rBC,
    const TypeId& rBCType,
    const SfxHint& rHint,
    const TypeId& rHintType)
{
    SfxViewShell::SFX_NOTIFY(rBC, rBCType, rHint, rHintType);

    if (rHint.IsA(TYPE(SfxEventHint)))
    {
        if( ((SfxEventHint&)rHint).GetEventId() == SFX_EVENT_OPENDOC )
        {
            if( GetDocument() && GetDocument()->IsStartWithPresentation() )
            {
                if( GetViewFrame() )
                {
                    GetDocument()->SetStartWithPresentation( false );
                    GetViewFrame()->GetDispatcher()->Execute(
                        SID_PRESENTATION, SFX_CALLMODE_ASYNCHRON );
                }
            }
        }
    }
}

void ViewShellBase::InnerResizePixel(const Point &rPos, const Size &rSize)
{
    ViewShell* pMainViewShell = GetSubShellManager().GetMainSubShell();
    if (pMainViewShell != NULL)
        pMainViewShell->InnerResizePixel (rPos, rSize);
}

ErrCode ViewShellBase::DoVerb (long nVerb)
{
    ErrCode aResult = ERRCODE_NONE;

    ViewShell* pShell = GetSubShellManager().GetMainSubShell();
    if (pShell != NULL)
        aResult = pShell->DoVerb (nVerb);

    return aResult;
}

SfxPrinter* ViewShellBase::GetPrinter (BOOL bCreate)
{
    return maPrintManager.GetPrinter (bCreate);
}

USHORT ViewShellBase::SetPrinter (
    SfxPrinter* pNewPrinter,

    USHORT nDiffFlags)
{
    return maPrintManager.SetPrinter (pNewPrinter, nDiffFlags);
}

PrintDialog* ViewShellBase::CreatePrintDialog (::Window *pParent)
{
    return maPrintManager.CreatePrintDialog (pParent);
}

SfxTabPage*  ViewShellBase::CreatePrintOptionsPage(
    ::Window *pParent,
    const SfxItemSet &rOptions)
{
    return maPrintManager.CreatePrintOptionsPage (pParent, rOptions);
}

USHORT  ViewShellBase::Print(SfxProgress& rProgress, PrintDialog* pDlg)
{
    return maPrintManager.Print (rProgress, pDlg);
}

ErrCode ViewShellBase::DoPrint (
    SfxPrinter* pPrinter,
    PrintDialog* pPrintDialog,
    BOOL bSilent)
{
    return maPrintManager.DoPrint (pPrinter, pPrintDialog, bSilent);
}

USHORT ViewShellBase::SetPrinterOptDlg (
    SfxPrinter* pNewPrinter,
    USHORT nDiffFlags,
    BOOL bShowDialog)
{
   return maPrintManager.SetPrinterOptDlg (
       pNewPrinter, nDiffFlags, bShowDialog);
}

void ViewShellBase::PreparePrint (PrintDialog* pPrintDialog)
{
    return maPrintManager.PreparePrint (pPrintDialog);
}

} // end of namespace sd
<commit_msg>INTEGRATION: CWS impress4ea1 (1.2.32); FILE MERGED 2004/03/02 08:59:21 af 1.2.32.1: #i26017# Added missing OuterResizePixel().<commit_after>/*************************************************************************
 *
 *  $RCSfile: ViewShellBase.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: obo $ $Date: 2004-03-17 11:28:52 $
 *
 *  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 "ViewShellBase.hxx"

#ifndef SD_DRAW_DOC_SHELL_HXX
#include "DrawDocShell.hxx"
#endif
#ifndef SD_VIEW_SHELL_HXX
#include "ViewShell.hxx"
#endif
#ifndef SD_SUB_SHELL_MANAGER_HXX
#include "SubShellManager.hxx"
#endif
#ifndef SD_OBJECT_BAR_MANAGER_HXX
#include "ObjectBarManager.hxx"
#endif
#ifndef SD_RESID_HXX
#include "sdresid.hxx"
#endif
#include "strings.hrc"
#ifndef _SFXREQUEST_HXX
#include <sfx2/request.hxx>
#endif
#include "app.hrc"
#ifndef _SFXENUMITEM_HXX
#include <svtools/eitem.hxx>
#endif
#ifndef _DRAWDOC_HXX
#include "drawdoc.hxx"
#endif
#ifndef _SFXAPP_HXX
#include <sfx2/app.hxx>
#endif
#include "glob.hrc"
#ifndef _SFXINTITEM_HXX
#include <svtools/intitem.hxx>
#endif
#ifndef _SFXDISPATCH_HXX
#include <sfx2/dispatch.hxx>
#endif
#ifndef _SFXEVENT_HXX
#include <sfx2/event.hxx>
#endif
#include <svx/svxids.hrc>
#ifndef SD_DRAW_CONTROLLER_HXX
#include "DrawController.hxx"
#endif
#ifndef SD_DRAW_VIEW_SHELL_HXX
#include "DrawViewShell.hxx"
#endif
#ifndef SD_DRAW_VIEW_HXX
#include "drawview.hxx"
#endif

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

namespace sd {

TYPEINIT1(ViewShellBase, SfxViewShell);

SFX_IMPL_VIEWFACTORY(ViewShellBase, SdResId(STR_DEFAULTVIEW))
{
    SFX_VIEW_REGISTRATION(DrawDocShell);
}

SFX_IMPL_INTERFACE(ViewShellBase, SfxViewShell, SdResId(STR_DRAWVIEWSHELL))
{
}

ViewShellBase::ViewShellBase (
    SfxViewFrame* pFrame,
    SfxViewShell* pOldShell,
    ViewShell::ShellType eDefaultSubShell)
    : SfxViewShell (pFrame,
        SFX_VIEW_MAXIMIZE_FIRST   |
        SFX_VIEW_OPTIMIZE_EACH    |
        SFX_VIEW_DISABLE_ACCELS   |
        SFX_VIEW_OBJECTSIZE_EMBEDDED |
        SFX_VIEW_CAN_PRINT           |
        SFX_VIEW_HAS_PRINTOPTIONS),
      mpDocShell (static_cast<DrawDocShell*>(
        GetViewFrame()->GetObjectShell())),
      mpDocument (mpDocShell->GetDoc()),
      mpController (NULL),
      maPrintManager (*this)
{
    Construct (eDefaultSubShell);
}

void ViewShellBase::Construct (
    ViewShell::ShellType eDefaultSubShell)
{
    // Now that this new object has (almost) finished its construction
    // we can pass it as argument to the SubShellManager constructor.
    mpSubShellManager = ::std::auto_ptr<SubShellManager>(
        new SubShellManager(*this));
    GetSubShellManager().SetMainSubShellType (eDefaultSubShell);

    StartListening(*GetViewFrame());
    StartListening(*GetDocShell());

    // Make sure that an instance of the controller exists.  Its
    // creation includes registration at the frame.
    GetDrawController();
}

ViewShellBase::~ViewShellBase (void)
{
    EndListening(*GetViewFrame());
    EndListening(*GetDocShell());
    mpSubShellManager.reset();
}

SubShellManager& ViewShellBase::GetSubShellManager (void) const
{
    return *mpSubShellManager.get();
}

ObjectBarManager& ViewShellBase::GetObjectBarManager (void) const
{
    return mpSubShellManager->GetObjectBarManager();
}

ViewShell* ViewShellBase::GetMainViewShell (SfxViewFrame* pViewFrame)
{
    ViewShell* pViewShell = NULL;

    if (pViewFrame != NULL)
    {
        // Get the view shell for the frame and cast it to
        // sd::ViewShellBase.
        SfxViewShell* pSfxViewShell = pViewFrame->GetViewShell();
        if (pSfxViewShell->ISA(::sd::ViewShellBase))
        {
            ViewShellBase* pSdViewShellBase =
                PTR_CAST(::sd::ViewShellBase, pSfxViewShell);
            if (pSdViewShellBase != NULL)
            {
                // Use the main sub shell manager to obtain the
                // desired view shell.
                pViewShell =
                    pSdViewShellBase->GetSubShellManager().GetMainSubShell();
            }
        }
    }

    return pViewShell;
}

void ViewShellBase::ExecuteModeChange (SfxRequest& rRequest)
{
    bool bIsActive = true;
    ViewShell::ShellType eType = ViewShell::ST_NONE;

    switch (rRequest.GetSlot())
    {
        case SID_SWITCH_SHELL:
        {
            SFX_REQUEST_ARG(rRequest, pMode, SfxInt32Item,
                SID_SWITCH_SHELL, FALSE);
            eType = static_cast<ViewShell::ShellType>(
                pMode->GetValue());
            switch (eType)
            {
                case ViewShell::ST_IMPRESS:
                case ViewShell::ST_HANDOUT:
                case ViewShell::ST_NOTES:
                case ViewShell::ST_SLIDE:
                case ViewShell::ST_OUTLINE:
                {
                    // Turn off effects.
                    ViewShell* pShell = GetSubShellManager().GetMainSubShell();
                    /*af the current shell will be destroyed in a short time
                         so calling SetAnimationMode() should not be
                         necessary.

                    if (pShell != NULL)
                        if (pShell->ISA(DrawViewShell))
                            static_cast<DrawView*>(pShell->GetDrawView())
                                ->SetAnimationMode(FALSE);
                        */
                    // AutoLayouts have to be ready.
                    GetDocument()->StopWorkStartupDelay();
                    GetSubShellManager().SetMainSubShellType (eType);
                    //          Invalidate ();
                    rRequest.Ignore ();
                }
                break;

                case ViewShell::ST_NONE:
                case ViewShell::ST_PRESENTATION:
                    GetSubShellManager().SetMainSubShellType (eType);
                    rRequest.Done ();
                    break;

                case ViewShell::ST_DRAW:
                case ViewShell::ST_PREVIEW:
                    break;
            }
        }
    }
}

void ViewShellBase::GetMenuState (SfxItemSet& rSet)
{
}

DrawController* ViewShellBase::GetDrawController (void)
{
    if (mpController == NULL)
    {
        ::osl::MutexGuard aGuard (maMutex);
        if (mpController == NULL)
            mpController = new DrawController (*this);
    }
    return mpController;
}

DrawDocShell* ViewShellBase::GetDocShell (void) const
{
    return mpDocShell;
}

SdDrawDocument* ViewShellBase::GetDocument (void) const
{
    return mpDocument;
}

void ViewShellBase::SFX_NOTIFY(SfxBroadcaster& rBC,
    const TypeId& rBCType,
    const SfxHint& rHint,
    const TypeId& rHintType)
{
    SfxViewShell::SFX_NOTIFY(rBC, rBCType, rHint, rHintType);

    if (rHint.IsA(TYPE(SfxEventHint)))
    {
        if( ((SfxEventHint&)rHint).GetEventId() == SFX_EVENT_OPENDOC )
        {
            if( GetDocument() && GetDocument()->IsStartWithPresentation() )
            {
                if( GetViewFrame() )
                {
                    GetDocument()->SetStartWithPresentation( false );
                    GetViewFrame()->GetDispatcher()->Execute(
                        SID_PRESENTATION, SFX_CALLMODE_ASYNCHRON );
                }
            }
        }
    }
}

void ViewShellBase::InnerResizePixel(const Point &rPos, const Size &rSize)
{
    SfxViewShell::InnerResizePixel (rPos, rSize);
    ViewShell* pMainViewShell = GetSubShellManager().GetMainSubShell();
    if (pMainViewShell != NULL)
        pMainViewShell->InnerResizePixel (rPos, rSize);
}

void ViewShellBase::OuterResizePixel(const Point &rPos, const Size &rSize)
{
    /*af
    SfxViewShell::OuterResizePixel (rPos, rSize);
    ViewShell* pMainViewShell = GetSubShellManager().GetMainSubShell();
    if (pMainViewShell != NULL)
        pMainViewShell->OuterResizePixel (rPos, rSize);
    */
}

ErrCode ViewShellBase::DoVerb (long nVerb)
{
    ErrCode aResult = ERRCODE_NONE;

    ViewShell* pShell = GetSubShellManager().GetMainSubShell();
    if (pShell != NULL)
        aResult = pShell->DoVerb (nVerb);

    return aResult;
}

SfxPrinter* ViewShellBase::GetPrinter (BOOL bCreate)
{
    return maPrintManager.GetPrinter (bCreate);
}

USHORT ViewShellBase::SetPrinter (
    SfxPrinter* pNewPrinter,

    USHORT nDiffFlags)
{
    return maPrintManager.SetPrinter (pNewPrinter, nDiffFlags);
}

PrintDialog* ViewShellBase::CreatePrintDialog (::Window *pParent)
{
    return maPrintManager.CreatePrintDialog (pParent);
}

SfxTabPage*  ViewShellBase::CreatePrintOptionsPage(
    ::Window *pParent,
    const SfxItemSet &rOptions)
{
    return maPrintManager.CreatePrintOptionsPage (pParent, rOptions);
}

USHORT  ViewShellBase::Print(SfxProgress& rProgress, PrintDialog* pDlg)
{
    return maPrintManager.Print (rProgress, pDlg);
}

ErrCode ViewShellBase::DoPrint (
    SfxPrinter* pPrinter,
    PrintDialog* pPrintDialog,
    BOOL bSilent)
{
    return maPrintManager.DoPrint (pPrinter, pPrintDialog, bSilent);
}

USHORT ViewShellBase::SetPrinterOptDlg (
    SfxPrinter* pNewPrinter,
    USHORT nDiffFlags,
    BOOL bShowDialog)
{
   return maPrintManager.SetPrinterOptDlg (
       pNewPrinter, nDiffFlags, bShowDialog);
}

void ViewShellBase::PreparePrint (PrintDialog* pPrintDialog)
{
    return maPrintManager.PreparePrint (pPrintDialog);
}

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


<commit_before>#include "mainwindow.h"
#include "pagefactory.h"
#include "dcppage.h"
#include "maintranslations.h"
#include <duiscenemanager.h>
#include <QtDebug>
#include <duinavigationbar.h>
#include <duiaction.h>
#include <duiapplication.h>

MainWindow::MainWindow()
{
   Pages::Handle handle = {Pages::MAIN, ""};
  // Pages::Handle handle = {Pages::APPLET, "Language"};
   changePage(handle);
}

void MainWindow::backClicked()
{
    PageFactory::instance()->back();

    /* overrides dui behaviour that it changes to close when switching
       inside a page TODO remove */
    if (PageFactory::instance()->currentPage()->handle().id == Pages::APPLET) {
        navigationBar()->showBackButton();
    }
}

MainWindow::~MainWindow()
{
}

void
MainWindow::changePage(Pages::Handle handle)
{
    DcpPage *page = PageFactory::instance()->create(handle);
    connect (page, SIGNAL(openSubPage(Pages::Handle)), this,
        SLOT(changePage(Pages::Handle)));
    connect(page, SIGNAL(backButtonClicked()), this, SLOT(backClicked()));

    // --- temporary to test rotating the device ---
    DuiAction* rotateAction = new DuiAction("ROT", page);
    rotateAction->setLocation(DuiAction::ToolBar);
    connect (rotateAction, SIGNAL (triggered()),
             this, SLOT(onRotateClicked()));
    // ---
    // closeAction
    DuiAction *quitAction = new DuiAction(DcpMain::quitMenuItemText, this);
    quitAction->setLocation(DuiAction::ViewMenu);
    connect(quitAction, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));

    // Add actions to page
    if (handle.id != Pages::MAIN)
        page->addAction(quitAction);
    page->addAction(rotateAction);

    page->appear(DuiSceneWindow::KeepWhenDone); //TODO -> Destroy
}

#include <DuiQueryDialog>
void MainWindow::onRotateClicked()
{
    DuiQueryDialog query("You have not selected any keyboard language,<br>"
                                 "would you like to keep the previous selection?");
    int keepPreviousId = query.addChoice("Keep previous");
    query.addChoice("Select new");
    query.exec();
    if (query.acceptedChoice() == keepPreviousId)
    {
        qDebug("DCP: accepted");
    }
/*
    DuiSceneManager *manager = DuiSceneManager::instance();
    static Dui::OrientationAngle angle = Dui::Angle0;
    if (angle == Dui::Angle270) {
	angle = Dui::Angle0;
    } else if (angle == Dui::Angle0) {
	angle = Dui::Angle90;
    } else if (angle == Dui::Angle90) {
	angle = Dui::Angle180;
    } else if (angle == Dui::Angle180) {
	angle = Dui::Angle270;
    }
    manager->setOrientationAngle (angle);
*/
}

<commit_msg>Restored mainwindow (used it for debugging)<commit_after>#include "mainwindow.h"
#include "pagefactory.h"
#include "dcppage.h"
#include "maintranslations.h"
#include <duiscenemanager.h>
#include <QtDebug>
#include <duinavigationbar.h>
#include <duiaction.h>
#include <duiapplication.h>

MainWindow::MainWindow()
{
   Pages::Handle handle = {Pages::MAIN, ""};
  // Pages::Handle handle = {Pages::APPLET, "Language"};
   changePage(handle);
}

void MainWindow::backClicked()
{
    PageFactory::instance()->back();

    /* overrides dui behaviour that it changes to close when switching
       inside a page TODO remove */
    if (PageFactory::instance()->currentPage()->handle().id == Pages::APPLET) {
        navigationBar()->showBackButton();
    }
}

MainWindow::~MainWindow()
{
}

void
MainWindow::changePage(Pages::Handle handle)
{
    DcpPage *page = PageFactory::instance()->create(handle);
    connect (page, SIGNAL(openSubPage(Pages::Handle)), this,
        SLOT(changePage(Pages::Handle)));
    connect(page, SIGNAL(backButtonClicked()), this, SLOT(backClicked()));

    // --- temporary to test rotating the device ---
    DuiAction* rotateAction = new DuiAction("ROT", page);
    rotateAction->setLocation(DuiAction::ToolBar);
    connect (rotateAction, SIGNAL (triggered()),
             this, SLOT(onRotateClicked()));
    // ---
    // closeAction
    DuiAction *quitAction = new DuiAction(DcpMain::quitMenuItemText, this);
    quitAction->setLocation(DuiAction::ViewMenu);
    connect(quitAction, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));

    // Add actions to page
    if (handle.id != Pages::MAIN)
        page->addAction(quitAction);
    page->addAction(rotateAction);

    page->appear(DuiSceneWindow::KeepWhenDone); //TODO -> Destroy
}

void MainWindow::onRotateClicked()
{
    DuiSceneManager *manager = DuiSceneManager::instance();
    static Dui::OrientationAngle angle = Dui::Angle0;
    if (angle == Dui::Angle270) {
	angle = Dui::Angle0;
    } else if (angle == Dui::Angle0) {
	angle = Dui::Angle90;
    } else if (angle == Dui::Angle90) {
	angle = Dui::Angle180;
    } else if (angle == Dui::Angle180) {
	angle = Dui::Angle270;
    }
    manager->setOrientationAngle (angle);
}

<|endoftext|>


<commit_before>/*
 * Copyright (C) 2017 ScyllaDB
 */

/*
 * This file is part of Scylla.
 *
 * Scylla is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Scylla 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Scylla.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include "partition_version.hh"

// Allows iterating over rows of mutation_partition represented by given partition_snapshot.
//
// The cursor initially has a position before all rows and is not pointing at any row.
// To position the cursor, use advance_to().
//
// All methods should be called with the region of the snapshot locked. The cursor is invalidated
// when that lock section is left, or if the snapshot is modified.
//
// When the cursor is invalidated, it still maintains its previous position. It can be brought
// back to validity by calling maybe_refresh(), or advance_to().
//
class partition_snapshot_row_cursor final {
    struct position_in_version {
        mutation_partition::rows_type::iterator it;
        mutation_partition::rows_type::iterator end;
        int version_no;

        struct less_compare {
            rows_entry::tri_compare _cmp;
        public:
            explicit less_compare(const schema& s) : _cmp(s) { }
            bool operator()(const position_in_version& a, const position_in_version& b) {
                auto res = _cmp(*a.it, *b.it);
                return res > 0 || (res == 0 && a.version_no > b.version_no);
            }
        };
    };

    const schema& _schema;
    logalloc::region& _region;
    partition_snapshot& _snp;
    std::vector<position_in_version> _heap;
    std::vector<position_in_version> _current_row;
    position_in_partition _position;
    uint64_t _last_reclaim_count = 0;
    size_t _last_versions_count = 0;

    // Removes the next row from _heap and puts it into _current_row
    void recreate_current_row() {
        position_in_version::less_compare heap_less(_schema);
        position_in_partition::equal_compare eq(_schema);
        do {
            boost::range::pop_heap(_heap, heap_less);
            _current_row.push_back(_heap.back());
            _heap.pop_back();
        } while (!_heap.empty() && eq(_current_row[0].it->position(), _heap[0].it->position()));
        _position = position_in_partition(_current_row[0].it->position());
    }
public:
    partition_snapshot_row_cursor(const schema& s, logalloc::region& region, partition_snapshot& snp)
        : _schema(s)
        , _region(region)
        , _snp(snp)
        , _position(position_in_partition::static_row_tag_t{})
    { }
    bool has_up_to_date_row_from_latest_version() const {
        return up_to_date() && _current_row[0].version_no == 0;
    }
    mutation_partition::rows_type::iterator get_iterator_in_latest_version() const {
        return _current_row[0].it;
    }
    bool up_to_date() const {
        return _region.reclaim_counter() == _last_reclaim_count && _last_versions_count == _snp.version_count();
    }

    // Brings back the cursor to validity.
    // Can be only called when cursor is pointing at a row.
    //
    // Semantically equivalent to:
    //
    //   advance_to(position());
    //
    // but avoids work if not necessary.
    bool maybe_refresh() {
        if (!up_to_date()) {
            return advance_to(_position);
        }
        return true;
    }

    // Moves the cursor to the first entry with position >= pos.
    //
    // The caller must ensure that such entry exists.
    //
    // Returns true iff there can't be any clustering row entries
    // between lower_bound (inclusive) and the entry to which the cursor
    // was advanced.
    //
    // May be called when cursor is not valid.
    // The cursor is valid after the call.
    // Must be called under reclaim lock.
    bool advance_to(position_in_partition_view lower_bound) {
        rows_entry::compare less(_schema);
        position_in_version::less_compare heap_less(_schema);
        _heap.clear();
        _current_row.clear();
        int version_no = 0;
        for (auto&& v : _snp.versions()) {
            auto& rows = v.partition().clustered_rows();
            auto pos = rows.lower_bound(lower_bound, less);
            auto end = rows.end();
            if (pos != end) {
                _heap.push_back({pos, end, version_no});
            }
            ++version_no;
        }
        boost::range::make_heap(_heap, heap_less);
        _last_reclaim_count = _region.reclaim_counter();
        _last_versions_count = _snp.version_count();
        bool found = no_clustering_row_between(_schema, lower_bound, _heap[0].it->position());
        recreate_current_row();
        return found;
    }

    // Advances the cursor to the next row.
    // If there is no next row, returns false and the cursor is no longer pointing at a row.
    // Can be only called on a valid cursor pointing at a row.
    bool next() {
        position_in_version::less_compare heap_less(_schema);
        assert(up_to_date());
        for (auto&& curr : _current_row) {
            ++curr.it;
            if (curr.it != curr.end) {
                _heap.push_back(curr);
                boost::range::push_heap(_heap, heap_less);
            }
        }
        _current_row.clear();
        if (_heap.empty()) {
            return false;
        }
        recreate_current_row();
        return true;
    }

    // Can be called only when cursor is valid and pointing at a row.
    bool continuous() const { return bool(_current_row[0].it->continuous()); }

    // Can be called only when cursor is valid and pointing at a row.
    bool dummy() const { return bool(_current_row[0].it->dummy()); }

    // Can be called only when cursor is valid and pointing at a row, and !dummy().
    const clustering_key& key() const { return _current_row[0].it->key(); }

    // Can be called only when cursor is valid and pointing at a row.
    clustering_row row() const {
        clustering_row result(key());
        for (auto&& v : _current_row) {
            result.apply(_schema, *v.it);
        }
        return result;
    }

    // Can be called when cursor is pointing at a row, even when invalid.
    const position_in_partition& position() const {
        return _position;
    }

    bool is_in_latest_version() const;
    bool previous_row_in_latest_version_has_key(const clustering_key_prefix& key) const;
    void set_continuous(bool val);
};

inline
bool partition_snapshot_row_cursor::is_in_latest_version() const {
    return _current_row[0].version_no == 0;
}

inline
bool partition_snapshot_row_cursor::previous_row_in_latest_version_has_key(const clustering_key_prefix& key) const {
    if (_current_row[0].it == _snp.version()->partition().clustered_rows().begin()) {
        return false;
    }
    auto prev_it = _current_row[0].it;
    --prev_it;
    clustering_key_prefix::tri_compare tri_comp(_schema);
    return tri_comp(prev_it->key(), key) == 0;
}

inline
void partition_snapshot_row_cursor::set_continuous(bool val) {
    _current_row[0].it->set_continuous(val);
}
<commit_msg>partition_snapshot_row_cursor: avoid apply() in single-version cases<commit_after>/*
 * Copyright (C) 2017 ScyllaDB
 */

/*
 * This file is part of Scylla.
 *
 * Scylla is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Scylla 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Scylla.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include "partition_version.hh"

// Allows iterating over rows of mutation_partition represented by given partition_snapshot.
//
// The cursor initially has a position before all rows and is not pointing at any row.
// To position the cursor, use advance_to().
//
// All methods should be called with the region of the snapshot locked. The cursor is invalidated
// when that lock section is left, or if the snapshot is modified.
//
// When the cursor is invalidated, it still maintains its previous position. It can be brought
// back to validity by calling maybe_refresh(), or advance_to().
//
class partition_snapshot_row_cursor final {
    struct position_in_version {
        mutation_partition::rows_type::iterator it;
        mutation_partition::rows_type::iterator end;
        int version_no;

        struct less_compare {
            rows_entry::tri_compare _cmp;
        public:
            explicit less_compare(const schema& s) : _cmp(s) { }
            bool operator()(const position_in_version& a, const position_in_version& b) {
                auto res = _cmp(*a.it, *b.it);
                return res > 0 || (res == 0 && a.version_no > b.version_no);
            }
        };
    };

    const schema& _schema;
    logalloc::region& _region;
    partition_snapshot& _snp;
    std::vector<position_in_version> _heap;
    std::vector<position_in_version> _current_row;
    position_in_partition _position;
    uint64_t _last_reclaim_count = 0;
    size_t _last_versions_count = 0;

    // Removes the next row from _heap and puts it into _current_row
    void recreate_current_row() {
        position_in_version::less_compare heap_less(_schema);
        position_in_partition::equal_compare eq(_schema);
        do {
            boost::range::pop_heap(_heap, heap_less);
            _current_row.push_back(_heap.back());
            _heap.pop_back();
        } while (!_heap.empty() && eq(_current_row[0].it->position(), _heap[0].it->position()));
        _position = position_in_partition(_current_row[0].it->position());
    }
public:
    partition_snapshot_row_cursor(const schema& s, logalloc::region& region, partition_snapshot& snp)
        : _schema(s)
        , _region(region)
        , _snp(snp)
        , _position(position_in_partition::static_row_tag_t{})
    { }
    bool has_up_to_date_row_from_latest_version() const {
        return up_to_date() && _current_row[0].version_no == 0;
    }
    mutation_partition::rows_type::iterator get_iterator_in_latest_version() const {
        return _current_row[0].it;
    }
    bool up_to_date() const {
        return _region.reclaim_counter() == _last_reclaim_count && _last_versions_count == _snp.version_count();
    }

    // Brings back the cursor to validity.
    // Can be only called when cursor is pointing at a row.
    //
    // Semantically equivalent to:
    //
    //   advance_to(position());
    //
    // but avoids work if not necessary.
    bool maybe_refresh() {
        if (!up_to_date()) {
            return advance_to(_position);
        }
        return true;
    }

    // Moves the cursor to the first entry with position >= pos.
    //
    // The caller must ensure that such entry exists.
    //
    // Returns true iff there can't be any clustering row entries
    // between lower_bound (inclusive) and the entry to which the cursor
    // was advanced.
    //
    // May be called when cursor is not valid.
    // The cursor is valid after the call.
    // Must be called under reclaim lock.
    bool advance_to(position_in_partition_view lower_bound) {
        rows_entry::compare less(_schema);
        position_in_version::less_compare heap_less(_schema);
        _heap.clear();
        _current_row.clear();
        int version_no = 0;
        for (auto&& v : _snp.versions()) {
            auto& rows = v.partition().clustered_rows();
            auto pos = rows.lower_bound(lower_bound, less);
            auto end = rows.end();
            if (pos != end) {
                _heap.push_back({pos, end, version_no});
            }
            ++version_no;
        }
        boost::range::make_heap(_heap, heap_less);
        _last_reclaim_count = _region.reclaim_counter();
        _last_versions_count = _snp.version_count();
        bool found = no_clustering_row_between(_schema, lower_bound, _heap[0].it->position());
        recreate_current_row();
        return found;
    }

    // Advances the cursor to the next row.
    // If there is no next row, returns false and the cursor is no longer pointing at a row.
    // Can be only called on a valid cursor pointing at a row.
    bool next() {
        position_in_version::less_compare heap_less(_schema);
        assert(up_to_date());
        for (auto&& curr : _current_row) {
            ++curr.it;
            if (curr.it != curr.end) {
                _heap.push_back(curr);
                boost::range::push_heap(_heap, heap_less);
            }
        }
        _current_row.clear();
        if (_heap.empty()) {
            return false;
        }
        recreate_current_row();
        return true;
    }

    // Can be called only when cursor is valid and pointing at a row.
    bool continuous() const { return bool(_current_row[0].it->continuous()); }

    // Can be called only when cursor is valid and pointing at a row.
    bool dummy() const { return bool(_current_row[0].it->dummy()); }

    // Can be called only when cursor is valid and pointing at a row, and !dummy().
    const clustering_key& key() const { return _current_row[0].it->key(); }

    // Can be called only when cursor is valid and pointing at a row.
    clustering_row row() const {
        auto it = _current_row.begin();
        auto cr = clustering_row(*it->it);
        for (++it; it != _current_row.end(); ++it) {
            cr.apply(_schema, *it->it);
        }
        return cr;
    }

    // Can be called when cursor is pointing at a row, even when invalid.
    const position_in_partition& position() const {
        return _position;
    }

    bool is_in_latest_version() const;
    bool previous_row_in_latest_version_has_key(const clustering_key_prefix& key) const;
    void set_continuous(bool val);
};

inline
bool partition_snapshot_row_cursor::is_in_latest_version() const {
    return _current_row[0].version_no == 0;
}

inline
bool partition_snapshot_row_cursor::previous_row_in_latest_version_has_key(const clustering_key_prefix& key) const {
    if (_current_row[0].it == _snp.version()->partition().clustered_rows().begin()) {
        return false;
    }
    auto prev_it = _current_row[0].it;
    --prev_it;
    clustering_key_prefix::tri_compare tri_comp(_schema);
    return tri_comp(prev_it->key(), key) == 0;
}

inline
void partition_snapshot_row_cursor::set_continuous(bool val) {
    _current_row[0].it->set_continuous(val);
}
<|endoftext|>