Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / sidebar / SelectionAnalyzer.cxx
blob39d85fc73b8c18bcc4c477ec670126ac886f6d54
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/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"
28 using sfx2::sidebar::EnumContext;
31 namespace svx { namespace sidebar {
33 EnumContext::Context SelectionAnalyzer::GetContextForSelection_SC (const SdrMarkList& rMarkList)
35 EnumContext::Context eContext = EnumContext::Context_Unknown;
37 switch (rMarkList.GetMarkCount())
39 case 0:
40 // Empty selection. Return Context_Unknown to let the caller
41 // substitute it with the default context.
42 break;
44 case 1:
46 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
47 if ( pObj->ISA(SdrTextObj) && ((SdrTextObj*)pObj)->IsInEditMode() )
49 eContext = EnumContext::Context_DrawText;
51 else
53 const sal_uInt32 nInv = pObj->GetObjInventor();
54 const sal_uInt16 nObjId = pObj->GetObjIdentifier();
55 if (nInv == SdrInventor)
56 eContext = GetContextForObjectId_SC(nObjId);
57 else if (nInv == FmFormInventor)
58 eContext = EnumContext::Context_Form;
60 break;
63 default:
65 // Multi selection.
66 switch (GetInventorTypeFromMark(rMarkList))
68 case SdrInventor:
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;
78 case FmFormInventor:
79 eContext = EnumContext::Context_Form;
80 break;
82 case 0:
83 eContext = EnumContext::Context_MultiObject;
84 break;
89 return eContext;
95 EnumContext::Context SelectionAnalyzer::GetContextForSelection_SD (
96 const SdrMarkList& rMarkList,
97 const ViewType eViewType)
99 EnumContext::Context eContext = EnumContext::Context_Unknown;
101 // Note that some cases are handled by the caller. They rely on
102 // sd specific data.
103 switch (rMarkList.GetMarkCount())
105 case 0:
106 switch(eViewType)
108 case VT_Standard:
109 eContext = EnumContext::Context_DrawPage;
110 break;
111 case VT_Master:
112 eContext = EnumContext::Context_MasterPage;
113 break;
114 case VT_Handout:
115 eContext = EnumContext::Context_HandoutPage;
116 break;
117 case VT_Notes:
118 eContext = EnumContext::Context_NotesPage;
119 break;
120 case VT_Outline:
121 eContext = EnumContext::Context_OutlineText;
122 break;
124 break;
126 case 1:
128 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
129 if (pObj->ISA(SdrTextObj) && ((SdrTextObj*)pObj)->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;
138 else
139 eContext = EnumContext::Context_DrawText;
141 else
143 const sal_uInt32 nInv = pObj->GetObjInventor();
144 sal_uInt16 nObjId = pObj->GetObjIdentifier();
145 if (nInv == SdrInventor)
147 if (nObjId == OBJ_GRUP)
149 nObjId = GetObjectTypeFromGroup(pObj);
150 if (nObjId == 0)
151 nObjId = OBJ_GRUP;
153 eContext = GetContextForObjectId_SD(nObjId, eViewType);
155 else if (nInv == E3dInventor)
157 eContext = EnumContext::Context_3DObject;
159 else if (nInv == FmFormInventor)
161 eContext = EnumContext::Context_Form;
164 break;
167 default:
169 switch (GetInventorTypeFromMark(rMarkList))
171 case SdrInventor:
173 const sal_uInt16 nObjId = GetObjectTypeFromMark(rMarkList);
174 if (nObjId == 0)
175 eContext = EnumContext::Context_MultiObject;
176 else
177 eContext = GetContextForObjectId_SD(nObjId, eViewType);
178 break;
181 case E3dInventor:
182 eContext = EnumContext::Context_3DObject;
183 break;
185 case FmFormInventor:
186 eContext = EnumContext::Context_Form;
187 break;
189 case 0:
190 eContext = EnumContext::Context_MultiObject;
191 break;
193 break;
197 return eContext;
203 EnumContext::Context SelectionAnalyzer::GetContextForObjectId_SC (const sal_uInt16 nObjectId)
205 switch (nObjectId)
207 case OBJ_CAPTION:
208 case OBJ_TITLETEXT:
209 case OBJ_OUTLINETEXT:
210 case OBJ_TEXT:
211 case OBJ_TEXTEXT:
212 case OBJ_PATHLINE:
213 case OBJ_PLIN:
214 case OBJ_FREELINE:
215 case OBJ_EDGE:
216 case OBJ_LINE:
217 case OBJ_MEASURE:
218 case OBJ_RECT:
219 case OBJ_CIRC:
220 case OBJ_FREEFILL:
221 case OBJ_PATHFILL:
222 case OBJ_POLY:
223 case OBJ_SECT:
224 case OBJ_CARC:
225 case OBJ_CCUT:
226 case OBJ_CUSTOMSHAPE:
227 case OBJ_GRUP:
228 return EnumContext::Context_Draw;
230 case OBJ_GRAF:
231 return EnumContext::Context_Graphic;
233 case OBJ_OLE2:
234 return EnumContext::Context_OLE;
236 case OBJ_MEDIA:
237 return EnumContext::Context_Media;
238 break;
240 default:
241 return EnumContext::Context_Unknown;
248 EnumContext::Context SelectionAnalyzer::GetContextForObjectId_SD (
249 const sal_uInt16 nObjectId,
250 const ViewType eViewType)
252 switch (nObjectId)
254 case OBJ_CAPTION:
255 case OBJ_PATHLINE:
256 case OBJ_PLIN:
257 case OBJ_FREELINE:
258 case OBJ_EDGE:
259 case OBJ_LINE:
260 case OBJ_MEASURE:
261 case OBJ_RECT:
262 case OBJ_CIRC:
263 case OBJ_FREEFILL:
264 case OBJ_PATHFILL:
265 case OBJ_POLY:
266 case OBJ_SECT:
267 case OBJ_CARC:
268 case OBJ_CCUT:
269 case OBJ_CUSTOMSHAPE:
270 case OBJ_GRUP:
271 return EnumContext::Context_Draw;
273 case OBJ_TITLETEXT:
274 case OBJ_OUTLINETEXT:
275 case OBJ_TEXT:
276 case OBJ_TEXTEXT:
277 return EnumContext::Context_TextObject;
279 case OBJ_GRAF:
280 return EnumContext::Context_Graphic;
282 case OBJ_OLE2:
283 return EnumContext::Context_OLE;
285 case OBJ_MEDIA:
286 return EnumContext::Context_Media;
288 case OBJ_TABLE:
289 return EnumContext::Context_Table;
291 case OBJ_PAGE:
292 switch (eViewType)
294 case VT_Handout:
295 return EnumContext::Context_HandoutPage;
296 case VT_Notes:
297 return EnumContext::Context_NotesPage;
298 case VT_Outline:
299 return EnumContext::Context_OutlineText;
300 default:
301 return EnumContext::Context_Unknown;
304 default:
305 return EnumContext::Context_Unknown;
312 sal_uInt32 SelectionAnalyzer::GetInventorTypeFromMark (const SdrMarkList& rMarkList)
314 const sal_uLong nMarkCount (rMarkList.GetMarkCount());
316 if (nMarkCount < 1)
317 return 0;
319 SdrMark* pMark = rMarkList.GetMark(0);
320 SdrObject* pObj = pMark->GetMarkedSdrObj();
321 const sal_uInt32 nFirstInv = pObj->GetObjInventor();
323 for (sal_uLong nIndex=1; nIndex<nMarkCount; ++nIndex)
325 pMark = rMarkList.GetMark(nIndex);
326 pObj = pMark->GetMarkedSdrObj();
327 const sal_uInt32 nInv (pObj->GetObjInventor());
329 if (nInv != nFirstInv)
330 return 0;
333 return nFirstInv;
339 sal_uInt16 SelectionAnalyzer::GetObjectTypeFromGroup (const SdrObject* pObj)
341 SdrObjList* pObjList = pObj->GetSubList();
342 if (pObjList)
344 const sal_uLong nSubObjCount (pObjList->GetObjCount());
346 if (nSubObjCount>0)
348 SdrObject* pSubObj = pObjList->GetObj(0);
349 sal_uInt16 nResultType = pSubObj->GetObjIdentifier();
351 if (nResultType == OBJ_GRUP)
352 nResultType = GetObjectTypeFromGroup(pSubObj);
354 if (IsShapeType(nResultType))
355 nResultType = OBJ_CUSTOMSHAPE;
357 if (IsTextObjType(nResultType))
358 nResultType = OBJ_TEXT;
360 for (sal_uInt16 nIndex=1; nIndex<nSubObjCount; ++nIndex)
362 pSubObj = pObjList->GetObj(nIndex);
363 sal_uInt16 nType (pSubObj->GetObjIdentifier());
365 if(nType == OBJ_GRUP)
366 nType = GetObjectTypeFromGroup(pSubObj);
368 if (IsShapeType(nType))
369 nType = OBJ_CUSTOMSHAPE;
371 if ((nType == OBJ_CUSTOMSHAPE) && (nResultType == OBJ_TEXT))
372 nType = OBJ_TEXT;
374 if (IsTextObjType(nType))
375 nType = OBJ_TEXT;
377 if ((nType == OBJ_TEXT) && (nResultType == OBJ_CUSTOMSHAPE))
378 nResultType = OBJ_TEXT;
380 if (nType != nResultType)
381 return 0;
384 return nResultType;
388 return 0;
394 sal_uInt16 SelectionAnalyzer::GetObjectTypeFromMark (const SdrMarkList& rMarkList)
396 const sal_uLong nMarkCount (rMarkList.GetMarkCount());
398 if (nMarkCount < 1)
399 return 0;
401 SdrMark* pMark = rMarkList.GetMark(0);
402 SdrObject* pObj = pMark->GetMarkedSdrObj();
403 sal_uInt16 nResultType = pObj->GetObjIdentifier();
405 if(nResultType == OBJ_GRUP)
406 nResultType = GetObjectTypeFromGroup(pObj);
408 if (IsShapeType(nResultType))
409 nResultType = OBJ_CUSTOMSHAPE;
411 if (IsTextObjType(nResultType))
412 nResultType = OBJ_TEXT;
414 for (sal_uLong nIndex=1; nIndex<nMarkCount; ++nIndex)
416 pMark = rMarkList.GetMark(nIndex);
417 pObj = pMark->GetMarkedSdrObj();
418 sal_uInt16 nType = pObj->GetObjIdentifier();
420 if(nType == OBJ_GRUP)
421 nType = GetObjectTypeFromGroup(pObj);
423 if (IsShapeType(nType))
424 nType = OBJ_CUSTOMSHAPE;
426 if ((nType == OBJ_CUSTOMSHAPE) && (nResultType == OBJ_TEXT))
427 nType = OBJ_TEXT;
429 if (IsTextObjType(nType))
430 nType = OBJ_TEXT;
432 if ((nType == OBJ_TEXT) && (nResultType == OBJ_CUSTOMSHAPE))
433 nResultType = OBJ_TEXT;
435 if (nType != nResultType)
436 return 0;
439 return nResultType;
445 bool SelectionAnalyzer::IsShapeType (const sal_uInt16 nType)
447 switch (nType)
449 case OBJ_LINE:
450 case OBJ_CARC:
451 case OBJ_PLIN:
452 case OBJ_PATHLINE:
453 case OBJ_RECT:
454 case OBJ_CIRC:
455 case OBJ_SECT:
456 case OBJ_CCUT:
457 case OBJ_PATHFILL:
458 case OBJ_CUSTOMSHAPE:
459 case OBJ_CAPTION:
460 case OBJ_MEASURE:
461 case OBJ_EDGE:
462 case OBJ_POLY:
463 case OBJ_FREELINE:
464 case OBJ_FREEFILL:
466 // #122145# adding OBJ_OLE2 since these also allow line/fill style and may
467 // be multiselected/grouped with normal draw objects, e.g. math OLE objects
468 case OBJ_OLE2:
469 return true;
471 default:
472 return false;
479 bool SelectionAnalyzer::IsTextObjType (const sal_uInt16 nType)
481 switch(nType)
483 case OBJ_TEXT:
484 case OBJ_TEXTEXT:
485 case OBJ_TITLETEXT:
486 case OBJ_OUTLINETEXT:
487 return true;
489 default:
490 return false;
496 } } // end of namespace ::svx::sidebar
498 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */