1*de7b3f82SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*de7b3f82SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*de7b3f82SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*de7b3f82SAndrew Rist  * distributed with this work for additional information
6*de7b3f82SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*de7b3f82SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*de7b3f82SAndrew Rist  * "License"); you may not use this file except in compliance
9*de7b3f82SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*de7b3f82SAndrew Rist  *
11*de7b3f82SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*de7b3f82SAndrew Rist  *
13*de7b3f82SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*de7b3f82SAndrew Rist  * software distributed under the License is distributed on an
15*de7b3f82SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*de7b3f82SAndrew Rist  * KIND, either express or implied.  See the License for the
17*de7b3f82SAndrew Rist  * specific language governing permissions and limitations
18*de7b3f82SAndrew Rist  * under the License.
19*de7b3f82SAndrew Rist  *
20*de7b3f82SAndrew Rist  *************************************************************/
21*de7b3f82SAndrew Rist 
22*de7b3f82SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef CHART_DATA_BROWSER_HXX
25cdf0e10cSrcweir #define CHART_DATA_BROWSER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <svtools/editbrowsebox.hxx>
28cdf0e10cSrcweir #include <vcl/outdev.hxx>
29cdf0e10cSrcweir #include <svtools/fmtfield.hxx>
30cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <vector>
33cdf0e10cSrcweir #include <memory>
34cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace com { namespace sun { namespace star {
37cdf0e10cSrcweir     namespace chart2 {
38cdf0e10cSrcweir         class XChartDocument;
39cdf0e10cSrcweir     }
40cdf0e10cSrcweir }}}
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace chart
43cdf0e10cSrcweir {
44cdf0e10cSrcweir 
45cdf0e10cSrcweir class DataBrowserModel;
46cdf0e10cSrcweir class NumberFormatterWrapper;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir namespace impl
49cdf0e10cSrcweir {
50cdf0e10cSrcweir class SeriesHeader;
51cdf0e10cSrcweir class SeriesHeaderEdit;
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir class DataBrowser : public ::svt::EditBrowseBox
55cdf0e10cSrcweir {
56cdf0e10cSrcweir protected:
57cdf0e10cSrcweir     // EditBrowseBox overridables
58cdf0e10cSrcweir     virtual void PaintCell( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColumnId ) const;
59cdf0e10cSrcweir     virtual sal_Bool SeekRow( long nRow );
60cdf0e10cSrcweir     virtual sal_Bool IsTabAllowed( sal_Bool bForward ) const;
61cdf0e10cSrcweir     virtual ::svt::CellController* GetController( long nRow, sal_uInt16 nCol );
62cdf0e10cSrcweir     virtual void InitController( ::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol );
63cdf0e10cSrcweir     virtual sal_Bool SaveModified();
64cdf0e10cSrcweir 	virtual void CursorMoved();
65cdf0e10cSrcweir     // called whenever the control of the current cell has been modified
66cdf0e10cSrcweir     virtual void CellModified();
67cdf0e10cSrcweir 	virtual void ColumnResized( sal_uInt16 nColId );
68cdf0e10cSrcweir     virtual void EndScroll();
69cdf0e10cSrcweir     virtual void MouseButtonDown( const BrowserMouseEvent& rEvt );
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     void SetDirty();
72cdf0e10cSrcweir 
73cdf0e10cSrcweir public:
74cdf0e10cSrcweir 	DataBrowser( Window* pParent, const ResId & rId, bool bLiveUpdate );
75cdf0e10cSrcweir 	virtual ~DataBrowser();
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	/** GetCellText returns the text at the given position
78cdf0e10cSrcweir 		@param	nRow
79cdf0e10cSrcweir 			the number of the row
80cdf0e10cSrcweir 		@param	nColId
81cdf0e10cSrcweir 			the ID of the column
82cdf0e10cSrcweir 		@return
83cdf0e10cSrcweir 			the text out of the cell
84cdf0e10cSrcweir 	*/
85cdf0e10cSrcweir 	virtual String	GetCellText(long nRow, sal_uInt16 nColId) const;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     /** returns the number in the given cell. If a cell is empty or contains a
88cdf0e10cSrcweir         string, the result will be Nan
89cdf0e10cSrcweir     */
90cdf0e10cSrcweir     double GetCellNumber( long nRow, sal_uInt16 nColumnId ) const;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     bool isDateString( rtl::OUString aInputString, double& fOutDateValue );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     // Window
95cdf0e10cSrcweir     virtual void Resize();
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     /// @return old state
98cdf0e10cSrcweir     bool SetReadOnly( bool bNewState );
99cdf0e10cSrcweir     bool IsReadOnly() const;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     /// reset the dirty status, if changes have been saved
102cdf0e10cSrcweir     void SetClean();
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     void SetDataFromModel( const ::com::sun::star::uno::Reference<
105cdf0e10cSrcweir                                ::com::sun::star::chart2::XChartDocument > & xChartDoc,
106cdf0e10cSrcweir                            const ::com::sun::star::uno::Reference<
107cdf0e10cSrcweir                                ::com::sun::star::uno::XComponentContext > & xContext );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir //     void setNumberFormatter();
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     // predicates to determine what actions are possible at the current cursor
112cdf0e10cSrcweir     // position.  This depends on the implementation of the according mutators
113cdf0e10cSrcweir     // below.  (They are used for enabling toolbar icons)
114cdf0e10cSrcweir     bool MayInsertRow() const;
115cdf0e10cSrcweir     bool MayInsertColumn() const;
116cdf0e10cSrcweir     bool MayDeleteRow() const;
117cdf0e10cSrcweir     bool MayDeleteColumn() const;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     bool MaySwapRows() const;
120cdf0e10cSrcweir     bool MaySwapColumns() const;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     // mutators mutating data
123cdf0e10cSrcweir 	void InsertRow();
124cdf0e10cSrcweir 	void InsertColumn();
125cdf0e10cSrcweir     void InsertTextColumn();
126cdf0e10cSrcweir 	void RemoveRow();
127cdf0e10cSrcweir 	void RemoveColumn();
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     using BrowseBox::RemoveColumn;
130cdf0e10cSrcweir     using BrowseBox::MouseButtonDown;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	void SwapRow();
133cdf0e10cSrcweir 	void SwapColumn();
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	void SetCursorMovedHdl( const Link& rLink );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     void SetCellModifiedHdl( const Link& rLink );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     /// confirms all pending changes to be ready to be closed
140cdf0e10cSrcweir     bool EndEditing();
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     // calls the protected inline-function BrowseBox::GetFirstVisibleColNumber()
143cdf0e10cSrcweir     sal_Int16 GetFirstVisibleColumNumber() const;
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     sal_Int32 GetTotalWidth() const;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     bool CellContainsNumbers( sal_Int32 nRow, sal_uInt16 nCol ) const;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     sal_uInt32 GetNumberFormatKey( sal_Int32 nRow, sal_uInt16 nCol ) const;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     bool IsEnableItem();
152cdf0e10cSrcweir     bool IsDataValid();
153cdf0e10cSrcweir     void ShowWarningBox();
154cdf0e10cSrcweir     bool ShowQueryBox();
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     void RenewSeriesHeaders();
157cdf0e10cSrcweir 
158cdf0e10cSrcweir private:
159cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
160cdf0e10cSrcweir             ::com::sun::star::chart2::XChartDocument > m_xChartDoc;
161cdf0e10cSrcweir     ::std::auto_ptr< DataBrowserModel > m_apDataBrowserModel;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     typedef ::std::vector< ::boost::shared_ptr< impl::SeriesHeader > > tSeriesHeaderContainer;
164cdf0e10cSrcweir     tSeriesHeaderContainer m_aSeriesHeaders;
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     ::boost::shared_ptr< NumberFormatterWrapper >  m_spNumberFormatterWrapper;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     /// the row that is currently painted
169cdf0e10cSrcweir     long                m_nSeekRow;
170cdf0e10cSrcweir     bool                m_bIsReadOnly;
171cdf0e10cSrcweir     bool                m_bIsDirty;
172cdf0e10cSrcweir     bool                m_bLiveUpdate;
173cdf0e10cSrcweir     bool                m_bDataValid;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     FormattedField      m_aNumberEditField;
176cdf0e10cSrcweir     Edit                m_aTextEditField;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     /// note: m_aNumberEditField must precede this member!
179cdf0e10cSrcweir     ::svt::CellControllerRef m_rNumberEditController;
180cdf0e10cSrcweir     /// note: m_aTextEditField must precede this member!
181cdf0e10cSrcweir     ::svt::CellControllerRef m_rTextEditController;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     Link				m_aCursorMovedHdlLink;
184cdf0e10cSrcweir     Link                m_aCellModifiedLink;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     void clearHeaders();
187cdf0e10cSrcweir 	void RenewTable();
188cdf0e10cSrcweir     void ImplAdjustHeaderControls();
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	String GetColString( sal_Int32 nColumnId ) const;
191cdf0e10cSrcweir 	String GetRowString( sal_Int32 nRow ) const;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     DECL_LINK( SeriesHeaderGotFocus, impl::SeriesHeaderEdit* );
194cdf0e10cSrcweir     DECL_LINK( SeriesHeaderChanged,  impl::SeriesHeaderEdit* );
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     /// not implemented: inhibit copy construction
197cdf0e10cSrcweir     DataBrowser( const DataBrowser & );
198cdf0e10cSrcweir };
199cdf0e10cSrcweir 
200cdf0e10cSrcweir } // namespace chart
201cdf0e10cSrcweir 
202cdf0e10cSrcweir #endif	// CHART_DATA_BROWSER_HXX
203