1*cde9e8dcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*cde9e8dcSAndrew Rist * distributed with this work for additional information 6*cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance 9*cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at 10*cde9e8dcSAndrew Rist * 11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*cde9e8dcSAndrew Rist * 13*cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*cde9e8dcSAndrew Rist * software distributed under the License is distributed on an 15*cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the 17*cde9e8dcSAndrew Rist * specific language governing permissions and limitations 18*cde9e8dcSAndrew Rist * under the License. 19*cde9e8dcSAndrew Rist * 20*cde9e8dcSAndrew Rist *************************************************************/ 21*cde9e8dcSAndrew Rist 22*cde9e8dcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_chart2.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "dlg_DataEditor.hxx" 28cdf0e10cSrcweir #include "dlg_DataEditor.hrc" 29cdf0e10cSrcweir #include "Strings.hrc" 30cdf0e10cSrcweir #include "DataBrowser.hxx" 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include "ResId.hxx" 33cdf0e10cSrcweir #include "Strings.hrc" 34cdf0e10cSrcweir #include "SchSlotIds.hxx" 35cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 36cdf0e10cSrcweir #include <vcl/msgbox.hxx> 37cdf0e10cSrcweir #include <vcl/taskpanelist.hxx> 38cdf0e10cSrcweir #include <svtools/miscopt.hxx> 39cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir // for SfxBoolItem 42cdf0e10cSrcweir #include <svl/eitem.hxx> 43cdf0e10cSrcweir 44cdf0e10cSrcweir #include <vcl/edit.hxx> 45cdf0e10cSrcweir 46cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp> 47cdf0e10cSrcweir #include <com/sun/star/chart2/XChartDocument.hpp> 48cdf0e10cSrcweir 49cdf0e10cSrcweir // for storing/reading the position and size of the dialog 50cdf0e10cSrcweir // #include <svtools/viewoptions.hxx> 51cdf0e10cSrcweir 52cdf0e10cSrcweir using namespace ::com::sun::star; 53cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 54cdf0e10cSrcweir using ::rtl::OUString; 55cdf0e10cSrcweir 56cdf0e10cSrcweir 57cdf0e10cSrcweir namespace chart 58cdf0e10cSrcweir { 59cdf0e10cSrcweir 60cdf0e10cSrcweir DataEditor::DataEditor( 61cdf0e10cSrcweir Window* pParent, 62cdf0e10cSrcweir const Reference< chart2::XChartDocument > & xChartDoc, 63cdf0e10cSrcweir const Reference< uno::XComponentContext > & xContext ) : 64cdf0e10cSrcweir ModalDialog( pParent, SchResId( DLG_DIAGRAM_DATA )), 65cdf0e10cSrcweir m_bReadOnly( false ), 66cdf0e10cSrcweir m_apBrwData( new DataBrowser( this, SchResId( CTL_DATA ), true /* bLiveUpdate */)), 67cdf0e10cSrcweir m_aTbxData( this, SchResId( TBX_DATA )), 68cdf0e10cSrcweir m_xChartDoc( xChartDoc ), 69cdf0e10cSrcweir m_xContext( xContext ), 70cdf0e10cSrcweir m_aToolboxImageList( SchResId( IL_DIAGRAM_DATA )), 71cdf0e10cSrcweir m_aToolboxImageListHighContrast( SchResId( IL_HC_DIAGRAM_DATA )) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir FreeResource(); 74cdf0e10cSrcweir 75cdf0e10cSrcweir // set min size to current size 76cdf0e10cSrcweir SetMinOutputSizePixel( GetOutputSizePixel() ); 77cdf0e10cSrcweir 78cdf0e10cSrcweir ApplyImageList(); 79cdf0e10cSrcweir 80cdf0e10cSrcweir m_aTbxData.SetSizePixel( m_aTbxData.CalcWindowSizePixel() ); 81cdf0e10cSrcweir m_aTbxData.SetSelectHdl( LINK( this, DataEditor, ToolboxHdl )); 82cdf0e10cSrcweir 83cdf0e10cSrcweir m_apBrwData->SetCursorMovedHdl( LINK( this, DataEditor, BrowserCursorMovedHdl )); 84cdf0e10cSrcweir m_apBrwData->SetCellModifiedHdl( LINK( this, DataEditor, CellModified )); 85cdf0e10cSrcweir 86cdf0e10cSrcweir UpdateData(); 87cdf0e10cSrcweir GrabFocus(); 88cdf0e10cSrcweir m_apBrwData->GrabFocus(); 89cdf0e10cSrcweir 90cdf0e10cSrcweir bool bReadOnly = true; 91cdf0e10cSrcweir Reference< frame::XStorable > xStor( m_xChartDoc, uno::UNO_QUERY ); 92cdf0e10cSrcweir if( xStor.is()) 93cdf0e10cSrcweir bReadOnly = xStor->isReadonly(); 94cdf0e10cSrcweir SetReadOnly( bReadOnly ); 95cdf0e10cSrcweir 96cdf0e10cSrcweir // #101228# change buttons to flat-look if set so by user 97cdf0e10cSrcweir SvtMiscOptions aMiscOptions; 98cdf0e10cSrcweir const sal_Int16 nStyle( aMiscOptions.GetToolboxStyle() ); 99cdf0e10cSrcweir // react on changes 100cdf0e10cSrcweir aMiscOptions.AddListenerLink( LINK( this, DataEditor, MiscHdl ) ); 101cdf0e10cSrcweir m_aTbxData.SetOutStyle( nStyle ); 102cdf0e10cSrcweir 103cdf0e10cSrcweir // set good window width 104cdf0e10cSrcweir Size aWinSize( GetOutputSizePixel()); 105cdf0e10cSrcweir Size aWinSizeWithBorder( GetSizePixel()); 106cdf0e10cSrcweir Point aWinPos( OutputToAbsoluteScreenPixel( GetPosPixel())); 107cdf0e10cSrcweir sal_Int32 nMinWidth = aWinSize.getWidth(); 108cdf0e10cSrcweir sal_Int32 nMaxWidth = GetDesktopRectPixel().getWidth() - 109cdf0e10cSrcweir (aWinSizeWithBorder.getWidth() - aWinSize.getWidth() + aWinPos.getX()) - 10; // leave some space 110cdf0e10cSrcweir sal_Int32 nBrowserWidth = m_apBrwData->GetTotalWidth() + 12 + 16; // plus padding + 16? 111cdf0e10cSrcweir sal_Int32 nWindowWidth = ::std::max( nMinWidth, nBrowserWidth ); 112cdf0e10cSrcweir nWindowWidth = ::std::min( nMaxWidth, nBrowserWidth ); 113cdf0e10cSrcweir aWinSize.setWidth( nWindowWidth ); 114cdf0e10cSrcweir SetOutputSizePixel( aWinSize ); 115cdf0e10cSrcweir AdaptBrowseBoxSize(); 116cdf0e10cSrcweir 117cdf0e10cSrcweir // ImplAdjustHeaderControls( false /* bRefreshFromModel */ ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir // allow travelling to toolbar with F6 120cdf0e10cSrcweir notifySystemWindow( this, & m_aTbxData, ::comphelper::mem_fun( & TaskPaneList::AddWindow )); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir DataEditor::~DataEditor() 124cdf0e10cSrcweir { 125cdf0e10cSrcweir notifySystemWindow( this, & m_aTbxData, ::comphelper::mem_fun( & TaskPaneList::RemoveWindow )); 126cdf0e10cSrcweir 127cdf0e10cSrcweir SvtMiscOptions aMiscOptions; 128cdf0e10cSrcweir aMiscOptions.RemoveListenerLink( LINK( this, DataEditor, MiscHdl ) ); 129cdf0e10cSrcweir 130cdf0e10cSrcweir OSL_TRACE( "DataEditor: DTOR" ); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir 133cdf0e10cSrcweir // react on click (or keypress) on toolbar icon 134cdf0e10cSrcweir IMPL_LINK( DataEditor, ToolboxHdl, void *, EMPTYARG ) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir switch( m_aTbxData.GetCurItemId() ) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir case TBI_DATA_INSERT_ROW: 139cdf0e10cSrcweir m_apBrwData->InsertRow(); 140cdf0e10cSrcweir break; 141cdf0e10cSrcweir case TBI_DATA_INSERT_COL: 142cdf0e10cSrcweir m_apBrwData->InsertColumn(); 143cdf0e10cSrcweir break; 144cdf0e10cSrcweir case TBI_DATA_INSERT_TEXT_COL: 145cdf0e10cSrcweir m_apBrwData->InsertTextColumn(); 146cdf0e10cSrcweir break; 147cdf0e10cSrcweir case TBI_DATA_DELETE_ROW: 148cdf0e10cSrcweir m_apBrwData->RemoveRow(); 149cdf0e10cSrcweir break; 150cdf0e10cSrcweir case TBI_DATA_DELETE_COL: 151cdf0e10cSrcweir m_apBrwData->RemoveColumn(); 152cdf0e10cSrcweir break; 153cdf0e10cSrcweir case TBI_DATA_SWAP_COL : 154cdf0e10cSrcweir m_apBrwData->SwapColumn (); 155cdf0e10cSrcweir break; 156cdf0e10cSrcweir case TBI_DATA_SWAP_ROW : 157cdf0e10cSrcweir m_apBrwData->SwapRow (); 158cdf0e10cSrcweir break; 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir return 0; 162cdf0e10cSrcweir } 163cdf0e10cSrcweir 164cdf0e10cSrcweir // refresh toolbar icons according to currently selected cell in brwose box 165cdf0e10cSrcweir IMPL_LINK( DataEditor, BrowserCursorMovedHdl, void *, EMPTYARG ) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir if( m_bReadOnly ) 168cdf0e10cSrcweir return 0; 169cdf0e10cSrcweir 170cdf0e10cSrcweir bool bIsDataValid = m_apBrwData->IsEnableItem(); 171cdf0e10cSrcweir 172cdf0e10cSrcweir m_aTbxData.EnableItem( TBI_DATA_INSERT_ROW, bIsDataValid && m_apBrwData->MayInsertRow() ); 173cdf0e10cSrcweir m_aTbxData.EnableItem( TBI_DATA_INSERT_COL, bIsDataValid && m_apBrwData->MayInsertColumn() ); 174cdf0e10cSrcweir m_aTbxData.EnableItem( TBI_DATA_INSERT_TEXT_COL, bIsDataValid && m_apBrwData->MayInsertColumn() ); 175cdf0e10cSrcweir m_aTbxData.EnableItem( TBI_DATA_DELETE_ROW, m_apBrwData->MayDeleteRow() ); 176cdf0e10cSrcweir m_aTbxData.EnableItem( TBI_DATA_DELETE_COL, m_apBrwData->MayDeleteColumn() ); 177cdf0e10cSrcweir 178cdf0e10cSrcweir m_aTbxData.EnableItem( TBI_DATA_SWAP_COL, bIsDataValid && m_apBrwData->MaySwapColumns() ); 179cdf0e10cSrcweir m_aTbxData.EnableItem( TBI_DATA_SWAP_ROW, bIsDataValid && m_apBrwData->MaySwapRows() ); 180cdf0e10cSrcweir 181cdf0e10cSrcweir return 0; 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir // disable all modifying controls 185cdf0e10cSrcweir void DataEditor::SetReadOnly( bool bReadOnly ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir m_bReadOnly = bReadOnly; 188cdf0e10cSrcweir if( m_bReadOnly ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir m_aTbxData.EnableItem( TBI_DATA_INSERT_ROW, sal_False ); 191cdf0e10cSrcweir m_aTbxData.EnableItem( TBI_DATA_INSERT_COL, sal_False ); 192cdf0e10cSrcweir m_aTbxData.EnableItem( TBI_DATA_INSERT_TEXT_COL, sal_False ); 193cdf0e10cSrcweir m_aTbxData.EnableItem( TBI_DATA_DELETE_ROW, sal_False ); 194cdf0e10cSrcweir m_aTbxData.EnableItem( TBI_DATA_DELETE_COL, sal_False ); 195cdf0e10cSrcweir m_aTbxData.EnableItem( TBI_DATA_SWAP_COL, sal_False ); 196cdf0e10cSrcweir m_aTbxData.EnableItem( TBI_DATA_SWAP_ROW, sal_False ); 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir m_apBrwData->SetReadOnly( m_bReadOnly ); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir IMPL_LINK( DataEditor, MiscHdl, void*, EMPTYARG ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir SvtMiscOptions aMiscOptions; 205cdf0e10cSrcweir sal_Int16 nStyle( aMiscOptions.GetToolboxStyle() ); 206cdf0e10cSrcweir 207cdf0e10cSrcweir m_aTbxData.SetOutStyle( nStyle ); 208cdf0e10cSrcweir 209cdf0e10cSrcweir return 0L; 210cdf0e10cSrcweir } 211cdf0e10cSrcweir 212cdf0e10cSrcweir IMPL_LINK( DataEditor, CellModified, void*, EMPTYARG ) 213cdf0e10cSrcweir { 214cdf0e10cSrcweir return 0; 215cdf0e10cSrcweir } 216cdf0e10cSrcweir 217cdf0e10cSrcweir // IMPL_LINK( DataEditor, BrowserColumnResized, void*, EMPTYARG ) 218cdf0e10cSrcweir // { 219cdf0e10cSrcweir // ImplAdjustHeaderControls( false /* bRefreshFromModel */ ); 220cdf0e10cSrcweir // return 0; 221cdf0e10cSrcweir // } 222cdf0e10cSrcweir 223cdf0e10cSrcweir // IMPL_LINK( DataEditor, BrowserContentScrolled, void*, EMPTYARG ) 224cdf0e10cSrcweir // { 225cdf0e10cSrcweir // ImplAdjustHeaderControls( false /* bRefreshFromModel */ ); 226cdf0e10cSrcweir // return 0; 227cdf0e10cSrcweir // } 228cdf0e10cSrcweir 229cdf0e10cSrcweir void DataEditor::UpdateData() 230cdf0e10cSrcweir { 231cdf0e10cSrcweir m_apBrwData->SetDataFromModel( m_xChartDoc, m_xContext ); 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir // react on the change of the underlying document by displaying the new data 235cdf0e10cSrcweir // void DataEditor::SFX_NOTIFY( 236cdf0e10cSrcweir // SfxBroadcaster& rBC, 237cdf0e10cSrcweir // const TypeId& rBCType, 238cdf0e10cSrcweir // const SfxHint& rHint, 239cdf0e10cSrcweir // const TypeId& rHintType ) 240cdf0e10cSrcweir // { 241cdf0e10cSrcweir // if( rHint.Type() == TYPE(SfxSimpleHint) ) 242cdf0e10cSrcweir // { 243cdf0e10cSrcweir // // note: if dynamic_cast works this should be changed 244cdf0e10cSrcweir // switch( static_cast< const SfxSimpleHint & >( rHint ).GetId()) 245cdf0e10cSrcweir // { 246cdf0e10cSrcweir // case SFX_HINT_DOCCHANGED: 247cdf0e10cSrcweir // UpdateData(); 248cdf0e10cSrcweir // break; 249cdf0e10cSrcweir 250cdf0e10cSrcweir // case SFX_HINT_DYING: 251cdf0e10cSrcweir // break; 252cdf0e10cSrcweir // } 253cdf0e10cSrcweir // } 254cdf0e10cSrcweir // } 255cdf0e10cSrcweir 256cdf0e10cSrcweir // { 257cdf0e10cSrcweir // sal_Bool bRet = sal_True; 258cdf0e10cSrcweir 259cdf0e10cSrcweir // // confirm changes currently made and not saved 260cdf0e10cSrcweir // m_apBrwData->EndEditing(); 261cdf0e10cSrcweir 262cdf0e10cSrcweir // if( m_apBrwData->IsDirty() ) 263cdf0e10cSrcweir // { 264cdf0e10cSrcweir // QueryBox aSafetyQuery( this, WB_YES_NO_CANCEL | WB_DEF_YES, 265cdf0e10cSrcweir // String( SchResId( STR_DIAGRAM_DATA_SAFETY_QUERY ))); 266cdf0e10cSrcweir // long nQueryResult = aSafetyQuery.Execute(); 267cdf0e10cSrcweir 268cdf0e10cSrcweir // bRet = ( nQueryResult != RET_CANCEL ); 269cdf0e10cSrcweir 270cdf0e10cSrcweir // if( nQueryResult == RET_YES ) 271cdf0e10cSrcweir // { 272cdf0e10cSrcweir // // save changes 273cdf0e10cSrcweir // ApplyChangesToModel(); 274cdf0e10cSrcweir // } 275cdf0e10cSrcweir // } 276cdf0e10cSrcweir 277cdf0e10cSrcweir // if( bRet ) 278cdf0e10cSrcweir // { 279cdf0e10cSrcweir // // close child window 280cdf0e10cSrcweir // SfxBoolItem aItem( SID_DIAGRAM_DATA, sal_False ); 281cdf0e10cSrcweir // if( m_pBindings ) 282cdf0e10cSrcweir // { 283cdf0e10cSrcweir // SfxDispatcher* pDisp = m_pBindings->GetDispatcher(); 284cdf0e10cSrcweir // if( pDisp ) 285cdf0e10cSrcweir // pDisp->Execute( SID_DIAGRAM_DATA, SFX_CALLMODE_ASYNCHRON, &aItem, 0L); 286cdf0e10cSrcweir // else 287cdf0e10cSrcweir // DBG_ERROR( "Couldn't dispatch command" ); 288cdf0e10cSrcweir // } 289cdf0e10cSrcweir // } 290cdf0e10cSrcweir 291cdf0e10cSrcweir // return ( bRet? SfxFloatingWindow::Close(): sal_False ); 292cdf0e10cSrcweir // } 293cdf0e10cSrcweir 294cdf0e10cSrcweir void DataEditor::AdaptBrowseBoxSize() 295cdf0e10cSrcweir { 296cdf0e10cSrcweir Size aSize( PixelToLogic( GetResizeOutputSizePixel(), MAP_APPFONT )); 297cdf0e10cSrcweir Size aDataSize; 298cdf0e10cSrcweir 299cdf0e10cSrcweir aDataSize.setWidth( aSize.getWidth() - 12 ); 300cdf0e10cSrcweir aDataSize.setHeight( aSize.getHeight() - 31 -24 ); 301cdf0e10cSrcweir 302cdf0e10cSrcweir m_apBrwData->SetSizePixel( LogicToPixel( aDataSize, MAP_APPFONT )); 303cdf0e10cSrcweir } 304cdf0e10cSrcweir 305cdf0e10cSrcweir void DataEditor::Resize() 306cdf0e10cSrcweir { 307cdf0e10cSrcweir Dialog::Resize(); 308cdf0e10cSrcweir AdaptBrowseBoxSize(); 309cdf0e10cSrcweir // ImplAdjustHeaderControls( false /* bRefreshFromModel */ ); 310cdf0e10cSrcweir } 311cdf0e10cSrcweir 312cdf0e10cSrcweir sal_Bool DataEditor::Close() 313cdf0e10cSrcweir { 314cdf0e10cSrcweir if( ApplyChangesToModel() ) 315cdf0e10cSrcweir return ModalDialog::Close(); 316cdf0e10cSrcweir else 317cdf0e10cSrcweir return sal_True; 318cdf0e10cSrcweir } 319cdf0e10cSrcweir 320cdf0e10cSrcweir bool DataEditor::ApplyChangesToModel() 321cdf0e10cSrcweir { 322cdf0e10cSrcweir return m_apBrwData->EndEditing(); 323cdf0e10cSrcweir } 324cdf0e10cSrcweir 325cdf0e10cSrcweir // sets the correct toolbar icons depending on the current mode (e.g. high contrast) 326cdf0e10cSrcweir void DataEditor::ApplyImageList() 327cdf0e10cSrcweir { 328cdf0e10cSrcweir bool bIsHighContrast = ( true && GetSettings().GetStyleSettings().GetHighContrastMode() ); 329cdf0e10cSrcweir 330cdf0e10cSrcweir ImageList& rImgLst = bIsHighContrast 331cdf0e10cSrcweir ? m_aToolboxImageListHighContrast 332cdf0e10cSrcweir : m_aToolboxImageList; 333cdf0e10cSrcweir 334cdf0e10cSrcweir m_aTbxData.SetImageList( rImgLst ); 335cdf0e10cSrcweir } 336cdf0e10cSrcweir 337cdf0e10cSrcweir // add/remove a window (the toolbar) to/from the global list, so that F6 338cdf0e10cSrcweir // travels/no longer travels over this window. _rMemFunc may be 339cdf0e10cSrcweir // TaskPaneList::AddWindow or TaskPaneList::RemoveWindow 340cdf0e10cSrcweir void DataEditor::notifySystemWindow( 341cdf0e10cSrcweir Window* pWindow, Window* pToRegister, 342cdf0e10cSrcweir ::comphelper::mem_fun1_t< TaskPaneList, Window* > rMemFunc ) 343cdf0e10cSrcweir { 344cdf0e10cSrcweir OSL_ENSURE( pWindow, "Window must not be null!" ); 345cdf0e10cSrcweir if( !pWindow ) 346cdf0e10cSrcweir return; 347cdf0e10cSrcweir Window* pParent = pWindow->GetParent(); 348cdf0e10cSrcweir while( pParent && ! pParent->IsSystemWindow() ) 349cdf0e10cSrcweir { 350cdf0e10cSrcweir pParent = pParent->GetParent(); 351cdf0e10cSrcweir } 352cdf0e10cSrcweir if ( pParent && pParent->IsSystemWindow()) 353cdf0e10cSrcweir { 354cdf0e10cSrcweir SystemWindow* pSystemWindow = static_cast< SystemWindow* >( pParent ); 355cdf0e10cSrcweir rMemFunc( pSystemWindow->GetTaskPaneList(),( pToRegister )); 356cdf0e10cSrcweir } 357cdf0e10cSrcweir } 358cdf0e10cSrcweir 359cdf0e10cSrcweir } // namespace chart 360