xref: /trunk/main/sd/source/ui/view/sdview5.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb) !
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "sdpage.hxx"
32 #include "View.hxx"
33 #include "pres.hxx"
34 
35 namespace sd {
36 
37 static bool implIsMultiPresObj( PresObjKind eKind )
38 {
39     switch( eKind )
40     {
41     case PRESOBJ_OUTLINE:
42     case PRESOBJ_GRAPHIC:
43     case PRESOBJ_OBJECT:
44     case PRESOBJ_CHART:
45     case PRESOBJ_ORGCHART:
46     case PRESOBJ_TABLE:
47     case PRESOBJ_IMAGE:
48     case PRESOBJ_MEDIA:
49         return true;
50     default:
51         return false;
52     }
53 }
54 
55 SdrObject* View::GetEmptyPresentationObject( PresObjKind eKind )
56 {
57     SdrObject* pEmptyObj = 0;
58 
59     SdrPageView*    pPV = GetSdrPageView();
60     if( pPV )
61     {
62         SdPage* pPage = static_cast< SdPage* >( pPV->GetPage() );
63         if( pPage && !pPage->IsMasterPage() )
64         {
65             // first try selected shape
66             if ( AreObjectsMarked() )
67             {
68                 /**********************************************************
69                 * Is an empty graphic object available?
70                 **********************************************************/
71                 const SdrMarkList& rMarkList = GetMarkedObjectList();
72 
73                 if (rMarkList.GetMarkCount() == 1)
74                 {
75                     SdrMark* pMark = rMarkList.GetMark(0);
76                     SdrObject* pObj = pMark->GetMarkedSdrObj();
77 
78                     if( pObj->IsEmptyPresObj() && implIsMultiPresObj( pPage->GetPresObjKind(pObj) ) )
79                         pEmptyObj = pObj;
80                 }
81             }
82 
83             // try to find empty pres obj of same type
84             if( !pEmptyObj )
85             {
86                 int nIndex = 1;
87                 do
88                 {
89                     pEmptyObj = pPage->GetPresObj(eKind, nIndex++ );
90                 }
91                 while( (pEmptyObj != 0) && (!pEmptyObj->IsEmptyPresObj()) );
92             }
93 
94             // last try to find empty pres obj of multiple type
95             if( !pEmptyObj )
96             {
97                 const std::list< SdrObject* >& rShapes = pPage->GetPresentationShapeList().getList();
98 
99                 for( std::list< SdrObject* >::const_iterator iter( rShapes.begin() ); iter != rShapes.end(); iter++ )
100                 {
101                     if( (*iter)->IsEmptyPresObj() && implIsMultiPresObj(pPage->GetPresObjKind(*iter)) )
102                     {
103                         pEmptyObj = (*iter);
104                         break;
105                     }
106                 }
107             }
108         }
109     }
110 
111     return pEmptyObj;
112 }
113 
114 }
115