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