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