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