1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
23 #include "ChartTypeTemplateProvider.hxx"
24 #include <DiagramHelper.hxx>
25 #include "DialogModel.hxx"
27 #include "tp_RangeChooser.hxx"
28 #include "tp_DataSource.hxx"
30 #include <vcl/layout.hxx>
32 using namespace ::com::sun::star
;
33 using namespace ::com::sun::star::chart2
;
34 using namespace ::chart
;
36 using ::com::sun::star::uno::Reference
;
41 class DocumentChartTypeTemplateProvider
: public ChartTypeTemplateProvider
44 explicit DocumentChartTypeTemplateProvider(
45 const Reference
< chart2::XChartDocument
> & xDoc
);
47 // ____ ChartTypeTemplateProvider ____
48 virtual Reference
< chart2::XChartTypeTemplate
> getCurrentTemplate() const override
;
51 Reference
< chart2::XChartTypeTemplate
> m_xTemplate
;
54 DocumentChartTypeTemplateProvider::DocumentChartTypeTemplateProvider(
55 const Reference
< chart2::XChartDocument
> & xDoc
)
59 Reference
< chart2::XDiagram
> xDia( xDoc
->getFirstDiagram());
62 DiagramHelper::tTemplateWithServiceName
aResult(
63 DiagramHelper::getTemplateForDiagram(
65 Reference
< lang::XMultiServiceFactory
>(
66 xDoc
->getChartTypeManager(), uno::UNO_QUERY
) ));
67 m_xTemplate
.set( aResult
.first
);
72 Reference
< chart2::XChartTypeTemplate
> DocumentChartTypeTemplateProvider::getCurrentTemplate() const
77 class DataSourceTabControl
: public TabControl
80 explicit DataSourceTabControl(vcl::Window
* pParent
);
82 virtual bool DeactivatePage() override
;
84 void DisableTabToggling();
85 void EnableTabToggling();
88 bool m_bTogglingEnabled
;
91 DataSourceTabControl::DataSourceTabControl(vcl::Window
* pParent
)
93 , m_bTogglingEnabled(true)
97 bool DataSourceTabControl::DeactivatePage()
99 return TabControl::DeactivatePage() && m_bTogglingEnabled
;
102 void DataSourceTabControl::DisableTabToggling()
104 m_bTogglingEnabled
= false;
107 void DataSourceTabControl::EnableTabToggling()
109 m_bTogglingEnabled
= true;
112 sal_uInt16
DataSourceDialog::m_nLastPageId
= 0;
114 enum DataSourceDialogPages
120 DataSourceDialog::DataSourceDialog(vcl::Window
* pParent
,
121 const Reference
< XChartDocument
> & xChartDocument
,
122 const Reference
< uno::XComponentContext
> & xContext
)
123 : TabDialog(pParent
, "DataRangeDialog",
124 "modules/schart/ui/datarangedialog.ui")
125 , m_apDocTemplateProvider(new DocumentChartTypeTemplateProvider(xChartDocument
))
126 , m_apDialogModel(new DialogModel(xChartDocument
, xContext
))
127 , m_pTabControl(VclPtr
<DataSourceTabControl
>::Create(get_content_area()))
128 , m_pRangeChooserTabPage(nullptr)
129 , m_pDataSourceTabPage(nullptr)
130 , m_bRangeChooserTabIsValid(true)
131 , m_bDataSourceTabIsValid(true)
135 m_pTabControl
->Show();
137 m_pRangeChooserTabPage
= VclPtr
<RangeChooserTabPage
>::Create( m_pTabControl
, *(m_apDialogModel
.get()),
138 m_apDocTemplateProvider
.get(), this, true /* bHideDescription */ );
139 m_pDataSourceTabPage
= VclPtr
<DataSourceTabPage
>::Create( m_pTabControl
, *(m_apDialogModel
.get()),
140 m_apDocTemplateProvider
.get(), this, true /* bHideDescription */ );
142 m_pTabControl
->InsertPage( TP_RANGECHOOSER
, SchResId(STR_PAGE_DATA_RANGE
) );
143 m_pTabControl
->InsertPage( TP_DATA_SOURCE
, SchResId(STR_OBJECT_DATASERIES_PLURAL
) );
145 m_pTabControl
->SetTabPage( TP_DATA_SOURCE
, m_pDataSourceTabPage
);
146 m_pTabControl
->SetTabPage( TP_RANGECHOOSER
, m_pRangeChooserTabPage
);
148 m_pTabControl
->SelectTabPage( m_nLastPageId
);
151 DataSourceDialog::~DataSourceDialog()
156 void DataSourceDialog::dispose()
158 m_pRangeChooserTabPage
.disposeAndClear();
159 m_pDataSourceTabPage
.disposeAndClear();
161 m_nLastPageId
= m_pTabControl
->GetCurPageId();
162 m_pTabControl
.disposeAndClear();
164 TabDialog::dispose();
167 short DataSourceDialog::Execute()
169 short nResult
= TabDialog::Execute();
170 if( nResult
== RET_OK
)
172 if( m_pRangeChooserTabPage
)
173 m_pRangeChooserTabPage
->commitPage();
174 if( m_pDataSourceTabPage
)
175 m_pDataSourceTabPage
->commitPage();
180 void DataSourceDialog::setInvalidPage( TabPage
* pTabPage
)
182 if( pTabPage
== m_pRangeChooserTabPage
)
183 m_bRangeChooserTabIsValid
= false;
184 else if( pTabPage
== m_pDataSourceTabPage
)
185 m_bDataSourceTabIsValid
= false;
187 if( ! (m_bRangeChooserTabIsValid
&& m_bDataSourceTabIsValid
))
189 m_pBtnOK
->Enable( false );
190 OSL_ASSERT( m_pTabControl
);
191 // note: there seems to be no suitable mechanism to address pages by
192 // identifier, at least it is unclear what the page identifiers are.
193 // @todo: change the fixed numbers to identifiers
194 if( m_bRangeChooserTabIsValid
)
195 m_pTabControl
->SetCurPageId( m_pTabControl
->GetPageId( 1 ));
196 else if( m_bDataSourceTabIsValid
)
197 m_pTabControl
->SetCurPageId( m_pTabControl
->GetPageId( 0 ));
198 m_pTabControl
->DisableTabToggling();
202 void DataSourceDialog::setValidPage( TabPage
* pTabPage
)
204 if( pTabPage
== m_pRangeChooserTabPage
)
205 m_bRangeChooserTabIsValid
= true;
206 else if( pTabPage
== m_pDataSourceTabPage
)
207 m_bDataSourceTabIsValid
= true;
209 if( m_bRangeChooserTabIsValid
&& m_bDataSourceTabIsValid
)
212 OSL_ASSERT( m_pTabControl
);
213 m_pTabControl
->EnableTabToggling();
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */