xref: /aoo4110/main/sw/source/core/inc/docsort.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _SORT_HXX
24 #define _SORT_HXX
25 
26 #include <svl/svarray.hxx>
27 #include <ndindex.hxx>
28 
29 
30 class SwDoc;
31 class SwTableBox;
32 class SwUndoSort;
33 class FlatFndBox;
34 struct SwSortOptions;
35 struct SwSortElement;
36 class _FndBox;
37 class _FndLine;
38 class CollatorWrapper;
39 class LocaleDataWrapper;
40 
41 
42 namespace com { namespace sun { namespace star { namespace lang {
43 	struct Locale;
44 }}}}
45 
46 /*--------------------------------------------------------------------
47 	Beschreibung: Liste aller sortierten Elemente
48  --------------------------------------------------------------------*/
49 typedef const _FndBox* 		_FndBoxPtr;
50 typedef SwSortElement* 		SwSortElementPtr;
51 typedef const SwTableBox* 	SwMovedBoxPtr;
52 
53 SV_DECL_PTRARR_SORT(SwSortElements, SwSortElementPtr, 0, 1 )
54 SV_DECL_PTRARR(SwMovedBoxes, 		SwMovedBoxPtr, 10, 10 )
55 
56 /*--------------------------------------------------------------------
57 	Beschreibung: Funktionen zum Moven von Boxen
58  --------------------------------------------------------------------*/
59 
60 void MoveCol(SwDoc* pDoc, const FlatFndBox& rBox,
61 			 sal_uInt16 nS, sal_uInt16 nT, SwMovedBoxes& rMovedList, SwUndoSort* pUD=0);
62 void MoveRow(SwDoc* pDoc, const FlatFndBox& rBox,
63 			 sal_uInt16 nS, sal_uInt16 nT, SwMovedBoxes& rMovedList, SwUndoSort* pUD=0);
64 void MoveCell(SwDoc* pDoc, const SwTableBox* pSource,
65 			  const SwTableBox* pTar, sal_Bool bMovedBefore, SwUndoSort* pUD=0);
66 
67 /*-------------------------------------------------------------------
68 	Beschreibung: Elemente zum Sortieren von Text und Tabellen-Inhalt
69  --------------------------------------------------------------------*/
70 
71 struct SwSortElement
72 {
73 	static SwSortOptions*		pOptions;
74 	static SwDoc*				pDoc;
75 	static const FlatFndBox*	pBox;
76 	static CollatorWrapper*		pSortCollator;
77 	static ::com::sun::star::lang::Locale* pLocale;
78 	static String*				pLastAlgorithm;
79 	static LocaleDataWrapper* 	pLclData;
80 
81 	static void Init( SwDoc*, const SwSortOptions& rOpt, FlatFndBox* = 0 );
82 	static void Finit();
83 
84 	virtual ~SwSortElement();
85 
86 	virtual	String GetKey(sal_uInt16 nKey ) const = 0;
87 	virtual	double GetValue(sal_uInt16 nKey ) const;
88 
89 	sal_Bool operator==(const SwSortElement& );
90 	sal_Bool operator<(const SwSortElement& );
91 
92 	double StrToDouble(const String& rStr) const;
93 };
94 
95 /*--------------------------------------------------------------------
96 	Beschreibung: Sortieren Text
97  --------------------------------------------------------------------*/
98 
99 struct SwSortTxtElement : public SwSortElement
100 {
101 	// fuer Text
102 	sal_uLong 			nOrg;
103 	SwNodeIndex		aPos;
104 
105 	SwSortTxtElement( const SwNodeIndex& rPos );
106 	virtual ~SwSortTxtElement();
107 
108 	virtual String GetKey( sal_uInt16 nKey ) const;
109 };
110 
111 /*--------------------------------------------------------------------
112 	Beschreibung: Sortieren Tabelle
113  --------------------------------------------------------------------*/
114 
115 struct SwSortBoxElement : public SwSortElement
116 {
117 	sal_uInt16 						nRow;
118 
119 	SwSortBoxElement( sal_uInt16 nRC );
120 	virtual ~SwSortBoxElement();
121 
122 	virtual String GetKey( sal_uInt16 nKey ) const;
123 	virtual	double GetValue( sal_uInt16 nKey ) const;
124 };
125 
126 
127 /*--------------------------------------------------------------------
128 	Beschreibung: SymFndBoxes stellt ein zweidimensionales
129 				  Array von FndBoxes dar
130  --------------------------------------------------------------------*/
131 
132 class FlatFndBox
133 {
134 public:
135 	FlatFndBox(SwDoc* pDocPtr, const _FndBox& rBox);
136 	~FlatFndBox();
137 
IsSymmetric() const138 	sal_Bool 				IsSymmetric() const { return bSym; 	}
GetRows() const139 	sal_uInt16				GetRows()	  const { return nRows;	}
GetCols() const140 	sal_uInt16				GetCols()	  const { return nCols;	}
141 
142 	const _FndBox* 		GetBox(sal_uInt16 nCol, sal_uInt16 nRow) const;
143 
144 	inline sal_Bool			HasItemSets() const;
145 	const SfxItemSet* 	GetItemSet(sal_uInt16 nCol, sal_uInt16 nRow) const;
146 
147 private:
148 
149 	sal_Bool 				CheckLineSymmetry(const _FndBox& rBox);
150 	sal_Bool 				CheckBoxSymmetry(const _FndLine& rLn);
151 	sal_uInt16 				GetColCount(const _FndBox& rBox);
152 	sal_uInt16 				GetRowCount(const _FndBox& rBox);
153 	void 		   		FillFlat(const _FndBox&, sal_Bool bLastBox=sal_False);
154 
155 	SwDoc*				pDoc;
156 	const _FndBox&		rBoxRef;
157 	_FndBoxPtr* 		pArr;
158 	SfxItemSet** 		ppItemSets;
159 
160 	sal_uInt16 	 			nRows;
161 	sal_uInt16   	   		nCols;
162 
163 	sal_uInt16 				nRow;
164 	sal_uInt16 				nCol;
165 
166 	sal_Bool				bSym;
167 };
168 
169 
HasItemSets() const170 inline sal_Bool FlatFndBox::HasItemSets() const	{ return 0 != ppItemSets; }
171 
172 #endif // _NDSORT_HXX
173