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

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

#ifndef _SC_XMLTABLESHAPEIMPORTHELPER_HXX
#include "XMLTableShapeImportHelper.hxx"
#endif

#ifndef SC_XMLIMPRT_HXX
#include "xmlimprt.hxx"
#endif
#ifndef _SC_XMLCONVERTER_HXX
#include "XMLConverter.hxx"
#endif
#ifndef SC_DRWLAYER_HXX
#include "drwlayer.hxx"
#endif
#ifndef SC_XMLANNOI_HXX
#include "xmlannoi.hxx"
#endif

#ifndef _XMLOFF_NMSPMAP_HXX
#include <xmloff/nmspmap.hxx>
#endif
#ifndef _XMLOFF_XMLNMSPE_HXX
#include <xmloff/xmlnmspe.hxx>
#endif
#ifndef _XMLOFF_XMLUCONV_HXX
#include <xmloff/xmluconv.hxx>
#endif
#ifndef _XMLOFF_XMLTOKEN_HXX
#include <xmloff/xmltoken.hxx>
#endif

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

#ifndef _COM_SUN_STAR_DRAWING_XSHAPE_HPP_
#include <com/sun/star/drawing/XShape.hpp>
#endif
#ifndef _COM_SUN_STAR_DRAWING_XSHAPES_HPP_
#include <com/sun/star/drawing/XShapes.hpp>
#endif

#define SC_LAYERID "LayerID"

using namespace ::com::sun::star;
using namespace xmloff::token;

XMLTableShapeImportHelper::XMLTableShapeImportHelper(
        ScXMLImport& rImp, SvXMLImportPropertyMapper *pImpMapper ) :
    XMLShapeImportHelper(rImp, rImp.GetModel(), pImpMapper ),
    pAnnotationContext(NULL),
    bOnTable(sal_False)
{
}

XMLTableShapeImportHelper::~XMLTableShapeImportHelper()
{
}

void XMLTableShapeImportHelper::SetLayer(uno::Reference<drawing::XShape>& rShape, sal_Int16 nLayerID, const rtl::OUString& sType) const
{
    if (sType.equals(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ControlShape"))))
        nLayerID = SC_LAYER_CONTROLS;
    if (nLayerID != -1)
    {
        uno::Reference< beans::XPropertySet > xShapeProp( rShape, uno::UNO_QUERY );
        if( xShapeProp.is() )
            xShapeProp->setPropertyValue(OUString( RTL_CONSTASCII_USTRINGPARAM( SC_LAYERID ) ), uno::makeAny(nLayerID) );
    }
}

void XMLTableShapeImportHelper::finishShape(
    uno::Reference< drawing::XShape >& rShape,
    const uno::Reference< xml::sax::XAttributeList >& xAttrList,
    uno::Reference< drawing::XShapes >& rShapes )
{
    XMLShapeImportHelper::finishShape( rShape, xAttrList, rShapes );
    static_cast<ScXMLImport&>(mrImporter).LockSolarMutex();
    if (rShapes == static_cast<ScXMLImport&>(mrImporter).GetTables().GetCurrentXShapes())
    {
        if (!pAnnotationContext)
        {
            sal_Int32 nEndX(-1);
            sal_Int32 nEndY(-1);
            sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
            table::CellAddress aEndCell;
            rtl::OUString* pRangeList(NULL);
            sal_Int16 nLayerID(-1);
            for( sal_Int16 i=0; i < nAttrCount; ++i )
            {
                const rtl::OUString& rAttrName(xAttrList->getNameByIndex( i ));
                const rtl::OUString& rValue(xAttrList->getValueByIndex( i ));

                rtl::OUString aLocalName;
                sal_uInt16 nPrefix(
                    static_cast<ScXMLImport&>(mrImporter).GetNamespaceMap().GetKeyByAttrName( rAttrName,
                                                                    &aLocalName ));
                if(nPrefix == XML_NAMESPACE_TABLE)
                {
                    if (IsXMLToken(aLocalName, XML_END_CELL_ADDRESS))
                    {
                        sal_Int32 nOffset(0);
                        ScXMLConverter::GetAddressFromString(aEndCell, rValue, static_cast<ScXMLImport&>(mrImporter).GetDocument(), nOffset);
                    }
                    else if (IsXMLToken(aLocalName, XML_END_X))
                        static_cast<ScXMLImport&>(mrImporter).GetMM100UnitConverter().convertMeasure(nEndX, rValue);
                    else if (IsXMLToken(aLocalName, XML_END_Y))
                        static_cast<ScXMLImport&>(mrImporter).GetMM100UnitConverter().convertMeasure(nEndY, rValue);
                    else if (IsXMLToken(aLocalName, XML_TABLE_BACKGROUND))
                        if (IsXMLToken(rValue, XML_TRUE))
                            nLayerID = SC_LAYER_BACK;
                }
                else if(nPrefix == XML_NAMESPACE_DRAW)
                {
                    if (IsXMLToken(aLocalName, XML_NOTIFY_ON_UPDATE_OF_RANGES))
                        pRangeList = new rtl::OUString(rValue);
                }
            }
            SetLayer(rShape, nLayerID, rShape->getShapeType());

            if (!bOnTable)
            {
                static_cast<ScXMLImport&>(mrImporter).GetTables().AddShape(rShape,
                    pRangeList, aStartCell, aEndCell, nEndX, nEndY);
                SvxShape* pShapeImp = SvxShape::getImplementation(rShape);
                if (pShapeImp)
                {
                    SdrObject *pSdrObj = pShapeImp->GetSdrObject();
                    if (pSdrObj)
                        ScDrawLayer::SetAnchor(pSdrObj, SCA_CELL);
                }
            }
            else
            {
                SvxShape* pShapeImp = SvxShape::getImplementation(rShape);
                if (pShapeImp)
                {
                    SdrObject *pSdrObj = pShapeImp->GetSdrObject();
                    if (pSdrObj)
                        ScDrawLayer::SetAnchor(pSdrObj, SCA_PAGE);
                }
            }
        }
        else // shape is annotation
        {
            pAnnotationContext->SetShape(rShape, rShapes);
        }
    }
    else //#99532# this are grouped shapes which should also get the layerid
    {
        sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
        sal_Int16 nLayerID(-1);
        for( sal_Int16 i=0; i < nAttrCount; ++i )
        {
            const rtl::OUString& rAttrName(xAttrList->getNameByIndex( i ));
            const rtl::OUString& rValue(xAttrList->getValueByIndex( i ));

            rtl::OUString aLocalName;
            sal_uInt16 nPrefix(static_cast<ScXMLImport&>(mrImporter).GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName ));
            if(nPrefix == XML_NAMESPACE_TABLE)
            {
                if (IsXMLToken(aLocalName, XML_TABLE_BACKGROUND))
                    if (IsXMLToken(rValue, XML_TRUE))
                        nLayerID = SC_LAYER_BACK;
            }
        }
        SetLayer(rShape, nLayerID, rShape->getShapeType());
    }
    static_cast<ScXMLImport&>(mrImporter).UnlockSolarMutex();
}
<commit_msg>INTEGRATION: CWS chart2mst3 (1.22.82); FILE MERGED 2007/04/25 03:07:04 bm 1.22.82.5: RESYNC: (1.25-1.26); FILE MERGED 2006/10/18 23:53:19 bm 1.22.82.4: RESYNC: (1.24-1.25); FILE MERGED 2005/10/08 08:59:49 bm 1.22.82.3: RESYNC: (1.23-1.24); FILE MERGED 2005/05/17 12:47:03 bm 1.22.82.2: RESYNC: (1.22-1.23); FILE MERGED 2005/05/12 19:56:34 sab 1.22.82.1: move range to string and string to range converter methods to rangeutil<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: XMLTableShapeImportHelper.cxx,v $
 *
 *  $Revision: 1.27 $
 *
 *  last change: $Author: vg $ $Date: 2007-05-22 20:03:11 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

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

#ifndef _SC_XMLTABLESHAPEIMPORTHELPER_HXX
#include "XMLTableShapeImportHelper.hxx"
#endif

#ifndef SC_XMLIMPRT_HXX
#include "xmlimprt.hxx"
#endif
#ifndef _SC_XMLCONVERTER_HXX
#include "XMLConverter.hxx"
#endif
#ifndef SC_DRWLAYER_HXX
#include "drwlayer.hxx"
#endif
#ifndef SC_XMLANNOI_HXX
#include "xmlannoi.hxx"
#endif
#ifndef SC_RANGEUTL_HXX
#include "rangeutl.hxx"
#endif

#ifndef _XMLOFF_NMSPMAP_HXX
#include <xmloff/nmspmap.hxx>
#endif
#ifndef _XMLOFF_XMLNMSPE_HXX
#include <xmloff/xmlnmspe.hxx>
#endif
#ifndef _XMLOFF_XMLUCONV_HXX
#include <xmloff/xmluconv.hxx>
#endif
#ifndef _XMLOFF_XMLTOKEN_HXX
#include <xmloff/xmltoken.hxx>
#endif

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

#ifndef _COM_SUN_STAR_DRAWING_XSHAPE_HPP_
#include <com/sun/star/drawing/XShape.hpp>
#endif
#ifndef _COM_SUN_STAR_DRAWING_XSHAPES_HPP_
#include <com/sun/star/drawing/XShapes.hpp>
#endif

#define SC_LAYERID "LayerID"

using namespace ::com::sun::star;
using namespace xmloff::token;

XMLTableShapeImportHelper::XMLTableShapeImportHelper(
        ScXMLImport& rImp, SvXMLImportPropertyMapper *pImpMapper ) :
    XMLShapeImportHelper(rImp, rImp.GetModel(), pImpMapper ),
    pAnnotationContext(NULL),
    bOnTable(sal_False)
{
}

XMLTableShapeImportHelper::~XMLTableShapeImportHelper()
{
}

void XMLTableShapeImportHelper::SetLayer(uno::Reference<drawing::XShape>& rShape, sal_Int16 nLayerID, const rtl::OUString& sType) const
{
    if (sType.equals(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ControlShape"))))
        nLayerID = SC_LAYER_CONTROLS;
    if (nLayerID != -1)
    {
        uno::Reference< beans::XPropertySet > xShapeProp( rShape, uno::UNO_QUERY );
        if( xShapeProp.is() )
            xShapeProp->setPropertyValue(OUString( RTL_CONSTASCII_USTRINGPARAM( SC_LAYERID ) ), uno::makeAny(nLayerID) );
    }
}

void XMLTableShapeImportHelper::finishShape(
    uno::Reference< drawing::XShape >& rShape,
    const uno::Reference< xml::sax::XAttributeList >& xAttrList,
    uno::Reference< drawing::XShapes >& rShapes )
{
    XMLShapeImportHelper::finishShape( rShape, xAttrList, rShapes );
    static_cast<ScXMLImport&>(mrImporter).LockSolarMutex();
    if (rShapes == static_cast<ScXMLImport&>(mrImporter).GetTables().GetCurrentXShapes())
    {
        if (!pAnnotationContext)
        {
            sal_Int32 nEndX(-1);
            sal_Int32 nEndY(-1);
            sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
            table::CellAddress aEndCell;
            rtl::OUString* pRangeList(NULL);
            sal_Int16 nLayerID(-1);
            for( sal_Int16 i=0; i < nAttrCount; ++i )
            {
                const rtl::OUString& rAttrName(xAttrList->getNameByIndex( i ));
                const rtl::OUString& rValue(xAttrList->getValueByIndex( i ));

                rtl::OUString aLocalName;
                sal_uInt16 nPrefix(
                    static_cast<ScXMLImport&>(mrImporter).GetNamespaceMap().GetKeyByAttrName( rAttrName,
                                                                    &aLocalName ));
                if(nPrefix == XML_NAMESPACE_TABLE)
                {
                    if (IsXMLToken(aLocalName, XML_END_CELL_ADDRESS))
                    {
                        sal_Int32 nOffset(0);
                        ScRangeStringConverter::GetAddressFromString(aEndCell, rValue, static_cast<ScXMLImport&>(mrImporter).GetDocument(), nOffset);
                    }
                    else if (IsXMLToken(aLocalName, XML_END_X))
                        static_cast<ScXMLImport&>(mrImporter).GetMM100UnitConverter().convertMeasure(nEndX, rValue);
                    else if (IsXMLToken(aLocalName, XML_END_Y))
                        static_cast<ScXMLImport&>(mrImporter).GetMM100UnitConverter().convertMeasure(nEndY, rValue);
                    else if (IsXMLToken(aLocalName, XML_TABLE_BACKGROUND))
                        if (IsXMLToken(rValue, XML_TRUE))
                            nLayerID = SC_LAYER_BACK;
                }
                else if(nPrefix == XML_NAMESPACE_DRAW)
                {
                    if (IsXMLToken(aLocalName, XML_NOTIFY_ON_UPDATE_OF_RANGES))
                        pRangeList = new rtl::OUString(rValue);
                }
            }
            SetLayer(rShape, nLayerID, rShape->getShapeType());

            if (!bOnTable)
            {
                static_cast<ScXMLImport&>(mrImporter).GetTables().AddShape(rShape,
                    pRangeList, aStartCell, aEndCell, nEndX, nEndY);
                SvxShape* pShapeImp = SvxShape::getImplementation(rShape);
                if (pShapeImp)
                {
                    SdrObject *pSdrObj = pShapeImp->GetSdrObject();
                    if (pSdrObj)
                        ScDrawLayer::SetAnchor(pSdrObj, SCA_CELL);
                }
            }
            else
            {
                SvxShape* pShapeImp = SvxShape::getImplementation(rShape);
                if (pShapeImp)
                {
                    SdrObject *pSdrObj = pShapeImp->GetSdrObject();
                    if (pSdrObj)
                        ScDrawLayer::SetAnchor(pSdrObj, SCA_PAGE);
                }
            }
        }
        else // shape is annotation
        {
            pAnnotationContext->SetShape(rShape, rShapes);
        }
    }
    else //#99532# this are grouped shapes which should also get the layerid
    {
        sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
        sal_Int16 nLayerID(-1);
        for( sal_Int16 i=0; i < nAttrCount; ++i )
        {
            const rtl::OUString& rAttrName(xAttrList->getNameByIndex( i ));
            const rtl::OUString& rValue(xAttrList->getValueByIndex( i ));

            rtl::OUString aLocalName;
            sal_uInt16 nPrefix(static_cast<ScXMLImport&>(mrImporter).GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName ));
            if(nPrefix == XML_NAMESPACE_TABLE)
            {
                if (IsXMLToken(aLocalName, XML_TABLE_BACKGROUND))
                    if (IsXMLToken(rValue, XML_TRUE))
                        nLayerID = SC_LAYER_BACK;
            }
        }
        SetLayer(rShape, nLayerID, rShape->getShapeType());
    }
    static_cast<ScXMLImport&>(mrImporter).UnlockSolarMutex();
}
<|endoftext|>


<commit_before><commit_msg>-Werror,-Wunused-private-field (Clang towards 3.2)<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: svdview.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: rt $ $Date: 2007-07-06 13:18:53 $
 *
 *  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 _SVDVIEW_HXX
#define _SVDVIEW_HXX

// HACK to avoid too deep includes and to have some
// levels free in svdmark itself (MS compiler include depth limit)
#ifndef _SVDHDL_HXX
#include <svx/svdhdl.hxx>
#endif

#ifndef _TOOLS_WEAKBASE_HXX_
#include <tools/weakbase.hxx>
#endif

#ifndef INCLUDED_SVTOOLS_ACCESSIBILITYOPTIONS_HXX
#include <svtools/accessibilityoptions.hxx>
#endif

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

#ifndef _SVDCRTV_HXX
#include <svx/svdcrtv.hxx>
#endif

////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Klassenhierarchie der View:
//         SfxListener
//         SdrPaintView    PntV   Action            ModChg   Attr   Notify
//         SdrSnapView     SnpV   Action
//
//         SdrMarkView     MrkV   Action   MrkChg   ModChg          Notify
//
//         SdrEditView     EdtV            MrkChg   ModChg   Attr
//         SdrPolyEditView PoEV
//         SdrGlueEditView GlEV
//         SdrObjEditView  EdxV   Action            ModChg   Attr   Notify
//
//         SdrExchangeView XcgV
//         SdrDragView     DrgV   Action
//
//         SdrCreateView   CrtV   Action
//         SdrView         View
//
////////////////////////////////////////////////////////////////////////////////////////////////////

//************************************************************
//   Vorausdeklarationen
//************************************************************

class SvxURLField;

//************************************************************
//   Defines
//************************************************************

enum SdrViewContext {SDRCONTEXT_STANDARD,
                     SDRCONTEXT_POINTEDIT,
                     SDRCONTEXT_GLUEPOINTEDIT,
                     SDRCONTEXT_TEXTEDIT,
                     SDRCONTEXT_GRAPHIC,
                     SDRCONTEXT_MEDIA};

enum SdrEventKind  {SDREVENT_NONE,
                    SDREVENT_TEXTEDIT,
                    SDREVENT_MOVACTION,
                    SDREVENT_ENDACTION,
                    SDREVENT_BCKACTION,
                    SDREVENT_BRKACTION,
                    SDREVENT_ENDCREATE,
                    SDREVENT_ENDDRAG,
                    SDREVENT_MARKOBJ,
                    SDREVENT_MARKPOINT,
                    SDREVENT_MARKGLUEPOINT,
                    SDREVENT_BEGMARK,
                    SDREVENT_BEGINSOBJPOINT,
                    SDREVENT_ENDINSOBJPOINT,
                    SDREVENT_BEGINSGLUEPOINT,
                    SDREVENT_BEGDRAGHELPLINE,
                    SDREVENT_BEGDRAGOBJ,
                    SDREVENT_BEGCREATEOBJ,
                    SDREVENT_BEGMACROOBJ,
                    SDREVENT_BEGTEXTEDIT,
                    SDREVENT_ENDMARK,
                    SDREVENT_BRKMARK,
                    SDREVENT_EXECUTEURL};

#define SDRMOUSEBUTTONDOWN 1
#define SDRMOUSEMOVE       2
#define SDRMOUSEBUTTONUP   3

//************************************************************
//   Hilfsklasse SdrViewEvent
//************************************************************

struct SVX_DLLPUBLIC SdrViewEvent
{
    SdrHdl*                     pHdl;
    SdrObject*                  pObj;
    SdrObject*                  pRootObj;        // Dieses Markieren bei SdrBeginTextEdit
    SdrPageView*                pPV;
    const SvxURLField*          pURLField;

    Point                       aLogicPos;
    SdrHitKind                  eHit;
    SdrEventKind                eEvent;
    SdrHdlKind                  eHdlKind;
    SdrCreateCmd                eEndCreateCmd;   // auch fuer EndInsPoint

    UINT16                      nMouseClicks;
    UINT16                      nMouseMode;
    UINT16                      nMouseCode;
    UINT16                      nHlplIdx;
    UINT16                      nGlueId;

    unsigned                    bMouseDown : 1;
    unsigned                    bMouseUp : 1;
    unsigned                    bDoubleHdlSize : 1;  // Doppelte Handlegroesse wg. TextEdit
    unsigned                    bIsAction : 1;       // Action ist aktiv
    unsigned                    bIsTextEdit : 1;     // TextEdit laeuft zur Zeit
    unsigned                    bTextEditHit : 1;    // offene OutlinerView getroffen
    unsigned                    bAddMark : 1;
    unsigned                    bUnmark : 1;
    unsigned                    bPrevNextMark : 1;
    unsigned                    bMarkPrev : 1;
    unsigned                    bInsPointNewObj : 1;
    unsigned                    bDragWithCopy : 1;
    unsigned                    bCaptureMouse : 1;
    unsigned                    bReleaseMouse : 1;

public:
    SdrViewEvent();
    ~SdrViewEvent();

    // nEventKind ist SDRMOUSEBUTTONDOWN, SDRMOUSEMOVE oder SDRMOUSEBUTTONUP
    void SetMouseEvent(const MouseEvent& rMEvt, USHORT nEventKind);
};

////////////////////////////////////////////////////////////////////////////////////////////////////
// helper class for all D&D overlays

class SVX_DLLPUBLIC SdrDropMarkerOverlay
{
    // The OverlayObjects
    ::sdr::overlay::OverlayObjectList               maObjects;

    void ImplCreateOverlays(const SdrView& rView, const basegfx::B2DPolyPolygon& rPolyPolygon);

public:
    SdrDropMarkerOverlay(const SdrView& rView, const SdrObject& rObject);
    SdrDropMarkerOverlay(const SdrView& rView, const Rectangle& rRectangle);
    SdrDropMarkerOverlay(const SdrView& rView, const Point& rStart, const Point& rEnd);
    ~SdrDropMarkerOverlay();
};

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  @@ @@ @@ @@@@@ @@   @@
//  @@ @@ @@ @@    @@   @@
//  @@ @@ @@ @@    @@ @ @@
//  @@@@@ @@ @@@@  @@@@@@@
//   @@@  @@ @@    @@@@@@@
//   @@@  @@ @@    @@@ @@@
//    @   @@ @@@@@ @@   @@
//
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

class SVX_DLLPUBLIC SdrView: public SdrCreateView, public tools::WeakBase< SdrView >
{
    friend class                SdrPageView;

    unsigned                    bNoExtendedMouseDispatcher : 1;
    unsigned                    bNoExtendedKeyDispatcher : 1;
    unsigned                    bNoExtendedCommandDispatcher : 1;
    unsigned                    bTextEditOnObjectsWithoutTextIfTextTool : 1;
    unsigned                    mbMasterPagePaintCaching : 1;

protected:
    SvtAccessibilityOptions maAccessibilityOptions;

    virtual void SFX_NOTIFY(SfxBroadcaster& rBC, const TypeId& rBCType, const SfxHint& rHint, const TypeId& rHintType);

public:
    TYPEINFO();
    SdrView(SdrModel* pModel1, OutputDevice* pOut = 0L);
    virtual ~SdrView();

    // Default sind alle Dispatcher aktiviert. Will die App z.B. fuer
    // Sonderbehandlungen im MouseDispatcher eingreifen, so muss sie
    // den erweiterten MouseDispather mit unten stehender Methode deaktivieren
    // und selbst nachimplementieren. Beispiel fuer MouseButtonDown:
    //      SdrViewEvent aVEvt;
    //      SdrHitKind eHit=pSdrView->PickAnything(rMEvt,SDRMOUSEBUTTONDOWN,aVEvt);
    //      ... hier Applikationsspezifischer Eingriff ...
    //      pSdrView->DoMouseEvent(aVEvt);
    //      SetPointer(GetPreferedPointer(...))
    //      CaptureMouse(...)
    void EnableExtendedMouseEventDispatcher(BOOL bOn) { bNoExtendedMouseDispatcher = !bOn; }
    BOOL IsExtendedMouseEventDispatcherEnabled() const { return bNoExtendedMouseDispatcher; }

    void EnableExtendedKeyInputDispatcher(BOOL bOn) { bNoExtendedKeyDispatcher=!bOn; }
    BOOL IsExtendedKeyInputDispatcherEnabled() const { return bNoExtendedKeyDispatcher; }

    void EnableExtendedCommandEventDispatcher(BOOL bOn) { bNoExtendedCommandDispatcher=!bOn; }
    BOOL IsExtendedCommandEventDispatcherEnabled() const { return bNoExtendedCommandDispatcher; }

    void EnableTextEditOnObjectsWithoutTextIfTextTool(BOOL bOn) { bTextEditOnObjectsWithoutTextIfTextTool=bOn; }
    BOOL IsEnableTextEditOnObjectsWithoutTextIfTextToolEnabled() const { return bTextEditOnObjectsWithoutTextIfTextTool; }

    void SetMasterPagePaintCaching(sal_Bool bOn);
    sal_Bool IsMasterPagePaintCaching() const { return mbMasterPagePaintCaching; }

    BOOL KeyInput(const KeyEvent& rKEvt, Window* pWin);
    virtual BOOL MouseButtonDown(const MouseEvent& rMEvt, Window* pWin);
    virtual BOOL MouseButtonUp(const MouseEvent& rMEvt, Window* pWin);
    virtual BOOL MouseMove(const MouseEvent& rMEvt, Window* pWin);
    virtual BOOL Command(const CommandEvent& rCEvt, Window* pWin);

    BOOL SetAttributes(const SfxItemSet& rSet, BOOL bReplaceAll=FALSE) { return SdrCreateView::SetAttributes(rSet,bReplaceAll); }
    BOOL SetStyleSheet(SfxStyleSheet* pStyleSheet, BOOL bDontRemoveHardAttr=FALSE) { return SdrCreateView::SetStyleSheet(pStyleSheet,bDontRemoveHardAttr); }

    /* new interface src537 */
    BOOL GetAttributes(SfxItemSet& rTargetSet, BOOL bOnlyHardAttr=FALSE) const;

    SfxStyleSheet* GetStyleSheet() const;

    // unvollstaendige Implementation:
    // Das OutputDevice ist notwendig, damit ich die HandleSize ermitteln kann.
    // Bei NULL wird das 1. angemeldete Win verwendet.
    Pointer GetPreferedPointer(const Point& rMousePos, const OutputDevice* pOut, USHORT nModifier=0, BOOL bLeftDown=FALSE) const;
    SdrHitKind PickAnything(const MouseEvent& rMEvt, USHORT nMouseDownOrMoveOrUp, SdrViewEvent& rVEvt) const;
    SdrHitKind PickAnything(const Point& rLogicPos, SdrViewEvent& rVEvt) const;
    BOOL DoMouseEvent(const SdrViewEvent& rVEvt);
    virtual SdrViewContext GetContext() const;

    // Die Methoden beruecksichtigen den jeweiligen Kontex:
    // - Einfaches Zeichnen
    // - Punktbearbeitungs-Mode
    // - Klebepunkt-Editmode
    // - TextEdit
    // - ... to be continued
    BOOL IsMarkPossible() const;
    void MarkAll();
    void UnmarkAll();
    BOOL IsAllMarked() const;
    BOOL IsAllMarkPrevNextPossible() const; // das geht naemlich nicht bei TextEdit!
    BOOL MarkNext(BOOL bPrev=FALSE);
    BOOL MarkNext(const Point& rPnt, BOOL bPrev=FALSE);

    const Rectangle& GetMarkedRect() const;
    void SetMarkedRect(const Rectangle& rRect);

    virtual void DeleteMarked();
    BOOL IsDeleteMarkedPossible() const;
    BOOL IsDeletePossible() const { return IsDeleteMarkedPossible(); }

    // Markieren von Objekten, Polygonpunkten oder Klebepunkten (je nach View-
    // Kontext) durch Aufziehen eines Selektionsrahmens.
    //   bAddMark=TRUE: zur bestehenden Selektion hinzumarkieren (->Shift)
    //   bUnmark=TRUE: Bereits selektierte Objekte/Punkte/Klebepunkte die innerhalb
    //                 des aufgezogenen Rahmens liegen werden deselektiert.
    BOOL BegMark(const Point& rPnt, BOOL bAddMark=FALSE, BOOL bUnmark=FALSE);

    // Folgende Actions sind moeglich:
    //   - ObjectCreating
    //   - ObjectMarking
    //   - Object-specific dragging
    //   - General dragging
    // und mehr...
    String GetStatusText();

    SvtAccessibilityOptions& getAccessibilityOptions();

    virtual void onAccessibilityOptionsChanged();
};

#endif //_SVDVIEW_HXX

////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Die App macht sich zunaechst ein SdrModel.
// Anschliessend oeffnet sie ein Win und erzeugt dann eine SdrView.
// An der SdrView meldet sie dann mit der Methode ShowSdrPage() eine Seite an.
// Eine SdrView kann in beliebig vielen Fenstern gleichzeitig angezeigt werden.
// Intern:
// Eine SdrView kann beliebig viele Seiten gleichzeitig anzeigen. Seiten
// werden an- und abgemeldet mit ShowSdrPage()/HideSdrPage(). Fuer jede angemeldete
// Seite wird eine SdrPageView-Instanz im Container aPages angelegt. Bei
// gleichzeitiger Anzeige mehrerer Seiten ist darauf zu achten, dass der Offset-
// Parameter von ShowSdrPage() der Seitengroesse angepasst ist, da sich sonst die
// Seiten ueberlappen koennten.
//
// Elementare Methoden:
// ~~~~~~~~~~~~~~~~~~~~
//   Einfache Events:
//   ~~~~~~~~~~~~~~~~
//     BOOL KeyInput(const KeyEvent& rKEvt, Window* pWin);
//     BOOL MouseButtonDown(const MouseEvent& rMEvt, Window* pWin);
//     BOOL MouseButtonUp(const MouseEvent& rMEvt, Window* pWin);
//     BOOL MouseMove(const MouseEvent& rMEvt, Window* pWin);
//     BOOL Command(const CommandEvent& rCEvt, Window* pWin);
//
//   Exchange (Clipboard derzeit noch ohne SdrPrivateData):
//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//     BOOL Cut(ULONG nFormat=SDR_ANYFORMAT);
//     BOOL Yank(ULONG nFormat=SDR_ANYFORMAT);
//     BOOL Paste(Window* pWin=NULL, ULONG nFormat=SDR_ANYFORMAT);
//
//   SfxItems:
//   ~~~~~~~~~
//     BOOL GetAttributes(SfxItemSet& rTargetSet, BOOL bOnlyHardAttr=FALSE) const;
//     BOOL SetAttributes(const SfxItemSet& rSet, BOOL bReplaceAll);
//     SfxStyleSheet* GetStyleSheet() const;
//     BOOL SetStyleSheet(SfxStyleSheet* pStyleSheet, BOOL bDontRemoveHardAttr);
//
//   Sonstiges:
//   ~~~~~~~~~~
//     Pointer GetPreferedPointer(const Point& rMousePos, const OutputDevice* pOut, USHORT nTol=0) const;
//     String  GetStatusText();
//
///////////////////////////////////////////////////////////////////////////////////////////////// */

<commit_msg>INTEGRATION: CWS impresstables2 (1.2.58); FILE MERGED 2007/08/01 16:55:06 cl 1.2.58.2: RESYNC: (1.2-1.3); FILE MERGED 2007/05/31 11:11:36 cl 1.2.58.1: #i68103# merging changes to moved header files for tables<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: svdview.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: rt $ $Date: 2008-03-12 09:31:49 $
 *
 *  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 _SVDVIEW_HXX
#define _SVDVIEW_HXX

// HACK to avoid too deep includes and to have some
// levels free in svdmark itself (MS compiler include depth limit)
#ifndef _SVDHDL_HXX
#include <svx/svdhdl.hxx>
#endif

#ifndef _TOOLS_WEAKBASE_HXX_
#include <tools/weakbase.hxx>
#endif

#ifndef INCLUDED_SVTOOLS_ACCESSIBILITYOPTIONS_HXX
#include <svtools/accessibilityoptions.hxx>
#endif

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

#ifndef _SVDCRTV_HXX
#include <svx/svdcrtv.hxx>
#endif

////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Klassenhierarchie der View:
//         SfxListener
//         SdrPaintView    PntV   Action            ModChg   Attr   Notify
//         SdrSnapView     SnpV   Action
//
//         SdrMarkView     MrkV   Action   MrkChg   ModChg          Notify
//
//         SdrEditView     EdtV            MrkChg   ModChg   Attr
//         SdrPolyEditView PoEV
//         SdrGlueEditView GlEV
//         SdrObjEditView  EdxV   Action            ModChg   Attr   Notify
//
//         SdrExchangeView XcgV
//         SdrDragView     DrgV   Action
//
//         SdrCreateView   CrtV   Action
//         SdrView         View
//
////////////////////////////////////////////////////////////////////////////////////////////////////

//************************************************************
//   Vorausdeklarationen
//************************************************************

class SvxURLField;

//************************************************************
//   Defines
//************************************************************

enum SdrViewContext {SDRCONTEXT_STANDARD,
                     SDRCONTEXT_POINTEDIT,
                     SDRCONTEXT_GLUEPOINTEDIT,
                     SDRCONTEXT_GRAPHIC,
                     SDRCONTEXT_MEDIA,
                     SDRCONTEXT_TABLE};

enum SdrEventKind  {SDREVENT_NONE,
                    SDREVENT_TEXTEDIT,
                    SDREVENT_MOVACTION,
                    SDREVENT_ENDACTION,
                    SDREVENT_BCKACTION,
                    SDREVENT_BRKACTION,
                    SDREVENT_ENDCREATE,
                    SDREVENT_ENDDRAG,
                    SDREVENT_MARKOBJ,
                    SDREVENT_MARKPOINT,
                    SDREVENT_MARKGLUEPOINT,
                    SDREVENT_BEGMARK,
                    SDREVENT_BEGINSOBJPOINT,
                    SDREVENT_ENDINSOBJPOINT,
                    SDREVENT_BEGINSGLUEPOINT,
                    SDREVENT_BEGDRAGHELPLINE,
                    SDREVENT_BEGDRAGOBJ,
                    SDREVENT_BEGCREATEOBJ,
                    SDREVENT_BEGMACROOBJ,
                    SDREVENT_BEGTEXTEDIT,
                    SDREVENT_ENDMARK,
                    SDREVENT_BRKMARK,
                    SDREVENT_EXECUTEURL};

#define SDRMOUSEBUTTONDOWN 1
#define SDRMOUSEMOVE       2
#define SDRMOUSEBUTTONUP   3

//************************************************************
//   Hilfsklasse SdrViewEvent
//************************************************************

struct SVX_DLLPUBLIC SdrViewEvent
{
    SdrHdl*                     pHdl;
    SdrObject*                  pObj;
    SdrObject*                  pRootObj;        // Dieses Markieren bei SdrBeginTextEdit
    SdrPageView*                pPV;
    const SvxURLField*          pURLField;

    Point                       aLogicPos;
    SdrHitKind                  eHit;
    SdrEventKind                eEvent;
    SdrHdlKind                  eHdlKind;
    SdrCreateCmd                eEndCreateCmd;   // auch fuer EndInsPoint

    UINT16                      nMouseClicks;
    UINT16                      nMouseMode;
    UINT16                      nMouseCode;
    UINT16                      nHlplIdx;
    UINT16                      nGlueId;

    unsigned                    bMouseDown : 1;
    unsigned                    bMouseUp : 1;
    unsigned                    bDoubleHdlSize : 1;  // Doppelte Handlegroesse wg. TextEdit
    unsigned                    bIsAction : 1;       // Action ist aktiv
    unsigned                    bIsTextEdit : 1;     // TextEdit laeuft zur Zeit
    unsigned                    bTextEditHit : 1;    // offene OutlinerView getroffen
    unsigned                    bAddMark : 1;
    unsigned                    bUnmark : 1;
    unsigned                    bPrevNextMark : 1;
    unsigned                    bMarkPrev : 1;
    unsigned                    bInsPointNewObj : 1;
    unsigned                    bDragWithCopy : 1;
    unsigned                    bCaptureMouse : 1;
    unsigned                    bReleaseMouse : 1;

public:
    SdrViewEvent();
    ~SdrViewEvent();

    // nEventKind ist SDRMOUSEBUTTONDOWN, SDRMOUSEMOVE oder SDRMOUSEBUTTONUP
    void SetMouseEvent(const MouseEvent& rMEvt, USHORT nEventKind);
};

////////////////////////////////////////////////////////////////////////////////////////////////////
// helper class for all D&D overlays

class SVX_DLLPUBLIC SdrDropMarkerOverlay
{
    // The OverlayObjects
    ::sdr::overlay::OverlayObjectList               maObjects;

    void ImplCreateOverlays(const SdrView& rView, const basegfx::B2DPolyPolygon& rPolyPolygon);

public:
    SdrDropMarkerOverlay(const SdrView& rView, const SdrObject& rObject);
    SdrDropMarkerOverlay(const SdrView& rView, const Rectangle& rRectangle);
    SdrDropMarkerOverlay(const SdrView& rView, const Point& rStart, const Point& rEnd);
    ~SdrDropMarkerOverlay();
};

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  @@ @@ @@ @@@@@ @@   @@
//  @@ @@ @@ @@    @@   @@
//  @@ @@ @@ @@    @@ @ @@
//  @@@@@ @@ @@@@  @@@@@@@
//   @@@  @@ @@    @@@@@@@
//   @@@  @@ @@    @@@ @@@
//    @   @@ @@@@@ @@   @@
//
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////

class SVX_DLLPUBLIC SdrView: public SdrCreateView, public tools::WeakBase< SdrView >
{
    friend class                SdrPageView;

    unsigned                    bNoExtendedMouseDispatcher : 1;
    unsigned                    bNoExtendedKeyDispatcher : 1;
    unsigned                    bNoExtendedCommandDispatcher : 1;
    unsigned                    bTextEditOnObjectsWithoutTextIfTextTool : 1;
    unsigned                    mbMasterPagePaintCaching : 1;

protected:
    SvtAccessibilityOptions maAccessibilityOptions;

    virtual void SFX_NOTIFY(SfxBroadcaster& rBC, const TypeId& rBCType, const SfxHint& rHint, const TypeId& rHintType);

public:
    TYPEINFO();
    SdrView(SdrModel* pModel1, OutputDevice* pOut = 0L);
    virtual ~SdrView();

    // Default sind alle Dispatcher aktiviert. Will die App z.B. fuer
    // Sonderbehandlungen im MouseDispatcher eingreifen, so muss sie
    // den erweiterten MouseDispather mit unten stehender Methode deaktivieren
    // und selbst nachimplementieren. Beispiel fuer MouseButtonDown:
    //      SdrViewEvent aVEvt;
    //      SdrHitKind eHit=pSdrView->PickAnything(rMEvt,SDRMOUSEBUTTONDOWN,aVEvt);
    //      ... hier Applikationsspezifischer Eingriff ...
    //      pSdrView->DoMouseEvent(aVEvt);
    //      SetPointer(GetPreferedPointer(...))
    //      CaptureMouse(...)
    void EnableExtendedMouseEventDispatcher(BOOL bOn) { bNoExtendedMouseDispatcher = !bOn; }
    BOOL IsExtendedMouseEventDispatcherEnabled() const { return bNoExtendedMouseDispatcher; }

    void EnableExtendedKeyInputDispatcher(BOOL bOn) { bNoExtendedKeyDispatcher=!bOn; }
    BOOL IsExtendedKeyInputDispatcherEnabled() const { return bNoExtendedKeyDispatcher; }

    void EnableExtendedCommandEventDispatcher(BOOL bOn) { bNoExtendedCommandDispatcher=!bOn; }
    BOOL IsExtendedCommandEventDispatcherEnabled() const { return bNoExtendedCommandDispatcher; }

    void EnableTextEditOnObjectsWithoutTextIfTextTool(BOOL bOn) { bTextEditOnObjectsWithoutTextIfTextTool=bOn; }
    BOOL IsEnableTextEditOnObjectsWithoutTextIfTextToolEnabled() const { return bTextEditOnObjectsWithoutTextIfTextTool; }

    void SetMasterPagePaintCaching(sal_Bool bOn);
    sal_Bool IsMasterPagePaintCaching() const { return mbMasterPagePaintCaching; }

    BOOL KeyInput(const KeyEvent& rKEvt, Window* pWin);
    virtual BOOL MouseButtonDown(const MouseEvent& rMEvt, Window* pWin);
    virtual BOOL MouseButtonUp(const MouseEvent& rMEvt, Window* pWin);
    virtual BOOL MouseMove(const MouseEvent& rMEvt, Window* pWin);
    virtual BOOL Command(const CommandEvent& rCEvt, Window* pWin);

    BOOL SetAttributes(const SfxItemSet& rSet, BOOL bReplaceAll=FALSE) { return SdrCreateView::SetAttributes(rSet,bReplaceAll); }
    BOOL SetStyleSheet(SfxStyleSheet* pStyleSheet, BOOL bDontRemoveHardAttr=FALSE) { return SdrCreateView::SetStyleSheet(pStyleSheet,bDontRemoveHardAttr); }

    /* new interface src537 */
    BOOL GetAttributes(SfxItemSet& rTargetSet, BOOL bOnlyHardAttr=FALSE) const;

    SfxStyleSheet* GetStyleSheet() const;

    // unvollstaendige Implementation:
    // Das OutputDevice ist notwendig, damit ich die HandleSize ermitteln kann.
    // Bei NULL wird das 1. angemeldete Win verwendet.
    Pointer GetPreferedPointer(const Point& rMousePos, const OutputDevice* pOut, USHORT nModifier=0, BOOL bLeftDown=FALSE) const;
    SdrHitKind PickAnything(const MouseEvent& rMEvt, USHORT nMouseDownOrMoveOrUp, SdrViewEvent& rVEvt) const;
    SdrHitKind PickAnything(const Point& rLogicPos, SdrViewEvent& rVEvt) const;
    BOOL DoMouseEvent(const SdrViewEvent& rVEvt);
    virtual SdrViewContext GetContext() const;

    // Die Methoden beruecksichtigen den jeweiligen Kontex:
    // - Einfaches Zeichnen
    // - Punktbearbeitungs-Mode
    // - Klebepunkt-Editmode
    // - TextEdit
    // - ... to be continued
    BOOL IsMarkPossible() const;
    void MarkAll();
    void UnmarkAll();
    BOOL IsAllMarked() const;
    BOOL IsAllMarkPrevNextPossible() const; // das geht naemlich nicht bei TextEdit!
    BOOL MarkNext(BOOL bPrev=FALSE);
    BOOL MarkNext(const Point& rPnt, BOOL bPrev=FALSE);

    const Rectangle& GetMarkedRect() const;
    void SetMarkedRect(const Rectangle& rRect);

    virtual void DeleteMarked();
    BOOL IsDeleteMarkedPossible() const;
    BOOL IsDeletePossible() const { return IsDeleteMarkedPossible(); }

    // Markieren von Objekten, Polygonpunkten oder Klebepunkten (je nach View-
    // Kontext) durch Aufziehen eines Selektionsrahmens.
    //   bAddMark=TRUE: zur bestehenden Selektion hinzumarkieren (->Shift)
    //   bUnmark=TRUE: Bereits selektierte Objekte/Punkte/Klebepunkte die innerhalb
    //                 des aufgezogenen Rahmens liegen werden deselektiert.
    BOOL BegMark(const Point& rPnt, BOOL bAddMark=FALSE, BOOL bUnmark=FALSE);

    // Folgende Actions sind moeglich:
    //   - ObjectCreating
    //   - ObjectMarking
    //   - Object-specific dragging
    //   - General dragging
    // und mehr...
    String GetStatusText();

    SvtAccessibilityOptions& getAccessibilityOptions();

    virtual void onAccessibilityOptionsChanged();
};

#endif //_SVDVIEW_HXX

////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Die App macht sich zunaechst ein SdrModel.
// Anschliessend oeffnet sie ein Win und erzeugt dann eine SdrView.
// An der SdrView meldet sie dann mit der Methode ShowSdrPage() eine Seite an.
// Eine SdrView kann in beliebig vielen Fenstern gleichzeitig angezeigt werden.
// Intern:
// Eine SdrView kann beliebig viele Seiten gleichzeitig anzeigen. Seiten
// werden an- und abgemeldet mit ShowSdrPage()/HideSdrPage(). Fuer jede angemeldete
// Seite wird eine SdrPageView-Instanz im Container aPages angelegt. Bei
// gleichzeitiger Anzeige mehrerer Seiten ist darauf zu achten, dass der Offset-
// Parameter von ShowSdrPage() der Seitengroesse angepasst ist, da sich sonst die
// Seiten ueberlappen koennten.
//
// Elementare Methoden:
// ~~~~~~~~~~~~~~~~~~~~
//   Einfache Events:
//   ~~~~~~~~~~~~~~~~
//     BOOL KeyInput(const KeyEvent& rKEvt, Window* pWin);
//     BOOL MouseButtonDown(const MouseEvent& rMEvt, Window* pWin);
//     BOOL MouseButtonUp(const MouseEvent& rMEvt, Window* pWin);
//     BOOL MouseMove(const MouseEvent& rMEvt, Window* pWin);
//     BOOL Command(const CommandEvent& rCEvt, Window* pWin);
//
//   Exchange (Clipboard derzeit noch ohne SdrPrivateData):
//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//     BOOL Cut(ULONG nFormat=SDR_ANYFORMAT);
//     BOOL Yank(ULONG nFormat=SDR_ANYFORMAT);
//     BOOL Paste(Window* pWin=NULL, ULONG nFormat=SDR_ANYFORMAT);
//
//   SfxItems:
//   ~~~~~~~~~
//     BOOL GetAttributes(SfxItemSet& rTargetSet, BOOL bOnlyHardAttr=FALSE) const;
//     BOOL SetAttributes(const SfxItemSet& rSet, BOOL bReplaceAll);
//     SfxStyleSheet* GetStyleSheet() const;
//     BOOL SetStyleSheet(SfxStyleSheet* pStyleSheet, BOOL bDontRemoveHardAttr);
//
//   Sonstiges:
//   ~~~~~~~~~~
//     Pointer GetPreferedPointer(const Point& rMousePos, const OutputDevice* pOut, USHORT nTol=0) const;
//     String  GetStatusText();
//
///////////////////////////////////////////////////////////////////////////////////////////////// */

<|endoftext|>


<commit_before>
#include <togo/core/config.hpp>
#include <togo/core/types.hpp>
#include <togo/core/error/assert.hpp>
#include <togo/core/utility/utility.hpp>
#include <togo/core/utility/tags.hpp>
#include <togo/core/utility/traits.hpp>
#include <togo/core/utility/constraints.hpp>
#include <togo/core/utility/args.hpp>
#include <togo/core/math/types.hpp>
#include <togo/core/math/math.hpp>
#include <togo/core/log/log.hpp>
#include <togo/core/log/test.hpp>
#include <togo/core/log/test_unconfigure.hpp>
#include <togo/core/memory/types.hpp>
#include <togo/core/memory/memory.hpp>
#include <togo/core/memory/jump_block_allocator.hpp>
#include <togo/core/memory/temp_allocator.hpp>
#include <togo/core/collection/types.hpp>
#include <togo/core/collection/fixed_array.hpp>
#include <togo/core/collection/array.hpp>
#include <togo/core/collection/queue.hpp>
#include <togo/core/collection/priority_queue.hpp>
#include <togo/core/collection/hash_map.hpp>
#include <togo/core/algorithm/sort.hpp>
#include <togo/core/string/types.hpp>
#include <togo/core/string/string.hpp>
#include <togo/core/hash/types.hpp>
#include <togo/core/hash/hash.hpp>
#include <togo/core/hash/hash_combiner.hpp>
#include <togo/core/system/system.hpp>
#include <togo/core/filesystem/types.hpp>
#include <togo/core/filesystem/filesystem.hpp>
#include <togo/core/filesystem/directory_reader.hpp>
#include <togo/core/random/types.hpp>
#include <togo/core/random/random.hpp>
#include <togo/core/threading/types.hpp>
#include <togo/core/threading/condvar.hpp>
#include <togo/core/threading/mutex.hpp>
#include <togo/core/threading/thread.hpp>
#include <togo/core/threading/task_manager.hpp>
#include <togo/core/io/types.hpp>
#include <togo/core/io/io.hpp>
#include <togo/core/io/proto.hpp>
#include <togo/core/io/memory_stream.hpp>
#include <togo/core/io/file_stream.hpp>
#include <togo/core/io/object_buffer_type.hpp>
#include <togo/core/io/object_buffer.hpp>
#include <togo/core/kvs/types.hpp>
#include <togo/core/kvs/kvs.hpp>
#include <togo/core/serialization/types.hpp>
#include <togo/core/serialization/serializer.hpp>
#include <togo/core/serialization/support.hpp>
#include <togo/core/serialization/binary_serializer.hpp>
#include <togo/core/serialization/fixed_array.hpp>
#include <togo/core/serialization/array.hpp>
#include <togo/core/serialization/string.hpp>
#include <togo/core/external/dlmalloc_import.hpp>

signed main() {
	return 0;
}
<commit_msg>lib/core/test/general/headers: included lib/core/utility/endian.<commit_after>
#include <togo/core/config.hpp>
#include <togo/core/types.hpp>
#include <togo/core/error/assert.hpp>
#include <togo/core/utility/utility.hpp>
#include <togo/core/utility/tags.hpp>
#include <togo/core/utility/traits.hpp>
#include <togo/core/utility/constraints.hpp>
#include <togo/core/utility/endian.hpp>
#include <togo/core/utility/args.hpp>
#include <togo/core/math/types.hpp>
#include <togo/core/math/math.hpp>
#include <togo/core/log/log.hpp>
#include <togo/core/log/test.hpp>
#include <togo/core/log/test_unconfigure.hpp>
#include <togo/core/memory/types.hpp>
#include <togo/core/memory/memory.hpp>
#include <togo/core/memory/jump_block_allocator.hpp>
#include <togo/core/memory/temp_allocator.hpp>
#include <togo/core/collection/types.hpp>
#include <togo/core/collection/fixed_array.hpp>
#include <togo/core/collection/array.hpp>
#include <togo/core/collection/queue.hpp>
#include <togo/core/collection/priority_queue.hpp>
#include <togo/core/collection/hash_map.hpp>
#include <togo/core/algorithm/sort.hpp>
#include <togo/core/string/types.hpp>
#include <togo/core/string/string.hpp>
#include <togo/core/hash/types.hpp>
#include <togo/core/hash/hash.hpp>
#include <togo/core/hash/hash_combiner.hpp>
#include <togo/core/system/system.hpp>
#include <togo/core/filesystem/types.hpp>
#include <togo/core/filesystem/filesystem.hpp>
#include <togo/core/filesystem/directory_reader.hpp>
#include <togo/core/random/types.hpp>
#include <togo/core/random/random.hpp>
#include <togo/core/threading/types.hpp>
#include <togo/core/threading/condvar.hpp>
#include <togo/core/threading/mutex.hpp>
#include <togo/core/threading/thread.hpp>
#include <togo/core/threading/task_manager.hpp>
#include <togo/core/io/types.hpp>
#include <togo/core/io/io.hpp>
#include <togo/core/io/proto.hpp>
#include <togo/core/io/memory_stream.hpp>
#include <togo/core/io/file_stream.hpp>
#include <togo/core/io/object_buffer_type.hpp>
#include <togo/core/io/object_buffer.hpp>
#include <togo/core/kvs/types.hpp>
#include <togo/core/kvs/kvs.hpp>
#include <togo/core/serialization/types.hpp>
#include <togo/core/serialization/serializer.hpp>
#include <togo/core/serialization/support.hpp>
#include <togo/core/serialization/binary_serializer.hpp>
#include <togo/core/serialization/fixed_array.hpp>
#include <togo/core/serialization/array.hpp>
#include <togo/core/serialization/string.hpp>
#include <togo/core/external/dlmalloc_import.hpp>

signed main() {
	return 0;
}
<|endoftext|>


<commit_before>#include <utility>

DECLARE_bool(flat_combining);

namespace Grappa {

/// Mixin for adding common global data structure functionality, such as mirrored
/// allocation on all cores.
template< typename Base, Core MASTER = 0 >
class MirroredGlobal : public Base {
  char pad[block_size - sizeof(Base)];
public:
  template <typename... Args>
  explicit MirroredGlobal(Args&&... args): Base(std::forward<Args...>(args...)) {}
  explicit MirroredGlobal(): Base() {}

  /// Allocate and call init() on all instances of Base
  ///
  /// @param init Lambda of the form: void init(Base*)
  ///
  /// @b Example:
  /// @code
  ///     auto c = MirroredGlobal<Counter>::create([](Counter* c){ new (c) Counter(0); });
  /// @endcode
  template< typename F >
  static GlobalAddress<MirroredGlobal<Base>> create(F init) {
    auto a = mirrored_global_alloc<MirroredGlobal<Base>>();
    call_on_all_cores([a,init]{ init(static_cast<Base*>(a.localize())); });
    return a;
  }

  /// Allocate an instance on all cores and initialize with default constructor.
  ///
  /// @note Requires Base class to have a default constructor.
  static GlobalAddress<MirroredGlobal<Base>> create() {
    auto a = mirrored_global_alloc<MirroredGlobal<Base>>();
    call_on_all_cores([a]{ new (a.localize()) MirroredGlobal<Base>(); });
    return a;
  }

  void destroy() {
    auto a = this->self;
    call_on_all_cores([a]{ a->~MirroredGlobal<Base>(); });
    global_free(a);
  }

};

template <typename T>
class FlatCombiner {

  struct Flusher {
    T * id;
    Worker * sender;
    ConditionVariable cv;
    Flusher(T * id): id(id), sender(nullptr) {}
    ~Flusher() { locale_free(id); }
  };

  Flusher * current;
  Flusher * inflight;

public:

  FlatCombiner(T * initial): current(new Flusher(initial)), inflight(nullptr) {}
  ~FlatCombiner() { delete current; delete inflight; }

  // template <typename... Args>
  // explicit FlatCombiner(Args&&... args)
  //   : current(new Flusher(new T(std::forward<Args...>(args...))))
  //   , inflight(nullptr)
  //   , sender(nullptr)
  // { }
  //
  // // in case it's a no-arg constructor
  // explicit FlatCombiner(): FlatCombiner() {}

  // for arbitrary return type defined by base class
  // auto operator()(Args&&... args) -> decltype(this->T::operator()(std::forward<Args...>(args...))) {

  template< typename F >
  void combine(F func) {
    auto s = current;

    func(*s->id);

    if (s->id->is_full() || inflight == nullptr) {
      inflight = current;
      current = new Flusher(s->id->clone_fresh());
      if (s->sender == nullptr) {
        flush(s);
      } // otherwise someone else is already assigned and will send when ready
    } else {
      Grappa::wait(&s->cv);
      if (&current_worker() == s->sender) {
        if (s == current) current = new Flusher(s->id->clone_fresh());
        flush(s);
      }
    }

  }

  void flush(Flusher * s) {
    s->sender = &current_worker(); // (if not set already)

    s->id->sync();

    broadcast(&s->cv); // wake our people
    if (current->cv.waiters_ != 0) {
      // atomically claim it so no one else tries to send in the meantime
      inflight = current;
      // wake someone and tell them to send
      inflight->sender = impl::get_waiters(&inflight->cv);
      signal(&inflight->cv);
    } else {
      inflight = nullptr;
    }
    s->sender = nullptr;
    delete s;
  }
};

// template< T >
// class ProxiedGlobal : public T {
//   using Master = typename T::Master;
//   using Proxy = typename T::Proxy;
// public:
//   GlobalAddress<ProxiedGlobal<T>> self;
//
//   template< typename... Args >
//   static GlobalAddress<ProxiedGlobal<T>> create(Args&&... args) {
//     static_assert(sizeof(ProxiedGlobal<T>) % block_size == 0,
//                   "must pad global proxy to multiple of block_size");
//     // allocate enough space that we are guaranteed to get one on each core at same location
//     auto qac = global_alloc<char>(cores()*(sizeof(ProxiedGlobal<T>)+block_size));
//     while (qac.core() != MASTER_CORE) qac++;
//     auto qa = static_cast<GlobalAddress<ProxiedGlobal<T>>>(qac);
//     CHECK_EQ(qa, qa.block_min());
//     CHECK_EQ(qa.core(), MASTER_CORE);
//
//     // intialize all cores' local versions
//     call_on_all_cores([=]{
//       new (s.self.localize()) ProxiedGlobal<T>(args...);
//     });
//
//     return qa;
//   }
//
//   void destroy() {
//     auto q = shared.self;
//     global_free(q->shared.base);
//     call_on_all_cores([q]{ q->~GlobalVector(); });
//     global_free(q);
//   }
//
// };
//

} // namespace Grappa

<commit_msg>Proper includes in FlatCombiner.hpp<commit_after>#include "Communicator.hpp"
#include "Addressing.hpp"
#include "GlobalAllocator.hpp"
#include "LocaleSharedMemory.hpp"
#include "ParallelLoop.hpp"
#include <utility>

DECLARE_bool(flat_combining);

namespace Grappa {

/// Mixin for adding common global data structure functionality, such as mirrored
/// allocation on all cores.
template< typename Base, Core MASTER = 0 >
class MirroredGlobal : public Base {
  char pad[block_size - sizeof(Base)];
public:
  template <typename... Args>
  explicit MirroredGlobal(Args&&... args): Base(std::forward<Args...>(args...)) {}
  explicit MirroredGlobal(): Base() {}

  /// Allocate and call init() on all instances of Base
  ///
  /// @param init Lambda of the form: void init(Base*)
  ///
  /// @b Example:
  /// @code
  ///     auto c = MirroredGlobal<Counter>::create([](Counter* c){ new (c) Counter(0); });
  /// @endcode
  template< typename F >
  static GlobalAddress<MirroredGlobal<Base>> create(F init) {
    auto a = mirrored_global_alloc<MirroredGlobal<Base>>();
    call_on_all_cores([a,init]{ init(static_cast<Base*>(a.localize())); });
    return a;
  }

  /// Allocate an instance on all cores and initialize with default constructor.
  ///
  /// @note Requires Base class to have a default constructor.
  static GlobalAddress<MirroredGlobal<Base>> create() {
    auto a = mirrored_global_alloc<MirroredGlobal>();
    call_on_all_cores([a]{ new (a.localize()) MirroredGlobal<Base>(); });
    return a;
  }

  void destroy() {
    auto a = this->self;
    call_on_all_cores([a]{ a->~MirroredGlobal<Base>(); });
    global_free(a);
  }

};

template <typename T>
class FlatCombiner {

  struct Flusher {
    T * id;
    Worker * sender;
    ConditionVariable cv;
    Flusher(T * id): id(id), sender(nullptr) {}
    ~Flusher() { locale_free(id); }
  };

  Flusher * current;
  Flusher * inflight;

public:

  FlatCombiner(T * initial): current(new Flusher(initial)), inflight(nullptr) {}
  ~FlatCombiner() { delete current; delete inflight; }

  // template <typename... Args>
  // explicit FlatCombiner(Args&&... args)
  //   : current(new Flusher(new T(std::forward<Args...>(args...))))
  //   , inflight(nullptr)
  //   , sender(nullptr)
  // { }
  //
  // // in case it's a no-arg constructor
  // explicit FlatCombiner(): FlatCombiner() {}

  // for arbitrary return type defined by base class
  // auto operator()(Args&&... args) -> decltype(this->T::operator()(std::forward<Args...>(args...))) {

  template< typename F >
  void combine(F func) {
    auto s = current;

    func(*s->id);

    if (s->id->is_full() || inflight == nullptr) {
      inflight = current;
      current = new Flusher(s->id->clone_fresh());
      if (s->sender == nullptr) {
        flush(s);
      } // otherwise someone else is already assigned and will send when ready
    } else {
      Grappa::wait(&s->cv);
      if (&current_worker() == s->sender) {
        if (s == current) current = new Flusher(s->id->clone_fresh());
        flush(s);
      }
    }

  }

  void flush(Flusher * s) {
    s->sender = &current_worker(); // (if not set already)

    s->id->sync();

    broadcast(&s->cv); // wake our people
    if (current->cv.waiters_ != 0) {
      // atomically claim it so no one else tries to send in the meantime
      inflight = current;
      // wake someone and tell them to send
      inflight->sender = impl::get_waiters(&inflight->cv);
      signal(&inflight->cv);
    } else {
      inflight = nullptr;
    }
    s->sender = nullptr;
    delete s;
  }
};

// template< T >
// class ProxiedGlobal : public T {
//   using Master = typename T::Master;
//   using Proxy = typename T::Proxy;
// public:
//   GlobalAddress<ProxiedGlobal<T>> self;
//
//   template< typename... Args >
//   static GlobalAddress<ProxiedGlobal<T>> create(Args&&... args) {
//     static_assert(sizeof(ProxiedGlobal<T>) % block_size == 0,
//                   "must pad global proxy to multiple of block_size");
//     // allocate enough space that we are guaranteed to get one on each core at same location
//     auto qac = global_alloc<char>(cores()*(sizeof(ProxiedGlobal<T>)+block_size));
//     while (qac.core() != MASTER_CORE) qac++;
//     auto qa = static_cast<GlobalAddress<ProxiedGlobal<T>>>(qac);
//     CHECK_EQ(qa, qa.block_min());
//     CHECK_EQ(qa.core(), MASTER_CORE);
//
//     // intialize all cores' local versions
//     call_on_all_cores([=]{
//       new (s.self.localize()) ProxiedGlobal<T>(args...);
//     });
//
//     return qa;
//   }
//
//   void destroy() {
//     auto q = shared.self;
//     global_free(q->shared.base);
//     call_on_all_cores([q]{ q->~GlobalVector(); });
//     global_free(q);
//   }
//
// };
//

} // namespace Grappa

<|endoftext|>


<commit_before>#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
using namespace std;
# define M_PI           3.14159265358979323846  /* lol it's pi */

// Get me meh distance.
double dist(int startY, int startX, int endY, int endX){
    double dx = ((double)endX-(double)startX);
    double dy = ((double)endY-(double)startY);
    return(sqrt(dx*dx + dy*dy));
}

unsigned int randLine(unsigned int seed, double pushCoefficient, int startY, int startX, int endY, int endX,
unsigned int* yList, unsigned int* xList, int* ySpareList, int* xSpareList,
unsigned int side, bool diagonal, bool debug){
    srand(1379966042);
	if(debug){
		cout << "--------- SEED: " << seed << " ---------" << endl;
	}
    int dList[13]  = {    2, 3,   6,9,8, 7, 4, 1, 2, 3,6,     9,8}; // Navigation array. Check numpad.
    int dRealList[13] = { 8, 9,   6,3,2, 1, 4, 7, 8, 9,6,     3,2};  // Adjusted for map display.
    // No longer in use. Use as reference instead.
    int yAddArray[13] = {-1,-1,   0,1,1, 1, 0,-1,-1,-1,0,     1,1};
    int xAddArray[13] = { 0, 1,   1,1,0,-1,-1,-1, 0, 1,1,     1,0};
    double orig = dist(startY,startX,endY,endX); // Get original distance..
    int ex = startX; // X
    int wy = startY; // Y
    //map[(startY*side) + startX] = 1;
	yList[0] = startY;
	xList[0] = startX;
    unsigned int index = 1;
	unsigned int spareIndex = 0;
    while(ex != endX || wy != endY){
        double result = atan2((endY-wy),(endX-ex)) + (M_PI * 2);
	result = fmod(result,(M_PI * 2));
        //This gets the thing in radians.
        // We multiply the result by 180/M_PI to save us some calculations.
        // We subtract by 22.5 (to shift the 4 orthogonal directions between the 4 quadrants.)
        // We then divide by 45. // To obtain the integer on the dList.
        // Then we round up. // To finalize getting integer.
        // We add 2 to adjust for dList offset.
        // ---
        // So, we simplify this to make it quicker, and to truncate instead of using ceil. Basically adding 1 and
        // rounding down. -22.5 / 45 = -0.5, plus 1 = 0.5. Add 2, etc...
        int bResult = (int)((result * (180/(M_PI*45)))+2.5);
        int origBResult = bResult;
        int random = rand()%1000; // Random number between 0 and 999.
	 double distToA = dist(wy,ex,startY,startX) + 1; // Add one so there's a 100% chance when right
							// beside the goal. Unfortunately, it means a more push to goal. Fix?
        if(random>299 && distToA < orig){ // Checks if, by absolute means, we're going straight or not. We can still go straight...
           // Also check if distToA larger than orig. Found this by debugging, still possible. :/

            //double pushCoefficient = 0.5;
		// Great than 0. Lower than zero means tendency means less push,
            // greater than 1 means greater push towards end point.
		// values 0.1 to 0.5 seem good. Recommend 0.1.
            int primChance = (int)(999.5 - (pow(((orig-distToA)/orig),pushCoefficient)*700)); //999 is max, 299 min. We truncate-round,
            // so add 0.5.
            if(random>primChance){ // Checks again if we're going straight.
                int thirChance = 600-primChance; // We don't need to know secondary chance. 999-399 is what
                // got 600 here. 999-primChance is secondary chance. then -399, gets thirChance.
                if(random>999-thirChance){
                    bResult=(bResult-2)+((random%2)*4); // If it's even, negative. Odd, positive.
                }
                else { // Then secondary chance occurs. We already checked primary and third, both failed.
                    bResult=(bResult-1)+((random%2)*2); // If it's even, negative. Odd, positive.
                }
            }
        }

        int yAdd = yAddArray[bResult]; // We get the values where to go.
        int xAdd = xAddArray[bResult];
        if(yList[index-1] == wy+yAdd && xList[index-1] == ex+xAdd){
            bResult = origBResult;
            yAdd = yAddArray[bResult]; // We get the values where to go.
            xAdd = xAddArray[bResult];
        }
        if(diagonal && yAdd*xAdd) { // Check if diagonal.
            if(dist(wy+yAdd,ex,endY,endX) < dist(wy,ex+xAdd,endY,endX)){
                yList[index] = wy+yAdd;
                xList[index] = ex;
                //map[((wy+yAdd)*side) + ex] = 2;
            }
            else{
                yList[index] = wy;
                xList[index] = ex+xAdd;
                //map[(wy*side) + ex+xAdd] = 2;
            }
            index++;
        }
        //--------------- DEBUG STUFF. /t for tabbing.
        if(debug){
        cout << "WY: " << wy << "+" << yAdd << "\tEX:" << ex << "+" << xAdd << "\tDRES:" << dList[bResult] <<
        "\tRES:" << (result*180)/M_PI;
        if(result!=0){
            cout <<"\tDELY:";
        }
        else{
            cout << "\t\tDELY:";
        }
        double distanceC = dist(wy,ex,startY,startX) + 1;
        cout << (endY-wy) << "\tDELX:" << (endX-ex) << "\tDIST:" << distanceC + 1;
        if(distanceC-floor(distanceC) > 0){
            cout << "\tCHANCE:";
        }
        else{
            cout << "\t\tCHANCE:";
        }
        cout << (int)(999.5 - (pow(((orig-(dist(wy,ex,startY,startX)+1))/orig),0.5)*700)) << "\tRANDOM:" << random << endl;
        }
        //---------------
	ex=ex+xAdd;
	wy=wy+yAdd;
	if(wy>=side || wy<0 || ex>=side || ex<0){
		cout << "OUTSIDE" << endl;
		xSpareList[spareIndex] = (ex);
        	ySpareList[spareIndex] = (wy);
        	spareIndex++;
	}
	else{
		xList[index] = (ex);
		yList[index] = (wy);
		index++;
	}
        //map[(wy*side) + ex] = 1;
    }
	xSpareList[spareIndex] = 1;
        ySpareList[spareIndex] = 1; // Why 1 and 1? Because all maps are 1x1 or greater, and spare is exclusively for coordinates
	// outside of map. We use that for length.
	return index; // Return length.
}

void int circle(double pushCoefficient, unsigned int pointX, unsigned int pointY, unsigned int radius,
unsigned int* map, unsigned int side, bool diagonal, bool debug){

}

int main () {
//unsigned int side = 20; changed to const below
const unsigned int side = 20;
    unsigned int yList[side*side];
    unsigned int xList[side*side];
	int ySpareList[side*side];
    int xSpareList[side*side];
    unsigned int map[side*side];
	bool debug = true;
	//-- For testing for BAD STUFF
	while(1){ // Since it's RNG... we'll need a lot to detect even a tiny bug.
	//--
    for (int i = 0; i < side*side; ++i)
    {
        map[i] = 0;
    }
    int length = randLine(rand(), 0.1, (side/2)-1, 0,  (side/2)-1, side-1, yList, xList, ySpareList,xSpareList, side, false,debug);
	//----------
	for(int i = 0; i<length; ++i){
		map[ (yList[i]*side) + xList[i] ] = 1;
		if(debug){
		cout << "Y: " << yList[i] << " X: " << xList[i] << endl;
		}
	}
	//----------
    for (int i = 0; i < side*side; ++i)
    {
        if(i%side == 0){
            cout << endl;
        }
        cout << map[i];

    }
	cout << endl;
	//--
    }
	//--
}
<commit_msg>Update linegen.cpp<commit_after>#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
using namespace std;
# define M_PI           3.14159265358979323846  /* lol it's pi */

// Get me meh distance.
double dist(int startY, int startX, int endY, int endX){
    double dx = ((double)endX-(double)startX);
    double dy = ((double)endY-(double)startY);
    return(sqrt(dx*dx + dy*dy));
}

unsigned int randLine(unsigned int seed, double pushCoefficient, int startY, int startX, int endY, int endX,
unsigned int* yList, unsigned int* xList, int* ySpareList, int* xSpareList,
unsigned int side, bool diagonal, bool debug){
    srand(1379966042);
	if(debug){
		cout << "--------- SEED: " << seed << " ---------" << endl;
	}
    int dList[13]  = {    2, 3,   6,9,8, 7, 4, 1, 2, 3,6,     9,8}; // Navigation array. Check numpad.
    int dRealList[13] = { 8, 9,   6,3,2, 1, 4, 7, 8, 9,6,     3,2};  // Adjusted for map display.
    // No longer in use. Use as reference instead.
    int yAddArray[13] = {-1,-1,   0,1,1, 1, 0,-1,-1,-1,0,     1,1};
    int xAddArray[13] = { 0, 1,   1,1,0,-1,-1,-1, 0, 1,1,     1,0};
    double orig = dist(startY,startX,endY,endX); // Get original distance..
    int ex = startX; // X
    int wy = startY; // Y
    //map[(startY*side) + startX] = 1;
	yList[0] = startY;
	xList[0] = startX;
    unsigned int index = 1;
	unsigned int spareIndex = 0;
    while(ex != endX || wy != endY){
        double result = atan2((endY-wy),(endX-ex)) + (M_PI * 2);
	result = fmod(result,(M_PI * 2));
        //This gets the thing in radians.
        // We multiply the result by 180/M_PI to save us some calculations.
        // We subtract by 22.5 (to shift the 4 orthogonal directions between the 4 quadrants.)
        // We then divide by 45. // To obtain the integer on the dList.
        // Then we round up. // To finalize getting integer.
        // We add 2 to adjust for dList offset.
        // ---
        // So, we simplify this to make it quicker, and to truncate instead of using ceil. Basically adding 1 and
        // rounding down. -22.5 / 45 = -0.5, plus 1 = 0.5. Add 2, etc...
        int bResult = (int)((result * (180/(M_PI*45)))+2.5);
        int origBResult = bResult;
        int random = rand()%1000; // Random number between 0 and 999.
	 double distToA = dist(wy,ex,startY,startX) + 1; // Add one so there's a 100% chance when right
							// beside the goal. Unfortunately, it means a more push to goal. Fix?
        if(random>299 && distToA < orig){ // Checks if, by absolute means, we're going straight or not. We can still go straight...
           // Also check if distToA larger than orig. Found this by debugging, still possible. :/

            //double pushCoefficient = 0.5;
		// Great than 0. Lower than zero means tendency means less push,
            // greater than 1 means greater push towards end point.
		// values 0.1 to 0.5 seem good. Recommend 0.1.
            int primChance = (int)(999.5 - (pow(((orig-distToA)/orig),pushCoefficient)*700)); //999 is max, 299 min. We truncate-round,
            // so add 0.5.
            if(random>primChance){ // Checks again if we're going straight.
                int thirChance = 600-primChance; // We don't need to know secondary chance. 999-399 is what
                // got 600 here. 999-primChance is secondary chance. then -399, gets thirChance.
                if(random>999-thirChance){
                    bResult=(bResult-2)+((random%2)*4); // If it's even, negative. Odd, positive.
                }
                else { // Then secondary chance occurs. We already checked primary and third, both failed.
                    bResult=(bResult-1)+((random%2)*2); // If it's even, negative. Odd, positive.
                }
            }
        }

        int yAdd = yAddArray[bResult]; // We get the values where to go.
        int xAdd = xAddArray[bResult];
        if(yList[index-1] == wy+yAdd && xList[index-1] == ex+xAdd){
            bResult = origBResult;
            yAdd = yAddArray[bResult]; // We get the values where to go.
            xAdd = xAddArray[bResult];
        }
        if(diagonal && yAdd*xAdd) { // Check if diagonal.
            if(dist(wy+yAdd,ex,endY,endX) < dist(wy,ex+xAdd,endY,endX)){
                yList[index] = wy+yAdd;
                xList[index] = ex;
                //map[((wy+yAdd)*side) + ex] = 2;
            }
            else{
                yList[index] = wy;
                xList[index] = ex+xAdd;
                //map[(wy*side) + ex+xAdd] = 2;
            }
            index++;
        }
        //--------------- DEBUG STUFF. /t for tabbing.
        if(debug){
        cout << "WY: " << wy << "+" << yAdd << "\tEX:" << ex << "+" << xAdd << "\tDRES:" << dList[bResult] <<
        "\tRES:" << (result*180)/M_PI;
        if(result!=0){
            cout <<"\tDELY:";
        }
        else{
            cout << "\t\tDELY:";
        }
        double distanceC = dist(wy,ex,startY,startX) + 1;
        cout << (endY-wy) << "\tDELX:" << (endX-ex) << "\tDIST:" << distanceC + 1;
        if(distanceC-floor(distanceC) > 0){
            cout << "\tCHANCE:";
        }
        else{
            cout << "\t\tCHANCE:";
        }
        cout << (int)(999.5 - (pow(((orig-(dist(wy,ex,startY,startX)+1))/orig),0.5)*700)) << "\tRANDOM:" << random << endl;
        }
        //---------------
	ex=ex+xAdd;
	wy=wy+yAdd;
	if(wy>=side || wy<0 || ex>=side || ex<0){
		cout << "OUTSIDE" << endl;
		xSpareList[spareIndex] = (ex);
        	ySpareList[spareIndex] = (wy);
        	spareIndex++;
	}
	else{
		xList[index] = (ex);
		yList[index] = (wy);
		index++;
	}
        //map[(wy*side) + ex] = 1;
    }
	xSpareList[spareIndex] = 1;
        ySpareList[spareIndex] = 1; // Why 1 and 1? Because all maps are 1x1 or greater, and spare is exclusively for coordinates
	// outside of map. We use that for length.
	return index; // Return length.
}

void circle(double pushCoefficient, unsigned int pointX, unsigned int pointY, unsigned int radius,
unsigned int* map, unsigned int side, bool diagonal, bool debug){

}

int main () {
//unsigned int side = 20; changed to const below
const unsigned int side = 20;
    unsigned int yList[side*side];
    unsigned int xList[side*side];
	int ySpareList[side*side];
    int xSpareList[side*side];
    unsigned int map[side*side];
	bool debug = true;
	//-- For testing for BAD STUFF
	while(1){ // Since it's RNG... we'll need a lot to detect even a tiny bug.
	//--
    for (int i = 0; i < side*side; ++i)
    {
        map[i] = 0;
    }
    int length = randLine(rand(), 0.1, (side/2)-1, 0,  (side/2)-1, side-1, yList, xList, ySpareList,xSpareList, side, false,debug);
	//----------
	for(int i = 0; i<length; ++i){
		map[ (yList[i]*side) + xList[i] ] = 1;
		if(debug){
		cout << "Y: " << yList[i] << " X: " << xList[i] << endl;
		}
	}
	//----------
    for (int i = 0; i < side*side; ++i)
    {
        if(i%side == 0){
            cout << endl;
        }
        cout << map[i];

    }
	cout << endl;
	//--
    }
	//--
}
<|endoftext|>


<commit_before>#include <arpc.h>
#include <id_utils.h>
#include <syncer.h>
#include <location.h>
#include <locationtable.h>

void
usage ()
{
  fatal << "syncer: some args\n";
}

int
main (int argc, char **argv)
{
  str db_name = "/var/tmp/db";
  str p2psocket = "/tmp/chord-sock";
  char *logfname = NULL;
  int vnodes = 1;
  int efrags=14, dfrags=7;
  char ch;
  chord_node host;
  host.r.port = 0;

  setprogname (argv[0]);

  while ((ch = getopt (argc, argv, "d:S:v:e:c:p:t:j:"))!=-1)
    switch (ch) {

    case 'd':
      db_name = optarg;
      break;

    case 'L':
      logfname = optarg;
      break;

    case 'v':
      vnodes = atoi (optarg);
      break;

    case 'e':
      efrags = atoi (optarg);
      break;
    case 'c':
      dfrags = atoi  (optarg);
      break;

    case 'S':
      p2psocket = optarg;
      break;

    case 'j':
      {
	char *bs_port = strchr (optarg, ':');
	if (!bs_port) usage ();
	char *sep = bs_port;
	*bs_port = 0;
	bs_port++;
	if (inet_addr (optarg) == INADDR_NONE) {
	  //yep, this blocks
	  struct hostent *h = gethostbyname (optarg);
	  if (!h) {
	    warn << "Invalid address or hostname: " << optarg << "\n";
	    usage ();
	  }
	  struct in_addr *ptr = (struct in_addr *)h->h_addr;
	  host.r.hostname = inet_ntoa (*ptr);
	}
	else
	  host.r.hostname = optarg;
	host.r.port = atoi (bs_port);

	*sep = ':'; // restore optarg for argv printing later.
	break;
      }

    default:
      usage ();
      break;
    }

  assert (dfrags > 0 && efrags > 0);
  assert (host.r.port > 0);

  ptr<locationtable> locations = New refcounted<locationtable> (1024);

  chord_node ret;
  for (u_int i = 0; i < 3; i++)
    ret.coords.push_back (0);
  ret.r.hostname = host.r.hostname;
  ret.r.port = host.r.port;
  for (int i = 0; i < vnodes; i++) {
    ret.vnode_num = i;
    ret.x = make_chordID (ret.r.hostname, ret.r.port, i);
    ptr<location> n = New refcounted<location> (ret);
    str dbname = strbuf () << db_name << "-" << i;
    vNew syncer (locations, n, dbname, efrags, dfrags);
  }

  // XXX check if lsd is running

  amain ();
}
<commit_msg>Usage message.<commit_after>#include <arpc.h>
#include <id_utils.h>
#include <syncer.h>
#include <location.h>
#include <locationtable.h>

static void
usage ()
{
  warnx << "Usage: " << progname << " -j hostname:port\n"
        << "\t[-v <number of vnodes>]\n"
        << "\t[-d <dbprefix>]\n"
        << "\t[-e <efrags>]\n"
        << "\t[-c <dfrags>]\n";
  exit (1);
}

int
main (int argc, char **argv)
{
  str db_name = "/var/tmp/db";
  char *logfname = NULL;
  int vnodes = 1;
  int efrags = 14, dfrags = 7;
  char ch;

  chord_node host;
  host.r.port = 0;

  setprogname (argv[0]);

  while ((ch = getopt (argc, argv, "d:S:v:e:c:p:t:j:"))!=-1)
    switch (ch) {
    case 'd':
      db_name = optarg;
      break;
    case 'L':
      logfname = optarg;
      break;
    case 'v':
      vnodes = atoi (optarg);
      break;
    case 'e':
      efrags = atoi (optarg);
      break;
    case 'c':
      dfrags = atoi  (optarg);
      break;
    case 'j':
      {
	char *bs_port = strchr (optarg, ':');
	if (!bs_port) usage ();
	char *sep = bs_port;
	*bs_port = 0;
	bs_port++;
	if (inet_addr (optarg) == INADDR_NONE) {
	  //yep, this blocks
	  struct hostent *h = gethostbyname (optarg);
	  if (!h) {
	    warn << "Invalid address or hostname: " << optarg << "\n";
	    usage ();
	  }
	  struct in_addr *ptr = (struct in_addr *)h->h_addr;
	  host.r.hostname = inet_ntoa (*ptr);
	}
	else
	  host.r.hostname = optarg;
	host.r.port = atoi (bs_port);

	*sep = ':'; // restore optarg for argv printing later.
	break;
      }

    default:
      usage ();
      break;
    }

  if (! (dfrags > 0 && efrags > 0 && host.r.port > 0))
    usage ();

  ptr<locationtable> locations = New refcounted<locationtable> (1024);

  chord_node ret;
  for (u_int i = 0; i < 3; i++)
    ret.coords.push_back (0);
  ret.r.hostname = host.r.hostname;
  ret.r.port = host.r.port;
  for (int i = 0; i < vnodes; i++) {
    ret.vnode_num = i;
    ret.x = make_chordID (ret.r.hostname, ret.r.port, i);
    ptr<location> n = New refcounted<location> (ret);
    str dbname = strbuf () << db_name << "-" << i;
    vNew syncer (locations, n, dbname, efrags, dfrags);
  }

  // XXX check if lsd is running

  amain ();
}
<|endoftext|>


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

#include <string>
#include <utility>
#include <map>
using namespace std;

map<char, float> letterfreq_en = {
	{'E',12.702},{'T',9.056},
	{'A',8.167}, {'O',7.507},
	{'I',6.996}, {'N',6.749},
	{'S',6.327}, {'R',5.987},
	{'H',6.094}, {'D',4.253},
	{'L',4.025}, {'U',2.758},
	{'C',2.782}, {'M',2.406},
	{'F',2.228}, {'Y',1.974},
	{'W',2.360}, {'G',2.015},
	{'P',1.929}, {'B',1.492},
	{'V',0.978}, {'K',0.772},
	{'X',0.150}, {'Q',0.095},
	{'J',0.153}, {'Z',0.074}};

map<char, float> letterfreq_de = {
	{'E',16.693},{'N',9.905},
	{'I',7.812}, {'S',6.765},
	{'R',6.539}, {'A',6.506},
	{'T',6.742}, {'D',5.414},
	{'H',4.064}, {'U',3.703},
	{'L',2.825}, {'C',2.837},
	{'G',3.647}, {'M',3.005},
	{'O',2.285}, {'B',2.566},
	{'W',1.396}, {'F',2.044},
	{'K',1.879}, {'Z',1.002},
	{'P',0.944}, {'V',1.069},
	{'J',0.191}, {'Y',0.032},
	{'X',0.022}, {'Q',0.055}};

map<string, map<char, float>*> letterfreqs = {
	{"en", &letterfreq_en},
	{"de", &letterfreq_de}};
map<char, float> *letterfreq = &letterfreq_en;

char alphasq[25] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

struct CaesarResult {
	int key;
	string text;
	};

struct VigenereResult {
	string key;
	string text;
	};

struct coords {
	short row;
	short column;
	short index;
	};

string cleanString(string *text);
map<char, float> calcLetterFreq(string *text);
float calcOffset(string *text);
string restorePunctuation(string *wopunc, string *wpunc, bool encrypting);

string encipherCaesarString(string *plain, char key);
string decipherCaesarString(string *cipher, char key);

CaesarResult crackCaesarString(string *cipher);

string encipherVigenereString(string *plain, string *key);
string decipherVigenereString(string *cipher, string *key);

float calcIC(string *cipher);
VigenereResult crackVigenereString(string *cipher);

string encipherOTPString(string *plain, int seed);
string decipherOTPString(string *cipher, int seed);

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

#include <string>
#include <utility>
#include <map>
using namespace std;

map<char, float> letterfreq_en = {
	{'E',12.702},{'T',9.056},
	{'A',8.167}, {'O',7.507},
	{'I',6.996}, {'N',6.749},
	{'S',6.327}, {'R',5.987},
	{'H',6.094}, {'D',4.253},
	{'L',4.025}, {'U',2.758},
	{'C',2.782}, {'M',2.406},
	{'F',2.228}, {'Y',1.974},
	{'W',2.360}, {'G',2.015},
	{'P',1.929}, {'B',1.492},
	{'V',0.978}, {'K',0.772},
	{'X',0.150}, {'Q',0.095},
	{'J',0.153}, {'Z',0.074}};

map<char, float> letterfreq_de = {
	{'E',16.693},{'N',9.905},
	{'I',7.812}, {'S',6.765},
	{'R',6.539}, {'A',6.506},
	{'T',6.742}, {'D',5.414},
	{'H',4.064}, {'U',3.703},
	{'L',2.825}, {'C',2.837},
	{'G',3.647}, {'M',3.005},
	{'O',2.285}, {'B',2.566},
	{'W',1.396}, {'F',2.044},
	{'K',1.879}, {'Z',1.002},
	{'P',0.944}, {'V',1.069},
	{'J',0.191}, {'Y',0.032},
	{'X',0.022}, {'Q',0.055}};

map<string, map<char, float>*> letterfreqs = {
	{"en", &letterfreq_en},
	{"de", &letterfreq_de}};
map<char, float> *letterfreq = &letterfreq_en;

char alphasq[25] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

struct CaesarResult {
	int key;
	string text;
	};

struct VigenereResult {
	string key;
	string text;
	};

struct coords {
	short row;
	short column;
	short index;
	};

string cleanString(string *text);
map<char, float> calcLetterFreq(string *text);
float calcOffset(string *text);
string restorePunctuation(string *wopunc, string *wpunc, bool encrypting);
string restoreMonographicShiftKey(string *plain, string *cipher);

string encipherCaesarString(string *plain, char key);
string decipherCaesarString(string *cipher, char key);

CaesarResult crackCaesarString(string *cipher);

string encipherVigenereString(string *plain, string *key);
string decipherVigenereString(string *cipher, string *key);

float calcIC(string *cipher);
VigenereResult crackVigenereString(string *cipher);

string encipherOTPString(string *plain, int seed);
string decipherOTPString(string *cipher, int seed);

char* genKeySquare(string *key);
string encipherPlayfairString(string *plain, char* keysq);
string decipherPlayfairString(string *cipher, char* keysq);
<|endoftext|>