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/svdmark.hxx>
22 #include <svx/svdobj.hxx>
23 #include <svx/svdotext.hxx>
24 #include <svx/svdpage.hxx>
25 #include <svx/fontworkbar.hxx>
27 using vcl::EnumContext
;
29 namespace svx::sidebar
31 EnumContext::Context
SelectionAnalyzer::GetContextForSelection_SC(const SdrMarkList
& rMarkList
)
33 EnumContext::Context eContext
= EnumContext::Context::Unknown
;
35 switch (rMarkList
.GetMarkCount())
38 // Empty selection. Return Context::Unknown to let the caller
39 // substitute it with the default context.
44 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
45 auto pTextObj
= dynamic_cast<SdrTextObj
*>(pObj
);
46 if (pTextObj
&& pTextObj
->IsInEditMode())
48 eContext
= EnumContext::Context::DrawText
;
50 else if (svx::checkForFontWork(pObj
))
52 eContext
= EnumContext::Context::DrawFontwork
;
56 const SdrInventor nInv
= pObj
->GetObjInventor();
57 const sal_uInt16 nObjId
= pObj
->GetObjIdentifier();
58 if (nInv
== SdrInventor::Default
)
59 eContext
= GetContextForObjectId_SC(nObjId
);
60 else if (nInv
== SdrInventor::FmForm
)
61 eContext
= EnumContext::Context::Form
;
69 switch (GetInventorTypeFromMark(rMarkList
))
71 case SdrInventor::Default
:
73 const sal_uInt16
nObjId(GetObjectTypeFromMark(rMarkList
));
75 eContext
= EnumContext::Context::MultiObject
;
77 eContext
= GetContextForObjectId_SC(nObjId
);
81 case SdrInventor::FmForm
:
82 eContext
= EnumContext::Context::Form
;
85 case SdrInventor::Unknown
:
86 eContext
= EnumContext::Context::MultiObject
;
98 EnumContext::Context
SelectionAnalyzer::GetContextForSelection_SD(const SdrMarkList
& rMarkList
,
99 const ViewType eViewType
)
101 EnumContext::Context eContext
= EnumContext::Context::Unknown
;
103 // Note that some cases are handled by the caller. They rely on
105 switch (rMarkList
.GetMarkCount())
110 case ViewType::Standard
:
111 eContext
= EnumContext::Context::DrawPage
;
113 case ViewType::Master
:
114 eContext
= EnumContext::Context::MasterPage
;
116 case ViewType::Handout
:
117 eContext
= EnumContext::Context::HandoutPage
;
119 case ViewType::Notes
:
120 eContext
= EnumContext::Context::NotesPage
;
127 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
128 auto pTextObj
= dynamic_cast<SdrTextObj
*>(pObj
);
129 if (pTextObj
&& pTextObj
->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
;
141 else if (svx::checkForFontWork(pObj
))
143 eContext
= EnumContext::Context::DrawFontwork
;
147 const SdrInventor nInv
= pObj
->GetObjInventor();
148 sal_uInt16 nObjId
= pObj
->GetObjIdentifier();
149 if (nInv
== SdrInventor::Default
)
151 if (nObjId
== OBJ_GRUP
)
153 nObjId
= GetObjectTypeFromGroup(pObj
);
157 eContext
= GetContextForObjectId_SD(nObjId
, eViewType
);
159 else if (nInv
== SdrInventor::E3d
)
161 eContext
= EnumContext::Context::ThreeDObject
;
163 else if (nInv
== SdrInventor::FmForm
)
165 eContext
= EnumContext::Context::Form
;
173 switch (GetInventorTypeFromMark(rMarkList
))
175 case SdrInventor::Default
:
177 const sal_uInt16 nObjId
= GetObjectTypeFromMark(rMarkList
);
179 eContext
= EnumContext::Context::MultiObject
;
181 eContext
= GetContextForObjectId_SD(nObjId
, eViewType
);
185 case SdrInventor::E3d
:
186 eContext
= EnumContext::Context::ThreeDObject
;
189 case SdrInventor::FmForm
:
190 eContext
= EnumContext::Context::Form
;
193 case SdrInventor::Unknown
:
194 eContext
= EnumContext::Context::MultiObject
;
207 EnumContext::Context
SelectionAnalyzer::GetContextForObjectId_SC(const sal_uInt16 nObjectId
)
213 case OBJ_OUTLINETEXT
:
224 case OBJ_CUSTOMSHAPE
:
226 return EnumContext::Context::Draw
;
233 return EnumContext::Context::DrawLine
;
236 return EnumContext::Context::Graphic
;
239 return EnumContext::Context::OLE
;
242 return EnumContext::Context::Media
;
245 return EnumContext::Context::Unknown
;
249 EnumContext::Context
SelectionAnalyzer::GetContextForObjectId_SD(const sal_uInt16 nObjectId
,
250 const ViewType eViewType
)
264 case OBJ_CUSTOMSHAPE
:
266 return EnumContext::Context::Draw
;
273 return EnumContext::Context::DrawLine
;
276 case OBJ_OUTLINETEXT
:
278 return EnumContext::Context::TextObject
;
281 return EnumContext::Context::Graphic
;
284 return EnumContext::Context::OLE
;
287 return EnumContext::Context::Media
;
290 return EnumContext::Context::Table
;
295 case ViewType::Handout
:
296 return EnumContext::Context::HandoutPage
;
297 case ViewType::Notes
:
298 return EnumContext::Context::NotesPage
;
300 return EnumContext::Context::Unknown
;
304 return EnumContext::Context::Unknown
;
308 SdrInventor
SelectionAnalyzer::GetInventorTypeFromMark(const SdrMarkList
& rMarkList
)
310 const size_t nMarkCount(rMarkList
.GetMarkCount());
313 return SdrInventor::Unknown
;
315 SdrMark
* pMark
= rMarkList
.GetMark(0);
316 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
317 const SdrInventor nFirstInv
= pObj
->GetObjInventor();
319 for (size_t nIndex
= 1; nIndex
< nMarkCount
; ++nIndex
)
321 pMark
= rMarkList
.GetMark(nIndex
);
322 pObj
= pMark
->GetMarkedSdrObj();
323 const SdrInventor
nInv(pObj
->GetObjInventor());
325 if (nInv
!= nFirstInv
)
326 return SdrInventor::Unknown
;
332 sal_uInt16
SelectionAnalyzer::GetObjectTypeFromGroup(const SdrObject
* pObj
)
334 SdrObjList
* pObjList
= pObj
->GetSubList();
337 const size_t nSubObjCount(pObjList
->GetObjCount());
339 if (nSubObjCount
> 0)
341 SdrObject
* pSubObj
= pObjList
->GetObj(0);
342 sal_uInt16 nResultType
= pSubObj
->GetObjIdentifier();
344 if (nResultType
== OBJ_GRUP
)
345 nResultType
= GetObjectTypeFromGroup(pSubObj
);
347 if (IsShapeType(nResultType
))
348 nResultType
= OBJ_CUSTOMSHAPE
;
350 if (IsTextObjType(nResultType
))
351 nResultType
= OBJ_TEXT
;
353 for (size_t nIndex
= 1; nIndex
< nSubObjCount
; ++nIndex
)
355 pSubObj
= pObjList
->GetObj(nIndex
);
356 sal_uInt16
nType(pSubObj
->GetObjIdentifier());
358 if (nType
== OBJ_GRUP
)
359 nType
= GetObjectTypeFromGroup(pSubObj
);
361 if (IsShapeType(nType
))
362 nType
= OBJ_CUSTOMSHAPE
;
364 if ((nType
== OBJ_CUSTOMSHAPE
) && (nResultType
== OBJ_TEXT
))
367 if (IsTextObjType(nType
))
370 if ((nType
== OBJ_TEXT
) && (nResultType
== OBJ_CUSTOMSHAPE
))
371 nResultType
= OBJ_TEXT
;
373 if (nType
!= nResultType
)
384 sal_uInt16
SelectionAnalyzer::GetObjectTypeFromMark(const SdrMarkList
& rMarkList
)
386 const size_t nMarkCount(rMarkList
.GetMarkCount());
391 SdrMark
* pMark
= rMarkList
.GetMark(0);
392 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
393 sal_uInt16 nResultType
= pObj
->GetObjIdentifier();
395 if (nResultType
== OBJ_GRUP
)
396 nResultType
= GetObjectTypeFromGroup(pObj
);
398 if (IsShapeType(nResultType
))
399 nResultType
= OBJ_CUSTOMSHAPE
;
401 if (IsTextObjType(nResultType
))
402 nResultType
= OBJ_TEXT
;
404 for (size_t nIndex
= 1; nIndex
< nMarkCount
; ++nIndex
)
406 pMark
= rMarkList
.GetMark(nIndex
);
407 pObj
= pMark
->GetMarkedSdrObj();
408 sal_uInt16 nType
= pObj
->GetObjIdentifier();
410 if (nType
== OBJ_GRUP
)
411 nType
= GetObjectTypeFromGroup(pObj
);
413 if (IsShapeType(nType
))
414 nType
= OBJ_CUSTOMSHAPE
;
416 if ((nType
== OBJ_CUSTOMSHAPE
) && (nResultType
== OBJ_TEXT
))
419 if (IsTextObjType(nType
))
422 if ((nType
== OBJ_TEXT
) && (nResultType
== OBJ_CUSTOMSHAPE
))
423 nResultType
= OBJ_TEXT
;
425 if (nType
!= nResultType
)
432 bool SelectionAnalyzer::IsShapeType(const sal_uInt16 nType
)
445 case OBJ_CUSTOMSHAPE
:
453 // #122145# adding OBJ_OLE2 since these also allow line/fill style and may
454 // be multiselected/grouped with normal draw objects, e.g. math OLE objects
463 bool SelectionAnalyzer::IsTextObjType(const sal_uInt16 nType
)
469 case OBJ_OUTLINETEXT
:
477 } // end of namespace svx::sidebar
479 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */