LibreOffice Module sd (master) 1
sdview5.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sdpage.hxx>
21#include <View.hxx>
22#include <pres.hxx>
23
24#include <svx/svdpagv.hxx>
25
26namespace sd {
27
28static bool implIsMultiPresObj( PresObjKind eKind )
29{
30 switch( eKind )
31 {
39 return true;
40 default:
41 return false;
42 }
43}
44
46{
47 SdPage* pPage = nullptr;
49 if( pPV )
50 {
51 pPage = static_cast< SdPage* >( pPV->GetPage() );
52 }
53
54 return pPage;
55}
56
57// returns selected object in case there's just one object in the selection
59{
60 SdrObject* pRet = nullptr;
61 if( pPage )
62 {
63 // first try selected shape
64 if ( AreObjectsMarked() )
65 {
66 const SdrMarkList& rMarkList = GetMarkedObjectList();
67
68 if (rMarkList.GetMarkCount() == 1)
69 {
70 SdrMark* pMark = rMarkList.GetMark(0);
71 pRet = pMark->GetMarkedSdrObj();
72 }
73 }
74 }
75
76 return pRet;
77}
78
80{
81 SdPage* pPage = GetPage();
82 SdrObject* pEmptyObj = nullptr;
83
84 if ( pPage && !pPage->IsMasterPage() ) {
85 SdrObject* pObj = GetSelectedSingleObject( pPage );
86
87 if( pObj && pObj->IsEmptyPresObj() && implIsMultiPresObj( pPage->GetPresObjKind(pObj) ) )
88 pEmptyObj = pObj;
89
90 // try to find empty pres obj of same type
91 if( !pEmptyObj )
92 {
93 int nIndex = 1;
94 do
95 {
96 pEmptyObj = pPage->GetPresObj(eKind, nIndex++ );
97 }
98 while( (pEmptyObj != nullptr) && (!pEmptyObj->IsEmptyPresObj()) );
99 }
100
101 // last try to find empty pres obj of multiple type
102 if( !pEmptyObj )
103 {
104 const std::list< SdrObject* >& rShapes = pPage->GetPresentationShapeList().getList();
105
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);
110 }
111 }
112
113 return pEmptyObj;
114}
115
116}
117
118/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SdrObject * GetPresObj(PresObjKind eObjKind, int nIndex=1, bool bFuzzySearch=false)
returns the nIndex'th object from the given PresObjKind, index starts with 1
Definition: sdpage.cxx:203
sd::ShapeList & GetPresentationShapeList()
Definition: sdpage.hxx:166
PresObjKind GetPresObjKind(SdrObject *pObj) const
Definition: sdpage.cxx:2309
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
bool AreObjectsMarked() const
SdrObject * GetMarkedSdrObj() const
bool IsEmptyPresObj() const
SdrPage * GetPage() const
bool IsMasterPage() const
SdrPageView * GetSdrPageView() const
const std::list< SdrObject * > & getList() const
Definition: shapelist.hxx:60
SdrObject * GetSelectedSingleObject(SdPage const *pPage)
Definition: sdview5.cxx:58
SdrObject * GetEmptyPresentationObject(PresObjKind eKind)
Definition: sdview5.cxx:79
SdPage * GetPage()
Definition: sdview5.cxx:45
sal_Int32 nIndex
static bool implIsMultiPresObj(PresObjKind eKind)
Definition: sdview5.cxx:28
PresObjKind
Definition: pres.hxx:22