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