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 
29 namespace svx::sidebar {
30 
31 EnumContext::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  if ( dynamic_cast<const SdrTextObj*>( pObj) != nullptr && 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: break;
85  }
86  }
87  }
88 
89  return eContext;
90 }
91 
92 
94  const SdrMarkList& rMarkList,
95  const ViewType eViewType)
96 {
97  EnumContext::Context eContext = EnumContext::Context::Unknown;
98 
99  // Note that some cases are handled by the caller. They rely on
100  // sd specific data.
101  switch (rMarkList.GetMarkCount())
102  {
103  case 0:
104  switch(eViewType)
105  {
106  case ViewType::Standard:
107  eContext = EnumContext::Context::DrawPage;
108  break;
109  case ViewType::Master:
110  eContext = EnumContext::Context::MasterPage;
111  break;
112  case ViewType::Handout:
113  eContext = EnumContext::Context::HandoutPage;
114  break;
115  case ViewType::Notes:
116  eContext = EnumContext::Context::NotesPage;
117  break;
118  }
119  break;
120 
121  case 1:
122  {
123  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
124  if (dynamic_cast<const SdrTextObj*>( pObj) != nullptr && 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: break;
189  }
190  break;
191  }
192  }
193 
194  return eContext;
195 }
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  break;
235 
236  default:
237  return EnumContext::Context::Unknown;
238  }
239 }
240 
241 
243  const sal_uInt16 nObjectId,
244  const ViewType eViewType)
245 {
246  switch (nObjectId)
247  {
248  case OBJ_CAPTION:
249  case OBJ_MEASURE:
250  case OBJ_RECT:
251  case OBJ_CIRC:
252  case OBJ_FREEFILL:
253  case OBJ_PATHFILL:
254  case OBJ_POLY:
255  case OBJ_SECT:
256  case OBJ_CARC:
257  case OBJ_CCUT:
258  case OBJ_CUSTOMSHAPE:
259  case OBJ_GRUP:
260  return EnumContext::Context::Draw;
261 
262  case OBJ_EDGE:
263  case OBJ_PATHLINE:
264  case OBJ_FREELINE:
265  case OBJ_PLIN:
266  case OBJ_LINE:
267  return EnumContext::Context::DrawLine;
268 
269  case OBJ_TITLETEXT:
270  case OBJ_OUTLINETEXT:
271  case OBJ_TEXT:
272  return EnumContext::Context::TextObject;
273 
274  case OBJ_GRAF:
275  return EnumContext::Context::Graphic;
276 
277  case OBJ_OLE2:
278  return EnumContext::Context::OLE;
279 
280  case OBJ_MEDIA:
281  return EnumContext::Context::Media;
282 
283  case OBJ_TABLE:
284  return EnumContext::Context::Table;
285 
286  case OBJ_PAGE:
287  switch (eViewType)
288  {
289  case ViewType::Handout:
290  return EnumContext::Context::HandoutPage;
291  case ViewType::Notes:
292  return EnumContext::Context::NotesPage;
293  default:
294  return EnumContext::Context::Unknown;
295  }
296 
297  default:
298  return EnumContext::Context::Unknown;
299  }
300 }
301 
302 
304 {
305  const size_t nMarkCount (rMarkList.GetMarkCount());
306 
307  if (nMarkCount < 1)
308  return SdrInventor::Unknown;
309 
310  SdrMark* pMark = rMarkList.GetMark(0);
311  SdrObject* pObj = pMark->GetMarkedSdrObj();
312  const SdrInventor nFirstInv = pObj->GetObjInventor();
313 
314  for (size_t nIndex=1; nIndex<nMarkCount; ++nIndex)
315  {
316  pMark = rMarkList.GetMark(nIndex);
317  pObj = pMark->GetMarkedSdrObj();
318  const SdrInventor nInv (pObj->GetObjInventor());
319 
320  if (nInv != nFirstInv)
321  return SdrInventor::Unknown;
322  }
323 
324  return nFirstInv;
325 }
326 
327 
329 {
330  SdrObjList* pObjList = pObj->GetSubList();
331  if (pObjList)
332  {
333  const size_t nSubObjCount (pObjList->GetObjCount());
334 
335  if (nSubObjCount>0)
336  {
337  SdrObject* pSubObj = pObjList->GetObj(0);
338  sal_uInt16 nResultType = pSubObj->GetObjIdentifier();
339 
340  if (nResultType == OBJ_GRUP)
341  nResultType = GetObjectTypeFromGroup(pSubObj);
342 
343  if (IsShapeType(nResultType))
344  nResultType = OBJ_CUSTOMSHAPE;
345 
346  if (IsTextObjType(nResultType))
347  nResultType = OBJ_TEXT;
348 
349  for (size_t nIndex=1; nIndex<nSubObjCount; ++nIndex)
350  {
351  pSubObj = pObjList->GetObj(nIndex);
352  sal_uInt16 nType (pSubObj->GetObjIdentifier());
353 
354  if(nType == OBJ_GRUP)
355  nType = GetObjectTypeFromGroup(pSubObj);
356 
357  if (IsShapeType(nType))
359 
360  if ((nType == OBJ_CUSTOMSHAPE) && (nResultType == OBJ_TEXT))
361  nType = OBJ_TEXT;
362 
363  if (IsTextObjType(nType))
364  nType = OBJ_TEXT;
365 
366  if ((nType == OBJ_TEXT) && (nResultType == OBJ_CUSTOMSHAPE))
367  nResultType = OBJ_TEXT;
368 
369  if (nType != nResultType)
370  return 0;
371  }
372 
373  return nResultType;
374  }
375  }
376 
377  return 0;
378 }
379 
380 
382 {
383  const size_t nMarkCount (rMarkList.GetMarkCount());
384 
385  if (nMarkCount < 1)
386  return 0;
387 
388  SdrMark* pMark = rMarkList.GetMark(0);
389  SdrObject* pObj = pMark->GetMarkedSdrObj();
390  sal_uInt16 nResultType = pObj->GetObjIdentifier();
391 
392  if(nResultType == OBJ_GRUP)
393  nResultType = GetObjectTypeFromGroup(pObj);
394 
395  if (IsShapeType(nResultType))
396  nResultType = OBJ_CUSTOMSHAPE;
397 
398  if (IsTextObjType(nResultType))
399  nResultType = OBJ_TEXT;
400 
401  for (size_t nIndex=1; nIndex<nMarkCount; ++nIndex)
402  {
403  pMark = rMarkList.GetMark(nIndex);
404  pObj = pMark->GetMarkedSdrObj();
405  sal_uInt16 nType = pObj->GetObjIdentifier();
406 
407  if(nType == OBJ_GRUP)
408  nType = GetObjectTypeFromGroup(pObj);
409 
410  if (IsShapeType(nType))
411  nType = OBJ_CUSTOMSHAPE;
412 
413  if ((nType == OBJ_CUSTOMSHAPE) && (nResultType == OBJ_TEXT))
414  nType = OBJ_TEXT;
415 
416  if (IsTextObjType(nType))
417  nType = OBJ_TEXT;
418 
419  if ((nType == OBJ_TEXT) && (nResultType == OBJ_CUSTOMSHAPE))
420  nResultType = OBJ_TEXT;
421 
422  if (nType != nResultType)
423  return 0;
424  }
425 
426  return nResultType;
427 }
428 
429 
430 bool SelectionAnalyzer::IsShapeType (const sal_uInt16 nType)
431 {
432  switch (nType)
433  {
434  case OBJ_LINE:
435  case OBJ_CARC:
436  case OBJ_PLIN:
437  case OBJ_PATHLINE:
438  case OBJ_RECT:
439  case OBJ_CIRC:
440  case OBJ_SECT:
441  case OBJ_CCUT:
442  case OBJ_PATHFILL:
443  case OBJ_CUSTOMSHAPE:
444  case OBJ_CAPTION:
445  case OBJ_MEASURE:
446  case OBJ_EDGE:
447  case OBJ_POLY:
448  case OBJ_FREELINE:
449  case OBJ_FREEFILL:
450 
451  // #122145# adding OBJ_OLE2 since these also allow line/fill style and may
452  // be multiselected/grouped with normal draw objects, e.g. math OLE objects
453  case OBJ_OLE2:
454  return true;
455 
456  default:
457  return false;
458  }
459 }
460 
461 
462 bool SelectionAnalyzer::IsTextObjType (const sal_uInt16 nType)
463 {
464  switch(nType)
465  {
466  case OBJ_TEXT:
467  case OBJ_TITLETEXT:
468  case OBJ_OUTLINETEXT:
469  return true;
470 
471  default:
472  return false;
473  }
474 }
475 
476 
477 } // end of namespace svx::sidebar
478 
479 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OutlineText, special text object for StarDraw.
Definition: svdobj.hxx:136
sal_Int32 nIndex
size_t GetMarkCount() const
Definition: svdmark.hxx:180
Universal Network Object packed into SvDraw object.
Definition: svdobj.hxx:146
foreign graphic (StarView Graphic)
Definition: svdobj.hxx:137
media shape
Definition: svdobj.hxx:148
static vcl::EnumContext::Context GetContextForSelection_SD(const SdrMarkList &rMarkList, const ViewType eViewType)
Polyline represented by SdrPathObj.
Definition: svdobj.hxx:142
periodic cubic Spline (ni)
Definition: svdobj.hxx:133
SdrObject * GetObj(size_t nNum) const
Definition: svdpage.cxx:758
size_t GetObjCount() const
Definition: svdpage.cxx:752
SdrInventor
Definition: svdobj.hxx:152
SdrMark * GetMark(size_t nNum) const
Definition: svdmark.cxx:229
OLE object.
Definition: svdobj.hxx:138
circle cut
Definition: svdobj.hxx:125
open free-hand line
Definition: svdobj.hxx:130
static vcl::EnumContext::Context GetContextForObjectId_SC(const sal_uInt16 nObjectId)
virtual SdrObjList * GetSubList() const
Definition: svdobj.cxx:647
polygon, PolyPolygon
Definition: svdobj.hxx:126
object that represents a SdrPage
Definition: svdobj.hxx:143
line
Definition: svdobj.hxx:120
static sal_uInt16 GetObjectTypeFromMark(const SdrMarkList &rMarkList)
custom shape
Definition: svdobj.hxx:147
connector object
Definition: svdobj.hxx:139
static vcl::EnumContext::Context GetContextForObjectId_SD(const sal_uInt16 nObjectId, const ViewType eViewType)
PolyLine.
Definition: svdobj.hxx:127
static bool IsTextObjType(const sal_uInt16 nType)
circle, ellipse
Definition: svdobj.hxx:122
SdrObject * GetMarkedSdrObj() const
Definition: svdmark.hxx:68
Everything a View needs to know about a selected object.
Definition: svdmark.hxx:44
object group
Definition: svdobj.hxx:119
abstract object (SdrObject)
Definition: svdobj.hxx:118
virtual sal_uInt16 GetObjIdentifier() const
Definition: svdobj.cxx:558
Abstract DrawObject.
Definition: svdobj.hxx:312
virtual SdrInventor GetObjInventor() const
Definition: svdobj.cxx:553
closed Bezier-curve
Definition: svdobj.hxx:129
static sal_uInt16 GetObjectTypeFromGroup(const SdrObject *pObj)
circle section
Definition: svdobj.hxx:123
TitleText, special text object for StarDraw.
Definition: svdobj.hxx:135
circle arc
Definition: svdobj.hxx:124
static vcl::EnumContext::Context GetContextForSelection_SC(const SdrMarkList &rMarkList)
QPRO_FUNC_TYPE nType
static bool IsShapeType(const sal_uInt16 nType)
static SdrInventor GetInventorTypeFromMark(const SdrMarkList &rMarkList)
text object
Definition: svdobj.hxx:134
open Bezier-curve
Definition: svdobj.hxx:128
rectangle (round corners optional)
Definition: svdobj.hxx:121