/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
//do not toggle multiclick selection if right clicked on the selected object or waiting for double click bool bAllowMultiClickSelectionChange = !bIsRightMouse && !bWaitingForDoubleClick;
//bAllowMultiClickSelectionChange==true -> a second click on the same object can lead to a changed selection (e.g. series -> single data point)
//get object to select:
{
m_aSelectedOID_selectOnlyIfNoDoubleClickIsFollowing = ObjectIdentifier();
//the search for the object to select starts with the hit object deepest in the grouping hierarchy (a leaf in the tree) //further we travel along the grouping hierarchy from child to parent
SdrObject* pNewObj = pDrawViewWrapper->getHitObject(rMousePos);
m_aSelectedOID = ObjectIdentifier( lcl_getObjectName( pNewObj ) );//name of pNewObj
//ignore handle only objects for hit test while( pNewObj && m_aSelectedOID.getObjectCID().match( "HandlesOnly" ) )
{
pNewObj->SetMarkProtect(true);
pNewObj = pDrawViewWrapper->getHitObject(rMousePos);
m_aSelectedOID = ObjectIdentifier( lcl_getObjectName( pNewObj ) );
}
//accept only named objects while searching for the object to select //this call may change m_aSelectedOID if ( SelectionHelper::findNamedParent( pNewObj, m_aSelectedOID, true ) )
{ //if the so far found object is a multi click object further steps are necessary while( ObjectIdentifier::isMultiClickObject( m_aSelectedOID.getObjectCID() ) )
{ bool bSameObjectAsLastSelected = ( aLastSelectedObject == m_aSelectedOID ); if( bSameObjectAsLastSelected )
{ //if the same child is clicked again don't go up further break;
} if ( ObjectIdentifier::areSiblings( aLastSelectedObject.getObjectCID(), m_aSelectedOID.getObjectCID() ) )
{ //if a sibling of the last selected object is clicked don't go up further break;
}
ObjectIdentifier aLastChild = m_aSelectedOID; if ( !SelectionHelper::findNamedParent( pNewObj, m_aSelectedOID, false ) )
{ //take the one found so far break;
} //if the last selected object is found don't go up further //but take the last child if selection change is allowed if ( aLastSelectedObject == m_aSelectedOID )
{ if( bAllowMultiClickSelectionChange )
{
m_aSelectedOID = std::move(aLastChild);
} else
m_aSelectedOID_selectOnlyIfNoDoubleClickIsFollowing = std::move(aLastChild); break;
}
}
OSL_ENSURE(m_aSelectedOID.isValid(), "somehow lost selected object");
} else
{ //maybe an additional shape was hit if ( pNewObj )
{
m_aSelectedOID = ObjectIdentifier( uno::Reference< drawing::XShape >( pNewObj->getUnoShape(), uno::UNO_QUERY ) );
} else
{
m_aSelectedOID = ObjectIdentifier();
}
}
if ( !m_aSelectedOID.isAdditionalShape() )
{
OUString aPageCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_PAGE, u"" ) );//@todo read CID from model
//check whether the diagram was hit but not selected (e.g. because it has no filling):
OUString aDiagramCID = ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM, OUString::number( 0 ) );
OUString aWallCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, u"" ) );//@todo read CID from model bool bBackGroundHit = m_aSelectedOID.getObjectCID() == aPageCID || m_aSelectedOID.getObjectCID() == aWallCID || !m_aSelectedOID.isAutoGeneratedObject(); if( bBackGroundHit )
{ //todo: if more than one diagram is available in future do check the list of all diagrams here
SdrObject* pDiagram = pDrawViewWrapper->getNamedSdrObject( aDiagramCID ); if( pDiagram )
{ if( DrawViewWrapper::IsObjectHit( pDiagram, rMousePos ) )
{
m_aSelectedOID = ObjectIdentifier( aDiagramCID );
}
}
} //check whether the legend was hit but not selected (e.g. because it has no filling): if( bBackGroundHit || m_aSelectedOID.getObjectCID() == aDiagramCID )
{
OUString aLegendCID( ObjectIdentifier::createClassifiedIdentifierForParticle( ObjectIdentifier::createParticleForLegend(nullptr) ) );//@todo read CID from model
SdrObject* pLegend = pDrawViewWrapper->getNamedSdrObject( aLegendCID ); if( pLegend )
{ if( DrawViewWrapper::IsObjectHit( pLegend, rMousePos ) )
{
m_aSelectedOID = ObjectIdentifier( aLegendCID );
}
}
}
}
}
//ignore handle only objects for hit test while( pNewObj && aRet.match("HandlesOnly") )
{
pNewObj->SetMarkProtect(true);
pNewObj = rDrawViewWrapper.getHitObject(rMPos);
aRet = lcl_getObjectName( pNewObj );
}
//accept only named objects while searching for the object to select if( !findNamedParent( pNewObj, aRet, true ) )
{
aRet.clear();
}
OUString aPageCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_PAGE, u"" ) );//@todo read CID from model //get page when nothing was hit if( aRet.isEmpty() && !pNewObj )
{
aRet = aPageCID;
}
//get diagram instead wall or page if hit inside diagram if( !aRet.isEmpty() )
{ if( aRet == aPageCID )
{
OUString aDiagramCID = ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM, OUString::number( 0 ) ); //todo: if more than one diagram is available in future do check the list of all diagrams here
SdrObject* pDiagram = rDrawViewWrapper.getNamedSdrObject( aDiagramCID ); if( pDiagram )
{ if( DrawViewWrapper::IsObjectHit( pDiagram, rMPos ) )
{
aRet = aDiagramCID;
}
}
} elseif( bGetDiagramInsteadOf_Wall )
{
OUString aWallCID( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, u"" ) );//@todo read CID from model
SdrObject* SelectionHelper::getMarkHandlesObject( SdrObject* pObj )
{ if(!pObj) return nullptr;
OUString aName( lcl_getObjectName( pObj ) ); if( aName.match("MarkHandles") || aName.match("HandlesOnly") ) return pObj; if( !aName.isEmpty() )//don't get the markhandles of a different object return nullptr;
//search for a child with name "MarkHandles" or "HandlesOnly"
SolarMutexGuard aSolarGuard;
SdrObjList* pSubList = pObj->GetSubList(); if(pSubList)
{
SdrObjListIter aIterator(pSubList, SdrIterMode::Flat); while (aIterator.IsMore())
{
SdrObject* pMarkHandles = SelectionHelper::getMarkHandlesObject( aIterator.Next() ); if( pMarkHandles ) return pMarkHandles;
}
} return nullptr;
}
SdrObject* SelectionHelper::getObjectToMark()
{ //return the selected object itself //or a specific other object if that exists
SdrObject* pObj = m_pSelectedObj;
m_pMarkObj = pObj;
//search for a child with name "MarkHandles" or "HandlesOnly" if(pObj)
{
SolarMutexGuard aSolarGuard;
SdrObjList* pSubList = pObj->GetSubList(); if(pSubList)
{
SdrObjListIter aIterator(pSubList, SdrIterMode::Flat); while (aIterator.IsMore())
{
SdrObject* pMarkHandles = SelectionHelper::getMarkHandlesObject( aIterator.Next() ); if( pMarkHandles )
{
m_pMarkObj = pMarkHandles; break;
}
}
}
} return m_pMarkObj;
}
E3dScene* SelectionHelper::getSceneToRotate( SdrObject* pObj )
{ //search whether the object or one of its children is a 3D object //if so, return the accessory 3DScene
//@todo -> more flexible handle creation //2 scenarios possible: //1. add an additional invisible shape as a child to the selected object //this child needs to be named somehow and handles need to be generated there from... //or 2. offer a central service per view where renderer and so can register for handle creation for a special shape //.. or 3. feature from drawinglayer to create handles for each shape... (bad performance... ?) ?
//scenario 1 is now used: //if a child with name MarkHandles exists //this child is marked instead of the logical selected object
/* //if a special mark object was found //that object should be used for marking only if( m_pMarkObj != m_pSelectedObj) return false;
*/ //if a special mark object was found //that object should be used to create handles from if( m_pMarkObj && m_pMarkObj != m_pSelectedObj)
{
rHdlList.Clear(); if( auto pPathObj = dynamic_cast<const SdrPathObj*>( m_pMarkObj) )
{ //if th object is a polygon //from each point a handle is generated const ::basegfx::B2DPolyPolygon& rPolyPolygon = pPathObj->GetPathPoly(); for( sal_uInt32 nN = 0; nN < rPolyPolygon.count(); nN++)
{ const ::basegfx::B2DPolygon& aPolygon(rPolyPolygon.getB2DPolygon(nN)); for( sal_uInt32 nM = 0; nM < aPolygon.count(); nM++)
{ const ::basegfx::B2DPoint aPoint(aPolygon.getB2DPoint(nM));
rHdlList.AddHdl(std::make_unique<SdrHdl>(Point(basegfx::fround<tools::Long>(aPoint.getX()), basegfx::fround<tools::Long>(aPoint.getY())), SdrHdlKind::Poly));
}
} returntrue;
} else returnfalse; //use the special MarkObject for marking
}
//@todo: //add and document good marking defaults ...
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.