<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: tbcontrl.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: kz $ $Date: 2007-05-10 14:32:35 $
 *
 *  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 _SVX_TBCONTRL_HXX
#define _SVX_TBCONTRL_HXX

/*--------------------------------------------------------------*\

    Beschreibung:
    -------------
    ToolBox-Controler fuer:
        Font-Name, Font-Hoehe, Font-Farbe
        Vorder-/Hintergrundfarbe /-Muster
        Rahmen, Linien
        (Absatz-)Vorlagen

    Bedienung:
    ----------
        SvxFontNameToolBoxControl
        -------------------------
        Item-Typ:       SvxFontItem
        Execute-Id:     SID_ATTR_CHAR_FONT
                        -> SvxFontItem
        Zusatzdaten
        aus DocShell:   SvxFontListItem (SID_ATTR_CHAR_FONTLIST)

        SvxFontHeightToolBoxControl
        ---------------------------
        Item-Typ:       SvxFontHeightItem
        Execute-Id:     SID_ATTR_CHAR_FONTHEIGHT
                        -> SvxFontHeightItem
        Zusatzdaten
        aus DocShell:   SvxFontListItem (SID_ATTR_CHAR_FONTLIST)

        SvxFontColorToolBoxControl
        --------------------------
        Item-Typ:       SvxFontColorItem
        Execute-Id:     SID_ATTR_CHAR_COLOR
                        -> SvxFontColorItem
        Zusatzdaten
        aus DocShell:   z.Zt. keine
                        in Zukunft: Farbpalette

        class SvxFontColorExtToolBoxControl
        -----------------------------------
        fuer die Zeichenfarbe
        Item-Typ        SvxColorItem
                    und SfxBoolItem
        Execute-Id      SID_ATTR_CHAR_COLOR
                    und SID_ATTR_CHAR_COLOR_EXT

        fuer den Zeichenhintergrund
        Item-Typ        SvxColorItem
                    und SfxBoolItem
        Execute-Id      SID_ATTR_CHAR_COLOR_BACKGROUND
                    und SID_ATTR_CHAR_COLOR_BACKGROUND_EXT

        SvxColorToolBoxControl
        --------------------------------
        Item-Typ:       SvxBrushItem
        Execute-Id:     SID_BACKGROUND_COLOR
                        -> SvxColorItem
        Zusatzdaten
        aus DocShell:   z.Zt. keine
                        in Zukunft: Farbpalette

        SvxPatternToolBoxControl
        ------------------------
        Item-Typ:       SvxBrushItem
        Execute-Id:     SID_BACKGROUND_PATTERN
                        -> SvxBrushItem
        Zusatzdaten
        aus DocShell:   z.Zt. keine
                        in Zukunft: Farbpalette
        Bemerkung:      Auswertung des BrushItems:
                        Die Brush-FillColor() wird als Schalter
                        missbraucht, um zu unterscheiden, ob ein
                        neuer Style oder eine neue Farbe
                        gesetzt wurde:

                        GetFillColor() == COL_BLACK -> GetStyle() auswerten,
                        GetFillColor() == COL_WHITE -> GetColor() auswerten

        SvxFrameToolBoxControl
        ----------------------
        Item-Typ:       SvxBoxItem
        Execute-Id:     SID_ATTR_BORDER
                        -> SvxBoxItem & SvxBoxInfoItem
        Zusatzdaten
        aus DocShell:   keine
        Bemerkung:      liefert je nach gewaehltem ValueSet-Item
                        nur SvxBoxItem oder zusaetzlich SvxBoxInfoItem
                        Wird dem Controller ein SfxUInt16Item mit einem
                        Wert != 0 geschickt, so wird der Paragraph-Mode
                        eingeschaltet, d.h. die letzte Zeile wird
                        ausgeblendet. Ein Wert == 0 schaltet wieder in
                        den Tabellenmodus.

        SvxFrameLineStyleToolBoxControl
        -------------------------------
        Item-Typ:       SvxLineItem
        Execute-Id:     SID_FRAME_LINESTYLE
                        -> SvxLineItem
        Zusatzdaten
        aus DocShell:   keine
        Bemerkung:      liefert ein SvxLineItem, welches eine SvxBorderLine
                        ohne Farbinformation liefert.

        SvxFrameLineColorToolBoxControl
        -------------------------------
        Item-Typ:       SvxColorItem
        Execute-Id:     SID_FRAME_LINECOLOR
                        -> SvxColorItem
        Zusatzdaten
        aus DocShell:   keine

        SvxStyleToolBoxControl
        ----------------------
        Item-Typ:       SfxTemplateItem
        Execute-Id:     SID_TEMPLATE_APPLY
                        -> StyleName (SfxStringItem)
                        -> eStyleFamily (SfxUInt16Item)
        Zusatzdaten
        aus DocShell:   keine
        Bemerkung:      Umschalten der Familie ueber Invalidate
                        an den Bindings (->SfxStyleControllerItem)

\*--------------------------------------------------------------*/

// include ---------------------------------------------------------------

// ITEMID_...-Defines im *.cxx

#ifndef _RSCSFX_HXX //autogen
#include <rsc/rscsfx.hxx>
#endif
#ifndef _SFXLSTNER_HXX //autogen
#include <svtools/lstner.hxx>
#endif
#ifndef _SFXTBXCTRL_HXX //autogen
#include <sfx2/tbxctrl.hxx>
#endif
#ifndef _SVX_STRARRAY_HXX
#include <svx/strarray.hxx>
#endif

#ifndef INCLUDED_SVXDLLAPI_H
#include "svx/svxdllapi.h"
#endif

// wichtig im mit HeDaBu erzeugtem tbxctrls.hxx!!!
class SvxLineItem;
class SvxBoxInfoItem;
class SvxFontItem;
class SvxFontHeightItem;
class SfxStyleControllerItem_Impl;
class SfxStyleSheetBasePool;
class SfxTemplateItem;

//########################################################################

//========================================================================
// class SvxStyleToolBoxControl ------------------------------------------
//========================================================================
class SVX_DLLPUBLIC SvxStyleToolBoxControl : public SfxToolBoxControl
{
    struct Impl;
public:
    SFX_DECL_TOOLBOX_CONTROL();

    SvxStyleToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );
    ~SvxStyleToolBoxControl();

    virtual Window* CreateItemWindow( Window *pParent );

    virtual void    StateChanged( USHORT nSID, SfxItemState eState,
                                  const SfxPoolItem* pState );

    DECL_LINK( VisibilityNotification, void* );
protected:
    // XInitialization
    virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);

    // XUpdatable
    virtual void SAL_CALL update() throw (::com::sun::star::uno::RuntimeException);

private:

#define MAX_FAMILIES 5

    SfxStyleSheetBasePool*              pStyleSheetPool;
    SfxStyleControllerItem_Impl*        pBoundItems [MAX_FAMILIES];
    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > m_xBoundItems[MAX_FAMILIES];
    SfxTemplateItem*                    pFamilyState[MAX_FAMILIES];
    USHORT                              nActFamily; // Id in der ToolBox = Position - 1
    USHORT                              nActFilter; // FilterIdx
    USHORT                              nAppFilter; // Filter, den die App gesetzt hat
    String                              aCurSel;
    BOOL                                bListening;
    Impl*                               pImpl;

    SVX_DLLPRIVATE void Update();
    SVX_DLLPRIVATE void FillStyleBox();
    SVX_DLLPRIVATE void     SelectStyle( const String& rStyleName );

friend class SfxStyleControllerItem_Impl;

    SVX_DLLPRIVATE void         SetFamilyState  ( USHORT nIdx, const SfxTemplateItem* pItem );
    SVX_DLLPRIVATE SfxStyleFamily   GetActFamily    ();
};

//========================================================================
// class SvxFontNameToolBoxControl ---------------------------------------
//========================================================================

class SVX_DLLPUBLIC SvxFontNameToolBoxControl : public SfxToolBoxControl
{
public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxFontNameToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );

    virtual void    StateChanged        ( USHORT nSID, SfxItemState eState,
                                          const SfxPoolItem* pState );
    virtual Window* CreateItemWindow    ( Window *pParent );
};

//========================================================================
// class SvxFontHeightToolBoxControl -------------------------------------
//========================================================================

class SvxFontSizeItem;
class SvxFontItem;
class SvxFontSizeBox_Impl;

class SVX_DLLPUBLIC SvxFontHeightToolBoxControl : public SfxToolBoxControl
{
    SvxFontSizeBox_Impl* pBox;               // ItemWindow f"ur quick-access
    SvxFontItem*        pFontItem;          // Kopie des aktuellen FontItems

public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxFontHeightToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );
    ~SvxFontHeightToolBoxControl();

    // new controller API
    // XStatusListener
    virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event )
        throw ( ::com::sun::star::uno::RuntimeException );

    virtual void        StateChanged( USHORT nSID, SfxItemState eState,
                                       const SfxPoolItem* pState );
    virtual Window*     CreateItemWindow( Window *pParent );

//#if 0 // _SOLAR__PRIVATE
    const SvxFontItem*  GetFontItem_Impl()
                        {
                            updateStatus( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CharFontName" )));
                            return pFontItem;
                        }
//#endif
};

//========================================================================
// class SvxFontColorToolBoxControl --------------------------------------
//========================================================================

class SvxTbxButtonColorUpdater_Impl;

class SVX_DLLPUBLIC SvxFontColorToolBoxControl : public SfxToolBoxControl
{
    SvxTbxButtonColorUpdater_Impl*   pBtnUpdater;

public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxFontColorToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );
    ~SvxFontColorToolBoxControl();

    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );
    virtual SfxPopupWindowType  GetPopupWindowType() const;
    virtual SfxPopupWindow*     CreatePopupWindow();
};

//========================================================================
// class SvxFontColorExtToolBoxControl --------------------------------------
//========================================================================

class SVX_DLLPUBLIC SvxFontColorExtToolBoxControl : public SfxToolBoxControl
{
    using SfxToolBoxControl::StateChanged;
    using SfxToolBoxControl::Select;

    //  SfxStatusForwarder          aForward;
    SvxTbxButtonColorUpdater_Impl*   pBtnUpdater;

public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxFontColorExtToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );
    ~SvxFontColorExtToolBoxControl();

    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );
    virtual SfxPopupWindowType  GetPopupWindowType() const;
    virtual SfxPopupWindow*     CreatePopupWindow();
    virtual void                Select( BOOL bMod1 = FALSE );

};

//========================================================================
// class SvxColorToolBoxControl ------------------------------------------
//========================================================================

class SVX_DLLPUBLIC SvxColorToolBoxControl : public SfxToolBoxControl
{
    SvxTbxButtonColorUpdater_Impl*   pBtnUpdater;
public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxColorToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );
    ~SvxColorToolBoxControl();

    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );
    virtual SfxPopupWindowType  GetPopupWindowType() const;
    virtual SfxPopupWindow*     CreatePopupWindow();
};

//========================================================================
// class SvxFrameToolBoxControl ------------------------------------------
//========================================================================

class SVX_DLLPUBLIC SvxFrameToolBoxControl : public SfxToolBoxControl
{
public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxFrameToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );

    virtual SfxPopupWindowType  GetPopupWindowType() const;
    virtual SfxPopupWindow*     CreatePopupWindow();
    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );

};

//========================================================================
// class SvxLineStyleToolBoxControl --------------------------------------
//========================================================================

class SVX_DLLPUBLIC SvxFrameLineStyleToolBoxControl : public SfxToolBoxControl
{
public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxFrameLineStyleToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );

    virtual SfxPopupWindowType  GetPopupWindowType() const;
    virtual SfxPopupWindow*     CreatePopupWindow();
    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );
};

//========================================================================
// class SvxFrameLineColorToolBoxControl ---------------------------------
//========================================================================

class SVX_DLLPUBLIC SvxFrameLineColorToolBoxControl : public SfxToolBoxControl
{
    SvxTbxButtonColorUpdater_Impl*   pBtnUpdater;
public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxFrameLineColorToolBoxControl( USHORT nSlotId,
                                     USHORT nId,
                                     ToolBox& rTbx );
    ~SvxFrameLineColorToolBoxControl();

    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );
    virtual SfxPopupWindowType  GetPopupWindowType() const;
    virtual SfxPopupWindow*     CreatePopupWindow();
};

class SvxReloadControllerItem_Impl;
class SvxReloadControllerItem : public SfxToolBoxControl
{
private:
    SvxReloadControllerItem_Impl* pImpl;

public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxReloadControllerItem( USHORT nSlotId,
                             USHORT nId,
                             ToolBox& rTbx );
    ~SvxReloadControllerItem();

protected:
    virtual void StateChanged( USHORT nSID, SfxItemState eState,
                               const SfxPoolItem* pState );
};

class SVX_DLLPUBLIC SvxSimpleUndoRedoController : public SfxToolBoxControl
{
private:
    ::rtl::OUString             aDefaultText;

public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxSimpleUndoRedoController( USHORT nSlotId, USHORT nId, ToolBox& rTbx );
    ~SvxSimpleUndoRedoController();

    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );
};

#endif // #ifndef _SVX_TBCONTRL_HXX
<commit_msg>INTEGRATION: CWS oj14 (1.2.22); FILE MERGED 2007/06/04 19:00:44 oj 1.2.22.2: RESYNC: (1.2-1.3); FILE MERGED 2007/05/03 08:05:27 oj 1.2.22.1: SvxTbxButtonColorUpdater_Impl renamed to ToolboxButtonColorUpdater, and outsourced to separate file<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: tbcontrl.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: rt $ $Date: 2007-07-06 07:31:16 $
 *
 *  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 _SVX_TBCONTRL_HXX
#define _SVX_TBCONTRL_HXX

/*--------------------------------------------------------------*\

    Beschreibung:
    -------------
    ToolBox-Controler fuer:
        Font-Name, Font-Hoehe, Font-Farbe
        Vorder-/Hintergrundfarbe /-Muster
        Rahmen, Linien
        (Absatz-)Vorlagen

    Bedienung:
    ----------
        SvxFontNameToolBoxControl
        -------------------------
        Item-Typ:       SvxFontItem
        Execute-Id:     SID_ATTR_CHAR_FONT
                        -> SvxFontItem
        Zusatzdaten
        aus DocShell:   SvxFontListItem (SID_ATTR_CHAR_FONTLIST)

        SvxFontHeightToolBoxControl
        ---------------------------
        Item-Typ:       SvxFontHeightItem
        Execute-Id:     SID_ATTR_CHAR_FONTHEIGHT
                        -> SvxFontHeightItem
        Zusatzdaten
        aus DocShell:   SvxFontListItem (SID_ATTR_CHAR_FONTLIST)

        SvxFontColorToolBoxControl
        --------------------------
        Item-Typ:       SvxFontColorItem
        Execute-Id:     SID_ATTR_CHAR_COLOR
                        -> SvxFontColorItem
        Zusatzdaten
        aus DocShell:   z.Zt. keine
                        in Zukunft: Farbpalette

        class SvxFontColorExtToolBoxControl
        -----------------------------------
        fuer die Zeichenfarbe
        Item-Typ        SvxColorItem
                    und SfxBoolItem
        Execute-Id      SID_ATTR_CHAR_COLOR
                    und SID_ATTR_CHAR_COLOR_EXT

        fuer den Zeichenhintergrund
        Item-Typ        SvxColorItem
                    und SfxBoolItem
        Execute-Id      SID_ATTR_CHAR_COLOR_BACKGROUND
                    und SID_ATTR_CHAR_COLOR_BACKGROUND_EXT

        SvxColorToolBoxControl
        --------------------------------
        Item-Typ:       SvxBrushItem
        Execute-Id:     SID_BACKGROUND_COLOR
                        -> SvxColorItem
        Zusatzdaten
        aus DocShell:   z.Zt. keine
                        in Zukunft: Farbpalette

        SvxPatternToolBoxControl
        ------------------------
        Item-Typ:       SvxBrushItem
        Execute-Id:     SID_BACKGROUND_PATTERN
                        -> SvxBrushItem
        Zusatzdaten
        aus DocShell:   z.Zt. keine
                        in Zukunft: Farbpalette
        Bemerkung:      Auswertung des BrushItems:
                        Die Brush-FillColor() wird als Schalter
                        missbraucht, um zu unterscheiden, ob ein
                        neuer Style oder eine neue Farbe
                        gesetzt wurde:

                        GetFillColor() == COL_BLACK -> GetStyle() auswerten,
                        GetFillColor() == COL_WHITE -> GetColor() auswerten

        SvxFrameToolBoxControl
        ----------------------
        Item-Typ:       SvxBoxItem
        Execute-Id:     SID_ATTR_BORDER
                        -> SvxBoxItem & SvxBoxInfoItem
        Zusatzdaten
        aus DocShell:   keine
        Bemerkung:      liefert je nach gewaehltem ValueSet-Item
                        nur SvxBoxItem oder zusaetzlich SvxBoxInfoItem
                        Wird dem Controller ein SfxUInt16Item mit einem
                        Wert != 0 geschickt, so wird der Paragraph-Mode
                        eingeschaltet, d.h. die letzte Zeile wird
                        ausgeblendet. Ein Wert == 0 schaltet wieder in
                        den Tabellenmodus.

        SvxFrameLineStyleToolBoxControl
        -------------------------------
        Item-Typ:       SvxLineItem
        Execute-Id:     SID_FRAME_LINESTYLE
                        -> SvxLineItem
        Zusatzdaten
        aus DocShell:   keine
        Bemerkung:      liefert ein SvxLineItem, welches eine SvxBorderLine
                        ohne Farbinformation liefert.

        SvxFrameLineColorToolBoxControl
        -------------------------------
        Item-Typ:       SvxColorItem
        Execute-Id:     SID_FRAME_LINECOLOR
                        -> SvxColorItem
        Zusatzdaten
        aus DocShell:   keine

        SvxStyleToolBoxControl
        ----------------------
        Item-Typ:       SfxTemplateItem
        Execute-Id:     SID_TEMPLATE_APPLY
                        -> StyleName (SfxStringItem)
                        -> eStyleFamily (SfxUInt16Item)
        Zusatzdaten
        aus DocShell:   keine
        Bemerkung:      Umschalten der Familie ueber Invalidate
                        an den Bindings (->SfxStyleControllerItem)

\*--------------------------------------------------------------*/

// include ---------------------------------------------------------------

// ITEMID_...-Defines im *.cxx

#ifndef _RSCSFX_HXX //autogen
#include <rsc/rscsfx.hxx>
#endif
#ifndef _SFXLSTNER_HXX //autogen
#include <svtools/lstner.hxx>
#endif
#ifndef _SFXTBXCTRL_HXX //autogen
#include <sfx2/tbxctrl.hxx>
#endif
#ifndef _SVX_STRARRAY_HXX
#include <svx/strarray.hxx>
#endif

#ifndef INCLUDED_SVXDLLAPI_H
#include "svx/svxdllapi.h"
#endif

// wichtig im mit HeDaBu erzeugtem tbxctrls.hxx!!!
class SvxLineItem;
class SvxBoxInfoItem;
class SvxFontItem;
class SvxFontHeightItem;
class SfxStyleControllerItem_Impl;
class SfxStyleSheetBasePool;
class SfxTemplateItem;

namespace svx
{
    class ToolboxButtonColorUpdater;
}
//########################################################################

//========================================================================
// class SvxStyleToolBoxControl ------------------------------------------
//========================================================================
class SVX_DLLPUBLIC SvxStyleToolBoxControl : public SfxToolBoxControl
{
    struct Impl;
public:
    SFX_DECL_TOOLBOX_CONTROL();

    SvxStyleToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );
    ~SvxStyleToolBoxControl();

    virtual Window* CreateItemWindow( Window *pParent );

    virtual void    StateChanged( USHORT nSID, SfxItemState eState,
                                  const SfxPoolItem* pState );

    DECL_LINK( VisibilityNotification, void* );
protected:
    // XInitialization
    virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);

    // XUpdatable
    virtual void SAL_CALL update() throw (::com::sun::star::uno::RuntimeException);

private:

#define MAX_FAMILIES 5

    SfxStyleSheetBasePool*              pStyleSheetPool;
    SfxStyleControllerItem_Impl*        pBoundItems [MAX_FAMILIES];
    ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > m_xBoundItems[MAX_FAMILIES];
    SfxTemplateItem*                    pFamilyState[MAX_FAMILIES];
    USHORT                              nActFamily; // Id in der ToolBox = Position - 1
    USHORT                              nActFilter; // FilterIdx
    USHORT                              nAppFilter; // Filter, den die App gesetzt hat
    String                              aCurSel;
    BOOL                                bListening;
    Impl*                               pImpl;

    SVX_DLLPRIVATE void Update();
    SVX_DLLPRIVATE void FillStyleBox();
    SVX_DLLPRIVATE void     SelectStyle( const String& rStyleName );

friend class SfxStyleControllerItem_Impl;

    SVX_DLLPRIVATE void         SetFamilyState  ( USHORT nIdx, const SfxTemplateItem* pItem );
    SVX_DLLPRIVATE SfxStyleFamily   GetActFamily    ();
};

//========================================================================
// class SvxFontNameToolBoxControl ---------------------------------------
//========================================================================

class SVX_DLLPUBLIC SvxFontNameToolBoxControl : public SfxToolBoxControl
{
public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxFontNameToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );

    virtual void    StateChanged        ( USHORT nSID, SfxItemState eState,
                                          const SfxPoolItem* pState );
    virtual Window* CreateItemWindow    ( Window *pParent );
};

//========================================================================
// class SvxFontHeightToolBoxControl -------------------------------------
//========================================================================

class SvxFontSizeItem;
class SvxFontItem;
class SvxFontSizeBox_Impl;

class SVX_DLLPUBLIC SvxFontHeightToolBoxControl : public SfxToolBoxControl
{
    SvxFontSizeBox_Impl* pBox;               // ItemWindow f"ur quick-access
    SvxFontItem*        pFontItem;          // Kopie des aktuellen FontItems

public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxFontHeightToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );
    ~SvxFontHeightToolBoxControl();

    // new controller API
    // XStatusListener
    virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event )
        throw ( ::com::sun::star::uno::RuntimeException );

    virtual void        StateChanged( USHORT nSID, SfxItemState eState,
                                       const SfxPoolItem* pState );
    virtual Window*     CreateItemWindow( Window *pParent );

//#if 0 // _SOLAR__PRIVATE
    const SvxFontItem*  GetFontItem_Impl()
                        {
                            updateStatus( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CharFontName" )));
                            return pFontItem;
                        }
//#endif
};

//========================================================================
// class SvxFontColorToolBoxControl --------------------------------------
//========================================================================

class SVX_DLLPUBLIC SvxFontColorToolBoxControl : public SfxToolBoxControl
{
    ::svx::ToolboxButtonColorUpdater*   pBtnUpdater;

public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxFontColorToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );
    ~SvxFontColorToolBoxControl();

    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );
    virtual SfxPopupWindowType  GetPopupWindowType() const;
    virtual SfxPopupWindow*     CreatePopupWindow();
};

//========================================================================
// class SvxFontColorExtToolBoxControl --------------------------------------
//========================================================================

class SVX_DLLPUBLIC SvxFontColorExtToolBoxControl : public SfxToolBoxControl
{
    using SfxToolBoxControl::StateChanged;
    using SfxToolBoxControl::Select;

    //  SfxStatusForwarder          aForward;
    ::svx::ToolboxButtonColorUpdater*   pBtnUpdater;

public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxFontColorExtToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );
    ~SvxFontColorExtToolBoxControl();

    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );
    virtual SfxPopupWindowType  GetPopupWindowType() const;
    virtual SfxPopupWindow*     CreatePopupWindow();
    virtual void                Select( BOOL bMod1 = FALSE );

};

//========================================================================
// class SvxColorToolBoxControl ------------------------------------------
//========================================================================

class SVX_DLLPUBLIC SvxColorToolBoxControl : public SfxToolBoxControl
{
    ::svx::ToolboxButtonColorUpdater*   pBtnUpdater;
public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxColorToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );
    ~SvxColorToolBoxControl();

    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );
    virtual SfxPopupWindowType  GetPopupWindowType() const;
    virtual SfxPopupWindow*     CreatePopupWindow();
};

//========================================================================
// class SvxFrameToolBoxControl ------------------------------------------
//========================================================================

class SVX_DLLPUBLIC SvxFrameToolBoxControl : public SfxToolBoxControl
{
public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxFrameToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );

    virtual SfxPopupWindowType  GetPopupWindowType() const;
    virtual SfxPopupWindow*     CreatePopupWindow();
    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );

};

//========================================================================
// class SvxLineStyleToolBoxControl --------------------------------------
//========================================================================

class SVX_DLLPUBLIC SvxFrameLineStyleToolBoxControl : public SfxToolBoxControl
{
public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxFrameLineStyleToolBoxControl( USHORT nSlotId, USHORT nId, ToolBox& rTbx );

    virtual SfxPopupWindowType  GetPopupWindowType() const;
    virtual SfxPopupWindow*     CreatePopupWindow();
    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );
};

//========================================================================
// class SvxFrameLineColorToolBoxControl ---------------------------------
//========================================================================

class SVX_DLLPUBLIC SvxFrameLineColorToolBoxControl : public SfxToolBoxControl
{
    ::svx::ToolboxButtonColorUpdater*   pBtnUpdater;
public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxFrameLineColorToolBoxControl( USHORT nSlotId,
                                     USHORT nId,
                                     ToolBox& rTbx );
    ~SvxFrameLineColorToolBoxControl();

    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );
    virtual SfxPopupWindowType  GetPopupWindowType() const;
    virtual SfxPopupWindow*     CreatePopupWindow();
};

class SvxReloadControllerItem_Impl;
class SvxReloadControllerItem : public SfxToolBoxControl
{
private:
    SvxReloadControllerItem_Impl* pImpl;

public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxReloadControllerItem( USHORT nSlotId,
                             USHORT nId,
                             ToolBox& rTbx );
    ~SvxReloadControllerItem();

protected:
    virtual void StateChanged( USHORT nSID, SfxItemState eState,
                               const SfxPoolItem* pState );
};

class SVX_DLLPUBLIC SvxSimpleUndoRedoController : public SfxToolBoxControl
{
private:
    ::rtl::OUString             aDefaultText;

public:
    SFX_DECL_TOOLBOX_CONTROL();
    SvxSimpleUndoRedoController( USHORT nSlotId, USHORT nId, ToolBox& rTbx );
    ~SvxSimpleUndoRedoController();

    virtual void                StateChanged( USHORT nSID, SfxItemState eState,
                                              const SfxPoolItem* pState );
};

#endif // #ifndef _SVX_TBCONTRL_HXX
<|endoftext|>


<commit_before><commit_msg>svx: pixelctl demo - cleanup headers<commit_after><|endoftext|>


<commit_before><commit_msg>Fix some character literals to use the right escape string.<commit_after><|endoftext|>


<commit_before>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkInputPort.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.

 * Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

 * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
   of any contributors may be used to endorse or promote products derived
   from this software without specific prior written permission.

 * Modified source versions must be plainly marked as such, and must not be
   misrepresented as being the original software.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=========================================================================*/
#include "vtkInputPort.h"
#include "vtkOutputPort.h"
#include "vtkMultiProcessController.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
#include "vtkStructuredGrid.h"
#include "vtkRectilinearGrid.h"
#include "vtkStructuredPoints.h"
#include "vtkImageData.h"
#include "vtkObjectFactory.h"
#include "vtkCommand.h"

//----------------------------------------------------------------------------
vtkInputPort* vtkInputPort::New()
{
  // First try to create the object from the vtkObjectFactory
  vtkObject* ret = vtkObjectFactory::CreateInstance("vtkInputPort");
  if(ret)
    {
    return (vtkInputPort*)ret;
    }
  // If the factory was unable to create the object, then create it here.
  return new vtkInputPort;
}

//----------------------------------------------------------------------------
vtkInputPort::vtkInputPort()
{
  this->RemoteProcessId = 0;
  this->Tag = 0;

  // Controller keeps a reference to this object as well.
  this->Controller = NULL;
  this->SetController(vtkMultiProcessController::GetGlobalController());

  // State variables.
  this->TransferNeeded = 0;
  this->DataTime = 0;

  this->DoUpdateInformation = 1;
}

//----------------------------------------------------------------------------
// We need to have a "GetNetReferenceCount" to avoid memory leaks.
vtkInputPort::~vtkInputPort()
{
  this->SetController(0);
}

//----------------------------------------------------------------------------
void vtkInputPort::PrintSelf(ostream& os, vtkIndent indent)
{
  vtkSource::PrintSelf(os,indent);
  os << indent << "RemoteProcessId: " << this->RemoteProcessId << endl;
  os << indent << "Tag: " << this->Tag << endl;
  os << indent << "Controller: (" << this->Controller << ")\n";
  os << indent << "DataTime: " << this->DataTime << endl;
  os << indent << "TransferNeeded: " << this->TransferNeeded << endl;
}

//----------------------------------------------------------------------------
// Maybe we can come up with a way to check the type of the upstream port's
// input here.  While we are at it, we could automatically generate a tag.
vtkPolyData *vtkInputPort::GetPolyDataOutput()
{
  vtkDataObject *output = NULL;

  // If there is already an output, I hope it is a vtkPolyData.
  if (this->Outputs)
    {
    output = this->Outputs[0];
    }
  if (output)
    {
    if (output->GetDataObjectType() == VTK_POLY_DATA)
      {
      return (vtkPolyData*)(output);
      }
    else
      {
      vtkWarningMacro("vtkInputPort: Changing data type of output.");
      }
    }

  output = vtkPolyData::New();
  output->ReleaseData();
  this->vtkSource::SetNthOutput(0, output);
  output->Delete();
  return (vtkPolyData*)(output);
}

//----------------------------------------------------------------------------
// Maybe we can come up with a way to check the type of the upstream port's
// input here.  While we are at it, we could automatically generate a tag.
vtkUnstructuredGrid *vtkInputPort::GetUnstructuredGridOutput()
{
  vtkDataObject *output = NULL;

  // If there is already an output, I hope it is a vtkPolyData.
  if (this->Outputs)
    {
    output = this->Outputs[0];
    }
  if (output)
    {
    if (output->GetDataObjectType() == VTK_UNSTRUCTURED_GRID)
      {
      return (vtkUnstructuredGrid*)(output);
      }
    else
      {
      vtkWarningMacro("vtkInputPort: Changing data type of output.");
      }
    }

  output = vtkUnstructuredGrid::New();
  output->ReleaseData();
  this->vtkSource::SetNthOutput(0, output);
  output->Delete();
  return (vtkUnstructuredGrid*)(output);
}

//----------------------------------------------------------------------------
// Maybe we can come up with a way to check the type of the upstream port's
// input here.  While we are at it, we could automatically generate a tag.
vtkStructuredGrid *vtkInputPort::GetStructuredGridOutput()
{
  vtkDataObject *output = NULL;

  // If there is already an output, I hope it is a vtkPolyData.
  if (this->Outputs)
    {
    output = this->Outputs[0];
    }
  if (output)
    {
    if (output->GetDataObjectType() == VTK_STRUCTURED_GRID)
      {
      return (vtkStructuredGrid*)(output);
      }
    else
      {
      vtkWarningMacro("vtkInputPort: Changing data type of output.");
      }
    }

  output = vtkStructuredGrid::New();
  output->ReleaseData();
  this->vtkSource::SetNthOutput(0, output);
  output->Delete();
  return (vtkStructuredGrid*)(output);
}

//----------------------------------------------------------------------------
// Maybe we can come up with a way to check the type of the upstream port's
// input here.  While we are at it, we could automatically generate a tag.
vtkRectilinearGrid *vtkInputPort::GetRectilinearGridOutput()
{
  vtkDataObject *output = NULL;

  // If there is already an output, I hope it is a vtkPolyData.
  if (this->Outputs)
    {
    output = this->Outputs[0];
    }
  if (output)
    {
    if (output->GetDataObjectType() == VTK_RECTILINEAR_GRID)
      {
      return (vtkRectilinearGrid*)(output);
      }
    else
      {
      vtkWarningMacro("vtkInputPort: Changing data type of output.");
      }
    }

  output = vtkRectilinearGrid::New();
  output->ReleaseData();
  this->vtkSource::SetNthOutput(0, output);
  output->Delete();
  return (vtkRectilinearGrid*)(output);
}

//----------------------------------------------------------------------------
// Maybe we can come up with a way to check the type of the upstream port's
// input here.  While we are at it, we could automatically generate a tag.
vtkStructuredPoints *vtkInputPort::GetStructuredPointsOutput()
{
  vtkDataObject *output = NULL;

  // If there is already an output, I hope it is a vtkPolyData.
  if (this->Outputs)
    {
    output = this->Outputs[0];
    }
  if (output)
    {
    if (output->GetDataObjectType() == VTK_STRUCTURED_POINTS)
      {
      return (vtkStructuredPoints*)(output);
      }
    else
      {
      vtkWarningMacro("vtkInputPort: Changing data type of output.");
      }
    }

  output = vtkStructuredPoints::New();
  output->ReleaseData();
  this->vtkSource::SetNthOutput(0, output);
  output->Delete();
  return (vtkStructuredPoints*)(output);
}

//----------------------------------------------------------------------------
// Maybe we can come up with a way to check the type of the upstream port's
// input here.  While we are at it, we could automatically generate a tag.
vtkImageData *vtkInputPort::GetImageDataOutput()
{
  vtkDataObject *output = NULL;

  // If there is already an output, I hope it is a vtkImageData.
  if (this->Outputs)
    {
    output = this->Outputs[0];
    }
  if (output)
    {
    if (output->GetDataObjectType() == VTK_IMAGE_DATA)
      {
      return (vtkImageData*)(output);
      }
    else
      {
      vtkWarningMacro("vtkInputPort: Changing data type of output.");
      }
    }

  output = vtkImageData::New();
  output->ReleaseData();
  this->vtkSource::SetNthOutput(0, output);
  output->Delete();
  return (vtkImageData*)(output);
}

//----------------------------------------------------------------------------
// The only tricky thing here is the translation of the PipelineMTime
// into a value meaningful to this process.
void vtkInputPort::UpdateInformation()
{
  vtkDataObject *output;
  unsigned long pmt;

  if (!this->DoUpdateInformation)
    {
    return;
    }

  if (this->Outputs == NULL || this->Outputs[0] == NULL)
    {
    vtkErrorMacro("No output.");
    return;
    }

  output = this->Outputs[0];

  // Trigger UpdateInformation in remotePort.
  // Up-stream port should have the same tag.
  this->Controller->TriggerRMI(this->RemoteProcessId, this->Tag);

  // Now receive the information
  int wholeInformation[7];
  this->Controller->Receive( wholeInformation, 7,
                             this->RemoteProcessId,
                             vtkInputPort::INFORMATION_TRANSFER_TAG);

  this->Controller->Receive( &pmt, 1,
                             this->RemoteProcessId,
                             vtkInputPort::INFORMATION_TRANSFER_TAG);

  output->SetWholeExtent( wholeInformation );

  // Save the upstream PMT for execute check (this may not be necessary)
  this->UpStreamMTime = pmt;

  // !!! Make sure that Update is called if data is released. !!!
  if (pmt > this->DataTime || output->GetDataReleased())
    {
    // Our data is out of data.  We will need a transfer.
    // This Modified call will ensure Update will get called.
    this->Modified();
    }
  output->SetPipelineMTime(this->GetMTime());
  // Locality has to be changed too.
  //output->GetDataInformation()->SetLocality(1.0);

}

//----------------------------------------------------------------------------
// The only tricky thing here is the translation of the PipelineMTime
// into a value meaningful to this process.
void vtkInputPort::TriggerAsynchronousUpdate()
{
  // This should be cleared by this point.
  // UpdateInformation and Update calls need to be made in pairs.
  if (this->TransferNeeded)
    {
    vtkWarningMacro("Transfer should have been received.");
    return;
    }

  vtkDataObject *output = this->Outputs[0];

  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  // This would normally be done in the Update method, but since
  // we want task parallelism with multiple input filters,
  // it needs to be here.

  // Do we need to update?
  // !!! I am uneasy about the Released check.  Although a new update extent
  // will cause the data to be released,  released data does not imply
  // Update will be called !!!!
  if (this->UpStreamMTime <= this->DataTime && ! output->GetDataReleased())
    {
    // No, we do not need to update.
    return;
    }

  // Trigger Update in remotePort.
  // remotePort should have the same tag.
  this->Controller->TriggerRMI(this->RemoteProcessId, this->Tag+1);

  // Send the UpdateExtent request. The first 6 ints are the 3d extent, the next
  // to are the pieces extent (we don't know which type it is - just send both)
  int extent[9];
  output->GetUpdateExtent( extent );
  extent[6] = output->GetUpdatePiece();
  extent[7] = output->GetUpdateNumberOfPieces();
  extent[8] = output->GetUpdateGhostLevel();
  this->Controller->Send( extent, 9, this->RemoteProcessId,
                          vtkInputPort::UPDATE_EXTENT_TAG);

  // This is for pipeline parallism.
  // The Upstream port may or may not promote its data (execute).
  // It needs the data time of our output to compare to the mtime
  // of its input to determine if it should send the data (execute).
  this->Controller->Send( &(this->DataTime), 1, this->RemoteProcessId,
			  vtkInputPort::NEW_DATA_TIME_TAG);

  // This automatically causes to remotePort to send the data.
  // Tell the update method to receive the data.
  this->TransferNeeded = 1;
}

//----------------------------------------------------------------------------
void vtkInputPort::UpdateData(vtkDataObject *output)
{

  if (this->UpStreamMTime <= this->DataTime && ! output->GetDataReleased())
    {
    // No, we do not need to update.
    return;
    }

  if ( ! this->TransferNeeded)
    {
    // If something unexpected happened, let me know.
    vtkWarningMacro("UpdateData was called when no data was needed.");
    return;
    }

  this->InvokeEvent(vtkCommand::StartEvent,NULL);

  // Well here is a bit of a hack.
  // Since the reader will overwrite whole extents, we need to save the whole
  // extent and reset it.
  int wholeExtent[6];
  output->GetWholeExtent(wholeExtent);
  // receive the data

  this->Controller->Receive(output, this->RemoteProcessId,
			    vtkInputPort::DATA_TRANSFER_TAG);

  output->SetWholeExtent( wholeExtent );

  this->InvokeEvent(vtkCommand::EndEvent,NULL);

  // Receive the data time
  this->Controller->Receive( &(this->DataTime), 1, this->RemoteProcessId,
			    vtkInputPort::NEW_DATA_TIME_TAG);

  this->TransferNeeded = 0;
}

<commit_msg>Need to set locality.<commit_after>/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkInputPort.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

 * Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.

 * Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

 * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
   of any contributors may be used to endorse or promote products derived
   from this software without specific prior written permission.

 * Modified source versions must be plainly marked as such, and must not be
   misrepresented as being the original software.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=========================================================================*/
#include "vtkInputPort.h"
#include "vtkOutputPort.h"
#include "vtkMultiProcessController.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
#include "vtkStructuredGrid.h"
#include "vtkRectilinearGrid.h"
#include "vtkStructuredPoints.h"
#include "vtkImageData.h"
#include "vtkObjectFactory.h"
#include "vtkCommand.h"

//----------------------------------------------------------------------------
vtkInputPort* vtkInputPort::New()
{
  // First try to create the object from the vtkObjectFactory
  vtkObject* ret = vtkObjectFactory::CreateInstance("vtkInputPort");
  if(ret)
    {
    return (vtkInputPort*)ret;
    }
  // If the factory was unable to create the object, then create it here.
  return new vtkInputPort;
}

//----------------------------------------------------------------------------
vtkInputPort::vtkInputPort()
{
  this->RemoteProcessId = 0;
  this->Tag = 0;

  // Controller keeps a reference to this object as well.
  this->Controller = NULL;
  this->SetController(vtkMultiProcessController::GetGlobalController());

  // State variables.
  this->TransferNeeded = 0;
  this->DataTime = 0;

  this->DoUpdateInformation = 1;
}

//----------------------------------------------------------------------------
// We need to have a "GetNetReferenceCount" to avoid memory leaks.
vtkInputPort::~vtkInputPort()
{
  this->SetController(0);
}

//----------------------------------------------------------------------------
void vtkInputPort::PrintSelf(ostream& os, vtkIndent indent)
{
  vtkSource::PrintSelf(os,indent);
  os << indent << "RemoteProcessId: " << this->RemoteProcessId << endl;
  os << indent << "Tag: " << this->Tag << endl;
  os << indent << "Controller: (" << this->Controller << ")\n";
  os << indent << "DataTime: " << this->DataTime << endl;
  os << indent << "TransferNeeded: " << this->TransferNeeded << endl;
}

//----------------------------------------------------------------------------
// Maybe we can come up with a way to check the type of the upstream port's
// input here.  While we are at it, we could automatically generate a tag.
vtkPolyData *vtkInputPort::GetPolyDataOutput()
{
  vtkDataObject *output = NULL;

  // If there is already an output, I hope it is a vtkPolyData.
  if (this->Outputs)
    {
    output = this->Outputs[0];
    }
  if (output)
    {
    if (output->GetDataObjectType() == VTK_POLY_DATA)
      {
      return (vtkPolyData*)(output);
      }
    else
      {
      vtkWarningMacro("vtkInputPort: Changing data type of output.");
      }
    }

  output = vtkPolyData::New();
  output->ReleaseData();
  this->vtkSource::SetNthOutput(0, output);
  output->Delete();
  return (vtkPolyData*)(output);
}

//----------------------------------------------------------------------------
// Maybe we can come up with a way to check the type of the upstream port's
// input here.  While we are at it, we could automatically generate a tag.
vtkUnstructuredGrid *vtkInputPort::GetUnstructuredGridOutput()
{
  vtkDataObject *output = NULL;

  // If there is already an output, I hope it is a vtkPolyData.
  if (this->Outputs)
    {
    output = this->Outputs[0];
    }
  if (output)
    {
    if (output->GetDataObjectType() == VTK_UNSTRUCTURED_GRID)
      {
      return (vtkUnstructuredGrid*)(output);
      }
    else
      {
      vtkWarningMacro("vtkInputPort: Changing data type of output.");
      }
    }

  output = vtkUnstructuredGrid::New();
  output->ReleaseData();
  this->vtkSource::SetNthOutput(0, output);
  output->Delete();
  return (vtkUnstructuredGrid*)(output);
}

//----------------------------------------------------------------------------
// Maybe we can come up with a way to check the type of the upstream port's
// input here.  While we are at it, we could automatically generate a tag.
vtkStructuredGrid *vtkInputPort::GetStructuredGridOutput()
{
  vtkDataObject *output = NULL;

  // If there is already an output, I hope it is a vtkPolyData.
  if (this->Outputs)
    {
    output = this->Outputs[0];
    }
  if (output)
    {
    if (output->GetDataObjectType() == VTK_STRUCTURED_GRID)
      {
      return (vtkStructuredGrid*)(output);
      }
    else
      {
      vtkWarningMacro("vtkInputPort: Changing data type of output.");
      }
    }

  output = vtkStructuredGrid::New();
  output->ReleaseData();
  this->vtkSource::SetNthOutput(0, output);
  output->Delete();
  return (vtkStructuredGrid*)(output);
}

//----------------------------------------------------------------------------
// Maybe we can come up with a way to check the type of the upstream port's
// input here.  While we are at it, we could automatically generate a tag.
vtkRectilinearGrid *vtkInputPort::GetRectilinearGridOutput()
{
  vtkDataObject *output = NULL;

  // If there is already an output, I hope it is a vtkPolyData.
  if (this->Outputs)
    {
    output = this->Outputs[0];
    }
  if (output)
    {
    if (output->GetDataObjectType() == VTK_RECTILINEAR_GRID)
      {
      return (vtkRectilinearGrid*)(output);
      }
    else
      {
      vtkWarningMacro("vtkInputPort: Changing data type of output.");
      }
    }

  output = vtkRectilinearGrid::New();
  output->ReleaseData();
  this->vtkSource::SetNthOutput(0, output);
  output->Delete();
  return (vtkRectilinearGrid*)(output);
}

//----------------------------------------------------------------------------
// Maybe we can come up with a way to check the type of the upstream port's
// input here.  While we are at it, we could automatically generate a tag.
vtkStructuredPoints *vtkInputPort::GetStructuredPointsOutput()
{
  vtkDataObject *output = NULL;

  // If there is already an output, I hope it is a vtkPolyData.
  if (this->Outputs)
    {
    output = this->Outputs[0];
    }
  if (output)
    {
    if (output->GetDataObjectType() == VTK_STRUCTURED_POINTS)
      {
      return (vtkStructuredPoints*)(output);
      }
    else
      {
      vtkWarningMacro("vtkInputPort: Changing data type of output.");
      }
    }

  output = vtkStructuredPoints::New();
  output->ReleaseData();
  this->vtkSource::SetNthOutput(0, output);
  output->Delete();
  return (vtkStructuredPoints*)(output);
}

//----------------------------------------------------------------------------
// Maybe we can come up with a way to check the type of the upstream port's
// input here.  While we are at it, we could automatically generate a tag.
vtkImageData *vtkInputPort::GetImageDataOutput()
{
  vtkDataObject *output = NULL;

  // If there is already an output, I hope it is a vtkImageData.
  if (this->Outputs)
    {
    output = this->Outputs[0];
    }
  if (output)
    {
    if (output->GetDataObjectType() == VTK_IMAGE_DATA)
      {
      return (vtkImageData*)(output);
      }
    else
      {
      vtkWarningMacro("vtkInputPort: Changing data type of output.");
      }
    }

  output = vtkImageData::New();
  output->ReleaseData();
  this->vtkSource::SetNthOutput(0, output);
  output->Delete();
  return (vtkImageData*)(output);
}

//----------------------------------------------------------------------------
// The only tricky thing here is the translation of the PipelineMTime
// into a value meaningful to this process.
void vtkInputPort::UpdateInformation()
{
  vtkDataObject *output;
  unsigned long pmt;

  if (!this->DoUpdateInformation)
    {
    return;
    }

  if (this->Outputs == NULL || this->Outputs[0] == NULL)
    {
    vtkErrorMacro("No output.");
    return;
    }

  output = this->Outputs[0];

  // Trigger UpdateInformation in remotePort.
  // Up-stream port should have the same tag.
  this->Controller->TriggerRMI(this->RemoteProcessId, this->Tag);

  // Now receive the information
  int wholeInformation[7];
  this->Controller->Receive( wholeInformation, 7,
                             this->RemoteProcessId,
                             vtkInputPort::INFORMATION_TRANSFER_TAG);

  this->Controller->Receive( &pmt, 1,
                             this->RemoteProcessId,
                             vtkInputPort::INFORMATION_TRANSFER_TAG);

  output->SetWholeExtent( wholeInformation );

  // Save the upstream PMT for execute check (this may not be necessary)
  this->UpStreamMTime = pmt;

  // !!! Make sure that Update is called if data is released. !!!
  if (pmt > this->DataTime || output->GetDataReleased())
    {
    // Our data is out of data.  We will need a transfer.
    // This Modified call will ensure Update will get called.
    this->Modified();
    }
  output->SetPipelineMTime(this->GetMTime());
  // Locality has to be changed too.
  output->SetLocality(1.0);

}

//----------------------------------------------------------------------------
// The only tricky thing here is the translation of the PipelineMTime
// into a value meaningful to this process.
void vtkInputPort::TriggerAsynchronousUpdate()
{
  // This should be cleared by this point.
  // UpdateInformation and Update calls need to be made in pairs.
  if (this->TransferNeeded)
    {
    vtkWarningMacro("Transfer should have been received.");
    return;
    }

  vtkDataObject *output = this->Outputs[0];

  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  // This would normally be done in the Update method, but since
  // we want task parallelism with multiple input filters,
  // it needs to be here.

  // Do we need to update?
  // !!! I am uneasy about the Released check.  Although a new update extent
  // will cause the data to be released,  released data does not imply
  // Update will be called !!!!
  if (this->UpStreamMTime <= this->DataTime && ! output->GetDataReleased())
    {
    // No, we do not need to update.
    return;
    }

  // Trigger Update in remotePort.
  // remotePort should have the same tag.
  this->Controller->TriggerRMI(this->RemoteProcessId, this->Tag+1);

  // Send the UpdateExtent request. The first 6 ints are the 3d extent, the next
  // to are the pieces extent (we don't know which type it is - just send both)
  int extent[9];
  output->GetUpdateExtent( extent );
  extent[6] = output->GetUpdatePiece();
  extent[7] = output->GetUpdateNumberOfPieces();
  extent[8] = output->GetUpdateGhostLevel();
  this->Controller->Send( extent, 9, this->RemoteProcessId,
                          vtkInputPort::UPDATE_EXTENT_TAG);

  // This is for pipeline parallism.
  // The Upstream port may or may not promote its data (execute).
  // It needs the data time of our output to compare to the mtime
  // of its input to determine if it should send the data (execute).
  this->Controller->Send( &(this->DataTime), 1, this->RemoteProcessId,
			  vtkInputPort::NEW_DATA_TIME_TAG);

  // This automatically causes to remotePort to send the data.
  // Tell the update method to receive the data.
  this->TransferNeeded = 1;
}

//----------------------------------------------------------------------------
void vtkInputPort::UpdateData(vtkDataObject *output)
{

  if (this->UpStreamMTime <= this->DataTime && ! output->GetDataReleased())
    {
    // No, we do not need to update.
    return;
    }

  if ( ! this->TransferNeeded)
    {
    // If something unexpected happened, let me know.
    vtkWarningMacro("UpdateData was called when no data was needed.");
    return;
    }

  this->InvokeEvent(vtkCommand::StartEvent,NULL);

  // Well here is a bit of a hack.
  // Since the reader will overwrite whole extents, we need to save the whole
  // extent and reset it.
  int wholeExtent[6];
  output->GetWholeExtent(wholeExtent);
  // receive the data

  this->Controller->Receive(output, this->RemoteProcessId,
			    vtkInputPort::DATA_TRANSFER_TAG);

  output->SetWholeExtent( wholeExtent );

  this->InvokeEvent(vtkCommand::EndEvent,NULL);

  // Receive the data time
  this->Controller->Receive( &(this->DataTime), 1, this->RemoteProcessId,
			    vtkInputPort::NEW_DATA_TIME_TAG);

  this->TransferNeeded = 0;
}

<|endoftext|>


<commit_before>#include "xchainer/numeric.h"

#include <cmath>

#include "xchainer/dtype.h"
#include "xchainer/error.h"
#include "xchainer/scalar.h"

namespace xchainer {

bool AllClose(const Array& a, const Array& b, double rtol, double atol) {
    if (a.shape() != b.shape()) {
        throw DimensionError("cannot compare Arrays of different shapes");
    }
    if (a.dtype() != b.dtype()) {
        throw DtypeError("cannot compare Arrays of different Dtypes");
    }
    return VisitDtype(a.dtype(), [&](auto pt) {
        using T = typename decltype(pt)::type;

        auto total_size = a.shape().total_size();
        auto* adata = static_cast<const T*>(a.data().get());
        auto* bdata = static_cast<const T*>(b.data().get());
        for (decltype(total_size) i = 0; i < total_size; i++) {
            if (std::abs(adata[i] - bdata[i]) > atol + rtol * std::abs(bdata[i])) {
                return false;
            }
        }
        return true;
    });
}

}  // namespace xchainer
<commit_msg>Remove auto for consistency<commit_after>#include "xchainer/numeric.h"

#include <cmath>

#include "xchainer/dtype.h"
#include "xchainer/error.h"
#include "xchainer/scalar.h"

namespace xchainer {

bool AllClose(const Array& a, const Array& b, double rtol, double atol) {
    if (a.shape() != b.shape()) {
        throw DimensionError("cannot compare Arrays of different shapes");
    }
    if (a.dtype() != b.dtype()) {
        throw DtypeError("cannot compare Arrays of different Dtypes");
    }
    return VisitDtype(a.dtype(), [&](auto pt) {
        using T = typename decltype(pt)::type;

        int64_t total_size = a.total_size();
        auto* adata = static_cast<const T*>(a.data().get());
        auto* bdata = static_cast<const T*>(b.data().get());

        for (int64_t i = 0; i < total_size; i++) {
            if (std::abs(adata[i] - bdata[i]) > atol + rtol * std::abs(bdata[i])) {
                return false;
            }
        }
        return true;
    });
}

}  // namespace xchainer
<|endoftext|>


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

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

#include "alienwarn.hxx"
#include "sfxresid.hxx"
#include <sfx2/sfxuno.hxx>

#include "alienwarn.hrc"
#include "dialog.hrc"
#include <vcl/msgbox.hxx>
#include <svtools/saveopt.hxx>

// class SfxAlienWarningDialog -------------------------------------------

SfxAlienWarningDialog::SfxAlienWarningDialog( Window* pParent, const String& _rFormatName ) :

    SfxModalDialog( pParent, SfxResId( RID_DLG_ALIEN_WARNING ) ),

    m_aQueryImage       ( this, SfxResId( FI_QUERY ) ),
    m_aInfoText         ( this, SfxResId( FT_INFOTEXT ) ),
    m_aKeepCurrentBtn   ( this, SfxResId( PB_NO ) ),
    m_aSaveODFBtn       ( this, SfxResId( PB_YES ) ),
    m_aMoreInfoBtn      ( this, SfxResId( PB_MOREINFO ) ),
    m_aOptionLine       ( this, SfxResId( FL_OPTION ) ),
    m_aWarningOnBox     ( this, SfxResId( CB_WARNING_OFF ) )

{
    FreeResource();

    // accessibility issue #i73576#: the buttons don't want the info text as label
    m_aKeepCurrentBtn.SetStyle( m_aKeepCurrentBtn.GetStyle() | WB_NOLABEL );
    m_aSaveODFBtn.SetStyle( m_aSaveODFBtn.GetStyle() | WB_NOLABEL );

    // set questionmark image
    m_aQueryImage.SetImage( QueryBox::GetStandardImage() );

    // replace formatname
    String sInfoText = m_aInfoText.GetText();
    sInfoText.SearchAndReplaceAll( DEFINE_CONST_UNICODE("%FORMATNAME"), _rFormatName );
    m_aInfoText.SetText( sInfoText );

    // load value of "warning on" checkbox from save options
    m_aWarningOnBox.Check( SvtSaveOptions().IsWarnAlienFormat() == sal_True );

    // set focus to "Keep Current Format" button
    m_aKeepCurrentBtn.GrabFocus();

    // pb: #i43989# we have no online help for this dialog at the moment
    // -> hide the "more info" button
    //m_aMoreInfoBtn.Hide();

    // calculate and set the size of the dialog and its controls
    InitSize();
}

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

SfxAlienWarningDialog::~SfxAlienWarningDialog()
{
    // save value of "warning off" checkbox, if necessary
    SvtSaveOptions aSaveOpt;
    sal_Bool bChecked = m_aWarningOnBox.IsChecked();
    if ( aSaveOpt.IsWarnAlienFormat() != bChecked )
        aSaveOpt.SetWarnAlienFormat( bChecked );
}

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

void SfxAlienWarningDialog::InitSize()
{
    // if the button text is too wide, then broaden the button
    long nTxtW = m_aMoreInfoBtn.GetCtrlTextWidth( m_aMoreInfoBtn.GetText() );
    long nCtrlW = m_aMoreInfoBtn.GetSizePixel().Width();
    if ( nTxtW >= nCtrlW )
    {
        long nDelta = nTxtW - nCtrlW;
        nDelta += IMPL_EXTRA_BUTTON_WIDTH;
        Point aNextPoint = m_aKeepCurrentBtn.GetPosPixel();
        aNextPoint.X() += m_aKeepCurrentBtn.GetSizePixel().Width();
        Point aNewPoint = m_aMoreInfoBtn.GetPosPixel();
        aNewPoint.X() -= nDelta;
        if ( aNextPoint.X() >= aNewPoint.X() )
        {
            long nSpace = aNextPoint.X() - aNewPoint.X();
            nSpace += 2;
            nDelta -= nSpace;
            aNewPoint.X() += nSpace;
        }
        Size aNewSize = m_aMoreInfoBtn.GetSizePixel();
        aNewSize.Width() += nDelta;
        m_aMoreInfoBtn.SetPosSizePixel( aNewPoint, aNewSize );
    }

    // text of checkbox to wide -> add new line
    nTxtW = m_aWarningOnBox.GetCtrlTextWidth( m_aWarningOnBox.GetText() ) + IMPL_EXTRA_BUTTON_WIDTH;
    nCtrlW = m_aWarningOnBox.GetSizePixel().Width();
    if ( nTxtW >= nCtrlW )
    {
        long nTextHeight = m_aWarningOnBox.GetTextHeight();
        Size aNewSize = m_aWarningOnBox.GetSizePixel();
        aNewSize.Height() += nTextHeight;
        m_aWarningOnBox.SetSizePixel( aNewSize );
        aNewSize = GetSizePixel();
        aNewSize.Height() += nTextHeight;
        SetSizePixel( aNewSize );
    }

    // align the size of the information text control (FixedText) to its content
    Size aMinSize = m_aInfoText.CalcMinimumSize( m_aInfoText.GetSizePixel().Width() );
    long nTxtH = aMinSize.Height();
    long nCtrlH = m_aInfoText.GetSizePixel().Height();
    long nDelta = ( nCtrlH - nTxtH );
    Size aNewSize = m_aInfoText.GetSizePixel();
    aNewSize.Height() -= nDelta;
    m_aInfoText.SetSizePixel( aNewSize );

    // new position for the succeeding windows
    Window* pWins[] =
    {
        &m_aSaveODFBtn, &m_aKeepCurrentBtn, &m_aMoreInfoBtn, &m_aOptionLine, &m_aWarningOnBox
    };
    Window** pCurrent = pWins;
    for ( sal_uInt32 i = 0; i < sizeof( pWins ) / sizeof( pWins[ 0 ] ); ++i, ++pCurrent )
    {
        Point aNewPos = (*pCurrent)->GetPosPixel();
        aNewPos.Y() -= nDelta;
        (*pCurrent)->SetPosPixel( aNewPos );
    }

    // new size of the dialog
    aNewSize = GetSizePixel();
    aNewSize.Height() -= nDelta;
    SetSizePixel( aNewSize );

    // recalculate the size and position of the buttons
    m_aMoreInfoBtn.Hide();
    nTxtW = m_aKeepCurrentBtn.GetCtrlTextWidth( m_aKeepCurrentBtn.GetText() );
    long nTemp = m_aSaveODFBtn.GetCtrlTextWidth( m_aSaveODFBtn.GetText() );
    if ( nTemp > nTxtW )
        nTxtW = nTemp;
    nTxtW += IMPL_EXTRA_BUTTON_WIDTH;
    Size a3Size = LogicToPixel( Size( 3, 3 ), MAP_APPFONT );
    Point aPos = m_aKeepCurrentBtn.GetPosPixel();
    aPos.X() = ( aNewSize.Width() - (2*nTxtW) - a3Size.Width() ) / 2;
    long nDefX = m_aWarningOnBox.GetPosPixel().X();
    if ( nDefX < aPos.X() )
        aPos.X() = nDefX;
    aNewSize = m_aKeepCurrentBtn.GetSizePixel();
    aNewSize.Width() = nTxtW;
    m_aKeepCurrentBtn.SetPosSizePixel( aPos, aNewSize );
    aPos.X() += nTxtW + a3Size.Width();
    m_aSaveODFBtn.SetPosSizePixel( aPos, aNewSize );
}

<commit_msg>INTEGRATION: CWS fwk90 (1.12.18); FILE MERGED 2008/06/09 04:51:49 pb 1.12.18.1: fix: #i89851# remove non-working a11y-fix<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: alienwarn.cxx,v $
 * $Revision: 1.13 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

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

#include "alienwarn.hxx"
#include "sfxresid.hxx"
#include <sfx2/sfxuno.hxx>

#include "alienwarn.hrc"
#include "dialog.hrc"
#include <vcl/msgbox.hxx>
#include <svtools/saveopt.hxx>

// class SfxAlienWarningDialog -------------------------------------------

SfxAlienWarningDialog::SfxAlienWarningDialog( Window* pParent, const String& _rFormatName ) :

    SfxModalDialog( pParent, SfxResId( RID_DLG_ALIEN_WARNING ) ),

    m_aQueryImage       ( this, SfxResId( FI_QUERY ) ),
    m_aInfoText         ( this, SfxResId( FT_INFOTEXT ) ),
    m_aKeepCurrentBtn   ( this, SfxResId( PB_NO ) ),
    m_aSaveODFBtn       ( this, SfxResId( PB_YES ) ),
    m_aMoreInfoBtn      ( this, SfxResId( PB_MOREINFO ) ),
    m_aOptionLine       ( this, SfxResId( FL_OPTION ) ),
    m_aWarningOnBox     ( this, SfxResId( CB_WARNING_OFF ) )

{
    FreeResource();

    // set questionmark image
    m_aQueryImage.SetImage( QueryBox::GetStandardImage() );

    // replace formatname
    String sInfoText = m_aInfoText.GetText();
    sInfoText.SearchAndReplaceAll( DEFINE_CONST_UNICODE("%FORMATNAME"), _rFormatName );
    m_aInfoText.SetText( sInfoText );

    // load value of "warning on" checkbox from save options
    m_aWarningOnBox.Check( SvtSaveOptions().IsWarnAlienFormat() == sal_True );

    // set focus to "Keep Current Format" button
    m_aKeepCurrentBtn.GrabFocus();

    // pb: #i43989# we have no online help for this dialog at the moment
    // -> hide the "more info" button
    //m_aMoreInfoBtn.Hide();

    // calculate and set the size of the dialog and its controls
    InitSize();
}

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

SfxAlienWarningDialog::~SfxAlienWarningDialog()
{
    // save value of "warning off" checkbox, if necessary
    SvtSaveOptions aSaveOpt;
    sal_Bool bChecked = m_aWarningOnBox.IsChecked();
    if ( aSaveOpt.IsWarnAlienFormat() != bChecked )
        aSaveOpt.SetWarnAlienFormat( bChecked );
}

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

void SfxAlienWarningDialog::InitSize()
{
    // if the button text is too wide, then broaden the button
    long nTxtW = m_aMoreInfoBtn.GetCtrlTextWidth( m_aMoreInfoBtn.GetText() );
    long nCtrlW = m_aMoreInfoBtn.GetSizePixel().Width();
    if ( nTxtW >= nCtrlW )
    {
        long nDelta = nTxtW - nCtrlW;
        nDelta += IMPL_EXTRA_BUTTON_WIDTH;
        Point aNextPoint = m_aKeepCurrentBtn.GetPosPixel();
        aNextPoint.X() += m_aKeepCurrentBtn.GetSizePixel().Width();
        Point aNewPoint = m_aMoreInfoBtn.GetPosPixel();
        aNewPoint.X() -= nDelta;
        if ( aNextPoint.X() >= aNewPoint.X() )
        {
            long nSpace = aNextPoint.X() - aNewPoint.X();
            nSpace += 2;
            nDelta -= nSpace;
            aNewPoint.X() += nSpace;
        }
        Size aNewSize = m_aMoreInfoBtn.GetSizePixel();
        aNewSize.Width() += nDelta;
        m_aMoreInfoBtn.SetPosSizePixel( aNewPoint, aNewSize );
    }

    // text of checkbox to wide -> add new line
    nTxtW = m_aWarningOnBox.GetCtrlTextWidth( m_aWarningOnBox.GetText() ) + IMPL_EXTRA_BUTTON_WIDTH;
    nCtrlW = m_aWarningOnBox.GetSizePixel().Width();
    if ( nTxtW >= nCtrlW )
    {
        long nTextHeight = m_aWarningOnBox.GetTextHeight();
        Size aNewSize = m_aWarningOnBox.GetSizePixel();
        aNewSize.Height() += nTextHeight;
        m_aWarningOnBox.SetSizePixel( aNewSize );
        aNewSize = GetSizePixel();
        aNewSize.Height() += nTextHeight;
        SetSizePixel( aNewSize );
    }

    // align the size of the information text control (FixedText) to its content
    Size aMinSize = m_aInfoText.CalcMinimumSize( m_aInfoText.GetSizePixel().Width() );
    long nTxtH = aMinSize.Height();
    long nCtrlH = m_aInfoText.GetSizePixel().Height();
    long nDelta = ( nCtrlH - nTxtH );
    Size aNewSize = m_aInfoText.GetSizePixel();
    aNewSize.Height() -= nDelta;
    m_aInfoText.SetSizePixel( aNewSize );

    // new position for the succeeding windows
    Window* pWins[] =
    {
        &m_aSaveODFBtn, &m_aKeepCurrentBtn, &m_aMoreInfoBtn, &m_aOptionLine, &m_aWarningOnBox
    };
    Window** pCurrent = pWins;
    for ( sal_uInt32 i = 0; i < sizeof( pWins ) / sizeof( pWins[ 0 ] ); ++i, ++pCurrent )
    {
        Point aNewPos = (*pCurrent)->GetPosPixel();
        aNewPos.Y() -= nDelta;
        (*pCurrent)->SetPosPixel( aNewPos );
    }

    // new size of the dialog
    aNewSize = GetSizePixel();
    aNewSize.Height() -= nDelta;
    SetSizePixel( aNewSize );

    // recalculate the size and position of the buttons
    m_aMoreInfoBtn.Hide();
    nTxtW = m_aKeepCurrentBtn.GetCtrlTextWidth( m_aKeepCurrentBtn.GetText() );
    long nTemp = m_aSaveODFBtn.GetCtrlTextWidth( m_aSaveODFBtn.GetText() );
    if ( nTemp > nTxtW )
        nTxtW = nTemp;
    nTxtW += IMPL_EXTRA_BUTTON_WIDTH;
    Size a3Size = LogicToPixel( Size( 3, 3 ), MAP_APPFONT );
    Point aPos = m_aKeepCurrentBtn.GetPosPixel();
    aPos.X() = ( aNewSize.Width() - (2*nTxtW) - a3Size.Width() ) / 2;
    long nDefX = m_aWarningOnBox.GetPosPixel().X();
    if ( nDefX < aPos.X() )
        aPos.X() = nDefX;
    aNewSize = m_aKeepCurrentBtn.GetSizePixel();
    aNewSize.Width() = nTxtW;
    m_aKeepCurrentBtn.SetPosSizePixel( aPos, aNewSize );
    aPos.X() += nTxtW + a3Size.Width();
    m_aSaveODFBtn.SetPosSizePixel( aPos, aNewSize );
}

<|endoftext|>


<commit_before>/*
Copyright (c) 2017, Vadim Malyshev, lboss75@gmail.com
All rights reserved
*/
#include "stdafx.h"
#include "tcp_network_socket.h"
#include "service_provider.h"
#include "mt_service.h"
#include "network_service.h"
#include "logger.h"
#include "file.h"
#include "barrier.h"
#include "tcp_socket_server.h"
#include "random_buffer.h"
#include "random_stream.h"
#include "compare_data.h"
#include "test_config.h"
#include "task_manager.h"

TEST(network_tests, test_server)
{
    vds::service_registrator registrator;

    vds::mt_service mt_service;
    vds::task_manager task_manager;
    vds::network_service network_service;
    vds::file_logger file_logger(
        test_config::instance().log_level(),
        test_config::instance().modules());

    registrator.add(file_logger);
    registrator.add(task_manager);
    registrator.add(mt_service);
    registrator.add(network_service);

    vds::barrier done;

    auto sp = registrator.build("network_tests::test_server");
    registrator.start(sp);

    vds::imt_service::enable_async(sp);

    std::shared_ptr<std::exception> error;
    vds::barrier b;
    vds::tcp_socket_server server;
    server.start(
        sp,
        "127.0.0.1",
        8000,
    [&error](const vds::service_provider & sp, const vds::tcp_network_socket & s) {
        vds::copy_stream<uint8_t>(sp, s.incoming(), s.outgoing())
        .execute(
        [s, sp, &error](const std::shared_ptr<std::exception> & ex) {
            if(!ex) {
                sp.get<vds::logger>()->debug("TCP", sp, "Server closed");
            } else {
                error = ex;
            }
        });
    }).execute(
    [&b, sp, &error](const std::shared_ptr<std::exception> & ex) {
        if(!ex) {
            sp.get<vds::logger>()->debug("TCP", sp, "Server has been started");
            b.set();
        } else {
            error = ex;
            b.set();
        }
    });

    b.wait();

    if (error) {
        registrator.shutdown(sp);
        GTEST_FAIL() << error->what();
    }

    b.reset();

    std::string answer;
    random_buffer data;

    vds::tcp_network_socket::connect(
        sp,
        (const char *)"127.0.0.1",
        8000)
    .then(
        [&b, &answer, &data, sp](
    const vds::tcp_network_socket & s) {

        sp.get<vds::logger>()->debug("TCP", sp, "Connected");

        auto rs = std::make_shared<random_stream_async<uint8_t>>(*s.outgoing());
        auto cd = std::make_shared<compare_data<uint8_t>>(data.data(), data.size());

        return vds::async_series(
                   rs->write_async(sp, data.data(), data.size())
        .then([rs, sp]() {
            return rs->write_async(sp, nullptr, 0);
        }),
        vds::copy_stream(
            sp,
            s.incoming(),
            std::static_pointer_cast<vds::stream_async<uint8_t>>(cd)));
    }).execute(
    [&b, sp, &error](const std::shared_ptr<std::exception> & ex) {
        if(!ex) {
            sp.get<vds::logger>()->debug("TCP", sp, "Request sent");
            b.set();
        } else {
            error = ex;
            sp.get<vds::logger>()->debug("TCP", sp, "Request error");
            b.set();
        }
    });

    b.wait();
    //Wait
    registrator.shutdown(sp);

    if (error) {
        GTEST_FAIL() << error->what();
    }
}
<commit_msg>fix compilation on windows<commit_after>/*
Copyright (c) 2017, Vadim Malyshev, lboss75@gmail.com
All rights reserved
*/
#include "stdafx.h"
#include "tcp_network_socket.h"
#include "service_provider.h"
#include "mt_service.h"
#include "network_service.h"
#include "logger.h"
#include "file.h"
#include "barrier.h"
#include "tcp_socket_server.h"
#include "random_buffer.h"
#include "random_stream.h"
#include "compare_data.h"
#include "test_config.h"
#include "task_manager.h"

class echo_stream : public vds::stream<uint8_t> {
public:
  echo_stream(const vds::tcp_network_socket & s)
    : vds::stream<uint8_t>(new _echo_stream(s)) {
  }

private:
  class _echo_stream : public vds::_stream<uint8_t> {
  public:
    _echo_stream(const vds::tcp_network_socket & s)
      : s_(s) {
    }

    void write(
      const uint8_t *data,
      size_t len) override {
      this->s_.write_async(data, len).wait();
    }

  private:
    vds::tcp_network_socket s_;
  };
};

TEST(network_tests, test_server)
{
    vds::service_registrator registrator;

    vds::mt_service mt_service;
    vds::task_manager task_manager;
    vds::network_service network_service;
    vds::file_logger file_logger(
        test_config::instance().log_level(),
        test_config::instance().modules());

    registrator.add(file_logger);
    registrator.add(task_manager);
    registrator.add(mt_service);
    registrator.add(network_service);

    vds::barrier done;

    auto sp = registrator.build("network_tests::test_server");
    registrator.start(sp);

    vds::imt_service::enable_async(sp);

    std::shared_ptr<std::exception> error;
    vds::barrier b;
    vds::tcp_socket_server server;
    server.start(
        sp,
        vds::network_address::any_ip4(8000),
      [sp](vds::tcp_network_socket s) {
      s.start(sp, echo_stream(s));
    }).execute(
    [&b, sp, &error](const std::shared_ptr<std::exception> & ex) {
        if(!ex) {
            sp.get<vds::logger>()->debug("TCP", sp, "Server has been started");
            b.set();
        } else {
            error = ex;
            b.set();
        }
    });

    b.wait();

    if (error) {
        registrator.shutdown(sp);
        GTEST_FAIL() << error->what();
    }

    b.reset();

    std::string answer;
    random_buffer data;

    vds::tcp_network_socket::connect(
        sp,
      vds::network_address::any_ip4(8000))
    .then(
        [&b, &answer, &data, sp](
    const vds::tcp_network_socket & s) {

        sp.get<vds::logger>()->debug("TCP", sp, "Connected");

        auto rs = std::make_shared<random_stream_async<uint8_t>>(*s.outgoing());
        auto cd = std::make_shared<compare_data<uint8_t>>(data.data(), data.size());

        return vds::async_series(
                   rs->write_async(sp, data.data(), data.size())
        .then([rs, sp]() {
            return rs->write_async(sp, nullptr, 0);
        }),
        vds::copy_stream(
            sp,
            s.incoming(),
            std::static_pointer_cast<vds::stream_async<uint8_t>>(cd)));
    }).execute(
    [&b, sp, &error](const std::shared_ptr<std::exception> & ex) {
        if(!ex) {
            sp.get<vds::logger>()->debug("TCP", sp, "Request sent");
            b.set();
        } else {
            error = ex;
            sp.get<vds::logger>()->debug("TCP", sp, "Request error");
            b.set();
        }
    });

    b.wait();
    //Wait
    registrator.shutdown(sp);

    if (error) {
        GTEST_FAIL() << error->what();
    }
}
<|endoftext|>


<commit_before>#include "mixture.hpp"
#include "normal.hpp"
#include "laplace.hpp"

#include <gtest/gtest.h>

#include <boost/random/mersenne_twister.hpp>

using namespace MultidimensionalArray;
using namespace ProbabilityDistributions;

TEST(MixtureTest, Likelihood) {
  boost::random::mt19937 rng;
  const unsigned int n_samples = 100;
  Normal<double> dist1(-10, 1);
  Normal<double> dist2(10, 1);
  auto dist = make_mixture(dist1, dist2);
  Array<double> samples;
  dist.sample(samples, n_samples, rng);

  double likelihood1 = dist.log_likelihood(samples);
  (void)likelihood1;

  dist.get_component<0>().set_mean(-0.1);
  dist.get_component<1>().set_mean(0.1);

  auto new_dist = make_mixture(Laplace<double>(-0.1, 1),
      Laplace<double>(0.1, 1));

  dist.MLE(samples);
  new_dist.MLE(samples);

  double likelihood2 = dist.log_likelihood(samples);
  double new_likelihood = new_dist.log_likelihood(samples);

  EXPECT_GE(likelihood2, likelihood1);
  EXPECT_GE(likelihood2, new_likelihood);
}

TEST(MixtureTest, Samples) {
  boost::random::mt19937 rng;
  const unsigned int n_samples = 100;
  Normal<double> dist1(-10, 1);
  Normal<double> dist2(10, 1);
  auto dist = make_mixture(dist1, dist2);
  Array<double> samples;
  dist.sample(samples, n_samples, rng);
  unsigned int count_0 = 0, count_1 = 0;

  for (size_t i = 0; i < n_samples; i++) {
    if (samples(i,0) < 0) {
      EXPECT_LT(-15, samples(i,0));
      EXPECT_GT(-5, samples(i,0));
      count_0++;
    }
    else {
      EXPECT_LT(5, samples(i,0));
      EXPECT_GT(15, samples(i,0));
      count_1++;
    }
  }

  EXPECT_LT(0, count_0);
  EXPECT_LT(0, count_1);
}
<commit_msg>Added test to mixture of asymmetric distributions.<commit_after>#include "asymmetric_laplace.hpp"
#include "asymmetric_normal.hpp"
#include "mixture.hpp"
#include "normal.hpp"
#include "laplace.hpp"

#include <gtest/gtest.h>

#include <boost/random/mersenne_twister.hpp>

using namespace MultidimensionalArray;
using namespace ProbabilityDistributions;

TEST(MixtureTest, LikelihoodNormal) {
  boost::random::mt19937 rng;
  const unsigned int n_samples = 100;
  Normal<double> dist1(-10, 1);
  Normal<double> dist2(10, 1);
  AsymmetricNormal<double> dist3(0.5, -10, 1);
  AsymmetricNormal<double> dist4(0.5, 10, 1);
  dist3.fix_p(true);
  dist4.fix_p(true);
  auto dist = make_mixture(dist1, dist2);
  auto dist_a = make_mixture(dist3, dist4);
  Array<double> samples;
  dist.sample(samples, n_samples, rng);

  double likelihood1 = dist.log_likelihood(samples);
  double likelihood1_a = dist_a.log_likelihood(samples);
  EXPECT_DOUBLE_EQ(likelihood1, likelihood1_a);

  dist.get_component<0>().set_mean(-0.1);
  dist.get_component<1>().set_mean(0.1);
  dist_a.get_component<0>().set_mu(-0.1);
  dist_a.get_component<1>().set_mu(0.1);

  auto new_dist = make_mixture(Laplace<double>(-0.1, 1),
      Laplace<double>(0.1, 1));

  dist.MLE(samples);
  dist_a.MLE(samples);
  new_dist.MLE(samples);

  double likelihood2 = dist.log_likelihood(samples);
  double likelihood2_a = dist_a.log_likelihood(samples);
  double new_likelihood = new_dist.log_likelihood(samples);

  EXPECT_DOUBLE_EQ(likelihood2, likelihood2_a);
  EXPECT_GE(likelihood2, likelihood1);
  EXPECT_GE(likelihood2, new_likelihood);
}

TEST(MixtureTest, LikelihoodLaplace) {
  boost::random::mt19937 rng;
  const unsigned int n_samples = 100;
  Laplace<double> dist1(-10, 1);
  Laplace<double> dist2(10, 1);
  AsymmetricLaplace<double> dist3(0.5, -10, 1);
  AsymmetricLaplace<double> dist4(0.5, 10, 1);
  dist3.fix_p(true);
  dist4.fix_p(true);
  auto dist = make_mixture(dist1, dist2);
  auto dist_a = make_mixture(dist3, dist4);
  Array<double> samples;
  dist.sample(samples, n_samples, rng);

  double likelihood1 = dist.log_likelihood(samples);
  double likelihood1_a = dist_a.log_likelihood(samples);
  EXPECT_DOUBLE_EQ(likelihood1, likelihood1_a);

  dist.get_component<0>().set_mu(-0.1);
  dist.get_component<1>().set_mu(0.1);
  dist_a.get_component<0>().set_mu(-0.1);
  dist_a.get_component<1>().set_mu(0.1);

  auto new_dist = make_mixture(Laplace<double>(-0.1, 1),
      Laplace<double>(0.1, 1));

  dist.MLE(samples);
  dist_a.MLE(samples);
  new_dist.MLE(samples);

  double likelihood2 = dist.log_likelihood(samples);
  double likelihood2_a = dist_a.log_likelihood(samples);
  double new_likelihood = new_dist.log_likelihood(samples);

  EXPECT_DOUBLE_EQ(likelihood2, likelihood2_a);
  EXPECT_GE(likelihood2, likelihood1);
  EXPECT_GE(likelihood2, new_likelihood);
}

TEST(MixtureTest, LikelihoodAsymmetricNormal) {
  boost::random::mt19937 rng;
  const unsigned int n_samples = 100;
  AsymmetricNormal<double> dist1(0.5, -10, 1);
  AsymmetricNormal<double> dist2(0.5, 10, 1);
  auto dist = make_mixture(dist1, dist2);
  dist1.fix_p(true);
  dist2.fix_p(true);
  auto dist_a = make_mixture(dist1, dist2);
  Array<double> samples;
  dist.sample(samples, n_samples, rng);

  double likelihood1 = dist.log_likelihood(samples);
  double likelihood1_a = dist_a.log_likelihood(samples);
  EXPECT_DOUBLE_EQ(likelihood1, likelihood1_a);

  dist.get_component<0>().set_mu(-0.1);
  dist.get_component<1>().set_mu(0.1);
  dist_a.get_component<0>().set_mu(-0.1);
  dist_a.get_component<1>().set_mu(0.1);

  auto new_dist = make_mixture(Laplace<double>(-0.1, 1),
      Laplace<double>(0.1, 1));

  dist.get_component<0>().fix_p(true);
  dist.get_component<1>().fix_p(true);
  dist.MLE(samples);
  dist.get_component<0>().fix_p(false);
  dist.get_component<1>().fix_p(false);
  dist.MLE(samples);

  dist_a.MLE(samples);
  new_dist.MLE(samples);

  double likelihood2 = dist.log_likelihood(samples);
  double likelihood2_a = dist_a.log_likelihood(samples);
  double new_likelihood = new_dist.log_likelihood(samples);

  EXPECT_GE(likelihood2, likelihood2_a);
  EXPECT_GE(likelihood2, likelihood1);
  EXPECT_GE(likelihood2, new_likelihood);
}

TEST(MixtureTest, LikelihoodAsymmetricLaplace) {
  boost::random::mt19937 rng;
  const unsigned int n_samples = 100;
  AsymmetricLaplace<double> dist1(0.5, -10, 1);
  AsymmetricLaplace<double> dist2(0.5, 10, 1);
  auto dist = make_mixture(dist1, dist2);
  dist1.fix_p(true);
  dist2.fix_p(true);
  auto dist_a = make_mixture(dist1, dist2);
  Array<double> samples;
  dist.sample(samples, n_samples, rng);

  double likelihood1 = dist.log_likelihood(samples);
  double likelihood1_a = dist_a.log_likelihood(samples);
  EXPECT_DOUBLE_EQ(likelihood1, likelihood1_a);

  dist.get_component<0>().set_mu(-0.1);
  dist.get_component<1>().set_mu(0.1);
  dist_a.get_component<0>().set_mu(-0.1);
  dist_a.get_component<1>().set_mu(0.1);

  auto new_dist = make_mixture(Normal<double>(-0.1, 1),
      Normal<double>(0.1, 1));

  dist.get_component<0>().fix_p(true);
  dist.get_component<1>().fix_p(true);
  dist.MLE(samples);
  dist.get_component<0>().fix_p(false);
  dist.get_component<1>().fix_p(false);
  dist.MLE(samples);

  dist_a.MLE(samples);
  new_dist.MLE(samples);

  double likelihood2 = dist.log_likelihood(samples);
  double likelihood2_a = dist_a.log_likelihood(samples);
  double new_likelihood = new_dist.log_likelihood(samples);

  EXPECT_GE(likelihood2, likelihood2_a);
  EXPECT_GE(likelihood2, likelihood1);
  EXPECT_GE(likelihood2, new_likelihood);
}

TEST(MixtureTest, Samples) {
  boost::random::mt19937 rng;
  const unsigned int n_samples = 100;
  Normal<double> dist1(-10, 1);
  Normal<double> dist2(10, 1);
  auto dist = make_mixture(dist1, dist2);
  Array<double> samples;
  dist.sample(samples, n_samples, rng);
  unsigned int count_0 = 0, count_1 = 0;

  for (size_t i = 0; i < n_samples; i++) {
    if (samples(i,0) < 0) {
      EXPECT_LT(-15, samples(i,0));
      EXPECT_GT(-5, samples(i,0));
      count_0++;
    }
    else {
      EXPECT_LT(5, samples(i,0));
      EXPECT_GT(15, samples(i,0));
      count_1++;
    }
  }

  EXPECT_LT(0, count_0);
  EXPECT_LT(0, count_1);
}
<|endoftext|>