LibreOffice Module sw (master)  1
dbinsdlg.cxx
Go to the documentation of this file.
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 <dbinsdlg.hxx>
21 
22 #include <float.h>
23 
24 #include <hintids.hxx>
25 #include <com/sun/star/container/XNameAccess.hpp>
26 #include <com/sun/star/sdbc/XDataSource.hpp>
27 #include <com/sun/star/sdbc/XRow.hpp>
28 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
29 #include <com/sun/star/sdbcx/XRowLocate.hpp>
30 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
31 #include <com/sun/star/sdb/XColumn.hpp>
32 #include <com/sun/star/sdbc/DataType.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/util/NumberFormatter.hpp>
35 #include <com/sun/star/util/XNumberFormatTypes.hpp>
37 #include <comphelper/sequence.hxx>
38 #include <comphelper/types.hxx>
39 #include <svl/numuno.hxx>
40 #include <svl/numformat.hxx>
41 #include <svl/stritem.hxx>
42 #include <tools/diagnose_ex.h>
43 #include <vcl/mnemonic.hxx>
44 #include <svl/style.hxx>
45 #include <svl/zformat.hxx>
46 #include <sfx2/htmlmode.hxx>
47 #include <svl/itemset.hxx>
48 #include <editeng/brushitem.hxx>
49 #include <editeng/boxitem.hxx>
51 #include <fmtclds.hxx>
52 #include <tabcol.hxx>
53 #include <uiitems.hxx>
54 #include <viewopt.hxx>
55 #include <wrtsh.hxx>
56 #include <view.hxx>
57 #include <docsh.hxx>
58 #include <dbmgr.hxx>
59 #include <tblafmt.hxx>
60 #include <cellatr.hxx>
61 #include <swtablerep.hxx>
62 #include <dbfld.hxx>
63 #include <fmtcol.hxx>
64 #include <swwait.hxx>
65 #include <modcfg.hxx>
66 #include <swmodule.hxx>
67 #include <poolfmt.hxx>
68 #include <connectivity/dbtools.hxx>
69 
70 #include <cmdid.h>
71 #include <SwStyleNameMapper.hxx>
72 #include <tabsh.hxx>
73 #include <swabstdlg.hxx>
74 #include <strings.hrc>
75 #include <IDocumentMarkAccess.hxx>
76 
77 #include <o3tl/any.hxx>
78 
79 #include <memory>
80 #include <string_view>
81 
82 #include <swuiexp.hxx>
83 
84 using namespace ::dbtools;
85 using namespace ::com::sun::star;
86 using namespace ::com::sun::star::beans;
87 using namespace ::com::sun::star::container;
88 using namespace ::com::sun::star::lang;
89 using namespace ::com::sun::star::sdb;
90 using namespace ::com::sun::star::sdbc;
91 using namespace ::com::sun::star::sdbcx;
92 using namespace ::com::sun::star::uno;
93 
94 const char cDBFieldStart = '<';
95 const char cDBFieldEnd = '>';
96 
97 // Helper structure for adding database rows as fields or text
98 struct DB_Column
99 {
101 
102  union {
103  OUString* pText;
105  sal_uInt32 nFormat;
106  };
108 
109  DB_Column() : eColType(Type::SPLITPARA),
110  pText(nullptr),
111  pColInfo(nullptr)
112  {}
113 
114  explicit DB_Column( const OUString& rText )
115  : eColType(Type::FILLTEXT),
116  pText(new OUString(rText)),
117  pColInfo(nullptr)
118  {}
119 
120  DB_Column( const SwInsDBColumn& rInfo, sal_uInt32 nFormat_ )
121  : eColType(Type::COL_TEXT),
122  nFormat(nFormat_),
123  pColInfo(&rInfo)
124  {}
125 
126  DB_Column( const SwInsDBColumn& rInfo, SwDBField& rField )
127  : eColType(Type::COL_FIELD),
128  pField(&rField),
129  pColInfo(&rInfo)
130  {}
131 
133  {
134  if( Type::COL_FIELD == eColType )
135  delete pField;
136  else if( Type::FILLTEXT == eColType )
137  delete pText;
138  }
139 };
140 
141 namespace {
142 
143 struct DB_ColumnConfigData
144 {
145  SwInsDBColumns aDBColumns;
146  OUString sEdit;
147  OUString sTableList;
148  OUString sTmplNm;
149  OUString sTAutoFormatNm;
150  bool bIsTable : 1,
151  bIsField : 1,
152  bIsHeadlineOn : 1,
153  bIsEmptyHeadln : 1;
154 
155  DB_ColumnConfigData(DB_ColumnConfigData const&) = delete;
156  DB_ColumnConfigData& operator=(DB_ColumnConfigData const&) = delete;
157 
158  DB_ColumnConfigData()
159  {
160  bIsTable = bIsHeadlineOn = true;
161  bIsField = bIsEmptyHeadln = false;
162  }
163 };
164 
165 }
166 
167 bool SwInsDBColumn::operator<( const SwInsDBColumn& rCmp ) const
168 {
169  return 0 > GetAppCollator().compareString( sColumn, rCmp.sColumn );
170 }
171 
173  Reference<XDataSource> const & xDataSource,
174  Reference<sdbcx::XColumnsSupplier> const & xColSupp,
175  const SwDBData& rData )
176  : SfxDialogController(rView.GetWindow()->GetFrameWeld(), "modules/swriter/ui/insertdbcolumnsdialog.ui", "InsertDbColumnsDialog")
177  , ConfigItem("Office.Writer/InsertData/DataSet", ConfigItemMode::NONE)
178  , aDBData(rData)
179  , sNoTmpl(SwResId(SW_STR_NONE))
180  , pView(&rView)
181  , m_xRbAsTable(m_xBuilder->weld_radio_button("astable"))
182  , m_xRbAsField(m_xBuilder->weld_radio_button("asfields"))
183  , m_xRbAsText(m_xBuilder->weld_radio_button("astext"))
184  , m_xHeadFrame(m_xBuilder->weld_frame("dbframe"))
185  , m_xLbTableDbColumn(m_xBuilder->weld_tree_view("tabledbcols"))
186  , m_xLbTextDbColumn(m_xBuilder->weld_tree_view("tabletxtcols"))
187  , m_xFormatFrame(m_xBuilder->weld_frame("formatframe"))
188  , m_xRbDbFormatFromDb(m_xBuilder->weld_radio_button("fromdatabase"))
189  , m_xRbDbFormatFromUsr(m_xBuilder->weld_radio_button("userdefined"))
190  , m_xLbDbFormatFromUsr(new NumFormatListBox(m_xBuilder->weld_combo_box("numformat")))
191  , m_xIbDbcolToEdit(m_xBuilder->weld_button("toedit"))
192  , m_xEdDbText(m_xBuilder->weld_text_view("textview"))
193  , m_xFtDbParaColl(m_xBuilder->weld_label("parastylelabel"))
194  , m_xLbDbParaColl(m_xBuilder->weld_combo_box("parastyle"))
195  , m_xIbDbcolAllTo(m_xBuilder->weld_button("oneright"))
196  , m_xIbDbcolOneTo(m_xBuilder->weld_button("allright"))
197  , m_xIbDbcolOneFrom(m_xBuilder->weld_button("oneleft"))
198  , m_xIbDbcolAllFrom(m_xBuilder->weld_button("allleft"))
199  , m_xFtTableCol(m_xBuilder->weld_label("tablecolft"))
200  , m_xLbTableCol(m_xBuilder->weld_tree_view("tablecols"))
201  , m_xCbTableHeadon(m_xBuilder->weld_check_button("tableheading"))
202  , m_xRbHeadlColnms(m_xBuilder->weld_radio_button("columnname"))
203  , m_xRbHeadlEmpty(m_xBuilder->weld_radio_button("rowonly"))
204  , m_xPbTableFormat(m_xBuilder->weld_button("tableformat"))
205  , m_xPbTableAutofmt(m_xBuilder->weld_button("autoformat"))
206 {
207  m_xEdDbText->set_size_request(m_xEdDbText->get_approximate_digit_width() * 40, -1);
208  m_xLbDbParaColl->make_sorted();
209 
210  nGBFormatLen = m_xFormatFrame->get_label().getLength();
211 
212  if (xColSupp.is())
213  {
214  SwWrtShell& rSh = pView->GetWrtShell();
215  SvNumberFormatter* pNumFormatr = rSh.GetNumberFormatter();
217  Reference< util::XNumberFormats > xDocNumberFormats = pNumFormat->getNumberFormats();
218  Reference< util::XNumberFormatTypes > xDocNumberFormatTypes(xDocNumberFormats, UNO_QUERY);
219 
220  Reference<XPropertySet> xSourceProps(xDataSource, UNO_QUERY);
221  Reference< util::XNumberFormats > xNumberFormats;
222  if(xSourceProps.is())
223  {
224  Any aFormats = xSourceProps->getPropertyValue("NumberFormatsSupplier");
225  if(aFormats.hasValue())
226  {
227  Reference< util::XNumberFormatsSupplier> xSuppl;
228  aFormats >>= xSuppl;
229  if(xSuppl.is())
230  {
231  xNumberFormats = xSuppl->getNumberFormats( );
232  }
233  }
234  }
235  Reference <XNameAccess> xCols = xColSupp->getColumns();
236  const Sequence<OUString> aColNames = xCols->getElementNames();
237  for (const OUString& rColName : aColNames)
238  {
239  std::unique_ptr<SwInsDBColumn> pNew(new SwInsDBColumn( rColName ));
240  Any aCol = xCols->getByName(rColName);
242  aCol >>= xCol;
243  Any aType = xCol->getPropertyValue("Type");
244  sal_Int32 eDataType = 0;
245  aType >>= eDataType;
246  switch(eDataType)
247  {
248  case DataType::BIT:
249  case DataType::BOOLEAN:
250  case DataType::TINYINT:
251  case DataType::SMALLINT:
252  case DataType::INTEGER:
253  case DataType::BIGINT:
254  case DataType::FLOAT:
255  case DataType::REAL:
256  case DataType::DOUBLE:
257  case DataType::NUMERIC:
258  case DataType::DECIMAL:
259  case DataType::DATE:
260  case DataType::TIME:
261  case DataType::TIMESTAMP:
262  {
263  pNew->bHasFormat = true;
264  Any aFormat = xCol->getPropertyValue("FormatKey");
265  if(aFormat.hasValue())
266  {
267  sal_Int32 nFormat = 0;
268  aFormat >>= nFormat;
269  if(xNumberFormats.is())
270  {
271  try
272  {
273  Reference<XPropertySet> xNumProps = xNumberFormats->getByKey( nFormat );
274  Any aFormatVal = xNumProps->getPropertyValue("FormatString");
275  Any aLocale = xNumProps->getPropertyValue("Locale");
276  OUString sFormat;
277  aFormatVal >>= sFormat;
278  lang::Locale aLoc;
279  aLocale >>= aLoc;
280  sal_Int32 nKey = xDocNumberFormats->queryKey( sFormat, aLoc, true);
281  if(nKey < 0)
282  {
283  nKey = xDocNumberFormats->addNew( sFormat, aLoc );
284  }
285  pNew->nDBNumFormat = nKey;
286  }
287  catch (const Exception&)
288  {
289  OSL_FAIL("illegal number format key");
290  }
291  }
292  }
293  else
294  {
295  pNew->nDBNumFormat = getDefaultNumberFormat(xCol,
296  xDocNumberFormatTypes, LanguageTag( rSh.GetCurLang() ).getLocale());
297  }
298 
299  }
300  break;
301  }
302  if( !aDBColumns.insert( std::move(pNew) ).second )
303  {
304  OSL_ENSURE( false, "Spaltenname mehrfach vergeben?" );
305  }
306  }
307  }
308 
309  // fill paragraph templates-ListBox
310  {
312  m_xLbDbParaColl->append_text( sNoTmpl );
313 
314  const SfxStyleSheetBase* pBase = pPool->First(SfxStyleFamily::Para);
315  while( pBase )
316  {
317  m_xLbDbParaColl->append_text( pBase->GetName() );
318  pBase = pPool->Next();
319  }
320  m_xLbDbParaColl->set_active( 0 );
321  }
322 
323  // when the cursor is inside of a table, table must NEVER be selectable
324  if( pView->GetWrtShell().GetTableFormat() )
325  {
326  m_xRbAsField->set_active(true);
327  m_xRbAsTable->set_sensitive(false);
328  m_xRbDbFormatFromDb->set_active(true);
329  }
330  else
331  {
332  m_xRbAsTable->set_active(true);
333  m_xRbDbFormatFromDb->set_active(true);
334  m_xIbDbcolOneFrom->set_sensitive( false );
335  m_xIbDbcolAllFrom->set_sensitive( false );
336  }
337 
338  // by default, select header button
339  m_xRbHeadlColnms->set_active(true);
340  m_xRbHeadlEmpty->set_active(false);
341 
342  m_xRbAsTable->connect_toggled( LINK(this, SwInsertDBColAutoPilot, PageHdl ));
343  m_xRbAsField->connect_toggled( LINK(this, SwInsertDBColAutoPilot, PageHdl ));
344  m_xRbAsText->connect_toggled( LINK(this, SwInsertDBColAutoPilot, PageHdl ));
345 
346  m_xRbDbFormatFromDb->connect_toggled( LINK(this, SwInsertDBColAutoPilot, DBFormatHdl ));
347  m_xRbDbFormatFromUsr->connect_toggled( LINK(this, SwInsertDBColAutoPilot, DBFormatHdl ));
348 
349  m_xPbTableFormat->connect_clicked(LINK(this, SwInsertDBColAutoPilot, TableFormatHdl ));
350  m_xPbTableAutofmt->connect_clicked(LINK(this, SwInsertDBColAutoPilot, AutoFormatHdl ));
351 
352  m_xIbDbcolAllTo->connect_clicked( LINK(this, SwInsertDBColAutoPilot, TableToFromHdl ));
353  m_xIbDbcolOneTo->connect_clicked( LINK(this, SwInsertDBColAutoPilot, TableToFromHdl ));
354  m_xIbDbcolOneFrom->connect_clicked( LINK(this, SwInsertDBColAutoPilot, TableToFromHdl ));
355  m_xIbDbcolAllFrom->connect_clicked( LINK(this, SwInsertDBColAutoPilot, TableToFromHdl ));
356  m_xIbDbcolToEdit->connect_clicked( LINK(this, SwInsertDBColAutoPilot, TableToFromHdl ));
357 
358  m_xCbTableHeadon->connect_toggled( LINK(this, SwInsertDBColAutoPilot, HeaderHdl ));
359 
360  m_xLbTextDbColumn->connect_changed( LINK( this, SwInsertDBColAutoPilot, TVSelectHdl ));
361  m_xLbTableDbColumn->connect_changed( LINK( this, SwInsertDBColAutoPilot, TVSelectHdl ));
362  m_xLbDbFormatFromUsr->connect_changed( LINK( this, SwInsertDBColAutoPilot, CBSelectHdl ));
363  m_xLbTableCol->connect_changed( LINK( this, SwInsertDBColAutoPilot, TVSelectHdl ));
364 
365  m_xLbTextDbColumn->connect_row_activated( LINK( this, SwInsertDBColAutoPilot, DblClickHdl ));
366  m_xLbTableDbColumn->connect_row_activated( LINK( this, SwInsertDBColAutoPilot, DblClickHdl ));
367  m_xLbTableCol->connect_row_activated( LINK( this, SwInsertDBColAutoPilot, DblClickHdl ));
368 
369  for( size_t n = 0; n < aDBColumns.size(); ++n )
370  {
371  const OUString& rS = aDBColumns[ n ]->sColumn;
372  m_xLbTableDbColumn->append_text(rS);
373  m_xLbTextDbColumn->append_text(rS);
374  }
375  m_xLbTextDbColumn->select(0);
376  m_xLbTableDbColumn->select(0);
377 
378  // read configuration
379  Load();
380 
381  // lock size to widest config
382  m_xHeadFrame->set_size_request(m_xHeadFrame->get_preferred_size().Width(), -1);
383  // initialise Controls:
384  PageHdl(m_xRbAsTable->get_active() ? *m_xRbAsTable : *m_xRbAsField);
385 }
386 
388 {
389 }
390 
392 {
393  if (!rButton.get_active())
394  return;
395 
396  bool bShowTable = m_xRbAsTable->get_active();
397 
398  weld::RadioButton& rRadio = dynamic_cast<weld::RadioButton&>(rButton);
399  m_xHeadFrame->set_label(MnemonicGenerator::EraseAllMnemonicChars(rRadio.get_label().replace('_', '~')));
400 
401  m_xLbTextDbColumn->set_visible( !bShowTable );
402  m_xIbDbcolToEdit->set_visible( !bShowTable );
403  m_xEdDbText->set_visible( !bShowTable );
404  m_xFtDbParaColl->set_visible( !bShowTable );
405  m_xLbDbParaColl->set_visible( !bShowTable );
406 
407  m_xLbTableDbColumn->set_visible( bShowTable );
408  m_xIbDbcolAllTo->set_visible( bShowTable );
409  m_xIbDbcolOneTo->set_visible( bShowTable );
410  m_xIbDbcolOneFrom->set_visible( bShowTable );
411  m_xIbDbcolAllFrom->set_visible( bShowTable );
412  m_xFtTableCol->set_visible( bShowTable );
413  m_xLbTableCol->set_visible( bShowTable );
414  m_xCbTableHeadon->set_visible( bShowTable );
415  m_xRbHeadlColnms->set_visible( bShowTable );
416  m_xRbHeadlEmpty->set_visible( bShowTable );
417  m_xPbTableFormat->set_visible( bShowTable );
418  m_xPbTableAutofmt->set_visible( bShowTable );
419 
420  if( bShowTable )
421  m_xPbTableFormat->set_sensitive( 0 != m_xLbTableCol->n_children() );
422 
423  TVSelectHdl( bShowTable ? *m_xLbTableDbColumn : *m_xLbTextDbColumn );
424 }
425 
426 IMPL_LINK( SwInsertDBColAutoPilot, DBFormatHdl, weld::Toggleable&, rButton, void )
427 {
428  if (!rButton.get_active())
429  return;
430 
431  weld::TreeView& rBox = m_xRbAsTable->get_active()
432  ? ( m_xLbTableCol->get_id(0).isEmpty()
433  ? *m_xLbTableDbColumn
434  : *m_xLbTableCol )
435  : *m_xLbTextDbColumn;
436 
437  SwInsDBColumn aSrch(rBox.get_selected_text());
438  SwInsDBColumns::const_iterator it = aDBColumns.find( &aSrch );
439 
440  bool bFromDB = m_xRbDbFormatFromDb->get_active();
441  (*it)->bIsDBFormat = bFromDB;
442  m_xLbDbFormatFromUsr->set_sensitive( !bFromDB );
443 }
444 
445 IMPL_LINK( SwInsertDBColAutoPilot, TableToFromHdl, weld::Button&, rButton, void )
446 {
447  bool bChgEnable = true, bEnableTo = true, bEnableFrom = true;
448 
449  if( &rButton == m_xIbDbcolAllTo.get() )
450  {
451  bEnableTo = false;
452 
453  sal_Int32 n, nInsPos = m_xLbTableCol->get_selected_index(),
454  nCnt = m_xLbTableDbColumn->n_children();
455 
456  m_xLbTableDbColumn->unselect_all();
457 
458  m_xLbTableDbColumn->freeze();
459  m_xLbTableCol->freeze();
460 
461  if (nInsPos == -1)
462  for( n = 0; n < nCnt; ++n )
463  m_xLbTableCol->append_text(m_xLbTableDbColumn->get_text(n));
464  else
465  for( n = 0; n < nCnt; ++n, ++nInsPos )
466  m_xLbTableCol->insert_text(nInsPos, m_xLbTableDbColumn->get_text(n));
467  m_xLbTableDbColumn->clear();
468 
469  m_xLbTableDbColumn->thaw();
470  m_xLbTableCol->thaw();
471 
472  m_xLbTableCol->select(nInsPos);
473  }
474  else if( &rButton == m_xIbDbcolOneTo.get() &&
475  m_xLbTableDbColumn->get_selected_index() != -1 )
476  {
477  sal_Int32 nInsPos = m_xLbTableCol->get_selected_index(),
478  nDelPos = m_xLbTableDbColumn->get_selected_index();
479  m_xLbTableCol->insert_text(nInsPos, m_xLbTableDbColumn->get_text(nDelPos));
480  m_xLbTableDbColumn->remove(nDelPos);
481 
482  m_xLbTableCol->select(nInsPos);
483  if (nDelPos >= m_xLbTableDbColumn->n_children())
484  nDelPos = m_xLbTableDbColumn->n_children() - 1;
485  m_xLbTableDbColumn->select(nDelPos);
486 
487  bEnableTo = 0 != m_xLbTableDbColumn->n_children();
488  }
489  else if( &rButton == m_xIbDbcolOneFrom.get() )
490  {
491  if (m_xLbTableCol->get_selected_index() != -1)
492  {
493  sal_Int32 nInsPos,
494  nDelPos = m_xLbTableCol->get_selected_index();
495 
496  // look for the right InsertPos!!
497  SwInsDBColumn aSrch(m_xLbTableCol->get_text(nDelPos));
498  SwInsDBColumns::const_iterator it = aDBColumns.find( &aSrch );
499  if( it == aDBColumns.begin() || (it+1) == aDBColumns.end() )
500  nInsPos = it - aDBColumns.begin();
501  else
502  {
503  nInsPos = -1;
504  while( ++it != aDBColumns.end() &&
505  -1 == (nInsPos = m_xLbTableDbColumn->
506  find_text( (*it)->sColumn )) )
507  ;
508  }
509 
510  m_xLbTableDbColumn->insert_text(nInsPos, aSrch.sColumn);
511  m_xLbTableCol->remove( nDelPos );
512 
513  if (nInsPos >= m_xLbTableDbColumn->n_children())
514  nInsPos = m_xLbTableDbColumn->n_children() - 1;
515  m_xLbTableDbColumn->select(nInsPos);
516 
517  if (nDelPos >= m_xLbTableCol->n_children())
518  nDelPos = m_xLbTableCol->n_children() - 1;
519  m_xLbTableCol->select(nDelPos);
520  }
521  else
522  bEnableTo = 0 != m_xLbTableDbColumn->n_children();
523 
524  bEnableFrom = 0 != m_xLbTableCol->n_children();
525  }
526  else if( &rButton == m_xIbDbcolAllFrom.get() )
527  {
528  bEnableFrom = false;
529 
530  m_xLbTableDbColumn->freeze();
531  m_xLbTableCol->freeze();
532 
533  m_xLbTableDbColumn->clear();
534  m_xLbTableCol->clear();
535  for (size_t n = 0; n < aDBColumns.size(); ++n)
536  m_xLbTableDbColumn->append_text(aDBColumns[n]->sColumn);
537 
538  m_xLbTableDbColumn->thaw();
539  m_xLbTableCol->thaw();
540 
541  m_xLbTableDbColumn->select(0);
542  }
543  else if( &rButton == m_xIbDbcolToEdit.get() )
544  {
545  bChgEnable = false;
546  // move data to Edit:
547  OUString aField(m_xLbTextDbColumn->get_selected_text());
548  if( !aField.isEmpty() )
549  {
550  OUString aStr( m_xEdDbText->get_text() );
551  int nStartPos, nEndPos;
552  m_xEdDbText->get_selection_bounds(nStartPos, nEndPos);
553  sal_Int32 nPos = std::min(nStartPos, nEndPos);
554  sal_Int32 nMax = std::max(nStartPos, nEndPos);
555  const sal_Int32 nSel = nMax - nPos;
556  if( nSel )
557  // first delete the existing selection
558  aStr = aStr.replaceAt( nPos, nSel, "" );
559 
560  aField = OUStringChar(cDBFieldStart) + aField + OUStringChar(cDBFieldEnd);
561  if( !aStr.isEmpty() )
562  {
563  if( nPos ) // one blank in front
564  {
565  sal_Unicode c = aStr[ nPos-1 ];
566  if( '\n' != c && '\r' != c )
567  aField = " " + aField;
568  }
569  if( nPos < aStr.getLength() ) // one blank behind
570  {
571  sal_Unicode c = aStr[ nPos ];
572  if( '\n' != c && '\r' != c )
573  aField += " ";
574  }
575  }
576 
577  m_xEdDbText->set_text( aStr.replaceAt( nPos, 0, aField ) );
578  nPos += aField.getLength();
579  m_xEdDbText->select_region(nPos, nPos);
580  }
581  }
582 
583  if( !bChgEnable )
584  return;
585 
586  m_xIbDbcolOneTo->set_sensitive( bEnableTo );
587  m_xIbDbcolAllTo->set_sensitive( bEnableTo );
588  m_xIbDbcolOneFrom->set_sensitive( bEnableFrom );
589  m_xIbDbcolAllFrom->set_sensitive( bEnableFrom );
590 
591  m_xRbDbFormatFromDb->set_sensitive( false );
592  m_xRbDbFormatFromUsr->set_sensitive( false );
593  m_xLbDbFormatFromUsr->set_sensitive( false );
594 
595  m_xPbTableFormat->set_sensitive( bEnableFrom );
596 }
597 
599 {
600  weld::Button* pButton = nullptr;
601  if( &rBox == m_xLbTextDbColumn.get() )
602  pButton = m_xIbDbcolToEdit.get();
603  else if( &rBox == m_xLbTableDbColumn.get() && m_xIbDbcolOneTo->get_sensitive() )
604  pButton = m_xIbDbcolOneTo.get();
605  else if( &rBox == m_xLbTableCol.get() && m_xIbDbcolOneFrom->get_sensitive() )
606  pButton = m_xIbDbcolOneFrom.get();
607 
608  if (pButton)
609  TableToFromHdl(*pButton);
610 
611  return true;
612 }
613 
615 {
616  SwWrtShell& rSh = pView->GetWrtShell();
617  bool bNewSet = false;
618  if( !pTableSet )
619  {
620  bNewSet = true;
621  pTableSet.reset(new SfxItemSet( rSh.GetAttrPool(), SwuiGetUITableAttrRange() ));
622 
623  // At first acquire the simple attributes
624  pTableSet->Put( SfxStringItem( FN_PARAM_TABLE_NAME, rSh.GetUniqueTableName() ));
625  pTableSet->Put( SfxUInt16Item( FN_PARAM_TABLE_HEADLINE, 1 ) );
626 
627  pTableSet->Put( SfxUInt16Item( SID_BACKGRND_DESTINATION,
628  rSh.GetViewOptions()->GetTableDest() ));
629 
630  SvxBrushItem aBrush( RES_BACKGROUND );
631  pTableSet->Put( aBrush );
632  aBrush.SetWhich(SID_ATTR_BRUSH_ROW);
633  pTableSet->Put( aBrush );
634  aBrush.SetWhich(SID_ATTR_BRUSH_TABLE);
635  pTableSet->Put( aBrush );
636 
637  SvxBoxInfoItem aBoxInfo( SID_ATTR_BORDER_INNER );
638  // table variant, when multiple table cells are selected
639  aBoxInfo.SetTable( true );
640  // always show gap field
641  aBoxInfo.SetDist( true);
642  // set minimum size in tables and paragraphs
643  aBoxInfo.SetMinDist( false );
644  // always set default-gap
645  aBoxInfo.SetDefDist( MIN_BORDER_DIST );
646  // Single lines can have DontCare-status only in tables
647  aBoxInfo.SetValid( SvxBoxInfoItemValidFlags::DISABLE );
648  pTableSet->Put( aBoxInfo );
649 
650  SwGetCurColNumPara aPara;
651  const sal_uInt16 nNum = rSh.GetCurColNum( &aPara );
652  tools::Long nWidth;
653 
654  if( nNum )
655  {
656  nWidth = aPara.pPrtRect->Width();
657  const SwFormatCol& rCol = aPara.pFrameFormat->GetCol();
658  const SwColumns& rCols = rCol.GetColumns();
659 
660  // initialise nStart and nEnd for nNum == 0
661  tools::Long nWidth1 = 0,
662  nStart1 = 0,
663  nEnd1 = nWidth;
664  for( sal_uInt16 i = 0; i < nNum; ++i )
665  {
666  const SwColumn* pCol = &rCols[i];
667  nStart1 = pCol->GetLeft() + nWidth1;
668  nWidth1 += static_cast<tools::Long>(rCol.CalcColWidth( i, o3tl::narrowing<sal_uInt16>(nWidth) ));
669  nEnd1 = nWidth1 - pCol->GetRight();
670  }
671  if(nStart1 || nEnd1 != nWidth)
672  nWidth = nEnd1 - nStart1;
673  }
674  else
675  nWidth = rSh.GetAnyCurRect(
676  (FrameTypeFlags::FLY_ANY & rSh.GetFrameType( nullptr, true ))
679 
680  SwTabCols aTabCols;
681  aTabCols.SetRight( nWidth );
682  aTabCols.SetRightMax( nWidth );
683  pRep.reset(new SwTableRep( aTabCols ));
684  pRep->SetAlign( text::HoriOrientation::NONE );
685  pRep->SetSpace( nWidth );
686  pRep->SetWidth( nWidth );
687  pRep->SetWidthPercent( 100 );
688  pTableSet->Put( SwPtrItem( FN_TABLE_REP, pRep.get() ));
689 
690  pTableSet->Put( SfxUInt16Item( SID_HTML_MODE,
691  ::GetHtmlMode( pView->GetDocShell() )));
692  }
693 
694  sal_Int32 nCols = m_xLbTableCol->n_children();
695  if (nCols != pRep->GetAllColCount() && nCols > 0)
696  {
697  // Number of columns has changed: then the TabCols have to be adjusted
698  tools::Long nWidth = pRep->GetWidth();
699  --nCols;
700  SwTabCols aTabCols( nCols );
701  aTabCols.SetRight( nWidth );
702  aTabCols.SetRightMax( nWidth );
703  if( nCols )
704  {
705  const sal_Int32 nStep = nWidth / (nCols+1);
706  for( sal_Int32 n = 0; n < nCols; ++n )
707  {
708  aTabCols.Insert( nStep*(n+1), false, n );
709  }
710  }
711  pRep.reset(new SwTableRep( aTabCols ));
712  pRep->SetAlign( text::HoriOrientation::NONE );
713  pRep->SetSpace( nWidth );
714  pRep->SetWidth( nWidth );
715  pRep->SetWidthPercent( 100 );
716  pTableSet->Put( SwPtrItem( FN_TABLE_REP, pRep.get() ));
717  }
718 
720 
721  ScopedVclPtr<SfxAbstractTabDialog> pDlg(rFact.CreateSwTableTabDlg(m_xDialog.get(), pTableSet.get(), &rSh));
722  if( RET_OK == pDlg->Execute() )
723  pTableSet->Put( *pDlg->GetOutputItemSet() );
724  else if( bNewSet )
725  {
726  pTableSet.reset();
727  pRep.reset();
728  }
729 }
730 
732 {
734 
735  ScopedVclPtr<AbstractSwAutoFormatDlg> pDlg(rFact.CreateSwAutoFormatDlg(m_xDialog.get(), pView->GetWrtShellPtr(), false, m_xTAutoFormat.get()));
736  if( RET_OK == pDlg->Execute())
737  m_xTAutoFormat = pDlg->FillAutoFormatOfIndex();
738 }
739 
741 {
742  weld::TreeView* pGetBox = &rBox;
743 
744  SwInsDBColumn aSrch(pGetBox->get_selected_text());
745  SwInsDBColumns::const_iterator it = aDBColumns.find( &aSrch );
746 
747  // set the selected FieldName at the FormatGroupBox, so that
748  // it's clear what field is configured by the format!
749  OUString sText( m_xFormatFrame->get_label().copy( 0, nGBFormatLen ));
750  if( aSrch.sColumn.isEmpty() )
751  {
752  m_xRbDbFormatFromDb->set_sensitive( false );
753  m_xRbDbFormatFromUsr->set_sensitive( false );
754  m_xLbDbFormatFromUsr->set_sensitive( false );
755  }
756  else
757  {
758  bool bEnableFormat = (*it)->bHasFormat;
759  m_xRbDbFormatFromDb->set_sensitive( bEnableFormat );
760  m_xRbDbFormatFromUsr->set_sensitive( bEnableFormat );
761 
762  if( bEnableFormat )
763  {
764  sText += " (" + aSrch.sColumn + ")";
765  }
766 
767  bool bIsDBFormat = (*it)->bIsDBFormat;
768  m_xRbDbFormatFromDb->set_active( bIsDBFormat );
769  m_xRbDbFormatFromUsr->set_active( !bIsDBFormat );
770  m_xLbDbFormatFromUsr->set_sensitive( !bIsDBFormat );
771  if( !bIsDBFormat )
772  m_xLbDbFormatFromUsr->SetDefFormat( (*it)->nUsrNumFormat );
773  }
774 
775  m_xFormatFrame->set_label(sText);
776 
777  if (m_xLbTableCol->n_children())
778  {
779  // to know later on, what ListBox was the "active", a Flag
780  // is remembered in the 1st entry
781  if (&rBox == m_xLbTableCol.get())
782  m_xLbTableCol->set_id(0, "tablecols");
783  else
784  m_xLbTableCol->set_id(0, OUString());
785  }
786 }
787 
789 {
790  weld::TreeView* pGetBox = m_xRbAsTable->get_active()
791  ? ( m_xLbTableCol->get_id(0).isEmpty()
792  ? m_xLbTableDbColumn.get()
793  : m_xLbTableCol.get() )
794  : m_xLbTextDbColumn.get();
795 
796  SwInsDBColumn aSrch(pGetBox->get_selected_text());
797  SwInsDBColumns::const_iterator it = aDBColumns.find( &aSrch );
798 
799  if( !aSrch.sColumn.isEmpty() )
800  {
801  m_xLbDbFormatFromUsr->CallSelectHdl();
802  (*it)->nUsrNumFormat = m_xLbDbFormatFromUsr->GetFormat();
803  }
804 }
805 
807 {
808  bool bEnable = m_xCbTableHeadon->get_active();
809  m_xRbHeadlColnms->set_sensitive( bEnable );
810  m_xRbHeadlEmpty->set_sensitive( bEnable );
811 }
812 
813 static void lcl_InsTextInArr( const OUString& rText, DB_Columns& rColArr )
814 {
815  sal_Int32 nSttPos = 0, nFndPos;
816  while( -1 != ( nFndPos = rText.indexOf( '\x0A', nSttPos )) )
817  {
818  if( 1 < nFndPos )
819  {
820  rColArr.push_back(std::make_unique<DB_Column>(rText.copy(nSttPos, nFndPos -1)));
821  }
822  rColArr.push_back(std::make_unique<DB_Column>());
823  nSttPos = nFndPos + 1;
824  }
825  if( nSttPos < rText.getLength() )
826  {
827  rColArr.push_back(std::make_unique<DB_Column>(rText.copy(nSttPos)));
828  }
829 }
830 
831 bool SwInsertDBColAutoPilot::SplitTextToColArr( const OUString& rText,
832  DB_Columns& rColArr,
833  bool bInsField )
834 {
835  // create each of the database columns from the text again
836  // and then save in an array
837  // database columns are in <> and must be present in the columns' array:
838  OUString sText( rText );
839  sal_Int32 nFndPos, nEndPos, nSttPos = 0;
840 
841  while( -1 != ( nFndPos = sText.indexOf( cDBFieldStart, nSttPos )))
842  {
843  nSttPos = nFndPos + 1;
844  nEndPos = sText.indexOf( cDBFieldEnd, nSttPos+1 );
845  if( -1 != nEndPos )
846  {
847  // Text in <> brackets found: what is it:
848  SwInsDBColumn aSrch( sText.copy( nSttPos, nEndPos - nSttPos ));
850  if( it != aDBColumns.end() )
851  {
852  // that is a valid field
853  // so surely the text "before":
854  const SwInsDBColumn& rFndCol = **it;
855 
856  DB_Column* pNew;
857 
858  if( 1 < nSttPos )
859  {
860  ::lcl_InsTextInArr( sText.copy( 0, nSttPos-1 ), rColArr );
861  sText = sText.copy( nSttPos-1 );
862  }
863 
864  sText = sText.copy( rFndCol.sColumn.getLength() + 2 );
865  nSttPos = 0;
866 
867  sal_uInt16 nSubType = 0;
868  sal_uInt32 nFormat;
869  if( rFndCol.bHasFormat )
870  {
871  if( rFndCol.bIsDBFormat )
872  nFormat = static_cast<sal_uInt32>(rFndCol.nDBNumFormat);
873  else
874  {
875  nFormat = rFndCol.nUsrNumFormat;
877  }
878  }
879  else
880  nFormat = 0;
881 
882  if( bInsField )
883  {
884  SwWrtShell& rSh = pView->GetWrtShell();
885  SwDBFieldType aFieldType( rSh.GetDoc(), aSrch.sColumn,
886  aDBData );
887  pNew = new DB_Column( rFndCol, *new SwDBField(
888  static_cast<SwDBFieldType*>(rSh.InsertFieldType( aFieldType )),
889  nFormat ) );
890  if( nSubType )
891  pNew->pField->SetSubType( nSubType );
892  }
893  else
894  pNew = new DB_Column( rFndCol, nFormat );
895 
896  rColArr.push_back( std::unique_ptr<DB_Column>(pNew) );
897  }
898  }
899  }
900 
901  // don't forget the last text
902  if( !sText.isEmpty() )
903  ::lcl_InsTextInArr( sText, rColArr );
904 
905  return !rColArr.empty();
906 }
907 
908 void SwInsertDBColAutoPilot::DataToDoc( const Sequence<Any>& rSelection,
909  Reference< XDataSource> const & xSource,
910  Reference< XConnection> const & xConnection,
911  Reference< sdbc::XResultSet > const & xResultSet_in )
912 {
913  auto xResultSet = xResultSet_in;
914 
915  const Any* pSelection = rSelection.hasElements() ? rSelection.getConstArray() : nullptr;
916  SwWrtShell& rSh = pView->GetWrtShell();
917 
918  //with the drag and drop interface no result set is initially available
919  bool bDisposeResultSet = false;
920  // we don't have a cursor, so we have to create our own RowSet
921  if ( !xResultSet.is() )
922  {
924  bDisposeResultSet = xResultSet.is();
925  }
926 
927  Reference< sdbc::XRow > xRow(xResultSet, UNO_QUERY);
928  if ( !xRow.is() )
929  return;
930 
931  rSh.StartAllAction();
932  bool bUndo = rSh.DoesUndo();
933  if( bUndo )
934  rSh.StartUndo();
935 
936  bool bAsTable = m_xRbAsTable->get_active();
937  SvNumberFormatter& rNumFormatr = *rSh.GetNumberFormatter();
938 
939  if( rSh.HasSelection() )
940  rSh.DelRight();
941 
942  std::unique_ptr<SwWait> pWait;
943 
944  Reference< XColumnsSupplier > xColsSupp( xResultSet, UNO_QUERY );
945  Reference <XNameAccess> xCols = xColsSupp->getColumns();
946 
947  uno::Reference<sdbcx::XRowLocate> xRowLocate(xResultSet, uno::UNO_QUERY_THROW);
948 
949  do{ // middle checked loop!!
950  if( bAsTable ) // fill in data as table
951  {
952  rSh.DoUndo( false );
953 
954  sal_Int32 nCols = m_xLbTableCol->n_children();
955  sal_Int32 nRows = 0;
956  if( m_xCbTableHeadon->get_active() )
957  nRows++;
958 
959  if( pSelection )
960  nRows += rSelection.getLength();
961  else
962  ++nRows;
963 
964  // prepare the array for the selected columns
965  std::vector<SwInsDBColumn*> aColFields;
966  for( sal_Int32 n = 0; n < nCols; ++n )
967  {
968  SwInsDBColumn aSrch(m_xLbTableCol->get_text(n));
970  if (it != aDBColumns.end())
971  aColFields.push_back(it->get());
972  else {
973  OSL_ENSURE( false, "database column not found" );
974  }
975  }
976 
977  if( static_cast<size_t>(nCols) != aColFields.size() )
978  {
979  OSL_ENSURE( false, "not all database columns found" );
980  nCols = static_cast<sal_Int32>(aColFields.size());
981  }
982 
983  if(!nRows || !nCols)
984  {
985  OSL_ENSURE( false, "wrong parameters" );
986  break;
987  }
988 
989  const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
990 
991  bool bHTML = 0 != (::GetHtmlMode( pView->GetDocShell() ) & HTMLMODE_ON);
992  rSh.InsertTable(
993  pModOpt->GetInsTableFlags(bHTML),
994  nRows, nCols, (pSelection ? m_xTAutoFormat.get(): nullptr) );
996 
997  if( pSelection && pTableSet )
998  SetTabSet();
999 
1001  RES_BOXATR_VALUE> );
1002  bool bIsAutoUpdateCells = rSh.IsAutoUpdateCells();
1003  rSh.SetAutoUpdateCells( false );
1004 
1005  if( m_xCbTableHeadon->get_active() )
1006  {
1007  for( sal_Int32 n = 0; n < nCols; ++n )
1008  {
1009  if( m_xRbHeadlColnms->get_active() )
1010  {
1011  rSh.SwEditShell::Insert2( aColFields[ n ]->sColumn );
1012  }
1013  rSh.GoNextCell();
1014  }
1015  }
1016  else
1017  rSh.SetRowsToRepeat( 0 );
1018 
1019  for( sal_Int32 i = 0 ; ; ++i )
1020  {
1021  bool bBreak = false;
1022  try
1023  {
1024  if(pSelection)
1025  {
1026  bBreak = !xRowLocate->moveToBookmark(pSelection[i]);
1027  }
1028  else if(!i)
1029  bBreak = !xResultSet->first();
1030  }
1031  catch (const Exception&)
1032  {
1033  bBreak = true;
1034  }
1035  if(bBreak)
1036  break;
1037 
1038  for( sal_Int32 n = 0; n < nCols; ++n )
1039  {
1040  // at the very first time, NO GoNextCell, because we're
1041  // already in it. Also no GoNextCell after the Insert,
1042  // because an empty line is added at the end.
1043  if( i || n )
1044  rSh.GoNextCell();
1045 
1046  const SwInsDBColumn* pEntry = aColFields[ n ];
1047 
1048  Reference< XColumn > xColumn;
1049  xCols->getByName(pEntry->sColumn) >>= xColumn;
1050  Reference< XPropertySet > xColumnProps( xColumn, UNO_QUERY );
1051  sal_Int32 eDataType = 0;
1052  if( xColumnProps.is() )
1053  {
1054  Any aType = xColumnProps->getPropertyValue("Type");
1055  aType >>= eDataType;
1056  }
1057  try
1058  {
1059  if( pEntry->bHasFormat )
1060  {
1061  SwTableBoxNumFormat aNumFormat(
1062  pEntry->bIsDBFormat ? static_cast<sal_uInt32>(pEntry->nDBNumFormat)
1063  : pEntry->nUsrNumFormat );
1064  aTableSet.Put(aNumFormat);
1065  if( xColumn.is() )
1066  {
1067  double fVal = xColumn->getDouble();
1068  if( xColumn->wasNull() )
1069  aTableSet.ClearItem( RES_BOXATR_VALUE );
1070  else
1071  {
1072  if(rNumFormatr.GetType(aNumFormat.GetValue()) & SvNumFormatType::DATE)
1073  {
1074  ::Date aStandard(1,1,1900);
1075  if (rNumFormatr.GetNullDate() != aStandard)
1076  fVal += (aStandard - rNumFormatr.GetNullDate());
1077  }
1078  aTableSet.Put( SwTableBoxValue( fVal ));
1079  }
1080  }
1081  else
1082  aTableSet.ClearItem( RES_BOXATR_VALUE );
1083  rSh.SetTableBoxFormulaAttrs( aTableSet );
1084  }
1085  //#i60207# don't insert binary data as string - creates a loop
1086  else if( DataType::BINARY == eDataType ||
1087  DataType::VARBINARY == eDataType ||
1088  DataType::LONGVARBINARY== eDataType ||
1089  DataType::SQLNULL == eDataType ||
1090  DataType::OTHER == eDataType ||
1091  DataType::OBJECT == eDataType ||
1092  DataType::DISTINCT == eDataType ||
1093  DataType::STRUCT == eDataType ||
1094  DataType::ARRAY == eDataType ||
1095  DataType::BLOB == eDataType ||
1096  DataType::CLOB == eDataType ||
1097  DataType::REF == eDataType
1098  )
1099  {
1100  // do nothing
1101  }
1102  else
1103  {
1104  const OUString sVal = xColumn->getString();
1105  if(!xColumn->wasNull())
1106  {
1107  rSh.SwEditShell::Insert2( sVal );
1108  }
1109  }
1110  }
1111  catch (const Exception&)
1112  {
1113  TOOLS_WARN_EXCEPTION("sw", "");
1114  }
1115  }
1116 
1117  if( !pSelection )
1118  {
1119  if ( !xResultSet->next() )
1120  break;
1121  }
1122  else if( i+1 >= rSelection.getLength() )
1123  break;
1124 
1125  if( 10 == i )
1126  pWait.reset(new SwWait( *pView->GetDocShell(), true ));
1127  }
1128 
1130  if( !pSelection && ( pTableSet || m_xTAutoFormat ))
1131  {
1132  if( pTableSet )
1133  SetTabSet();
1134 
1135  if (m_xTAutoFormat)
1137  }
1138  rSh.SetAutoUpdateCells( bIsAutoUpdateCells );
1139  }
1140  else // add data as fields/text
1141  {
1142  DB_Columns aColArr;
1143  if( SplitTextToColArr( m_xEdDbText->get_text(), aColArr, m_xRbAsField->get_active() ) )
1144  {
1145  // now for each data set, we can iterate over the array
1146  // and add the data
1147 
1148  if( !rSh.IsSttPara() )
1149  rSh.SwEditShell::SplitNode();
1150  if( !rSh.IsEndPara() )
1151  {
1152  rSh.SwEditShell::SplitNode();
1153  rSh.SwCursorShell::Left(1,CRSR_SKIP_CHARS);
1154  }
1155 
1156  rSh.DoUndo( false );
1157 
1158  SwTextFormatColl* pColl = nullptr;
1159  {
1160  const OUString sTmplNm(m_xLbDbParaColl->get_active_text());
1161  if( sNoTmpl != sTmplNm )
1162  {
1163  pColl = rSh.FindTextFormatCollByName( sTmplNm );
1164  if( !pColl )
1165  {
1166  const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(
1167  sTmplNm, SwGetPoolIdFromName::TxtColl );
1168  if( USHRT_MAX != nId )
1169  pColl = rSh.GetTextCollFromPool( nId );
1170  else
1171  pColl = rSh.MakeTextFormatColl( sTmplNm );
1172  }
1173  rSh.SetTextFormatColl( pColl );
1174  }
1175  }
1176 
1177  // for adding as fields -> insert a "NextField" after
1178  // every data set
1179  SwDBFormatData aDBFormatData;
1181  aDBFormatData.xFormatter.set(util::NumberFormatter::create(xContext), UNO_QUERY_THROW) ;
1182 
1183  Reference<XPropertySet> xSourceProps(xSource, UNO_QUERY);
1184  if(xSourceProps.is())
1185  {
1186  Any aFormats = xSourceProps->getPropertyValue("NumberFormatsSupplier");
1187  if(aFormats.hasValue())
1188  {
1189  Reference< util::XNumberFormatsSupplier> xSuppl;
1190  aFormats >>= xSuppl;
1191  if(xSuppl.is())
1192  {
1193  Reference< XPropertySet > xSettings = xSuppl->getNumberFormatSettings();
1194  Any aNull = xSettings->getPropertyValue("NullDate");
1195  aNull >>= aDBFormatData.aNullDate;
1196  if(aDBFormatData.xFormatter.is())
1197  aDBFormatData.xFormatter->attachNumberFormatsSupplier(xSuppl);
1198  }
1199  }
1200  }
1201  aDBFormatData.aLocale = LanguageTag( rSh.GetCurLang() ).getLocale();
1202  SwDBNextSetField aNxtDBField( static_cast<SwDBNextSetFieldType*>(rSh.
1203  GetFieldType( 0, SwFieldIds::DbNextSet )),
1204  "1", aDBData );
1205 
1206  bool bSetCursor = true;
1207  const size_t nCols = aColArr.size();
1208  ::sw::mark::IMark* pMark = nullptr;
1209  for( sal_Int32 i = 0 ; ; ++i )
1210  {
1211  bool bBreak = false;
1212  try
1213  {
1214  if(pSelection)
1215  {
1216  bBreak = !xRowLocate->moveToBookmark(pSelection[i]);
1217  }
1218  else if(!i)
1219  bBreak = !xResultSet->first();
1220  }
1221  catch (const Exception&)
1222  {
1223  bBreak = true;
1224  }
1225 
1226  if(bBreak)
1227  break;
1228 
1229  for( size_t n = 0; n < nCols; ++n )
1230  {
1231  DB_Column* pDBCol = aColArr[ n ].get();
1232  OUString sIns;
1233  switch( pDBCol->eColType )
1234  {
1236  sIns = *pDBCol->pText;
1237  break;
1238 
1240  rSh.SplitNode();
1241  // when the template is not the same as the follow template,
1242  // the selected has to be set newly
1243  if( pColl && &pColl->GetNextTextFormatColl() != pColl )
1244  rSh.SetTextFormatColl( pColl );
1245  break;
1246 
1248  {
1249  std::unique_ptr<SwDBField> pField(static_cast<SwDBField *>(
1250  pDBCol->pField->CopyField().release()));
1251  double nValue = DBL_MAX;
1252 
1253  Reference< XPropertySet > xColumnProps;
1254  xCols->getByName(pDBCol->pColInfo->sColumn) >>= xColumnProps;
1255 
1256  pField->SetExpansion( SwDBManager::GetDBField(
1257  xColumnProps,
1258  aDBFormatData,
1259  &nValue ) );
1260  if( DBL_MAX != nValue )
1261  {
1262  Any aType = xColumnProps->getPropertyValue("Type");
1263  sal_Int32 eDataType = 0;
1264  aType >>= eDataType;
1265  if( DataType::DATE == eDataType || DataType::TIME == eDataType ||
1266  DataType::TIMESTAMP == eDataType)
1267 
1268  {
1269  ::Date aStandard(1,1,1900);
1270  ::Date aCompare(aDBFormatData.aNullDate.Day ,
1271  aDBFormatData.aNullDate.Month,
1272  aDBFormatData.aNullDate.Year);
1273  if(aStandard != aCompare)
1274  nValue += (aStandard - aCompare);
1275  }
1276  pField->ChgValue( nValue, true );
1277  }
1278  pField->SetInitialized();
1279 
1280  rSh.Insert( *pField );
1281  }
1282  break;
1283 
1285  {
1286  double nValue = DBL_MAX;
1287  Reference< XPropertySet > xColumnProps;
1288  xCols->getByName(pDBCol->pColInfo->sColumn) >>= xColumnProps;
1289  sIns = SwDBManager::GetDBField(
1290  xColumnProps,
1291  aDBFormatData,
1292  &nValue );
1293  if( pDBCol->nFormat &&
1294  DBL_MAX != nValue )
1295  {
1296  const Color* pCol;
1297  if(rNumFormatr.GetType(pDBCol->nFormat) & SvNumFormatType::DATE)
1298  {
1299  ::Date aStandard(1,1,1900);
1300  if (rNumFormatr.GetNullDate() != aStandard)
1301  nValue += (aStandard - rNumFormatr.GetNullDate());
1302  }
1303  rNumFormatr.GetOutputString( nValue,
1304  pDBCol->nFormat,
1305  sIns, &pCol );
1306  }
1307  }
1308  break;
1309  }
1310 
1311  if( !sIns.isEmpty() )
1312  {
1313  rSh.Insert( sIns );
1314 
1315  if( bSetCursor)
1316  {
1317  // to the beginning and set a mark, so that
1318  // the cursor can be set to the initial position
1319  // at the end.
1320 
1321  rSh.SwCursorShell::MovePara(
1323  pMark = rSh.SetBookmark(
1324  vcl::KeyCode(),
1325  OUString(),
1327  rSh.SwCursorShell::MovePara(
1328  GoCurrPara, fnParaEnd );
1329  bSetCursor = false;
1330  }
1331  }
1332  }
1333 
1334  if( !pSelection )
1335  {
1336  bool bNext = xResultSet->next();
1337  if(!bNext)
1338  break;
1339  }
1340  else if( i+1 >= rSelection.getLength() )
1341  break;
1342 
1343  if( m_xRbAsField->get_active() )
1344  rSh.Insert( aNxtDBField );
1345 
1346  if( !rSh.IsSttPara() )
1347  rSh.SwEditShell::SplitNode();
1348 
1349  if( 10 == i )
1350  pWait.reset(new SwWait( *pView->GetDocShell(), true ));
1351  }
1352 
1353  if( !bSetCursor && pMark != nullptr)
1354  {
1355  rSh.SetMark();
1356  rSh.GotoMark( pMark );
1357  rSh.getIDocumentMarkAccess()->deleteMark( pMark );
1358  break;
1359  }
1360  }
1361  }
1362  // write configuration
1363  Commit();
1364  }while( false ); // middle checked loop
1365 
1366  if( bUndo )
1367  {
1368  rSh.DoUndo();
1369  rSh.AppendUndoForInsertFromDB( bAsTable );
1370  rSh.EndUndo();
1371  }
1372  rSh.ClearMark();
1373  rSh.EndAllAction();
1374 
1375  if ( bDisposeResultSet )
1376  ::comphelper::disposeComponent(xResultSet);
1377 }
1378 
1380 {
1381  SwWrtShell& rSh = pView->GetWrtShell();
1382  const SfxPoolItem* pItem;
1383 
1384  if (m_xTAutoFormat)
1385  {
1386  if (m_xTAutoFormat->IsFrame())
1387  {
1388  // border is from AutoFormat
1389  pTableSet->ClearItem( RES_BOX );
1390  pTableSet->ClearItem( SID_ATTR_BORDER_INNER );
1391  }
1392  if (m_xTAutoFormat->IsBackground())
1393  {
1394  pTableSet->ClearItem( RES_BACKGROUND );
1395  pTableSet->ClearItem( SID_ATTR_BRUSH_ROW );
1396  pTableSet->ClearItem( SID_ATTR_BRUSH_TABLE );
1397  }
1398  }
1399  else
1400  {
1401  // remove the defaults again, it makes no sense to set them
1402  SvxBrushItem aBrush( RES_BACKGROUND );
1403  static const sal_uInt16 aIds[3] =
1404  { RES_BACKGROUND, SID_ATTR_BRUSH_ROW, SID_ATTR_BRUSH_TABLE };
1405  for(sal_uInt16 i : aIds)
1406  if( SfxItemState::SET == pTableSet->GetItemState( i,
1407  false, &pItem ) && *pItem == aBrush )
1408  pTableSet->ClearItem( i );
1409  }
1410 
1411  if( SfxItemState::SET == pTableSet->GetItemState( FN_PARAM_TABLE_NAME, false,
1412  &pItem ) && static_cast<const SfxStringItem*>(pItem)->GetValue() ==
1413  rSh.GetTableFormat()->GetName() )
1414  pTableSet->ClearItem( FN_PARAM_TABLE_NAME );
1415 
1417  rSh.SetMark();
1419 
1420  ItemSetToTableParam( *pTableSet, rSh );
1421 
1422  rSh.ClearMark();
1424 }
1425 
1426 static Sequence<OUString> lcl_createSourceNames(std::u16string_view rNodeName)
1427 {
1428  Sequence<OUString> aSourceNames(11);
1429  OUString* pNames = aSourceNames.getArray();
1430  pNames[0] = OUString::Concat(rNodeName) + "/DataSource";
1431  pNames[1] = OUString::Concat(rNodeName) + "/Command";
1432  pNames[2] = OUString::Concat(rNodeName) + "/CommandType";
1433  pNames[3] = OUString::Concat(rNodeName) + "/ColumnsToText";
1434  pNames[4] = OUString::Concat(rNodeName) + "/ColumnsToTable";
1435  pNames[5] = OUString::Concat(rNodeName) + "/ParaStyle";
1436  pNames[6] = OUString::Concat(rNodeName) + "/TableAutoFormat";
1437  pNames[7] = OUString::Concat(rNodeName) + "/IsTable";
1438  pNames[8] = OUString::Concat(rNodeName) + "/IsField";
1439  pNames[9] = OUString::Concat(rNodeName) + "/IsHeadlineOn";
1440  pNames[10] = OUString::Concat(rNodeName) + "/IsEmptyHeadline";
1441  return aSourceNames;
1442 }
1443 
1444 static Sequence<OUString> lcl_CreateSubNames(std::u16string_view rSubNodeName)
1445 {
1446  return
1447  {
1448  OUString::Concat(rSubNodeName) + "/ColumnName",
1449  OUString::Concat(rSubNodeName) + "/ColumnIndex",
1450  OUString::Concat(rSubNodeName) + "/IsNumberFormat",
1451  OUString::Concat(rSubNodeName) + "/IsNumberFormatFromDataBase",
1452  OUString::Concat(rSubNodeName) + "/NumberFormat",
1453  OUString::Concat(rSubNodeName) + "/NumberFormatLocale"
1454  };
1455 }
1456 
1457 static OUString lcl_CreateUniqueName(const Sequence<OUString>& aNames)
1458 {
1459  sal_Int32 nIdx = aNames.getLength();
1460  while(true)
1461  {
1462  const OUString sRet = "_" + OUString::number(nIdx++);
1463  if ( comphelper::findValue(aNames, sRet) == -1 )
1464  return sRet; // No match found, return unique name
1465  }
1466 }
1467 
1468 void SwInsertDBColAutoPilot::Notify( const css::uno::Sequence< OUString >& ) {}
1469 
1471 {
1472  Sequence <OUString> aNames = GetNodeNames(OUString());
1473  //remove entries that contain this data source + table at first
1474  for(OUString const & nodeName : std::as_const(aNames))
1475  {
1476  Sequence<Any> aSourceProperties = GetProperties({ nodeName + "/DataSource", nodeName + "/Command" });
1477  const Any* pSourceProps = aSourceProperties.getArray();
1478  OUString sSource, sCommand;
1479  pSourceProps[0] >>= sSource;
1480  pSourceProps[1] >>= sCommand;
1481  if(sSource==aDBData.sDataSource && sCommand==aDBData.sCommand)
1482  {
1483  ClearNodeElements(OUString(), { nodeName });
1484  }
1485  }
1486 
1487  aNames = GetNodeNames(OUString());
1488  OUString sNewNode = lcl_CreateUniqueName(aNames);
1489  Sequence<OUString> aNodeNames = lcl_createSourceNames(sNewNode);
1490  Sequence<PropertyValue> aValues(aNodeNames.getLength());
1491  PropertyValue* pValues = aValues.getArray();
1492  const OUString* pNodeNames = aNodeNames.getConstArray();
1493  for(sal_Int32 i = 0; i < aNodeNames.getLength(); i++)
1494  {
1495  pValues[i].Name = "/" + pNodeNames[i];
1496  }
1497 
1498  pValues[0].Value <<= aDBData.sDataSource;
1499  pValues[1].Value <<= aDBData.sCommand;
1500  pValues[2].Value <<= aDBData.nCommandType;
1501  pValues[3].Value <<= m_xEdDbText->get_text();
1502 
1503  OUString sTmp;
1504  const sal_Int32 nCnt = m_xLbTableCol->n_children();
1505  for( sal_Int32 n = 0; n < nCnt; ++n )
1506  sTmp += m_xLbTableCol->get_text(n) + "\x0a";
1507 
1508  if (!sTmp.isEmpty())
1509  pValues[4].Value <<= sTmp;
1510 
1511  if( sNoTmpl != (sTmp = m_xLbDbParaColl->get_active_text()) )
1512  pValues[5].Value <<= sTmp;
1513 
1514  if (m_xTAutoFormat)
1515  pValues[6].Value <<= m_xTAutoFormat->GetName();
1516 
1517  pValues[7].Value <<= m_xRbAsTable->get_active();
1518  pValues[8].Value <<= m_xRbAsField->get_active();
1519  pValues[9].Value <<= m_xCbTableHeadon->get_active();
1520  pValues[10].Value <<= m_xRbHeadlEmpty->get_active();
1521 
1522  SetSetProperties(OUString(), aValues);
1523 
1524  sNewNode += "/ColumnSet";
1525 
1526  LanguageType ePrevLang(0xffff);
1527 
1529  for(size_t nCol = 0; nCol < aDBColumns.size(); nCol++)
1530  {
1531  SwInsDBColumn* pColumn = aDBColumns[nCol].get();
1532  OUString sColumnInsertNode(sNewNode + "/__");
1533  if( nCol < 10 )
1534  sColumnInsertNode += "00";
1535  else if( nCol < 100 )
1536  sColumnInsertNode += "0";
1537  sColumnInsertNode += OUString::number( nCol );
1538 
1539  const Sequence <OUString> aSubNodeNames = lcl_CreateSubNames(sColumnInsertNode);
1540  Sequence<PropertyValue> aSubValues(aSubNodeNames.getLength());
1541  PropertyValue* pSubValues = aSubValues.getArray();
1542  sal_Int32 i = 0;
1543 
1544  for( const OUString& rSubNodeName : aSubNodeNames)
1545  pSubValues[i++].Name = rSubNodeName;
1546  pSubValues[0].Value <<= pColumn->sColumn;
1547  pSubValues[1].Value <<= i;
1548  pSubValues[2].Value <<= pColumn->bHasFormat;
1549  pSubValues[3].Value <<= pColumn->bIsDBFormat;
1550 
1552  const SvNumberformat* pNF = rNFormatr.GetEntry( pColumn->nUsrNumFormat );
1553  LanguageType eLang;
1554  if( pNF )
1555  {
1556  pSubValues[4].Value <<= pNF->GetFormatstring();
1557  eLang = pNF->GetLanguage();
1558  }
1559  else
1560  {
1561  pSubValues[4].Value <<= sTmp;
1562  eLang = GetAppLanguage();
1563  }
1564 
1565  OUString sPrevLang;
1566  if( eLang != ePrevLang )
1567  {
1568  sPrevLang = LanguageTag::convertToBcp47( eLang );
1569  ePrevLang = eLang;
1570  }
1571 
1572  pSubValues[5].Value <<= sPrevLang;
1573  SetSetProperties(sNewNode, aSubValues);
1574  }
1575 }
1576 
1578 {
1579  const Sequence<OUString> aNames = GetNodeNames(OUString());
1581  for(OUString const & nodeName : aNames)
1582  {
1583  //search for entries with the appropriate data source and table
1584  Sequence<OUString> aSourceNames = lcl_createSourceNames(nodeName);
1585 
1586  Sequence< Any> aDataSourceProps = GetProperties(aSourceNames);
1587  const Any* pDataSourceProps = aDataSourceProps.getConstArray();
1588  OUString sSource, sCommand;
1589  sal_Int16 nCommandType;
1590  pDataSourceProps[0] >>= sSource;
1591  pDataSourceProps[1] >>= sCommand;
1592  pDataSourceProps[2] >>= nCommandType;
1593  if(sSource == aDBData.sDataSource && sCommand == aDBData.sCommand)
1594  {
1595  DB_ColumnConfigData aNewData;
1596 
1597  pDataSourceProps[3] >>= aNewData.sEdit;
1598  pDataSourceProps[4] >>= aNewData.sTableList;
1599  pDataSourceProps[5] >>= aNewData.sTmplNm;
1600  pDataSourceProps[6] >>= aNewData.sTAutoFormatNm;
1601  if(pDataSourceProps[7].hasValue())
1602  aNewData.bIsTable = *o3tl::doAccess<bool>(pDataSourceProps[7]);
1603  if(pDataSourceProps[8].hasValue())
1604  aNewData.bIsField = *o3tl::doAccess<bool>(pDataSourceProps[8]);
1605  if(pDataSourceProps[9].hasValue())
1606  aNewData.bIsHeadlineOn = *o3tl::doAccess<bool>(pDataSourceProps[9]);
1607  if(pDataSourceProps[10].hasValue())
1608  aNewData.bIsEmptyHeadln = *o3tl::doAccess<bool>(pDataSourceProps[10]);
1609 
1610  const OUString sSubNodeName(nodeName + "/ColumnSet/");
1611  const Sequence <OUString> aSubNames = GetNodeNames(sSubNodeName);
1612  for(const OUString& rSubName : aSubNames)
1613  {
1614  Sequence <OUString> aSubNodeNames =
1615  lcl_CreateSubNames(OUString(sSubNodeName + rSubName));
1616  Sequence< Any> aSubProps = GetProperties(aSubNodeNames);
1617  const Any* pSubProps = aSubProps.getConstArray();
1618 
1619  OUString sColumn;
1620  pSubProps[0] >>= sColumn;
1621  // check for existence of the loaded column name
1622  bool bFound = false;
1623  for(size_t nRealColumn = 0; nRealColumn < aDBColumns.size(); ++nRealColumn)
1624  {
1625  if(aDBColumns[nRealColumn]->sColumn == sColumn)
1626  {
1627  bFound = true;
1628  break;
1629  }
1630  }
1631  if(!bFound)
1632  continue;
1633  sal_Int16 nIndex = 0;
1634  pSubProps[1] >>= nIndex;
1635  std::unique_ptr<SwInsDBColumn> pInsDBColumn(new SwInsDBColumn(sColumn));
1636  if(pSubProps[2].hasValue())
1637  pInsDBColumn->bHasFormat = *o3tl::doAccess<bool>(pSubProps[2]);
1638  if(pSubProps[3].hasValue())
1639  pInsDBColumn->bIsDBFormat = *o3tl::doAccess<bool>(pSubProps[3]);
1640 
1641  pSubProps[4] >>= pInsDBColumn->sUsrNumFormat;
1642  OUString sNumberFormatLocale;
1643  pSubProps[5] >>= sNumberFormatLocale;
1644 
1645  /* XXX Earlier versions wrote a Country-Language string in
1646  * SwInsertDBColAutoPilot::Commit() that here was read as
1647  * Language-Country with 2 characters copied to language,
1648  * 1 character separator and unconditionally 2 characters read
1649  * as country. So for 'DE-de' and locales that have similar
1650  * case-insensitive equal language/country combos that may have
1651  * worked, for all others not. FIXME if you need to read old
1652  * data that you were never able to read before. */
1653  pInsDBColumn->eUsrNumFormatLng = LanguageTag::convertToLanguageType( sNumberFormatLocale );
1654 
1655  pInsDBColumn->nUsrNumFormat = rNFormatr.GetEntryKey( pInsDBColumn->sUsrNumFormat,
1656  pInsDBColumn->eUsrNumFormatLng );
1657 
1658  aNewData.aDBColumns.insert(std::move(pInsDBColumn));
1659  }
1660  OUString sTmp( aNewData.sTableList );
1661  if( !sTmp.isEmpty() )
1662  {
1663  sal_Int32 n = 0;
1664  do {
1665  const OUString sEntry( sTmp.getToken( 0, '\x0a', n ) );
1666  //preselect column - if they still exist!
1667  if (m_xLbTableDbColumn->find_text(sEntry) != -1)
1668  {
1669  m_xLbTableCol->append_text(sEntry);
1670  m_xLbTableDbColumn->remove_text(sEntry);
1671  }
1672  } while( n>=0 );
1673 
1674  if (!m_xLbTableDbColumn->n_children())
1675  {
1676  m_xIbDbcolAllTo->set_sensitive( false );
1677  m_xIbDbcolOneTo->set_sensitive( false );
1678  }
1679  m_xIbDbcolOneFrom->set_sensitive(true);
1680  m_xIbDbcolAllFrom->set_sensitive(true);
1681  }
1682  m_xEdDbText->set_text( aNewData.sEdit );
1683 
1684  sTmp = aNewData.sTmplNm;
1685  if( !sTmp.isEmpty() )
1686  m_xLbDbParaColl->set_active_text(sTmp);
1687  else
1688  m_xLbDbParaColl->set_active(0);
1689 
1690  m_xTAutoFormat.reset();
1691  sTmp = aNewData.sTAutoFormatNm;
1692  if( !sTmp.isEmpty() )
1693  {
1694  // then load the AutoFormat file and look for Autoformat first
1695  SwTableAutoFormatTable aAutoFormatTable;
1696  aAutoFormatTable.Load();
1697  for( size_t nAutoFormat = aAutoFormatTable.size(); nAutoFormat; )
1698  if( sTmp == aAutoFormatTable[ --nAutoFormat ].GetName() )
1699  {
1700  m_xTAutoFormat.reset(new SwTableAutoFormat(aAutoFormatTable[nAutoFormat]));
1701  break;
1702  }
1703  }
1704 
1705  m_xRbAsTable->set_active( aNewData.bIsTable );
1706  m_xRbAsField->set_active( aNewData.bIsField );
1707  m_xRbAsText->set_active( !aNewData.bIsTable && !aNewData.bIsField );
1708 
1709  m_xCbTableHeadon->set_active( aNewData.bIsHeadlineOn );
1710  m_xRbHeadlColnms->set_active( !aNewData.bIsEmptyHeadln );
1711  m_xRbHeadlEmpty->set_active( aNewData.bIsEmptyHeadln );
1712  HeaderHdl(*m_xCbTableHeadon);
1713 
1714  // now copy the user defined Numberformat strings to the
1715  // Shell. Then only these are available as ID
1716  for( size_t n = 0; n < aDBColumns.size() ; ++n )
1717  {
1718  SwInsDBColumn& rSet = *aDBColumns[ n ];
1719  for( size_t m = 0; m < aNewData.aDBColumns.size() ; ++m )
1720  {
1721  SwInsDBColumn& rGet = *aNewData.aDBColumns[ m ];
1722  if(rGet.sColumn == rSet.sColumn)
1723  {
1724  if( rGet.bHasFormat && !rGet.bIsDBFormat )
1725  {
1726  rSet.bIsDBFormat = false;
1727  rSet.nUsrNumFormat = rNFormatr.GetEntryKey( rGet.sUsrNumFormat,
1728  rGet.eUsrNumFormatLng );
1730  {
1731  sal_Int32 nCheckPos;
1733  rNFormatr.PutEntry( rGet.sUsrNumFormat, nCheckPos, nType,
1734  rSet.nUsrNumFormat, rGet.eUsrNumFormatLng );
1735  }
1736  }
1737  break;
1738  }
1739  }
1740  }
1741 
1742  // when the cursor is inside of a table, table must NEVER be selectable
1743  if( !m_xRbAsTable->get_sensitive() && m_xRbAsTable->get_active() )
1744  m_xRbAsField->set_active(true);
1745  break;
1746  }
1747  }
1748 }
1749 
1750 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Frame > m_xFormatFrame
Definition: dbinsdlg.hxx:102
SfxStyleSheetBase * First(SfxStyleFamily eFamily, SfxStyleSearchBits eMask=SfxStyleSearchBits::All)
SwField * pField
Definition: dbinsdlg.cxx:104
SwMoveFnCollection const & fnParaEnd
Definition: paminit.cxx:47
SwMoveFnCollection const & fnTableEnd
Definition: paminit.cxx:53
OUString sColumn
Definition: dbinsdlg.hxx:56
constexpr SwTwips MIN_BORDER_DIST
Definition: swtypes.hxx:71
sal_Int32 nIndex
sal_Int32 nCommandType
Definition: swdbdata.hxx:32
static bool SetSetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const OUString &rNode, const css::uno::Sequence< css::beans::PropertyValue > &rValues)
void SplitNode(bool bAutoFormat=false)
Definition: wrtsh1.cxx:1022
static void lcl_InsTextInArr(const OUString &rText, DB_Columns &rColArr)
Definition: dbinsdlg.cxx:813
bool IsAutoUpdateCells() const
Definition: crsrsh.hxx:805
static css::uno::Sequence< OUString > GetNodeNames(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const OUString &rNode, ConfigNameFormat eFormat)
std::unique_ptr< NumFormatListBox > m_xLbDbFormatFromUsr
Definition: dbinsdlg.hxx:105
const SwFormatCol & GetCol(bool=true) const
Definition: fmtclds.hxx:168
Represents the style of a paragraph.
Definition: fmtcol.hxx:56
bool bIsDBFormat
Definition: dbinsdlg.hxx:61
std::vector< SwColumn > SwColumns
Definition: fmtclds.hxx:57
SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId)
Definition: edfmt.cxx:123
sal_Int32 compareString(const OUString &s1, const OUString &s2) const
void SetDefDist(sal_uInt16 nNew)
css::util::Date aNullDate
Definition: dbmgr.hxx:66
constexpr TypedWhichId< SwTableBoxNumFormat > RES_BOXATR_FORMAT(RES_BOXATR_BEGIN)
static constexpr auto Items
bool GotoPrevTable(SwPaM &rCurrentCursor, SwMoveFnCollection const &fnPosTable, bool bInReadOnly)
Definition: trvltbl.cxx:481
void SetAutoUpdateCells(bool bFlag)
Definition: crsrsh.hxx:806
bool GoCurrPara(SwPaM &rPam, SwMoveFnCollection const &aPosPara)
Definition: pam.cxx:1016
virtual const SfxItemSet * GetOutputItemSet() const =0
std::string GetValue
const Color aColNames[SC_RANGECOLORS]
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
void SetRight(tools::Long nNew)
Definition: tabcol.hxx:84
bool IsSttPara() const
Definition: crsrsh.cxx:1095
void SetMinDist(bool bNew)
const SwRect & GetAnyCurRect(CurRectType eType, const Point *pPt=nullptr, const css::uno::Reference< css::embed::XEmbeddedObject > &=css::uno::Reference< css::embed::XEmbeddedObject >()) const
Definition: fews.cxx:90
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
static OUString convertToBcp47(LanguageType nLangID)
const char cDBFieldStart
Definition: dbinsdlg.cxx:94
long Long
virtual std::unique_ptr< SwTableAutoFormat > FillAutoFormatOfIndex() const =0
OUString sDataSource
Definition: swdbdata.hxx:30
sal_uInt16 GetCurColNum(SwGetCurColNumPara *pPara=nullptr) const
The ruler needs some information too.
Definition: fews.cxx:641
ConfigItemMode
void SetTable(bool bNew)
Base class of all fields.
Definition: fldbas.hxx:289
std::unique_ptr< weld::TreeView > m_xLbTextDbColumn
Definition: dbinsdlg.hxx:100
OUString * pText
Definition: dbinsdlg.cxx:103
sal_Int64 n
SwMoveFnCollection const & fnParaStart
Definition: paminit.cxx:46
SvNumFormatType GetType(sal_uInt32 nFIndex) const
DB_Column(const OUString &rText)
Definition: dbinsdlg.cxx:114
std::unique_ptr< SwField > CopyField() const
Definition: fldbas.cxx:485
sal_Int16 nId
bool operator<(const SwInsDBColumn &rCmp) const
Definition: dbinsdlg.cxx:167
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:234
const_iterator find(const Value &x) const
std::vector< std::unique_ptr< DB_Column > > DB_Columns
Definition: dbinsdlg.hxx:50
virtual VclPtr< SfxAbstractTabDialog > CreateSwTableTabDlg(weld::Window *pParent, const SfxItemSet *pItemSet, SwWrtShell *pSh)=0
#define FN_PARAM_TABLE_NAME
Definition: cmdid.h:780
void DoUndo(bool bOn=true)
Undo.
Definition: edws.cxx:200
std::unique_ptr< weld::Button > m_xPbTableAutofmt
Definition: dbinsdlg.hxx:124
std::unique_ptr< weld::CheckButton > m_xCbTableHeadon
Definition: dbinsdlg.hxx:120
std::unique_ptr< weld::RadioButton > m_xRbAsText
Definition: dbinsdlg.hxx:95
constexpr TypedWhichId< SwTableBoxValue > RES_BOXATR_VALUE(152)
virtual short Execute()=0
DB_Column(const SwInsDBColumn &rInfo, sal_uInt32 nFormat_)
Definition: dbinsdlg.cxx:120
void EndAllAction()
Definition: edws.cxx:97
enum DB_Column::Type eColType
virtual void Notify(const css::uno::Sequence< OUString > &aPropertyNames) override
Definition: dbinsdlg.cxx:1468
const OUString & GetFormatstring() const
bool GoNextCell(bool bAppendLine=true)
set cursor into next/previous cell
Definition: trvltbl.cxx:39
std::unique_ptr< weld::TreeView > m_xLbTableCol
Definition: dbinsdlg.hxx:119
bool DelRight()
Definition: delete.cxx:295
SwWrtShell & GetWrtShell() const
Definition: view.hxx:413
bool GotoCurrTable(SwPaM &rCurrentCursor, SwMoveFnCollection const &fnPosTable, bool bInReadOnly)
Definition: trvltbl.cxx:633
void SetRightMax(tools::Long nNew)
Definition: tabcol.hxx:85
LanguageType GetCurLang() const
Definition: edattr.cxx:818
Used by the UI to modify the document model.
Definition: wrtsh.hxx:93
#define FN_PARAM_TABLE_HEADLINE
Definition: cmdid.h:781
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:165
Value
std::unique_ptr< weld::TextView > m_xEdDbText
Definition: dbinsdlg.hxx:109
sal_uInt16 sal_Unicode
const SwTable & InsertTable(const SwInsertTableOptions &rInsTableOpts, sal_uInt16 nRows, sal_uInt16 nCols, const SwTableAutoFormat *pTAFormat=nullptr)
Definition: edtab.cxx:101
virtual OUString get_selected_text() const =0
const OUString & GetName() const
bool SplitTextToColArr(const OUString &rText, DB_Columns &rColArr, bool bInsField)
Definition: dbinsdlg.cxx:831
OUString sUsrNumFormat
Definition: dbinsdlg.hxx:56
bool PutEntry(OUString &rString, sal_Int32 &nCheckPos, SvNumFormatType &nType, sal_uInt32 &nKey, LanguageType eLnge=LANGUAGE_DONTKNOW, bool bReplaceBooleanEquivalent=true)
std::unique_ptr< SfxItemSet > pTableSet
Definition: dbinsdlg.hxx:89
sal_uInt32 nFormat
Definition: dbinsdlg.cxx:105
constexpr sal_uInt32 NUMBERFORMAT_ENTRY_NOT_FOUND
const OUString & GetName() const
Definition: format.hxx:115
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
void Width(tools::Long nNew)
Definition: swrect.hxx:186
virtual VclPtr< AbstractSwAutoFormatDlg > CreateSwAutoFormatDlg(weld::Window *pParent, SwWrtShell *pShell, bool bSetAutoFormat=true, const SwTableAutoFormat *pSelFormat=nullptr)=0
SwDoc * GetDoc() const
Definition: viewsh.hxx:281
const IDocumentMarkAccess * getIDocumentMarkAccess() const
Provides access to the document bookmark interface.
Definition: viewsh.cxx:2672
size_type size() const
css::lang::Locale aLocale
Definition: dbmgr.hxx:68
LanguageType eUsrNumFormatLng
Definition: dbinsdlg.hxx:59
void Insert(SwField const &, SwPaM *pAnnotationRange=nullptr)
Definition: wrtsh2.cxx:62
SW_DLLPUBLIC const WhichRangesContainer & SwuiGetUITableAttrRange()
Definition: tabsh.cxx:124
static css::uno::Reference< css::sdbc::XResultSet > createCursor(const OUString &_sDataSourceName, const OUString &_sCommand, sal_Int32 _nCommandType, const css::uno::Reference< css::sdbc::XConnection > &_xConnection, const SwView *pView)
creates a RowSet, which must be disposed after use.
Definition: dbmgr.cxx:3098
void SetTableBoxFormulaAttrs(const SfxItemSet &rSet)
Definition: edtab.cxx:346
virtual std::unique_ptr< ILazyDeleter > deleteMark(const IDocumentMarkAccess::const_iterator_t &ppMark)=0
Deletes a mark.
IMPL_LINK_NOARG(SwInsertDBColAutoPilot, TableFormatHdl, weld::Button &, void)
Definition: dbinsdlg.cxx:614
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:19
bool ClearNodeElements(const OUString &rNode, css::uno::Sequence< OUString > const &rElements)
static css::uno::Sequence< css::uno::Any > GetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, bool bAllLocales)
const SfxItemPool & GetAttrPool() const
Definition: viewsh.hxx:612
void SetTextFormatColl(SwTextFormatColl *, const bool bResetListAttrs=false)
Add 2nd optional parameter - see also
Definition: edfcol.cxx:2190
#define TOOLS_WARN_EXCEPTION(area, stream)
Rect of current PrtArea of page.
bool HasSelection() const
Definition: wrtsh.hxx:144
#define SW_MOD()
Definition: swmodule.hxx:256
int i
const SwColumns & GetColumns() const
Definition: fmtclds.hxx:112
SwFieldType * InsertFieldType(const SwFieldType &)
insert field type
Definition: edfld.cxx:336
void SetRowsToRepeat(sal_uInt16 nNumOfRows)
Definition: fetab.cxx:1028
std::unique_ptr< weld::Button > m_xPbTableFormat
Definition: dbinsdlg.hxx:123
SwAbstractDialogFactory & GetFactory()
Definition: swuiexp.cxx:26
std::unique_ptr< weld::RadioButton > m_xRbDbFormatFromUsr
Definition: dbinsdlg.hxx:104
std::unique_ptr< weld::RadioButton > m_xRbAsField
Definition: dbinsdlg.hxx:94
SwInsDBColumns aDBColumns
Definition: dbinsdlg.hxx:81
::sw::mark::IMark * SetBookmark(const vcl::KeyCode &, const OUString &rName, IDocumentMarkAccess::MarkType eMark=IDocumentMarkAccess::MarkType::BOOKMARK)
Definition: crbm.cxx:80
HTMLMODE_ON
sal_uInt16 CalcColWidth(sal_uInt16 nCol, sal_uInt16 nAct) const
Calculates current width of column nCol.
Definition: atrfrm.cxx:991
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:354
size_t size() const
Definition: tblafmt.cxx:916
const SwInsDBColumn * pColInfo
Definition: dbinsdlg.cxx:107
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:223
virtual SfxStyleSheetBasePool * GetStyleSheetPool() override
For Style PI.
Definition: docsh.cxx:1142
uno::Reference< sdbc::XRow > xRow
OUString GetUniqueTableName() const
Definition: edfmt.cxx:111
SvNumFormatType
void SetMark()
Definition: crsrsh.hxx:875
std::unique_ptr< weld::Frame > m_xHeadFrame
Definition: dbinsdlg.hxx:97
const SwDBData aDBData
Definition: dbinsdlg.hxx:82
sal_uInt32 GetEntryKey(std::u16string_view sStr, LanguageType eLnge=LANGUAGE_DONTKNOW)
const_iterator end() const
void SetTableStyle(const OUString &rStyleName)
Set table style of the current table.
Definition: fetab.cxx:1202
SwDocShell * GetDocShell()
Definition: view.cxx:1127
SwFrameFormat * GetTableFormat()
Definition: edws.cxx:183
void DataToDoc(const css::uno::Sequence< css::uno::Any > &rSelection, css::uno::Reference< css::sdbc::XDataSource > const &rxSource, css::uno::Reference< css::sdbc::XConnection > const &xConnection, css::uno::Reference< css::sdbc::XResultSet > const &xResultSet)
Definition: dbinsdlg.cxx:908
DB_Column(const SwInsDBColumn &rInfo, SwDBField &rField)
Definition: dbinsdlg.cxx:126
void AppendUndoForInsertFromDB(bool bIsTable)
Set up InsertDB as table Undo.
Definition: edtab.cxx:529
const LanguageTag & getLocale()
sal_Int32 getDefaultNumberFormat(const Reference< XPropertySet > &_xColumn, const Reference< XNumberFormatTypes > &_xTypes, const Locale &_rLocale)
sal_uInt8 GetTableDest() const
Definition: viewopt.hxx:548
const PropertyValue * pValues
IMPL_LINK(SwInsertDBColAutoPilot, PageHdl, weld::Toggleable &, rButton, void)
Definition: dbinsdlg.cxx:391
void GotoMark(const ::sw::mark::IMark *const pMark)
Definition: wrtsh3.cxx:134
constexpr TypedWhichId< SvxBrushItem > RES_BACKGROUND(105)
std::unique_ptr< weld::RadioButton > m_xRbHeadlColnms
Definition: dbinsdlg.hxx:121
SwMoveFnCollection const & fnTableStart
Definition: paminit.cxx:52
sal_uInt16 GetRight() const
Definition: fmtclds.hxx:52
#define FN_TABLE_REP
Definition: cmdid.h:345
sal_Int32 nDBNumFormat
Definition: dbinsdlg.hxx:57
const SvNumberformat * GetEntry(sal_uInt32 nKey) const
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:423
bool MoveTable(SwWhichTable, SwMoveFnCollection const &)
Definition: trvltbl.cxx:682
std::unique_ptr< weld::ComboBox > m_xLbDbParaColl
Definition: dbinsdlg.hxx:111
SfxStyleSheetBase * Next()
SwInsertDBColAutoPilot(SwView &rView, css::uno::Reference< css::sdbc::XDataSource > const &rxSource, css::uno::Reference< css::sdbcx::XColumnsSupplier > const &xColSupp, const SwDBData &rData)
Definition: dbinsdlg.cxx:172
std::unique_ptr< weld::Button > m_xIbDbcolAllTo
Definition: dbinsdlg.hxx:114
SwTextFormatColl * FindTextFormatCollByName(const OUString &rName) const
Definition: edfmt.cxx:154
LanguageType GetAppLanguage()
Definition: init.cxx:723
RET_OK
SW_DLLPUBLIC void ItemSetToTableParam(const SfxItemSet &rSet, SwWrtShell &rSh)
Definition: tabsh.cxx:270
std::unique_ptr< weld::TreeView > m_xLbTableDbColumn
Definition: dbinsdlg.hxx:99
virtual void ImplCommit() override
Definition: dbinsdlg.cxx:1470
void Insert(tools::Long nValue, bool bValue, size_t nPos)
Definition: tabcol.cxx:69
Reference< XExecutableDialog > m_xDialog
static Sequence< OUString > lcl_createSourceNames(std::u16string_view rNodeName)
Definition: dbinsdlg.cxx:1426
const SwExtendedSubType SUB_OWN_FMT
SwDBField: Don't accept formatting from database.
Definition: fldbas.hxx:213
Reference< XComponentContext > getProcessComponentContext()
static OUString GetDBField(css::uno::Reference< css::beans::XPropertySet > const &xColumnProp, const SwDBFormatData &rDBFormatData, double *pNumber=nullptr)
Definition: dbmgr.cxx:1926
QPRO_FUNC_TYPE nType
css::uno::Reference< css::util::XNumberFormatter > xFormatter
Definition: dbmgr.hxx:67
std::unique_ptr< weld::Button > m_xIbDbcolAllFrom
Definition: dbinsdlg.hxx:117
ColumnDescriptor.
Definition: fmtclds.hxx:33
virtual ~SwInsertDBColAutoPilot() override
Definition: dbinsdlg.cxx:387
void ClearMark()
Definition: crsrsh.cxx:939
constexpr TypedWhichId< SvxBoxItem > RES_BOX(106)
Reference< XColumn > xColumn
const SwRect * pPrtRect
Definition: fesh.hxx:153
sal_uInt16 GetLeft() const
Definition: fmtclds.hxx:51
static Sequence< OUString > lcl_CreateSubNames(std::u16string_view rSubNodeName)
Definition: dbinsdlg.cxx:1444
std::unique_ptr< weld::Button > m_xIbDbcolOneFrom
Definition: dbinsdlg.hxx:116
sal_uInt32 GetValue() const
void SetValid(SvxBoxInfoItemValidFlags nValid, bool bValid=true)
const sal_uInt16 CRSR_SKIP_CHARS
Definition: swcrsr.hxx:65
const SwFrameFormat * pFrameFormat
Definition: fesh.hxx:152
const char cDBFieldEnd
Definition: dbinsdlg.cxx:95
std::unique_ptr< SwTableAutoFormat > m_xTAutoFormat
Definition: dbinsdlg.hxx:87
sal_Int32 nGBFormatLen
Definition: dbinsdlg.hxx:91
static OUString lcl_CreateUniqueName(const Sequence< OUString > &aNames)
Definition: dbinsdlg.cxx:1457
static OUString EraseAllMnemonicChars(const OUString &rStr)
bool IsEndPara() const
Definition: crsrsh.cxx:1114
std::unique_ptr< weld::RadioButton > m_xRbHeadlEmpty
Definition: dbinsdlg.hxx:122
sal_uInt32 nUsrNumFormat
Definition: dbinsdlg.hxx:58
tuple m
SwTextFormatColl * MakeTextFormatColl(const OUString &rFormatCollName, SwTextFormatColl *pDerivedFrom=nullptr)
Definition: edfcol.cxx:2239
bool DoesUndo() const
Definition: edws.cxx:203
virtual OUString get_label() const =0
const SwInsertTableOptions & GetInsTableFlags(bool bHTML) const
Definition: modcfg.hxx:303
std::pair< const_iterator, bool > insert(Value &&x)
virtual void SetSubType(sal_uInt16)
Definition: fldbas.cxx:342
const Date & GetNullDate() const
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
SvNumberFormatter * GetNumberFormatter()
Query NumberFormatter from document.
Definition: editsh.cxx:745
OUString sCommand
Definition: swdbdata.hxx:31
Rect of PrtArea of FlyFrame.
aStr
FrameTypeFlags GetFrameType(const Point *pPt, bool bStopAtFly) const
For return values see above FrameType.
Definition: fews.cxx:237
std::unique_ptr< weld::RadioButton > m_xRbDbFormatFromDb
Definition: dbinsdlg.hxx:103
void GetOutputString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &sOutString, const Color **ppColor, bool bUseStarFormat=false)
virtual void set_label(const OUString &rText)=0
LanguageType GetLanguage() const
Definition: view.hxx:144
sal_uInt16 nPos
std::vector< std::unique_ptr< SwInsDBColumn > >::const_iterator const_iterator
SwTextFormatColl & GetNextTextFormatColl() const
Definition: fmtcol.hxx:102
bool bHasFormat
Definition: dbinsdlg.hxx:60
sal_Int16 nValue
CollatorWrapper & GetAppCollator()
Definition: init.cxx:735
void SetDist(bool bNew)
std::unique_ptr< weld::Button > m_xIbDbcolToEdit
Definition: dbinsdlg.hxx:108
std::unique_ptr< weld::Button > m_xIbDbcolOneTo
Definition: dbinsdlg.hxx:115
SAL_DLLPRIVATE bool Load(SvStream &rStream)
Definition: tblafmt.cxx:1047
std::unique_ptr< weld::RadioButton > m_xRbAsTable
Definition: dbinsdlg.hxx:93