Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / inc / docsort.hxx
blob0aad16da4a859db265d7982e02b1203c6aa4eb96
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SW_SOURCE_CORE_INC_DOCSORT_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_DOCSORT_HXX
23 #include <ndindex.hxx>
25 #include <memory>
26 #include <vector>
28 class SwDoc;
29 class SwTableBox;
30 class SwUndoSort;
31 class FlatFndBox;
32 struct SwSortOptions;
33 class FndBox_;
34 class FndLine_;
35 class CollatorWrapper;
36 class LocaleDataWrapper;
37 namespace com::sun::star::lang { struct Locale; }
39 class SwMovedBoxes
41 private:
42 std::vector<const SwTableBox*> mBoxes;
44 public:
45 void push_back(const SwTableBox* &rpTableBox) {mBoxes.push_back(rpTableBox);}
47 sal_uInt16 GetPos(const SwTableBox* pTableBox) const;
50 // Functions for moving boxes
51 void MoveCol(SwDoc* pDoc, const FlatFndBox& rBox,
52 sal_uInt16 nS, sal_uInt16 nT, SwMovedBoxes& rMovedList, SwUndoSort* pUD);
53 void MoveRow(SwDoc* pDoc, const FlatFndBox& rBox,
54 sal_uInt16 nS, sal_uInt16 nT, SwMovedBoxes& rMovedList, SwUndoSort* pUD);
55 void MoveCell(SwDoc* pDoc, const SwTableBox* pSource,
56 const SwTableBox* pTar, bool bMovedBefore, SwUndoSort* pUD=nullptr);
58 // Elements for sorting text and table content
59 struct SwSortElement
61 static SwSortOptions* pOptions;
62 static SwDoc* pDoc;
63 static const FlatFndBox* pBox;
64 static CollatorWrapper* pSortCollator;
65 static css::lang::Locale* pLocale;
66 static std::optional<OUString> xLastAlgorithm;
67 static LocaleDataWrapper* pLclData;
69 static void Init( SwDoc*, const SwSortOptions& rOpt, FlatFndBox const * = nullptr );
70 static void Finit();
72 SwSortElement() = default;
73 SwSortElement(SwSortElement const &) = default;
74 SwSortElement(SwSortElement &&) = default;
75 SwSortElement & operator =(SwSortElement const &) = default;
76 SwSortElement & operator =(SwSortElement &&) = default;
78 virtual ~SwSortElement();
80 virtual OUString GetKey(sal_uInt16 nKey ) const = 0;
81 virtual double GetValue(sal_uInt16 nKey ) const;
83 bool operator<(const SwSortElement& ) const;
85 static double StrToDouble(std::u16string_view rStr);
86 private:
87 int keycompare(const SwSortElement& rCmp, sal_uInt16 nKey) const;
90 // sort text
91 struct SwSortTextElement final : public SwSortElement
93 SwNodeOffset nOrg;
94 SwNodeIndex aPos;
96 SwSortTextElement( const SwNodeIndex& rPos );
98 virtual OUString GetKey( sal_uInt16 nKey ) const override;
101 // sort table
102 struct SwSortBoxElement final : public SwSortElement
104 sal_uInt16 nRow;
106 SwSortBoxElement( sal_uInt16 nRC );
108 virtual OUString GetKey( sal_uInt16 nKey ) const override;
109 virtual double GetValue( sal_uInt16 nKey ) const override;
112 // two-dimensional array of FndBoxes
113 class FlatFndBox
115 public:
116 FlatFndBox(SwDoc* pDocPtr, const FndBox_& rBox);
117 ~FlatFndBox();
119 bool IsSymmetric() const { return m_bSym; }
120 sal_uInt16 GetRows() const { return m_nRows; }
121 sal_uInt16 GetCols() const { return m_nCols; }
123 const FndBox_* GetBox(sal_uInt16 nCol, sal_uInt16 nRow) const;
125 inline bool HasItemSets() const;
126 const SfxItemSet* GetItemSet(sal_uInt16 nCol, sal_uInt16 nRow) const;
128 private:
129 bool CheckLineSymmetry(const FndBox_& rBox);
130 bool CheckBoxSymmetry(const FndLine_& rLn);
131 sal_uInt16 GetColCount(const FndBox_& rBox);
132 sal_uInt16 GetRowCount(const FndBox_& rBox);
133 void FillFlat(const FndBox_&, bool bLastBox=false);
135 SwDoc* m_pDoc;
136 std::unique_ptr<FndBox_ const *[]> m_pArr;
137 /// using optional because SfxItemSet has no default constructor
138 std::vector<std::optional<SfxItemSet>> m_vItemSets;
140 sal_uInt16 m_nRows;
141 sal_uInt16 m_nCols;
142 sal_uInt16 m_nRow;
143 sal_uInt16 m_nCol;
145 bool m_bSym;
148 inline bool FlatFndBox::HasItemSets() const { return !m_vItemSets.empty(); }
150 #endif
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */