/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #ifndef INCLUDED_SC_INC_POSTIT_HXX #define INCLUDED_SC_INC_POSTIT_HXX #include #include "address.hxx" #include "scdllapi.h" #include #include class EditTextObject; class OutlinerParaObject; class SdrCaptionObj; class SdrPage; class SfxItemSet; class ScDocument; namespace tools { class Rectangle; } struct ScCaptionInitData; /** Some desperate attempt to fight against the caption object ownership mess, to which none of shared/weak/plain pointer is a cure. */ class ScCaptionPtr { public: ScCaptionPtr(); explicit ScCaptionPtr( SdrCaptionObj* p ); ScCaptionPtr( const ScCaptionPtr& r ); ScCaptionPtr( ScCaptionPtr&& r ); ~ScCaptionPtr(); ScCaptionPtr& operator=( const ScCaptionPtr& r ); ScCaptionPtr& operator=( ScCaptionPtr&& r ); explicit operator bool() const { return mpCaption != nullptr; } SdrCaptionObj* get() const { return mpCaption; } SdrCaptionObj* operator->() const { return mpCaption; } SdrCaptionObj& operator*() const { return *mpCaption; } // Does not default to nullptr to make it visually obvious where such is used. void reset( SdrCaptionObj* p ); /** Insert to draw page. The caption object is owned by the draw page then. */ void insertToDrawPage( SdrPage& rDrawPage ); /** Remove from draw page. The caption object is not owned anymore by the draw page then. */ void removeFromDrawPage( SdrPage& rDrawPage ); /** Remove from draw page and free caption object if no Undo recording. */ void removeFromDrawPageAndFree( bool bIgnoreUndo = false ); /** Release all management of the SdrCaptionObj* in all instances of this list and dissolve. The SdrCaptionObj pointer returned is ready to be managed elsewhere. */ SdrCaptionObj* release(); /** Forget the SdrCaptionObj pointer in this one instance. Decrements a use count but does not destroy the object, it's up to the caller to manage this mess.. @returns if the last reference was decremented. */ bool forget(); /** Flag that this instance is in Undo, so drawing layer owns it. */ void setNotOwner(); oslInterlockedCount getRefs() const; private: struct Head { ScCaptionPtr* mpFirst; ///< first in list oslInterlockedCount mnRefs; ///< use count Head() = delete; explicit Head( ScCaptionPtr* ); }; Head* mpHead; ///< points to the "master" entry mutable ScCaptionPtr* mpNext; ///< next in list SdrCaptionObj* mpCaption; ///< the caption object, managed by head master bool mbNotOwner; ///< whether this caption object is owned by something else, e.g. held in Undo /* TODO: can that be moved to Head? * It's unclear when to reset, so * each instance has its own flag. * The last reference count * decrement automatically has the * then current state available. * */ void newHead(); //< Allocate a new Head and init. void incRef() const; bool decRef() const; //< @returns if the last reference was decremented. void decRefAndDestroy(); //< Destroys caption object if the last reference was decremented. /** Remove from current list and close gap. Usually there are only very few instances, so maintaining a doubly linked list isn't worth memory/performance wise and a simple walk does it. */ void removeFromList(); /** Replace this instance with pNew in a list, if any. Used by move-ctor and move assignment operator. */ void replaceInList( ScCaptionPtr* pNew ); /** Dissolve list when the caption object is released or gone. */ void dissolve(); /** Just clear everything, while dissolving the list. */ void clear(); }; /** Internal data for a cell annotation. */ struct SC_DLLPUBLIC ScNoteData { typedef std::shared_ptr< ScCaptionInitData > ScCaptionInitDataRef; OUString maDate; /// Creation date of the note. OUString maAuthor; /// Author of the note. ScCaptionInitDataRef mxInitData; /// Initial data for invisible notes without SdrObject. ScCaptionPtr mxCaption; /// Drawing object representing the cell note. bool mbShown; /// True = note is visible. explicit ScNoteData( bool bShown = false ); ~ScNoteData(); }; /** * Additional class containing cell annotation data. */ class SC_DLLPUBLIC ScPostIt { public: static sal_uInt32 mnLastPostItId; /** Creates an empty note and its caption object and places it according to the passed cell position. */ explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, sal_uInt32 nPostItId = 0 ); /** Copy constructor. Clones the note and its caption to a new document. */ explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, const ScPostIt& rNote, sal_uInt32 nPostItId = 0 ); /** Creates a note from the passed note data with existing caption object. @param bAlwaysCreateCaption Instead of a pointer to an existing caption object, the passed note data structure may contain a reference to an ScCaptionInitData structure containing information about how to construct a missing caption object. If sal_True is passed, the caption drawing object will be created immediately from that data. If sal_False is passed and the note is not visible, it will continue to cache that data until the caption object is requested. */ explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, const ScNoteData& rNoteData, bool bAlwaysCreateCaption, sal_uInt32 nPostItId = 0 ); /** Removes the caption object from drawing layer, if this note is its owner. */ ~ScPostIt(); /** Clones this note and its caption object, if specified. @param bCloneCaption If sal_True is passed, clones the caption object and inserts it into the drawing layer of the destination document. If sal_False is passed, the cloned note will refer to the old caption object (used e.g. in Undo documents to restore the pointer to the existing caption object). */ ScPostIt* Clone( const ScAddress& rOwnPos, ScDocument& rDestDoc, const ScAddress& rDestPos, bool bCloneCaption ) const; /** Returns the note id. */ sal_uInt32 GetId() const { return mnPostItId; } /** Returns the data struct containing all note settings. */ const ScNoteData& GetNoteData() const { return maNoteData;} /** Returns the creation date of this note. */ const OUString& GetDate() const { return maNoteData.maDate;} /** Sets a new creation date for this note. */ void SetDate( const OUString& rDate ); /** Returns the author date of this note. */ const OUString& GetAuthor() const { return maNoteData.maAuthor;} /** Sets a new author date for this note. */ void SetAuthor( const OUString& rAuthor ); /** Sets date and author from system settings. */ void AutoStamp(); /** Returns the pointer to the current outliner object, or null. */ const OutlinerParaObject* GetOutlinerObject() const; /** Returns the pointer to the current edit text object, or null. */ const EditTextObject* GetEditTextObject() const; /** Returns the caption text of this note. */ OUString GetText() const; /** Returns true, if the caption text of this note contains line breaks. */ bool HasMultiLineText() const; /** Changes the caption text of this note. All text formatting will be lost. */ void SetText( const ScAddress& rPos, const OUString& rText ); /** Returns an existing note caption object. returns null, if the note contains initial caption data needed to construct a caption object. The SdrCaptionObj* returned is still managed by the underlying ScNoteData::ScCaptionPtr and must not be stored elsewhere. */ SdrCaptionObj* GetCaption() const { return maNoteData.mxCaption.get();} /** Returns the caption object of this note. Creates the caption object, if the note contains initial caption data instead of the caption. The SdrCaptionObj* returned is still managed by the underlying ScNoteData::ScCaptionPtr and must not be stored elsewhere. */ SdrCaptionObj* GetOrCreateCaption( const ScAddress& rPos ) const; /** Forgets the pointer to the note caption object. @param bPreserveData If true then the note text is remembered in maNoteData to be able to later reconstruct a caption from it. */ void ForgetCaption( bool bPreserveData = false ); /** Shows or hides the note caption object. */ void ShowCaption( const ScAddress& rPos, bool bShow ); /** Returns true, if the caption object is visible. */ bool IsCaptionShown() const { return maNoteData.mbShown;} /** Shows or hides the caption temporarily (does not change internal visibility state). */ void ShowCaptionTemp( const ScAddress& rPos, bool bShow = true ); /** Updates caption position according to position of the passed cell. */ void UpdateCaptionPos( const ScAddress& rPos ); private: ScPostIt( const ScPostIt& ) = delete; ScPostIt& operator=( const ScPostIt& ) = delete; /** Creates the caption object from initial caption data if existing. */ void CreateCaptionFromInitData( const ScAddress& rPos ) const; /** Creates a new caption object at the passed cell position, clones passed existing caption. */ void CreateCaption( const ScAddress& rPos, const SdrCaptionObj* pCaption = nullptr ); /** Removes the caption object from the drawing layer, if this note is its owner. */ void RemoveCaption(); private: ScDocument& mrDoc; /// Parent document containing the note. mutable ScNoteData maNoteData; /// Note data with pointer to caption object. sal_uInt32 mnPostItId; }; class SC_DLLPUBLIC ScNoteUtil { public: /** Creates and returns a caption object for a temporary caption. */ static ScCaptionPtr CreateTempCaption( ScDocument& rDoc, const ScAddress& rPos, SdrPage& rDrawPage, const OUString& rUserText, const tools::Rectangle& rVisRect, bool bTailFront ); /** Creates a cell note using the passed caption drawing object. This function is used in import filters to reuse the imported drawing object as note caption object. @param pCaption The drawing object for the cell note. This object MUST be inserted into the document at the correct drawing page already. The underlying ScPostIt::ScNoteData::ScCaptionPtr takes managing ownership of the pointer. @return Pointer to the new cell note object if insertion was successful (i.e. the passed cell position was valid), null otherwise. The Calc document is the owner of the note object. The passed item set and outliner object are deleted automatically if creation of the note was not successful. */ static ScPostIt* CreateNoteFromCaption( ScDocument& rDoc, const ScAddress& rPos, SdrCaptionObj* pCaption, bool bShown ); /** Creates a cell note based on the passed caption object data. This function is used in import filters to use an existing imported item set and outliner object to create a note caption object. For performance reasons, it is possible to specify that the caption drawing object for the cell note is not created yet but the note caches the passed data needed to create the caption object on demand (see parameter bAlwaysCreateCaption). @param pItemSet Pointer to an item set on heap memory containing all formatting attributes of the caption object. This function takes ownership of the passed item set. @param pOutlinerObj Pointer to an outliner object on heap memory containing (formatted) text for the caption object. This function takes ownership of the passed outliner object. @param rCaptionRect The absolute position and size of the caption object. The rectangle may be empty, in this case the default position and size is used. @param bAlwaysCreateCaption If sal_True is passed, the caption drawing object will be created immediately. If sal_False is passed, the caption drawing object will not be created if the note is not visible (bShown = sal_False), but the cell note will cache the passed data. MUST be set to sal_False outside of import filter implementations! @return Pointer to the new cell note object if insertion was successful (i.e. the passed cell position was valid), null otherwise. The Calc document is the owner of the note object. */ static ScPostIt* CreateNoteFromObjectData( ScDocument& rDoc, const ScAddress& rPos, SfxItemSet* pItemSet, OutlinerParaObject* pOutlinerObj, const tools::Rectangle& rCaptionRect, bool bShown, bool bAlwaysCreateCaption, sal_uInt32 nPostItId = 0 ); /** Creates a cell note based on the passed string and inserts it into the document. @param rNoteText The text used to create the note caption object. Must not be empty. @param bAlwaysCreateCaption If sal_True is passed, the caption drawing object will be created immediately. If sal_False is passed, the caption drawing object will not be created if the note is not visible (bShown = sal_False), but the cell note will cache the passed data. MUST be set to sal_False outside of import filter implementations! @return Pointer to the new cell note object if insertion was successful (i.e. the passed cell position was valid), null otherwise. The Calc document is the owner of the note object. */ static ScPostIt* CreateNoteFromString( ScDocument& rDoc, const ScAddress& rPos, const OUString& rNoteText, bool bShown, bool bAlwaysCreateCaption, sal_uInt32 nPostItId = 0 ); }; namespace sc { struct NoteEntry { ScAddress maPos; const ScPostIt* mpNote; NoteEntry( const ScAddress& rPos, const ScPostIt* pNote ); }; } #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ re/droid_calimpress4'>feature/droid_calimpress4 LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2024-11-01tdf#163667 speed up spreadsheet with lots of cond formattingNoel Grandin
Attempt to avoid the cost of GetCondResult when dealing with large runs of identical cells Change-Id: If9192a9858e6785263ea1621e98d1b1d5de74c4c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175909 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com> (cherry picked from commit 7d7d94b7713d86e2fd972c3b81845eaffb5761e5) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175898 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2024-10-25speedup saving large XLS file with lots of query formulaNoel Grandin
make more use of svl::SharedString instead of unnecessarily creating OUString that then need to be interned. We were spending all our time inside the the SharedStringPool::intern function. 20s to 12s Change-Id: I344f0acfd462fdb6d78e392881f066a56844fa94 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175538 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2022-06-27cid#1506511 silence Uncaught exceptionCaolán McNamara
and cid#1506512 Uncaught exception cid#1506513 Uncaught exception Change-Id: I964430a69ce4d4beb7f7a551d3ac454c8122a3fa Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136503 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2022-06-20use std::monostate in std::variantNoel Grandin
as suggest by llunak Change-Id: Id22253198bff16eeb596e1a15ddaba1f6ac227d5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136146 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2022-06-18clean up Sc*CellValueNoel Grandin
after my recent commits (*) make more fields private (*) rename fields (remove suffix "1") now that I am sure I got everything. Change-Id: I0f8b9b1a534181c8b66532f9da5a0d16aa049cf0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136074 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2022-06-18tdf#126109 calc slow when replacing string to numberNoel Grandin
Store SharedString inline in ScCellValue. Shaves 10% off time. Use std::variant to handle the complexities of correctly calling constructor and destructor of SharedString. Change-Id: I820de5339e31434fbdbde1a72e25abe207bf008d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135863 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2022-06-18create getter for ScCellValue::mpFormulaNoel Grandin
so we can assert that it has the correct tag type Change-Id: Iab13a6d6ea1783c69395f06f28732769e5fe8b18 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136059 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2022-06-17create getter for ScCellValue::mpEditTextNoel Grandin
so we can assert that it has the correct tag type Change-Id: I984c22ae2527d652f2d4194227dc1173793300c6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136054 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2022-06-16create getter for ScCellValue::mfValueNoel Grandin
so we can assert that has the correct tag type Change-Id: I0d626130cb014e19239e88a6988018c83d061f68 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136001 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2022-06-16pass EditTextObject by unique_ptrNoel Grandin
to make the ownership passing obvious Change-Id: Icf4b94a422b91da3082fe1ce56eff149d390a649 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136000 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2022-06-16make meType in ScCellValue privateNoel Grandin
as a first step to wrapping up the internals of this class and adding some asserts Change-Id: Ic13ddd917948dbf3fd6d73f44b8efcc727726baf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135994 Tested-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2021-11-11Drop ScGlobal::GetEmptyOUString() and EMPTY_OUSTRINGMike Kaganski
OUString default ctor already uses a static instance (through rtl_uString_new), no need to have another module-specific static. Commit d8037ae18a297229d1b79f8f76331abfd548350d had removed its sw counterpart some time ago. Change-Id: I140fe13bc1f6b0cbe188e83e602fdebe995e467a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125061 Tested-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2020-09-24some places where ScDocument* is never passed a nullptrCaolán McNamara
Change-Id: Ie06fef80990b539d5b6cc87c80d9bbd3e851766c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103299 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2020-09-24some places where ScDocument* is never passed a nullptrCaolán McNamara
Change-Id: Ic15bebe20cdea9df2cd5afd7af666bc76c88c8c3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103277 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2020-09-18ScCellValue::getString never called with a null ScDocument*Caolán McNamara
Change-Id: Idff982e715b012e35e0abd0b904f4b83d7f6f51a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103007 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2020-09-16ScAttrArray never has a null ScDocument* memberCaolán McNamara
Change-Id: I06e4190235799d6ff231179ae3bbc8f76d4a3342 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102867 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2019-12-07rename ScEditEngineDefaulter::SetTextCaolán McNamara
so its clear that it is not an override of baseclass EditEngine::SetText Change-Id: I85ee9c9b212fe9248fb7e5fcb1ec83679ffb633d Reviewed-on: https://gerrit.libreoffice.org/84553 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
2019-08-23Mark move ctors/assignments noexceptMike Kaganski
This should enable using move semantics where possible e.g. in standard containers. According to https://en.cppreference.com/w/cpp/language/move_constructor: To make strong exception guarantee possible, user-defined move constructors should not throw exceptions. For example, std::vector relies on std::move_if_noexcept to choose between move and copy when the elements need to be relocated. Change-Id: I6e1e1cdd5cd430b139ffa2fa7031fb0bb625decb Reviewed-on: https://gerrit.libreoffice.org/77957 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2019-05-16optimize ScHTMLExport::WriteTables() with large columnsLuboš Luňák
Again, unless given a hint, mdds always starts a search from the beginning of the container, so iterating over a column becomes quadratic. Shows when selecting (the title of) a large column with different value types, e.g. in tdf#120558, which triggers setting the selection from VclQt5Clipboard::setContents(), which calls this. Change-Id: Ida009c5ddf18ccdc8dff88c15530cc7e33ce80e7 Reviewed-on: https://gerrit.libreoffice.org/72366 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
2019-05-14cache cell positions when searching in calc (tdf#108347)Luboš Luňák
The document has a large number of rows, and mdds normally always searches from the first item when looking up the container position, which leads to a quadratic cost when searching the entire sheet. GetCellValue() already has a variant that caches the last position, so just use it (and make sure to invalidate if it's search&replace and something changes). Change-Id: I26da60cebf641e10ed92e548fe5f9016900d3cf0 Reviewed-on: https://gerrit.libreoffice.org/72290 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
2018-04-11pass EditTextObject around using std::unique_ptrNoel Grandin
Change-Id: I71f4529c2e02fd0ac2561191e4cb35e18e206037 Reviewed-on: https://gerrit.libreoffice.org/52682 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2017-12-24sc: compact ScColumnAshod Nakashian
Remove ScDocument* member from ScColumn and re-use the one in ScAttrArray. This saves 8 bytes and makes the code more homogenious by using GetDoc() member everywhere. (cherry picked from commit 1168a11278ed3c2a00058e1f802f6e44cb925318) Reviewed-on: https://gerrit.libreoffice.org/46680 Reviewed-by: Jan Holesovsky <kendy@collabora.com> Tested-by: Jan Holesovsky <kendy@collabora.com> (cherry picked from commit dc3f0bde0bdef2a1e94055be146b433cb9fc54ba) Change-Id: I16a94b7ef7c45ef3af14e812b45f255f39939a6e Reviewed-on: https://gerrit.libreoffice.org/46990 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
2017-12-06coverity#1421089 seems to be really reporting missing move ctors/assignmentsCaolán McNamara
Change-Id: I434eebac395bbb53a0c586a43568f64ec3fb8448
2017-10-23loplugin:includeform: scStephan Bergmann
Change-Id: I2ed763e0584a188032c80fde60890de3c6985cbd