LCOV - code coverage report
Current view: top level - dbaccess/source/ui/tabledesign - TEditControl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 897 0.0 %
Date: 2014-04-11 Functions: 0 73 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10