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