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