Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / miscdlgs / datastreamdlg.cxx
blob432ae7ede665ac5ce9cd7a3e37b8de42fc41203c
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/.
8 */
10 #include <datastreamdlg.hxx>
12 #include <sfx2/filedlghelper.hxx>
13 #include <svtools/inettbc.hxx>
14 #include <vcl/layout.hxx>
15 #include <address.hxx>
16 #include <docsh.hxx>
18 namespace sc {
20 DataStreamDlg::DataStreamDlg(ScDocShell *pDocShell, vcl::Window* pParent)
21 : ModalDialog(pParent, "DataStreamDialog", "modules/scalc/ui/datastreams.ui")
22 , mpDocShell(pDocShell)
24 get(m_pCbUrl, "url");
25 get(m_pBtnBrowse, "browse");
26 get(m_pRBDirectData, "directdata");
27 get(m_pRBScriptData, "scriptdata");
28 get(m_pRBValuesInLine, "valuesinline");
29 get(m_pRBAddressValue, "addressvalue");
30 get(m_pCBRefreshOnEmpty, "refresh_ui");
31 get(m_pRBDataDown, "datadown");
32 get(m_pRBRangeDown, "rangedown");
33 get(m_pRBNoMove, "nomove");
34 get(m_pRBMaxLimit, "maxlimit");
35 get(m_pRBUnlimited, "unlimited");
36 get(m_pEdRange, "range");
37 get(m_pEdLimit, "limit");
38 get(m_pBtnOk, "ok");
39 get(m_pVclFrameLimit, "framelimit");
40 get(m_pVclFrameMove, "framemove");
42 m_pCbUrl->SetSelectHdl( LINK( this, DataStreamDlg, UpdateComboBoxHdl ) );
43 m_pRBAddressValue->SetClickHdl( LINK( this, DataStreamDlg, UpdateClickHdl ) );
44 m_pRBAddressValue->Enable(false);
45 m_pRBScriptData->Enable(false);
46 m_pRBDirectData->Hide();
47 m_pRBScriptData->Hide();
48 m_pRBNoMove->Hide();
49 m_pRBValuesInLine->SetClickHdl( LINK( this, DataStreamDlg, UpdateClickHdl ) );
50 m_pEdRange->SetModifyHdl( LINK( this, DataStreamDlg, UpdateHdl ) );
51 m_pBtnBrowse->SetClickHdl( LINK( this, DataStreamDlg, BrowseHdl ) );
52 UpdateEnable();
55 DataStreamDlg::~DataStreamDlg()
57 disposeOnce();
60 void DataStreamDlg::dispose()
62 m_pCbUrl.clear();
63 m_pBtnBrowse.clear();
64 m_pRBDirectData.clear();
65 m_pRBScriptData.clear();
66 m_pRBValuesInLine.clear();
67 m_pRBAddressValue.clear();
68 m_pCBRefreshOnEmpty.clear();
69 m_pRBDataDown.clear();
70 m_pRBRangeDown.clear();
71 m_pRBNoMove.clear();
72 m_pRBMaxLimit.clear();
73 m_pRBUnlimited.clear();
74 m_pEdRange.clear();
75 m_pEdLimit.clear();
76 m_pBtnOk.clear();
77 m_pVclFrameLimit.clear();
78 m_pVclFrameMove.clear();
79 ModalDialog::dispose();
82 IMPL_LINK_NOARG_TYPED(DataStreamDlg, BrowseHdl, Button*, void)
84 sfx2::FileDialogHelper aFileDialog(0);
85 if ( aFileDialog.Execute() != ERRCODE_NONE )
86 return;
88 m_pCbUrl->SetText( aFileDialog.GetPath() );
89 UpdateEnable();
92 IMPL_LINK_NOARG_TYPED(DataStreamDlg, UpdateClickHdl, Button*, void)
94 UpdateEnable();
96 IMPL_LINK_NOARG_TYPED(DataStreamDlg, UpdateComboBoxHdl, ComboBox&, void)
98 UpdateEnable();
100 IMPL_LINK_NOARG_TYPED(DataStreamDlg, UpdateHdl, Edit&, void)
102 UpdateEnable();
105 void DataStreamDlg::UpdateEnable()
107 bool bOk = !m_pCbUrl->GetURL().isEmpty();
108 if (m_pRBAddressValue->IsChecked())
110 m_pVclFrameLimit->Disable();
111 m_pVclFrameMove->Disable();
112 m_pEdRange->Disable();
114 else
116 m_pVclFrameLimit->Enable();
117 m_pVclFrameMove->Enable();
118 m_pEdRange->Enable();
119 if (bOk)
121 // Check the given range to make sure it's valid.
122 ScRange aTest = GetStartRange();
123 if (!aTest.IsValid())
124 bOk = false;
127 m_pBtnOk->Enable(bOk);
128 setOptimalLayoutSize();
131 ScRange DataStreamDlg::GetStartRange()
133 OUString aStr = m_pEdRange->GetText();
134 ScDocument& rDoc = mpDocShell->GetDocument();
135 ScRange aRange;
136 ScRefFlags nRes = aRange.Parse(aStr, &rDoc, rDoc.GetAddressConvention());
137 if ( ((nRes & ScRefFlags::VALID) == ScRefFlags::ZERO) || !aRange.IsValid())
139 // Invalid range.
140 aRange.SetInvalid();
141 return aRange;
144 // Make sure it's only one row tall.
145 if (aRange.aStart.Row() != aRange.aEnd.Row())
146 aRange.SetInvalid();
148 return aRange;
151 void DataStreamDlg::Init( const DataStream& rStrm )
153 m_pCbUrl->SetText(rStrm.GetURL());
154 ScDocument& rDoc = mpDocShell->GetDocument();
156 ScRange aRange = rStrm.GetRange();
157 ScRange aTopRange = aRange;
158 aTopRange.aEnd.SetRow(aTopRange.aStart.Row());
159 OUString aStr = aTopRange.Format(ScRefFlags::RANGE_ABS_3D, &rDoc, rDoc.GetAddressConvention());
160 m_pEdRange->SetText(aStr);
161 SCROW nRows = aRange.aEnd.Row() - aRange.aStart.Row() + 1;
163 if (aRange.aEnd.Row() == MAXROW)
164 m_pRBUnlimited->Check();
165 else
167 m_pRBMaxLimit->Check();
168 m_pEdLimit->SetText(OUString::number(nRows));
171 DataStream::MoveType eMove = rStrm.GetMove();
172 switch (eMove)
174 case DataStream::MOVE_DOWN:
175 m_pRBDataDown->Check();
176 break;
177 case DataStream::RANGE_DOWN:
178 m_pRBRangeDown->Check();
179 break;
180 case DataStream::MOVE_UP:
181 case DataStream::NO_MOVE:
182 default:
186 m_pCBRefreshOnEmpty->Check(rStrm.IsRefreshOnEmptyLine());
188 UpdateEnable();
191 void DataStreamDlg::StartStream()
193 ScRange aStartRange = GetStartRange();
194 if (!aStartRange.IsValid())
195 // Don't start the stream without a valid range.
196 return;
198 sal_Int32 nLimit = 0;
199 if (m_pRBMaxLimit->IsChecked())
200 nLimit = m_pEdLimit->GetText().toInt32();
201 OUString rURL = m_pCbUrl->GetText();
202 sal_uInt32 nSettings = 0;
203 if (m_pRBScriptData->IsChecked())
204 nSettings |= DataStream::SCRIPT_STREAM;
205 if (m_pRBValuesInLine->IsChecked())
206 nSettings |= DataStream::VALUES_IN_LINE;
208 DataStream::MoveType eMove =
209 m_pRBRangeDown->IsChecked() ? DataStream::RANGE_DOWN : DataStream::MOVE_DOWN;
211 DataStream* pStream = DataStream::Set(mpDocShell, rURL, aStartRange, nLimit, eMove, nSettings);
212 pStream->SetRefreshOnEmptyLine(m_pCBRefreshOnEmpty->IsChecked());
213 DataStream::MakeToolbarVisible();
214 pStream->StartImport();
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */