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