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

Generated by: LCOV version 1.10