Line data Source code
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 : namespace sd {
25 :
26 0 : static bool implIsMultiPresObj( PresObjKind eKind )
27 : {
28 0 : switch( eKind )
29 : {
30 : case PRESOBJ_OUTLINE:
31 : case PRESOBJ_GRAPHIC:
32 : case PRESOBJ_OBJECT:
33 : case PRESOBJ_CHART:
34 : case PRESOBJ_ORGCHART:
35 : case PRESOBJ_TABLE:
36 : case PRESOBJ_IMAGE:
37 : case PRESOBJ_MEDIA:
38 0 : return true;
39 : default:
40 0 : return false;
41 : }
42 : }
43 :
44 0 : SdPage* View::GetPage()
45 : {
46 0 : SdPage* pPage = NULL;
47 0 : SdrPageView* pPV = GetSdrPageView();
48 0 : if( pPV )
49 : {
50 0 : pPage = static_cast< SdPage* >( pPV->GetPage() );
51 : }
52 :
53 0 : return pPage;
54 : }
55 :
56 : // returns selected object in case there's just one object in the selection
57 0 : SdrObject* View::GetSelectedSingleObject(SdPage* pPage)
58 : {
59 0 : SdrObject* pRet = NULL;
60 0 : if( pPage )
61 : {
62 : // first try selected shape
63 0 : if ( AreObjectsMarked() )
64 : {
65 0 : const SdrMarkList& rMarkList = GetMarkedObjectList();
66 :
67 0 : if (rMarkList.GetMarkCount() == 1)
68 : {
69 0 : SdrMark* pMark = rMarkList.GetMark(0);
70 0 : pRet = pMark->GetMarkedSdrObj();
71 : }
72 : }
73 : }
74 :
75 0 : return pRet;
76 : }
77 :
78 0 : SdrObject* View::GetEmptyPresentationObject( PresObjKind eKind )
79 : {
80 0 : SdPage* pPage = GetPage();
81 0 : SdrObject* pEmptyObj = NULL;
82 :
83 0 : if ( pPage && !pPage->IsMasterPage() ) {
84 0 : SdrObject* pObj = GetSelectedSingleObject( pPage );
85 :
86 0 : if( pObj && pObj->IsEmptyPresObj() && implIsMultiPresObj( pPage->GetPresObjKind(pObj) ) )
87 0 : pEmptyObj = pObj;
88 :
89 : // try to find empty pres obj of same type
90 0 : if( !pEmptyObj )
91 : {
92 0 : int nIndex = 1;
93 0 : do
94 : {
95 0 : pEmptyObj = pPage->GetPresObj(eKind, nIndex++ );
96 : }
97 0 : while( (pEmptyObj != 0) && (!pEmptyObj->IsEmptyPresObj()) );
98 : }
99 :
100 : // last try to find empty pres obj of multiple type
101 0 : if( !pEmptyObj )
102 : {
103 0 : const std::list< SdrObject* >& rShapes = pPage->GetPresentationShapeList().getList();
104 :
105 0 : for( std::list< SdrObject* >::const_iterator iter( rShapes.begin() ); iter != rShapes.end(); ++iter )
106 : {
107 0 : if( (*iter)->IsEmptyPresObj() && implIsMultiPresObj(pPage->GetPresObjKind(*iter)) )
108 : {
109 0 : pEmptyObj = (*iter);
110 0 : break;
111 : }
112 : }
113 : }
114 : }
115 :
116 0 : return pEmptyObj;
117 : }
118 :
119 66 : }
120 :
121 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|