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 : :
30 : : #include "fmdocumentclassification.hxx"
31 : : #include "fmobj.hxx"
32 : : #include "fmpgeimp.hxx"
33 : : #include "fmprop.hrc"
34 : : #include "svx/fmresids.hrc"
35 : : #include "fmservs.hxx"
36 : : #include "fmshimp.hxx"
37 : : #include "svx/fmtools.hxx"
38 : : #include "fmundo.hxx"
39 : : #include "fmvwimp.hxx"
40 : : #include "formcontrolfactory.hxx"
41 : : #include "svx/sdrpaintwindow.hxx"
42 : : #include "svx/svditer.hxx"
43 : : #include "svx/dataaccessdescriptor.hxx"
44 : : #include "svx/dialmgr.hxx"
45 : : #include "svx/fmglob.hxx"
46 : : #include "svx/fmmodel.hxx"
47 : : #include "svx/fmpage.hxx"
48 : : #include "svx/fmshell.hxx"
49 : : #include "svx/fmview.hxx"
50 : : #include "svx/sdrpagewindow.hxx"
51 : : #include "svx/svdogrp.hxx"
52 : : #include "svx/svdpagv.hxx"
53 : : #include "svx/xmlexchg.hxx"
54 : :
55 : : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
56 : : #include <com/sun/star/style/VerticalAlignment.hpp>
57 : : #include <com/sun/star/lang/XInitialization.hpp>
58 : : #include <com/sun/star/sdbc/XRowSet.hpp>
59 : : #include <com/sun/star/form/XLoadable.hpp>
60 : : #include <com/sun/star/awt/VisualEffect.hpp>
61 : : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
62 : : #include <com/sun/star/util/XNumberFormats.hpp>
63 : : #include <com/sun/star/sdb/CommandType.hpp>
64 : : #include <com/sun/star/sdbc/DataType.hpp>
65 : : #include <com/sun/star/sdbc/ColumnValue.hpp>
66 : : #include <com/sun/star/form/FormComponentType.hpp>
67 : : #include <com/sun/star/form/FormButtonType.hpp>
68 : : #include <com/sun/star/form/XReset.hpp>
69 : : #include <com/sun/star/form/binding/XBindableValue.hpp>
70 : : #include <com/sun/star/form/binding/XValueBinding.hpp>
71 : : #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
72 : : #include <com/sun/star/awt/XTabControllerModel.hpp>
73 : : #include <com/sun/star/awt/XControlContainer.hpp>
74 : : #include <com/sun/star/awt/XTabController.hpp>
75 : : #include <com/sun/star/container/XIndexAccess.hpp>
76 : : #include <com/sun/star/awt/XControl.hpp>
77 : : #include <com/sun/star/lang/XUnoTunnel.hpp>
78 : : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
79 : : #include <com/sun/star/sdbc/XPreparedStatement.hpp>
80 : : #include <com/sun/star/sdb/XQueriesSupplier.hpp>
81 : : #include <com/sun/star/container/XContainer.hpp>
82 : :
83 : : #include <comphelper/enumhelper.hxx>
84 : : #include <comphelper/extract.hxx>
85 : : #include <comphelper/namedvaluecollection.hxx>
86 : : #include <comphelper/numbers.hxx>
87 : : #include <comphelper/property.hxx>
88 : : #include <cppuhelper/exc_hlp.hxx>
89 : : #include <unotools/moduleoptions.hxx>
90 : : #include <tools/diagnose_ex.h>
91 : : #include <vcl/msgbox.hxx>
92 : : #include <vcl/stdtext.hxx>
93 : : #include <osl/mutex.hxx>
94 : : #include <rtl/logfile.hxx>
95 : :
96 : : #include <algorithm>
97 : :
98 : : using namespace ::comphelper;
99 : : using namespace ::svx;
100 : : using namespace ::svxform;
101 : :
102 : : using namespace ::com::sun::star;
103 : : /** === begin UNO using === **/
104 : : using ::com::sun::star::uno::Exception;
105 : : using ::com::sun::star::uno::RuntimeException;
106 : : using ::com::sun::star::uno::XInterface;
107 : : using ::com::sun::star::uno::Sequence;
108 : : using ::com::sun::star::uno::UNO_QUERY;
109 : : using ::com::sun::star::uno::UNO_QUERY_THROW;
110 : : using ::com::sun::star::uno::UNO_SET_THROW;
111 : : using ::com::sun::star::uno::Type;
112 : : using ::com::sun::star::uno::Reference;
113 : : using ::com::sun::star::uno::Any;
114 : : using ::com::sun::star::uno::makeAny;
115 : : using ::com::sun::star::style::VerticalAlignment_MIDDLE;
116 : : using ::com::sun::star::form::FormButtonType_SUBMIT;
117 : : using ::com::sun::star::form::binding::XValueBinding;
118 : : using ::com::sun::star::form::binding::XBindableValue;
119 : : using ::com::sun::star::lang::XComponent;
120 : : using ::com::sun::star::container::XIndexAccess;
121 : : using ::com::sun::star::form::XForm;
122 : : using ::com::sun::star::form::runtime::XFormController;
123 : : using ::com::sun::star::script::XEventAttacherManager;
124 : : using ::com::sun::star::awt::XTabControllerModel;
125 : : using ::com::sun::star::container::XChild;
126 : : using ::com::sun::star::container::XEnumeration;
127 : : using ::com::sun::star::task::XInteractionHandler;
128 : : using ::com::sun::star::lang::XInitialization;
129 : : using ::com::sun::star::awt::XTabController;
130 : : using ::com::sun::star::lang::XUnoTunnel;
131 : : using ::com::sun::star::awt::XControlContainer;
132 : : using ::com::sun::star::awt::XControl;
133 : : using ::com::sun::star::form::XFormComponent;
134 : : using ::com::sun::star::form::XForm;
135 : : using ::com::sun::star::lang::IndexOutOfBoundsException;
136 : : using ::com::sun::star::lang::WrappedTargetException;
137 : : using ::com::sun::star::container::XContainer;
138 : : using ::com::sun::star::container::ContainerEvent;
139 : : using ::com::sun::star::lang::EventObject;
140 : : using ::com::sun::star::beans::NamedValue;
141 : : using ::com::sun::star::sdb::SQLErrorEvent;
142 : : using ::com::sun::star::sdbc::XRowSet;
143 : : using ::com::sun::star::beans::XPropertySet;
144 : : using ::com::sun::star::container::XElementAccess;
145 : : using ::com::sun::star::awt::XWindow;
146 : : using ::com::sun::star::awt::FocusEvent;
147 : : using ::com::sun::star::ui::dialogs::XExecutableDialog;
148 : : using ::com::sun::star::sdbc::XDataSource;
149 : : using ::com::sun::star::container::XIndexContainer;
150 : : using ::com::sun::star::sdbc::XConnection;
151 : : using ::com::sun::star::container::XNameAccess;
152 : : using ::com::sun::star::sdb::SQLContext;
153 : : using ::com::sun::star::sdbc::SQLWarning;
154 : : using ::com::sun::star::sdbc::SQLException;
155 : : using ::com::sun::star::util::XNumberFormatsSupplier;
156 : : using ::com::sun::star::util::XNumberFormats;
157 : : using ::com::sun::star::beans::XPropertySetInfo;
158 : : /** === end UNO using === **/
159 : : namespace FormComponentType = ::com::sun::star::form::FormComponentType;
160 : : namespace CommandType = ::com::sun::star::sdb::CommandType;
161 : : namespace DataType = ::com::sun::star::sdbc::DataType;
162 : :
163 : : //------------------------------------------------------------------------------
164 [ - + ]: 116 : class FmXFormView::ObjectRemoveListener : public SfxListener
165 : : {
166 : : FmXFormView* m_pParent;
167 : : public:
168 : : ObjectRemoveListener( FmXFormView* pParent );
169 : : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
170 : : };
171 : :
172 : : //========================================================================
173 : : DBG_NAME(FormViewPageWindowAdapter)
174 : : //------------------------------------------------------------------------
175 : 93 : FormViewPageWindowAdapter::FormViewPageWindowAdapter( const ::comphelper::ComponentContext& _rContext, const SdrPageWindow& _rWindow, FmXFormView* _pViewImpl )
176 : : : m_xControlContainer( _rWindow.GetControlContainer() ),
177 : : m_aContext( _rContext ),
178 : : m_pViewImpl( _pViewImpl ),
179 [ + - ][ + - ]: 93 : m_pWindow( dynamic_cast< Window* >( &_rWindow.GetPaintWindow().GetOutputDevice() ) )
[ + - ][ - + ]
180 : : {
181 : : DBG_CTOR(FormViewPageWindowAdapter,NULL);
182 : :
183 : : // create an XFormController for every form
184 [ - + ]: 93 : FmFormPage* pFormPage = dynamic_cast< FmFormPage* >( _rWindow.GetPageView().GetPage() );
185 : : DBG_ASSERT( pFormPage, "FormViewPageWindowAdapter::FormViewPageWindowAdapter: no FmFormPage found!" );
186 [ + - ]: 93 : if ( pFormPage )
187 : : {
188 : : try
189 : : {
190 [ + - ][ + + ]: 93 : Reference< XIndexAccess > xForms( pFormPage->GetForms(), UNO_QUERY_THROW );
191 [ + - ][ + - ]: 90 : sal_uInt32 nLength = xForms->getCount();
192 [ + + ]: 110 : for (sal_uInt32 i = 0; i < nLength; i++)
193 : : {
194 [ + - ][ + - ]: 20 : Reference< XForm > xForm( xForms->getByIndex(i), UNO_QUERY );
[ + - ]
195 [ + - ]: 20 : if ( xForm.is() )
196 [ + - ][ + - ]: 20 : setController( xForm, NULL );
197 [ - + ]: 113 : }
198 : : }
199 [ + - ]: 3 : catch (const Exception&)
200 : : {
201 : : DBG_UNHANDLED_EXCEPTION();
202 : : }
203 : : }
204 : 93 : }
205 : : // -----------------------------------------------------------------------------
206 [ + - ]: 82 : FormViewPageWindowAdapter::~FormViewPageWindowAdapter()
207 : : {
208 : : DBG_DTOR(FormViewPageWindowAdapter,NULL);
209 [ - + ]: 164 : }
210 : :
211 : : //------------------------------------------------------------------
212 : 82 : void FormViewPageWindowAdapter::dispose()
213 : : {
214 [ + - ][ + - ]: 198 : for ( ::std::vector< Reference< XFormController > >::const_iterator i = m_aControllerList.begin();
[ + + ]
215 : 99 : i != m_aControllerList.end();
216 : : ++i
217 : : )
218 : : {
219 : : try
220 : : {
221 [ + - ]: 17 : Reference< XFormController > xController( *i, UNO_QUERY_THROW );
222 : :
223 : : // detaching the events
224 [ + - ][ + - ]: 17 : Reference< XChild > xControllerModel( xController->getModel(), UNO_QUERY );
[ + - ]
225 [ + - ]: 17 : if ( xControllerModel.is() )
226 : : {
227 [ + - ][ + - ]: 17 : Reference< XEventAttacherManager > xEventManager( xControllerModel->getParent(), UNO_QUERY_THROW );
[ + - ]
228 [ + - ]: 17 : Reference< XInterface > xControllerNormalized( xController, UNO_QUERY_THROW );
229 [ + - ][ + - ]: 17 : xEventManager->detach( i - m_aControllerList.begin(), xControllerNormalized );
[ + - ]
230 : : }
231 : :
232 : : // dispose the formcontroller
233 [ + - ]: 17 : Reference< XComponent > xComp( xController, UNO_QUERY_THROW );
234 [ + - ][ + - ]: 17 : xComp->dispose();
[ # # ]
235 : : }
236 [ # # ]: 0 : catch (const Exception&)
237 : : {
238 : : DBG_UNHANDLED_EXCEPTION();
239 : : }
240 : : }
241 : :
242 : 82 : m_aControllerList.clear();
243 : 82 : }
244 : :
245 : :
246 : : //------------------------------------------------------------------------------
247 : 0 : sal_Bool SAL_CALL FormViewPageWindowAdapter::hasElements(void) throw( RuntimeException )
248 : : {
249 : 0 : return getCount() != 0;
250 : : }
251 : :
252 : : //------------------------------------------------------------------------------
253 : 0 : Type SAL_CALL FormViewPageWindowAdapter::getElementType(void) throw( RuntimeException )
254 : : {
255 : 0 : return ::getCppuType((const Reference< XFormController>*)0);
256 : : }
257 : :
258 : : // XEnumerationAccess
259 : : //------------------------------------------------------------------------------
260 : 0 : Reference< XEnumeration > SAL_CALL FormViewPageWindowAdapter::createEnumeration(void) throw( RuntimeException )
261 : : {
262 [ # # ][ # # ]: 0 : return new ::comphelper::OEnumerationByIndex(this);
[ # # ]
263 : : }
264 : :
265 : : // XIndexAccess
266 : : //------------------------------------------------------------------------------
267 : 0 : sal_Int32 SAL_CALL FormViewPageWindowAdapter::getCount(void) throw( RuntimeException )
268 : : {
269 : 0 : return m_aControllerList.size();
270 : : }
271 : :
272 : : //------------------------------------------------------------------------------
273 : 0 : Any SAL_CALL FormViewPageWindowAdapter::getByIndex(sal_Int32 nIndex) throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
274 : : {
275 [ # # # # ]: 0 : if (nIndex < 0 ||
[ # # ]
276 : 0 : nIndex >= getCount())
277 [ # # ]: 0 : throw IndexOutOfBoundsException();
278 : :
279 : 0 : Any aElement;
280 [ # # ]: 0 : aElement <<= m_aControllerList[nIndex];
281 : 0 : return aElement;
282 : : }
283 : :
284 : : //------------------------------------------------------------------------
285 : 6 : void SAL_CALL FormViewPageWindowAdapter::makeVisible( const Reference< XControl >& _Control ) throw (RuntimeException)
286 : : {
287 [ + - ]: 6 : SolarMutexGuard aSolarGuard;
288 : :
289 [ + - ]: 6 : Reference< XWindow > xWindow( _Control, UNO_QUERY );
290 [ + - ][ + - ]: 6 : if ( xWindow.is() && m_pViewImpl->getView() && m_pWindow )
[ + - ][ + - ]
291 : : {
292 [ + - ][ + - ]: 6 : awt::Rectangle aRect = xWindow->getPosSize();
293 [ + - ]: 6 : ::Rectangle aNewRect( aRect.X, aRect.Y, aRect.X + aRect.Width, aRect.Y + aRect.Height );
294 [ + - ]: 6 : aNewRect = m_pWindow->PixelToLogic( aNewRect );
295 [ + - ]: 6 : m_pViewImpl->getView()->MakeVisible( aNewRect, *m_pWindow );
296 [ + - ]: 6 : }
297 : 6 : }
298 : :
299 : : //------------------------------------------------------------------------
300 : 0 : Reference< XFormController > getControllerSearchChildren( const Reference< XIndexAccess > & xIndex, const Reference< XTabControllerModel > & xModel)
301 : : {
302 [ # # ][ # # ]: 0 : if (xIndex.is() && xIndex->getCount())
[ # # ]
303 : : {
304 : 0 : Reference< XFormController > xController;
305 : :
306 [ # # ][ # # ]: 0 : for (sal_Int32 n = xIndex->getCount(); n-- && !xController.is(); )
[ # # ][ # # ]
[ # # ]
307 : : {
308 [ # # ][ # # ]: 0 : xIndex->getByIndex(n) >>= xController;
[ # # ]
309 [ # # ][ # # ]: 0 : if ((XTabControllerModel*)xModel.get() == (XTabControllerModel*)xController->getModel().get())
[ # # ][ # # ]
[ # # ]
310 : 0 : return xController;
311 : : else
312 : : {
313 [ # # ][ # # ]: 0 : xController = getControllerSearchChildren(Reference< XIndexAccess > (xController, UNO_QUERY), xModel);
[ # # ]
314 [ # # ]: 0 : if ( xController.is() )
315 : 0 : return xController;
316 : : }
317 [ # # ]: 0 : }
318 : : }
319 : 0 : return Reference< XFormController > ();
320 : : }
321 : :
322 : : // Search the according controller
323 : : //------------------------------------------------------------------------
324 : 11 : Reference< XFormController > FormViewPageWindowAdapter::getController( const Reference< XForm > & xForm ) const
325 : : {
326 [ + - ]: 11 : Reference< XTabControllerModel > xModel(xForm, UNO_QUERY);
327 [ + - ][ + - ]: 33 : for (::std::vector< Reference< XFormController > >::const_iterator i = m_aControllerList.begin();
328 : 11 : i != m_aControllerList.end(); ++i)
329 : : {
330 [ + - ][ + - ]: 11 : if ((XTabControllerModel*)(*i)->getModel().get() == (XTabControllerModel*)xModel.get())
[ + - ][ + - ]
[ + - ]
331 : 11 : return *i;
332 : :
333 : : // the current-round controller isn't the right one. perhaps one of it's children ?
334 [ # # ][ # # ]: 0 : Reference< XFormController > xChildSearch = getControllerSearchChildren(Reference< XIndexAccess > (*i, UNO_QUERY), xModel);
335 [ # # ]: 0 : if (xChildSearch.is())
336 : 0 : return xChildSearch;
337 [ # # ]: 0 : }
338 : 11 : return Reference< XFormController > ();
339 : : }
340 : :
341 : : //------------------------------------------------------------------------
342 : 20 : void FormViewPageWindowAdapter::setController(const Reference< XForm > & xForm, const Reference< XFormController >& _rxParentController )
343 : : {
344 : : DBG_ASSERT( xForm.is(), "FormViewPageWindowAdapter::setController: there should be a form!" );
345 [ + - ]: 20 : Reference< XIndexAccess > xFormCps(xForm, UNO_QUERY);
346 [ - + ]: 20 : if (!xFormCps.is())
347 : : return;
348 : :
349 [ + - ]: 20 : Reference< XTabControllerModel > xTabOrder(xForm, UNO_QUERY);
350 : :
351 : : // create a form controller
352 [ + - ][ + - ]: 20 : Reference< XFormController > xController( m_aContext.createComponent( FM_FORM_CONTROLLER ), UNO_QUERY );
[ + - ]
353 [ - + ]: 20 : if ( !xController.is() )
354 : : {
355 [ # # ][ # # ]: 0 : ShowServiceNotAvailableError( m_pWindow, FM_FORM_CONTROLLER, sal_True );
[ # # ][ # # ]
356 : : return;
357 : : }
358 : :
359 : 20 : Reference< XInteractionHandler > xHandler;
360 [ - + ]: 20 : if ( _rxParentController.is() )
361 [ # # ][ # # ]: 0 : xHandler = _rxParentController->getInteractionHandler();
[ # # ]
362 : : else
363 : : {
364 : : // TODO: should we create a default handler? Not really necessary, since the
365 : : // FormController itself has a default fallback
366 : : }
367 [ - + ]: 20 : if ( xHandler.is() )
368 [ # # ][ # # ]: 0 : xController->setInteractionHandler( xHandler );
369 : :
370 [ + - ][ + - ]: 20 : xController->setContext( this );
[ + - ]
371 : :
372 [ + - ][ + - ]: 20 : xController->setModel( xTabOrder );
373 [ + - ][ + - ]: 20 : xController->setContainer( m_xControlContainer );
374 [ + - ][ + - ]: 20 : xController->activateTabOrder();
375 [ + - ][ + - ]: 20 : xController->addActivateListener( m_pViewImpl );
[ + - ][ + - ]
376 : :
377 [ - + ]: 20 : if ( _rxParentController.is() )
378 [ # # ][ # # ]: 0 : _rxParentController->addChildController( xController );
379 : : else
380 : : {
381 [ + - ]: 20 : m_aControllerList.push_back(xController);
382 : :
383 [ + - ][ + - ]: 20 : xController->setParent( *this );
[ + - ]
384 : :
385 : : // attaching the events
386 [ + - ][ + - ]: 20 : Reference< XEventAttacherManager > xEventManager( xForm->getParent(), UNO_QUERY );
[ + - ]
387 [ + - ]: 20 : Reference< XInterface > xIfc(xController, UNO_QUERY);
388 [ + - ][ + - ]: 20 : xEventManager->attach(m_aControllerList.size() - 1, xIfc, makeAny(xController) );
[ + - ]
389 : : }
390 : :
391 : : // jetzt die Subforms durchgehen
392 [ + - ][ + - ]: 20 : sal_uInt32 nLength = xFormCps->getCount();
393 : 20 : Reference< XForm > xSubForm;
394 [ + + ]: 52 : for (sal_uInt32 i = 0; i < nLength; i++)
395 : : {
396 [ + - ][ + - ]: 32 : if ( xFormCps->getByIndex(i) >>= xSubForm )
[ + - ][ - + ]
397 [ # # ]: 0 : setController( xSubForm, xController );
398 [ - + ][ - + ]: 20 : }
[ + - ]
399 : : }
400 : :
401 : : //------------------------------------------------------------------------
402 : 9 : void FormViewPageWindowAdapter::updateTabOrder( const Reference< XForm >& _rxForm )
403 : : {
404 : : OSL_PRECOND( _rxForm.is(), "FormViewPageWindowAdapter::updateTabOrder: illegal argument!" );
405 [ - + ]: 9 : if ( !_rxForm.is() )
406 : 9 : return;
407 : :
408 : : try
409 : : {
410 [ + - ][ + - ]: 9 : Reference< XTabController > xTabCtrl( getController( _rxForm ).get() );
[ + - ]
411 [ + - ]: 9 : if ( xTabCtrl.is() )
412 : : { // if there already is a TabController for this form, then delegate the "updateTabOrder" request
413 [ + - ][ + - ]: 9 : xTabCtrl->activateTabOrder();
414 : : }
415 : : else
416 : : { // otherwise, create a TabController
417 : :
418 : : // if it's a sub form, then we must ensure there exist TabControllers
419 : : // for all its ancestors, too
420 [ # # ][ # # ]: 0 : Reference< XForm > xParentForm( _rxForm->getParent(), UNO_QUERY );
[ # # ]
421 : : // there is a parent form -> look for the respective controller
422 : 0 : Reference< XFormController > xParentController;
423 [ # # ]: 0 : if ( xParentForm.is() )
424 [ # # ][ # # ]: 0 : xParentController.set( getController( xParentForm ), UNO_QUERY );
425 : :
426 [ # # ]: 0 : setController( _rxForm, xParentController );
427 [ # # ]: 9 : }
428 : : }
429 : 0 : catch (const Exception&)
430 : : {
431 : : DBG_UNHANDLED_EXCEPTION();
432 : : }
433 : : }
434 : :
435 : : //------------------------------------------------------------------------
436 : 1976 : FmXFormView::FmXFormView(const ::comphelper::ComponentContext& _rContext, FmFormView* _pView )
437 : : :m_aContext( _rContext )
438 : : ,m_pMarkedGrid(NULL)
439 : : ,m_pView(_pView)
440 : : ,m_nActivationEvent(0)
441 : : ,m_nErrorMessageEvent( 0 )
442 : : ,m_nAutoFocusEvent( 0 )
443 : : ,m_nControlWizardEvent( 0 )
444 : : ,m_pWatchStoredList( NULL )
445 : : ,m_bFirstActivation( true )
446 [ + - ][ + - ]: 1976 : ,m_isTabOrderUpdateSuspended( false )
[ + - ][ + - ]
[ + - ]
447 : : {
448 : 1976 : }
449 : :
450 : : //------------------------------------------------------------------------
451 : 3770 : void FmXFormView::cancelEvents()
452 : : {
453 [ + + ]: 3770 : if ( m_nActivationEvent )
454 : : {
455 : 12 : Application::RemoveUserEvent( m_nActivationEvent );
456 : 12 : m_nActivationEvent = 0;
457 : : }
458 : :
459 [ - + ]: 3770 : if ( m_nErrorMessageEvent )
460 : : {
461 : 0 : Application::RemoveUserEvent( m_nErrorMessageEvent );
462 : 0 : m_nErrorMessageEvent = 0;
463 : : }
464 : :
465 [ - + ]: 3770 : if ( m_nAutoFocusEvent )
466 : : {
467 : 0 : Application::RemoveUserEvent( m_nAutoFocusEvent );
468 : 0 : m_nAutoFocusEvent = 0;
469 : : }
470 : :
471 [ - + ]: 3770 : if ( m_nControlWizardEvent )
472 : : {
473 : 0 : Application::RemoveUserEvent( m_nControlWizardEvent );
474 : 0 : m_nControlWizardEvent = 0;
475 : : }
476 : 3770 : }
477 : :
478 : : //------------------------------------------------------------------------
479 : 1885 : void FmXFormView::notifyViewDying( )
480 : : {
481 : : DBG_ASSERT( m_pView, "FmXFormView::notifyViewDying: my view already died!" );
482 : 1885 : m_pView = NULL;
483 : 1885 : cancelEvents();
484 : 1885 : }
485 : :
486 : : //------------------------------------------------------------------------
487 [ + - ][ + - ]: 1885 : FmXFormView::~FmXFormView()
[ + - ]
488 : : {
489 : : DBG_ASSERT( m_aPageWindowAdapters.empty(), "FmXFormView::~FmXFormView: Window list not empty!" );
490 [ - + ]: 1885 : if ( !m_aPageWindowAdapters.empty() )
491 : : {
492 [ # # ][ # # ]: 0 : for ( PageWindowAdapterList::const_iterator loop = m_aPageWindowAdapters.begin();
[ # # ]
493 : 0 : loop != m_aPageWindowAdapters.end();
494 : : ++loop
495 : : )
496 : : {
497 [ # # ]: 0 : (*loop)->dispose();
498 : : }
499 : : }
500 : :
501 [ + - ]: 1885 : cancelEvents();
502 : :
503 [ + + ][ + - ]: 1885 : delete m_pWatchStoredList;
504 : 1885 : m_pWatchStoredList = NULL;
505 [ - + ]: 3770 : }
506 : :
507 : : // EventListener
508 : : //------------------------------------------------------------------------------
509 : 17 : void SAL_CALL FmXFormView::disposing(const EventObject& Source) throw( RuntimeException )
510 : : {
511 [ - + ][ # # ]: 17 : if ( m_xWindow.is() && Source.Source == m_xWindow )
[ - + ]
512 : 0 : removeGridWindowListening();
513 : 17 : }
514 : :
515 : : // XFormControllerListener
516 : : //------------------------------------------------------------------------------
517 : 6 : void SAL_CALL FmXFormView::formActivated(const EventObject& rEvent) throw( RuntimeException )
518 : : {
519 [ + - ][ + - ]: 6 : if ( m_pView && m_pView->GetFormShell() && m_pView->GetFormShell()->GetImpl() )
[ + - ][ + - ]
520 : 6 : m_pView->GetFormShell()->GetImpl()->formActivated( rEvent );
521 : 6 : }
522 : :
523 : : //------------------------------------------------------------------------------
524 : 6 : void SAL_CALL FmXFormView::formDeactivated(const EventObject& rEvent) throw( RuntimeException )
525 : : {
526 [ + - ][ + - ]: 6 : if ( m_pView && m_pView->GetFormShell() && m_pView->GetFormShell()->GetImpl() )
[ + - ][ + - ]
527 : 6 : m_pView->GetFormShell()->GetImpl()->formDeactivated( rEvent );
528 : 6 : }
529 : :
530 : : // XContainerListener
531 : : //------------------------------------------------------------------------------
532 : 19 : void SAL_CALL FmXFormView::elementInserted(const ContainerEvent& evt) throw( RuntimeException )
533 : : {
534 : : try
535 : : {
536 [ + - ]: 19 : Reference< XControlContainer > xControlContainer( evt.Source, UNO_QUERY_THROW );
537 [ + - ]: 19 : Reference< XControl > xControl( evt.Element, UNO_QUERY_THROW );
538 [ + - ][ + - ]: 19 : Reference< XFormComponent > xControlModel( xControl->getModel(), UNO_QUERY_THROW );
[ + - ]
539 [ + - ][ + - ]: 19 : Reference< XForm > xForm( xControlModel->getParent(), UNO_QUERY_THROW );
[ + - ]
540 : :
541 [ + - ]: 19 : if ( m_isTabOrderUpdateSuspended )
542 : : {
543 : : // remember the container and the control, so we can update the tab order on resumeTabOrderUpdate
544 [ + - ][ + - ]: 19 : m_aNeedTabOrderUpdate[ xControlContainer ].insert( xForm );
545 : : }
546 : : else
547 : : {
548 [ # # ]: 0 : PFormViewPageWindowAdapter pAdapter = findWindow( xControlContainer );
549 [ # # ]: 0 : if ( pAdapter.is() )
550 [ # # ]: 0 : pAdapter->updateTabOrder( xForm );
551 [ # # ]: 19 : }
552 : : }
553 : 0 : catch (const Exception&)
554 : : {
555 : : DBG_UNHANDLED_EXCEPTION();
556 : : }
557 : 19 : }
558 : :
559 : : //------------------------------------------------------------------------------
560 : 0 : void SAL_CALL FmXFormView::elementReplaced(const ContainerEvent& evt) throw( RuntimeException )
561 : : {
562 : 0 : elementInserted(evt);
563 : 0 : }
564 : :
565 : : //------------------------------------------------------------------------------
566 : 2 : void SAL_CALL FmXFormView::elementRemoved(const ContainerEvent& /*evt*/) throw( RuntimeException )
567 : : {
568 : 2 : }
569 : :
570 : : //------------------------------------------------------------------------------
571 : 191 : PFormViewPageWindowAdapter FmXFormView::findWindow( const Reference< XControlContainer >& _rxCC ) const
572 : : {
573 [ + - ][ + + ]: 382 : for ( PageWindowAdapterList::const_iterator i = m_aPageWindowAdapters.begin();
574 : 191 : i != m_aPageWindowAdapters.end();
575 : : ++i
576 : : )
577 : : {
578 [ + - ][ + - ]: 98 : if ( _rxCC == (*i)->getControlContainer() )
[ + - ]
579 : 98 : return *i;
580 : : }
581 : 191 : return NULL;
582 : : }
583 : :
584 : : //------------------------------------------------------------------------------
585 : 182 : void FmXFormView::addWindow(const SdrPageWindow& rWindow)
586 : : {
587 [ + - ][ + - ]: 182 : FmFormPage* pFormPage = PTR_CAST( FmFormPage, rWindow.GetPageView().GetPage() );
[ + - ][ + - ]
588 [ + - ]: 182 : if ( !pFormPage )
589 : 182 : return;
590 : :
591 [ + - ]: 182 : Reference< XControlContainer > xCC = rWindow.GetControlContainer();
592 [ + - + + ]: 546 : if ( xCC.is()
[ + + ]
593 [ + - ][ + - ]: 364 : && ( !findWindow( xCC ).is() )
[ # # ]
594 : : )
595 : : {
596 [ + - ]: 93 : PFormViewPageWindowAdapter pAdapter = new FormViewPageWindowAdapter( m_aContext, rWindow, this );
597 [ + - ]: 93 : m_aPageWindowAdapters.push_back( pAdapter );
598 : :
599 : : // Am ControlContainer horchen um Aenderungen mitzbekommen
600 [ + - ]: 93 : Reference< XContainer > xContainer( xCC, UNO_QUERY );
601 [ + - ]: 93 : if ( xContainer.is() )
602 [ + - ][ + - ]: 93 : xContainer->addContainerListener( this );
[ + - ]
603 : 182 : }
604 : : }
605 : :
606 : : //------------------------------------------------------------------------------
607 : 511 : void FmXFormView::removeWindow( const Reference< XControlContainer >& _rxCC )
608 : : {
609 : : // Wird gerufen, wenn
610 : : // - in den Design-Modus geschaltet wird
611 : : // - ein Window geloescht wird, waehrend man im Design-Modus ist
612 : : // - der Control-Container fuer ein Window entfernt wird, waehrend
613 : : // der aktive Modus eingeschaltet ist.
614 : :
615 [ + - ][ + + ]: 1022 : for ( PageWindowAdapterList::iterator i = m_aPageWindowAdapters.begin();
616 : 511 : i != m_aPageWindowAdapters.end();
617 : : ++i
618 : : )
619 : : {
620 [ + - ][ + - ]: 82 : if ( _rxCC != (*i)->getControlContainer() )
[ - + ]
621 : 0 : continue;
622 : :
623 [ + - ]: 82 : Reference< XContainer > xContainer( _rxCC, UNO_QUERY );
624 [ + - ]: 82 : if ( xContainer.is() )
625 [ + - ][ + - ]: 82 : xContainer->removeContainerListener( this );
[ + - ]
626 : :
627 [ + - ]: 82 : (*i)->dispose();
628 [ + - ]: 82 : m_aPageWindowAdapters.erase( i );
629 : : break;
630 : 82 : }
631 : 511 : }
632 : :
633 : : //------------------------------------------------------------------------------
634 : 0 : void FmXFormView::displayAsyncErrorMessage( const SQLErrorEvent& _rEvent )
635 : : {
636 : : DBG_ASSERT( 0 == m_nErrorMessageEvent, "FmXFormView::displayAsyncErrorMessage: not too fast, please!" );
637 : : // This should not happen - usually, the PostUserEvent is faster than any possible user
638 : : // interaction which could trigger a new error. If it happens, we need a queue for the events.
639 : 0 : m_aAsyncError = _rEvent;
640 [ # # ]: 0 : m_nErrorMessageEvent = Application::PostUserEvent( LINK( this, FmXFormView, OnDelayedErrorMessage ) );
641 : 0 : }
642 : :
643 : : //------------------------------------------------------------------------------
644 : 0 : IMPL_LINK(FmXFormView, OnDelayedErrorMessage, void*, /*EMPTYTAG*/)
645 : : {
646 : 0 : m_nErrorMessageEvent = 0;
647 : 0 : displayException( m_aAsyncError );
648 : 0 : return 0L;
649 : : }
650 : :
651 : : //------------------------------------------------------------------------------
652 : 69 : void FmXFormView::onFirstViewActivation( const FmFormModel* _pDocModel )
653 : : {
654 [ + - ][ + + ]: 69 : if ( _pDocModel && _pDocModel->GetAutoControlFocus() )
[ + + ]
655 [ + - ]: 2 : m_nAutoFocusEvent = Application::PostUserEvent( LINK( this, FmXFormView, OnAutoFocus ) );
656 : 69 : }
657 : :
658 : : //------------------------------------------------------------------------------
659 : 15027 : void FmXFormView::suspendTabOrderUpdate()
660 : : {
661 : : OSL_ENSURE( !m_isTabOrderUpdateSuspended, "FmXFormView::suspendTabOrderUpdate: nesting not allowed!" );
662 : 15027 : m_isTabOrderUpdateSuspended = true;
663 : 15027 : }
664 : :
665 : : //------------------------------------------------------------------------------
666 : 15027 : void FmXFormView::resumeTabOrderUpdate()
667 : : {
668 : : OSL_ENSURE( m_isTabOrderUpdateSuspended, "FmXFormView::resumeTabOrderUpdate: not suspended!" );
669 : 15027 : m_isTabOrderUpdateSuspended = false;
670 : :
671 : : // update the tab orders for all components which were collected since the suspendTabOrderUpdate call.
672 [ + + ]: 30072 : for ( MapControlContainerToSetOfForms::const_iterator container = m_aNeedTabOrderUpdate.begin();
673 : 15036 : container != m_aNeedTabOrderUpdate.end();
674 : : ++container
675 : : )
676 : : {
677 [ + - ]: 9 : PFormViewPageWindowAdapter pAdapter = findWindow( container->first );
678 [ - + ]: 9 : if ( !pAdapter.is() )
679 : 0 : continue;
680 : :
681 [ + + ]: 36 : for ( SetOfForms::const_iterator form = container->second.begin();
682 : 18 : form != container->second.end();
683 : : ++form
684 : : )
685 : : {
686 [ + - ]: 9 : pAdapter->updateTabOrder( *form );
687 : : }
688 [ + - ]: 9 : }
689 : 15027 : m_aNeedTabOrderUpdate.clear();
690 : 15027 : }
691 : :
692 : : //------------------------------------------------------------------------------
693 : 1242 : IMPL_LINK(FmXFormView, OnActivate, void*, /*EMPTYTAG*/)
694 : : {
695 : 1242 : m_nActivationEvent = 0;
696 : :
697 [ - + ]: 1242 : if ( !m_pView )
698 : : {
699 : : OSL_FAIL( "FmXFormView::OnActivate: well .... seems we have a timing problem (the view already died)!" );
700 : 0 : return 0;
701 : : }
702 : :
703 : : // setting the controller to activate
704 [ + + ][ + + ]: 1242 : if (m_pView->GetFormShell() && m_pView->GetActualOutDev() && m_pView->GetActualOutDev()->GetOutDevType() == OUTDEV_WINDOW)
[ + - ][ + + ]
705 : : {
706 : 574 : Window* pWindow = const_cast<Window*>(static_cast<const Window*>(m_pView->GetActualOutDev()));
707 [ + + ]: 574 : PFormViewPageWindowAdapter pAdapter = m_aPageWindowAdapters.empty() ? NULL : m_aPageWindowAdapters[0];
708 [ + - ][ + - ]: 1206 : for ( PageWindowAdapterList::const_iterator i = m_aPageWindowAdapters.begin();
[ + + ]
709 : 603 : i != m_aPageWindowAdapters.end();
710 : : ++i
711 : : )
712 : : {
713 [ + - ]: 29 : if ( pWindow == (*i)->getWindow() )
714 [ + - ]: 29 : pAdapter =*i;
715 : : }
716 : :
717 [ + + ]: 574 : if ( pAdapter.get() )
718 : : {
719 [ + - ][ + + ]: 96 : for ( ::std::vector< Reference< XFormController > >::const_iterator i = pAdapter->GetList().begin();
720 : 48 : i != pAdapter->GetList().end();
721 : : ++i
722 : : )
723 : : {
724 : 19 : const Reference< XFormController > & xController = *i;
725 [ - + ]: 19 : if ( !xController.is() )
726 : 0 : continue;
727 : :
728 : : // only database forms are to be activated
729 [ + - ][ + - ]: 19 : Reference< XRowSet > xForm(xController->getModel(), UNO_QUERY);
[ + - ]
730 [ + - ][ + - ]: 19 : if ( !xForm.is() || !OStaticDataAccessTools().getRowSetConnection( xForm ).is() )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - # #
# # ][ + - ]
731 : 19 : continue;
732 : :
733 [ # # ]: 0 : Reference< XPropertySet > xFormSet( xForm, UNO_QUERY );
734 [ # # ]: 0 : if ( !xFormSet.is() )
735 : : {
736 : : SAL_WARN( "svx.form", "FmXFormView::OnActivate: a form which does not have properties?" );
737 : 0 : continue;
738 : : }
739 : :
740 [ # # ][ # # ]: 0 : const ::rtl::OUString aSource = ::comphelper::getString( xFormSet->getPropertyValue( FM_PROP_COMMAND ) );
[ # # ][ # # ]
741 [ # # ]: 0 : if ( !aSource.isEmpty() )
742 : : {
743 : 0 : FmXFormShell* pShImpl = m_pView->GetFormShell()->GetImpl();
744 [ # # ]: 0 : if ( pShImpl )
745 [ # # ]: 0 : pShImpl->setActiveController( xController );
746 : : break;
747 : : }
748 [ # # ]: 19 : }
[ # # # ]
[ - + - ]
749 : 574 : }
750 : : }
751 : 1242 : return 0;
752 : : }
753 : :
754 : : //------------------------------------------------------------------------------
755 : 2091 : void FmXFormView::Activate(sal_Bool bSync)
756 : : {
757 [ + + ]: 2091 : if (m_nActivationEvent)
758 : : {
759 : 65 : Application::RemoveUserEvent(m_nActivationEvent);
760 : 65 : m_nActivationEvent = 0;
761 : : }
762 : :
763 [ + + ]: 2091 : if (bSync)
764 : : {
765 [ + - ]: 20 : LINK(this,FmXFormView,OnActivate).Call(NULL);
766 : : }
767 : : else
768 [ + - ]: 2071 : m_nActivationEvent = Application::PostUserEvent(LINK(this,FmXFormView,OnActivate));
769 : 2091 : }
770 : :
771 : : //------------------------------------------------------------------------------
772 : 2102 : void FmXFormView::Deactivate(sal_Bool bDeactivateController)
773 : : {
774 [ + + ]: 2102 : if (m_nActivationEvent)
775 : : {
776 : 768 : Application::RemoveUserEvent(m_nActivationEvent);
777 : 768 : m_nActivationEvent = 0;
778 : : }
779 : :
780 [ + + ]: 2102 : FmXFormShell* pShImpl = m_pView->GetFormShell() ? m_pView->GetFormShell()->GetImpl() : NULL;
781 [ + + ][ + + ]: 2102 : if (pShImpl && bDeactivateController)
782 [ + - ]: 26 : pShImpl->setActiveController( NULL );
783 : 2102 : }
784 : :
785 : : //------------------------------------------------------------------------------
786 : 3346 : FmFormShell* FmXFormView::GetFormShell() const
787 : : {
788 [ + - ]: 3346 : return m_pView ? m_pView->GetFormShell() : NULL;
789 : : }
790 : : // -----------------------------------------------------------------------------
791 : 0 : void FmXFormView::AutoFocus( sal_Bool _bSync )
792 : : {
793 [ # # ]: 0 : if (m_nAutoFocusEvent)
794 : 0 : Application::RemoveUserEvent(m_nAutoFocusEvent);
795 : :
796 [ # # ]: 0 : if ( _bSync )
797 : 0 : OnAutoFocus( NULL );
798 : : else
799 [ # # ]: 0 : m_nAutoFocusEvent = Application::PostUserEvent(LINK(this, FmXFormView, OnAutoFocus));
800 : 0 : }
801 : :
802 : : // -----------------------------------------------------------------------------
803 : 2 : bool FmXFormView::isFocusable( const Reference< XControl >& i_rControl )
804 : : {
805 [ - + ]: 2 : if ( !i_rControl.is() )
806 : 0 : return false;
807 : :
808 : : try
809 : : {
810 [ + - ][ + - ]: 2 : Reference< XPropertySet > xModelProps( i_rControl->getModel(), UNO_QUERY_THROW );
[ + - ]
811 : :
812 : : // only enabled controls are allowed to participate
813 : 2 : sal_Bool bEnabled = sal_False;
814 [ + - ][ + - ]: 2 : OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_ENABLED ) >>= bEnabled );
[ + - ]
815 [ - + ]: 2 : if ( !bEnabled )
816 : 0 : return false;
817 : :
818 : : // check the class id of the control model
819 : 2 : sal_Int16 nClassId = FormComponentType::CONTROL;
820 [ + - ][ + - ]: 2 : OSL_VERIFY( xModelProps->getPropertyValue( FM_PROP_CLASSID ) >>= nClassId );
[ + - ]
821 : :
822 : : // controls which are not focussable
823 [ + - ][ + - ]: 2 : if ( ( FormComponentType::CONTROL != nClassId )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
824 : : && ( FormComponentType::IMAGEBUTTON != nClassId )
825 : : && ( FormComponentType::GROUPBOX != nClassId )
826 : : && ( FormComponentType::FIXEDTEXT != nClassId )
827 : : && ( FormComponentType::HIDDENCONTROL != nClassId )
828 : : && ( FormComponentType::IMAGECONTROL != nClassId )
829 : : && ( FormComponentType::SCROLLBAR != nClassId )
830 : : && ( FormComponentType::SPINBUTTON!= nClassId )
831 : : )
832 : : {
833 : 2 : return true;
834 [ - + ][ # # ]: 2 : }
835 : : }
836 : 0 : catch (const Exception&)
837 : : {
838 : : DBG_UNHANDLED_EXCEPTION();
839 : : }
840 : 2 : return false;
841 : : }
842 : :
843 : : // -----------------------------------------------------------------------------
844 : 2 : static Reference< XControl > lcl_firstFocussableControl( const Sequence< Reference< XControl > >& _rControls )
845 : : {
846 : 2 : Reference< XControl > xReturn;
847 : :
848 : : // loop through all the controls
849 : 2 : const Reference< XControl >* pControls = _rControls.getConstArray();
850 : 2 : const Reference< XControl >* pControlsEnd = _rControls.getConstArray() + _rControls.getLength();
851 [ + - ]: 2 : for ( ; pControls != pControlsEnd; ++pControls )
852 : : {
853 [ - + ]: 2 : if ( !pControls->is() )
854 : 0 : continue;
855 : :
856 [ + - ][ + - ]: 2 : if ( FmXFormView::isFocusable( *pControls ) )
857 : : {
858 [ + - ]: 2 : xReturn = *pControls;
859 : 2 : break;
860 : : }
861 : : }
862 : :
863 [ - + ][ # # ]: 2 : if ( !xReturn.is() && _rControls.getLength() )
[ - + ]
864 [ # # ]: 0 : xReturn = _rControls[0];
865 : :
866 : 2 : return xReturn;
867 : : }
868 : :
869 : : // -----------------------------------------------------------------------------
870 : : namespace
871 : : {
872 : : // .........................................................................
873 : 0 : void lcl_ensureControlsOfFormExist_nothrow( const SdrPage& _rPage, const SdrView& _rView, const Window& _rWindow, const Reference< XForm >& _rxForm )
874 : : {
875 : : try
876 : : {
877 [ # # ]: 0 : Reference< XInterface > xNormalizedForm( _rxForm, UNO_QUERY_THROW );
878 : :
879 [ # # ]: 0 : SdrObjListIter aSdrObjectLoop( _rPage, IM_DEEPNOGROUPS );
880 [ # # ]: 0 : while ( aSdrObjectLoop.IsMore() )
881 : : {
882 [ # # ][ # # ]: 0 : FmFormObj* pFormObject = FmFormObj::GetFormObject( aSdrObjectLoop.Next() );
883 [ # # ]: 0 : if ( !pFormObject )
884 : 0 : continue;
885 : :
886 [ # # ][ # # ]: 0 : Reference< XChild > xModel( pFormObject->GetUnoControlModel(), UNO_QUERY_THROW );
887 [ # # ][ # # ]: 0 : Reference< XInterface > xModelParent( xModel->getParent(), UNO_QUERY_THROW );
[ # # ]
888 : :
889 [ # # ][ # # ]: 0 : if ( xNormalizedForm.get() != xModelParent.get() )
[ # # ]
890 : 0 : continue;
891 : :
892 [ # # ][ # # ]: 0 : pFormObject->GetUnoControl( _rView, _rWindow );
893 [ # # ][ # # ]: 0 : }
894 : : }
895 : 0 : catch (const Exception&)
896 : : {
897 : : DBG_UNHANDLED_EXCEPTION();
898 : : }
899 : 0 : }
900 : : }
901 : :
902 : : // -----------------------------------------------------------------------------
903 : 0 : Reference< XFormController > FmXFormView::getFormController( const Reference< XForm >& _rxForm, const OutputDevice& _rDevice ) const
904 : : {
905 : 0 : Reference< XFormController > xController;
906 : :
907 [ # # ][ # # ]: 0 : for ( PageWindowAdapterList::const_iterator pos = m_aPageWindowAdapters.begin();
908 : 0 : pos != m_aPageWindowAdapters.end();
909 : : ++pos
910 : : )
911 : : {
912 : 0 : const PFormViewPageWindowAdapter pAdapter( *pos );
913 [ # # ]: 0 : if ( !pAdapter.get() )
914 : : {
915 : : SAL_WARN( "svx.form", "FmXFormView::getFormController: invalid page window adapter!" );
916 : 0 : continue;
917 : : }
918 : :
919 [ # # ]: 0 : if ( pAdapter->getWindow() != &_rDevice )
920 : : // wrong device
921 : 0 : continue;
922 : :
923 [ # # ][ # # ]: 0 : xController = pAdapter->getController( _rxForm );
924 [ # # ]: 0 : if ( xController.is() )
925 : : break;
926 [ # # # ]: 0 : }
927 : 0 : return xController;
928 : : }
929 : :
930 : : // -----------------------------------------------------------------------------
931 : 2 : IMPL_LINK(FmXFormView, OnAutoFocus, void*, /*EMPTYTAG*/)
932 : : {
933 : 2 : m_nAutoFocusEvent = 0;
934 : :
935 : : // go to the first form of our page, examine it's TabController, go to it's first (in terms of the tab order)
936 : : // control, give it the focus
937 : :
938 : : do
939 : : {
940 : :
941 : : // get the forms collection of the page we belong to
942 [ + - ][ + - ]: 2 : FmFormPage* pPage = m_pView ? PTR_CAST( FmFormPage, m_pView->GetSdrPageView()->GetPage() ) : NULL;
[ + - ][ + - ]
[ + - ]
943 [ + - ][ + - ]: 2 : Reference< XIndexAccess > xForms( pPage ? Reference< XIndexAccess >( pPage->GetForms(), UNO_QUERY ) : Reference< XIndexAccess >() );
[ + - ]
944 : :
945 [ - + ]: 2 : const PFormViewPageWindowAdapter pAdapter = m_aPageWindowAdapters.empty() ? NULL : m_aPageWindowAdapters[0];
946 [ + - ]: 2 : const Window* pWindow = pAdapter.get() ? pAdapter->getWindow() : NULL;
947 : :
948 [ + - ][ - + ]: 2 : ENSURE_OR_RETURN( xForms.is() && pWindow, "FmXFormView::OnAutoFocus: could not collect all essentials!", 0L );
[ - + ]
949 : :
950 : : try
951 : : {
952 : : // go for the tab controller of the first form
953 [ + - ][ + - ]: 2 : if ( !xForms->getCount() )
[ + - ]
954 : : break;
955 [ + - ][ + - ]: 2 : Reference< XForm > xForm( xForms->getByIndex( 0 ), UNO_QUERY_THROW );
[ + - ]
956 [ + - ][ + - ]: 2 : Reference< XTabController > xTabController( pAdapter->getController( xForm ), UNO_QUERY_THROW );
957 : :
958 : : // go for the first control of the controller
959 [ + - ][ + - ]: 2 : Sequence< Reference< XControl > > aControls( xTabController->getControls() );
960 [ - + ]: 2 : if ( aControls.getLength() == 0 )
961 : : {
962 [ # # ]: 0 : Reference< XElementAccess > xFormElementAccess( xForm, UNO_QUERY_THROW );
963 [ # # ][ # # ]: 0 : if ( xFormElementAccess->hasElements() )
[ # # ]
964 : : {
965 : : // there are control models in the form, but no controls, yet.
966 : : // Well, since some time controls are created on demand only. In particular,
967 : : // they're normally created when they're first painted.
968 : : // Unfortunately, the FormController does not have any way to
969 : : // trigger the creation itself, so we must hack this ...
970 [ # # ]: 0 : lcl_ensureControlsOfFormExist_nothrow( *pPage, *m_pView, *pWindow, xForm );
971 [ # # ][ # # ]: 0 : aControls = xTabController->getControls();
[ # # ][ # # ]
972 : : OSL_ENSURE( aControls.getLength(), "FmXFormView::OnAutoFocus: no controls at all!" );
973 : 0 : }
974 : : }
975 : :
976 : : // set the focus to this first control
977 [ + - ][ + - ]: 2 : Reference< XWindow > xControlWindow( lcl_firstFocussableControl( aControls ), UNO_QUERY );
978 [ - + ]: 2 : if ( !xControlWindow.is() )
979 : : break;
980 : :
981 [ + - ][ + - ]: 2 : xControlWindow->setFocus();
982 : :
983 : : // ensure that the control is visible
984 : : // 80210 - 12/07/00 - FS
985 [ - + ]: 2 : const Window* pCurrentWindow = dynamic_cast< const Window* >( m_pView->GetActualOutDev() );
986 [ + - ]: 2 : if ( pCurrentWindow )
987 : : {
988 [ + - ][ + - ]: 2 : awt::Rectangle aRect = xControlWindow->getPosSize();
989 [ + - ]: 2 : ::Rectangle aNonUnoRect( aRect.X, aRect.Y, aRect.X + aRect.Width, aRect.Y + aRect.Height );
990 [ + - ][ + - ]: 2 : m_pView->MakeVisible( pCurrentWindow->PixelToLogic( aNonUnoRect ), *const_cast< Window* >( pCurrentWindow ) );
991 [ - + ][ + - ]: 2 : }
[ - + ][ - + ]
[ + - ][ # # ]
992 : : }
993 [ # # ]: 0 : catch (const Exception&)
994 : : {
995 : : DBG_UNHANDLED_EXCEPTION();
996 [ - - + ]: 2 : }
[ + - - ]
997 : :
998 : : } // do
999 : : while ( false );
1000 : :
1001 : 2 : return 1L;
1002 : : }
1003 : :
1004 : : // -----------------------------------------------------------------------------
1005 : 0 : void FmXFormView::onCreatedFormObject( FmFormObj& _rFormObject )
1006 : : {
1007 [ # # ]: 0 : FmFormShell* pShell = m_pView ? m_pView->GetFormShell() : NULL;
1008 [ # # ]: 0 : FmXFormShell* pShellImpl = pShell ? pShell->GetImpl() : NULL;
1009 : : OSL_ENSURE( pShellImpl, "FmXFormView::onCreatedFormObject: no form shell!" );
1010 [ # # ]: 0 : if ( !pShellImpl )
1011 : : return;
1012 : :
1013 : : // it is valid that the form shell's forms collection is not initialized, yet
1014 [ # # ]: 0 : pShellImpl->UpdateForms( sal_True );
1015 : :
1016 [ # # ][ # # ]: 0 : m_xLastCreatedControlModel.set( _rFormObject.GetUnoControlModel(), UNO_QUERY );
1017 [ # # ]: 0 : if ( !m_xLastCreatedControlModel.is() )
1018 : : return;
1019 : :
1020 : : // some initial property defaults
1021 [ # # ]: 0 : FormControlFactory aControlFactory( m_aContext );
1022 [ # # ][ # # ]: 0 : aControlFactory.initializeControlModel( pShellImpl->getDocumentType(), _rFormObject );
1023 : :
1024 [ # # ]: 0 : if ( !pShellImpl->GetWizardUsing() )
1025 : : return;
1026 : :
1027 : : // #i31958# don't call wizards in XForms mode
1028 [ # # ][ # # ]: 0 : if ( pShellImpl->isEnhancedForm() )
1029 : : return;
1030 : :
1031 : : // #i46898# no wizards if there is no Base installed - currently, all wizards are
1032 : : // database related
1033 [ # # ][ # # ]: 0 : if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
[ # # ][ # # ]
1034 : : return;
1035 : :
1036 [ # # ]: 0 : if ( m_nControlWizardEvent )
1037 [ # # ]: 0 : Application::RemoveUserEvent( m_nControlWizardEvent );
1038 [ # # ][ # # ]: 0 : m_nControlWizardEvent = Application::PostUserEvent( LINK( this, FmXFormView, OnStartControlWizard ) );
[ # # ][ # # ]
1039 : : }
1040 : :
1041 : : // -----------------------------------------------------------------------------
1042 : 0 : IMPL_LINK( FmXFormView, OnStartControlWizard, void*, /**/ )
1043 : : {
1044 : 0 : m_nControlWizardEvent = 0;
1045 : : OSL_PRECOND( m_xLastCreatedControlModel.is(), "FmXFormView::OnStartControlWizard: illegal call!" );
1046 [ # # ]: 0 : if ( !m_xLastCreatedControlModel.is() )
1047 : 0 : return 0L;
1048 : :
1049 : 0 : sal_Int16 nClassId = FormComponentType::CONTROL;
1050 : : try
1051 : : {
1052 [ # # ][ # # ]: 0 : OSL_VERIFY( m_xLastCreatedControlModel->getPropertyValue( FM_PROP_CLASSID ) >>= nClassId );
[ # # ][ # # ]
1053 : : }
1054 [ # # ]: 0 : catch (const Exception&)
1055 : : {
1056 : : DBG_UNHANDLED_EXCEPTION();
1057 : : }
1058 : :
1059 : 0 : const sal_Char* pWizardAsciiName = NULL;
1060 [ # # # # ]: 0 : switch ( nClassId )
1061 : : {
1062 : : case FormComponentType::GRIDCONTROL:
1063 : 0 : pWizardAsciiName = "com.sun.star.sdb.GridControlAutoPilot";
1064 : 0 : break;
1065 : : case FormComponentType::LISTBOX:
1066 : : case FormComponentType::COMBOBOX:
1067 : 0 : pWizardAsciiName = "com.sun.star.sdb.ListComboBoxAutoPilot";
1068 : 0 : break;
1069 : : case FormComponentType::GROUPBOX:
1070 : 0 : pWizardAsciiName = "com.sun.star.sdb.GroupBoxAutoPilot";
1071 : 0 : break;
1072 : : }
1073 : :
1074 [ # # ]: 0 : if ( pWizardAsciiName )
1075 : : {
1076 : : // build the argument list
1077 [ # # ]: 0 : ::comphelper::NamedValueCollection aWizardArgs;
1078 [ # # ]: 0 : aWizardArgs.put( "ObjectModel", m_xLastCreatedControlModel );
1079 : :
1080 : : // create the wizard object
1081 : 0 : Reference< XExecutableDialog > xWizard;
1082 : : try
1083 : : {
1084 [ # # ][ # # ]: 0 : m_aContext.createComponentWithArguments( pWizardAsciiName, aWizardArgs.getWrappedPropertyValues(), xWizard );
[ # # ][ # # ]
1085 : : }
1086 [ # # ]: 0 : catch (const Exception&)
1087 : : {
1088 : : DBG_UNHANDLED_EXCEPTION();
1089 : : }
1090 : :
1091 [ # # ]: 0 : if ( !xWizard.is() )
1092 : : {
1093 [ # # ][ # # ]: 0 : ShowServiceNotAvailableError( NULL, rtl::OUString::createFromAscii(pWizardAsciiName), sal_True );
[ # # ][ # # ]
1094 : : }
1095 : : else
1096 : : {
1097 : : // execute the wizard
1098 : : try
1099 : : {
1100 [ # # ][ # # ]: 0 : xWizard->execute();
1101 : : }
1102 [ # # ]: 0 : catch (const Exception&)
1103 : : {
1104 : : DBG_UNHANDLED_EXCEPTION();
1105 : : }
1106 [ # # ]: 0 : }
1107 : : }
1108 : :
1109 : 0 : m_xLastCreatedControlModel.clear();
1110 : 0 : return 1L;
1111 : : }
1112 : :
1113 : : // -----------------------------------------------------------------------------
1114 : : namespace
1115 : : {
1116 : 0 : void lcl_insertIntoFormComponentHierarchy_throw( const FmFormView& _rView, const SdrUnoObj& _rSdrObj,
1117 : : const Reference< XDataSource >& _rxDataSource = NULL, const ::rtl::OUString& _rDataSourceName = ::rtl::OUString(),
1118 : : const ::rtl::OUString& _rCommand = ::rtl::OUString(), const sal_Int32 _nCommandType = -1 )
1119 : : {
1120 : 0 : FmFormPage& rPage = static_cast< FmFormPage& >( *_rView.GetSdrPageView()->GetPage() );
1121 : :
1122 [ # # ][ # # ]: 0 : Reference< XFormComponent > xFormComponent( _rSdrObj.GetUnoControlModel(), UNO_QUERY_THROW );
1123 : : Reference< XForm > xTargetForm(
1124 : 0 : rPage.GetImpl().findPlaceInFormComponentHierarchy( xFormComponent, _rxDataSource, _rDataSourceName, _rCommand, _nCommandType ),
1125 [ # # ][ # # ]: 0 : UNO_SET_THROW );
1126 : :
1127 [ # # ]: 0 : rPage.GetImpl().setUniqueName( xFormComponent, xTargetForm );
1128 : :
1129 [ # # ]: 0 : Reference< XIndexContainer > xFormAsContainer( xTargetForm, UNO_QUERY_THROW );
1130 [ # # ][ # # ]: 0 : xFormAsContainer->insertByIndex( xFormAsContainer->getCount(), makeAny( xFormComponent ) );
[ # # ][ # # ]
[ # # ]
1131 : 0 : }
1132 : : }
1133 : :
1134 : : // -----------------------------------------------------------------------------
1135 : 0 : SdrObject* FmXFormView::implCreateFieldControl( const ::svx::ODataAccessDescriptor& _rColumnDescriptor )
1136 : : {
1137 : : // not if we're in design mode
1138 [ # # ]: 0 : if ( !m_pView->IsDesignMode() )
1139 : 0 : return NULL;
1140 : :
1141 : 0 : ::rtl::OUString sCommand, sFieldName;
1142 : 0 : sal_Int32 nCommandType = CommandType::COMMAND;
1143 [ # # ]: 0 : SharedConnection xConnection;
1144 : :
1145 [ # # ]: 0 : ::rtl::OUString sDataSource = _rColumnDescriptor.getDataSource();
1146 [ # # ]: 0 : _rColumnDescriptor[ daCommand ] >>= sCommand;
1147 [ # # ]: 0 : _rColumnDescriptor[ daColumnName ] >>= sFieldName;
1148 [ # # ]: 0 : _rColumnDescriptor[ daCommandType ] >>= nCommandType;
1149 : : {
1150 : 0 : Reference< XConnection > xExternalConnection;
1151 [ # # ][ # # ]: 0 : _rColumnDescriptor[ daConnection ] >>= xExternalConnection;
1152 [ # # ]: 0 : xConnection.reset( xExternalConnection, SharedConnection::NoTakeOwnership );
1153 : : }
1154 : :
1155 [ # # # # : 0 : if ( sCommand.isEmpty()
# # # # ]
1156 : 0 : || sFieldName.isEmpty()
1157 : 0 : || ( sDataSource.isEmpty()
1158 : 0 : && !xConnection.is()
1159 : : )
1160 : : )
1161 : : {
1162 : : OSL_FAIL( "FmXFormView::implCreateFieldControl: nonsense!" );
1163 : : }
1164 : :
1165 : 0 : Reference< XDataSource > xDataSource;
1166 [ # # ]: 0 : SQLErrorEvent aError;
1167 : : try
1168 : : {
1169 [ # # ][ # # ]: 0 : if ( xConnection.is() && !xDataSource.is() && sDataSource.isEmpty() )
[ # # ][ # # ]
1170 : : {
1171 [ # # ]: 0 : Reference< XChild > xChild( xConnection, UNO_QUERY );
1172 [ # # ]: 0 : if ( xChild.is() )
1173 [ # # ][ # # ]: 0 : xDataSource = xDataSource.query( xChild->getParent() );
[ # # ][ # # ]
1174 : : }
1175 : :
1176 : : // obtain the data source
1177 [ # # ]: 0 : if ( !xDataSource.is() )
1178 [ # # ][ # # ]: 0 : xDataSource = OStaticDataAccessTools().getDataSource( sDataSource, m_aContext.getLegacyServiceFactory() );
[ # # ][ # # ]
[ # # ]
1179 : :
1180 : : // and the connection, if necessary
1181 [ # # ]: 0 : if ( !xConnection.is() )
1182 : : xConnection.reset( OStaticDataAccessTools().getConnection_withFeedback(
1183 : : sDataSource,
1184 : : ::rtl::OUString(),
1185 : : ::rtl::OUString(),
1186 : : m_aContext.getLegacyServiceFactory()
1187 [ # # ][ # # ]: 0 : ) );
[ # # ][ # # ]
[ # # ]
1188 : : }
1189 [ # # # # : 0 : catch (const SQLException&)
# ]
1190 : : {
1191 [ # # ]: 0 : aError.Reason = ::cppu::getCaughtException();
1192 : : }
1193 [ # # ]: 0 : catch (const Exception& )
1194 : : {
1195 : : /* will be asserted below */
1196 : : }
1197 [ # # ]: 0 : if (aError.Reason.hasValue())
1198 : : {
1199 [ # # ]: 0 : displayAsyncErrorMessage( aError );
1200 : 0 : return NULL;
1201 : : }
1202 : :
1203 : : // need a data source and a connection here
1204 [ # # ][ # # ]: 0 : if (!xDataSource.is() || !xConnection.is())
[ # # ]
1205 : : {
1206 : : OSL_FAIL("FmXFormView::implCreateFieldControl : could not retrieve the data source or the connection!");
1207 : 0 : return NULL;
1208 : : }
1209 : :
1210 [ # # ]: 0 : OStaticDataAccessTools aDBATools;
1211 : 0 : Reference< XComponent > xKeepFieldsAlive;
1212 : : // go
1213 : : try
1214 : : {
1215 : : // determine the table/query field which we should create a control for
1216 : 0 : Reference< XPropertySet > xField;
1217 : :
1218 : : Reference< XNameAccess > xFields = aDBATools.getFieldsByCommandDescriptor(
1219 [ # # ]: 0 : xConnection, nCommandType, sCommand, xKeepFieldsAlive );
1220 : :
1221 [ # # ][ # # ]: 0 : if (xFields.is() && xFields->hasByName(sFieldName))
[ # # ][ # # ]
[ # # ]
1222 [ # # ][ # # ]: 0 : xFields->getByName(sFieldName) >>= xField;
[ # # ]
1223 [ # # ]: 0 : if ( !xField.is() )
1224 : 0 : return NULL;
1225 : :
1226 [ # # ][ # # ]: 0 : Reference< XNumberFormatsSupplier > xSupplier( aDBATools.getNumberFormats( xConnection, sal_False ), UNO_SET_THROW );
1227 [ # # ][ # # ]: 0 : Reference< XNumberFormats > xNumberFormats( xSupplier->getNumberFormats(), UNO_SET_THROW );
[ # # ]
1228 : :
1229 : 0 : ::rtl::OUString sLabelPostfix;
1230 : :
1231 : : ////////////////////////////////////////////////////////////////
1232 : : // nur fuer Textgroesse
1233 : 0 : OutputDevice* pOutDev = NULL;
1234 [ # # ][ # # ]: 0 : if (m_pView->GetActualOutDev() && m_pView->GetActualOutDev()->GetOutDevType() == OUTDEV_WINDOW)
[ # # ]
1235 : 0 : pOutDev = const_cast<OutputDevice*>(m_pView->GetActualOutDev());
1236 : : else
1237 : : {// OutDev suchen
1238 : 0 : SdrPageView* pPageView = m_pView->GetSdrPageView();
1239 [ # # ][ # # ]: 0 : if( pPageView && !pOutDev )
1240 : : {
1241 : : // const SdrPageViewWinList& rWinList = pPageView->GetWinList();
1242 : : // const SdrPageViewWindows& rPageViewWindows = pPageView->GetPageViewWindows();
1243 : :
1244 [ # # ]: 0 : for( sal_uInt32 i = 0L; i < pPageView->PageWindowCount(); i++ )
1245 : : {
1246 [ # # ]: 0 : const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(i);
1247 : :
1248 [ # # ]: 0 : if( rPageWindow.GetPaintWindow().OutputToWindow())
1249 : : {
1250 : 0 : pOutDev = &rPageWindow.GetPaintWindow().GetOutputDevice();
1251 : 0 : break;
1252 : : }
1253 : : }
1254 : : }
1255 : : }
1256 : :
1257 [ # # ]: 0 : if ( !pOutDev )
1258 : 0 : return NULL;
1259 : :
1260 [ # # ][ # # ]: 0 : sal_Int32 nDataType = ::comphelper::getINT32(xField->getPropertyValue(FM_PROP_FIELDTYPE));
[ # # ][ # # ]
1261 [ # # ][ # # ]: 0 : if ((DataType::BINARY == nDataType) || (DataType::VARBINARY == nDataType))
1262 : 0 : return NULL;
1263 : :
1264 : : //////////////////////////////////////////////////////////////////////
1265 : : // determine the control type by examining the data type of the bound column
1266 : 0 : sal_uInt16 nOBJID = 0;
1267 : 0 : sal_Bool bDateNTimeField = sal_False;
1268 : :
1269 : 0 : sal_Bool bIsCurrency = sal_False;
1270 [ # # ][ # # ]: 0 : if (::comphelper::hasProperty(FM_PROP_ISCURRENCY, xField))
[ # # ]
1271 [ # # ][ # # ]: 0 : bIsCurrency = ::comphelper::getBOOL(xField->getPropertyValue(FM_PROP_ISCURRENCY));
[ # # ][ # # ]
1272 : :
1273 [ # # ]: 0 : if (bIsCurrency)
1274 : 0 : nOBJID = OBJ_FM_CURRENCYFIELD;
1275 : : else
1276 [ # # # # : 0 : switch (nDataType)
# # # # #
# ]
1277 : : {
1278 : : case DataType::BLOB:
1279 : : case DataType::LONGVARBINARY:
1280 : 0 : nOBJID = OBJ_FM_IMAGECONTROL;
1281 : 0 : break;
1282 : : case DataType::LONGVARCHAR:
1283 : : case DataType::CLOB:
1284 : 0 : nOBJID = OBJ_FM_EDIT;
1285 : 0 : break;
1286 : : case DataType::BINARY:
1287 : : case DataType::VARBINARY:
1288 : 0 : return NULL;
1289 : : case DataType::BIT:
1290 : : case DataType::BOOLEAN:
1291 : 0 : nOBJID = OBJ_FM_CHECKBOX;
1292 : 0 : break;
1293 : : case DataType::TINYINT:
1294 : : case DataType::SMALLINT:
1295 : : case DataType::INTEGER:
1296 : 0 : nOBJID = OBJ_FM_NUMERICFIELD;
1297 : 0 : break;
1298 : : case DataType::REAL:
1299 : : case DataType::DOUBLE:
1300 : : case DataType::NUMERIC:
1301 : : case DataType::DECIMAL:
1302 : 0 : nOBJID = OBJ_FM_FORMATTEDFIELD;
1303 : 0 : break;
1304 : : case DataType::TIMESTAMP:
1305 : 0 : bDateNTimeField = sal_True;
1306 [ # # ][ # # ]: 0 : sLabelPostfix = String( SVX_RES( RID_STR_POSTFIX_DATE ) );
[ # # ][ # # ]
1307 : : // DON'T break !
1308 : : case DataType::DATE:
1309 : 0 : nOBJID = OBJ_FM_DATEFIELD;
1310 : 0 : break;
1311 : : case DataType::TIME:
1312 : 0 : nOBJID = OBJ_FM_TIMEFIELD;
1313 : 0 : break;
1314 : : case DataType::CHAR:
1315 : : case DataType::VARCHAR:
1316 : : default:
1317 : 0 : nOBJID = OBJ_FM_EDIT;
1318 : 0 : break;
1319 : : }
1320 [ # # ]: 0 : if (!nOBJID)
1321 : 0 : return NULL;
1322 : :
1323 : 0 : SdrUnoObj* pLabel( NULL );
1324 : 0 : SdrUnoObj* pControl( NULL );
1325 [ # # ]: 0 : if ( !createControlLabelPair( *pOutDev, 0, 0, xField, xNumberFormats, nOBJID, sLabelPostfix,
1326 [ # # ]: 0 : pLabel, pControl, xDataSource, sDataSource, sCommand, nCommandType )
1327 : : )
1328 : : {
1329 : 0 : return NULL;
1330 : : }
1331 : :
1332 : : //////////////////////////////////////////////////////////////////////
1333 : : // group objects
1334 : 0 : bool bCheckbox = ( OBJ_FM_CHECKBOX == nOBJID );
1335 : : OSL_ENSURE( !bCheckbox || !pLabel, "FmXFormView::implCreateFieldControl: why was there a label created for a check box?" );
1336 [ # # ]: 0 : if ( bCheckbox )
1337 : 0 : return pControl;
1338 : :
1339 [ # # ][ # # ]: 0 : SdrObjGroup* pGroup = new SdrObjGroup();
1340 [ # # ]: 0 : SdrObjList* pObjList = pGroup->GetSubList();
1341 [ # # ]: 0 : pObjList->InsertObject( pLabel );
1342 [ # # ]: 0 : pObjList->InsertObject( pControl );
1343 : :
1344 [ # # ]: 0 : if ( bDateNTimeField )
1345 : : { // so far we created a date field only, but we also need a time field
1346 : 0 : pLabel = pControl = NULL;
1347 [ # # ][ # # ]: 0 : if ( createControlLabelPair( *pOutDev, 0, 1000, xField, xNumberFormats, OBJ_FM_TIMEFIELD,
1348 [ # # ]: 0 : String( SVX_RES( RID_STR_POSTFIX_TIME ) ), pLabel, pControl,
1349 [ # # ][ # # ]: 0 : xDataSource, sDataSource, sCommand, nCommandType )
[ # # ]
1350 : : )
1351 : : {
1352 [ # # ]: 0 : pObjList->InsertObject( pLabel );
1353 [ # # ]: 0 : pObjList->InsertObject( pControl );
1354 : : }
1355 : : }
1356 : :
1357 [ # # ]: 0 : return pGroup; // und fertig
1358 : : }
1359 [ # # ]: 0 : catch (const Exception&)
1360 : : {
1361 : : DBG_UNHANDLED_EXCEPTION();
1362 : : }
1363 : :
1364 : :
1365 [ # # ][ # # ]: 0 : return NULL;
[ # # ]
1366 : : }
1367 : :
1368 : : // -----------------------------------------------------------------------------
1369 : 0 : SdrObject* FmXFormView::implCreateXFormsControl( const ::svx::OXFormsDescriptor &_rDesc )
1370 : : {
1371 : : // not if we're in design mode
1372 [ # # ]: 0 : if ( !m_pView->IsDesignMode() )
1373 : 0 : return NULL;
1374 : :
1375 : 0 : Reference< XComponent > xKeepFieldsAlive;
1376 : :
1377 : : // go
1378 : : try
1379 : : {
1380 : : // determine the table/query field which we should create a control for
1381 : 0 : Reference< XNumberFormats > xNumberFormats;
1382 [ # # ]: 0 : ::rtl::OUString sLabelPostfix = _rDesc.szName;
1383 : :
1384 : : ////////////////////////////////////////////////////////////////
1385 : : // nur fuer Textgroesse
1386 : 0 : OutputDevice* pOutDev = NULL;
1387 [ # # ][ # # ]: 0 : if (m_pView->GetActualOutDev() && m_pView->GetActualOutDev()->GetOutDevType() == OUTDEV_WINDOW)
[ # # ]
1388 : 0 : pOutDev = const_cast<OutputDevice*>(m_pView->GetActualOutDev());
1389 : : else
1390 : : {// OutDev suchen
1391 : 0 : SdrPageView* pPageView = m_pView->GetSdrPageView();
1392 [ # # ][ # # ]: 0 : if( pPageView && !pOutDev )
1393 : : {
1394 : : // const SdrPageViewWinList& rWinList = pPageView->GetWinList();
1395 : : // const SdrPageViewWindows& rPageViewWindows = pPageView->GetPageViewWindows();
1396 : :
1397 [ # # ]: 0 : for( sal_uInt32 i = 0L; i < pPageView->PageWindowCount(); i++ )
1398 : : {
1399 [ # # ]: 0 : const SdrPageWindow& rPageWindow = *pPageView->GetPageWindow(i);
1400 : :
1401 [ # # ]: 0 : if( rPageWindow.GetPaintWindow().GetOutputDevice().GetOutDevType() == OUTDEV_WINDOW)
1402 : : {
1403 : 0 : pOutDev = &rPageWindow.GetPaintWindow().GetOutputDevice();
1404 : 0 : break;
1405 : : }
1406 : : }
1407 : : }
1408 : : }
1409 : :
1410 [ # # ]: 0 : if ( !pOutDev )
1411 : 0 : return NULL;
1412 : :
1413 : : //////////////////////////////////////////////////////////////////////
1414 : : // The service name decides which control should be created
1415 : 0 : sal_uInt16 nOBJID = OBJ_FM_EDIT;
1416 [ # # ][ # # ]: 0 : if(::rtl::OUString(_rDesc.szServiceName).equals((::rtl::OUString)FM_SUN_COMPONENT_NUMERICFIELD))
[ # # ]
1417 : 0 : nOBJID = OBJ_FM_NUMERICFIELD;
1418 [ # # ][ # # ]: 0 : if(::rtl::OUString(_rDesc.szServiceName).equals((::rtl::OUString)FM_SUN_COMPONENT_CHECKBOX))
[ # # ]
1419 : 0 : nOBJID = OBJ_FM_CHECKBOX;
1420 [ # # ][ # # ]: 0 : if(::rtl::OUString(_rDesc.szServiceName).equals((::rtl::OUString)FM_COMPONENT_COMMANDBUTTON))
[ # # ]
1421 : 0 : nOBJID = OBJ_FM_BUTTON;
1422 : :
1423 : : typedef ::com::sun::star::form::submission::XSubmission XSubmission_t;
1424 [ # # ]: 0 : Reference< XSubmission_t > xSubmission(_rDesc.xPropSet, UNO_QUERY);
1425 : :
1426 : : // xform control or submission button?
1427 [ # # ]: 0 : if ( !xSubmission.is() )
1428 : : {
1429 : 0 : SdrUnoObj* pLabel( NULL );
1430 : 0 : SdrUnoObj* pControl( NULL );
1431 [ # # ]: 0 : if ( !createControlLabelPair( *pOutDev, 0, 0, NULL, xNumberFormats, nOBJID, sLabelPostfix,
1432 [ # # ][ # # ]: 0 : pLabel, pControl )
[ # # ]
1433 : : )
1434 : : {
1435 : 0 : return NULL;
1436 : : }
1437 : :
1438 : : //////////////////////////////////////////////////////////////////////
1439 : : // Now build the connection between the control and the data item.
1440 [ # # ]: 0 : Reference< XValueBinding > xValueBinding(_rDesc.xPropSet,UNO_QUERY);
1441 [ # # ][ # # ]: 0 : Reference< XBindableValue > xBindableValue(pControl->GetUnoControlModel(),UNO_QUERY);
1442 : :
1443 : : DBG_ASSERT( xBindableValue.is(), "FmXFormView::implCreateXFormsControl: control's not bindable!" );
1444 [ # # ]: 0 : if ( xBindableValue.is() )
1445 [ # # ][ # # ]: 0 : xBindableValue->setValueBinding(xValueBinding);
1446 : :
1447 : 0 : bool bCheckbox = ( OBJ_FM_CHECKBOX == nOBJID );
1448 : : OSL_ENSURE( !bCheckbox || !pLabel, "FmXFormView::implCreateXFormsControl: why was there a label created for a check box?" );
1449 [ # # ]: 0 : if ( bCheckbox )
1450 : 0 : return pControl;
1451 : :
1452 : : //////////////////////////////////////////////////////////////////////
1453 : : // group objects
1454 [ # # ][ # # ]: 0 : SdrObjGroup* pGroup = new SdrObjGroup();
1455 [ # # ]: 0 : SdrObjList* pObjList = pGroup->GetSubList();
1456 [ # # ]: 0 : pObjList->InsertObject(pLabel);
1457 [ # # ]: 0 : pObjList->InsertObject(pControl);
1458 : :
1459 : 0 : return pGroup;
1460 : : }
1461 : : else {
1462 : :
1463 : : // create a button control
1464 [ # # ]: 0 : const MapMode eTargetMode( pOutDev->GetMapMode() );
1465 [ # # ]: 0 : const MapMode eSourceMode(MAP_100TH_MM);
1466 : 0 : const sal_uInt16 nObjID = OBJ_FM_BUTTON;
1467 : 0 : ::Size controlSize(4000, 500);
1468 [ # # ]: 0 : FmFormObj *pControl = static_cast<FmFormObj*>(SdrObjFactory::MakeNewObject( FmFormInventor, nObjID, NULL, NULL ));
1469 [ # # ][ # # ]: 0 : controlSize.Width() = Fraction(controlSize.Width(), 1) * eTargetMode.GetScaleX();
[ # # ]
1470 [ # # ][ # # ]: 0 : controlSize.Height() = Fraction(controlSize.Height(), 1) * eTargetMode.GetScaleY();
[ # # ]
1471 [ # # ]: 0 : ::Point controlPos( pOutDev->LogicToLogic( ::Point( controlSize.Width(), 0 ), eSourceMode, eTargetMode ) );
1472 [ # # ][ # # ]: 0 : ::Rectangle controlRect( controlPos, pOutDev->LogicToLogic( controlSize, eSourceMode, eTargetMode ) );
1473 [ # # ]: 0 : pControl->SetLogicRect(controlRect);
1474 : :
1475 : : // set the button label
1476 [ # # ][ # # ]: 0 : Reference< XPropertySet > xControlSet(pControl->GetUnoControlModel(), UNO_QUERY);
1477 [ # # ][ # # ]: 0 : xControlSet->setPropertyValue(FM_PROP_LABEL, makeAny(::rtl::OUString(_rDesc.szName)));
[ # # ][ # # ]
[ # # ]
1478 : :
1479 : : // connect the submission with the submission supplier (aka the button)
1480 [ # # ]: 0 : xControlSet->setPropertyValue( FM_PROP_BUTTON_TYPE,
1481 [ # # ][ # # ]: 0 : makeAny( FormButtonType_SUBMIT ) );
[ # # ]
1482 : : typedef ::com::sun::star::form::submission::XSubmissionSupplier XSubmissionSupplier_t;
1483 [ # # ][ # # ]: 0 : Reference< XSubmissionSupplier_t > xSubmissionSupplier(pControl->GetUnoControlModel(), UNO_QUERY);
1484 [ # # ][ # # ]: 0 : xSubmissionSupplier->setSubmission(xSubmission);
1485 : :
1486 [ # # ][ # # ]: 0 : return pControl;
1487 [ # # ]: 0 : }
1488 : : }
1489 [ # # ]: 0 : catch (const Exception&)
1490 : : {
1491 : : OSL_FAIL("FmXFormView::implCreateXFormsControl: caught an exception while creating the control !");
1492 : : }
1493 : :
1494 : :
1495 : 0 : return NULL;
1496 : : }
1497 : :
1498 : : //------------------------------------------------------------------------
1499 : 0 : bool FmXFormView::createControlLabelPair( OutputDevice& _rOutDev, sal_Int32 _nXOffsetMM, sal_Int32 _nYOffsetMM,
1500 : : const Reference< XPropertySet >& _rxField, const Reference< XNumberFormats >& _rxNumberFormats,
1501 : : sal_uInt16 _nControlObjectID, const ::rtl::OUString& _rFieldPostfix,
1502 : : SdrUnoObj*& _rpLabel, SdrUnoObj*& _rpControl,
1503 : : const Reference< XDataSource >& _rxDataSource, const ::rtl::OUString& _rDataSourceName,
1504 : : const ::rtl::OUString& _rCommand, const sal_Int32 _nCommandType )
1505 : : {
1506 [ # # ]: 0 : if ( !createControlLabelPair( m_aContext, _rOutDev, _nXOffsetMM, _nYOffsetMM,
1507 : : _rxField, _rxNumberFormats, _nControlObjectID, _rFieldPostfix, FmFormInventor, OBJ_FM_FIXEDTEXT,
1508 [ # # ]: 0 : NULL, NULL, NULL, _rpLabel, _rpControl )
1509 : : )
1510 : 0 : return false;
1511 : :
1512 : : // insert the control model(s) into the form component hierachy
1513 [ # # ]: 0 : if ( _rpLabel )
1514 [ # # ]: 0 : lcl_insertIntoFormComponentHierarchy_throw( *m_pView, *_rpLabel, _rxDataSource, _rDataSourceName, _rCommand, _nCommandType );
1515 [ # # ]: 0 : lcl_insertIntoFormComponentHierarchy_throw( *m_pView, *_rpControl, _rxDataSource, _rDataSourceName, _rCommand, _nCommandType );
1516 : :
1517 : : // some context-dependent initializations
1518 [ # # ]: 0 : FormControlFactory aControlFactory( m_aContext );
1519 [ # # ]: 0 : if ( _rpLabel )
1520 [ # # ][ # # ]: 0 : aControlFactory.initializeControlModel( impl_getDocumentType(), *_rpLabel );
1521 [ # # ][ # # ]: 0 : aControlFactory.initializeControlModel( impl_getDocumentType(), *_rpControl );
1522 : :
1523 [ # # ]: 0 : return true;
1524 : : }
1525 : :
1526 : : //------------------------------------------------------------------------
1527 : 0 : bool FmXFormView::createControlLabelPair( const ::comphelper::ComponentContext& _rContext,
1528 : : OutputDevice& _rOutDev, sal_Int32 _nXOffsetMM, sal_Int32 _nYOffsetMM, const Reference< XPropertySet >& _rxField,
1529 : : const Reference< XNumberFormats >& _rxNumberFormats, sal_uInt16 _nControlObjectID,
1530 : : const ::rtl::OUString& _rFieldPostfix, sal_uInt32 _nInventor, sal_uInt16 _nLabelObjectID,
1531 : : SdrPage* _pLabelPage, SdrPage* _pControlPage, SdrModel* _pModel, SdrUnoObj*& _rpLabel, SdrUnoObj*& _rpControl)
1532 : : {
1533 : 0 : sal_Int32 nDataType = 0;
1534 : 0 : ::rtl::OUString sFieldName;
1535 : 0 : Any aFieldName;
1536 [ # # ]: 0 : if ( _rxField.is() )
1537 : : {
1538 [ # # ][ # # ]: 0 : nDataType = ::comphelper::getINT32(_rxField->getPropertyValue(FM_PROP_FIELDTYPE));
[ # # ][ # # ]
1539 [ # # ][ # # ]: 0 : aFieldName = Any(_rxField->getPropertyValue(FM_PROP_NAME));
[ # # ]
1540 : 0 : aFieldName >>= sFieldName;
1541 : : }
1542 : :
1543 : : // calculate the positions, respecting the settings of the target device
1544 [ # # ][ # # ]: 0 : ::Size aTextSize( _rOutDev.GetTextWidth(sFieldName + _rFieldPostfix), _rOutDev.GetTextHeight() );
[ # # ][ # # ]
1545 : :
1546 [ # # ]: 0 : MapMode eTargetMode( _rOutDev.GetMapMode() ),
1547 [ # # ]: 0 : eSourceMode( MAP_100TH_MM );
1548 : :
1549 : : // Textbreite ist mindestens 4cm
1550 : : // Texthoehe immer halber cm
1551 : 0 : ::Size aDefTxtSize(4000, 500);
1552 : 0 : ::Size aDefSize(4000, 500);
1553 : 0 : ::Size aDefImageSize(4000, 4000);
1554 : :
1555 [ # # ]: 0 : ::Size aRealSize = _rOutDev.LogicToLogic(aTextSize, eTargetMode, eSourceMode);
1556 [ # # ]: 0 : aRealSize.Width() = std::max(aRealSize.Width(), aDefTxtSize.Width());
1557 : 0 : aRealSize.Height()= aDefSize.Height();
1558 : :
1559 : : // adjust to scaling of the target device (#53523#)
1560 [ # # ][ # # ]: 0 : aRealSize.Width() = long(Fraction(aRealSize.Width(), 1) * eTargetMode.GetScaleX());
[ # # ]
1561 [ # # ][ # # ]: 0 : aRealSize.Height() = long(Fraction(aRealSize.Height(), 1) * eTargetMode.GetScaleY());
[ # # ]
1562 : :
1563 : : // for boolean fields, we do not create a label, but just a checkbox
1564 : 0 : bool bNeedLabel = ( _nControlObjectID != OBJ_FM_CHECKBOX );
1565 : :
1566 : : // the label
1567 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1568 : 0 : ::std::auto_ptr< SdrUnoObj > pLabel;
1569 : : SAL_WNODEPRECATED_DECLARATIONS_POP
1570 : 0 : Reference< XPropertySet > xLabelModel;
1571 [ # # ]: 0 : if ( bNeedLabel )
1572 : : {
1573 : : pLabel.reset( dynamic_cast< SdrUnoObj* >(
1574 [ # # ][ # # ]: 0 : SdrObjFactory::MakeNewObject( _nInventor, _nLabelObjectID, _pLabelPage, _pModel ) ) );
1575 : : OSL_ENSURE( pLabel.get(), "FmXFormView::createControlLabelPair: could not create the label!" );
1576 [ # # ]: 0 : if ( !pLabel.get() )
1577 : 0 : return false;
1578 : :
1579 [ # # ][ # # ]: 0 : xLabelModel.set( pLabel->GetUnoControlModel(), UNO_QUERY );
1580 [ # # ]: 0 : if ( xLabelModel.is() )
1581 : : {
1582 : 0 : ::rtl::OUString sLabel;
1583 [ # # ][ # # ]: 0 : if ( _rxField.is() && _rxField->getPropertySetInfo()->hasPropertyByName(FM_PROP_LABEL) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # #
# # ][ # # ]
1584 [ # # ][ # # ]: 0 : _rxField->getPropertyValue(FM_PROP_LABEL) >>= sLabel;
[ # # ]
1585 [ # # ]: 0 : if ( sLabel.isEmpty() )
1586 : 0 : sLabel = sFieldName;
1587 : :
1588 [ # # ][ # # ]: 0 : xLabelModel->setPropertyValue( FM_PROP_LABEL, makeAny( sLabel + _rFieldPostfix ) );
[ # # ][ # # ]
1589 [ # # ][ # # ]: 0 : String sObjectLabel( SVX_RES( RID_STR_OBJECT_LABEL ) );
1590 [ # # ][ # # ]: 0 : sObjectLabel.SearchAndReplaceAllAscii( "#object#", sFieldName );
[ # # ]
1591 [ # # ][ # # ]: 0 : xLabelModel->setPropertyValue( FM_PROP_NAME, makeAny( ::rtl::OUString( sObjectLabel ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
1592 : : }
1593 : :
1594 : 0 : pLabel->SetLogicRect( ::Rectangle(
1595 : 0 : _rOutDev.LogicToLogic( ::Point( _nXOffsetMM, _nYOffsetMM ), eSourceMode, eTargetMode ),
1596 : : _rOutDev.LogicToLogic( aRealSize, eSourceMode, eTargetMode )
1597 [ # # ][ # # ]: 0 : ) );
[ # # # # ]
1598 : : }
1599 : :
1600 : : // the control
1601 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1602 : : ::std::auto_ptr< SdrUnoObj > pControl( dynamic_cast< SdrUnoObj* >(
1603 [ # # ][ # # ]: 0 : SdrObjFactory::MakeNewObject( _nInventor, _nControlObjectID, _pControlPage, _pModel ) ) );
1604 : : SAL_WNODEPRECATED_DECLARATIONS_POP
1605 : : OSL_ENSURE( pControl.get(), "FmXFormView::createControlLabelPair: could not create the control!" );
1606 [ # # ]: 0 : if ( !pControl.get() )
1607 : 0 : return false;
1608 : :
1609 [ # # ][ # # ]: 0 : Reference< XPropertySet > xControlSet( pControl->GetUnoControlModel(), UNO_QUERY );
1610 [ # # ]: 0 : if ( !xControlSet.is() )
1611 : 0 : return false;
1612 : :
1613 : : // size of the control
1614 : 0 : ::Size aControlSize( aDefSize );
1615 [ # # # ]: 0 : switch ( nDataType )
1616 : : {
1617 : : case DataType::BIT:
1618 : : case DataType::BOOLEAN:
1619 : 0 : aControlSize = aDefSize;
1620 : 0 : break;
1621 : : case DataType::LONGVARCHAR:
1622 : : case DataType::CLOB:
1623 : : case DataType::LONGVARBINARY:
1624 : : case DataType::BLOB:
1625 : 0 : aControlSize = aDefImageSize;
1626 : 0 : break;
1627 : : }
1628 : :
1629 [ # # ]: 0 : if ( OBJ_FM_IMAGECONTROL == _nControlObjectID )
1630 : 0 : aControlSize = aDefImageSize;
1631 : :
1632 [ # # ][ # # ]: 0 : aControlSize.Width() = long(Fraction(aControlSize.Width(), 1) * eTargetMode.GetScaleX());
[ # # ]
1633 [ # # ][ # # ]: 0 : aControlSize.Height() = long(Fraction(aControlSize.Height(), 1) * eTargetMode.GetScaleY());
[ # # ]
1634 : :
1635 : 0 : pControl->SetLogicRect( ::Rectangle(
1636 : 0 : _rOutDev.LogicToLogic( ::Point( aRealSize.Width() + _nXOffsetMM, _nYOffsetMM ), eSourceMode, eTargetMode ),
1637 : : _rOutDev.LogicToLogic( aControlSize, eSourceMode, eTargetMode )
1638 [ # # ][ # # ]: 0 : ) );
[ # # # # ]
1639 : :
1640 : : // some initializations
1641 [ # # ][ # # ]: 0 : Reference< XPropertySetInfo > xControlPropInfo = xControlSet->getPropertySetInfo();
1642 : :
1643 [ # # ]: 0 : if ( aFieldName.hasValue() )
1644 : : {
1645 [ # # ][ # # ]: 0 : xControlSet->setPropertyValue( FM_PROP_CONTROLSOURCE, aFieldName );
[ # # ]
1646 [ # # ][ # # ]: 0 : xControlSet->setPropertyValue( FM_PROP_NAME, aFieldName );
[ # # ]
1647 [ # # ]: 0 : if ( !bNeedLabel )
1648 : : {
1649 : : // no dedicated label control => use the label property
1650 [ # # ][ # # ]: 0 : if ( xControlPropInfo->hasPropertyByName( FM_PROP_LABEL ) )
[ # # ][ # # ]
1651 [ # # ][ # # ]: 0 : xControlSet->setPropertyValue( FM_PROP_LABEL, makeAny( sFieldName + _rFieldPostfix ) );
[ # # ][ # # ]
1652 : : else
1653 : : OSL_FAIL( "FmXFormView::createControlLabelPair: can't set a label for the control!" );
1654 : : }
1655 : : }
1656 : :
1657 [ # # ][ # # ]: 0 : if ( (nDataType == DataType::LONGVARCHAR || nDataType == DataType::CLOB) && xControlPropInfo->hasPropertyByName( FM_PROP_MULTILINE ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
[ # # # # ]
1658 : : {
1659 [ # # ][ # # ]: 0 : xControlSet->setPropertyValue( FM_PROP_MULTILINE, makeAny( sal_Bool( sal_True ) ) );
[ # # ][ # # ]
1660 : : }
1661 : :
1662 : : // announce the label to the control
1663 [ # # ][ # # ]: 0 : if ( xControlPropInfo->hasPropertyByName( FM_PROP_CONTROLLABEL ) && xLabelModel.is() )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
1664 : : {
1665 : : try
1666 : : {
1667 [ # # ][ # # ]: 0 : xControlSet->setPropertyValue( FM_PROP_CONTROLLABEL, makeAny( xLabelModel ) );
[ # # ][ # # ]
[ # # ]
1668 : : }
1669 [ # # ]: 0 : catch (const Exception&)
1670 : : {
1671 : : DBG_UNHANDLED_EXCEPTION();
1672 : : }
1673 : : }
1674 : :
1675 [ # # ]: 0 : if ( _rxField.is() )
1676 : : {
1677 [ # # ]: 0 : FormControlFactory aControlFactory( _rContext );
1678 [ # # ][ # # ]: 0 : aControlFactory.initializeFieldDependentProperties( _rxField, xControlSet, _rxNumberFormats );
1679 : : }
1680 : :
1681 : 0 : _rpLabel = pLabel.release();
1682 : 0 : _rpControl = pControl.release();
1683 [ # # ][ # # ]: 0 : return true;
[ # # ][ # # ]
1684 : : }
1685 : :
1686 : : //------------------------------------------------------------------------------
1687 : 69 : FmXFormView::ObjectRemoveListener::ObjectRemoveListener( FmXFormView* pParent )
1688 : 69 : :m_pParent( pParent )
1689 : : {
1690 : 69 : }
1691 : :
1692 : : //------------------------------------------------------------------------------
1693 : 14 : void FmXFormView::ObjectRemoveListener::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
1694 : : {
1695 [ + + ][ - + ]: 14 : if (rHint.ISA(SdrHint) && (((SdrHint&)rHint).GetKind() == HINT_OBJREMOVED))
[ - + ]
1696 : 0 : m_pParent->ObjectRemovedInAliveMode(((SdrHint&)rHint).GetObject());
1697 : 14 : }
1698 : :
1699 : : //------------------------------------------------------------------------------
1700 : 0 : void FmXFormView::ObjectRemovedInAliveMode( const SdrObject* pObject )
1701 : : {
1702 : : // wenn das entfernte Objekt in meiner MarkList, die ich mir beim Umschalten in den Alive-Mode gemerkt habe, steht,
1703 : : // muss ich es jetzt da rausnehmen, da ich sonst beim Zurueckschalten versuche, die Markierung wieder zu setzen
1704 : : // (interesanterweise geht das nur bei gruppierten Objekten schief (beim Zugriff auf deren ObjList GPF), nicht bei einzelnen)
1705 : :
1706 : 0 : sal_uIntPtr nCount = m_aMark.GetMarkCount();
1707 [ # # ]: 0 : for (sal_uIntPtr i = 0; i < nCount; ++i)
1708 : : {
1709 : 0 : SdrMark* pMark = m_aMark.GetMark(i);
1710 : 0 : SdrObject* pCurrent = pMark->GetMarkedSdrObj();
1711 [ # # ]: 0 : if (pObject == pCurrent)
1712 : : {
1713 : 0 : m_aMark.DeleteMark(i);
1714 : 0 : return;
1715 : : }
1716 : : // ich brauche nicht in GroupObjects absteigen : wenn dort unten ein Objekt geloescht wird, dann bleibt der
1717 : : // Zeiger auf das GroupObject, den ich habe, trotzdem weiter gueltig bleibt ...
1718 : : }
1719 : : }
1720 : :
1721 : : //------------------------------------------------------------------------------
1722 : 1604 : void FmXFormView::stopMarkListWatching()
1723 : : {
1724 [ - + ]: 1604 : if ( m_pWatchStoredList )
1725 : : {
1726 : 0 : m_pWatchStoredList->EndListeningAll();
1727 [ # # ]: 0 : delete m_pWatchStoredList;
1728 : 0 : m_pWatchStoredList = NULL;
1729 : : }
1730 : 1604 : }
1731 : :
1732 : : //------------------------------------------------------------------------------
1733 : 69 : void FmXFormView::startMarkListWatching()
1734 : : {
1735 [ + - ]: 69 : if ( !m_pWatchStoredList )
1736 : : {
1737 [ + - ]: 69 : m_pWatchStoredList = new ObjectRemoveListener( this );
1738 [ + - ]: 69 : FmFormModel* pModel = GetFormShell() ? GetFormShell()->GetFormModel() : NULL;
1739 : : DBG_ASSERT( pModel != NULL, "FmXFormView::startMarkListWatching: shell has no model!" );
1740 : 69 : m_pWatchStoredList->StartListening( *static_cast< SfxBroadcaster* >( pModel ) );
1741 : : }
1742 : : else
1743 : : {
1744 : : OSL_FAIL( "FmXFormView::startMarkListWatching: already listening!" );
1745 : : }
1746 : 69 : }
1747 : :
1748 : : //------------------------------------------------------------------------------
1749 : 69 : void FmXFormView::saveMarkList( sal_Bool _bSmartUnmark )
1750 : : {
1751 [ + - ]: 69 : if ( m_pView )
1752 : : {
1753 : 69 : m_aMark = m_pView->GetMarkedObjectList();
1754 [ + - ]: 69 : if ( _bSmartUnmark )
1755 : : {
1756 : 69 : sal_uIntPtr nCount = m_aMark.GetMarkCount( );
1757 [ - + ]: 69 : for ( sal_uIntPtr i = 0; i < nCount; ++i )
1758 : : {
1759 : 0 : SdrMark* pMark = m_aMark.GetMark(i);
1760 : 0 : SdrObject* pObj = pMark->GetMarkedSdrObj();
1761 : :
1762 [ # # ]: 0 : if ( m_pView->IsObjMarked( pObj ) )
1763 : : {
1764 [ # # ]: 0 : if ( pObj->IsGroupObject() )
1765 : : {
1766 [ # # ][ # # ]: 0 : SdrObjListIter aIter( *pObj->GetSubList() );
1767 : 0 : sal_Bool bMixed = sal_False;
1768 [ # # ][ # # ]: 0 : while ( aIter.IsMore() && !bMixed )
[ # # ]
1769 [ # # ][ # # ]: 0 : bMixed = ( aIter.Next()->GetObjInventor() != FmFormInventor );
1770 : :
1771 [ # # ]: 0 : if ( !bMixed )
1772 : : {
1773 : : // all objects in the group are form objects
1774 [ # # ][ # # ]: 0 : m_pView->MarkObj( pMark->GetMarkedSdrObj(), pMark->GetPageView(), sal_True /* unmark! */ );
1775 : 0 : }
1776 : : }
1777 : : else
1778 : : {
1779 [ # # ]: 0 : if ( pObj->GetObjInventor() == FmFormInventor )
1780 : : { // this is a form layer object
1781 : 0 : m_pView->MarkObj( pMark->GetMarkedSdrObj(), pMark->GetPageView(), sal_True /* unmark! */ );
1782 : : }
1783 : : }
1784 : : }
1785 : : }
1786 : : }
1787 : : }
1788 : : else
1789 : : {
1790 : : OSL_FAIL( "FmXFormView::saveMarkList: invalid view!" );
1791 [ # # ]: 0 : m_aMark = SdrMarkList();
1792 : : }
1793 : 69 : }
1794 : :
1795 : : //--------------------------------------------------------------------------
1796 : 0 : static sal_Bool lcl_hasObject( SdrObjListIter& rIter, SdrObject* pObj )
1797 : : {
1798 : 0 : sal_Bool bFound = sal_False;
1799 [ # # ][ # # ]: 0 : while (rIter.IsMore() && !bFound)
[ # # ]
1800 : 0 : bFound = pObj == rIter.Next();
1801 : :
1802 : 0 : rIter.Reset();
1803 : 0 : return bFound;
1804 : : }
1805 : :
1806 : : //------------------------------------------------------------------------------
1807 : 1604 : void FmXFormView::restoreMarkList( SdrMarkList& _rRestoredMarkList )
1808 : : {
1809 [ - + ]: 1604 : if ( !m_pView )
1810 : 0 : return;
1811 : :
1812 : 1604 : _rRestoredMarkList.Clear();
1813 : :
1814 : 1604 : const SdrMarkList& rCurrentList = m_pView->GetMarkedObjectList();
1815 [ + - ]: 1604 : FmFormPage* pPage = GetFormShell() ? GetFormShell()->GetCurPage() : NULL;
1816 [ + - ]: 1604 : if (pPage)
1817 : : {
1818 [ - + ]: 1604 : if (rCurrentList.GetMarkCount())
1819 : : { // there is a current mark ... hmm. Is it a subset of the mark we remembered in saveMarkList?
1820 : 0 : sal_Bool bMisMatch = sal_False;
1821 : :
1822 : : // loop through all current marks
1823 : 0 : sal_uIntPtr nCurrentCount = rCurrentList.GetMarkCount();
1824 [ # # ][ # # ]: 0 : for ( sal_uIntPtr i=0; i<nCurrentCount&& !bMisMatch; ++i )
[ # # ]
1825 : : {
1826 [ # # ][ # # ]: 0 : const SdrObject* pCurrentMarked = rCurrentList.GetMark( i )->GetMarkedSdrObj();
1827 : :
1828 : : // loop through all saved marks, check for equality
1829 : 0 : sal_Bool bFound = sal_False;
1830 : 0 : sal_uIntPtr nSavedCount = m_aMark.GetMarkCount();
1831 [ # # ][ # # ]: 0 : for ( sal_uIntPtr j=0; j<nSavedCount && !bFound; ++j )
[ # # ]
1832 : : {
1833 [ # # ][ # # ]: 0 : if ( m_aMark.GetMark( j )->GetMarkedSdrObj() == pCurrentMarked )
[ # # ]
1834 : 0 : bFound = sal_True;
1835 : : }
1836 : :
1837 : : // did not find a current mark in the saved marks
1838 [ # # ]: 0 : if ( !bFound )
1839 : 0 : bMisMatch = sal_True;
1840 : : }
1841 : :
1842 [ # # ]: 0 : if ( bMisMatch )
1843 : : {
1844 [ # # ]: 0 : m_aMark.Clear();
1845 [ # # ]: 0 : _rRestoredMarkList = rCurrentList;
1846 : : return;
1847 : : }
1848 : : }
1849 : : // wichtig ist das auf die Objecte der markliste nicht zugegriffen wird
1850 : : // da diese bereits zerstoert sein koennen
1851 : 1604 : SdrPageView* pCurPageView = m_pView->GetSdrPageView();
1852 [ + - ]: 1604 : SdrObjListIter aPageIter( *pPage );
1853 : 1604 : sal_Bool bFound = sal_True;
1854 : :
1855 : : // gibt es noch alle Objecte
1856 : 1604 : sal_uIntPtr nCount = m_aMark.GetMarkCount();
1857 [ - + ][ # # ]: 1604 : for (sal_uIntPtr i = 0; i < nCount && bFound; i++)
[ - + ]
1858 : : {
1859 [ # # ]: 0 : SdrMark* pMark = m_aMark.GetMark(i);
1860 [ # # ]: 0 : SdrObject* pObj = pMark->GetMarkedSdrObj();
1861 [ # # ][ # # ]: 0 : if (pObj->IsGroupObject())
1862 : : {
1863 [ # # ][ # # ]: 0 : SdrObjListIter aIter(*pObj->GetSubList());
1864 [ # # ][ # # ]: 0 : while (aIter.IsMore() && bFound)
[ # # ]
1865 [ # # ][ # # ]: 0 : bFound = lcl_hasObject(aPageIter, aIter.Next());
1866 : : }
1867 : : else
1868 [ # # ]: 0 : bFound = lcl_hasObject(aPageIter, pObj);
1869 : :
1870 [ # # ][ # # ]: 0 : bFound = bFound && pCurPageView == pMark->GetPageView();
1871 : : }
1872 : :
1873 [ + - ]: 1604 : if (bFound)
1874 : : {
1875 : : // Das LastObject auswerten
1876 [ - + ]: 1604 : if (nCount) // Objecte jetzt Markieren
1877 : : {
1878 [ # # ]: 0 : for (sal_uIntPtr i = 0; i < nCount; i++)
1879 : : {
1880 [ # # ]: 0 : SdrMark* pMark = m_aMark.GetMark(i);
1881 [ # # ]: 0 : SdrObject* pObj = pMark->GetMarkedSdrObj();
1882 [ # # ][ # # ]: 0 : if ( pObj->GetObjInventor() == FmFormInventor )
1883 [ # # ][ # # ]: 0 : if ( !m_pView->IsObjMarked( pObj ) )
1884 [ # # ]: 0 : m_pView->MarkObj( pObj, pMark->GetPageView() );
1885 : : }
1886 : :
1887 [ # # ]: 0 : _rRestoredMarkList = m_aMark;
1888 : : }
1889 : : }
1890 [ + - ]: 1604 : m_aMark.Clear();
1891 : : }
1892 : : }
1893 : : // -----------------------------------------------------------------------------
1894 : 0 : void SAL_CALL FmXFormView::focusGained( const FocusEvent& /*e*/ ) throw (RuntimeException)
1895 : : {
1896 [ # # ][ # # ]: 0 : if ( m_xWindow.is() && m_pView )
[ # # ]
1897 : : {
1898 [ # # ]: 0 : m_pView->SetMoveOutside( sal_True, FmFormView::ImplAccess() );
1899 : : }
1900 : 0 : }
1901 : : // -----------------------------------------------------------------------------
1902 : 0 : void SAL_CALL FmXFormView::focusLost( const FocusEvent& /*e*/ ) throw (RuntimeException)
1903 : : {
1904 : : // when switch the focus outside the office the mark didn't change
1905 : : // so we can not remove us as focus listener
1906 [ # # ][ # # ]: 0 : if ( m_xWindow.is() && m_pView )
[ # # ]
1907 : : {
1908 [ # # ]: 0 : m_pView->SetMoveOutside( sal_False, FmFormView::ImplAccess() );
1909 : : }
1910 : 0 : }
1911 : : // -----------------------------------------------------------------------------
1912 : 0 : void FmXFormView::removeGridWindowListening()
1913 : : {
1914 [ # # ]: 0 : if ( m_xWindow.is() )
1915 : : {
1916 [ # # ]: 0 : m_xWindow->removeFocusListener(this);
1917 [ # # ]: 0 : if ( m_pView )
1918 : : {
1919 [ # # ]: 0 : m_pView->SetMoveOutside( sal_False, FmFormView::ImplAccess() );
1920 : : }
1921 : 0 : m_xWindow = NULL;
1922 : : }
1923 : 0 : }
1924 : :
1925 : : // -----------------------------------------------------------------------------
1926 : 0 : DocumentType FmXFormView::impl_getDocumentType() const
1927 : : {
1928 [ # # ][ # # ]: 0 : if ( GetFormShell() && GetFormShell()->GetImpl() )
[ # # ]
1929 : 0 : return GetFormShell()->GetImpl()->getDocumentType();
1930 : 0 : return eUnknownDocumentType;
1931 : : }
1932 : :
1933 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|