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  SW3, // SW3 file
78  XML // XML Block List
79  };
80  static FileType GetFileType( const OUString& );
81 
82  virtual void ClearDoc(); // Delete Doc content
83  std::unique_ptr<SwPaM> MakePaM(); // Span PaM over Doc
84  virtual void AddName( const OUString&, const OUString&, bool bOnlyText = false );
85  bool IsFileChanged() const;
86  void Touch();
87 
88 public:
89  virtual ~SwImpBlocks();
90 
91  static sal_uInt16 Hash( const OUString& );
92  sal_uInt16 GetCount() const;
93  sal_uInt16 GetIndex( const OUString& ) const;
94  sal_uInt16 GetLongIndex( const OUString& ) const;
95  OUString GetShortName( sal_uInt16 ) const;
96  OUString GetLongName( sal_uInt16 ) const;
97  OUString GetPackageName( sal_uInt16 ) const;
98 
99  const OUString& GetFileName() const {return m_aFile;}
100  void SetName( const OUString& rName )
101  { m_aName = rName; m_bInfoChanged = true; }
102  const OUString& GetName() const
103  { return m_aName; }
104 
105  const OUString& GetBaseURL() const { return m_sBaseURL;}
106  void SetBaseURL( const OUString& rURL ) { m_sBaseURL = rURL; }
107 
108  virtual ErrCode Delete( sal_uInt16 ) = 0;
109  virtual ErrCode Rename( sal_uInt16, const OUString& ) = 0;
110  virtual ErrCode GetDoc( sal_uInt16 ) = 0;
111  virtual ErrCode BeginPutDoc( const OUString&, const OUString& ) = 0;
112  virtual ErrCode PutDoc() = 0;
113  virtual ErrCode PutText( const OUString&, const OUString&, const OUString& ) = 0;
114  virtual ErrCode MakeBlockList() = 0;
115 
116  virtual ErrCode OpenFile( bool bReadOnly = true ) = 0;
117  virtual void CloseFile() = 0;
118 
119  virtual bool IsOnlyTextBlock( const OUString& rShort ) const;
120 
121  virtual ErrCode GetMacroTable( sal_uInt16 nIdx, SvxMacroTableDtor& rMacroTable );
122  virtual ErrCode SetMacroTable( sal_uInt16 nIdx,
123  const SvxMacroTableDtor& rMacroTable );
124  virtual bool PutMuchEntries( bool bOn );
125 };
126 
127 #endif
128 
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void ClearDoc()
Delete the document's content.
Definition: swblocks.cxx:111
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:185
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:137
virtual ErrCode PutDoc()=0
virtual ~SwImpBlocks()
Definition: swblocks.cxx:104
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:223
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:99
SwBlockName(const OUString &rShort, const OUString &rLong)
Unformatted text.
Definition: swblocks.cxx:58
const OUString & GetName() const
Definition: swblocks.hxx:102
sal_uInt16 GetCount() const
Hashcode for Block names.
Definition: swblocks.cxx:129
SwImpBlocks(const OUString &)
Definition: swblocks.cxx:89
virtual ErrCode PutText(const OUString &, const OUString &, const OUString &)=0
bool IsFileChanged() const
Definition: swblocks.cxx:199
virtual bool IsOnlyTextBlock(const OUString &rShort) const
Definition: swblocks.cxx:213
OUString m_aShort
Definition: swblocks.hxx:61
virtual ErrCode GetMacroTable(sal_uInt16 nIdx, SvxMacroTableDtor &rMacroTable)
Definition: swblocks.cxx:218
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:105
sal_uInt16 GetLongIndex(const OUString &) const
Index for shortnames.
Definition: swblocks.cxx:151
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:77
virtual ErrCode GetDoc(sal_uInt16)=0
OUString GetShortName(sal_uInt16) const
Index for longnames.
Definition: swblocks.cxx:164
OUString GetLongName(sal_uInt16) const
Return shortname for index.
Definition: swblocks.cxx:171
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:119
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:100
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:178
bool m_bInPutMuchBlocks
Definition: swblocks.hxx:69
virtual bool PutMuchEntries(bool bOn)
Definition: swblocks.cxx:228
SwBlockNames m_aNames
Definition: swblocks.hxx:63
void SetBaseURL(const OUString &rURL)
Definition: swblocks.hxx:106
static sal_uInt16 Hash(const OUString &)
Calculate hash code (is not guaranteed to be unique)
Definition: swblocks.cxx:46
void Touch()
Definition: swblocks.cxx:208