PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/svx/source/svdraw/svdlayer.cxx

https://bitbucket.org/mst/ooo340
C++ | 458 lines | 355 code | 60 blank | 43 comment | 76 complexity | 46a4cc874a3bd1477fd4f7cf43c7adb5 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, AGPL-1.0, BSD-3-Clause-No-Nuclear-License-2014, GPL-3.0, GPL-2.0, BSD-3-Clause, LGPL-2.1
  1. /*************************************************************************
  2. *
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * Copyright 2000, 2010 Oracle and/or its affiliates.
  6. *
  7. * OpenOffice.org - a multi-platform office productivity suite
  8. *
  9. * This file is part of OpenOffice.org.
  10. *
  11. * OpenOffice.org is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Lesser General Public License version 3
  13. * only, as published by the Free Software Foundation.
  14. *
  15. * OpenOffice.org is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Lesser General Public License version 3 for more details
  19. * (a copy is included in the LICENSE file that accompanied this code).
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * version 3 along with OpenOffice.org. If not, see
  23. * <http://www.openoffice.org/license.html>
  24. * for a copy of the LGPLv3 License.
  25. *
  26. ************************************************************************/
  27. // MARKER(update_precomp.py): autogen include statement, do not remove
  28. #include "precompiled_svx.hxx"
  29. #include <com/sun/star/uno/Sequence.hxx>
  30. #include <svx/svdlayer.hxx>
  31. #include <svx/svdmodel.hxx> // fuer Broadcasting
  32. #include "svdglob.hxx" // StringCache
  33. #include "svdstr.hrc" // Namen aus der Resource
  34. ////////////////////////////////////////////////////////////////////////////////////////////////////
  35. // SetOfByte
  36. ////////////////////////////////////////////////////////////////////////////////////////////////////
  37. sal_Bool SetOfByte::IsEmpty() const
  38. {
  39. for(sal_uInt16 i(0); i < 32; i++)
  40. {
  41. if(aData[i] != 0)
  42. return sal_False;
  43. }
  44. return sal_True;
  45. }
  46. sal_Bool SetOfByte::IsFull() const
  47. {
  48. for(sal_uInt16 i(0); i < 32; i++)
  49. {
  50. if(aData[i] != 0xFF)
  51. return sal_False;
  52. }
  53. return sal_True;
  54. }
  55. sal_uInt16 SetOfByte::GetSetCount() const
  56. {
  57. sal_uInt16 nRet(0);
  58. for(sal_uInt16 i(0); i < 32; i++)
  59. {
  60. sal_uInt8 a(aData[i]);
  61. if(a != 0)
  62. {
  63. if(a & 0x80) nRet++;
  64. if(a & 0x40) nRet++;
  65. if(a & 0x20) nRet++;
  66. if(a & 0x10) nRet++;
  67. if(a & 0x08) nRet++;
  68. if(a & 0x04) nRet++;
  69. if(a & 0x02) nRet++;
  70. if(a & 0x01) nRet++;
  71. }
  72. }
  73. return nRet;
  74. }
  75. sal_uInt8 SetOfByte::GetSetBit(sal_uInt16 nNum) const
  76. {
  77. nNum++;
  78. sal_uInt16 i(0), j(0);
  79. sal_uInt16 nRet(0);
  80. while(j < nNum && i < 256)
  81. {
  82. if(IsSet(sal_uInt8(i)))
  83. j++;
  84. i++;
  85. }
  86. if(j == nNum)
  87. nRet = i - 1;
  88. return sal_uInt8(nRet);
  89. }
  90. sal_uInt16 SetOfByte::GetClearCount() const
  91. {
  92. return sal_uInt16(256 - GetSetCount());
  93. }
  94. sal_uInt8 SetOfByte::GetClearBit(sal_uInt16 nNum) const
  95. {
  96. nNum++;
  97. sal_uInt16 i(0), j(0);
  98. sal_uInt16 nRet(0);
  99. while(j < nNum && i < 256)
  100. {
  101. if(!IsSet(sal_uInt8(i)))
  102. j++;
  103. i++;
  104. }
  105. if(j == nNum)
  106. nRet = i - 1;
  107. return sal_uInt8(nRet);
  108. }
  109. void SetOfByte::operator&=(const SetOfByte& r2ndSet)
  110. {
  111. for(sal_uInt16 i(0); i < 32; i++)
  112. {
  113. aData[i] &= r2ndSet.aData[i];
  114. }
  115. }
  116. void SetOfByte::operator|=(const SetOfByte& r2ndSet)
  117. {
  118. for(sal_uInt16 i(0); i < 32; i++)
  119. {
  120. aData[i] |= r2ndSet.aData[i];
  121. }
  122. }
  123. /** initialize this set with a uno sequence of sal_Int8
  124. */
  125. void SetOfByte::PutValue( const com::sun::star::uno::Any & rAny )
  126. {
  127. com::sun::star::uno::Sequence< sal_Int8 > aSeq;
  128. if( rAny >>= aSeq )
  129. {
  130. sal_Int16 nCount = (sal_Int16)aSeq.getLength();
  131. if( nCount > 32 )
  132. nCount = 32;
  133. sal_Int16 nIndex;
  134. for( nIndex = 0; nIndex < nCount; nIndex++ )
  135. {
  136. aData[nIndex] = static_cast<BYTE>(aSeq[nIndex]);
  137. }
  138. for( ; nIndex < 32; nIndex++ )
  139. {
  140. aData[nIndex] = 0;
  141. }
  142. }
  143. }
  144. /** returns a uno sequence of sal_Int8
  145. */
  146. void SetOfByte::QueryValue( com::sun::star::uno::Any & rAny ) const
  147. {
  148. sal_Int16 nNumBytesSet = 0;
  149. sal_Int16 nIndex;
  150. for( nIndex = 31; nIndex >= 00; nIndex-- )
  151. {
  152. if( 0 != aData[nIndex] )
  153. {
  154. nNumBytesSet = nIndex + 1;
  155. break;
  156. }
  157. }
  158. com::sun::star::uno::Sequence< sal_Int8 > aSeq( nNumBytesSet );
  159. for( nIndex = 0; nIndex < nNumBytesSet; nIndex++ )
  160. {
  161. aSeq[nIndex] = static_cast<sal_Int8>(aData[nIndex]);
  162. }
  163. rAny <<= aSeq;
  164. }
  165. ////////////////////////////////////////////////////////////////////////////////////////////////////
  166. // SdrLayer
  167. ////////////////////////////////////////////////////////////////////////////////////////////////////
  168. void SdrLayer::SetStandardLayer(FASTBOOL bStd)
  169. {
  170. nType=(UINT16)bStd;
  171. if (bStd) {
  172. aName=ImpGetResStr(STR_StandardLayerName);
  173. }
  174. if (pModel!=NULL) {
  175. SdrHint aHint(HINT_LAYERCHG);
  176. pModel->Broadcast(aHint);
  177. pModel->SetChanged();
  178. }
  179. }
  180. void SdrLayer::SetName(const XubString& rNewName)
  181. {
  182. if(!rNewName.Equals(aName))
  183. {
  184. aName = rNewName;
  185. nType = 0; // Userdefined
  186. if(pModel)
  187. {
  188. SdrHint aHint(HINT_LAYERCHG);
  189. pModel->Broadcast(aHint);
  190. pModel->SetChanged();
  191. }
  192. }
  193. }
  194. bool SdrLayer::operator==(const SdrLayer& rCmpLayer) const
  195. {
  196. return (nID == rCmpLayer.nID
  197. && nType == rCmpLayer.nType
  198. && aName.Equals(rCmpLayer.aName));
  199. }
  200. ////////////////////////////////////////////////////////////////////////////////////////////////////
  201. // SdrLayerAdmin
  202. ////////////////////////////////////////////////////////////////////////////////////////////////////
  203. SdrLayerAdmin::SdrLayerAdmin(SdrLayerAdmin* pNewParent):
  204. aLayer(1024,16,16),
  205. aLSets(1024,16,16),
  206. pModel(NULL)
  207. {
  208. sal_Char aTextControls[] = "Controls";
  209. aControlLayerName = String(aTextControls, sizeof(aTextControls-1));
  210. pParent=pNewParent;
  211. }
  212. SdrLayerAdmin::SdrLayerAdmin(const SdrLayerAdmin& rSrcLayerAdmin):
  213. aLayer(1024,16,16),
  214. aLSets(1024,16,16),
  215. pParent(NULL),
  216. pModel(NULL)
  217. {
  218. sal_Char aTextControls[] = "Controls";
  219. aControlLayerName = String(aTextControls, sizeof(aTextControls-1));
  220. *this = rSrcLayerAdmin;
  221. }
  222. SdrLayerAdmin::~SdrLayerAdmin()
  223. {
  224. ClearLayer();
  225. }
  226. void SdrLayerAdmin::ClearLayer()
  227. {
  228. SdrLayer* pL;
  229. pL=(SdrLayer*)aLayer.First();
  230. while (pL!=NULL) {
  231. delete pL;
  232. pL=(SdrLayer*)aLayer.Next();
  233. }
  234. aLayer.Clear();
  235. }
  236. const SdrLayerAdmin& SdrLayerAdmin::operator=(const SdrLayerAdmin& rSrcLayerAdmin)
  237. {
  238. ClearLayer();
  239. pParent=rSrcLayerAdmin.pParent;
  240. USHORT i;
  241. USHORT nAnz=rSrcLayerAdmin.GetLayerCount();
  242. for (i=0; i<nAnz; i++) {
  243. aLayer.Insert(new SdrLayer(*rSrcLayerAdmin.GetLayer(i)),CONTAINER_APPEND);
  244. }
  245. return *this;
  246. }
  247. bool SdrLayerAdmin::operator==(const SdrLayerAdmin& rCmpLayerAdmin) const
  248. {
  249. if (pParent!=rCmpLayerAdmin.pParent ||
  250. aLayer.Count()!=rCmpLayerAdmin.aLayer.Count() ||
  251. aLSets.Count()!=rCmpLayerAdmin.aLSets.Count()) return FALSE;
  252. FASTBOOL bOk=TRUE;
  253. USHORT nAnz=GetLayerCount();
  254. USHORT i=0;
  255. while (bOk && i<nAnz) {
  256. bOk=*GetLayer(i)==*rCmpLayerAdmin.GetLayer(i);
  257. i++;
  258. }
  259. return bOk;
  260. }
  261. void SdrLayerAdmin::SetModel(SdrModel* pNewModel)
  262. {
  263. if (pNewModel!=pModel) {
  264. pModel=pNewModel;
  265. USHORT nAnz=GetLayerCount();
  266. USHORT i;
  267. for (i=0; i<nAnz; i++) {
  268. GetLayer(i)->SetModel(pNewModel);
  269. }
  270. }
  271. }
  272. void SdrLayerAdmin::Broadcast() const
  273. {
  274. if (pModel!=NULL) {
  275. SdrHint aHint(HINT_LAYERORDERCHG);
  276. pModel->Broadcast(aHint);
  277. pModel->SetChanged();
  278. }
  279. }
  280. SdrLayer* SdrLayerAdmin::RemoveLayer(USHORT nPos)
  281. {
  282. SdrLayer* pRetLayer=(SdrLayer*)(aLayer.Remove(nPos));
  283. Broadcast();
  284. return pRetLayer;
  285. }
  286. SdrLayer* SdrLayerAdmin::NewLayer(const XubString& rName, USHORT nPos)
  287. {
  288. SdrLayerID nID=GetUniqueLayerID();
  289. SdrLayer* pLay=new SdrLayer(nID,rName);
  290. pLay->SetModel(pModel);
  291. aLayer.Insert(pLay,nPos);
  292. Broadcast();
  293. return pLay;
  294. }
  295. SdrLayer* SdrLayerAdmin::NewStandardLayer(USHORT nPos)
  296. {
  297. SdrLayerID nID=GetUniqueLayerID();
  298. SdrLayer* pLay=new SdrLayer(nID,String());
  299. pLay->SetStandardLayer();
  300. pLay->SetModel(pModel);
  301. aLayer.Insert(pLay,nPos);
  302. Broadcast();
  303. return pLay;
  304. }
  305. SdrLayer* SdrLayerAdmin::MoveLayer(USHORT nPos, USHORT nNewPos)
  306. {
  307. SdrLayer* pLayer=(SdrLayer*)(aLayer.Remove(nPos));
  308. if (pLayer!=NULL) {
  309. aLayer.Insert(pLayer,nNewPos);
  310. }
  311. Broadcast();
  312. return pLayer;
  313. }
  314. void SdrLayerAdmin::MoveLayer(SdrLayer* pLayer, USHORT nNewPos)
  315. {
  316. ULONG nPos=aLayer.GetPos(pLayer);
  317. if (nPos!=CONTAINER_ENTRY_NOTFOUND) {
  318. aLayer.Remove(nPos);
  319. aLayer.Insert(pLayer,nNewPos);
  320. Broadcast();
  321. }
  322. }
  323. USHORT SdrLayerAdmin::GetLayerPos(SdrLayer* pLayer) const
  324. {
  325. ULONG nRet=SDRLAYER_NOTFOUND;
  326. if (pLayer!=NULL) {
  327. nRet=aLayer.GetPos(pLayer);
  328. if (nRet==CONTAINER_ENTRY_NOTFOUND) {
  329. nRet=SDRLAYER_NOTFOUND;
  330. }
  331. }
  332. return USHORT(nRet);
  333. }
  334. const SdrLayer* SdrLayerAdmin::GetLayer(const XubString& rName, FASTBOOL /*bInherited*/) const
  335. {
  336. UINT16 i(0);
  337. const SdrLayer* pLay = NULL;
  338. while(i < GetLayerCount() && !pLay)
  339. {
  340. if(rName.Equals(GetLayer(i)->GetName()))
  341. pLay = GetLayer(i);
  342. else
  343. i++;
  344. }
  345. if(!pLay && pParent)
  346. {
  347. pLay = pParent->GetLayer(rName, TRUE);
  348. }
  349. return pLay;
  350. }
  351. SdrLayerID SdrLayerAdmin::GetLayerID(const XubString& rName, FASTBOOL bInherited) const
  352. {
  353. SdrLayerID nRet=SDRLAYER_NOTFOUND;
  354. const SdrLayer* pLay=GetLayer(rName,bInherited);
  355. if (pLay!=NULL) nRet=pLay->GetID();
  356. return nRet;
  357. }
  358. const SdrLayer* SdrLayerAdmin::GetLayerPerID(USHORT nID) const
  359. {
  360. USHORT i=0;
  361. const SdrLayer* pLay=NULL;
  362. while (i<GetLayerCount() && pLay==NULL) {
  363. if (nID==GetLayer(i)->GetID()) pLay=GetLayer(i);
  364. else i++;
  365. }
  366. return pLay;
  367. }
  368. // Globale LayerID's beginnen mit 0 aufsteigend.
  369. // Lokale LayerID's beginnen mit 254 absteigend.
  370. // 255 ist reserviert fuer SDRLAYER_NOTFOUND
  371. SdrLayerID SdrLayerAdmin::GetUniqueLayerID() const
  372. {
  373. SetOfByte aSet;
  374. sal_Bool bDown = (pParent == NULL);
  375. USHORT j;
  376. for (j=0; j<GetLayerCount(); j++)
  377. {
  378. aSet.Set(GetLayer((sal_uInt16)j)->GetID());
  379. }
  380. SdrLayerID i;
  381. if (!bDown)
  382. {
  383. i=254;
  384. while (i && aSet.IsSet(BYTE(i)))
  385. --i;
  386. if (i == 0)
  387. i=254;
  388. }
  389. else
  390. {
  391. i=0;
  392. while (i<=254 && aSet.IsSet(BYTE(i)))
  393. i++;
  394. if (i>254)
  395. i=0;
  396. }
  397. return i;
  398. }