LibreOffice Module sc (master)  1
drwlayer.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 
20 #pragma once
21 
22 #include <svx/fmmodel.hxx>
23 #include <svx/svdundo.hxx>
24 #include "global.hxx"
25 
26 class ScDocument;
27 class SfxObjectShell;
28 class ScDrawObjData;
29 class ScMacroInfo;
30 class ScMarkData;
31 
32 class ScTabDeletedHint final : public SfxHint
33 {
34 private:
36 public:
37  ScTabDeletedHint( SCTAB nTabNo );
38  virtual ~ScTabDeletedHint() override;
39 
40  SCTAB GetTab() const { return nTab; }
41 };
42 
43 class ScTabSizeChangedHint final : public SfxHint
44 {
45 private:
47 public:
48  ScTabSizeChangedHint( SCTAB nTabNo );
49  virtual ~ScTabSizeChangedHint() override;
50 
51  SCTAB GetTab() const { return nTab; }
52 };
53 
54 // Adjusting of detective UserData and draw undo's both have to be in SdrUndoGroup;
55 // therefore derived from SdrUndoAction
56 
57 class ScUndoObjData final : public SdrUndoObj
58 {
59 private:
64 public:
65  ScUndoObjData( SdrObject* pObj, const ScAddress& rOS, const ScAddress& rOE,
66  const ScAddress& rNS, const ScAddress& rNE );
67  virtual ~ScUndoObjData() override;
68 
69  virtual void Undo() override;
70  virtual void Redo() override;
71 };
72 
73 class ScUndoAnchorData final : public SdrUndoObj
74 {
75 private:
80 public:
82  virtual ~ScUndoAnchorData() override;
83 
84  virtual void Undo() override;
85  virtual void Redo() override;
86 };
87 
88 // for ScDrawLayer::SetPageSize
89 enum class ScObjectHandling
90 {
91  RecalcPosMode, // used for row height or col width changes
92  MoveRTLMode, // used for switch to RTL during import of right-to-left sheet
93  MirrorRTLMode // used for switch between RTL and LTR by .uno:SheetRightToLeft
94 };
95 
96 class SC_DLLPUBLIC ScDrawLayer final : public FmFormModel
97 {
98 private:
99  OUString aName;
101  std::unique_ptr<SdrUndoGroup> pUndoGroup;
105 
106 private:
107  void MoveCells( SCTAB nTab, SCCOL nCol1,SCROW nRow1, SCCOL nCol2,SCROW nRow2,
108  SCCOL nDx,SCROW nDy, bool bUpdateNoteCaptionPos );
109 
110  void ResizeLastRectFromAnchor( const SdrObject* pObj, ScDrawObjData& rData, bool bNegativePage, bool bCanResize );
111 
112 public:
113  ScDrawLayer( ScDocument* pDocument, const OUString& rName );
114  virtual ~ScDrawLayer() override;
115 
116  virtual rtl::Reference<SdrPage> AllocPage(bool bMasterPage) override;
117  virtual SdrModel* AllocModel() const override;
118  virtual void SetChanged( bool bFlg = true ) override;
119 
120  bool HasObjects() const;
121 
122  bool ScAddPage( SCTAB nTab );
123  void ScRemovePage( SCTAB nTab );
124  void ScRenamePage( SCTAB nTab, const OUString& rNewName );
125  void ScMovePage( sal_uInt16 nOldPos, sal_uInt16 nNewPos );
126  void ScCopyPage( sal_uInt16 nOldPos, sal_uInt16 nNewPos );
127  void ResetTab( SCTAB nStart, SCTAB nEnd );
128 
129  ScDocument* GetDocument() const { return pDoc; }
130 
131  void UseHyphenator();
132 
133  bool GetPrintArea( ScRange& rRange, bool bSetHor, bool bSetVer ) const;
134 
135  // automatic adjustments
136 
137  void EnableAdjust( bool bSet ) { bAdjustEnabled = bSet; }
138 
139  void BeginCalcUndo(bool bDisableTextEditUsesCommonUndoManager);
140  std::unique_ptr<SdrUndoGroup> GetCalcUndo();
141  bool IsRecording() const { return bRecording; }
142  void AddCalcUndo( std::unique_ptr<SdrUndoAction> pUndo );
143 
144  void MoveArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1, SCCOL nCol2,SCROW nRow2,
145  SCCOL nDx,SCROW nDy, bool bInsDel, bool bUpdateNoteCaptionPos );
146  void InitializeCellAnchoredObj(SdrObject* pObj, ScDrawObjData& rData);
147  void RecalcPos( SdrObject* pObj, ScDrawObjData& rData, bool bNegativePage, bool bUpdateNoteCaptionPos );
148 
149  bool HasObjectsInRows( SCTAB nTab, SCROW nStartRow, SCROW nEndRow );
150 
151  void DeleteObjectsInArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1,
152  SCCOL nCol2,SCROW nRow2, bool bAnchored = false );
153  void DeleteObjectsInSelection( const ScMarkData& rMark );
154 
155  void CopyToClip( ScDocument* pClipDoc, SCTAB nTab, const tools::Rectangle& rRange );
156  void CopyFromClip( ScDrawLayer* pClipModel,
157  SCTAB nSourceTab, const tools::Rectangle& rSourceRange,
158  const ScAddress& rDestPos, const tools::Rectangle& rDestRange );
159 
160  void SetPageSize(sal_uInt16 nPageNo, const Size& rSize, bool bUpdateNoteCaptionPos,
161  const ScObjectHandling eObjectHandling = ScObjectHandling::RecalcPosMode);
162 
163  // mirror or move between positive and negative positions for RTL
164  void MirrorRTL( SdrObject* pObj );
165  void MoveRTL(SdrObject* pObj);
166  static void MirrorRectRTL( tools::Rectangle& rRect ); // for bounding rectangles etc.
167 
170  static tools::Rectangle GetCellRect( const ScDocument& rDoc, const ScAddress& rPos, bool bMergedCell );
171 
172  // GetVisibleName: name for navigator etc: GetPersistName or GetName
173  // (ChartListenerCollection etc. must use GetPersistName directly)
174  static OUString GetVisibleName( const SdrObject* pObj );
175 
176  SdrObject* GetNamedObject( std::u16string_view rName, sal_uInt16 nId, SCTAB& rFoundTab ) const;
177  // if pnCounter != NULL, the search for a name starts with this index + 1,
178  // and the index really used is returned.
179  OUString GetNewGraphicName( tools::Long* pnCounter = nullptr ) const;
180  void EnsureGraphicNames();
181 
182  static bool IsCellAnchored( const SdrObject& rObj );
183  static bool IsResizeWithCell( const SdrObject& rObj );
184  static void SetPageAnchored( SdrObject& );
185  static void SetCellAnchored( SdrObject&, const ScDrawObjData &rAnchor );
186  static void SetNonRotatedAnchor( SdrObject&, const ScDrawObjData &rAnchor );
187 
188  // Updates rAnchor based on position of rObj
189  static void GetCellAnchorFromPosition(
190  const tools::Rectangle &rRectangle,
191  ScDrawObjData &rAnchor,
192  const ScDocument &rDoc,
193  SCTAB nTab,
194  bool bHiddenAsZero = true);
195 
196  static void SetCellAnchoredFromPosition( SdrObject &rObj, const ScDocument &rDoc, SCTAB nTab, bool bResizeWithCell );
197  static void UpdateCellAnchorFromPositionEnd( const SdrObject &rObj, ScDrawObjData &rAnchor, const ScDocument &rDoc, SCTAB nTab, bool bUseLogicRect = true );
198  static ScAnchorType GetAnchorType( const SdrObject& );
199  std::vector<SdrObject*> GetObjectsAnchoredToRows(SCTAB nTab, SCROW nStartRow, SCROW nEndRow);
200  std::map<SCROW, std::vector<SdrObject*>> GetObjectsAnchoredToRange(SCTAB nTab, SCCOL nCol, SCROW nStartRow, SCROW nEndRow);
201  bool HasObjectsAnchoredInRange(const ScRange& rRange);
202  std::vector<SdrObject*> GetObjectsAnchoredToCols(SCTAB nTab, SCCOL nStartCol, SCCOL nEndCol);
203  void MoveObject(SdrObject* pObj, const ScAddress& rNewPosition);
204 
205  // positions for detective lines
206  static ScDrawObjData* GetObjData( SdrObject* pObj, bool bCreate=false );
207  static ScDrawObjData* GetNonRotatedObjData( SdrObject* pObj, bool bCreate=false );
208 
209  // The sheet information in ScDrawObjData isn't updated when sheets are inserted/deleted.
210  // Use this method to get an object with positions on the specified sheet (should be the
211  // sheet on which the object is inserted).
212  static ScDrawObjData* GetObjDataTab( SdrObject* pObj, SCTAB nTab );
213 
215  static bool IsNoteCaption( SdrObject* pObj );
216 
218  static ScDrawObjData* GetNoteCaptionData( SdrObject* pObj, SCTAB nTab );
219 
220  static ScMacroInfo* GetMacroInfo( SdrObject* pObj, bool bCreate = false );
221 
222 private:
223  static SfxObjectShell* pGlobalDrawPersist; // for AllocModel
224 public:
225  static void SetGlobalDrawPersist(SfxObjectShell* pPersist);
226 private:
227  virtual css::uno::Reference< css::uno::XInterface > createUnoModel() override;
228 };
229 
230 extern bool bDrawIsInUndo; // somewhere as member!
231 
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool mbWasCellAnchored
Definition: drwlayer.hxx:76
bool bAdjustEnabled
Definition: drwlayer.hxx:103
static SfxObjectShell * pGlobalDrawPersist
Definition: drwlayer.hxx:223
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:42
SCTAB GetTab() const
Definition: drwlayer.hxx:40
ScObjectHandling
Definition: drwlayer.hxx:89
ScUndoObjData(SdrObject *pObj, const ScAddress &rOS, const ScAddress &rOE, const ScAddress &rNS, const ScAddress &rNE)
Definition: drwlayer.cxx:94
virtual css::uno::Reference< css::uno::XInterface > createUnoModel()
long Long
ScAddress aNewStt
Definition: drwlayer.hxx:62
virtual ~ScTabDeletedHint() override
Definition: drwlayer.cxx:194
SCTAB GetTab() const
Definition: drwlayer.hxx:51
virtual void Redo() override
Definition: drwlayer.cxx:174
virtual ~ScUndoObjData() override
Definition: drwlayer.cxx:104
ScUndoAnchorData(SdrObject *pObj, ScDocument *pDoc, SCTAB nTab)
Definition: drwlayer.cxx:146
virtual void SetChanged(bool bFlg=true)
virtual void Redo() override
Definition: drwlayer.cxx:127
ScDocument * GetDocument() const
Definition: drwlayer.hxx:129
ScAnchorType
Definition: global.hxx:382
bool bRecording
Definition: drwlayer.hxx:102
ScAddress aOldStt
Definition: drwlayer.hxx:60
sal_Int16 SCCOL
Definition: types.hxx:21
virtual ~ScUndoAnchorData() override
Definition: drwlayer.cxx:155
ScDocument * pDoc
Definition: drwlayer.hxx:100
SdrObject * pObj
virtual void Undo() override
Definition: drwlayer.cxx:108
virtual rtl::Reference< SdrPage > AllocPage(bool bMasterPage) override
bool bHyphenatorSet
Definition: drwlayer.hxx:104
sal_Int32 SCROW
Definition: types.hxx:17
virtual void Undo() override
Definition: drwlayer.cxx:159
virtual SdrModel * AllocModel() const
std::unique_ptr< SdrUndoGroup > pUndoGroup
Definition: drwlayer.hxx:101
OUString aName
Definition: drwlayer.hxx:99
virtual ~ScTabSizeChangedHint() override
Definition: drwlayer.cxx:203
ScAddress aNewEnd
Definition: drwlayer.hxx:63
bool mbWasResizeWithCell
Definition: drwlayer.hxx:77
ScAddress aOldEnd
Definition: drwlayer.hxx:61
ScTabDeletedHint(SCTAB nTabNo)
Definition: drwlayer.cxx:189
void EnableAdjust(bool bSet)
Definition: drwlayer.hxx:137
bool bDrawIsInUndo
Definition: drwlayer.cxx:92
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
ScTabSizeChangedHint(SCTAB nTabNo)
Definition: drwlayer.cxx:198
ScDocument * mpDoc
Definition: drwlayer.hxx:78
sal_Int16 SCTAB
Definition: types.hxx:22
bool IsRecording() const
Definition: drwlayer.hxx:141