15d39f272SZheng Fan /**************************************************************
25d39f272SZheng Fan  *
35d39f272SZheng Fan  * Licensed to the Apache Software Foundation (ASF) under one
45d39f272SZheng Fan  * or more contributor license agreements.  See the NOTICE file
55d39f272SZheng Fan  * distributed with this work for additional information
65d39f272SZheng Fan  * regarding copyright ownership.  The ASF licenses this file
75d39f272SZheng Fan  * to you under the Apache License, Version 2.0 (the
85d39f272SZheng Fan  * "License"); you may not use this file except in compliance
95d39f272SZheng Fan  * with the License.  You may obtain a copy of the License at
105d39f272SZheng Fan  *
115d39f272SZheng Fan  *   http://www.apache.org/licenses/LICENSE-2.0
125d39f272SZheng Fan  *
135d39f272SZheng Fan  * Unless required by applicable law or agreed to in writing,
145d39f272SZheng Fan  * software distributed under the License is distributed on an
155d39f272SZheng Fan  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165d39f272SZheng Fan  * KIND, either express or implied.  See the License for the
175d39f272SZheng Fan  * specific language governing permissions and limitations
185d39f272SZheng Fan  * under the License.
195d39f272SZheng Fan  *
205d39f272SZheng Fan  *************************************************************/
215d39f272SZheng Fan 
225d39f272SZheng Fan #include "precompiled_svx.hxx"
235d39f272SZheng Fan 
245d39f272SZheng Fan #include "svx/sidebar/SelectionAnalyzer.hxx"
255d39f272SZheng Fan #include "svx/svdmrkv.hxx"
265d39f272SZheng Fan #include "svx/svdobj.hxx"
2703e5ec27SOliver-Rainer Wittmann #include "svx/svdotext.hxx"
285d39f272SZheng Fan #include "svx/svdpage.hxx"
295d39f272SZheng Fan #include "svx/fmglob.hxx"
305d39f272SZheng Fan #include "svx/globl3d.hxx"
315d39f272SZheng Fan 
325d39f272SZheng Fan using sfx2::sidebar::EnumContext;
335d39f272SZheng Fan 
345d39f272SZheng Fan 
355d39f272SZheng Fan namespace svx { namespace sidebar {
365d39f272SZheng Fan 
GetContextForSelection_SC(const SdrMarkList & rMarkList)375d39f272SZheng Fan EnumContext::Context SelectionAnalyzer::GetContextForSelection_SC (const SdrMarkList& rMarkList)
385d39f272SZheng Fan {
395d39f272SZheng Fan     EnumContext::Context eContext = EnumContext::Context_Unknown;
405d39f272SZheng Fan 
415d39f272SZheng Fan     switch (rMarkList.GetMarkCount())
425d39f272SZheng Fan     {
435d39f272SZheng Fan         case 0:
445d39f272SZheng Fan             // Empty selection.  Return Context_Unknown to let the caller
455d39f272SZheng Fan             // substitute it with the default context.
465d39f272SZheng Fan             break;
475d39f272SZheng Fan 
485d39f272SZheng Fan         case 1:
495d39f272SZheng Fan         {
505d39f272SZheng Fan             SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
5103e5ec27SOliver-Rainer Wittmann             if ( pObj->ISA(SdrTextObj) && ((SdrTextObj*)pObj)->IsInEditMode() )
5203e5ec27SOliver-Rainer Wittmann             {
5303e5ec27SOliver-Rainer Wittmann                 eContext = EnumContext::Context_DrawText;
5403e5ec27SOliver-Rainer Wittmann             }
5503e5ec27SOliver-Rainer Wittmann             else
5603e5ec27SOliver-Rainer Wittmann             {
5703e5ec27SOliver-Rainer Wittmann                 const sal_uInt32 nInv = pObj->GetObjInventor();
5803e5ec27SOliver-Rainer Wittmann                 const sal_uInt16 nObjId = pObj->GetObjIdentifier();
5903e5ec27SOliver-Rainer Wittmann                 if (nInv == SdrInventor)
6003e5ec27SOliver-Rainer Wittmann                     eContext = GetContextForObjectId_SC(nObjId);
6103e5ec27SOliver-Rainer Wittmann                 else if (nInv == FmFormInventor)
6203e5ec27SOliver-Rainer Wittmann                     eContext = EnumContext::Context_Form;
6303e5ec27SOliver-Rainer Wittmann             }
645d39f272SZheng Fan             break;
655d39f272SZheng Fan         }
665d39f272SZheng Fan 
675d39f272SZheng Fan         default:
685d39f272SZheng Fan         {
695d39f272SZheng Fan             // Multi selection.
705d39f272SZheng Fan             switch (GetInventorTypeFromMark(rMarkList))
715d39f272SZheng Fan             {
725d39f272SZheng Fan                 case SdrInventor:
735d39f272SZheng Fan                 {
745d39f272SZheng Fan                     const sal_uInt16 nObjId (GetObjectTypeFromMark(rMarkList));
755d39f272SZheng Fan                     if (nObjId == 0)
765d39f272SZheng Fan                         eContext = EnumContext::Context_MultiObject;
775d39f272SZheng Fan                     else
785d39f272SZheng Fan                         eContext = GetContextForObjectId_SC(nObjId);
795d39f272SZheng Fan                     break;
805d39f272SZheng Fan                 }
815d39f272SZheng Fan 
825d39f272SZheng Fan                 case FmFormInventor:
835d39f272SZheng Fan                     eContext = EnumContext::Context_Form;
845d39f272SZheng Fan                     break;
855d39f272SZheng Fan 
865d39f272SZheng Fan                 case 0:
875d39f272SZheng Fan                     eContext = EnumContext::Context_MultiObject;
885d39f272SZheng Fan                     break;
895d39f272SZheng Fan             }
905d39f272SZheng Fan         }
915d39f272SZheng Fan     }
925d39f272SZheng Fan 
935d39f272SZheng Fan     return eContext;
945d39f272SZheng Fan }
955d39f272SZheng Fan 
965d39f272SZheng Fan 
975d39f272SZheng Fan 
985d39f272SZheng Fan 
GetContextForSelection_SD(const SdrMarkList & rMarkList,const ViewType eViewType)995d39f272SZheng Fan EnumContext::Context SelectionAnalyzer::GetContextForSelection_SD (
1005d39f272SZheng Fan     const SdrMarkList& rMarkList,
101*2a3f8a0eSAndre Fischer     const ViewType eViewType)
1025d39f272SZheng Fan {
1035d39f272SZheng Fan     EnumContext::Context eContext = EnumContext::Context_Unknown;
1045d39f272SZheng Fan 
1055d39f272SZheng Fan     // Note that some cases are handled by the caller.  They rely on
1065d39f272SZheng Fan     // sd specific data.
1075d39f272SZheng Fan     switch (rMarkList.GetMarkCount())
1085d39f272SZheng Fan     {
1095d39f272SZheng Fan         case 0:
110*2a3f8a0eSAndre Fischer             switch(eViewType)
111*2a3f8a0eSAndre Fischer             {
112*2a3f8a0eSAndre Fischer                 case VT_Standard:
113*2a3f8a0eSAndre Fischer                     eContext = EnumContext::Context_DrawPage;
114*2a3f8a0eSAndre Fischer                     break;
115*2a3f8a0eSAndre Fischer                 case VT_Master:
116*2a3f8a0eSAndre Fischer                     eContext = EnumContext::Context_MasterPage;
117*2a3f8a0eSAndre Fischer                     break;
118*2a3f8a0eSAndre Fischer                 case VT_Handout:
119*2a3f8a0eSAndre Fischer                     eContext = EnumContext::Context_HandoutPage;
120*2a3f8a0eSAndre Fischer                     break;
121*2a3f8a0eSAndre Fischer                 case VT_Notes:
122*2a3f8a0eSAndre Fischer                     eContext = EnumContext::Context_NotesPage;
123*2a3f8a0eSAndre Fischer                     break;
124*2a3f8a0eSAndre Fischer                 case VT_Outline:
125*2a3f8a0eSAndre Fischer                     eContext = EnumContext::Context_OutlineText;
126*2a3f8a0eSAndre Fischer                     break;
127*2a3f8a0eSAndre Fischer             }
1285d39f272SZheng Fan             break;
1295d39f272SZheng Fan 
1305d39f272SZheng Fan         case 1:
1315d39f272SZheng Fan         {
1325d39f272SZheng Fan             SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
133c9c475c9SAndre Fischer             if (pObj->ISA(SdrTextObj) && ((SdrTextObj*)pObj)->IsInEditMode())
1345d39f272SZheng Fan             {
135c9c475c9SAndre Fischer                 if (pObj->GetObjIdentifier() == OBJ_TABLE)
136c9c475c9SAndre Fischer                 {
137c9c475c9SAndre Fischer                     // Let a table object take precedence over text
138c9c475c9SAndre Fischer                     // edit mode.  The panels for text editing are
139c9c475c9SAndre Fischer                     // present for table context as well, anyway.
140c9c475c9SAndre Fischer                     eContext = EnumContext::Context_Table;
141c9c475c9SAndre Fischer                 }
142c9c475c9SAndre Fischer                 else
143c9c475c9SAndre Fischer                     eContext = EnumContext::Context_DrawText;
1445d39f272SZheng Fan             }
14503e5ec27SOliver-Rainer Wittmann             else
1465d39f272SZheng Fan             {
14703e5ec27SOliver-Rainer Wittmann                 const sal_uInt32 nInv = pObj->GetObjInventor();
14803e5ec27SOliver-Rainer Wittmann                 sal_uInt16 nObjId = pObj->GetObjIdentifier();
14903e5ec27SOliver-Rainer Wittmann                 if (nInv == SdrInventor)
15003e5ec27SOliver-Rainer Wittmann                 {
15103e5ec27SOliver-Rainer Wittmann                     if (nObjId == OBJ_GRUP)
15203e5ec27SOliver-Rainer Wittmann                     {
15303e5ec27SOliver-Rainer Wittmann                         nObjId = GetObjectTypeFromGroup(pObj);
15403e5ec27SOliver-Rainer Wittmann                         if (nObjId == 0)
15503e5ec27SOliver-Rainer Wittmann                             nObjId = OBJ_GRUP;
15603e5ec27SOliver-Rainer Wittmann                     }
157*2a3f8a0eSAndre Fischer                     eContext = GetContextForObjectId_SD(nObjId, eViewType);
15803e5ec27SOliver-Rainer Wittmann                 }
15903e5ec27SOliver-Rainer Wittmann                 else if (nInv == E3dInventor)
16003e5ec27SOliver-Rainer Wittmann                 {
16103e5ec27SOliver-Rainer Wittmann                     eContext = EnumContext::Context_3DObject;
16203e5ec27SOliver-Rainer Wittmann                 }
16303e5ec27SOliver-Rainer Wittmann                 else if (nInv == FmFormInventor)
16403e5ec27SOliver-Rainer Wittmann                 {
16503e5ec27SOliver-Rainer Wittmann                     eContext = EnumContext::Context_Form;
16603e5ec27SOliver-Rainer Wittmann                 }
1675d39f272SZheng Fan             }
1685d39f272SZheng Fan             break;
1695d39f272SZheng Fan         }
1705d39f272SZheng Fan 
1715d39f272SZheng Fan         default:
1725d39f272SZheng Fan         {
1735d39f272SZheng Fan             switch (GetInventorTypeFromMark(rMarkList))
1745d39f272SZheng Fan             {
1755d39f272SZheng Fan                 case SdrInventor:
1765d39f272SZheng Fan                 {
1775d39f272SZheng Fan                     const sal_uInt16 nObjId = GetObjectTypeFromMark(rMarkList);
1785d39f272SZheng Fan                     if (nObjId == 0)
1795d39f272SZheng Fan                         eContext = EnumContext::Context_MultiObject;
1805d39f272SZheng Fan                     else
181*2a3f8a0eSAndre Fischer                         eContext = GetContextForObjectId_SD(nObjId, eViewType);
1825d39f272SZheng Fan                     break;
1835d39f272SZheng Fan                 }
1845d39f272SZheng Fan 
1855d39f272SZheng Fan                 case E3dInventor:
1865d39f272SZheng Fan                     eContext = EnumContext::Context_3DObject;
1875d39f272SZheng Fan                     break;
1885d39f272SZheng Fan 
1895d39f272SZheng Fan                 case FmFormInventor:
1905d39f272SZheng Fan                     eContext = EnumContext::Context_Form;
1915d39f272SZheng Fan                     break;
1925d39f272SZheng Fan 
1935d39f272SZheng Fan                 case 0:
1945d39f272SZheng Fan                     eContext = EnumContext::Context_MultiObject;
1955d39f272SZheng Fan                     break;
1965d39f272SZheng Fan             }
1975d39f272SZheng Fan             break;
1985d39f272SZheng Fan         }
1995d39f272SZheng Fan     }
2005d39f272SZheng Fan 
2015d39f272SZheng Fan 	return eContext;
2025d39f272SZheng Fan }
2035d39f272SZheng Fan 
2045d39f272SZheng Fan 
2055d39f272SZheng Fan 
2065d39f272SZheng Fan 
GetContextForObjectId_SC(const sal_uInt16 nObjectId)2075d39f272SZheng Fan EnumContext::Context SelectionAnalyzer::GetContextForObjectId_SC (const sal_uInt16 nObjectId)
2085d39f272SZheng Fan {
2095d39f272SZheng Fan     switch (nObjectId)
2105d39f272SZheng Fan     {
2115d39f272SZheng Fan         case OBJ_CAPTION:
2125d39f272SZheng Fan         case OBJ_TITLETEXT:
2135d39f272SZheng Fan         case OBJ_OUTLINETEXT:
2145d39f272SZheng Fan         case OBJ_TEXT:
2155d39f272SZheng Fan         case OBJ_TEXTEXT:
2165d39f272SZheng Fan         case OBJ_PATHLINE:
2175d39f272SZheng Fan         case OBJ_PLIN:
2185d39f272SZheng Fan         case OBJ_FREELINE:
2195d39f272SZheng Fan         case OBJ_EDGE:
2205d39f272SZheng Fan         case OBJ_LINE:
2215d39f272SZheng Fan         case OBJ_MEASURE:
2225d39f272SZheng Fan         case OBJ_RECT:
2235d39f272SZheng Fan         case OBJ_CIRC:
2245d39f272SZheng Fan         case OBJ_FREEFILL:
2255d39f272SZheng Fan         case OBJ_PATHFILL:
2265d39f272SZheng Fan         case OBJ_POLY:
2275d39f272SZheng Fan         case OBJ_SECT:
2285d39f272SZheng Fan         case OBJ_CARC:
2295d39f272SZheng Fan         case OBJ_CCUT:
2305d39f272SZheng Fan         case OBJ_CUSTOMSHAPE:
2315d39f272SZheng Fan         case OBJ_GRUP:
2325d39f272SZheng Fan             return EnumContext::Context_Draw;
2335d39f272SZheng Fan 
2345d39f272SZheng Fan         case OBJ_GRAF:
2355d39f272SZheng Fan             return EnumContext::Context_Graphic;
2365d39f272SZheng Fan 
2375d39f272SZheng Fan         case OBJ_OLE2:
2385d39f272SZheng Fan             return EnumContext::Context_OLE;
2395d39f272SZheng Fan 
2405d39f272SZheng Fan         case OBJ_MEDIA:
2415d39f272SZheng Fan             return EnumContext::Context_Media;
2425d39f272SZheng Fan             break;
2435d39f272SZheng Fan 
2445d39f272SZheng Fan         default:
2455d39f272SZheng Fan             return EnumContext::Context_Unknown;
2465d39f272SZheng Fan     }
2475d39f272SZheng Fan }
2485d39f272SZheng Fan 
2495d39f272SZheng Fan 
2505d39f272SZheng Fan 
2515d39f272SZheng Fan 
GetContextForObjectId_SD(const sal_uInt16 nObjectId,const ViewType eViewType)2525d39f272SZheng Fan EnumContext::Context SelectionAnalyzer::GetContextForObjectId_SD (
2535d39f272SZheng Fan     const sal_uInt16 nObjectId,
254*2a3f8a0eSAndre Fischer     const ViewType eViewType)
2555d39f272SZheng Fan {
2565d39f272SZheng Fan 	switch (nObjectId)
2575d39f272SZheng Fan 	{
2585d39f272SZheng Fan 		case OBJ_CAPTION:
2595d39f272SZheng Fan 		case OBJ_PATHLINE:
2605d39f272SZheng Fan 		case OBJ_PLIN:
2615d39f272SZheng Fan 		case OBJ_FREELINE:
2625d39f272SZheng Fan 		case OBJ_EDGE:
2635d39f272SZheng Fan 		case OBJ_LINE:
2645d39f272SZheng Fan 		case OBJ_MEASURE:
2655d39f272SZheng Fan 		case OBJ_RECT:
2665d39f272SZheng Fan 		case OBJ_CIRC:
2675d39f272SZheng Fan 		case OBJ_FREEFILL:
2685d39f272SZheng Fan 		case OBJ_PATHFILL:
2695d39f272SZheng Fan 		case OBJ_POLY:
2705d39f272SZheng Fan 		case OBJ_SECT:
2715d39f272SZheng Fan 		case OBJ_CARC:
2725d39f272SZheng Fan 		case OBJ_CCUT:
2735d39f272SZheng Fan 		case OBJ_CUSTOMSHAPE:
2745d39f272SZheng Fan 		case OBJ_GRUP:
2755d39f272SZheng Fan 			return EnumContext::Context_Draw;
2765d39f272SZheng Fan 
2775d39f272SZheng Fan 		case OBJ_TITLETEXT:
2785d39f272SZheng Fan 		case OBJ_OUTLINETEXT:
2795d39f272SZheng Fan 		case OBJ_TEXT:
2805d39f272SZheng Fan 		case OBJ_TEXTEXT:
2815d39f272SZheng Fan 			return EnumContext::Context_TextObject;
2825d39f272SZheng Fan 
2835d39f272SZheng Fan 		case OBJ_GRAF:
2845d39f272SZheng Fan 			return EnumContext::Context_Graphic;
2855d39f272SZheng Fan 
2865d39f272SZheng Fan 		case OBJ_OLE2:
2875d39f272SZheng Fan 			return EnumContext::Context_OLE;
2885d39f272SZheng Fan 
2895d39f272SZheng Fan 		case OBJ_MEDIA:
2905d39f272SZheng Fan 			return EnumContext::Context_Media;
2915d39f272SZheng Fan 
2925d39f272SZheng Fan 		case OBJ_TABLE:
2935d39f272SZheng Fan 			return EnumContext::Context_Table;
2945d39f272SZheng Fan 
2955d39f272SZheng Fan 		case OBJ_PAGE:
296*2a3f8a0eSAndre Fischer             switch (eViewType)
297*2a3f8a0eSAndre Fischer             {
298*2a3f8a0eSAndre Fischer                 case VT_Handout:
299*2a3f8a0eSAndre Fischer                     return EnumContext::Context_HandoutPage;
300*2a3f8a0eSAndre Fischer                 case VT_Notes:
301*2a3f8a0eSAndre Fischer                     return EnumContext::Context_NotesPage;
302*2a3f8a0eSAndre Fischer                 case VT_Outline:
303*2a3f8a0eSAndre Fischer                     return EnumContext::Context_OutlineText;
304*2a3f8a0eSAndre Fischer                 default:
305*2a3f8a0eSAndre Fischer                     return EnumContext::Context_Unknown;
306*2a3f8a0eSAndre Fischer             }
3075d39f272SZheng Fan 
3085d39f272SZheng Fan         default:
3095d39f272SZheng Fan             return EnumContext::Context_Unknown;
3105d39f272SZheng Fan 	}
3115d39f272SZheng Fan }
3125d39f272SZheng Fan 
3135d39f272SZheng Fan 
3145d39f272SZheng Fan 
3155d39f272SZheng Fan 
GetInventorTypeFromMark(const SdrMarkList & rMarkList)3165d39f272SZheng Fan sal_uInt32 SelectionAnalyzer::GetInventorTypeFromMark (const SdrMarkList& rMarkList)
3175d39f272SZheng Fan {
3185d39f272SZheng Fan     const sal_uLong nMarkCount (rMarkList.GetMarkCount());
3195d39f272SZheng Fan 
3205d39f272SZheng Fan     if (nMarkCount < 1)
3215d39f272SZheng Fan         return 0;
3225d39f272SZheng Fan 
3235d39f272SZheng Fan     SdrMark* pMark = rMarkList.GetMark(0);
3245d39f272SZheng Fan     SdrObject* pObj = pMark->GetMarkedSdrObj();
3255d39f272SZheng Fan     const sal_uInt32 nFirstInv = pObj->GetObjInventor();
3265d39f272SZheng Fan 
3275d39f272SZheng Fan     for (sal_uLong nIndex=1; nIndex<nMarkCount; ++nIndex)
3285d39f272SZheng Fan     {
3295d39f272SZheng Fan         pMark = rMarkList.GetMark(nIndex);
3305d39f272SZheng Fan         pObj = pMark->GetMarkedSdrObj();
3315d39f272SZheng Fan         const sal_uInt32 nInv (pObj->GetObjInventor());
3325d39f272SZheng Fan 
3335d39f272SZheng Fan         if (nInv != nFirstInv)
3345d39f272SZheng Fan             return 0;
3355d39f272SZheng Fan     }
3365d39f272SZheng Fan 
3375d39f272SZheng Fan     return nFirstInv;
3385d39f272SZheng Fan }
3395d39f272SZheng Fan 
3405d39f272SZheng Fan 
3415d39f272SZheng Fan 
3425d39f272SZheng Fan 
GetObjectTypeFromGroup(const SdrObject * pObj)3435d39f272SZheng Fan sal_uInt16 SelectionAnalyzer::GetObjectTypeFromGroup (const SdrObject* pObj)
3445d39f272SZheng Fan {
3455d39f272SZheng Fan     SdrObjList* pObjList = pObj->GetSubList();
3465d39f272SZheng Fan     if (pObjList)
3475d39f272SZheng Fan     {
3485d39f272SZheng Fan         const sal_uLong nSubObjCount (pObjList->GetObjCount());
3495d39f272SZheng Fan 
3505d39f272SZheng Fan         if (nSubObjCount>0)
3515d39f272SZheng Fan         {
3525d39f272SZheng Fan             SdrObject* pObj = pObjList->GetObj(0);
3535d39f272SZheng Fan             sal_uInt16 nResultType = pObj->GetObjIdentifier();
3545d39f272SZheng Fan 
3555d39f272SZheng Fan             if (nResultType == OBJ_GRUP)
3565d39f272SZheng Fan                 nResultType = GetObjectTypeFromGroup(pObj);
3575d39f272SZheng Fan 
3585d39f272SZheng Fan             if (IsShapeType(nResultType))
3595d39f272SZheng Fan                 nResultType = OBJ_CUSTOMSHAPE;
3605d39f272SZheng Fan 
3615d39f272SZheng Fan             if (IsTextObjType(nResultType))
3625d39f272SZheng Fan                 nResultType = OBJ_TEXT;
3635d39f272SZheng Fan 
3645d39f272SZheng Fan             for (sal_uInt16 nIndex=1; nIndex<nSubObjCount; ++nIndex)
3655d39f272SZheng Fan             {
3665d39f272SZheng Fan                 pObj = pObjList->GetObj(nIndex);
3675d39f272SZheng Fan                 sal_uInt16 nType (pObj->GetObjIdentifier());
3685d39f272SZheng Fan 
3695d39f272SZheng Fan                 if(nType == OBJ_GRUP)
3705d39f272SZheng Fan                     nType = GetObjectTypeFromGroup(pObj);
3715d39f272SZheng Fan 
3725d39f272SZheng Fan                 if (IsShapeType(nType))
3735d39f272SZheng Fan                     nType = OBJ_CUSTOMSHAPE;
3745d39f272SZheng Fan 
3755d39f272SZheng Fan                 if ((nType == OBJ_CUSTOMSHAPE) && (nResultType == OBJ_TEXT))
3765d39f272SZheng Fan                     nType = OBJ_TEXT;
3775d39f272SZheng Fan 
3785d39f272SZheng Fan                 if (IsTextObjType(nType))
3795d39f272SZheng Fan                     nType = OBJ_TEXT;
3805d39f272SZheng Fan 
3815d39f272SZheng Fan                 if ((nType == OBJ_TEXT) && (nResultType == OBJ_CUSTOMSHAPE))
3825d39f272SZheng Fan                     nResultType = OBJ_TEXT;
3835d39f272SZheng Fan 
3845d39f272SZheng Fan                 if (nType != nResultType)
3855d39f272SZheng Fan                     return 0;
3865d39f272SZheng Fan             }
3875d39f272SZheng Fan 
3885d39f272SZheng Fan             return nResultType;
3895d39f272SZheng Fan         }
3905d39f272SZheng Fan     }
3915d39f272SZheng Fan 
3925d39f272SZheng Fan     return 0;
3935d39f272SZheng Fan }
3945d39f272SZheng Fan 
3955d39f272SZheng Fan 
3965d39f272SZheng Fan 
3975d39f272SZheng Fan 
GetObjectTypeFromMark(const SdrMarkList & rMarkList)3985d39f272SZheng Fan sal_uInt16  SelectionAnalyzer::GetObjectTypeFromMark (const SdrMarkList& rMarkList)
3995d39f272SZheng Fan {
4005d39f272SZheng Fan     const sal_uLong nMarkCount (rMarkList.GetMarkCount());
4015d39f272SZheng Fan 
4025d39f272SZheng Fan     if (nMarkCount < 1)
4035d39f272SZheng Fan         return 0;
4045d39f272SZheng Fan 
4055d39f272SZheng Fan     SdrMark* pMark = rMarkList.GetMark(0);
4065d39f272SZheng Fan     SdrObject* pObj = pMark->GetMarkedSdrObj();
4075d39f272SZheng Fan     sal_uInt16 nResultType = pObj->GetObjIdentifier();
4085d39f272SZheng Fan 
4095d39f272SZheng Fan     if(nResultType == OBJ_GRUP)
4105d39f272SZheng Fan         nResultType = GetObjectTypeFromGroup(pObj);
4115d39f272SZheng Fan 
4125d39f272SZheng Fan     if (IsShapeType(nResultType))
4135d39f272SZheng Fan         nResultType = OBJ_CUSTOMSHAPE;
4145d39f272SZheng Fan 
4155d39f272SZheng Fan     if (IsTextObjType(nResultType))
4165d39f272SZheng Fan         nResultType = OBJ_TEXT;
4175d39f272SZheng Fan 
4185d39f272SZheng Fan     for (sal_uLong nIndex=1; nIndex<nMarkCount; ++nIndex)
4195d39f272SZheng Fan     {
4205d39f272SZheng Fan         pMark = rMarkList.GetMark(nIndex);
4215d39f272SZheng Fan         pObj = pMark->GetMarkedSdrObj();
4225d39f272SZheng Fan         sal_uInt16 nType = pObj->GetObjIdentifier();
4235d39f272SZheng Fan 
4245d39f272SZheng Fan         if(nType == OBJ_GRUP)
4255d39f272SZheng Fan             nType = GetObjectTypeFromGroup(pObj);
4265d39f272SZheng Fan 
4275d39f272SZheng Fan         if (IsShapeType(nType))
4285d39f272SZheng Fan             nType = OBJ_CUSTOMSHAPE;
4295d39f272SZheng Fan 
4305d39f272SZheng Fan         if ((nType == OBJ_CUSTOMSHAPE) && (nResultType == OBJ_TEXT))
4315d39f272SZheng Fan             nType = OBJ_TEXT;
4325d39f272SZheng Fan 
4335d39f272SZheng Fan         if (IsTextObjType(nType))
4345d39f272SZheng Fan             nType = OBJ_TEXT;
4355d39f272SZheng Fan 
4365d39f272SZheng Fan         if ((nType == OBJ_TEXT) && (nResultType == OBJ_CUSTOMSHAPE))
4375d39f272SZheng Fan             nResultType = OBJ_TEXT;
4385d39f272SZheng Fan 
4395d39f272SZheng Fan         if (nType != nResultType)
4405d39f272SZheng Fan             return 0;
4415d39f272SZheng Fan     }
4425d39f272SZheng Fan 
4435d39f272SZheng Fan     return nResultType;
4445d39f272SZheng Fan }
4455d39f272SZheng Fan 
4465d39f272SZheng Fan 
4475d39f272SZheng Fan 
4485d39f272SZheng Fan 
IsShapeType(const sal_uInt16 nType)4495d39f272SZheng Fan bool SelectionAnalyzer::IsShapeType (const sal_uInt16 nType)
4505d39f272SZheng Fan {
4515d39f272SZheng Fan 	switch (nType)
4525d39f272SZheng Fan     {
4535d39f272SZheng Fan 		case OBJ_LINE:
4545d39f272SZheng Fan 		case OBJ_CARC:
4555d39f272SZheng Fan 		case OBJ_PLIN:
4565d39f272SZheng Fan 		case OBJ_PATHLINE:
4575d39f272SZheng Fan 		case OBJ_RECT:
4585d39f272SZheng Fan 		case OBJ_CIRC:
4595d39f272SZheng Fan 		case OBJ_SECT:
4605d39f272SZheng Fan 		case OBJ_CCUT:
4615d39f272SZheng Fan 		case OBJ_PATHFILL:
4625d39f272SZheng Fan 		case OBJ_CUSTOMSHAPE:
4635d39f272SZheng Fan 		case OBJ_CAPTION:
4645d39f272SZheng Fan 		case OBJ_MEASURE:
4655d39f272SZheng Fan 		case OBJ_EDGE:
4665d39f272SZheng Fan 		case OBJ_POLY:
4675d39f272SZheng Fan 		case OBJ_FREELINE:
4685d39f272SZheng Fan 		case OBJ_FREEFILL:
46918eb8d65SArmin Le Grand 
47018eb8d65SArmin Le Grand         // #122145# adding OBJ_OLE2 since these also allow line/fill style and may
47118eb8d65SArmin Le Grand         // be multiselected/grouped with normal draw objects, e.g. math OLE objects
47218eb8d65SArmin Le Grand         case OBJ_OLE2:
4735d39f272SZheng Fan 			return true;
4745d39f272SZheng Fan 
4755d39f272SZheng Fan 		default:
4765d39f272SZheng Fan             return false;
4775d39f272SZheng Fan 	}
4785d39f272SZheng Fan }
4795d39f272SZheng Fan 
4805d39f272SZheng Fan 
4815d39f272SZheng Fan 
4825d39f272SZheng Fan 
IsTextObjType(const sal_uInt16 nType)4835d39f272SZheng Fan bool SelectionAnalyzer::IsTextObjType (const sal_uInt16 nType)
4845d39f272SZheng Fan {
4855d39f272SZheng Fan 	switch(nType)
4865d39f272SZheng Fan     {
4875d39f272SZheng Fan 		case OBJ_TEXT:
4885d39f272SZheng Fan 		case OBJ_TEXTEXT:
4895d39f272SZheng Fan 		case OBJ_TITLETEXT:
4905d39f272SZheng Fan 		case OBJ_OUTLINETEXT:
4915d39f272SZheng Fan 			return true;
4925d39f272SZheng Fan 
4935d39f272SZheng Fan 		default:
4945d39f272SZheng Fan             return false;
4955d39f272SZheng Fan 	}
4965d39f272SZheng Fan }
4975d39f272SZheng Fan 
4985d39f272SZheng Fan 
4995d39f272SZheng Fan 
5005d39f272SZheng Fan } } // end of namespace ::svx::sidebar
501