update dev300-m58
[ooovba.git] / chart2 / source / controller / dialogs / dlg_DataSource.cxx
blobdc18673d1b895ea942b8aecd00daa1b12b05fb20
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dlg_DataSource.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "dlg_DataSource.hxx"
35 #include "dlg_DataSource.hrc"
36 #include "Strings.hrc"
37 #include "ResId.hxx"
38 #include "ChartTypeTemplateProvider.hxx"
39 #include "DiagramHelper.hxx"
40 #include "DialogModel.hxx"
41 #include "HelpIds.hrc"
43 #include "tp_RangeChooser.hxx"
44 #include "tp_DataSource.hxx"
46 // for RET_OK
47 #include <vcl/msgbox.hxx>
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::chart2;
51 using namespace ::chart;
53 using ::com::sun::star::uno::Reference;
54 using ::com::sun::star::uno::Sequence;
55 using ::rtl::OUString;
57 // --------------------------------------------------------------------------------
60 namespace chart
63 // ----------------------------------------
65 class DocumentChartTypeTemplateProvider : public ChartTypeTemplateProvider
67 public:
68 DocumentChartTypeTemplateProvider(
69 const Reference< chart2::XChartDocument > & xDoc );
70 virtual ~DocumentChartTypeTemplateProvider();
72 // ____ ChartTypeTemplateProvider ____
73 virtual Reference< chart2::XChartTypeTemplate > getCurrentTemplate() const;
75 private:
76 Reference< chart2::XChartTypeTemplate > m_xTemplate;
79 DocumentChartTypeTemplateProvider::DocumentChartTypeTemplateProvider(
80 const Reference< chart2::XChartDocument > & xDoc )
82 if( xDoc.is())
84 Reference< chart2::XDiagram > xDia( xDoc->getFirstDiagram());
85 if( xDia.is())
87 DiagramHelper::tTemplateWithServiceName aResult(
88 DiagramHelper::getTemplateForDiagram(
89 xDia,
90 Reference< lang::XMultiServiceFactory >(
91 xDoc->getChartTypeManager(), uno::UNO_QUERY ) ));
92 m_xTemplate.set( aResult.first );
97 DocumentChartTypeTemplateProvider::~DocumentChartTypeTemplateProvider()
100 Reference< chart2::XChartTypeTemplate > DocumentChartTypeTemplateProvider::getCurrentTemplate() const
102 return m_xTemplate;
105 // ----------------------------------------
107 class DataSourceTabControl : public TabControl
109 public:
110 DataSourceTabControl( Window* pParent, const ResId& rResId );
111 ~DataSourceTabControl();
113 virtual long DeactivatePage();
115 void DisableTabToggling();
116 void EnableTabToggling();
118 private:
119 bool m_bTogglingEnabled;
122 DataSourceTabControl::DataSourceTabControl( Window* pParent, const ResId& rResId ) :
123 TabControl( pParent, rResId ),
124 m_bTogglingEnabled( true )
127 DataSourceTabControl::~DataSourceTabControl()
130 // Note that the result is long, but is intended to be a bool
131 long DataSourceTabControl::DeactivatePage()
133 bool bCanDeactivate( TabControl::DeactivatePage() != 0 );
135 bCanDeactivate = (bCanDeactivate && m_bTogglingEnabled);
137 return (bCanDeactivate ? 1 : 0 );
140 void DataSourceTabControl::DisableTabToggling()
142 m_bTogglingEnabled = false;
145 void DataSourceTabControl::EnableTabToggling()
147 m_bTogglingEnabled = true;
150 // ----------------------------------------
152 // static
153 USHORT DataSourceDialog::m_nLastPageId = 0;
155 DataSourceDialog::DataSourceDialog(
156 Window * pParent,
157 const Reference< XChartDocument > & xChartDocument,
158 const Reference< uno::XComponentContext > & xContext ) :
160 TabDialog( pParent, SchResId( DLG_DATA_SOURCE )),
162 m_xChartDocument( xChartDocument ),
163 m_xContext( xContext ),
164 m_apDocTemplateProvider( new DocumentChartTypeTemplateProvider( xChartDocument )),
165 m_apDialogModel( new DialogModel( xChartDocument, xContext )),
167 m_pTabControl( new DataSourceTabControl( this, SchResId( TABCTRL ) )),
168 m_aBtnOK( this, SchResId( BTN_OK ) ),
169 m_aBtnCancel( this, SchResId( BTN_CANCEL ) ),
170 m_aBtnHelp( this, SchResId( BTN_HELP ) ),
172 m_pRangeChooserTabePage(0),
173 m_pDataSourceTabPage(0),
174 m_bRangeChooserTabIsValid( true ),
175 m_bDataSourceTabIsValid( true )
177 FreeResource();
179 //don't create the tabpages before FreeResource, otherwise the help ids are not matched correctly
180 m_pRangeChooserTabePage = new RangeChooserTabPage( m_pTabControl, *(m_apDialogModel.get()),
181 m_apDocTemplateProvider.get(), this, true /* bHideDescription */ );
182 m_pDataSourceTabPage = new DataSourceTabPage( m_pTabControl, *(m_apDialogModel.get()),
183 m_apDocTemplateProvider.get(), this, true /* bHideDescription */ );
185 m_pTabControl->InsertPage( TP_RANGECHOOSER, String( SchResId( STR_PAGE_DATA_RANGE )));
186 m_pTabControl->InsertPage( TP_DATA_SOURCE, String( SchResId( STR_OBJECT_DATASERIES_PLURAL )));
188 m_pTabControl->SetTabPage( TP_RANGECHOOSER, m_pRangeChooserTabePage );
189 m_pTabControl->SetTabPage( TP_DATA_SOURCE, m_pDataSourceTabPage );
191 m_pTabControl->SelectTabPage( m_nLastPageId );
193 SetHelpId( HID_SCH_DLG_RANGES );
196 DataSourceDialog::~DataSourceDialog()
198 delete m_pRangeChooserTabePage;
199 delete m_pDataSourceTabPage;
201 m_nLastPageId = m_pTabControl->GetCurPageId();
202 delete m_pTabControl;
205 short DataSourceDialog::Execute()
207 short nResult = TabDialog::Execute();
208 if( nResult == RET_OK )
210 if( m_pRangeChooserTabePage )
211 m_pRangeChooserTabePage->commitPage();
212 if( m_pDataSourceTabPage )
213 m_pDataSourceTabPage->commitPage();
215 return nResult;
218 void DataSourceDialog::setInvalidPage( TabPage * pTabPage )
220 if( pTabPage == m_pRangeChooserTabePage )
221 m_bRangeChooserTabIsValid = false;
222 else if( pTabPage == m_pDataSourceTabPage )
223 m_bDataSourceTabIsValid = false;
225 if( ! (m_bRangeChooserTabIsValid && m_bDataSourceTabIsValid ))
227 m_aBtnOK.Enable( FALSE );
228 OSL_ASSERT( m_pTabControl );
229 // note: there seems to be no suitable mechanism to address pages by
230 // identifier, at least it is unclear what the page identifiers are.
231 // @todo: change the fixed numbers to identifiers
232 if( m_bRangeChooserTabIsValid )
233 m_pTabControl->SetCurPageId( m_pTabControl->GetPageId( 1 ));
234 else if( m_bDataSourceTabIsValid )
235 m_pTabControl->SetCurPageId( m_pTabControl->GetPageId( 0 ));
236 m_pTabControl->DisableTabToggling();
240 void DataSourceDialog::setValidPage( TabPage * pTabPage )
242 if( pTabPage == m_pRangeChooserTabePage )
243 m_bRangeChooserTabIsValid = true;
244 else if( pTabPage == m_pDataSourceTabPage )
245 m_bDataSourceTabIsValid = true;
247 if( m_bRangeChooserTabIsValid && m_bDataSourceTabIsValid )
249 m_aBtnOK.Enable( TRUE );
250 OSL_ASSERT( m_pTabControl );
251 m_pTabControl->EnableTabToggling();
256 } // namespace chart