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