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 : 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 : DataSourceTabControl(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(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(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(new DataSourceTabControl(get_content_area()))
137 : , m_pRangeChooserTabePage(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_pRangeChooserTabePage = new RangeChooserTabPage( m_pTabControl, *(m_apDialogModel.get()),
147 0 : m_apDocTemplateProvider.get(), this, true /* bHideDescription */ );
148 0 : m_pDataSourceTabPage = new DataSourceTabPage( 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_pRangeChooserTabePage );
156 :
157 0 : m_pTabControl->SelectTabPage( m_nLastPageId );
158 0 : }
159 :
160 0 : DataSourceDialog::~DataSourceDialog()
161 : {
162 0 : delete m_pRangeChooserTabePage;
163 0 : delete m_pDataSourceTabPage;
164 :
165 0 : m_nLastPageId = m_pTabControl->GetCurPageId();
166 0 : delete m_pTabControl;
167 0 : }
168 :
169 0 : short DataSourceDialog::Execute()
170 : {
171 0 : short nResult = TabDialog::Execute();
172 0 : if( nResult == RET_OK )
173 : {
174 0 : if( m_pRangeChooserTabePage )
175 0 : m_pRangeChooserTabePage->commitPage();
176 0 : if( m_pDataSourceTabPage )
177 0 : m_pDataSourceTabPage->commitPage();
178 : }
179 0 : return nResult;
180 : }
181 :
182 0 : void DataSourceDialog::setInvalidPage( TabPage * pTabPage )
183 : {
184 0 : if( pTabPage == m_pRangeChooserTabePage )
185 0 : m_bRangeChooserTabIsValid = false;
186 0 : else if( pTabPage == m_pDataSourceTabPage )
187 0 : m_bDataSourceTabIsValid = false;
188 :
189 0 : if( ! (m_bRangeChooserTabIsValid && m_bDataSourceTabIsValid ))
190 : {
191 0 : m_pBtnOK->Enable( false );
192 : OSL_ASSERT( m_pTabControl );
193 : // note: there seems to be no suitable mechanism to address pages by
194 : // identifier, at least it is unclear what the page identifiers are.
195 : // @todo: change the fixed numbers to identifiers
196 0 : if( m_bRangeChooserTabIsValid )
197 0 : m_pTabControl->SetCurPageId( m_pTabControl->GetPageId( 1 ));
198 0 : else if( m_bDataSourceTabIsValid )
199 0 : m_pTabControl->SetCurPageId( m_pTabControl->GetPageId( 0 ));
200 0 : m_pTabControl->DisableTabToggling();
201 : }
202 0 : }
203 :
204 0 : void DataSourceDialog::setValidPage( TabPage * pTabPage )
205 : {
206 0 : if( pTabPage == m_pRangeChooserTabePage )
207 0 : m_bRangeChooserTabIsValid = true;
208 0 : else if( pTabPage == m_pDataSourceTabPage )
209 0 : m_bDataSourceTabIsValid = true;
210 :
211 0 : if( m_bRangeChooserTabIsValid && m_bDataSourceTabIsValid )
212 : {
213 0 : m_pBtnOK->Enable( true );
214 : OSL_ASSERT( m_pTabControl );
215 0 : m_pTabControl->EnableTabToggling();
216 : }
217 0 : }
218 :
219 0 : } // namespace chart
220 :
221 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|