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