summaryrefslogtreecommitdiff
path: root/embeddedobj/source/general/docholder.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'embeddedobj/source/general/docholder.cxx')
-rw-r--r--embeddedobj/source/general/docholder.cxx209
1 files changed, 104 insertions, 105 deletions
diff --git a/embeddedobj/source/general/docholder.cxx b/embeddedobj/source/general/docholder.cxx
index 90a04d85e125..4fcb563bc424 100644
--- a/embeddedobj/source/general/docholder.cxx
+++ b/embeddedobj/source/general/docholder.cxx
@@ -57,6 +57,7 @@
#include <com/sun/star/embed/EmbedMisc.hpp>
#include <com/sun/star/embed/EmbedStates.hpp>
#include <osl/diagnose.h>
+#include <utility>
#include <vcl/svapp.hxx>
#include <unotools/resmgr.hxx>
#include <sfx2/strings.hrc>
@@ -110,45 +111,50 @@ static void InsertMenu_Impl( const uno::Reference< container::XIndexContainer >&
uno::Sequence< beans::PropertyValue > aSourceProps;
xSourceMenu->getByIndex( nSourceIndex ) >>= aSourceProps;
uno::Sequence< beans::PropertyValue > aTargetProps( aSourceProps.getLength() );
+ auto aTargetPropsRange = asNonConstRange(aTargetProps);
for ( nInd = 0; nInd < aSourceProps.getLength(); nInd++ )
{
- aTargetProps[nInd].Name = aSourceProps[nInd].Name;
+ aTargetPropsRange[nInd].Name = aSourceProps[nInd].Name;
if ( !aContModuleName.isEmpty() && aTargetProps[nInd].Name == aModuleIdentPropName )
{
- aTargetProps[nInd].Value <<= aContModuleName;
+ aTargetPropsRange[nInd].Value <<= aContModuleName;
bModuleNameSet = true;
}
else if ( aTargetProps[nInd].Name == aDispProvPropName )
{
- aTargetProps[nInd].Value <<= xSourceDisp;
+ aTargetPropsRange[nInd].Value <<= xSourceDisp;
bDispProvSet = true;
}
else
- aTargetProps[nInd].Value = aSourceProps[nInd].Value;
+ aTargetPropsRange[nInd].Value = aSourceProps[nInd].Value;
}
if ( !bModuleNameSet && !aContModuleName.isEmpty() )
{
aTargetProps.realloc( ++nInd );
- aTargetProps[nInd-1].Name = aModuleIdentPropName;
- aTargetProps[nInd-1].Value <<= aContModuleName;
+ auto pTargetProps = aTargetProps.getArray();
+ pTargetProps[nInd-1].Name = aModuleIdentPropName;
+ pTargetProps[nInd-1].Value <<= aContModuleName;
}
if ( !bDispProvSet && xSourceDisp.is() )
{
aTargetProps.realloc( ++nInd );
- aTargetProps[nInd-1].Name = aDispProvPropName;
- aTargetProps[nInd-1].Value <<= xSourceDisp;
+ auto pTargetProps = aTargetProps.getArray();
+ pTargetProps[nInd-1].Name = aDispProvPropName;
+ pTargetProps[nInd-1].Value <<= xSourceDisp;
}
- xTargetMenu->insertByIndex( nTargetIndex, uno::makeAny( aTargetProps ) );
+ xTargetMenu->insertByIndex( nTargetIndex, uno::Any( aTargetProps ) );
}
+namespace embeddedobj
+{
-DocumentHolder::DocumentHolder( const uno::Reference< uno::XComponentContext >& xContext,
+DocumentHolder::DocumentHolder( uno::Reference< uno::XComponentContext > xContext,
OCommonEmbeddedObject* pEmbObj )
: m_pEmbedObj( pEmbObj ),
- m_xContext( xContext ),
+ m_xContext(std::move( xContext )),
m_bReadOnly( false ),
m_bWaitForClose( false ),
m_bAllowClosing( false ),
@@ -156,17 +162,6 @@ DocumentHolder::DocumentHolder( const uno::Reference< uno::XComponentContext >&
m_nNoBorderResizeReact( 0 ),
m_nNoResizeReact( 0 )
{
- m_aOutplaceFrameProps.realloc( 3 );
- beans::NamedValue aArg;
-
- aArg.Name = "TopWindow";
- aArg.Value <<= true;
- m_aOutplaceFrameProps[0] <<= aArg;
-
- aArg.Name = "MakeVisible";
- aArg.Value <<= false;
- m_aOutplaceFrameProps[1] <<= aArg;
-
uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( m_xContext );
osl_atomic_increment(&m_refCount);
try
@@ -178,9 +173,10 @@ DocumentHolder::DocumentHolder( const uno::Reference< uno::XComponentContext >&
}
osl_atomic_decrement(&m_refCount);
- aArg.Name = "ParentFrame";
- aArg.Value <<= xDesktop; //TODO/LATER: should use parent document frame
- m_aOutplaceFrameProps[2] <<= aArg;
+ m_aOutplaceFrameProps = { uno::Any(beans::NamedValue{ "TopWindow", uno::Any(true) }),
+ uno::Any(beans::NamedValue{ "MakeVisible", uno::Any(false) }),
+ //TODO/LATER: should use parent document frame
+ uno::Any(beans::NamedValue{ "ParentFrame", uno::Any(xDesktop) }) };
}
@@ -239,8 +235,12 @@ void DocumentHolder::CloseFrame()
void DocumentHolder::FreeOffice()
{
- uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( m_xContext );
- xDesktop->removeTerminateListener( this );
+ try {
+ uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( m_xContext );
+ xDesktop->removeTerminateListener( this );
+ } catch (const css::uno::DeploymentException&) {
+ // if this happens, the desktop is already gone
+ }
// the following code is commented out since for now there is still no completely correct way to detect
// whether the office can be terminated, so it is better to have unnecessary process running than
@@ -430,26 +430,25 @@ bool DocumentHolder::ShowInplace( const uno::Reference< awt::XWindowPeer >& xPar
uno::Reference< awt::XWindowPeer > xNewWinPeer = xToolkit->createWindow( aOwnWinDescriptor );
uno::Reference< awt::XWindow > xOwnWindow( xNewWinPeer, uno::UNO_QUERY_THROW );
+ uno::Reference< frame::XFrame > xContFrame( xContDisp, uno::UNO_QUERY );
// create a frame based on the specified window
uno::Reference< lang::XSingleServiceFactory > xFrameFact = frame::TaskCreator::create(m_xContext);
- uno::Sequence< uno::Any > aArgs( 2 );
+ uno::Sequence< uno::Any > aArgs( xContFrame.is() ? 2 : 1 );
+ auto pArgs = aArgs.getArray();
beans::NamedValue aArg;
aArg.Name = "ContainerWindow";
aArg.Value <<= xOwnWindow;
- aArgs[0] <<= aArg;
+ pArgs[0] <<= aArg;
- uno::Reference< frame::XFrame > xContFrame( xContDisp, uno::UNO_QUERY );
if ( xContFrame.is() )
{
aArg.Name = "ParentFrame";
aArg.Value <<= xContFrame;
- aArgs[1] <<= aArg;
+ pArgs[1] <<= aArg;
}
- else
- aArgs.realloc( 1 );
// the call will create, initialize the frame, and register it in the parent
m_xFrame.set( xFrameFact->createInstanceWithArguments( aArgs ), uno::UNO_QUERY_THROW );
@@ -472,30 +471,28 @@ bool DocumentHolder::ShowInplace( const uno::Reference< awt::XWindowPeer >& xPar
// TODO: some listeners to the frame and the window ( resize for example )
}
- if ( m_xComponent.is() )
- {
- if ( !LoadDocToFrame( true ) )
- {
- CloseFrame();
- return false;
- }
+ if ( !m_xComponent )
+ return false;
- uno::Reference< frame::XControllerBorder > xControllerBorder( m_xFrame->getController(), uno::UNO_QUERY );
- if ( xControllerBorder.is() )
- {
- m_aBorderWidths = xControllerBorder->getBorder();
- xControllerBorder->addBorderResizeListener( static_cast<frame::XBorderResizeListener*>(this) );
- }
+ if ( !LoadDocToFrame( true ) )
+ {
+ CloseFrame();
+ return false;
+ }
- PlaceFrame( aRectangleToShow );
+ uno::Reference< frame::XControllerBorder > xControllerBorder( m_xFrame->getController(), uno::UNO_QUERY );
+ if ( xControllerBorder.is() )
+ {
+ m_aBorderWidths = xControllerBorder->getBorder();
+ xControllerBorder->addBorderResizeListener( static_cast<frame::XBorderResizeListener*>(this) );
+ }
- if ( m_xHatchWindow.is() )
- m_xHatchWindow->setVisible( true );
+ PlaceFrame( aRectangleToShow );
- return true;
- }
+ if ( m_xHatchWindow.is() )
+ m_xHatchWindow->setVisible( true );
- return false;
+ return true;
}
@@ -547,7 +544,7 @@ uno::Reference< container::XIndexAccess > DocumentHolder::RetrieveOwnMenu_Impl()
}
if ( !xResult.is() )
- throw uno::RuntimeException();
+ throw uno::RuntimeException("Unable to retrieve the UI configuration menu.", getXWeak());
return xResult;
}
@@ -564,7 +561,7 @@ void DocumentHolder::FindConnectPoints(
uno::Sequence< beans::PropertyValue > aProps;
xMenu->getByIndex( nInd ) >>= aProps;
OUString aCommand;
- for ( beans::PropertyValue const & prop : std::as_const(aProps) )
+ for (beans::PropertyValue const& prop : aProps)
if ( prop.Name == "CommandURL" )
{
prop.Value >>= aCommand;
@@ -572,7 +569,7 @@ void DocumentHolder::FindConnectPoints(
}
if ( aCommand.isEmpty() )
- throw uno::RuntimeException();
+ throw uno::RuntimeException("CommandURL is empty at index: " + OUString::number(nInd), xMenu);
if ( aCommand == ".uno:PickList" )
nConnectPoints[0] = nInd;
@@ -641,7 +638,7 @@ bool DocumentHolder::MergeMenus_Impl( const uno::Reference< css::frame::XLayoutM
uno::UNO_QUERY_THROW );
uno::Reference< container::XIndexAccess > xContMenu = xUISettings->getSettings( true );
if ( !xContMenu.is() )
- throw uno::RuntimeException();
+ throw uno::RuntimeException("Unable to merge the menu", getXWeak());
uno::Reference< container::XIndexAccess > xOwnMenu = RetrieveOwnMenu_Impl();
uno::Reference< frame::XDispatchProvider > xOwnDisp( m_xFrame, uno::UNO_QUERY_THROW );
@@ -830,7 +827,7 @@ uno::Reference< frame::XFrame > const & DocumentHolder::GetDocFrame()
m_xInterceptor = new Interceptor( this );
- xInterception->registerDispatchProviderInterceptor( m_xInterceptor.get() );
+ xInterception->registerDispatchProviderInterceptor( m_xInterceptor );
// register interceptor from outside
if ( m_xOutplaceInterceptor.is() )
@@ -879,7 +876,7 @@ uno::Reference< frame::XFrame > const & DocumentHolder::GetDocFrame()
{
sal_Int32 nDisplay = Application::GetDisplayBuiltInScreen();
- tools::Rectangle aWorkRect = Application::GetScreenPosSizePixel( nDisplay );
+ AbsoluteScreenPixelRectangle aWorkRect = Application::GetScreenPosSizePixel( nDisplay );
awt::Rectangle aWindowRect = xHWindow->getPosSize();
if (( aWindowRect.Width < aWorkRect.GetWidth()) && ( aWindowRect.Height < aWorkRect.GetHeight() ))
@@ -942,60 +939,60 @@ void DocumentHolder::SetComponent( const uno::Reference< util::XCloseable >& xDo
bool DocumentHolder::LoadDocToFrame( bool bInPlace )
{
- if ( m_xFrame.is() && m_xComponent.is() )
+ if ( !m_xFrame || !m_xComponent )
+ return true;
+
+ uno::Reference < frame::XModel > xDoc( m_xComponent, uno::UNO_QUERY );
+ if ( xDoc.is() )
{
- uno::Reference < frame::XModel > xDoc( m_xComponent, uno::UNO_QUERY );
- if ( xDoc.is() )
- {
- // load new document into the frame
- uno::Reference< frame::XComponentLoader > xComponentLoader( m_xFrame, uno::UNO_QUERY_THROW );
+ // load new document into the frame
+ uno::Reference< frame::XComponentLoader > xComponentLoader( m_xFrame, uno::UNO_QUERY_THROW );
- ::comphelper::NamedValueCollection aArgs;
- aArgs.put( "Model", m_xComponent );
- aArgs.put( "ReadOnly", m_bReadOnly );
+ ::comphelper::NamedValueCollection aArgs;
+ aArgs.put( "Model", m_xComponent );
+ aArgs.put( "ReadOnly", m_bReadOnly );
- // set document title to show in the title bar
- css::uno::Reference< css::frame::XTitle > xModelTitle( xDoc, css::uno::UNO_QUERY );
- if( xModelTitle.is() && m_pEmbedObj && !m_pEmbedObj->getContainerName().isEmpty() )
- {
- std::locale aResLoc = Translate::Create("sfx");
- OUString sEmbedded = Translate::get(STR_EMBEDDED_TITLE, aResLoc);
- xModelTitle->setTitle( m_pEmbedObj->getContainerName() + sEmbedded );
- m_aContainerName = m_pEmbedObj->getContainerName();
- // TODO: get real m_aDocumentNamePart
- m_aDocumentNamePart = sEmbedded;
- }
+ // set document title to show in the title bar
+ css::uno::Reference< css::frame::XTitle > xModelTitle( xDoc, css::uno::UNO_QUERY );
+ if( xModelTitle.is() && m_pEmbedObj && !m_pEmbedObj->getContainerName().isEmpty() )
+ {
+ std::locale aResLoc = Translate::Create("sfx");
+ OUString sEmbedded = Translate::get(STR_EMBEDDED_TITLE, aResLoc);
+ xModelTitle->setTitle( m_pEmbedObj->getContainerName() + sEmbedded );
+ m_aContainerName = m_pEmbedObj->getContainerName();
+ // TODO: get real m_aDocumentNamePart
+ m_aDocumentNamePart = sEmbedded;
+ }
- if ( bInPlace )
- aArgs.put( "PluginMode", sal_Int16(1) );
- OUString sUrl;
- uno::Reference< lang::XServiceInfo> xServiceInfo(xDoc,uno::UNO_QUERY);
- if ( xServiceInfo.is()
- && xServiceInfo->supportsService("com.sun.star.report.ReportDefinition") )
- {
- sUrl = ".component:DB/ReportDesign";
- }
- else if( xServiceInfo.is()
- && xServiceInfo->supportsService("com.sun.star.chart2.ChartDocument"))
- sUrl = "private:factory/schart";
- else
- sUrl = "private:object";
+ if ( bInPlace )
+ aArgs.put( "PluginMode", sal_Int16(1) );
+ OUString sUrl;
+ uno::Reference< lang::XServiceInfo> xServiceInfo(xDoc,uno::UNO_QUERY);
+ if ( xServiceInfo.is()
+ && xServiceInfo->supportsService("com.sun.star.report.ReportDefinition") )
+ {
+ sUrl = ".component:DB/ReportDesign";
+ }
+ else if( xServiceInfo.is()
+ && xServiceInfo->supportsService("com.sun.star.chart2.ChartDocument"))
+ sUrl = "private:factory/schart";
+ else
+ sUrl = "private:object";
- xComponentLoader->loadComponentFromURL( sUrl,
- "_self",
- 0,
- aArgs.getPropertyValues() );
+ xComponentLoader->loadComponentFromURL( sUrl,
+ "_self",
+ 0,
+ aArgs.getPropertyValues() );
- return true;
- }
+ return true;
+ }
+ else
+ {
+ uno::Reference < frame::XSynchronousFrameLoader > xLoader( m_xComponent, uno::UNO_QUERY );
+ if ( xLoader.is() )
+ return xLoader->load( uno::Sequence < beans::PropertyValue >(), m_xFrame );
else
- {
- uno::Reference < frame::XSynchronousFrameLoader > xLoader( m_xComponent, uno::UNO_QUERY );
- if ( xLoader.is() )
- return xLoader->load( uno::Sequence < beans::PropertyValue >(), m_xFrame );
- else
- return false;
- }
+ return false;
}
return true;
@@ -1285,4 +1282,6 @@ void SAL_CALL DocumentHolder::deactivated( )
// so UIDeactivation is actively triggered by the container
}
+} // namespace embeddedobj
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */