LibreOffice Module sw (master)  1
swblocks.hxx
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 #ifndef INCLUDED_SW_SOURCE_CORE_INC_SWBLOCKS_HXX
20 #define INCLUDED_SW_SOURCE_CORE_INC_SWBLOCKS_HXX
21 
22 #include <tools/date.hxx>
23 #include <tools/time.hxx>
24 #include <o3tl/sorted_vector.hxx>
25 #include <vcl/errcode.hxx>
26 #include <rtl/ref.hxx>
27 
28 class SwPaM;
29 class SwDoc;
30 class SvxMacroTableDtor;
31 
32 // Name of a text block:
33 
35 {
36  friend class SwImpBlocks;
37  sal_uInt16 nHashS, nHashL; // Hash codes for testing
38 public:
39  OUString const aShort;
40  OUString aLong;
41  OUString const aPackageName;
43  bool bIsOnlyText : 1;
44 
45  SwBlockName( const OUString& rShort, const OUString& rLong );
46  SwBlockName( const OUString& rShort, const OUString& rLong, const OUString& rPackageName );
47 
49  bool operator< ( const SwBlockName& r ) const { return aShort < r.aShort; }
50 };
51 
52 class SwBlockNames : public o3tl::sorted_vector<std::unique_ptr<SwBlockName>, o3tl::less_uniqueptr_to<SwBlockName> > {};
53 
55 {
56  friend class SwTextBlocks;
57 protected:
58  OUString const m_aFile; // Physical file name
59  OUString m_aName; // Logical file name
60  OUString m_aCurrentText; // Current text
61  OUString m_aShort, m_aLong; // Short- and longname (PutDoc)
62  OUString m_sBaseURL; // Base URL - has to be set at the Readers and Writers
63  SwBlockNames m_aNames; // List of all Blocks
64  Date m_aDateModified; // For aligning the Actions
66  rtl::Reference<SwDoc> m_xDoc; // Document to be switched
67  sal_uInt16 m_nCurrentIndex; // Current Index
68  bool m_bReadOnly : 1;
69  bool m_bInPutMuchBlocks : 1; // Put several block entries
70  bool m_bInfoChanged : 1; // Whether any info of TextBlock changed
71 
72  explicit SwImpBlocks( const OUString& );
73 
74  enum class FileType {
75  NoFile, // Not present
76  None, // No TB file
77  XML // XML Block List
78  };
79  static FileType GetFileType( const OUString& );
80 
81  virtual void ClearDoc(); // Delete Doc content
82  std::unique_ptr<SwPaM> MakePaM(); // Span PaM over Doc
83  virtual void AddName( const OUString&, const OUString&, bool bOnlyText = false );
84  bool IsFileChanged() const;
85  void Touch();
86 
87 public:
88  virtual ~SwImpBlocks();
89 
90  static sal_uInt16 Hash( const OUString& );
91  sal_uInt16 GetCount() const;
92  sal_uInt16 GetIndex( const OUString& ) const;
93  sal_uInt16 GetLongIndex( const OUString& ) const;
94  OUString GetShortName( sal_uInt16 ) const;
95  OUString GetLongName( sal_uInt16 ) const;
96  OUString GetPackageName( sal_uInt16 ) const;
97 
98  const OUString& GetFileName() const {return m_aFile;}
99  void SetName( const OUString& rName )
100  { m_aName = rName; m_bInfoChanged = true; }
101  const OUString& GetName() const
102  { return m_aName; }
103 
104  const OUString& GetBaseURL() const { return m_sBaseURL;}
105  void SetBaseURL( const OUString& rURL ) { m_sBaseURL = rURL; }
106 
107  virtual ErrCode Delete( sal_uInt16 ) = 0;
108  virtual ErrCode Rename( sal_uInt16, const OUString& ) = 0;
109  virtual ErrCode GetDoc( sal_uInt16 ) = 0;
110  virtual ErrCode BeginPutDoc( const OUString&, const OUString& ) = 0;
111  virtual ErrCode PutDoc() = 0;
112  virtual ErrCode PutText( const OUString&, const OUString&, const OUString& ) = 0;
113  virtual ErrCode MakeBlockList() = 0;
114 
115  virtual ErrCode OpenFile( bool bReadOnly = true ) = 0;
116  virtual void CloseFile() = 0;
117 
118  virtual bool IsOnlyTextBlock( const OUString& rShort ) const;
119 
120  virtual ErrCode GetMacroTable( sal_uInt16 nIdx, SvxMacroTableDtor& rMacroTable );
121  virtual ErrCode SetMacroTable( sal_uInt16 nIdx,
122  const SvxMacroTableDtor& rMacroTable );
123  virtual bool PutMuchEntries( bool bOn );
124 };
125 
126 #endif
127 
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void ClearDoc()
Delete the document's content.
Definition: swblocks.cxx:101
virtual ErrCode Rename(sal_uInt16, const OUString &)=0
virtual ErrCode OpenFile(bool bReadOnly=true)=0
virtual void AddName(const OUString &, const OUString &, bool bOnlyText=false)
Definition: swblocks.cxx:175
OUString m_sBaseURL
Definition: swblocks.hxx:62
rtl::Reference< SwDoc > m_xDoc
Definition: swblocks.hxx:66
bool bIsOnlyTextFlagInit
Package name.
Definition: swblocks.hxx:42
sal_uInt16 GetIndex(const OUString &) const
Get count of Text Blocks.
Definition: swblocks.cxx:127
virtual ErrCode PutDoc()=0
virtual ~SwImpBlocks()
Definition: swblocks.cxx:94
Definition: doc.hxx:185
sal_uInt16 m_nCurrentIndex
Definition: swblocks.hxx:67
OUString const m_aFile
Definition: swblocks.hxx:58
virtual ErrCode SetMacroTable(sal_uInt16 nIdx, const SvxMacroTableDtor &rMacroTable)
Definition: swblocks.cxx:213
tools::Time m_aTimeModified
Definition: swblocks.hxx:65
OUString const aPackageName
Longname.
Definition: swblocks.hxx:41
const OUString & GetFileName() const
Return packagename for index.
Definition: swblocks.hxx:98
SwBlockName(const OUString &rShort, const OUString &rLong)
Unformatted text.
Definition: swblocks.cxx:50
const OUString & GetName() const
Definition: swblocks.hxx:101
sal_uInt16 GetCount() const
Hashcode for Block names.
Definition: swblocks.cxx:119
SwImpBlocks(const OUString &)
Definition: swblocks.cxx:79
virtual ErrCode PutText(const OUString &, const OUString &, const OUString &)=0
bool IsFileChanged() const
Definition: swblocks.cxx:189
virtual bool IsOnlyTextBlock(const OUString &rShort) const
Definition: swblocks.cxx:203
OUString m_aShort
Definition: swblocks.hxx:61
virtual ErrCode GetMacroTable(sal_uInt16 nIdx, SvxMacroTableDtor &rMacroTable)
Definition: swblocks.cxx:208
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
virtual void CloseFile()=0
bool m_bInfoChanged
Definition: swblocks.hxx:70
const OUString & GetBaseURL() const
Definition: swblocks.hxx:104
sal_uInt16 GetLongIndex(const OUString &) const
Index for shortnames.
Definition: swblocks.cxx:141
virtual ErrCode BeginPutDoc(const OUString &, const OUString &)=0
static FileType GetFileType(const OUString &)
Is the provided file a storage or doesn't it exist?
Definition: swblocks.cxx:69
virtual ErrCode GetDoc(sal_uInt16)=0
OUString GetShortName(sal_uInt16) const
Index for longnames.
Definition: swblocks.cxx:154
OUString GetLongName(sal_uInt16) const
Return shortname for index.
Definition: swblocks.cxx:161
OUString m_aName
Definition: swblocks.hxx:59
virtual ErrCode Delete(sal_uInt16)=0
std::unique_ptr< SwPaM > MakePaM()
Creating a PaM, that spans the whole document.
Definition: swblocks.cxx:109
OUString m_aLong
Definition: swblocks.hxx:61
OUString m_aCurrentText
Definition: swblocks.hxx:60
bool operator<(const SwBlockName &r) const
For sorting in the array.
Definition: swblocks.hxx:49
OUString aLong
Shortname.
Definition: swblocks.hxx:40
bool bIsOnlyText
Is the Flag valid?
Definition: swblocks.hxx:43
sal_uInt16 nHashS
Definition: swblocks.hxx:37
virtual ErrCode MakeBlockList()=0
void SetName(const OUString &rName)
Return physical file name.
Definition: swblocks.hxx:99
OUString const aShort
Definition: swblocks.hxx:39
bool m_bReadOnly
Definition: swblocks.hxx:68
Date m_aDateModified
Definition: swblocks.hxx:64
sal_uInt16 nHashL
Definition: swblocks.hxx:37
OUString GetPackageName(sal_uInt16) const
Return longname for index.
Definition: swblocks.cxx:168
bool m_bInPutMuchBlocks
Definition: swblocks.hxx:69
virtual bool PutMuchEntries(bool bOn)
Definition: swblocks.cxx:218
SwBlockNames m_aNames
Definition: swblocks.hxx:63
void SetBaseURL(const OUString &rURL)
Definition: swblocks.hxx:105
static sal_uInt16 Hash(const OUString &)
Calculate hash code (is not guaranteed to be unique)
Definition: swblocks.cxx:38
void Touch()
Definition: swblocks.cxx:198