LibreOffice Module svx (master) 1
SelectionAnalyzer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
26
28
29namespace svx::sidebar
30{
31EnumContext::Context SelectionAnalyzer::GetContextForSelection_SC(const SdrMarkList& rMarkList)
32{
33 EnumContext::Context eContext = EnumContext::Context::Unknown;
34
35 switch (rMarkList.GetMarkCount())
36 {
37 case 0:
38 // Empty selection. Return Context::Unknown to let the caller
39 // substitute it with the default context.
40 break;
41
42 case 1:
43 {
44 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
45 auto pTextObj = DynCastSdrTextObj(pObj);
46 if (pTextObj && pTextObj->IsInEditMode())
47 {
48 eContext = EnumContext::Context::DrawText;
49 }
50 else if (svx::checkForFontWork(pObj))
51 {
52 eContext = EnumContext::Context::DrawFontwork;
53 }
54 else
55 {
56 const SdrInventor nInv = pObj->GetObjInventor();
57 const SdrObjKind nObjId = pObj->GetObjIdentifier();
58 if (nInv == SdrInventor::Default)
59 eContext = GetContextForObjectId_SC(nObjId);
60 else if (nInv == SdrInventor::FmForm)
61 eContext = EnumContext::Context::Form;
62 }
63 break;
64 }
65
66 default:
67 {
68 // Multi selection.
69 switch (GetInventorTypeFromMark(rMarkList))
70 {
72 {
73 const SdrObjKind nObjId(GetObjectTypeFromMark(rMarkList));
74 if (nObjId == SdrObjKind::NONE)
75 eContext = EnumContext::Context::MultiObject;
76 else
77 eContext = GetContextForObjectId_SC(nObjId);
78 break;
79 }
80
82 eContext = EnumContext::Context::Form;
83 break;
84
86 eContext = EnumContext::Context::MultiObject;
87 break;
88
89 default:
90 break;
91 }
92 }
93 }
94
95 return eContext;
96}
97
98EnumContext::Context SelectionAnalyzer::GetContextForSelection_SD(const SdrMarkList& rMarkList,
99 const ViewType eViewType)
100{
101 EnumContext::Context eContext = EnumContext::Context::Unknown;
102
103 // Note that some cases are handled by the caller. They rely on
104 // sd specific data.
105 switch (rMarkList.GetMarkCount())
106 {
107 case 0:
108 switch (eViewType)
109 {
111 eContext = EnumContext::Context::DrawPage;
112 break;
113 case ViewType::Master:
114 eContext = EnumContext::Context::MasterPage;
115 break;
117 eContext = EnumContext::Context::HandoutPage;
118 break;
119 case ViewType::Notes:
120 eContext = EnumContext::Context::NotesPage;
121 break;
122 }
123 break;
124
125 case 1:
126 {
127 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
128 auto pTextObj = DynCastSdrTextObj(pObj);
129 if (pTextObj && pTextObj->IsInEditMode())
130 {
131 if (pObj->GetObjIdentifier() == SdrObjKind::Table)
132 {
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;
137 }
138 else
139 eContext = EnumContext::Context::DrawText;
140 }
141 else if (svx::checkForFontWork(pObj))
142 {
143 eContext = EnumContext::Context::DrawFontwork;
144 }
145 else
146 {
147 const SdrInventor nInv = pObj->GetObjInventor();
148 SdrObjKind nObjId = pObj->GetObjIdentifier();
149 if (nInv == SdrInventor::Default)
150 {
151 if (nObjId == SdrObjKind::Group)
152 {
153 nObjId = GetObjectTypeFromGroup(pObj);
154 if (nObjId == SdrObjKind::NONE)
155 nObjId = SdrObjKind::Group;
156 }
157 eContext = GetContextForObjectId_SD(nObjId, eViewType);
158 }
159 else if (nInv == SdrInventor::E3d)
160 {
161 eContext = EnumContext::Context::ThreeDObject;
162 }
163 else if (nInv == SdrInventor::FmForm)
164 {
165 eContext = EnumContext::Context::Form;
166 }
167 }
168 break;
169 }
170
171 default:
172 {
173 switch (GetInventorTypeFromMark(rMarkList))
174 {
176 {
177 const SdrObjKind nObjId = GetObjectTypeFromMark(rMarkList);
178 if (nObjId == SdrObjKind::NONE)
179 eContext = EnumContext::Context::MultiObject;
180 else
181 eContext = GetContextForObjectId_SD(nObjId, eViewType);
182 break;
183 }
184
185 case SdrInventor::E3d:
186 eContext = EnumContext::Context::ThreeDObject;
187 break;
188
190 eContext = EnumContext::Context::Form;
191 break;
192
194 eContext = EnumContext::Context::MultiObject;
195 break;
196
197 default:
198 break;
199 }
200 break;
201 }
202 }
203
204 return eContext;
205}
206
207EnumContext::Context SelectionAnalyzer::GetContextForObjectId_SC(const SdrObjKind nObjectId)
208{
209 switch (nObjectId)
210 {
214 case SdrObjKind::Text:
226 return EnumContext::Context::Draw;
227
231 case SdrObjKind::Line:
232 case SdrObjKind::Edge:
233 return EnumContext::Context::DrawLine;
234
236 return EnumContext::Context::Graphic;
237
238 case SdrObjKind::OLE2:
239 return EnumContext::Context::OLE;
240
242 return EnumContext::Context::Media;
243
244 default:
245 return EnumContext::Context::Unknown;
246 }
247}
248
249EnumContext::Context SelectionAnalyzer::GetContextForObjectId_SD(const SdrObjKind nObjectId,
250 const ViewType eViewType)
251{
252 switch (nObjectId)
253 {
266 return EnumContext::Context::Draw;
267
268 case SdrObjKind::Edge:
272 case SdrObjKind::Line:
273 return EnumContext::Context::DrawLine;
274
277 case SdrObjKind::Text:
278 return EnumContext::Context::TextObject;
279
281 return EnumContext::Context::Graphic;
282
283 case SdrObjKind::OLE2:
284 return EnumContext::Context::OLE;
285
287 return EnumContext::Context::Media;
288
290 return EnumContext::Context::Table;
291
292 case SdrObjKind::Page:
293 switch (eViewType)
294 {
296 return EnumContext::Context::HandoutPage;
297 case ViewType::Notes:
298 return EnumContext::Context::NotesPage;
299 default:
300 return EnumContext::Context::Unknown;
301 }
302
303 default:
304 return EnumContext::Context::Unknown;
305 }
306}
307
309{
310 const size_t nMarkCount(rMarkList.GetMarkCount());
311
312 if (nMarkCount < 1)
314
315 SdrMark* pMark = rMarkList.GetMark(0);
316 SdrObject* pObj = pMark->GetMarkedSdrObj();
317 const SdrInventor nFirstInv = pObj->GetObjInventor();
318
319 for (size_t nIndex = 1; nIndex < nMarkCount; ++nIndex)
320 {
321 pMark = rMarkList.GetMark(nIndex);
322 pObj = pMark->GetMarkedSdrObj();
323 const SdrInventor nInv(pObj->GetObjInventor());
324
325 if (nInv != nFirstInv)
327 }
328
329 return nFirstInv;
330}
331
333{
334 SdrObjList* pObjList = pObj->GetSubList();
335 if (pObjList)
336 {
337 const size_t nSubObjCount(pObjList->GetObjCount());
338
339 if (nSubObjCount > 0)
340 {
341 SdrObject* pSubObj = pObjList->GetObj(0);
342 SdrObjKind nResultType = pSubObj->GetObjIdentifier();
343
344 if (nResultType == SdrObjKind::Group)
345 nResultType = GetObjectTypeFromGroup(pSubObj);
346
347 if (IsShapeType(nResultType))
348 nResultType = SdrObjKind::CustomShape;
349
350 if (IsTextObjType(nResultType))
351 nResultType = SdrObjKind::Text;
352
353 for (size_t nIndex = 1; nIndex < nSubObjCount; ++nIndex)
354 {
355 pSubObj = pObjList->GetObj(nIndex);
357
359 nType = GetObjectTypeFromGroup(pSubObj);
360
361 if (IsShapeType(nType))
363
364 if ((nType == SdrObjKind::CustomShape) && (nResultType == SdrObjKind::Text))
366
367 if (IsTextObjType(nType))
369
370 if ((nType == SdrObjKind::Text) && (nResultType == SdrObjKind::CustomShape))
371 nResultType = SdrObjKind::Text;
372
373 if (nType != nResultType)
374 return SdrObjKind::NONE;
375 }
376
377 return nResultType;
378 }
379 }
380
381 return SdrObjKind::NONE;
382}
383
385{
386 const size_t nMarkCount(rMarkList.GetMarkCount());
387
388 if (nMarkCount < 1)
389 return SdrObjKind::NONE;
390
391 SdrMark* pMark = rMarkList.GetMark(0);
392 SdrObject* pObj = pMark->GetMarkedSdrObj();
393 SdrObjKind nResultType = pObj->GetObjIdentifier();
394
395 if (nResultType == SdrObjKind::Group)
396 nResultType = GetObjectTypeFromGroup(pObj);
397
398 if (IsShapeType(nResultType))
399 nResultType = SdrObjKind::CustomShape;
400
401 if (IsTextObjType(nResultType))
402 nResultType = SdrObjKind::Text;
403
404 for (size_t nIndex = 1; nIndex < nMarkCount; ++nIndex)
405 {
406 pMark = rMarkList.GetMark(nIndex);
407 pObj = pMark->GetMarkedSdrObj();
409
412
413 if (IsShapeType(nType))
415
416 if ((nType == SdrObjKind::CustomShape) && (nResultType == SdrObjKind::Text))
418
419 if (IsTextObjType(nType))
421
422 if ((nType == SdrObjKind::Text) && (nResultType == SdrObjKind::CustomShape))
423 nResultType = SdrObjKind::Text;
424
425 if (nType != nResultType)
426 return SdrObjKind::NONE;
427 }
428
429 return nResultType;
430}
431
433{
434 switch (nType)
435 {
436 case SdrObjKind::Line:
448 case SdrObjKind::Edge:
452
453 // #122145# adding SdrObjKind::OLE2 since these also allow line/fill style and may
454 // be multiselected/grouped with normal draw objects, e.g. math OLE objects
455 case SdrObjKind::OLE2:
456 return true;
457
458 default:
459 return false;
460 }
461}
462
464{
465 switch (nType)
466 {
467 case SdrObjKind::Text:
470 return true;
471
472 default:
473 return false;
474 }
475}
476
477} // end of namespace svx::sidebar
478
479/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
size_t GetMarkCount() const
Definition: svdmark.hxx:178
SdrMark * GetMark(size_t nNum) const
Definition: svdmark.cxx:230
Everything a View needs to know about a selected object.
Definition: svdmark.hxx:45
SdrObject * GetMarkedSdrObj() const
Definition: svdmark.hxx:68
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:785
size_t GetObjCount() const
Definition: svdpage.cxx:779
Abstract DrawObject.
Definition: svdobj.hxx:260
virtual SdrInventor GetObjInventor() const
Definition: svdobj.cxx:621
virtual SdrObjList * GetSubList() const
Definition: svdobj.cxx:717
virtual SdrObjKind GetObjIdentifier() const
Definition: svdobj.cxx:626
static bool IsTextObjType(const SdrObjKind nType)
static vcl::EnumContext::Context GetContextForObjectId_SD(const SdrObjKind nObjectId, const ViewType eViewType)
static bool IsShapeType(const SdrObjKind nType)
static vcl::EnumContext::Context GetContextForObjectId_SC(const SdrObjKind nObjectId)
static SdrInventor GetInventorTypeFromMark(const SdrMarkList &rMarkList)
static vcl::EnumContext::Context GetContextForSelection_SC(const SdrMarkList &rMarkList)
static SdrObjKind GetObjectTypeFromGroup(const SdrObject *pObj)
static SdrObjKind GetObjectTypeFromMark(const SdrMarkList &rMarkList)
static vcl::EnumContext::Context GetContextForSelection_SD(const SdrMarkList &rMarkList, const ViewType eViewType)
sal_Int32 nIndex
bool checkForFontWork(const SdrObject *pObj)
QPRO_FUNC_TYPE nType
SdrTextObj * DynCastSdrTextObj(SdrObject *pObj)
Definition: svdobj.cxx:3212
SdrInventor
Definition: svdobj.hxx:98
SdrObjKind
Definition: svdobjkind.hxx:25
@ Group
abstract object (SdrObject)
@ Measure
object that represents a SdrPage
@ Page
Polyline represented by SdrPathObj.
@ Caption
connector object
@ Media
custom shape
@ PathFill
open Bezier-curve
@ Line
object group
@ Polygon
circle cut
@ Table
media shape
@ FreehandLine
closed Bezier-curve
@ PathLine
PolyLine.
@ CustomShape
Universal Network Object packed into SvDraw object.
@ CircleOrEllipse
rectangle (round corners optional)
@ Text
closed free-hand line
@ OLE2
foreign graphic (StarView Graphic)
@ Graphic
OutlineText, special text object for StarDraw.
@ CircleCut
circle arc
@ Rectangle
line
@ CircleSection
circle, ellipse
@ OutlineText
TitleText, special text object for StarDraw.
@ CircleArc
circle section
@ PolyLine
polygon, PolyPolygon
@ Edge
OLE object.
@ TitleText
text object
@ FreehandFill
open free-hand line