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  return;
578 
579  m_xIbDbcolOneTo->set_sensitive( bEnableTo );
580  m_xIbDbcolAllTo->set_sensitive( bEnableTo );
581  m_xIbDbcolOneFrom->set_sensitive( bEnableFrom );
582  m_xIbDbcolAllFrom->set_sensitive( bEnableFrom );
583 
584  m_xRbDbFormatFromDb->set_sensitive( false );
585  m_xRbDbFormatFromUsr->set_sensitive( false );
586  m_xLbDbFormatFromUsr->set_sensitive( false );
587 
588  m_xPbTableFormat->set_sensitive( bEnableFrom );
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  nEndPos = sText.indexOf( cDBFieldEnd, nSttPos+1 );
842  if( -1 != nEndPos )
843  {
844  // Text in <> brackets found: what is it:
845  SwInsDBColumn aSrch( sText.copy( nSttPos, nEndPos - nSttPos ));
847  if( it != aDBColumns.end() )
848  {
849  // that is a valid field
850  // so surely the text "before":
851  const SwInsDBColumn& rFndCol = **it;
852 
853  DB_Column* pNew;
854 
855  if( 1 < nSttPos )
856  {
857  ::lcl_InsTextInArr( sText.copy( 0, nSttPos-1 ), rColArr );
858  sText = sText.copy( nSttPos-1 );
859  }
860 
861  sText = sText.copy( rFndCol.sColumn.getLength() + 2 );
862  nSttPos = 0;
863 
864  sal_uInt16 nSubType = 0;
865  sal_uInt32 nFormat;
866  if( rFndCol.bHasFormat )
867  {
868  if( rFndCol.bIsDBFormat )
869  nFormat = static_cast<sal_uInt32>(rFndCol.nDBNumFormat);
870  else
871  {
872  nFormat = rFndCol.nUsrNumFormat;
874  }
875  }
876  else
877  nFormat = 0;
878 
879  if( bInsField )
880  {
881  SwWrtShell& rSh = pView->GetWrtShell();
882  SwDBFieldType aFieldType( rSh.GetDoc(), aSrch.sColumn,
883  aDBData );
884  pNew = new DB_Column( rFndCol, *new SwDBField(
885  static_cast<SwDBFieldType*>(rSh.InsertFieldType( aFieldType )),
886  nFormat ) );
887  if( nSubType )
888  pNew->pField->SetSubType( nSubType );
889  }
890  else
891  pNew = new DB_Column( rFndCol, nFormat );
892 
893  rColArr.push_back( std::unique_ptr<DB_Column>(pNew) );
894  }
895  }
896  }
897 
898  // don't forget the last text
899  if( !sText.isEmpty() )
900  ::lcl_InsTextInArr( sText, rColArr );
901 
902  return !rColArr.empty();
903 }
904 
905 void SwInsertDBColAutoPilot::DataToDoc( const Sequence<Any>& rSelection,
906  Reference< XDataSource> const & xSource,
907  Reference< XConnection> const & xConnection,
908  Reference< sdbc::XResultSet > const & xResultSet_in )
909 {
910  auto xResultSet = xResultSet_in;
911 
912  const Any* pSelection = rSelection.hasElements() ? rSelection.getConstArray() : nullptr;
913  SwWrtShell& rSh = pView->GetWrtShell();
914 
915  //with the drag and drop interface no result set is initially available
916  bool bDisposeResultSet = false;
917  // we don't have a cursor, so we have to create our own RowSet
918  if ( !xResultSet.is() )
919  {
921  bDisposeResultSet = xResultSet.is();
922  }
923 
924  Reference< sdbc::XRow > xRow(xResultSet, UNO_QUERY);
925  if ( !xRow.is() )
926  return;
927 
928  rSh.StartAllAction();
929  bool bUndo = rSh.DoesUndo();
930  if( bUndo )
931  rSh.StartUndo();
932 
933  bool bAsTable = m_xRbAsTable->get_active();
934  SvNumberFormatter& rNumFormatr = *rSh.GetNumberFormatter();
935 
936  if( rSh.HasSelection() )
937  rSh.DelRight();
938 
939  std::unique_ptr<SwWait> pWait;
940 
941  Reference< XColumnsSupplier > xColsSupp( xResultSet, UNO_QUERY );
942  Reference <XNameAccess> xCols = xColsSupp->getColumns();
943 
944  uno::Reference<sdbcx::XRowLocate> xRowLocate(xResultSet, uno::UNO_QUERY_THROW);
945 
946  do{ // middle checked loop!!
947  if( bAsTable ) // fill in data as table
948  {
949  rSh.DoUndo( false );
950 
951  sal_Int32 nCols = m_xLbTableCol->n_children();
952  sal_Int32 nRows = 0;
953  if( m_xCbTableHeadon->get_active() )
954  nRows++;
955 
956  if( pSelection )
957  nRows += rSelection.getLength();
958  else
959  ++nRows;
960 
961  // prepare the array for the selected columns
962  std::vector<SwInsDBColumn*> aColFields;
963  for( sal_Int32 n = 0; n < nCols; ++n )
964  {
965  SwInsDBColumn aSrch(m_xLbTableCol->get_text(n));
967  if (it != aDBColumns.end())
968  aColFields.push_back(it->get());
969  else {
970  OSL_ENSURE( false, "database column not found" );
971  }
972  }
973 
974  if( static_cast<size_t>(nCols) != aColFields.size() )
975  {
976  OSL_ENSURE( false, "not all database columns found" );
977  nCols = static_cast<sal_Int32>(aColFields.size());
978  }
979 
980  if(!nRows || !nCols)
981  {
982  OSL_ENSURE( false, "wrong parameters" );
983  break;
984  }
985 
986  const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
987 
988  bool bHTML = 0 != (::GetHtmlMode( pView->GetDocShell() ) & HTMLMODE_ON);
989  rSh.InsertTable(
990  pModOpt->GetInsTableFlags(bHTML),
991  nRows, nCols, (pSelection ? m_xTAutoFormat.get(): nullptr) );
993 
994  if( pSelection && pTableSet )
995  SetTabSet();
996 
998  RES_BOXATR_VALUE>{} );
999  bool bIsAutoUpdateCells = rSh.IsAutoUpdateCells();
1000  rSh.SetAutoUpdateCells( false );
1001 
1002  if( m_xCbTableHeadon->get_active() )
1003  {
1004  for( sal_Int32 n = 0; n < nCols; ++n )
1005  {
1006  if( m_xRbHeadlColnms->get_active() )
1007  {
1008  rSh.SwEditShell::Insert2( aColFields[ n ]->sColumn );
1009  }
1010  rSh.GoNextCell();
1011  }
1012  }
1013  else
1014  rSh.SetRowsToRepeat( 0 );
1015 
1016  for( sal_Int32 i = 0 ; ; ++i )
1017  {
1018  bool bBreak = false;
1019  try
1020  {
1021  if(pSelection)
1022  {
1023  bBreak = !xRowLocate->moveToBookmark(pSelection[i]);
1024  }
1025  else if(!i)
1026  bBreak = !xResultSet->first();
1027  }
1028  catch (const Exception&)
1029  {
1030  bBreak = true;
1031  }
1032  if(bBreak)
1033  break;
1034 
1035  for( sal_Int32 n = 0; n < nCols; ++n )
1036  {
1037  // at the very first time, NO GoNextCell, because we're
1038  // already in it. Also no GoNextCell after the Insert,
1039  // because an empty line is added at the end.
1040  if( i || n )
1041  rSh.GoNextCell();
1042 
1043  const SwInsDBColumn* pEntry = aColFields[ n ];
1044 
1045  Reference< XColumn > xColumn;
1046  xCols->getByName(pEntry->sColumn) >>= xColumn;
1047  Reference< XPropertySet > xColumnProps( xColumn, UNO_QUERY );
1048  sal_Int32 eDataType = 0;
1049  if( xColumnProps.is() )
1050  {
1051  Any aType = xColumnProps->getPropertyValue("Type");
1052  aType >>= eDataType;
1053  }
1054  try
1055  {
1056  if( pEntry->bHasFormat )
1057  {
1058  SwTableBoxNumFormat aNumFormat(
1059  pEntry->bIsDBFormat ? static_cast<sal_uInt32>(pEntry->nDBNumFormat)
1060  : pEntry->nUsrNumFormat );
1061  aTableSet.Put(aNumFormat);
1062  if( xColumn.is() )
1063  {
1064  double fVal = xColumn->getDouble();
1065  if( xColumn->wasNull() )
1066  aTableSet.ClearItem( RES_BOXATR_VALUE );
1067  else
1068  {
1069  if(rNumFormatr.GetType(aNumFormat.GetValue()) & SvNumFormatType::DATE)
1070  {
1071  ::Date aStandard(1,1,1900);
1072  if (rNumFormatr.GetNullDate() != aStandard)
1073  fVal += (aStandard - rNumFormatr.GetNullDate());
1074  }
1075  aTableSet.Put( SwTableBoxValue( fVal ));
1076  }
1077  }
1078  else
1079  aTableSet.ClearItem( RES_BOXATR_VALUE );
1080  rSh.SetTableBoxFormulaAttrs( aTableSet );
1081  }
1082  //#i60207# don't insert binary data as string - creates a loop
1083  else if( DataType::BINARY == eDataType ||
1084  DataType::VARBINARY == eDataType ||
1085  DataType::LONGVARBINARY== eDataType ||
1086  DataType::SQLNULL == eDataType ||
1087  DataType::OTHER == eDataType ||
1088  DataType::OBJECT == eDataType ||
1089  DataType::DISTINCT == eDataType ||
1090  DataType::STRUCT == eDataType ||
1091  DataType::ARRAY == eDataType ||
1092  DataType::BLOB == eDataType ||
1093  DataType::CLOB == eDataType ||
1094  DataType::REF == eDataType
1095  )
1096  {
1097  // do nothing
1098  }
1099  else
1100  {
1101  const OUString sVal = xColumn->getString();
1102  if(!xColumn->wasNull())
1103  {
1104  rSh.SwEditShell::Insert2( sVal );
1105  }
1106  }
1107  }
1108  catch (const Exception&)
1109  {
1110  TOOLS_WARN_EXCEPTION("sw", "");
1111  }
1112  }
1113 
1114  if( !pSelection )
1115  {
1116  if ( !xResultSet->next() )
1117  break;
1118  }
1119  else if( i+1 >= rSelection.getLength() )
1120  break;
1121 
1122  if( 10 == i )
1123  pWait.reset(new SwWait( *pView->GetDocShell(), true ));
1124  }
1125 
1127  if( !pSelection && ( pTableSet || m_xTAutoFormat ))
1128  {
1129  if( pTableSet )
1130  SetTabSet();
1131 
1132  if (m_xTAutoFormat)
1134  }
1135  rSh.SetAutoUpdateCells( bIsAutoUpdateCells );
1136  }
1137  else // add data as fields/text
1138  {
1139  DB_Columns aColArr;
1140  if( SplitTextToColArr( m_xEdDbText->get_text(), aColArr, m_xRbAsField->get_active() ) )
1141  {
1142  // now for each data set, we can iterate over the array
1143  // and add the data
1144 
1145  if( !rSh.IsSttPara() )
1146  rSh.SwEditShell::SplitNode();
1147  if( !rSh.IsEndPara() )
1148  {
1149  rSh.SwEditShell::SplitNode();
1150  rSh.SwCursorShell::Left(1,CRSR_SKIP_CHARS);
1151  }
1152 
1153  rSh.DoUndo( false );
1154 
1155  SwTextFormatColl* pColl = nullptr;
1156  {
1157  const OUString sTmplNm(m_xLbDbParaColl->get_active_text());
1158  if( sNoTmpl != sTmplNm )
1159  {
1160  pColl = rSh.FindTextFormatCollByName( sTmplNm );
1161  if( !pColl )
1162  {
1163  const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(
1164  sTmplNm, SwGetPoolIdFromName::TxtColl );
1165  if( USHRT_MAX != nId )
1166  pColl = rSh.GetTextCollFromPool( nId );
1167  else
1168  pColl = rSh.MakeTextFormatColl( sTmplNm );
1169  }
1170  rSh.SetTextFormatColl( pColl );
1171  }
1172  }
1173 
1174  // for adding as fields -> insert a "NextField" after
1175  // every data set
1176  SwDBFormatData aDBFormatData;
1178  aDBFormatData.xFormatter.set(util::NumberFormatter::create(xContext), UNO_QUERY_THROW) ;
1179 
1180  Reference<XPropertySet> xSourceProps(xSource, UNO_QUERY);
1181  if(xSourceProps.is())
1182  {
1183  Any aFormats = xSourceProps->getPropertyValue("NumberFormatsSupplier");
1184  if(aFormats.hasValue())
1185  {
1186  Reference< util::XNumberFormatsSupplier> xSuppl;
1187  aFormats >>= xSuppl;
1188  if(xSuppl.is())
1189  {
1190  Reference< XPropertySet > xSettings = xSuppl->getNumberFormatSettings();
1191  Any aNull = xSettings->getPropertyValue("NullDate");
1192  aNull >>= aDBFormatData.aNullDate;
1193  if(aDBFormatData.xFormatter.is())
1194  aDBFormatData.xFormatter->attachNumberFormatsSupplier(xSuppl);
1195  }
1196  }
1197  }
1198  aDBFormatData.aLocale = LanguageTag( rSh.GetCurLang() ).getLocale();
1199  SwDBNextSetField aNxtDBField( static_cast<SwDBNextSetFieldType*>(rSh.
1200  GetFieldType( 0, SwFieldIds::DbNextSet )),
1201  "1", aDBData );
1202 
1203  bool bSetCursor = true;
1204  const size_t nCols = aColArr.size();
1205  ::sw::mark::IMark* pMark = nullptr;
1206  for( sal_Int32 i = 0 ; ; ++i )
1207  {
1208  bool bBreak = false;
1209  try
1210  {
1211  if(pSelection)
1212  {
1213  bBreak = !xRowLocate->moveToBookmark(pSelection[i]);
1214  }
1215  else if(!i)
1216  bBreak = !xResultSet->first();
1217  }
1218  catch (const Exception&)
1219  {
1220  bBreak = true;
1221  }
1222 
1223  if(bBreak)
1224  break;
1225 
1226  for( size_t n = 0; n < nCols; ++n )
1227  {
1228  DB_Column* pDBCol = aColArr[ n ].get();
1229  OUString sIns;
1230  switch( pDBCol->eColType )
1231  {
1233  sIns = *pDBCol->pText;
1234  break;
1235 
1237  rSh.SplitNode();
1238  // when the template is not the same as the follow template,
1239  // the selected has to be set newly
1240  if( pColl && &pColl->GetNextTextFormatColl() != pColl )
1241  rSh.SetTextFormatColl( pColl );
1242  break;
1243 
1245  {
1246  std::unique_ptr<SwDBField> pField(static_cast<SwDBField *>(
1247  pDBCol->pField->CopyField().release()));
1248  double nValue = DBL_MAX;
1249 
1250  Reference< XPropertySet > xColumnProps;
1251  xCols->getByName(pDBCol->pColInfo->sColumn) >>= xColumnProps;
1252 
1253  pField->SetExpansion( SwDBManager::GetDBField(
1254  xColumnProps,
1255  aDBFormatData,
1256  &nValue ) );
1257  if( DBL_MAX != nValue )
1258  {
1259  Any aType = xColumnProps->getPropertyValue("Type");
1260  sal_Int32 eDataType = 0;
1261  aType >>= eDataType;
1262  if( DataType::DATE == eDataType || DataType::TIME == eDataType ||
1263  DataType::TIMESTAMP == eDataType)
1264 
1265  {
1266  ::Date aStandard(1,1,1900);
1267  ::Date aCompare(aDBFormatData.aNullDate.Day ,
1268  aDBFormatData.aNullDate.Month,
1269  aDBFormatData.aNullDate.Year);
1270  if(aStandard != aCompare)
1271  nValue += (aStandard - aCompare);
1272  }
1273  pField->ChgValue( nValue, true );
1274  }
1275  pField->SetInitialized();
1276 
1277  rSh.Insert( *pField );
1278  }
1279  break;
1280 
1282  {
1283  double nValue = DBL_MAX;
1284  Reference< XPropertySet > xColumnProps;
1285  xCols->getByName(pDBCol->pColInfo->sColumn) >>= xColumnProps;
1286  sIns = SwDBManager::GetDBField(
1287  xColumnProps,
1288  aDBFormatData,
1289  &nValue );
1290  if( pDBCol->nFormat &&
1291  DBL_MAX != nValue )
1292  {
1293  Color* pCol;
1294  if(rNumFormatr.GetType(pDBCol->nFormat) & SvNumFormatType::DATE)
1295  {
1296  ::Date aStandard(1,1,1900);
1297  if (rNumFormatr.GetNullDate() != aStandard)
1298  nValue += (aStandard - rNumFormatr.GetNullDate());
1299  }
1300  rNumFormatr.GetOutputString( nValue,
1301  pDBCol->nFormat,
1302  sIns, &pCol );
1303  }
1304  }
1305  break;
1306  }
1307 
1308  if( !sIns.isEmpty() )
1309  {
1310  rSh.Insert( sIns );
1311 
1312  if( bSetCursor)
1313  {
1314  // to the beginning and set a mark, so that
1315  // the cursor can be set to the initial position
1316  // at the end.
1317 
1318  rSh.SwCursorShell::MovePara(
1320  pMark = rSh.SetBookmark(
1321  vcl::KeyCode(),
1322  OUString(),
1324  rSh.SwCursorShell::MovePara(
1325  GoCurrPara, fnParaEnd );
1326  bSetCursor = false;
1327  }
1328  }
1329  }
1330 
1331  if( !pSelection )
1332  {
1333  bool bNext = xResultSet->next();
1334  if(!bNext)
1335  break;
1336  }
1337  else if( i+1 >= rSelection.getLength() )
1338  break;
1339 
1340  if( m_xRbAsField->get_active() )
1341  rSh.Insert( aNxtDBField );
1342 
1343  if( !rSh.IsSttPara() )
1344  rSh.SwEditShell::SplitNode();
1345 
1346  if( 10 == i )
1347  pWait.reset(new SwWait( *pView->GetDocShell(), true ));
1348  }
1349 
1350  if( !bSetCursor && pMark != nullptr)
1351  {
1352  rSh.SetMark();
1353  rSh.GotoMark( pMark );
1354  rSh.getIDocumentMarkAccess()->deleteMark( pMark );
1355  break;
1356  }
1357  }
1358  }
1359  // write configuration
1360  Commit();
1361  }while( false ); // middle checked loop
1362 
1363  if( bUndo )
1364  {
1365  rSh.DoUndo();
1366  rSh.AppendUndoForInsertFromDB( bAsTable );
1367  rSh.EndUndo();
1368  }
1369  rSh.ClearMark();
1370  rSh.EndAllAction();
1371 
1372  if ( bDisposeResultSet )
1373  ::comphelper::disposeComponent(xResultSet);
1374 }
1375 
1377 {
1378  SwWrtShell& rSh = pView->GetWrtShell();
1379  const SfxPoolItem* pItem;
1380 
1381  if (m_xTAutoFormat)
1382  {
1383  if (m_xTAutoFormat->IsFrame())
1384  {
1385  // border is from AutoFormat
1386  pTableSet->ClearItem( RES_BOX );
1387  pTableSet->ClearItem( SID_ATTR_BORDER_INNER );
1388  }
1389  if (m_xTAutoFormat->IsBackground())
1390  {
1391  pTableSet->ClearItem( RES_BACKGROUND );
1392  pTableSet->ClearItem( SID_ATTR_BRUSH_ROW );
1393  pTableSet->ClearItem( SID_ATTR_BRUSH_TABLE );
1394  }
1395  }
1396  else
1397  {
1398  // remove the defaults again, it makes no sense to set them
1399  SvxBrushItem aBrush( RES_BACKGROUND );
1400  static const sal_uInt16 aIds[3] =
1401  { RES_BACKGROUND, SID_ATTR_BRUSH_ROW, SID_ATTR_BRUSH_TABLE };
1402  for(sal_uInt16 i : aIds)
1403  if( SfxItemState::SET == pTableSet->GetItemState( i,
1404  false, &pItem ) && *pItem == aBrush )
1405  pTableSet->ClearItem( i );
1406  }
1407 
1408  if( SfxItemState::SET == pTableSet->GetItemState( FN_PARAM_TABLE_NAME, false,
1409  &pItem ) && static_cast<const SfxStringItem*>(pItem)->GetValue() ==
1410  rSh.GetTableFormat()->GetName() )
1411  pTableSet->ClearItem( FN_PARAM_TABLE_NAME );
1412 
1414  rSh.SetMark();
1416 
1417  ItemSetToTableParam( *pTableSet, rSh );
1418 
1419  rSh.ClearMark();
1421 }
1422 
1423 static Sequence<OUString> lcl_createSourceNames(const OUString& rNodeName)
1424 {
1425  Sequence<OUString> aSourceNames(11);
1426  OUString* pNames = aSourceNames.getArray();
1427  pNames[0] = rNodeName + "/DataSource";
1428  pNames[1] = rNodeName + "/Command";
1429  pNames[2] = rNodeName + "/CommandType";
1430  pNames[3] = rNodeName + "/ColumnsToText";
1431  pNames[4] = rNodeName + "/ColumnsToTable";
1432  pNames[5] = rNodeName + "/ParaStyle";
1433  pNames[6] = rNodeName + "/TableAutoFormat";
1434  pNames[7] = rNodeName + "/IsTable";
1435  pNames[8] = rNodeName + "/IsField";
1436  pNames[9] = rNodeName + "/IsHeadlineOn";
1437  pNames[10] = rNodeName + "/IsEmptyHeadline";
1438  return aSourceNames;
1439 }
1440 
1441 static Sequence<OUString> lcl_CreateSubNames(const OUString& rSubNodeName)
1442 {
1443  Sequence<OUString> aSubSourceNames(6);
1444  OUString* pNames = aSubSourceNames.getArray();
1445  pNames[0] = rSubNodeName + "/ColumnName";
1446  pNames[1] = rSubNodeName + "/ColumnIndex";
1447  pNames[2] = rSubNodeName + "/IsNumberFormat";
1448  pNames[3] = rSubNodeName + "/IsNumberFormatFromDataBase";
1449  pNames[4] = rSubNodeName + "/NumberFormat";
1450  pNames[5] = rSubNodeName + "/NumberFormatLocale";
1451  return aSubSourceNames;
1452 }
1453 
1454 static OUString lcl_CreateUniqueName(const Sequence<OUString>& aNames)
1455 {
1456  sal_Int32 nIdx = aNames.getLength();
1457  while(true)
1458  {
1459  const OUString sRet = "_" + OUString::number(nIdx++);
1460  if ( comphelper::findValue(aNames, sRet) == -1 )
1461  return sRet; // No match found, return unique name
1462  }
1463 }
1464 
1465 void SwInsertDBColAutoPilot::Notify( const css::uno::Sequence< OUString >& ) {}
1466 
1468 {
1469  Sequence <OUString> aNames = GetNodeNames(OUString());
1470  //remove entries that contain this data source + table at first
1471  for(OUString const & nodeName : std::as_const(aNames))
1472  {
1473  Sequence<OUString> aSourceNames(2);
1474  OUString* pSourceNames = aSourceNames.getArray();
1475  pSourceNames[0] = nodeName + "/DataSource";
1476  pSourceNames[1] = nodeName + "/Command";
1477  Sequence<Any> aSourceProperties = GetProperties(aSourceNames);
1478  const Any* pSourceProps = aSourceProperties.getArray();
1479  OUString sSource, sCommand;
1480  pSourceProps[0] >>= sSource;
1481  pSourceProps[1] >>= sCommand;
1482  if(sSource==aDBData.sDataSource && sCommand==aDBData.sCommand)
1483  {
1484  Sequence<OUString> aElements { nodeName };
1485  ClearNodeElements(OUString(), aElements);
1486  }
1487  }
1488 
1489  aNames = GetNodeNames(OUString());
1490  OUString sNewNode = lcl_CreateUniqueName(aNames);
1491  Sequence<OUString> aNodeNames = lcl_createSourceNames(sNewNode);
1492  Sequence<PropertyValue> aValues(aNodeNames.getLength());
1493  PropertyValue* pValues = aValues.getArray();
1494  const OUString* pNodeNames = aNodeNames.getConstArray();
1495  for(sal_Int32 i = 0; i < aNodeNames.getLength(); i++)
1496  {
1497  pValues[i].Name = "/" + pNodeNames[i];
1498  }
1499 
1500  pValues[0].Value <<= aDBData.sDataSource;
1501  pValues[1].Value <<= aDBData.sCommand;
1502  pValues[2].Value <<= aDBData.nCommandType;
1503  pValues[3].Value <<= m_xEdDbText->get_text();
1504 
1505  OUString sTmp;
1506  const sal_Int32 nCnt = m_xLbTableCol->n_children();
1507  for( sal_Int32 n = 0; n < nCnt; ++n )
1508  sTmp += m_xLbTableCol->get_text(n) + "\x0a";
1509 
1510  if (!sTmp.isEmpty())
1511  pValues[4].Value <<= sTmp;
1512 
1513  if( sNoTmpl != (sTmp = m_xLbDbParaColl->get_active_text()) )
1514  pValues[5].Value <<= sTmp;
1515 
1516  if (m_xTAutoFormat)
1517  pValues[6].Value <<= m_xTAutoFormat->GetName();
1518 
1519  pValues[7].Value <<= m_xRbAsTable->get_active();
1520  pValues[8].Value <<= m_xRbAsField->get_active();
1521  pValues[9].Value <<= m_xCbTableHeadon->get_active();
1522  pValues[10].Value <<= m_xRbHeadlEmpty->get_active();
1523 
1524  SetSetProperties(OUString(), aValues);
1525 
1526  sNewNode += "/ColumnSet";
1527 
1528  LanguageType ePrevLang(0xffff);
1529 
1531  for(size_t nCol = 0; nCol < aDBColumns.size(); nCol++)
1532  {
1533  SwInsDBColumn* pColumn = aDBColumns[nCol].get();
1534  OUString sColumnInsertNode(sNewNode + "/__");
1535  if( nCol < 10 )
1536  sColumnInsertNode += "00";
1537  else if( nCol < 100 )
1538  sColumnInsertNode += "0";
1539  sColumnInsertNode += OUString::number( nCol );
1540 
1541  const Sequence <OUString> aSubNodeNames = lcl_CreateSubNames(sColumnInsertNode);
1542  Sequence<PropertyValue> aSubValues(aSubNodeNames.getLength());
1543  PropertyValue* pSubValues = aSubValues.getArray();
1544  sal_Int32 i = 0;
1545 
1546  for( const OUString& rSubNodeName : aSubNodeNames)
1547  pSubValues[i++].Name = rSubNodeName;
1548  pSubValues[0].Value <<= pColumn->sColumn;
1549  pSubValues[1].Value <<= i;
1550  pSubValues[2].Value <<= pColumn->bHasFormat;
1551  pSubValues[3].Value <<= pColumn->bIsDBFormat;
1552 
1554  const SvNumberformat* pNF = rNFormatr.GetEntry( pColumn->nUsrNumFormat );
1555  LanguageType eLang;
1556  if( pNF )
1557  {
1558  pSubValues[4].Value <<= pNF->GetFormatstring();
1559  eLang = pNF->GetLanguage();
1560  }
1561  else
1562  {
1563  pSubValues[4].Value <<= sTmp;
1564  eLang = GetAppLanguage();
1565  }
1566 
1567  OUString sPrevLang;
1568  if( eLang != ePrevLang )
1569  {
1570  sPrevLang = LanguageTag::convertToBcp47( eLang );
1571  ePrevLang = eLang;
1572  }
1573 
1574  pSubValues[5].Value <<= sPrevLang;
1575  SetSetProperties(sNewNode, aSubValues);
1576  }
1577 }
1578 
1580 {
1581  const Sequence<OUString> aNames = GetNodeNames(OUString());
1583  for(OUString const & nodeName : aNames)
1584  {
1585  //search for entries with the appropriate data source and table
1586  Sequence<OUString> aSourceNames = lcl_createSourceNames(nodeName);
1587 
1588  Sequence< Any> aDataSourceProps = GetProperties(aSourceNames);
1589  const Any* pDataSourceProps = aDataSourceProps.getConstArray();
1590  OUString sSource, sCommand;
1591  sal_Int16 nCommandType;
1592  pDataSourceProps[0] >>= sSource;
1593  pDataSourceProps[1] >>= sCommand;
1594  pDataSourceProps[2] >>= nCommandType;
1595  if(sSource == aDBData.sDataSource && sCommand == aDBData.sCommand)
1596  {
1597  std::unique_ptr<DB_ColumnConfigData> pNewData(new DB_ColumnConfigData);
1598 
1599  pDataSourceProps[3] >>= pNewData->sEdit;
1600  pDataSourceProps[4] >>= pNewData->sTableList;
1601  pDataSourceProps[5] >>= pNewData->sTmplNm;
1602  pDataSourceProps[6] >>= pNewData->sTAutoFormatNm;
1603  if(pDataSourceProps[7].hasValue())
1604  pNewData->bIsTable = *o3tl::doAccess<bool>(pDataSourceProps[7]);
1605  if(pDataSourceProps[8].hasValue())
1606  pNewData->bIsField = *o3tl::doAccess<bool>(pDataSourceProps[8]);
1607  if(pDataSourceProps[9].hasValue())
1608  pNewData->bIsHeadlineOn = *o3tl::doAccess<bool>(pDataSourceProps[9]);
1609  if(pDataSourceProps[10].hasValue())
1610  pNewData->bIsEmptyHeadln = *o3tl::doAccess<bool>(pDataSourceProps[10]);
1611 
1612  const OUString sSubNodeName(nodeName + "/ColumnSet/");
1613  const Sequence <OUString> aSubNames = GetNodeNames(sSubNodeName);
1614  for(const OUString& rSubName : aSubNames)
1615  {
1616  Sequence <OUString> aSubNodeNames =
1617  lcl_CreateSubNames(sSubNodeName + rSubName);
1618  Sequence< Any> aSubProps = GetProperties(aSubNodeNames);
1619  const Any* pSubProps = aSubProps.getConstArray();
1620 
1621  OUString sColumn;
1622  pSubProps[0] >>= sColumn;
1623  // check for existence of the loaded column name
1624  bool bFound = false;
1625  for(size_t nRealColumn = 0; nRealColumn < aDBColumns.size(); ++nRealColumn)
1626  {
1627  if(aDBColumns[nRealColumn]->sColumn == sColumn)
1628  {
1629  bFound = true;
1630  break;
1631  }
1632  }
1633  if(!bFound)
1634  continue;
1635  sal_Int16 nIndex = 0;
1636  pSubProps[1] >>= nIndex;
1637  std::unique_ptr<SwInsDBColumn> pInsDBColumn(new SwInsDBColumn(sColumn));
1638  if(pSubProps[2].hasValue())
1639  pInsDBColumn->bHasFormat = *o3tl::doAccess<bool>(pSubProps[2]);
1640  if(pSubProps[3].hasValue())
1641  pInsDBColumn->bIsDBFormat = *o3tl::doAccess<bool>(pSubProps[3]);
1642 
1643  pSubProps[4] >>= pInsDBColumn->sUsrNumFormat;
1644  OUString sNumberFormatLocale;
1645  pSubProps[5] >>= sNumberFormatLocale;
1646 
1647  /* XXX Earlier versions wrote a Country-Language string in
1648  * SwInsertDBColAutoPilot::Commit() that here was read as
1649  * Language-Country with 2 characters copied to language,
1650  * 1 character separator and unconditionally 2 characters read
1651  * as country. So for 'DE-de' and locales that have similar
1652  * case-insensitive equal language/country combos that may have
1653  * worked, for all others not. FIXME if you need to read old
1654  * data that you were never able to read before. */
1655  pInsDBColumn->eUsrNumFormatLng = LanguageTag::convertToLanguageType( sNumberFormatLocale );
1656 
1657  pInsDBColumn->nUsrNumFormat = rNFormatr.GetEntryKey( pInsDBColumn->sUsrNumFormat,
1658  pInsDBColumn->eUsrNumFormatLng );
1659 
1660  pNewData->aDBColumns.insert(std::move(pInsDBColumn));
1661  }
1662  OUString sTmp( pNewData->sTableList );
1663  if( !sTmp.isEmpty() )
1664  {
1665  sal_Int32 n = 0;
1666  do {
1667  const OUString sEntry( sTmp.getToken( 0, '\x0a', n ) );
1668  //preselect column - if they still exist!
1669  if (m_xLbTableDbColumn->find_text(sEntry) != -1)
1670  {
1671  m_xLbTableCol->append_text(sEntry);
1672  m_xLbTableDbColumn->remove_text(sEntry);
1673  }
1674  } while( n>=0 );
1675 
1676  if (!m_xLbTableDbColumn->n_children())
1677  {
1678  m_xIbDbcolAllTo->set_sensitive( false );
1679  m_xIbDbcolOneTo->set_sensitive( false );
1680  }
1681  m_xIbDbcolOneFrom->set_sensitive(true);
1682  m_xIbDbcolAllFrom->set_sensitive(true);
1683  }
1684  m_xEdDbText->set_text( pNewData->sEdit );
1685 
1686  sTmp = pNewData->sTmplNm;
1687  if( !sTmp.isEmpty() )
1688  m_xLbDbParaColl->set_active_text(sTmp);
1689  else
1690  m_xLbDbParaColl->set_active(0);
1691 
1692  m_xTAutoFormat.reset();
1693  sTmp = pNewData->sTAutoFormatNm;
1694  if( !sTmp.isEmpty() )
1695  {
1696  // then load the AutoFormat file and look for Autoformat first
1697  SwTableAutoFormatTable aAutoFormatTable;
1698  aAutoFormatTable.Load();
1699  for( size_t nAutoFormat = aAutoFormatTable.size(); nAutoFormat; )
1700  if( sTmp == aAutoFormatTable[ --nAutoFormat ].GetName() )
1701  {
1702  m_xTAutoFormat.reset(new SwTableAutoFormat(aAutoFormatTable[nAutoFormat]));
1703  break;
1704  }
1705  }
1706 
1707  m_xRbAsTable->set_active( pNewData->bIsTable );
1708  m_xRbAsField->set_active( pNewData->bIsField );
1709  m_xRbAsText->set_active( !pNewData->bIsTable && !pNewData->bIsField );
1710 
1711  m_xCbTableHeadon->set_active( pNewData->bIsHeadlineOn );
1712  m_xRbHeadlColnms->set_active( !pNewData->bIsEmptyHeadln );
1713  m_xRbHeadlEmpty->set_active( pNewData->bIsEmptyHeadln );
1714  HeaderHdl(*m_xCbTableHeadon);
1715 
1716  // now copy the user defined Numberformat strings to the
1717  // Shell. Then only these are available as ID
1718  for( size_t n = 0; n < aDBColumns.size() ; ++n )
1719  {
1720  SwInsDBColumn& rSet = *aDBColumns[ n ];
1721  for( size_t m = 0; m < pNewData->aDBColumns.size() ; ++m )
1722  {
1723  SwInsDBColumn& rGet = *pNewData->aDBColumns[ m ];
1724  if(rGet.sColumn == rSet.sColumn)
1725  {
1726  if( rGet.bHasFormat && !rGet.bIsDBFormat )
1727  {
1728  rSet.bIsDBFormat = false;
1729  rSet.nUsrNumFormat = rNFormatr.GetEntryKey( rGet.sUsrNumFormat,
1730  rGet.eUsrNumFormatLng );
1732  {
1733  sal_Int32 nCheckPos;
1735  rNFormatr.PutEntry( rGet.sUsrNumFormat, nCheckPos, nType,
1736  rSet.nUsrNumFormat, rGet.eUsrNumFormatLng );
1737  }
1738  }
1739  break;
1740  }
1741  }
1742  }
1743 
1744  // when the cursor is inside of a table, table must NEVER be selectable
1745  if( !m_xRbAsTable->get_sensitive() && m_xRbAsTable->get_active() )
1746  m_xRbAsField->set_active(true);
1747  break;
1748  }
1749  }
1750 }
1751 
1752 /* 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:991
static void lcl_InsTextInArr(const OUString &rText, DB_Columns &rColArr)
Definition: dbinsdlg.cxx:810
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: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:806
bool GoCurrPara(SwPaM &rPam, SwMoveFnCollection const &aPosPara)
Definition: pam.cxx:1009
virtual const SfxItemSet * GetOutputItemSet() const =0
std::string GetValue
const Color aColNames[SC_RANGECOLORS]
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: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: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:640
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:775
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:1465
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:398
bool GotoCurrTable(SwPaM &rCurrentCursor, SwMoveFnCollection const &fnPosTable, bool bInReadOnly)
Definition: trvltbl.cxx:632
LanguageType GetCurLang() const
Definition: edattr.cxx:811
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
#define FN_PARAM_TABLE_HEADLINE
Definition: cmdid.h:776
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:1172
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:282
const IDocumentMarkAccess * getIDocumentMarkAccess() const
Provides access to the document bookmark interface.
Definition: viewsh.cxx:2587
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:3180
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:612
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:255
int i
const SwColumns & GetColumns() const
Definition: fmtclds.hxx:112
SwFieldType * InsertFieldType(const SwFieldType &)
insert field type
Definition: edfld.cxx:347
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:973
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:1139
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
const_iterator end() const
OUString SwResId(const char *pId)
Definition: swmodule.cxx:165
static Sequence< OUString > lcl_createSourceNames(const OUString &rNodeName)
Definition: dbinsdlg.cxx:1423
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:905
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:530
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:342
sal_Int32 nDBNumFormat
Definition: dbinsdlg.hxx:57
const SvNumberformat * GetEntry(sal_uInt32 nKey) const
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:424
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:1441
SwTextFormatColl * FindTextFormatCollByName(const OUString &rName) const
Definition: edfmt.cxx:154
LanguageType GetAppLanguage()
Definition: init.cxx:728
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:1467
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:2007
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:938
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:1454
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:2228
bool DoesUndo() const
Definition: edws.cxx:203
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: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:236
std::unique_ptr< weld::RadioButton > m_xRbDbFormatFromDb
Definition: dbinsdlg.hxx:103
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:97
bool bHasFormat
Definition: dbinsdlg.hxx:60
sal_Int16 nValue
CollatorWrapper & GetAppCollator()
Definition: init.cxx:740
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