Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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"
27 :
28 : #include "tp_RangeChooser.hxx"
29 : #include "tp_DataSource.hxx"
30 :
31 : #include <vcl/layout.hxx>
32 : #include <vcl/msgbox.hxx> // for RET_OK
33 :
34 : using namespace ::com::sun::star;
35 : using namespace ::com::sun::star::chart2;
36 : using namespace ::chart;
37 :
38 : using ::com::sun::star::uno::Reference;
39 : using ::com::sun::star::uno::Sequence;
40 :
41 : namespace chart
42 : {
43 :
44 : class DocumentChartTypeTemplateProvider : public ChartTypeTemplateProvider
45 : {
46 : public:
47 : explicit DocumentChartTypeTemplateProvider(
48 : const Reference< chart2::XChartDocument > & xDoc );
49 : virtual ~DocumentChartTypeTemplateProvider();
50 :
51 : // ____ ChartTypeTemplateProvider ____
52 : virtual Reference< chart2::XChartTypeTemplate > getCurrentTemplate() const SAL_OVERRIDE;
53 :
54 : private:
55 : Reference< chart2::XChartTypeTemplate > m_xTemplate;
56 : };
57 :
58 0 : DocumentChartTypeTemplateProvider::DocumentChartTypeTemplateProvider(
59 0 : const Reference< chart2::XChartDocument > & xDoc )
60 : {
61 0 : if( xDoc.is())
62 : {
63 0 : Reference< chart2::XDiagram > xDia( xDoc->getFirstDiagram());
64 0 : if( xDia.is())
65 : {
66 : DiagramHelper::tTemplateWithServiceName aResult(
67 : DiagramHelper::getTemplateForDiagram(
68 : xDia,
69 : Reference< lang::XMultiServiceFactory >(
70 0 : xDoc->getChartTypeManager(), uno::UNO_QUERY ) ));
71 0 : m_xTemplate.set( aResult.first );
72 0 : }
73 : }
74 0 : }
75 :
76 0 : DocumentChartTypeTemplateProvider::~DocumentChartTypeTemplateProvider()
77 0 : {}
78 :
79 0 : Reference< chart2::XChartTypeTemplate > DocumentChartTypeTemplateProvider::getCurrentTemplate() const
80 : {
81 0 : return m_xTemplate;
82 : }
83 :
84 0 : class DataSourceTabControl : public TabControl
85 : {
86 : public:
87 : explicit DataSourceTabControl(vcl::Window* pParent);
88 :
89 : virtual bool DeactivatePage() SAL_OVERRIDE;
90 :
91 : void DisableTabToggling();
92 : void EnableTabToggling();
93 :
94 : private:
95 : bool m_bTogglingEnabled;
96 : };
97 :
98 0 : DataSourceTabControl::DataSourceTabControl(vcl::Window* pParent)
99 : : TabControl(pParent)
100 0 : , m_bTogglingEnabled(true)
101 : {
102 0 : }
103 :
104 0 : bool DataSourceTabControl::DeactivatePage()
105 : {
106 0 : return TabControl::DeactivatePage() && m_bTogglingEnabled;
107 : }
108 :
109 0 : void DataSourceTabControl::DisableTabToggling()
110 : {
111 0 : m_bTogglingEnabled = false;
112 0 : }
113 :
114 0 : void DataSourceTabControl::EnableTabToggling()
115 : {
116 0 : m_bTogglingEnabled = true;
117 0 : }
118 :
119 : sal_uInt16 DataSourceDialog::m_nLastPageId = 0;
120 :
121 : enum DataSourceDialogPages
122 : {
123 : TP_RANGECHOOSER = 1,
124 : TP_DATA_SOURCE = 2
125 : };
126 :
127 0 : 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 0 : , m_apDocTemplateProvider(new DocumentChartTypeTemplateProvider(xChartDocument))
135 0 : , m_apDialogModel(new DialogModel(xChartDocument, xContext))
136 0 : , m_pTabControl(VclPtr<DataSourceTabControl>::Create(get_content_area()))
137 : , m_pRangeChooserTabPage(0)
138 : , m_pDataSourceTabPage(0)
139 : , m_bRangeChooserTabIsValid(true)
140 0 : , m_bDataSourceTabIsValid(true)
141 : {
142 0 : get(m_pBtnOK, "ok");
143 :
144 0 : m_pTabControl->Show();
145 :
146 0 : m_pRangeChooserTabPage = VclPtr<RangeChooserTabPage>::Create( m_pTabControl, *(m_apDialogModel.get()),
147 0 : m_apDocTemplateProvider.get(), this, true /* bHideDescription */ );
148 0 : m_pDataSourceTabPage = VclPtr<DataSourceTabPage>::Create( m_pTabControl, *(m_apDialogModel.get()),
149 0 : m_apDocTemplateProvider.get(), this, true /* bHideDescription */ );
150 :
151 0 : m_pTabControl->InsertPage( TP_RANGECHOOSER, SCH_RESSTR(STR_PAGE_DATA_RANGE) );
152 0 : m_pTabControl->InsertPage( TP_DATA_SOURCE, SCH_RESSTR(STR_OBJECT_DATASERIES_PLURAL) );
153 :
154 0 : m_pTabControl->SetTabPage( TP_DATA_SOURCE, m_pDataSourceTabPage );
155 0 : m_pTabControl->SetTabPage( TP_RANGECHOOSER, m_pRangeChooserTabPage );
156 :
157 0 : m_pTabControl->SelectTabPage( m_nLastPageId );
158 0 : }
159 :
160 0 : DataSourceDialog::~DataSourceDialog()
161 : {
162 0 : disposeOnce();
163 0 : }
164 :
165 0 : void DataSourceDialog::dispose()
166 : {
167 0 : m_pRangeChooserTabPage.disposeAndClear();
168 0 : m_pDataSourceTabPage.disposeAndClear();
169 0 : if (m_pTabControl)
170 0 : m_nLastPageId = m_pTabControl->GetCurPageId();
171 0 : m_pTabControl.disposeAndClear();
172 0 : m_pBtnOK.clear();
173 0 : TabDialog::dispose();
174 0 : }
175 :
176 0 : short DataSourceDialog::Execute()
177 : {
178 0 : short nResult = TabDialog::Execute();
179 0 : if( nResult == RET_OK )
180 : {
181 0 : if( m_pRangeChooserTabPage )
182 0 : m_pRangeChooserTabPage->commitPage();
183 0 : if( m_pDataSourceTabPage )
184 0 : m_pDataSourceTabPage->commitPage();
185 : }
186 0 : return nResult;
187 : }
188 :
189 0 : void DataSourceDialog::setInvalidPage( TabPage * pTabPage )
190 : {
191 0 : if( pTabPage == m_pRangeChooserTabPage )
192 0 : m_bRangeChooserTabIsValid = false;
193 0 : else if( pTabPage == m_pDataSourceTabPage )
194 0 : m_bDataSourceTabIsValid = false;
195 :
196 0 : if( ! (m_bRangeChooserTabIsValid && m_bDataSourceTabIsValid ))
197 : {
198 0 : 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 0 : if( m_bRangeChooserTabIsValid )
204 0 : m_pTabControl->SetCurPageId( m_pTabControl->GetPageId( 1 ));
205 0 : else if( m_bDataSourceTabIsValid )
206 0 : m_pTabControl->SetCurPageId( m_pTabControl->GetPageId( 0 ));
207 0 : m_pTabControl->DisableTabToggling();
208 : }
209 0 : }
210 :
211 0 : void DataSourceDialog::setValidPage( TabPage * pTabPage )
212 : {
213 0 : if( pTabPage == m_pRangeChooserTabPage )
214 0 : m_bRangeChooserTabIsValid = true;
215 0 : else if( pTabPage == m_pDataSourceTabPage )
216 0 : m_bDataSourceTabIsValid = true;
217 :
218 0 : if( m_bRangeChooserTabIsValid && m_bDataSourceTabIsValid )
219 : {
220 0 : m_pBtnOK->Enable( true );
221 : OSL_ASSERT( m_pTabControl );
222 0 : m_pTabControl->EnableTabToggling();
223 : }
224 0 : }
225 :
226 57 : } // namespace chart
227 :
228 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|