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 // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_chart2.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir // header for class SvNumberformat 32*cdf0e10cSrcweir #ifndef _ZFORMAT_HXX 33*cdf0e10cSrcweir #ifndef _ZFORLIST_DECLARE_TABLE 34*cdf0e10cSrcweir #define _ZFORLIST_DECLARE_TABLE 35*cdf0e10cSrcweir #endif 36*cdf0e10cSrcweir #include <svl/zformat.hxx> 37*cdf0e10cSrcweir #endif 38*cdf0e10cSrcweir // header for SvNumberFormatter 39*cdf0e10cSrcweir #include <svl/zforlist.hxx> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include "DataBrowser.hxx" 42*cdf0e10cSrcweir #include "DataBrowserModel.hxx" 43*cdf0e10cSrcweir #include "Strings.hrc" 44*cdf0e10cSrcweir #include "ContainerHelper.hxx" 45*cdf0e10cSrcweir #include "DataSeriesHelper.hxx" 46*cdf0e10cSrcweir #include "DiagramHelper.hxx" 47*cdf0e10cSrcweir #include "ChartModelHelper.hxx" 48*cdf0e10cSrcweir #include "CommonConverters.hxx" 49*cdf0e10cSrcweir #include "macros.hxx" 50*cdf0e10cSrcweir #include "NumberFormatterWrapper.hxx" 51*cdf0e10cSrcweir #include "servicenames_charttypes.hxx" 52*cdf0e10cSrcweir #include "ResId.hxx" 53*cdf0e10cSrcweir #include "Bitmaps.hrc" 54*cdf0e10cSrcweir #include "Bitmaps_HC.hrc" 55*cdf0e10cSrcweir #include "HelpIds.hrc" 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir #include <vcl/fixed.hxx> 58*cdf0e10cSrcweir #include <vcl/image.hxx> 59*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 60*cdf0e10cSrcweir #include <rtl/math.hxx> 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp> 63*cdf0e10cSrcweir #include <com/sun/star/chart2/XChartDocument.hpp> 64*cdf0e10cSrcweir #include <com/sun/star/chart2/XChartType.hpp> 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir #include <com/sun/star/container/XIndexReplace.hpp> 67*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormats.hpp> 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir #include <algorithm> 70*cdf0e10cSrcweir #include <functional> 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir #define SELECT_IMAGE(name,hc) Image( SchResId( hc ? name ## _HC : name )) 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir /* BROWSER_COLUMNSELECTION : single cells may be selected rather than only 75*cdf0e10cSrcweir entire rows 76*cdf0e10cSrcweir BROWSER_(H|V)LINES : show horizontal or vertical grid-lines 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir BROWSER_AUTO_(H|V)SCROLL : scroll automated horizontally or vertically when 79*cdf0e10cSrcweir cursor is moved beyond the edge of the dialog 80*cdf0e10cSrcweir BROWSER_HIGHLIGHT_NONE : Do not mark the current row with selection color 81*cdf0e10cSrcweir (usually blue) 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir */ 84*cdf0e10cSrcweir #define BROWSER_STANDARD_FLAGS \ 85*cdf0e10cSrcweir BROWSER_COLUMNSELECTION | \ 86*cdf0e10cSrcweir BROWSER_HLINES | BROWSER_VLINES | \ 87*cdf0e10cSrcweir BROWSER_AUTO_HSCROLL | BROWSER_AUTO_VSCROLL | \ 88*cdf0e10cSrcweir BROWSER_HIGHLIGHT_NONE 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir // BROWSER_HIDECURSOR would prevent flickering in edit fields, but navigating 91*cdf0e10cSrcweir // with shift up/down, and entering non-editable cells would be problematic, 92*cdf0e10cSrcweir // e.g. the first cell, or when being in read-only mode 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir using namespace ::com::sun::star; 96*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 97*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 98*cdf0e10cSrcweir using ::rtl::OUString; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir using namespace ::svt; 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir namespace 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir sal_Int32 lcl_getRowInData( long nRow ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir return static_cast< sal_Int32 >( nRow ); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir sal_Int32 lcl_getColumnInData( sal_uInt16 nCol ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir return static_cast< sal_Int32 >( nCol ) - 1; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir } // anonymous namespace 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir // -------------------------------------------------------------------------------- 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir namespace chart 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir // ---------------------------------------- 122*cdf0e10cSrcweir namespace impl 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir class SeriesHeaderEdit : public Edit 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir public: 128*cdf0e10cSrcweir SeriesHeaderEdit( Window * pParent ); 129*cdf0e10cSrcweir virtual ~SeriesHeaderEdit(); 130*cdf0e10cSrcweir virtual void MouseButtonDown( const MouseEvent& rMEvt ); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir void setStartColumn( sal_Int32 nStartColumn ); 133*cdf0e10cSrcweir sal_Int32 getStartColumn() const; 134*cdf0e10cSrcweir void SetShowWarningBox( bool bShowWarning = true ); 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir private: 137*cdf0e10cSrcweir sal_Int32 m_nStartColumn; 138*cdf0e10cSrcweir bool m_bShowWarningBox; 139*cdf0e10cSrcweir }; 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir SeriesHeaderEdit::SeriesHeaderEdit( Window * pParent ) : 142*cdf0e10cSrcweir Edit( pParent ), 143*cdf0e10cSrcweir m_nStartColumn( 0 ), 144*cdf0e10cSrcweir m_bShowWarningBox( false ) 145*cdf0e10cSrcweir {} 146*cdf0e10cSrcweir SeriesHeaderEdit::~SeriesHeaderEdit() 147*cdf0e10cSrcweir {} 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir void SeriesHeaderEdit::setStartColumn( sal_Int32 nStartColumn ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir m_nStartColumn = nStartColumn; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir sal_Int32 SeriesHeaderEdit::getStartColumn() const 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir return m_nStartColumn; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir void SeriesHeaderEdit::SetShowWarningBox( bool bShowWarning ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir m_bShowWarningBox = bShowWarning; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir void SeriesHeaderEdit::MouseButtonDown( const MouseEvent& rMEvt ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir Edit::MouseButtonDown( rMEvt ); 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir if( m_bShowWarningBox ) 169*cdf0e10cSrcweir WarningBox( this, WinBits( WB_OK ), 170*cdf0e10cSrcweir String( SchResId( STR_INVALID_NUMBER ))).Execute(); 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir class SeriesHeader 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir public: 176*cdf0e10cSrcweir explicit SeriesHeader( Window * pParent ); 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir void SetColor( const Color & rCol ); 179*cdf0e10cSrcweir void SetPos( const Point & rPos ); 180*cdf0e10cSrcweir void SetWidth( sal_Int32 nWidth ); 181*cdf0e10cSrcweir void SetChartType( const Reference< chart2::XChartType > & xChartType, 182*cdf0e10cSrcweir bool bSwapXAndYAxis, 183*cdf0e10cSrcweir bool bIsHighContrast ); 184*cdf0e10cSrcweir void SetSeriesName( const String & rName ); 185*cdf0e10cSrcweir void SetRange( sal_Int32 nStartCol, sal_Int32 nEndCol ); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir void SetPixelPosX( sal_Int32 nPos ); 188*cdf0e10cSrcweir void SetPixelWidth( sal_Int32 nWidth ); 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir sal_Int32 GetStartColumn() const; 191*cdf0e10cSrcweir sal_Int32 GetEndColumn() const; 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir static sal_Int32 GetRelativeAppFontXPosForNameField(); 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir void Show(); 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir /** call this before destroying the class. This notifies the listeners to 198*cdf0e10cSrcweir changes of the edit field for the series name. 199*cdf0e10cSrcweir */ 200*cdf0e10cSrcweir void applyChanges(); 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir void SetGetFocusHdl( const Link& rLink ); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir void SetEditChangedHdl( const Link & rLink ); 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir bool HasFocus() const; 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir private: 209*cdf0e10cSrcweir ::boost::shared_ptr< FixedImage > m_spSymbol; 210*cdf0e10cSrcweir ::boost::shared_ptr< SeriesHeaderEdit > m_spSeriesName; 211*cdf0e10cSrcweir ::boost::shared_ptr< FixedText > m_spColorBar; 212*cdf0e10cSrcweir OutputDevice * m_pDevice; 213*cdf0e10cSrcweir Link m_aChangeLink; 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir void notifyChanges(); 216*cdf0e10cSrcweir DECL_LINK( SeriesNameChanged, void * ); 217*cdf0e10cSrcweir DECL_LINK( SeriesNameEdited, void * ); 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir /// @param bHC </sal_True> for hight-contrast image 220*cdf0e10cSrcweir static Image GetChartTypeImage( 221*cdf0e10cSrcweir const Reference< chart2::XChartType > & xChartType, 222*cdf0e10cSrcweir bool bSwapXAndYAxis, 223*cdf0e10cSrcweir bool bHC ); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir sal_Int32 m_nStartCol, m_nEndCol; 226*cdf0e10cSrcweir sal_Int32 m_nWidth; 227*cdf0e10cSrcweir Point m_aPos; 228*cdf0e10cSrcweir bool m_bSeriesNameChangePending; 229*cdf0e10cSrcweir }; 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir SeriesHeader::SeriesHeader( Window * pParent ) : 232*cdf0e10cSrcweir m_spSymbol( new FixedImage( pParent, WB_NOBORDER )), 233*cdf0e10cSrcweir m_spSeriesName( new SeriesHeaderEdit( pParent )), 234*cdf0e10cSrcweir m_spColorBar( new FixedText( pParent, WB_NOBORDER )), 235*cdf0e10cSrcweir m_pDevice( pParent ), 236*cdf0e10cSrcweir m_nStartCol( 0 ), 237*cdf0e10cSrcweir m_nEndCol( 0 ), 238*cdf0e10cSrcweir m_nWidth( 42 ), 239*cdf0e10cSrcweir m_aPos( 0, 22 ), 240*cdf0e10cSrcweir m_bSeriesNameChangePending( false ) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir m_spSeriesName->EnableUpdateData( 4 * EDIT_UPDATEDATA_TIMEOUT ); // define is in vcl/edit.hxx 243*cdf0e10cSrcweir m_spSeriesName->SetUpdateDataHdl( LINK( this, SeriesHeader, SeriesNameChanged )); 244*cdf0e10cSrcweir m_spSeriesName->SetModifyHdl( LINK( this, SeriesHeader, SeriesNameEdited )); 245*cdf0e10cSrcweir m_spSeriesName->SetHelpId( HID_SCH_DATA_SERIES_LABEL ); 246*cdf0e10cSrcweir Show(); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir void SeriesHeader::notifyChanges() 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir if( m_aChangeLink.IsSet()) 252*cdf0e10cSrcweir m_aChangeLink.Call( m_spSeriesName.get()); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir m_bSeriesNameChangePending = false; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir void SeriesHeader::applyChanges() 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir if( m_bSeriesNameChangePending ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir notifyChanges(); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir void SeriesHeader::SetColor( const Color & rCol ) 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir m_spColorBar->SetControlBackground( rCol ); 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir const sal_Int32 nSymbolHeight = 10; 271*cdf0e10cSrcweir const sal_Int32 nSymbolDistance = 2; 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir sal_Int32 SeriesHeader::GetRelativeAppFontXPosForNameField() 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir return nSymbolHeight + nSymbolDistance; 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir void SeriesHeader::SetPos( const Point & rPos ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir m_aPos = rPos; 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir // chart type symbol 283*cdf0e10cSrcweir Point aPos( rPos ); 284*cdf0e10cSrcweir aPos.setY( aPos.getY() + nSymbolDistance ); 285*cdf0e10cSrcweir Size aSize( nSymbolHeight, nSymbolHeight ); 286*cdf0e10cSrcweir m_spSymbol->SetPosPixel( m_pDevice->LogicToPixel( aPos, MAP_APPFONT )); 287*cdf0e10cSrcweir m_spSymbol->SetSizePixel( m_pDevice->LogicToPixel( aSize, MAP_APPFONT )); 288*cdf0e10cSrcweir aPos.setY( aPos.getY() - nSymbolDistance ); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir // series name edit field 291*cdf0e10cSrcweir aPos.setX( aPos.getX() + nSymbolHeight + nSymbolDistance ); 292*cdf0e10cSrcweir aSize.setWidth( m_nWidth - nSymbolHeight - nSymbolDistance ); 293*cdf0e10cSrcweir sal_Int32 nHeight = 12; 294*cdf0e10cSrcweir aSize.setHeight( nHeight ); 295*cdf0e10cSrcweir m_spSeriesName->SetPosPixel( m_pDevice->LogicToPixel( aPos, MAP_APPFONT )); 296*cdf0e10cSrcweir m_spSeriesName->SetSizePixel( m_pDevice->LogicToPixel( aSize, MAP_APPFONT )); 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir // color bar 299*cdf0e10cSrcweir aPos.setX( rPos.getX() + 1 ); 300*cdf0e10cSrcweir aPos.setY( aPos.getY() + nHeight + 2 ); 301*cdf0e10cSrcweir nHeight = 3; 302*cdf0e10cSrcweir aSize.setWidth( m_nWidth - 1 ); 303*cdf0e10cSrcweir aSize.setHeight( nHeight ); 304*cdf0e10cSrcweir m_spColorBar->SetPosPixel( m_pDevice->LogicToPixel( aPos, MAP_APPFONT )); 305*cdf0e10cSrcweir m_spColorBar->SetSizePixel( m_pDevice->LogicToPixel( aSize, MAP_APPFONT )); 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir void SeriesHeader::SetWidth( sal_Int32 nWidth ) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir m_nWidth = nWidth; 311*cdf0e10cSrcweir SetPos( m_aPos ); 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir void SeriesHeader::SetPixelPosX( sal_Int32 nPos ) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir Point aPos( m_pDevice->LogicToPixel( m_aPos, MAP_APPFONT )); 318*cdf0e10cSrcweir aPos.setX( nPos ); 319*cdf0e10cSrcweir SetPos( m_pDevice->PixelToLogic( aPos, MAP_APPFONT )); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir void SeriesHeader::SetPixelWidth( sal_Int32 nWidth ) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir SetWidth( m_pDevice->PixelToLogic( Size( nWidth, 0 ), MAP_APPFONT ).getWidth()); 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir void SeriesHeader::SetChartType( 328*cdf0e10cSrcweir const Reference< chart2::XChartType > & xChartType, 329*cdf0e10cSrcweir bool bSwapXAndYAxis, 330*cdf0e10cSrcweir bool bIsHighContrast ) 331*cdf0e10cSrcweir { 332*cdf0e10cSrcweir m_spSymbol->SetImage( GetChartTypeImage( xChartType, bSwapXAndYAxis, bIsHighContrast )); 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir void SeriesHeader::SetSeriesName( const String & rName ) 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir m_spSeriesName->SetText( rName ); 338*cdf0e10cSrcweir } 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir void SeriesHeader::SetRange( sal_Int32 nStartCol, sal_Int32 nEndCol ) 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir m_nStartCol = nStartCol; 343*cdf0e10cSrcweir m_nEndCol = (nEndCol > nStartCol) ? nEndCol : nStartCol; 344*cdf0e10cSrcweir m_spSeriesName->setStartColumn( nStartCol ); 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir sal_Int32 SeriesHeader::GetStartColumn() const 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir return m_nStartCol; 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir sal_Int32 SeriesHeader::GetEndColumn() const 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir return m_nEndCol; 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir void SeriesHeader::Show() 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir m_spSymbol->Show(); 360*cdf0e10cSrcweir m_spSeriesName->Show(); 361*cdf0e10cSrcweir m_spColorBar->Show(); 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir void SeriesHeader::SetEditChangedHdl( const Link & rLink ) 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir m_aChangeLink = rLink; 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir IMPL_LINK( SeriesHeader, SeriesNameChanged, void * , EMPTYARG ) 370*cdf0e10cSrcweir { 371*cdf0e10cSrcweir notifyChanges(); 372*cdf0e10cSrcweir return 0; 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir IMPL_LINK( SeriesHeader, SeriesNameEdited, void * , EMPTYARG ) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir m_bSeriesNameChangePending = true; 378*cdf0e10cSrcweir return 0; 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir void SeriesHeader::SetGetFocusHdl( const Link& rLink ) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir m_spSeriesName->SetGetFocusHdl( rLink ); 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir bool SeriesHeader::HasFocus() const 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir return m_spSeriesName->HasFocus(); 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir Image SeriesHeader::GetChartTypeImage( 392*cdf0e10cSrcweir const Reference< chart2::XChartType > & xChartType, 393*cdf0e10cSrcweir bool bSwapXAndYAxis, 394*cdf0e10cSrcweir bool bHC ) 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir Image aResult; 397*cdf0e10cSrcweir if( !xChartType.is()) 398*cdf0e10cSrcweir return aResult; 399*cdf0e10cSrcweir OUString aChartTypeName( xChartType->getChartType()); 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir if( aChartTypeName.equals( CHART2_SERVICE_NAME_CHARTTYPE_AREA )) 402*cdf0e10cSrcweir { 403*cdf0e10cSrcweir aResult = SELECT_IMAGE( IMG_TYPE_AREA, bHC ); 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir else if( aChartTypeName.equals( CHART2_SERVICE_NAME_CHARTTYPE_COLUMN )) 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir if( bSwapXAndYAxis ) 408*cdf0e10cSrcweir aResult = SELECT_IMAGE( IMG_TYPE_BAR, bHC ); 409*cdf0e10cSrcweir else 410*cdf0e10cSrcweir aResult = SELECT_IMAGE( IMG_TYPE_COLUMN, bHC ); 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir else if( aChartTypeName.equals( CHART2_SERVICE_NAME_CHARTTYPE_LINE )) 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir aResult = SELECT_IMAGE( IMG_TYPE_LINE, bHC ); 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir else if( aChartTypeName.equals( CHART2_SERVICE_NAME_CHARTTYPE_SCATTER )) 417*cdf0e10cSrcweir { 418*cdf0e10cSrcweir aResult = SELECT_IMAGE( IMG_TYPE_XY, bHC ); 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir else if( aChartTypeName.equals( CHART2_SERVICE_NAME_CHARTTYPE_PIE )) 421*cdf0e10cSrcweir { 422*cdf0e10cSrcweir aResult = SELECT_IMAGE( IMG_TYPE_PIE, bHC ); 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir else if( aChartTypeName.equals( CHART2_SERVICE_NAME_CHARTTYPE_NET ) 425*cdf0e10cSrcweir || aChartTypeName.equals( CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET ) ) 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir aResult = SELECT_IMAGE( IMG_TYPE_NET, bHC ); 428*cdf0e10cSrcweir } 429*cdf0e10cSrcweir else if( aChartTypeName.equals( CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK )) 430*cdf0e10cSrcweir { 431*cdf0e10cSrcweir // @todo: correct image for candle-stick type 432*cdf0e10cSrcweir aResult = SELECT_IMAGE( IMG_TYPE_STOCK, bHC ); 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir else if( aChartTypeName.equals( CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE )) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir aResult = SELECT_IMAGE( IMG_TYPE_BUBBLE, bHC ); 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir return aResult; 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir struct applyChangesFunctor : public ::std::unary_function< ::boost::shared_ptr< SeriesHeader >, void > 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir void operator() ( ::boost::shared_ptr< SeriesHeader > spHeader ) 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir spHeader->applyChanges(); 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir }; 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir } // namespace impl 451*cdf0e10cSrcweir // ---------------------------------------- 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir namespace 454*cdf0e10cSrcweir { 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir /** returns false, if no header as the focus. 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir If a header has the focus, true is returned and the index of the header 459*cdf0e10cSrcweir with focus is set at pIndex if pOutIndex is not 0. 460*cdf0e10cSrcweir */ 461*cdf0e10cSrcweir bool lcl_SeriesHeaderHasFocus( 462*cdf0e10cSrcweir const ::std::vector< ::boost::shared_ptr< ::chart::impl::SeriesHeader > > & rSeriesHeader, 463*cdf0e10cSrcweir sal_Int32 * pOutIndex = 0 ) 464*cdf0e10cSrcweir { 465*cdf0e10cSrcweir sal_Int32 nIndex = 0; 466*cdf0e10cSrcweir for( ::std::vector< ::boost::shared_ptr< ::chart::impl::SeriesHeader > >::const_iterator aIt( rSeriesHeader.begin()); 467*cdf0e10cSrcweir aIt != rSeriesHeader.end(); ++aIt, ++nIndex ) 468*cdf0e10cSrcweir { 469*cdf0e10cSrcweir if( (*aIt)->HasFocus()) 470*cdf0e10cSrcweir { 471*cdf0e10cSrcweir if( pOutIndex ) 472*cdf0e10cSrcweir *pOutIndex = nIndex; 473*cdf0e10cSrcweir return true; 474*cdf0e10cSrcweir } 475*cdf0e10cSrcweir } 476*cdf0e10cSrcweir return false; 477*cdf0e10cSrcweir } 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir sal_Int32 lcl_getColumnInDataOrHeader( 480*cdf0e10cSrcweir sal_uInt16 nCol, const ::std::vector< ::boost::shared_ptr< ::chart::impl::SeriesHeader > > & rSeriesHeader ) 481*cdf0e10cSrcweir { 482*cdf0e10cSrcweir sal_Int32 nColIdx = 0; 483*cdf0e10cSrcweir bool bHeaderHasFocus( lcl_SeriesHeaderHasFocus( rSeriesHeader, &nColIdx )); 484*cdf0e10cSrcweir 485*cdf0e10cSrcweir if( bHeaderHasFocus ) 486*cdf0e10cSrcweir nColIdx = lcl_getColumnInData( static_cast< sal_uInt16 >( rSeriesHeader[nColIdx]->GetStartColumn())); 487*cdf0e10cSrcweir else 488*cdf0e10cSrcweir nColIdx = lcl_getColumnInData( nCol ); 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir return nColIdx; 491*cdf0e10cSrcweir } 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir } // anonymous namespace 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir DataBrowser::DataBrowser( Window* pParent, const ResId& rId, bool bLiveUpdate ) : 497*cdf0e10cSrcweir ::svt::EditBrowseBox( pParent, rId, EBBF_SMART_TAB_TRAVEL | EBBF_HANDLE_COLUMN_TEXT, BROWSER_STANDARD_FLAGS ), 498*cdf0e10cSrcweir m_nSeekRow( 0 ), 499*cdf0e10cSrcweir m_bIsReadOnly( false ), 500*cdf0e10cSrcweir m_bIsDirty( false ), 501*cdf0e10cSrcweir m_bLiveUpdate( bLiveUpdate ), 502*cdf0e10cSrcweir m_bDataValid( true ), 503*cdf0e10cSrcweir m_aNumberEditField( & EditBrowseBox::GetDataWindow(), WB_NOBORDER ), 504*cdf0e10cSrcweir m_aTextEditField( & EditBrowseBox::GetDataWindow(), WB_NOBORDER ), 505*cdf0e10cSrcweir m_rNumberEditController( new ::svt::FormattedFieldCellController( & m_aNumberEditField )), 506*cdf0e10cSrcweir m_rTextEditController( new ::svt::EditCellController( & m_aTextEditField )) 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir double fNan; 509*cdf0e10cSrcweir ::rtl::math::setNan( & fNan ); 510*cdf0e10cSrcweir m_aNumberEditField.SetDefaultValue( fNan ); 511*cdf0e10cSrcweir m_aNumberEditField.TreatAsNumber( sal_True ); 512*cdf0e10cSrcweir RenewTable(); 513*cdf0e10cSrcweir SetClean(); 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir DataBrowser::~DataBrowser() 517*cdf0e10cSrcweir { 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir 520*cdf0e10cSrcweir bool DataBrowser::MayInsertRow() const 521*cdf0e10cSrcweir { 522*cdf0e10cSrcweir return ! IsReadOnly() 523*cdf0e10cSrcweir && ( !lcl_SeriesHeaderHasFocus( m_aSeriesHeaders )); 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir bool DataBrowser::MayInsertColumn() const 527*cdf0e10cSrcweir { 528*cdf0e10cSrcweir return ! IsReadOnly(); 529*cdf0e10cSrcweir } 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir bool DataBrowser::MayDeleteRow() const 532*cdf0e10cSrcweir { 533*cdf0e10cSrcweir return ! IsReadOnly() 534*cdf0e10cSrcweir && ( !lcl_SeriesHeaderHasFocus( m_aSeriesHeaders )) 535*cdf0e10cSrcweir && ( GetCurRow() >= 0 ) 536*cdf0e10cSrcweir && ( GetRowCount() > 1 ); 537*cdf0e10cSrcweir } 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir bool DataBrowser::MayDeleteColumn() const 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir // if a series header has the focus 542*cdf0e10cSrcweir if( lcl_SeriesHeaderHasFocus( m_aSeriesHeaders )) 543*cdf0e10cSrcweir return true; 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir return ! IsReadOnly() 546*cdf0e10cSrcweir && ( GetCurColumnId() > 1 ) 547*cdf0e10cSrcweir && ( ColCount() > 2 ); 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir bool DataBrowser::MaySwapRows() const 551*cdf0e10cSrcweir { 552*cdf0e10cSrcweir return ! IsReadOnly() 553*cdf0e10cSrcweir && ( !lcl_SeriesHeaderHasFocus( m_aSeriesHeaders )) 554*cdf0e10cSrcweir && ( GetCurRow() >= 0 ) 555*cdf0e10cSrcweir && ( GetCurRow() < GetRowCount() - 1 ); 556*cdf0e10cSrcweir } 557*cdf0e10cSrcweir 558*cdf0e10cSrcweir bool DataBrowser::MaySwapColumns() const 559*cdf0e10cSrcweir { 560*cdf0e10cSrcweir // if a series header (except the last one) has the focus 561*cdf0e10cSrcweir { 562*cdf0e10cSrcweir sal_Int32 nColIndex(0); 563*cdf0e10cSrcweir if( lcl_SeriesHeaderHasFocus( m_aSeriesHeaders, &nColIndex )) 564*cdf0e10cSrcweir return (static_cast< sal_uInt32 >( nColIndex ) < (m_aSeriesHeaders.size() - 1)); 565*cdf0e10cSrcweir } 566*cdf0e10cSrcweir 567*cdf0e10cSrcweir sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); 568*cdf0e10cSrcweir return ! IsReadOnly() 569*cdf0e10cSrcweir && ( nColIdx > 0 ) 570*cdf0e10cSrcweir && ( nColIdx < ColCount()-2 ) 571*cdf0e10cSrcweir && m_apDataBrowserModel.get() 572*cdf0e10cSrcweir && !m_apDataBrowserModel->isCategoriesColumn( nColIdx ); 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir 575*cdf0e10cSrcweir void DataBrowser::clearHeaders() 576*cdf0e10cSrcweir { 577*cdf0e10cSrcweir ::std::for_each( m_aSeriesHeaders.begin(), m_aSeriesHeaders.end(), impl::applyChangesFunctor()); 578*cdf0e10cSrcweir m_aSeriesHeaders.clear(); 579*cdf0e10cSrcweir } 580*cdf0e10cSrcweir 581*cdf0e10cSrcweir void DataBrowser::RenewTable() 582*cdf0e10cSrcweir { 583*cdf0e10cSrcweir if( ! m_apDataBrowserModel.get()) 584*cdf0e10cSrcweir return; 585*cdf0e10cSrcweir 586*cdf0e10cSrcweir long nOldRow = GetCurRow(); 587*cdf0e10cSrcweir sal_uInt16 nOldColId = GetCurColumnId(); 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir sal_Bool bLastUpdateMode = GetUpdateMode(); 590*cdf0e10cSrcweir SetUpdateMode( sal_False ); 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir if( IsModified() ) 593*cdf0e10cSrcweir SaveModified(); 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir DeactivateCell(); 596*cdf0e10cSrcweir 597*cdf0e10cSrcweir RemoveColumns(); 598*cdf0e10cSrcweir RowRemoved( 1, GetRowCount() ); 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir // for row numbers 601*cdf0e10cSrcweir InsertHandleColumn( static_cast< sal_uInt16 >( 602*cdf0e10cSrcweir GetDataWindow().LogicToPixel( Size( 42, 0 )).getWidth() )); 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir OUString aDefaultSeriesName( ::chart::SchResId::getResString( STR_COLUMN_LABEL )); 605*cdf0e10cSrcweir replaceParamterInString( aDefaultSeriesName, C2U("%COLUMNNUMBER"), OUString::valueOf( sal_Int32(24) ) ); 606*cdf0e10cSrcweir sal_Int32 nColumnWidth = GetDataWindow().GetTextWidth( aDefaultSeriesName ) 607*cdf0e10cSrcweir + GetDataWindow().LogicToPixel( Point( 4 + impl::SeriesHeader::GetRelativeAppFontXPosForNameField(), 0 ), MAP_APPFONT ).X(); 608*cdf0e10cSrcweir sal_Int32 nColumnCount = m_apDataBrowserModel->getColumnCount(); 609*cdf0e10cSrcweir // nRowCount is a member of a base class 610*cdf0e10cSrcweir sal_Int32 nRowCountLocal = m_apDataBrowserModel->getMaxRowCount(); 611*cdf0e10cSrcweir for( sal_Int32 nColIdx=1; nColIdx<=nColumnCount; ++nColIdx ) 612*cdf0e10cSrcweir { 613*cdf0e10cSrcweir InsertDataColumn( static_cast< sal_uInt16 >( nColIdx ), GetColString( nColIdx ), nColumnWidth ); 614*cdf0e10cSrcweir } 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir RowInserted( 1, nRowCountLocal ); 617*cdf0e10cSrcweir GoToRow( ::std::min( nOldRow, GetRowCount() - 1 )); 618*cdf0e10cSrcweir GoToColumnId( ::std::min( nOldColId, static_cast< sal_uInt16 >( ColCount() - 1 ))); 619*cdf0e10cSrcweir 620*cdf0e10cSrcweir Window * pWin = this->GetParent(); 621*cdf0e10cSrcweir if( !pWin ) 622*cdf0e10cSrcweir pWin = this; 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir // fill series headers 625*cdf0e10cSrcweir clearHeaders(); 626*cdf0e10cSrcweir const DataBrowserModel::tDataHeaderVector& aHeaders( m_apDataBrowserModel->getDataHeaders()); 627*cdf0e10cSrcweir Link aFocusLink( LINK( this, DataBrowser, SeriesHeaderGotFocus )); 628*cdf0e10cSrcweir Link aSeriesHeaderChangedLink( LINK( this, DataBrowser, SeriesHeaderChanged )); 629*cdf0e10cSrcweir bool bIsHighContrast = pWin ? (pWin->GetSettings().GetStyleSettings().GetHighContrastMode()) : false; 630*cdf0e10cSrcweir 631*cdf0e10cSrcweir for( DataBrowserModel::tDataHeaderVector::const_iterator aIt( aHeaders.begin()); 632*cdf0e10cSrcweir aIt != aHeaders.end(); ++aIt ) 633*cdf0e10cSrcweir { 634*cdf0e10cSrcweir ::boost::shared_ptr< impl::SeriesHeader > spHeader( new impl::SeriesHeader( pWin )); 635*cdf0e10cSrcweir Reference< beans::XPropertySet > xSeriesProp( aIt->m_xDataSeries, uno::UNO_QUERY ); 636*cdf0e10cSrcweir sal_Int32 nColor = 0; 637*cdf0e10cSrcweir // @todo: Set "DraftColor", i.e. interpolated colors for gradients, bitmaps, etc. 638*cdf0e10cSrcweir if( xSeriesProp.is() && 639*cdf0e10cSrcweir ( xSeriesProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Color"))) >>= nColor )) 640*cdf0e10cSrcweir spHeader->SetColor( Color( nColor )); 641*cdf0e10cSrcweir spHeader->SetChartType( aIt->m_xChartType, aIt->m_bSwapXAndYAxis, bIsHighContrast ); 642*cdf0e10cSrcweir spHeader->SetSeriesName( 643*cdf0e10cSrcweir String( DataSeriesHelper::getDataSeriesLabel( 644*cdf0e10cSrcweir aIt->m_xDataSeries, 645*cdf0e10cSrcweir (aIt->m_xChartType.is() ? 646*cdf0e10cSrcweir aIt->m_xChartType->getRoleOfSequenceForSeriesLabel() : 647*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("values-y")))))); 648*cdf0e10cSrcweir // index is 1-based, as 0 is for the column that contains the row-numbers 649*cdf0e10cSrcweir spHeader->SetRange( aIt->m_nStartColumn + 1, aIt->m_nEndColumn + 1 ); 650*cdf0e10cSrcweir spHeader->SetGetFocusHdl( aFocusLink ); 651*cdf0e10cSrcweir spHeader->SetEditChangedHdl( aSeriesHeaderChangedLink ); 652*cdf0e10cSrcweir m_aSeriesHeaders.push_back( spHeader ); 653*cdf0e10cSrcweir } 654*cdf0e10cSrcweir 655*cdf0e10cSrcweir ImplAdjustHeaderControls(); 656*cdf0e10cSrcweir SetDirty(); 657*cdf0e10cSrcweir SetUpdateMode( bLastUpdateMode ); 658*cdf0e10cSrcweir ActivateCell(); 659*cdf0e10cSrcweir Invalidate(); 660*cdf0e10cSrcweir } 661*cdf0e10cSrcweir 662*cdf0e10cSrcweir String DataBrowser::GetColString( sal_Int32 nColumnId ) const 663*cdf0e10cSrcweir { 664*cdf0e10cSrcweir OSL_ASSERT( m_apDataBrowserModel.get()); 665*cdf0e10cSrcweir if( nColumnId > 0 ) 666*cdf0e10cSrcweir return String( m_apDataBrowserModel->getRoleOfColumn( static_cast< sal_Int32 >( nColumnId ) - 1 )); 667*cdf0e10cSrcweir return String(); 668*cdf0e10cSrcweir } 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir String DataBrowser::GetRowString( sal_Int32 nRow ) const 671*cdf0e10cSrcweir { 672*cdf0e10cSrcweir return String::CreateFromInt32( nRow + 1 ); 673*cdf0e10cSrcweir } 674*cdf0e10cSrcweir 675*cdf0e10cSrcweir String DataBrowser::GetCellText( long nRow, sal_uInt16 nColumnId ) const 676*cdf0e10cSrcweir { 677*cdf0e10cSrcweir String aResult; 678*cdf0e10cSrcweir 679*cdf0e10cSrcweir if( nColumnId == 0 ) 680*cdf0e10cSrcweir { 681*cdf0e10cSrcweir aResult = GetRowString( static_cast< sal_Int32 >( nRow )); 682*cdf0e10cSrcweir } 683*cdf0e10cSrcweir else if( nRow >= 0 && 684*cdf0e10cSrcweir m_apDataBrowserModel.get()) 685*cdf0e10cSrcweir { 686*cdf0e10cSrcweir sal_Int32 nColIndex = static_cast< sal_Int32 >( nColumnId ) - 1; 687*cdf0e10cSrcweir 688*cdf0e10cSrcweir if( m_apDataBrowserModel->getCellType( nColIndex, nRow ) == DataBrowserModel::NUMBER ) 689*cdf0e10cSrcweir { 690*cdf0e10cSrcweir double fData( m_apDataBrowserModel->getCellNumber( nColIndex, nRow )); 691*cdf0e10cSrcweir sal_Int32 nLabelColor; 692*cdf0e10cSrcweir bool bColorChanged = false; 693*cdf0e10cSrcweir 694*cdf0e10cSrcweir if( ! ::rtl::math::isNan( fData ) && 695*cdf0e10cSrcweir m_spNumberFormatterWrapper.get() ) 696*cdf0e10cSrcweir aResult = String( m_spNumberFormatterWrapper->getFormattedString( 697*cdf0e10cSrcweir GetNumberFormatKey( nRow, nColumnId ), 698*cdf0e10cSrcweir fData, nLabelColor, bColorChanged )); 699*cdf0e10cSrcweir } 700*cdf0e10cSrcweir else if( m_apDataBrowserModel->getCellType( nColIndex, nRow ) == DataBrowserModel::TEXTORDATE ) 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir uno::Any aAny = m_apDataBrowserModel->getCellAny( nColIndex, nRow ); 703*cdf0e10cSrcweir OUString aText; 704*cdf0e10cSrcweir double fDouble=0.0; 705*cdf0e10cSrcweir if( aAny>>=aText ) 706*cdf0e10cSrcweir aResult = aText; 707*cdf0e10cSrcweir else if( aAny>>=fDouble ) 708*cdf0e10cSrcweir { 709*cdf0e10cSrcweir sal_Int32 nLabelColor; 710*cdf0e10cSrcweir bool bColorChanged = false; 711*cdf0e10cSrcweir sal_Int32 nDateNumberFormat = DiagramHelper::getDateNumberFormat( Reference< util::XNumberFormatsSupplier >( m_xChartDoc, uno::UNO_QUERY) ); 712*cdf0e10cSrcweir if( ! ::rtl::math::isNan( fDouble ) && m_spNumberFormatterWrapper.get() ) 713*cdf0e10cSrcweir aResult = String( m_spNumberFormatterWrapper->getFormattedString( 714*cdf0e10cSrcweir nDateNumberFormat, fDouble, nLabelColor, bColorChanged )); 715*cdf0e10cSrcweir } 716*cdf0e10cSrcweir } 717*cdf0e10cSrcweir else 718*cdf0e10cSrcweir { 719*cdf0e10cSrcweir OSL_ASSERT( m_apDataBrowserModel->getCellType( nColIndex, nRow ) == DataBrowserModel::TEXT ); 720*cdf0e10cSrcweir aResult = m_apDataBrowserModel->getCellText( nColIndex, nRow ); 721*cdf0e10cSrcweir } 722*cdf0e10cSrcweir } 723*cdf0e10cSrcweir 724*cdf0e10cSrcweir return aResult; 725*cdf0e10cSrcweir } 726*cdf0e10cSrcweir 727*cdf0e10cSrcweir double DataBrowser::GetCellNumber( long nRow, sal_uInt16 nColumnId ) const 728*cdf0e10cSrcweir { 729*cdf0e10cSrcweir double fResult; 730*cdf0e10cSrcweir ::rtl::math::setNan( & fResult ); 731*cdf0e10cSrcweir 732*cdf0e10cSrcweir if(( nColumnId >= 1 ) && ( nRow >= 0 ) && 733*cdf0e10cSrcweir m_apDataBrowserModel.get()) 734*cdf0e10cSrcweir { 735*cdf0e10cSrcweir fResult = m_apDataBrowserModel->getCellNumber( 736*cdf0e10cSrcweir static_cast< sal_Int32 >( nColumnId ) - 1, nRow ); 737*cdf0e10cSrcweir } 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir return fResult; 740*cdf0e10cSrcweir } 741*cdf0e10cSrcweir 742*cdf0e10cSrcweir void DataBrowser::Resize() 743*cdf0e10cSrcweir { 744*cdf0e10cSrcweir sal_Bool bLastUpdateMode = GetUpdateMode(); 745*cdf0e10cSrcweir SetUpdateMode( sal_False ); 746*cdf0e10cSrcweir 747*cdf0e10cSrcweir ::svt::EditBrowseBox::Resize(); 748*cdf0e10cSrcweir ImplAdjustHeaderControls(); 749*cdf0e10cSrcweir SetUpdateMode( bLastUpdateMode ); 750*cdf0e10cSrcweir } 751*cdf0e10cSrcweir 752*cdf0e10cSrcweir bool DataBrowser::SetReadOnly( bool bNewState ) 753*cdf0e10cSrcweir { 754*cdf0e10cSrcweir bool bResult = m_bIsReadOnly; 755*cdf0e10cSrcweir 756*cdf0e10cSrcweir if( m_bIsReadOnly != bNewState ) 757*cdf0e10cSrcweir { 758*cdf0e10cSrcweir m_bIsReadOnly = bNewState; 759*cdf0e10cSrcweir Invalidate(); 760*cdf0e10cSrcweir DeactivateCell(); 761*cdf0e10cSrcweir } 762*cdf0e10cSrcweir 763*cdf0e10cSrcweir return bResult; 764*cdf0e10cSrcweir } 765*cdf0e10cSrcweir 766*cdf0e10cSrcweir bool DataBrowser::IsReadOnly() const 767*cdf0e10cSrcweir { 768*cdf0e10cSrcweir return m_bIsReadOnly; 769*cdf0e10cSrcweir } 770*cdf0e10cSrcweir 771*cdf0e10cSrcweir 772*cdf0e10cSrcweir void DataBrowser::SetClean() 773*cdf0e10cSrcweir { 774*cdf0e10cSrcweir m_bIsDirty = false; 775*cdf0e10cSrcweir } 776*cdf0e10cSrcweir 777*cdf0e10cSrcweir void DataBrowser::SetDirty() 778*cdf0e10cSrcweir { 779*cdf0e10cSrcweir if( !m_bLiveUpdate ) 780*cdf0e10cSrcweir m_bIsDirty = true; 781*cdf0e10cSrcweir } 782*cdf0e10cSrcweir 783*cdf0e10cSrcweir void DataBrowser::CursorMoved() 784*cdf0e10cSrcweir { 785*cdf0e10cSrcweir EditBrowseBox::CursorMoved(); 786*cdf0e10cSrcweir 787*cdf0e10cSrcweir if( GetUpdateMode() && m_aCursorMovedHdlLink.IsSet()) 788*cdf0e10cSrcweir m_aCursorMovedHdlLink.Call( this ); 789*cdf0e10cSrcweir } 790*cdf0e10cSrcweir 791*cdf0e10cSrcweir void DataBrowser::SetCellModifiedHdl( const Link& rLink ) 792*cdf0e10cSrcweir { 793*cdf0e10cSrcweir m_aCellModifiedLink = rLink; 794*cdf0e10cSrcweir } 795*cdf0e10cSrcweir 796*cdf0e10cSrcweir void DataBrowser::MouseButtonDown( const BrowserMouseEvent& rEvt ) 797*cdf0e10cSrcweir { 798*cdf0e10cSrcweir if( !m_bDataValid ) 799*cdf0e10cSrcweir ShowWarningBox(); 800*cdf0e10cSrcweir else 801*cdf0e10cSrcweir EditBrowseBox::MouseButtonDown( rEvt ); 802*cdf0e10cSrcweir } 803*cdf0e10cSrcweir 804*cdf0e10cSrcweir void DataBrowser::ShowWarningBox() 805*cdf0e10cSrcweir { 806*cdf0e10cSrcweir WarningBox( this, WinBits( WB_OK ), 807*cdf0e10cSrcweir String( SchResId( STR_INVALID_NUMBER ))).Execute(); 808*cdf0e10cSrcweir } 809*cdf0e10cSrcweir 810*cdf0e10cSrcweir bool DataBrowser::ShowQueryBox() 811*cdf0e10cSrcweir { 812*cdf0e10cSrcweir QueryBox* pQueryBox = new QueryBox( this, WB_YES_NO, String( SchResId( STR_DATA_EDITOR_INCORRECT_INPUT ))); 813*cdf0e10cSrcweir 814*cdf0e10cSrcweir return ( pQueryBox->Execute() == RET_YES ); 815*cdf0e10cSrcweir } 816*cdf0e10cSrcweir 817*cdf0e10cSrcweir bool DataBrowser::IsDataValid() 818*cdf0e10cSrcweir { 819*cdf0e10cSrcweir bool bValid = true; 820*cdf0e10cSrcweir const sal_Int32 nRow = lcl_getRowInData( GetCurRow()); 821*cdf0e10cSrcweir const sal_Int32 nCol = lcl_getColumnInData( GetCurColumnId()); 822*cdf0e10cSrcweir 823*cdf0e10cSrcweir if( m_apDataBrowserModel->getCellType( nCol, nRow ) == DataBrowserModel::NUMBER ) 824*cdf0e10cSrcweir { 825*cdf0e10cSrcweir sal_uInt32 nDummy = 0; 826*cdf0e10cSrcweir double fDummy = 0.0; 827*cdf0e10cSrcweir String aText( m_aNumberEditField.GetText()); 828*cdf0e10cSrcweir 829*cdf0e10cSrcweir if( aText.Len() > 0 && 830*cdf0e10cSrcweir m_spNumberFormatterWrapper.get() && 831*cdf0e10cSrcweir m_spNumberFormatterWrapper->getSvNumberFormatter() && 832*cdf0e10cSrcweir ! m_spNumberFormatterWrapper->getSvNumberFormatter()->IsNumberFormat( 833*cdf0e10cSrcweir aText, nDummy, fDummy )) 834*cdf0e10cSrcweir { 835*cdf0e10cSrcweir bValid = false; 836*cdf0e10cSrcweir } 837*cdf0e10cSrcweir } 838*cdf0e10cSrcweir 839*cdf0e10cSrcweir return bValid; 840*cdf0e10cSrcweir } 841*cdf0e10cSrcweir 842*cdf0e10cSrcweir bool DataBrowser::IsEnableItem() 843*cdf0e10cSrcweir { 844*cdf0e10cSrcweir return m_bDataValid; 845*cdf0e10cSrcweir } 846*cdf0e10cSrcweir 847*cdf0e10cSrcweir void DataBrowser::CellModified() 848*cdf0e10cSrcweir { 849*cdf0e10cSrcweir m_bDataValid = IsDataValid(); 850*cdf0e10cSrcweir SetDirty(); 851*cdf0e10cSrcweir if( m_aCellModifiedLink.IsSet()) 852*cdf0e10cSrcweir m_aCursorMovedHdlLink.Call( this ); 853*cdf0e10cSrcweir } 854*cdf0e10cSrcweir 855*cdf0e10cSrcweir void DataBrowser::SetDataFromModel( 856*cdf0e10cSrcweir const Reference< chart2::XChartDocument > & xChartDoc, 857*cdf0e10cSrcweir const Reference< uno::XComponentContext > & xContext ) 858*cdf0e10cSrcweir { 859*cdf0e10cSrcweir if( m_bLiveUpdate ) 860*cdf0e10cSrcweir { 861*cdf0e10cSrcweir m_xChartDoc.set( xChartDoc ); 862*cdf0e10cSrcweir } 863*cdf0e10cSrcweir else 864*cdf0e10cSrcweir { 865*cdf0e10cSrcweir Reference< util::XCloneable > xCloneable( xChartDoc, uno::UNO_QUERY ); 866*cdf0e10cSrcweir if( xCloneable.is()) 867*cdf0e10cSrcweir m_xChartDoc.set( xCloneable->createClone(), uno::UNO_QUERY ); 868*cdf0e10cSrcweir } 869*cdf0e10cSrcweir 870*cdf0e10cSrcweir m_apDataBrowserModel.reset( new DataBrowserModel( m_xChartDoc, xContext )); 871*cdf0e10cSrcweir m_spNumberFormatterWrapper.reset( 872*cdf0e10cSrcweir new NumberFormatterWrapper( 873*cdf0e10cSrcweir Reference< util::XNumberFormatsSupplier >( m_xChartDoc, uno::UNO_QUERY ))); 874*cdf0e10cSrcweir 875*cdf0e10cSrcweir if( m_spNumberFormatterWrapper.get() ) 876*cdf0e10cSrcweir m_aNumberEditField.SetFormatter( m_spNumberFormatterWrapper->getSvNumberFormatter() ); 877*cdf0e10cSrcweir 878*cdf0e10cSrcweir RenewTable(); 879*cdf0e10cSrcweir 880*cdf0e10cSrcweir const sal_Int32 nColCnt = m_apDataBrowserModel->getColumnCount(); 881*cdf0e10cSrcweir const sal_Int32 nRowCnt = m_apDataBrowserModel->getMaxRowCount(); 882*cdf0e10cSrcweir if( nRowCnt && nColCnt ) 883*cdf0e10cSrcweir { 884*cdf0e10cSrcweir GoToRow( 0 ); 885*cdf0e10cSrcweir GoToColumnId( 1 ); 886*cdf0e10cSrcweir } 887*cdf0e10cSrcweir SetClean(); 888*cdf0e10cSrcweir } 889*cdf0e10cSrcweir 890*cdf0e10cSrcweir void DataBrowser::InsertColumn() 891*cdf0e10cSrcweir { 892*cdf0e10cSrcweir sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); 893*cdf0e10cSrcweir 894*cdf0e10cSrcweir if( nColIdx >= 0 && 895*cdf0e10cSrcweir m_apDataBrowserModel.get()) 896*cdf0e10cSrcweir { 897*cdf0e10cSrcweir // save changes made to edit-field 898*cdf0e10cSrcweir if( IsModified() ) 899*cdf0e10cSrcweir SaveModified(); 900*cdf0e10cSrcweir 901*cdf0e10cSrcweir m_apDataBrowserModel->insertDataSeries( nColIdx ); 902*cdf0e10cSrcweir RenewTable(); 903*cdf0e10cSrcweir } 904*cdf0e10cSrcweir } 905*cdf0e10cSrcweir 906*cdf0e10cSrcweir void DataBrowser::InsertTextColumn() 907*cdf0e10cSrcweir { 908*cdf0e10cSrcweir sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); 909*cdf0e10cSrcweir 910*cdf0e10cSrcweir if( nColIdx >= 0 && 911*cdf0e10cSrcweir m_apDataBrowserModel.get()) 912*cdf0e10cSrcweir { 913*cdf0e10cSrcweir // save changes made to edit-field 914*cdf0e10cSrcweir if( IsModified() ) 915*cdf0e10cSrcweir SaveModified(); 916*cdf0e10cSrcweir 917*cdf0e10cSrcweir m_apDataBrowserModel->insertComplexCategoryLevel( nColIdx ); 918*cdf0e10cSrcweir RenewTable(); 919*cdf0e10cSrcweir } 920*cdf0e10cSrcweir } 921*cdf0e10cSrcweir 922*cdf0e10cSrcweir void DataBrowser::RemoveColumn() 923*cdf0e10cSrcweir { 924*cdf0e10cSrcweir sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); 925*cdf0e10cSrcweir 926*cdf0e10cSrcweir if( nColIdx >= 0 && 927*cdf0e10cSrcweir m_apDataBrowserModel.get()) 928*cdf0e10cSrcweir { 929*cdf0e10cSrcweir // save changes made to edit-field 930*cdf0e10cSrcweir if( IsModified() ) 931*cdf0e10cSrcweir SaveModified(); 932*cdf0e10cSrcweir 933*cdf0e10cSrcweir m_bDataValid = true; 934*cdf0e10cSrcweir m_apDataBrowserModel->removeDataSeriesOrComplexCategoryLevel( nColIdx ); 935*cdf0e10cSrcweir RenewTable(); 936*cdf0e10cSrcweir } 937*cdf0e10cSrcweir } 938*cdf0e10cSrcweir 939*cdf0e10cSrcweir void DataBrowser::InsertRow() 940*cdf0e10cSrcweir { 941*cdf0e10cSrcweir sal_Int32 nRowIdx = lcl_getRowInData( GetCurRow()); 942*cdf0e10cSrcweir 943*cdf0e10cSrcweir if( nRowIdx >= 0 && 944*cdf0e10cSrcweir m_apDataBrowserModel.get()) 945*cdf0e10cSrcweir { 946*cdf0e10cSrcweir // save changes made to edit-field 947*cdf0e10cSrcweir if( IsModified() ) 948*cdf0e10cSrcweir SaveModified(); 949*cdf0e10cSrcweir 950*cdf0e10cSrcweir m_apDataBrowserModel->insertDataPointForAllSeries( nRowIdx ); 951*cdf0e10cSrcweir RenewTable(); 952*cdf0e10cSrcweir } 953*cdf0e10cSrcweir } 954*cdf0e10cSrcweir 955*cdf0e10cSrcweir void DataBrowser::RemoveRow() 956*cdf0e10cSrcweir { 957*cdf0e10cSrcweir sal_Int32 nRowIdx = lcl_getRowInData( GetCurRow()); 958*cdf0e10cSrcweir 959*cdf0e10cSrcweir if( nRowIdx >= 0 && 960*cdf0e10cSrcweir m_apDataBrowserModel.get()) 961*cdf0e10cSrcweir { 962*cdf0e10cSrcweir // save changes made to edit-field 963*cdf0e10cSrcweir if( IsModified() ) 964*cdf0e10cSrcweir SaveModified(); 965*cdf0e10cSrcweir 966*cdf0e10cSrcweir m_bDataValid = true; 967*cdf0e10cSrcweir m_apDataBrowserModel->removeDataPointForAllSeries( nRowIdx ); 968*cdf0e10cSrcweir RenewTable(); 969*cdf0e10cSrcweir } 970*cdf0e10cSrcweir } 971*cdf0e10cSrcweir 972*cdf0e10cSrcweir void DataBrowser::SwapColumn() 973*cdf0e10cSrcweir { 974*cdf0e10cSrcweir sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders ); 975*cdf0e10cSrcweir 976*cdf0e10cSrcweir if( nColIdx >= 0 && 977*cdf0e10cSrcweir m_apDataBrowserModel.get()) 978*cdf0e10cSrcweir { 979*cdf0e10cSrcweir // save changes made to edit-field 980*cdf0e10cSrcweir if( IsModified() ) 981*cdf0e10cSrcweir SaveModified(); 982*cdf0e10cSrcweir 983*cdf0e10cSrcweir m_apDataBrowserModel->swapDataSeries( nColIdx ); 984*cdf0e10cSrcweir 985*cdf0e10cSrcweir // keep cursor in swapped column 986*cdf0e10cSrcweir if( GetCurColumnId() < ColCount() - 1 ) 987*cdf0e10cSrcweir { 988*cdf0e10cSrcweir Dispatch( BROWSER_CURSORRIGHT ); 989*cdf0e10cSrcweir } 990*cdf0e10cSrcweir RenewTable(); 991*cdf0e10cSrcweir } 992*cdf0e10cSrcweir } 993*cdf0e10cSrcweir 994*cdf0e10cSrcweir void DataBrowser::SwapRow() 995*cdf0e10cSrcweir { 996*cdf0e10cSrcweir sal_Int32 nRowIdx = lcl_getRowInData( GetCurRow()); 997*cdf0e10cSrcweir 998*cdf0e10cSrcweir if( nRowIdx >= 0 && 999*cdf0e10cSrcweir m_apDataBrowserModel.get()) 1000*cdf0e10cSrcweir { 1001*cdf0e10cSrcweir // save changes made to edit-field 1002*cdf0e10cSrcweir if( IsModified() ) 1003*cdf0e10cSrcweir SaveModified(); 1004*cdf0e10cSrcweir 1005*cdf0e10cSrcweir m_apDataBrowserModel->swapDataPointForAllSeries( nRowIdx ); 1006*cdf0e10cSrcweir 1007*cdf0e10cSrcweir // keep cursor in swapped row 1008*cdf0e10cSrcweir if( GetCurRow() < GetRowCount() - 1 ) 1009*cdf0e10cSrcweir { 1010*cdf0e10cSrcweir Dispatch( BROWSER_CURSORDOWN ); 1011*cdf0e10cSrcweir } 1012*cdf0e10cSrcweir RenewTable(); 1013*cdf0e10cSrcweir } 1014*cdf0e10cSrcweir } 1015*cdf0e10cSrcweir 1016*cdf0e10cSrcweir void DataBrowser::SetCursorMovedHdl( const Link& rLink ) 1017*cdf0e10cSrcweir { 1018*cdf0e10cSrcweir m_aCursorMovedHdlLink = rLink; 1019*cdf0e10cSrcweir } 1020*cdf0e10cSrcweir 1021*cdf0e10cSrcweir // implementations for ::svt::EditBrowseBox (pure virtual methods) 1022*cdf0e10cSrcweir void DataBrowser::PaintCell( 1023*cdf0e10cSrcweir OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColumnId ) const 1024*cdf0e10cSrcweir { 1025*cdf0e10cSrcweir Point aPos( rRect.TopLeft()); 1026*cdf0e10cSrcweir aPos.X() += 1; 1027*cdf0e10cSrcweir 1028*cdf0e10cSrcweir String aText = GetCellText( m_nSeekRow, nColumnId ); 1029*cdf0e10cSrcweir Size TxtSize( GetDataWindow().GetTextWidth( aText ), GetDataWindow().GetTextHeight()); 1030*cdf0e10cSrcweir 1031*cdf0e10cSrcweir // clipping 1032*cdf0e10cSrcweir if( aPos.X() < rRect.Right() || aPos.X() + TxtSize.Width() > rRect.Right() || 1033*cdf0e10cSrcweir aPos.Y() < rRect.Top() || aPos.Y() + TxtSize.Height() > rRect.Bottom()) 1034*cdf0e10cSrcweir rDev.SetClipRegion( rRect ); 1035*cdf0e10cSrcweir 1036*cdf0e10cSrcweir // allow for a disabled control ... 1037*cdf0e10cSrcweir sal_Bool bEnabled = IsEnabled(); 1038*cdf0e10cSrcweir Color aOriginalColor = rDev.GetTextColor(); 1039*cdf0e10cSrcweir if( ! bEnabled ) 1040*cdf0e10cSrcweir rDev.SetTextColor( GetSettings().GetStyleSettings().GetDisableColor() ); 1041*cdf0e10cSrcweir 1042*cdf0e10cSrcweir // TEST 1043*cdf0e10cSrcweir // if( nColumnId == 1 ) 1044*cdf0e10cSrcweir // // categories 1045*cdf0e10cSrcweir // rDev.SetFillColor( Color( 0xff, 0xff, 0xff )); 1046*cdf0e10cSrcweir // else if( nColumnId == 2 ) 1047*cdf0e10cSrcweir // // x-values 1048*cdf0e10cSrcweir // rDev.SetFillColor( Color( 0xf0, 0xf0, 0xff )); 1049*cdf0e10cSrcweir // else 1050*cdf0e10cSrcweir // // y-values 1051*cdf0e10cSrcweir // rDev.SetFillColor( Color( 0xff, 0xff, 0xf0 )); 1052*cdf0e10cSrcweir 1053*cdf0e10cSrcweir // rDev.DrawRect( rRect ); 1054*cdf0e10cSrcweir 1055*cdf0e10cSrcweir // draw the text 1056*cdf0e10cSrcweir rDev.DrawText( aPos, aText ); 1057*cdf0e10cSrcweir 1058*cdf0e10cSrcweir // reset the color (if necessary) 1059*cdf0e10cSrcweir if( ! bEnabled ) 1060*cdf0e10cSrcweir rDev.SetTextColor( aOriginalColor ); 1061*cdf0e10cSrcweir 1062*cdf0e10cSrcweir if( rDev.IsClipRegion()) 1063*cdf0e10cSrcweir rDev.SetClipRegion(); 1064*cdf0e10cSrcweir } 1065*cdf0e10cSrcweir 1066*cdf0e10cSrcweir sal_Bool DataBrowser::SeekRow( long nRow ) 1067*cdf0e10cSrcweir { 1068*cdf0e10cSrcweir if( ! EditBrowseBox::SeekRow( nRow )) 1069*cdf0e10cSrcweir return sal_False; 1070*cdf0e10cSrcweir 1071*cdf0e10cSrcweir if( nRow < 0 ) 1072*cdf0e10cSrcweir m_nSeekRow = - 1; 1073*cdf0e10cSrcweir else 1074*cdf0e10cSrcweir m_nSeekRow = nRow; 1075*cdf0e10cSrcweir 1076*cdf0e10cSrcweir return sal_True; 1077*cdf0e10cSrcweir } 1078*cdf0e10cSrcweir 1079*cdf0e10cSrcweir sal_Bool DataBrowser::IsTabAllowed( sal_Bool bForward ) const 1080*cdf0e10cSrcweir { 1081*cdf0e10cSrcweir long nRow = GetCurRow(); 1082*cdf0e10cSrcweir long nCol = GetCurColumnId(); 1083*cdf0e10cSrcweir 1084*cdf0e10cSrcweir // column 0 is header-column 1085*cdf0e10cSrcweir long nBadCol = bForward 1086*cdf0e10cSrcweir ? GetColumnCount() - 1 1087*cdf0e10cSrcweir : 1; 1088*cdf0e10cSrcweir long nBadRow = bForward 1089*cdf0e10cSrcweir ? GetRowCount() - 1 1090*cdf0e10cSrcweir : 0; 1091*cdf0e10cSrcweir 1092*cdf0e10cSrcweir if( !m_bDataValid ) 1093*cdf0e10cSrcweir { 1094*cdf0e10cSrcweir const_cast< DataBrowser* >( this )->ShowWarningBox(); 1095*cdf0e10cSrcweir return sal_False; 1096*cdf0e10cSrcweir } 1097*cdf0e10cSrcweir 1098*cdf0e10cSrcweir return ( nRow != nBadRow || 1099*cdf0e10cSrcweir nCol != nBadCol ); 1100*cdf0e10cSrcweir } 1101*cdf0e10cSrcweir 1102*cdf0e10cSrcweir ::svt::CellController* DataBrowser::GetController( long nRow, sal_uInt16 nCol ) 1103*cdf0e10cSrcweir { 1104*cdf0e10cSrcweir if( m_bIsReadOnly ) 1105*cdf0e10cSrcweir return 0; 1106*cdf0e10cSrcweir 1107*cdf0e10cSrcweir if( CellContainsNumbers( nRow, nCol )) 1108*cdf0e10cSrcweir { 1109*cdf0e10cSrcweir m_aNumberEditField.UseInputStringForFormatting(); 1110*cdf0e10cSrcweir m_aNumberEditField.SetFormatKey( GetNumberFormatKey( nRow, nCol )); 1111*cdf0e10cSrcweir return m_rNumberEditController; 1112*cdf0e10cSrcweir } 1113*cdf0e10cSrcweir 1114*cdf0e10cSrcweir return m_rTextEditController; 1115*cdf0e10cSrcweir } 1116*cdf0e10cSrcweir 1117*cdf0e10cSrcweir void DataBrowser::InitController( 1118*cdf0e10cSrcweir ::svt::CellControllerRef& rController, long nRow, sal_uInt16 nCol ) 1119*cdf0e10cSrcweir { 1120*cdf0e10cSrcweir if( rController == m_rTextEditController ) 1121*cdf0e10cSrcweir { 1122*cdf0e10cSrcweir String aText( GetCellText( nRow, nCol ) ); 1123*cdf0e10cSrcweir m_aTextEditField.SetText( aText ); 1124*cdf0e10cSrcweir m_aTextEditField.SetSelection( Selection( 0, aText.Len() )); 1125*cdf0e10cSrcweir } 1126*cdf0e10cSrcweir else if( rController == m_rNumberEditController ) 1127*cdf0e10cSrcweir { 1128*cdf0e10cSrcweir // treat invalid and empty text as Nan 1129*cdf0e10cSrcweir m_aNumberEditField.EnableNotANumber( true ); 1130*cdf0e10cSrcweir if( ::rtl::math::isNan( GetCellNumber( nRow, nCol ))) 1131*cdf0e10cSrcweir m_aNumberEditField.SetTextValue( String()); 1132*cdf0e10cSrcweir else 1133*cdf0e10cSrcweir m_aNumberEditField.SetValue( GetCellNumber( nRow, nCol ) ); 1134*cdf0e10cSrcweir String aText( m_aNumberEditField.GetText()); 1135*cdf0e10cSrcweir m_aNumberEditField.SetSelection( Selection( 0, aText.Len())); 1136*cdf0e10cSrcweir } 1137*cdf0e10cSrcweir else 1138*cdf0e10cSrcweir { 1139*cdf0e10cSrcweir DBG_ERROR( "Invalid Controller" ); 1140*cdf0e10cSrcweir } 1141*cdf0e10cSrcweir } 1142*cdf0e10cSrcweir 1143*cdf0e10cSrcweir bool DataBrowser::CellContainsNumbers( sal_Int32 nRow, sal_uInt16 nCol ) const 1144*cdf0e10cSrcweir { 1145*cdf0e10cSrcweir if( ! m_apDataBrowserModel.get()) 1146*cdf0e10cSrcweir return false; 1147*cdf0e10cSrcweir return (m_apDataBrowserModel->getCellType( lcl_getColumnInData( nCol ), lcl_getRowInData( nRow )) == 1148*cdf0e10cSrcweir DataBrowserModel::NUMBER); 1149*cdf0e10cSrcweir } 1150*cdf0e10cSrcweir 1151*cdf0e10cSrcweir sal_uInt32 DataBrowser::GetNumberFormatKey( sal_Int32 nRow, sal_uInt16 nCol ) const 1152*cdf0e10cSrcweir { 1153*cdf0e10cSrcweir if( ! m_apDataBrowserModel.get()) 1154*cdf0e10cSrcweir return 0; 1155*cdf0e10cSrcweir return m_apDataBrowserModel->getNumberFormatKey( lcl_getColumnInData( nCol ), lcl_getRowInData( nRow )); 1156*cdf0e10cSrcweir } 1157*cdf0e10cSrcweir 1158*cdf0e10cSrcweir bool DataBrowser::isDateString( rtl::OUString aInputString, double& fOutDateValue ) 1159*cdf0e10cSrcweir { 1160*cdf0e10cSrcweir sal_uInt32 nNumberFormat=0; 1161*cdf0e10cSrcweir SvNumberFormatter* pSvNumberFormatter = m_spNumberFormatterWrapper.get() ? m_spNumberFormatterWrapper->getSvNumberFormatter() : 0; 1162*cdf0e10cSrcweir if( aInputString.getLength() > 0 && pSvNumberFormatter && pSvNumberFormatter->IsNumberFormat( aInputString, nNumberFormat, fOutDateValue ) ) 1163*cdf0e10cSrcweir { 1164*cdf0e10cSrcweir Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( m_xChartDoc, uno::UNO_QUERY ); 1165*cdf0e10cSrcweir Reference< util::XNumberFormats > xNumberFormats; 1166*cdf0e10cSrcweir if( xNumberFormatsSupplier.is() ) 1167*cdf0e10cSrcweir xNumberFormats = Reference< util::XNumberFormats >( xNumberFormatsSupplier->getNumberFormats() ); 1168*cdf0e10cSrcweir if( DiagramHelper::isDateNumberFormat( nNumberFormat, xNumberFormats ) ) 1169*cdf0e10cSrcweir return true; 1170*cdf0e10cSrcweir } 1171*cdf0e10cSrcweir return false; 1172*cdf0e10cSrcweir } 1173*cdf0e10cSrcweir 1174*cdf0e10cSrcweir sal_Bool DataBrowser::SaveModified() 1175*cdf0e10cSrcweir { 1176*cdf0e10cSrcweir if( ! IsModified() ) 1177*cdf0e10cSrcweir return sal_True; 1178*cdf0e10cSrcweir 1179*cdf0e10cSrcweir sal_Bool bChangeValid = sal_True; 1180*cdf0e10cSrcweir 1181*cdf0e10cSrcweir const sal_Int32 nRow = lcl_getRowInData( GetCurRow()); 1182*cdf0e10cSrcweir const sal_Int32 nCol = lcl_getColumnInData( GetCurColumnId()); 1183*cdf0e10cSrcweir 1184*cdf0e10cSrcweir DBG_ASSERT( nRow >= 0 || nCol >= 0, "This cell should not be modified!" ); 1185*cdf0e10cSrcweir 1186*cdf0e10cSrcweir SvNumberFormatter* pSvNumberFormatter = m_spNumberFormatterWrapper.get() ? m_spNumberFormatterWrapper->getSvNumberFormatter() : 0; 1187*cdf0e10cSrcweir switch( m_apDataBrowserModel->getCellType( nCol, nRow )) 1188*cdf0e10cSrcweir { 1189*cdf0e10cSrcweir case DataBrowserModel::NUMBER: 1190*cdf0e10cSrcweir { 1191*cdf0e10cSrcweir sal_uInt32 nDummy = 0; 1192*cdf0e10cSrcweir double fDummy = 0.0; 1193*cdf0e10cSrcweir String aText( m_aNumberEditField.GetText()); 1194*cdf0e10cSrcweir // an empty string is valid, if no numberformatter exists, all 1195*cdf0e10cSrcweir // values are treated as valid 1196*cdf0e10cSrcweir if( aText.Len() > 0 && pSvNumberFormatter && 1197*cdf0e10cSrcweir ! pSvNumberFormatter->IsNumberFormat( aText, nDummy, fDummy ) ) 1198*cdf0e10cSrcweir { 1199*cdf0e10cSrcweir bChangeValid = sal_False; 1200*cdf0e10cSrcweir } 1201*cdf0e10cSrcweir else 1202*cdf0e10cSrcweir { 1203*cdf0e10cSrcweir double fData = m_aNumberEditField.GetValue(); 1204*cdf0e10cSrcweir bChangeValid = m_apDataBrowserModel->setCellNumber( nCol, nRow, fData ); 1205*cdf0e10cSrcweir } 1206*cdf0e10cSrcweir } 1207*cdf0e10cSrcweir break; 1208*cdf0e10cSrcweir case DataBrowserModel::TEXTORDATE: 1209*cdf0e10cSrcweir { 1210*cdf0e10cSrcweir OUString aText( m_aTextEditField.GetText() ); 1211*cdf0e10cSrcweir double fDateValue=0.0; 1212*cdf0e10cSrcweir bChangeValid = sal_False; 1213*cdf0e10cSrcweir if( isDateString( aText, fDateValue ) ) 1214*cdf0e10cSrcweir bChangeValid = m_apDataBrowserModel->setCellAny( nCol, nRow, uno::makeAny( fDateValue ) ); 1215*cdf0e10cSrcweir if(!bChangeValid) 1216*cdf0e10cSrcweir bChangeValid = m_apDataBrowserModel->setCellAny( nCol, nRow, uno::makeAny( aText ) ); 1217*cdf0e10cSrcweir } 1218*cdf0e10cSrcweir break; 1219*cdf0e10cSrcweir case DataBrowserModel::TEXT: 1220*cdf0e10cSrcweir { 1221*cdf0e10cSrcweir OUString aText( m_aTextEditField.GetText()); 1222*cdf0e10cSrcweir bChangeValid = m_apDataBrowserModel->setCellText( nCol, nRow, aText ); 1223*cdf0e10cSrcweir } 1224*cdf0e10cSrcweir break; 1225*cdf0e10cSrcweir } 1226*cdf0e10cSrcweir 1227*cdf0e10cSrcweir // the first valid change changes this to true 1228*cdf0e10cSrcweir if( bChangeValid ) 1229*cdf0e10cSrcweir { 1230*cdf0e10cSrcweir RowModified( GetCurRow(), GetCurColumnId()); 1231*cdf0e10cSrcweir ::svt::CellController* pCtrl = GetController( GetCurRow(), GetCurColumnId()); 1232*cdf0e10cSrcweir if( pCtrl ) 1233*cdf0e10cSrcweir pCtrl->ClearModified(); 1234*cdf0e10cSrcweir SetDirty(); 1235*cdf0e10cSrcweir } 1236*cdf0e10cSrcweir 1237*cdf0e10cSrcweir return bChangeValid; 1238*cdf0e10cSrcweir } 1239*cdf0e10cSrcweir 1240*cdf0e10cSrcweir bool DataBrowser::EndEditing() 1241*cdf0e10cSrcweir { 1242*cdf0e10cSrcweir if( IsModified()) 1243*cdf0e10cSrcweir SaveModified(); 1244*cdf0e10cSrcweir 1245*cdf0e10cSrcweir // apply changes made to series headers 1246*cdf0e10cSrcweir ::std::for_each( m_aSeriesHeaders.begin(), m_aSeriesHeaders.end(), impl::applyChangesFunctor()); 1247*cdf0e10cSrcweir 1248*cdf0e10cSrcweir if( m_bDataValid ) 1249*cdf0e10cSrcweir return true; 1250*cdf0e10cSrcweir else 1251*cdf0e10cSrcweir return ShowQueryBox(); 1252*cdf0e10cSrcweir } 1253*cdf0e10cSrcweir 1254*cdf0e10cSrcweir sal_Int16 DataBrowser::GetFirstVisibleColumNumber() const 1255*cdf0e10cSrcweir { 1256*cdf0e10cSrcweir return GetFirstVisibleColNumber(); 1257*cdf0e10cSrcweir } 1258*cdf0e10cSrcweir 1259*cdf0e10cSrcweir void DataBrowser::ColumnResized( sal_uInt16 nColId ) 1260*cdf0e10cSrcweir { 1261*cdf0e10cSrcweir sal_Bool bLastUpdateMode = GetUpdateMode(); 1262*cdf0e10cSrcweir SetUpdateMode( sal_False ); 1263*cdf0e10cSrcweir 1264*cdf0e10cSrcweir EditBrowseBox::ColumnResized( nColId ); 1265*cdf0e10cSrcweir ImplAdjustHeaderControls(); 1266*cdf0e10cSrcweir SetUpdateMode( bLastUpdateMode ); 1267*cdf0e10cSrcweir } 1268*cdf0e10cSrcweir 1269*cdf0e10cSrcweir // virtual void MouseMove( const MouseEvent& rEvt ); 1270*cdf0e10cSrcweir 1271*cdf0e10cSrcweir void DataBrowser::EndScroll() 1272*cdf0e10cSrcweir { 1273*cdf0e10cSrcweir sal_Bool bLastUpdateMode = GetUpdateMode(); 1274*cdf0e10cSrcweir SetUpdateMode( sal_False ); 1275*cdf0e10cSrcweir 1276*cdf0e10cSrcweir EditBrowseBox::EndScroll(); 1277*cdf0e10cSrcweir RenewSeriesHeaders(); 1278*cdf0e10cSrcweir 1279*cdf0e10cSrcweir SetUpdateMode( bLastUpdateMode ); 1280*cdf0e10cSrcweir } 1281*cdf0e10cSrcweir 1282*cdf0e10cSrcweir void DataBrowser::RenewSeriesHeaders() 1283*cdf0e10cSrcweir { 1284*cdf0e10cSrcweir Window * pWin = this->GetParent(); 1285*cdf0e10cSrcweir if( !pWin ) 1286*cdf0e10cSrcweir pWin = this; 1287*cdf0e10cSrcweir 1288*cdf0e10cSrcweir clearHeaders(); 1289*cdf0e10cSrcweir DataBrowserModel::tDataHeaderVector aHeaders( m_apDataBrowserModel->getDataHeaders()); 1290*cdf0e10cSrcweir Link aFocusLink( LINK( this, DataBrowser, SeriesHeaderGotFocus )); 1291*cdf0e10cSrcweir Link aSeriesHeaderChangedLink( LINK( this, DataBrowser, SeriesHeaderChanged )); 1292*cdf0e10cSrcweir bool bIsHighContrast = pWin ? (pWin->GetSettings().GetStyleSettings().GetHighContrastMode()) : false; 1293*cdf0e10cSrcweir 1294*cdf0e10cSrcweir for( DataBrowserModel::tDataHeaderVector::const_iterator aIt( aHeaders.begin()); 1295*cdf0e10cSrcweir aIt != aHeaders.end(); ++aIt ) 1296*cdf0e10cSrcweir { 1297*cdf0e10cSrcweir ::boost::shared_ptr< impl::SeriesHeader > spHeader( new impl::SeriesHeader( pWin )); 1298*cdf0e10cSrcweir Reference< beans::XPropertySet > xSeriesProp( aIt->m_xDataSeries, uno::UNO_QUERY ); 1299*cdf0e10cSrcweir sal_Int32 nColor = 0; 1300*cdf0e10cSrcweir if( xSeriesProp.is() && 1301*cdf0e10cSrcweir ( xSeriesProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Color"))) >>= nColor )) 1302*cdf0e10cSrcweir spHeader->SetColor( Color( nColor )); 1303*cdf0e10cSrcweir spHeader->SetChartType( aIt->m_xChartType, aIt->m_bSwapXAndYAxis, bIsHighContrast ); 1304*cdf0e10cSrcweir spHeader->SetSeriesName( 1305*cdf0e10cSrcweir String( DataSeriesHelper::getDataSeriesLabel( 1306*cdf0e10cSrcweir aIt->m_xDataSeries, 1307*cdf0e10cSrcweir (aIt->m_xChartType.is() ? 1308*cdf0e10cSrcweir aIt->m_xChartType->getRoleOfSequenceForSeriesLabel() : 1309*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("values-y")))))); 1310*cdf0e10cSrcweir spHeader->SetRange( aIt->m_nStartColumn + 1, aIt->m_nEndColumn + 1 ); 1311*cdf0e10cSrcweir spHeader->SetGetFocusHdl( aFocusLink ); 1312*cdf0e10cSrcweir spHeader->SetEditChangedHdl( aSeriesHeaderChangedLink ); 1313*cdf0e10cSrcweir m_aSeriesHeaders.push_back( spHeader ); 1314*cdf0e10cSrcweir } 1315*cdf0e10cSrcweir 1316*cdf0e10cSrcweir ImplAdjustHeaderControls(); 1317*cdf0e10cSrcweir } 1318*cdf0e10cSrcweir 1319*cdf0e10cSrcweir void DataBrowser::ImplAdjustHeaderControls() 1320*cdf0e10cSrcweir { 1321*cdf0e10cSrcweir sal_uInt16 nColCount = this->GetColumnCount(); 1322*cdf0e10cSrcweir sal_uInt32 nCurrentPos = this->GetPosPixel().getX(); 1323*cdf0e10cSrcweir sal_uInt32 nMaxPos = nCurrentPos + this->GetOutputSizePixel().getWidth(); 1324*cdf0e10cSrcweir sal_uInt32 nStartPos = nCurrentPos; 1325*cdf0e10cSrcweir 1326*cdf0e10cSrcweir // width of header column 1327*cdf0e10cSrcweir nCurrentPos += this->GetColumnWidth( 0 ); 1328*cdf0e10cSrcweir tSeriesHeaderContainer::iterator aIt( m_aSeriesHeaders.begin()); 1329*cdf0e10cSrcweir sal_uInt16 i = this->GetFirstVisibleColumNumber(); 1330*cdf0e10cSrcweir while( (aIt != m_aSeriesHeaders.end()) && ((*aIt)->GetStartColumn() < i) ) 1331*cdf0e10cSrcweir ++aIt; 1332*cdf0e10cSrcweir for( ; i < nColCount && aIt != m_aSeriesHeaders.end(); ++i ) 1333*cdf0e10cSrcweir { 1334*cdf0e10cSrcweir if( (*aIt)->GetStartColumn() == i ) 1335*cdf0e10cSrcweir nStartPos = nCurrentPos; 1336*cdf0e10cSrcweir 1337*cdf0e10cSrcweir nCurrentPos += (this->GetColumnWidth( i )); 1338*cdf0e10cSrcweir 1339*cdf0e10cSrcweir if( (*aIt)->GetEndColumn() == i ) 1340*cdf0e10cSrcweir { 1341*cdf0e10cSrcweir if( nStartPos < nMaxPos ) 1342*cdf0e10cSrcweir { 1343*cdf0e10cSrcweir (*aIt)->SetPixelPosX( nStartPos + 2 ); 1344*cdf0e10cSrcweir (*aIt)->SetPixelWidth( nCurrentPos - nStartPos - 3 ); 1345*cdf0e10cSrcweir } 1346*cdf0e10cSrcweir else 1347*cdf0e10cSrcweir // do not hide, to get focus events. Move outside the dialog for "hiding" 1348*cdf0e10cSrcweir (*aIt)->SetPixelPosX( nMaxPos + 42 ); 1349*cdf0e10cSrcweir ++aIt; 1350*cdf0e10cSrcweir } 1351*cdf0e10cSrcweir } 1352*cdf0e10cSrcweir } 1353*cdf0e10cSrcweir 1354*cdf0e10cSrcweir IMPL_LINK( DataBrowser, SeriesHeaderGotFocus, impl::SeriesHeaderEdit*, pEdit ) 1355*cdf0e10cSrcweir { 1356*cdf0e10cSrcweir if( pEdit ) 1357*cdf0e10cSrcweir { 1358*cdf0e10cSrcweir pEdit->SetShowWarningBox( !m_bDataValid ); 1359*cdf0e10cSrcweir 1360*cdf0e10cSrcweir if( !m_bDataValid ) 1361*cdf0e10cSrcweir GoToCell( 0, 0 ); 1362*cdf0e10cSrcweir else 1363*cdf0e10cSrcweir { 1364*cdf0e10cSrcweir //DeactivateCell(); 1365*cdf0e10cSrcweir MakeFieldVisible( GetCurRow(), static_cast< sal_uInt16 >( pEdit->getStartColumn()), true /* bComplete */ ); 1366*cdf0e10cSrcweir ActivateCell(); 1367*cdf0e10cSrcweir m_aCursorMovedHdlLink.Call( this ); 1368*cdf0e10cSrcweir } 1369*cdf0e10cSrcweir } 1370*cdf0e10cSrcweir return 0; 1371*cdf0e10cSrcweir } 1372*cdf0e10cSrcweir 1373*cdf0e10cSrcweir IMPL_LINK( DataBrowser, SeriesHeaderChanged, impl::SeriesHeaderEdit*, pEdit ) 1374*cdf0e10cSrcweir { 1375*cdf0e10cSrcweir if( pEdit ) 1376*cdf0e10cSrcweir { 1377*cdf0e10cSrcweir Reference< chart2::XDataSeries > xSeries( 1378*cdf0e10cSrcweir m_apDataBrowserModel->getDataSeriesByColumn( pEdit->getStartColumn() - 1 )); 1379*cdf0e10cSrcweir Reference< chart2::data::XDataSource > xSource( xSeries, uno::UNO_QUERY ); 1380*cdf0e10cSrcweir if( xSource.is()) 1381*cdf0e10cSrcweir { 1382*cdf0e10cSrcweir Reference< chart2::XChartType > xChartType( 1383*cdf0e10cSrcweir m_apDataBrowserModel->getHeaderForSeries( xSeries ).m_xChartType ); 1384*cdf0e10cSrcweir if( xChartType.is()) 1385*cdf0e10cSrcweir { 1386*cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > xLabeledSeq( 1387*cdf0e10cSrcweir DataSeriesHelper::getDataSequenceByRole( xSource, xChartType->getRoleOfSequenceForSeriesLabel())); 1388*cdf0e10cSrcweir if( xLabeledSeq.is()) 1389*cdf0e10cSrcweir { 1390*cdf0e10cSrcweir Reference< container::XIndexReplace > xIndexReplace( xLabeledSeq->getLabel(), uno::UNO_QUERY ); 1391*cdf0e10cSrcweir if( xIndexReplace.is()) 1392*cdf0e10cSrcweir xIndexReplace->replaceByIndex( 1393*cdf0e10cSrcweir 0, uno::makeAny( OUString( pEdit->GetText()))); 1394*cdf0e10cSrcweir } 1395*cdf0e10cSrcweir } 1396*cdf0e10cSrcweir } 1397*cdf0e10cSrcweir } 1398*cdf0e10cSrcweir return 0; 1399*cdf0e10cSrcweir } 1400*cdf0e10cSrcweir 1401*cdf0e10cSrcweir sal_Int32 DataBrowser::GetTotalWidth() const 1402*cdf0e10cSrcweir { 1403*cdf0e10cSrcweir sal_uLong nWidth = 0; 1404*cdf0e10cSrcweir for ( sal_uInt16 nCol = 0; nCol < ColCount(); ++nCol ) 1405*cdf0e10cSrcweir nWidth += GetColumnWidth( nCol ); 1406*cdf0e10cSrcweir return static_cast< sal_Int32 >( nWidth ); 1407*cdf0e10cSrcweir } 1408*cdf0e10cSrcweir 1409*cdf0e10cSrcweir } // namespace chart 1410