LibreOffice Module dbaccess (master) 1
TEditControl.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 "TEditControl.hxx"
21#include <com/sun/star/sdbc/ColumnValue.hpp>
22#include <com/sun/star/sdbc/SQLException.hpp>
23#include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
24#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
25#include <com/sun/star/util/XNumberFormatTypes.hpp>
26#include <core_resource.hxx>
27#include <strings.hrc>
28#include <strings.hxx>
29#include <helpids.h>
30#include <comphelper/types.hxx>
31#include <FieldDescControl.hxx>
32#include <FieldDescriptions.hxx>
33#include "TableUndo.hxx"
34#include <TableController.hxx>
37#include <SqlNameEdit.hxx>
38#include <TableRowExchange.hxx>
39#include <o3tl/safeint.hxx>
40#include <sot/storage.hxx>
41#include <svx/svxids.hrc>
42#include <UITools.hxx>
43#include "TableFieldControl.hxx"
44#include <dsntypes.hxx>
45#include <vcl/commandevent.hxx>
46#include <vcl/svapp.hxx>
47
48using namespace ::dbaui;
49using namespace ::comphelper;
50using namespace ::svt;
51using namespace ::com::sun::star::uno;
52using namespace ::com::sun::star::container;
53using namespace ::com::sun::star::io;
54using namespace ::com::sun::star::beans;
55using namespace ::com::sun::star::util;
56using namespace ::com::sun::star::lang;
57using namespace ::com::sun::star::sdbc;
58using namespace ::com::sun::star::sdbcx;
59using namespace ::com::sun::star::sdb;
60
61
62#define HANDLE_ID 0
63
64// default field widths
65#define FIELDNAME_WIDTH 100
66#define FIELDTYPE_WIDTH 150
67#define FIELDDESCR_WIDTH 300
68
69// Maximum length in description field
70#define MAX_DESCR_LEN 256
71
72OTableEditorCtrl::ClipboardInvalidator::ClipboardInvalidator(OTableEditorCtrl* _pOwner)
73: m_aInvalidateTimer("dbaccess ClipboardInvalidator")
74, m_pOwner(_pOwner)
75{
76
80}
81
83{
84 m_aInvalidateTimer.Stop();
85}
86
88{
89 m_aInvalidateTimer.Stop();
90}
91
92IMPL_LINK_NOARG(OTableEditorCtrl::ClipboardInvalidator, OnInvalidate, Timer *, void)
93{
94 m_pOwner->GetView()->getController().InvalidateFeature(SID_CUT);
95 m_pOwner->GetView()->getController().InvalidateFeature(SID_COPY);
96 m_pOwner->GetView()->getController().InvalidateFeature(SID_PASTE);
97}
98
100{
102
103 // Should it be opened ReadOnly?
104 bool bRead(GetView()->getController().isReadOnly());
105
106 SetReadOnly( bRead );
107
108 // Insert the columns
109 InsertDataColumn( FIELD_NAME, DBA_RES(STR_TAB_FIELD_COLUMN_NAME), FIELDNAME_WIDTH );
110
111 InsertDataColumn( FIELD_TYPE, DBA_RES(STR_TAB_FIELD_COLUMN_DATATYPE), FIELDTYPE_WIDTH );
112
113 ::dbaccess::ODsnTypeCollection aDsnTypes(GetView()->getController().getORB());
114 bool bShowColumnDescription = aDsnTypes.supportsColumnDescription(::comphelper::getString(GetView()->getController().getDataSource()->getPropertyValue(PROPERTY_URL)));
115 InsertDataColumn( HELP_TEXT, DBA_RES(STR_TAB_HELP_TEXT), bShowColumnDescription ? FIELDTYPE_WIDTH : FIELDDESCR_WIDTH );
116
117 if ( bShowColumnDescription )
118 {
119 InsertDataColumn( COLUMN_DESCRIPTION, DBA_RES(STR_COLUMN_DESCRIPTION), FIELDTYPE_WIDTH );
120 }
121
123
124 // Insert the rows
125 RowInserted(0, m_pRowList->size());
126}
127
129 :OTableRowView(pWindow)
130 ,m_pView(pView)
131 ,pNameCell(nullptr)
132 ,pTypeCell(nullptr)
133 ,pHelpTextCell(nullptr)
134 ,pDescrCell(nullptr)
135 ,pDescrWin(nullptr)
136 ,nCutEvent(nullptr)
137 ,nPasteEvent(nullptr)
138 ,nDeleteEvent(nullptr)
139 ,nInsNewRowsEvent(nullptr)
140 ,nInvalidateTypeEvent(nullptr)
142 ,nOldDataPos(-1)
143 ,bReadOnly(true)
144 ,m_aInvalidate(this)
145{
147 GetDataWindow().SetHelpId(HID_CTL_TABLEEDIT);
148
150 m_nDataPos = 0;
151}
152
154{
156}
157
158
160{
161 // nothing to do?
162 if (bRead == IsReadOnly())
163 // This check is important, as the underlying Def may be unnecessarily locked or unlocked
164 // or worse, this action may not be reversed afterwards
165 return;
166
167 bReadOnly = bRead;
168
169 // Disable active cells
170 sal_Int32 nRow(GetCurRow());
171 sal_uInt16 nCol(GetCurColumnId());
173
174 // Select the correct Browsers cursor
175 BrowserMode nMode(BrowserMode::COLUMNSELECTION | BrowserMode::MULTISELECTION | BrowserMode::KEEPHIGHLIGHT |
176 BrowserMode::HLINES | BrowserMode::VLINES|BrowserMode::AUTOSIZE_LASTCOL);
177 if( !bReadOnly )
178 nMode |= BrowserMode::HIDECURSOR;
179 SetMode(nMode);
180
181 if( !bReadOnly )
182 ActivateCell( nRow, nCol );
183}
184
186{
187 // Cell Field name
188 sal_Int32 nMaxTextLen = 0;
189 OUString sExtraNameChars;
191 try
192 {
193 xCon = GetView()->getController().getConnection();
194 Reference< XDatabaseMetaData> xMetaData = xCon.is() ? xCon->getMetaData() : Reference< XDatabaseMetaData>();
195
196 // length 0 is treated by Entry::set_max_length as unlimited
197 nMaxTextLen = xMetaData.is() ? xMetaData->getMaxColumnNameLength() : 0;
198
199 sExtraNameChars = xMetaData.is() ? xMetaData->getExtraNameCharacters() : OUString();
200
201 }
202 catch(SQLException&)
203 {
204 OSL_FAIL("getMaxColumnNameLength");
205 }
206
208 pNameCell->get_widget().set_max_length(nMaxTextLen);
209 pNameCell->setCheck( isSQL92CheckEnabled(xCon) );
210
211 // Cell type
213
214 // Cell description
216 pDescrCell->get_widget().set_max_length(MAX_DESCR_LEN);
217
219 pHelpTextCell->get_widget().set_max_length(MAX_DESCR_LEN);
220
225
226 Size aHeight;
227 const Control* pControls[] = { pTypeCell,pDescrCell,pNameCell,pHelpTextCell};
228 for(const Control* pControl : pControls)
229 {
230 const Size aTemp(pControl->GetOptimalSize());
231 if ( aTemp.Height() > aHeight.Height() )
232 aHeight.setHeight( aTemp.Height() );
233 }
234 SetDataRowHeight(aHeight.Height());
235
237}
238
240{
241 pNameCell->get_widget().save_value();
242 pDescrCell->get_widget().save_value();
243 pHelpTextCell->get_widget().save_value();
244 pTypeCell->get_widget().save_value();
245}
246
248{
249 disposeOnce();
250}
251
253{
254 // Reset the Undo-Manager
256
258
259 // Take possible Events from the queue
260 if( nCutEvent )
262 if( nPasteEvent )
264 if( nDeleteEvent )
266 if( nInsNewRowsEvent )
270
271 // Delete the control types
272 pNameCell.disposeAndClear();
273 pTypeCell.disposeAndClear();
274 pDescrCell.disposeAndClear();
275 pHelpTextCell.disposeAndClear();
276 pDescrWin = nullptr;
277 m_pView.clear();
279}
280
281bool OTableEditorCtrl::SetDataPtr( sal_Int32 nRow )
282{
283 if(nRow == -1)
284 return false;
285
286 OSL_ENSURE(nRow < static_cast<tools::Long>(m_pRowList->size()),"Row is greater than size!");
287 if(nRow >= static_cast<tools::Long>(m_pRowList->size()))
288 return false;
289 pActRow = (*m_pRowList)[nRow];
290 return pActRow != nullptr;
291}
292
293bool OTableEditorCtrl::SeekRow(sal_Int32 _nRow)
294{
295 // Call the Base class to remember which row must be repainted
297
298 m_nCurrentPos = _nRow;
299 return SetDataPtr(_nRow);
300}
301
303 sal_uInt16 nColumnId ) const
304{
305 const OUString aText( GetCellText( m_nCurrentPos, nColumnId ));
306
308 rDev.SetClipRegion(vcl::Region(rRect));
309 rDev.DrawText( rRect, aText, DrawTextFlags::Left | DrawTextFlags::VCenter );
310 rDev.Pop();
311}
312
313CellController* OTableEditorCtrl::GetController(sal_Int32 nRow, sal_uInt16 nColumnId)
314{
315 // If EditorCtrl is ReadOnly, editing is forbidden
317 if (IsReadOnly() || ( xTable.is() &&
318 xTable->getPropertySetInfo()->hasPropertyByName(PROPERTY_TYPE) &&
319 ::comphelper::getString(xTable->getPropertyValue(PROPERTY_TYPE)) == "VIEW"))
320 return nullptr;
321
322 // If the row is ReadOnly, editing is forbidden
323 SetDataPtr( nRow );
324 if( pActRow->IsReadOnly() )
325 return nullptr;
326
327 OFieldDescription* pActFieldDescr = pActRow->GetActFieldDescr();
328 switch (nColumnId)
329 {
330 case FIELD_NAME:
331 return new EditCellController( pNameCell );
332 case FIELD_TYPE:
333 if (pActFieldDescr && !pActFieldDescr->GetName().isEmpty())
334 return new ListBoxCellController( pTypeCell );
335 else return nullptr;
336 case HELP_TEXT:
337 if (pActFieldDescr && !pActFieldDescr->GetName().isEmpty())
338 return new EditCellController( pHelpTextCell );
339 else
340 return nullptr;
342 if (pActFieldDescr && !pActFieldDescr->GetName().isEmpty())
343 return new EditCellController( pDescrCell );
344 else
345 return nullptr;
346 default:
347 return nullptr;
348 }
349}
350
351void OTableEditorCtrl::InitController(CellControllerRef&, sal_Int32 nRow, sal_uInt16 nColumnId)
352{
353 SeekRow( nRow == -1 ? GetCurRow() : nRow);
354 OFieldDescription* pActFieldDescr = pActRow->GetActFieldDescr();
355 OUString aInitString;
356
357 switch (nColumnId)
358 {
359 case FIELD_NAME:
360 {
361 if( pActFieldDescr )
362 aInitString = pActFieldDescr->GetName();
363
364 weld::Entry& rEntry = pNameCell->get_widget();
365 rEntry.set_text(aInitString);
366 rEntry.save_value();
367 break;
368 }
369 case FIELD_TYPE:
370 {
371 if ( pActFieldDescr && pActFieldDescr->getTypeInfo() )
372 aInitString = pActFieldDescr->getTypeInfo()->aUIName;
373
374 // Set the ComboBox contents
375 weld::ComboBox& rTypeList = pTypeCell->get_widget();
376 rTypeList.clear();
377 if( !pActFieldDescr )
378 break;
379
380 const OTypeInfoMap& rTypeInfo = GetView()->getController().getTypeInfo();
381 for (auto const& elem : rTypeInfo)
382 rTypeList.append_text(elem.second->aUIName);
383 rTypeList.set_active_text(aInitString);
384 }
385
386 break;
387 case HELP_TEXT:
388 {
389 if( pActFieldDescr )
390 aInitString = pActFieldDescr->GetHelpText();
391 weld::Entry& rEntry = pHelpTextCell->get_widget();
392 rEntry.set_text(aInitString);
393 rEntry.save_value();
394 break;
395 }
397 {
398 if( pActFieldDescr )
399 aInitString = pActFieldDescr->GetDescription();
400 weld::Entry& rEntry = pDescrCell->get_widget();
401 rEntry.set_text(aInitString);
402 rEntry.save_value();
403 break;
404 }
405 }
406}
407
409{
410 const_cast<OTableEditorCtrl*>(this)->SetDataPtr( nRow );
411 if( !pActRow )
413 if (nRow >= 0 && nRow == m_nDataPos)
414 {
415 if( pActRow->IsPrimaryKey() )
418 }
419 else
420 {
421 if( pActRow->IsPrimaryKey() )
424 }
425}
426
428{
429 if (GetFieldDescr(GetCurRow()) == nullptr)
430 // there is no data in the current row
431 return;
432 if (!SaveModified())
433 return;
434
436 pDescrWin->SaveData( pActRow->GetActFieldDescr() );
437}
438
440{
441 // go to the correct cell
442 SetDataPtr(nRow);
443
444 // Disable Edit-Mode temporarily
445 bool bWasEditing = IsEditing();
446 if (bWasEditing)
448
449 CellControllerRef aTemp;
450 InitController(aTemp, nRow, FIELD_NAME);
451 InitController(aTemp, nRow, FIELD_TYPE);
453 InitController(aTemp, nRow, HELP_TEXT);
454
455 GoToRow(nRow);
456 // Update the Description-Window
458 // redraw the row
459 RowModified(nRow);
460
461 // and re-enable edit mode
463}
464
466{
467 // New line?
469 if( m_nDataPos != nOldDataPos && m_nDataPos != -1)
470 {
471 CellControllerRef aTemp;
476 }
477
479}
480
481sal_Int32 OTableEditorCtrl::HasFieldName( std::u16string_view rFieldName )
482{
483
484 Reference<XConnection> xCon = GetView()->getController().getConnection();
485 Reference< XDatabaseMetaData> xMetaData = xCon.is() ? xCon->getMetaData() : Reference< XDatabaseMetaData>();
486
487 ::comphelper::UStringMixEqual bCase(!xMetaData.is() || xMetaData->supportsMixedCaseQuotedIdentifiers());
488
489 sal_Int32 nCount(0);
490 for (auto const& row : *m_pRowList)
491 {
492 OFieldDescription* pFieldDescr = row->GetActFieldDescr();
493 if( pFieldDescr && bCase(rFieldName,pFieldDescr->GetName()))
494 nCount++;
495 }
496 return nCount;
497}
498
499void OTableEditorCtrl::SaveData(sal_Int32 nRow, sal_uInt16 nColId)
500{
501 // Store the cell content
502 SetDataPtr( nRow == -1 ? GetCurRow() : nRow);
503 OFieldDescription* pActFieldDescr = pActRow->GetActFieldDescr();
504
505 switch( nColId)
506 {
507 // Store NameCell
508 case FIELD_NAME:
509 {
510 // If there is no name, do nothing
511 weld::Entry& rEntry = pNameCell->get_widget();
512 const OUString aName(rEntry.get_text());
513
514 if( aName.isEmpty() )
515 {
516 // If FieldDescr exists, the field is deleted and the old content restored
517 if (pActFieldDescr)
518 {
519 GetUndoManager().AddUndoAction(std::make_unique<OTableEditorTypeSelUndoAct>(this, nRow, FIELD_TYPE, pActFieldDescr->getTypeInfo()));
521 pActFieldDescr = pActRow->GetActFieldDescr();
522 }
523 else
524 return;
525 }
526 if(pActFieldDescr)
527 pActFieldDescr->SetName( aName );
528 rEntry.save_value();
529
530 break;
531 }
532
533 // Store the field type
534 case FIELD_TYPE:
535 break;
536
537 // Store DescrCell
538 case HELP_TEXT:
539 {
540 // if the current field description is NULL, set Default
541 weld::Entry& rEntry = pHelpTextCell->get_widget();
542 if( !pActFieldDescr )
543 {
544 rEntry.set_text(OUString());
545 rEntry.save_value();
546 }
547 else
548 pActFieldDescr->SetHelpText(rEntry.get_text());
549 break;
550 }
552 {
553 // Set the default if the field description is null
554 weld::Entry& rEntry = pDescrCell->get_widget();
555 if( !pActFieldDescr )
556 {
557 rEntry.set_text(OUString());
558 rEntry.save_value();
559 }
560 else
561 pActFieldDescr->SetDescription(rEntry.get_text());
562 break;
563 }
572 pDescrWin->SaveData(pActFieldDescr);
573
574 if ( FIELD_PROPERTY_AUTOINC == nColId && pActFieldDescr->IsAutoIncrement() )
575 {
576 OTableController& rController = GetView()->getController();
577 if ( rController.isAutoIncrementPrimaryKey() )
578 {
579 pActFieldDescr->SetPrimaryKey( true );
581 Invalidate();
582 }
583 }
584 break;
585 }
586}
587
589{
590 sal_uInt16 nColId = GetCurColumnId();
591
592 switch( nColId )
593 {
594 // Field type
595 case FIELD_TYPE:
596 {
597 // Reset the type
598 resetType();
599 } break;
600 }
601
602 return true;
603}
604
605bool OTableEditorCtrl::CursorMoving(sal_Int32 nNewRow, sal_uInt16 nNewCol)
606{
607
608 if (!EditBrowseBox::CursorMoving(nNewRow, nNewCol))
609 return false;
610
611 // Called after SaveModified(), current row is still the old one
612 m_nDataPos = nNewRow;
614
615 // Reset the markers
618
619 // Store the data from the Property window
621 pDescrWin->SaveData( pActRow->GetActFieldDescr() );
622
623 // Show new data in the Property window
625 pDescrWin->DisplayData( pActRow->GetActFieldDescr() );
626
627 return true;
628}
629
630IMPL_LINK_NOARG( OTableEditorCtrl, InvalidateFieldType, void*, void )
631{
632 nInvalidateTypeEvent = nullptr;
633 Invalidate( GetFieldRectPixel(nOldDataPos, FIELD_TYPE) );
634}
635
636void OTableEditorCtrl::CellModified( sal_Int32 nRow, sal_uInt16 nColId )
637{
638
639 // If the description is null, use the default
640 if(nRow == -1)
641 nRow = GetCurRow();
642 SetDataPtr( nRow );
643 OFieldDescription* pActFieldDescr = pActRow->GetActFieldDescr();
644
645 OUString sActionDescription;
646 switch ( nColId )
647 {
648 case FIELD_NAME: sActionDescription = DBA_RES( STR_CHANGE_COLUMN_NAME ); break;
649 case FIELD_TYPE: sActionDescription = DBA_RES( STR_CHANGE_COLUMN_TYPE ); break;
650 case HELP_TEXT:
651 case COLUMN_DESCRIPTION: sActionDescription = DBA_RES( STR_CHANGE_COLUMN_DESCRIPTION ); break;
652 default: sActionDescription = DBA_RES( STR_CHANGE_COLUMN_ATTRIBUTE ); break;
653 }
654
655 GetUndoManager().EnterListAction( sActionDescription, OUString(), 0, ViewShellId(-1) );
656 if (!pActFieldDescr)
657 {
658 const OTypeInfoMap& rTypeInfoMap = GetView()->getController().getTypeInfo();
659 if ( !rTypeInfoMap.empty() )
660 {
661 OTypeInfoMap::const_iterator aTypeIter = rTypeInfoMap.find(DataType::VARCHAR);
662 if ( aTypeIter == rTypeInfoMap.end() )
663 aTypeIter = rTypeInfoMap.begin();
664 pActRow->SetFieldType( aTypeIter->second );
665 }
666 else
667 pActRow->SetFieldType( GetView()->getController().getTypeInfoFallBack() );
668
669 nInvalidateTypeEvent = Application::PostUserEvent( LINK(this, OTableEditorCtrl, InvalidateFieldType), nullptr, true );
670 pActFieldDescr = pActRow->GetActFieldDescr();
671 pDescrWin->DisplayData( pActFieldDescr );
672 GetUndoManager().AddUndoAction( std::make_unique<OTableEditorTypeSelUndoAct>(this, nRow, nColId+1, TOTypeInfoSP()) );
673 }
674
675 if( nColId != FIELD_TYPE )
676 GetUndoManager().AddUndoAction( std::make_unique<OTableDesignCellUndoAct>(this, nRow, nColId) );
677 else
678 {
679 GetUndoManager().AddUndoAction(std::make_unique<OTableEditorTypeSelUndoAct>(this, GetCurRow(), nColId, GetFieldDescr(GetCurRow())->getTypeInfo()));
680 resetType();
681 }
682
683 SaveData(nRow,nColId);
684 // SaveData could create an undo action as well
686 RowModified(nRow);
687
688 // Set the Modify flag
689 GetView()->getController().setModified( true );
691}
692
694{
695 sal_Int32 nPos = pTypeCell->get_widget().get_active();
696 if(nPos != -1)
697 SwitchType( GetView()->getController().getTypeInfo(nPos) );
698 else
700}
701
703{
705}
706
708{
709 GetView()->getController().InvalidateFeature(SID_UNDO);
710 GetView()->getController().InvalidateFeature(SID_REDO);
711 GetView()->getController().InvalidateFeature(SID_SAVEDOC);
712}
713
715{
716 // set to the right row and save it
718 pDescrWin->SaveData( pActRow->GetActFieldDescr() );
719
720 // Copy selected rows to the ClipboardList
721 std::shared_ptr<OTableRow> pClipboardRow;
722 std::shared_ptr<OTableRow> pRow;
723 std::vector< std::shared_ptr<OTableRow> > vClipboardList;
724 vClipboardList.reserve(GetSelectRowCount());
725
727 {
728 pRow = (*m_pRowList)[nIndex];
729 OSL_ENSURE(pRow,"OTableEditorCtrl::CopyRows: Row is NULL!");
730 if ( pRow && pRow->GetActFieldDescr() )
731 {
732 pClipboardRow = std::make_shared<OTableRow>( *pRow );
733 vClipboardList.push_back( pClipboardRow);
734 }
735 }
736 if(!vClipboardList.empty())
737 {
738 rtl::Reference<OTableRowExchange> pData = new OTableRowExchange(std::move(vClipboardList));
739 pData->CopyToClipboard(GetParent());
740 }
741}
742
743OUString OTableEditorCtrl::GenerateName( const OUString& rName )
744{
745 // Create a base name for appending numbers to
746 OUString aBaseName;
747 Reference<XConnection> xCon = GetView()->getController().getConnection();
748 Reference< XDatabaseMetaData> xMetaData = xCon.is() ? xCon->getMetaData() : Reference< XDatabaseMetaData>();
749
750 sal_Int32 nMaxTextLen(xMetaData.is() ? xMetaData->getMaxColumnNameLength() : 0);
751
752 if( (rName.getLength()+2) >nMaxTextLen )
753 aBaseName = rName.copy( 0, nMaxTextLen-2 );
754 else
755 aBaseName = rName;
756
757 // append a sequential number to the base name (up to 99)
758 OUString aFieldName( rName);
759 sal_Int32 i=1;
760 while( HasFieldName(aFieldName) )
761 {
762 aFieldName = aBaseName + OUString::number(i);
763 i++;
764 }
765
766 return aFieldName;
767}
768
769void OTableEditorCtrl::InsertRows( sal_Int32 nRow )
770{
771
772 std::vector< std::shared_ptr<OTableRow> > vInsertedUndoRedoRows; // need for undo/redo handling
773 // get rows from clipboard
775 if(aTransferData.HasFormat(SotClipboardFormatId::SBA_TABED))
776 {
778 bool bOk = aTransferData.GetSotStorageStream(SotClipboardFormatId::SBA_TABED,aStreamRef);
779 if (bOk && aStreamRef.is())
780 {
781 aStreamRef->Seek(STREAM_SEEK_TO_BEGIN);
782 aStreamRef->ResetError();
783 sal_Int32 nInsertRow = nRow;
784 std::shared_ptr<OTableRow> pRow;
785 sal_Int32 nSize = 0;
786 (*aStreamRef).ReadInt32( nSize );
787 vInsertedUndoRedoRows.reserve(nSize);
788 for(sal_Int32 i=0;i < nSize;++i)
789 {
790 pRow = std::make_shared<OTableRow>();
791 ReadOTableRow( *aStreamRef, *pRow );
792 pRow->SetReadOnly( false );
793 sal_Int32 nType = pRow->GetActFieldDescr()->GetType();
794 if ( pRow->GetActFieldDescr() )
795 pRow->GetActFieldDescr()->SetType(GetView()->getController().getTypeInfoByType(nType));
796 // Adjust the field names
797 pRow->GetActFieldDescr()->SetName( GenerateName( pRow->GetActFieldDescr()->GetName() ) );
798 pRow->SetPos(nInsertRow);
799 m_pRowList->insert( m_pRowList->begin()+nInsertRow,pRow );
800 vInsertedUndoRedoRows.push_back(std::make_shared<OTableRow>(*pRow));
801 nInsertRow++;
802 }
803 }
804 }
805 // RowInserted calls CursorMoved.
806 // The UI data should not be stored here.
807 RowInserted( nRow,vInsertedUndoRedoRows.size() );
808
809 // Create the Undo-Action
810 GetUndoManager().AddUndoAction( std::make_unique<OTableEditorInsUndoAct>(this, nRow, std::move(vInsertedUndoRedoRows)) );
811 GetView()->getController().setModified( true );
813}
814
816{
817 OSL_ENSURE(GetView()->getController().isDropAllowed(),"Call of DeleteRows not valid here. Please check isDropAllowed!");
818 // Create the Undo-Action
819 GetUndoManager().AddUndoAction( std::make_unique<OTableEditorDelUndoAct>(this) );
820
821 // Delete all marked rows
824
825 while( nIndex != SFX_ENDOFSELECTION )
826 {
827 // Remove rows
828 m_pRowList->erase( m_pRowList->begin()+nIndex );
830
831 // Insert the empty row at the end
832 m_pRowList->push_back( std::make_shared<OTableRow>());
834
836 }
837
838 // Force the current record to be displayed
843 ActivateCell();
844 pDescrWin->DisplayData( pActRow->GetActFieldDescr() );
845 GetView()->getController().setModified( true );
847}
848
850{
851 OSL_ENSURE(GetView()->getController().isAddAllowed(),"Call of InsertNewRows not valid here. Please check isAppendAllowed!");
852 // Create Undo-Action
853 sal_Int32 nInsertRows = GetSelectRowCount();
854 if( !nInsertRows )
855 nInsertRows = 1;
856 GetUndoManager().AddUndoAction( std::make_unique<OTableEditorInsNewUndoAct>(this, nRow, nInsertRows) );
857 // Insert the number of selected rows
858 for( tools::Long i=nRow; i<(nRow+nInsertRows); i++ )
859 m_pRowList->insert( m_pRowList->begin()+i ,std::make_shared<OTableRow>());
860 RowInserted( nRow, nInsertRows );
861
862 GetView()->getController().setModified( true );
864}
865
866void OTableEditorCtrl::SetControlText( sal_Int32 nRow, sal_uInt16 nColId, const OUString& rText )
867{
868 // Set the Browser Controls
869 if( nColId < FIELD_FIRST_VIRTUAL_COLUMN )
870 {
871 GoToRow( nRow );
872 GoToColumnId( nColId );
874 if(xController.is())
875 xController->GetWindow().SetText( rText );
876 else
877 RowModified(nRow,nColId);
878 }
879
880 // Set the Tabpage controls
881 else
882 {
883 pDescrWin->SetControlText( nColId, rText );
884 }
885}
886
887void OTableEditorCtrl::SetCellData( sal_Int32 nRow, sal_uInt16 nColId, const TOTypeInfoSP& _pTypeInfo )
888{
889 // Relocate the current pointer
890 if( nRow == -1 )
891 nRow = GetCurRow();
892 OFieldDescription* pFieldDescr = GetFieldDescr( nRow );
893 if( !pFieldDescr && nColId != FIELD_TYPE)
894 return;
895
896 // Set individual fields
897 switch( nColId )
898 {
899 case FIELD_TYPE:
900 SwitchType( _pTypeInfo );
901 break;
902 default:
903 OSL_FAIL("OTableEditorCtrl::SetCellData: invalid column!");
904 }
905 SetControlText(nRow,nColId,_pTypeInfo ? _pTypeInfo->aUIName : OUString());
906}
907
908void OTableEditorCtrl::SetCellData( sal_Int32 nRow, sal_uInt16 nColId, const css::uno::Any& _rNewData )
909{
910 // Relocate the current pointer
911 if( nRow == -1 )
912 nRow = GetCurRow();
913 OFieldDescription* pFieldDescr = GetFieldDescr( nRow );
914 if( !pFieldDescr && nColId != FIELD_TYPE)
915 return;
916
917 OUString sValue;
918 // Set individual fields
919 switch( nColId )
920 {
921 case FIELD_NAME:
922 sValue = ::comphelper::getString(_rNewData);
923 pFieldDescr->SetName( sValue );
924 break;
925
926 case FIELD_TYPE:
927 OSL_FAIL("OTableEditorCtrl::SetCellData: invalid column!");
928 break;
929
931 sValue = ::comphelper::getString(_rNewData);
932 pFieldDescr->SetDescription( sValue );
933 break;
934
936 pFieldDescr->SetControlDefault( _rNewData );
937 sValue = GetView()->GetDescWin()->getGenPage()->getControlDefault(pFieldDescr);
938 break;
939
941 {
942 sValue = ::comphelper::getString(_rNewData);
943 pFieldDescr->SetIsNullable( sValue.toInt32() );
944 }
945 break;
946
949 {
950 sValue = ::comphelper::getString(_rNewData);
951 pFieldDescr->SetPrecision( sValue.toInt32() );
952 }
953 break;
954
956 OSL_FAIL("OTableEditorCtrl::SetCellData: invalid column!");
957 break;
958
960 {
961 sValue = ::comphelper::getString(_rNewData);
962 pFieldDescr->SetAutoIncrement(sValue == DBA_RES(STR_VALUE_YES));
963 }
964 break;
966 {
967 sValue = ::comphelper::getString(_rNewData);
968 pFieldDescr->SetScale(sValue.toInt32());
969 }
970 break;
971
973 sValue = GetView()->GetDescWin()->BoolStringPersistent(::comphelper::getString(_rNewData));
974 pFieldDescr->SetControlDefault(Any(sValue));
975 break;
976
978 {
979 sValue = ::comphelper::getString(_rNewData);
980 pFieldDescr->SetFormatKey(sValue.toInt32());
981 }
982 break;
983 }
984
985 SetControlText(nRow,nColId,sValue);
986}
987
988Any OTableEditorCtrl::GetCellData( sal_Int32 nRow, sal_uInt16 nColId )
989{
990 OFieldDescription* pFieldDescr = GetFieldDescr( nRow );
991 if( !pFieldDescr )
992 return Any();
993
994 // Relocate the current pointer
995 if( nRow==-1 )
996 nRow = GetCurRow();
997 SetDataPtr( nRow );
998
999 static const OUString strYes(DBA_RES(STR_VALUE_YES));
1000 static const OUString strNo(DBA_RES(STR_VALUE_NO));
1001 OUString sValue;
1002 // Read out the fields
1003 switch( nColId )
1004 {
1005 case FIELD_NAME:
1006 sValue = pFieldDescr->GetName();
1007 break;
1008
1009 case FIELD_TYPE:
1010 if ( pFieldDescr->getTypeInfo() )
1011 sValue = pFieldDescr->getTypeInfo()->aUIName;
1012 break;
1013
1014 case COLUMN_DESCRIPTION:
1015 sValue = pFieldDescr->GetDescription();
1016 break;
1017 case HELP_TEXT:
1018 sValue = pFieldDescr->GetHelpText();
1019 break;
1020
1022 return pFieldDescr->GetControlDefault();
1023
1025 sValue = pFieldDescr->GetIsNullable() == ColumnValue::NULLABLE ? strYes : strNo;
1026 break;
1027
1030 sValue = OUString::number(pFieldDescr->GetPrecision());
1031 break;
1032
1034 OSL_FAIL("OTableEditorCtrl::GetCellData: invalid column!");
1035 break;
1036
1038 sValue = pFieldDescr->IsAutoIncrement() ? strYes : strNo;
1039 break;
1040
1042 sValue = OUString::number(pFieldDescr->GetScale());
1043 break;
1044
1046 sValue = GetView()->GetDescWin()->BoolStringUI(::comphelper::getString(pFieldDescr->GetControlDefault()));
1047 break;
1048
1050 sValue = OUString::number(pFieldDescr->GetFormatKey());
1051 break;
1052 }
1053
1054 return Any(sValue);
1055}
1056
1057OUString OTableEditorCtrl::GetCellText( sal_Int32 nRow, sal_uInt16 nColId ) const
1058{
1059 OUString sCellText;
1060 const_cast< OTableEditorCtrl* >( this )->GetCellData( nRow, nColId ) >>= sCellText;
1061 return sCellText;
1062}
1063
1064sal_uInt32 OTableEditorCtrl::GetTotalCellWidth(sal_Int32 nRow, sal_uInt16 nColId)
1065{
1066 return GetTextWidth(GetCellText(nRow, nColId)) + 2 * GetTextWidth("0");
1067}
1068
1070{
1071 std::vector< std::shared_ptr<OTableRow> >::size_type nListCount(
1072 m_pRowList->size());
1073 if( (nRow<0) || (sal::static_int_cast< unsigned long >(nRow)>=nListCount) )
1074 {
1075 OSL_FAIL("(nRow<0) || (nRow>=nListCount)");
1076 return nullptr;
1077 }
1078 std::shared_ptr<OTableRow> pRow = (*m_pRowList)[ nRow ];
1079 if( !pRow )
1080 return nullptr;
1081 return pRow->GetActFieldDescr();
1082}
1083
1085{
1086 bool bIsCutAllowed = (GetView()->getController().isAddAllowed() && GetView()->getController().isDropAllowed()) ||
1088
1089 if (bIsCutAllowed)
1090 {
1091 int nStartPos, nEndPos;
1092 switch(m_eChildFocus)
1093 {
1094 case DESCRIPTION:
1095 {
1096 weld::Entry& rEntry = pDescrCell->get_widget();
1097 bIsCutAllowed = rEntry.get_selection_bounds(nStartPos, nEndPos);
1098 break;
1099 }
1100 case HELPTEXT:
1101 {
1102 weld::Entry& rEntry = pHelpTextCell->get_widget();
1103 bIsCutAllowed = rEntry.get_selection_bounds(nStartPos, nEndPos);
1104 break;
1105 }
1106 case NAME:
1107 {
1108 weld::Entry& rEntry = pNameCell->get_widget();
1109 bIsCutAllowed = rEntry.get_selection_bounds(nStartPos, nEndPos);
1110 break;
1111 }
1112 case ROW:
1113 bIsCutAllowed = IsCopyAllowed();
1114 break;
1115 default:
1116 bIsCutAllowed = false;
1117 break;
1118 }
1119 }
1120
1121 return bIsCutAllowed;
1122}
1123
1125{
1126 bool bIsCopyAllowed = false;
1127 int nStartPos, nEndPos;
1128 if (m_eChildFocus == DESCRIPTION )
1129 {
1130 weld::Entry& rEntry = pDescrCell->get_widget();
1131 bIsCopyAllowed = rEntry.get_selection_bounds(nStartPos, nEndPos);
1132 }
1133 else if(HELPTEXT == m_eChildFocus )
1134 {
1135 weld::Entry& rEntry = pHelpTextCell->get_widget();
1136 bIsCopyAllowed = rEntry.get_selection_bounds(nStartPos, nEndPos);
1137 }
1138 else if(m_eChildFocus == NAME)
1139 {
1140 weld::Entry& rEntry = pNameCell->get_widget();
1141 bIsCopyAllowed = rEntry.get_selection_bounds(nStartPos, nEndPos);
1142 }
1143 else if(m_eChildFocus == ROW)
1144 {
1146 if( !GetSelectRowCount() || (xTable.is() && ::comphelper::getString(xTable->getPropertyValue(PROPERTY_TYPE)) == "VIEW"))
1147 return false;
1148
1149 // If one of the selected rows is empty, Copy is not possible
1150 std::shared_ptr<OTableRow> pRow;
1152 while( nIndex != SFX_ENDOFSELECTION )
1153 {
1154 pRow = (*m_pRowList)[nIndex];
1155 if( !pRow->GetActFieldDescr() )
1156 return false;
1157
1159 }
1160
1161 bIsCopyAllowed = true;
1162 }
1163
1164 return bIsCopyAllowed;
1165}
1166
1168{
1169 bool bAllowed = GetView()->getController().isAddAllowed();
1170 if ( bAllowed )
1171 {
1173 bool bRowFormat = aTransferData.HasFormat(SotClipboardFormatId::SBA_TABED);
1174 if ( m_eChildFocus == ROW )
1175 bAllowed = bRowFormat;
1176 else
1177 bAllowed = !bRowFormat && aTransferData.HasFormat(SotClipboardFormatId::STRING);
1178 }
1179
1180 return bAllowed;
1181}
1182
1184{
1185 if(m_eChildFocus == NAME)
1186 {
1187 if(GetView()->getController().isAlterAllowed())
1188 {
1189 SaveData(-1,FIELD_NAME);
1190 pNameCell->get_widget().cut_clipboard();
1192 }
1193 }
1194 else if(m_eChildFocus == DESCRIPTION)
1195 {
1196 if(GetView()->getController().isAlterAllowed())
1197 {
1199 pDescrCell->get_widget().cut_clipboard();
1201 }
1202 }
1203 else if(HELPTEXT == m_eChildFocus )
1204 {
1205 if(GetView()->getController().isAlterAllowed())
1206 {
1207 SaveData(-1,HELP_TEXT);
1208 pHelpTextCell->get_widget().cut_clipboard();
1210 }
1211 }
1212 else if(m_eChildFocus == ROW)
1213 {
1214 if (nCutEvent)
1216 nCutEvent = Application::PostUserEvent(LINK(this, OTableEditorCtrl, DelayedCut), nullptr, true);
1217 }
1218}
1219
1221{
1222 if (GetSelectRowCount())
1224 else if(m_eChildFocus == NAME)
1225 {
1226 weld::Entry& rEntry = pNameCell->get_widget();
1227 rEntry.copy_clipboard();
1228 }
1229 else if(HELPTEXT == m_eChildFocus )
1230 {
1231 weld::Entry& rEntry = pHelpTextCell->get_widget();
1232 rEntry.copy_clipboard();
1233 }
1234 else if(m_eChildFocus == DESCRIPTION )
1235 {
1236 weld::Entry& rEntry = pDescrCell->get_widget();
1237 rEntry.copy_clipboard();
1238 }
1239}
1240
1242{
1244 if(aTransferData.HasFormat(SotClipboardFormatId::SBA_TABED))
1245 {
1246 if( nPasteEvent )
1248 nPasteEvent = Application::PostUserEvent( LINK(this, OTableEditorCtrl, DelayedPaste), nullptr, true );
1249 }
1250 else if(m_eChildFocus == NAME)
1251 {
1252 if(GetView()->getController().isAlterAllowed())
1253 {
1254 pNameCell->get_widget().paste_clipboard();
1255 CellModified();
1256 }
1257 }
1258 else if(HELPTEXT == m_eChildFocus )
1259 {
1260 if(GetView()->getController().isAlterAllowed())
1261 {
1262 pHelpTextCell->get_widget().paste_clipboard();
1263 CellModified();
1264 }
1265 }
1266 else if(m_eChildFocus == DESCRIPTION)
1267 {
1268 if(GetView()->getController().isAlterAllowed())
1269 {
1270 pDescrCell->get_widget().paste_clipboard();
1271 CellModified();
1272 }
1273 }
1274}
1275
1277{
1278
1279 return GetSelectRowCount() != 0 && GetView()->getController().isDropAllowed();
1280}
1281
1283{
1284
1285 bool bInsertNewAllowed = GetView()->getController().isAddAllowed();
1286 // If fields can be added, Paste in the new fields
1287 if (bInsertNewAllowed && !GetView()->getController().isDropAllowed())
1288 {
1289 SetDataPtr(nRow);
1290 if( GetActRow()->IsReadOnly() )
1291 return false;
1292 }
1293
1294 return bInsertNewAllowed;
1295}
1296
1298{
1299 if( !GetSelectRowCount() )
1300 return false;
1301
1302 OTableController& rController = GetView()->getController();
1303 if ( !rController.getSdbMetaData().supportsPrimaryKeys() )
1304 return false;
1305
1306 Reference<XPropertySet> xTable = rController.getTable();
1307 // Key must not be changed
1308 // This applies only if the table is not new and not a css::sdbcx::View. Otherwise no DROP is executed
1309
1310 if(xTable.is() && ::comphelper::getString(xTable->getPropertyValue(PROPERTY_TYPE)) == "VIEW")
1311 return false;
1312 // If there is an empty field, no primary key
1313 // The entry is only permitted if
1314 // - there are no empty entries in the selection
1315 // - No Memo or Image entries
1316 // - DROP is not permitted (see above) and the column is not Required (not null flag is not set).
1318 std::shared_ptr<OTableRow> pRow;
1319 while( nIndex != SFX_ENDOFSELECTION )
1320 {
1321 pRow = (*m_pRowList)[nIndex];
1322 OFieldDescription* pFieldDescr = pRow->GetActFieldDescr();
1323 if(!pFieldDescr)
1324 return false;
1325 else
1326 {
1327 // Memo and Image fields cannot be primary keys
1328 // or if the column cannot be dropped and the Required flag is not set
1329 // or if a css::sdbcx::View is available and the Required flag is not set
1330 const TOTypeInfoSP& pTypeInfo = pFieldDescr->getTypeInfo();
1331 if( pTypeInfo->nSearchType == ColumnSearch::NONE
1332 || (pFieldDescr->IsNullable() && pRow->IsReadOnly())
1333 )
1334 return false;
1335 }
1336
1338 }
1339
1340 return true;
1341}
1342
1344{
1345 switch (rEvt.GetCommand())
1346 {
1347 case CommandEventId::ContextMenu:
1348 {
1349 Point aMenuPos( rEvt.GetMousePosPixel() );
1350 if (!rEvt.IsMouseEvent())
1351 {
1352 if ( 1 == GetSelectColumnCount() )
1353 {
1354 sal_uInt16 nSelId = GetColumnId(
1355 sal::static_int_cast< sal_uInt16 >(
1356 FirstSelectedColumn() ) );
1357 ::tools::Rectangle aColRect( GetFieldRectPixel( 0, nSelId, false ) );
1358
1359 aMenuPos = aColRect.TopCenter();
1360 }
1361 else if ( GetSelectRowCount() > 0 )
1362 {
1364
1365 aMenuPos = aColRect.TopCenter();
1366 }
1367 else
1368 {
1370 return;
1371 }
1372 }
1373
1374 // Show the Context menu
1375 if( !IsReadOnly() )
1376 {
1377 sal_uInt16 nColId = GetColumnId(GetColumnAtXPosPixel(aMenuPos.X()));
1378 sal_Int32 nRow = GetRowAtYPosPixel(aMenuPos.Y());
1379
1380 if ( HANDLE_ID != nColId )
1381 {
1382 if ( nRow < 0 && nColId != BROWSER_INVALIDID )
1383 { // hit the header
1384 if ( 3 != nColId )
1385 { // 3 would mean the last column, and this last column is auto-sized
1386 if ( !IsColumnSelected( nColId ) )
1387 SelectColumnId( nColId );
1388
1389 ::tools::Rectangle aRect(aMenuPos, Size(1, 1));
1390 weld::Window* pPopupParent = weld::GetPopupParent(*this, aRect);
1391 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pPopupParent, "dbaccess/ui/querycolmenu.ui"));
1392 std::unique_ptr<weld::Menu> xContextMenu(xBuilder->weld_menu("menu"));
1393 xContextMenu->remove("delete");
1394 xContextMenu->remove("separator");
1395 if (xContextMenu->popup_at_rect(pPopupParent, aRect) == "width")
1396 adjustBrowseBoxColumnWidth( this, nColId );
1397 }
1398 }
1399 }
1400 else
1401 {
1402 ::tools::Rectangle aRect(aMenuPos, Size(1, 1));
1403 weld::Window* pPopupParent = weld::GetPopupParent(*this, aRect);
1404 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pPopupParent, "dbaccess/ui/tabledesignrowmenu.ui"));
1405 std::unique_ptr<weld::Menu> xContextMenu(xBuilder->weld_menu("menu"));
1406
1407 if (!IsCutAllowed())
1408 xContextMenu->remove("cut");
1409 if (!IsCopyAllowed())
1410 xContextMenu->remove("copy");
1411 if (!IsPasteAllowed())
1412 xContextMenu->remove("paste");
1413 if (!IsDeleteAllowed())
1414 xContextMenu->remove("delete");
1415 if (!IsPrimaryKeyAllowed())
1416 xContextMenu->remove("primarykey");
1417 if (!IsInsertNewAllowed(nRow))
1418 xContextMenu->remove("insert");
1419 xContextMenu->set_active("primarykey", IsRowSelected(GetCurRow()) && IsPrimaryKey());
1420
1421 if( SetDataPtr(m_nDataPos) )
1422 pDescrWin->SaveData( pActRow->GetActFieldDescr() );
1423
1424 // All actions which change the number of rows must be run asynchronously
1425 // otherwise there may be problems between the Context menu and the Browser
1427 OUString sIdent = xContextMenu->popup_at_rect(pPopupParent, aRect);
1428 if (sIdent == "cut")
1429 cut();
1430 else if (sIdent == "copy")
1431 copy();
1432 else if (sIdent == "paste")
1433 paste();
1434 else if (sIdent == "delete")
1435 {
1436 if( nDeleteEvent )
1438 nDeleteEvent = Application::PostUserEvent( LINK(this, OTableEditorCtrl, DelayedDelete), nullptr, true );
1439 }
1440 else if (sIdent == "insert")
1441 {
1442 if( nInsNewRowsEvent )
1444 nInsNewRowsEvent = Application::PostUserEvent( LINK(this, OTableEditorCtrl, DelayedInsNewRows), nullptr, true );
1445 }
1446 else if (sIdent == "primarykey")
1447 {
1449 }
1450 }
1451 }
1452 }
1453 break;
1454 default:
1456 }
1457
1458}
1459
1460IMPL_LINK_NOARG( OTableEditorCtrl, DelayedCut, void*, void )
1461{
1462 nCutEvent = nullptr;
1464}
1465
1466IMPL_LINK_NOARG( OTableEditorCtrl, DelayedPaste, void*, void )
1467{
1468 nPasteEvent = nullptr;
1469
1470 sal_Int32 nPastePosition = GetView()->getController().getFirstEmptyRowPosition();
1471 if ( !GetView()->getController().getTable().is() )
1472 nPastePosition = GetSelectRowCount() ? FirstSelectedRow() : GetCurRow();
1473
1474 if (!IsInsertNewAllowed(nPastePosition))
1475 { // Insertion is not allowed, only appending, so test if there are full cells after the PastePosition
1476
1477 auto aIter = std::find_if(m_pRowList->rbegin(), m_pRowList->rend(), [](const std::shared_ptr<OTableRow>& rxRow) {
1478 return rxRow && rxRow->GetActFieldDescr() && !rxRow->GetActFieldDescr()->GetName().isEmpty(); });
1479 auto nFreeFromPos = static_cast<sal_Int32>(std::distance(aIter, m_pRowList->rend())); // from here on there are only empty rows
1480 if (nPastePosition < nFreeFromPos) // if at least one PastePosition is full, go right to the end
1481 nPastePosition = nFreeFromPos;
1482 }
1483
1484 OTableRowView::Paste( nPastePosition );
1485 SetNoSelection();
1486 GoToRow( nPastePosition );
1487}
1488
1489IMPL_LINK_NOARG( OTableEditorCtrl, DelayedDelete, void*, void )
1490{
1491 nDeleteEvent = nullptr;
1492 DeleteRows();
1493}
1494
1495IMPL_LINK_NOARG( OTableEditorCtrl, DelayedInsNewRows, void*, void )
1496{
1497 nInsNewRowsEvent = nullptr;
1498 sal_Int32 nPastePosition = GetView()->getController().getFirstEmptyRowPosition();
1499 if ( !GetView()->getController().getTable().is() )
1500 nPastePosition = GetSelectRowCount() ? FirstSelectedRow() : m_nDataPos;
1501
1502 InsertNewRows( nPastePosition );
1503 SetNoSelection();
1504 GoToRow( nPastePosition );
1505}
1506
1508 MultiSelection& _rMultiSel,
1509 sal_Int32 _nPos,
1510 bool _bSet,
1511 bool _bPrimaryKey)
1512{
1513 _pFieldDesc->SetPrimaryKey( _bPrimaryKey );
1514 if(!_bSet && _pFieldDesc->getTypeInfo()->bNullable)
1515 {
1516 _pFieldDesc->SetIsNullable(ColumnValue::NO_NULLS);
1517 _pFieldDesc->SetControlDefault(Any());
1518 }
1519 if ( _pFieldDesc->IsAutoIncrement() && !_bPrimaryKey )
1520 {
1521 OTableController& rController = GetView()->getController();
1522 if ( rController.isAutoIncrementPrimaryKey() )
1523 {
1524 _pFieldDesc->SetAutoIncrement(false);
1525 }
1526 }
1527 // update field description
1528 pDescrWin->DisplayData(_pFieldDesc);
1529
1530 _rMultiSel.Insert( _nPos );
1531 _rMultiSel.Select( _nPos );
1532}
1533
1535{
1536 // Delete any existing Primary Keys
1537 MultiSelection aDeletedPrimKeys;
1538 aDeletedPrimKeys.SetTotalRange( Range(0,GetRowCount()) );
1539
1540 sal_Int32 nRow = 0;
1541 for (auto const& row : *m_pRowList)
1542 {
1543 OFieldDescription* pFieldDescr = row->GetActFieldDescr();
1544 if( pFieldDescr && row->IsPrimaryKey() && (!bSet || !IsRowSelected(nRow)) )
1545 {
1546 AdjustFieldDescription(pFieldDescr,aDeletedPrimKeys,nRow,bSet,false);
1547 }
1548 ++nRow;
1549 }
1550
1551 // Set the primary keys of the marked rows
1552 MultiSelection aInsertedPrimKeys;
1553 aInsertedPrimKeys.SetTotalRange( Range(0,GetRowCount()) );
1554 if( bSet )
1555 {
1557 while( nIndex != SFX_ENDOFSELECTION )
1558 {
1559 // Set the key
1560 std::shared_ptr<OTableRow> pRow = (*m_pRowList)[nIndex];
1561 OFieldDescription* pFieldDescr = pRow->GetActFieldDescr();
1562 if(pFieldDescr)
1563 AdjustFieldDescription(pFieldDescr,aInsertedPrimKeys,nIndex,false,true);
1564
1566 }
1567 }
1568
1569 GetUndoManager().AddUndoAction( std::make_unique<OPrimKeyUndoAct>(this, aDeletedPrimKeys, aInsertedPrimKeys) );
1570
1571 // Invalidate the handle-columns
1573
1574 // Set the TableDocSh's ModifyFlag
1575 GetView()->getController().setModified( true );
1577}
1578
1580{
1581 // Are all marked fields part of the Primary Key ?
1582 tools::Long nPrimaryKeys = 0;
1583 sal_Int32 nRow=0;
1584 for (auto const& row : *m_pRowList)
1585 {
1586 if( IsRowSelected(nRow) && !row->IsPrimaryKey() )
1587 return false;
1588 if( row->IsPrimaryKey() )
1589 ++nPrimaryKeys;
1590 ++nRow;
1591 }
1592
1593 // Are there any unselected fields that are part of the Key ?
1594 return GetSelectRowCount() == nPrimaryKeys;
1595}
1596
1598{
1599 // if there is no assigned field name
1600 sal_Int32 nRow(GetCurRow());
1601 OFieldDescription* pActFieldDescr = GetFieldDescr( nRow );
1602 if( pActFieldDescr )
1603 // Store the old description
1604 pDescrWin->SaveData( pActFieldDescr );
1605
1606 if ( nRow < 0 || o3tl::make_unsigned(nRow) > m_pRowList->size() )
1607 return;
1608 // Show the new description
1609 std::shared_ptr<OTableRow> pRow = (*m_pRowList)[nRow];
1610 pRow->SetFieldType( _pType, true );
1611 if ( _pType )
1612 {
1613 weld::ComboBox& rTypeList = pTypeCell->get_widget();
1614 const sal_Int32 nCurrentlySelected = rTypeList.get_active();
1615
1616 if ( ( nCurrentlySelected == -1 )
1617 || ( GetView()->getController().getTypeInfo( nCurrentlySelected ) != _pType )
1618 )
1619 {
1620 sal_Int32 nEntryPos = 0;
1621 const OTypeInfoMap& rTypeInfo = GetView()->getController().getTypeInfo();
1622 for (auto const& elem : rTypeInfo)
1623 {
1624 if(elem.second == _pType)
1625 break;
1626 ++nEntryPos;
1627 }
1628 if (nEntryPos < rTypeList.get_count())
1629 rTypeList.set_active(nEntryPos);
1630 }
1631 }
1632
1633 pActFieldDescr = pRow->GetActFieldDescr();
1634 if (pActFieldDescr != nullptr && !pActFieldDescr->GetFormatKey())
1635 {
1636 sal_Int32 nFormatKey = ::dbtools::getDefaultNumberFormat( pActFieldDescr->GetType(),
1637 pActFieldDescr->GetScale(),
1638 pActFieldDescr->IsCurrency(),
1639 Reference< XNumberFormatTypes>(GetView()->getController().getNumberFormatter()->getNumberFormatsSupplier()->getNumberFormats(),UNO_QUERY),
1640 GetView()->getLocale());
1641
1642 pActFieldDescr->SetFormatKey(nFormatKey);
1643 }
1644
1645 pDescrWin->DisplayData( pActFieldDescr );
1646}
1647
1649{
1650 return m_pView;
1651}
1652
1654{
1656 // now we have to deactivate the field description
1657 sal_Int32 nRow(GetCurRow());
1658 if (pDescrWin)
1660}
1661
1663{
1664 if (rNEvt.GetType() == NotifyEventType::GETFOCUS)
1665 {
1666 if( pHelpTextCell && pHelpTextCell->HasChildPathFocus() )
1668 else if( pDescrCell && pDescrCell->HasChildPathFocus() )
1670 else if(pNameCell && pNameCell->HasChildPathFocus() )
1672 else
1674 }
1675
1676 return OTableRowView::PreNotify(rNEvt);
1677}
1678
1679/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define FIELD_PROPERTY_LENGTH
#define FIELD_PROPERTY_SCALE
#define FIELD_PROPERTY_NUMTYPE
#define FIELD_FIRST_VIRTUAL_COLUMN
#define FIELD_NAME
#define FIELD_PROPERTY_TEXTLEN
#define COLUMN_DESCRIPTION
#define FIELD_PROPERTY_REQUIRED
#define FIELD_PROPERTY_FORMAT
#define FIELD_PROPERTY_BOOL_DEFAULT
#define FIELD_TYPE
#define FIELD_PROPERTY_DEFAULT
#define FIELD_PROPERTY_AUTOINC
#define HELP_TEXT
#define FIELDDESCR_WIDTH
#define MAX_DESCR_LEN
#define HANDLE_ID
#define FIELDNAME_WIDTH
#define FIELDTYPE_WIDTH
#define BROWSER_INVALIDID
BrowserMode
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
void RowRemoved(sal_Int32 nRow, sal_Int32 nNumRows=1, bool bDoPaint=true)
sal_uInt16 GetColumnId(sal_uInt16 nPos) const
bool GoToColumnId(sal_uInt16 nColId)
BrowserDataWin & GetDataWindow() const
void InsertDataColumn(sal_uInt16 nItemId, const OUString &rText, tools::Long nSize, HeaderBarItemBits nBits=HeaderBarItemBits::STDSTYLE, sal_uInt16 nPos=HEADERBAR_APPEND)
sal_Int32 FirstSelectedColumn() const
bool GoToRow(sal_Int32 nRow)
sal_Int32 GetCurRow() const
sal_uInt16 GetSelectColumnCount() const
sal_Int32 GetRowAtYPosPixel(tools::Long nY, bool bRelToBrowser=true) const
void RowModified(sal_Int32 nRow, sal_uInt16 nColId=BROWSER_INVALIDID)
void SetMode(BrowserMode nMode)
void SelectColumnId(sal_uInt16 nColId)
sal_Int32 GetSelectRowCount() const
sal_uInt16 GetCurColumnId() const
tools::Rectangle GetFieldRectPixel(sal_Int32 nRow, sal_uInt16 nColId, bool bRelToBrowser=true) const
void SetDataRowHeight(tools::Long nPixel)
void RowInserted(sal_Int32 nRow, sal_Int32 nNumRows=1, bool bDoPaint=true, bool bKeepSelection=false)
sal_uInt16 GetColumnAtXPosPixel(tools::Long nX) const
sal_Int32 FirstSelectedRow()
virtual sal_Int32 GetRowCount() const override
bool IsColumnSelected(sal_uInt16 nColumnId) const
sal_Int32 NextSelectedRow()
virtual bool IsRowSelected(sal_Int32 nRow) const override
CommandEventId GetCommand() const
const Point & GetMousePosPixel() const
bool IsMouseEvent() const
void Insert(sal_Int32 nIndex, sal_Int32 nCount=1)
bool Select(sal_Int32 nIndex, bool bSelect=true)
void SetTotalRange(const Range &rTotRange)
NotifyEventType GetType() const
void SetClipRegion()
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
constexpr tools::Long Y() const
constexpr tools::Long X() const
size_t LeaveListAction()
virtual void Clear()
virtual void EnterListAction(const OUString &rComment, const OUString &rRepeatComment, sal_uInt16 nId, ViewShellId nViewShellId)
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
constexpr tools::Long Height() const
void setHeight(tools::Long nHeight)
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
virtual void Start(bool bStartTimer=true) override
bool GetSotStorageStream(SotClipboardFormatId nFormat, tools::SvRef< SotTempStream > &rStreamRef) const
static TransferableDataHelper CreateFromSystemClipboard(vcl::Window *pWindow)
bool HasFormat(SotClipboardFormatId nFormat) const
static VclPtr< reference_type > Create(Arg &&... arg)
bool supportsColumnDescription(std::u16string_view _sURL) const
check if the given data source allows to show column description.
Definition: dsntypes.cxx:261
OUString getControlDefault(const OFieldDescription *pFieldDescr, bool _bCheck=true) const
void SetHelpText(const OUString &_sHelptext)
void SetControlDefault(const css::uno::Any &_rControlDefault)
void SetIsNullable(sal_Int32 _rIsNullable)
const TOTypeInfoSP & getTypeInfo() const
void SetPrimaryKey(bool _bPKey)
void SetAutoIncrement(bool _bAuto)
void SetName(const OUString &_rName)
sal_Int32 GetFormatKey() const
void SetDescription(const OUString &_rDescription)
css::uno::Any GetControlDefault() const
sal_Int32 GetPrecision() const
sal_Int32 GetIsNullable() const
void SetFormatKey(sal_Int32 _rFormatKey)
SfxUndoManager & GetUndoManager() const
need for undo's and redo's
bool isAutoIncrementPrimaryKey() const
const OTypeInfoMap & getTypeInfo() const
std::vector< std::shared_ptr< OTableRow > > & getRows()
const css::uno::Reference< css::beans::XPropertySet > & getTable() const
OTableFieldDescWin * GetDescWin() const
OTableController & getController() const
virtual void paste() override
VclPtr<::svt::EditControl > pDescrCell
virtual OUString GetCellText(sal_Int32 nRow, sal_uInt16 nColId) const override
void InvalidateFeatures()
InvalidateFeatures invalidates the slots SID_UNDO | SID_REDO | SID_SAVEDOC.
OFieldDescription * GetFieldDescr(sal_Int32 nRow)
virtual void copy() override
virtual void SetControlText(sal_Int32 nRow, sal_uInt16 nColId, const OUString &rText) override
virtual ~OTableEditorCtrl() override
ClipboardInvalidator m_aInvalidate
virtual void PaintCell(OutputDevice &rDev, const tools::Rectangle &rRect, sal_uInt16 nColumnId) const override
OTableFieldDescWin * pDescrWin
virtual void CellModified() override
virtual bool IsDeleteAllowed() override
ImplSVEvent * nInsNewRowsEvent
VclPtr<::svt::ListBoxControl > pTypeCell
VclPtr< OSQLNameEditControl > pNameCell
virtual void CopyRows() override
virtual bool SeekRow(sal_Int32 nRow) override
SfxUndoManager & GetUndoManager() const
void SaveData(sal_Int32 nRow, sal_uInt16 nColumnId)
VclPtr<::svt::EditControl > pHelpTextCell
virtual ::svt::CellController * GetController(sal_Int32 nRow, sal_uInt16 nCol) override
virtual void InitController(::svt::CellControllerRef &rController, sal_Int32 nRow, sal_uInt16 nCol) override
const std::shared_ptr< OTableRow > & GetActRow() const
void AdjustFieldDescription(OFieldDescription *_pFieldDesc, MultiSelection &_rMultiSel, sal_Int32 _nPos, bool _bSet, bool _bPrimaryKey)
AdjustFieldDescription set the needed values for the description.
virtual void DeactivateCell(bool bUpdate=true) override
virtual bool SaveModified() override
virtual bool IsPrimaryKeyAllowed() override
virtual sal_uInt32 GetTotalCellWidth(sal_Int32 nRow, sal_uInt16 nColId) override
virtual RowStatus GetRowStatus(sal_Int32 nRow) const override
virtual bool CursorMoving(sal_Int32 nNewRow, sal_uInt16 nNewCol) override
void SwitchType(const TOTypeInfoSP &_pType)
void SetReadOnly(bool bRead)
virtual void dispose() override
virtual void CursorMoved() override
void SetPrimaryKey(bool bSet)
virtual void Command(const CommandEvent &rEvt) override
virtual void DeleteRows() override
virtual void SetCellData(sal_Int32 nRow, sal_uInt16 nColId, const TOTypeInfoSP &_pTypeInfo) override
virtual void InsertRows(sal_Int32 nRow) override
ImplSVEvent * nPasteEvent
ChildFocusState m_eChildFocus
ImplSVEvent * nInvalidateTypeEvent
OTableEditorCtrl(vcl::Window *pParentWin, OTableDesignView *pView)
void DisplayData(sal_Int32 nRow)
force displaying of the given row
VclPtr< OTableDesignView > m_pView
virtual css::uno::Any GetCellData(sal_Int32 nRow, sal_uInt16 nColId) override
sal_Int32 HasFieldName(std::u16string_view rFieldName)
virtual bool IsInsertNewAllowed(sal_Int32 nRow) override
bool SetDataPtr(sal_Int32 nRow)
virtual void Init() override
virtual void cut() override
OUString GenerateName(const OUString &rName)
std::shared_ptr< OTableRow > pActRow
virtual bool PreNotify(NotifyEvent &rNEvt) override
virtual void InsertNewRows(sal_Int32 nRow) override
virtual OTableDesignView * GetView() const override
std::vector< std::shared_ptr< OTableRow > > * m_pRowList
ImplSVEvent * nDeleteEvent
OUString BoolStringUI(const OUString &rPersistentString) const
void SaveData(OFieldDescription *pFieldDescr)
OUString BoolStringPersistent(std::u16string_view rUIString) const
void SetControlText(sal_uInt16 nControlId, const OUString &rText)
OTableFieldControl * getGenPage() const
void DisplayData(OFieldDescription *pFieldDescr)
void SetReadOnly(bool bReadOnly)
tools::Long m_nCurrentPos
current position of selected column
void Paste(sal_Int32 nRow)
virtual void cut() override
tools::Long m_nDataPos
currently needed row
virtual void copy() override
virtual void Command(const CommandEvent &rEvt) override
virtual void Init() override
virtual void CursorMoved() override
bool IsEditing() const
virtual void DeactivateCell(bool bUpdate=true)
const CellControllerRef & Controller() const
virtual bool CursorMoving(sal_Int32 nNewRow, sal_uInt16 nNewCol)
virtual bool PreNotify(NotifyEvent &rNEvt) override
void InvalidateStatusCell(sal_Int32 nRow)
virtual bool SeekRow(sal_Int32 nRow) override
void InvalidateHandleColumn()
virtual void dispose() override
constexpr Point TopCenter() const
bool is() const
virtual void clear()=0
virtual void set_active(int pos)=0
void append_text(const OUString &rStr)
virtual int get_active() const=0
virtual int get_count() const=0
void set_active_text(const OUString &rStr)
virtual void set_text(const OUString &rText)=0
void save_value()
virtual bool get_selection_bounds(int &rStartPos, int &rEndPos)=0
virtual void copy_clipboard()=0
virtual OUString get_text() const=0
#define DBA_RES(id)
int nCount
virtual void SetHelpId(const OUString &) override
constexpr OUStringLiteral HID_TABDESIGN_TYPECELL
Definition: helpids.h:48
constexpr OUStringLiteral HID_TABDESIGN_HELPTEXT
Definition: helpids.h:99
constexpr OUStringLiteral HID_TABDESIGN_NAMECELL
Definition: helpids.h:47
constexpr OUStringLiteral HID_TABDESIGN_BACKGROUND
Definition: helpids.h:45
constexpr OUStringLiteral HID_CTL_TABLEEDIT
Definition: helpids.h:46
constexpr OUStringLiteral HID_TABDESIGN_COMMENTCELL
Definition: helpids.h:49
sal_Int32 nIndex
OUString aName
sal_uInt16 nPos
std::unique_ptr< sal_Int32[]> pData
#define SFX_ENDOFSELECTION
const LanguageTag & getLocale()
css::uno::Reference< css::uno::XInterface > getDataSource(const css::uno::Reference< css::uno::XInterface > &_rxDependentObject)
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
void adjustBrowseBoxColumnWidth(::svt::EditBrowseBox *_pBox, sal_uInt16 _nColId)
Definition: UITools.cxx:928
css::uno::Reference< css::util::XNumberFormatter > getNumberFormatter(const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
creates a number formatter
std::multimap< sal_Int32, TOTypeInfoSP > OTypeInfoMap
Definition: TypeInfo.hxx:100
std::shared_ptr< OTypeInfo > TOTypeInfoSP
Definition: TypeInfo.hxx:99
SvStream & ReadOTableRow(SvStream &_rStr, OTableRow &_rRow)
Definition: TableRow.cxx:128
bool isSQL92CheckEnabled(const css::uno::Reference< css::sdbc::XConnection > &_xConnection)
check if SQL92 name checking is enabled
Reference< XNumberFormatsSupplier > getNumberFormats(const Reference< XConnection > &_rxConn, bool _bAlloweDefault, const Reference< XComponentContext > &_rxContext)
int i
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
long Long
weld::Window * GetPopupParent(vcl::Window &rOutWin, tools::Rectangle &rRect)
ContentProvider * m_pOwner
QPRO_FUNC_TYPE nType
#define STREAM_SEEK_TO_BEGIN
constexpr OUStringLiteral PROPERTY_URL(u"URL")
constexpr OUStringLiteral PROPERTY_TYPE(u"Type")
Reference< XController > xController
the controller of the sub component. Must not be <NULL>
sal_Int32 _nPos