24#include <osl/diagnose.h>
33#include <rtl/textenc.h>
34#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
35#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
46struct SwAddressFragment
48 std::unique_ptr<weld::Builder> m_xBuilder;
49 std::unique_ptr<weld::Label>
m_xLabel;
50 std::unique_ptr<weld::Entry> m_xEntry;
54 : m_xBuilder(
Application::CreateBuilder(pGrid,
"modules/swriter/ui/addressfragment.ui"))
55 ,
m_xLabel(m_xBuilder->weld_label(
"label"))
56 , m_xEntry(m_xBuilder->weld_entry(
"entry"))
60 m_xLabel->set_grid_top_attach(nLine);
62 m_xEntry->set_grid_left_attach(1);
63 m_xEntry->set_grid_top_attach(nLine);
68 m_pGrid->
move(m_xEntry.get(),
nullptr);
86 std::vector<std::unique_ptr<SwAddressFragment>>
m_aLines;
106 , m_nCurrentDataSet(0)
108 , m_xScrollBar(rBuilder.weld_scrolled_window(
"scrollwin"))
109 , m_xWindow(rBuilder.weld_container(
"CONTAINER"))
125 sal_Int32 nLines = 0;
134 auto nLineHeight =
m_xWindow->get_preferred_size().Height();
166 "number of columns doesn't match number of Edits");
175 int x,
y, width, height;
176 rEdit.get_extents_relative_to(*m_xWindow,
x,
y, width, height);
185 auto nMinVisiblePos =
m_xScrollBar->vadjustment_get_value();
186 auto nMaxVisiblePos = nMinVisiblePos +
m_xScrollBar->vadjustment_get_page_size();
187 if (rRect.
Top() < nMinVisiblePos || rRect.
Bottom() > nMaxVisiblePos)
195 sal_Int32
nIndex = m_aEditLines[&rEdit];
197 OSL_ENSURE(
m_pData->aDBData.size() > m_nCurrentDataSet,
"wrong data set index" );
198 if (
m_pData->aDBData.size() > m_nCurrentDataSet)
200 m_pData->aDBData[m_nCurrentDataSet][
nIndex] = rEdit.get_text();
216 :
SfxDialogController(pParent,
"modules/swriter/ui/createaddresslist.ui",
"CreateAddressList")
217 , m_sAddressListFilterName(
SwResId(ST_FILTERNAME))
221 , m_xNewPB(m_xBuilder->weld_button(
"NEW"))
222 , m_xDeletePB(m_xBuilder->weld_button(
"DELETE"))
223 , m_xFindPB(m_xBuilder->weld_button(
"FIND"))
224 , m_xCustomizePB(m_xBuilder->weld_button(
"CUSTOMIZE"))
225 , m_xStartPB(m_xBuilder->weld_button(
"START"))
226 , m_xPrevPB(m_xBuilder->weld_button(
"PREV"))
227 , m_xSetNoED(m_xBuilder->weld_entry(
"SETNOED"))
228 , m_xSetNoNF(m_xBuilder->weld_spin_button(
"SETNOSB"))
229 , m_xNextPB(m_xBuilder->weld_button(
"NEXT"))
230 , m_xEndPB(m_xBuilder->weld_button(
"END"))
231 , m_xOK(m_xBuilder->weld_button(
"ok"))
262 if(bRead && !sLine.isEmpty())
268 OSL_ENSURE(sHeader.size() > 2 &&
270 "Wrong format of header");
271 if(sHeader.size() > 2)
273 m_pCSVData->aDBColumnHeaders.push_back( OUString(sHeader.substr(1, sHeader.size() -2)));
280 std::vector<OUString> aNewData;
282 sal_Int32
nIndex = { sLine.isEmpty() ? -1 : 0 };
285 const OUString sData = sLine.getToken( 0,
'\t',
nIndex );
286 OSL_ENSURE( sData.startsWith(
"\"") && sData.endsWith(
"\""),
287 "Wrong format of line");
288 if(sData.getLength() >= 2)
289 aNewData.push_back(sData.copy(1, sData.getLength() - 2));
291 aNewData.push_back(sData);
301 const sal_uInt32
nCount = rAddressHeader.size();
302 for(sal_uInt32 nHeader = 0; nHeader <
nCount; ++nHeader)
303 m_pCSVData->aDBColumnHeaders.push_back(rAddressHeader[nHeader].first);
304 std::vector<OUString> aNewData;
305 aNewData.insert(aNewData.begin(),
nCount, OUString());
325 sal_uInt32 nCurrent = m_xAddressControl->GetCurrentDataSet();
326 std::vector<OUString> aNewData;
327 aNewData.insert(aNewData.begin(), m_pCSVData->aDBColumnHeaders.size(), OUString());
328 m_pCSVData->aDBData.insert(m_pCSVData->aDBData.begin() + ++nCurrent, aNewData);
329 m_xSetNoNF->set_max(m_pCSVData->aDBData.size());
331 m_xSetNoNF->set_value(nCurrent + 1);
332 RefreshNum_Impl(*m_xSetNoED);
334 m_xAddressControl->SetCurrentDataSet(nCurrent);
340 sal_uInt32 nCurrent = m_xAddressControl->GetCurrentDataSet();
341 if (m_pCSVData->aDBData.size() > 1)
343 m_pCSVData->aDBData.erase(m_pCSVData->aDBData.begin() + nCurrent);
350 m_pCSVData->aDBData[0].assign(m_pCSVData->aDBData[0].size(), OUString());
351 m_xDeletePB->set_sensitive(
false);
353 m_xAddressControl->CurrentDataSetInvalidated();
354 m_xAddressControl->SetCurrentDataSet(nCurrent);
355 m_xSetNoNF->set_max(m_pCSVData->aDBData.size());
365 for(
const auto& rHeader : m_pCSVData->aDBColumnHeaders)
371 m_xFindDlg->set_visible(!m_xFindDlg->get_visible());
380 m_xAddressControl->SetData(*m_pCSVData);
381 m_xAddressControl->SetCurrentDataSet(m_xAddressControl->GetCurrentDataSet());
389 for(
const auto& rHeader : m_pCSVData->aDBColumnHeaders)
397void lcl_WriteValues(
const std::vector<OUString> *pFields,
SvStream* pStream)
399 OUStringBuffer sLine;
400 const std::vector< OUString >::const_iterator aBegin = pFields->begin();
401 const std::vector< OUString >::const_iterator aEnd = pFields->end();
402 for(std::vector< OUString >::const_iterator aIter = aBegin; aIter != aEnd; ++aIter)
406 sLine.append(
"\"" + *aIter +
"\"");
410 sLine.append(
"\t\"" + *aIter +
"\"");
425 uno::Reference < XFilePicker3 > xFP = aDlgHelper.
GetFilePicker();
426 xFP->appendFilter( m_sAddressListFilterName,
"*.csv" );
427 xFP->setCurrentFilter( m_sAddressListFilterName ) ;
431 m_sURL = xFP->getSelectedFiles().getConstArray()[0];
445 lcl_WriteValues(&(m_pCSVData->aDBColumnHeaders), pStream);
447 for(
const auto& rData : m_pCSVData->aDBData)
449 lcl_WriteValues(&rData, pStream);
457 int nValue = m_xSetNoNF->get_value();
459 if (&rButton == m_xStartPB.get())
461 else if (&rButton == m_xPrevPB.get())
466 else if (&rButton == m_xNextPB.get())
468 if (nValue < m_xSetNoNF->get_max())
472 nValue = m_xSetNoNF->get_max();
473 if (
nValue != m_xSetNoNF->get_value())
475 m_xSetNoNF->set_value(
nValue);
476 RefreshNum_Impl(*m_xSetNoED);
483 m_xSetNoNF->set_text(m_xSetNoED->get_text());
489 m_xSetNoED->set_text(OUString::number(m_xSetNoNF->get_value()));
500 sal_uInt32 nCurrent =
static_cast< sal_uInt32
>(
m_xSetNoNF->get_value() );
501 sal_uInt32 nSize =
static_cast<sal_uInt32
>(
m_pCSVData->aDBData.size());
504 m_xNextPB->set_sensitive(nCurrent != nSize);
505 m_xEndPB->set_sensitive(nCurrent != nSize);
511 const OUString sSearch = rSearch.toAsciiLowerCase();
515 sal_uInt32 nStart = nCurrent + 1;
517 std::size_t nElement = 0;
519 for(
short nTemp = 0; nTemp < 2 && !bFound; nTemp++)
525 bFound = -1 !=
aData[
static_cast<sal_uInt32
>(nColumn)].toAsciiLowerCase().indexOf(sSearch);
528 for( nElement = 0; nElement <
aData.size(); ++nElement)
530 bFound = -1 !=
aData[nElement].toAsciiLowerCase().indexOf(sSearch);
555 : GenericDialogController(pParent->getDialog(),
"modules/swriter/ui/findentrydialog.ui",
"FindEntryDialog")
557 , m_xFindED(m_xBuilder->weld_entry(
"entry"))
558 , m_xFindOnlyCB(m_xBuilder->weld_check_button(
"findin"))
559 , m_xFindOnlyLB(m_xBuilder->weld_combo_box(
"area"))
560 , m_xFindPB(m_xBuilder->weld_button(
"find"))
561 , m_xCancel(m_xBuilder->weld_button(
"cancel"))
574 sal_Int32 nColumn = -1;
575 if (m_xFindOnlyCB->get_active())
576 nColumn = m_xFindOnlyLB->get_active();
577 m_pParent->Find(m_xFindED->get_text(), nColumn);
582 m_xFindPB->set_sensitive(!m_xFindED->get_text().isEmpty());
Reference< XExecutableDialog > m_xDialog
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool setExtension(std::u16string_view rTheExtension, sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
SvStream * GetOutStream()
bool WriteByteStringLine(std::u16string_view rStr, rtl_TextEncoding eDestCharSet)
bool ReadByteStringLine(OUString &rStr, rtl_TextEncoding eSrcCharSet, sal_Int32 nMaxBytesToRead=0xFFFE)
void SetLineDelimiter(LineEnd eLineEnd)
void SetStreamCharSet(rtl_TextEncoding eCharSet)
void CurrentDataSetInvalidated()
SwAddressControl_Impl(weld::Builder &rBuilder)
std::unique_ptr< weld::Container > m_xWindow
std::unique_ptr< weld::ScrolledWindow > m_xScrollBar
void SetCursorTo(std::size_t nElement)
void MakeVisible(const tools::Rectangle &aRect)
void SetData(SwCSVData &rDBData)
sal_uInt32 m_nCurrentDataSet
sal_uInt32 GetCurrentDataSet() const
void SetCurrentDataSet(sal_uInt32 nSet)
std::vector< std::unique_ptr< SwAddressFragment > > m_aLines
std::map< weld::Entry *, sal_Int32 > m_aEditLines
DECL_LINK(GotFocusHdl_Impl, weld::Widget &, void)
DECL_LINK(EditModifyHdl_Impl, weld::Entry &, void)
std::unique_ptr< weld::Button > m_xFindPB
std::unique_ptr< weld::Button > m_xOK
void Find(const OUString &rSearch, sal_Int32 nColumn)
std::unique_ptr< weld::SpinButton > m_xSetNoNF
std::unique_ptr< weld::Button > m_xNewPB
virtual ~SwCreateAddressListDialog() override
std::unique_ptr< weld::Button > m_xDeletePB
std::unique_ptr< SwCSVData > m_pCSVData
std::unique_ptr< weld::Button > m_xNextPB
std::unique_ptr< SwAddressControl_Impl > m_xAddressControl
std::unique_ptr< weld::Button > m_xStartPB
SwCreateAddressListDialog(weld::Window *pParent, OUString aURL, SwMailMergeConfigItem const &rConfig)
std::unique_ptr< weld::Button > m_xEndPB
std::unique_ptr< weld::Entry > m_xSetNoED
std::unique_ptr< weld::Button > m_xPrevPB
std::unique_ptr< weld::Button > m_xCustomizePB
std::unique_ptr< SwCSVData > ReleaseNewData()
virtual ~SwFindEntryDialog() override
std::unique_ptr< weld::Button > m_xCancel
SwFindEntryDialog(SwCreateAddressListDialog *pParent)
std::unique_ptr< weld::Button > m_xFindPB
std::unique_ptr< weld::Entry > m_xFindED
const std::vector< std::pair< OUString, int > > & GetDefaultAddressHeaders() const
std::unique_ptr< weld::Label > m_xLabel
const css::uno::Reference< css::ui::dialogs::XFilePicker3 > & GetFilePicker() const
void SetContext(Context _eNewContext)
virtual void set_active(int pos)=0
void append_text(const OUString &rStr)
virtual void move(weld::Widget *pWidget, weld::Container *pNewParent)=0
virtual void connect_changed(const Link< Entry &, void > &rLink)
virtual void set_label(const OUString &rText)=0
IMPL_LINK_NOARG(SwCreateAddressListDialog, NewHdl_Impl, weld::Button &, void)
IMPL_LINK(SwAddressControl_Impl, GotFocusHdl_Impl, weld::Widget &, rEdit, void)
#define LINK(Instance, Class, Member)
constexpr OUStringLiteral aData
constexpr bool ends_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
std::vector< OUString > aDBColumnHeaders
std::vector< std::vector< OUString > > aDBData
OUString SwResId(TranslateId aId)