1b9e67834SAndre Fischer /**************************************************************
2b9e67834SAndre Fischer  *
3b9e67834SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
4b9e67834SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
5b9e67834SAndre Fischer  * distributed with this work for additional information
6b9e67834SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
7b9e67834SAndre Fischer  * to you under the Apache License, Version 2.0 (the
8b9e67834SAndre Fischer  * "License"); you may not use this file except in compliance
9b9e67834SAndre Fischer  * with the License.  You may obtain a copy of the License at
10b9e67834SAndre Fischer  *
11b9e67834SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
12b9e67834SAndre Fischer  *
13b9e67834SAndre Fischer  * Unless required by applicable law or agreed to in writing,
14b9e67834SAndre Fischer  * software distributed under the License is distributed on an
15b9e67834SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b9e67834SAndre Fischer  * KIND, either express or implied.  See the License for the
17b9e67834SAndre Fischer  * specific language governing permissions and limitations
18b9e67834SAndre Fischer  * under the License.
19b9e67834SAndre Fischer  *
20b9e67834SAndre Fischer  *************************************************************/
21b9e67834SAndre Fischer 
22b9e67834SAndre Fischer #include "sidebar/PanelFactory.hxx"
23b9e67834SAndre Fischer 
2402c50d82SAndre Fischer #include "text/TextPropertyPanel.hxx"
25*8dcb2a10SAndre Fischer #include "area/AreaPropertyPanel.hxx"
26*8dcb2a10SAndre Fischer #include "graphic/GraphicPropertyPanel.hxx"
27*8dcb2a10SAndre Fischer #include "line/LinePropertyPanel.hxx"
28*8dcb2a10SAndre Fischer #include "transform/TransformationPropertyPanel.hxx"
2902c50d82SAndre Fischer #include "gallery/GalleryControl.hxx"
302d839242SAndre Fischer #include "ColorPanel.hxx"
3195a18594SAndre Fischer #include <sfx2/sidebar/SidebarPanelBase.hxx>
3295a18594SAndre Fischer #include <sfx2/sfxbasecontroller.hxx>
33b9e67834SAndre Fischer #include <toolkit/helper/vclunohelper.hxx>
34b9e67834SAndre Fischer #include <vcl/window.hxx>
35b9e67834SAndre Fischer #include <rtl/ref.hxx>
367a32b0c8SAndre Fischer #include <comphelper/namedvaluecollection.hxx>
377a32b0c8SAndre Fischer 
3802c50d82SAndre Fischer 
397a32b0c8SAndre Fischer #include <boost/bind.hpp>
40b9e67834SAndre Fischer 
41b9e67834SAndre Fischer 
42b9e67834SAndre Fischer using namespace css;
43b9e67834SAndre Fischer using namespace cssu;
44b9e67834SAndre Fischer using ::rtl::OUString;
45b9e67834SAndre Fischer 
46b9e67834SAndre Fischer 
47b9e67834SAndre Fischer namespace svx { namespace sidebar {
48b9e67834SAndre Fischer 
49b9e67834SAndre Fischer #define A2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
50b9e67834SAndre Fischer #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.svx.sidebar.PanelFactory"
51b9e67834SAndre Fischer #define SERVICE_NAME "com.sun.star.ui.UIElementFactory"
52b9e67834SAndre Fischer 
53b9e67834SAndre Fischer 
54b9e67834SAndre Fischer ::rtl::OUString SAL_CALL PanelFactory::getImplementationName (void)
55b9e67834SAndre Fischer {
56b9e67834SAndre Fischer     return A2S(IMPLEMENTATION_NAME);
57b9e67834SAndre Fischer }
58b9e67834SAndre Fischer 
59b9e67834SAndre Fischer 
60b9e67834SAndre Fischer 
61b9e67834SAndre Fischer 
62b9e67834SAndre Fischer cssu::Reference<cssu::XInterface> SAL_CALL PanelFactory::createInstance (
63b9e67834SAndre Fischer     const uno::Reference<lang::XMultiServiceFactory>& rxFactory)
64b9e67834SAndre Fischer {
65b9e67834SAndre Fischer     (void)rxFactory;
66b9e67834SAndre Fischer 
67b9e67834SAndre Fischer     ::rtl::Reference<PanelFactory> pPanelFactory (new PanelFactory());
68b9e67834SAndre Fischer     cssu::Reference<cssu::XInterface> xService (static_cast<XWeak*>(pPanelFactory.get()), cssu::UNO_QUERY);
69b9e67834SAndre Fischer     return xService;
70b9e67834SAndre Fischer }
71b9e67834SAndre Fischer 
72b9e67834SAndre Fischer 
73b9e67834SAndre Fischer 
74b9e67834SAndre Fischer 
75b9e67834SAndre Fischer cssu::Sequence<OUString> SAL_CALL PanelFactory::getSupportedServiceNames (void)
76b9e67834SAndre Fischer {
77b9e67834SAndre Fischer     cssu::Sequence<OUString> aServiceNames (1);
78b9e67834SAndre Fischer     aServiceNames[0] = A2S(SERVICE_NAME);
79b9e67834SAndre Fischer     return aServiceNames;
80b9e67834SAndre Fischer 
81b9e67834SAndre Fischer }
82b9e67834SAndre Fischer 
83b9e67834SAndre Fischer 
84b9e67834SAndre Fischer 
85b9e67834SAndre Fischer 
86b9e67834SAndre Fischer PanelFactory::PanelFactory (void)
87b9e67834SAndre Fischer     : PanelFactoryInterfaceBase(m_aMutex)
88b9e67834SAndre Fischer {
89b9e67834SAndre Fischer }
90b9e67834SAndre Fischer 
91b9e67834SAndre Fischer 
92b9e67834SAndre Fischer 
93b9e67834SAndre Fischer 
94b9e67834SAndre Fischer PanelFactory::~PanelFactory (void)
95b9e67834SAndre Fischer {
96b9e67834SAndre Fischer }
97b9e67834SAndre Fischer 
98b9e67834SAndre Fischer 
99b9e67834SAndre Fischer 
100b9e67834SAndre Fischer 
101b9e67834SAndre Fischer Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
102b9e67834SAndre Fischer     const ::rtl::OUString& rsResourceURL,
103b9e67834SAndre Fischer     const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
104b9e67834SAndre Fischer     throw(
105b9e67834SAndre Fischer         container::NoSuchElementException,
106b9e67834SAndre Fischer         lang::IllegalArgumentException,
107b9e67834SAndre Fischer         RuntimeException)
108b9e67834SAndre Fischer {
109b9e67834SAndre Fischer     Reference<ui::XUIElement> xElement;
110b9e67834SAndre Fischer 
1117a32b0c8SAndre Fischer     const ::comphelper::NamedValueCollection aArguments (rArguments);
1127a32b0c8SAndre Fischer     Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>()));
1137a32b0c8SAndre Fischer     Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>()));
1147a32b0c8SAndre Fischer     const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0)));
1157a32b0c8SAndre Fischer     SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue);
116b9e67834SAndre Fischer 
117b9e67834SAndre Fischer     ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
118b9e67834SAndre Fischer     if ( ! xParentWindow.is() || pParentWindow==NULL)
119b9e67834SAndre Fischer         throw RuntimeException(
120b9e67834SAndre Fischer             A2S("PanelFactory::createUIElement called without ParentWindow"),
121b9e67834SAndre Fischer             NULL);
122b9e67834SAndre Fischer     if ( ! xFrame.is())
123b9e67834SAndre Fischer         throw RuntimeException(
124b9e67834SAndre Fischer             A2S("PanelFactory::createUIElement called without Frame"),
125b9e67834SAndre Fischer             NULL);
126b9e67834SAndre Fischer     if (pBindings == NULL)
127b9e67834SAndre Fischer         throw RuntimeException(
128b9e67834SAndre Fischer             A2S("PanelFactory::createUIElement called without SfxBindings"),
129b9e67834SAndre Fischer             NULL);
130b9e67834SAndre Fischer 
13102c50d82SAndre Fischer #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s))
13202c50d82SAndre Fischer     if (DoesResourceEndWith("/TextPropertyPanel"))
13395a18594SAndre Fischer     {
13495a18594SAndre Fischer         TextPropertyPanel* pPanel = TextPropertyPanel::Create(pParentWindow, xFrame, pBindings);
13595a18594SAndre Fischer         xElement = sfx2::sidebar::SidebarPanelBase::Create(
13695a18594SAndre Fischer             rsResourceURL,
13795a18594SAndre Fischer             xFrame,
1387a32b0c8SAndre Fischer             pPanel,
13902c50d82SAndre Fischer             ::boost::bind(&TextPropertyPanel::ShowMenu, pPanel),
14002c50d82SAndre Fischer             ui::LayoutSize(-1,-1,-1));
14195a18594SAndre Fischer     }
14202c50d82SAndre Fischer     else if (DoesResourceEndWith("/AreaPropertyPanel"))
14366c1fc23SArmin Le Grand     {
14466c1fc23SArmin Le Grand         AreaPropertyPanel* pPanel = AreaPropertyPanel::Create(pParentWindow, xFrame, pBindings);
14566c1fc23SArmin Le Grand         xElement = sfx2::sidebar::SidebarPanelBase::Create(
14666c1fc23SArmin Le Grand             rsResourceURL,
14766c1fc23SArmin Le Grand             xFrame,
1485d65efa0SAndre Fischer             pPanel,
14902c50d82SAndre Fischer             ::boost::bind(&AreaPropertyPanel::ShowMenu, pPanel),
15002c50d82SAndre Fischer             ui::LayoutSize(-1,-1,-1));
15166c1fc23SArmin Le Grand     }
15202c50d82SAndre Fischer     else if (DoesResourceEndWith("/GraphicPropertyPanel"))
1532bdfcea1SArmin Le Grand     {
1542bdfcea1SArmin Le Grand         GraphicPropertyPanel* pPanel = GraphicPropertyPanel::Create(pParentWindow, xFrame, pBindings);
1552bdfcea1SArmin Le Grand         xElement = sfx2::sidebar::SidebarPanelBase::Create(
1562bdfcea1SArmin Le Grand             rsResourceURL,
1572bdfcea1SArmin Le Grand             xFrame,
1582bdfcea1SArmin Le Grand             pPanel,
15902c50d82SAndre Fischer             ::boost::function<void(void)>(),
16002c50d82SAndre Fischer             ui::LayoutSize(-1,-1,-1));
1612bdfcea1SArmin Le Grand     }
16202c50d82SAndre Fischer     else if (DoesResourceEndWith("/LinePropertyPanel"))
16358e893aeSArmin Le Grand     {
16458e893aeSArmin Le Grand         LinePropertyPanel* pPanel = LinePropertyPanel::Create(pParentWindow, xFrame, pBindings);
16558e893aeSArmin Le Grand         xElement = sfx2::sidebar::SidebarPanelBase::Create(
16658e893aeSArmin Le Grand             rsResourceURL,
16758e893aeSArmin Le Grand             xFrame,
16858e893aeSArmin Le Grand             pPanel,
16902c50d82SAndre Fischer             ::boost::bind(&LinePropertyPanel::ShowMenu, pPanel),
17002c50d82SAndre Fischer             ui::LayoutSize(-1,-1,-1));
17158e893aeSArmin Le Grand     }
17202c50d82SAndre Fischer     else if (DoesResourceEndWith("/TransformationPropertyPanel"))
17335fa8f12SArmin Le Grand     {
1746cdc6e4fSArmin Le Grand         TransformationPropertyPanel* pPanel = TransformationPropertyPanel::Create(pParentWindow, xFrame, pBindings);
17535fa8f12SArmin Le Grand         xElement = sfx2::sidebar::SidebarPanelBase::Create(
17635fa8f12SArmin Le Grand             rsResourceURL,
17735fa8f12SArmin Le Grand             xFrame,
17835fa8f12SArmin Le Grand             pPanel,
17902c50d82SAndre Fischer             ::boost::bind(&TransformationPropertyPanel::ShowMenu, pPanel),
18002c50d82SAndre Fischer             ui::LayoutSize(-1,-1,-1));
18102c50d82SAndre Fischer     }
18202c50d82SAndre Fischer     else if (DoesResourceEndWith("/GalleryPanel"))
18302c50d82SAndre Fischer     {
18402c50d82SAndre Fischer         GalleryControl* pGalleryControl = new GalleryControl(
18502c50d82SAndre Fischer             pBindings,
18602c50d82SAndre Fischer             pParentWindow);
18702c50d82SAndre Fischer         xElement = sfx2::sidebar::SidebarPanelBase::Create(
18802c50d82SAndre Fischer             rsResourceURL,
18902c50d82SAndre Fischer             xFrame,
19002c50d82SAndre Fischer             pGalleryControl,
19102c50d82SAndre Fischer             ::boost::function<void(void)>(),
19202c50d82SAndre Fischer             ui::LayoutSize(300,-1,400));
19335fa8f12SArmin Le Grand     }
1942d839242SAndre Fischer     else if (DoesResourceEndWith("/Debug_ColorPanel"))
1952d839242SAndre Fischer     {
1962d839242SAndre Fischer         ColorPanel* pColorPanel = new ColorPanel(
1972d839242SAndre Fischer             pParentWindow);
1982d839242SAndre Fischer         xElement = sfx2::sidebar::SidebarPanelBase::Create(
1992d839242SAndre Fischer             rsResourceURL,
2002d839242SAndre Fischer             xFrame,
2012d839242SAndre Fischer             pColorPanel,
2022d839242SAndre Fischer             ::boost::function<void(void)>(),
2032d839242SAndre Fischer             ui::LayoutSize(300,-1,400));
2042d839242SAndre Fischer     }
20502c50d82SAndre Fischer #undef DoesResourceEndWith
20666c1fc23SArmin Le Grand 
207b9e67834SAndre Fischer     return xElement;
208b9e67834SAndre Fischer }
209b9e67834SAndre Fischer 
210b9e67834SAndre Fischer } } // end of namespace svx::sidebar
21135fa8f12SArmin Le Grand 
21235fa8f12SArmin Le Grand // eof
213