LCOV - code coverage report
Current view: top level - svx/source/table - tablecontroller.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 1222 0.0 %
Date: 2012-08-25 Functions: 0 71 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 2354 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "tablecontroller.hxx"
      31                 :            : 
      32                 :            : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      33                 :            : #include <com/sun/star/container/XIndexAccess.hpp>
      34                 :            : 
      35                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      36                 :            : #include <com/sun/star/table/XMergeableCellRange.hpp>
      37                 :            : #include <com/sun/star/table/XMergeableCell.hpp>
      38                 :            : 
      39                 :            : #include <sal/config.h>
      40                 :            : 
      41                 :            : #include <vcl/svapp.hxx>
      42                 :            : #include <svl/whiter.hxx>
      43                 :            : 
      44                 :            : #include <sfx2/request.hxx>
      45                 :            : 
      46                 :            : #include <editeng/scripttypeitem.hxx>
      47                 :            : #include <svx/svdotable.hxx>
      48                 :            : #include <svx/sdr/overlay/overlayobjectcell.hxx>
      49                 :            : #include <svx/sdr/overlay/overlaymanager.hxx>
      50                 :            : #include <svx/svxids.hrc>
      51                 :            : #include <editeng/outlobj.hxx>
      52                 :            : #include <svx/svdoutl.hxx>
      53                 :            : #include <svx/svdpagv.hxx>
      54                 :            : #include <svx/svdetc.hxx>
      55                 :            : #include <editeng/editobj.hxx>
      56                 :            : #include "editeng/editstat.hxx"
      57                 :            : #include "editeng/unolingu.hxx"
      58                 :            : #include "svx/sdrpagewindow.hxx"
      59                 :            : #include <svx/selectioncontroller.hxx>
      60                 :            : #include <svx/svdmodel.hxx>
      61                 :            : #include "svx/sdrpaintwindow.hxx"
      62                 :            : #include <svx/svxdlg.hxx>
      63                 :            : #include <editeng/boxitem.hxx>
      64                 :            : #include "cell.hxx"
      65                 :            : #include <editeng/borderline.hxx>
      66                 :            : #include <editeng/colritem.hxx>
      67                 :            : #include "editeng/bolnitem.hxx"
      68                 :            : #include "svx/svdstr.hrc"
      69                 :            : #include "svx/svdglob.hxx"
      70                 :            : #include "svx/svdpage.hxx"
      71                 :            : #include "tableundo.hxx"
      72                 :            : #include "tablelayouter.hxx"
      73                 :            : 
      74                 :            : using ::editeng::SvxBorderLine;
      75                 :            : using ::rtl::OUString;
      76                 :            : using namespace ::sdr::table;
      77                 :            : using namespace ::com::sun::star;
      78                 :            : using namespace ::com::sun::star::uno;
      79                 :            : using namespace ::com::sun::star::table;
      80                 :            : using namespace ::com::sun::star::beans;
      81                 :            : using namespace ::com::sun::star::container;
      82                 :            : using namespace ::com::sun::star::text;
      83                 :            : using namespace ::com::sun::star::style;
      84                 :            : 
      85                 :            : namespace sdr { namespace table {
      86                 :            : 
      87                 :            : // --------------------------------------------------------------------
      88                 :            : // class SvxTableControllerModifyListener
      89                 :            : // --------------------------------------------------------------------
      90                 :            : 
      91         [ #  # ]:          0 : class SvxTableControllerModifyListener : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XModifyListener >
      92                 :            : {
      93                 :            : public:
      94                 :          0 :     SvxTableControllerModifyListener( SvxTableController* pController )
      95                 :          0 :         : mpController( pController ) {}
      96                 :            : 
      97                 :            :     // XModifyListener
      98                 :            :     virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
      99                 :            : 
     100                 :            :     // XEventListener
     101                 :            :     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
     102                 :            : 
     103                 :            :     SvxTableController* mpController;
     104                 :            : };
     105                 :            : 
     106                 :            : // --------------------------------------------------------------------
     107                 :            : // XModifyListener
     108                 :            : // --------------------------------------------------------------------
     109                 :            : 
     110                 :          0 : void SAL_CALL SvxTableControllerModifyListener::modified( const ::com::sun::star::lang::EventObject&  ) throw (::com::sun::star::uno::RuntimeException)
     111                 :            : {
     112         [ #  # ]:          0 :     if( mpController )
     113                 :          0 :         mpController->onTableModified();
     114                 :          0 : }
     115                 :            : 
     116                 :            : // --------------------------------------------------------------------
     117                 :            : // XEventListener
     118                 :            : // --------------------------------------------------------------------
     119                 :            : 
     120                 :          0 : void SAL_CALL SvxTableControllerModifyListener::disposing( const ::com::sun::star::lang::EventObject&  ) throw (::com::sun::star::uno::RuntimeException)
     121                 :            : {
     122                 :          0 :     mpController = 0;
     123                 :          0 : }
     124                 :            : 
     125                 :            : // --------------------------------------------------------------------
     126                 :            : // class SvxTableController
     127                 :            : // --------------------------------------------------------------------
     128                 :            : 
     129                 :          0 : rtl::Reference< sdr::SelectionController > CreateTableController( SdrObjEditView* pView, const SdrObject* pObj, const rtl::Reference< sdr::SelectionController >& xRefController )
     130                 :            : {
     131                 :          0 :     return SvxTableController::create( pView, pObj, xRefController );
     132                 :            : }
     133                 :            : 
     134                 :            : // --------------------------------------------------------------------
     135                 :            : 
     136                 :          0 : rtl::Reference< sdr::SelectionController > SvxTableController::create( SdrObjEditView* pView, const SdrObject* pObj, const rtl::Reference< sdr::SelectionController >& xRefController )
     137                 :            : {
     138         [ #  # ]:          0 :     if( xRefController.is() )
     139                 :            :     {
     140         [ #  # ]:          0 :         SvxTableController* pController = dynamic_cast< SvxTableController* >( xRefController.get() );
     141 [ #  # ][ #  # ]:          0 :         if( pController && (pController->mxTableObj.get() == pObj) && (pController->mpView == pView)  )
         [ #  # ][ #  # ]
     142                 :          0 :             return xRefController;
     143                 :            :     }
     144         [ #  # ]:          0 :     return new SvxTableController( pView, pObj );
     145                 :            : }
     146                 :            : 
     147                 :            : // --------------------------------------------------------------------
     148                 :            : 
     149                 :          0 : SvxTableController::SvxTableController( SdrObjEditView* pView, const SdrObject* pObj )
     150                 :            : : mbCellSelectionMode(false)
     151                 :            : , mbLeftButtonDown(false)
     152                 :            : , mpSelectionOverlay(0)
     153                 :            : , mpView( dynamic_cast< SdrView* >( pView ) )
     154                 :            : , mxTableObj( dynamic_cast< SdrTableObj* >( const_cast< SdrObject* >( pObj ) ) )
     155                 :            : , mpModel( 0 )
     156 [ #  # ][ #  # ]:          0 : , mnUpdateEvent( 0 )
                 [ #  # ]
     157                 :            : {
     158         [ #  # ]:          0 :     if( pObj )
     159         [ #  # ]:          0 :         mpModel = pObj->GetModel();
     160                 :            : 
     161         [ #  # ]:          0 :     if( mxTableObj.is() )
     162                 :            :     {
     163         [ #  # ]:          0 :         static_cast< const SdrTableObj* >( pObj )->getActiveCellPos( maCursorFirstPos );
     164                 :          0 :         maCursorLastPos = maCursorFirstPos;
     165                 :            : 
     166         [ #  # ]:          0 :         Reference< XTable > xTable( static_cast< const SdrTableObj* >( pObj )->getTable() );
     167         [ #  # ]:          0 :         if( xTable.is() )
     168                 :            :         {
     169 [ #  # ][ #  # ]:          0 :             mxModifyListener = new SvxTableControllerModifyListener( this );
                 [ #  # ]
     170 [ #  # ][ #  # ]:          0 :             xTable->addModifyListener( mxModifyListener );
     171                 :            : 
     172 [ #  # ][ #  # ]:          0 :             mxTable.set( dynamic_cast< TableModel* >( xTable.get() ) );
     173                 :          0 :         }
     174                 :            :     }
     175                 :          0 : }
     176                 :            : 
     177                 :            : // --------------------------------------------------------------------
     178                 :            : 
     179         [ #  # ]:          0 : SvxTableController::~SvxTableController()
     180                 :            : {
     181         [ #  # ]:          0 :     if( mnUpdateEvent )
     182                 :            :     {
     183         [ #  # ]:          0 :         Application::RemoveUserEvent( mnUpdateEvent );
     184                 :            :     }
     185                 :            : 
     186 [ #  # ][ #  # ]:          0 :     if( mxModifyListener.is() && mxTableObj.get() )
                 [ #  # ]
     187                 :            :     {
     188         [ #  # ]:          0 :         Reference< XTable > xTable( static_cast< SdrTableObj* >( mxTableObj.get() )->getTable() );
     189         [ #  # ]:          0 :         if( xTable.is() )
     190                 :            :         {
     191 [ #  # ][ #  # ]:          0 :             xTable->removeModifyListener( mxModifyListener );
     192                 :          0 :             mxModifyListener.clear();
     193                 :          0 :         }
     194                 :            :     }
     195         [ #  # ]:          0 : }
     196                 :            : 
     197                 :            : // --------------------------------------------------------------------
     198                 :            : 
     199                 :            : const sal_uInt16 ACTION_NONE = 0;
     200                 :            : const sal_uInt16 ACTION_GOTO_FIRST_CELL = 1;
     201                 :            : const sal_uInt16 ACTION_GOTO_FIRST_COLUMN = 2;
     202                 :            : const sal_uInt16 ACTION_GOTO_FIRST_ROW = 3;
     203                 :            : const sal_uInt16 ACTION_GOTO_LEFT_CELL = 4;
     204                 :            : const sal_uInt16 ACTION_GOTO_UP_CELL = 5;
     205                 :            : const sal_uInt16 ACTION_GOTO_RIGHT_CELL = 6;
     206                 :            : const sal_uInt16 ACTION_GOTO_DOWN_CELL = 7;
     207                 :            : const sal_uInt16 ACTION_GOTO_LAST_CELL = 8;
     208                 :            : const sal_uInt16 ACTION_GOTO_LAST_COLUMN = 9;
     209                 :            : const sal_uInt16 ACTION_GOTO_LAST_ROW = 10;
     210                 :            : const sal_uInt16 ACTION_EDIT_CELL = 11;
     211                 :            : const sal_uInt16 ACTION_STOP_TEXT_EDIT = 12;
     212                 :            : const sal_uInt16 ACTION_REMOVE_SELECTION = 13;
     213                 :            : const sal_uInt16 ACTION_START_SELECTION = 14;
     214                 :            : const sal_uInt16 ACTION_HANDLED_BY_VIEW = 15;
     215                 :            : const sal_uInt16 ACTION_TAB = 18;
     216                 :            : 
     217                 :          0 : bool SvxTableController::onKeyInput(const KeyEvent& rKEvt, Window* pWindow )
     218                 :            : {
     219         [ #  # ]:          0 :     if( !checkTableObject() )
     220                 :          0 :         return false;
     221                 :            : 
     222                 :            :     // check if we are read only
     223 [ #  # ][ #  # ]:          0 :     if( mpModel && mpModel->IsReadOnly())
                 [ #  # ]
     224                 :            :     {
     225         [ #  # ]:          0 :         switch( rKEvt.GetKeyCode().GetCode() )
     226                 :            :         {
     227                 :            :         case awt::Key::DOWN:
     228                 :            :         case awt::Key::UP:
     229                 :            :         case awt::Key::LEFT:
     230                 :            :         case awt::Key::RIGHT:
     231                 :            :         case awt::Key::TAB:
     232                 :            :         case awt::Key::HOME:
     233                 :            :         case awt::Key::END:
     234                 :            :         case awt::Key::NUM2:
     235                 :            :         case awt::Key::NUM4:
     236                 :            :         case awt::Key::NUM6:
     237                 :            :         case awt::Key::NUM8:
     238                 :            :         case awt::Key::ESCAPE:
     239                 :            :         case awt::Key::F2:
     240                 :          0 :             break;
     241                 :            :         default:
     242                 :            :             // tell the view we eat the event, no further processing needed
     243                 :          0 :             return true;
     244                 :            :         }
     245                 :            :     }
     246                 :            : 
     247                 :          0 :     sal_uInt16 nAction = getKeyboardAction( rKEvt, pWindow );
     248                 :            : 
     249                 :          0 :     return executeAction( nAction, ( rKEvt.GetKeyCode().IsShift() ) ? sal_True : sal_False, pWindow );
     250                 :            : }
     251                 :            : 
     252                 :            : // --------------------------------------------------------------------
     253                 :            : // ::com::sun::star::awt::XMouseClickHandler:
     254                 :            : // --------------------------------------------------------------------
     255                 :            : 
     256                 :          0 : bool SvxTableController::onMouseButtonDown(const MouseEvent& rMEvt, Window* pWindow )
     257                 :            : {
     258 [ #  # ][ #  # ]:          0 :     if( !pWindow || !checkTableObject() )
         [ #  # ][ #  # ]
     259                 :          0 :         return false;
     260                 :            : 
     261         [ #  # ]:          0 :     SdrViewEvent aVEvt;
     262 [ #  # ][ #  # ]:          0 :     if( !rMEvt.IsRight() && mpView->PickAnything(rMEvt,SDRMOUSEBUTTONDOWN, aVEvt) == SDRHIT_HANDLE )
         [ #  # ][ #  # ]
     263                 :          0 :         return false;
     264                 :            : 
     265 [ #  # ][ #  # ]:          0 :     TableHitKind eHit = static_cast< SdrTableObj* >(mxTableObj.get())->CheckTableHit( pWindow->PixelToLogic(rMEvt.GetPosPixel()), maMouseDownPos.mnCol, maMouseDownPos.mnRow, 0 );
     266                 :            : 
     267 [ #  # ][ #  # ]:          0 :     mbLeftButtonDown = (rMEvt.GetClicks() == 1) && rMEvt.IsLeft();
     268                 :            : 
     269         [ #  # ]:          0 :     if( eHit == SDRTABLEHIT_CELL )
     270                 :            :     {
     271         [ #  # ]:          0 :         StartSelection( maMouseDownPos );
     272                 :          0 :         return true;
     273                 :            :     }
     274                 :            : 
     275 [ #  # ][ #  # ]:          0 :     if( rMEvt.IsRight() && eHit != SDRTABLEHIT_NONE )
                 [ #  # ]
     276                 :          0 :         return true; // right click will become context menu
     277                 :            : 
     278                 :            :     // for cell selektion with the mouse remember our first hit
     279         [ #  # ]:          0 :     if( mbLeftButtonDown )
     280                 :            :     {
     281         [ #  # ]:          0 :         RemoveSelection();
     282                 :            : 
     283                 :          0 :         Point aPnt(rMEvt.GetPosPixel());
     284         [ #  # ]:          0 :         if (pWindow!=NULL)
     285         [ #  # ]:          0 :             aPnt=pWindow->PixelToLogic(aPnt);
     286                 :            : 
     287         [ #  # ]:          0 :         SdrHdl* pHdl = mpView->PickHandle(aPnt);
     288                 :            : 
     289         [ #  # ]:          0 :         if( pHdl )
     290                 :            :         {
     291                 :          0 :             mbLeftButtonDown = false;
     292                 :            :         }
     293                 :            :         else
     294                 :            :         {
     295         [ #  # ]:          0 :             ::sdr::table::SdrTableObj* pTableObj = dynamic_cast< ::sdr::table::SdrTableObj* >( mxTableObj.get() );
     296                 :            : 
     297 [ #  # ][ #  # ]:          0 :             if( !pWindow || !pTableObj || eHit  == SDRTABLEHIT_NONE)
                 [ #  # ]
     298                 :            :             {
     299                 :          0 :                 mbLeftButtonDown = false;
     300                 :            :             }
     301                 :            :         }
     302                 :            :     }
     303                 :            : 
     304         [ #  # ]:          0 :     return false;
     305                 :            : }
     306                 :            : 
     307                 :            : // --------------------------------------------------------------------
     308                 :            : 
     309                 :          0 : bool SvxTableController::onMouseButtonUp(const MouseEvent& rMEvt, Window* /*pWin*/)
     310                 :            : {
     311         [ #  # ]:          0 :     if( !checkTableObject() )
     312                 :          0 :         return false;
     313                 :            : 
     314                 :          0 :     mbLeftButtonDown = false;
     315                 :            : 
     316         [ #  # ]:          0 :     if( rMEvt.GetClicks() == 2 )
     317                 :          0 :         return true;
     318                 :            : 
     319                 :          0 :     return false;
     320                 :            : }
     321                 :            : 
     322                 :            : // --------------------------------------------------------------------
     323                 :            : 
     324                 :          0 : bool SvxTableController::onMouseMove(const MouseEvent& rMEvt, Window* pWindow )
     325                 :            : {
     326 [ #  # ][ #  # ]:          0 :     if( !checkTableObject() )
     327                 :          0 :         return false;
     328                 :            : 
     329         [ #  # ]:          0 :     if( rMEvt.IsLeft() )
     330                 :            :     {
     331                 :          0 :         int i = 0;
     332                 :          0 :         i++;
     333                 :            :     }
     334                 :            : 
     335         [ #  # ]:          0 :     SdrTableObj* pTableObj = dynamic_cast< SdrTableObj* >( mxTableObj.get() );
     336                 :          0 :     CellPos aPos;
     337 [ #  # ][ #  # ]:          0 :     if( mbLeftButtonDown && pTableObj && pTableObj->CheckTableHit( pWindow->PixelToLogic(rMEvt.GetPosPixel()), aPos.mnCol, aPos.mnRow, 0 ) != SDRTABLEHIT_NONE )
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
                 [ #  # ]
     338                 :            :     {
     339         [ #  # ]:          0 :         if(aPos != maMouseDownPos)
     340                 :            :         {
     341         [ #  # ]:          0 :             if( mbCellSelectionMode )
     342                 :            :             {
     343         [ #  # ]:          0 :                 setSelectedCells( maMouseDownPos, aPos );
     344                 :          0 :                 return true;
     345                 :            :             }
     346                 :            :             else
     347                 :            :             {
     348         [ #  # ]:          0 :                 StartSelection( maMouseDownPos );
     349                 :            :             }
     350                 :            :         }
     351         [ #  # ]:          0 :         else if( mbCellSelectionMode )
     352                 :            :         {
     353         [ #  # ]:          0 :             UpdateSelection( aPos );
     354                 :          0 :             return true;
     355                 :            :         }
     356                 :            :     }
     357                 :          0 :     return false;
     358                 :            : }
     359                 :            : 
     360                 :            : // --------------------------------------------------------------------
     361                 :            : 
     362                 :          0 : void SvxTableController::onSelectionHasChanged()
     363                 :            : {
     364                 :          0 :     bool bSelected = false;
     365                 :            : 
     366         [ #  # ]:          0 :     SdrTableObj* pTableObj = dynamic_cast< SdrTableObj* >( mxTableObj.get() );
     367 [ #  # ][ #  # ]:          0 :     if( pTableObj && pTableObj->IsTextEditActive() )
                 [ #  # ]
     368                 :            :     {
     369                 :          0 :         pTableObj->getActiveCellPos( maCursorFirstPos );
     370                 :          0 :         maCursorLastPos = maCursorFirstPos;
     371                 :          0 :         mbCellSelectionMode = false;
     372                 :            :     }
     373                 :            :     else
     374                 :            :     {
     375                 :          0 :         const SdrMarkList& rMarkList= mpView->GetMarkedObjectList();
     376         [ #  # ]:          0 :         if( rMarkList.GetMarkCount() == 1 )
     377                 :          0 :             bSelected = mxTableObj.get() == rMarkList.GetMark(0)->GetMarkedSdrObj();
     378                 :            :     }
     379                 :            : 
     380         [ #  # ]:          0 :     if( bSelected )
     381                 :            :     {
     382                 :          0 :         updateSelectionOverlay();
     383                 :            :     }
     384                 :            :     else
     385                 :            :     {
     386                 :          0 :         destroySelectionOverlay();
     387                 :            :     }
     388                 :          0 : }
     389                 :            : 
     390                 :            : // --------------------------------------------------------------------
     391                 :            : 
     392                 :          0 : void SvxTableController::GetState( SfxItemSet& rSet )
     393                 :            : {
     394 [ #  # ][ #  # ]:          0 :     if( !mxTable.is() || !mxTableObj.is() || !mxTableObj->GetModel() )
         [ #  # ][ #  # ]
                 [ #  # ]
     395                 :          0 :         return;
     396                 :            : 
     397                 :          0 :     SfxItemSet* pSet = 0;
     398                 :            : 
     399                 :          0 :     bool bVertDone = false;
     400                 :            : 
     401                 :            :     // Iterate over all requested items in the set.
     402         [ #  # ]:          0 :     SfxWhichIter aIter( rSet );
     403         [ #  # ]:          0 :     sal_uInt16 nWhich = aIter.FirstWhich();
     404         [ #  # ]:          0 :     while (nWhich)
     405                 :            :     {
     406   [ #  #  #  #  :          0 :         switch (nWhich)
             #  #  #  # ]
     407                 :            :         {
     408                 :            :             case SID_TABLE_VERT_BOTTOM:
     409                 :            :             case SID_TABLE_VERT_CENTER:
     410                 :            :             case SID_TABLE_VERT_NONE:
     411                 :            :                 {
     412 [ #  # ][ #  # ]:          0 :                     if( !mxTable.is() || !mxTableObj->GetModel() )
         [ #  # ][ #  # ]
     413                 :            :                     {
     414         [ #  # ]:          0 :                         rSet.DisableItem(nWhich);
     415                 :            :                     }
     416         [ #  # ]:          0 :                     else if(!bVertDone)
     417                 :            :                     {
     418         [ #  # ]:          0 :                         if( !pSet )
     419                 :            :                         {
     420 [ #  # ][ #  # ]:          0 :                             pSet = new SfxItemSet( mxTableObj->GetModel()->GetItemPool() );
                 [ #  # ]
     421         [ #  # ]:          0 :                             MergeAttrFromSelectedCells(*pSet, sal_False);
     422                 :            :                         }
     423                 :            : 
     424                 :          0 :                         SdrTextVertAdjust eAdj = SDRTEXTVERTADJUST_BLOCK;
     425                 :            : 
     426 [ #  # ][ #  # ]:          0 :                         if( pSet->GetItemState( SDRATTR_TEXT_VERTADJUST ) != SFX_ITEM_DONTCARE )
     427         [ #  # ]:          0 :                             eAdj = ((SdrTextVertAdjustItem&)(pSet->Get(SDRATTR_TEXT_VERTADJUST))).GetValue();
     428                 :            : 
     429 [ #  # ][ #  # ]:          0 :                         rSet.Put(SfxBoolItem(SID_TABLE_VERT_BOTTOM, eAdj == SDRTEXTVERTADJUST_BOTTOM));
                 [ #  # ]
     430 [ #  # ][ #  # ]:          0 :                         rSet.Put(SfxBoolItem(SID_TABLE_VERT_CENTER, eAdj == SDRTEXTVERTADJUST_CENTER));
                 [ #  # ]
     431 [ #  # ][ #  # ]:          0 :                         rSet.Put(SfxBoolItem(SID_TABLE_VERT_NONE, eAdj == SDRTEXTVERTADJUST_TOP));
                 [ #  # ]
     432                 :          0 :                         bVertDone = true;
     433                 :            :                     }
     434                 :          0 :                     break;
     435                 :            :                 }
     436                 :            :             case SID_TABLE_DELETE_ROW:
     437 [ #  # ][ #  # ]:          0 :                 if( !mxTable.is() || !hasSelectedCells() || (mxTable->getRowCount() <= 1) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     438         [ #  # ]:          0 :                     rSet.DisableItem(SID_TABLE_DELETE_ROW);
     439                 :          0 :                 break;
     440                 :            :             case SID_TABLE_DELETE_COL:
     441 [ #  # ][ #  # ]:          0 :                 if( !mxTable.is() || !hasSelectedCells() || (mxTable->getColumnCount() <= 1) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     442         [ #  # ]:          0 :                     rSet.DisableItem(SID_TABLE_DELETE_COL);
     443                 :          0 :                 break;
     444                 :            :             case SID_TABLE_MERGE_CELLS:
     445 [ #  # ][ #  # ]:          0 :                 if( !mxTable.is() || !hasSelectedCells() )
         [ #  # ][ #  # ]
     446         [ #  # ]:          0 :                     rSet.DisableItem(SID_TABLE_MERGE_CELLS);
     447                 :          0 :                 break;
     448                 :            :             case SID_TABLE_SPLIT_CELLS:
     449 [ #  # ][ #  # ]:          0 :                 if( !hasSelectedCells() || !mxTable.is() )
         [ #  # ][ #  # ]
     450         [ #  # ]:          0 :                     rSet.DisableItem(SID_TABLE_SPLIT_CELLS);
     451                 :          0 :                 break;
     452                 :            : 
     453                 :            :             case SID_OPTIMIZE_TABLE:
     454                 :            :             case SID_TABLE_DISTRIBUTE_COLUMNS:
     455                 :            :             case SID_TABLE_DISTRIBUTE_ROWS:
     456                 :            :             {
     457                 :          0 :                 bool bDistributeColumns = false;
     458                 :          0 :                 bool bDistributeRows = false;
     459         [ #  # ]:          0 :                 if( mxTable.is() )
     460                 :            :                 {
     461                 :          0 :                     CellPos aStart, aEnd;
     462         [ #  # ]:          0 :                     getSelectedCells( aStart, aEnd );
     463                 :            : 
     464                 :          0 :                     bDistributeColumns = aStart.mnCol != aEnd.mnCol;
     465                 :          0 :                     bDistributeRows = aStart.mnRow != aEnd.mnRow;
     466                 :            :                 }
     467 [ #  # ][ #  # ]:          0 :                 if( !bDistributeColumns && !bDistributeRows )
     468         [ #  # ]:          0 :                     rSet.DisableItem(SID_OPTIMIZE_TABLE);
     469         [ #  # ]:          0 :                 if( !bDistributeColumns )
     470         [ #  # ]:          0 :                     rSet.DisableItem(SID_TABLE_DISTRIBUTE_COLUMNS);
     471         [ #  # ]:          0 :                 if( !bDistributeRows )
     472         [ #  # ]:          0 :                     rSet.DisableItem(SID_TABLE_DISTRIBUTE_ROWS);
     473                 :          0 :                 break;
     474                 :            :             }
     475                 :            : 
     476                 :            :             case SID_AUTOFORMAT:
     477                 :            :             case SID_TABLE_SORT_DIALOG:
     478                 :            :             case SID_TABLE_AUTOSUM:
     479                 :            : //              if( !mxTable.is() )
     480                 :            : //                  rSet.DisableItem( nWhich );
     481                 :          0 :                 break;
     482                 :            :             default:
     483                 :          0 :                 break;
     484                 :            :         }
     485         [ #  # ]:          0 :         nWhich = aIter.NextWhich();
     486                 :            :     }
     487         [ #  # ]:          0 :     if( pSet )
     488 [ #  # ][ #  # ]:          0 :         delete pSet;
                 [ #  # ]
     489                 :            : }
     490                 :            : 
     491                 :            : // --------------------------------------------------------------------
     492                 :            : 
     493                 :          0 : void SvxTableController::onInsert( sal_uInt16 nSId, const SfxItemSet* pArgs )
     494                 :            : {
     495         [ #  # ]:          0 :     ::sdr::table::SdrTableObj* pTableObj = dynamic_cast< ::sdr::table::SdrTableObj* >( mxTableObj.get() );
     496         [ #  # ]:          0 :     if( !pTableObj )
     497                 :          0 :         return;
     498                 :            : 
     499         [ #  # ]:          0 :     if( mxTable.is() ) try
     500                 :            :     {
     501                 :            :         //
     502                 :          0 :         bool bInsertAfter = true;
     503                 :          0 :         sal_uInt16 nCount = 0;
     504         [ #  # ]:          0 :         if( pArgs )
     505                 :            :         {
     506                 :          0 :             const SfxPoolItem* pItem = 0;
     507         [ #  # ]:          0 :             pArgs->GetItemState(nSId, sal_False, &pItem);
     508         [ #  # ]:          0 :             if (pItem)
     509                 :            :             {
     510                 :          0 :                 nCount = ((const SfxInt16Item* )pItem)->GetValue();
     511 [ #  # ][ #  # ]:          0 :                 if(SFX_ITEM_SET == pArgs->GetItemState(SID_TABLE_PARAM_INSERT_AFTER, sal_True, &pItem))
     512                 :          0 :                     bInsertAfter = ((const SfxBoolItem* )pItem)->GetValue();
     513                 :            :             }
     514                 :            :         }
     515                 :            : 
     516                 :          0 :         CellPos aStart, aEnd;
     517 [ #  # ][ #  # ]:          0 :         if( hasSelectedCells() )
     518                 :            :         {
     519         [ #  # ]:          0 :             getSelectedCells( aStart, aEnd );
     520                 :            :         }
     521                 :            :         else
     522                 :            :         {
     523         [ #  # ]:          0 :             if( bInsertAfter )
     524                 :            :             {
     525         [ #  # ]:          0 :                 aStart.mnCol = mxTable->getColumnCount() - 1;
     526         [ #  # ]:          0 :                 aStart.mnRow = mxTable->getRowCount() - 1;
     527                 :          0 :                 aEnd = aStart;
     528                 :            :             }
     529                 :            :         }
     530                 :            : 
     531         [ #  # ]:          0 :         if( pTableObj->IsTextEditActive() )
     532         [ #  # ]:          0 :             mpView->SdrEndTextEdit(sal_True);
     533                 :            : 
     534         [ #  # ]:          0 :         RemoveSelection();
     535                 :            : 
     536         [ #  # ]:          0 :         const OUString sSize( RTL_CONSTASCII_USTRINGPARAM( "Size" ) );
     537                 :            : 
     538 [ #  # ][ #  # ]:          0 :         const bool bUndo = mpModel && mpModel->IsUndoEnabled();
                 [ #  # ]
     539                 :            : 
     540      [ #  #  # ]:          0 :         switch( nSId )
     541                 :            :         {
     542                 :            :         case SID_TABLE_INSERT_COL:
     543                 :            :         {
     544         [ #  # ]:          0 :             TableModelNotifyGuard aGuard( mxTable.get() );
     545                 :            : 
     546         [ #  # ]:          0 :             if( bUndo )
     547                 :            :             {
     548 [ #  # ][ #  # ]:          0 :                 mpModel->BegUndo( ImpGetResStr(STR_TABLE_INSCOL) );
                 [ #  # ]
     549 [ #  # ][ #  # ]:          0 :                 mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*pTableObj) );
                 [ #  # ]
     550                 :            :             }
     551                 :            : 
     552         [ #  # ]:          0 :             Reference< XTableColumns > xCols( mxTable->getColumns() );
     553         [ #  # ]:          0 :             const sal_Int32 nNewColumns = (nCount == 0) ? (aEnd.mnCol - aStart.mnCol + 1) : nCount;
     554         [ #  # ]:          0 :             const sal_Int32 nNewStartColumn = aEnd.mnCol + (bInsertAfter ? 1 : 0);
     555 [ #  # ][ #  # ]:          0 :             xCols->insertByIndex( nNewStartColumn, nNewColumns );
     556                 :            : 
     557         [ #  # ]:          0 :             for( sal_Int32 nOffset = 0; nOffset < nNewColumns; nOffset++ )
     558                 :            :             {
     559 [ #  # ][ #  # ]:          0 :                 Reference< XPropertySet >( xCols->getByIndex( aEnd.mnCol + nOffset + 1 ), UNO_QUERY_THROW )->
         [ #  # ][ #  # ]
     560                 :            :                     setPropertyValue( sSize,
     561 [ #  # ][ #  # ]:          0 :                         Reference< XPropertySet >( xCols->getByIndex( aStart.mnCol + nOffset ), UNO_QUERY_THROW )->
         [ #  # ][ #  # ]
     562 [ #  # ][ #  # ]:          0 :                             getPropertyValue( sSize ) );
     563                 :            :             }
     564                 :            : 
     565         [ #  # ]:          0 :             if( bUndo )
     566         [ #  # ]:          0 :                 mpModel->EndUndo();
     567                 :            : 
     568                 :          0 :             aStart.mnCol = nNewStartColumn;
     569                 :          0 :             aStart.mnRow = 0;
     570                 :          0 :             aEnd.mnCol = aStart.mnCol + nNewColumns - 1;
     571         [ #  # ]:          0 :             aEnd.mnRow = mxTable->getRowCount() - 1;
     572         [ #  # ]:          0 :             break;
     573                 :            :         }
     574                 :            : 
     575                 :            :         case SID_TABLE_INSERT_ROW:
     576                 :            :         {
     577         [ #  # ]:          0 :             TableModelNotifyGuard aGuard( mxTable.get() );
     578                 :            : 
     579         [ #  # ]:          0 :             if( bUndo )
     580                 :            :             {
     581 [ #  # ][ #  # ]:          0 :                 mpModel->BegUndo( ImpGetResStr(STR_TABLE_INSROW ) );
                 [ #  # ]
     582 [ #  # ][ #  # ]:          0 :                 mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*pTableObj) );
                 [ #  # ]
     583                 :            :             }
     584                 :            : 
     585         [ #  # ]:          0 :             Reference< XTableRows > xRows( mxTable->getRows() );
     586         [ #  # ]:          0 :             const sal_Int32 nNewRows = (nCount == 0) ? (aEnd.mnRow - aStart.mnRow + 1) : nCount;
     587         [ #  # ]:          0 :             const sal_Int32 nNewRowStart = aEnd.mnRow + (bInsertAfter ? 1 : 0);
     588 [ #  # ][ #  # ]:          0 :             xRows->insertByIndex( nNewRowStart, nNewRows );
     589                 :            : 
     590         [ #  # ]:          0 :             for( sal_Int32 nOffset = 0; nOffset < nNewRows; nOffset++ )
     591                 :            :             {
     592 [ #  # ][ #  # ]:          0 :                 Reference< XPropertySet >( xRows->getByIndex( aEnd.mnRow + nOffset + 1 ), UNO_QUERY_THROW )->
         [ #  # ][ #  # ]
     593                 :            :                     setPropertyValue( sSize,
     594 [ #  # ][ #  # ]:          0 :                         Reference< XPropertySet >( xRows->getByIndex( aStart.mnRow + nOffset ), UNO_QUERY_THROW )->
         [ #  # ][ #  # ]
     595 [ #  # ][ #  # ]:          0 :                             getPropertyValue( sSize ) );
     596                 :            :             }
     597                 :            : 
     598         [ #  # ]:          0 :             if( bUndo )
     599         [ #  # ]:          0 :                 mpModel->EndUndo();
     600                 :            : 
     601                 :          0 :             aStart.mnCol = 0;
     602                 :          0 :             aStart.mnRow = nNewRowStart;
     603         [ #  # ]:          0 :             aEnd.mnCol = mxTable->getColumnCount() - 1;
     604                 :          0 :             aEnd.mnRow = aStart.mnRow + nNewRows - 1;
     605         [ #  # ]:          0 :             break;
     606                 :            :         }
     607                 :            :         }
     608                 :            : 
     609         [ #  # ]:          0 :         StartSelection( aStart );
     610 [ #  # ][ #  # ]:          0 :         UpdateSelection( aEnd );
     611                 :            :     }
     612                 :          0 :     catch( Exception& )
     613                 :            :     {
     614                 :            :         OSL_FAIL("svx::SvxTableController::onInsert(), exception caught!");
     615                 :            :     }
     616                 :            : }
     617                 :            : 
     618                 :            : // --------------------------------------------------------------------
     619                 :            : 
     620                 :          0 : void SvxTableController::onDelete( sal_uInt16 nSId )
     621                 :            : {
     622         [ #  # ]:          0 :     ::sdr::table::SdrTableObj* pTableObj = dynamic_cast< ::sdr::table::SdrTableObj* >( mxTableObj.get() );
     623         [ #  # ]:          0 :     if( !pTableObj )
     624                 :          0 :         return;
     625                 :            : 
     626 [ #  # ][ #  # ]:          0 :     if( mxTable.is() && hasSelectedCells() )
                 [ #  # ]
     627                 :            :     {
     628                 :          0 :         CellPos aStart, aEnd;
     629         [ #  # ]:          0 :         getSelectedCells( aStart, aEnd );
     630                 :            : 
     631         [ #  # ]:          0 :         if( pTableObj->IsTextEditActive() )
     632         [ #  # ]:          0 :             mpView->SdrEndTextEdit(sal_True);
     633                 :            : 
     634         [ #  # ]:          0 :         RemoveSelection();
     635                 :            : 
     636                 :          0 :         bool bDeleteTable = false;
     637      [ #  #  # ]:          0 :         switch( nSId )
     638                 :            :         {
     639                 :            :         case SID_TABLE_DELETE_COL:
     640                 :            :         {
     641                 :          0 :             const sal_Int32 nRemovedColumns = aEnd.mnCol - aStart.mnCol + 1;
     642 [ #  # ][ #  # ]:          0 :             if( nRemovedColumns == mxTable->getColumnCount() )
     643                 :            :             {
     644                 :          0 :                 bDeleteTable = true;
     645                 :            :             }
     646                 :            :             else
     647                 :            :             {
     648         [ #  # ]:          0 :                 Reference< XTableColumns > xCols( mxTable->getColumns() );
     649 [ #  # ][ #  # ]:          0 :                 xCols->removeByIndex( aStart.mnCol, nRemovedColumns );
     650                 :            :             }
     651                 :          0 :             break;
     652                 :            :         }
     653                 :            : 
     654                 :            :         case SID_TABLE_DELETE_ROW:
     655                 :            :         {
     656                 :          0 :             const sal_Int32 nRemovedRows = aEnd.mnRow - aStart.mnRow + 1;
     657 [ #  # ][ #  # ]:          0 :             if( nRemovedRows == mxTable->getRowCount() )
     658                 :            :             {
     659                 :          0 :                 bDeleteTable = true;
     660                 :            :             }
     661                 :            :             else
     662                 :            :             {
     663         [ #  # ]:          0 :                 Reference< XTableRows > xRows( mxTable->getRows() );
     664 [ #  # ][ #  # ]:          0 :                 xRows->removeByIndex( aStart.mnRow, nRemovedRows );
     665                 :            :             }
     666                 :          0 :             break;
     667                 :            :         }
     668                 :            :         }
     669                 :            : 
     670         [ #  # ]:          0 :         if( bDeleteTable )
     671         [ #  # ]:          0 :             mpView->DeleteMarkedObj();
     672                 :            :         else
     673         [ #  # ]:          0 :             UpdateTableShape();
     674                 :            :     }
     675                 :            : }
     676                 :            : 
     677                 :            : // --------------------------------------------------------------------
     678                 :            : 
     679                 :          0 : void SvxTableController::onSelect( sal_uInt16 nSId )
     680                 :            : {
     681         [ #  # ]:          0 :     if( mxTable.is() )
     682                 :            :     {
     683                 :          0 :         const sal_Int32 nRowCount = mxTable->getRowCount();
     684                 :          0 :         const sal_Int32 nColCount = mxTable->getColumnCount();
     685 [ #  # ][ #  # ]:          0 :         if( nRowCount && nColCount )
     686                 :            :         {
     687                 :          0 :             CellPos aStart, aEnd;
     688         [ #  # ]:          0 :             getSelectedCells( aStart, aEnd );
     689                 :            : 
     690   [ #  #  #  # ]:          0 :             switch( nSId )
     691                 :            :             {
     692                 :            :             case SID_TABLE_SELECT_ALL:
     693                 :          0 :                 aEnd.mnCol = 0; aEnd.mnRow = 0;
     694                 :          0 :                 aStart.mnCol = nColCount - 1; aStart.mnRow = nRowCount - 1;
     695                 :          0 :                 break;
     696                 :            :             case SID_TABLE_SELECT_COL:
     697                 :          0 :                 aEnd.mnRow = nRowCount - 1;
     698                 :          0 :                 aStart.mnRow = 0;
     699                 :          0 :                 break;
     700                 :            :             case SID_TABLE_SELECT_ROW:
     701                 :          0 :                 aEnd.mnCol = nColCount - 1;
     702                 :          0 :                 aStart.mnCol = 0;
     703                 :          0 :                 break;
     704                 :            :             }
     705                 :            : 
     706         [ #  # ]:          0 :             StartSelection( aEnd );
     707         [ #  # ]:          0 :             gotoCell( aStart, true, 0 );
     708                 :            :         }
     709                 :            :     }
     710                 :          0 : }
     711                 :            : 
     712                 :            : // --------------------------------------------------------------------
     713                 :          0 : void SvxTableController::onFormatTable( SfxRequest& rReq )
     714                 :            : {
     715         [ #  # ]:          0 :     ::sdr::table::SdrTableObj* pTableObj = dynamic_cast< ::sdr::table::SdrTableObj* >( mxTableObj.get() );
     716         [ #  # ]:          0 :     if( !pTableObj )
     717                 :          0 :         return;
     718                 :            : 
     719                 :          0 :     const SfxItemSet* pArgs = rReq.GetArgs();
     720                 :            : 
     721 [ #  # ][ #  # ]:          0 :     if( !pArgs && pTableObj->GetModel() )
                 [ #  # ]
     722                 :            :     {
     723 [ #  # ][ #  # ]:          0 :         SfxItemSet aNewAttr( pTableObj->GetModel()->GetItemPool() );
     724         [ #  # ]:          0 :         MergeAttrFromSelectedCells(aNewAttr, sal_False);
     725                 :            : 
     726                 :            :         // merge drawing layer text distance items into SvxBoxItem used by the dialog
     727 [ #  # ][ #  # ]:          0 :         SvxBoxItem aBoxItem( static_cast< const SvxBoxItem& >( aNewAttr.Get( SDRATTR_TABLE_BORDER ) ) );
     728 [ #  # ][ #  # ]:          0 :         aBoxItem.SetDistance( sal::static_int_cast< sal_uInt16 >( ((SdrTextLeftDistItem&)(aNewAttr.Get(SDRATTR_TEXT_LEFTDIST))).GetValue()), BOX_LINE_LEFT );
     729 [ #  # ][ #  # ]:          0 :         aBoxItem.SetDistance( sal::static_int_cast< sal_uInt16 >( ((SdrTextRightDistItem&)(aNewAttr.Get(SDRATTR_TEXT_RIGHTDIST))).GetValue()), BOX_LINE_RIGHT );
     730 [ #  # ][ #  # ]:          0 :         aBoxItem.SetDistance( sal::static_int_cast< sal_uInt16 >( ((SdrTextUpperDistItem&)(aNewAttr.Get(SDRATTR_TEXT_UPPERDIST))).GetValue()), BOX_LINE_TOP );
     731 [ #  # ][ #  # ]:          0 :         aBoxItem.SetDistance( sal::static_int_cast< sal_uInt16 >( ((SdrTextLowerDistItem&)(aNewAttr.Get(SDRATTR_TEXT_LOWERDIST))).GetValue()), BOX_LINE_BOTTOM );
     732         [ #  # ]:          0 :         aNewAttr.Put( aBoxItem );
     733                 :            : 
     734         [ #  # ]:          0 :         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     735 [ #  # ][ #  # ]:          0 :         std::auto_ptr< SfxAbstractTabDialog > pDlg( pFact ? pFact->CreateSvxFormatCellsDialog( NULL, &aNewAttr, pTableObj->GetModel(), pTableObj) : 0 );
                 [ #  # ]
     736 [ #  # ][ #  # ]:          0 :         if( pDlg.get() && pDlg->Execute() )
         [ #  # ][ #  # ]
     737                 :            :         {
     738 [ #  # ][ #  # ]:          0 :             SfxItemSet aNewSet( *(pDlg->GetOutputItemSet ()) );
     739                 :            : 
     740 [ #  # ][ #  # ]:          0 :             SvxBoxItem aNewBoxItem( static_cast< const SvxBoxItem& >( aNewSet.Get( SDRATTR_TABLE_BORDER ) ) );
     741                 :            : 
     742 [ #  # ][ #  # ]:          0 :             if( aNewBoxItem.GetDistance( BOX_LINE_LEFT ) != aBoxItem.GetDistance( BOX_LINE_LEFT ) )
                 [ #  # ]
     743 [ #  # ][ #  # ]:          0 :                 aNewSet.Put(SdrTextLeftDistItem( aNewBoxItem.GetDistance( BOX_LINE_LEFT ) ) );
         [ #  # ][ #  # ]
     744                 :            : 
     745 [ #  # ][ #  # ]:          0 :             if( aNewBoxItem.GetDistance( BOX_LINE_RIGHT ) != aBoxItem.GetDistance( BOX_LINE_RIGHT ) )
                 [ #  # ]
     746 [ #  # ][ #  # ]:          0 :                 aNewSet.Put(SdrTextRightDistItem( aNewBoxItem.GetDistance( BOX_LINE_RIGHT ) ) );
         [ #  # ][ #  # ]
     747                 :            : 
     748 [ #  # ][ #  # ]:          0 :             if( aNewBoxItem.GetDistance( BOX_LINE_TOP ) != aBoxItem.GetDistance( BOX_LINE_TOP ) )
                 [ #  # ]
     749 [ #  # ][ #  # ]:          0 :                 aNewSet.Put(SdrTextUpperDistItem( aNewBoxItem.GetDistance( BOX_LINE_TOP ) ) );
         [ #  # ][ #  # ]
     750                 :            : 
     751 [ #  # ][ #  # ]:          0 :             if( aNewBoxItem.GetDistance( BOX_LINE_BOTTOM ) != aBoxItem.GetDistance( BOX_LINE_BOTTOM ) )
                 [ #  # ]
     752 [ #  # ][ #  # ]:          0 :                 aNewSet.Put(SdrTextLowerDistItem( aNewBoxItem.GetDistance( BOX_LINE_BOTTOM ) ) );
         [ #  # ][ #  # ]
     753                 :            : 
     754 [ #  # ][ #  # ]:          0 :             SetAttrToSelectedCells(aNewSet, sal_False);
                 [ #  # ]
     755                 :            :         }
     756 [ #  # ][ #  # ]:          0 :         UpdateTableShape();
         [ #  # ][ #  # ]
     757                 :            :     }
     758                 :            : }
     759                 :            : 
     760                 :            : // --------------------------------------------------------------------
     761                 :            : 
     762                 :          0 : void SvxTableController::Execute( SfxRequest& rReq )
     763                 :            : {
     764                 :          0 :     const sal_uInt16 nSId = rReq.GetSlot();
     765   [ #  #  #  #  :          0 :     switch( nSId )
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     766                 :            :     {
     767                 :            :     case SID_TABLE_INSERT_ROW:
     768                 :            :     case SID_TABLE_INSERT_COL:
     769                 :          0 :         onInsert( nSId, rReq.GetArgs() );
     770                 :          0 :         break;
     771                 :            :     case SID_TABLE_DELETE_ROW:
     772                 :            :     case SID_TABLE_DELETE_COL:
     773                 :          0 :         onDelete( nSId );
     774                 :          0 :         break;
     775                 :            :     case SID_TABLE_SELECT_ALL:
     776                 :            :     case SID_TABLE_SELECT_COL:
     777                 :            :     case SID_TABLE_SELECT_ROW:
     778                 :          0 :         onSelect( nSId );
     779                 :          0 :         break;
     780                 :            :     case SID_FORMAT_TABLE_DLG:
     781                 :          0 :         onFormatTable( rReq );
     782                 :          0 :         break;
     783                 :            : 
     784                 :            :     case SID_FRAME_LINESTYLE:
     785                 :            :     case SID_FRAME_LINECOLOR:
     786                 :            :     case SID_ATTR_BORDER:
     787                 :            :         {
     788                 :          0 :             const SfxItemSet* pArgs = rReq.GetArgs();
     789         [ #  # ]:          0 :             if( pArgs )
     790                 :          0 :                 ApplyBorderAttr( *pArgs );
     791                 :            :         }
     792                 :          0 :         break;
     793                 :            : 
     794                 :            :     case SID_ATTR_FILL_STYLE:
     795                 :            :         {
     796                 :          0 :             const SfxItemSet* pArgs = rReq.GetArgs();
     797         [ #  # ]:          0 :             if( pArgs )
     798                 :          0 :                 SetAttributes( *pArgs, false );
     799                 :            :         }
     800                 :          0 :         break;
     801                 :            : 
     802                 :            :     case SID_TABLE_MERGE_CELLS:
     803                 :          0 :         MergeMarkedCells();
     804                 :          0 :         break;
     805                 :            : 
     806                 :            :     case SID_TABLE_SPLIT_CELLS:
     807                 :          0 :         SplitMarkedCells();
     808                 :          0 :         break;
     809                 :            : 
     810                 :            :     case SID_TABLE_DISTRIBUTE_COLUMNS:
     811                 :          0 :         DistributeColumns();
     812                 :          0 :         break;
     813                 :            : 
     814                 :            :     case SID_TABLE_DISTRIBUTE_ROWS:
     815                 :          0 :         DistributeRows();
     816                 :          0 :         break;
     817                 :            : 
     818                 :            :     case SID_TABLE_VERT_BOTTOM:
     819                 :            :     case SID_TABLE_VERT_CENTER:
     820                 :            :     case SID_TABLE_VERT_NONE:
     821                 :          0 :         SetVertical( nSId );
     822                 :          0 :         break;
     823                 :            : 
     824                 :            :     case SID_AUTOFORMAT:
     825                 :            :     case SID_TABLE_SORT_DIALOG:
     826                 :            :     case SID_TABLE_AUTOSUM:
     827                 :            :     default:
     828                 :          0 :         break;
     829                 :            : 
     830                 :            :     case SID_TABLE_STYLE:
     831                 :          0 :         SetTableStyle( rReq.GetArgs() );
     832                 :          0 :         break;
     833                 :            : 
     834                 :            :     case SID_TABLE_STYLE_SETTINGS:
     835                 :          0 :         SetTableStyleSettings( rReq.GetArgs() );
     836                 :          0 :         break;
     837                 :            :     }
     838                 :          0 : }
     839                 :            : 
     840                 :          0 : void SvxTableController::SetTableStyle( const SfxItemSet* pArgs )
     841                 :            : {
     842         [ #  # ]:          0 :     SdrTableObj* pTableObj = dynamic_cast< ::sdr::table::SdrTableObj* >( mxTableObj.get() );
     843         [ #  # ]:          0 :     SdrModel* pModel = pTableObj ? pTableObj->GetModel() : 0;
     844                 :            : 
     845 [ #  # ][ #  # ]:          0 :     if( !pTableObj || !pModel || !pArgs || (SFX_ITEM_SET != pArgs->GetItemState(SID_TABLE_STYLE, sal_False)) )
         [ #  # ][ #  # ]
                 [ #  # ]
     846                 :          0 :         return;
     847                 :            : 
     848         [ #  # ]:          0 :     const SfxStringItem* pArg = dynamic_cast< const SfxStringItem* >( &pArgs->Get( SID_TABLE_STYLE ) );
     849 [ #  # ][ #  # ]:          0 :     if( pArg && mxTable.is() ) try
                 [ #  # ]
     850                 :            :     {
     851 [ #  # ][ #  # ]:          0 :         Reference< XStyleFamiliesSupplier > xSFS( pModel->getUnoModel(), UNO_QUERY_THROW );
     852 [ #  # ][ #  # ]:          0 :         Reference< XNameAccess > xFamilyNameAccess( xSFS->getStyleFamilies(), UNO_QUERY_THROW );
                 [ #  # ]
     853         [ #  # ]:          0 :         const OUString sFamilyName( RTL_CONSTASCII_USTRINGPARAM( "table" ) );
     854 [ #  # ][ #  # ]:          0 :         Reference< XNameAccess > xTableFamilyAccess( xFamilyNameAccess->getByName( sFamilyName ), UNO_QUERY_THROW );
                 [ #  # ]
     855                 :            : 
     856 [ #  # ][ #  # ]:          0 :         if( xTableFamilyAccess->hasByName( pArg->GetValue() ) )
         [ #  # ][ #  # ]
     857                 :            :         {
     858                 :            :             // found table style with the same name
     859 [ #  # ][ #  # ]:          0 :             Reference< XIndexAccess > xNewTableStyle( xTableFamilyAccess->getByName( pArg->GetValue() ), UNO_QUERY_THROW );
         [ #  # ][ #  # ]
     860                 :            : 
     861         [ #  # ]:          0 :             const bool bUndo = pModel->IsUndoEnabled();
     862                 :            : 
     863         [ #  # ]:          0 :             if( bUndo )
     864                 :            :             {
     865 [ #  # ][ #  # ]:          0 :                 pModel->BegUndo( ImpGetResStr(STR_TABLE_STYLE) );
                 [ #  # ]
     866 [ #  # ][ #  # ]:          0 :                 pModel->AddUndo( new TableStyleUndo( *pTableObj ) );
                 [ #  # ]
     867                 :            :             }
     868                 :            : 
     869         [ #  # ]:          0 :             pTableObj->setTableStyle( xNewTableStyle );
     870                 :            : 
     871         [ #  # ]:          0 :             const sal_Int32 nRowCount = mxTable->getRowCount();
     872         [ #  # ]:          0 :             const sal_Int32 nColCount = mxTable->getColumnCount();
     873         [ #  # ]:          0 :             for( sal_Int32 nRow = 0; nRow < nRowCount; nRow++ )
     874                 :            :             {
     875         [ #  # ]:          0 :                 for( sal_Int32 nCol = 0; nCol < nColCount; nCol++ ) try
     876                 :            :                 {
     877 [ #  # ][ #  # ]:          0 :                     CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
                 [ #  # ]
     878         [ #  # ]:          0 :                     if( xCell.is() )
     879                 :            :                     {
     880 [ #  # ][ #  # ]:          0 :                         SfxItemSet aSet( xCell->GetItemSet() );
     881                 :          0 :                         bool bChanges = false;
     882 [ #  # ][ #  # ]:          0 :                         const SfxItemSet& rStyleAttribs = xCell->GetStyleSheet()->GetItemSet();
     883                 :            : 
     884         [ #  # ]:          0 :                         for ( sal_uInt16 nWhich = SDRATTR_START; nWhich <= SDRATTR_TABLE_LAST; nWhich++ )
     885                 :            :                         {
     886 [ #  # ][ #  # ]:          0 :                             if( (rStyleAttribs.GetItemState( nWhich ) == SFX_ITEM_ON) && (aSet.GetItemState( nWhich ) == SFX_ITEM_ON) )
         [ #  # ][ #  # ]
                 [ #  # ]
     887                 :            :                             {
     888         [ #  # ]:          0 :                                 aSet.ClearItem( nWhich );
     889                 :          0 :                                 bChanges = true;
     890                 :            :                             }
     891                 :            :                         }
     892                 :            : 
     893         [ #  # ]:          0 :                         if( bChanges )
     894                 :            :                         {
     895         [ #  # ]:          0 :                             if( bUndo )
     896         [ #  # ]:          0 :                                 xCell->AddUndo();
     897                 :            : 
     898         [ #  # ]:          0 :                             xCell->SetMergedItemSetAndBroadcast( aSet, sal_True );
     899         [ #  # ]:          0 :                         }
     900         [ #  # ]:          0 :                     }
     901                 :            :                 }
     902         [ #  # ]:          0 :                 catch( Exception& )
     903                 :            :                 {
     904                 :            :                     OSL_FAIL( "svx::SvxTableController::SetTableStyle(), exception caught!" );
     905                 :            :                 }
     906                 :            :             }
     907                 :            : 
     908         [ #  # ]:          0 :             if( bUndo )
     909         [ #  # ]:          0 :                 pModel->EndUndo();
     910         [ #  # ]:          0 :         }
     911                 :            :     }
     912                 :          0 :     catch( Exception& )
     913                 :            :     {
     914                 :            :         OSL_FAIL( "svx::SvxTableController::SetTableStyle(), exception caught!" );
     915                 :            :     }
     916                 :            : }
     917                 :            : 
     918                 :          0 : void SvxTableController::SetTableStyleSettings( const SfxItemSet* pArgs )
     919                 :            : {
     920         [ #  # ]:          0 :     SdrTableObj* pTableObj = dynamic_cast< ::sdr::table::SdrTableObj* >( mxTableObj.get() );
     921 [ #  # ][ #  # ]:          0 :     SdrModel* pModel = pTableObj ? pTableObj->GetModel() : 0;
     922                 :            : 
     923 [ #  # ][ #  # ]:          0 :     if( !pTableObj || !pModel )
     924                 :            :         return;
     925                 :            : 
     926 [ #  # ][ #  # ]:          0 :     TableStyleSettings aSettings( pTableObj->getTableStyleSettings() );
     927                 :            : 
     928                 :          0 :     const SfxPoolItem *pPoolItem=NULL;
     929                 :            : 
     930 [ #  # ][ #  # ]:          0 :     if( (SFX_ITEM_SET == pArgs->GetItemState(ID_VAL_USEFIRSTROWSTYLE, sal_False,&pPoolItem)) )
     931                 :          0 :         aSettings.mbUseFirstRow = static_cast< const SfxBoolItem* >(pPoolItem)->GetValue();
     932                 :            : 
     933 [ #  # ][ #  # ]:          0 :     if( (SFX_ITEM_SET == pArgs->GetItemState(ID_VAL_USELASTROWSTYLE, sal_False,&pPoolItem)) )
     934                 :          0 :         aSettings.mbUseLastRow = static_cast< const SfxBoolItem* >(pPoolItem)->GetValue();
     935                 :            : 
     936 [ #  # ][ #  # ]:          0 :     if( (SFX_ITEM_SET == pArgs->GetItemState(ID_VAL_USEBANDINGROWSTYLE, sal_False,&pPoolItem)) )
     937                 :          0 :         aSettings.mbUseRowBanding = static_cast< const SfxBoolItem* >(pPoolItem)->GetValue();
     938                 :            : 
     939 [ #  # ][ #  # ]:          0 :     if( (SFX_ITEM_SET == pArgs->GetItemState(ID_VAL_USEFIRSTCOLUMNSTYLE, sal_False,&pPoolItem)) )
     940                 :          0 :         aSettings.mbUseFirstColumn = static_cast< const SfxBoolItem* >(pPoolItem)->GetValue();
     941                 :            : 
     942 [ #  # ][ #  # ]:          0 :     if( (SFX_ITEM_SET == pArgs->GetItemState(ID_VAL_USELASTCOLUMNSTYLE, sal_False,&pPoolItem)) )
     943                 :          0 :         aSettings.mbUseLastColumn = static_cast< const SfxBoolItem* >(pPoolItem)->GetValue();
     944                 :            : 
     945 [ #  # ][ #  # ]:          0 :     if( (SFX_ITEM_SET == pArgs->GetItemState(ID_VAL_USEBANDINGCOLUMNSTYLE, sal_False,&pPoolItem)) )
     946                 :          0 :         aSettings.mbUseColumnBanding = static_cast< const SfxBoolItem* >(pPoolItem)->GetValue();
     947                 :            : 
     948 [ #  # ][ #  # ]:          0 :     if( aSettings == pTableObj->getTableStyleSettings() )
                 [ #  # ]
     949                 :            :         return;
     950                 :            : 
     951         [ #  # ]:          0 :     const bool bUndo = pModel->IsUndoEnabled();
     952                 :            : 
     953         [ #  # ]:          0 :     if( bUndo )
     954                 :            :     {
     955 [ #  # ][ #  # ]:          0 :         pModel->BegUndo( ImpGetResStr(STR_TABLE_STYLE_SETTINGS) );
                 [ #  # ]
     956 [ #  # ][ #  # ]:          0 :         pModel->AddUndo( new TableStyleUndo( *pTableObj ) );
                 [ #  # ]
     957                 :            :     }
     958                 :            : 
     959         [ #  # ]:          0 :     pTableObj->setTableStyleSettings( aSettings );
     960                 :            : 
     961         [ #  # ]:          0 :     if( bUndo )
     962         [ #  # ]:          0 :         pModel->EndUndo();
     963                 :            : }
     964                 :            : 
     965                 :          0 : void SvxTableController::SetVertical( sal_uInt16 nSId )
     966                 :            : {
     967         [ #  # ]:          0 :     SdrTableObj* pTableObj = dynamic_cast< ::sdr::table::SdrTableObj* >( mxTableObj.get() );
     968 [ #  # ][ #  # ]:          0 :     if( mxTable.is() && pTableObj )
                 [ #  # ]
     969                 :            :     {
     970         [ #  # ]:          0 :         TableModelNotifyGuard aGuard( mxTable.get() );
     971                 :            : 
     972                 :          0 :         CellPos aStart, aEnd;
     973         [ #  # ]:          0 :         getSelectedCells( aStart, aEnd );
     974                 :            : 
     975                 :          0 :         SdrTextVertAdjust eAdj = SDRTEXTVERTADJUST_TOP;
     976                 :            : 
     977      [ #  #  # ]:          0 :         switch( nSId )
     978                 :            :         {
     979                 :            :             case SID_TABLE_VERT_BOTTOM:
     980                 :          0 :                 eAdj = SDRTEXTVERTADJUST_BOTTOM;
     981                 :          0 :                 break;
     982                 :            :             case SID_TABLE_VERT_CENTER:
     983                 :          0 :                 eAdj = SDRTEXTVERTADJUST_CENTER;
     984                 :          0 :                 break;
     985                 :            :             //case SID_TABLE_VERT_NONE:
     986                 :            :             default:
     987                 :          0 :                 break;
     988                 :            :         }
     989                 :            : 
     990         [ #  # ]:          0 :         SdrTextVertAdjustItem aItem( eAdj );
     991                 :            : 
     992         [ #  # ]:          0 :         for( sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++ )
     993                 :            :         {
     994         [ #  # ]:          0 :             for( sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++ )
     995                 :            :             {
     996 [ #  # ][ #  # ]:          0 :                 CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
                 [ #  # ]
     997         [ #  # ]:          0 :                 if( xCell.is() )
     998         [ #  # ]:          0 :                     xCell->SetMergedItem(aItem);
     999                 :          0 :             }
    1000                 :            :         }
    1001                 :            : 
    1002 [ #  # ][ #  # ]:          0 :         UpdateTableShape();
                 [ #  # ]
    1003                 :            :     }
    1004                 :          0 : }
    1005                 :            : 
    1006                 :          0 : void SvxTableController::MergeMarkedCells()
    1007                 :            : {
    1008                 :          0 :     CellPos aStart, aEnd;
    1009         [ #  # ]:          0 :     getSelectedCells( aStart, aEnd );
    1010         [ #  # ]:          0 :     SdrTableObj* pTableObj = dynamic_cast< ::sdr::table::SdrTableObj* >( mxTableObj.get() );
    1011         [ #  # ]:          0 :     if( pTableObj )
    1012                 :            :     {
    1013         [ #  # ]:          0 :         if( pTableObj->IsTextEditActive() )
    1014         [ #  # ]:          0 :             mpView->SdrEndTextEdit(sal_True);
    1015                 :            : 
    1016         [ #  # ]:          0 :         TableModelNotifyGuard aGuard( mxTable.get() );
    1017 [ #  # ][ #  # ]:          0 :         MergeRange( aStart.mnCol, aStart.mnRow, aEnd.mnCol, aEnd.mnRow );
    1018                 :            :     }
    1019                 :          0 : }
    1020                 :            : 
    1021                 :          0 : void SvxTableController::SplitMarkedCells()
    1022                 :            : {
    1023         [ #  # ]:          0 :     if( mxTable.is() )
    1024                 :            :     {
    1025                 :          0 :         CellPos aStart, aEnd;
    1026         [ #  # ]:          0 :         getSelectedCells( aStart, aEnd );
    1027                 :            : 
    1028         [ #  # ]:          0 :         SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
    1029 [ #  # ][ #  # ]:          0 :         std::auto_ptr< SvxAbstractSplittTableDialog > xDlg( pFact ? pFact->CreateSvxSplittTableDialog( NULL, false, 99, 99 ) : 0 );
    1030 [ #  # ][ #  # ]:          0 :         if( xDlg.get() && xDlg->Execute() )
         [ #  # ][ #  # ]
    1031                 :            :         {
    1032         [ #  # ]:          0 :             const sal_Int32 nCount = xDlg->GetCount() - 1;
    1033         [ #  # ]:          0 :             if( nCount < 1 )
    1034                 :          0 :                 return;
    1035                 :            : 
    1036         [ #  # ]:          0 :             getSelectedCells( aStart, aEnd );
    1037                 :            : 
    1038 [ #  # ][ #  # ]:          0 :             Reference< XMergeableCellRange > xRange( mxTable->createCursorByRange( mxTable->getCellRangeByPosition( aStart.mnCol, aStart.mnRow, aEnd.mnCol, aEnd.mnRow ) ), UNO_QUERY_THROW );
                 [ #  # ]
    1039                 :            : 
    1040         [ #  # ]:          0 :             const sal_Int32 nRowCount = mxTable->getRowCount();
    1041         [ #  # ]:          0 :             const sal_Int32 nColCount = mxTable->getColumnCount();
    1042                 :            : 
    1043                 :            : 
    1044         [ #  # ]:          0 :             SdrTableObj* pTableObj = dynamic_cast< SdrTableObj* >( mxTableObj.get() );
    1045         [ #  # ]:          0 :             if( pTableObj )
    1046                 :            :             {
    1047         [ #  # ]:          0 :                 if( pTableObj->IsTextEditActive() )
    1048         [ #  # ]:          0 :                     mpView->SdrEndTextEdit(sal_True);
    1049                 :            : 
    1050         [ #  # ]:          0 :                 TableModelNotifyGuard aGuard( mxTable.get() );
    1051                 :            : 
    1052 [ #  # ][ #  # ]:          0 :                 const bool bUndo = mpModel && mpModel->IsUndoEnabled();
                 [ #  # ]
    1053         [ #  # ]:          0 :                 if( bUndo )
    1054                 :            :                 {
    1055 [ #  # ][ #  # ]:          0 :                     mpModel->BegUndo( ImpGetResStr(STR_TABLE_SPLIT) );
                 [ #  # ]
    1056 [ #  # ][ #  # ]:          0 :                     mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*pTableObj) );
                 [ #  # ]
    1057                 :            :                 }
    1058                 :            : 
    1059 [ #  # ][ #  # ]:          0 :                 if( xDlg->IsHorizontal() )
    1060                 :            :                 {
    1061 [ #  # ][ #  # ]:          0 :                     xRange->split( 0, nCount );
    1062                 :            :                 }
    1063                 :            :                 else
    1064                 :            :                 {
    1065 [ #  # ][ #  # ]:          0 :                     xRange->split( nCount, 0 );
    1066                 :            :                 }
    1067                 :            : 
    1068         [ #  # ]:          0 :                 if( bUndo )
    1069 [ #  # ][ #  # ]:          0 :                     mpModel->EndUndo();
    1070                 :            :             }
    1071         [ #  # ]:          0 :             aEnd.mnRow += mxTable->getRowCount() - nRowCount;
    1072         [ #  # ]:          0 :             aEnd.mnCol += mxTable->getColumnCount() - nColCount;
    1073                 :            : 
    1074         [ #  # ]:          0 :             setSelectedCells( aStart, aEnd );
    1075 [ #  # ][ #  # ]:          0 :         }
    1076                 :            :     }
    1077                 :            : }
    1078                 :            : 
    1079                 :          0 : void SvxTableController::DistributeColumns()
    1080                 :            : {
    1081         [ #  # ]:          0 :     SdrTableObj* pTableObj = dynamic_cast< SdrTableObj* >( mxTableObj.get() );
    1082         [ #  # ]:          0 :     if( pTableObj )
    1083                 :            :     {
    1084 [ #  # ][ #  # ]:          0 :         const bool bUndo = mpModel && mpModel->IsUndoEnabled();
                 [ #  # ]
    1085         [ #  # ]:          0 :         if( bUndo )
    1086                 :            :         {
    1087 [ #  # ][ #  # ]:          0 :             mpModel->BegUndo( ImpGetResStr(STR_TABLE_DISTRIBUTE_COLUMNS) );
                 [ #  # ]
    1088 [ #  # ][ #  # ]:          0 :             mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*pTableObj) );
                 [ #  # ]
    1089                 :            :         }
    1090                 :            : 
    1091                 :          0 :         CellPos aStart, aEnd;
    1092         [ #  # ]:          0 :         getSelectedCells( aStart, aEnd );
    1093         [ #  # ]:          0 :         pTableObj->DistributeColumns( aStart.mnCol, aEnd.mnCol );
    1094                 :            : 
    1095         [ #  # ]:          0 :         if( bUndo )
    1096         [ #  # ]:          0 :             mpModel->EndUndo();
    1097                 :            :     }
    1098                 :          0 : }
    1099                 :            : 
    1100                 :          0 : void SvxTableController::DistributeRows()
    1101                 :            : {
    1102         [ #  # ]:          0 :     SdrTableObj* pTableObj = dynamic_cast< SdrTableObj* >( mxTableObj.get() );
    1103         [ #  # ]:          0 :     if( pTableObj )
    1104                 :            :     {
    1105 [ #  # ][ #  # ]:          0 :         const bool bUndo = mpModel && mpModel->IsUndoEnabled();
                 [ #  # ]
    1106         [ #  # ]:          0 :         if( bUndo )
    1107                 :            :         {
    1108 [ #  # ][ #  # ]:          0 :             mpModel->BegUndo( ImpGetResStr(STR_TABLE_DISTRIBUTE_ROWS) );
                 [ #  # ]
    1109 [ #  # ][ #  # ]:          0 :             mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*pTableObj) );
                 [ #  # ]
    1110                 :            :         }
    1111                 :            : 
    1112                 :          0 :         CellPos aStart, aEnd;
    1113         [ #  # ]:          0 :         getSelectedCells( aStart, aEnd );
    1114         [ #  # ]:          0 :         pTableObj->DistributeRows( aStart.mnRow, aEnd.mnRow );
    1115                 :            : 
    1116         [ #  # ]:          0 :         if( bUndo )
    1117         [ #  # ]:          0 :             mpModel->EndUndo();
    1118                 :            :     }
    1119                 :          0 : }
    1120                 :            : 
    1121                 :          0 : bool SvxTableController::DeleteMarked()
    1122                 :            : {
    1123         [ #  # ]:          0 :     if( mbCellSelectionMode )
    1124                 :            :     {
    1125         [ #  # ]:          0 :         if( mxTable.is() )
    1126                 :            :         {
    1127                 :          0 :             CellPos aStart, aEnd;
    1128         [ #  # ]:          0 :             getSelectedCells( aStart, aEnd );
    1129         [ #  # ]:          0 :             for( sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++ )
    1130                 :            :             {
    1131         [ #  # ]:          0 :                 for( sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++ )
    1132                 :            :                 {
    1133 [ #  # ][ #  # ]:          0 :                     CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
                 [ #  # ]
    1134         [ #  # ]:          0 :                     if( xCell.is() )
    1135         [ #  # ]:          0 :                         xCell->SetOutlinerParaObject( 0 );
    1136                 :          0 :                 }
    1137                 :            :             }
    1138                 :            : 
    1139         [ #  # ]:          0 :             UpdateTableShape();
    1140                 :          0 :             return true;
    1141                 :            :         }
    1142                 :            :     }
    1143                 :            : 
    1144                 :          0 :     return false;
    1145                 :            : }
    1146                 :            : 
    1147                 :          0 : bool SvxTableController::GetStyleSheet( SfxStyleSheet*& rpStyleSheet ) const
    1148                 :            : {
    1149         [ #  # ]:          0 :     if( hasSelectedCells() )
    1150                 :            :     {
    1151                 :          0 :         rpStyleSheet = 0;
    1152                 :            : 
    1153         [ #  # ]:          0 :         if( mxTable.is() )
    1154                 :            :         {
    1155                 :          0 :             SfxStyleSheet* pRet=0;
    1156                 :          0 :             bool b1st=true;
    1157                 :            : 
    1158                 :          0 :             CellPos aStart, aEnd;
    1159         [ #  # ]:          0 :             const_cast<SvxTableController&>(*this).getSelectedCells( aStart, aEnd );
    1160                 :            : 
    1161         [ #  # ]:          0 :             for( sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++ )
    1162                 :            :             {
    1163         [ #  # ]:          0 :                 for( sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++ )
    1164                 :            :                 {
    1165 [ #  # ][ #  # ]:          0 :                     CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
                 [ #  # ]
    1166         [ #  # ]:          0 :                     if( xCell.is() )
    1167                 :            :                     {
    1168         [ #  # ]:          0 :                         SfxStyleSheet* pSS=xCell->GetStyleSheet();
    1169         [ #  # ]:          0 :                         if(b1st)
    1170                 :            :                         {
    1171                 :          0 :                             pRet=pSS;
    1172                 :            :                         }
    1173         [ #  # ]:          0 :                         else if(pRet != pSS)
    1174                 :            :                         {
    1175                 :          0 :                             return true;
    1176                 :            :                         }
    1177                 :          0 :                         b1st=false;
    1178                 :            :                     }
    1179         [ #  # ]:          0 :                 }
    1180                 :            :             }
    1181                 :          0 :             rpStyleSheet = pRet;
    1182                 :          0 :             return true;
    1183                 :            :         }
    1184                 :            :     }
    1185                 :          0 :     return false;
    1186                 :            : }
    1187                 :            : 
    1188                 :          0 : bool SvxTableController::SetStyleSheet( SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr )
    1189                 :            : {
    1190 [ #  # ][ #  # ]:          0 :     if( hasSelectedCells() && (!pStyleSheet || pStyleSheet->GetFamily() == SFX_STYLE_FAMILY_FRAME) )
         [ #  # ][ #  # ]
    1191                 :            :     {
    1192         [ #  # ]:          0 :         if( mxTable.is() )
    1193                 :            :         {
    1194                 :          0 :             CellPos aStart, aEnd;
    1195         [ #  # ]:          0 :             getSelectedCells( aStart, aEnd );
    1196                 :            : 
    1197         [ #  # ]:          0 :             for( sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++ )
    1198                 :            :             {
    1199         [ #  # ]:          0 :                 for( sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++ )
    1200                 :            :                 {
    1201 [ #  # ][ #  # ]:          0 :                     CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
                 [ #  # ]
    1202         [ #  # ]:          0 :                     if( xCell.is() )
    1203         [ #  # ]:          0 :                         xCell->SetStyleSheet(pStyleSheet,bDontRemoveHardAttr);
    1204                 :          0 :                 }
    1205                 :            :             }
    1206                 :            : 
    1207         [ #  # ]:          0 :             UpdateTableShape();
    1208                 :          0 :             return true;
    1209                 :            :         }
    1210                 :            :     }
    1211                 :          0 :     return false;
    1212                 :            : }
    1213                 :            : 
    1214                 :            : // --------------------------------------------------------------------
    1215                 :            : // internals
    1216                 :            : // --------------------------------------------------------------------
    1217                 :            : 
    1218                 :          0 : bool SvxTableController::checkTableObject()
    1219                 :            : {
    1220                 :          0 :     return mxTableObj.is();
    1221                 :            : }
    1222                 :            : 
    1223                 :            : // --------------------------------------------------------------------
    1224                 :            : 
    1225                 :          0 : sal_uInt16 SvxTableController::getKeyboardAction( const KeyEvent& rKEvt, Window* /*pWindow*/ )
    1226                 :            : {
    1227                 :          0 :     const bool bMod1 = rKEvt.GetKeyCode().IsMod1(); // ctrl
    1228                 :          0 :     const bool bMod2 = rKEvt.GetKeyCode().IsMod2() != 0; // Alt
    1229                 :            : 
    1230                 :          0 :     const bool bTextEdit = mpView->IsTextEdit();
    1231                 :            : 
    1232                 :          0 :     sal_uInt16 nAction = ACTION_HANDLED_BY_VIEW;
    1233                 :            : 
    1234         [ #  # ]:          0 :     ::sdr::table::SdrTableObj* pTableObj = dynamic_cast< ::sdr::table::SdrTableObj* >( mxTableObj.get() );
    1235         [ #  # ]:          0 :     if( !pTableObj )
    1236                 :          0 :         return nAction;
    1237                 :            : 
    1238                 :            :     // handle special keys
    1239                 :          0 :     const sal_Int16 nCode = rKEvt.GetKeyCode().GetCode();
    1240   [ #  #  #  #  :          0 :     switch( nCode )
          #  #  #  #  #  
                      # ]
    1241                 :            :     {
    1242                 :            :     case awt::Key::ESCAPE:          // handle escape
    1243                 :            :     {
    1244         [ #  # ]:          0 :         if( bTextEdit )
    1245                 :            :         {
    1246                 :            :             // escape during text edit ends text edit
    1247                 :          0 :             nAction = ACTION_STOP_TEXT_EDIT;
    1248                 :            :         }
    1249         [ #  # ]:          0 :         if( mbCellSelectionMode )
    1250                 :            :         {
    1251                 :            :             // escape with selected cells removes selection
    1252                 :          0 :             nAction = ACTION_REMOVE_SELECTION;
    1253                 :            :         }
    1254                 :          0 :         break;
    1255                 :            :     }
    1256                 :            :     case awt::Key::RETURN:      // handle return
    1257                 :            :     {
    1258 [ #  # ][ #  # ]:          0 :         if( !bMod1 && !bMod2 && !bTextEdit )
                 [ #  # ]
    1259                 :            :         {
    1260                 :            :             // when not already editing, return starts text edit
    1261                 :          0 :             setSelectionStart( pTableObj->getFirstCell() );
    1262                 :          0 :             nAction = ACTION_EDIT_CELL;
    1263                 :            :         }
    1264                 :          0 :         break;
    1265                 :            :     }
    1266                 :            :     case awt::Key::F2:          // f2 toggles text edit
    1267                 :            :     {
    1268 [ #  # ][ #  # ]:          0 :         if( bMod1 || bMod2 )    // f2 with modifiers is handled by the view
    1269                 :            :         {
    1270                 :            :         }
    1271         [ #  # ]:          0 :         else if( bTextEdit )
    1272                 :            :         {
    1273                 :            :             // f2 during text edit stops text edit
    1274                 :          0 :             nAction = ACTION_STOP_TEXT_EDIT;
    1275                 :            :         }
    1276         [ #  # ]:          0 :         else if( mbCellSelectionMode )
    1277                 :            :         {
    1278                 :            :             // f2 with selected cells removes selection
    1279                 :          0 :             nAction = ACTION_REMOVE_SELECTION;
    1280                 :            :         }
    1281                 :            :         else
    1282                 :            :         {
    1283                 :            :             // f2 with no selection and no text edit starts text edit
    1284                 :          0 :             setSelectionStart( pTableObj->getFirstCell() );
    1285                 :          0 :             nAction = ACTION_EDIT_CELL;
    1286                 :            :         }
    1287                 :          0 :         break;
    1288                 :            :     }
    1289                 :            :     case awt::Key::HOME:
    1290                 :            :     case awt::Key::NUM7:
    1291                 :            :     {
    1292 [ #  # ][ #  # ]:          0 :         if( (bMod1 ||  bMod2) && (bTextEdit || mbCellSelectionMode) )
         [ #  # ][ #  # ]
    1293                 :            :         {
    1294 [ #  # ][ #  # ]:          0 :             if( bMod1 && !bMod2 )
    1295                 :            :             {
    1296                 :            :                 // strg + home jumps to first cell
    1297                 :          0 :                 nAction = ACTION_GOTO_FIRST_CELL;
    1298                 :            :             }
    1299 [ #  # ][ #  # ]:          0 :             else if( !bMod1 && bMod2 )
    1300                 :            :             {
    1301                 :            :                 // alt + home jumps to first column
    1302                 :          0 :                 nAction = ACTION_GOTO_FIRST_COLUMN;
    1303                 :            :             }
    1304                 :            :         }
    1305                 :          0 :         break;
    1306                 :            :     }
    1307                 :            :     case awt::Key::END:
    1308                 :            :     case awt::Key::NUM1:
    1309                 :            :     {
    1310 [ #  # ][ #  # ]:          0 :         if( (bMod1 ||  bMod2) && (bTextEdit || mbCellSelectionMode) )
         [ #  # ][ #  # ]
    1311                 :            :         {
    1312 [ #  # ][ #  # ]:          0 :             if( bMod1 && !bMod2 )
    1313                 :            :             {
    1314                 :            :                 // strg + end jumps to last cell
    1315                 :          0 :                 nAction = ACTION_GOTO_LAST_CELL;
    1316                 :            :             }
    1317 [ #  # ][ #  # ]:          0 :             else if( !bMod1 && bMod2 )
    1318                 :            :             {
    1319                 :            :                 // alt + home jumps to last column
    1320                 :          0 :                 nAction = ACTION_GOTO_LAST_COLUMN;
    1321                 :            :             }
    1322                 :            :         }
    1323                 :          0 :         break;
    1324                 :            :     }
    1325                 :            : 
    1326                 :            :     case awt::Key::TAB:
    1327                 :            :     {
    1328 [ #  # ][ #  # ]:          0 :         if( bTextEdit || mbCellSelectionMode )
    1329                 :          0 :             nAction = ACTION_TAB;
    1330                 :          0 :         break;
    1331                 :            :     }
    1332                 :            : 
    1333                 :            :     case awt::Key::UP:
    1334                 :            :     case awt::Key::NUM8:
    1335                 :            :     case awt::Key::DOWN:
    1336                 :            :     case awt::Key::NUM2:
    1337                 :            :     case awt::Key::LEFT:
    1338                 :            :     case awt::Key::NUM4:
    1339                 :            :     case awt::Key::RIGHT:
    1340                 :            :     case awt::Key::NUM6:
    1341                 :            :     {
    1342                 :          0 :         bool bTextMove = false;
    1343                 :            : 
    1344 [ #  # ][ #  # ]:          0 :         if( !bMod1 && bMod2 )
    1345                 :            :         {
    1346 [ #  # ][ #  # ]:          0 :             if( (nCode == awt::Key::UP) || (nCode == awt::Key::NUM8) )
    1347                 :            :             {
    1348                 :          0 :                 nAction = ACTION_GOTO_LEFT_CELL;
    1349                 :            :             }
    1350 [ #  # ][ #  # ]:          0 :             else if( (nCode == awt::Key::DOWN) || (nCode == awt::Key::NUM2) )
    1351                 :            :             {
    1352                 :          0 :                 nAction = ACTION_GOTO_RIGHT_CELL;
    1353                 :            :             }
    1354                 :          0 :             break;
    1355                 :            :         }
    1356                 :            : 
    1357         [ #  # ]:          0 :         if( !bTextMove )
    1358                 :            :         {
    1359                 :          0 :             OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
    1360         [ #  # ]:          0 :             if( pOLV )
    1361                 :            :             {
    1362         [ #  # ]:          0 :                 RemoveSelection();
    1363                 :            :                 // during text edit, check if we navigate out of the cell
    1364         [ #  # ]:          0 :                 ESelection aOldSelection = pOLV->GetSelection();
    1365         [ #  # ]:          0 :                 pOLV->PostKeyEvent(rKEvt);
    1366 [ #  # ][ #  # ]:          0 :                 bTextMove = pOLV && ( aOldSelection.IsEqual(pOLV->GetSelection()) );
         [ #  # ][ #  # ]
                 [ #  # ]
    1367         [ #  # ]:          0 :                 if( !bTextMove )
    1368                 :            :                 {
    1369                 :          0 :                     nAction = ACTION_NONE;
    1370                 :            :                 }
    1371                 :            :             }
    1372                 :            :         }
    1373                 :            : 
    1374 [ #  # ][ #  # ]:          0 :         if( mbCellSelectionMode || bTextMove )
    1375                 :            :         {
    1376                 :            :             // no text edit, navigate in cells if selection active
    1377   [ #  #  #  #  :          0 :             switch( nCode )
                      # ]
    1378                 :            :             {
    1379                 :            :             case awt::Key::LEFT:
    1380                 :            :             case awt::Key::NUM4:
    1381                 :          0 :                 nAction = ACTION_GOTO_LEFT_CELL;
    1382                 :          0 :                 break;
    1383                 :            :             case awt::Key::RIGHT:
    1384                 :            :             case awt::Key::NUM6:
    1385                 :          0 :                 nAction = ACTION_GOTO_RIGHT_CELL;
    1386                 :          0 :                 break;
    1387                 :            :             case awt::Key::DOWN:
    1388                 :            :             case awt::Key::NUM2:
    1389                 :          0 :                 nAction = ACTION_GOTO_DOWN_CELL;
    1390                 :          0 :                 break;
    1391                 :            :             case awt::Key::UP:
    1392                 :            :             case awt::Key::NUM8:
    1393                 :          0 :                 nAction = ACTION_GOTO_UP_CELL;
    1394                 :          0 :                 break;
    1395                 :            :             }
    1396                 :            :         }
    1397                 :          0 :         break;
    1398                 :            :     }
    1399                 :            :     case awt::Key::PAGEUP:
    1400         [ #  # ]:          0 :         if( bMod2 )
    1401                 :          0 :             nAction = ACTION_GOTO_FIRST_ROW;
    1402                 :          0 :         break;
    1403                 :            : 
    1404                 :            :     case awt::Key::PAGEDOWN:
    1405         [ #  # ]:          0 :         if( bMod2 )
    1406                 :          0 :             nAction = ACTION_GOTO_LAST_ROW;
    1407                 :          0 :         break;
    1408                 :            :     }
    1409                 :          0 :     return nAction;
    1410                 :            : }
    1411                 :            : 
    1412                 :          0 : bool SvxTableController::executeAction( sal_uInt16 nAction, bool bSelect, Window* pWindow )
    1413                 :            : {
    1414         [ #  # ]:          0 :     ::sdr::table::SdrTableObj* pTableObj = dynamic_cast< ::sdr::table::SdrTableObj* >( mxTableObj.get() );
    1415         [ #  # ]:          0 :     if( !pTableObj )
    1416                 :          0 :         return false;
    1417                 :            : 
    1418   [ #  #  #  #  :          0 :     switch( nAction )
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1419                 :            :     {
    1420                 :            :     case ACTION_GOTO_FIRST_CELL:
    1421                 :            :     {
    1422         [ #  # ]:          0 :         gotoCell( pTableObj->getFirstCell(), bSelect, pWindow, nAction );
    1423                 :          0 :         break;
    1424                 :            :     }
    1425                 :            : 
    1426                 :            :     case ACTION_GOTO_LEFT_CELL:
    1427                 :            :     {
    1428         [ #  # ]:          0 :         gotoCell( pTableObj->getLeftCell( getSelectionEnd(), !bSelect ), bSelect, pWindow, nAction );
    1429                 :          0 :         break;
    1430                 :            :     }
    1431                 :            : 
    1432                 :            :     case ACTION_GOTO_RIGHT_CELL:
    1433                 :            :     {
    1434         [ #  # ]:          0 :         gotoCell( pTableObj->getRightCell( getSelectionEnd(), !bSelect ), bSelect, pWindow, nAction);
    1435                 :          0 :         break;
    1436                 :            :     }
    1437                 :            : 
    1438                 :            :     case ACTION_GOTO_LAST_CELL:
    1439                 :            :     {
    1440         [ #  # ]:          0 :         gotoCell( pTableObj->getLastCell(), bSelect, pWindow, nAction );
    1441                 :          0 :         break;
    1442                 :            :     }
    1443                 :            : 
    1444                 :            :     case ACTION_GOTO_FIRST_COLUMN:
    1445                 :            :     {
    1446 [ #  # ][ #  # ]:          0 :         CellPos aPos( pTableObj->getFirstCell().mnCol, getSelectionEnd().mnRow );
    1447         [ #  # ]:          0 :         gotoCell( aPos, bSelect, pWindow, nAction );
    1448                 :            :         break;
    1449                 :            :     }
    1450                 :            : 
    1451                 :            :     case ACTION_GOTO_LAST_COLUMN:
    1452                 :            :     {
    1453 [ #  # ][ #  # ]:          0 :         CellPos aPos( pTableObj->getLastCell().mnCol, getSelectionEnd().mnRow );
    1454         [ #  # ]:          0 :         gotoCell( aPos, bSelect, pWindow, nAction );
    1455                 :            :         break;
    1456                 :            :     }
    1457                 :            : 
    1458                 :            :     case ACTION_GOTO_FIRST_ROW:
    1459                 :            :     {
    1460 [ #  # ][ #  # ]:          0 :         CellPos aPos( getSelectionEnd().mnCol, pTableObj->getFirstCell().mnRow );
    1461         [ #  # ]:          0 :         gotoCell( aPos, bSelect, pWindow, nAction );
    1462                 :            :         break;
    1463                 :            :     }
    1464                 :            : 
    1465                 :            :     case ACTION_GOTO_UP_CELL:
    1466                 :            :     {
    1467         [ #  # ]:          0 :         gotoCell( pTableObj->getUpCell(getSelectionEnd(), !bSelect), bSelect, pWindow, nAction );
    1468                 :          0 :         break;
    1469                 :            :     }
    1470                 :            : 
    1471                 :            :     case ACTION_GOTO_DOWN_CELL:
    1472                 :            :     {
    1473         [ #  # ]:          0 :         gotoCell( pTableObj->getDownCell(getSelectionEnd(), !bSelect), bSelect, pWindow, nAction );
    1474                 :          0 :         break;
    1475                 :            :     }
    1476                 :            : 
    1477                 :            :     case ACTION_GOTO_LAST_ROW:
    1478                 :            :     {
    1479 [ #  # ][ #  # ]:          0 :         CellPos aPos( getSelectionEnd().mnCol, pTableObj->getLastCell().mnRow );
    1480         [ #  # ]:          0 :         gotoCell( aPos, bSelect, pWindow, nAction );
    1481                 :            :         break;
    1482                 :            :     }
    1483                 :            : 
    1484                 :            :     case ACTION_EDIT_CELL:
    1485                 :          0 :         EditCell( getSelectionStart(), pWindow, 0, nAction );
    1486                 :          0 :         break;
    1487                 :            : 
    1488                 :            :     case ACTION_STOP_TEXT_EDIT:
    1489                 :          0 :         StopTextEdit();
    1490                 :          0 :         break;
    1491                 :            : 
    1492                 :            :     case ACTION_REMOVE_SELECTION:
    1493                 :          0 :         RemoveSelection();
    1494                 :          0 :         break;
    1495                 :            : 
    1496                 :            :     case ACTION_START_SELECTION:
    1497                 :          0 :         StartSelection( getSelectionStart() );
    1498                 :          0 :         break;
    1499                 :            : 
    1500                 :            :     case ACTION_TAB:
    1501                 :            :     {
    1502         [ #  # ]:          0 :         if( bSelect )
    1503         [ #  # ]:          0 :             gotoCell( pTableObj->getPreviousCell( getSelectionEnd(), true ), false, pWindow, nAction );
    1504                 :            :         else
    1505                 :            :         {
    1506         [ #  # ]:          0 :             CellPos aSelectionEnd( getSelectionEnd() );
    1507         [ #  # ]:          0 :             CellPos aNextCell( pTableObj->getNextCell( aSelectionEnd, true ) );
    1508         [ #  # ]:          0 :             if( aSelectionEnd == aNextCell )
    1509                 :            :             {
    1510         [ #  # ]:          0 :                 onInsert( SID_TABLE_INSERT_ROW, 0 );
    1511         [ #  # ]:          0 :                 aNextCell = pTableObj->getNextCell( aSelectionEnd, true );
    1512                 :            :             }
    1513         [ #  # ]:          0 :             gotoCell( aNextCell, false, pWindow, nAction );
    1514                 :            :         }
    1515                 :          0 :         break;
    1516                 :            :     }
    1517                 :            :     }
    1518                 :            : 
    1519                 :          0 :     return nAction != ACTION_HANDLED_BY_VIEW;
    1520                 :            : }
    1521                 :            : 
    1522                 :            : // --------------------------------------------------------------------
    1523                 :            : 
    1524                 :          0 : void SvxTableController::gotoCell( const CellPos& rPos, bool bSelect, Window* pWindow, sal_uInt16 nAction )
    1525                 :            : {
    1526 [ #  # ][ #  # ]:          0 :     if( mxTableObj.is() && static_cast<SdrTableObj*>(mxTableObj.get())->IsTextEditActive() )
                 [ #  # ]
    1527                 :          0 :         mpView->SdrEndTextEdit(sal_True);
    1528                 :            : 
    1529         [ #  # ]:          0 :     if( bSelect )
    1530                 :            :     {
    1531                 :          0 :         maCursorLastPos = rPos;
    1532         [ #  # ]:          0 :         if( mxTableObj.is() )
    1533                 :          0 :             static_cast< SdrTableObj* >( mxTableObj.get() )->setActiveCell( rPos );
    1534                 :            : 
    1535         [ #  # ]:          0 :         if( !mbCellSelectionMode )
    1536                 :            :         {
    1537                 :          0 :             setSelectedCells( maCursorFirstPos, rPos );
    1538                 :            :         }
    1539                 :            :         else
    1540                 :            :         {
    1541                 :          0 :             UpdateSelection( rPos );
    1542                 :            :         }
    1543                 :            :     }
    1544                 :            :     else
    1545                 :            :     {
    1546                 :          0 :         RemoveSelection();
    1547                 :          0 :         EditCell( rPos, pWindow, 0, nAction );
    1548                 :            :     }
    1549                 :          0 : }
    1550                 :            : 
    1551                 :            : // --------------------------------------------------------------------
    1552                 :            : 
    1553                 :          0 : const CellPos& SvxTableController::getSelectionStart()
    1554                 :            : {
    1555                 :          0 :     checkCell( maCursorFirstPos );
    1556                 :          0 :     return maCursorFirstPos;
    1557                 :            : }
    1558                 :            : 
    1559                 :            : // --------------------------------------------------------------------
    1560                 :            : 
    1561                 :          0 : void SvxTableController::setSelectionStart( const CellPos& rPos )
    1562                 :            : {
    1563                 :          0 :     maCursorFirstPos = rPos;
    1564                 :          0 : }
    1565                 :            : 
    1566                 :            : // --------------------------------------------------------------------
    1567                 :            : 
    1568                 :          0 : const CellPos& SvxTableController::getSelectionEnd()
    1569                 :            : {
    1570                 :          0 :     checkCell( maCursorLastPos );
    1571                 :          0 :     return maCursorLastPos;
    1572                 :            : }
    1573                 :            : 
    1574                 :            : // --------------------------------------------------------------------
    1575                 :            : 
    1576                 :          0 : void SvxTableController::MergeRange( sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow )
    1577                 :            : {
    1578         [ #  # ]:          0 :     if( mxTable.is() ) try
    1579                 :            :     {
    1580 [ #  # ][ #  # ]:          0 :         Reference< XMergeableCellRange > xRange( mxTable->createCursorByRange( mxTable->getCellRangeByPosition( nFirstCol, nFirstRow,nLastCol, nLastRow ) ), UNO_QUERY_THROW );
                 [ #  # ]
    1581 [ #  # ][ #  # ]:          0 :         if( xRange->isMergeable() )
                 [ #  # ]
    1582                 :            :         {
    1583 [ #  # ][ #  # ]:          0 :             const bool bUndo = mpModel && mpModel->IsUndoEnabled();
                 [ #  # ]
    1584         [ #  # ]:          0 :             if( bUndo )
    1585                 :            :             {
    1586 [ #  # ][ #  # ]:          0 :                 mpModel->BegUndo( ImpGetResStr(STR_TABLE_MERGE) );
                 [ #  # ]
    1587 [ #  # ][ #  # ]:          0 :                 mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*mxTableObj.get()) );
                 [ #  # ]
    1588                 :            :             }
    1589                 :            : 
    1590 [ #  # ][ #  # ]:          0 :             xRange->merge();
    1591                 :            : 
    1592         [ #  # ]:          0 :             if( bUndo )
    1593         [ #  # ]:          0 :                 mpModel->EndUndo();
    1594         [ #  # ]:          0 :         }
    1595                 :            :     }
    1596                 :          0 :     catch( Exception& )
    1597                 :            :     {
    1598                 :            :         DBG_ASSERT( false, "sdr::table::SvxTableController::MergeRange(), exception caught!" );
    1599                 :            :     }
    1600                 :          0 : }
    1601                 :            : 
    1602                 :            : 
    1603                 :            : 
    1604                 :            : // --------------------------------------------------------------------
    1605                 :            : 
    1606                 :          0 : void SvxTableController::checkCell( CellPos& rPos )
    1607                 :            : {
    1608         [ #  # ]:          0 :     if( mxTable.is() ) try
    1609                 :            :     {
    1610 [ #  # ][ #  # ]:          0 :         if( rPos.mnCol >= mxTable->getColumnCount() )
    1611         [ #  # ]:          0 :             rPos.mnCol = mxTable->getColumnCount()-1;
    1612                 :            : 
    1613 [ #  # ][ #  # ]:          0 :         if( rPos.mnRow >= mxTable->getRowCount() )
    1614         [ #  # ]:          0 :             rPos.mnRow = mxTable->getRowCount()-1;
    1615                 :            :     }
    1616                 :          0 :     catch( Exception& )
    1617                 :            :     {
    1618                 :            :         OSL_FAIL("sdr::table::SvxTableController::checkCell(), exception caught!" );
    1619                 :            :     }
    1620         [ #  # ]:          0 : }
    1621                 :            : 
    1622                 :            : // --------------------------------------------------------------------
    1623                 :            : 
    1624                 :          0 : void SvxTableController::findMergeOrigin( CellPos& rPos )
    1625                 :            : {
    1626         [ #  # ]:          0 :     if( mxTable.is() ) try
    1627                 :            :     {
    1628 [ #  # ][ #  # ]:          0 :         Reference< XMergeableCell > xCell( mxTable->getCellByPosition( rPos.mnCol, rPos.mnRow ), UNO_QUERY_THROW );
    1629 [ #  # ][ #  # ]:          0 :         if( xCell.is() && xCell->isMerged() )
         [ #  # ][ #  # ]
                 [ #  # ]
    1630                 :            :         {
    1631         [ #  # ]:          0 :             ::findMergeOrigin( mxTable, rPos.mnCol, rPos.mnRow, rPos.mnCol, rPos.mnRow );
    1632         [ #  # ]:          0 :         }
    1633                 :            :     }
    1634                 :          0 :     catch( Exception& )
    1635                 :            :     {
    1636                 :            :         OSL_FAIL("sdr::table::SvxTableController::findMergeOrigin(), exception caught!" );
    1637                 :            :     }
    1638                 :          0 : }
    1639                 :            : 
    1640                 :            : // --------------------------------------------------------------------
    1641                 :            : 
    1642                 :          0 : void SvxTableController::EditCell( const CellPos& rPos, ::Window* pWindow, const awt::MouseEvent* pMouseEvent /*= 0*/, sal_uInt16 nAction /*= ACTION_NONE */ )
    1643                 :            : {
    1644                 :          0 :     SdrPageView* pPV = mpView->GetSdrPageView();
    1645                 :            : 
    1646         [ #  # ]:          0 :     ::sdr::table::SdrTableObj* pTableObj = dynamic_cast< ::sdr::table::SdrTableObj* >( mxTableObj.get() );
    1647 [ #  # ][ #  # ]:          0 :     if( pTableObj && pTableObj->GetPage() == pPV->GetPage() )
                 [ #  # ]
    1648                 :            :     {
    1649                 :          0 :         bool bEmptyOutliner = false;
    1650                 :            : 
    1651 [ #  # ][ #  # ]:          0 :         if(!pTableObj->GetOutlinerParaObject() && mpView->GetTextEditOutliner())
         [ #  # ][ #  # ]
    1652                 :            :         {
    1653                 :          0 :             ::Outliner* pOutl = mpView->GetTextEditOutliner();
    1654         [ #  # ]:          0 :             sal_uIntPtr nParaAnz = pOutl->GetParagraphCount();
    1655         [ #  # ]:          0 :             Paragraph* p1stPara = pOutl->GetParagraph( 0 );
    1656                 :            : 
    1657 [ #  # ][ #  # ]:          0 :             if(nParaAnz==1 && p1stPara)
    1658                 :            :             {
    1659                 :            :                 // Bei nur einem Pararaph
    1660 [ #  # ][ #  # ]:          0 :                 if (pOutl->GetText(p1stPara).Len() == 0)
                 [ #  # ]
    1661                 :            :                 {
    1662                 :          0 :                     bEmptyOutliner = true;
    1663                 :            :                 }
    1664                 :            :             }
    1665                 :            :         }
    1666                 :            : 
    1667                 :          0 :         CellPos aPos( rPos );
    1668         [ #  # ]:          0 :         findMergeOrigin( aPos );
    1669                 :            : 
    1670 [ #  # ][ #  # ]:          0 :         if( pTableObj != mpView->GetTextEditObject() || bEmptyOutliner || !pTableObj->IsTextEditActive( aPos ) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1671                 :            :         {
    1672         [ #  # ]:          0 :             if( pTableObj->IsTextEditActive() )
    1673         [ #  # ]:          0 :                 mpView->SdrEndTextEdit(sal_True);
    1674                 :            : 
    1675         [ #  # ]:          0 :             pTableObj->setActiveCell( aPos );
    1676                 :            : 
    1677                 :            :             // create new outliner, owner will be the SdrObjEditView
    1678         [ #  # ]:          0 :             SdrOutliner* pOutl = SdrMakeOutliner( OUTLINERMODE_OUTLINEOBJECT, mpModel );
    1679 [ #  # ][ #  # ]:          0 :             if( pTableObj->IsVerticalWriting() )
    1680         [ #  # ]:          0 :                 pOutl->SetVertical( sal_True );
    1681                 :            : 
    1682 [ #  # ][ #  # ]:          0 :             if(mpView->SdrBeginTextEdit(pTableObj, pPV, pWindow, sal_True, pOutl))
    1683                 :            :             {
    1684                 :          0 :                 maCursorLastPos = maCursorFirstPos = rPos;
    1685                 :            : 
    1686                 :          0 :                 OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
    1687                 :            : 
    1688                 :          0 :                 bool bNoSel = true;
    1689                 :            : 
    1690         [ #  # ]:          0 :                 if( pMouseEvent )
    1691                 :            :                 {
    1692         [ #  # ]:          0 :                     ::MouseEvent aMEvt( *pMouseEvent );
    1693                 :            : 
    1694         [ #  # ]:          0 :                     SdrViewEvent aVEvt;
    1695         [ #  # ]:          0 :                     SdrHitKind eHit = mpView->PickAnything(aMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
    1696                 :            : 
    1697         [ #  # ]:          0 :                     if (eHit == SDRHIT_TEXTEDIT)
    1698                 :            :                     {
    1699                 :            :                         // Text getroffen
    1700         [ #  # ]:          0 :                         pOLV->MouseButtonDown(aMEvt);
    1701         [ #  # ]:          0 :                         pOLV->MouseMove(aMEvt);
    1702         [ #  # ]:          0 :                         pOLV->MouseButtonUp(aMEvt);
    1703                 :            : //                      pOLV->MouseButtonDown(aMEvt);
    1704                 :          0 :                         bNoSel = false;
    1705                 :            :                     }
    1706                 :            :                     else
    1707                 :            :                     {
    1708                 :          0 :                         nAction = ACTION_GOTO_LEFT_CELL;
    1709         [ #  # ]:          0 :                     }
    1710                 :            :                 }
    1711                 :            : 
    1712         [ #  # ]:          0 :                 if( bNoSel )
    1713                 :            :                 {
    1714                 :            :                     // Move cursor to end of text
    1715                 :          0 :                     ESelection aNewSelection;
    1716                 :            : 
    1717         [ #  # ]:          0 :                     const WritingMode eMode = pTableObj->GetWritingMode();
    1718 [ #  # ][ #  # ]:          0 :                     if( ((nAction == ACTION_GOTO_LEFT_CELL) || (nAction == ACTION_GOTO_RIGHT_CELL)) && (eMode != WritingMode_TB_RL) )
                 [ #  # ]
    1719                 :            :                     {
    1720                 :            :                         const bool bLast = ((nAction == ACTION_GOTO_LEFT_CELL) && (eMode == WritingMode_LR_TB)) ||
    1721 [ #  # ][ #  # ]:          0 :                                              ((nAction == ACTION_GOTO_RIGHT_CELL) && (eMode == WritingMode_RL_TB));
         [ #  # ][ #  # ]
    1722                 :            : 
    1723         [ #  # ]:          0 :                         if( bLast )
    1724                 :          0 :                             aNewSelection = ESelection(EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND, EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND);
    1725                 :            :                     }
    1726         [ #  # ]:          0 :                     pOLV->SetSelection(aNewSelection);
    1727                 :            :                 }
    1728                 :            :             }
    1729                 :            :         }
    1730                 :            :     }
    1731                 :          0 : }
    1732                 :            : 
    1733                 :            : // --------------------------------------------------------------------
    1734                 :            : 
    1735                 :          0 : bool SvxTableController::StopTextEdit()
    1736                 :            : {
    1737         [ #  # ]:          0 :     if(mpView->IsTextEdit())
    1738                 :            :     {
    1739                 :          0 :         mpView->SdrEndTextEdit();
    1740                 :          0 :         mpView->SetCurrentObj(OBJ_TABLE);
    1741                 :          0 :         mpView->SetEditMode(SDREDITMODE_EDIT);
    1742                 :          0 :         return true;
    1743                 :            :     }
    1744                 :            :     else
    1745                 :            :     {
    1746                 :          0 :         return false;
    1747                 :            :     }
    1748                 :            : }
    1749                 :            : 
    1750                 :            : // --------------------------------------------------------------------
    1751                 :            : 
    1752                 :          0 : void SvxTableController::getSelectedCells( CellPos& rFirst, CellPos& rLast )
    1753                 :            : {
    1754         [ #  # ]:          0 :     if( mbCellSelectionMode )
    1755                 :            :     {
    1756                 :          0 :         checkCell( maCursorFirstPos );
    1757                 :          0 :         checkCell( maCursorLastPos );
    1758                 :            : 
    1759                 :          0 :         rFirst.mnCol = std::min( maCursorFirstPos.mnCol, maCursorLastPos.mnCol );
    1760                 :          0 :         rFirst.mnRow = std::min( maCursorFirstPos.mnRow, maCursorLastPos.mnRow );
    1761                 :          0 :         rLast.mnCol = std::max( maCursorFirstPos.mnCol, maCursorLastPos.mnCol );
    1762                 :          0 :         rLast.mnRow = std::max( maCursorFirstPos.mnRow, maCursorLastPos.mnRow );
    1763                 :            : 
    1764                 :          0 :         bool bExt = false;
    1765 [ #  # ][ #  # ]:          0 :         if( mxTable.is() ) do
    1766                 :            :         {
    1767                 :          0 :             bExt = false;
    1768 [ #  # ][ #  # ]:          0 :             for( sal_Int32 nRow = rFirst.mnRow; nRow <= rLast.mnRow && !bExt; nRow++ )
                 [ #  # ]
    1769                 :            :             {
    1770 [ #  # ][ #  # ]:          0 :                 for( sal_Int32 nCol = rFirst.mnCol; nCol <= rLast.mnCol && !bExt; nCol++ )
                 [ #  # ]
    1771                 :            :                 {
    1772 [ #  # ][ #  # ]:          0 :                     Reference< XMergeableCell > xCell( mxTable->getCellByPosition( nCol, nRow ), UNO_QUERY );
    1773         [ #  # ]:          0 :                     if( !xCell.is() )
    1774                 :          0 :                         continue;
    1775                 :            : 
    1776 [ #  # ][ #  # ]:          0 :                     if( xCell->isMerged() )
                 [ #  # ]
    1777                 :            :                     {
    1778                 :          0 :                         CellPos aPos( nCol, nRow );
    1779         [ #  # ]:          0 :                         findMergeOrigin( aPos );
    1780 [ #  # ][ #  # ]:          0 :                         if( (aPos.mnCol < rFirst.mnCol) || (aPos.mnRow < rFirst.mnRow) )
    1781                 :            :                         {
    1782         [ #  # ]:          0 :                             rFirst.mnCol = std::min( rFirst.mnCol, aPos.mnCol );
    1783         [ #  # ]:          0 :                             rFirst.mnRow = std::min( rFirst.mnRow, aPos.mnRow );
    1784                 :          0 :                             bExt = true;
    1785                 :            :                         }
    1786                 :            :                     }
    1787                 :            :                     else
    1788                 :            :                     {
    1789 [ #  # ][ #  # ]:          0 :                         if( ((nCol + xCell->getColumnSpan() - 1) > rLast.mnCol) || (nRow + xCell->getRowSpan() - 1 ) > rLast.mnRow )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1790                 :            :                         {
    1791 [ #  # ][ #  # ]:          0 :                             rLast.mnCol = std::max( rLast.mnCol, nCol + xCell->getColumnSpan() - 1 );
                 [ #  # ]
    1792 [ #  # ][ #  # ]:          0 :                             rLast.mnRow = std::max( rLast.mnRow, nRow + xCell->getRowSpan() - 1 );
                 [ #  # ]
    1793                 :          0 :                             bExt = true;
    1794                 :            :                         }
    1795                 :            :                     }
    1796         [ #  # ]:          0 :                 }
    1797                 :            :             }
    1798                 :            :         }
    1799                 :            :         while(bExt);
    1800                 :            :     }
    1801 [ #  # ][ #  # ]:          0 :     else if( mpView && mpView->IsTextEdit() )
                 [ #  # ]
    1802                 :            :     {
    1803                 :          0 :         rFirst = getSelectionStart();
    1804                 :          0 :         findMergeOrigin( rFirst );
    1805                 :          0 :         rLast = rFirst;
    1806                 :            : 
    1807         [ #  # ]:          0 :         if( mxTable.is() )
    1808                 :            :         {
    1809 [ #  # ][ #  # ]:          0 :             Reference< XMergeableCell > xCell( mxTable->getCellByPosition( rLast.mnCol, rLast.mnRow ), UNO_QUERY );
    1810         [ #  # ]:          0 :             if( xCell.is() )
    1811                 :            :             {
    1812 [ #  # ][ #  # ]:          0 :                 rLast.mnCol += xCell->getColumnSpan() - 1;
    1813 [ #  # ][ #  # ]:          0 :                 rLast.mnRow += xCell->getRowSpan() - 1;
    1814                 :          0 :             }
    1815                 :            :         }
    1816                 :            :     }
    1817                 :            :     else
    1818                 :            :     {
    1819                 :          0 :         rFirst.mnCol = 0;
    1820                 :          0 :         rFirst.mnRow = 0;
    1821         [ #  # ]:          0 :         if( mxTable.is() )
    1822                 :            :         {
    1823                 :          0 :             rLast.mnRow = mxTable->getRowCount()-1;
    1824                 :          0 :             rLast.mnCol = mxTable->getColumnCount()-1;
    1825                 :            :         }
    1826                 :            :         else
    1827                 :            :         {
    1828                 :          0 :             rLast.mnRow = 0;
    1829                 :          0 :             rLast.mnCol = 0;
    1830                 :            :         }
    1831                 :            :     }
    1832                 :          0 : }
    1833                 :            : 
    1834                 :            : // --------------------------------------------------------------------
    1835                 :            : 
    1836                 :          0 : void SvxTableController::StartSelection( const CellPos& rPos )
    1837                 :            : {
    1838                 :          0 :     StopTextEdit();
    1839                 :          0 :     mbCellSelectionMode = true;
    1840                 :          0 :     maCursorLastPos = maCursorFirstPos = rPos;
    1841                 :          0 :     mpView->MarkListHasChanged();
    1842                 :          0 : }
    1843                 :            : 
    1844                 :            : // --------------------------------------------------------------------
    1845                 :            : 
    1846                 :          0 : void SvxTableController::setSelectedCells( const CellPos& rStart, const CellPos& rEnd )
    1847                 :            : {
    1848                 :          0 :     StopTextEdit();
    1849                 :          0 :     mbCellSelectionMode = true;
    1850                 :          0 :     maCursorFirstPos = rStart;
    1851                 :          0 :     UpdateSelection( rEnd );
    1852                 :          0 : }
    1853                 :            : 
    1854                 :            : // --------------------------------------------------------------------
    1855                 :            : 
    1856                 :          0 : void SvxTableController::UpdateSelection( const CellPos& rPos )
    1857                 :            : {
    1858                 :          0 :     maCursorLastPos = rPos;
    1859                 :          0 :     mpView->MarkListHasChanged();
    1860                 :          0 : }
    1861                 :            : 
    1862                 :            : // --------------------------------------------------------------------
    1863                 :            : 
    1864                 :          0 : void SvxTableController::clearSelection()
    1865                 :            : {
    1866                 :          0 :     RemoveSelection();
    1867                 :          0 : }
    1868                 :            : 
    1869                 :            : // --------------------------------------------------------------------
    1870                 :            : 
    1871                 :          0 : void SvxTableController::selectAll()
    1872                 :            : {
    1873         [ #  # ]:          0 :     if( mxTable.is() )
    1874                 :            :     {
    1875 [ #  # ][ #  # ]:          0 :         CellPos aPos1, aPos2( mxTable->getColumnCount()-1, mxTable->getRowCount()-1 );
    1876 [ #  # ][ #  # ]:          0 :         if( (aPos2.mnCol >= 0) && (aPos2.mnRow >= 0) )
    1877                 :            :         {
    1878         [ #  # ]:          0 :             setSelectedCells( aPos1, aPos2 );
    1879                 :            :         }
    1880                 :            :     }
    1881                 :          0 : }
    1882                 :            : 
    1883                 :            : // --------------------------------------------------------------------
    1884                 :            : 
    1885                 :          0 : void SvxTableController::RemoveSelection()
    1886                 :            : {
    1887         [ #  # ]:          0 :     if( mbCellSelectionMode )
    1888                 :            :     {
    1889                 :          0 :         mbCellSelectionMode = false;
    1890                 :          0 :         mpView->MarkListHasChanged();
    1891                 :            :     }
    1892                 :          0 : }
    1893                 :            : 
    1894                 :            : // --------------------------------------------------------------------
    1895                 :            : 
    1896                 :          0 : void SvxTableController::onTableModified()
    1897                 :            : {
    1898         [ #  # ]:          0 :     if( mnUpdateEvent == 0 )
    1899         [ #  # ]:          0 :         mnUpdateEvent = Application::PostUserEvent( LINK( this, SvxTableController, UpdateHdl ) );
    1900                 :          0 : }
    1901                 :            : // --------------------------------------------------------------------
    1902                 :            : 
    1903                 :          0 : void SvxTableController::updateSelectionOverlay()
    1904                 :            : {
    1905                 :          0 :     destroySelectionOverlay();
    1906         [ #  # ]:          0 :     if( mbCellSelectionMode )
    1907                 :            :     {
    1908         [ #  # ]:          0 :         ::sdr::table::SdrTableObj* pTableObj = dynamic_cast< ::sdr::table::SdrTableObj* >( mxTableObj.get() );
    1909         [ #  # ]:          0 :         if( pTableObj )
    1910                 :            :         {
    1911         [ #  # ]:          0 :             sdr::overlay::OverlayObjectCell::RangeVector aRanges;
    1912                 :            : 
    1913         [ #  # ]:          0 :             Rectangle aRect;
    1914                 :          0 :             CellPos aStart,aEnd;
    1915         [ #  # ]:          0 :             getSelectedCells( aStart, aEnd );
    1916         [ #  # ]:          0 :             pTableObj->getCellBounds( aStart, aRect );
    1917                 :            : 
    1918         [ #  # ]:          0 :             basegfx::B2DRange a2DRange( basegfx::B2DPoint(aRect.Left(), aRect.Top()) );
    1919         [ #  # ]:          0 :             a2DRange.expand( basegfx::B2DPoint(aRect.Right(), aRect.Bottom()) );
    1920                 :            : 
    1921         [ #  # ]:          0 :             findMergeOrigin( aEnd );
    1922         [ #  # ]:          0 :             pTableObj->getCellBounds( aEnd, aRect );
    1923         [ #  # ]:          0 :             a2DRange.expand( basegfx::B2DPoint(aRect.Left(), aRect.Top()) );
    1924         [ #  # ]:          0 :             a2DRange.expand( basegfx::B2DPoint(aRect.Right(), aRect.Bottom()) );
    1925         [ #  # ]:          0 :             aRanges.push_back( a2DRange );
    1926                 :            : 
    1927                 :          0 :             ::Color aHighlight( COL_BLUE );
    1928         [ #  # ]:          0 :             OutputDevice* pOutDev = mpView->GetFirstOutputDevice();
    1929         [ #  # ]:          0 :             if( pOutDev )
    1930                 :          0 :                 aHighlight = pOutDev->GetSettings().GetStyleSettings().GetHighlightColor();
    1931                 :            : 
    1932                 :          0 :             const sal_uInt32 nCount = mpView->PaintWindowCount();
    1933         [ #  # ]:          0 :             for( sal_uInt32 nIndex = 0; nIndex < nCount; nIndex++ )
    1934                 :            :             {
    1935         [ #  # ]:          0 :                 SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow(nIndex);
    1936         [ #  # ]:          0 :                 if( pPaintWindow )
    1937                 :            :                 {
    1938         [ #  # ]:          0 :                     rtl::Reference < ::sdr::overlay::OverlayManager > xOverlayManager = pPaintWindow->GetOverlayManager();
    1939         [ #  # ]:          0 :                     if( xOverlayManager.is() )
    1940                 :            :                     {
    1941                 :            :                         // sdr::overlay::CellOverlayType eType = sdr::overlay::CELL_OVERLAY_INVERT;
    1942                 :          0 :                         sdr::overlay::CellOverlayType eType = sdr::overlay::CELL_OVERLAY_TRANSPARENT;
    1943                 :            : 
    1944 [ #  # ][ #  # ]:          0 :                         sdr::overlay::OverlayObjectCell* pOverlay = new sdr::overlay::OverlayObjectCell( eType, aHighlight, aRanges );
    1945                 :            : 
    1946         [ #  # ]:          0 :                         xOverlayManager->add(*pOverlay);
    1947 [ #  # ][ #  # ]:          0 :                         mpSelectionOverlay = new ::sdr::overlay::OverlayObjectList;
    1948         [ #  # ]:          0 :                         mpSelectionOverlay->append(*pOverlay);
    1949         [ #  # ]:          0 :                     }
    1950                 :            :                 }
    1951                 :          0 :             }
    1952                 :            :         }
    1953                 :            :     }
    1954                 :          0 : }
    1955                 :            : 
    1956                 :            : // --------------------------------------------------------------------
    1957                 :            : 
    1958                 :          0 : void SvxTableController::destroySelectionOverlay()
    1959                 :            : {
    1960         [ #  # ]:          0 :     if( mpSelectionOverlay )
    1961                 :            :     {
    1962         [ #  # ]:          0 :         delete mpSelectionOverlay;
    1963                 :          0 :         mpSelectionOverlay = 0;
    1964                 :            :     }
    1965                 :          0 : }
    1966                 :            : 
    1967                 :            : // --------------------------------------------------------------------
    1968                 :            : 
    1969                 :          0 : void SvxTableController::MergeAttrFromSelectedCells(SfxItemSet& rAttr, bool bOnlyHardAttr) const
    1970                 :            : {
    1971         [ #  # ]:          0 :     if( mxTable.is() )
    1972                 :            :     {
    1973                 :          0 :         CellPos aStart, aEnd;
    1974         [ #  # ]:          0 :         const_cast<SvxTableController&>(*this).getSelectedCells( aStart, aEnd );
    1975                 :            : 
    1976         [ #  # ]:          0 :         for( sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++ )
    1977                 :            :         {
    1978         [ #  # ]:          0 :             for( sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++ )
    1979                 :            :             {
    1980 [ #  # ][ #  # ]:          0 :                 CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
                 [ #  # ]
    1981 [ #  # ][ #  # ]:          0 :                 if( xCell.is() && !xCell->isMerged() )
         [ #  # ][ #  # ]
    1982                 :            :                 {
    1983         [ #  # ]:          0 :                     const SfxItemSet& rSet = xCell->GetItemSet();
    1984         [ #  # ]:          0 :                     SfxWhichIter aIter(rSet);
    1985         [ #  # ]:          0 :                     sal_uInt16 nWhich(aIter.FirstWhich());
    1986         [ #  # ]:          0 :                     while(nWhich)
    1987                 :            :                     {
    1988         [ #  # ]:          0 :                         if(!bOnlyHardAttr)
    1989                 :            :                         {
    1990 [ #  # ][ #  # ]:          0 :                             if(SFX_ITEM_DONTCARE == rSet.GetItemState(nWhich, sal_False))
    1991         [ #  # ]:          0 :                                 rAttr.InvalidateItem(nWhich);
    1992                 :            :                             else
    1993 [ #  # ][ #  # ]:          0 :                                 rAttr.MergeValue(rSet.Get(nWhich), sal_True);
    1994                 :            :                         }
    1995 [ #  # ][ #  # ]:          0 :                         else if(SFX_ITEM_SET == rSet.GetItemState(nWhich, sal_False))
    1996                 :            :                         {
    1997         [ #  # ]:          0 :                             const SfxPoolItem& rItem = rSet.Get(nWhich);
    1998         [ #  # ]:          0 :                             rAttr.MergeValue(rItem, sal_True);
    1999                 :            :                         }
    2000                 :            : 
    2001         [ #  # ]:          0 :                         nWhich = aIter.NextWhich();
    2002         [ #  # ]:          0 :                     }
    2003                 :            :                 }
    2004                 :          0 :             }
    2005                 :            :         }
    2006                 :            :     }
    2007                 :            : 
    2008                 :          0 :     if( mpView->IsTextEdit() )
    2009                 :            :     {
    2010                 :            :     }
    2011                 :          0 : }
    2012                 :            : 
    2013                 :            : // --------------------------------------------------------------------
    2014                 :            : 
    2015                 :            : const sal_uInt16 CELL_BEFORE = 0x0001;
    2016                 :            : const sal_uInt16 CELL_LEFT   = 0x0002;
    2017                 :            : const sal_uInt16 CELL_RIGHT  = 0x0004;
    2018                 :            : const sal_uInt16 CELL_AFTER  = 0x0008;
    2019                 :            : 
    2020                 :            : const sal_uInt16 CELL_UPPER  = 0x0010;
    2021                 :            : const sal_uInt16 CELL_TOP    = 0x0020;
    2022                 :            : const sal_uInt16 CELL_BOTTOM = 0x0040;
    2023                 :            : const sal_uInt16 CELL_LOWER  = 0x0080;
    2024                 :            : 
    2025                 :            : // --------------------------------------------------------------------
    2026                 :            : 
    2027                 :          0 : static void ImplSetLinePreserveColor( SvxBoxItem& rNewFrame, const SvxBorderLine* pNew, sal_uInt16 nLine )
    2028                 :            : {
    2029         [ #  # ]:          0 :     if( pNew )
    2030                 :            :     {
    2031                 :          0 :         const SvxBorderLine* pOld = rNewFrame.GetLine(nLine);
    2032         [ #  # ]:          0 :         if( pOld )
    2033                 :            :         {
    2034         [ #  # ]:          0 :             SvxBorderLine aNewLine( *pNew );
    2035                 :          0 :             aNewLine.SetColor( pOld->GetColor() );
    2036         [ #  # ]:          0 :             rNewFrame.SetLine( &aNewLine, nLine );
    2037                 :          0 :             return;
    2038                 :            :         }
    2039                 :            :     }
    2040                 :          0 :     rNewFrame.SetLine( pNew, nLine );
    2041                 :            : }
    2042                 :            : 
    2043                 :            : // --------------------------------------------------------------------
    2044                 :            : 
    2045                 :          0 : static void ImplApplyBoxItem( sal_uInt16 nCellFlags, const SvxBoxItem* pBoxItem, const SvxBoxInfoItem* pBoxInfoItem, SvxBoxItem& rNewFrame )
    2046                 :            : {
    2047         [ #  # ]:          0 :     if( (nCellFlags & (CELL_BEFORE|CELL_AFTER|CELL_UPPER|CELL_LOWER)) != 0 )
    2048                 :            :     {
    2049                 :            :         // current cell is outside the selection
    2050                 :            : 
    2051         [ #  # ]:          0 :         if( (nCellFlags & ( CELL_BEFORE|CELL_AFTER)) == 0 ) // check if its not nw or ne corner
    2052                 :            :         {
    2053         [ #  # ]:          0 :             if( nCellFlags & CELL_UPPER )
    2054                 :            :             {
    2055         [ #  # ]:          0 :                 if( pBoxInfoItem->IsValid(VALID_TOP) )
    2056                 :          0 :                     rNewFrame.SetLine(0, BOX_LINE_BOTTOM );
    2057                 :            :             }
    2058         [ #  # ]:          0 :             else if( nCellFlags & CELL_LOWER )
    2059                 :            :             {
    2060         [ #  # ]:          0 :                 if( pBoxInfoItem->IsValid(VALID_BOTTOM) )
    2061                 :          0 :                     rNewFrame.SetLine( 0, BOX_LINE_TOP );
    2062                 :            :             }
    2063                 :            :         }
    2064         [ #  # ]:          0 :         else if( (nCellFlags & ( CELL_UPPER|CELL_LOWER)) == 0 ) // check if its not sw or se corner
    2065                 :            :         {
    2066         [ #  # ]:          0 :             if( nCellFlags & CELL_BEFORE )
    2067                 :            :             {
    2068         [ #  # ]:          0 :                 if( pBoxInfoItem->IsValid(VALID_LEFT) )
    2069                 :          0 :                     rNewFrame.SetLine( 0, BOX_LINE_RIGHT );
    2070                 :            :             }
    2071         [ #  # ]:          0 :             else if( nCellFlags & CELL_AFTER )
    2072                 :            :             {
    2073         [ #  # ]:          0 :                 if( pBoxInfoItem->IsValid(VALID_RIGHT) )
    2074                 :          0 :                     rNewFrame.SetLine( 0, BOX_LINE_LEFT );
    2075                 :            :             }
    2076                 :            :         }
    2077                 :            :     }
    2078                 :            :     else
    2079                 :            :     {
    2080                 :            :         // current cell is inside the selection
    2081                 :            : 
    2082 [ #  # ][ #  # ]:          0 :         if( (nCellFlags & CELL_LEFT) ? pBoxInfoItem->IsValid(VALID_LEFT) : pBoxInfoItem->IsValid(VALID_VERT) )
    2083         [ #  # ]:          0 :             rNewFrame.SetLine( (nCellFlags & CELL_LEFT) ? pBoxItem->GetLeft() : pBoxInfoItem->GetVert(), BOX_LINE_LEFT );
    2084                 :            : 
    2085 [ #  # ][ #  # ]:          0 :         if( (nCellFlags & CELL_RIGHT) ? pBoxInfoItem->IsValid(VALID_RIGHT) : pBoxInfoItem->IsValid(VALID_VERT) )
    2086         [ #  # ]:          0 :             rNewFrame.SetLine( (nCellFlags & CELL_RIGHT) ? pBoxItem->GetRight() : pBoxInfoItem->GetVert(), BOX_LINE_RIGHT );
    2087                 :            : 
    2088 [ #  # ][ #  # ]:          0 :         if( (nCellFlags & CELL_TOP) ? pBoxInfoItem->IsValid(VALID_TOP) : pBoxInfoItem->IsValid(VALID_HORI) )
    2089         [ #  # ]:          0 :             rNewFrame.SetLine( (nCellFlags & CELL_TOP) ? pBoxItem->GetTop() : pBoxInfoItem->GetHori(), BOX_LINE_TOP );
    2090                 :            : 
    2091 [ #  # ][ #  # ]:          0 :         if( (nCellFlags & CELL_BOTTOM) ? pBoxInfoItem->IsValid(VALID_BOTTOM) : pBoxInfoItem->IsValid(VALID_HORI) )
    2092         [ #  # ]:          0 :             rNewFrame.SetLine( (nCellFlags & CELL_BOTTOM) ? pBoxItem->GetBottom() : pBoxInfoItem->GetHori(), BOX_LINE_BOTTOM );
    2093                 :            : 
    2094                 :            :         // apply distance to borders
    2095         [ #  # ]:          0 :         if( pBoxInfoItem->IsValid( VALID_DISTANCE ) )
    2096         [ #  # ]:          0 :             for( sal_uInt16 nLine = 0; nLine < 4; ++nLine )
    2097                 :          0 :                 rNewFrame.SetDistance( pBoxItem->GetDistance( nLine ), nLine );
    2098                 :            :     }
    2099                 :          0 : }
    2100                 :            : 
    2101                 :            : // --------------------------------------------------------------------
    2102                 :            : 
    2103                 :          0 : static void ImplSetLineColor( SvxBoxItem& rNewFrame, sal_uInt16 nLine, const Color& rColor )
    2104                 :            : {
    2105                 :          0 :     const SvxBorderLine* pSourceLine = rNewFrame.GetLine( nLine );
    2106         [ #  # ]:          0 :     if( pSourceLine )
    2107                 :            :     {
    2108         [ #  # ]:          0 :         SvxBorderLine aLine( *pSourceLine );
    2109                 :          0 :         aLine.SetColor( rColor );
    2110         [ #  # ]:          0 :         rNewFrame.SetLine( &aLine, nLine );
    2111                 :            :     }
    2112                 :          0 : }
    2113                 :            : 
    2114                 :            : // --------------------------------------------------------------------
    2115                 :            : 
    2116                 :          0 : static void ImplApplyLineColorItem( sal_uInt16 nCellFlags, const SvxColorItem* pLineColorItem, SvxBoxItem& rNewFrame )
    2117                 :            : {
    2118                 :          0 :     const Color aColor( pLineColorItem->GetValue() );
    2119                 :            : 
    2120         [ #  # ]:          0 :     if( (nCellFlags & (CELL_LOWER|CELL_BEFORE|CELL_AFTER)) == 0 )
    2121         [ #  # ]:          0 :         ImplSetLineColor( rNewFrame, BOX_LINE_BOTTOM, aColor );
    2122                 :            : 
    2123         [ #  # ]:          0 :     if( (nCellFlags & (CELL_UPPER|CELL_BEFORE|CELL_AFTER)) == 0 )
    2124         [ #  # ]:          0 :         ImplSetLineColor( rNewFrame, BOX_LINE_TOP, aColor );
    2125                 :            : 
    2126         [ #  # ]:          0 :     if( (nCellFlags & (CELL_UPPER|CELL_LOWER|CELL_AFTER)) == 0 )
    2127         [ #  # ]:          0 :         ImplSetLineColor( rNewFrame, BOX_LINE_RIGHT, aColor );
    2128                 :            : 
    2129         [ #  # ]:          0 :     if( (nCellFlags & (CELL_UPPER|CELL_LOWER|CELL_BEFORE)) == 0 )
    2130         [ #  # ]:          0 :         ImplSetLineColor( rNewFrame, BOX_LINE_LEFT, aColor );
    2131                 :          0 : }
    2132                 :            : 
    2133                 :            : // --------------------------------------------------------------------
    2134                 :            : 
    2135                 :          0 : static void ImplApplyBorderLineItem( sal_uInt16 nCellFlags, const SvxBorderLine* pBorderLineItem, SvxBoxItem& rNewFrame )
    2136                 :            : {
    2137         [ #  # ]:          0 :     if( (nCellFlags & ( CELL_BEFORE|CELL_AFTER|CELL_UPPER|CELL_LOWER)) != 0 )
    2138                 :            :     {
    2139         [ #  # ]:          0 :         if( (nCellFlags & ( CELL_BEFORE|CELL_AFTER)) == 0 ) // check if its not nw or ne corner
    2140                 :            :         {
    2141         [ #  # ]:          0 :             if( nCellFlags & CELL_UPPER )
    2142                 :            :             {
    2143         [ #  # ]:          0 :                 if( rNewFrame.GetBottom() )
    2144                 :          0 :                     ImplSetLinePreserveColor( rNewFrame, pBorderLineItem, BOX_LINE_BOTTOM );
    2145                 :            :             }
    2146         [ #  # ]:          0 :             else if( nCellFlags & CELL_LOWER )
    2147                 :            :             {
    2148         [ #  # ]:          0 :                 if( rNewFrame.GetTop() )
    2149                 :          0 :                     ImplSetLinePreserveColor( rNewFrame, pBorderLineItem, BOX_LINE_TOP );
    2150                 :            :             }
    2151                 :            :         }
    2152         [ #  # ]:          0 :         else if( (nCellFlags & ( CELL_UPPER|CELL_LOWER)) == 0 ) // check if its not sw or se corner
    2153                 :            :         {
    2154         [ #  # ]:          0 :             if( nCellFlags & CELL_BEFORE )
    2155                 :            :             {
    2156         [ #  # ]:          0 :                 if( rNewFrame.GetRight() )
    2157                 :          0 :                     ImplSetLinePreserveColor( rNewFrame, pBorderLineItem, BOX_LINE_RIGHT );
    2158                 :            :             }
    2159         [ #  # ]:          0 :             else if( nCellFlags & CELL_AFTER )
    2160                 :            :             {
    2161         [ #  # ]:          0 :                 if( rNewFrame.GetLeft() )
    2162                 :          0 :                     ImplSetLinePreserveColor( rNewFrame, pBorderLineItem, BOX_LINE_LEFT );
    2163                 :            :             }
    2164                 :            :         }
    2165                 :            :     }
    2166                 :            :     else
    2167                 :            :     {
    2168         [ #  # ]:          0 :         if( rNewFrame.GetBottom() )
    2169                 :          0 :             ImplSetLinePreserveColor( rNewFrame, pBorderLineItem, BOX_LINE_BOTTOM );
    2170         [ #  # ]:          0 :         if( rNewFrame.GetTop() )
    2171                 :          0 :             ImplSetLinePreserveColor( rNewFrame, pBorderLineItem, BOX_LINE_TOP );
    2172         [ #  # ]:          0 :         if( rNewFrame.GetRight() )
    2173                 :          0 :             ImplSetLinePreserveColor( rNewFrame, pBorderLineItem, BOX_LINE_RIGHT );
    2174         [ #  # ]:          0 :         if( rNewFrame.GetLeft() )
    2175                 :          0 :             ImplSetLinePreserveColor( rNewFrame, pBorderLineItem, BOX_LINE_LEFT );
    2176                 :            :     }
    2177                 :          0 : }
    2178                 :            : 
    2179                 :            : // --------------------------------------------------------------------
    2180                 :            : 
    2181                 :          0 : void SvxTableController::ApplyBorderAttr( const SfxItemSet& rAttr )
    2182                 :            : {
    2183         [ #  # ]:          0 :     if( mxTable.is() )
    2184                 :            :     {
    2185         [ #  # ]:          0 :         const sal_Int32 nRowCount = mxTable->getRowCount();
    2186         [ #  # ]:          0 :         const sal_Int32 nColCount = mxTable->getColumnCount();
    2187 [ #  # ][ #  # ]:          0 :         if( nRowCount && nColCount )
    2188                 :            :         {
    2189                 :          0 :             const SvxBoxItem* pBoxItem = 0;
    2190 [ #  # ][ #  # ]:          0 :             if(SFX_ITEM_SET == rAttr.GetItemState(SDRATTR_TABLE_BORDER, sal_False) )
    2191 [ #  # ][ #  # ]:          0 :                 pBoxItem = dynamic_cast< const SvxBoxItem* >( &rAttr.Get( SDRATTR_TABLE_BORDER ) );
    2192                 :            : 
    2193                 :          0 :             const SvxBoxInfoItem* pBoxInfoItem = 0;
    2194 [ #  # ][ #  # ]:          0 :             if(SFX_ITEM_SET == rAttr.GetItemState(SDRATTR_TABLE_BORDER_INNER, sal_False) )
    2195 [ #  # ][ #  # ]:          0 :                 pBoxInfoItem = dynamic_cast< const SvxBoxInfoItem* >( &rAttr.Get( SDRATTR_TABLE_BORDER_INNER ) );
    2196                 :            : 
    2197                 :          0 :             const SvxColorItem* pLineColorItem = 0;
    2198 [ #  # ][ #  # ]:          0 :             if(SFX_ITEM_SET == rAttr.GetItemState(SID_FRAME_LINECOLOR, sal_False) )
    2199 [ #  # ][ #  # ]:          0 :                 pLineColorItem = dynamic_cast< const SvxColorItem* >( &rAttr.Get( SID_FRAME_LINECOLOR ) );
    2200                 :            : 
    2201                 :          0 :             const SvxBorderLine* pBorderLineItem = 0;
    2202 [ #  # ][ #  # ]:          0 :             if(SFX_ITEM_SET == rAttr.GetItemState(SID_FRAME_LINESTYLE, sal_False) )
    2203         [ #  # ]:          0 :                 pBorderLineItem = ((const SvxLineItem&)rAttr.Get( SID_FRAME_LINESTYLE )).GetLine();
    2204                 :            : 
    2205 [ #  # ][ #  # ]:          0 :             if( pBoxInfoItem && !pBoxItem )
    2206                 :            :             {
    2207 [ #  # ][ #  # ]:          0 :                 const static SvxBoxItem gaEmptyBoxItem( SDRATTR_TABLE_BORDER );
         [ #  # ][ #  # ]
    2208                 :          0 :                 pBoxItem = &gaEmptyBoxItem;
    2209                 :            :             }
    2210 [ #  # ][ #  # ]:          0 :             else if( pBoxItem && !pBoxInfoItem )
    2211                 :            :             {
    2212 [ #  # ][ #  # ]:          0 :                 const static SvxBoxInfoItem gaEmptyBoxInfoItem( SDRATTR_TABLE_BORDER_INNER );
         [ #  # ][ #  # ]
    2213                 :          0 :                 pBoxInfoItem = &gaEmptyBoxInfoItem;
    2214                 :            :             }
    2215                 :            : 
    2216                 :          0 :             CellPos aStart, aEnd;
    2217         [ #  # ]:          0 :             getSelectedCells( aStart, aEnd );
    2218                 :            : 
    2219         [ #  # ]:          0 :             const sal_Int32 nLastRow = std::min( aEnd.mnRow + 2, nRowCount );
    2220         [ #  # ]:          0 :             const sal_Int32 nLastCol = std::min( aEnd.mnCol + 2, nColCount );
    2221                 :            : 
    2222 [ #  # ][ #  # ]:          0 :             for( sal_Int32 nRow = std::max( aStart.mnRow - 1, (sal_Int32)0 ); nRow < nLastRow; nRow++ )
    2223                 :            :             {
    2224                 :          0 :                 sal_uInt16 nRowFlags = 0;
    2225         [ #  # ]:          0 :                 nRowFlags |= (nRow == aStart.mnRow) ? CELL_TOP : 0;
    2226         [ #  # ]:          0 :                 nRowFlags |= (nRow == aEnd.mnRow)   ? CELL_BOTTOM : 0;
    2227         [ #  # ]:          0 :                 nRowFlags |= (nRow < aStart.mnRow)  ? CELL_UPPER : 0;
    2228         [ #  # ]:          0 :                 nRowFlags |= (nRow > aEnd.mnRow)    ? CELL_LOWER : 0;
    2229                 :            : 
    2230 [ #  # ][ #  # ]:          0 :                 for( sal_Int32 nCol = std::max( aStart.mnCol - 1, (sal_Int32)0 ); nCol < nLastCol; nCol++ )
    2231                 :            :                 {
    2232 [ #  # ][ #  # ]:          0 :                     CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
                 [ #  # ]
    2233         [ #  # ]:          0 :                     if( !xCell.is() )
    2234                 :          0 :                         continue;
    2235                 :            : 
    2236         [ #  # ]:          0 :                     const SfxItemSet& rSet = xCell->GetItemSet();
    2237         [ #  # ]:          0 :                     const SvxBoxItem* pOldOuter = (const SvxBoxItem*)     &rSet.Get( SDRATTR_TABLE_BORDER );
    2238                 :            : 
    2239         [ #  # ]:          0 :                     SvxBoxItem aNewFrame( *pOldOuter );
    2240                 :            : 
    2241                 :          0 :                     sal_uInt16 nCellFlags = nRowFlags;
    2242         [ #  # ]:          0 :                     nCellFlags |= (nCol == aStart.mnCol) ? CELL_LEFT : 0;
    2243         [ #  # ]:          0 :                     nCellFlags |= (nCol == aEnd.mnCol)   ? CELL_RIGHT : 0;
    2244         [ #  # ]:          0 :                     nCellFlags |= (nCol < aStart.mnCol)  ? CELL_BEFORE : 0;
    2245         [ #  # ]:          0 :                     nCellFlags |= (nCol > aEnd.mnCol)    ? CELL_AFTER : 0;
    2246                 :            : 
    2247 [ #  # ][ #  # ]:          0 :                     if( pBoxItem && pBoxInfoItem )
    2248         [ #  # ]:          0 :                         ImplApplyBoxItem( nCellFlags, pBoxItem, pBoxInfoItem, aNewFrame );
    2249                 :            : 
    2250         [ #  # ]:          0 :                     if( pLineColorItem )
    2251         [ #  # ]:          0 :                         ImplApplyLineColorItem( nCellFlags, pLineColorItem, aNewFrame );
    2252                 :            : 
    2253         [ #  # ]:          0 :                     if( pBorderLineItem )
    2254         [ #  # ]:          0 :                         ImplApplyBorderLineItem( nCellFlags, pBorderLineItem, aNewFrame );
    2255                 :            : 
    2256 [ #  # ][ #  # ]:          0 :                     if (aNewFrame != *pOldOuter)
    2257                 :            :                     {
    2258         [ #  # ]:          0 :                         SfxItemSet aAttr(*rSet.GetPool(), rSet.GetRanges());
    2259         [ #  # ]:          0 :                         aAttr.Put(aNewFrame);
    2260 [ #  # ][ #  # ]:          0 :                         xCell->SetMergedItemSetAndBroadcast( aAttr, false );
    2261                 :            :                     }
    2262 [ #  # ][ #  # ]:          0 :                 }
    2263                 :            :             }
    2264                 :            :         }
    2265                 :            :     }
    2266                 :          0 : }
    2267                 :            : 
    2268                 :            : // --------------------------------------------------------------------
    2269                 :            : 
    2270                 :          0 : void SvxTableController::UpdateTableShape()
    2271                 :            : {
    2272                 :          0 :     SdrObject* pTableObj = mxTableObj.get();
    2273         [ #  # ]:          0 :     if( pTableObj )
    2274                 :            :     {
    2275                 :          0 :         pTableObj->ActionChanged();
    2276                 :          0 :         pTableObj->BroadcastObjectChange();
    2277                 :            :     }
    2278                 :          0 :     updateSelectionOverlay();
    2279                 :          0 : }
    2280                 :            : 
    2281                 :            : 
    2282                 :            : // --------------------------------------------------------------------
    2283                 :            : 
    2284                 :          0 : void SvxTableController::SetAttrToSelectedCells(const SfxItemSet& rAttr, bool bReplaceAll)
    2285                 :            : {
    2286         [ #  # ]:          0 :     if( mxTable.is() )
    2287                 :            :     {
    2288 [ #  # ][ #  # ]:          0 :         const bool bUndo = mpModel && mpModel->IsUndoEnabled();
                 [ #  # ]
    2289                 :            : 
    2290         [ #  # ]:          0 :         if( bUndo )
    2291 [ #  # ][ #  # ]:          0 :             mpModel->BegUndo( ImpGetResStr(STR_TABLE_NUMFORMAT) );
                 [ #  # ]
    2292                 :            : 
    2293                 :          0 :         CellPos aStart, aEnd;
    2294         [ #  # ]:          0 :         getSelectedCells( aStart, aEnd );
    2295                 :            : 
    2296         [ #  # ]:          0 :         SfxItemSet aAttr(*rAttr.GetPool(), rAttr.GetRanges());
    2297         [ #  # ]:          0 :         aAttr.Put(rAttr, sal_True);
    2298                 :            : 
    2299 [ #  # ][ #  # ]:          0 :         const bool bFrame = (rAttr.GetItemState( SDRATTR_TABLE_BORDER ) == SFX_ITEM_SET) || (rAttr.GetItemState( SDRATTR_TABLE_BORDER_INNER ) == SFX_ITEM_SET);
         [ #  # ][ #  # ]
    2300                 :            : 
    2301         [ #  # ]:          0 :         if( bFrame )
    2302                 :            :         {
    2303         [ #  # ]:          0 :             aAttr.ClearItem( SDRATTR_TABLE_BORDER );
    2304         [ #  # ]:          0 :             aAttr.ClearItem( SDRATTR_TABLE_BORDER_INNER );
    2305                 :            :         }
    2306                 :            : 
    2307         [ #  # ]:          0 :         for( sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++ )
    2308                 :            :         {
    2309         [ #  # ]:          0 :             for( sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++ )
    2310                 :            :             {
    2311 [ #  # ][ #  # ]:          0 :                 CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
                 [ #  # ]
    2312         [ #  # ]:          0 :                 if( xCell.is() )
    2313                 :            :                 {
    2314         [ #  # ]:          0 :                     if( bUndo )
    2315         [ #  # ]:          0 :                         xCell->AddUndo();
    2316         [ #  # ]:          0 :                     xCell->SetMergedItemSetAndBroadcast(aAttr, bReplaceAll);
    2317                 :            :                 }
    2318                 :          0 :             }
    2319                 :            :         }
    2320                 :            : 
    2321         [ #  # ]:          0 :         if( bFrame )
    2322                 :            :         {
    2323         [ #  # ]:          0 :             ApplyBorderAttr( rAttr );
    2324                 :            :         }
    2325                 :            : 
    2326         [ #  # ]:          0 :         UpdateTableShape();
    2327                 :            : 
    2328         [ #  # ]:          0 :         if( bUndo )
    2329 [ #  # ][ #  # ]:          0 :             mpModel->EndUndo();
    2330                 :            : 
    2331                 :            :     }
    2332                 :          0 : }
    2333                 :            : 
    2334                 :            : // --------------------------------------------------------------------
    2335                 :            : 
    2336                 :          0 : bool SvxTableController::GetAttributes(SfxItemSet& rTargetSet, bool bOnlyHardAttr) const
    2337                 :            : {
    2338 [ #  # ][ #  # ]:          0 :     if( mxTableObj.is() && hasSelectedCells() )
                 [ #  # ]
    2339                 :            :     {
    2340                 :          0 :         MergeAttrFromSelectedCells( rTargetSet, bOnlyHardAttr );
    2341                 :            : 
    2342         [ #  # ]:          0 :         if( mpView->IsTextEdit() )
    2343                 :            :         {
    2344         [ #  # ]:          0 :             if( mxTableObj->GetOutlinerParaObject() )
    2345         [ #  # ]:          0 :                 rTargetSet.Put( SvxScriptTypeItem( mxTableObj->GetOutlinerParaObject()->GetTextObject().GetScriptType() ) );
    2346                 :            : 
    2347                 :          0 :             OutlinerView* pTextEditOutlinerView = mpView->GetTextEditOutlinerView();
    2348         [ #  # ]:          0 :             if(pTextEditOutlinerView)
    2349                 :            :             {
    2350                 :            :                 // FALSE= InvalidItems nicht al Default, sondern als "Loecher" betrachten
    2351         [ #  # ]:          0 :                 rTargetSet.Put(pTextEditOutlinerView->GetAttribs(), sal_False);
    2352         [ #  # ]:          0 :                 rTargetSet.Put( SvxScriptTypeItem( pTextEditOutlinerView->GetSelectedScriptType() ), sal_False );
    2353                 :            :             }
    2354                 :            :         }
    2355                 :            : 
    2356                 :          0 :         return true;
    2357                 :            :     }
    2358                 :            :     else
    2359                 :            :     {
    2360                 :          0 :         return false;
    2361                 :            :     }
    2362                 :            : }
    2363                 :            : 
    2364                 :            : // --------------------------------------------------------------------
    2365                 :            : 
    2366                 :          0 : bool SvxTableController::SetAttributes(const SfxItemSet& rSet, bool bReplaceAll)
    2367                 :            : {
    2368 [ #  # ][ #  # ]:          0 :     if( mbCellSelectionMode || mpView->IsTextEdit()  )
                 [ #  # ]
    2369                 :            :     {
    2370                 :          0 :         SetAttrToSelectedCells( rSet, bReplaceAll );
    2371                 :          0 :         return true;
    2372                 :            :     }
    2373                 :          0 :     return false;
    2374                 :            : }
    2375                 :            : 
    2376                 :            : // --------------------------------------------------------------------
    2377                 :            : 
    2378                 :          0 : bool SvxTableController::GetMarkedObjModel( SdrPage* pNewPage )
    2379                 :            : {
    2380 [ #  # ][ #  # ]:          0 :     if( mxTableObj.is() && mbCellSelectionMode && pNewPage ) try
         [ #  # ][ #  # ]
    2381                 :            :     {
    2382                 :          0 :         ::sdr::table::SdrTableObj& rTableObj = *static_cast< ::sdr::table::SdrTableObj* >( mxTableObj.get() );
    2383                 :            : 
    2384                 :          0 :         CellPos aStart, aEnd;
    2385         [ #  # ]:          0 :         getSelectedCells( aStart, aEnd );
    2386                 :            : 
    2387         [ #  # ]:          0 :         SdrTableObj* pNewTableObj = rTableObj.CloneRange( aStart, aEnd );
    2388                 :            : 
    2389         [ #  # ]:          0 :         pNewTableObj->SetPage( pNewPage );
    2390 [ #  # ][ #  # ]:          0 :         pNewTableObj->SetModel( pNewPage->GetModel() );
    2391                 :            : 
    2392                 :          0 :         SdrInsertReason aReason(SDRREASON_VIEWCALL);
    2393         [ #  # ]:          0 :         pNewPage->InsertObject(pNewTableObj,CONTAINER_APPEND,&aReason);
    2394                 :            : 
    2395                 :          0 :         return true;
    2396                 :            :     }
    2397                 :          0 :     catch( Exception& )
    2398                 :            :     {
    2399                 :            :         OSL_FAIL( "svx::SvxTableController::GetMarkedObjModel(), exception caught!" );
    2400                 :            :     }
    2401         [ #  # ]:          0 :     return false;
    2402                 :            : }
    2403                 :            : 
    2404                 :            : // --------------------------------------------------------------------
    2405                 :            : 
    2406                 :          0 : bool SvxTableController::PasteObjModel( const SdrModel& rModel )
    2407                 :            : {
    2408 [ #  # ][ #  # ]:          0 :     if( mxTableObj.is() && mpView && (rModel.GetPageCount() >= 1) )
         [ #  # ][ #  # ]
    2409                 :            :     {
    2410                 :          0 :         const SdrPage* pPastePage = rModel.GetPage(0);
    2411 [ #  # ][ #  # ]:          0 :         if( pPastePage && pPastePage->GetObjCount() == 1 )
                 [ #  # ]
    2412                 :            :         {
    2413         [ #  # ]:          0 :             SdrTableObj* pPasteTableObj = dynamic_cast< SdrTableObj* >( pPastePage->GetObj(0) );
    2414         [ #  # ]:          0 :             if( pPasteTableObj )
    2415                 :            :             {
    2416                 :          0 :                 return PasteObject( pPasteTableObj );
    2417                 :            :             }
    2418                 :            :         }
    2419                 :            :     }
    2420                 :            : 
    2421                 :          0 :     return false;
    2422                 :            : }
    2423                 :            : 
    2424                 :            : // --------------------------------------------------------------------
    2425                 :            : 
    2426                 :          0 : bool SvxTableController::PasteObject( SdrTableObj* pPasteTableObj )
    2427                 :            : {
    2428         [ #  # ]:          0 :     if( !pPasteTableObj )
    2429                 :          0 :         return false;
    2430                 :            : 
    2431         [ #  # ]:          0 :     Reference< XTable > xPasteTable( pPasteTableObj->getTable() );
    2432         [ #  # ]:          0 :     if( !xPasteTable.is() )
    2433                 :          0 :         return false;
    2434                 :            : 
    2435         [ #  # ]:          0 :     if( !mxTable.is() )
    2436                 :          0 :         return false;
    2437                 :            : 
    2438 [ #  # ][ #  # ]:          0 :     sal_Int32 nPasteColumns = xPasteTable->getColumnCount();
    2439 [ #  # ][ #  # ]:          0 :     sal_Int32 nPasteRows = xPasteTable->getRowCount();
    2440                 :            : 
    2441                 :          0 :     CellPos aStart, aEnd;
    2442         [ #  # ]:          0 :     getSelectedCells( aStart, aEnd );
    2443                 :            : 
    2444 [ #  # ][ #  # ]:          0 :     if( mpView->IsTextEdit() )
    2445         [ #  # ]:          0 :         mpView->SdrEndTextEdit(sal_True);
    2446                 :            : 
    2447         [ #  # ]:          0 :     sal_Int32 nColumns = mxTable->getColumnCount();
    2448         [ #  # ]:          0 :     sal_Int32 nRows = mxTable->getRowCount();
    2449                 :            : 
    2450                 :          0 :     const sal_Int32 nMissing = nPasteRows - ( nRows - aStart.mnRow );
    2451         [ #  # ]:          0 :     if( nMissing > 0 )
    2452                 :            :     {
    2453         [ #  # ]:          0 :         Reference< XTableRows > xRows( mxTable->getRows() );
    2454 [ #  # ][ #  # ]:          0 :         xRows->insertByIndex( nRows, nMissing );
    2455         [ #  # ]:          0 :         nRows = mxTable->getRowCount();
    2456                 :            :     }
    2457                 :            : 
    2458         [ #  # ]:          0 :     nPasteRows = std::min( nPasteRows, nRows - aStart.mnRow );
    2459         [ #  # ]:          0 :     nPasteColumns = std::min( nPasteColumns, nColumns - aStart.mnCol );
    2460                 :            : 
    2461                 :            :     // copy cell contents
    2462         [ #  # ]:          0 :     for( sal_Int32 nRow = 0; nRow < nPasteRows; ++nRow )
    2463                 :            :     {
    2464         [ #  # ]:          0 :         for( sal_Int32 nCol = 0; nCol < nPasteColumns; ++nCol )
    2465                 :            :         {
    2466 [ #  # ][ #  # ]:          0 :             CellRef xTargetCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( aStart.mnCol + nCol, aStart.mnRow + nRow ).get() ) );
                 [ #  # ]
    2467 [ #  # ][ #  # ]:          0 :             if( xTargetCell.is() && !xTargetCell->isMerged() )
         [ #  # ][ #  # ]
    2468                 :            :             {
    2469         [ #  # ]:          0 :                 xTargetCell->AddUndo();
    2470 [ #  # ][ #  # ]:          0 :                 xTargetCell->cloneFrom( dynamic_cast< Cell* >( xPasteTable->getCellByPosition( nCol, nRow ).get() ) );
         [ #  # ][ #  # ]
                 [ #  # ]
    2471         [ #  # ]:          0 :                 nCol += xTargetCell->getColumnSpan() - 1;
    2472                 :            :             }
    2473                 :          0 :         }
    2474                 :            :     }
    2475                 :            : 
    2476         [ #  # ]:          0 :     UpdateTableShape();
    2477                 :            : 
    2478                 :          0 :     return true;
    2479                 :            : }
    2480                 :            : 
    2481                 :          0 : bool SvxTableController::TakeFormatPaintBrush( boost::shared_ptr< SfxItemSet >& /*rFormatSet*/  )
    2482                 :            : {
    2483                 :            :     // SdrView::TakeFormatPaintBrush() is enough
    2484                 :          0 :     return false;
    2485                 :            : }
    2486                 :            : 
    2487                 :          0 : bool SvxTableController::ApplyFormatPaintBrush( SfxItemSet& rFormatSet, bool bNoCharacterFormats, bool bNoParagraphFormats )
    2488                 :            : {
    2489         [ #  # ]:          0 :     if( mbCellSelectionMode )
    2490                 :            :     {
    2491         [ #  # ]:          0 :         SdrTextObj* pTableObj = dynamic_cast<SdrTextObj*>( mxTableObj.get() );
    2492         [ #  # ]:          0 :         if( !pTableObj )
    2493                 :          0 :             return false;
    2494                 :            : 
    2495 [ #  # ][ #  # ]:          0 :         const bool bUndo = mpModel && mpModel->IsUndoEnabled();
                 [ #  # ]
    2496                 :            : 
    2497         [ #  # ]:          0 :         if( bUndo )
    2498 [ #  # ][ #  # ]:          0 :             mpModel->BegUndo( ImpGetResStr(STR_TABLE_NUMFORMAT) );
                 [ #  # ]
    2499                 :            : 
    2500                 :          0 :         CellPos aStart, aEnd;
    2501         [ #  # ]:          0 :         getSelectedCells( aStart, aEnd );
    2502                 :            : 
    2503         [ #  # ]:          0 :         SfxItemSet aAttr(*rFormatSet.GetPool(), rFormatSet.GetRanges());
    2504         [ #  # ]:          0 :         aAttr.Put(rFormatSet, sal_True);
    2505                 :            : 
    2506 [ #  # ][ #  # ]:          0 :         const bool bFrame = (rFormatSet.GetItemState( SDRATTR_TABLE_BORDER ) == SFX_ITEM_SET) || (rFormatSet.GetItemState( SDRATTR_TABLE_BORDER_INNER ) == SFX_ITEM_SET);
         [ #  # ][ #  # ]
    2507                 :            : 
    2508         [ #  # ]:          0 :         if( bFrame )
    2509                 :            :         {
    2510         [ #  # ]:          0 :             aAttr.ClearItem( SDRATTR_TABLE_BORDER );
    2511         [ #  # ]:          0 :             aAttr.ClearItem( SDRATTR_TABLE_BORDER_INNER );
    2512                 :            :         }
    2513                 :            : 
    2514                 :          0 :         const sal_uInt16* pRanges = rFormatSet.GetRanges();
    2515                 :          0 :         bool bTextOnly = true;
    2516                 :            : 
    2517         [ #  # ]:          0 :         while( *pRanges )
    2518                 :            :         {
    2519 [ #  # ][ #  # ]:          0 :             if( (*pRanges != EE_PARA_START) && (*pRanges != EE_CHAR_START) )
    2520                 :            :             {
    2521                 :          0 :                 bTextOnly = true;
    2522                 :          0 :                 break;
    2523                 :            :             }
    2524                 :          0 :             pRanges += 2;
    2525                 :            :         }
    2526                 :            : 
    2527                 :          0 :         const bool bReplaceAll = false;
    2528         [ #  # ]:          0 :         for( sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++ )
    2529                 :            :         {
    2530         [ #  # ]:          0 :             for( sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++ )
    2531                 :            :             {
    2532 [ #  # ][ #  # ]:          0 :                 CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
                 [ #  # ]
    2533         [ #  # ]:          0 :                 if( xCell.is() )
    2534                 :            :                 {
    2535         [ #  # ]:          0 :                     if( bUndo )
    2536         [ #  # ]:          0 :                         xCell->AddUndo();
    2537         [ #  # ]:          0 :                     if( !bTextOnly )
    2538         [ #  # ]:          0 :                         xCell->SetMergedItemSetAndBroadcast(aAttr, bReplaceAll);
    2539                 :            : 
    2540                 :          0 :                     SdrText* pText = static_cast< SdrText* >( xCell.get() );
    2541         [ #  # ]:          0 :                     mpView->ApplyFormatPaintBrushToText( rFormatSet, *pTableObj, pText, bNoCharacterFormats, bNoParagraphFormats );
    2542                 :            :                 }
    2543                 :          0 :             }
    2544                 :            :         }
    2545                 :            : 
    2546         [ #  # ]:          0 :         if( bFrame )
    2547                 :            :         {
    2548         [ #  # ]:          0 :             ApplyBorderAttr( rFormatSet );
    2549                 :            :         }
    2550                 :            : 
    2551         [ #  # ]:          0 :         UpdateTableShape();
    2552                 :            : 
    2553         [ #  # ]:          0 :         if( bUndo )
    2554         [ #  # ]:          0 :             mpModel->EndUndo();
    2555                 :            : 
    2556         [ #  # ]:          0 :         return true;
    2557                 :            : 
    2558                 :            :     }
    2559                 :          0 :     return false;
    2560                 :            : }
    2561                 :            : 
    2562                 :            : 
    2563                 :            : // --------------------------------------------------------------------
    2564                 :            : 
    2565                 :          0 : IMPL_LINK_NOARG(SvxTableController, UpdateHdl)
    2566                 :            : {
    2567                 :          0 :     mnUpdateEvent = 0;
    2568                 :            : 
    2569         [ #  # ]:          0 :     if( mbCellSelectionMode )
    2570                 :            :     {
    2571                 :          0 :         CellPos aStart( maCursorFirstPos );
    2572                 :          0 :         CellPos aEnd( maCursorLastPos );
    2573         [ #  # ]:          0 :         checkCell(aStart);
    2574         [ #  # ]:          0 :         checkCell(aEnd);
    2575 [ #  # ][ #  # ]:          0 :         if( aStart != maCursorFirstPos  || aEnd != maCursorLastPos )
                 [ #  # ]
    2576                 :            :         {
    2577         [ #  # ]:          0 :             setSelectedCells( aStart, aEnd );
    2578                 :            :         }
    2579                 :            :     }
    2580                 :          0 :     updateSelectionOverlay();
    2581                 :            : 
    2582                 :          0 :     return 0;
    2583                 :            : }
    2584                 :            : 
    2585                 :            : } }
    2586                 :            : 
    2587                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10