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 23 24 #ifndef _SECTION_HXX 25 #define _SECTION_HXX 26 27 #include <boost/utility.hpp> 28 29 #include <com/sun/star/uno/Sequence.h> 30 31 #include <tools/rtti.hxx> 32 #include <tools/ref.hxx> 33 #include <svl/svarray.hxx> 34 // --> OD #i117863# 35 #include <svl/smplhint.hxx> 36 // <-- 37 #include <sfx2/lnkbase.hxx> 38 #include <sfx2/Metadatable.hxx> 39 40 #include <frmfmt.hxx> 41 42 43 namespace com { namespace sun { namespace star { 44 namespace text { class XTextSection; } 45 } } } 46 47 // Forward Deklaration 48 class SwSectionFmt; 49 class SwDoc; 50 class SwSection; 51 class SwSectionNode; 52 class SwTOXBase; 53 54 #ifndef SW_DECL_SWSERVEROBJECT_DEFINED 55 #define SW_DECL_SWSERVEROBJECT_DEFINED 56 SV_DECL_REF( SwServerObject ) 57 #endif 58 59 SV_DECL_PTRARR( SwSections, SwSection*, 0, 4 ) 60 61 enum SectionType { CONTENT_SECTION, 62 TOX_HEADER_SECTION, 63 TOX_CONTENT_SECTION, 64 DDE_LINK_SECTION = OBJECT_CLIENT_DDE, 65 FILE_LINK_SECTION = OBJECT_CLIENT_FILE 66 /* 67 // verbleiben noch: 68 OBJECT_CLIENT_SO = 0x80, 69 OBJECT_CLIENT_OLE = 0x82, 70 OBJECT_CLIENT_OLE_CACHE = 0x83, 71 */ 72 }; 73 74 enum LinkCreateType 75 { 76 CREATE_NONE, // nichts weiter tun 77 CREATE_CONNECT, // Link gleich connecten 78 CREATE_UPDATE // Link connecten und updaten 79 }; 80 81 class SW_DLLPUBLIC SwSectionData 82 { 83 private: 84 SectionType m_eType; 85 86 String m_sSectionName; 87 String m_sCondition; 88 String m_sLinkFileName; 89 String m_sLinkFilePassword; // JP 27.02.2001: must be changed to Sequence 90 ::com::sun::star::uno::Sequence <sal_Int8> m_Password; 91 92 /// it seems this flag caches the current final "hidden" state 93 bool m_bHiddenFlag : 1; 94 /// flags that correspond to attributes in the format: 95 /// may have different value than format attribute: 96 /// format attr has value for this section, while flag is 97 /// effectively ORed with parent sections! 98 bool m_bProtectFlag : 1; 99 // --> FME 2004-06-22 #114856# edit in readonly sections 100 bool m_bEditInReadonlyFlag : 1; 101 // <-- 102 bool m_bHidden : 1; // all paragraphs hidden? 103 bool m_bCondHiddenFlag : 1; // Hiddenflag for condition 104 bool m_bConnectFlag : 1; // connected to server? 105 106 public: 107 108 SwSectionData(SectionType const eType, String const& rName); 109 explicit SwSectionData(SwSection const&); 110 SwSectionData(SwSectionData const&); 111 SwSectionData & operator=(SwSectionData const&); 112 bool operator==(SwSectionData const&) const; 113 114 String const& GetSectionName() const { return m_sSectionName; } 115 void SetSectionName(String const& rName){ m_sSectionName = rName; } 116 SectionType GetType() const { return m_eType; } 117 void SetType(SectionType const eNew) { m_eType = eNew; } 118 119 bool IsHidden() const { return m_bHidden; } 120 void SetHidden(bool const bFlag = true) { m_bHidden = bFlag; } 121 122 bool IsHiddenFlag() const { return m_bHiddenFlag; } 123 SW_DLLPRIVATE void 124 SetHiddenFlag(bool const bFlag) { m_bHiddenFlag = bFlag; } 125 bool IsProtectFlag() const { return m_bProtectFlag; } 126 SW_DLLPRIVATE void 127 SetProtectFlag(bool const bFlag) { m_bProtectFlag = bFlag; } 128 // --> FME 2004-06-22 #114856# edit in readonly sections 129 bool IsEditInReadonlyFlag() const { return m_bEditInReadonlyFlag; } 130 void SetEditInReadonlyFlag(bool const bFlag) 131 { m_bEditInReadonlyFlag = bFlag; } 132 // <-- 133 134 void SetCondHidden(bool const bFlag = true) { m_bCondHiddenFlag = bFlag; }; 135 bool IsCondHidden() const { return m_bCondHiddenFlag; } 136 137 String const& GetCondition() const { return m_sCondition; } 138 void SetCondition(String const& rNew) { m_sCondition = rNew; } 139 140 String const& GetLinkFileName() const { return m_sLinkFileName; }; 141 void SetLinkFileName(String const& rNew, String const* pPassWd = 0) 142 { 143 m_sLinkFileName = rNew; 144 if (pPassWd) { SetLinkFilePassword(*pPassWd); } 145 } 146 147 String const& GetLinkFilePassword() const { return m_sLinkFilePassword; } 148 void SetLinkFilePassword(String const& rS) { m_sLinkFilePassword = rS; } 149 150 ::com::sun::star::uno::Sequence<sal_Int8> const& GetPassword() const 151 { return m_Password; } 152 void SetPassword(::com::sun::star::uno::Sequence<sal_Int8> const& rNew) 153 { m_Password = rNew; } 154 bool IsLinkType() const 155 { return (DDE_LINK_SECTION == m_eType) || (FILE_LINK_SECTION == m_eType); } 156 157 bool IsConnectFlag() const { return m_bConnectFlag; } 158 void SetConnectFlag(bool const bFlag = true){ m_bConnectFlag = bFlag; } 159 }; 160 161 class SW_DLLPUBLIC SwSection 162 : public SwClient 163 { 164 // damit beim Anlegen/Loeschen von Frames das Flag richtig gepflegt wird! 165 friend class SwSectionNode; 166 // the "read CTOR" of SwSectionFrm have to change the Hiddenflag 167 friend class SwSectionFrm; 168 169 private: 170 SwSectionData m_Data; 171 172 SwServerObjectRef m_RefObj; // set if DataServer 173 ::sfx2::SvBaseLinkRef m_RefLink; 174 175 SW_DLLPRIVATE void ImplSetHiddenFlag( 176 bool const bHidden, bool const bCondition); 177 178 protected: 179 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ); 180 181 public: 182 TYPEINFO(); // rtti 183 184 SwSection(SectionType const eType, String const& rName, 185 SwSectionFmt & rFormat); 186 virtual ~SwSection(); 187 188 bool DataEquals(SwSectionData const& rCmp) const; 189 190 void SetSectionData(SwSectionData const& rData); 191 192 String const& GetSectionName() const { return m_Data.GetSectionName(); } 193 void SetSectionName(String const& rName){ m_Data.SetSectionName(rName); } 194 SectionType GetType() const { return m_Data.GetType(); } 195 void SetType(SectionType const eType) { return m_Data.SetType(eType); } 196 197 SwSectionFmt* GetFmt() { return (SwSectionFmt*)GetRegisteredIn(); } 198 SwSectionFmt* GetFmt() const { return (SwSectionFmt*)GetRegisteredIn(); } 199 200 // setze die Hidden/Protected -> gesamten Baum updaten ! 201 // (Attribute/Flags werden gesetzt/erfragt) 202 bool IsHidden() const { return m_Data.IsHidden(); } 203 void SetHidden (bool const bFlag = true); 204 bool IsProtect() const; 205 void SetProtect(bool const bFlag = true); 206 // --> FME 2004-06-22 #114856# edit in readonly sections 207 bool IsEditInReadonly() const; 208 void SetEditInReadonly(bool const bFlag = true); 209 // <-- 210 211 // erfrage die internen Flags (Zustand inklusive Parents nicht, was 212 // aktuell an der Section gesetzt ist!!) 213 bool IsHiddenFlag() const { return m_Data.IsHiddenFlag(); } 214 bool IsProtectFlag() const { return m_Data.IsProtectFlag(); } 215 // --> FME 2004-06-22 #114856# edit in readonly sections 216 bool IsEditInReadonlyFlag() const { return m_Data.IsEditInReadonlyFlag(); } 217 // <-- 218 219 void SetCondHidden(bool const bFlag = true); 220 bool IsCondHidden() const { return m_Data.IsCondHidden(); } 221 // erfrage (auch ueber die Parents), ob diese Section versteckt sein soll. 222 sal_Bool CalcHiddenFlag() const; 223 224 225 inline SwSection* GetParent() const; 226 227 String const& GetCondition() const { return m_Data.GetCondition(); } 228 void SetCondition(String const& rNew) { m_Data.SetCondition(rNew); } 229 230 const String& GetLinkFileName() const; 231 void SetLinkFileName(String const& rNew, String const*const pPassWd = 0); 232 // password of linked file (only valid during runtime!) 233 String const& GetLinkFilePassword() const 234 { return m_Data.GetLinkFilePassword(); } 235 void SetLinkFilePassword(String const& rS) 236 { m_Data.SetLinkFilePassword(rS); } 237 238 // get / set password of this section 239 ::com::sun::star::uno::Sequence<sal_Int8> const& GetPassword() const 240 { return m_Data.GetPassword(); } 241 void SetPassword(::com::sun::star::uno::Sequence <sal_Int8> const& rNew) 242 { m_Data.SetPassword(rNew); } 243 244 // Daten Server-Methoden 245 void SetRefObject( SwServerObject* pObj ); 246 const SwServerObject* GetObject() const { return & m_RefObj; } 247 SwServerObject* GetObject() { return & m_RefObj; } 248 bool IsServer() const { return m_RefObj.Is(); } 249 250 // Methoden fuer gelinkte Bereiche 251 sal_uInt16 GetUpdateType() const { return m_RefLink->GetUpdateMode(); } 252 void SetUpdateType(sal_uInt16 const nType ) 253 { m_RefLink->SetUpdateMode(nType); } 254 255 bool IsConnected() const { return m_RefLink.Is(); } 256 void UpdateNow() { m_RefLink->Update(); } 257 void Disconnect() { m_RefLink->Disconnect(); } 258 259 const ::sfx2::SvBaseLink& GetBaseLink() const { return *m_RefLink; } 260 ::sfx2::SvBaseLink& GetBaseLink() { return *m_RefLink; } 261 262 void CreateLink( LinkCreateType eType ); 263 264 void MakeChildLinksVisible( const SwSectionNode& rSectNd ); 265 266 bool IsLinkType() const { return m_Data.IsLinkType(); } 267 268 // Flags fuer UI - Verbindung geklappt? 269 bool IsConnectFlag() const { return m_Data.IsConnectFlag(); } 270 void SetConnectFlag(bool const bFlag = true) 271 { m_Data.SetConnectFlag(bFlag); } 272 273 // return the TOX base class if the section is a TOX section 274 const SwTOXBase* GetTOXBase() const; 275 276 // --> OD 2007-02-14 #b6521322# 277 void BreakLink(); 278 // <-- 279 280 }; 281 282 // --> OD #i117863# 283 class SwSectionFrmMoveAndDeleteHint : public SfxSimpleHint 284 { 285 public: 286 SwSectionFrmMoveAndDeleteHint( const sal_Bool bSaveCntnt ) 287 : SfxSimpleHint( SFX_HINT_DYING ) 288 , mbSaveCntnt( bSaveCntnt ) 289 {} 290 291 ~SwSectionFrmMoveAndDeleteHint() 292 {} 293 294 sal_Bool IsSaveCntnt() const 295 { 296 return mbSaveCntnt; 297 } 298 299 private: 300 const sal_Bool mbSaveCntnt; 301 }; 302 // <-- 303 304 enum SectionSort { SORTSECT_NOT, SORTSECT_NAME, SORTSECT_POS }; 305 306 class SW_DLLPUBLIC SwSectionFmt 307 : public SwFrmFmt 308 , public ::sfx2::Metadatable 309 { 310 friend class SwDoc; 311 312 /** why does this exist in addition to the m_wXObject in SwFrmFmt? 313 in case of an index, both a SwXDocumentIndex and a SwXTextSection 314 register at this SwSectionFmt, so we need to have two refs. 315 */ 316 ::com::sun::star::uno::WeakReference< 317 ::com::sun::star::text::XTextSection> m_wXTextSection; 318 319 SW_DLLPRIVATE void UpdateParent(); // Parent wurde veraendert 320 321 protected: 322 SwSectionFmt( SwSectionFmt* pDrvdFrm, SwDoc *pDoc ); 323 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ); 324 325 public: 326 TYPEINFO(); //Bereits in Basisklasse Client drin. 327 ~SwSectionFmt(); 328 329 //Vernichtet alle Frms in aDepend (Frms werden per PTR_CAST erkannt). 330 virtual void DelFrms(); 331 332 //Erzeugt die Ansichten 333 virtual void MakeFrms(); 334 335 // erfrage vom Format Informationen 336 virtual sal_Bool GetInfo( SfxPoolItem& ) const; 337 338 SwSection* GetSection() const; 339 inline SwSectionFmt* GetParent() const; 340 inline SwSection* GetParentSection() const; 341 342 // alle Sections, die von dieser abgeleitet sind 343 // - sortiert nach : Name oder Position oder unsortiert 344 // - alle oder nur die, die sich im normalten Nodes-Array befinden 345 sal_uInt16 GetChildSections( SwSections& rArr, 346 SectionSort eSort = SORTSECT_NOT, 347 sal_Bool bAllSections = sal_True ) const; 348 349 // erfrage, ob sich die Section im Nodes-Array oder UndoNodes-Array 350 // befindet. 351 sal_Bool IsInNodesArr() const; 352 353 SwSectionNode* GetSectionNode(bool const bEvenIfInUndo = false); 354 const SwSectionNode* GetSectionNode(bool const bEvenIfInUndo = false) const 355 { return const_cast<SwSectionFmt *>(this) 356 ->GetSectionNode(bEvenIfInUndo); } 357 358 // ist die Section eine gueltige fuers GlobalDocument? 359 const SwSection* GetGlobalDocSection() const; 360 361 SW_DLLPRIVATE ::com::sun::star::uno::WeakReference< 362 ::com::sun::star::text::XTextSection> const& GetXTextSection() const 363 { return m_wXTextSection; } 364 SW_DLLPRIVATE void SetXTextSection(::com::sun::star::uno::Reference< 365 ::com::sun::star::text::XTextSection> const& xTextSection) 366 { m_wXTextSection = xTextSection; } 367 368 // sfx2::Metadatable 369 virtual ::sfx2::IXmlIdRegistry& GetRegistry(); 370 virtual bool IsInClipboard() const; 371 virtual bool IsInUndo() const; 372 virtual bool IsInContent() const; 373 virtual ::com::sun::star::uno::Reference< 374 ::com::sun::star::rdf::XMetadatable > MakeUnoObject(); 375 376 }; 377 378 // -------------- inlines --------------------------------- 379 380 inline SwSection* SwSection::GetParent() const 381 { 382 SwSectionFmt* pFmt = GetFmt(); 383 SwSection* pRet = 0; 384 if( pFmt ) 385 pRet = pFmt->GetParentSection(); 386 return pRet; 387 } 388 389 inline SwSectionFmt* SwSectionFmt::GetParent() const 390 { 391 SwSectionFmt* pRet = 0; 392 if( GetRegisteredIn() ) 393 pRet = PTR_CAST( SwSectionFmt, GetRegisteredIn() ); 394 return pRet; 395 } 396 397 inline SwSection* SwSectionFmt::GetParentSection() const 398 { 399 SwSectionFmt* pParent = GetParent(); 400 SwSection* pRet = 0; 401 if( pParent ) 402 { 403 pRet = pParent->GetSection(); 404 } 405 return pRet; 406 } 407 408 409 #endif /* _SECTION_HXX */ 410