Update git submodules
[LibreOffice.git] / sd / source / ui / view / sdview5.cxx
blobdcd9d93c77696e85e7f8a5eeb210f29a85057af5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sdpage.hxx>
21 #include <View.hxx>
22 #include <pres.hxx>
24 #include <svx/svdpagv.hxx>
26 namespace sd {
28 static bool implIsMultiPresObj( PresObjKind eKind )
30 switch( eKind )
32 case PresObjKind::Outline:
33 case PresObjKind::Graphic:
34 case PresObjKind::Object:
35 case PresObjKind::Chart:
36 case PresObjKind::OrgChart:
37 case PresObjKind::Table:
38 case PresObjKind::Media:
39 return true;
40 default:
41 return false;
45 SdPage* View::GetPage()
47 SdPage* pPage = nullptr;
48 SdrPageView* pPV = GetSdrPageView();
49 if( pPV )
51 pPage = static_cast< SdPage* >( pPV->GetPage() );
54 return pPage;
57 // returns selected object in case there's just one object in the selection
58 SdrObject* View::GetSelectedSingleObject(SdPage const * pPage)
60 SdrObject* pRet = nullptr;
61 if( pPage )
63 const SdrMarkList& rMarkList = GetMarkedObjectList();
65 // first try selected shape
66 if ( rMarkList.GetMarkCount() != 0 )
68 if (rMarkList.GetMarkCount() == 1)
70 SdrMark* pMark = rMarkList.GetMark(0);
71 pRet = pMark->GetMarkedSdrObj();
76 return pRet;
79 SdrObject* View::GetEmptyPresentationObject( PresObjKind eKind )
81 SdPage* pPage = GetPage();
82 SdrObject* pEmptyObj = nullptr;
84 if ( pPage && !pPage->IsMasterPage() ) {
85 SdrObject* pObj = GetSelectedSingleObject( pPage );
87 if( pObj && pObj->IsEmptyPresObj() && implIsMultiPresObj( pPage->GetPresObjKind(pObj) ) )
88 pEmptyObj = pObj;
90 // try to find empty pres obj of same type
91 if( !pEmptyObj )
93 int nIndex = 1;
96 pEmptyObj = pPage->GetPresObj(eKind, nIndex++ );
98 while( (pEmptyObj != nullptr) && (!pEmptyObj->IsEmptyPresObj()) );
101 // last try to find empty pres obj of multiple type
102 if( !pEmptyObj )
104 const std::list< SdrObject* >& rShapes = pPage->GetPresentationShapeList().getList();
106 auto iter = std::find_if(rShapes.begin(), rShapes.end(),
107 [&pPage](SdrObject* pShape) { return pShape->IsEmptyPresObj() && implIsMultiPresObj(pPage->GetPresObjKind(pShape)); });
108 if (iter != rShapes.end())
109 pEmptyObj = (*iter);
113 return pEmptyObj;
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */