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 #include "dlg_DataSource.hxx" 32*cdf0e10cSrcweir #include "dlg_DataSource.hrc" 33*cdf0e10cSrcweir #include "Strings.hrc" 34*cdf0e10cSrcweir #include "ResId.hxx" 35*cdf0e10cSrcweir #include "ChartTypeTemplateProvider.hxx" 36*cdf0e10cSrcweir #include "DiagramHelper.hxx" 37*cdf0e10cSrcweir #include "DialogModel.hxx" 38*cdf0e10cSrcweir #include "HelpIds.hrc" 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include "tp_RangeChooser.hxx" 41*cdf0e10cSrcweir #include "tp_DataSource.hxx" 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir // for RET_OK 44*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir using namespace ::com::sun::star; 47*cdf0e10cSrcweir using namespace ::com::sun::star::chart2; 48*cdf0e10cSrcweir using namespace ::chart; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 51*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 52*cdf0e10cSrcweir using ::rtl::OUString; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir // -------------------------------------------------------------------------------- 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir namespace chart 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir // ---------------------------------------- 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir class DocumentChartTypeTemplateProvider : public ChartTypeTemplateProvider 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir public: 65*cdf0e10cSrcweir DocumentChartTypeTemplateProvider( 66*cdf0e10cSrcweir const Reference< chart2::XChartDocument > & xDoc ); 67*cdf0e10cSrcweir virtual ~DocumentChartTypeTemplateProvider(); 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir // ____ ChartTypeTemplateProvider ____ 70*cdf0e10cSrcweir virtual Reference< chart2::XChartTypeTemplate > getCurrentTemplate() const; 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir private: 73*cdf0e10cSrcweir Reference< chart2::XChartTypeTemplate > m_xTemplate; 74*cdf0e10cSrcweir }; 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir DocumentChartTypeTemplateProvider::DocumentChartTypeTemplateProvider( 77*cdf0e10cSrcweir const Reference< chart2::XChartDocument > & xDoc ) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir if( xDoc.is()) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir Reference< chart2::XDiagram > xDia( xDoc->getFirstDiagram()); 82*cdf0e10cSrcweir if( xDia.is()) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir DiagramHelper::tTemplateWithServiceName aResult( 85*cdf0e10cSrcweir DiagramHelper::getTemplateForDiagram( 86*cdf0e10cSrcweir xDia, 87*cdf0e10cSrcweir Reference< lang::XMultiServiceFactory >( 88*cdf0e10cSrcweir xDoc->getChartTypeManager(), uno::UNO_QUERY ) )); 89*cdf0e10cSrcweir m_xTemplate.set( aResult.first ); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir DocumentChartTypeTemplateProvider::~DocumentChartTypeTemplateProvider() 95*cdf0e10cSrcweir {} 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir Reference< chart2::XChartTypeTemplate > DocumentChartTypeTemplateProvider::getCurrentTemplate() const 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir return m_xTemplate; 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir // ---------------------------------------- 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir class DataSourceTabControl : public TabControl 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir public: 107*cdf0e10cSrcweir DataSourceTabControl( Window* pParent, const ResId& rResId ); 108*cdf0e10cSrcweir ~DataSourceTabControl(); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir virtual long DeactivatePage(); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir void DisableTabToggling(); 113*cdf0e10cSrcweir void EnableTabToggling(); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir private: 116*cdf0e10cSrcweir bool m_bTogglingEnabled; 117*cdf0e10cSrcweir }; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir DataSourceTabControl::DataSourceTabControl( Window* pParent, const ResId& rResId ) : 120*cdf0e10cSrcweir TabControl( pParent, rResId ), 121*cdf0e10cSrcweir m_bTogglingEnabled( true ) 122*cdf0e10cSrcweir {} 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir DataSourceTabControl::~DataSourceTabControl() 125*cdf0e10cSrcweir {} 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir // Note that the result is long, but is intended to be a bool 128*cdf0e10cSrcweir long DataSourceTabControl::DeactivatePage() 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir bool bCanDeactivate( TabControl::DeactivatePage() != 0 ); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir bCanDeactivate = (bCanDeactivate && m_bTogglingEnabled); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir return (bCanDeactivate ? 1 : 0 ); 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir void DataSourceTabControl::DisableTabToggling() 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir m_bTogglingEnabled = false; 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir void DataSourceTabControl::EnableTabToggling() 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir m_bTogglingEnabled = true; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir // ---------------------------------------- 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir sal_uInt16 DataSourceDialog::m_nLastPageId = 0; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir DataSourceDialog::DataSourceDialog( 152*cdf0e10cSrcweir Window * pParent, 153*cdf0e10cSrcweir const Reference< XChartDocument > & xChartDocument, 154*cdf0e10cSrcweir const Reference< uno::XComponentContext > & xContext ) : 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir TabDialog( pParent, SchResId( DLG_DATA_SOURCE )), 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir m_xChartDocument( xChartDocument ), 159*cdf0e10cSrcweir m_xContext( xContext ), 160*cdf0e10cSrcweir m_apDocTemplateProvider( new DocumentChartTypeTemplateProvider( xChartDocument )), 161*cdf0e10cSrcweir m_apDialogModel( new DialogModel( xChartDocument, xContext )), 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir m_pTabControl( new DataSourceTabControl( this, SchResId( TABCTRL ) )), 164*cdf0e10cSrcweir m_aBtnOK( this, SchResId( BTN_OK ) ), 165*cdf0e10cSrcweir m_aBtnCancel( this, SchResId( BTN_CANCEL ) ), 166*cdf0e10cSrcweir m_aBtnHelp( this, SchResId( BTN_HELP ) ), 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir m_pRangeChooserTabePage(0), 169*cdf0e10cSrcweir m_pDataSourceTabPage(0), 170*cdf0e10cSrcweir m_bRangeChooserTabIsValid( true ), 171*cdf0e10cSrcweir m_bDataSourceTabIsValid( true ) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir FreeResource(); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir //don't create the tabpages before FreeResource, otherwise the help ids are not matched correctly 176*cdf0e10cSrcweir m_pRangeChooserTabePage = new RangeChooserTabPage( m_pTabControl, *(m_apDialogModel.get()), 177*cdf0e10cSrcweir m_apDocTemplateProvider.get(), this, true /* bHideDescription */ ); 178*cdf0e10cSrcweir m_pDataSourceTabPage = new DataSourceTabPage( m_pTabControl, *(m_apDialogModel.get()), 179*cdf0e10cSrcweir m_apDocTemplateProvider.get(), this, true /* bHideDescription */ ); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir m_pTabControl->InsertPage( TP_RANGECHOOSER, String( SchResId( STR_PAGE_DATA_RANGE ))); 182*cdf0e10cSrcweir m_pTabControl->InsertPage( TP_DATA_SOURCE, String( SchResId( STR_OBJECT_DATASERIES_PLURAL ))); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir m_pTabControl->SetTabPage( TP_RANGECHOOSER, m_pRangeChooserTabePage ); 185*cdf0e10cSrcweir m_pTabControl->SetTabPage( TP_DATA_SOURCE, m_pDataSourceTabPage ); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir m_pTabControl->SelectTabPage( m_nLastPageId ); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir SetHelpId( HID_SCH_DLG_RANGES ); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir DataSourceDialog::~DataSourceDialog() 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir delete m_pRangeChooserTabePage; 195*cdf0e10cSrcweir delete m_pDataSourceTabPage; 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir m_nLastPageId = m_pTabControl->GetCurPageId(); 198*cdf0e10cSrcweir delete m_pTabControl; 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir short DataSourceDialog::Execute() 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir short nResult = TabDialog::Execute(); 204*cdf0e10cSrcweir if( nResult == RET_OK ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir if( m_pRangeChooserTabePage ) 207*cdf0e10cSrcweir m_pRangeChooserTabePage->commitPage(); 208*cdf0e10cSrcweir if( m_pDataSourceTabPage ) 209*cdf0e10cSrcweir m_pDataSourceTabPage->commitPage(); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir return nResult; 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir void DataSourceDialog::setInvalidPage( TabPage * pTabPage ) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir if( pTabPage == m_pRangeChooserTabePage ) 217*cdf0e10cSrcweir m_bRangeChooserTabIsValid = false; 218*cdf0e10cSrcweir else if( pTabPage == m_pDataSourceTabPage ) 219*cdf0e10cSrcweir m_bDataSourceTabIsValid = false; 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir if( ! (m_bRangeChooserTabIsValid && m_bDataSourceTabIsValid )) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir m_aBtnOK.Enable( sal_False ); 224*cdf0e10cSrcweir OSL_ASSERT( m_pTabControl ); 225*cdf0e10cSrcweir // note: there seems to be no suitable mechanism to address pages by 226*cdf0e10cSrcweir // identifier, at least it is unclear what the page identifiers are. 227*cdf0e10cSrcweir // @todo: change the fixed numbers to identifiers 228*cdf0e10cSrcweir if( m_bRangeChooserTabIsValid ) 229*cdf0e10cSrcweir m_pTabControl->SetCurPageId( m_pTabControl->GetPageId( 1 )); 230*cdf0e10cSrcweir else if( m_bDataSourceTabIsValid ) 231*cdf0e10cSrcweir m_pTabControl->SetCurPageId( m_pTabControl->GetPageId( 0 )); 232*cdf0e10cSrcweir m_pTabControl->DisableTabToggling(); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir void DataSourceDialog::setValidPage( TabPage * pTabPage ) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir if( pTabPage == m_pRangeChooserTabePage ) 239*cdf0e10cSrcweir m_bRangeChooserTabIsValid = true; 240*cdf0e10cSrcweir else if( pTabPage == m_pDataSourceTabPage ) 241*cdf0e10cSrcweir m_bDataSourceTabIsValid = true; 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir if( m_bRangeChooserTabIsValid && m_bDataSourceTabIsValid ) 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir m_aBtnOK.Enable( sal_True ); 246*cdf0e10cSrcweir OSL_ASSERT( m_pTabControl ); 247*cdf0e10cSrcweir m_pTabControl->EnableTabToggling(); 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir } // namespace chart 253