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 
24 
25 #ifndef _SC_ACCESSIBLESPREADSHEET_HXX
26 #define _SC_ACCESSIBLESPREADSHEET_HXX
27 
28 #include "AccessibleTableBase.hxx"
29 #include "viewdata.hxx"
30 
31 #include <com/sun/star/ucb/CommandFailedException.hpp>
32 #include <com/sun/star/ucb/ContentCreationException.hpp>
33 
34 #include <vector>
35 
36 #include "rangelst.hxx"
37 #include <map>
38 class ScMyAddress : public ScAddress
39 {
40 public:
41 	ScMyAddress() : ScAddress() {}
42     ScMyAddress(SCCOL nColP, SCROW nRowP, SCTAB nTabP) : ScAddress(nColP, nRowP, nTabP) {}
43 	ScMyAddress(const ScAddress& rAddress) : ScAddress(rAddress) {}
44 
45 	sal_Bool operator< ( const ScMyAddress& rAddress ) const
46     {
47 		if( Row() != rAddress.Row() )
48 			return (Row() < rAddress.Row());
49 		else
50 			return (Col() < rAddress.Col());
51     }
52 };
53 
54 class ScTabViewShell;
55 class ScAccessibleDocument;
56 class ScAccessibleCell;
57 
58 /**	@descr
59         This base class provides an implementation of the
60         <code>AccessibleTable</code> service.
61 */
62 class ScAccessibleSpreadsheet
63 	:	public	ScAccessibleTableBase
64 {
65 public:
66 	//=====  internal  ========================================================
67 	ScAccessibleSpreadsheet(
68         ScAccessibleDocument* pAccDoc,
69 		ScTabViewShell* pViewShell,
70 		SCTAB	nTab,
71 		ScSplitPos eSplitPos);
72 protected:
73     ScAccessibleSpreadsheet(
74         ScAccessibleSpreadsheet& rParent,
75         const ScRange& rRange );
76 
77 	virtual ~ScAccessibleSpreadsheet();
78 
79     void ConstructScAccessibleSpreadsheet(
80         ScAccessibleDocument* pAccDoc,
81         ScTabViewShell* pViewShell,
82         SCTAB nTab,
83         ScSplitPos eSplitPos);
84 
85     using ScAccessibleTableBase::IsDefunc;
86 
87 public:
88     using ScAccessibleTableBase::addEventListener;
89     using ScAccessibleTableBase::disposing;
90 
91  	virtual void SAL_CALL disposing();
92 
93 	void CompleteSelectionChanged(sal_Bool bNewState);
94 
95     virtual void LostFocus();
96 
97     virtual void GotFocus();
98 
99     void BoundingBoxChanged();
100 
101     void VisAreaChanged();
102 
103 	///=====  SfxListener  =====================================================
104 
105 	virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
106 
107 	///=====  XAccessibleTable  ================================================
108 
109     /// Returns the row headers as an AccessibleTable.
110     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleTable > SAL_CALL
111                 getAccessibleRowHeaders(  )
112                     throw (::com::sun::star::uno::RuntimeException);
113 
114     /// Returns the column headers as an AccessibleTable.
115     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleTable > SAL_CALL
116                 getAccessibleColumnHeaders(  )
117                     throw (::com::sun::star::uno::RuntimeException);
118 
119     /// Returns the selected rows in a table.
120     virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL
121     			getSelectedAccessibleRows(  )
122     				throw (::com::sun::star::uno::RuntimeException);
123 
124     /// Returns the selected columns in a table.
125     virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL
126     			getSelectedAccessibleColumns(  )
127     				throw (::com::sun::star::uno::RuntimeException);
128 
129     /// Returns a boolean value indicating whether the specified row is selected.
130     virtual sal_Bool SAL_CALL
131     			isAccessibleRowSelected( sal_Int32 nRow )
132     				throw (::com::sun::star::uno::RuntimeException,
133 				    ::com::sun::star::lang::IndexOutOfBoundsException);
134 
135     /// Returns a boolean value indicating whether the specified column is selected.
136     virtual sal_Bool SAL_CALL
137     			isAccessibleColumnSelected( sal_Int32 nColumn )
138     				throw (::com::sun::star::uno::RuntimeException,
139 				    ::com::sun::star::lang::IndexOutOfBoundsException);
140 
141 	/// Returns the Accessible at a specified row and column in the table.
142     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL
143     			getAccessibleCellAt( sal_Int32 nRow, sal_Int32 nColumn )
144     				throw (::com::sun::star::uno::RuntimeException,
145     				        ::com::sun::star::lang::IndexOutOfBoundsException);
146 
147     ScAccessibleCell* GetAccessibleCellAt(sal_Int32 nRow, sal_Int32 nColumn);
148 
149 	/// Returns a boolean value indicating whether the accessible at a specified row and column is selected.
150     virtual sal_Bool SAL_CALL
151     			isAccessibleSelected( sal_Int32 nRow, sal_Int32 nColumn )
152     				throw (::com::sun::star::uno::RuntimeException,
153 				    ::com::sun::star::lang::IndexOutOfBoundsException);
154 
155 	///=====  XAccessibleComponent  ============================================
156 
157     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
158 		SAL_CALL getAccessibleAtPoint(
159 		const ::com::sun::star::awt::Point& rPoint )
160 		throw (::com::sun::star::uno::RuntimeException);
161 
162     virtual void SAL_CALL grabFocus(  )
163 		throw (::com::sun::star::uno::RuntimeException);
164 
165     virtual sal_Int32 SAL_CALL getForeground(  )
166         throw (::com::sun::star::uno::RuntimeException);
167 
168     virtual sal_Int32 SAL_CALL getBackground(  )
169         throw (::com::sun::star::uno::RuntimeException);
170 
171     ///=====  XAccessibleContext  ==============================================
172 
173 	///	Return NULL to indicate that an empty relation set.
174 	virtual ::com::sun::star::uno::Reference<
175             ::com::sun::star::accessibility::XAccessibleRelationSet> SAL_CALL
176     	getAccessibleRelationSet(void)
177         throw (::com::sun::star::uno::RuntimeException);
178 
179     ///	Return the set of current states.
180 	virtual ::com::sun::star::uno::Reference<
181             ::com::sun::star::accessibility::XAccessibleStateSet> SAL_CALL
182     	getAccessibleStateSet(void)
183         throw (::com::sun::star::uno::RuntimeException);
184 
185 	///=====  XAccessibleSelection  ===========================================
186 
187     virtual void SAL_CALL
188 		selectAccessibleChild( sal_Int32 nChildIndex )
189 		throw (::com::sun::star::lang::IndexOutOfBoundsException,
190 		::com::sun::star::uno::RuntimeException);
191 
192     virtual void SAL_CALL
193 		clearAccessibleSelection(  )
194 		throw (::com::sun::star::uno::RuntimeException);
195 
196     virtual void SAL_CALL
197 		selectAllAccessibleChildren(  )
198 		throw (::com::sun::star::uno::RuntimeException);
199 
200     virtual sal_Int32 SAL_CALL
201 		getSelectedAccessibleChildCount(  )
202 		throw (::com::sun::star::uno::RuntimeException);
203 
204     virtual ::com::sun::star::uno::Reference<
205 		::com::sun::star::accessibility::XAccessible > SAL_CALL
206 		getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex )
207 		throw (::com::sun::star::lang::IndexOutOfBoundsException,
208 		::com::sun::star::uno::RuntimeException);
209 
210     virtual void SAL_CALL
211 		deselectAccessibleChild( sal_Int32 nChildIndex )
212 		throw (::com::sun::star::lang::IndexOutOfBoundsException,
213 		::com::sun::star::uno::RuntimeException);
214 
215 	///=====  XServiceInfo  ====================================================
216 
217     /**	Returns an identifier for the implementation of this object.
218     */
219 	virtual ::rtl::OUString SAL_CALL
220     	getImplementationName(void)
221         throw (::com::sun::star::uno::RuntimeException);
222 
223     /** Returns a list of all supported services.
224     */
225 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
226     	getSupportedServiceNames(void)
227         throw (::com::sun::star::uno::RuntimeException);
228 
229 	///=====  XTypeProvider  ===================================================
230 
231     /**	Returns a implementation id.
232     */
233     virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL
234         getImplementationId(void)
235         throw (::com::sun::star::uno::RuntimeException);
236 
237 	///=====  XAccessibleEventBroadcaster  =====================================
238 
239     /**	Add listener that is informed of future changes of name,
240       	description and so on events.
241     */
242 	virtual void SAL_CALL
243     	addEventListener(
244         	const ::com::sun::star::uno::Reference<
245                 ::com::sun::star::accessibility::XAccessibleEventListener>& xListener)
246         throw (com::sun::star::uno::RuntimeException);
247 	//=====  XAccessibleTableSelection  ============================================
248 	virtual sal_Bool SAL_CALL selectRow( sal_Int32 row )
249 		throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, ::com::sun::star::ucb::CommandFailedException, com::sun::star::ucb::ContentCreationException) ;
250     virtual sal_Bool SAL_CALL selectColumn( sal_Int32 column )
251 		throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, ::com::sun::star::ucb::CommandFailedException, com::sun::star::ucb::ContentCreationException) ;
252     virtual sal_Bool SAL_CALL unselectRow( sal_Int32 row )
253 		throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, ::com::sun::star::ucb::CommandFailedException, com::sun::star::ucb::ContentCreationException) ;
254     virtual sal_Bool SAL_CALL unselectColumn( sal_Int32 column )
255 		throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, ::com::sun::star::ucb::CommandFailedException, com::sun::star::ucb::ContentCreationException) ;
256 
257 protected:
258     ///	Return the object's current bounding box relative to the desktop.
259 	virtual Rectangle GetBoundingBoxOnScreen(void) const
260 		throw (::com::sun::star::uno::RuntimeException);
261 
262 	///	Return the object's current bounding box relative to the parent object.
263 	virtual Rectangle GetBoundingBox(void) const
264 		throw (::com::sun::star::uno::RuntimeException);
265 private:
266 	ScTabViewShell* mpViewShell;
267 	ScRangeList*	mpMarkedRanges;
268 	std::vector<ScMyAddress>* mpSortedMarkedCells;
269     ScAccessibleDocument* mpAccDoc;
270     ScAccessibleCell*   mpAccCell;
271 	Rectangle		maVisCells;
272 	ScSplitPos 		meSplitPos;
273 	ScAddress		maActiveCell;
274     SCTAB           mnTab;
275     sal_Bool        mbIsSpreadsheet;
276 	sal_Bool		mbHasSelection;
277 	sal_Bool		mbDelIns;
278     sal_Bool        mbIsFocusSend;
279 
280 	sal_Bool IsDefunc(
281 		const com::sun::star::uno::Reference<
282 		::com::sun::star::accessibility::XAccessibleStateSet>& rxParentStates);
283 	sal_Bool IsEditable(
284 		const com::sun::star::uno::Reference<
285 		::com::sun::star::accessibility::XAccessibleStateSet>& rxParentStates);
286     sal_Bool IsFocused();
287 	sal_Bool IsCompleteSheetSelected();
288 
289 	void SelectCell(sal_Int32 nRow, sal_Int32 nCol, sal_Bool bDeselect);
290 	void CreateSortedMarkedCells();
291 	void AddMarkedRange(const ScRange& rRange);
292 
293 	ScDocument* GetDocument(ScTabViewShell* pViewShell);
294 	Rectangle	GetVisArea(ScTabViewShell* pViewShell, ScSplitPos eSplitPos);
295 	Rectangle	GetVisCells(const Rectangle& rVisArea);
296 	//void CreateSortedMarkedCells();
297 	//void AddMarkedRange(const ScRange& rRange);
298 	typedef std::vector<ScMyAddress> VEC_MYADDR;
299 
300 	typedef std::map<ScMyAddress,com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > >
301 		MAP_ADDR_XACC;
302 	MAP_ADDR_XACC m_mapSelectionSend;
303 	void RemoveSelection(ScMarkData &refScMarkData);
304 	sal_Bool IsSameMarkCell();
305 	void CommitFocusCell(const ScAddress &aNewCell);
306 public:
307 	void FireFirstCellFocus();
308 private:
309 	sal_Bool m_bFormulaMode;
310 	sal_Bool m_bFormulaLastMode;
311 	ScAddress m_aFormulaActiveCell;
312 	MAP_ADDR_XACC m_mapFormulaSelectionSend;
313 	VEC_MYADDR m_vecFormulaLastMyAddr;
314     ScAccessibleCell*   m_pAccFormulaCell;
315 	sal_uInt16 m_nMinX;
316 	sal_uInt16 m_nMaxX;
317 	sal_Int32 m_nMinY;
318 	sal_Int32 m_nMaxY;
319 	sal_Int32 GetRowAll() const { return m_nMaxY - m_nMinY + 1 ; }
320 	sal_uInt16  GetColAll() const { return m_nMaxX - m_nMinX + 1; }
321 	void NotifyRefMode();
322 	void RemoveFormulaSelection(sal_Bool bRemoveAll =sal_False);
323 	sal_Bool CheckChildIndex(sal_Int32)const ;
324 	ScAddress GetChildIndexAddress(sal_Int32) const;
325     sal_Int32 GetAccessibleIndexFormula( sal_Int32 nRow, sal_Int32 nColumn );
326 	sal_Bool GetFormulaCurrentFocusCell(ScAddress &addr);
327 public:
328 	sal_Bool IsScAddrFormulaSel (const ScAddress &addr) const ;
329 	sal_Bool IsFormulaMode() ;
330 	::com::sun::star::uno::Reference < ::com::sun::star::accessibility::XAccessible > GetActiveCell();
331 	ScRange m_aLastWithInMarkRange;
332     String m_strCurCellValue;
333     ScRangeList m_LastMarkedRanges;
334     typedef std::vector<ScRange*> VEC_RANGE;
335     VEC_RANGE m_vecTempRange;
336     typedef std::pair<sal_uInt16,sal_uInt16> PAIR_COL;
337     typedef std::vector<PAIR_COL> VEC_COL;
338     VEC_COL m_vecTempCol;
339     ScMyAddress CalcScAddressFromRangeList(ScRangeList *pMarkedRanges,sal_Int32 nSelectedChildIndex);
340 	sal_Bool CalcScRangeDifferenceMax(ScRange *pSrc,ScRange *pDest,int nMax,VEC_MYADDR &vecRet,int &nSize);
341 	sal_Bool CalcScRangeListDifferenceMax(ScRangeList *pSrc,ScRangeList *pDest,int nMax,VEC_MYADDR &vecRet);
342 	String m_strOldTabName;
343 };
344 
345 
346 #endif
347