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 <com/sun/star/chart2/XChartDocument.hpp>
21 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
23 #include <dlg_DataSource.hxx>
24 #include <ChartTypeTemplateProvider.hxx>
25 #include <DiagramHelper.hxx>
26 #include "DialogModel.hxx"
28 #include "tp_RangeChooser.hxx"
29 #include "tp_DataSource.hxx"
31 using namespace ::com::sun::star
;
32 using namespace ::com::sun::star::chart2
;
33 using namespace ::chart
;
35 using ::com::sun::star::uno::Reference
;
40 class DocumentChartTypeTemplateProvider
: public ChartTypeTemplateProvider
43 explicit DocumentChartTypeTemplateProvider(
44 const Reference
< chart2::XChartDocument
> & xDoc
);
46 // ____ ChartTypeTemplateProvider ____
47 virtual Reference
< chart2::XChartTypeTemplate
> getCurrentTemplate() const override
;
50 Reference
< chart2::XChartTypeTemplate
> m_xTemplate
;
53 DocumentChartTypeTemplateProvider::DocumentChartTypeTemplateProvider(
54 const Reference
< chart2::XChartDocument
> & xDoc
)
58 Reference
< chart2::XDiagram
> xDia( xDoc
->getFirstDiagram());
61 DiagramHelper::tTemplateWithServiceName
aResult(
62 DiagramHelper::getTemplateForDiagram(
64 Reference
< lang::XMultiServiceFactory
>(
65 xDoc
->getChartTypeManager(), uno::UNO_QUERY
) ));
66 m_xTemplate
.set( aResult
.first
);
71 Reference
< chart2::XChartTypeTemplate
> DocumentChartTypeTemplateProvider::getCurrentTemplate() const
76 sal_uInt16
DataSourceDialog::m_nLastPageId
= 0;
78 DataSourceDialog::DataSourceDialog(weld::Window
* pParent
,
79 const Reference
< XChartDocument
> & xChartDocument
,
80 const Reference
< uno::XComponentContext
> & xContext
)
81 : GenericDialogController(pParent
, "modules/schart/ui/datarangedialog.ui",
83 , m_apDocTemplateProvider(new DocumentChartTypeTemplateProvider(xChartDocument
))
84 , m_apDialogModel(new DialogModel(xChartDocument
, xContext
))
85 , m_bRangeChooserTabIsValid(true)
86 , m_bDataSourceTabIsValid(true)
87 , m_bTogglingEnabled(true)
88 , m_xTabControl(m_xBuilder
->weld_notebook("tabcontrol"))
89 , m_xBtnOK(m_xBuilder
->weld_button("ok"))
91 m_xRangeChooserTabPage
= std::make_unique
<RangeChooserTabPage
>(m_xTabControl
->get_page("range"), this,
93 m_apDocTemplateProvider
.get(), true /* bHideDescription */ );
94 m_xDataSourceTabPage
= std::make_unique
<DataSourceTabPage
>(m_xTabControl
->get_page("series"), this,
96 m_apDocTemplateProvider
.get(), true /* bHideDescription */ );
97 m_xTabControl
->connect_enter_page(LINK(this, DataSourceDialog
, ActivatePageHdl
));
98 m_xTabControl
->connect_leave_page(LINK(this, DataSourceDialog
, DeactivatePageHdl
));
99 ActivatePageHdl(m_xTabControl
->get_current_page_ident());
100 if (m_nLastPageId
!= 0)
102 m_xTabControl
->set_current_page(m_nLastPageId
);
103 ActivatePageHdl(m_xTabControl
->get_current_page_ident());
107 DataSourceDialog::~DataSourceDialog()
109 m_xRangeChooserTabPage
.reset();
110 m_xDataSourceTabPage
.reset();
111 m_nLastPageId
= m_xTabControl
->get_current_page();
114 short DataSourceDialog::run()
116 short nResult
= GenericDialogController::run();
117 if( nResult
== RET_OK
)
119 if( m_xRangeChooserTabPage
)
120 m_xRangeChooserTabPage
->commitPage();
121 if( m_xDataSourceTabPage
)
122 m_xDataSourceTabPage
->commitPage();
127 IMPL_LINK(DataSourceDialog
, ActivatePageHdl
, const OString
&, rPage
, void)
129 if (rPage
== "range")
130 m_xRangeChooserTabPage
->Activate();
131 else if (rPage
== "series")
132 m_xDataSourceTabPage
->Activate();
135 // allow/disallow user to leave page
136 IMPL_LINK_NOARG(DataSourceDialog
, DeactivatePageHdl
, const OString
&, bool)
138 return m_bTogglingEnabled
;
141 void DataSourceDialog::DisableTabToggling()
143 m_bTogglingEnabled
= false;
146 void DataSourceDialog::EnableTabToggling()
148 m_bTogglingEnabled
= true;
151 void DataSourceDialog::setInvalidPage(BuilderPage
* pTabPage
)
153 if (pTabPage
== m_xRangeChooserTabPage
.get())
154 m_bRangeChooserTabIsValid
= false;
155 else if (pTabPage
== m_xDataSourceTabPage
.get())
156 m_bDataSourceTabIsValid
= false;
158 if (!(m_bRangeChooserTabIsValid
&& m_bDataSourceTabIsValid
))
160 m_xBtnOK
->set_sensitive(false);
161 // note: there seems to be no suitable mechanism to address pages by
162 // identifier, at least it is unclear what the page identifiers are.
163 // @todo: change the fixed numbers to identifiers
164 if( m_bRangeChooserTabIsValid
)
165 m_xTabControl
->set_current_page(1);
166 else if( m_bDataSourceTabIsValid
)
167 m_xTabControl
->set_current_page(0);
168 DisableTabToggling();
172 void DataSourceDialog::setValidPage(BuilderPage
* pTabPage
)
174 if( pTabPage
== m_xRangeChooserTabPage
.get() )
175 m_bRangeChooserTabIsValid
= true;
176 else if( pTabPage
== m_xDataSourceTabPage
.get() )
177 m_bDataSourceTabIsValid
= true;
179 if (m_bRangeChooserTabIsValid
&& m_bDataSourceTabIsValid
)
181 m_xBtnOK
->set_sensitive(true);
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */