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