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