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 
26 using vcl::EnumContext;
27 
28 namespace svx::sidebar
29 {
30 EnumContext::Context SelectionAnalyzer::GetContextForSelection_SC(const SdrMarkList& rMarkList)
31 {
32  EnumContext::Context eContext = EnumContext::Context::Unknown;
33 
34  switch (rMarkList.GetMarkCount())
35  {
36  case 0:
37  // Empty selection. Return Context::Unknown to let the caller
38  // substitute it with the default context.
39  break;
40 
41  case 1:
42  {
43  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
44  if (dynamic_cast<const SdrTextObj*>(pObj) != nullptr
45  && static_cast<SdrTextObj*>(pObj)->IsInEditMode())
46  {
47  eContext = EnumContext::Context::DrawText;
48  }
49  else
50  {
51  const SdrInventor nInv = pObj->GetObjInventor();
52  const sal_uInt16 nObjId = pObj->GetObjIdentifier();
53  if (nInv == SdrInventor::Default)
54  eContext = GetContextForObjectId_SC(nObjId);
55  else if (nInv == SdrInventor::FmForm)
56  eContext = EnumContext::Context::Form;
57  }
58  break;
59  }
60 
61  default:
62  {
63  // Multi selection.
64  switch (GetInventorTypeFromMark(rMarkList))
65  {
67  {
68  const sal_uInt16 nObjId(GetObjectTypeFromMark(rMarkList));
69  if (nObjId == 0)
70  eContext = EnumContext::Context::MultiObject;
71  else
72  eContext = GetContextForObjectId_SC(nObjId);
73  break;
74  }
75 
77  eContext = EnumContext::Context::Form;
78  break;
79 
81  eContext = EnumContext::Context::MultiObject;
82  break;
83 
84  default:
85  break;
86  }
87  }
88  }
89 
90  return eContext;
91 }
92 
93 EnumContext::Context SelectionAnalyzer::GetContextForSelection_SD(const SdrMarkList& rMarkList,
94  const ViewType eViewType)
95 {
96  EnumContext::Context eContext = EnumContext::Context::Unknown;
97 
98  // Note that some cases are handled by the caller. They rely on
99  // sd specific data.
100  switch (rMarkList.GetMarkCount())
101  {
102  case 0:
103  switch (eViewType)
104  {
105  case ViewType::Standard:
106  eContext = EnumContext::Context::DrawPage;
107  break;
108  case ViewType::Master:
109  eContext = EnumContext::Context::MasterPage;
110  break;
111  case ViewType::Handout:
112  eContext = EnumContext::Context::HandoutPage;
113  break;
114  case ViewType::Notes:
115  eContext = EnumContext::Context::NotesPage;
116  break;
117  }
118  break;
119 
120  case 1:
121  {
122  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
123  if (dynamic_cast<const SdrTextObj*>(pObj) != nullptr
124  && static_cast<SdrTextObj*>(pObj)->IsInEditMode())
125  {
126  if (pObj->GetObjIdentifier() == OBJ_TABLE)
127  {
128  // Let a table object take precedence over text
129  // edit mode. The panels for text editing are
130  // present for table context as well, anyway.
131  eContext = EnumContext::Context::Table;
132  }
133  else
134  eContext = EnumContext::Context::DrawText;
135  }
136  else
137  {
138  const SdrInventor nInv = pObj->GetObjInventor();
139  sal_uInt16 nObjId = pObj->GetObjIdentifier();
140  if (nInv == SdrInventor::Default)
141  {
142  if (nObjId == OBJ_GRUP)
143  {
144  nObjId = GetObjectTypeFromGroup(pObj);
145  if (nObjId == 0)
146  nObjId = OBJ_GRUP;
147  }
148  eContext = GetContextForObjectId_SD(nObjId, eViewType);
149  }
150  else if (nInv == SdrInventor::E3d)
151  {
152  eContext = EnumContext::Context::ThreeDObject;
153  }
154  else if (nInv == SdrInventor::FmForm)
155  {
156  eContext = EnumContext::Context::Form;
157  }
158  }
159  break;
160  }
161 
162  default:
163  {
164  switch (GetInventorTypeFromMark(rMarkList))
165  {
167  {
168  const sal_uInt16 nObjId = GetObjectTypeFromMark(rMarkList);
169  if (nObjId == 0)
170  eContext = EnumContext::Context::MultiObject;
171  else
172  eContext = GetContextForObjectId_SD(nObjId, eViewType);
173  break;
174  }
175 
176  case SdrInventor::E3d:
177  eContext = EnumContext::Context::ThreeDObject;
178  break;
179 
180  case SdrInventor::FmForm:
181  eContext = EnumContext::Context::Form;
182  break;
183 
185  eContext = EnumContext::Context::MultiObject;
186  break;
187 
188  default:
189  break;
190  }
191  break;
192  }
193  }
194 
195  return eContext;
196 }
197 
198 EnumContext::Context SelectionAnalyzer::GetContextForObjectId_SC(const sal_uInt16 nObjectId)
199 {
200  switch (nObjectId)
201  {
202  case OBJ_CAPTION:
203  case OBJ_TITLETEXT:
204  case OBJ_OUTLINETEXT:
205  case OBJ_TEXT:
206  case OBJ_MEASURE:
207  case OBJ_RECT:
208  case OBJ_CIRC:
209  case OBJ_FREEFILL:
210  case OBJ_PATHFILL:
211  case OBJ_POLY:
212  case OBJ_SECT:
213  case OBJ_CARC:
214  case OBJ_CCUT:
215  case OBJ_CUSTOMSHAPE:
216  case OBJ_GRUP:
217  return EnumContext::Context::Draw;
218 
219  case OBJ_PLIN:
220  case OBJ_PATHLINE:
221  case OBJ_FREELINE:
222  case OBJ_LINE:
223  case OBJ_EDGE:
224  return EnumContext::Context::DrawLine;
225 
226  case OBJ_GRAF:
227  return EnumContext::Context::Graphic;
228 
229  case OBJ_OLE2:
230  return EnumContext::Context::OLE;
231 
232  case OBJ_MEDIA:
233  return EnumContext::Context::Media;
234 
235  default:
236  return EnumContext::Context::Unknown;
237  }
238 }
239 
240 EnumContext::Context SelectionAnalyzer::GetContextForObjectId_SD(const sal_uInt16 nObjectId,
241  const ViewType eViewType)
242 {
243  switch (nObjectId)
244  {
245  case OBJ_CAPTION:
246  case OBJ_MEASURE:
247  case OBJ_RECT:
248  case OBJ_CIRC:
249  case OBJ_FREEFILL:
250  case OBJ_PATHFILL:
251  case OBJ_POLY:
252  case OBJ_SECT:
253  case OBJ_CARC:
254  case OBJ_CCUT:
255  case OBJ_CUSTOMSHAPE:
256  case OBJ_GRUP:
257  return EnumContext::Context::Draw;
258 
259  case OBJ_EDGE:
260  case OBJ_PATHLINE:
261  case OBJ_FREELINE:
262  case OBJ_PLIN:
263  case OBJ_LINE:
264  return EnumContext::Context::DrawLine;
265 
266  case OBJ_TITLETEXT:
267  case OBJ_OUTLINETEXT:
268  case OBJ_TEXT:
269  return EnumContext::Context::TextObject;
270 
271  case OBJ_GRAF:
272  return EnumContext::Context::Graphic;
273 
274  case OBJ_OLE2:
275  return EnumContext::Context::OLE;
276 
277  case OBJ_MEDIA:
278  return EnumContext::Context::Media;
279 
280  case OBJ_TABLE:
281  return EnumContext::Context::Table;
282 
283  case OBJ_PAGE:
284  switch (eViewType)
285  {
286  case ViewType::Handout:
287  return EnumContext::Context::HandoutPage;
288  case ViewType::Notes:
289  return EnumContext::Context::NotesPage;
290  default:
291  return EnumContext::Context::Unknown;
292  }
293 
294  default:
295  return EnumContext::Context::Unknown;
296  }
297 }
298 
300 {
301  const size_t nMarkCount(rMarkList.GetMarkCount());
302 
303  if (nMarkCount < 1)
304  return SdrInventor::Unknown;
305 
306  SdrMark* pMark = rMarkList.GetMark(0);
307  SdrObject* pObj = pMark->GetMarkedSdrObj();
308  const SdrInventor nFirstInv = pObj->GetObjInventor();
309 
310  for (size_t nIndex = 1; nIndex < nMarkCount; ++nIndex)
311  {
312  pMark = rMarkList.GetMark(nIndex);
313  pObj = pMark->GetMarkedSdrObj();
314  const SdrInventor nInv(pObj->GetObjInventor());
315 
316  if (nInv != nFirstInv)
317  return SdrInventor::Unknown;
318  }
319 
320  return nFirstInv;
321 }
322 
324 {
325  SdrObjList* pObjList = pObj->GetSubList();
326  if (pObjList)
327  {
328  const size_t nSubObjCount(pObjList->GetObjCount());
329 
330  if (nSubObjCount > 0)
331  {
332  SdrObject* pSubObj = pObjList->GetObj(0);
333  sal_uInt16 nResultType = pSubObj->GetObjIdentifier();
334 
335  if (nResultType == OBJ_GRUP)
336  nResultType = GetObjectTypeFromGroup(pSubObj);
337 
338  if (IsShapeType(nResultType))
339  nResultType = OBJ_CUSTOMSHAPE;
340 
341  if (IsTextObjType(nResultType))
342  nResultType = OBJ_TEXT;
343 
344  for (size_t nIndex = 1; nIndex < nSubObjCount; ++nIndex)
345  {
346  pSubObj = pObjList->GetObj(nIndex);
347  sal_uInt16 nType(pSubObj->GetObjIdentifier());
348 
349  if (nType == OBJ_GRUP)
350  nType = GetObjectTypeFromGroup(pSubObj);
351 
352  if (IsShapeType(nType))
354 
355  if ((nType == OBJ_CUSTOMSHAPE) && (nResultType == OBJ_TEXT))
356  nType = OBJ_TEXT;
357 
358  if (IsTextObjType(nType))
359  nType = OBJ_TEXT;
360 
361  if ((nType == OBJ_TEXT) && (nResultType == OBJ_CUSTOMSHAPE))
362  nResultType = OBJ_TEXT;
363 
364  if (nType != nResultType)
365  return 0;
366  }
367 
368  return nResultType;
369  }
370  }
371 
372  return 0;
373 }
374 
376 {
377  const size_t nMarkCount(rMarkList.GetMarkCount());
378 
379  if (nMarkCount < 1)
380  return 0;
381 
382  SdrMark* pMark = rMarkList.GetMark(0);
383  SdrObject* pObj = pMark->GetMarkedSdrObj();
384  sal_uInt16 nResultType = pObj->GetObjIdentifier();
385 
386  if (nResultType == OBJ_GRUP)
387  nResultType = GetObjectTypeFromGroup(pObj);
388 
389  if (IsShapeType(nResultType))
390  nResultType = OBJ_CUSTOMSHAPE;
391 
392  if (IsTextObjType(nResultType))
393  nResultType = OBJ_TEXT;
394 
395  for (size_t nIndex = 1; nIndex < nMarkCount; ++nIndex)
396  {
397  pMark = rMarkList.GetMark(nIndex);
398  pObj = pMark->GetMarkedSdrObj();
399  sal_uInt16 nType = pObj->GetObjIdentifier();
400 
401  if (nType == OBJ_GRUP)
402  nType = GetObjectTypeFromGroup(pObj);
403 
404  if (IsShapeType(nType))
405  nType = OBJ_CUSTOMSHAPE;
406 
407  if ((nType == OBJ_CUSTOMSHAPE) && (nResultType == OBJ_TEXT))
408  nType = OBJ_TEXT;
409 
410  if (IsTextObjType(nType))
411  nType = OBJ_TEXT;
412 
413  if ((nType == OBJ_TEXT) && (nResultType == OBJ_CUSTOMSHAPE))
414  nResultType = OBJ_TEXT;
415 
416  if (nType != nResultType)
417  return 0;
418  }
419 
420  return nResultType;
421 }
422 
423 bool SelectionAnalyzer::IsShapeType(const sal_uInt16 nType)
424 {
425  switch (nType)
426  {
427  case OBJ_LINE:
428  case OBJ_CARC:
429  case OBJ_PLIN:
430  case OBJ_PATHLINE:
431  case OBJ_RECT:
432  case OBJ_CIRC:
433  case OBJ_SECT:
434  case OBJ_CCUT:
435  case OBJ_PATHFILL:
436  case OBJ_CUSTOMSHAPE:
437  case OBJ_CAPTION:
438  case OBJ_MEASURE:
439  case OBJ_EDGE:
440  case OBJ_POLY:
441  case OBJ_FREELINE:
442  case OBJ_FREEFILL:
443 
444  // #122145# adding OBJ_OLE2 since these also allow line/fill style and may
445  // be multiselected/grouped with normal draw objects, e.g. math OLE objects
446  case OBJ_OLE2:
447  return true;
448 
449  default:
450  return false;
451  }
452 }
453 
454 bool SelectionAnalyzer::IsTextObjType(const sal_uInt16 nType)
455 {
456  switch (nType)
457  {
458  case OBJ_TEXT:
459  case OBJ_TITLETEXT:
460  case OBJ_OUTLINETEXT:
461  return true;
462 
463  default:
464  return false;
465  }
466 }
467 
468 } // end of namespace svx::sidebar
469 
470 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nIndex
line
Definition: svdobjkind.hxx:29
size_t GetMarkCount() const
Definition: svdmark.hxx:180
abstract object (SdrObject)
Definition: svdobjkind.hxx:27
static vcl::EnumContext::Context GetContextForSelection_SD(const SdrMarkList &rMarkList, const ViewType eViewType)
rectangle (round corners optional)
Definition: svdobjkind.hxx:30
object group
Definition: svdobjkind.hxx:28
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:758
size_t GetObjCount() const
Definition: svdpage.cxx:752
circle cut
Definition: svdobjkind.hxx:34
circle section
Definition: svdobjkind.hxx:32
SdrInventor
Definition: svdobj.hxx:100
SdrMark * GetMark(size_t nNum) const
Definition: svdmark.cxx:229
virtual SdrObjKind GetObjIdentifier() const
Definition: svdobj.cxx:629
static vcl::EnumContext::Context GetContextForObjectId_SC(const sal_uInt16 nObjectId)
media shape
Definition: svdobjkind.hxx:57
virtual SdrObjList * GetSubList() const
Definition: svdobj.cxx:718
static sal_uInt16 GetObjectTypeFromMark(const SdrMarkList &rMarkList)
circle, ellipse
Definition: svdobjkind.hxx:31
static vcl::EnumContext::Context GetContextForObjectId_SD(const sal_uInt16 nObjectId, const ViewType eViewType)
static bool IsTextObjType(const sal_uInt16 nType)
Polyline represented by SdrPathObj.
Definition: svdobjkind.hxx:51
SdrObject * GetMarkedSdrObj() const
Definition: svdmark.hxx:68
Everything a View needs to know about a selected object.
Definition: svdmark.hxx:44
open Bezier-curve
Definition: svdobjkind.hxx:37
connector object
Definition: svdobjkind.hxx:48
OutlineText, special text object for StarDraw.
Definition: svdobjkind.hxx:45
open free-hand line
Definition: svdobjkind.hxx:39
polygon, PolyPolygon
Definition: svdobjkind.hxx:35
closed Bezier-curve
Definition: svdobjkind.hxx:38
Abstract DrawObject.
Definition: svdobj.hxx:260
virtual SdrInventor GetObjInventor() const
Definition: svdobj.cxx:624
static sal_uInt16 GetObjectTypeFromGroup(const SdrObject *pObj)
object that represents a SdrPage
Definition: svdobjkind.hxx:52
static vcl::EnumContext::Context GetContextForSelection_SC(const SdrMarkList &rMarkList)
QPRO_FUNC_TYPE nType
static bool IsShapeType(const sal_uInt16 nType)
text object
Definition: svdobjkind.hxx:43
Universal Network Object packed into SvDraw object.
Definition: svdobjkind.hxx:55
PolyLine.
Definition: svdobjkind.hxx:36
static SdrInventor GetInventorTypeFromMark(const SdrMarkList &rMarkList)
OLE object.
Definition: svdobjkind.hxx:47
TitleText, special text object for StarDraw.
Definition: svdobjkind.hxx:44
circle arc
Definition: svdobjkind.hxx:33
periodic cubic Spline (ni)
Definition: svdobjkind.hxx:42
foreign graphic (StarView Graphic)
Definition: svdobjkind.hxx:46
custom shape
Definition: svdobjkind.hxx:56