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