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