2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "svx/sidebar/SelectionAnalyzer.hxx"
20 #include "svx/svdmrkv.hxx"
21 #include "svx/svdobj.hxx"
22 #include "svx/svdotext.hxx"
23 #include "svx/svdpage.hxx"
24 #include "svx/fmglob.hxx"
25 #include "svx/globl3d.hxx"
27 using sfx2::sidebar::EnumContext
;
30 namespace svx
{ namespace sidebar
{
32 EnumContext::Context
SelectionAnalyzer::GetContextForSelection_SC (const SdrMarkList
& rMarkList
)
34 EnumContext::Context eContext
= EnumContext::Context_Unknown
;
36 switch (rMarkList
.GetMarkCount())
39 // Empty selection. Return Context_Unknown to let the caller
40 // substitute it with the default context.
45 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
46 if ( pObj
->ISA(SdrTextObj
) && ((SdrTextObj
*)pObj
)->IsInEditMode() )
48 eContext
= EnumContext::Context_DrawText
;
52 const sal_uInt32 nInv
= pObj
->GetObjInventor();
53 const sal_uInt16 nObjId
= pObj
->GetObjIdentifier();
54 if (nInv
== SdrInventor
)
55 eContext
= GetContextForObjectId_SC(nObjId
);
56 else if (nInv
== FmFormInventor
)
57 eContext
= EnumContext::Context_Form
;
65 switch (GetInventorTypeFromMark(rMarkList
))
69 const sal_uInt16
nObjId (GetObjectTypeFromMark(rMarkList
));
71 eContext
= EnumContext::Context_MultiObject
;
73 eContext
= GetContextForObjectId_SC(nObjId
);
78 eContext
= EnumContext::Context_Form
;
82 eContext
= EnumContext::Context_MultiObject
;
94 EnumContext::Context
SelectionAnalyzer::GetContextForSelection_SD (
95 const SdrMarkList
& rMarkList
,
96 const ViewType eViewType
)
98 EnumContext::Context eContext
= EnumContext::Context_Unknown
;
100 // Note that some cases are handled by the caller. They rely on
102 switch (rMarkList
.GetMarkCount())
108 eContext
= EnumContext::Context_DrawPage
;
111 eContext
= EnumContext::Context_MasterPage
;
114 eContext
= EnumContext::Context_HandoutPage
;
117 eContext
= EnumContext::Context_NotesPage
;
120 eContext
= EnumContext::Context_OutlineText
;
127 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
128 if (pObj
->ISA(SdrTextObj
) && ((SdrTextObj
*)pObj
)->IsInEditMode())
130 if (pObj
->GetObjIdentifier() == OBJ_TABLE
)
132 // Let a table object take precedence over text
133 // edit mode. The panels for text editing are
134 // present for table context as well, anyway.
135 eContext
= EnumContext::Context_Table
;
138 eContext
= EnumContext::Context_DrawText
;
142 const sal_uInt32 nInv
= pObj
->GetObjInventor();
143 sal_uInt16 nObjId
= pObj
->GetObjIdentifier();
144 if (nInv
== SdrInventor
)
146 if (nObjId
== OBJ_GRUP
)
148 nObjId
= GetObjectTypeFromGroup(pObj
);
152 eContext
= GetContextForObjectId_SD(nObjId
, eViewType
);
154 else if (nInv
== E3dInventor
)
156 eContext
= EnumContext::Context_3DObject
;
158 else if (nInv
== FmFormInventor
)
160 eContext
= EnumContext::Context_Form
;
168 switch (GetInventorTypeFromMark(rMarkList
))
172 const sal_uInt16 nObjId
= GetObjectTypeFromMark(rMarkList
);
174 eContext
= EnumContext::Context_MultiObject
;
176 eContext
= GetContextForObjectId_SD(nObjId
, eViewType
);
181 eContext
= EnumContext::Context_3DObject
;
185 eContext
= EnumContext::Context_Form
;
189 eContext
= EnumContext::Context_MultiObject
;
202 EnumContext::Context
SelectionAnalyzer::GetContextForObjectId_SC (const sal_uInt16 nObjectId
)
208 case OBJ_OUTLINETEXT
:
225 case OBJ_CUSTOMSHAPE
:
227 return EnumContext::Context_Draw
;
230 return EnumContext::Context_Graphic
;
233 return EnumContext::Context_OLE
;
236 return EnumContext::Context_Media
;
240 return EnumContext::Context_Unknown
;
247 EnumContext::Context
SelectionAnalyzer::GetContextForObjectId_SD (
248 const sal_uInt16 nObjectId
,
249 const ViewType eViewType
)
268 case OBJ_CUSTOMSHAPE
:
270 return EnumContext::Context_Draw
;
273 case OBJ_OUTLINETEXT
:
276 return EnumContext::Context_TextObject
;
279 return EnumContext::Context_Graphic
;
282 return EnumContext::Context_OLE
;
285 return EnumContext::Context_Media
;
288 return EnumContext::Context_Table
;
294 return EnumContext::Context_HandoutPage
;
296 return EnumContext::Context_NotesPage
;
298 return EnumContext::Context_OutlineText
;
300 return EnumContext::Context_Unknown
;
304 return EnumContext::Context_Unknown
;
311 sal_uInt32
SelectionAnalyzer::GetInventorTypeFromMark (const SdrMarkList
& rMarkList
)
313 const sal_uLong
nMarkCount (rMarkList
.GetMarkCount());
318 SdrMark
* pMark
= rMarkList
.GetMark(0);
319 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
320 const sal_uInt32 nFirstInv
= pObj
->GetObjInventor();
322 for (sal_uLong nIndex
=1; nIndex
<nMarkCount
; ++nIndex
)
324 pMark
= rMarkList
.GetMark(nIndex
);
325 pObj
= pMark
->GetMarkedSdrObj();
326 const sal_uInt32
nInv (pObj
->GetObjInventor());
328 if (nInv
!= nFirstInv
)
338 sal_uInt16
SelectionAnalyzer::GetObjectTypeFromGroup (const SdrObject
* pObj
)
340 SdrObjList
* pObjList
= pObj
->GetSubList();
343 const sal_uLong
nSubObjCount (pObjList
->GetObjCount());
347 SdrObject
* pSubObj
= pObjList
->GetObj(0);
348 sal_uInt16 nResultType
= pSubObj
->GetObjIdentifier();
350 if (nResultType
== OBJ_GRUP
)
351 nResultType
= GetObjectTypeFromGroup(pSubObj
);
353 if (IsShapeType(nResultType
))
354 nResultType
= OBJ_CUSTOMSHAPE
;
356 if (IsTextObjType(nResultType
))
357 nResultType
= OBJ_TEXT
;
359 for (sal_uInt16 nIndex
=1; nIndex
<nSubObjCount
; ++nIndex
)
361 pSubObj
= pObjList
->GetObj(nIndex
);
362 sal_uInt16
nType (pSubObj
->GetObjIdentifier());
364 if(nType
== OBJ_GRUP
)
365 nType
= GetObjectTypeFromGroup(pSubObj
);
367 if (IsShapeType(nType
))
368 nType
= OBJ_CUSTOMSHAPE
;
370 if ((nType
== OBJ_CUSTOMSHAPE
) && (nResultType
== OBJ_TEXT
))
373 if (IsTextObjType(nType
))
376 if ((nType
== OBJ_TEXT
) && (nResultType
== OBJ_CUSTOMSHAPE
))
377 nResultType
= OBJ_TEXT
;
379 if (nType
!= nResultType
)
393 sal_uInt16
SelectionAnalyzer::GetObjectTypeFromMark (const SdrMarkList
& rMarkList
)
395 const sal_uLong
nMarkCount (rMarkList
.GetMarkCount());
400 SdrMark
* pMark
= rMarkList
.GetMark(0);
401 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
402 sal_uInt16 nResultType
= pObj
->GetObjIdentifier();
404 if(nResultType
== OBJ_GRUP
)
405 nResultType
= GetObjectTypeFromGroup(pObj
);
407 if (IsShapeType(nResultType
))
408 nResultType
= OBJ_CUSTOMSHAPE
;
410 if (IsTextObjType(nResultType
))
411 nResultType
= OBJ_TEXT
;
413 for (sal_uLong nIndex
=1; nIndex
<nMarkCount
; ++nIndex
)
415 pMark
= rMarkList
.GetMark(nIndex
);
416 pObj
= pMark
->GetMarkedSdrObj();
417 sal_uInt16 nType
= pObj
->GetObjIdentifier();
419 if(nType
== OBJ_GRUP
)
420 nType
= GetObjectTypeFromGroup(pObj
);
422 if (IsShapeType(nType
))
423 nType
= OBJ_CUSTOMSHAPE
;
425 if ((nType
== OBJ_CUSTOMSHAPE
) && (nResultType
== OBJ_TEXT
))
428 if (IsTextObjType(nType
))
431 if ((nType
== OBJ_TEXT
) && (nResultType
== OBJ_CUSTOMSHAPE
))
432 nResultType
= OBJ_TEXT
;
434 if (nType
!= nResultType
)
444 bool SelectionAnalyzer::IsShapeType (const sal_uInt16 nType
)
457 case OBJ_CUSTOMSHAPE
:
465 // #122145# adding OBJ_OLE2 since these also allow line/fill style and may
466 // be multiselected/grouped with normal draw objects, e.g. math OLE objects
478 bool SelectionAnalyzer::IsTextObjType (const sal_uInt16 nType
)
485 case OBJ_OUTLINETEXT
:
495 } } // end of namespace ::svx::sidebar