1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "fmdocumentclassification.hxx"
23 #include "fmpgeimp.hxx"
25 #include "svx/fmresids.hrc"
26 #include "fmservs.hxx"
27 #include "fmshimp.hxx"
28 #include "svx/fmtools.hxx"
30 #include "fmvwimp.hxx"
31 #include "formcontrolfactory.hxx"
32 #include "svx/sdrpaintwindow.hxx"
33 #include "svx/svditer.hxx"
34 #include "svx/dataaccessdescriptor.hxx"
35 #include "svx/dialmgr.hxx"
36 #include "svx/fmglob.hxx"
37 #include "svx/fmmodel.hxx"
38 #include "svx/fmpage.hxx"
39 #include "svx/fmshell.hxx"
40 #include "svx/fmview.hxx"
41 #include "svx/sdrpagewindow.hxx"
42 #include "svx/svdogrp.hxx"
43 #include "svx/svdpagv.hxx"
44 #include "svx/xmlexchg.hxx"
46 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
47 #include <com/sun/star/style/VerticalAlignment.hpp>
48 #include <com/sun/star/lang/XInitialization.hpp>
49 #include <com/sun/star/sdbc/XRowSet.hpp>
50 #include <com/sun/star/form/XLoadable.hpp>
51 #include <com/sun/star/awt/VisualEffect.hpp>
52 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
53 #include <com/sun/star/util/XNumberFormats.hpp>
54 #include <com/sun/star/sdb/CommandType.hpp>
55 #include <com/sun/star/sdbc/DataType.hpp>
56 #include <com/sun/star/sdbc/ColumnValue.hpp>
57 #include <com/sun/star/form/FormComponentType.hpp>
58 #include <com/sun/star/form/FormButtonType.hpp>
59 #include <com/sun/star/form/XReset.hpp>
60 #include <com/sun/star/form/binding/XBindableValue.hpp>
61 #include <com/sun/star/form/binding/XValueBinding.hpp>
62 #include <com/sun/star/form/runtime/FormController.hpp>
63 #include <com/sun/star/form/submission/XSubmissionSupplier.hpp>
64 #include <com/sun/star/awt/XTabControllerModel.hpp>
65 #include <com/sun/star/awt/XControlContainer.hpp>
66 #include <com/sun/star/awt/XTabController.hpp>
67 #include <com/sun/star/container/XIndexAccess.hpp>
68 #include <com/sun/star/awt/XControl.hpp>
69 #include <com/sun/star/lang/XUnoTunnel.hpp>
70 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
71 #include <com/sun/star/sdbc/XPreparedStatement.hpp>
72 #include <com/sun/star/sdb/XQueriesSupplier.hpp>
73 #include <com/sun/star/container/XContainer.hpp>
75 #include <comphelper/enumhelper.hxx>
76 #include <comphelper/extract.hxx>
77 #include <comphelper/namedvaluecollection.hxx>
78 #include <comphelper/numbers.hxx>
79 #include <comphelper/property.hxx>
80 #include <comphelper/processfactory.hxx>
81 #include <cppuhelper/exc_hlp.hxx>
82 #include <unotools/moduleoptions.hxx>
83 #include <tools/diagnose_ex.h>
84 #include <vcl/msgbox.hxx>
85 #include <vcl/stdtext.hxx>
86 #include <osl/mutex.hxx>
90 using namespace ::comphelper
;
91 using namespace ::svx
;
92 using namespace ::svxform
;
94 using namespace ::com::sun::star
;
95 using ::com::sun::star::uno::Exception
;
96 using ::com::sun::star::uno::RuntimeException
;
97 using ::com::sun::star::uno::XInterface
;
98 using ::com::sun::star::uno::Sequence
;
99 using ::com::sun::star::uno::UNO_QUERY
;
100 using ::com::sun::star::uno::UNO_QUERY_THROW
;
101 using ::com::sun::star::uno::UNO_SET_THROW
;
102 using ::com::sun::star::uno::Type
;
103 using ::com::sun::star::uno::Reference
;
104 using ::com::sun::star::uno::Any
;
105 using ::com::sun::star::uno::makeAny
;
106 using ::com::sun::star::uno::XComponentContext
;
107 using ::com::sun::star::style::VerticalAlignment_MIDDLE
;
108 using ::com::sun::star::form::FormButtonType_SUBMIT
;
109 using ::com::sun::star::form::binding::XValueBinding
;
110 using ::com::sun::star::form::binding::XBindableValue
;
111 using ::com::sun::star::lang::XComponent
;
112 using ::com::sun::star::container::XIndexAccess
;
113 using ::com::sun::star::form::runtime::FormController
;
114 using ::com::sun::star::form::runtime::XFormController
;
115 using ::com::sun::star::script::XEventAttacherManager
;
116 using ::com::sun::star::awt::XTabControllerModel
;
117 using ::com::sun::star::container::XChild
;
118 using ::com::sun::star::container::XEnumeration
;
119 using ::com::sun::star::task::XInteractionHandler
;
120 using ::com::sun::star::lang::XInitialization
;
121 using ::com::sun::star::awt::XTabController
;
122 using ::com::sun::star::lang::XUnoTunnel
;
123 using ::com::sun::star::awt::XControlContainer
;
124 using ::com::sun::star::awt::XControl
;
125 using ::com::sun::star::form::XFormComponent
;
126 using ::com::sun::star::form::XForm
;
127 using ::com::sun::star::lang::IndexOutOfBoundsException
;
128 using ::com::sun::star::lang::WrappedTargetException
;
129 using ::com::sun::star::container::XContainer
;
130 using ::com::sun::star::container::ContainerEvent
;
131 using ::com::sun::star::lang::EventObject
;
132 using ::com::sun::star::beans::NamedValue
;
133 using ::com::sun::star::sdb::SQLErrorEvent
;
134 using ::com::sun::star::sdbc::XRowSet
;
135 using ::com::sun::star::beans::XPropertySet
;
136 using ::com::sun::star::container::XElementAccess
;
137 using ::com::sun::star::awt::XWindow
;
138 using ::com::sun::star::awt::FocusEvent
;
139 using ::com::sun::star::ui::dialogs::XExecutableDialog
;
140 using ::com::sun::star::sdbc::XDataSource
;
141 using ::com::sun::star::container::XIndexContainer
;
142 using ::com::sun::star::sdbc::XConnection
;
143 using ::com::sun::star::container::XNameAccess
;
144 using ::com::sun::star::sdb::SQLContext
;
145 using ::com::sun::star::sdbc::SQLWarning
;
146 using ::com::sun::star::sdbc::SQLException
;
147 using ::com::sun::star::util::XNumberFormatsSupplier
;
148 using ::com::sun::star::util::XNumberFormats
;
149 using ::com::sun::star::beans::XPropertySetInfo
;
151 namespace FormComponentType
= ::com::sun::star::form::FormComponentType
;
152 namespace CommandType
= ::com::sun::star::sdb::CommandType
;
153 namespace DataType
= ::com::sun::star::sdbc::DataType
;
156 class FmXFormView::ObjectRemoveListener
: public SfxListener
158 FmXFormView
* m_pParent
;
160 ObjectRemoveListener( FmXFormView
* pParent
);
161 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) SAL_OVERRIDE
;
166 FormViewPageWindowAdapter::FormViewPageWindowAdapter( const css::uno::Reference
<css::uno::XComponentContext
>& _rContext
, const SdrPageWindow
& _rWindow
, FmXFormView
* _pViewImpl
)
167 : m_xControlContainer( _rWindow
.GetControlContainer() ),
168 m_xContext( _rContext
),
169 m_pViewImpl( _pViewImpl
),
170 m_pWindow( dynamic_cast< Window
* >( &_rWindow
.GetPaintWindow().GetOutputDevice() ) )
173 // create an XFormController for every form
174 FmFormPage
* pFormPage
= dynamic_cast< FmFormPage
* >( _rWindow
.GetPageView().GetPage() );
175 DBG_ASSERT( pFormPage
, "FormViewPageWindowAdapter::FormViewPageWindowAdapter: no FmFormPage found!" );
180 Reference
< XIndexAccess
> xForms( pFormPage
->GetForms(), UNO_QUERY_THROW
);
181 sal_uInt32 nLength
= xForms
->getCount();
182 for (sal_uInt32 i
= 0; i
< nLength
; i
++)
184 Reference
< XForm
> xForm( xForms
->getByIndex(i
), UNO_QUERY
);
186 setController( xForm
, NULL
);
189 catch (const Exception
&)
191 DBG_UNHANDLED_EXCEPTION();
196 FormViewPageWindowAdapter::~FormViewPageWindowAdapter()
201 void FormViewPageWindowAdapter::dispose()
203 for ( ::std::vector
< Reference
< XFormController
> >::const_iterator i
= m_aControllerList
.begin();
204 i
!= m_aControllerList
.end();
210 Reference
< XFormController
> xController( *i
, UNO_QUERY_THROW
);
212 // detaching the events
213 Reference
< XChild
> xControllerModel( xController
->getModel(), UNO_QUERY
);
214 if ( xControllerModel
.is() )
216 Reference
< XEventAttacherManager
> xEventManager( xControllerModel
->getParent(), UNO_QUERY_THROW
);
217 Reference
< XInterface
> xControllerNormalized( xController
, UNO_QUERY_THROW
);
218 xEventManager
->detach( i
- m_aControllerList
.begin(), xControllerNormalized
);
221 // dispose the formcontroller
222 xController
->dispose();
224 catch (const Exception
&)
226 DBG_UNHANDLED_EXCEPTION();
230 m_aControllerList
.clear();
235 sal_Bool SAL_CALL
FormViewPageWindowAdapter::hasElements(void) throw( RuntimeException
, std::exception
)
237 return getCount() != 0;
241 Type SAL_CALL
FormViewPageWindowAdapter::getElementType(void) throw( RuntimeException
, std::exception
)
243 return cppu::UnoType
<XFormController
>::get();
246 // XEnumerationAccess
248 Reference
< XEnumeration
> SAL_CALL
FormViewPageWindowAdapter::createEnumeration(void) throw( RuntimeException
)
250 return new ::comphelper::OEnumerationByIndex(this);
255 sal_Int32 SAL_CALL
FormViewPageWindowAdapter::getCount(void) throw( RuntimeException
, std::exception
)
257 return m_aControllerList
.size();
261 Any SAL_CALL
FormViewPageWindowAdapter::getByIndex(sal_Int32 nIndex
) throw( IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
, std::exception
)
264 nIndex
>= getCount())
265 throw IndexOutOfBoundsException();
268 aElement
<<= m_aControllerList
[nIndex
];
273 void SAL_CALL
FormViewPageWindowAdapter::makeVisible( const Reference
< XControl
>& _Control
) throw (RuntimeException
, std::exception
)
275 SolarMutexGuard aSolarGuard
;
277 Reference
< XWindow
> xWindow( _Control
, UNO_QUERY
);
278 if ( xWindow
.is() && m_pViewImpl
->getView() && m_pWindow
)
280 awt::Rectangle aRect
= xWindow
->getPosSize();
281 ::Rectangle
aNewRect( aRect
.X
, aRect
.Y
, aRect
.X
+ aRect
.Width
, aRect
.Y
+ aRect
.Height
);
282 aNewRect
= m_pWindow
->PixelToLogic( aNewRect
);
283 m_pViewImpl
->getView()->MakeVisible( aNewRect
, *m_pWindow
);
288 Reference
< XFormController
> getControllerSearchChildren( const Reference
< XIndexAccess
> & xIndex
, const Reference
< XTabControllerModel
> & xModel
)
290 if (xIndex
.is() && xIndex
->getCount())
292 Reference
< XFormController
> xController
;
294 for (sal_Int32 n
= xIndex
->getCount(); n
-- && !xController
.is(); )
296 xIndex
->getByIndex(n
) >>= xController
;
297 if ((XTabControllerModel
*)xModel
.get() == (XTabControllerModel
*)xController
->getModel().get())
301 xController
= getControllerSearchChildren(xController
, xModel
);
302 if ( xController
.is() )
307 return Reference
< XFormController
> ();
310 // Search the according controller
312 Reference
< XFormController
> FormViewPageWindowAdapter::getController( const Reference
< XForm
> & xForm
) const
314 Reference
< XTabControllerModel
> xModel(xForm
, UNO_QUERY
);
315 for (::std::vector
< Reference
< XFormController
> >::const_iterator i
= m_aControllerList
.begin();
316 i
!= m_aControllerList
.end(); ++i
)
318 if ((XTabControllerModel
*)(*i
)->getModel().get() == (XTabControllerModel
*)xModel
.get())
321 // the current-round controller isn't the right one. perhaps one of its children ?
322 Reference
< XFormController
> xChildSearch
= getControllerSearchChildren(Reference
< XIndexAccess
> (*i
, UNO_QUERY
), xModel
);
323 if (xChildSearch
.is())
326 return Reference
< XFormController
> ();
330 void FormViewPageWindowAdapter::setController(const Reference
< XForm
> & xForm
, const Reference
< XFormController
>& _rxParentController
)
332 DBG_ASSERT( xForm
.is(), "FormViewPageWindowAdapter::setController: there should be a form!" );
333 Reference
< XIndexAccess
> xFormCps(xForm
, UNO_QUERY
);
337 Reference
< XTabControllerModel
> xTabOrder(xForm
, UNO_QUERY
);
339 // create a form controller
340 Reference
< XFormController
> xController( FormController::create(m_xContext
) );
342 Reference
< XInteractionHandler
> xHandler
;
343 if ( _rxParentController
.is() )
344 xHandler
= _rxParentController
->getInteractionHandler();
347 // TODO: should we create a default handler? Not really necessary, since the
348 // FormController itself has a default fallback
351 xController
->setInteractionHandler( xHandler
);
353 xController
->setContext( this );
355 xController
->setModel( xTabOrder
);
356 xController
->setContainer( m_xControlContainer
);
357 xController
->activateTabOrder();
358 xController
->addActivateListener( m_pViewImpl
);
360 if ( _rxParentController
.is() )
361 _rxParentController
->addChildController( xController
);
364 m_aControllerList
.push_back(xController
);
366 xController
->setParent( *this );
368 // attaching the events
369 Reference
< XEventAttacherManager
> xEventManager( xForm
->getParent(), UNO_QUERY
);
370 xEventManager
->attach(m_aControllerList
.size() - 1, xController
, makeAny(xController
) );
373 // jetzt die Subforms durchgehen
374 sal_uInt32 nLength
= xFormCps
->getCount();
375 Reference
< XForm
> xSubForm
;
376 for (sal_uInt32 i
= 0; i
< nLength
; i
++)
378 if ( xFormCps
->getByIndex(i
) >>= xSubForm
)
379 setController( xSubForm
, xController
);
384 void FormViewPageWindowAdapter::updateTabOrder( const Reference
< XForm
>& _rxForm
)
386 OSL_PRECOND( _rxForm
.is(), "FormViewPageWindowAdapter::updateTabOrder: illegal argument!" );
392 Reference
< XTabController
> xTabCtrl( getController( _rxForm
).get() );
394 { // if there already is a TabController for this form, then delegate the "updateTabOrder" request
395 xTabCtrl
->activateTabOrder();
398 { // otherwise, create a TabController
400 // if it's a sub form, then we must ensure there exist TabControllers
401 // for all its ancestors, too
402 Reference
< XForm
> xParentForm( _rxForm
->getParent(), UNO_QUERY
);
403 // there is a parent form -> look for the respective controller
404 Reference
< XFormController
> xParentController
;
405 if ( xParentForm
.is() )
406 xParentController
.set( getController( xParentForm
), UNO_QUERY
);
408 setController( _rxForm
, xParentController
);
411 catch (const Exception
&)
413 DBG_UNHANDLED_EXCEPTION();
418 FmXFormView::FmXFormView(FmFormView
* _pView
)
421 ,m_nActivationEvent(0)
422 ,m_nErrorMessageEvent( 0 )
423 ,m_nAutoFocusEvent( 0 )
424 ,m_nControlWizardEvent( 0 )
425 ,m_pWatchStoredList( NULL
)
426 ,m_bFirstActivation( true )
427 ,m_isTabOrderUpdateSuspended( false )
432 void FmXFormView::cancelEvents()
434 if ( m_nActivationEvent
)
436 Application::RemoveUserEvent( m_nActivationEvent
);
437 m_nActivationEvent
= 0;
440 if ( m_nErrorMessageEvent
)
442 Application::RemoveUserEvent( m_nErrorMessageEvent
);
443 m_nErrorMessageEvent
= 0;
446 if ( m_nAutoFocusEvent
)
448 Application::RemoveUserEvent( m_nAutoFocusEvent
);
449 m_nAutoFocusEvent
= 0;
452 if ( m_nControlWizardEvent
)
454 Application::RemoveUserEvent( m_nControlWizardEvent
);
455 m_nControlWizardEvent
= 0;
460 void FmXFormView::notifyViewDying( )
462 DBG_ASSERT( m_pView
, "FmXFormView::notifyViewDying: my view already died!" );
468 FmXFormView::~FmXFormView()
470 DBG_ASSERT( m_aPageWindowAdapters
.empty(), "FmXFormView::~FmXFormView: Window list not empty!" );
471 if ( !m_aPageWindowAdapters
.empty() )
473 for ( PageWindowAdapterList::const_iterator loop
= m_aPageWindowAdapters
.begin();
474 loop
!= m_aPageWindowAdapters
.end();
484 delete m_pWatchStoredList
;
485 m_pWatchStoredList
= NULL
;
490 void SAL_CALL
FmXFormView::disposing(const EventObject
& Source
) throw( RuntimeException
, std::exception
)
492 if ( m_xWindow
.is() && Source
.Source
== m_xWindow
)
493 removeGridWindowListening();
496 // XFormControllerListener
498 void SAL_CALL
FmXFormView::formActivated(const EventObject
& rEvent
) throw( RuntimeException
, std::exception
)
500 if ( m_pView
&& m_pView
->GetFormShell() && m_pView
->GetFormShell()->GetImpl() )
501 m_pView
->GetFormShell()->GetImpl()->formActivated( rEvent
);
505 void SAL_CALL
FmXFormView::formDeactivated(const EventObject
& rEvent
) throw( RuntimeException
, std::exception
)
507 if ( m_pView
&& m_pView
->GetFormShell() && m_pView
->GetFormShell()->GetImpl() )
508 m_pView
->GetFormShell()->GetImpl()->formDeactivated( rEvent
);
511 // XContainerListener
513 void SAL_CALL
FmXFormView::elementInserted(const ContainerEvent
& evt
) throw( RuntimeException
, std::exception
)
517 Reference
< XControlContainer
> xControlContainer( evt
.Source
, UNO_QUERY_THROW
);
518 Reference
< XControl
> xControl( evt
.Element
, UNO_QUERY_THROW
);
519 Reference
< XFormComponent
> xControlModel( xControl
->getModel(), UNO_QUERY_THROW
);
520 Reference
< XForm
> xForm( xControlModel
->getParent(), UNO_QUERY_THROW
);
522 if ( m_isTabOrderUpdateSuspended
)
524 // remember the container and the control, so we can update the tab order on resumeTabOrderUpdate
525 m_aNeedTabOrderUpdate
[ xControlContainer
].insert( xForm
);
529 PFormViewPageWindowAdapter pAdapter
= findWindow( xControlContainer
);
531 pAdapter
->updateTabOrder( xForm
);
534 catch (const Exception
&)
536 DBG_UNHANDLED_EXCEPTION();
541 void SAL_CALL
FmXFormView::elementReplaced(const ContainerEvent
& evt
) throw( RuntimeException
, std::exception
)
543 elementInserted(evt
);
547 void SAL_CALL
FmXFormView::elementRemoved(const ContainerEvent
& /*evt*/) throw( RuntimeException
, std::exception
)
552 PFormViewPageWindowAdapter
FmXFormView::findWindow( const Reference
< XControlContainer
>& _rxCC
) const
554 for ( PageWindowAdapterList::const_iterator i
= m_aPageWindowAdapters
.begin();
555 i
!= m_aPageWindowAdapters
.end();
559 if ( _rxCC
== (*i
)->getControlContainer() )
566 void FmXFormView::addWindow(const SdrPageWindow
& rWindow
)
568 FmFormPage
* pFormPage
= PTR_CAST( FmFormPage
, rWindow
.GetPageView().GetPage() );
572 Reference
< XControlContainer
> xCC
= rWindow
.GetControlContainer();
574 && ( !findWindow( xCC
).is() )
577 PFormViewPageWindowAdapter pAdapter
= new FormViewPageWindowAdapter( comphelper::getProcessComponentContext(), rWindow
, this );
578 m_aPageWindowAdapters
.push_back( pAdapter
);
580 // Am ControlContainer horchen um Aenderungen mitzbekommen
581 Reference
< XContainer
> xContainer( xCC
, UNO_QUERY
);
582 if ( xContainer
.is() )
583 xContainer
->addContainerListener( this );
588 void FmXFormView::removeWindow( const Reference
< XControlContainer
>& _rxCC
)
590 // Wird gerufen, wenn
591 // - in den Design-Modus geschaltet wird
592 // - ein Window geloescht wird, waehrend man im Design-Modus ist
593 // - der Control-Container fuer ein Window entfernt wird, waehrend
594 // der aktive Modus eingeschaltet ist.
596 for ( PageWindowAdapterList::iterator i
= m_aPageWindowAdapters
.begin();
597 i
!= m_aPageWindowAdapters
.end();
601 if ( _rxCC
!= (*i
)->getControlContainer() )
604 Reference
< XContainer
> xContainer( _rxCC
, UNO_QUERY
);
605 if ( xContainer
.is() )
606 xContainer
->removeContainerListener( this );
609 m_aPageWindowAdapters
.erase( i
);
615 void FmXFormView::displayAsyncErrorMessage( const SQLErrorEvent
& _rEvent
)
617 DBG_ASSERT( 0 == m_nErrorMessageEvent
, "FmXFormView::displayAsyncErrorMessage: not too fast, please!" );
618 // This should not happen - usually, the PostUserEvent is faster than any possible user
619 // interaction which could trigger a new error. If it happens, we need a queue for the events.
620 m_aAsyncError
= _rEvent
;
621 m_nErrorMessageEvent
= Application::PostUserEvent( LINK( this, FmXFormView
, OnDelayedErrorMessage
) );
625 IMPL_LINK(FmXFormView
, OnDelayedErrorMessage
, void*, /*EMPTYTAG*/)
627 m_nErrorMessageEvent
= 0;
628 displayException( m_aAsyncError
);
633 void FmXFormView::onFirstViewActivation( const FmFormModel
* _pDocModel
)
635 if ( _pDocModel
&& _pDocModel
->GetAutoControlFocus() )
636 m_nAutoFocusEvent
= Application::PostUserEvent( LINK( this, FmXFormView
, OnAutoFocus
) );
640 void FmXFormView::suspendTabOrderUpdate()
642 OSL_ENSURE( !m_isTabOrderUpdateSuspended
, "FmXFormView::suspendTabOrderUpdate: nesting not allowed!" );
643 m_isTabOrderUpdateSuspended
= true;
647 void FmXFormView::resumeTabOrderUpdate()
649 OSL_ENSURE( m_isTabOrderUpdateSuspended
, "FmXFormView::resumeTabOrderUpdate: not suspended!" );
650 m_isTabOrderUpdateSuspended
= false;
652 // update the tab orders for all components which were collected since the suspendTabOrderUpdate call.
653 for ( MapControlContainerToSetOfForms::const_iterator container
= m_aNeedTabOrderUpdate
.begin();
654 container
!= m_aNeedTabOrderUpdate
.end();
658 PFormViewPageWindowAdapter pAdapter
= findWindow( container
->first
);
659 if ( !pAdapter
.is() )
662 for ( SetOfForms::const_iterator form
= container
->second
.begin();
663 form
!= container
->second
.end();
667 pAdapter
->updateTabOrder( *form
);
670 m_aNeedTabOrderUpdate
.clear();
674 IMPL_LINK(FmXFormView
, OnActivate
, void*, /*EMPTYTAG*/)
676 m_nActivationEvent
= 0;
680 OSL_FAIL( "FmXFormView::OnActivate: well .... seems we have a timing problem (the view already died)!" );
684 // setting the controller to activate
685 if (m_pView
->GetFormShell() && m_pView
->GetActualOutDev() && m_pView
->GetActualOutDev()->GetOutDevType() == OUTDEV_WINDOW
)
687 Window
* pWindow
= const_cast<Window
*>(static_cast<const Window
*>(m_pView
->GetActualOutDev()));
688 PFormViewPageWindowAdapter pAdapter
= m_aPageWindowAdapters
.empty() ? NULL
: m_aPageWindowAdapters
[0];
689 for ( PageWindowAdapterList::const_iterator i
= m_aPageWindowAdapters
.begin();
690 i
!= m_aPageWindowAdapters
.end();
694 if ( pWindow
== (*i
)->getWindow() )
698 if ( pAdapter
.get() )
700 for ( ::std::vector
< Reference
< XFormController
> >::const_iterator i
= pAdapter
->GetList().begin();
701 i
!= pAdapter
->GetList().end();
705 const Reference
< XFormController
> & xController
= *i
;
706 if ( !xController
.is() )
709 // only database forms are to be activated
710 Reference
< XRowSet
> xForm(xController
->getModel(), UNO_QUERY
);
711 if ( !xForm
.is() || !OStaticDataAccessTools().getRowSetConnection( xForm
).is() )
714 Reference
< XPropertySet
> xFormSet( xForm
, UNO_QUERY
);
715 if ( !xFormSet
.is() )
717 SAL_WARN( "svx.form", "FmXFormView::OnActivate: a form which does not have properties?" );
721 const OUString aSource
= ::comphelper::getString( xFormSet
->getPropertyValue( FM_PROP_COMMAND
) );
722 if ( !aSource
.isEmpty() )
724 FmXFormShell
* pShImpl
= m_pView
->GetFormShell()->GetImpl();
726 pShImpl
->setActiveController( xController
);
736 void FmXFormView::Activate(bool bSync
)
738 if (m_nActivationEvent
)
740 Application::RemoveUserEvent(m_nActivationEvent
);
741 m_nActivationEvent
= 0;
746 LINK(this,FmXFormView
,OnActivate
).Call(NULL
);
749 m_nActivationEvent
= Application::PostUserEvent(LINK(this,FmXFormView
,OnActivate
));
753 void FmXFormView::Deactivate(bool bDeactivateController
)
755 if (m_nActivationEvent
)
757 Application::RemoveUserEvent(m_nActivationEvent
);
758 m_nActivationEvent
= 0;
761 FmXFormShell
* pShImpl
= m_pView
->GetFormShell() ? m_pView
->GetFormShell()->GetImpl() : NULL
;
762 if (pShImpl
&& bDeactivateController
)
763 pShImpl
->setActiveController( NULL
);
767 FmFormShell
* FmXFormView::GetFormShell() const
769 return m_pView
? m_pView
->GetFormShell() : NULL
;
772 void FmXFormView::AutoFocus( bool _bSync
)
774 if (m_nAutoFocusEvent
)
775 Application::RemoveUserEvent(m_nAutoFocusEvent
);
780 m_nAutoFocusEvent
= Application::PostUserEvent(LINK(this, FmXFormView
, OnAutoFocus
));
784 bool FmXFormView::isFocusable( const Reference
< XControl
>& i_rControl
)
786 if ( !i_rControl
.is() )
791 Reference
< XPropertySet
> xModelProps( i_rControl
->getModel(), UNO_QUERY_THROW
);
793 // only enabled controls are allowed to participate
794 bool bEnabled
= false;
795 OSL_VERIFY( xModelProps
->getPropertyValue( FM_PROP_ENABLED
) >>= bEnabled
);
799 // check the class id of the control model
800 sal_Int16 nClassId
= FormComponentType::CONTROL
;
801 OSL_VERIFY( xModelProps
->getPropertyValue( FM_PROP_CLASSID
) >>= nClassId
);
803 // controls which are not focussable
804 if ( ( FormComponentType::CONTROL
!= nClassId
)
805 && ( FormComponentType::IMAGEBUTTON
!= nClassId
)
806 && ( FormComponentType::GROUPBOX
!= nClassId
)
807 && ( FormComponentType::FIXEDTEXT
!= nClassId
)
808 && ( FormComponentType::HIDDENCONTROL
!= nClassId
)
809 && ( FormComponentType::IMAGECONTROL
!= nClassId
)
810 && ( FormComponentType::SCROLLBAR
!= nClassId
)
811 && ( FormComponentType::SPINBUTTON
!= nClassId
)
817 catch (const Exception
&)
819 DBG_UNHANDLED_EXCEPTION();
825 static Reference
< XControl
> lcl_firstFocussableControl( const Sequence
< Reference
< XControl
> >& _rControls
)
827 Reference
< XControl
> xReturn
;
829 // loop through all the controls
830 const Reference
< XControl
>* pControls
= _rControls
.getConstArray();
831 const Reference
< XControl
>* pControlsEnd
= _rControls
.getConstArray() + _rControls
.getLength();
832 for ( ; pControls
!= pControlsEnd
; ++pControls
)
834 if ( !pControls
->is() )
837 if ( FmXFormView::isFocusable( *pControls
) )
839 xReturn
= *pControls
;
844 if ( !xReturn
.is() && _rControls
.getLength() )
845 xReturn
= _rControls
[0];
854 void lcl_ensureControlsOfFormExist_nothrow( const SdrPage
& _rPage
, const SdrView
& _rView
, const Window
& _rWindow
, const Reference
< XForm
>& _rxForm
)
858 Reference
< XInterface
> xNormalizedForm( _rxForm
, UNO_QUERY_THROW
);
860 SdrObjListIter
aSdrObjectLoop( _rPage
, IM_DEEPNOGROUPS
);
861 while ( aSdrObjectLoop
.IsMore() )
863 FmFormObj
* pFormObject
= FmFormObj::GetFormObject( aSdrObjectLoop
.Next() );
867 Reference
< XChild
> xModel( pFormObject
->GetUnoControlModel(), UNO_QUERY_THROW
);
868 Reference
< XInterface
> xModelParent( xModel
->getParent(), UNO_QUERY_THROW
);
870 if ( xNormalizedForm
.get() != xModelParent
.get() )
873 pFormObject
->GetUnoControl( _rView
, _rWindow
);
876 catch (const Exception
&)
878 DBG_UNHANDLED_EXCEPTION();
884 Reference
< XFormController
> FmXFormView::getFormController( const Reference
< XForm
>& _rxForm
, const OutputDevice
& _rDevice
) const
886 Reference
< XFormController
> xController
;
888 for ( PageWindowAdapterList::const_iterator pos
= m_aPageWindowAdapters
.begin();
889 pos
!= m_aPageWindowAdapters
.end();
893 const PFormViewPageWindowAdapter
pAdapter( *pos
);
894 if ( !pAdapter
.get() )
896 SAL_WARN( "svx.form", "FmXFormView::getFormController: invalid page window adapter!" );
900 if ( pAdapter
->getWindow() != &_rDevice
)
904 xController
= pAdapter
->getController( _rxForm
);
905 if ( xController
.is() )
912 IMPL_LINK(FmXFormView
, OnAutoFocus
, void*, /*EMPTYTAG*/)
914 m_nAutoFocusEvent
= 0;
916 // go to the first form of our page, examine it's TabController, go to it's first (in terms of the tab order)
917 // control, give it the focus
922 SdrPageView
*pPageView
= m_pView
? m_pView
->GetSdrPageView() : NULL
;
923 SdrPage
*pSdrPage
= pPageView
? pPageView
->GetPage() : NULL
;
924 // get the forms collection of the page we belong to
925 FmFormPage
* pPage
= PTR_CAST( FmFormPage
, pSdrPage
);
926 Reference
< XIndexAccess
> xForms( pPage
? Reference
< XIndexAccess
>( pPage
->GetForms(), UNO_QUERY
) : Reference
< XIndexAccess
>() );
928 const PFormViewPageWindowAdapter pAdapter
= m_aPageWindowAdapters
.empty() ? NULL
: m_aPageWindowAdapters
[0];
929 const Window
* pWindow
= pAdapter
.get() ? pAdapter
->getWindow() : NULL
;
931 ENSURE_OR_RETURN( xForms
.is() && pWindow
, "FmXFormView::OnAutoFocus: could not collect all essentials!", 0L );
935 // go for the tab controller of the first form
936 if ( !xForms
->getCount() )
938 Reference
< XForm
> xForm( xForms
->getByIndex( 0 ), UNO_QUERY_THROW
);
939 Reference
< XTabController
> xTabController( pAdapter
->getController( xForm
), UNO_QUERY_THROW
);
941 // go for the first control of the controller
942 Sequence
< Reference
< XControl
> > aControls( xTabController
->getControls() );
943 if ( aControls
.getLength() == 0 )
945 Reference
< XElementAccess
> xFormElementAccess( xForm
, UNO_QUERY_THROW
);
946 if (xFormElementAccess
->hasElements() && pPage
&& m_pView
)
948 // there are control models in the form, but no controls, yet.
949 // Well, since some time controls are created on demand only. In particular,
950 // they're normally created when they're first painted.
951 // Unfortunately, the FormController does not have any way to
952 // trigger the creation itself, so we must hack this ...
953 lcl_ensureControlsOfFormExist_nothrow( *pPage
, *m_pView
, *pWindow
, xForm
);
954 aControls
= xTabController
->getControls();
955 OSL_ENSURE( aControls
.getLength(), "FmXFormView::OnAutoFocus: no controls at all!" );
959 // set the focus to this first control
960 Reference
< XWindow
> xControlWindow( lcl_firstFocussableControl( aControls
), UNO_QUERY
);
961 if ( !xControlWindow
.is() )
964 xControlWindow
->setFocus();
966 // ensure that the control is visible
967 // 80210 - 12/07/00 - FS
968 const Window
* pCurrentWindow
= dynamic_cast< const Window
* >( m_pView
->GetActualOutDev() );
969 if ( pCurrentWindow
)
971 awt::Rectangle aRect
= xControlWindow
->getPosSize();
972 ::Rectangle
aNonUnoRect( aRect
.X
, aRect
.Y
, aRect
.X
+ aRect
.Width
, aRect
.Y
+ aRect
.Height
);
973 m_pView
->MakeVisible( pCurrentWindow
->PixelToLogic( aNonUnoRect
), *const_cast< Window
* >( pCurrentWindow
) );
976 catch (const Exception
&)
978 DBG_UNHANDLED_EXCEPTION();
988 void FmXFormView::onCreatedFormObject( FmFormObj
& _rFormObject
)
990 FmFormShell
* pShell
= m_pView
? m_pView
->GetFormShell() : NULL
;
991 FmXFormShell
* pShellImpl
= pShell
? pShell
->GetImpl() : NULL
;
992 OSL_ENSURE( pShellImpl
, "FmXFormView::onCreatedFormObject: no form shell!" );
996 // it is valid that the form shell's forms collection is not initialized, yet
997 pShellImpl
->UpdateForms( true );
999 m_xLastCreatedControlModel
.set( _rFormObject
.GetUnoControlModel(), UNO_QUERY
);
1000 if ( !m_xLastCreatedControlModel
.is() )
1003 // some initial property defaults
1004 FormControlFactory aControlFactory
;
1005 aControlFactory
.initializeControlModel( pShellImpl
->getDocumentType(), _rFormObject
);
1007 if ( !pShellImpl
->GetWizardUsing() )
1010 // #i31958# don't call wizards in XForms mode
1011 if ( pShellImpl
->isEnhancedForm() )
1014 // #i46898# no wizards if there is no Base installed - currently, all wizards are
1016 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE
) )
1019 if ( m_nControlWizardEvent
)
1020 Application::RemoveUserEvent( m_nControlWizardEvent
);
1021 m_nControlWizardEvent
= Application::PostUserEvent( LINK( this, FmXFormView
, OnStartControlWizard
) );
1025 IMPL_LINK( FmXFormView
, OnStartControlWizard
, void*, /**/ )
1027 m_nControlWizardEvent
= 0;
1028 OSL_PRECOND( m_xLastCreatedControlModel
.is(), "FmXFormView::OnStartControlWizard: illegal call!" );
1029 if ( !m_xLastCreatedControlModel
.is() )
1032 sal_Int16 nClassId
= FormComponentType::CONTROL
;
1035 OSL_VERIFY( m_xLastCreatedControlModel
->getPropertyValue( FM_PROP_CLASSID
) >>= nClassId
);
1037 catch (const Exception
&)
1039 DBG_UNHANDLED_EXCEPTION();
1042 const sal_Char
* pWizardAsciiName
= NULL
;
1045 case FormComponentType::GRIDCONTROL
:
1046 pWizardAsciiName
= "com.sun.star.sdb.GridControlAutoPilot";
1048 case FormComponentType::LISTBOX
:
1049 case FormComponentType::COMBOBOX
:
1050 pWizardAsciiName
= "com.sun.star.sdb.ListComboBoxAutoPilot";
1052 case FormComponentType::GROUPBOX
:
1053 pWizardAsciiName
= "com.sun.star.sdb.GroupBoxAutoPilot";
1057 if ( pWizardAsciiName
)
1059 // build the argument list
1060 ::comphelper::NamedValueCollection aWizardArgs
;
1061 aWizardArgs
.put( "ObjectModel", m_xLastCreatedControlModel
);
1063 // create the wizard object
1064 Reference
< XExecutableDialog
> xWizard
;
1067 Reference
<XComponentContext
> xContext
= comphelper::getProcessComponentContext();
1068 xWizard
.set( xContext
->getServiceManager()->createInstanceWithArgumentsAndContext( OUString::createFromAscii(pWizardAsciiName
), aWizardArgs
.getWrappedPropertyValues(), xContext
), UNO_QUERY
);;
1070 catch (const Exception
&)
1072 DBG_UNHANDLED_EXCEPTION();
1075 if ( !xWizard
.is() )
1077 ShowServiceNotAvailableError( NULL
, OUString::createFromAscii(pWizardAsciiName
), true );
1081 // execute the wizard
1086 catch (const Exception
&)
1088 DBG_UNHANDLED_EXCEPTION();
1093 m_xLastCreatedControlModel
.clear();
1100 void lcl_insertIntoFormComponentHierarchy_throw( const FmFormView
& _rView
, const SdrUnoObj
& _rSdrObj
,
1101 const Reference
< XDataSource
>& _rxDataSource
= NULL
, const OUString
& _rDataSourceName
= OUString(),
1102 const OUString
& _rCommand
= OUString(), const sal_Int32 _nCommandType
= -1 )
1104 FmFormPage
& rPage
= static_cast< FmFormPage
& >( *_rView
.GetSdrPageView()->GetPage() );
1106 Reference
< XFormComponent
> xFormComponent( _rSdrObj
.GetUnoControlModel(), UNO_QUERY_THROW
);
1107 Reference
< XForm
> xTargetForm(
1108 rPage
.GetImpl().findPlaceInFormComponentHierarchy( xFormComponent
, _rxDataSource
, _rDataSourceName
, _rCommand
, _nCommandType
),
1111 rPage
.GetImpl().setUniqueName( xFormComponent
, xTargetForm
);
1113 Reference
< XIndexContainer
> xFormAsContainer( xTargetForm
, UNO_QUERY_THROW
);
1114 xFormAsContainer
->insertByIndex( xFormAsContainer
->getCount(), makeAny( xFormComponent
) );
1119 SdrObject
* FmXFormView::implCreateFieldControl( const ::svx::ODataAccessDescriptor
& _rColumnDescriptor
)
1121 // not if we're in design mode
1122 if ( !m_pView
->IsDesignMode() )
1125 OUString sCommand
, sFieldName
;
1126 sal_Int32 nCommandType
= CommandType::COMMAND
;
1127 SharedConnection xConnection
;
1129 OUString sDataSource
= _rColumnDescriptor
.getDataSource();
1130 _rColumnDescriptor
[ daCommand
] >>= sCommand
;
1131 _rColumnDescriptor
[ daColumnName
] >>= sFieldName
;
1132 _rColumnDescriptor
[ daCommandType
] >>= nCommandType
;
1134 Reference
< XConnection
> xExternalConnection
;
1135 _rColumnDescriptor
[ daConnection
] >>= xExternalConnection
;
1136 xConnection
.reset( xExternalConnection
, SharedConnection::NoTakeOwnership
);
1139 if ( sCommand
.isEmpty()
1140 || sFieldName
.isEmpty()
1141 || ( sDataSource
.isEmpty()
1142 && !xConnection
.is()
1146 OSL_FAIL( "FmXFormView::implCreateFieldControl: nonsense!" );
1149 Reference
< XDataSource
> xDataSource
;
1150 SQLErrorEvent aError
;
1153 if ( xConnection
.is() && !xDataSource
.is() && sDataSource
.isEmpty() )
1155 Reference
< XChild
> xChild( xConnection
, UNO_QUERY
);
1157 xDataSource
= xDataSource
.query( xChild
->getParent() );
1160 // obtain the data source
1161 if ( !xDataSource
.is() )
1162 xDataSource
= OStaticDataAccessTools().getDataSource( sDataSource
, comphelper::getProcessComponentContext() );
1164 // and the connection, if necessary
1165 if ( !xConnection
.is() )
1166 xConnection
.reset( OStaticDataAccessTools().getConnection_withFeedback(
1170 comphelper::getProcessComponentContext()
1173 catch (const SQLException
&)
1175 aError
.Reason
= ::cppu::getCaughtException();
1177 catch (const Exception
& )
1179 /* will be asserted below */
1181 if (aError
.Reason
.hasValue())
1183 displayAsyncErrorMessage( aError
);
1187 // need a data source and a connection here
1188 if (!xDataSource
.is() || !xConnection
.is())
1190 OSL_FAIL("FmXFormView::implCreateFieldControl : could not retrieve the data source or the connection!");
1194 OStaticDataAccessTools aDBATools
;
1195 Reference
< XComponent
> xKeepFieldsAlive
;
1199 // determine the table/query field which we should create a control for
1200 Reference
< XPropertySet
> xField
;
1202 Reference
< XNameAccess
> xFields
= aDBATools
.getFieldsByCommandDescriptor(
1203 xConnection
, nCommandType
, sCommand
, xKeepFieldsAlive
);
1205 if (xFields
.is() && xFields
->hasByName(sFieldName
))
1206 xFields
->getByName(sFieldName
) >>= xField
;
1210 Reference
< XNumberFormatsSupplier
> xSupplier( aDBATools
.getNumberFormats( xConnection
, false ), UNO_SET_THROW
);
1211 Reference
< XNumberFormats
> xNumberFormats( xSupplier
->getNumberFormats(), UNO_SET_THROW
);
1213 OUString sLabelPostfix
;
1216 // nur fuer Textgroesse
1217 OutputDevice
* pOutDev
= NULL
;
1218 if (m_pView
->GetActualOutDev() && m_pView
->GetActualOutDev()->GetOutDevType() == OUTDEV_WINDOW
)
1219 pOutDev
= const_cast<OutputDevice
*>(m_pView
->GetActualOutDev());
1222 SdrPageView
* pPageView
= m_pView
->GetSdrPageView();
1223 if( pPageView
&& !pOutDev
)
1225 // const SdrPageViewWinList& rWinList = pPageView->GetWinList();
1226 // const SdrPageViewWindows& rPageViewWindows = pPageView->GetPageViewWindows();
1228 for( sal_uInt32 i
= 0L; i
< pPageView
->PageWindowCount(); i
++ )
1230 const SdrPageWindow
& rPageWindow
= *pPageView
->GetPageWindow(i
);
1232 if( rPageWindow
.GetPaintWindow().OutputToWindow())
1234 pOutDev
= &rPageWindow
.GetPaintWindow().GetOutputDevice();
1244 sal_Int32 nDataType
= ::comphelper::getINT32(xField
->getPropertyValue(FM_PROP_FIELDTYPE
));
1245 if ((DataType::BINARY
== nDataType
) || (DataType::VARBINARY
== nDataType
))
1249 // determine the control type by examining the data type of the bound column
1250 sal_uInt16 nOBJID
= 0;
1251 bool bDateNTimeField
= false;
1253 bool bIsCurrency
= false;
1254 if (::comphelper::hasProperty(FM_PROP_ISCURRENCY
, xField
))
1255 bIsCurrency
= ::comphelper::getBOOL(xField
->getPropertyValue(FM_PROP_ISCURRENCY
));
1258 nOBJID
= OBJ_FM_CURRENCYFIELD
;
1262 case DataType::BLOB
:
1263 case DataType::LONGVARBINARY
:
1264 nOBJID
= OBJ_FM_IMAGECONTROL
;
1266 case DataType::LONGVARCHAR
:
1267 case DataType::CLOB
:
1268 nOBJID
= OBJ_FM_EDIT
;
1270 case DataType::BINARY
:
1271 case DataType::VARBINARY
:
1274 case DataType::BOOLEAN
:
1275 nOBJID
= OBJ_FM_CHECKBOX
;
1277 case DataType::TINYINT
:
1278 case DataType::SMALLINT
:
1279 case DataType::INTEGER
:
1280 nOBJID
= OBJ_FM_NUMERICFIELD
;
1282 case DataType::REAL
:
1283 case DataType::DOUBLE
:
1284 case DataType::NUMERIC
:
1285 case DataType::DECIMAL
:
1286 nOBJID
= OBJ_FM_FORMATTEDFIELD
;
1288 case DataType::TIMESTAMP
:
1289 bDateNTimeField
= true;
1290 sLabelPostfix
= SVX_RESSTR(RID_STR_POSTFIX_DATE
);
1292 case DataType::DATE
:
1293 nOBJID
= OBJ_FM_DATEFIELD
;
1295 case DataType::TIME
:
1296 nOBJID
= OBJ_FM_TIMEFIELD
;
1298 case DataType::CHAR
:
1299 case DataType::VARCHAR
:
1301 nOBJID
= OBJ_FM_EDIT
;
1307 SdrUnoObj
* pLabel( NULL
);
1308 SdrUnoObj
* pControl( NULL
);
1309 if ( !createControlLabelPair( *pOutDev
, 0, 0, xField
, xNumberFormats
, nOBJID
, sLabelPostfix
,
1310 pLabel
, pControl
, xDataSource
, sDataSource
, sCommand
, nCommandType
)
1318 bool bCheckbox
= ( OBJ_FM_CHECKBOX
== nOBJID
);
1319 OSL_ENSURE( !bCheckbox
|| !pLabel
, "FmXFormView::implCreateFieldControl: why was there a label created for a check box?" );
1323 SdrObjGroup
* pGroup
= new SdrObjGroup();
1324 SdrObjList
* pObjList
= pGroup
->GetSubList();
1325 pObjList
->InsertObject( pLabel
);
1326 pObjList
->InsertObject( pControl
);
1328 if ( bDateNTimeField
)
1329 { // so far we created a date field only, but we also need a time field
1330 pLabel
= pControl
= NULL
;
1331 if ( createControlLabelPair( *pOutDev
, 0, 1000, xField
, xNumberFormats
, OBJ_FM_TIMEFIELD
,
1332 SVX_RESSTR(RID_STR_POSTFIX_TIME
), pLabel
, pControl
,
1333 xDataSource
, sDataSource
, sCommand
, nCommandType
)
1336 pObjList
->InsertObject( pLabel
);
1337 pObjList
->InsertObject( pControl
);
1341 return pGroup
; // und fertig
1343 catch (const Exception
&)
1345 DBG_UNHANDLED_EXCEPTION();
1353 SdrObject
* FmXFormView::implCreateXFormsControl( const ::svx::OXFormsDescriptor
&_rDesc
)
1355 // not if we're in design mode
1356 if ( !m_pView
->IsDesignMode() )
1359 Reference
< XComponent
> xKeepFieldsAlive
;
1364 // determine the table/query field which we should create a control for
1365 Reference
< XNumberFormats
> xNumberFormats
;
1366 OUString sLabelPostfix
= _rDesc
.szName
;
1369 // nur fuer Textgroesse
1370 OutputDevice
* pOutDev
= NULL
;
1371 if (m_pView
->GetActualOutDev() && m_pView
->GetActualOutDev()->GetOutDevType() == OUTDEV_WINDOW
)
1372 pOutDev
= const_cast<OutputDevice
*>(m_pView
->GetActualOutDev());
1375 SdrPageView
* pPageView
= m_pView
->GetSdrPageView();
1376 if( pPageView
&& !pOutDev
)
1378 // const SdrPageViewWinList& rWinList = pPageView->GetWinList();
1379 // const SdrPageViewWindows& rPageViewWindows = pPageView->GetPageViewWindows();
1381 for( sal_uInt32 i
= 0L; i
< pPageView
->PageWindowCount(); i
++ )
1383 const SdrPageWindow
& rPageWindow
= *pPageView
->GetPageWindow(i
);
1385 if( rPageWindow
.GetPaintWindow().GetOutputDevice().GetOutDevType() == OUTDEV_WINDOW
)
1387 pOutDev
= &rPageWindow
.GetPaintWindow().GetOutputDevice();
1398 // The service name decides which control should be created
1399 sal_uInt16 nOBJID
= OBJ_FM_EDIT
;
1400 if(OUString(_rDesc
.szServiceName
).equals((OUString
)FM_SUN_COMPONENT_NUMERICFIELD
))
1401 nOBJID
= OBJ_FM_NUMERICFIELD
;
1402 if(OUString(_rDesc
.szServiceName
).equals((OUString
)FM_SUN_COMPONENT_CHECKBOX
))
1403 nOBJID
= OBJ_FM_CHECKBOX
;
1404 if(OUString(_rDesc
.szServiceName
).equals((OUString
)FM_COMPONENT_COMMANDBUTTON
))
1405 nOBJID
= OBJ_FM_BUTTON
;
1407 typedef ::com::sun::star::form::submission::XSubmission XSubmission_t
;
1408 Reference
< XSubmission_t
> xSubmission(_rDesc
.xPropSet
, UNO_QUERY
);
1410 // xform control or submission button?
1411 if ( !xSubmission
.is() )
1413 SdrUnoObj
* pLabel( NULL
);
1414 SdrUnoObj
* pControl( NULL
);
1415 if ( !createControlLabelPair( *pOutDev
, 0, 0, NULL
, xNumberFormats
, nOBJID
, sLabelPostfix
,
1423 // Now build the connection between the control and the data item.
1424 Reference
< XValueBinding
> xValueBinding(_rDesc
.xPropSet
,UNO_QUERY
);
1425 Reference
< XBindableValue
> xBindableValue(pControl
->GetUnoControlModel(),UNO_QUERY
);
1427 DBG_ASSERT( xBindableValue
.is(), "FmXFormView::implCreateXFormsControl: control's not bindable!" );
1428 if ( xBindableValue
.is() )
1429 xBindableValue
->setValueBinding(xValueBinding
);
1431 bool bCheckbox
= ( OBJ_FM_CHECKBOX
== nOBJID
);
1432 OSL_ENSURE( !bCheckbox
|| !pLabel
, "FmXFormView::implCreateXFormsControl: why was there a label created for a check box?" );
1438 SdrObjGroup
* pGroup
= new SdrObjGroup();
1439 SdrObjList
* pObjList
= pGroup
->GetSubList();
1440 pObjList
->InsertObject(pLabel
);
1441 pObjList
->InsertObject(pControl
);
1447 // create a button control
1448 const MapMode
eTargetMode( pOutDev
->GetMapMode() );
1449 const MapMode
eSourceMode(MAP_100TH_MM
);
1450 const sal_uInt16 nObjID
= OBJ_FM_BUTTON
;
1451 ::Size
controlSize(4000, 500);
1452 FmFormObj
*pControl
= static_cast<FmFormObj
*>(SdrObjFactory::MakeNewObject( FmFormInventor
, nObjID
, NULL
, NULL
));
1453 controlSize
.Width() = Fraction(controlSize
.Width(), 1) * eTargetMode
.GetScaleX();
1454 controlSize
.Height() = Fraction(controlSize
.Height(), 1) * eTargetMode
.GetScaleY();
1455 ::Point
controlPos( pOutDev
->LogicToLogic( ::Point( controlSize
.Width(), 0 ), eSourceMode
, eTargetMode
) );
1456 ::Rectangle
controlRect( controlPos
, pOutDev
->LogicToLogic( controlSize
, eSourceMode
, eTargetMode
) );
1457 pControl
->SetLogicRect(controlRect
);
1459 // set the button label
1460 Reference
< XPropertySet
> xControlSet(pControl
->GetUnoControlModel(), UNO_QUERY
);
1461 xControlSet
->setPropertyValue(FM_PROP_LABEL
, makeAny(OUString(_rDesc
.szName
)));
1463 // connect the submission with the submission supplier (aka the button)
1464 xControlSet
->setPropertyValue( FM_PROP_BUTTON_TYPE
,
1465 makeAny( FormButtonType_SUBMIT
) );
1466 typedef ::com::sun::star::form::submission::XSubmissionSupplier XSubmissionSupplier_t
;
1467 Reference
< XSubmissionSupplier_t
> xSubmissionSupplier(pControl
->GetUnoControlModel(), UNO_QUERY
);
1468 xSubmissionSupplier
->setSubmission(xSubmission
);
1473 catch (const Exception
&)
1475 OSL_FAIL("FmXFormView::implCreateXFormsControl: caught an exception while creating the control !");
1483 bool FmXFormView::createControlLabelPair( OutputDevice
& _rOutDev
, sal_Int32 _nXOffsetMM
, sal_Int32 _nYOffsetMM
,
1484 const Reference
< XPropertySet
>& _rxField
, const Reference
< XNumberFormats
>& _rxNumberFormats
,
1485 sal_uInt16 _nControlObjectID
, const OUString
& _rFieldPostfix
,
1486 SdrUnoObj
*& _rpLabel
, SdrUnoObj
*& _rpControl
,
1487 const Reference
< XDataSource
>& _rxDataSource
, const OUString
& _rDataSourceName
,
1488 const OUString
& _rCommand
, const sal_Int32 _nCommandType
)
1490 if ( !createControlLabelPair( _rOutDev
, _nXOffsetMM
, _nYOffsetMM
,
1491 _rxField
, _rxNumberFormats
, _nControlObjectID
, _rFieldPostfix
, FmFormInventor
, OBJ_FM_FIXEDTEXT
,
1492 NULL
, NULL
, NULL
, _rpLabel
, _rpControl
)
1496 // insert the control model(s) into the form component hierarchy
1498 lcl_insertIntoFormComponentHierarchy_throw( *m_pView
, *_rpLabel
, _rxDataSource
, _rDataSourceName
, _rCommand
, _nCommandType
);
1499 lcl_insertIntoFormComponentHierarchy_throw( *m_pView
, *_rpControl
, _rxDataSource
, _rDataSourceName
, _rCommand
, _nCommandType
);
1501 // some context-dependent initializations
1502 FormControlFactory aControlFactory
;
1504 aControlFactory
.initializeControlModel( impl_getDocumentType(), *_rpLabel
);
1505 aControlFactory
.initializeControlModel( impl_getDocumentType(), *_rpControl
);
1511 bool FmXFormView::createControlLabelPair( OutputDevice
& _rOutDev
, sal_Int32 _nXOffsetMM
, sal_Int32 _nYOffsetMM
,
1512 const Reference
< XPropertySet
>& _rxField
,
1513 const Reference
< XNumberFormats
>& _rxNumberFormats
, sal_uInt16 _nControlObjectID
,
1514 const OUString
& _rFieldPostfix
, sal_uInt32 _nInventor
, sal_uInt16 _nLabelObjectID
,
1515 SdrPage
* _pLabelPage
, SdrPage
* _pControlPage
, SdrModel
* _pModel
, SdrUnoObj
*& _rpLabel
, SdrUnoObj
*& _rpControl
)
1517 sal_Int32 nDataType
= 0;
1518 OUString sFieldName
;
1520 if ( _rxField
.is() )
1522 nDataType
= ::comphelper::getINT32(_rxField
->getPropertyValue(FM_PROP_FIELDTYPE
));
1523 aFieldName
= Any(_rxField
->getPropertyValue(FM_PROP_NAME
));
1524 aFieldName
>>= sFieldName
;
1527 // calculate the positions, respecting the settings of the target device
1528 ::Size
aTextSize( _rOutDev
.GetTextWidth(sFieldName
+ _rFieldPostfix
), _rOutDev
.GetTextHeight() );
1530 MapMode
eTargetMode( _rOutDev
.GetMapMode() ),
1531 eSourceMode( MAP_100TH_MM
);
1533 // Textbreite ist mindestens 4cm
1534 // Texthoehe immer halber cm
1535 ::Size
aDefTxtSize(4000, 500);
1536 ::Size
aDefSize(4000, 500);
1537 ::Size
aDefImageSize(4000, 4000);
1539 ::Size aRealSize
= _rOutDev
.LogicToLogic(aTextSize
, eTargetMode
, eSourceMode
);
1540 aRealSize
.Width() = std::max(aRealSize
.Width(), aDefTxtSize
.Width());
1541 aRealSize
.Height()= aDefSize
.Height();
1543 // adjust to scaling of the target device (#53523#)
1544 aRealSize
.Width() = long(Fraction(aRealSize
.Width(), 1) * eTargetMode
.GetScaleX());
1545 aRealSize
.Height() = long(Fraction(aRealSize
.Height(), 1) * eTargetMode
.GetScaleY());
1547 // for boolean fields, we do not create a label, but just a checkbox
1548 bool bNeedLabel
= ( _nControlObjectID
!= OBJ_FM_CHECKBOX
);
1551 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1552 ::std::auto_ptr
< SdrUnoObj
> pLabel
;
1553 SAL_WNODEPRECATED_DECLARATIONS_POP
1554 Reference
< XPropertySet
> xLabelModel
;
1557 pLabel
.reset( dynamic_cast< SdrUnoObj
* >(
1558 SdrObjFactory::MakeNewObject( _nInventor
, _nLabelObjectID
, _pLabelPage
, _pModel
) ) );
1559 OSL_ENSURE( pLabel
.get(), "FmXFormView::createControlLabelPair: could not create the label!" );
1560 if ( !pLabel
.get() )
1563 xLabelModel
.set( pLabel
->GetUnoControlModel(), UNO_QUERY
);
1564 if ( xLabelModel
.is() )
1567 if ( _rxField
.is() && _rxField
->getPropertySetInfo()->hasPropertyByName(FM_PROP_LABEL
) )
1568 _rxField
->getPropertyValue(FM_PROP_LABEL
) >>= sLabel
;
1569 if ( sLabel
.isEmpty() )
1570 sLabel
= sFieldName
;
1572 xLabelModel
->setPropertyValue( FM_PROP_LABEL
, makeAny( sLabel
+ _rFieldPostfix
) );
1573 OUString
sObjectLabel(SVX_RESSTR(RID_STR_OBJECT_LABEL
).replaceAll("#object#", sFieldName
));
1574 xLabelModel
->setPropertyValue(FM_PROP_NAME
, makeAny(sObjectLabel
));
1577 pLabel
->SetLogicRect( ::Rectangle(
1578 _rOutDev
.LogicToLogic( ::Point( _nXOffsetMM
, _nYOffsetMM
), eSourceMode
, eTargetMode
),
1579 _rOutDev
.LogicToLogic( aRealSize
, eSourceMode
, eTargetMode
)
1584 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1585 ::std::auto_ptr
< SdrUnoObj
> pControl( dynamic_cast< SdrUnoObj
* >(
1586 SdrObjFactory::MakeNewObject( _nInventor
, _nControlObjectID
, _pControlPage
, _pModel
) ) );
1587 SAL_WNODEPRECATED_DECLARATIONS_POP
1588 OSL_ENSURE( pControl
.get(), "FmXFormView::createControlLabelPair: could not create the control!" );
1589 if ( !pControl
.get() )
1592 Reference
< XPropertySet
> xControlSet( pControl
->GetUnoControlModel(), UNO_QUERY
);
1593 if ( !xControlSet
.is() )
1596 // size of the control
1597 ::Size
aControlSize( aDefSize
);
1598 switch ( nDataType
)
1601 case DataType::BOOLEAN
:
1602 aControlSize
= aDefSize
;
1604 case DataType::LONGVARCHAR
:
1605 case DataType::CLOB
:
1606 case DataType::LONGVARBINARY
:
1607 case DataType::BLOB
:
1608 aControlSize
= aDefImageSize
;
1612 if ( OBJ_FM_IMAGECONTROL
== _nControlObjectID
)
1613 aControlSize
= aDefImageSize
;
1615 aControlSize
.Width() = long(Fraction(aControlSize
.Width(), 1) * eTargetMode
.GetScaleX());
1616 aControlSize
.Height() = long(Fraction(aControlSize
.Height(), 1) * eTargetMode
.GetScaleY());
1618 pControl
->SetLogicRect( ::Rectangle(
1619 _rOutDev
.LogicToLogic( ::Point( aRealSize
.Width() + _nXOffsetMM
, _nYOffsetMM
), eSourceMode
, eTargetMode
),
1620 _rOutDev
.LogicToLogic( aControlSize
, eSourceMode
, eTargetMode
)
1623 // some initializations
1624 Reference
< XPropertySetInfo
> xControlPropInfo
= xControlSet
->getPropertySetInfo();
1626 if ( aFieldName
.hasValue() )
1628 xControlSet
->setPropertyValue( FM_PROP_CONTROLSOURCE
, aFieldName
);
1629 xControlSet
->setPropertyValue( FM_PROP_NAME
, aFieldName
);
1632 // no dedicated label control => use the label property
1633 if ( xControlPropInfo
->hasPropertyByName( FM_PROP_LABEL
) )
1634 xControlSet
->setPropertyValue( FM_PROP_LABEL
, makeAny( sFieldName
+ _rFieldPostfix
) );
1636 OSL_FAIL( "FmXFormView::createControlLabelPair: can't set a label for the control!" );
1640 if ( (nDataType
== DataType::LONGVARCHAR
|| nDataType
== DataType::CLOB
) && xControlPropInfo
->hasPropertyByName( FM_PROP_MULTILINE
) )
1642 xControlSet
->setPropertyValue( FM_PROP_MULTILINE
, makeAny( true ) );
1645 // announce the label to the control
1646 if ( xControlPropInfo
->hasPropertyByName( FM_PROP_CONTROLLABEL
) && xLabelModel
.is() )
1650 xControlSet
->setPropertyValue( FM_PROP_CONTROLLABEL
, makeAny( xLabelModel
) );
1652 catch (const Exception
&)
1654 DBG_UNHANDLED_EXCEPTION();
1658 if ( _rxField
.is() )
1660 FormControlFactory aControlFactory
;
1661 aControlFactory
.initializeFieldDependentProperties( _rxField
, xControlSet
, _rxNumberFormats
);
1664 _rpLabel
= pLabel
.release();
1665 _rpControl
= pControl
.release();
1670 FmXFormView::ObjectRemoveListener::ObjectRemoveListener( FmXFormView
* pParent
)
1671 :m_pParent( pParent
)
1676 void FmXFormView::ObjectRemoveListener::Notify( SfxBroadcaster
& /*rBC*/, const SfxHint
& rHint
)
1678 if (rHint
.ISA(SdrHint
) && (((SdrHint
&)rHint
).GetKind() == HINT_OBJREMOVED
))
1679 m_pParent
->ObjectRemovedInAliveMode(((SdrHint
&)rHint
).GetObject());
1683 void FmXFormView::ObjectRemovedInAliveMode( const SdrObject
* pObject
)
1685 // wenn das entfernte Objekt in meiner MarkList, die ich mir beim Umschalten in den Alive-Mode gemerkt habe, steht,
1686 // muss ich es jetzt da rausnehmen, da ich sonst beim Zurueckschalten versuche, die Markierung wieder zu setzen
1687 // (interesanterweise geht das nur bei gruppierten Objekten schief (beim Zugriff auf deren ObjList GPF), nicht bei einzelnen)
1689 sal_uIntPtr nCount
= m_aMark
.GetMarkCount();
1690 for (sal_uIntPtr i
= 0; i
< nCount
; ++i
)
1692 SdrMark
* pMark
= m_aMark
.GetMark(i
);
1693 SdrObject
* pCurrent
= pMark
->GetMarkedSdrObj();
1694 if (pObject
== pCurrent
)
1696 m_aMark
.DeleteMark(i
);
1699 // ich brauche nicht in GroupObjects absteigen : wenn dort unten ein Objekt geloescht wird, dann bleibt der
1700 // Zeiger auf das GroupObject, den ich habe, trotzdem weiter gueltig bleibt ...
1705 void FmXFormView::stopMarkListWatching()
1707 if ( m_pWatchStoredList
)
1709 m_pWatchStoredList
->EndListeningAll();
1710 delete m_pWatchStoredList
;
1711 m_pWatchStoredList
= NULL
;
1716 void FmXFormView::startMarkListWatching()
1718 if ( !m_pWatchStoredList
)
1720 FmFormModel
* pModel
= GetFormShell() ? GetFormShell()->GetFormModel() : NULL
;
1721 DBG_ASSERT( pModel
!= NULL
, "FmXFormView::startMarkListWatching: shell has no model!" );
1724 m_pWatchStoredList
= new ObjectRemoveListener( this );
1725 m_pWatchStoredList
->StartListening( *static_cast< SfxBroadcaster
* >( pModel
) );
1730 OSL_FAIL( "FmXFormView::startMarkListWatching: already listening!" );
1735 void FmXFormView::saveMarkList( bool _bSmartUnmark
)
1739 m_aMark
= m_pView
->GetMarkedObjectList();
1740 if ( _bSmartUnmark
)
1742 sal_uIntPtr nCount
= m_aMark
.GetMarkCount( );
1743 for ( sal_uIntPtr i
= 0; i
< nCount
; ++i
)
1745 SdrMark
* pMark
= m_aMark
.GetMark(i
);
1746 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
1748 if ( m_pView
->IsObjMarked( pObj
) )
1750 if ( pObj
->IsGroupObject() )
1752 SdrObjListIter
aIter( *pObj
->GetSubList() );
1753 bool bMixed
= false;
1754 while ( aIter
.IsMore() && !bMixed
)
1755 bMixed
= ( aIter
.Next()->GetObjInventor() != FmFormInventor
);
1759 // all objects in the group are form objects
1760 m_pView
->MarkObj( pMark
->GetMarkedSdrObj(), pMark
->GetPageView(), true /* unmark! */ );
1765 if ( pObj
->GetObjInventor() == FmFormInventor
)
1766 { // this is a form layer object
1767 m_pView
->MarkObj( pMark
->GetMarkedSdrObj(), pMark
->GetPageView(), true /* unmark! */ );
1776 OSL_FAIL( "FmXFormView::saveMarkList: invalid view!" );
1777 m_aMark
= SdrMarkList();
1782 static bool lcl_hasObject( SdrObjListIter
& rIter
, SdrObject
* pObj
)
1784 bool bFound
= false;
1785 while (rIter
.IsMore() && !bFound
)
1786 bFound
= pObj
== rIter
.Next();
1793 void FmXFormView::restoreMarkList( SdrMarkList
& _rRestoredMarkList
)
1798 _rRestoredMarkList
.Clear();
1800 const SdrMarkList
& rCurrentList
= m_pView
->GetMarkedObjectList();
1801 FmFormPage
* pPage
= GetFormShell() ? GetFormShell()->GetCurPage() : NULL
;
1804 if (rCurrentList
.GetMarkCount())
1805 { // there is a current mark ... hmm. Is it a subset of the mark we remembered in saveMarkList?
1806 bool bMisMatch
= false;
1808 // loop through all current marks
1809 sal_uIntPtr nCurrentCount
= rCurrentList
.GetMarkCount();
1810 for ( sal_uIntPtr i
=0; i
<nCurrentCount
&& !bMisMatch
; ++i
)
1812 const SdrObject
* pCurrentMarked
= rCurrentList
.GetMark( i
)->GetMarkedSdrObj();
1814 // loop through all saved marks, check for equality
1815 bool bFound
= false;
1816 sal_uIntPtr nSavedCount
= m_aMark
.GetMarkCount();
1817 for ( sal_uIntPtr j
=0; j
<nSavedCount
&& !bFound
; ++j
)
1819 if ( m_aMark
.GetMark( j
)->GetMarkedSdrObj() == pCurrentMarked
)
1823 // did not find a current mark in the saved marks
1831 _rRestoredMarkList
= rCurrentList
;
1835 // wichtig ist das auf die Objecte der markliste nicht zugegriffen wird
1836 // da diese bereits zerstoert sein koennen
1837 SdrPageView
* pCurPageView
= m_pView
->GetSdrPageView();
1838 SdrObjListIter
aPageIter( *pPage
);
1841 // gibt es noch alle Objecte
1842 sal_uIntPtr nCount
= m_aMark
.GetMarkCount();
1843 for (sal_uIntPtr i
= 0; i
< nCount
&& bFound
; i
++)
1845 SdrMark
* pMark
= m_aMark
.GetMark(i
);
1846 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
1847 if (pObj
->IsGroupObject())
1849 SdrObjListIter
aIter(*pObj
->GetSubList());
1850 while (aIter
.IsMore() && bFound
)
1851 bFound
= lcl_hasObject(aPageIter
, aIter
.Next());
1854 bFound
= lcl_hasObject(aPageIter
, pObj
);
1856 bFound
= bFound
&& pCurPageView
== pMark
->GetPageView();
1861 // Das LastObject auswerten
1862 if (nCount
) // Objecte jetzt Markieren
1864 for (sal_uIntPtr i
= 0; i
< nCount
; i
++)
1866 SdrMark
* pMark
= m_aMark
.GetMark(i
);
1867 SdrObject
* pObj
= pMark
->GetMarkedSdrObj();
1868 if ( pObj
->GetObjInventor() == FmFormInventor
)
1869 if ( !m_pView
->IsObjMarked( pObj
) )
1870 m_pView
->MarkObj( pObj
, pMark
->GetPageView() );
1873 _rRestoredMarkList
= m_aMark
;
1880 void SAL_CALL
FmXFormView::focusGained( const FocusEvent
& /*e*/ ) throw (RuntimeException
, std::exception
)
1882 if ( m_xWindow
.is() && m_pView
)
1884 m_pView
->SetMoveOutside( true, FmFormView::ImplAccess() );
1888 void SAL_CALL
FmXFormView::focusLost( const FocusEvent
& /*e*/ ) throw (RuntimeException
, std::exception
)
1890 // when switch the focus outside the office the mark didn't change
1891 // so we can not remove us as focus listener
1892 if ( m_xWindow
.is() && m_pView
)
1894 m_pView
->SetMoveOutside( false, FmFormView::ImplAccess() );
1898 void FmXFormView::removeGridWindowListening()
1900 if ( m_xWindow
.is() )
1902 m_xWindow
->removeFocusListener(this);
1905 m_pView
->SetMoveOutside( false, FmFormView::ImplAccess() );
1912 DocumentType
FmXFormView::impl_getDocumentType() const
1914 if ( GetFormShell() && GetFormShell()->GetImpl() )
1915 return GetFormShell()->GetImpl()->getDocumentType();
1916 return eUnknownDocumentType
;
1919 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */