1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "svx/sidebar/SelectionAnalyzer.hxx"
21 #include "svx/svdmrkv.hxx"
22 #include "svx/svdobj.hxx"
23 #include "svx/svdotext.hxx"
24 #include "svx/svdpage.hxx"
25 #include "svx/fmglob.hxx"
26 #include "svx/globl3d.hxx"
28 using sfx2::sidebar::EnumContext
;
31 namespace svx
{ namespace sidebar
{
33 EnumContext::Context
SelectionAnalyzer::GetContextForSelection_SC (const SdrMarkList
& rMarkList
)
35 EnumContext::Context eContext
= EnumContext::Context_Unknown
;
37 switch (rMarkList
.GetMarkCount())
40 // Empty selection. Return Context_Unknown to let the caller
41 // substitute it with the default context.
46 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
47 if ( pObj
->ISA(SdrTextObj
) && ((SdrTextObj
*)pObj
)->IsInEditMode() )
49 eContext
= EnumContext::Context_DrawText
;
53 const sal_uInt32 nInv
= pObj
->GetObjInventor();
54 const sal_uInt16 nObjId
= pObj
->GetObjIdentifier();
55 if (nInv
== SdrInventor
)
56 eContext
= GetContextForObjectId_SC(nObjId
);
57 else if (nInv
== FmFormInventor
)
58 eContext
= EnumContext::Context_Form
;
66 switch (GetInventorTypeFromMark(rMarkList
))
70 const sal_uInt16
nObjId (GetObjectTypeFromMark(rMarkList
));
72 eContext
= EnumContext::Context_MultiObject
;
74 eContext
= GetContextForObjectId_SC(nObjId
);
79 eContext
= EnumContext::Context_Form
;
83 eContext
= EnumContext::Context_MultiObject
;
95 EnumContext::Context
SelectionAnalyzer::GetContextForSelection_SD (
96 const SdrMarkList
& rMarkList
,
97 const ViewType eViewType
)
99 EnumContext::Context eContext
= EnumContext::Context_Unknown
;
101 // Note that some cases are handled by the caller. They rely on
103 switch (rMarkList
.GetMarkCount())
109 eContext
= EnumContext::Context_DrawPage
;
112 eContext
= EnumContext::Context_MasterPage
;
115 eContext
= EnumContext::Context_HandoutPage
;
118 eContext
= EnumContext::Context_NotesPage
;
121 eContext
= EnumContext::Context_OutlineText
;
128 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
129 if (pObj
->ISA(SdrTextObj
) && ((SdrTextObj
*)pObj
)->IsInEditMode())
131 if (pObj
->GetObjIdentifier() == OBJ_TABLE
)
133 // Let a table object take precedence over text
134 // edit mode. The panels for text editing are
135 // present for table context as well, anyway.
136 eContext
= EnumContext::Context_Table
;
139 eContext
= EnumContext::Context_DrawText
;
143 const sal_uInt32 nInv
= pObj
->GetObjInventor();
144 sal_uInt16 nObjId
= pObj
->GetObjIdentifier();
145 if (nInv
== SdrInventor
)
147 if (nObjId
== OBJ_GRUP
)
149 nObjId
= GetObjectTypeFromGroup(pObj
);
153 eContext
= GetContextForObjectId_SD(nObjId
, eViewType
);
155 else if (nInv
== E3dInventor
)
157 eContext
= EnumContext::Context_3DObject
;
159 else if (nInv
== FmFormInventor
)
161 eContext
= EnumContext::Context_Form
;
169 switch (GetInventorTypeFromMark(rMarkList
))
173 const sal_uInt16 nObjId
= GetObjectTypeFromMark(rMarkList
);
175 eContext
= EnumContext::Context_MultiObject
;
177 eContext
= GetContextForObjectId_SD(nObjId
, eViewType
);
182 eContext
= EnumContext::Context_3DObject
;
186 eContext
= EnumContext::Context_Form
;
190 eContext
= EnumContext::Context_MultiObject
;
203 EnumContext::Context
SelectionAnalyzer::GetContextForObjectId_SC (const sal_uInt16 nObjectId
)
209 case OBJ_OUTLINETEXT
:
226 case OBJ_CUSTOMSHAPE
:
228 return EnumContext::Context_Draw
;
231 return EnumContext::Context_Graphic
;
234 return EnumContext::Context_OLE
;
237 return EnumContext::Context_Media
;
241 return EnumContext::Context_Unknown
;
248 EnumContext::Context
SelectionAnalyzer::GetContextForObjectId_SD (
249 const sal_uInt16 nObjectId
,
250 const ViewType eViewType
)
269 case OBJ_CUSTOMSHAPE
:
271 return EnumContext::Context_Draw
;
274 case OBJ_OUTLINETEXT
:
277 return EnumContext::Context_TextObject
;
280 return EnumContext::Context_Graphic
;
283 return EnumContext::Context_OLE
;
286 return EnumContext::Context_Media
;
289 return EnumContext::Context_Table
;
295 return EnumContext::Context_HandoutPage
;
297 return EnumContext::Context_NotesPage
;
299 return EnumContext::Context_OutlineText
;
301 return EnumContext::Context_Unknown
;
305 return EnumContext::Context_Unknown
;
312 sal_uInt32
SelectionAnalyzer::GetInventorTypeFromMark (const SdrMarkList
& rMarkList
)
314 const sal_uLong
nMarkCount (rMarkList
.GetMarkCount());
319 SdrMark
* pMark
= rMarkList
.GetMark(0);
320 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
321 const sal_uInt32 nFirstInv
= pObj
->GetObjInventor();
323 for (sal_uLong nIndex
=1; nIndex
<nMarkCount
; ++nIndex
)
325 pMark
= rMarkList
.GetMark(nIndex
);
326 pObj
= pMark
->GetMarkedSdrObj();
327 const sal_uInt32
nInv (pObj
->GetObjInventor());
329 if (nInv
!= nFirstInv
)
339 sal_uInt16
SelectionAnalyzer::GetObjectTypeFromGroup (const SdrObject
* pObj
)
341 SdrObjList
* pObjList
= pObj
->GetSubList();
344 const sal_uLong
nSubObjCount (pObjList
->GetObjCount());
348 SdrObject
* pSubObj
= pObjList
->GetObj(0);
349 sal_uInt16 nResultType
= pSubObj
->GetObjIdentifier();
351 if (nResultType
== OBJ_GRUP
)
352 nResultType
= GetObjectTypeFromGroup(pSubObj
);
354 if (IsShapeType(nResultType
))
355 nResultType
= OBJ_CUSTOMSHAPE
;
357 if (IsTextObjType(nResultType
))
358 nResultType
= OBJ_TEXT
;
360 for (sal_uInt16 nIndex
=1; nIndex
<nSubObjCount
; ++nIndex
)
362 pSubObj
= pObjList
->GetObj(nIndex
);
363 sal_uInt16
nType (pSubObj
->GetObjIdentifier());
365 if(nType
== OBJ_GRUP
)
366 nType
= GetObjectTypeFromGroup(pSubObj
);
368 if (IsShapeType(nType
))
369 nType
= OBJ_CUSTOMSHAPE
;
371 if ((nType
== OBJ_CUSTOMSHAPE
) && (nResultType
== OBJ_TEXT
))
374 if (IsTextObjType(nType
))
377 if ((nType
== OBJ_TEXT
) && (nResultType
== OBJ_CUSTOMSHAPE
))
378 nResultType
= OBJ_TEXT
;
380 if (nType
!= nResultType
)
394 sal_uInt16
SelectionAnalyzer::GetObjectTypeFromMark (const SdrMarkList
& rMarkList
)
396 const sal_uLong
nMarkCount (rMarkList
.GetMarkCount());
401 SdrMark
* pMark
= rMarkList
.GetMark(0);
402 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
403 sal_uInt16 nResultType
= pObj
->GetObjIdentifier();
405 if(nResultType
== OBJ_GRUP
)
406 nResultType
= GetObjectTypeFromGroup(pObj
);
408 if (IsShapeType(nResultType
))
409 nResultType
= OBJ_CUSTOMSHAPE
;
411 if (IsTextObjType(nResultType
))
412 nResultType
= OBJ_TEXT
;
414 for (sal_uLong nIndex
=1; nIndex
<nMarkCount
; ++nIndex
)
416 pMark
= rMarkList
.GetMark(nIndex
);
417 pObj
= pMark
->GetMarkedSdrObj();
418 sal_uInt16 nType
= pObj
->GetObjIdentifier();
420 if(nType
== OBJ_GRUP
)
421 nType
= GetObjectTypeFromGroup(pObj
);
423 if (IsShapeType(nType
))
424 nType
= OBJ_CUSTOMSHAPE
;
426 if ((nType
== OBJ_CUSTOMSHAPE
) && (nResultType
== OBJ_TEXT
))
429 if (IsTextObjType(nType
))
432 if ((nType
== OBJ_TEXT
) && (nResultType
== OBJ_CUSTOMSHAPE
))
433 nResultType
= OBJ_TEXT
;
435 if (nType
!= nResultType
)
445 bool SelectionAnalyzer::IsShapeType (const sal_uInt16 nType
)
458 case OBJ_CUSTOMSHAPE
:
466 // #122145# adding OBJ_OLE2 since these also allow line/fill style and may
467 // be multiselected/grouped with normal draw objects, e.g. math OLE objects
479 bool SelectionAnalyzer::IsTextObjType (const sal_uInt16 nType
)
486 case OBJ_OUTLINETEXT
:
496 } } // end of namespace ::svx::sidebar
498 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */