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/.
10 #include <datastreamdlg.hxx>
12 #include <sfx2/filedlghelper.hxx>
13 #include <svtools/inettbc.hxx>
14 #include <vcl/layout.hxx>
15 #include <address.hxx>
20 DataStreamDlg::DataStreamDlg(ScDocShell
*pDocShell
, vcl::Window
* pParent
)
21 : ModalDialog(pParent
, "DataStreamDialog", "modules/scalc/ui/datastreams.ui")
22 , mpDocShell(pDocShell
)
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");
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();
49 m_pRBValuesInLine
->SetClickHdl( LINK( this, DataStreamDlg
, UpdateClickHdl
) );
50 m_pEdRange
->SetModifyHdl( LINK( this, DataStreamDlg
, UpdateHdl
) );
51 m_pBtnBrowse
->SetClickHdl( LINK( this, DataStreamDlg
, BrowseHdl
) );
55 DataStreamDlg::~DataStreamDlg()
60 void DataStreamDlg::dispose()
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();
72 m_pRBMaxLimit
.clear();
73 m_pRBUnlimited
.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
)
88 m_pCbUrl
->SetText( aFileDialog
.GetPath() );
92 IMPL_LINK_NOARG_TYPED(DataStreamDlg
, UpdateClickHdl
, Button
*, void)
96 IMPL_LINK_NOARG_TYPED(DataStreamDlg
, UpdateComboBoxHdl
, ComboBox
&, void)
100 IMPL_LINK_NOARG_TYPED(DataStreamDlg
, UpdateHdl
, Edit
&, void)
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();
116 m_pVclFrameLimit
->Enable();
117 m_pVclFrameMove
->Enable();
118 m_pEdRange
->Enable();
121 // Check the given range to make sure it's valid.
122 ScRange aTest
= GetStartRange();
123 if (!aTest
.IsValid())
127 m_pBtnOk
->Enable(bOk
);
128 setOptimalLayoutSize();
131 ScRange
DataStreamDlg::GetStartRange()
133 OUString aStr
= m_pEdRange
->GetText();
134 ScDocument
& rDoc
= mpDocShell
->GetDocument();
136 ScRefFlags nRes
= aRange
.Parse(aStr
, &rDoc
, rDoc
.GetAddressConvention());
137 if ( ((nRes
& ScRefFlags::VALID
) == ScRefFlags::ZERO
) || !aRange
.IsValid())
144 // Make sure it's only one row tall.
145 if (aRange
.aStart
.Row() != aRange
.aEnd
.Row())
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();
167 m_pRBMaxLimit
->Check();
168 m_pEdLimit
->SetText(OUString::number(nRows
));
171 DataStream::MoveType eMove
= rStrm
.GetMove();
174 case DataStream::MOVE_DOWN
:
175 m_pRBDataDown
->Check();
177 case DataStream::RANGE_DOWN
:
178 m_pRBRangeDown
->Check();
180 case DataStream::MOVE_UP
:
181 case DataStream::NO_MOVE
:
186 m_pCBRefreshOnEmpty
->Check(rStrm
.IsRefreshOnEmptyLine());
191 void DataStreamDlg::StartStream()
193 ScRange aStartRange
= GetStartRange();
194 if (!aStartRange
.IsValid())
195 // Don't start the stream without a valid range.
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: */