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 "filtnav.hxx"
30 : : #include "fmexch.hxx"
31 : : #include "fmhelp.hrc"
32 : : #include "fmitems.hxx"
33 : : #include "fmprop.hrc"
34 : : #include "svx/fmresids.hrc"
35 : :
36 : : #include <com/sun/star/awt/XControlModel.hpp>
37 : : #include <com/sun/star/awt/XControl.hpp>
38 : : #include <com/sun/star/awt/XTextComponent.hpp>
39 : : #include <com/sun/star/form/runtime/XFormController.hpp>
40 : : #include <com/sun/star/lang/XUnoTunnel.hpp>
41 : : #include <com/sun/star/util/XNumberFormatter.hpp>
42 : : #include <com/sun/star/beans/XFastPropertySet.hpp>
43 : :
44 : : #include <comphelper/processfactory.hxx>
45 : : #include <comphelper/property.hxx>
46 : : #include <comphelper/sequence.hxx>
47 : : #include <comphelper/string.hxx>
48 : : #include <comphelper/uno3.hxx>
49 : : #include <connectivity/dbtools.hxx>
50 : : #include <cppuhelper/implbase1.hxx>
51 : : #include <fmservs.hxx>
52 : : #include <fmshimp.hxx>
53 : : #include <rtl/logfile.hxx>
54 : : #include <sfx2/dispatch.hxx>
55 : : #include <sfx2/objitem.hxx>
56 : : #include <sfx2/objsh.hxx>
57 : : #include <sfx2/request.hxx>
58 : : #include <svx/dialmgr.hxx>
59 : : #include <svx/fmshell.hxx>
60 : : #include <svx/fmtools.hxx>
61 : : #include <svx/svxids.hrc>
62 : : #include <tools/shl.hxx>
63 : : #include <vcl/wrkwin.hxx>
64 : : #include <tools/diagnose_ex.h>
65 : :
66 : : #include <functional>
67 : :
68 : : #define DROP_ACTION_TIMER_INITIAL_TICKS 10
69 : : // solange dauert es, bis das Scrollen anspringt
70 : : #define DROP_ACTION_TIMER_SCROLL_TICKS 3
71 : : // in diesen Intervallen wird jeweils eine Zeile gescrollt
72 : : #define DROP_ACTION_TIMER_TICK_BASE 10
73 : : // das ist die Basis, mit der beide Angaben multipliziert werden (in ms)
74 : :
75 : : using namespace ::svxform;
76 : : using namespace ::connectivity::simple;
77 : : using namespace ::connectivity;
78 : :
79 : :
80 : : //........................................................................
81 : : namespace svxform
82 : : {
83 : : //........................................................................
84 : :
85 : : /** === begin UNO using === **/
86 : : using ::com::sun::star::uno::Reference;
87 : : using ::com::sun::star::lang::XMultiServiceFactory;
88 : : using ::com::sun::star::awt::TextEvent;
89 : : using ::com::sun::star::container::XIndexAccess;
90 : : using ::com::sun::star::uno::UNO_QUERY;
91 : : using ::com::sun::star::beans::XPropertySet;
92 : : using ::com::sun::star::form::runtime::XFormController;
93 : : using ::com::sun::star::form::runtime::XFilterController;
94 : : using ::com::sun::star::form::runtime::XFilterControllerListener;
95 : : using ::com::sun::star::form::runtime::FilterEvent;
96 : : using ::com::sun::star::lang::EventObject;
97 : : using ::com::sun::star::uno::RuntimeException;
98 : : using ::com::sun::star::form::XForm;
99 : : using ::com::sun::star::container::XChild;
100 : : using ::com::sun::star::awt::XControl;
101 : : using ::com::sun::star::sdbc::XConnection;
102 : : using ::com::sun::star::util::XNumberFormatsSupplier;
103 : : using ::com::sun::star::beans::XPropertySet;
104 : : using ::com::sun::star::util::XNumberFormatter;
105 : : using ::com::sun::star::sdbc::XRowSet;
106 : : using ::com::sun::star::lang::Locale;
107 : : using ::com::sun::star::sdb::SQLContext;
108 : : using ::com::sun::star::uno::XInterface;
109 : : using ::com::sun::star::uno::UNO_QUERY_THROW;
110 : : using ::com::sun::star::uno::UNO_SET_THROW;
111 : : using ::com::sun::star::uno::Exception;
112 : : using ::com::sun::star::awt::XTextComponent;
113 : : using ::com::sun::star::uno::Sequence;
114 : : /** === end UNO using === **/
115 : :
116 : : //========================================================================
117 [ # # ]: 0 : OFilterItemExchange::OFilterItemExchange()
118 : : {
119 : 0 : }
120 : :
121 : : //------------------------------------------------------------------------
122 : 0 : void OFilterItemExchange::AddSupportedFormats()
123 : : {
124 : 0 : AddFormat(getFormatId());
125 : 0 : }
126 : :
127 : : //------------------------------------------------------------------------
128 : 0 : sal_uInt32 OFilterItemExchange::getFormatId()
129 : : {
130 : : static sal_uInt32 s_nFormat = (sal_uInt32)-1;
131 [ # # ]: 0 : if ((sal_uInt32)-1 == s_nFormat)
132 : : {
133 [ # # ][ # # ]: 0 : s_nFormat = SotExchange::RegisterFormatName(rtl::OUString("application/x-openoffice;windows_formatname=\"form.FilterControlExchange\""));
[ # # ]
134 : : DBG_ASSERT((sal_uInt32)-1 != s_nFormat, "OFilterExchangeHelper::getFormatId: bad exchange id!");
135 : : }
136 : 0 : return s_nFormat;
137 : : }
138 : :
139 : : //------------------------------------------------------------------------
140 : 0 : OLocalExchange* OFilterExchangeHelper::createExchange() const
141 : : {
142 [ # # ]: 0 : return new OFilterItemExchange;
143 : : }
144 : :
145 : : //========================================================================
146 [ # # ]: 0 : TYPEINIT0(FmFilterData);
147 : 0 : Image FmFilterData::GetImage() const
148 : : {
149 : 0 : return Image();
150 : : }
151 : :
152 : : //========================================================================
153 [ # # ][ # # ]: 0 : TYPEINIT1(FmParentData, FmFilterData);
154 : : //------------------------------------------------------------------------
155 : 0 : FmParentData::~FmParentData()
156 : : {
157 [ # # ][ # # ]: 0 : for (::std::vector<FmFilterData*>::const_iterator i = m_aChildren.begin();
[ # # ]
158 : 0 : i != m_aChildren.end(); ++i)
159 [ # # ][ # # ]: 0 : delete (*i);
160 [ # # ]: 0 : }
161 : :
162 : : //========================================================================
163 [ # # ][ # # ]: 0 : TYPEINIT1(FmFormItem, FmParentData);
164 : : //------------------------------------------------------------------------
165 : 0 : Image FmFormItem::GetImage() const
166 : : {
167 [ # # ][ # # ]: 0 : static Image aImage;
[ # # ][ # # ]
168 : :
169 [ # # ]: 0 : if (!aImage)
170 : : {
171 [ # # ][ # # ]: 0 : ImageList aNavigatorImages( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
172 [ # # ][ # # ]: 0 : aImage = aNavigatorImages.GetImage( RID_SVXIMG_FORM );
[ # # ][ # # ]
173 : : }
174 : 0 : return aImage;
175 : : }
176 : :
177 : : //========================================================================
178 [ # # ][ # # ]: 0 : TYPEINIT1(FmFilterItems, FmParentData);
179 : : //------------------------------------------------------------------------
180 : 0 : FmFilterItem* FmFilterItems::Find( const ::sal_Int32 _nFilterComponentIndex ) const
181 : : {
182 [ # # ][ # # ]: 0 : for ( ::std::vector< FmFilterData* >::const_iterator i = m_aChildren.begin();
183 : 0 : i != m_aChildren.end();
184 : : ++i
185 : : )
186 : : {
187 [ # # ][ # # ]: 0 : FmFilterItem* pCondition = PTR_CAST( FmFilterItem, *i );
[ # # ]
188 : : DBG_ASSERT( pCondition, "FmFilterItems::Find: Wrong element in container!" );
189 [ # # ]: 0 : if ( _nFilterComponentIndex == pCondition->GetComponentIndex() )
190 : 0 : return pCondition;
191 : : }
192 : 0 : return NULL;
193 : : }
194 : :
195 : : //------------------------------------------------------------------------
196 : 0 : Image FmFilterItems::GetImage() const
197 : : {
198 [ # # ][ # # ]: 0 : static Image aImage;
[ # # ][ # # ]
199 : :
200 [ # # ]: 0 : if (!aImage)
201 : : {
202 [ # # ][ # # ]: 0 : ImageList aNavigatorImages( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
203 [ # # ][ # # ]: 0 : aImage = aNavigatorImages.GetImage( RID_SVXIMG_FILTER );
[ # # ][ # # ]
204 : : }
205 : 0 : return aImage;
206 : : }
207 : :
208 : : //========================================================================
209 [ # # ][ # # ]: 0 : TYPEINIT1(FmFilterItem, FmFilterData);
210 : : //------------------------------------------------------------------------
211 : 0 : FmFilterItem::FmFilterItem( const Reference< XMultiServiceFactory >& _rxFactory,
212 : : FmFilterItems* pParent,
213 : : const ::rtl::OUString& aFieldName,
214 : : const ::rtl::OUString& aText,
215 : : const sal_Int32 _nComponentIndex )
216 : : :FmFilterData(_rxFactory,pParent, aText)
217 : : ,m_aFieldName(aFieldName)
218 : 0 : ,m_nComponentIndex( _nComponentIndex )
219 : : {
220 : 0 : }
221 : :
222 : : //------------------------------------------------------------------------
223 : 0 : Image FmFilterItem::GetImage() const
224 : : {
225 [ # # ][ # # ]: 0 : static Image aImage;
[ # # ][ # # ]
226 : :
227 [ # # ]: 0 : if (!aImage)
228 : : {
229 [ # # ][ # # ]: 0 : ImageList aNavigatorImages( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
230 [ # # ][ # # ]: 0 : aImage = aNavigatorImages.GetImage( RID_SVXIMG_FIELD );
[ # # ][ # # ]
231 : : }
232 : 0 : return aImage;
233 : : }
234 : :
235 : : //========================================================================
236 : : // Hints for communicatition between model and view
237 : : //========================================================================
238 [ # # ]: 0 : class FmFilterHint : public SfxHint
239 : : {
240 : : FmFilterData* m_pData;
241 : :
242 : : public:
243 : : TYPEINFO();
244 : 0 : FmFilterHint(FmFilterData* pData):m_pData(pData){}
245 : 0 : FmFilterData* GetData() const { return m_pData; }
246 : : };
247 [ # # ][ # # ]: 0 : TYPEINIT1( FmFilterHint, SfxHint );
248 : :
249 : : //========================================================================
250 [ # # ]: 0 : class FmFilterInsertedHint : public FmFilterHint
251 : : {
252 : : sal_uLong m_nPos; // Position relative to the parent of the data
253 : :
254 : : public:
255 : : TYPEINFO();
256 : 0 : FmFilterInsertedHint(FmFilterData* pData, sal_uLong nRelPos)
257 : : :FmFilterHint(pData)
258 : 0 : ,m_nPos(nRelPos){}
259 : :
260 : 0 : sal_uLong GetPos() const { return m_nPos; }
261 : : };
262 [ # # ][ # # ]: 0 : TYPEINIT1( FmFilterInsertedHint, FmFilterHint );
263 : :
264 : : //========================================================================
265 [ # # ]: 0 : class FmFilterRemovedHint : public FmFilterHint
266 : : {
267 : : public:
268 : : TYPEINFO();
269 : 0 : FmFilterRemovedHint(FmFilterData* pData)
270 : 0 : :FmFilterHint(pData){}
271 : :
272 : : };
273 [ # # ][ # # ]: 0 : TYPEINIT1( FmFilterRemovedHint, FmFilterHint );
274 : :
275 : : //========================================================================
276 [ # # ]: 0 : class FmFilterTextChangedHint : public FmFilterHint
277 : : {
278 : : public:
279 : : TYPEINFO();
280 : 0 : FmFilterTextChangedHint(FmFilterData* pData)
281 : 0 : :FmFilterHint(pData){}
282 : :
283 : : };
284 [ # # ][ # # ]: 0 : TYPEINIT1( FmFilterTextChangedHint, FmFilterHint );
285 : :
286 : : //========================================================================
287 [ # # ]: 0 : class FilterClearingHint : public SfxHint
288 : : {
289 : : public:
290 : : TYPEINFO();
291 : 0 : FilterClearingHint(){}
292 : : };
293 [ # # ][ # # ]: 0 : TYPEINIT1( FilterClearingHint, SfxHint );
294 : :
295 : : //========================================================================
296 [ # # ]: 0 : class FmFilterCurrentChangedHint : public SfxHint
297 : : {
298 : : public:
299 : : TYPEINFO();
300 : 0 : FmFilterCurrentChangedHint(){}
301 : : };
302 [ # # ][ # # ]: 0 : TYPEINIT1( FmFilterCurrentChangedHint, SfxHint );
303 : :
304 : : //========================================================================
305 : : // class FmFilterAdapter, Listener an den FilterControls
306 : : //========================================================================
307 [ # # ]: 0 : class FmFilterAdapter : public ::cppu::WeakImplHelper1< XFilterControllerListener >
308 : : {
309 : : FmFilterModel* m_pModel;
310 : : Reference< XIndexAccess > m_xControllers;
311 : :
312 : : public:
313 : : FmFilterAdapter(FmFilterModel* pModel, const Reference< XIndexAccess >& xControllers);
314 : :
315 : : // XEventListener
316 : : virtual void SAL_CALL disposing(const EventObject& Source) throw( RuntimeException );
317 : :
318 : : // XFilterControllerListener
319 : : virtual void SAL_CALL predicateExpressionChanged( const FilterEvent& _Event ) throw (RuntimeException);
320 : : virtual void SAL_CALL disjunctiveTermRemoved( const FilterEvent& _Event ) throw (RuntimeException);
321 : : virtual void SAL_CALL disjunctiveTermAdded( const FilterEvent& _Event ) throw (RuntimeException);
322 : :
323 : : // helpers
324 : : void dispose() throw( RuntimeException );
325 : :
326 : : void AddOrRemoveListener( const Reference< XIndexAccess >& _rxControllers, const bool _bAdd );
327 : :
328 : : void setText(sal_Int32 nPos,
329 : : const FmFilterItem* pFilterItem,
330 : : const ::rtl::OUString& rText);
331 : : };
332 : :
333 : : //------------------------------------------------------------------------
334 : 0 : FmFilterAdapter::FmFilterAdapter(FmFilterModel* pModel, const Reference< XIndexAccess >& xControllers)
335 : : :m_pModel( pModel )
336 : 0 : ,m_xControllers( xControllers )
337 : : {
338 [ # # ]: 0 : AddOrRemoveListener( m_xControllers, true );
339 : 0 : }
340 : :
341 : : //------------------------------------------------------------------------
342 : 0 : void FmFilterAdapter::dispose() throw( RuntimeException )
343 : : {
344 : 0 : AddOrRemoveListener( m_xControllers, false );
345 : 0 : }
346 : :
347 : : //------------------------------------------------------------------------
348 : 0 : void FmFilterAdapter::AddOrRemoveListener( const Reference< XIndexAccess >& _rxControllers, const bool _bAdd )
349 : : {
350 [ # # ]: 0 : for (sal_Int32 i = 0, nLen = _rxControllers->getCount(); i < nLen; ++i)
351 : : {
352 [ # # ][ # # ]: 0 : Reference< XIndexAccess > xElement( _rxControllers->getByIndex(i), UNO_QUERY );
[ # # ]
353 : :
354 : : // step down
355 [ # # ]: 0 : AddOrRemoveListener( xElement, _bAdd );
356 : :
357 : : // handle this particular controller
358 [ # # ]: 0 : Reference< XFilterController > xController( xElement, UNO_QUERY );
359 : : OSL_ENSURE( xController.is(), "FmFilterAdapter::InsertElements: no XFilterController, cannot sync data!" );
360 [ # # ]: 0 : if ( xController.is() )
361 : : {
362 [ # # ]: 0 : if ( _bAdd )
363 [ # # ][ # # ]: 0 : xController->addFilterControllerListener( this );
[ # # ]
364 : : else
365 [ # # ][ # # ]: 0 : xController->removeFilterControllerListener( this );
[ # # ]
366 : : }
367 : 0 : }
368 : 0 : }
369 : :
370 : : //------------------------------------------------------------------------
371 : 0 : void FmFilterAdapter::setText(sal_Int32 nRowPos,
372 : : const FmFilterItem* pFilterItem,
373 : : const ::rtl::OUString& rText)
374 : : {
375 [ # # ][ # # ]: 0 : FmFormItem* pFormItem = PTR_CAST( FmFormItem, pFilterItem->GetParent()->GetParent() );
376 : :
377 : : try
378 : : {
379 [ # # ]: 0 : Reference< XFilterController > xController( pFormItem->GetController(), UNO_QUERY_THROW );
380 [ # # ][ # # ]: 0 : xController->setPredicateExpression( pFilterItem->GetComponentIndex(), nRowPos, rText );
[ # # ]
381 : : }
382 : 0 : catch( const Exception& )
383 : : {
384 : : DBG_UNHANDLED_EXCEPTION();
385 : : }
386 : 0 : }
387 : :
388 : :
389 : : // XEventListener
390 : : //------------------------------------------------------------------------
391 : 0 : void SAL_CALL FmFilterAdapter::disposing(const EventObject& /*e*/) throw( RuntimeException )
392 : : {
393 : 0 : }
394 : :
395 : : //------------------------------------------------------------------------
396 : : namespace
397 : : {
398 : 0 : ::rtl::OUString lcl_getLabelName_nothrow( const Reference< XControl >& _rxControl )
399 : : {
400 : 0 : ::rtl::OUString sLabelName;
401 : : try
402 : : {
403 [ # # ]: 0 : Reference< XControl > xControl( _rxControl, UNO_SET_THROW );
404 [ # # ][ # # ]: 0 : Reference< XPropertySet > xModel( xControl->getModel(), UNO_QUERY_THROW );
[ # # ]
405 [ # # ][ # # ]: 0 : sLabelName = getLabelName( xModel );
406 : : }
407 [ # # ]: 0 : catch( const Exception& )
408 : : {
409 : : DBG_UNHANDLED_EXCEPTION();
410 : : }
411 : 0 : return sLabelName;
412 : : }
413 : :
414 : 0 : Reference< XPropertySet > lcl_getBoundField_nothrow( const Reference< XControl >& _rxControl )
415 : : {
416 : 0 : Reference< XPropertySet > xField;
417 : : try
418 : : {
419 [ # # ]: 0 : Reference< XControl > xControl( _rxControl, UNO_SET_THROW );
420 [ # # ][ # # ]: 0 : Reference< XPropertySet > xModelProps( xControl->getModel(), UNO_QUERY_THROW );
[ # # ]
421 [ # # ][ # # ]: 0 : xField.set( xModelProps->getPropertyValue( FM_PROP_BOUNDFIELD ), UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ]
422 : : }
423 [ # # ]: 0 : catch( const Exception& )
424 : : {
425 : : DBG_UNHANDLED_EXCEPTION();
426 : : }
427 : 0 : return xField;
428 : : }
429 : : }
430 : :
431 : : // XFilterControllerListener
432 : : //------------------------------------------------------------------------
433 : 0 : void FmFilterAdapter::predicateExpressionChanged( const FilterEvent& _Event ) throw( RuntimeException )
434 : : {
435 [ # # ]: 0 : SolarMutexGuard aGuard;
436 : :
437 [ # # ]: 0 : if ( !m_pModel )
438 : : return;
439 : :
440 : : // the controller which sent the event
441 [ # # ]: 0 : Reference< XFormController > xController( _Event.Source, UNO_QUERY_THROW );
442 [ # # ]: 0 : Reference< XFilterController > xFilterController( _Event.Source, UNO_QUERY_THROW );
443 [ # # ][ # # ]: 0 : Reference< XForm > xForm( xController->getModel(), UNO_QUERY_THROW );
[ # # ]
444 : :
445 [ # # ]: 0 : FmFormItem* pFormItem = m_pModel->Find( m_pModel->m_aChildren, xForm );
446 : : OSL_ENSURE( pFormItem, "FmFilterAdapter::predicateExpressionChanged: don't know this form!" );
447 [ # # ]: 0 : if ( !pFormItem )
448 : : return;
449 : :
450 [ # # ][ # # ]: 0 : const sal_Int32 nActiveTerm( xFilterController->getActiveTerm() );
451 : :
452 [ # # ][ # # ]: 0 : FmFilterItems* pFilter = PTR_CAST( FmFilterItems, pFormItem->GetChildren()[ nActiveTerm ] );
[ # # ]
453 [ # # ]: 0 : FmFilterItem* pFilterItem = pFilter->Find( _Event.FilterComponent );
454 [ # # ]: 0 : if ( pFilterItem )
455 : : {
456 [ # # ]: 0 : if ( !_Event.PredicateExpression.isEmpty())
457 : : {
458 : 0 : pFilterItem->SetText( _Event.PredicateExpression );
459 : : // UI benachrichtigen
460 [ # # ]: 0 : FmFilterTextChangedHint aChangeHint(pFilterItem);
461 [ # # ][ # # ]: 0 : m_pModel->Broadcast( aChangeHint );
462 : : }
463 : : else
464 : : {
465 : : // no text anymore so remove the condition
466 [ # # ]: 0 : m_pModel->Remove(pFilterItem);
467 : : }
468 : : }
469 : : else
470 : : {
471 : : // searching the component by field name
472 [ # # ][ # # ]: 0 : ::rtl::OUString aFieldName( lcl_getLabelName_nothrow( xFilterController->getFilterComponent( _Event.FilterComponent ) ) );
[ # # ]
473 : :
474 [ # # ][ # # ]: 0 : pFilterItem = new FmFilterItem( m_pModel->getORB(), pFilter, aFieldName, _Event.PredicateExpression, _Event.FilterComponent );
[ # # ]
475 [ # # ]: 0 : m_pModel->Insert(pFilter->GetChildren().end(), pFilterItem);
476 : : }
477 : :
478 : : // ensure there's one empty term in the filter, just in case the active term was previously empty
479 [ # # ][ # # ]: 0 : m_pModel->EnsureEmptyFilterRows( *pFormItem );
[ # # ][ # # ]
[ # # ][ # # ]
480 : : }
481 : :
482 : : //------------------------------------------------------------------------
483 : 0 : void SAL_CALL FmFilterAdapter::disjunctiveTermRemoved( const FilterEvent& _Event ) throw (RuntimeException)
484 : : {
485 [ # # ]: 0 : SolarMutexGuard aGuard;
486 : :
487 [ # # ]: 0 : Reference< XFormController > xController( _Event.Source, UNO_QUERY_THROW );
488 [ # # ]: 0 : Reference< XFilterController > xFilterController( _Event.Source, UNO_QUERY_THROW );
489 [ # # ][ # # ]: 0 : Reference< XForm > xForm( xController->getModel(), UNO_QUERY_THROW );
[ # # ]
490 : :
491 [ # # ]: 0 : FmFormItem* pFormItem = m_pModel->Find( m_pModel->m_aChildren, xForm );
492 : : OSL_ENSURE( pFormItem, "FmFilterAdapter::disjunctiveTermRemoved: don't know this form!" );
493 [ # # ]: 0 : if ( !pFormItem )
494 : : return;
495 : :
496 : 0 : ::std::vector< FmFilterData* >& rTermItems = pFormItem->GetChildren();
497 [ # # ][ # # ]: 0 : const bool bValidIndex = ( _Event.DisjunctiveTerm >= 0 ) && ( (size_t)_Event.DisjunctiveTerm < rTermItems.size() );
498 : : OSL_ENSURE( bValidIndex, "FmFilterAdapter::disjunctiveTermRemoved: invalid term index!" );
499 [ # # ]: 0 : if ( !bValidIndex )
500 : : return;
501 : :
502 : : // if the first term was removed, then the to-be first term needs its text updated
503 [ # # ]: 0 : if ( _Event.DisjunctiveTerm == 0 )
504 : : {
505 [ # # ][ # # ]: 0 : rTermItems[1]->SetText( String( SVX_RES( RID_STR_FILTER_FILTER_FOR ) ) );
[ # # ][ # # ]
506 [ # # ]: 0 : FmFilterTextChangedHint aChangeHint( rTermItems[1] );
507 [ # # ][ # # ]: 0 : m_pModel->Broadcast( aChangeHint );
508 : : }
509 : :
510 : : // finally remove the entry from the model
511 [ # # ][ # # ]: 0 : m_pModel->Remove( rTermItems.begin() + _Event.DisjunctiveTerm );
512 : :
513 : : // ensure there's one empty term in the filter, just in case the currently removed one was the last empty one
514 [ # # ][ # # ]: 0 : m_pModel->EnsureEmptyFilterRows( *pFormItem );
[ # # ][ # # ]
[ # # ][ # # ]
515 : : }
516 : :
517 : : //------------------------------------------------------------------------
518 : 0 : void SAL_CALL FmFilterAdapter::disjunctiveTermAdded( const FilterEvent& _Event ) throw (RuntimeException)
519 : : {
520 [ # # ]: 0 : SolarMutexGuard aGuard;
521 : :
522 [ # # ]: 0 : Reference< XFormController > xController( _Event.Source, UNO_QUERY_THROW );
523 [ # # ]: 0 : Reference< XFilterController > xFilterController( _Event.Source, UNO_QUERY_THROW );
524 [ # # ][ # # ]: 0 : Reference< XForm > xForm( xController->getModel(), UNO_QUERY_THROW );
[ # # ]
525 : :
526 [ # # ]: 0 : FmFormItem* pFormItem = m_pModel->Find( m_pModel->m_aChildren, xForm );
527 : : OSL_ENSURE( pFormItem, "FmFilterAdapter::disjunctiveTermAdded: don't know this form!" );
528 [ # # ]: 0 : if ( !pFormItem )
529 : : return;
530 : :
531 : 0 : const sal_Int32 nInsertPos = _Event.DisjunctiveTerm;
532 [ # # ][ # # ]: 0 : bool bValidIndex = ( nInsertPos >= 0 ) && ( (size_t)nInsertPos <= pFormItem->GetChildren().size() );
533 [ # # ]: 0 : if ( !bValidIndex )
534 : : {
535 : : OSL_FAIL( "FmFilterAdapter::disjunctiveTermAdded: invalid index!" );
536 : : return;
537 : : }
538 : :
539 [ # # ]: 0 : const ::std::vector< FmFilterData* >::iterator insertPos = pFormItem->GetChildren().begin() + nInsertPos;
540 : :
541 [ # # ][ # # ]: 0 : FmFilterItems* pFilterItems = new FmFilterItems( m_pModel->getORB(), pFormItem, String( SVX_RES( RID_STR_FILTER_FILTER_OR ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
542 [ # # ][ # # ]: 0 : m_pModel->Insert( insertPos, pFilterItems );
[ # # ][ # # ]
[ # # ][ # # ]
543 : : }
544 : :
545 : : //========================================================================
546 : : // class FmFilterModel
547 : : //========================================================================
548 [ # # ][ # # ]: 0 : TYPEINIT1(FmFilterModel, FmParentData);
549 : : //------------------------------------------------------------------------
550 : 0 : FmFilterModel::FmFilterModel(const Reference< XMultiServiceFactory >& _rxFactory)
551 : : :FmParentData(_rxFactory,NULL, ::rtl::OUString())
552 : : ,OSQLParserClient(_rxFactory)
553 : : ,m_xORB(_rxFactory)
554 : : ,m_pAdapter(NULL)
555 [ # # ][ # # ]: 0 : ,m_pCurrentItems(NULL)
[ # # ]
556 : : {
557 : 0 : }
558 : :
559 : : //------------------------------------------------------------------------
560 [ # # ][ # # ]: 0 : FmFilterModel::~FmFilterModel()
561 : : {
562 [ # # ]: 0 : Clear();
563 [ # # ]: 0 : }
564 : :
565 : : //------------------------------------------------------------------------
566 : 0 : void FmFilterModel::Clear()
567 : : {
568 : : // notify
569 [ # # ]: 0 : FilterClearingHint aClearedHint;
570 [ # # ]: 0 : Broadcast( aClearedHint );
571 : :
572 : : // loose endings
573 [ # # ]: 0 : if (m_pAdapter)
574 : : {
575 [ # # ]: 0 : m_pAdapter->dispose();
576 : 0 : m_pAdapter->release();
577 : 0 : m_pAdapter= NULL;
578 : : }
579 : :
580 : 0 : m_pCurrentItems = NULL;
581 [ # # ]: 0 : m_xController = NULL;
582 [ # # ]: 0 : m_xControllers = NULL;
583 : :
584 [ # # ][ # # ]: 0 : for (::std::vector<FmFilterData*>::const_iterator i = m_aChildren.begin();
[ # # ]
585 : 0 : i != m_aChildren.end(); ++i)
586 [ # # ][ # # ]: 0 : delete (*i);
587 : :
588 [ # # ]: 0 : m_aChildren.clear();
589 : 0 : }
590 : :
591 : : //------------------------------------------------------------------------
592 : 0 : void FmFilterModel::Update(const Reference< XIndexAccess > & xControllers, const Reference< XFormController > & xCurrent)
593 : : {
594 [ # # ]: 0 : if ( xCurrent == m_xController )
595 : 0 : return;
596 : :
597 [ # # ]: 0 : if (!xControllers.is())
598 : : {
599 : 0 : Clear();
600 : 0 : return;
601 : : }
602 : :
603 : : // there is only a new current controller
604 [ # # ]: 0 : if ( m_xControllers != xControllers )
605 : : {
606 : 0 : Clear();
607 : :
608 : 0 : m_xControllers = xControllers;
609 : 0 : Update(m_xControllers, this);
610 : :
611 : : DBG_ASSERT(xCurrent.is(), "FmFilterModel::Update(...) no current controller");
612 : :
613 : : // Listening for TextChanges
614 [ # # ]: 0 : m_pAdapter = new FmFilterAdapter(this, xControllers);
615 : 0 : m_pAdapter->acquire();
616 : :
617 : 0 : SetCurrentController(xCurrent);
618 : 0 : EnsureEmptyFilterRows( *this );
619 : : }
620 : : else
621 : 0 : SetCurrentController(xCurrent);
622 : : }
623 : :
624 : : //------------------------------------------------------------------------
625 : 0 : void FmFilterModel::Update(const Reference< XIndexAccess > & xControllers, FmParentData* pParent)
626 : : {
627 : : try
628 : : {
629 [ # # ][ # # ]: 0 : sal_Int32 nCount = xControllers->getCount();
630 [ # # ]: 0 : for ( sal_Int32 i = 0; i < nCount; ++i )
631 : : {
632 [ # # ][ # # ]: 0 : Reference< XFormController > xController( xControllers->getByIndex(i), UNO_QUERY_THROW );
[ # # ]
633 : :
634 [ # # ][ # # ]: 0 : Reference< XPropertySet > xFormProperties( xController->getModel(), UNO_QUERY_THROW );
[ # # ]
635 : 0 : ::rtl::OUString aName;
636 [ # # ][ # # ]: 0 : OSL_VERIFY( xFormProperties->getPropertyValue( FM_PROP_NAME ) >>= aName );
[ # # ]
637 : :
638 : : // Insert a new item for the form
639 [ # # ][ # # ]: 0 : FmFormItem* pFormItem = new FmFormItem( m_xORB, pParent, xController, aName );
640 [ # # ]: 0 : Insert( pParent->GetChildren().end(), pFormItem );
641 : :
642 [ # # ]: 0 : Reference< XFilterController > xFilterController( pFormItem->GetFilterController(), UNO_SET_THROW );
643 : :
644 : : // insert the existing filters for the form
645 [ # # ][ # # ]: 0 : String aTitle( SVX_RES( RID_STR_FILTER_FILTER_FOR ) );
646 : :
647 [ # # ][ # # ]: 0 : Sequence< Sequence< ::rtl::OUString > > aExpressions = xFilterController->getPredicateExpressions();
648 [ # # ]: 0 : for ( const Sequence< ::rtl::OUString >* pConjunctionTerm = aExpressions.getConstArray();
649 : 0 : pConjunctionTerm != aExpressions.getConstArray() + aExpressions.getLength();
650 : : ++pConjunctionTerm
651 : : )
652 : : {
653 : : // we always display one row, even if there's no term to be displayed
654 [ # # ][ # # ]: 0 : FmFilterItems* pFilterItems = new FmFilterItems( m_xORB, pFormItem, aTitle );
[ # # ]
655 [ # # ]: 0 : Insert( pFormItem->GetChildren().end(), pFilterItems );
656 : :
657 : 0 : const Sequence< ::rtl::OUString >& rDisjunction( *pConjunctionTerm );
658 [ # # ]: 0 : for ( const ::rtl::OUString* pDisjunctiveTerm = rDisjunction.getConstArray();
659 : 0 : pDisjunctiveTerm != rDisjunction.getConstArray() + rDisjunction.getLength();
660 : : ++pDisjunctiveTerm
661 : : )
662 : : {
663 [ # # ]: 0 : if ( pDisjunctiveTerm->isEmpty() )
664 : : // no condition for this particular component in this particular conjunction term
665 : 0 : continue;
666 : :
667 : 0 : const sal_Int32 nComponentIndex = pDisjunctiveTerm - rDisjunction.getConstArray();
668 : :
669 : : // determine the display name of the control
670 [ # # ][ # # ]: 0 : const Reference< XControl > xFilterControl( xFilterController->getFilterComponent( nComponentIndex ) );
671 [ # # ]: 0 : const ::rtl::OUString sDisplayName( lcl_getLabelName_nothrow( xFilterControl ) );
672 : :
673 : : // insert a new entry
674 [ # # ][ # # ]: 0 : FmFilterItem* pANDCondition = new FmFilterItem( m_xORB, pFilterItems, sDisplayName, *pDisjunctiveTerm, nComponentIndex );
675 [ # # ]: 0 : Insert( pFilterItems->GetChildren().end(), pANDCondition );
676 : 0 : }
677 : :
678 : : // title for the next conditions
679 [ # # ][ # # ]: 0 : aTitle = SVX_RESSTR( RID_STR_FILTER_FILTER_OR );
[ # # ]
680 : : }
681 : :
682 : : // now add dependent controllers
683 [ # # ]: 0 : Reference< XIndexAccess > xControllerAsIndex( xController, UNO_QUERY );
684 [ # # ]: 0 : Update( xControllerAsIndex, pFormItem );
685 [ # # ][ # # ]: 0 : }
[ # # ]
686 : : }
687 : 0 : catch( const Exception& )
688 : : {
689 : : DBG_UNHANDLED_EXCEPTION();
690 : : }
691 : 0 : }
692 : :
693 : : //------------------------------------------------------------------------
694 : 0 : FmFormItem* FmFilterModel::Find(const ::std::vector<FmFilterData*>& rItems, const Reference< XFormController > & xController) const
695 : : {
696 [ # # ][ # # ]: 0 : for (::std::vector<FmFilterData*>::const_iterator i = rItems.begin();
697 : 0 : i != rItems.end(); ++i)
698 : : {
699 [ # # ][ # # ]: 0 : FmFormItem* pForm = PTR_CAST(FmFormItem,*i);
[ # # ]
700 [ # # ]: 0 : if (pForm)
701 : : {
702 [ # # ][ # # ]: 0 : if ( xController == pForm->GetController() )
703 : 0 : return pForm;
704 : : else
705 : : {
706 [ # # ]: 0 : pForm = Find(pForm->GetChildren(), xController);
707 [ # # ]: 0 : if (pForm)
708 : 0 : return pForm;
709 : : }
710 : : }
711 : : }
712 : 0 : return NULL;
713 : : }
714 : :
715 : : //------------------------------------------------------------------------
716 : 0 : FmFormItem* FmFilterModel::Find(const ::std::vector<FmFilterData*>& rItems, const Reference< XForm >& xForm) const
717 : : {
718 [ # # ][ # # ]: 0 : for (::std::vector<FmFilterData*>::const_iterator i = rItems.begin();
719 : 0 : i != rItems.end(); ++i)
720 : : {
721 [ # # ][ # # ]: 0 : FmFormItem* pForm = PTR_CAST(FmFormItem,*i);
[ # # ]
722 [ # # ]: 0 : if (pForm)
723 : : {
724 [ # # ][ # # ]: 0 : if (xForm == pForm->GetController()->getModel())
[ # # ][ # # ]
725 : 0 : return pForm;
726 : : else
727 : : {
728 [ # # ]: 0 : pForm = Find(pForm->GetChildren(), xForm);
729 [ # # ]: 0 : if (pForm)
730 : 0 : return pForm;
731 : : }
732 : : }
733 : : }
734 : 0 : return NULL;
735 : : }
736 : :
737 : : //------------------------------------------------------------------------
738 : 0 : void FmFilterModel::SetCurrentController(const Reference< XFormController > & xCurrent)
739 : : {
740 [ # # ]: 0 : if ( xCurrent == m_xController )
741 : 0 : return;
742 : :
743 : 0 : m_xController = xCurrent;
744 : :
745 : 0 : FmFormItem* pItem = Find( m_aChildren, xCurrent );
746 [ # # ]: 0 : if ( !pItem )
747 : 0 : return;
748 : :
749 : : try
750 : : {
751 [ # # ]: 0 : Reference< XFilterController > xFilterController( m_xController, UNO_QUERY_THROW );
752 [ # # ][ # # ]: 0 : const sal_Int32 nActiveTerm( xFilterController->getActiveTerm() );
753 [ # # ]: 0 : if ( pItem->GetChildren().size() > (size_t)nActiveTerm )
754 : : {
755 [ # # ]: 0 : SetCurrentItems( static_cast< FmFilterItems* >( pItem->GetChildren()[ nActiveTerm ] ) );
756 [ # # ]: 0 : }
757 : : }
758 : 0 : catch( const Exception& )
759 : : {
760 : : DBG_UNHANDLED_EXCEPTION();
761 : : }
762 : : }
763 : :
764 : : //------------------------------------------------------------------------
765 : 0 : void FmFilterModel::AppendFilterItems( FmFormItem& _rFormItem )
766 : : {
767 : : // insert the condition behind the last filter items
768 : 0 : ::std::vector<FmFilterData*>::reverse_iterator iter;
769 [ # # # # ]: 0 : for ( iter = _rFormItem.GetChildren().rbegin();
[ # # ]
770 : 0 : iter != _rFormItem.GetChildren().rend();
771 : : ++iter
772 : : )
773 : : {
774 [ # # ][ # # ]: 0 : if ((*iter)->ISA(FmFilterItems))
[ # # ]
775 : 0 : break;
776 : : }
777 : :
778 [ # # ]: 0 : sal_Int32 nInsertPos = iter.base() - _rFormItem.GetChildren().begin();
779 : : // delegate this to the FilterController, it will notify us, which will let us update our model
780 : : try
781 : : {
782 [ # # ]: 0 : Reference< XFilterController > xFilterController( _rFormItem.GetFilterController(), UNO_SET_THROW );
783 [ # # ][ # # ]: 0 : if ( nInsertPos >= xFilterController->getDisjunctiveTerms() )
[ # # ]
784 [ # # ][ # # ]: 0 : xFilterController->appendEmptyDisjunctiveTerm();
[ # # ]
785 : : }
786 [ # # ]: 0 : catch( const Exception& )
787 : : {
788 : : DBG_UNHANDLED_EXCEPTION();
789 : : }
790 : 0 : }
791 : :
792 : : //------------------------------------------------------------------------
793 : 0 : void FmFilterModel::Insert(const ::std::vector<FmFilterData*>::iterator& rPos, FmFilterData* pData)
794 : : {
795 : 0 : ::std::vector<FmFilterData*>& rItems = pData->GetParent()->GetChildren();
796 [ # # ][ # # ]: 0 : sal_uLong nPos = rPos == rItems.end() ? LIST_APPEND : rPos - rItems.begin();
[ # # ][ # # ]
[ # # ]
797 [ # # ]: 0 : rItems.insert(rPos, pData);
798 : :
799 : : // UI benachrichtigen
800 [ # # ]: 0 : FmFilterInsertedHint aInsertedHint(pData, nPos);
801 [ # # ][ # # ]: 0 : Broadcast( aInsertedHint );
802 : 0 : }
803 : :
804 : : //------------------------------------------------------------------------
805 : 0 : void FmFilterModel::Remove(FmFilterData* pData)
806 : : {
807 : 0 : FmParentData* pParent = pData->GetParent();
808 : 0 : ::std::vector<FmFilterData*>& rItems = pParent->GetChildren();
809 : :
810 : : // erase the item from the model
811 [ # # ]: 0 : ::std::vector<FmFilterData*>::iterator i = ::std::find(rItems.begin(), rItems.end(), pData);
812 : : DBG_ASSERT(i != rItems.end(), "FmFilterModel::Remove(): unknown Item");
813 : : // position within the parent
814 [ # # ]: 0 : sal_Int32 nPos = i - rItems.begin();
815 [ # # ][ # # ]: 0 : if (pData->ISA(FmFilterItems))
816 : : {
817 : 0 : FmFormItem* pFormItem = (FmFormItem*)pParent;
818 : :
819 : : try
820 : : {
821 [ # # ]: 0 : Reference< XFilterController > xFilterController( pFormItem->GetFilterController(), UNO_SET_THROW );
822 : :
823 [ # # ][ # # ]: 0 : bool bEmptyLastTerm = ( ( nPos == 0 ) && xFilterController->getDisjunctiveTerms() == 1 );
[ # # ][ # # ]
824 [ # # ]: 0 : if ( bEmptyLastTerm )
825 : : {
826 : : // remove all children (by setting an empty predicate expression)
827 : 0 : ::std::vector< FmFilterData* >& rChildren = ((FmFilterItems*)pData)->GetChildren();
828 [ # # ]: 0 : while ( !rChildren.empty() )
829 : : {
830 [ # # ]: 0 : ::std::vector< FmFilterData* >::iterator removePos = rChildren.end() - 1;
831 [ # # ][ # # ]: 0 : FmFilterItem* pFilterItem = PTR_CAST( FmFilterItem, *removePos );
[ # # ]
832 [ # # ]: 0 : m_pAdapter->setText( nPos, pFilterItem, ::rtl::OUString() );
833 [ # # ]: 0 : Remove( removePos );
834 : : }
835 : : }
836 : : else
837 : : {
838 [ # # ][ # # ]: 0 : xFilterController->removeDisjunctiveTerm( nPos );
839 [ # # ]: 0 : }
840 : : }
841 [ # # ]: 0 : catch( const Exception& )
842 : : {
843 : : DBG_UNHANDLED_EXCEPTION();
844 : : }
845 : : }
846 : : else // FormItems can not be deleted
847 : : {
848 [ # # ][ # # ]: 0 : FmFilterItem* pFilterItem = PTR_CAST(FmFilterItem, pData);
[ # # ]
849 : :
850 : : // if its the last condition remove the parent
851 [ # # ]: 0 : if (rItems.size() == 1)
852 [ # # ]: 0 : Remove(pFilterItem->GetParent());
853 : : else
854 : : {
855 : : // find the position of the father within his father
856 : 0 : ::std::vector<FmFilterData*>& rParentParentItems = pData->GetParent()->GetParent()->GetChildren();
857 [ # # ]: 0 : ::std::vector<FmFilterData*>::iterator j = ::std::find(rParentParentItems.begin(), rParentParentItems.end(), pFilterItem->GetParent());
858 : : DBG_ASSERT(j != rParentParentItems.end(), "FmFilterModel::Remove(): unknown Item");
859 [ # # ]: 0 : sal_Int32 nParentPos = j - rParentParentItems.begin();
860 : :
861 : : // EmptyText removes the filter
862 [ # # ]: 0 : m_pAdapter->setText(nParentPos, pFilterItem, ::rtl::OUString());
863 [ # # ]: 0 : Remove( i );
864 : : }
865 : : }
866 : 0 : }
867 : :
868 : : //------------------------------------------------------------------------
869 : 0 : void FmFilterModel::Remove( const ::std::vector<FmFilterData*>::iterator& rPos )
870 : : {
871 : : // remove from parent's child list
872 : 0 : FmFilterData* pData = *rPos;
873 [ # # ]: 0 : pData->GetParent()->GetChildren().erase( rPos );
874 : :
875 : : // notify the view, this will remove the actual SvLBoxEntry
876 [ # # ]: 0 : FmFilterRemovedHint aRemoveHint( pData );
877 [ # # ]: 0 : Broadcast( aRemoveHint );
878 : :
879 [ # # ][ # # ]: 0 : delete pData;
[ # # ]
880 : 0 : }
881 : :
882 : : //------------------------------------------------------------------------
883 : 0 : sal_Bool FmFilterModel::ValidateText(FmFilterItem* pItem, UniString& rText, UniString& rErrorMsg) const
884 : : {
885 [ # # ][ # # ]: 0 : FmFormItem* pFormItem = PTR_CAST( FmFormItem, pItem->GetParent()->GetParent() );
886 : : try
887 : : {
888 : 0 : Reference< XFormController > xFormController( pFormItem->GetController() );
889 : : // obtain the connection of the form belonging to the controller
890 [ # # ]: 0 : OStaticDataAccessTools aStaticTools;
891 [ # # ][ # # ]: 0 : Reference< XRowSet > xRowSet( xFormController->getModel(), UNO_QUERY_THROW );
[ # # ]
892 [ # # ]: 0 : Reference< XConnection > xConnection( aStaticTools.getRowSetConnection( xRowSet ) );
893 : :
894 : : // obtain a number formatter for this connection
895 : : // TODO: shouldn't this be cached?
896 [ # # ]: 0 : Reference< XNumberFormatsSupplier > xFormatSupplier = aStaticTools.getNumberFormats( xConnection, sal_True );
897 [ # # ][ # # ]: 0 : Reference< XNumberFormatter > xFormatter( m_xORB->createInstance( FM_NUMBER_FORMATTER ), UNO_QUERY );
[ # # ][ # # ]
898 [ # # ][ # # ]: 0 : xFormatter->attachNumberFormatsSupplier( xFormatSupplier );
899 : :
900 : : // get the field (database column) which the item is responsible for
901 [ # # ]: 0 : Reference< XFilterController > xFilterController( xFormController, UNO_QUERY_THROW );
902 [ # # ][ # # ]: 0 : Reference< XPropertySet > xField( lcl_getBoundField_nothrow( xFilterController->getFilterComponent( pItem->GetComponentIndex() ) ), UNO_SET_THROW );
[ # # ][ # # ]
903 : :
904 : : // parse the given text as filter predicate
905 [ # # ]: 0 : ::rtl::OUString aErr, aTxt( rText );
906 [ # # ]: 0 : ::rtl::Reference< ISQLParseNode > xParseNode = predicateTree( aErr, aTxt, xFormatter, xField );
907 [ # # ]: 0 : rErrorMsg = aErr;
908 [ # # ]: 0 : rText = aTxt;
909 [ # # ]: 0 : if ( xParseNode.is() )
910 : : {
911 : 0 : ::rtl::OUString aPreparedText;
912 [ # # ][ # # ]: 0 : Locale aAppLocale = Application::GetSettings().GetUILocale();
913 : 0 : xParseNode->parseNodeToPredicateStr(
914 [ # # ][ # # ]: 0 : aPreparedText, xConnection, xFormatter, xField, aAppLocale, '.', getParseContext() );
915 [ # # ]: 0 : rText = aPreparedText;
916 : 0 : return sal_True;
917 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
918 : : }
919 : 0 : catch( const Exception& )
920 : : {
921 : : DBG_UNHANDLED_EXCEPTION();
922 : : }
923 : :
924 : 0 : return sal_False;
925 : : }
926 : :
927 : : //------------------------------------------------------------------------
928 : 0 : void FmFilterModel::Append(FmFilterItems* pItems, FmFilterItem* pFilterItem)
929 : : {
930 [ # # ]: 0 : Insert(pItems->GetChildren().end(), pFilterItem);
931 : 0 : }
932 : :
933 : : //------------------------------------------------------------------------
934 : 0 : void FmFilterModel::SetTextForItem(FmFilterItem* pItem, const ::rtl::OUString& rText)
935 : : {
936 : 0 : ::std::vector<FmFilterData*>& rItems = pItem->GetParent()->GetParent()->GetChildren();
937 [ # # ]: 0 : ::std::vector<FmFilterData*>::iterator i = ::std::find(rItems.begin(), rItems.end(), pItem->GetParent());
938 [ # # ]: 0 : sal_Int32 nParentPos = i - rItems.begin();
939 : :
940 [ # # ]: 0 : m_pAdapter->setText(nParentPos, pItem, rText);
941 : :
942 [ # # ]: 0 : if (rText.isEmpty())
943 [ # # ]: 0 : Remove(pItem);
944 : : else
945 : : {
946 : : // Change the text
947 : 0 : pItem->SetText(rText);
948 [ # # ]: 0 : FmFilterTextChangedHint aChangeHint(pItem);
949 [ # # ][ # # ]: 0 : Broadcast( aChangeHint );
950 : : }
951 : 0 : }
952 : :
953 : : //------------------------------------------------------------------------
954 : 0 : void FmFilterModel::SetCurrentItems(FmFilterItems* pCurrent)
955 : : {
956 [ # # ]: 0 : if (m_pCurrentItems == pCurrent)
957 : 0 : return;
958 : :
959 : : // search for the condition
960 [ # # ]: 0 : if (pCurrent)
961 : : {
962 : 0 : FmFormItem* pFormItem = (FmFormItem*)pCurrent->GetParent();
963 : 0 : ::std::vector<FmFilterData*>& rItems = pFormItem->GetChildren();
964 [ # # ][ # # ]: 0 : ::std::vector<FmFilterData*>::const_iterator i = ::std::find(rItems.begin(), rItems.end(), pCurrent);
965 : :
966 [ # # ][ # # ]: 0 : if (i != rItems.end())
967 : : {
968 : : // determine the filter position
969 [ # # ]: 0 : sal_Int32 nPos = i - rItems.begin();
970 : : try
971 : : {
972 [ # # ]: 0 : Reference< XFilterController > xFilterController( pFormItem->GetFilterController(), UNO_SET_THROW );
973 [ # # ][ # # ]: 0 : xFilterController->setActiveTerm( nPos );
[ # # ]
974 : : }
975 [ # # ]: 0 : catch( const Exception& )
976 : : {
977 : : DBG_UNHANDLED_EXCEPTION();
978 : : }
979 : :
980 [ # # ][ # # ]: 0 : if ( m_xController != pFormItem->GetController() )
981 : : // calls SetCurrentItems again
982 [ # # ]: 0 : SetCurrentController( pFormItem->GetController() );
983 : : else
984 : 0 : m_pCurrentItems = pCurrent;
985 : : }
986 : : else
987 : 0 : m_pCurrentItems = NULL;
988 : : }
989 : : else
990 : 0 : m_pCurrentItems = NULL;
991 : :
992 : :
993 : : // UI benachrichtigen
994 [ # # ]: 0 : FmFilterCurrentChangedHint aHint;
995 [ # # ][ # # ]: 0 : Broadcast( aHint );
996 : : }
997 : :
998 : : //------------------------------------------------------------------------
999 : 0 : void FmFilterModel::EnsureEmptyFilterRows( FmParentData& _rItem )
1000 : : {
1001 : : // checks whether for each form there's one free level for input
1002 : 0 : ::std::vector< FmFilterData* >& rChildren = _rItem.GetChildren();
1003 : 0 : sal_Bool bAppendLevel = _rItem.ISA( FmFormItem );
1004 : :
1005 [ # # ][ # # ]: 0 : for ( ::std::vector<FmFilterData*>::iterator i = rChildren.begin();
1006 : 0 : i != rChildren.end();
1007 : : ++i
1008 : : )
1009 : : {
1010 [ # # ][ # # ]: 0 : FmFilterItems* pItems = PTR_CAST(FmFilterItems, *i);
[ # # ]
1011 [ # # ][ # # ]: 0 : if ( pItems && pItems->GetChildren().empty() )
[ # # ]
1012 : : {
1013 : 0 : bAppendLevel = sal_False;
1014 : 0 : break;
1015 : : }
1016 : :
1017 [ # # ][ # # ]: 0 : FmFormItem* pFormItem = PTR_CAST(FmFormItem, *i);
[ # # ]
1018 [ # # ]: 0 : if (pFormItem)
1019 : : {
1020 [ # # ]: 0 : EnsureEmptyFilterRows( *pFormItem );
1021 : 0 : continue;
1022 : : }
1023 : : }
1024 : :
1025 [ # # ]: 0 : if ( bAppendLevel )
1026 : : {
1027 [ # # ][ # # ]: 0 : FmFormItem* pFormItem = PTR_CAST( FmFormItem, &_rItem );
1028 : : OSL_ENSURE( pFormItem, "FmFilterModel::EnsureEmptyFilterRows: no FmFormItem, but a FmFilterItems child?" );
1029 [ # # ]: 0 : if ( pFormItem )
1030 : 0 : AppendFilterItems( *pFormItem );
1031 : : }
1032 : 0 : }
1033 : :
1034 : : //========================================================================
1035 : : // class FmFilterItemsString
1036 : : //========================================================================
1037 [ # # ]: 0 : class FmFilterItemsString : public SvLBoxString
1038 : : {
1039 : : public:
1040 : 0 : FmFilterItemsString( SvLBoxEntry* pEntry, sal_uInt16 nFlags, const XubString& rStr )
1041 [ # # ]: 0 : :SvLBoxString(pEntry,nFlags,rStr){}
1042 : :
1043 : : virtual void Paint(const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, SvLBoxEntry* pEntry);
1044 : : virtual void InitViewData( SvLBox* pView,SvLBoxEntry* pEntry, SvViewDataItem* pViewData);
1045 : : };
1046 : :
1047 : : const int nxDBmp = 12;
1048 : : //------------------------------------------------------------------------
1049 : 0 : void FmFilterItemsString::Paint(const Point& rPos, SvLBox& rDev, sal_uInt16 /*nFlags*/, SvLBoxEntry* pEntry )
1050 : : {
1051 : 0 : FmFilterItems* pRow = (FmFilterItems*)pEntry->GetUserData();
1052 : 0 : FmFormItem* pForm = (FmFormItem*)pRow->GetParent();
1053 : :
1054 : : // current filter is significant painted
1055 : 0 : const bool bIsCurrentFilter = pForm->GetChildren()[ pForm->GetFilterController()->getActiveTerm() ] == pRow;
1056 [ # # ]: 0 : if ( bIsCurrentFilter )
1057 : : {
1058 [ # # ]: 0 : rDev.Push( PUSH_LINECOLOR );
1059 : :
1060 [ # # ]: 0 : rDev.SetLineColor( rDev.GetTextColor() );
1061 : :
1062 [ # # ][ # # ]: 0 : Rectangle aRect( rPos, GetSize( &rDev, pEntry ) );
1063 : 0 : Point aFirst( rPos.X(), aRect.Bottom() - 6 );
1064 : 0 : Point aSecond(aFirst .X() + 2, aFirst.Y() + 3 );
1065 : :
1066 [ # # ]: 0 : rDev.DrawLine( aFirst, aSecond );
1067 : :
1068 : 0 : aFirst = aSecond;
1069 : 0 : aFirst.X() += 1;
1070 : 0 : aSecond.X() += 6;
1071 : 0 : aSecond.Y() -= 5;
1072 : :
1073 [ # # ]: 0 : rDev.DrawLine( aFirst, aSecond );
1074 : :
1075 [ # # ]: 0 : rDev.Pop();
1076 : : }
1077 : :
1078 [ # # ][ # # ]: 0 : rDev.DrawText( Point(rPos.X() + nxDBmp, rPos.Y()), GetText() );
[ # # ]
1079 : 0 : }
1080 : :
1081 : : //------------------------------------------------------------------------
1082 : 0 : void FmFilterItemsString::InitViewData( SvLBox* pView,SvLBoxEntry* pEntry, SvViewDataItem* pViewData)
1083 : : {
1084 [ # # ]: 0 : if( !pViewData )
1085 [ # # ]: 0 : pViewData = pView->GetViewDataItem( pEntry, this );
1086 : :
1087 [ # # ][ # # ]: 0 : Size aSize(pView->GetTextWidth(GetText()), pView->GetTextHeight());
[ # # ][ # # ]
1088 : 0 : aSize.Width() += nxDBmp;
1089 : 0 : pViewData->aSize = aSize;
1090 : 0 : }
1091 : :
1092 : : //========================================================================
1093 : : // class FmFilterString
1094 : : //========================================================================
1095 [ # # ][ # # ]: 0 : class FmFilterString : public SvLBoxString
1096 : : {
1097 : : UniString m_aName;
1098 : :
1099 : : public:
1100 : 0 : FmFilterString( SvLBoxEntry* pEntry, sal_uInt16 nFlags, const XubString& rStr, const UniString& aName)
1101 : : :SvLBoxString(pEntry,nFlags,rStr)
1102 [ # # ][ # # ]: 0 : ,m_aName(aName)
1103 : : {
1104 [ # # ]: 0 : m_aName.AppendAscii(": ");
1105 : 0 : }
1106 : :
1107 : : virtual void Paint(const Point& rPos, SvLBox& rDev, sal_uInt16 nFlags, SvLBoxEntry* pEntry);
1108 : : virtual void InitViewData( SvLBox* pView,SvLBoxEntry* pEntry, SvViewDataItem* pViewData);
1109 : : };
1110 : :
1111 : : const int nxD = 4;
1112 : :
1113 : : //------------------------------------------------------------------------
1114 : 0 : void FmFilterString::InitViewData( SvLBox* pView,SvLBoxEntry* pEntry, SvViewDataItem* pViewData)
1115 : : {
1116 [ # # ]: 0 : if( !pViewData )
1117 [ # # ]: 0 : pViewData = pView->GetViewDataItem( pEntry, this );
1118 : :
1119 [ # # ]: 0 : Font aOldFont( pView->GetFont());
1120 [ # # ]: 0 : Font aFont( aOldFont );
1121 [ # # ]: 0 : aFont.SetWeight(WEIGHT_BOLD);
1122 [ # # ]: 0 : pView->SetFont( aFont );
1123 : :
1124 [ # # ][ # # ]: 0 : Size aSize(pView->GetTextWidth(m_aName), pView->GetTextHeight());
1125 [ # # ]: 0 : pView->SetFont( aOldFont );
1126 [ # # ][ # # ]: 0 : aSize.Width() += pView->GetTextWidth(GetText()) + nxD;
[ # # ]
1127 [ # # ][ # # ]: 0 : pViewData->aSize = aSize;
1128 : 0 : }
1129 : :
1130 : : //------------------------------------------------------------------------
1131 : 0 : void FmFilterString::Paint(const Point& rPos, SvLBox& rDev, sal_uInt16 /*nFlags*/, SvLBoxEntry* /*pEntry*/ )
1132 : : {
1133 [ # # ]: 0 : Font aOldFont( rDev.GetFont());
1134 [ # # ]: 0 : Font aFont( aOldFont );
1135 [ # # ]: 0 : aFont.SetWeight(WEIGHT_BOLD);
1136 [ # # ]: 0 : rDev.SetFont( aFont );
1137 : :
1138 : 0 : Point aPos(rPos);
1139 [ # # ]: 0 : rDev.DrawText( aPos, m_aName );
1140 : :
1141 : : // position for the second text
1142 [ # # ]: 0 : aPos.X() += rDev.GetTextWidth(m_aName) + nxD;
1143 [ # # ]: 0 : rDev.SetFont( aOldFont );
1144 [ # # ][ # # ]: 0 : rDev.DrawText( aPos, GetText() );
[ # # ][ # # ]
[ # # ]
1145 : 0 : }
1146 : :
1147 : : //========================================================================
1148 : : // class FmFilterNavigator
1149 : : //========================================================================
1150 : 0 : FmFilterNavigator::FmFilterNavigator( Window* pParent )
1151 : : :SvTreeListBox( pParent, WB_HASBUTTONS|WB_HASLINES|WB_BORDER|WB_HASBUTTONSATROOT )
1152 : : ,m_pModel( NULL )
1153 : : ,m_pEditingCurrently( NULL )
1154 : : ,m_aControlExchange( this )
1155 : : ,m_aTimerCounter( 0 )
1156 [ # # ][ # # ]: 0 : ,m_aDropActionType( DA_SCROLLUP )
[ # # ]
1157 : : {
1158 [ # # ]: 0 : SetHelpId( HID_FILTER_NAVIGATOR );
1159 : :
1160 : : {
1161 [ # # ][ # # ]: 0 : ImageList aNavigatorImages( SVX_RES( RID_SVXIMGLIST_FMEXPL ) );
1162 : : SetNodeBitmaps(
1163 : : aNavigatorImages.GetImage( RID_SVXIMG_COLLAPSEDNODE ),
1164 : : aNavigatorImages.GetImage( RID_SVXIMG_EXPANDEDNODE )
1165 [ # # ][ # # ]: 0 : );
[ # # ][ # # ]
[ # # ][ # # ]
1166 : : }
1167 : :
1168 [ # # ][ # # ]: 0 : m_pModel = new FmFilterModel(comphelper::getProcessServiceFactory());
[ # # ]
1169 [ # # ]: 0 : StartListening( *m_pModel );
1170 : :
1171 [ # # ]: 0 : EnableInplaceEditing( sal_True );
1172 [ # # ]: 0 : SetSelectionMode(MULTIPLE_SELECTION);
1173 : :
1174 [ # # ]: 0 : SetDragDropMode(0xFFFF);
1175 : :
1176 [ # # ]: 0 : m_aDropActionTimer.SetTimeoutHdl(LINK(this, FmFilterNavigator, OnDropActionTimer));
1177 : 0 : }
1178 : :
1179 : : //------------------------------------------------------------------------
1180 [ # # ][ # # ]: 0 : FmFilterNavigator::~FmFilterNavigator()
[ # # ]
1181 : : {
1182 [ # # ]: 0 : EndListening( *m_pModel );
1183 [ # # ][ # # ]: 0 : delete m_pModel;
1184 [ # # ]: 0 : }
1185 : :
1186 : : //------------------------------------------------------------------------
1187 : 0 : void FmFilterNavigator::UpdateContent(const Reference< XIndexAccess > & xControllers, const Reference< XFormController > & xCurrent)
1188 : : {
1189 [ # # ]: 0 : if (xCurrent == m_pModel->GetCurrentController())
1190 : 0 : return;
1191 : :
1192 : 0 : m_pModel->Update(xControllers, xCurrent);
1193 : :
1194 : : // expand the filters for the current controller
1195 : 0 : SvLBoxEntry* pEntry = FindEntry(m_pModel->GetCurrentForm());
1196 [ # # ][ # # ]: 0 : if (pEntry && !IsExpanded(pEntry))
[ # # ]
1197 : : {
1198 : 0 : SelectAll(sal_False);
1199 : :
1200 [ # # ]: 0 : if (!IsExpanded(pEntry))
1201 : 0 : Expand(pEntry);
1202 : :
1203 : 0 : pEntry = FindEntry(m_pModel->GetCurrentItems());
1204 [ # # ]: 0 : if (pEntry)
1205 : : {
1206 [ # # ]: 0 : if (!IsExpanded(pEntry))
1207 : 0 : Expand(pEntry);
1208 : 0 : Select(pEntry, sal_True);
1209 : : }
1210 : : }
1211 : : }
1212 : :
1213 : : //------------------------------------------------------------------------
1214 : 0 : sal_Bool FmFilterNavigator::EditingEntry( SvLBoxEntry* pEntry, Selection& rSelection )
1215 : : {
1216 : 0 : m_pEditingCurrently = pEntry;
1217 [ # # ]: 0 : if (!SvTreeListBox::EditingEntry( pEntry, rSelection ))
1218 : 0 : return sal_False;
1219 : :
1220 [ # # ][ # # ]: 0 : return pEntry && ((FmFilterData*)pEntry->GetUserData())->ISA(FmFilterItem);
1221 : : }
1222 : :
1223 : : //------------------------------------------------------------------------
1224 : 0 : sal_Bool FmFilterNavigator::EditedEntry( SvLBoxEntry* pEntry, const rtl::OUString& rNewText )
1225 : : {
1226 : : DBG_ASSERT(pEntry == m_pEditingCurrently, "FmFilterNavigator::EditedEntry: suspicious entry!");
1227 : 0 : m_pEditingCurrently = NULL;
1228 : :
1229 [ # # ][ # # ]: 0 : if (EditingCanceled())
1230 : 0 : return sal_True;
1231 : :
1232 : : DBG_ASSERT(((FmFilterData*)pEntry->GetUserData())->ISA(FmFilterItem),
1233 : : "FmFilterNavigator::EditedEntry() wrong entry");
1234 : :
1235 [ # # ][ # # ]: 0 : UniString aText(comphelper::string::strip(rNewText, ' '));
1236 [ # # ]: 0 : if (aText.Len() == 0)
1237 : : {
1238 : : // deleting the entry asynchron
1239 : : sal_uLong nEvent;
1240 [ # # ][ # # ]: 0 : PostUserEvent(nEvent, LINK(this, FmFilterNavigator, OnRemove), pEntry);
1241 : : }
1242 : : else
1243 : : {
1244 [ # # ]: 0 : UniString aErrorMsg;
1245 : :
1246 [ # # ][ # # ]: 0 : if (m_pModel->ValidateText((FmFilterItem*)pEntry->GetUserData(), aText, aErrorMsg))
1247 : : {
1248 [ # # ]: 0 : GrabFocus();
1249 : : // this will set the text at the FmFilterItem, as well as update any filter controls
1250 : : // which are connected to this particular entry
1251 [ # # ][ # # ]: 0 : m_pModel->SetTextForItem( static_cast< FmFilterItem* >( pEntry->GetUserData() ), aText );
1252 : :
1253 [ # # ]: 0 : SetCursor( pEntry, sal_True );
1254 [ # # ]: 0 : SetEntryText( pEntry, aText );
1255 : : }
1256 : : else
1257 : : {
1258 : : // display the error and return sal_False
1259 [ # # ]: 0 : SQLContext aError;
1260 [ # # ][ # # ]: 0 : aError.Message = String(SVX_RES(RID_STR_SYNTAXERROR));
[ # # ][ # # ]
1261 [ # # ]: 0 : aError.Details = aErrorMsg;
1262 [ # # ]: 0 : displayException(aError, this);
1263 : :
1264 [ # # ]: 0 : return sal_False;
1265 [ # # ][ # # ]: 0 : }
1266 : : }
1267 [ # # ]: 0 : return sal_True;
1268 : : }
1269 : :
1270 : : //------------------------------------------------------------------------
1271 : 0 : IMPL_LINK( FmFilterNavigator, OnRemove, SvLBoxEntry*, pEntry )
1272 : : {
1273 : : // now remove the entry
1274 : 0 : m_pModel->Remove((FmFilterData*) pEntry->GetUserData());
1275 : 0 : return 0L;
1276 : : }
1277 : :
1278 : : //------------------------------------------------------------------------
1279 : 0 : IMPL_LINK_NOARG(FmFilterNavigator, OnDropActionTimer)
1280 : : {
1281 [ # # ]: 0 : if (--m_aTimerCounter > 0)
1282 : 0 : return 0L;
1283 : :
1284 [ # # # # ]: 0 : switch (m_aDropActionType)
1285 : : {
1286 : : case DA_SCROLLUP :
1287 : 0 : ScrollOutputArea(1);
1288 : 0 : m_aTimerCounter = DROP_ACTION_TIMER_SCROLL_TICKS;
1289 : 0 : break;
1290 : : case DA_SCROLLDOWN :
1291 : 0 : ScrollOutputArea(-1);
1292 : 0 : m_aTimerCounter = DROP_ACTION_TIMER_SCROLL_TICKS;
1293 : 0 : break;
1294 : : case DA_EXPANDNODE:
1295 : : {
1296 : 0 : SvLBoxEntry* pToExpand = GetEntry(m_aTimerTriggered);
1297 [ # # ][ # # ]: 0 : if (pToExpand && (GetChildCount(pToExpand) > 0) && !IsExpanded(pToExpand))
[ # # ][ # # ]
1298 : : // tja, eigentlich muesste ich noch testen, ob die Node nicht schon expandiert ist, aber ich
1299 : : // habe dazu weder in den Basisklassen noch im Model eine Methode gefunden ...
1300 : : // aber ich denke, die BK sollte es auch so vertragen
1301 : 0 : Expand(pToExpand);
1302 : :
1303 : : // nach dem Expand habe ich im Gegensatz zum Scrollen natuerlich nix mehr zu tun
1304 : 0 : m_aDropActionTimer.Stop();
1305 : : }
1306 : 0 : break;
1307 : : }
1308 : 0 : return 0L;
1309 : : }
1310 : :
1311 : :
1312 : : //------------------------------------------------------------------------
1313 : 0 : sal_Int8 FmFilterNavigator::AcceptDrop( const AcceptDropEvent& rEvt )
1314 : : {
1315 : 0 : Point aDropPos = rEvt.maPosPixel;
1316 : :
1317 : : // kuemmern wir uns erst mal um moeglich DropActions (Scrollen und Aufklappen)
1318 [ # # ]: 0 : if (rEvt.mbLeaving)
1319 : : {
1320 [ # # ]: 0 : if (m_aDropActionTimer.IsActive())
1321 [ # # ]: 0 : m_aDropActionTimer.Stop();
1322 : : }
1323 : : else
1324 : : {
1325 : 0 : sal_Bool bNeedTrigger = sal_False;
1326 : : // auf dem ersten Eintrag ?
1327 [ # # ][ # # ]: 0 : if ((aDropPos.Y() >= 0) && (aDropPos.Y() < GetEntryHeight()))
[ # # ]
1328 : : {
1329 : 0 : m_aDropActionType = DA_SCROLLUP;
1330 : 0 : bNeedTrigger = sal_True;
1331 : : }
1332 : : else
1333 : : {
1334 : : // auf dem letzten (bzw. in dem Bereich, den ein Eintrag einnehmen wuerde, wenn er unten genau buendig
1335 : : // abschliessen wuerde) ?
1336 [ # # ][ # # ]: 0 : if ((aDropPos.Y() < GetSizePixel().Height()) && (aDropPos.Y() >= GetSizePixel().Height() - GetEntryHeight()))
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # #
# # ]
1337 : : {
1338 : 0 : m_aDropActionType = DA_SCROLLDOWN;
1339 : 0 : bNeedTrigger = sal_True;
1340 : : }
1341 : : else
1342 : : { // is it an entry whith children, and not yet expanded?
1343 [ # # ]: 0 : SvLBoxEntry* pDropppedOn = GetEntry(aDropPos);
1344 [ # # ][ # # ]: 0 : if (pDropppedOn && (GetChildCount(pDropppedOn) > 0) && !IsExpanded(pDropppedOn))
[ # # ][ # # ]
[ # # ][ # # ]
1345 : : {
1346 : : // -> aufklappen
1347 : 0 : m_aDropActionType = DA_EXPANDNODE;
1348 : 0 : bNeedTrigger = sal_True;
1349 : : }
1350 : : }
1351 : : }
1352 [ # # ][ # # ]: 0 : if (bNeedTrigger && (m_aTimerTriggered != aDropPos))
[ # # ]
1353 : : {
1354 : : // neu anfangen zu zaehlen
1355 : 0 : m_aTimerCounter = DROP_ACTION_TIMER_INITIAL_TICKS;
1356 : : // die Pos merken, da ich auch QueryDrops bekomme, wenn sich die Maus gar nicht bewegt hat
1357 : 0 : m_aTimerTriggered = aDropPos;
1358 : : // und den Timer los
1359 [ # # ]: 0 : if (!m_aDropActionTimer.IsActive()) // gibt es den Timer schon ?
1360 : : {
1361 [ # # ]: 0 : m_aDropActionTimer.SetTimeout(DROP_ACTION_TIMER_TICK_BASE);
1362 [ # # ]: 0 : m_aDropActionTimer.Start();
1363 : : }
1364 : : }
1365 [ # # ]: 0 : else if (!bNeedTrigger)
1366 [ # # ]: 0 : m_aDropActionTimer.Stop();
1367 : : }
1368 : :
1369 : :
1370 : : // Hat das Object das richtige Format?
1371 [ # # ]: 0 : if (!m_aControlExchange.isDragSource())
1372 : 0 : return DND_ACTION_NONE;
1373 : :
1374 [ # # ][ # # ]: 0 : if (!m_aControlExchange->hasFormat(GetDataFlavorExVector()))
1375 : 0 : return DND_ACTION_NONE;
1376 : :
1377 : : // do we conain the formitem?
1378 [ # # ][ # # ]: 0 : if (!FindEntry(m_aControlExchange->getFormItem()))
1379 : 0 : return DND_ACTION_NONE;
1380 : :
1381 [ # # ]: 0 : SvLBoxEntry* pDropTarget = GetEntry(aDropPos);
1382 [ # # ]: 0 : if (!pDropTarget)
1383 : 0 : return DND_ACTION_NONE;
1384 : :
1385 : 0 : FmFilterData* pData = (FmFilterData*)pDropTarget->GetUserData();
1386 : 0 : FmFormItem* pForm = NULL;
1387 [ # # ][ # # ]: 0 : if (pData->ISA(FmFilterItem))
1388 : : {
1389 [ # # ][ # # ]: 0 : pForm = PTR_CAST(FmFormItem,pData->GetParent()->GetParent());
[ # # ]
1390 [ # # ]: 0 : if (pForm != m_aControlExchange->getFormItem())
1391 : 0 : return DND_ACTION_NONE;
1392 : : }
1393 [ # # ][ # # ]: 0 : else if (pData->ISA(FmFilterItems))
1394 : : {
1395 [ # # ][ # # ]: 0 : pForm = PTR_CAST(FmFormItem,pData->GetParent());
[ # # ]
1396 [ # # ]: 0 : if (pForm != m_aControlExchange->getFormItem())
1397 : 0 : return DND_ACTION_NONE;
1398 : : }
1399 : : else
1400 : 0 : return DND_ACTION_NONE;
1401 : :
1402 : 0 : return rEvt.mnAction;
1403 : : }
1404 : : // -----------------------------------------------------------------------------
1405 : : namespace
1406 : : {
1407 : 0 : FmFilterItems* getTargetItems(SvLBoxEntry* _pTarget)
1408 : : {
1409 : 0 : FmFilterData* pData = static_cast<FmFilterData*>(_pTarget->GetUserData());
1410 : 0 : FmFilterItems* pTargetItems = pData->ISA(FmFilterItems)
1411 : : ?
1412 : 0 : PTR_CAST(FmFilterItems,pData)
1413 : : :
1414 [ # # # # ]: 0 : PTR_CAST(FmFilterItems,pData->GetParent());
[ # # ][ # # ]
[ # # ]
1415 : 0 : return pTargetItems;
1416 : : }
1417 : : }
1418 : : //------------------------------------------------------------------------
1419 : 0 : sal_Int8 FmFilterNavigator::ExecuteDrop( const ExecuteDropEvent& rEvt )
1420 : : {
1421 : : // ware schlecht, wenn nach dem Droppen noch gescrollt wird ...
1422 [ # # ]: 0 : if (m_aDropActionTimer.IsActive())
1423 [ # # ]: 0 : m_aDropActionTimer.Stop();
1424 : :
1425 : : // Format-Ueberpruefung
1426 [ # # ]: 0 : if (!m_aControlExchange.isDragSource())
1427 : 0 : return DND_ACTION_NONE;
1428 : :
1429 : : // das Ziel des Drop sowie einige Daten darueber
1430 : 0 : Point aDropPos = rEvt.maPosPixel;
1431 [ # # ]: 0 : SvLBoxEntry* pDropTarget = GetEntry( aDropPos );
1432 [ # # ]: 0 : if (!pDropTarget)
1433 : 0 : return DND_ACTION_NONE;
1434 : :
1435 : : // search the container where to add the items
1436 [ # # ]: 0 : FmFilterItems* pTargetItems = getTargetItems(pDropTarget);
1437 [ # # ]: 0 : SelectAll(sal_False);
1438 [ # # ]: 0 : SvLBoxEntry* pEntry = FindEntry(pTargetItems);
1439 [ # # ]: 0 : Select(pEntry, sal_True);
1440 [ # # ]: 0 : SetCurEntry(pEntry);
1441 : :
1442 [ # # ]: 0 : insertFilterItem(m_aControlExchange->getDraggedEntries(),pTargetItems,DND_ACTION_COPY == rEvt.mnAction);
1443 : :
1444 : 0 : return sal_True;
1445 : : }
1446 : :
1447 : : //------------------------------------------------------------------------
1448 : 0 : void FmFilterNavigator::InitEntry(SvLBoxEntry* pEntry,
1449 : : const XubString& rStr,
1450 : : const Image& rImg1,
1451 : : const Image& rImg2,
1452 : : SvLBoxButtonKind eButtonKind)
1453 : : {
1454 : 0 : SvTreeListBox::InitEntry( pEntry, rStr, rImg1, rImg2, eButtonKind );
1455 : 0 : SvLBoxString* pString = NULL;
1456 : :
1457 [ # # ]: 0 : if (((FmFilterData*)pEntry->GetUserData())->ISA(FmFilterItem))
1458 [ # # ][ # # ]: 0 : pString = new FmFilterString(pEntry, 0, rStr, ((FmFilterItem*)pEntry->GetUserData())->GetFieldName());
1459 [ # # ]: 0 : else if (((FmFilterData*)pEntry->GetUserData())->ISA(FmFilterItems))
1460 [ # # ]: 0 : pString = new FmFilterItemsString(pEntry, 0, rStr );
1461 : :
1462 [ # # ]: 0 : if (pString)
1463 : 0 : pEntry->ReplaceItem( pString, 1 );
1464 : 0 : }
1465 : :
1466 : : //------------------------------------------------------------------------
1467 : 0 : sal_Bool FmFilterNavigator::Select( SvLBoxEntry* pEntry, sal_Bool bSelect )
1468 : : {
1469 [ # # ]: 0 : if (bSelect == IsSelected(pEntry)) // das passiert manchmal, ich glaube, die Basisklasse geht zu sehr auf Nummer sicher ;)
1470 : 0 : return sal_True;
1471 : :
1472 [ # # ]: 0 : if (SvTreeListBox::Select(pEntry, bSelect))
1473 : : {
1474 [ # # ]: 0 : if (bSelect)
1475 : : {
1476 : 0 : FmFormItem* pFormItem = NULL;
1477 [ # # ]: 0 : if (((FmFilterData*)pEntry->GetUserData())->ISA(FmFilterItem))
1478 : 0 : pFormItem = (FmFormItem*)((FmFilterItem*)pEntry->GetUserData())->GetParent()->GetParent();
1479 [ # # ]: 0 : else if (((FmFilterData*)pEntry->GetUserData())->ISA(FmFilterItems))
1480 : 0 : pFormItem = (FmFormItem*)((FmFilterItem*)pEntry->GetUserData())->GetParent()->GetParent();
1481 [ # # ]: 0 : else if (((FmFilterData*)pEntry->GetUserData())->ISA(FmFormItem))
1482 : 0 : pFormItem = (FmFormItem*)pEntry->GetUserData();
1483 : :
1484 [ # # ]: 0 : if (pFormItem)
1485 : : {
1486 : : // will the controller be exchanged?
1487 [ # # ]: 0 : if (((FmFilterData*)pEntry->GetUserData())->ISA(FmFilterItem))
1488 : 0 : m_pModel->SetCurrentItems((FmFilterItems*)((FmFilterItem*)pEntry->GetUserData())->GetParent());
1489 [ # # ]: 0 : else if (((FmFilterData*)pEntry->GetUserData())->ISA(FmFilterItems))
1490 : 0 : m_pModel->SetCurrentItems((FmFilterItems*)pEntry->GetUserData());
1491 [ # # ]: 0 : else if (((FmFilterData*)pEntry->GetUserData())->ISA(FmFormItem))
1492 : 0 : m_pModel->SetCurrentController(((FmFormItem*)pEntry->GetUserData())->GetController());
1493 : : }
1494 : : }
1495 : 0 : return sal_True;
1496 : : }
1497 : : else
1498 : 0 : return sal_False;
1499 : : }
1500 : :
1501 : : //------------------------------------------------------------------------
1502 : 0 : void FmFilterNavigator::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
1503 : : {
1504 [ # # ]: 0 : if (rHint.ISA(FmFilterInsertedHint))
1505 : : {
1506 : 0 : FmFilterInsertedHint* pHint = (FmFilterInsertedHint*)&rHint;
1507 : 0 : Insert(pHint->GetData(), pHint->GetPos());
1508 : : }
1509 [ # # ]: 0 : else if( rHint.ISA(FilterClearingHint) )
1510 : : {
1511 : 0 : SvTreeListBox::Clear();
1512 : : }
1513 [ # # ]: 0 : else if( rHint.ISA(FmFilterRemovedHint) )
1514 : : {
1515 : 0 : FmFilterRemovedHint* pHint = (FmFilterRemovedHint*)&rHint;
1516 : 0 : Remove(pHint->GetData());
1517 : : }
1518 [ # # ]: 0 : else if( rHint.ISA(FmFilterTextChangedHint) )
1519 : : {
1520 : 0 : FmFilterTextChangedHint* pHint = (FmFilterTextChangedHint*)&rHint;
1521 : 0 : SvLBoxEntry* pEntry = FindEntry(pHint->GetData());
1522 [ # # ]: 0 : if (pEntry)
1523 [ # # ][ # # ]: 0 : SetEntryText( pEntry, pHint->GetData()->GetText());
[ # # ]
1524 : : }
1525 [ # # ]: 0 : else if( rHint.ISA(FmFilterCurrentChangedHint) )
1526 : : {
1527 : : // invalidate the entries
1528 [ # # ]: 0 : for (SvLBoxEntry* pEntry = First(); pEntry != NULL;
1529 : 0 : pEntry = Next(pEntry))
1530 : 0 : GetModel()->InvalidateEntry( pEntry );
1531 : : }
1532 : 0 : }
1533 : :
1534 : : //------------------------------------------------------------------------
1535 : 0 : SvLBoxEntry* FmFilterNavigator::FindEntry(const FmFilterData* pItem) const
1536 : : {
1537 : 0 : SvLBoxEntry* pEntry = NULL;
1538 [ # # ]: 0 : if (pItem)
1539 : : {
1540 [ # # ]: 0 : for (pEntry = First(); pEntry != NULL; pEntry = Next( pEntry ))
1541 : : {
1542 : 0 : FmFilterData* pEntryItem = (FmFilterData*)pEntry->GetUserData();
1543 [ # # ]: 0 : if (pEntryItem == pItem)
1544 : 0 : break;
1545 : : }
1546 : : }
1547 : 0 : return pEntry;
1548 : : }
1549 : :
1550 : : //------------------------------------------------------------------------
1551 : 0 : void FmFilterNavigator::Insert(FmFilterData* pItem, sal_uLong nPos)
1552 : : {
1553 [ # # ]: 0 : const FmParentData* pParent = pItem->GetParent() ? pItem->GetParent() : GetFilterModel();
1554 : :
1555 : : // insert the item
1556 : 0 : SvLBoxEntry* pParentEntry = FindEntry( pParent );
1557 [ # # ][ # # ]: 0 : InsertEntry( pItem->GetText(), pItem->GetImage(), pItem->GetImage(), pParentEntry, sal_False, nPos, pItem );
[ # # ][ # # ]
[ # # ]
1558 [ # # ]: 0 : if ( pParentEntry )
1559 : 0 : Expand( pParentEntry );
1560 : 0 : }
1561 : :
1562 : : //------------------------------------------------------------------------
1563 : 0 : void FmFilterNavigator::Remove(FmFilterData* pItem)
1564 : : {
1565 : : // der Entry zu den Daten
1566 : 0 : SvLBoxEntry* pEntry = FindEntry(pItem);
1567 : :
1568 [ # # ]: 0 : if (pEntry == m_pEditingCurrently)
1569 : : // cancel editing
1570 : 0 : EndEditing(sal_True);
1571 : :
1572 [ # # ]: 0 : if (pEntry)
1573 : 0 : GetModel()->Remove( pEntry );
1574 : 0 : }
1575 : : // -----------------------------------------------------------------------------
1576 : 0 : FmFormItem* FmFilterNavigator::getSelectedFilterItems(::std::vector<FmFilterItem*>& _rItemList)
1577 : : {
1578 : : // be sure that the data is only used within only one form!
1579 : 0 : FmFormItem* pFirstItem = NULL;
1580 : :
1581 : 0 : sal_Bool bHandled = sal_True;
1582 : 0 : sal_Bool bFoundSomething = sal_False;
1583 [ # # ][ # # ]: 0 : for (SvLBoxEntry* pEntry = FirstSelected();
[ # # ]
1584 : : bHandled && pEntry != NULL;
1585 : 0 : pEntry = NextSelected(pEntry))
1586 : : {
1587 [ # # ][ # # ]: 0 : FmFilterItem* pFilter = PTR_CAST(FmFilterItem, (FmFilterData*)pEntry->GetUserData());
[ # # ]
1588 [ # # ]: 0 : if (pFilter)
1589 : : {
1590 [ # # ][ # # ]: 0 : FmFormItem* pForm = PTR_CAST(FmFormItem,pFilter->GetParent()->GetParent());
[ # # ]
1591 [ # # ]: 0 : if (!pForm)
1592 : 0 : bHandled = sal_False;
1593 [ # # ]: 0 : else if (!pFirstItem)
1594 : 0 : pFirstItem = pForm;
1595 [ # # ]: 0 : else if (pFirstItem != pForm)
1596 : 0 : bHandled = sal_False;
1597 : :
1598 [ # # ]: 0 : if (bHandled)
1599 : : {
1600 [ # # ]: 0 : _rItemList.push_back(pFilter);
1601 : 0 : bFoundSomething = sal_True;
1602 : : }
1603 : : }
1604 : : }
1605 [ # # ][ # # ]: 0 : if ( !bHandled || !bFoundSomething )
1606 : 0 : pFirstItem = NULL;
1607 : 0 : return pFirstItem;
1608 : : }
1609 : : // -----------------------------------------------------------------------------
1610 : 0 : void FmFilterNavigator::insertFilterItem(const ::std::vector<FmFilterItem*>& _rFilterList,FmFilterItems* _pTargetItems,sal_Bool _bCopy)
1611 : : {
1612 : 0 : ::std::vector<FmFilterItem*>::const_iterator aEnd = _rFilterList.end();
1613 [ # # ][ # # ]: 0 : for ( ::std::vector< FmFilterItem* >::const_iterator i = _rFilterList.begin();
1614 : : i != aEnd;
1615 : : ++i
1616 : : )
1617 : : {
1618 : 0 : FmFilterItem* pLookupItem( *i );
1619 [ # # ]: 0 : if ( pLookupItem->GetParent() == _pTargetItems )
1620 : 0 : continue;
1621 : :
1622 [ # # ]: 0 : FmFilterItem* pFilterItem = _pTargetItems->Find( pLookupItem->GetComponentIndex() );
1623 [ # # ]: 0 : String aText = pLookupItem->GetText();
1624 [ # # ]: 0 : if ( !pFilterItem )
1625 : : {
1626 [ # # ][ # # ]: 0 : pFilterItem = new FmFilterItem( m_pModel->getORB(), _pTargetItems, pLookupItem->GetFieldName(), aText, pLookupItem->GetComponentIndex() );
[ # # ][ # # ]
1627 [ # # ]: 0 : m_pModel->Append( _pTargetItems, pFilterItem );
1628 : : }
1629 : :
1630 [ # # ]: 0 : if ( !_bCopy )
1631 [ # # ]: 0 : m_pModel->Remove( pLookupItem );
1632 : :
1633 : : // now set the text for the new dragged item
1634 [ # # ][ # # ]: 0 : m_pModel->SetTextForItem( pFilterItem, aText );
1635 [ # # ]: 0 : }
1636 : :
1637 [ # # ]: 0 : m_pModel->EnsureEmptyFilterRows( *_pTargetItems->GetParent() );
1638 : 0 : }
1639 : :
1640 : : //------------------------------------------------------------------------------
1641 : 0 : void FmFilterNavigator::StartDrag( sal_Int8 /*_nAction*/, const Point& /*_rPosPixel*/ )
1642 : : {
1643 [ # # ]: 0 : EndSelection();
1644 : :
1645 : : // be sure that the data is only used within a only one form!
1646 [ # # ]: 0 : m_aControlExchange.prepareDrag();
1647 : :
1648 [ # # ]: 0 : ::std::vector<FmFilterItem*> aItemList;
1649 [ # # ][ # # ]: 0 : if ( FmFormItem* pFirstItem = getSelectedFilterItems(aItemList) )
1650 : : {
1651 [ # # ]: 0 : m_aControlExchange->setDraggedEntries(aItemList);
1652 : 0 : m_aControlExchange->setFormItem(pFirstItem);
1653 [ # # ]: 0 : m_aControlExchange.startDrag( DND_ACTION_COPYMOVE );
1654 : 0 : }
1655 : 0 : }
1656 : :
1657 : : //------------------------------------------------------------------------------
1658 : 0 : void FmFilterNavigator::Command( const CommandEvent& rEvt )
1659 : : {
1660 : 0 : sal_Bool bHandled = sal_False;
1661 [ # # ]: 0 : switch (rEvt.GetCommand())
1662 : : {
1663 : : case COMMAND_CONTEXTMENU:
1664 : : {
1665 : : // die Stelle, an der geklickt wurde
1666 : 0 : Point aWhere;
1667 : 0 : SvLBoxEntry* pClicked = NULL;
1668 [ # # ]: 0 : if (rEvt.IsMouseEvent())
1669 : : {
1670 : 0 : aWhere = rEvt.GetMousePosPixel();
1671 [ # # ]: 0 : pClicked = GetEntry(aWhere);
1672 [ # # ]: 0 : if (pClicked == NULL)
1673 : : break;
1674 : :
1675 [ # # ][ # # ]: 0 : if (!IsSelected(pClicked))
1676 : : {
1677 [ # # ]: 0 : SelectAll(sal_False);
1678 [ # # ]: 0 : Select(pClicked, sal_True);
1679 [ # # ]: 0 : SetCurEntry(pClicked);
1680 : : }
1681 : : }
1682 : : else
1683 : : {
1684 [ # # ]: 0 : pClicked = GetCurEntry();
1685 [ # # ]: 0 : if (!pClicked)
1686 : : break;
1687 [ # # ]: 0 : aWhere = GetEntryPosition( pClicked );
1688 : : }
1689 : :
1690 [ # # ]: 0 : ::std::vector<FmFilterData*> aSelectList;
1691 [ # # ][ # # ]: 0 : for (SvLBoxEntry* pEntry = FirstSelected();
[ # # ]
1692 : : pEntry != NULL;
1693 : 0 : pEntry = NextSelected(pEntry))
1694 : : {
1695 : : // don't delete forms
1696 [ # # ][ # # ]: 0 : FmFormItem* pForm = PTR_CAST(FmFormItem, (FmFilterData*)pEntry->GetUserData());
[ # # ]
1697 [ # # ]: 0 : if (!pForm)
1698 [ # # ]: 0 : aSelectList.push_back((FmFilterData*)pEntry->GetUserData());
1699 : : }
1700 [ # # ]: 0 : if (aSelectList.size() == 1)
1701 : : {
1702 : : // don't delete the only empty row of a form
1703 [ # # ][ # # ]: 0 : FmFilterItems* pFilterItems = PTR_CAST(FmFilterItems, aSelectList[0]);
[ # # ]
1704 [ # # ]: 0 : if (pFilterItems && pFilterItems->GetChildren().empty()
[ # # # # ]
[ # # ]
1705 : 0 : && pFilterItems->GetParent()->GetChildren().size() == 1)
1706 : 0 : aSelectList.clear();
1707 : : }
1708 : :
1709 [ # # ][ # # ]: 0 : PopupMenu aContextMenu(SVX_RES(RID_FM_FILTER_MENU));
1710 : :
1711 : : // every condition could be deleted except the first one if its the only one
1712 [ # # ]: 0 : aContextMenu.EnableItem( SID_FM_DELETE, !aSelectList.empty() );
1713 : :
1714 : : //
1715 [ # # ]: 0 : sal_Bool bEdit = PTR_CAST(FmFilterItem, (FmFilterData*)pClicked->GetUserData()) != NULL &&
1716 [ # # # # ]: 0 : IsSelected(pClicked) && GetSelectionCount() == 1;
[ # # ][ # # ]
[ # # ][ # # ]
1717 : :
1718 : : aContextMenu.EnableItem( SID_FM_FILTER_EDIT,
1719 [ # # ]: 0 : bEdit );
1720 : : aContextMenu.EnableItem( SID_FM_FILTER_IS_NULL,
1721 [ # # ]: 0 : bEdit );
1722 : : aContextMenu.EnableItem( SID_FM_FILTER_IS_NOT_NULL,
1723 [ # # ]: 0 : bEdit );
1724 : :
1725 [ # # ]: 0 : aContextMenu.RemoveDisabledEntries(sal_True, sal_True);
1726 [ # # ]: 0 : sal_uInt16 nSlotId = aContextMenu.Execute( this, aWhere );
1727 [ # # # # ]: 0 : switch( nSlotId )
1728 : : {
1729 : : case SID_FM_FILTER_EDIT:
1730 : : {
1731 [ # # ]: 0 : EditEntry( pClicked );
1732 : 0 : } break;
1733 : : case SID_FM_FILTER_IS_NULL:
1734 : : case SID_FM_FILTER_IS_NOT_NULL:
1735 : : {
1736 [ # # ]: 0 : UniString aErrorMsg;
1737 [ # # ]: 0 : UniString aText;
1738 [ # # ]: 0 : if (nSlotId == SID_FM_FILTER_IS_NULL)
1739 [ # # ]: 0 : aText.AssignAscii("IS NULL");
1740 : : else
1741 [ # # ]: 0 : aText.AssignAscii("IS NOT NULL");
1742 : :
1743 : 0 : m_pModel->ValidateText((FmFilterItem*)pClicked->GetUserData(),
1744 [ # # ]: 0 : aText, aErrorMsg);
1745 [ # # ][ # # ]: 0 : m_pModel->SetTextForItem((FmFilterItem*)pClicked->GetUserData(), aText);
[ # # ][ # # ]
1746 : 0 : } break;
1747 : : case SID_FM_DELETE:
1748 : : {
1749 [ # # ]: 0 : DeleteSelection();
1750 : 0 : } break;
1751 : : }
1752 [ # # ]: 0 : bHandled = sal_True;
1753 : 0 : } break;
1754 : : }
1755 : :
1756 [ # # ]: 0 : if (!bHandled)
1757 : 0 : SvTreeListBox::Command( rEvt );
1758 : 0 : }
1759 : : // -----------------------------------------------------------------------------
1760 : 0 : SvLBoxEntry* FmFilterNavigator::getNextEntry(SvLBoxEntry* _pStartWith)
1761 : : {
1762 [ # # ]: 0 : SvLBoxEntry* pEntry = _pStartWith ? _pStartWith : LastSelected();
1763 : 0 : pEntry = Next(pEntry);
1764 : : // we need the next filter entry
1765 [ # # ][ # # ]: 0 : while( pEntry && GetChildCount( pEntry ) == 0 && pEntry != Last() )
[ # # ][ # # ]
1766 : 0 : pEntry = Next(pEntry);
1767 : 0 : return pEntry;
1768 : : }
1769 : : // -----------------------------------------------------------------------------
1770 : 0 : SvLBoxEntry* FmFilterNavigator::getPrevEntry(SvLBoxEntry* _pStartWith)
1771 : : {
1772 [ # # ]: 0 : SvLBoxEntry* pEntry = _pStartWith ? _pStartWith : FirstSelected();
1773 : 0 : pEntry = Prev(pEntry);
1774 : : // check if the previous entry is a filter, if so get the next prev
1775 [ # # ][ # # ]: 0 : if ( pEntry && GetChildCount( pEntry ) != 0 )
[ # # ]
1776 : : {
1777 : 0 : pEntry = Prev(pEntry);
1778 : : // if the entry is still no leaf return
1779 [ # # ][ # # ]: 0 : if ( pEntry && GetChildCount( pEntry ) != 0 )
[ # # ]
1780 : 0 : pEntry = NULL;
1781 : : }
1782 : 0 : return pEntry;
1783 : : }
1784 : : //------------------------------------------------------------------------
1785 : 0 : void FmFilterNavigator::KeyInput(const KeyEvent& rKEvt)
1786 : : {
1787 : 0 : const KeyCode& rKeyCode = rKEvt.GetKeyCode();
1788 : :
1789 [ # # # ]: 0 : switch ( rKeyCode.GetCode() )
1790 : : {
1791 : : case KEY_UP:
1792 : : case KEY_DOWN:
1793 : : {
1794 [ # # ][ # # ]: 0 : if ( !rKeyCode.IsMod1() || !rKeyCode.IsMod2() || rKeyCode.IsShift() )
[ # # ][ # # ]
1795 : : break;
1796 : :
1797 [ # # ]: 0 : ::std::vector<FmFilterItem*> aItemList;
1798 [ # # ][ # # ]: 0 : if ( !getSelectedFilterItems( aItemList ) )
1799 : : break;
1800 : :
1801 [ # # ]: 0 : ::std::mem_fun1_t<SvLBoxEntry*,FmFilterNavigator,SvLBoxEntry*> getter = ::std::mem_fun(&FmFilterNavigator::getNextEntry);
1802 [ # # ]: 0 : if ( rKeyCode.GetCode() == KEY_UP )
1803 [ # # ]: 0 : getter = ::std::mem_fun(&FmFilterNavigator::getPrevEntry);
1804 : :
1805 [ # # ]: 0 : SvLBoxEntry* pTarget = getter( this, NULL );
1806 [ # # ]: 0 : if ( !pTarget )
1807 : : break;
1808 : :
1809 [ # # ]: 0 : FmFilterItems* pTargetItems = getTargetItems( pTarget );
1810 [ # # ]: 0 : if ( !pTargetItems )
1811 : : break;
1812 : :
1813 [ # # ]: 0 : ::std::vector<FmFilterItem*>::const_iterator aEnd = aItemList.end();
1814 : 0 : sal_Bool bNextTargetItem = sal_True;
1815 [ # # ]: 0 : while ( bNextTargetItem )
1816 : : {
1817 [ # # ]: 0 : ::std::vector<FmFilterItem*>::const_iterator i = aItemList.begin();
1818 [ # # ][ # # ]: 0 : for (; i != aEnd; ++i)
1819 : : {
1820 [ # # ]: 0 : if ( (*i)->GetParent() == pTargetItems )
1821 : : {
1822 [ # # ]: 0 : pTarget = getter(this,pTarget);
1823 [ # # ]: 0 : if ( !pTarget )
1824 : : return;
1825 [ # # ]: 0 : pTargetItems = getTargetItems( pTarget );
1826 : 0 : break;
1827 : : }
1828 : : else
1829 : : {
1830 [ # # ]: 0 : FmFilterItem* pFilterItem = pTargetItems->Find( (*i)->GetComponentIndex() );
1831 : : // we found the text component so jump above
1832 [ # # ]: 0 : if ( pFilterItem )
1833 : : {
1834 [ # # ]: 0 : pTarget = getter( this, pTarget );
1835 [ # # ]: 0 : if ( !pTarget )
1836 : : return;
1837 : :
1838 [ # # ]: 0 : pTargetItems = getTargetItems( pTarget );
1839 : 0 : break;
1840 : : }
1841 : : }
1842 : : }
1843 [ # # ][ # # ]: 0 : bNextTargetItem = i != aEnd && pTargetItems;
[ # # ]
1844 : : }
1845 : :
1846 [ # # ]: 0 : if ( pTargetItems )
1847 : : {
1848 [ # # ]: 0 : insertFilterItem( aItemList, pTargetItems );
1849 : : return;
1850 [ # # # ]: 0 : }
1851 : : }
1852 : 0 : break;
1853 : :
1854 : : case KEY_DELETE:
1855 : : {
1856 [ # # ]: 0 : if ( rKeyCode.GetModifier() )
1857 : 0 : break;
1858 : :
1859 [ # # ][ # # ]: 0 : if ( !IsSelected( First() ) || GetEntryCount() > 1 )
[ # # ]
1860 : 0 : DeleteSelection();
1861 : 0 : return;
1862 : : }
1863 : : }
1864 : :
1865 : 0 : SvTreeListBox::KeyInput(rKEvt);
1866 : : }
1867 : :
1868 : : //------------------------------------------------------------------------------
1869 : 0 : void FmFilterNavigator::DeleteSelection()
1870 : : {
1871 : : // to avoid the deletion of an entry twice (e.g. deletion of a parent and afterward
1872 : : // the deletion of it's child, i have to shrink the selecton list
1873 [ # # ]: 0 : ::std::vector<SvLBoxEntry*> aEntryList;
1874 [ # # ][ # # ]: 0 : for (SvLBoxEntry* pEntry = FirstSelected();
1875 : : pEntry != NULL;
1876 [ # # ]: 0 : pEntry = NextSelected(pEntry))
1877 : : {
1878 [ # # ][ # # ]: 0 : FmFilterItem* pFilterItem = PTR_CAST(FmFilterItem, (FmFilterData*)pEntry->GetUserData());
[ # # ]
1879 [ # # ][ # # ]: 0 : if (pFilterItem && IsSelected(GetParent(pEntry)))
[ # # ][ # # ]
[ # # ]
1880 : 0 : continue;
1881 : :
1882 [ # # ][ # # ]: 0 : FmFormItem* pForm = PTR_CAST(FmFormItem, (FmFilterData*)pEntry->GetUserData());
[ # # ]
1883 [ # # ]: 0 : if (!pForm)
1884 [ # # ]: 0 : aEntryList.push_back(pEntry);
1885 : : }
1886 : :
1887 : : // Remove the selection
1888 [ # # ]: 0 : SelectAll(sal_False);
1889 : :
1890 [ # # ][ # # ]: 0 : for (::std::vector<SvLBoxEntry*>::reverse_iterator i = aEntryList.rbegin();
[ # # ]
1891 : : // link problems with operator ==
1892 [ # # ][ # # ]: 0 : i.base() != aEntryList.rend().base(); ++i)
1893 : : {
1894 [ # # ][ # # ]: 0 : m_pModel->Remove((FmFilterData*)(*i)->GetUserData());
1895 : 0 : }
1896 : 0 : }
1897 : : // -----------------------------------------------------------------------------
1898 : :
1899 : : //========================================================================
1900 : : // class FmFilterNavigatorWin
1901 : : //========================================================================
1902 : 0 : FmFilterNavigatorWin::FmFilterNavigatorWin( SfxBindings* _pBindings, SfxChildWindow* _pMgr,
1903 : : Window* _pParent )
1904 : : :SfxDockingWindow( _pBindings, _pMgr, _pParent, WinBits(WB_STDMODELESS|WB_SIZEABLE|WB_ROLLABLE|WB_3DLOOK|WB_DOCKABLE) )
1905 [ # # ]: 0 : ,SfxControllerItem( SID_FM_FILTER_NAVIGATOR_CONTROL, *_pBindings )
1906 : : {
1907 [ # # ]: 0 : SetHelpId( HID_FILTER_NAVIGATOR_WIN );
1908 : :
1909 [ # # ][ # # ]: 0 : m_pNavigator = new FmFilterNavigator( this );
1910 [ # # ]: 0 : m_pNavigator->Show();
1911 [ # # ][ # # ]: 0 : SetText( SVX_RES(RID_STR_FILTER_NAVIGATOR) );
[ # # ][ # # ]
1912 : 0 : SfxDockingWindow::SetFloatingSize( Size(200,200) );
1913 : 0 : }
1914 : :
1915 : : //------------------------------------------------------------------------
1916 [ # # ]: 0 : FmFilterNavigatorWin::~FmFilterNavigatorWin()
1917 : : {
1918 [ # # ][ # # ]: 0 : delete m_pNavigator;
1919 [ # # ]: 0 : }
1920 : :
1921 : : //-----------------------------------------------------------------------
1922 : 0 : void FmFilterNavigatorWin::UpdateContent(FmFormShell* pFormShell)
1923 : : {
1924 [ # # ]: 0 : if (!pFormShell)
1925 [ # # ][ # # ]: 0 : m_pNavigator->UpdateContent( NULL, NULL );
1926 : : else
1927 : : {
1928 [ # # ]: 0 : Reference< XFormController > xController(pFormShell->GetImpl()->getActiveInternalController());
1929 : 0 : Reference< XIndexAccess > xContainer;
1930 [ # # ]: 0 : if (xController.is())
1931 : : {
1932 [ # # ]: 0 : Reference< XChild > xChild(xController, UNO_QUERY);
1933 [ # # ][ # # ]: 0 : for (Reference< XInterface > xParent(xChild->getParent());
[ # # # # ]
1934 : 0 : xParent.is();
1935 [ # # ][ # # ]: 0 : xParent = xChild.is() ? xChild->getParent() : Reference< XInterface > ())
[ # # ]
1936 : : {
1937 [ # # ][ # # ]: 0 : xContainer = Reference< XIndexAccess > (xParent, UNO_QUERY);
1938 [ # # ][ # # ]: 0 : xChild = Reference< XChild > (xParent, UNO_QUERY);
1939 : 0 : }
1940 : : }
1941 [ # # ]: 0 : m_pNavigator->UpdateContent(xContainer, xController);
1942 : : }
1943 : 0 : }
1944 : :
1945 : : //-----------------------------------------------------------------------
1946 : 0 : void FmFilterNavigatorWin::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
1947 : : {
1948 [ # # ][ # # ]: 0 : if( !pState || SID_FM_FILTER_NAVIGATOR_CONTROL != nSID )
1949 : 0 : return;
1950 : :
1951 [ # # ]: 0 : if( eState >= SFX_ITEM_AVAILABLE )
1952 : : {
1953 [ # # ][ # # ]: 0 : FmFormShell* pShell = PTR_CAST( FmFormShell,((SfxObjectItem*)pState)->GetShell() );
1954 : 0 : UpdateContent( pShell );
1955 : : }
1956 : : else
1957 : 0 : UpdateContent( NULL );
1958 : : }
1959 : :
1960 : : //-----------------------------------------------------------------------
1961 : 0 : sal_Bool FmFilterNavigatorWin::Close()
1962 : : {
1963 [ # # ][ # # ]: 0 : if ( m_pNavigator && m_pNavigator->IsEditingActive() )
[ # # ]
1964 : 0 : m_pNavigator->EndEditing();
1965 : :
1966 [ # # ][ # # ]: 0 : if ( m_pNavigator && m_pNavigator->IsEditingActive() )
[ # # ]
1967 : : // the EndEditing was vetoed (perhaps of an syntax error or such)
1968 : 0 : return sal_False;
1969 : :
1970 : 0 : UpdateContent( NULL );
1971 : 0 : return SfxDockingWindow::Close();
1972 : : }
1973 : :
1974 : : //-----------------------------------------------------------------------
1975 : 0 : void FmFilterNavigatorWin::FillInfo( SfxChildWinInfo& rInfo ) const
1976 : : {
1977 : 0 : SfxDockingWindow::FillInfo( rInfo );
1978 : 0 : rInfo.bVisible = sal_False;
1979 : 0 : }
1980 : :
1981 : : //-----------------------------------------------------------------------
1982 : 0 : Size FmFilterNavigatorWin::CalcDockingSize( SfxChildAlignment eAlign )
1983 : : {
1984 [ # # ][ # # ]: 0 : if ( ( eAlign == SFX_ALIGN_TOP ) || ( eAlign == SFX_ALIGN_BOTTOM ) )
1985 : 0 : return Size();
1986 : :
1987 : 0 : return SfxDockingWindow::CalcDockingSize( eAlign );
1988 : : }
1989 : :
1990 : : //-----------------------------------------------------------------------
1991 : 0 : SfxChildAlignment FmFilterNavigatorWin::CheckAlignment( SfxChildAlignment eActAlign, SfxChildAlignment eAlign )
1992 : : {
1993 [ # # ]: 0 : switch (eAlign)
1994 : : {
1995 : : case SFX_ALIGN_LEFT:
1996 : : case SFX_ALIGN_RIGHT:
1997 : : case SFX_ALIGN_NOALIGNMENT:
1998 : 0 : return (eAlign);
1999 : : default:
2000 : 0 : break;
2001 : : }
2002 : :
2003 : 0 : return (eActAlign);
2004 : : }
2005 : :
2006 : : //------------------------------------------------------------------------
2007 : 0 : void FmFilterNavigatorWin::Resize()
2008 : : {
2009 [ # # ]: 0 : SfxDockingWindow::Resize();
2010 : :
2011 [ # # ][ # # ]: 0 : Size aLogOutputSize = PixelToLogic( GetOutputSizePixel(), MAP_APPFONT );
[ # # ][ # # ]
2012 : 0 : Size aLogExplSize = aLogOutputSize;
2013 : 0 : aLogExplSize.Width() -= 6;
2014 : 0 : aLogExplSize.Height() -= 6;
2015 : :
2016 [ # # ][ # # ]: 0 : Point aExplPos = LogicToPixel( Point(3,3), MAP_APPFONT );
[ # # ]
2017 [ # # ][ # # ]: 0 : Size aExplSize = LogicToPixel( aLogExplSize, MAP_APPFONT );
[ # # ]
2018 : :
2019 [ # # ]: 0 : m_pNavigator->SetPosSizePixel( aExplPos, aExplSize );
2020 : 0 : }
2021 : : // -----------------------------------------------------------------------------
2022 : 0 : void FmFilterNavigatorWin::GetFocus()
2023 : : {
2024 : : // oj #97405#
2025 [ # # ]: 0 : if ( m_pNavigator )
2026 : 0 : m_pNavigator->GrabFocus();
2027 : 0 : }
2028 : : // -----------------------------------------------------------------------------
2029 : :
2030 : :
2031 : : //========================================================================
2032 : : // class FmFilterNavigatorWinMgr
2033 : : //========================================================================
2034 [ # # ][ + - ]: 135 : SFX_IMPL_DOCKINGWINDOW( FmFilterNavigatorWinMgr, SID_FM_FILTER_NAVIGATOR )
[ # # ]
2035 : :
2036 : : //-----------------------------------------------------------------------
2037 : 0 : FmFilterNavigatorWinMgr::FmFilterNavigatorWinMgr( Window *_pParent, sal_uInt16 _nId,
2038 : : SfxBindings *_pBindings, SfxChildWinInfo* _pInfo )
2039 : 0 : :SfxChildWindow( _pParent, _nId )
2040 : : {
2041 [ # # ][ # # ]: 0 : pWindow = new FmFilterNavigatorWin( _pBindings, this, _pParent );
2042 : 0 : eChildAlignment = SFX_ALIGN_NOALIGNMENT;
2043 [ # # ]: 0 : ((SfxDockingWindow*)pWindow)->Initialize( _pInfo );
2044 : 0 : }
2045 : :
2046 : : //........................................................................
2047 : : } // namespace svxform
2048 : : //........................................................................
2049 : :
2050 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|