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