1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 #include "precompiled_svx.hxx" 23 24 #include "svx/sidebar/SelectionAnalyzer.hxx" 25 #include "svx/svdmrkv.hxx" 26 #include "svx/svdobj.hxx" 27 #include "svx/svdpage.hxx" 28 #include "svx/fmglob.hxx" 29 #include "svx/globl3d.hxx" 30 31 using sfx2::sidebar::EnumContext; 32 33 34 namespace svx { namespace sidebar { 35 36 EnumContext::Context SelectionAnalyzer::GetContextForSelection_SC (const SdrMarkList& rMarkList) 37 { 38 EnumContext::Context eContext = EnumContext::Context_Unknown; 39 40 switch (rMarkList.GetMarkCount()) 41 { 42 case 0: 43 // Empty selection. Return Context_Unknown to let the caller 44 // substitute it with the default context. 45 break; 46 47 case 1: 48 { 49 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj(); 50 const sal_uInt32 nInv = pObj->GetObjInventor(); 51 const sal_uInt16 nObjId = pObj->GetObjIdentifier(); 52 if (nInv == SdrInventor) 53 eContext = GetContextForObjectId_SC(nObjId); 54 else if (nInv == FmFormInventor) 55 eContext = EnumContext::Context_Form; 56 break; 57 } 58 59 default: 60 { 61 // Multi selection. 62 switch (GetInventorTypeFromMark(rMarkList)) 63 { 64 case SdrInventor: 65 { 66 const sal_uInt16 nObjId (GetObjectTypeFromMark(rMarkList)); 67 if (nObjId == 0) 68 eContext = EnumContext::Context_MultiObject; 69 else 70 eContext = GetContextForObjectId_SC(nObjId); 71 break; 72 } 73 74 case FmFormInventor: 75 eContext = EnumContext::Context_Form; 76 break; 77 78 case 0: 79 eContext = EnumContext::Context_MultiObject; 80 break; 81 } 82 } 83 } 84 85 return eContext; 86 } 87 88 89 90 91 EnumContext::Context SelectionAnalyzer::GetContextForSelection_SD ( 92 const SdrMarkList& rMarkList, 93 const bool bIsMasterPage, 94 const bool bIsHandoutPage, 95 const bool bIsNotesPage) 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 if (bIsHandoutPage) 105 eContext = EnumContext::Context_HandoutPage; 106 else if (bIsNotesPage) 107 eContext = EnumContext::Context_NotesPage; 108 else if (bIsMasterPage) 109 eContext = EnumContext::Context_MasterPage; 110 else 111 eContext = EnumContext::Context_DrawPage; 112 break; 113 114 case 1: 115 { 116 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj(); 117 const sal_uInt32 nInv = pObj->GetObjInventor(); 118 sal_uInt16 nObjId = pObj->GetObjIdentifier(); 119 if (nInv == SdrInventor) 120 { 121 if (nObjId == OBJ_GRUP) 122 { 123 nObjId = GetObjectTypeFromGroup(pObj); 124 if (nObjId == 0) 125 nObjId = OBJ_GRUP; 126 } 127 eContext = GetContextForObjectId_SD(nObjId, bIsHandoutPage, bIsNotesPage); 128 } 129 else if (nInv == E3dInventor) 130 { 131 eContext = EnumContext::Context_3DObject; 132 } 133 else if (nInv == FmFormInventor) 134 { 135 eContext = EnumContext::Context_Form; 136 } 137 break; 138 } 139 140 default: 141 { 142 switch (GetInventorTypeFromMark(rMarkList)) 143 { 144 case SdrInventor: 145 { 146 const sal_uInt16 nObjId = GetObjectTypeFromMark(rMarkList); 147 if (nObjId == 0) 148 eContext = EnumContext::Context_MultiObject; 149 else 150 eContext = GetContextForObjectId_SD(nObjId, bIsHandoutPage, bIsNotesPage); 151 break; 152 } 153 154 case E3dInventor: 155 eContext = EnumContext::Context_3DObject; 156 break; 157 158 case FmFormInventor: 159 eContext = EnumContext::Context_Form; 160 break; 161 162 case 0: 163 eContext = EnumContext::Context_MultiObject; 164 break; 165 } 166 break; 167 } 168 } 169 170 return eContext; 171 } 172 173 174 175 176 EnumContext::Context SelectionAnalyzer::GetContextForObjectId_SC (const sal_uInt16 nObjectId) 177 { 178 switch (nObjectId) 179 { 180 case OBJ_CAPTION: 181 case OBJ_TITLETEXT: 182 case OBJ_OUTLINETEXT: 183 case OBJ_TEXT: 184 case OBJ_TEXTEXT: 185 case OBJ_PATHLINE: 186 case OBJ_PLIN: 187 case OBJ_FREELINE: 188 case OBJ_EDGE: 189 case OBJ_LINE: 190 case OBJ_MEASURE: 191 case OBJ_RECT: 192 case OBJ_CIRC: 193 case OBJ_FREEFILL: 194 case OBJ_PATHFILL: 195 case OBJ_POLY: 196 case OBJ_SECT: 197 case OBJ_CARC: 198 case OBJ_CCUT: 199 case OBJ_CUSTOMSHAPE: 200 case OBJ_GRUP: 201 return EnumContext::Context_Draw; 202 203 case OBJ_GRAF: 204 return EnumContext::Context_Graphic; 205 206 case OBJ_OLE2: 207 return EnumContext::Context_OLE; 208 209 case OBJ_MEDIA: 210 return EnumContext::Context_Media; 211 break; 212 213 default: 214 return EnumContext::Context_Unknown; 215 } 216 } 217 218 219 220 221 EnumContext::Context SelectionAnalyzer::GetContextForObjectId_SD ( 222 const sal_uInt16 nObjectId, 223 const bool bIsHandoutPage, 224 const bool bIsNotesPage) 225 { 226 switch (nObjectId) 227 { 228 case OBJ_CAPTION: 229 case OBJ_PATHLINE: 230 case OBJ_PLIN: 231 case OBJ_FREELINE: 232 case OBJ_EDGE: 233 case OBJ_LINE: 234 case OBJ_MEASURE: 235 case OBJ_RECT: 236 case OBJ_CIRC: 237 case OBJ_FREEFILL: 238 case OBJ_PATHFILL: 239 case OBJ_POLY: 240 case OBJ_SECT: 241 case OBJ_CARC: 242 case OBJ_CCUT: 243 case OBJ_CUSTOMSHAPE: 244 case OBJ_GRUP: 245 return EnumContext::Context_Draw; 246 247 case OBJ_TITLETEXT: 248 case OBJ_OUTLINETEXT: 249 case OBJ_TEXT: 250 case OBJ_TEXTEXT: 251 return EnumContext::Context_TextObject; 252 253 case OBJ_GRAF: 254 return EnumContext::Context_Graphic; 255 256 case OBJ_OLE2: 257 return EnumContext::Context_OLE; 258 259 case OBJ_MEDIA: 260 return EnumContext::Context_Media; 261 262 case OBJ_TABLE: 263 return EnumContext::Context_Table; 264 265 case OBJ_PAGE: 266 if (bIsHandoutPage) 267 return EnumContext::Context_HandoutPage; 268 else if (bIsNotesPage) 269 return EnumContext::Context_NotesPage; 270 else 271 return EnumContext::Context_Unknown; 272 273 default: 274 return EnumContext::Context_Unknown; 275 } 276 } 277 278 279 280 281 sal_uInt32 SelectionAnalyzer::GetInventorTypeFromMark (const SdrMarkList& rMarkList) 282 { 283 const sal_uLong nMarkCount (rMarkList.GetMarkCount()); 284 285 if (nMarkCount < 1) 286 return 0; 287 288 SdrMark* pMark = rMarkList.GetMark(0); 289 SdrObject* pObj = pMark->GetMarkedSdrObj(); 290 const sal_uInt32 nFirstInv = pObj->GetObjInventor(); 291 292 for (sal_uLong nIndex=1; nIndex<nMarkCount; ++nIndex) 293 { 294 pMark = rMarkList.GetMark(nIndex); 295 pObj = pMark->GetMarkedSdrObj(); 296 const sal_uInt32 nInv (pObj->GetObjInventor()); 297 298 if (nInv != nFirstInv) 299 return 0; 300 } 301 302 return nFirstInv; 303 } 304 305 306 307 308 sal_uInt16 SelectionAnalyzer::GetObjectTypeFromGroup (const SdrObject* pObj) 309 { 310 SdrObjList* pObjList = pObj->GetSubList(); 311 if (pObjList) 312 { 313 const sal_uLong nSubObjCount (pObjList->GetObjCount()); 314 315 if (nSubObjCount>0) 316 { 317 SdrObject* pObj = pObjList->GetObj(0); 318 sal_uInt16 nResultType = pObj->GetObjIdentifier(); 319 320 if (nResultType == OBJ_GRUP) 321 nResultType = GetObjectTypeFromGroup(pObj); 322 323 if (IsShapeType(nResultType)) 324 nResultType = OBJ_CUSTOMSHAPE; 325 326 if (IsTextObjType(nResultType)) 327 nResultType = OBJ_TEXT; 328 329 for (sal_uInt16 nIndex=1; nIndex<nSubObjCount; ++nIndex) 330 { 331 pObj = pObjList->GetObj(nIndex); 332 sal_uInt16 nType (pObj->GetObjIdentifier()); 333 334 if(nType == OBJ_GRUP) 335 nType = GetObjectTypeFromGroup(pObj); 336 337 if (IsShapeType(nType)) 338 nType = OBJ_CUSTOMSHAPE; 339 340 if ((nType == OBJ_CUSTOMSHAPE) && (nResultType == OBJ_TEXT)) 341 nType = OBJ_TEXT; 342 343 if (IsTextObjType(nType)) 344 nType = OBJ_TEXT; 345 346 if ((nType == OBJ_TEXT) && (nResultType == OBJ_CUSTOMSHAPE)) 347 nResultType = OBJ_TEXT; 348 349 if (nType != nResultType) 350 return 0; 351 } 352 353 return nResultType; 354 } 355 } 356 357 return 0; 358 } 359 360 361 362 363 sal_uInt16 SelectionAnalyzer::GetObjectTypeFromMark (const SdrMarkList& rMarkList) 364 { 365 const sal_uLong nMarkCount (rMarkList.GetMarkCount()); 366 367 if (nMarkCount < 1) 368 return 0; 369 370 SdrMark* pMark = rMarkList.GetMark(0); 371 SdrObject* pObj = pMark->GetMarkedSdrObj(); 372 sal_uInt16 nResultType = pObj->GetObjIdentifier(); 373 374 if(nResultType == OBJ_GRUP) 375 nResultType = GetObjectTypeFromGroup(pObj); 376 377 if (IsShapeType(nResultType)) 378 nResultType = OBJ_CUSTOMSHAPE; 379 380 if (IsTextObjType(nResultType)) 381 nResultType = OBJ_TEXT; 382 383 for (sal_uLong nIndex=1; nIndex<nMarkCount; ++nIndex) 384 { 385 pMark = rMarkList.GetMark(nIndex); 386 pObj = pMark->GetMarkedSdrObj(); 387 sal_uInt16 nType = pObj->GetObjIdentifier(); 388 389 if(nType == OBJ_GRUP) 390 nType = GetObjectTypeFromGroup(pObj); 391 392 if (IsShapeType(nType)) 393 nType = OBJ_CUSTOMSHAPE; 394 395 if ((nType == OBJ_CUSTOMSHAPE) && (nResultType == OBJ_TEXT)) 396 nType = OBJ_TEXT; 397 398 if (IsTextObjType(nType)) 399 nType = OBJ_TEXT; 400 401 if ((nType == OBJ_TEXT) && (nResultType == OBJ_CUSTOMSHAPE)) 402 nResultType = OBJ_TEXT; 403 404 if (nType != nResultType) 405 return 0; 406 } 407 408 return nResultType; 409 } 410 411 412 413 414 bool SelectionAnalyzer::IsShapeType (const sal_uInt16 nType) 415 { 416 switch (nType) 417 { 418 case OBJ_LINE: 419 case OBJ_CARC: 420 case OBJ_PLIN: 421 case OBJ_PATHLINE: 422 case OBJ_RECT: 423 case OBJ_CIRC: 424 case OBJ_SECT: 425 case OBJ_CCUT: 426 case OBJ_PATHFILL: 427 case OBJ_CUSTOMSHAPE: 428 case OBJ_CAPTION: 429 case OBJ_MEASURE: 430 case OBJ_EDGE: 431 case OBJ_POLY: 432 case OBJ_FREELINE: 433 case OBJ_FREEFILL: 434 return true; 435 436 default: 437 return false; 438 } 439 } 440 441 442 443 444 bool SelectionAnalyzer::IsTextObjType (const sal_uInt16 nType) 445 { 446 switch(nType) 447 { 448 case OBJ_TEXT: 449 case OBJ_TEXTEXT: 450 case OBJ_TITLETEXT: 451 case OBJ_OUTLINETEXT: 452 return true; 453 454 default: 455 return false; 456 } 457 } 458 459 460 461 } } // end of namespace ::svx::sidebar 462