Files
libreoffice/sdext/source/presenter/PresenterPaneFactory.cxx

338 lines
11 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* 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 .
*/
#include "PresenterPaneFactory.hxx"
#include "PresenterController.hxx"
#include "PresenterPane.hxx"
#include "PresenterPaneBorderPainter.hxx"
#include "PresenterPaneContainer.hxx"
#include "PresenterSpritePane.hxx"
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/drawing/framework/ResourceId.hpp>
#include <com/sun/star/drawing/framework/XControllerManager.hpp>
#include <com/sun/star/drawing/framework/XConfigurationController.hpp>
#include <com/sun/star/frame/XController.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <boost/bind.hpp>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
2010-03-22 13:36:52 +01:00
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::drawing::framework;
namespace sdext { namespace presenter {
const OUString PresenterPaneFactory::msCurrentSlidePreviewPaneURL(
"private:resource/pane/Presenter/Pane1");
const OUString PresenterPaneFactory::msNextSlidePreviewPaneURL(
"private:resource/pane/Presenter/Pane2");
const OUString PresenterPaneFactory::msNotesPaneURL(
"private:resource/pane/Presenter/Pane3");
const OUString PresenterPaneFactory::msToolBarPaneURL(
"private:resource/pane/Presenter/Pane4");
const OUString PresenterPaneFactory::msSlideSorterPaneURL(
"private:resource/pane/Presenter/Pane5");
const OUString PresenterPaneFactory::msHelpPaneURL(
"private:resource/pane/Presenter/Pane6");
const OUString PresenterPaneFactory::msOverlayPaneURL(
"private:resource/pane/Presenter/Overlay");
//===== PresenterPaneFactory ==================================================
Reference<drawing::framework::XResourceFactory> PresenterPaneFactory::Create (
const Reference<uno::XComponentContext>& rxContext,
const Reference<frame::XController>& rxController,
const ::rtl::Reference<PresenterController>& rpPresenterController)
{
rtl::Reference<PresenterPaneFactory> pFactory (
new PresenterPaneFactory(rxContext,rpPresenterController));
pFactory->Register(rxController);
return Reference<drawing::framework::XResourceFactory>(
static_cast<XWeak*>(pFactory.get()), UNO_QUERY);
}
PresenterPaneFactory::PresenterPaneFactory (
const Reference<uno::XComponentContext>& rxContext,
const ::rtl::Reference<PresenterController>& rpPresenterController)
: PresenterPaneFactoryInterfaceBase(m_aMutex),
mxComponentContextWeak(rxContext),
mxConfigurationControllerWeak(),
mpPresenterController(rpPresenterController),
mpResourceCache()
{
}
void PresenterPaneFactory::Register (const Reference<frame::XController>& rxController)
{
Reference<XConfigurationController> xCC;
try
{
// Get the configuration controller.
Reference<XControllerManager> xCM (rxController, UNO_QUERY_THROW);
xCC = Reference<XConfigurationController>(xCM->getConfigurationController());
mxConfigurationControllerWeak = xCC;
if ( ! xCC.is())
{
throw RuntimeException();
}
else
{
xCC->addResourceFactory(
OUString("private:resource/pane/Presenter/*"),
this);
}
}
catch (RuntimeException&)
{
OSL_ASSERT(false);
if (xCC.is())
xCC->removeResourceFactoryForReference(this);
mxConfigurationControllerWeak = WeakReference<XConfigurationController>();
throw;
}
}
PresenterPaneFactory::~PresenterPaneFactory()
{
}
void SAL_CALL PresenterPaneFactory::disposing()
throw (RuntimeException)
{
Reference<XConfigurationController> xCC (mxConfigurationControllerWeak);
if (xCC.is())
xCC->removeResourceFactoryForReference(this);
mxConfigurationControllerWeak = WeakReference<XConfigurationController>();
// Dispose the panes in the cache.
if (mpResourceCache.get() != NULL)
{
ResourceContainer::const_iterator iPane (mpResourceCache->begin());
ResourceContainer::const_iterator iEnd (mpResourceCache->end());
for ( ; iPane!=iEnd; ++iPane)
{
Reference<lang::XComponent> xPaneComponent (iPane->second, UNO_QUERY);
if (xPaneComponent.is())
xPaneComponent->dispose();
}
mpResourceCache.reset();
}
}
//----- XPaneFactory ----------------------------------------------------------
Reference<XResource> SAL_CALL PresenterPaneFactory::createResource (
const Reference<XResourceId>& rxPaneId)
throw (RuntimeException, IllegalArgumentException, WrappedTargetException, std::exception)
{
CWS-TOOLING: integrate CWS sjfixes10 2009-01-15 14:02:24 +0100 af r266369 : #i88851# Finding the right font size is now an iterative process. 2009-01-15 11:01:59 +0100 wg r266354 : i97985 2009-01-15 10:57:33 +0100 wg r266353 : i97985 2009-01-15 10:48:53 +0100 wg r266347 : i97985 2009-01-15 10:48:23 +0100 wg r266346 : i97985 2009-01-15 10:46:47 +0100 wg r266345 : i97985 2009-01-15 10:45:43 +0100 wg r266344 : i97985 2009-01-15 10:45:14 +0100 wg r266343 : i97985 2009-01-15 10:44:38 +0100 wg r266342 : i97985 2009-01-15 10:43:56 +0100 wg r266341 : i97985 2009-01-15 10:42:50 +0100 wg r266340 : i97985 2009-01-15 10:41:40 +0100 wg r266339 : i97985 2009-01-15 10:39:46 +0100 wg r266337 : i97985 2009-01-15 10:00:09 +0100 hde r266336 : i98065 2009-01-13 15:48:20 +0100 wg r266232 : i97985 2009-01-13 13:22:05 +0100 wg r266217 : i97985 2009-01-13 12:34:05 +0100 wg r266210 : i97985 2009-01-13 12:30:56 +0100 wg r266209 : i97985 2009-01-13 12:26:56 +0100 wg r266208 : i97985 2009-01-12 15:58:06 +0100 wg r266165 : i97985 2009-01-12 15:43:24 +0100 wg r266163 : i97985 2009-01-08 16:21:47 +0100 sj r266023 : fixed warning 2009-01-08 15:33:34 +0100 sj r266017 : fixed warning 2009-01-06 18:13:42 +0100 sj r265935 : CWS-TOOLING: rebase CWS sjfixes10 to trunk@265758 (milestone: DEV300:m38) 2008-12-10 16:54:02 +0100 af r265206 : #i43354# Do not delete all unused master pages automatically. 2008-12-04 13:12:50 +0100 af r264836 : #i92795# Use BitmapEx for icons to allow transparency. 2008-12-02 17:01:49 +0100 af r264723 : #i93082# Fixed SID_INSERTPAGE_LAYOUT_MENU. 2008-11-28 14:37:28 +0100 af r264555 : #i88851# Changed association of Ctrl-'?' to views. 2008-11-28 11:38:52 +0100 af r264535 : #i96681# Set version to 1.0.2 2008-11-28 11:30:04 +0100 af r264533 : #i88851# Ctrl-1,2,3 switch to slide overview, notes, normal view. 2008-11-27 16:41:25 +0100 af r264505 : #i92144# Removed unused code. 2008-11-26 15:29:56 +0100 af r264401 : #i92574# Do not lock configuration controller when main pane is not available. 2008-11-21 10:13:40 +0100 sj r264112 : #i96146# applied patch (ambiguous && ||) 2008-11-20 20:12:06 +0100 sj r264097 : #i96083# applied patch (ambigous && ||) 2008-11-20 19:13:53 +0100 sj r264096 : #i96163# applied patch (ambigous && ||) 2008-11-20 18:39:10 +0100 sj r264093 : #i96165# applied patch (ambigous && ||) 2008-11-03 18:12:29 +0100 sj r263303 : #i93996# fixed word wrapping problem 2008-11-03 18:11:02 +0100 sj r263302 : #i93996# fixed word wrapping problem 2008-11-03 18:08:41 +0100 sj r263301 : #i93996# fixed word wrapping problem 2008-11-03 18:06:45 +0100 sj r263300 : #i93996# fixed word wrapping problem 2008-11-03 18:05:00 +0100 sj r263299 : #i94831,i93616# fixed crash when importing diagonal cell border lines, fixed table import 2008-11-03 18:00:43 +0100 sj r263298 : #i93718# spellchecking is no longer triggering the autolayout of connector objects
2009-01-21 14:22:27 +00:00
ThrowIfDisposed();
if ( ! rxPaneId.is())
return NULL;
const OUString sPaneURL (rxPaneId->getResourceURL());
if (sPaneURL.isEmpty())
return NULL;
if (mpResourceCache.get() != NULL)
{
// Has the requested resource already been created?
ResourceContainer::const_iterator iResource (mpResourceCache->find(sPaneURL));
if (iResource != mpResourceCache->end())
{
// Yes. Mark it as active.
rtl::Reference<PresenterPaneContainer> pPaneContainer(
mpPresenterController->GetPaneContainer());
PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
pPaneContainer->FindPaneURL(sPaneURL));
if (pDescriptor.get() != NULL)
{
pDescriptor->SetActivationState(true);
if (pDescriptor->mxBorderWindow.is())
pDescriptor->mxBorderWindow->setVisible(sal_True);
pPaneContainer->StorePane(pDescriptor->mxPane);
}
return iResource->second;
}
}
// No. Create a new one.
Reference<XResource> xResource = CreatePane(rxPaneId, OUString());
return xResource;
}
void SAL_CALL PresenterPaneFactory::releaseResource (const Reference<XResource>& rxResource)
throw (RuntimeException, std::exception)
{
CWS-TOOLING: integrate CWS sjfixes10 2009-01-15 14:02:24 +0100 af r266369 : #i88851# Finding the right font size is now an iterative process. 2009-01-15 11:01:59 +0100 wg r266354 : i97985 2009-01-15 10:57:33 +0100 wg r266353 : i97985 2009-01-15 10:48:53 +0100 wg r266347 : i97985 2009-01-15 10:48:23 +0100 wg r266346 : i97985 2009-01-15 10:46:47 +0100 wg r266345 : i97985 2009-01-15 10:45:43 +0100 wg r266344 : i97985 2009-01-15 10:45:14 +0100 wg r266343 : i97985 2009-01-15 10:44:38 +0100 wg r266342 : i97985 2009-01-15 10:43:56 +0100 wg r266341 : i97985 2009-01-15 10:42:50 +0100 wg r266340 : i97985 2009-01-15 10:41:40 +0100 wg r266339 : i97985 2009-01-15 10:39:46 +0100 wg r266337 : i97985 2009-01-15 10:00:09 +0100 hde r266336 : i98065 2009-01-13 15:48:20 +0100 wg r266232 : i97985 2009-01-13 13:22:05 +0100 wg r266217 : i97985 2009-01-13 12:34:05 +0100 wg r266210 : i97985 2009-01-13 12:30:56 +0100 wg r266209 : i97985 2009-01-13 12:26:56 +0100 wg r266208 : i97985 2009-01-12 15:58:06 +0100 wg r266165 : i97985 2009-01-12 15:43:24 +0100 wg r266163 : i97985 2009-01-08 16:21:47 +0100 sj r266023 : fixed warning 2009-01-08 15:33:34 +0100 sj r266017 : fixed warning 2009-01-06 18:13:42 +0100 sj r265935 : CWS-TOOLING: rebase CWS sjfixes10 to trunk@265758 (milestone: DEV300:m38) 2008-12-10 16:54:02 +0100 af r265206 : #i43354# Do not delete all unused master pages automatically. 2008-12-04 13:12:50 +0100 af r264836 : #i92795# Use BitmapEx for icons to allow transparency. 2008-12-02 17:01:49 +0100 af r264723 : #i93082# Fixed SID_INSERTPAGE_LAYOUT_MENU. 2008-11-28 14:37:28 +0100 af r264555 : #i88851# Changed association of Ctrl-'?' to views. 2008-11-28 11:38:52 +0100 af r264535 : #i96681# Set version to 1.0.2 2008-11-28 11:30:04 +0100 af r264533 : #i88851# Ctrl-1,2,3 switch to slide overview, notes, normal view. 2008-11-27 16:41:25 +0100 af r264505 : #i92144# Removed unused code. 2008-11-26 15:29:56 +0100 af r264401 : #i92574# Do not lock configuration controller when main pane is not available. 2008-11-21 10:13:40 +0100 sj r264112 : #i96146# applied patch (ambiguous && ||) 2008-11-20 20:12:06 +0100 sj r264097 : #i96083# applied patch (ambigous && ||) 2008-11-20 19:13:53 +0100 sj r264096 : #i96163# applied patch (ambigous && ||) 2008-11-20 18:39:10 +0100 sj r264093 : #i96165# applied patch (ambigous && ||) 2008-11-03 18:12:29 +0100 sj r263303 : #i93996# fixed word wrapping problem 2008-11-03 18:11:02 +0100 sj r263302 : #i93996# fixed word wrapping problem 2008-11-03 18:08:41 +0100 sj r263301 : #i93996# fixed word wrapping problem 2008-11-03 18:06:45 +0100 sj r263300 : #i93996# fixed word wrapping problem 2008-11-03 18:05:00 +0100 sj r263299 : #i94831,i93616# fixed crash when importing diagonal cell border lines, fixed table import 2008-11-03 18:00:43 +0100 sj r263298 : #i93718# spellchecking is no longer triggering the autolayout of connector objects
2009-01-21 14:22:27 +00:00
ThrowIfDisposed();
if ( ! rxResource.is())
throw lang::IllegalArgumentException();
// Mark the pane as inactive.
rtl::Reference<PresenterPaneContainer> pPaneContainer(
mpPresenterController->GetPaneContainer());
const OUString sPaneURL (rxResource->getResourceId()->getResourceURL());
PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
pPaneContainer->FindPaneURL(sPaneURL));
if (pDescriptor.get() != NULL)
{
pDescriptor->SetActivationState(false);
if (pDescriptor->mxBorderWindow.is())
pDescriptor->mxBorderWindow->setVisible(sal_False);
if (mpResourceCache.get() != NULL)
{
// Store the pane in the cache.
(*mpResourceCache)[sPaneURL] = rxResource;
}
else
{
// Dispose the pane.
Reference<lang::XComponent> xPaneComponent (rxResource, UNO_QUERY);
if (xPaneComponent.is())
xPaneComponent->dispose();
}
}
}
Reference<XResource> PresenterPaneFactory::CreatePane (
const Reference<XResourceId>& rxPaneId,
const OUString& rsTitle)
{
if ( ! rxPaneId.is())
return NULL;
Reference<XConfigurationController> xCC (mxConfigurationControllerWeak);
if ( ! xCC.is())
return NULL;
Reference<XComponentContext> xContext (mxComponentContextWeak);
if ( ! xContext.is())
return NULL;
Reference<XPane> xParentPane (xCC->getResource(rxPaneId->getAnchor()), UNO_QUERY);
if ( ! xParentPane.is())
return NULL;
try
{
return CreatePane(
rxPaneId,
rsTitle,
xParentPane,
rxPaneId->getFullResourceURL().Arguments == "Sprite=1");
}
catch (Exception&)
{
OSL_ASSERT(false);
}
return NULL;
}
Reference<XResource> PresenterPaneFactory::CreatePane (
const Reference<XResourceId>& rxPaneId,
const OUString& rsTitle,
const Reference<drawing::framework::XPane>& rxParentPane,
const bool bIsSpritePane)
{
Reference<XComponentContext> xContext (mxComponentContextWeak);
Reference<lang::XMultiComponentFactory> xFactory (
xContext->getServiceManager(), UNO_QUERY_THROW);
// Create a border window and canvas and store it in the pane
// container.
// Create the pane.
::rtl::Reference<PresenterPaneBase> xPane;
if (bIsSpritePane)
{
xPane = ::rtl::Reference<PresenterPaneBase>(
new PresenterSpritePane(xContext, mpPresenterController));
}
else
{
xPane = ::rtl::Reference<PresenterPaneBase>(
new PresenterPane(xContext, mpPresenterController));
}
// Supply arguments.
Sequence<Any> aArguments (6);
aArguments[0] <<= rxPaneId;
aArguments[1] <<= rxParentPane->getWindow();
aArguments[2] <<= rxParentPane->getCanvas();
aArguments[3] <<= rsTitle;
aArguments[4] <<= Reference<drawing::framework::XPaneBorderPainter>(
static_cast<XWeak*>(mpPresenterController->GetPaneBorderPainter().get()),
UNO_QUERY);
aArguments[5] <<= !bIsSpritePane;
xPane->initialize(aArguments);
// Store pane and canvases and windows in container.
::rtl::Reference<PresenterPaneContainer> pContainer (
mpPresenterController->GetPaneContainer());
PresenterPaneContainer::SharedPaneDescriptor pDescriptor(
pContainer->StoreBorderWindow(rxPaneId, xPane->GetBorderWindow()));
pContainer->StorePane(xPane);
if (pDescriptor.get() != NULL)
{
if (bIsSpritePane)
{
pDescriptor->maSpriteProvider = ::boost::bind(
&PresenterSpritePane::GetSprite,
dynamic_cast<PresenterSpritePane*>(xPane.get()));
pDescriptor->mbIsSprite = true;
pDescriptor->mbNeedsClipping = false;
}
else
{
pDescriptor->mbIsSprite = false;
pDescriptor->mbNeedsClipping = true;
}
// Get the window of the frame and make that visible.
Reference<awt::XWindow> xWindow (pDescriptor->mxBorderWindow, UNO_QUERY_THROW);
xWindow->setVisible(sal_True);
}
return Reference<XResource>(static_cast<XWeak*>(xPane.get()), UNO_QUERY_THROW);
}
void PresenterPaneFactory::ThrowIfDisposed() const
throw (::com::sun::star::lang::DisposedException)
{
if (rBHelper.bDisposed || rBHelper.bInDispose)
{
throw lang::DisposedException (
OUString( "PresenterPaneFactory object has already been disposed"),
const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
}
}
} } // end of namespace sdext::presenter
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */