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