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