fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / dialogs / dlg_DataSource.cxx
blob046077324a52771b3fb18ecac73cae952f309173
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "dlg_DataSource.hxx"
21 #include "Strings.hrc"
22 #include "ResId.hxx"
23 #include "ChartTypeTemplateProvider.hxx"
24 #include "DiagramHelper.hxx"
25 #include "DialogModel.hxx"
26 #include "HelpIds.hrc"
28 #include "tp_RangeChooser.hxx"
29 #include "tp_DataSource.hxx"
31 #include <vcl/layout.hxx>
32 #include <vcl/msgbox.hxx> // for RET_OK
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::chart2;
36 using namespace ::chart;
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::uno::Sequence;
41 namespace chart
44 class DocumentChartTypeTemplateProvider : public ChartTypeTemplateProvider
46 public:
47 DocumentChartTypeTemplateProvider(
48 const Reference< chart2::XChartDocument > & xDoc );
49 virtual ~DocumentChartTypeTemplateProvider();
51 // ____ ChartTypeTemplateProvider ____
52 virtual Reference< chart2::XChartTypeTemplate > getCurrentTemplate() const SAL_OVERRIDE;
54 private:
55 Reference< chart2::XChartTypeTemplate > m_xTemplate;
58 DocumentChartTypeTemplateProvider::DocumentChartTypeTemplateProvider(
59 const Reference< chart2::XChartDocument > & xDoc )
61 if( xDoc.is())
63 Reference< chart2::XDiagram > xDia( xDoc->getFirstDiagram());
64 if( xDia.is())
66 DiagramHelper::tTemplateWithServiceName aResult(
67 DiagramHelper::getTemplateForDiagram(
68 xDia,
69 Reference< lang::XMultiServiceFactory >(
70 xDoc->getChartTypeManager(), uno::UNO_QUERY ) ));
71 m_xTemplate.set( aResult.first );
76 DocumentChartTypeTemplateProvider::~DocumentChartTypeTemplateProvider()
79 Reference< chart2::XChartTypeTemplate > DocumentChartTypeTemplateProvider::getCurrentTemplate() const
81 return m_xTemplate;
84 class DataSourceTabControl : public TabControl
86 public:
87 DataSourceTabControl(vcl::Window* pParent);
89 virtual bool DeactivatePage() SAL_OVERRIDE;
91 void DisableTabToggling();
92 void EnableTabToggling();
94 private:
95 bool m_bTogglingEnabled;
98 DataSourceTabControl::DataSourceTabControl(vcl::Window* pParent)
99 : TabControl(pParent)
100 , m_bTogglingEnabled(true)
104 bool DataSourceTabControl::DeactivatePage()
106 return TabControl::DeactivatePage() && m_bTogglingEnabled;
109 void DataSourceTabControl::DisableTabToggling()
111 m_bTogglingEnabled = false;
114 void DataSourceTabControl::EnableTabToggling()
116 m_bTogglingEnabled = true;
119 sal_uInt16 DataSourceDialog::m_nLastPageId = 0;
121 enum DataSourceDialogPages
123 TP_RANGECHOOSER = 1,
124 TP_DATA_SOURCE = 2
127 DataSourceDialog::DataSourceDialog(vcl::Window * pParent,
128 const Reference< XChartDocument > & xChartDocument,
129 const Reference< uno::XComponentContext > & xContext)
130 : TabDialog(pParent, "DataRangeDialog",
131 "modules/schart/ui/datarangedialog.ui")
132 , m_xChartDocument(xChartDocument)
133 , m_xContext(xContext)
134 , m_apDocTemplateProvider(new DocumentChartTypeTemplateProvider(xChartDocument))
135 , m_apDialogModel(new DialogModel(xChartDocument, xContext))
136 , m_pTabControl(VclPtr<DataSourceTabControl>::Create(get_content_area()))
137 , m_pRangeChooserTabPage(0)
138 , m_pDataSourceTabPage(0)
139 , m_bRangeChooserTabIsValid(true)
140 , m_bDataSourceTabIsValid(true)
142 get(m_pBtnOK, "ok");
144 m_pTabControl->Show();
146 m_pRangeChooserTabPage = VclPtr<RangeChooserTabPage>::Create( m_pTabControl, *(m_apDialogModel.get()),
147 m_apDocTemplateProvider.get(), this, true /* bHideDescription */ );
148 m_pDataSourceTabPage = VclPtr<DataSourceTabPage>::Create( m_pTabControl, *(m_apDialogModel.get()),
149 m_apDocTemplateProvider.get(), this, true /* bHideDescription */ );
151 m_pTabControl->InsertPage( TP_RANGECHOOSER, SCH_RESSTR(STR_PAGE_DATA_RANGE) );
152 m_pTabControl->InsertPage( TP_DATA_SOURCE, SCH_RESSTR(STR_OBJECT_DATASERIES_PLURAL) );
154 m_pTabControl->SetTabPage( TP_DATA_SOURCE, m_pDataSourceTabPage );
155 m_pTabControl->SetTabPage( TP_RANGECHOOSER, m_pRangeChooserTabPage );
157 m_pTabControl->SelectTabPage( m_nLastPageId );
160 DataSourceDialog::~DataSourceDialog()
162 disposeOnce();
165 void DataSourceDialog::dispose()
167 m_pRangeChooserTabPage.disposeAndClear();
168 m_pDataSourceTabPage.disposeAndClear();
169 if (m_pTabControl)
170 m_nLastPageId = m_pTabControl->GetCurPageId();
171 m_pTabControl.disposeAndClear();
172 m_pBtnOK.clear();
173 TabDialog::dispose();
176 short DataSourceDialog::Execute()
178 short nResult = TabDialog::Execute();
179 if( nResult == RET_OK )
181 if( m_pRangeChooserTabPage )
182 m_pRangeChooserTabPage->commitPage();
183 if( m_pDataSourceTabPage )
184 m_pDataSourceTabPage->commitPage();
186 return nResult;
189 void DataSourceDialog::setInvalidPage( TabPage * pTabPage )
191 if( pTabPage == m_pRangeChooserTabPage )
192 m_bRangeChooserTabIsValid = false;
193 else if( pTabPage == m_pDataSourceTabPage )
194 m_bDataSourceTabIsValid = false;
196 if( ! (m_bRangeChooserTabIsValid && m_bDataSourceTabIsValid ))
198 m_pBtnOK->Enable( false );
199 OSL_ASSERT( m_pTabControl );
200 // note: there seems to be no suitable mechanism to address pages by
201 // identifier, at least it is unclear what the page identifiers are.
202 // @todo: change the fixed numbers to identifiers
203 if( m_bRangeChooserTabIsValid )
204 m_pTabControl->SetCurPageId( m_pTabControl->GetPageId( 1 ));
205 else if( m_bDataSourceTabIsValid )
206 m_pTabControl->SetCurPageId( m_pTabControl->GetPageId( 0 ));
207 m_pTabControl->DisableTabToggling();
211 void DataSourceDialog::setValidPage( TabPage * pTabPage )
213 if( pTabPage == m_pRangeChooserTabPage )
214 m_bRangeChooserTabIsValid = true;
215 else if( pTabPage == m_pDataSourceTabPage )
216 m_bDataSourceTabIsValid = true;
218 if( m_bRangeChooserTabIsValid && m_bDataSourceTabIsValid )
220 m_pBtnOK->Enable( true );
221 OSL_ASSERT( m_pTabControl );
222 m_pTabControl->EnableTabToggling();
226 } // namespace chart
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */