xref: /aoo4110/main/sd/source/ui/view/sdview5.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include "sdpage.hxx"
28 #include "View.hxx"
29 #include "pres.hxx"
30 
31 namespace sd {
32 
implIsMultiPresObj(PresObjKind eKind)33 static bool implIsMultiPresObj( PresObjKind eKind )
34 {
35 	switch( eKind )
36 	{
37 	case PRESOBJ_OUTLINE:
38 	case PRESOBJ_GRAPHIC:
39 	case PRESOBJ_OBJECT:
40 	case PRESOBJ_CHART:
41 	case PRESOBJ_ORGCHART:
42 	case PRESOBJ_TABLE:
43 	case PRESOBJ_IMAGE:
44 	case PRESOBJ_MEDIA:
45 		return true;
46 	default:
47 		return false;
48 	}
49 }
50 
GetEmptyPresentationObject(PresObjKind eKind)51 SdrObject* View::GetEmptyPresentationObject( PresObjKind eKind )
52 {
53 	SdrObject* pEmptyObj = 0;
54 
55 	SdrPageView*	pPV = GetSdrPageView();
56 	if( pPV )
57 	{
58 		SdPage* pPage = static_cast< SdPage* >( pPV->GetPage() );
59 		if( pPage && !pPage->IsMasterPage() )
60 		{
61 			// first try selected shape
62 			if ( AreObjectsMarked() )
63 			{
64 				/**********************************************************
65 				* Is an empty graphic object available?
66 				**********************************************************/
67 				const SdrMarkList& rMarkList = GetMarkedObjectList();
68 
69 				if (rMarkList.GetMarkCount() == 1)
70 				{
71 					SdrMark* pMark = rMarkList.GetMark(0);
72 					SdrObject* pObj = pMark->GetMarkedSdrObj();
73 
74 					if( pObj->IsEmptyPresObj() && implIsMultiPresObj( pPage->GetPresObjKind(pObj) ) )
75 						pEmptyObj = pObj;
76 				}
77 			}
78 
79 			// try to find empty pres obj of same type
80 			if( !pEmptyObj )
81 			{
82 				int nIndex = 1;
83 				do
84 				{
85 					pEmptyObj = pPage->GetPresObj(eKind, nIndex++ );
86 				}
87 				while( (pEmptyObj != 0) && (!pEmptyObj->IsEmptyPresObj()) );
88 			}
89 
90 			// last try to find empty pres obj of multiple type
91 			if( !pEmptyObj )
92 			{
93 				const std::list< SdrObject* >& rShapes = pPage->GetPresentationShapeList().getList();
94 
95     			for( std::list< SdrObject* >::const_iterator iter( rShapes.begin() ); iter != rShapes.end(); iter++ )
96     			{
97     				if( (*iter)->IsEmptyPresObj() && implIsMultiPresObj(pPage->GetPresObjKind(*iter)) )
98     				{
99 						pEmptyObj = (*iter);
100 						break;
101 					}
102 				}
103 			}
104 		}
105 	}
106 
107 	return pEmptyObj;
108 }
109 
110 }
111