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