LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/reportdesign/source/ui/dlg - CondFormat.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 260 0.0 %
Date: 2013-07-09 Functions: 0 33 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "CondFormat.hxx"
      21             : #include "CondFormat.hrc"
      22             : 
      23             : #include "uistrings.hrc"
      24             : #include "RptResId.hrc"
      25             : #include "rptui_slotid.hrc"
      26             : #include "ModuleHelper.hxx"
      27             : #include "helpids.hrc"
      28             : #include "UITools.hxx"
      29             : #include "ReportController.hxx"
      30             : #include "Condition.hxx"
      31             : 
      32             : #include <com/sun/star/beans/XPropertySet.hpp>
      33             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      34             : 
      35             : #include <toolkit/helper/vclunohelper.hxx>
      36             : 
      37             : #include <vcl/msgbox.hxx>
      38             : 
      39             : #include <tools/debug.hxx>
      40             : #include <tools/diagnose_ex.h>
      41             : 
      42             : #include <comphelper/property.hxx>
      43             : 
      44             : #include <algorithm>
      45             : #include "UndoActions.hxx"
      46             : 
      47             : // .............................................................................
      48             : namespace rptui
      49             : {
      50             : // .............................................................................
      51             : 
      52             :     using ::com::sun::star::uno::Reference;
      53             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      54             :     using ::com::sun::star::uno::UNO_QUERY;
      55             :     using ::com::sun::star::uno::Exception;
      56             :     using ::com::sun::star::lang::IllegalArgumentException;
      57             :     using ::com::sun::star::uno::Sequence;
      58             :     using ::com::sun::star::beans::PropertyValue;
      59             :     using ::com::sun::star::uno::Any;
      60             : 
      61             :     using namespace ::com::sun::star::report;
      62             : 
      63             :     //========================================================================
      64             :     // UpdateLocker
      65             :     //========================================================================
      66             :     class UpdateLocker
      67             :     {
      68             :         Window& m_rWindow;
      69             : 
      70             :     public:
      71           0 :         UpdateLocker( Window& _rWindow )
      72           0 :             :m_rWindow( _rWindow )
      73             :         {
      74           0 :             _rWindow.SetUpdateMode( sal_False );
      75           0 :         }
      76           0 :         ~UpdateLocker()
      77             :         {
      78           0 :             m_rWindow.SetUpdateMode( sal_True );
      79           0 :         }
      80             :     };
      81             : 
      82             :     //========================================================================
      83             :     // class ConditionalFormattingDialog
      84             :     //========================================================================
      85             :     DBG_NAME(rpt_ConditionalFormattingDialog)
      86           0 :     ConditionalFormattingDialog::ConditionalFormattingDialog(
      87             :             Window* _pParent, const Reference< XReportControlModel >& _rxFormatConditions, ::rptui::OReportController& _rController )
      88             :         :ModalDialog( _pParent, ModuleRes(RID_CONDFORMAT) )
      89             :         ,m_aConditionPlayground( this, ModuleRes( WND_COND_PLAYGROUND ) )
      90             :         ,m_aSeparator(this,     ModuleRes(FL_SEPARATOR1))
      91             :         ,m_aPB_OK(this,         ModuleRes(PB_OK))
      92             :         ,m_aPB_CANCEL(this,     ModuleRes(PB_CANCEL))
      93             :         ,m_aPB_Help(this,       ModuleRes(PB_HELP))
      94             :         ,m_aCondScroll( this,   ModuleRes( SB_ALL_CONDITIONS ) )
      95             :         ,m_rController( _rController )
      96             :         ,m_xFormatConditions( _rxFormatConditions )
      97           0 :         ,m_bDeletingCondition( false )
      98             :     {
      99             :         DBG_CTOR(rpt_ConditionalFormattingDialog,NULL);
     100             :         OSL_ENSURE( m_xFormatConditions.is(), "ConditionalFormattingDialog::ConditionalFormattingDialog: ReportControlModel is NULL -> Prepare for GPF!" );
     101             : 
     102           0 :         m_xCopy.set( m_xFormatConditions->createClone(), UNO_QUERY_THROW );
     103             : 
     104           0 :         m_aCondScroll.SetScrollHdl( LINK( this, ConditionalFormattingDialog, OnScroll ) );
     105             : 
     106           0 :         impl_initializeConditions();
     107             : 
     108           0 :         FreeResource();
     109           0 :     }
     110             : 
     111             :     //------------------------------------------------------------------------
     112           0 :     ConditionalFormattingDialog::~ConditionalFormattingDialog()
     113             :     {
     114           0 :         m_aConditions.clear();
     115             :         DBG_DTOR(rpt_ConditionalFormattingDialog,NULL);
     116           0 :     }
     117             : 
     118             :     // -----------------------------------------------------------------------------
     119           0 :     void ConditionalFormattingDialog::impl_updateConditionIndicies()
     120             :     {
     121           0 :         sal_Int32 nIndex = 0;
     122           0 :         for (   Conditions::const_iterator cond = m_aConditions.begin();
     123           0 :                 cond != m_aConditions.end();
     124             :                 ++cond, ++nIndex
     125             :             )
     126             :         {
     127           0 :             (*cond)->setConditionIndex( nIndex, impl_getConditionCount() );
     128             :         }
     129           0 :     }
     130             : 
     131             :     // -----------------------------------------------------------------------------
     132           0 :     void ConditionalFormattingDialog::impl_conditionCountChanged()
     133             :     {
     134           0 :         if ( m_aConditions.empty() )
     135           0 :             impl_addCondition_nothrow( 0 );
     136             : 
     137           0 :         impl_updateScrollBarRange();
     138           0 :         impl_updateConditionIndicies();
     139           0 :         impl_layoutAll();
     140           0 :     }
     141             : 
     142             :     // -----------------------------------------------------------------------------
     143           0 :     void ConditionalFormattingDialog::addCondition( size_t _nAddAfterIndex )
     144             :     {
     145             :         OSL_PRECOND( _nAddAfterIndex < impl_getConditionCount(), "ConditionalFormattingDialog::addCondition: illegal condition index!" );
     146           0 :         impl_addCondition_nothrow( _nAddAfterIndex + 1 );
     147           0 :     }
     148             : 
     149             :     // -----------------------------------------------------------------------------
     150           0 :     void ConditionalFormattingDialog::deleteCondition( size_t _nCondIndex )
     151             :     {
     152           0 :         impl_deleteCondition_nothrow( _nCondIndex );
     153           0 :     }
     154             : 
     155             :     // -----------------------------------------------------------------------------
     156           0 :     void ConditionalFormattingDialog::impl_addCondition_nothrow( size_t _nNewCondIndex )
     157             :     {
     158           0 :         UpdateLocker aLockUpdates( *this );
     159             : 
     160             :         try
     161             :         {
     162           0 :             if ( _nNewCondIndex > (size_t)m_xCopy->getCount() )
     163           0 :                 throw IllegalArgumentException();
     164             : 
     165           0 :             Reference< XFormatCondition > xCond = m_xCopy->createFormatCondition();
     166           0 :             ::comphelper::copyProperties(m_xCopy.get(),xCond.get());
     167           0 :             m_xCopy->insertByIndex( _nNewCondIndex, makeAny( xCond ) );
     168             : 
     169           0 :             ConditionPtr pCon( new Condition( &m_aConditionPlayground, *this, m_rController ) );
     170           0 :             pCon->setCondition( xCond );
     171           0 :             m_aConditions.insert( m_aConditions.begin() + _nNewCondIndex, pCon );
     172             : 
     173           0 :             pCon->setPosSizePixel( 0, 0, impl_getConditionWidth(), 0, WINDOW_POSSIZE_WIDTH );
     174             :         }
     175           0 :         catch( const Exception& )
     176             :         {
     177             :             DBG_UNHANDLED_EXCEPTION();
     178             :         }
     179             : 
     180           0 :         impl_conditionCountChanged();
     181             : 
     182           0 :         impl_ensureConditionVisible( _nNewCondIndex );
     183           0 :     }
     184             : 
     185             :     // -----------------------------------------------------------------------------
     186           0 :     void ConditionalFormattingDialog::impl_focusCondition( size_t _nCondIndex )
     187             :     {
     188             :         OSL_PRECOND( _nCondIndex < impl_getConditionCount(),
     189             :             "ConditionalFormattingDialog::impl_focusCondition: illegal index!" );
     190             : 
     191           0 :         impl_ensureConditionVisible( _nCondIndex );
     192           0 :         m_aConditions[ _nCondIndex ]->GrabFocus();
     193           0 :     }
     194             : 
     195             :     // -----------------------------------------------------------------------------
     196           0 :     void ConditionalFormattingDialog::impl_deleteCondition_nothrow( size_t _nCondIndex )
     197             :     {
     198           0 :         UpdateLocker aLockUpdates( *this );
     199             : 
     200             :         OSL_PRECOND( _nCondIndex < impl_getConditionCount(),
     201             :             "ConditionalFormattingDialog::impl_deleteCondition_nothrow: illegal index!" );
     202             : 
     203           0 :         bool bLastCondition = ( impl_getConditionCount() == 1 );
     204             : 
     205           0 :         bool bSetNewFocus = false;
     206           0 :         size_t nNewFocusIndex( _nCondIndex );
     207             :         try
     208             :         {
     209           0 :             if ( !bLastCondition )
     210           0 :                 m_xCopy->removeByIndex( _nCondIndex );
     211             : 
     212           0 :             Conditions::iterator pos = m_aConditions.begin() + _nCondIndex;
     213           0 :             if ( bLastCondition )
     214             :             {
     215           0 :                 Reference< XFormatCondition > xFormatCondition( m_xCopy->getByIndex( 0 ), UNO_QUERY_THROW );
     216           0 :                 xFormatCondition->setFormula( OUString() );
     217           0 :                 (*pos)->setCondition( xFormatCondition );
     218             :             }
     219             :             else
     220             :             {
     221           0 :                 bSetNewFocus = (*pos)->HasChildPathFocus();
     222           0 :                 m_bDeletingCondition = true;
     223           0 :                 m_aConditions.erase( pos );
     224           0 :                 m_bDeletingCondition = false;
     225             :             }
     226             : 
     227           0 :             if ( bSetNewFocus )
     228             :             {
     229           0 :                 if ( nNewFocusIndex >= impl_getConditionCount() )
     230           0 :                     nNewFocusIndex = impl_getConditionCount() - 1;
     231             :             }
     232             :         }
     233           0 :         catch( const Exception& )
     234             :         {
     235             :             DBG_UNHANDLED_EXCEPTION();
     236             :         }
     237             : 
     238           0 :         impl_conditionCountChanged();
     239           0 :         if ( bSetNewFocus )
     240           0 :             impl_focusCondition( nNewFocusIndex );
     241           0 :     }
     242             : 
     243             :     // -----------------------------------------------------------------------------
     244           0 :     void ConditionalFormattingDialog::impl_moveCondition_nothrow( size_t _nCondIndex, bool _bMoveUp )
     245             :     {
     246           0 :         size_t nOldConditionIndex( _nCondIndex );
     247           0 :         size_t nNewConditionIndex( _bMoveUp ? _nCondIndex - 1 : _nCondIndex + 1 );
     248             : 
     249             :         // do this in two steps, so we don't become inconsistent if any of the UNO actions fails
     250           0 :         Any aMovedCondition;
     251           0 :         ConditionPtr pMovedCondition;
     252             :         try
     253             :         {
     254           0 :             aMovedCondition = m_xCopy->getByIndex( (sal_Int32)nOldConditionIndex );
     255           0 :             m_xCopy->removeByIndex( (sal_Int32)nOldConditionIndex );
     256             : 
     257           0 :             Conditions::iterator aRemovePos( m_aConditions.begin() + nOldConditionIndex );
     258           0 :             pMovedCondition = *aRemovePos;
     259           0 :             m_aConditions.erase( aRemovePos );
     260             :         }
     261           0 :         catch( const Exception& )
     262             :         {
     263             :             DBG_UNHANDLED_EXCEPTION();
     264           0 :             return;
     265             :         }
     266             : 
     267             :         try
     268             :         {
     269           0 :             m_xCopy->insertByIndex( (sal_Int32)nNewConditionIndex, aMovedCondition );
     270           0 :             m_aConditions.insert( m_aConditions.begin() + nNewConditionIndex, pMovedCondition );
     271             :         }
     272           0 :         catch( const Exception& )
     273             :         {
     274             :             DBG_UNHANDLED_EXCEPTION();
     275             :         }
     276             : 
     277             :         // at least the two swapped conditions need to know their new index
     278           0 :         impl_updateConditionIndicies();
     279             : 
     280             :         // re-layout all conditions
     281           0 :         Point aDummy;
     282           0 :         impl_layoutConditions( aDummy );
     283             : 
     284             :         // ensure the moved condition is visible
     285           0 :         impl_ensureConditionVisible( nNewConditionIndex );
     286             :     }
     287             : 
     288             :     // -----------------------------------------------------------------------------
     289           0 :     long ConditionalFormattingDialog::impl_getConditionWidth() const
     290             :     {
     291           0 :         const Size aDialogSize( GetOutputSizePixel() );
     292           0 :         const Size aScrollBarWidth( LogicToPixel( Size( SCROLLBAR_WIDTH + UNRELATED_CONTROLS, 0 ), MAP_APPFONT ) );
     293           0 :         return aDialogSize.Width() - aScrollBarWidth.Width();
     294             :     }
     295             : 
     296             :     // -----------------------------------------------------------------------------
     297           0 :     IMPL_LINK( ConditionalFormattingDialog, OnScroll, ScrollBar*, /*_pNotInterestedIn*/ )
     298             :     {
     299           0 :         size_t nFirstCondIndex( impl_getFirstVisibleConditionIndex() );
     300           0 :         size_t nFocusCondIndex = impl_getFocusedConditionIndex( nFirstCondIndex );
     301             : 
     302           0 :         Point aDummy;
     303           0 :         impl_layoutConditions( aDummy );
     304             : 
     305           0 :         if ( nFocusCondIndex < nFirstCondIndex )
     306           0 :             impl_focusCondition( nFirstCondIndex );
     307           0 :         else if ( nFocusCondIndex >= nFirstCondIndex + MAX_CONDITIONS )
     308           0 :             impl_focusCondition( nFirstCondIndex + MAX_CONDITIONS - 1 );
     309             : 
     310           0 :         return 0;
     311             :     }
     312             : 
     313             :     // -----------------------------------------------------------------------------
     314           0 :     void ConditionalFormattingDialog::impl_layoutConditions( Point& _out_rBelowLastVisible )
     315             :     {
     316             :         // position the condition's playground
     317           0 :         long nConditionWidth = impl_getConditionWidth();
     318           0 :         long nConditionHeight = LogicToPixel( Size( 0, CONDITION_HEIGHT ), MAP_APPFONT ).Height();
     319           0 :         size_t nVisibleConditions = ::std::min( impl_getConditionCount(), MAX_CONDITIONS );
     320           0 :         Size aPlaygroundSize( nConditionWidth, nVisibleConditions * nConditionHeight );
     321           0 :         m_aConditionPlayground.SetSizePixel( aPlaygroundSize );
     322           0 :         _out_rBelowLastVisible = Point( 0, aPlaygroundSize.Height() );
     323             : 
     324             :         // position the single conditions
     325           0 :         Point aConditionPos( 0, -1 * nConditionHeight * impl_getFirstVisibleConditionIndex() );
     326           0 :         for (   Conditions::const_iterator cond = m_aConditions.begin();
     327           0 :                 cond != m_aConditions.end();
     328             :                 ++cond
     329             :             )
     330             :         {
     331           0 :             (*cond)->setPosSizePixel( aConditionPos.X(), aConditionPos.Y(), nConditionWidth, nConditionHeight );
     332           0 :             aConditionPos.Move( 0, nConditionHeight );
     333             :         }
     334           0 :     }
     335             : 
     336             :     // -----------------------------------------------------------------------------
     337           0 :     void ConditionalFormattingDialog::impl_layoutAll()
     338             :     {
     339             :         // condition's positions
     340           0 :         Point aPos;
     341           0 :         impl_layoutConditions( aPos );
     342             : 
     343             :         // scrollbar size and visibility
     344           0 :         m_aCondScroll.setPosSizePixel( 0, 0, 0, aPos.Y(), WINDOW_POSSIZE_HEIGHT );
     345           0 :         if ( !impl_needScrollBar() )
     346             :             // normalize the position, so it can, in all situations, be used as top index
     347           0 :             m_aCondScroll.SetThumbPos( 0 );
     348             : 
     349             :         // the separator and the buttons below it
     350           0 :         aPos += LogicToPixel( Point( 0 , RELATED_CONTROLS ), MAP_APPFONT );
     351           0 :         m_aSeparator.setPosSizePixel( 0, aPos.Y(), 0, 0, WINDOW_POSSIZE_Y );
     352             : 
     353           0 :         aPos += LogicToPixel( Point( 0 , UNRELATED_CONTROLS ), MAP_APPFONT );
     354           0 :         Window* pWindows[] = { &m_aPB_OK, &m_aPB_CANCEL, &m_aPB_Help };
     355           0 :         for ( size_t i= 0; i < sizeof(pWindows)/sizeof(pWindows[0]); ++i )
     356             :         {
     357           0 :             pWindows[i]->setPosSizePixel( 0, aPos.Y(), 0, 0, WINDOW_POSSIZE_Y );
     358             :         }
     359             : 
     360           0 :         aPos += LogicToPixel( Point( 0, BUTTON_HEIGHT + RELATED_CONTROLS ), MAP_APPFONT );
     361           0 :         setPosSizePixel( 0, 0, 0, aPos.Y(), WINDOW_POSSIZE_HEIGHT );
     362           0 :     }
     363             :     // -----------------------------------------------------------------------------
     364           0 :     void ConditionalFormattingDialog::impl_initializeConditions()
     365             :     {
     366             :         try
     367             :         {
     368           0 :             sal_Int32 nCount = m_xCopy->getCount();
     369           0 :             for ( sal_Int32 i = 0; i < nCount ; ++i )
     370             :             {
     371           0 :                 ConditionPtr pCon( new Condition( &m_aConditionPlayground, *this, m_rController ) );
     372           0 :                 Reference< XFormatCondition > xCond( m_xCopy->getByIndex(i), UNO_QUERY );
     373           0 :                 pCon->setCondition( xCond );
     374           0 :                 pCon->updateToolbar( xCond.get() );
     375           0 :                 m_aConditions.push_back( pCon );
     376           0 :             }
     377             :         }
     378           0 :         catch(Exception&)
     379             :         {
     380             :             OSL_FAIL("Can not access format condition!");
     381             :         }
     382             : 
     383           0 :         impl_conditionCountChanged();
     384           0 :     }
     385             : 
     386             :     // -----------------------------------------------------------------------------
     387           0 :     void ConditionalFormattingDialog::applyCommand( size_t _nCondIndex, sal_uInt16 _nCommandId, const ::Color _aColor )
     388             :     {
     389             :         OSL_PRECOND( _nCommandId, "ConditionalFormattingDialog::applyCommand: illegal command id!" );
     390             :         try
     391             :         {
     392           0 :             Reference< XReportControlFormat > xReportControlFormat( m_xCopy->getByIndex( _nCondIndex ), UNO_QUERY_THROW );
     393             : 
     394           0 :             Sequence< PropertyValue > aArgs(3);
     395             : 
     396           0 :             aArgs[0].Name = REPORTCONTROLFORMAT;
     397           0 :             aArgs[0].Value <<= xReportControlFormat;
     398             : 
     399           0 :             aArgs[1].Name = CURRENT_WINDOW;
     400           0 :             aArgs[1].Value <<= VCLUnoHelper::GetInterface(this);
     401             : 
     402           0 :             aArgs[2].Name = PROPERTY_FONTCOLOR;
     403           0 :             aArgs[2].Value <<= (sal_uInt32)_aColor.GetColor();
     404             : 
     405             :             // we use this way to create undo actions
     406           0 :             m_rController.executeUnChecked(_nCommandId,aArgs);
     407           0 :             m_aConditions[ _nCondIndex ]->updateToolbar(xReportControlFormat);
     408             :         }
     409           0 :         catch( Exception& )
     410             :         {
     411             :             DBG_UNHANDLED_EXCEPTION();
     412             :         }
     413           0 :     }
     414             : 
     415             :     // -----------------------------------------------------------------------------
     416           0 :     void ConditionalFormattingDialog::moveConditionUp( size_t _nCondIndex )
     417             :     {
     418             :         OSL_PRECOND( _nCondIndex > 0, "ConditionalFormattingDialog::moveConditionUp: cannot move up the first condition!" );
     419           0 :         if ( _nCondIndex > 0 )
     420           0 :             impl_moveCondition_nothrow( _nCondIndex, true );
     421           0 :     }
     422             : 
     423             :     // -----------------------------------------------------------------------------
     424           0 :     void ConditionalFormattingDialog::moveConditionDown( size_t _nCondIndex )
     425             :     {
     426             :         OSL_PRECOND( _nCondIndex < impl_getConditionCount(), "ConditionalFormattingDialog::moveConditionDown: cannot move down the last condition!" );
     427           0 :         if ( _nCondIndex < impl_getConditionCount() )
     428           0 :             impl_moveCondition_nothrow( _nCondIndex, false );
     429           0 :     }
     430             : 
     431             :     // -----------------------------------------------------------------------------
     432           0 :     OUString ConditionalFormattingDialog::getDataField() const
     433             :     {
     434           0 :         OUString sDataField;
     435             :         try
     436             :         {
     437           0 :             sDataField = m_xFormatConditions->getDataField();
     438             :         }
     439           0 :         catch( const Exception& )
     440             :         {
     441             :             DBG_UNHANDLED_EXCEPTION();
     442             :         }
     443           0 :         return sDataField;
     444             :     }
     445             : 
     446             :     // -----------------------------------------------------------------------------
     447           0 :     short ConditionalFormattingDialog::Execute()
     448             :     {
     449           0 :         short nRet = ModalDialog::Execute();
     450           0 :         if ( nRet == RET_OK )
     451             :         {
     452           0 :             const String sUndoAction( ModuleRes( RID_STR_UNDO_CONDITIONAL_FORMATTING ) );
     453           0 :             const UndoContext aUndoContext( m_rController.getUndoManager(), sUndoAction );
     454             :             try
     455             :             {
     456           0 :                 sal_Int32 j(0), i(0);;
     457           0 :                 for (   Conditions::const_iterator cond = m_aConditions.begin();
     458           0 :                         cond != m_aConditions.end();
     459             :                         ++cond, ++i
     460             :                     )
     461             :                 {
     462           0 :                     Reference< XFormatCondition > xCond( m_xCopy->getByIndex(i), UNO_QUERY_THROW );
     463           0 :                     (*cond)->fillFormatCondition( xCond );
     464             : 
     465           0 :                     if ( (*cond)->isEmpty() )
     466           0 :                         continue;
     467             : 
     468           0 :                     Reference< XFormatCondition > xNewCond;
     469           0 :                     sal_Bool bAppend = j >= m_xFormatConditions->getCount();
     470           0 :                     if ( bAppend )
     471             :                     {
     472           0 :                         xNewCond = m_xFormatConditions->createFormatCondition();
     473           0 :                         m_xFormatConditions->insertByIndex( i, makeAny( xNewCond ) );
     474             :                     }
     475             :                     else
     476           0 :                         xNewCond.set( m_xFormatConditions->getByIndex(j), UNO_QUERY );
     477           0 :                     ++j;
     478             : 
     479           0 :                     ::comphelper::copyProperties(xCond.get(),xNewCond.get());
     480           0 :                 }
     481             : 
     482           0 :                 for ( sal_Int32 k = m_xFormatConditions->getCount()-1; k >= j; --k )
     483           0 :                     m_xFormatConditions->removeByIndex(k);
     484             : 
     485           0 :                 ::comphelper::copyProperties( m_xCopy.get(), m_xFormatConditions.get() );
     486             :             }
     487           0 :             catch ( const Exception& )
     488             :             {
     489             :                 DBG_UNHANDLED_EXCEPTION();
     490           0 :                 nRet = RET_NO;
     491           0 :             }
     492             :         }
     493           0 :         return nRet;
     494             :     }
     495             : 
     496             :     // -----------------------------------------------------------------------------
     497           0 :     long ConditionalFormattingDialog::PreNotify( NotifyEvent& _rNEvt )
     498             :     {
     499           0 :         switch ( _rNEvt.GetType() )
     500             :         {
     501             :         case EVENT_KEYINPUT:
     502             :         {
     503           0 :             const KeyEvent* pKeyEvent( _rNEvt.GetKeyEvent() );
     504           0 :             const KeyCode& rKeyCode = pKeyEvent->GetKeyCode();
     505           0 :             if ( rKeyCode.IsMod1() && rKeyCode.IsMod2() )
     506             :             {
     507           0 :                 if ( rKeyCode.GetCode() == 0x0508 ) // -
     508             :                 {
     509           0 :                     impl_deleteCondition_nothrow( impl_getFocusedConditionIndex( 0 ) );
     510           0 :                     return 1;
     511             :                 }
     512           0 :                 if ( rKeyCode.GetCode() == 0x0507 ) // +
     513             :                 {
     514           0 :                     impl_addCondition_nothrow( impl_getFocusedConditionIndex( impl_getConditionCount() - 1 ) + 1 );
     515           0 :                     return 1;
     516             :                 }
     517             :             }
     518             :         }
     519           0 :         break;
     520             :         case EVENT_GETFOCUS:
     521             :         {
     522           0 :             if ( m_bDeletingCondition )
     523           0 :                 break;
     524             : 
     525           0 :             const Window* pGetFocusWindow( _rNEvt.GetWindow() );
     526             : 
     527             :             // determine whether the new focus window is part of an (currently invisible) condition
     528           0 :             const Window* pConditionCandidate = pGetFocusWindow->GetParent();
     529           0 :             const Window* pPlaygroundCandidate = pConditionCandidate ? pConditionCandidate->GetParent() : NULL;
     530           0 :             while   (   ( pPlaygroundCandidate )
     531           0 :                     &&  ( pPlaygroundCandidate != this )
     532           0 :                     &&  ( pPlaygroundCandidate != &m_aConditionPlayground )
     533             :                     )
     534             :             {
     535           0 :                 pConditionCandidate = pConditionCandidate->GetParent();
     536           0 :                 pPlaygroundCandidate = pConditionCandidate ? pConditionCandidate->GetParent() : NULL;
     537             :             }
     538           0 :             if ( pPlaygroundCandidate == &m_aConditionPlayground )
     539             :             {
     540           0 :                 impl_ensureConditionVisible( dynamic_cast< const Condition& >( *pConditionCandidate ).getConditionIndex() );
     541             :             }
     542             :         }
     543           0 :         break;
     544             :         }
     545             : 
     546           0 :         return ModalDialog::PreNotify( _rNEvt );
     547             :     }
     548             : 
     549             :     // -----------------------------------------------------------------------------
     550           0 :     size_t ConditionalFormattingDialog::impl_getFirstVisibleConditionIndex() const
     551             :     {
     552           0 :         return (size_t)m_aCondScroll.GetThumbPos();
     553             :     }
     554             : 
     555             :     // -----------------------------------------------------------------------------
     556           0 :     size_t ConditionalFormattingDialog::impl_getLastVisibleConditionIndex() const
     557             :     {
     558           0 :         return ::std::min( impl_getFirstVisibleConditionIndex() + MAX_CONDITIONS, impl_getConditionCount() ) - 1;
     559             :     }
     560             : 
     561             :     // -----------------------------------------------------------------------------
     562           0 :     size_t ConditionalFormattingDialog::impl_getFocusedConditionIndex( sal_Int32 _nFallBackIfNone ) const
     563             :     {
     564           0 :         size_t nIndex( 0 );
     565           0 :         for (   Conditions::const_iterator cond = m_aConditions.begin();
     566           0 :                 cond != m_aConditions.end();
     567             :                 ++cond, ++nIndex
     568             :             )
     569             :         {
     570           0 :             if ( (*cond)->HasChildPathFocus() )
     571           0 :                 return nIndex;
     572             :         }
     573           0 :         return _nFallBackIfNone;
     574             :     }
     575             : 
     576             :     // -----------------------------------------------------------------------------
     577           0 :     void ConditionalFormattingDialog::impl_updateScrollBarRange()
     578             :     {
     579           0 :         long nMax = ( impl_getConditionCount() > MAX_CONDITIONS ) ? impl_getConditionCount() - MAX_CONDITIONS + 1 : 0;
     580             : 
     581           0 :         m_aCondScroll.SetRangeMin( 0 );
     582           0 :         m_aCondScroll.SetRangeMax( nMax );
     583           0 :         m_aCondScroll.SetVisibleSize( 1 );
     584           0 :     }
     585             : 
     586             :     // -----------------------------------------------------------------------------
     587           0 :     void ConditionalFormattingDialog::impl_scrollTo( size_t _nTopCondIndex )
     588             :     {
     589             :         OSL_PRECOND( _nTopCondIndex + MAX_CONDITIONS <= impl_getConditionCount(),
     590             :             "ConditionalFormattingDialog::impl_scrollTo: illegal index!" );
     591           0 :         m_aCondScroll.SetThumbPos( _nTopCondIndex );
     592           0 :         OnScroll( &m_aCondScroll );
     593           0 :     }
     594             : 
     595             :     // -----------------------------------------------------------------------------
     596           0 :     void ConditionalFormattingDialog::impl_ensureConditionVisible( size_t _nCondIndex )
     597             :     {
     598             :         OSL_PRECOND( _nCondIndex < impl_getConditionCount(),
     599             :             "ConditionalFormattingDialog::impl_ensureConditionVisible: illegal index!" );
     600             : 
     601           0 :         if ( _nCondIndex < impl_getFirstVisibleConditionIndex() )
     602           0 :             impl_scrollTo( _nCondIndex );
     603           0 :         else if ( _nCondIndex > impl_getLastVisibleConditionIndex() )
     604           0 :             impl_scrollTo( _nCondIndex - MAX_CONDITIONS + 1 );
     605           0 :     }
     606             : 
     607             : // .............................................................................
     608           0 : } // rptui
     609             : // .............................................................................
     610             : 
     611             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10