162024513SAndre Fischer /**************************************************************
262024513SAndre Fischer *
362024513SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one
462024513SAndre Fischer * or more contributor license agreements. See the NOTICE file
562024513SAndre Fischer * distributed with this work for additional information
662024513SAndre Fischer * regarding copyright ownership. The ASF licenses this file
762024513SAndre Fischer * to you under the Apache License, Version 2.0 (the
862024513SAndre Fischer * "License"); you may not use this file except in compliance
962024513SAndre Fischer * with the License. You may obtain a copy of the License at
1062024513SAndre Fischer *
1162024513SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0
1262024513SAndre Fischer *
1362024513SAndre Fischer * Unless required by applicable law or agreed to in writing,
1462024513SAndre Fischer * software distributed under the License is distributed on an
1562024513SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1662024513SAndre Fischer * KIND, either express or implied. See the License for the
1762024513SAndre Fischer * specific language governing permissions and limitations
1862024513SAndre Fischer * under the License.
1962024513SAndre Fischer *
2062024513SAndre Fischer *************************************************************/
2162024513SAndre Fischer
2262024513SAndre Fischer #include "precompiled_sd.hxx"
2362024513SAndre Fischer
2462024513SAndre Fischer #include "PanelFactory.hxx"
2562024513SAndre Fischer #include "framework/Pane.hxx"
2662024513SAndre Fischer #include "ViewShellBase.hxx"
2762024513SAndre Fischer #include "DrawController.hxx"
2862024513SAndre Fischer #include "LayoutMenu.hxx"
2962024513SAndre Fischer #include "CurrentMasterPagesSelector.hxx"
3062024513SAndre Fischer #include "RecentMasterPagesSelector.hxx"
3162024513SAndre Fischer #include "AllMasterPagesSelector.hxx"
3262024513SAndre Fischer #include "CustomAnimationPanel.hxx"
3362024513SAndre Fischer #include "SlideTransitionPanel.hxx"
3462024513SAndre Fischer #include "NavigatorWrapper.hxx"
3562024513SAndre Fischer
3662024513SAndre Fischer #include <sfx2/viewfrm.hxx>
3762024513SAndre Fischer #include <sfx2/sidebar/SidebarPanelBase.hxx>
3862024513SAndre Fischer #include <comphelper/namedvaluecollection.hxx>
3962024513SAndre Fischer #include <vcl/window.hxx>
4062024513SAndre Fischer #include <toolkit/helper/vclunohelper.hxx>
4162024513SAndre Fischer
4262024513SAndre Fischer using namespace css;
4362024513SAndre Fischer using namespace cssu;
4462024513SAndre Fischer using namespace ::sd::framework;
4562024513SAndre Fischer using ::rtl::OUString;
4662024513SAndre Fischer
4762024513SAndre Fischer #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
4862024513SAndre Fischer
49*f6859a6bSAndre Fischer namespace sd {
50*f6859a6bSAndre Fischer extern ::Window * createTableDesignPanel (::Window* pParent, ViewShellBase& rBase);
51*f6859a6bSAndre Fischer }
52*f6859a6bSAndre Fischer
5362024513SAndre Fischer namespace sd { namespace sidebar {
5462024513SAndre Fischer
5562024513SAndre Fischer namespace {
5662024513SAndre Fischer /** Note that these names have to be identical to (the tail of)
5762024513SAndre Fischer the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu
5862024513SAndre Fischer for the TaskPanelFactory.
5962024513SAndre Fischer */
6062024513SAndre Fischer const static char* gsResourceNameCustomAnimations = "/CustomAnimations";
6162024513SAndre Fischer const static char* gsResourceNameLayouts = "/Layouts";
6262024513SAndre Fischer const static char* gsResourceNameAllMasterPages = "/AllMasterPages";
6362024513SAndre Fischer const static char* gsResourceNameRecentMasterPages = "/RecentMasterPages";
6462024513SAndre Fischer const static char* gsResourceNameUsedMasterPages = "/UsedMasterPages";
6562024513SAndre Fischer const static char* gsResourceNameSlideTransitions = "/SlideTransitions";
6662024513SAndre Fischer const static char* gsResourceNameTableDesign = "/TableDesign";
673c226292SAndre Fischer const static char* gsResourceNameNavigator = "/NavigatorPanel";
6862024513SAndre Fischer }
6962024513SAndre Fischer
7062024513SAndre Fischer Reference<lang::XEventListener> mxControllerDisposeListener;
7162024513SAndre Fischer
7262024513SAndre Fischer
7362024513SAndre Fischer
7462024513SAndre Fischer // ----- Service functions ----------------------------------------------------
7562024513SAndre Fischer
PanelFactory_createInstance(const Reference<XComponentContext> & rxContext)7662024513SAndre Fischer Reference<XInterface> SAL_CALL PanelFactory_createInstance (
7762024513SAndre Fischer const Reference<XComponentContext>& rxContext)
7862024513SAndre Fischer {
7962024513SAndre Fischer return Reference<XInterface>(static_cast<XWeak*>(new PanelFactory(rxContext)));
8062024513SAndre Fischer }
8162024513SAndre Fischer
8262024513SAndre Fischer
8362024513SAndre Fischer
8462024513SAndre Fischer
PanelFactory_getImplementationName(void)8562024513SAndre Fischer ::rtl::OUString PanelFactory_getImplementationName (void) throw(RuntimeException)
8662024513SAndre Fischer {
8762024513SAndre Fischer return ::rtl::OUString(
8862024513SAndre Fischer RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.Draw.framework.PanelFactory"));
8962024513SAndre Fischer }
9062024513SAndre Fischer
9162024513SAndre Fischer
9262024513SAndre Fischer
9362024513SAndre Fischer
PanelFactory_getSupportedServiceNames(void)9462024513SAndre Fischer Sequence<rtl::OUString> SAL_CALL PanelFactory_getSupportedServiceNames (void)
9562024513SAndre Fischer throw (RuntimeException)
9662024513SAndre Fischer {
9762024513SAndre Fischer static const ::rtl::OUString sServiceName(
9862024513SAndre Fischer ::rtl::OUString::createFromAscii("com.sun.star.drawing.framework.PanelFactory"));
9962024513SAndre Fischer return Sequence<rtl::OUString>(&sServiceName, 1);
10062024513SAndre Fischer }
10162024513SAndre Fischer
10262024513SAndre Fischer
10362024513SAndre Fischer
10462024513SAndre Fischer
10562024513SAndre Fischer //----- PanelFactory --------------------------------------------------------
10662024513SAndre Fischer
PanelFactory(const css::uno::Reference<css::uno::XComponentContext> & rxContext)10762024513SAndre Fischer PanelFactory::PanelFactory(
10862024513SAndre Fischer const css::uno::Reference<css::uno::XComponentContext>& rxContext)
10962024513SAndre Fischer : PanelFactoryInterfaceBase(m_aMutex)
11062024513SAndre Fischer {
11162024513SAndre Fischer }
11262024513SAndre Fischer
11362024513SAndre Fischer
11462024513SAndre Fischer
11562024513SAndre Fischer
~PanelFactory(void)11662024513SAndre Fischer PanelFactory::~PanelFactory (void)
11762024513SAndre Fischer {
11862024513SAndre Fischer }
11962024513SAndre Fischer
12062024513SAndre Fischer
12162024513SAndre Fischer
12262024513SAndre Fischer
disposing(void)12362024513SAndre Fischer void SAL_CALL PanelFactory::disposing (void)
12462024513SAndre Fischer {
12562024513SAndre Fischer }
12662024513SAndre Fischer
12762024513SAndre Fischer
12862024513SAndre Fischer
12962024513SAndre Fischer
13062024513SAndre Fischer // XUIElementFactory
13162024513SAndre Fischer
createUIElement(const::rtl::OUString & rsUIElementResourceURL,const::cssu::Sequence<css::beans::PropertyValue> & rArguments)13262024513SAndre Fischer Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
13362024513SAndre Fischer const ::rtl::OUString& rsUIElementResourceURL,
13462024513SAndre Fischer const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
13562024513SAndre Fischer throw(
13662024513SAndre Fischer css::container::NoSuchElementException,
13762024513SAndre Fischer css::lang::IllegalArgumentException,
13862024513SAndre Fischer cssu::RuntimeException)
13962024513SAndre Fischer {
14062024513SAndre Fischer // Process arguments.
14162024513SAndre Fischer const ::comphelper::NamedValueCollection aArguments (rArguments);
14262024513SAndre Fischer Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
14362024513SAndre Fischer Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
14462024513SAndre Fischer Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>()));
14562024513SAndre Fischer
14662024513SAndre Fischer // Throw exceptions when the arguments are not as expected.
14762024513SAndre Fischer ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
14862024513SAndre Fischer if ( ! xParentWindow.is() || pParentWindow==NULL)
14962024513SAndre Fischer throw RuntimeException(
15062024513SAndre Fischer A2S("PanelFactory::createUIElement called without ParentWindow"),
15162024513SAndre Fischer NULL);
15262024513SAndre Fischer if ( ! xFrame.is())
15362024513SAndre Fischer throw RuntimeException(
15462024513SAndre Fischer A2S("PanelFactory::createUIElement called without XFrame"),
15562024513SAndre Fischer NULL);
15662024513SAndre Fischer
15762024513SAndre Fischer // Tunnel through the controller to obtain a ViewShellBase.
15862024513SAndre Fischer ViewShellBase* pBase = NULL;
15962024513SAndre Fischer Reference<lang::XUnoTunnel> xTunnel (xFrame->getController(), UNO_QUERY);
16062024513SAndre Fischer if (xTunnel.is())
16162024513SAndre Fischer {
16262024513SAndre Fischer ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
16362024513SAndre Fischer xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
16462024513SAndre Fischer if (pController != NULL)
16562024513SAndre Fischer pBase = pController->GetViewShellBase();
16662024513SAndre Fischer }
16762024513SAndre Fischer if (pBase == NULL)
16862024513SAndre Fischer throw RuntimeException(A2S("can not get ViewShellBase for frame"), NULL);
16962024513SAndre Fischer
17062024513SAndre Fischer // Get bindings from given arguments.
17162024513SAndre Fischer const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
17262024513SAndre Fischer SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
17362024513SAndre Fischer
17462024513SAndre Fischer // Create a framework view.
17562024513SAndre Fischer ::Window* pControl = NULL;
176*f6859a6bSAndre Fischer css::ui::LayoutSize aLayoutSize (-1,-1,-1);
17762024513SAndre Fischer
17862024513SAndre Fischer #define EndsWith(s,t) s.endsWithAsciiL(t,strlen(t))
17962024513SAndre Fischer if (EndsWith(rsUIElementResourceURL, gsResourceNameCustomAnimations))
18062024513SAndre Fischer pControl = new CustomAnimationPanel(pParentWindow, *pBase);
18162024513SAndre Fischer else if (EndsWith(rsUIElementResourceURL, gsResourceNameLayouts))
18262024513SAndre Fischer pControl = new LayoutMenu(pParentWindow, *pBase, xSidebar);
18362024513SAndre Fischer else if (EndsWith(rsUIElementResourceURL, gsResourceNameAllMasterPages))
18462024513SAndre Fischer pControl = AllMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
18562024513SAndre Fischer else if (EndsWith(rsUIElementResourceURL, gsResourceNameRecentMasterPages))
18662024513SAndre Fischer pControl = RecentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
18762024513SAndre Fischer else if (EndsWith(rsUIElementResourceURL, gsResourceNameUsedMasterPages))
18862024513SAndre Fischer pControl = CurrentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar);
18962024513SAndre Fischer else if (EndsWith(rsUIElementResourceURL, gsResourceNameSlideTransitions))
19062024513SAndre Fischer pControl = new SlideTransitionPanel(pParentWindow, *pBase);
19162024513SAndre Fischer else if (EndsWith(rsUIElementResourceURL, gsResourceNameTableDesign))
192*f6859a6bSAndre Fischer pControl = createTableDesignPanel(pParentWindow, *pBase);
19362024513SAndre Fischer else if (EndsWith(rsUIElementResourceURL, gsResourceNameNavigator))
19462024513SAndre Fischer pControl = new NavigatorWrapper(pParentWindow, *pBase, pBindings);
19562024513SAndre Fischer #undef EndsWith
19662024513SAndre Fischer
19762024513SAndre Fischer if (pControl == NULL)
19862024513SAndre Fischer throw lang::IllegalArgumentException();
19962024513SAndre Fischer
20062024513SAndre Fischer // Create a wrapper around the control that implements the
20162024513SAndre Fischer // necessary UNO interfaces.
20262024513SAndre Fischer return sfx2::sidebar::SidebarPanelBase::Create(
20362024513SAndre Fischer rsUIElementResourceURL,
20462024513SAndre Fischer xFrame,
20562024513SAndre Fischer pControl,
206*f6859a6bSAndre Fischer aLayoutSize);
20762024513SAndre Fischer }
20862024513SAndre Fischer
20962024513SAndre Fischer
21062024513SAndre Fischer
21162024513SAndre Fischer
21262024513SAndre Fischer } } // end of namespace sd::sidebar
213