2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
|
|
|
* $RCSfile: fmpgeimp.cxx,v $
|
|
|
|
*
|
2001-07-25 12:44:28 +00:00
|
|
|
* $Revision: 1.11 $
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2001-07-25 12:44:28 +00:00
|
|
|
* last change: $Author: fs $ $Date: 2001-07-25 13:43:36 $
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
|
|
|
* The Contents of this file are made available subject to the terms of
|
|
|
|
* either of the following licenses
|
|
|
|
*
|
|
|
|
* - GNU Lesser General Public License Version 2.1
|
|
|
|
* - Sun Industry Standards Source License Version 1.1
|
|
|
|
*
|
|
|
|
* Sun Microsystems Inc., October, 2000
|
|
|
|
*
|
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2000 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Sun Industry Standards Source License Version 1.1
|
|
|
|
* =================================================
|
|
|
|
* The contents of this file are subject to the Sun Industry Standards
|
|
|
|
* Source License Version 1.1 (the "License"); You may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of the
|
|
|
|
* License at http://www.openoffice.org/license.html.
|
|
|
|
*
|
|
|
|
* Software provided under this License is provided on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
|
|
|
|
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
|
|
|
|
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
|
|
|
|
* See the License for the specific provisions governing your rights and
|
|
|
|
* obligations concerning the Software.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* Copyright: 2000 by Sun Microsystems, Inc.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): _______________________________________
|
|
|
|
*
|
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
#pragma hdrstop
|
|
|
|
|
|
|
|
#define _EXTERN_FORMLAYER_
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _SVXERR_HXX
|
|
|
|
#include "svxerr.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SVX_FMUNOPGE_HXX
|
|
|
|
#include "fmpgeimp.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_
|
|
|
|
#include <com/sun/star/sdb/CommandType.hpp>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _COM_SUN_STAR_IO_XOBJECTINPUTSTREAM_HPP_
|
|
|
|
#include <com/sun/star/io/XObjectInputStream.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_IO_XPERSISTOBJECT_HPP_
|
|
|
|
#include <com/sun/star/io/XPersistObject.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_IO_XOBJECTOUTPUTSTREAM_HPP_
|
|
|
|
#include <com/sun/star/io/XObjectOutputStream.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_IO_XACTIVEDATASINK_HPP_
|
|
|
|
#include <com/sun/star/io/XActiveDataSink.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_IO_XACTIVEDATASOURCE_HPP_
|
|
|
|
#include <com/sun/star/io/XActiveDataSource.hpp>
|
|
|
|
#endif
|
|
|
|
#ifndef _COM_SUN_STAR_IO_XMARKABLESTREAM_HPP_
|
|
|
|
#include <com/sun/star/io/XMarkableStream.hpp>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SFX_OBJSH_HXX
|
|
|
|
#include <sfx2/objsh.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SVX_FMUNDO_HXX
|
|
|
|
#include "fmundo.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _SVX_FMTOOLS_HXX
|
|
|
|
#include "fmtools.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _SVX_FMPROP_HRC
|
|
|
|
#include "fmprop.hrc"
|
|
|
|
#endif
|
|
|
|
#ifndef _SVX_FMGLOB_HXX
|
|
|
|
#include "fmglob.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _SVX_FMSERVS_HXX
|
|
|
|
#include "fmservs.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// #include "fmstream.hxx"
|
|
|
|
#ifndef _SVX_FMOBJ_HXX
|
|
|
|
#include "fmobj.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _SVX_FMPAGE_HXX
|
|
|
|
#include "fmpage.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _SVX_FMMODEL_HXX
|
|
|
|
#include "fmmodel.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _TOOLS_RESID_HXX //autogen
|
|
|
|
#include <tools/resid.hxx>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SVDITER_HXX //autogen
|
|
|
|
#include "svditer.hxx"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SVX_FMRESIDS_HRC
|
|
|
|
#include "fmresids.hrc"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef _SHL_HXX
|
|
|
|
#include <tools/shl.hxx>
|
|
|
|
#endif
|
2000-11-24 07:32:57 +00:00
|
|
|
#ifndef _VCL_STDTEXT_HXX
|
|
|
|
#include <vcl/stdtext.hxx>
|
|
|
|
#endif
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
#ifndef _SVX_DIALMGR_HXX
|
|
|
|
#include "dialmgr.hxx"
|
|
|
|
#endif
|
|
|
|
|
2000-10-20 13:18:57 +00:00
|
|
|
#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
|
|
|
|
#include <comphelper/processfactory.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#endif
|
2000-10-20 13:18:57 +00:00
|
|
|
#ifndef _COMPHELPER_UNO3_HXX_
|
|
|
|
#include <comphelper/uno3.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#endif
|
2000-10-20 13:18:57 +00:00
|
|
|
#ifndef _COMPHELPER_TYPES_HXX_
|
|
|
|
#include <comphelper/types.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#endif
|
|
|
|
#ifndef _UTL_STREAM_WRAPPER_HXX_
|
|
|
|
#include <unotools/streamwrap.hxx>
|
|
|
|
#endif
|
2000-10-20 13:18:57 +00:00
|
|
|
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
|
|
|
|
#include <connectivity/dbtools.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#endif
|
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
using namespace ::com::sun::star::sdbc;
|
|
|
|
using namespace ::com::sun::star::sdb;
|
2001-06-05 09:48:53 +00:00
|
|
|
using namespace ::com::sun::star::container;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace ::com::sun::star::form;
|
2000-12-18 07:22:38 +00:00
|
|
|
using namespace ::svxform;
|
2000-11-15 13:55:12 +00:00
|
|
|
|
2000-11-07 12:16:50 +00:00
|
|
|
DBG_NAME(FmFormPageImpl);
|
2000-09-18 16:07:07 +00:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
FmFormPageImpl::FmFormPageImpl(FmFormPage* _pPage)
|
|
|
|
:pPage(_pPage)
|
|
|
|
{
|
2000-11-07 12:16:50 +00:00
|
|
|
DBG_CTOR(FmFormPageImpl,NULL);
|
2000-09-18 16:07:07 +00:00
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
FmFormPageImpl::FmFormPageImpl(FmFormPage* _pPage, const FmFormPageImpl& rImpl)
|
|
|
|
:pPage(_pPage)
|
|
|
|
{
|
2000-11-07 12:16:50 +00:00
|
|
|
DBG_CTOR(FmFormPageImpl,NULL);
|
2000-09-18 16:07:07 +00:00
|
|
|
Init();
|
|
|
|
|
|
|
|
// copy it by streaming
|
|
|
|
// creating a pipe
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XOutputStream > xOutPipe(::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.io.Pipe")), UNO_QUERY);
|
|
|
|
Reference< ::com::sun::star::io::XInputStream > xInPipe(xOutPipe, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// creating the mark streams
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XInputStream > xMarkIn(::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.io.MarkableInputStream")), UNO_QUERY);
|
|
|
|
Reference< ::com::sun::star::io::XActiveDataSink > xMarkSink(xMarkIn, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XOutputStream > xMarkOut(::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.io.MarkableOutputStream")), UNO_QUERY);
|
|
|
|
Reference< ::com::sun::star::io::XActiveDataSource > xMarkSource(xMarkOut, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// connect pipe and sink
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XActiveDataSink > xSink(::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.io.ObjectInputStream")), UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// connect pipe and source
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XActiveDataSource > xSource(::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.io.ObjectOutputStream")), UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XObjectOutputStream > xOutStrm(xSource, UNO_QUERY);
|
|
|
|
Reference< ::com::sun::star::io::XObjectInputStream > xInStrm(xSink, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
if (xMarkSink.is() && xMarkSource.is() && xSink.is() && xSource.is() && xOutStrm.is() && xInStrm.is())
|
|
|
|
{
|
|
|
|
xMarkSink->setInputStream(xInPipe);
|
|
|
|
xMarkSource->setOutputStream(xOutPipe);
|
|
|
|
xSink->setInputStream(xMarkIn);
|
|
|
|
xSource->setOutputStream(xMarkOut);
|
|
|
|
|
|
|
|
// write the objects to source
|
|
|
|
rImpl.write(xOutStrm);
|
|
|
|
xOutStrm->closeOutput();
|
|
|
|
|
|
|
|
// read them
|
|
|
|
read(xInStrm);
|
|
|
|
xInStrm->closeInput();
|
|
|
|
}
|
|
|
|
// what to do else ?
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void FmFormPageImpl::Init()
|
|
|
|
{
|
|
|
|
if (pPage)
|
|
|
|
{
|
|
|
|
FmFormModel* pDrawModel = (FmFormModel*)pPage->GetModel();
|
|
|
|
SfxObjectShell* pObjShell = pDrawModel->GetObjectShell();
|
|
|
|
if( pObjShell )
|
|
|
|
xModel = pObjShell->GetModel();
|
|
|
|
|
|
|
|
// get a unique page id from the model
|
|
|
|
m_sPageId = pDrawModel->GetUniquePageId();
|
|
|
|
}
|
|
|
|
|
2000-11-24 07:32:57 +00:00
|
|
|
static const ::rtl::OUString sFormsCollectionServiceName = ::rtl::OUString::createFromAscii("com.sun.star.form.Forms");
|
2000-11-15 13:55:12 +00:00
|
|
|
xForms = Reference< ::com::sun::star::container::XNameContainer > (
|
2000-10-20 13:18:57 +00:00
|
|
|
::comphelper::getProcessServiceFactory()->createInstance(
|
2000-11-24 07:32:57 +00:00
|
|
|
sFormsCollectionServiceName), ::com::sun::star::uno::UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
DBG_ASSERT(xForms.is(), "FmFormPageImpl::Init : could not create a forms collection !");
|
2000-11-24 07:32:57 +00:00
|
|
|
if (!xForms.is())
|
|
|
|
ShowServiceNotAvailableError(NULL, sFormsCollectionServiceName, sal_True);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::container::XChild > xAsChild(xForms, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
if (xAsChild.is())
|
|
|
|
xAsChild->setParent( xModel );
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
FmFormPageImpl::~FmFormPageImpl()
|
|
|
|
{
|
|
|
|
xCurrentForm = NULL;
|
|
|
|
|
2000-10-20 13:18:57 +00:00
|
|
|
::comphelper::disposeComponent(xForms);
|
2000-11-07 12:16:50 +00:00
|
|
|
DBG_DTOR(FmFormPageImpl,NULL);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2000-11-15 13:55:12 +00:00
|
|
|
void FmFormPageImpl::setCurForm(Reference< ::com::sun::star::form::XForm > xForm)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
xCurrentForm = xForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::form::XForm > FmFormPageImpl::getDefaultForm()
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::form::XForm > xForm;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// wenn noch kein TargetForm gefunden, dann aktuelle oder Default
|
|
|
|
if (!xCurrentForm.is())
|
|
|
|
{
|
|
|
|
if (xForms->hasElements())
|
|
|
|
{
|
|
|
|
// suche die Standardform
|
|
|
|
::rtl::OUString ustrStdFormName = ::rtl::OUString(SVX_RES(RID_STR_STDFORMNAME));
|
|
|
|
|
|
|
|
if (xForms->hasByName(ustrStdFormName))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2000-11-07 12:16:50 +00:00
|
|
|
xForms->getByName(ustrStdFormName) >>= xForm;
|
|
|
|
}
|
|
|
|
catch(::com::sun::star::container::NoSuchElementException &)
|
|
|
|
{
|
|
|
|
DBG_ERROR("NoSuchElementException occured!");
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2000-11-07 12:16:50 +00:00
|
|
|
catch(::com::sun::star::lang::WrappedTargetException &)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-11-07 12:16:50 +00:00
|
|
|
DBG_ERROR("WrappedTargetException occured!");
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// gibt es denn ueberhaupt eine
|
|
|
|
if (!xForm.is())
|
|
|
|
{
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::container::XIndexAccess > xGetFirst(xForms, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
DBG_ASSERT(xGetFirst.is(), "FmFormPageImpl::getDefaultForm : no IndexAccess on my form container !");
|
|
|
|
// wenn das anspringt, muesste man sich die Namen des NameContainers geben lassen und dann das Objekt fuer den
|
|
|
|
// ersten Namen erfragen ... aber normalerweise sollte die FOrms-Sammlung auch einen IndexAccess haben
|
2000-11-07 12:16:50 +00:00
|
|
|
xGetFirst->getByIndex(0) >>= xForm;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
xForm = xCurrentForm;
|
|
|
|
|
|
|
|
// keine gefunden dann standard erzeugen
|
|
|
|
if (!xForm.is())
|
|
|
|
{
|
|
|
|
|
|
|
|
SdrModel* pModel = pPage->GetModel();
|
|
|
|
XubString aStr(SVX_RES(RID_STR_FORM));
|
|
|
|
XubString aUndoStr(SVX_RES(RID_STR_UNDO_CONTAINER_INSERT));
|
|
|
|
aUndoStr.SearchAndReplace('#', aStr);
|
|
|
|
pModel->BegUndo(aUndoStr);
|
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
xForm = Reference< ::com::sun::star::form::XForm >(::comphelper::getProcessServiceFactory()->createInstance(FM_SUN_COMPONENT_FORM), UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
// a form should always have the command type table as default
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::beans::XPropertySet > xSet(xForm, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
try
|
|
|
|
{
|
2000-11-15 13:55:12 +00:00
|
|
|
xSet->setPropertyValue(FM_PROP_COMMANDTYPE, makeAny(sal_Int32(CommandType::TABLE)));
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2000-11-24 06:01:26 +00:00
|
|
|
catch(Exception&)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
::rtl::OUString aName = ::rtl::OUString(SVX_RES(RID_STR_STDFORMNAME));
|
2000-11-15 13:55:12 +00:00
|
|
|
xSet->setPropertyValue(FM_PROP_NAME, makeAny(aName));
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::container::XIndexContainer > xContainer(xForms, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
pModel->AddUndo(new FmUndoContainerAction(*(FmFormModel*)pModel,
|
|
|
|
FmUndoContainerAction::Inserted,
|
|
|
|
xContainer,
|
|
|
|
xForm,
|
|
|
|
xContainer->getCount()));
|
2000-11-15 13:55:12 +00:00
|
|
|
xForms->insertByName(aName, makeAny(xForm));
|
2000-09-18 16:07:07 +00:00
|
|
|
xCurrentForm = xForm;
|
|
|
|
pModel->EndUndo();
|
|
|
|
}
|
|
|
|
return xForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::form::XForm > FmFormPageImpl::SetDefaults(const Reference< ::com::sun::star::form::XFormComponent > & rContent,
|
|
|
|
const Reference< XDataSource > & rDatabase,
|
2000-09-18 16:07:07 +00:00
|
|
|
const ::rtl::OUString& rDBTitle,
|
|
|
|
const ::rtl::OUString& rCursorSource,
|
|
|
|
sal_Int32 nCommandType)
|
|
|
|
{
|
|
|
|
// Ist das Control bereits einer ::com::sun::star::form zugeordnet
|
|
|
|
if (!rContent.is() || rContent->getParent().is())
|
|
|
|
return NULL;
|
|
|
|
|
2001-06-05 09:48:53 +00:00
|
|
|
Reference< XForm > xForm;
|
|
|
|
Reference< XPropertySet > xSet;
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// Wenn Datenbank und CursorSource gesetzt sind, dann wird
|
|
|
|
// die ::com::sun::star::form anhand dieser Kriterien gesucht, ansonsten nur aktuelle
|
|
|
|
// und die StandardForm
|
2001-05-11 15:07:05 +00:00
|
|
|
if (rDatabase.is() && rCursorSource.getLength())
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
// erst in der aktuellen form suchen
|
|
|
|
xForm = FindForm(xCurrentForm, rDatabase, rCursorSource, nCommandType);
|
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::container::XIndexAccess > xFormsByIndex(xForms, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
DBG_ASSERT(xFormsByIndex.is(), "FmFormPageImpl::SetDefaults : no index access for my forms collection !");
|
|
|
|
sal_Int32 nCount = xFormsByIndex->getCount();
|
|
|
|
for (sal_Int32 i = 0; !xForm.is() && i < nCount; i++)
|
|
|
|
{
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::form::XForm > xToSearch;
|
2000-11-07 12:16:50 +00:00
|
|
|
xFormsByIndex->getByIndex(i) >>= xToSearch;
|
2000-09-18 16:07:07 +00:00
|
|
|
xForm = FindForm(xToSearch, rDatabase, rCursorSource, nCommandType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// wenn keine ::com::sun::star::form gefunden, dann eine neue erzeugen
|
|
|
|
if (!xForm.is())
|
|
|
|
{
|
|
|
|
SdrModel* pModel = pPage->GetModel();
|
|
|
|
XubString aStr(SVX_RES(RID_STR_FORM));
|
|
|
|
XubString aUndoStr(SVX_RES(RID_STR_UNDO_CONTAINER_INSERT));
|
|
|
|
aUndoStr.SearchAndReplace('#', aStr);
|
|
|
|
pModel->BegUndo(aUndoStr);
|
2000-11-15 13:55:12 +00:00
|
|
|
xForm = Reference< ::com::sun::star::form::XForm >(::comphelper::getProcessServiceFactory()->createInstance(FM_SUN_COMPONENT_FORM), UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
// a form should always have the command type table as default
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::beans::XPropertySet > xSet(xForm, UNO_QUERY);
|
|
|
|
try { xSet->setPropertyValue(FM_PROP_COMMANDTYPE, makeAny(sal_Int32(CommandType::TABLE))); }
|
2000-11-24 06:01:26 +00:00
|
|
|
catch(Exception&) { }
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2001-05-11 15:07:05 +00:00
|
|
|
if (rDBTitle.getLength())
|
2000-11-15 13:55:12 +00:00
|
|
|
xSet->setPropertyValue(FM_PROP_DATASOURCE,makeAny(rDBTitle));
|
2000-09-18 16:07:07 +00:00
|
|
|
else
|
|
|
|
{
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::beans::XPropertySet > xDatabaseProps(rDatabase, UNO_QUERY);
|
|
|
|
Any aDatabaseUrl = xDatabaseProps->getPropertyValue(FM_PROP_URL);
|
2000-09-18 16:07:07 +00:00
|
|
|
xSet->setPropertyValue(FM_PROP_DATASOURCE, aDatabaseUrl);
|
|
|
|
}
|
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
xSet->setPropertyValue(FM_PROP_COMMAND,makeAny(rCursorSource));
|
|
|
|
xSet->setPropertyValue(FM_PROP_COMMANDTYPE, makeAny(nCommandType));
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::container::XNameAccess > xNamedSet(xForms, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
::rtl::OUString aName;
|
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
if ((CommandType::TABLE == nCommandType) || (CommandType::QUERY == nCommandType))
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
// Namen der ::com::sun::star::form ueber den Titel der CursorSource setzen
|
|
|
|
aName = getUniqueName(rCursorSource, xNamedSet);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
// ansonsten StandardformName verwenden
|
|
|
|
aName = getUniqueName(::rtl::OUString(SVX_RES(RID_STR_STDFORMNAME)), xNamedSet);
|
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
xSet->setPropertyValue(FM_PROP_NAME, makeAny(aName));
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::container::XIndexContainer > xContainer(xForms, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
pModel->AddUndo(new FmUndoContainerAction(*(FmFormModel*)pModel,
|
|
|
|
FmUndoContainerAction::Inserted,
|
|
|
|
xContainer,
|
|
|
|
xForm,
|
|
|
|
xContainer->getCount()));
|
|
|
|
|
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
xForms->insertByName(aName, makeAny(xForm));
|
2000-09-18 16:07:07 +00:00
|
|
|
pModel->EndUndo();
|
|
|
|
}
|
|
|
|
xCurrentForm = xForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
xForm = getDefaultForm();
|
|
|
|
// eindeutigen Namen fuer die Componente setzen
|
|
|
|
setUniqueName(rContent, xForm);
|
|
|
|
return xForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2001-06-05 09:48:53 +00:00
|
|
|
Reference< XForm > FmFormPageImpl::FindForm(
|
|
|
|
const Reference< XForm > & rForm, const Reference< XDataSource > & _rxDatabase,
|
|
|
|
const ::rtl::OUString& _rCursorSource, sal_Int32 nCommandType)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-06-05 09:48:53 +00:00
|
|
|
Reference< XForm > xResultForm;
|
|
|
|
Reference< XRowSet > xDBForm(rForm, UNO_QUERY);
|
|
|
|
Reference< XPropertySet > xFormProps(rForm, UNO_QUERY);
|
|
|
|
if (!xDBForm.is() || !xFormProps.is())
|
|
|
|
return xResultForm;
|
|
|
|
|
|
|
|
OSL_ENSURE(_rxDatabase.is(), "FmFormPageImpl::FindForm: invalid data source!");
|
|
|
|
::rtl::OUString sLookupName; // the name of the data source we're looking for
|
|
|
|
::rtl::OUString sFormDataSourceName; // the name of the data source the current connection in the form is based on
|
2000-09-18 16:07:07 +00:00
|
|
|
try
|
|
|
|
{
|
2001-06-05 09:48:53 +00:00
|
|
|
Reference< XPropertySet > xDSProps(_rxDatabase, UNO_QUERY);
|
|
|
|
if (xDSProps.is())
|
|
|
|
xDSProps->getPropertyValue(FM_PROP_NAME) >>= sLookupName;
|
|
|
|
|
|
|
|
xFormProps->getPropertyValue(FM_PROP_DATASOURCE) >>= sFormDataSourceName;
|
|
|
|
if (0 == sFormDataSourceName.getLength())
|
|
|
|
{
|
|
|
|
// check if it has an active connection
|
2001-07-25 12:44:28 +00:00
|
|
|
Reference< XConnection > xFormConnection = getRowsetConnection(xDBForm);
|
2001-06-05 09:48:53 +00:00
|
|
|
if (xFormConnection.is())
|
|
|
|
{
|
|
|
|
OSL_ENSURE(sal_False, "FmFormPageImpl::FindForm: a connection without data source name?");
|
|
|
|
// don't know if this is allowed to happen (don't think so, that's why asserting this).
|
|
|
|
// 05.06.2001 - 87688 - frank.schoenheit@sun.com
|
|
|
|
Reference< XChild > xConnAsChild(xFormConnection, UNO_QUERY);
|
|
|
|
if (xConnAsChild.is())
|
|
|
|
{
|
|
|
|
Reference< XDataSource > xFormDS(xConnAsChild->getParent(), UNO_QUERY);
|
|
|
|
// the data source which created the connection
|
|
|
|
if (xFormDS.is())
|
|
|
|
{
|
|
|
|
xDSProps = xDSProps.query(xFormDS);
|
|
|
|
if (xDSProps.is())
|
|
|
|
xDSProps->getPropertyValue(FM_PROP_NAME) >>= sFormDataSourceName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2001-06-05 09:48:53 +00:00
|
|
|
catch(const Exception& e)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-06-05 09:48:53 +00:00
|
|
|
e;
|
|
|
|
OSL_ENSURE(sal_False, "FmFormPageImpl::FindForm: caught an exception!");
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2001-06-05 09:48:53 +00:00
|
|
|
if (sLookupName == sFormDataSourceName)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
// jetzt noch ueberpruefen ob CursorSource und Type uebereinstimmen
|
2001-06-05 09:48:53 +00:00
|
|
|
::rtl::OUString aCursorSource = ::comphelper::getString(xFormProps->getPropertyValue(FM_PROP_COMMAND));
|
|
|
|
sal_Int32 nType = ::comphelper::getINT32(xFormProps->getPropertyValue(FM_PROP_COMMANDTYPE));
|
|
|
|
if (!aCursorSource.getLength() || ((nType == nCommandType) && (aCursorSource == _rCursorSource))) // found the form
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
xResultForm = rForm;
|
|
|
|
// Ist noch keine Datenquelle gesetzt, wird dieses hier nachgeholt
|
2001-05-11 15:07:05 +00:00
|
|
|
if (!aCursorSource.getLength())
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2001-06-05 09:48:53 +00:00
|
|
|
xFormProps->setPropertyValue(FM_PROP_COMMAND, makeAny(_rCursorSource));
|
|
|
|
xFormProps->setPropertyValue(FM_PROP_COMMANDTYPE, makeAny((sal_Int32)nCommandType));
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-05 09:48:53 +00:00
|
|
|
// as long as xResultForm is NULL, search the child forms of rForm
|
|
|
|
Reference< XIndexAccess > xComponents(rForm, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
sal_Int32 nCount = xComponents->getCount();
|
|
|
|
for (sal_Int32 i = 0; !xResultForm.is() && i < nCount; ++i)
|
|
|
|
{
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::form::XForm > xSearchForm;
|
2000-11-07 12:16:50 +00:00
|
|
|
xComponents->getByIndex(i) >>= xSearchForm;
|
2000-09-18 16:07:07 +00:00
|
|
|
// jetzt innerhalb der ::com::sun::star::form weitersuchen
|
|
|
|
if (xSearchForm.is())
|
2001-06-05 09:48:53 +00:00
|
|
|
xResultForm = FindForm(xSearchForm, _rxDatabase, _rCursorSource, nCommandType);
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
return xResultForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2000-11-15 13:55:12 +00:00
|
|
|
::rtl::OUString FmFormPageImpl::setUniqueName(const Reference< ::com::sun::star::form::XFormComponent > & xFormComponent, const Reference< ::com::sun::star::form::XForm > & xControls)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
::rtl::OUString sName;
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::beans::XPropertySet > xSet(xFormComponent, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
if (xSet.is())
|
|
|
|
{
|
2000-11-15 13:55:12 +00:00
|
|
|
Any aValue = xSet->getPropertyValue(FM_PROP_NAME);
|
2000-10-20 13:18:57 +00:00
|
|
|
sName = ::comphelper::getString(aValue);
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::container::XNameAccess > xNameAcc(xControls, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2001-05-11 15:07:05 +00:00
|
|
|
if (!sName.getLength() || xNameAcc->hasByName(sName))
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
// setzen eines default Namens ueber die ClassId
|
2000-11-15 13:55:12 +00:00
|
|
|
Any aValue = xSet->getPropertyValue(FM_PROP_CLASSID);
|
2000-09-18 16:07:07 +00:00
|
|
|
sal_Int16 nClassId(::com::sun::star::form::FormComponentType::CONTROL);
|
|
|
|
aValue >>= nClassId;
|
|
|
|
|
|
|
|
::rtl::OUString sDefaultName = getDefaultName(nClassId, xControls);
|
|
|
|
// bei Radiobuttons, die einen Namen haben, diesen nicht ueberschreiben!
|
2001-05-11 15:07:05 +00:00
|
|
|
if (!sName.getLength() || nClassId != ::com::sun::star::form::FormComponentType::RADIOBUTTON)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-11-15 13:55:12 +00:00
|
|
|
xSet->setPropertyValue(FM_PROP_NAME, makeAny(sDefaultName));
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
// Labels anpassen
|
|
|
|
UniString aLabel = sDefaultName;
|
|
|
|
sal_uInt16 nResId = 0;
|
|
|
|
|
|
|
|
switch (nClassId)
|
|
|
|
{
|
|
|
|
case ::com::sun::star::form::FormComponentType::COMMANDBUTTON: nResId = RID_STR_PROPTITLE_PUSHBUTTON; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::RADIOBUTTON: nResId = RID_STR_PROPTITLE_RADIOBUTTON; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::CHECKBOX: nResId = RID_STR_PROPTITLE_CHECKBOX; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::GROUPBOX: nResId = RID_STR_PROPTITLE_GROUPBOX; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::FIXEDTEXT: nResId = RID_STR_PROPTITLE_FIXEDTEXT; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nResId)
|
|
|
|
{
|
|
|
|
aValue = xSet->getPropertyValue(FM_PROP_LABEL);
|
|
|
|
::rtl::OUString aText;
|
|
|
|
aValue >>= aText;
|
2001-05-11 15:07:05 +00:00
|
|
|
if (!aText.getLength())
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
aLabel.SearchAndReplace( getDefaultName(nClassId), ::rtl::OUString(SVX_RES(nResId)) );
|
2000-11-15 13:55:12 +00:00
|
|
|
xSet->setPropertyValue( FM_PROP_LABEL, makeAny(::rtl::OUString(aLabel)) );
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sName = sDefaultName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UniString FmFormPageImpl::getDefaultName(sal_Int16 nClassId)
|
|
|
|
{
|
|
|
|
sal_uInt16 nResId;
|
|
|
|
|
|
|
|
switch (nClassId)
|
|
|
|
{
|
|
|
|
case ::com::sun::star::form::FormComponentType::TEXTFIELD: nResId = RID_STR_EDIT_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::COMMANDBUTTON: nResId = RID_STR_BUTTON_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::RADIOBUTTON: nResId = RID_STR_RADIOBUTTON_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::CHECKBOX: nResId = RID_STR_CHECKBOX_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::LISTBOX: nResId = RID_STR_LISTBOX_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::COMBOBOX: nResId = RID_STR_COMBOBOX_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::GROUPBOX: nResId = RID_STR_GROUPBOX_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::IMAGEBUTTON: nResId = RID_STR_IMAGE_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::FIXEDTEXT: nResId = RID_STR_FIXEDTEXT_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::GRIDCONTROL: nResId = RID_STR_GRID_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::FILECONTROL: nResId = RID_STR_FILECONTROL_CLASSNAME; break;
|
|
|
|
|
|
|
|
case ::com::sun::star::form::FormComponentType::DATEFIELD: nResId = RID_STR_DATEFIELD_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::TIMEFIELD: nResId = RID_STR_TIMEFIELD_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::NUMERICFIELD: nResId = RID_STR_NUMERICFIELD_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::CURRENCYFIELD: nResId = RID_STR_CURRENCYFIELD_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::PATTERNFIELD: nResId = RID_STR_PATTERNFIELD_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::IMAGECONTROL: nResId = RID_STR_IMAGECONTROL_CLASSNAME; break;
|
|
|
|
case ::com::sun::star::form::FormComponentType::HIDDENCONTROL: nResId = RID_STR_HIDDEN_CLASSNAME; break;
|
|
|
|
|
|
|
|
case ::com::sun::star::form::FormComponentType::CONTROL:
|
|
|
|
default:
|
|
|
|
nResId = RID_STR_CONTROL_CLASSNAME; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SVX_RES(nResId);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2000-11-15 13:55:12 +00:00
|
|
|
::rtl::OUString FmFormPageImpl::getDefaultName(sal_Int16 nClassId, const Reference< ::com::sun::star::form::XForm > & xControls) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
::rtl::OUString aClassName=getDefaultName(nClassId);
|
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::container::XNameAccess > xNamedSet(xControls, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
return getUniqueName(aClassName, xNamedSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
2000-11-15 13:55:12 +00:00
|
|
|
::rtl::OUString FmFormPageImpl::getUniqueName(const ::rtl::OUString& rName, const Reference< ::com::sun::star::container::XNameAccess > & xNamedSet) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::container::XIndexAccess > xIndexSet(xNamedSet, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
::rtl::OUString sName;
|
|
|
|
|
|
|
|
if ( !xIndexSet.is() )
|
|
|
|
return sName;
|
|
|
|
|
|
|
|
sal_Int32 n = 0;
|
|
|
|
::rtl::OUString sClassName = rName;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
sName = sClassName + ::rtl::OUString::valueOf(++n);
|
|
|
|
} while (xNamedSet->hasByName(sName));
|
|
|
|
return sName;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void FmFormPageImpl::WriteData(SvStream& rOut) const
|
|
|
|
{
|
|
|
|
// anlegen eines output streams fuer UNO
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XActiveDataSource > xSource(::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.io.ObjectOutputStream")), UNO_QUERY);
|
|
|
|
Reference< ::com::sun::star::io::XOutputStream > xMarkOut(::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.io.MarkableOutputStream")), UNO_QUERY);
|
|
|
|
Reference< ::com::sun::star::io::XActiveDataSource > xMarkSource(xMarkOut, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
if (xSource.is())
|
|
|
|
{
|
|
|
|
xMarkSource->setOutputStream(new ::utl::OOutputStreamWrapper(rOut));
|
|
|
|
xSource->setOutputStream(xMarkOut);
|
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XObjectOutputStream > xOutStrm(xSource, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
write(xOutStrm);
|
|
|
|
}
|
2000-11-24 06:01:26 +00:00
|
|
|
catch(Exception&)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
rOut.SetError( ERRCODE_CLASS_WRITE | ERRCODE_SVX_FORMS_READWRITEFAILED | ERRCODE_WARNING_MASK );
|
|
|
|
}
|
|
|
|
|
|
|
|
xOutStrm->closeOutput();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// let's do a hack : in former versions we didn't use UNO-stream but SvStreams, so there was
|
|
|
|
// no possibility that we couldn't write because of the lack of stream objects. Now, with UNO, this may happen
|
|
|
|
// (as it happended here). But the read-methods of the older versions don't expect that (there is no flag in
|
|
|
|
// the fileformat as it never was neccessary). To allow the old versions the read of the documents, we fake the
|
|
|
|
// write : the first token usually written by our impl is an sal_Int32 giving the number of forms within the forms
|
|
|
|
// collection. If this number is 0, no further reading will occur.
|
|
|
|
sal_Int32 nDummLength = 0; rOut << nDummLength; // this means 'no forms'
|
|
|
|
nDummLength = 0; rOut << nDummLength; // this means 'no form controls"
|
|
|
|
// To tell the user that something went wrong we set a warning on the stream.
|
|
|
|
rOut.SetError( ERRCODE_CLASS_WRITE | ERRCODE_SVX_FORMS_NOIOSERVICES | ERRCODE_WARNING_MASK );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void FmFormPageImpl::ReadData(const SdrIOHeader& rHead, SvStream& rIn)
|
|
|
|
{
|
|
|
|
// Abholen des InputStreams ueber uno
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XActiveDataSink > xSink(::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.io.ObjectInputStream")), UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// creating the mark streams
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XInputStream > xMarkIn(::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.io.MarkableInputStream")), UNO_QUERY);
|
|
|
|
Reference< ::com::sun::star::io::XActiveDataSink > xMarkSink(xMarkIn, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
if (xSink.is())
|
|
|
|
{
|
|
|
|
::utl::OInputStreamWrapper* pUnoStream = new ::utl::OInputStreamWrapper(rIn);
|
2000-11-15 13:55:12 +00:00
|
|
|
xMarkSink->setInputStream(Reference< ::com::sun::star::io::XInputStream > (pUnoStream));
|
2000-09-18 16:07:07 +00:00
|
|
|
xSink->setInputStream(xMarkIn);
|
|
|
|
|
|
|
|
// freigeben aller forms
|
|
|
|
xCurrentForm = NULL;
|
|
|
|
|
|
|
|
if (xForms->hasElements())
|
|
|
|
{
|
2000-10-20 13:18:57 +00:00
|
|
|
::comphelper::disposeComponent(xForms);
|
2000-09-18 16:07:07 +00:00
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XObjectInputStream > xInStrm(xSink,UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
read(xInStrm);
|
|
|
|
}
|
2000-11-24 06:01:26 +00:00
|
|
|
catch(Exception&)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
|
|
|
rIn.SetError( ERRCODE_CLASS_READ | ERRCODE_SVX_FORMS_READWRITEFAILED | ERRCODE_WARNING_MASK );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
xInStrm->closeInput();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rIn.SetError( ERRCODE_CLASS_READ | ERRCODE_SVX_FORMS_NOIOSERVICES | ERRCODE_WARNING_MASK );
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2000-11-15 13:55:12 +00:00
|
|
|
void FmFormPageImpl::write(const Reference< ::com::sun::star::io::XObjectOutputStream > & xOutStrm) const
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XMarkableStream > xMarkStrm(xOutStrm, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
if (!xMarkStrm.is())
|
|
|
|
return; // exception
|
|
|
|
|
|
|
|
// sortieren der objectlist nach der Reihenfolge
|
|
|
|
FmObjectList aList;
|
|
|
|
fillList(aList, *pPage, sal_True);
|
|
|
|
|
|
|
|
// schreiben aller forms
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XPersistObject > xAsPersist(xForms, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
if (xAsPersist.is())
|
|
|
|
xAsPersist->write(xOutStrm);
|
|
|
|
// don't use the writeObject of the stream, as this wouldn't be compatible with older documents
|
|
|
|
|
|
|
|
// objectliste einfuegen
|
|
|
|
sal_Int32 nLength = aList.Count();
|
|
|
|
|
|
|
|
// schreiben der laenge
|
|
|
|
xOutStrm->writeLong(nLength);
|
|
|
|
|
|
|
|
for (sal_Int32 i = 0; i < nLength; i++)
|
|
|
|
{
|
|
|
|
// schreiben des Objects mit Marke
|
|
|
|
// Marke um an den Anfang zu springen
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XPersistObject > xObj(aList.GetObject(i)->GetUnoControlModel(), UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
if (xObj.is())
|
|
|
|
{
|
|
|
|
xOutStrm->writeObject(xObj);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
;// exception
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
2000-11-15 13:55:12 +00:00
|
|
|
void FmFormPageImpl::read(const Reference< ::com::sun::star::io::XObjectInputStream > & xInStrm)
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XMarkableStream > xMarkStrm(xInStrm, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
if (!xMarkStrm.is())
|
|
|
|
return; // exception
|
|
|
|
|
|
|
|
// sortieren der objectlist nach der Reihenfolge
|
|
|
|
FmObjectList aList;
|
|
|
|
fillList(aList, *pPage, sal_False);
|
|
|
|
|
|
|
|
// lesen aller forms
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::io::XPersistObject > xAsPersist(xForms, UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
if (xAsPersist.is())
|
|
|
|
xAsPersist->read(xInStrm);
|
|
|
|
// don't use the readObject of the stream, as this wouldn't be compatible with older documents
|
|
|
|
|
|
|
|
// Zuordnung der Formobjekte zu den FormComponents
|
|
|
|
sal_Int32 nLength = xInStrm->readLong();
|
|
|
|
DBG_ASSERT(nLength == (sal_Int32) aList.Count(), "Fehler beim Lesen der UnoModels");
|
|
|
|
for (sal_Int32 i = 0; i < nLength; i++)
|
|
|
|
{
|
2000-11-15 13:55:12 +00:00
|
|
|
Reference< ::com::sun::star::awt::XControlModel > xRef(xInStrm->readObject(), UNO_QUERY);
|
2000-09-18 16:07:07 +00:00
|
|
|
if (i < (sal_Int32)aList.Count())
|
|
|
|
aList.GetObject(i)->SetUnoControlModel(xRef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
void FmFormPageImpl::fillList(FmObjectList& rList, const SdrObjList& rObjList, sal_Bool bConnected) const
|
|
|
|
{
|
|
|
|
SdrObjListIter aIter(rObjList);
|
|
|
|
while (aIter.IsMore())
|
|
|
|
{
|
|
|
|
SdrObject* pObj = aIter.Next();
|
|
|
|
if (pObj && pObj->GetObjInventor() == FmFormInventor)
|
|
|
|
{
|
|
|
|
FmFormObj* pFormObj = PTR_CAST(FmFormObj, pObj);
|
|
|
|
DBG_ASSERT(!bConnected || pFormObj->GetUnoControlModel().is(), "Controlshape ohne Control");
|
|
|
|
if (!bConnected || pFormObj->GetUnoControlModel().is())
|
|
|
|
rList.Insert(pFormObj, LIST_APPEND);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|