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
, 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
, UpdateHdl
) );
43 m_pRBAddressValue
->SetClickHdl( LINK( this, DataStreamDlg
, UpdateHdl
) );
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
, UpdateHdl
) );
50 m_pEdRange
->SetModifyHdl( LINK( this, DataStreamDlg
, UpdateHdl
) );
51 m_pBtnBrowse
->SetClickHdl( LINK( this, DataStreamDlg
, BrowseHdl
) );
55 IMPL_LINK_NOARG(DataStreamDlg
, BrowseHdl
)
57 sfx2::FileDialogHelper
aFileDialog(0, 0);
58 if ( aFileDialog
.Execute() != ERRCODE_NONE
)
61 m_pCbUrl
->SetText( aFileDialog
.GetPath() );
66 IMPL_LINK_NOARG(DataStreamDlg
, UpdateHdl
)
72 void DataStreamDlg::UpdateEnable()
74 bool bOk
= !m_pCbUrl
->GetURL().isEmpty();
75 if (m_pRBAddressValue
->IsChecked())
77 m_pVclFrameLimit
->Disable();
78 m_pVclFrameMove
->Disable();
79 m_pEdRange
->Disable();
83 m_pVclFrameLimit
->Enable();
84 m_pVclFrameMove
->Enable();
88 // Check the given range to make sure it's valid.
89 ScRange aTest
= GetStartRange();
94 m_pBtnOk
->Enable(bOk
);
95 setOptimalLayoutSize();
98 ScRange
DataStreamDlg::GetStartRange()
100 OUString aStr
= m_pEdRange
->GetText();
101 ScDocument
* pDoc
= mpDocShell
->GetDocument();
103 sal_uInt16 nRes
= aRange
.Parse(aStr
, pDoc
, pDoc
->GetAddressConvention());
104 if ((nRes
& SCA_VALID
) != SCA_VALID
|| !aRange
.IsValid())
111 // Make sure it's only one row tall.
112 if (aRange
.aStart
.Row() != aRange
.aEnd
.Row())
118 void DataStreamDlg::Init( const DataStream
& rStrm
)
120 m_pCbUrl
->SetText(rStrm
.GetURL());
121 ScDocument
* pDoc
= mpDocShell
->GetDocument();
123 ScRange aRange
= rStrm
.GetRange();
124 ScRange aTopRange
= aRange
;
125 aTopRange
.aEnd
.SetRow(aTopRange
.aStart
.Row());
126 OUString aStr
= aTopRange
.Format(SCR_ABS_3D
, pDoc
, pDoc
->GetAddressConvention());
127 m_pEdRange
->SetText(aStr
);
128 SCROW nRows
= aRange
.aEnd
.Row() - aRange
.aStart
.Row() + 1;
130 if (aRange
.aEnd
.Row() == MAXROW
)
131 m_pRBUnlimited
->Check();
134 m_pRBMaxLimit
->Check();
135 m_pEdLimit
->SetText(OUString::number(nRows
));
138 DataStream::MoveType eMove
= rStrm
.GetMove();
141 case DataStream::MOVE_DOWN
:
142 m_pRBDataDown
->Check();
145 case DataStream::RANGE_DOWN
:
146 m_pRBRangeDown
->Check();
148 case DataStream::MOVE_UP
:
149 case DataStream::NO_MOVE
:
154 m_pCBRefreshOnEmpty
->Check(rStrm
.IsRefreshOnEmptyLine());
159 void DataStreamDlg::StartStream()
161 ScRange aStartRange
= GetStartRange();
162 if (!aStartRange
.IsValid())
163 // Don't start the stream without a valid range.
166 sal_Int32 nLimit
= 0;
167 if (m_pRBMaxLimit
->IsChecked())
168 nLimit
= m_pEdLimit
->GetText().toInt32();
169 OUString rURL
= m_pCbUrl
->GetText();
170 sal_uInt32 nSettings
= 0;
171 if (m_pRBScriptData
->IsChecked())
172 nSettings
|= DataStream::SCRIPT_STREAM
;
173 if (m_pRBValuesInLine
->IsChecked())
174 nSettings
|= DataStream::VALUES_IN_LINE
;
176 DataStream::MoveType eMove
=
177 m_pRBRangeDown
->IsChecked() ? DataStream::RANGE_DOWN
: DataStream::MOVE_DOWN
;
179 DataStream
* pStream
= DataStream::Set(mpDocShell
, rURL
, aStartRange
, nLimit
, eMove
, nSettings
);
180 pStream
->SetRefreshOnEmptyLine(m_pCBRefreshOnEmpty
->IsChecked());
181 DataStream::MakeToolbarVisible();
182 pStream
->StartImport();
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */