2010-10-14 08:30:41 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2011-03-31 10:05:04 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2004-11-16 09:21:59 +00:00
|
|
|
|
|
|
|
#include <doc.hxx>
|
2007-04-16 14:40:20 +00:00
|
|
|
#include <docsh.hxx>
|
2004-11-16 09:21:59 +00:00
|
|
|
#include <com/sun/star/uno/Reference.hxx>
|
|
|
|
#include <com/sun/star/container/XNameContainer.hpp>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
2007-04-16 14:40:20 +00:00
|
|
|
#include <com/sun/star/frame/XModule.hpp>
|
2004-11-16 09:21:59 +00:00
|
|
|
#include <com/sun/star/xforms/XModel.hpp>
|
|
|
|
#include <com/sun/star/xforms/XFormsUIHelper1.hpp>
|
2011-11-14 11:49:31 +01:00
|
|
|
#include <comphelper/processfactory.hxx>
|
2007-04-16 14:40:20 +00:00
|
|
|
#include <tools/diagnose_ex.h>
|
|
|
|
|
2004-11-16 09:21:59 +00:00
|
|
|
|
2007-09-27 07:37:33 +00:00
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
|
|
|
using uno::Reference;
|
|
|
|
using uno::XInterface;
|
|
|
|
using uno::UNO_QUERY;
|
|
|
|
using uno::makeAny;
|
|
|
|
using uno::Exception;
|
|
|
|
using container::XNameContainer;
|
|
|
|
using xforms::XModel;
|
|
|
|
using frame::XModule;
|
|
|
|
using xforms::XFormsUIHelper1;
|
2013-03-01 13:50:58 +01:00
|
|
|
using ::rtl::OUString;
|
2004-11-16 09:21:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
Reference<XNameContainer> SwDoc::getXForms() const
|
|
|
|
{
|
2013-02-18 07:54:37 +01:00
|
|
|
return mxXForms;
|
2004-11-16 09:21:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SwDoc::isXForms() const
|
|
|
|
{
|
2013-02-18 07:54:37 +01:00
|
|
|
return mxXForms.is();
|
2004-11-16 09:21:59 +00:00
|
|
|
}
|
|
|
|
|
2012-10-12 16:49:40 +02:00
|
|
|
static Reference<XInterface> lcl_createInstance( const sal_Char* pServiceName )
|
2004-11-16 09:21:59 +00:00
|
|
|
{
|
2011-05-08 22:14:45 +02:00
|
|
|
OSL_ENSURE( pServiceName != NULL, "no service name" );
|
2011-11-14 11:49:31 +01:00
|
|
|
return comphelper::getProcessServiceFactory()->createInstance(
|
2004-11-16 09:21:59 +00:00
|
|
|
OUString::createFromAscii( pServiceName ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwDoc::initXForms( bool bCreateDefaultModel )
|
|
|
|
{
|
2011-05-08 22:14:45 +02:00
|
|
|
OSL_ENSURE( ! isXForms(), "please initialize only once" );
|
2004-11-16 09:21:59 +00:00
|
|
|
|
2007-04-16 14:40:20 +00:00
|
|
|
try
|
2004-11-16 09:21:59 +00:00
|
|
|
{
|
2007-04-16 14:40:20 +00:00
|
|
|
// create XForms components
|
2013-02-18 07:54:37 +01:00
|
|
|
mxXForms.set( lcl_createInstance( "com.sun.star.xforms.XForms" ),
|
2007-04-16 14:40:20 +00:00
|
|
|
UNO_QUERY );
|
2013-02-18 07:54:37 +01:00
|
|
|
OSL_ENSURE( mxXForms.is(), "can't create XForms container" );
|
2007-04-16 14:40:20 +00:00
|
|
|
|
|
|
|
// change our module identifier, to be able to have a dedicated UI
|
|
|
|
Reference< XModule > xModule;
|
|
|
|
SwDocShell* pShell( GetDocShell() );
|
|
|
|
if ( pShell )
|
|
|
|
xModule = xModule.query( pShell->GetModel() );
|
2011-05-08 22:14:45 +02:00
|
|
|
OSL_ENSURE( xModule.is(), "SwDoc::initXForms: no XModule at the document!" );
|
2007-04-16 14:40:20 +00:00
|
|
|
if ( xModule.is() )
|
2013-03-01 13:50:58 +01:00
|
|
|
xModule->setIdentifier( OUString( "com.sun.star.xforms.XMLFormDocument" ) );
|
2007-04-16 14:40:20 +00:00
|
|
|
|
|
|
|
// create default model
|
2013-02-18 07:54:37 +01:00
|
|
|
if( bCreateDefaultModel && mxXForms.is() )
|
2004-11-16 09:21:59 +00:00
|
|
|
{
|
2013-03-01 13:50:58 +01:00
|
|
|
OUString sName("Model 1");
|
2007-04-16 14:40:20 +00:00
|
|
|
Reference<XModel> xModel(
|
|
|
|
lcl_createInstance( "com.sun.star.xforms.Model" ),
|
|
|
|
UNO_QUERY );
|
2011-05-08 22:14:45 +02:00
|
|
|
OSL_ENSURE( xModel.is(), "no model?" );
|
2007-04-16 14:40:20 +00:00
|
|
|
if( xModel.is() )
|
|
|
|
{
|
|
|
|
xModel->setID( sName );
|
|
|
|
Reference<XFormsUIHelper1>( xModel, UNO_QUERY )->newInstance(
|
2013-03-01 13:50:58 +01:00
|
|
|
OUString("Instance 1"),
|
2007-04-16 14:40:20 +00:00
|
|
|
OUString(), sal_True );
|
|
|
|
xModel->initialize();
|
2013-02-18 07:54:37 +01:00
|
|
|
mxXForms->insertByName( sName, makeAny( xModel ) );
|
2007-04-16 14:40:20 +00:00
|
|
|
}
|
2013-02-18 07:54:37 +01:00
|
|
|
OSL_ENSURE( mxXForms->hasElements(), "can't create XForms model" );
|
2004-11-16 09:21:59 +00:00
|
|
|
}
|
|
|
|
|
2011-05-08 22:14:45 +02:00
|
|
|
OSL_ENSURE( isXForms(), "initialization failed" );
|
2007-04-16 14:40:20 +00:00
|
|
|
}
|
|
|
|
catch( const Exception& )
|
|
|
|
{
|
|
|
|
DBG_UNHANDLED_EXCEPTION();
|
|
|
|
}
|
2004-11-16 09:21:59 +00:00
|
|
|
}
|
2010-10-14 08:30:41 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|