/src/libreoffice/editeng/inc/ParagraphPortionList.hxx
Line | Count | Source |
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 "ParagraphPortion.hxx" |
23 | | |
24 | | #include <vector> |
25 | | |
26 | | class EditDoc; |
27 | | |
28 | | class ParaPortionList |
29 | | { |
30 | | mutable sal_Int32 nLastCache = 0; |
31 | | typedef std::vector<std::unique_ptr<ParaPortion>> ParaPortionContainerType; |
32 | | ParaPortionContainerType maPortions; |
33 | | |
34 | | public: |
35 | 628k | ParaPortionList() = default; |
36 | | |
37 | | void Reset(); |
38 | | tools::Long GetYOffset(const ParaPortion* pPPortion) const; |
39 | | sal_Int32 FindParagraph(tools::Long nYOffset) const; |
40 | | |
41 | | const ParaPortion* SafeGetObject(sal_Int32 nPos) const |
42 | 35.6M | { |
43 | 35.6M | return exists(nPos) ? maPortions[nPos].get() : nullptr; |
44 | 35.6M | } |
45 | | |
46 | | ParaPortion* SafeGetObject(sal_Int32 nPos) |
47 | 77.4M | { |
48 | 77.4M | return exists(nPos) ? maPortions[nPos].get() : nullptr; |
49 | 77.4M | } |
50 | | |
51 | | sal_Int32 GetPos(const ParaPortion* p) const; |
52 | | |
53 | 225M | ParaPortion& getRef(sal_Int32 nPosition) { return *maPortions[nPosition]; } |
54 | 0 | ParaPortion const& getRef(sal_Int32 nPosition) const { return *maPortions[nPosition]; } |
55 | | |
56 | | std::unique_ptr<ParaPortion> Release(sal_Int32 nPos); |
57 | | void Remove(sal_Int32 nPos); |
58 | | void Insert(sal_Int32 nPos, std::unique_ptr<ParaPortion> p); |
59 | | void Append(std::unique_ptr<ParaPortion> p); |
60 | | sal_Int32 Count() const; |
61 | 14.1M | sal_Int32 lastIndex() const { return Count() - 1; } |
62 | | |
63 | | bool exists(sal_Int32 nPosition) const |
64 | 114M | { |
65 | 114M | return nPosition >= 0 && o3tl::make_unsigned(nPosition) < maPortions.size() |
66 | 100M | && maPortions[nPosition]; |
67 | 114M | } |
68 | | |
69 | 2.34M | ParaPortionContainerType::iterator begin() { return maPortions.begin(); } |
70 | 2.34M | ParaPortionContainerType::iterator end() { return maPortions.end(); } |
71 | 0 | ParaPortionContainerType::const_iterator cbegin() const { return maPortions.cbegin(); } |
72 | 0 | ParaPortionContainerType::const_iterator cend() const { return maPortions.cend(); } |
73 | | |
74 | | void MarkAllSelectionsInvalid(sal_Int32 nStart) |
75 | 5.53M | { |
76 | 5.53M | for (auto& pParaPortion : maPortions) |
77 | 6.58M | pParaPortion->MarkSelectionInvalid(nStart); |
78 | 5.53M | } |
79 | | |
80 | | #if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG |
81 | | // temporary: |
82 | | static void DbgCheck(ParaPortionList const&, EditDoc const& rDoc); |
83 | | #endif |
84 | | }; |
85 | | |
86 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |