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