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 
24b9e67834SAndre Fischer #include "text/TextPropertyPanel.hxx"
25*66c1fc23SArmin Le Grand #include <geometry/AreaPropertyPanel.hxx>
2695a18594SAndre Fischer #include <sfx2/sidebar/SidebarPanelBase.hxx>
2795a18594SAndre Fischer #include <sfx2/sfxbasecontroller.hxx>
28b9e67834SAndre Fischer #include <toolkit/helper/vclunohelper.hxx>
29b9e67834SAndre Fischer #include <vcl/window.hxx>
30b9e67834SAndre Fischer #include <rtl/ref.hxx>
31b9e67834SAndre Fischer 
32b9e67834SAndre Fischer 
33b9e67834SAndre Fischer using namespace css;
34b9e67834SAndre Fischer using namespace cssu;
35b9e67834SAndre Fischer using ::rtl::OUString;
36b9e67834SAndre Fischer 
37b9e67834SAndre Fischer 
38b9e67834SAndre Fischer namespace svx { namespace sidebar {
39b9e67834SAndre Fischer 
40b9e67834SAndre Fischer #define A2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
41b9e67834SAndre Fischer #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.svx.sidebar.PanelFactory"
42b9e67834SAndre Fischer #define SERVICE_NAME "com.sun.star.ui.UIElementFactory"
43b9e67834SAndre Fischer 
44b9e67834SAndre Fischer 
45b9e67834SAndre Fischer ::rtl::OUString SAL_CALL PanelFactory::getImplementationName (void)
46b9e67834SAndre Fischer {
47b9e67834SAndre Fischer     return A2S(IMPLEMENTATION_NAME);
48b9e67834SAndre Fischer }
49b9e67834SAndre Fischer 
50b9e67834SAndre Fischer 
51b9e67834SAndre Fischer 
52b9e67834SAndre Fischer 
53b9e67834SAndre Fischer cssu::Reference<cssu::XInterface> SAL_CALL PanelFactory::createInstance (
54b9e67834SAndre Fischer     const uno::Reference<lang::XMultiServiceFactory>& rxFactory)
55b9e67834SAndre Fischer {
56b9e67834SAndre Fischer     (void)rxFactory;
57b9e67834SAndre Fischer 
58b9e67834SAndre Fischer     ::rtl::Reference<PanelFactory> pPanelFactory (new PanelFactory());
59b9e67834SAndre Fischer     cssu::Reference<cssu::XInterface> xService (static_cast<XWeak*>(pPanelFactory.get()), cssu::UNO_QUERY);
60b9e67834SAndre Fischer     return xService;
61b9e67834SAndre Fischer }
62b9e67834SAndre Fischer 
63b9e67834SAndre Fischer 
64b9e67834SAndre Fischer 
65b9e67834SAndre Fischer 
66b9e67834SAndre Fischer cssu::Sequence<OUString> SAL_CALL PanelFactory::getSupportedServiceNames (void)
67b9e67834SAndre Fischer {
68b9e67834SAndre Fischer     cssu::Sequence<OUString> aServiceNames (1);
69b9e67834SAndre Fischer     aServiceNames[0] = A2S(SERVICE_NAME);
70b9e67834SAndre Fischer     return aServiceNames;
71b9e67834SAndre Fischer 
72b9e67834SAndre Fischer }
73b9e67834SAndre Fischer 
74b9e67834SAndre Fischer 
75b9e67834SAndre Fischer 
76b9e67834SAndre Fischer 
77b9e67834SAndre Fischer PanelFactory::PanelFactory (void)
78b9e67834SAndre Fischer     : PanelFactoryInterfaceBase(m_aMutex)
79b9e67834SAndre Fischer {
80b9e67834SAndre Fischer }
81b9e67834SAndre Fischer 
82b9e67834SAndre Fischer 
83b9e67834SAndre Fischer 
84b9e67834SAndre Fischer 
85b9e67834SAndre Fischer PanelFactory::~PanelFactory (void)
86b9e67834SAndre Fischer {
87b9e67834SAndre Fischer }
88b9e67834SAndre Fischer 
89b9e67834SAndre Fischer 
90b9e67834SAndre Fischer 
91b9e67834SAndre Fischer 
92b9e67834SAndre Fischer Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
93b9e67834SAndre Fischer     const ::rtl::OUString& rsResourceURL,
94b9e67834SAndre Fischer     const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
95b9e67834SAndre Fischer     throw(
96b9e67834SAndre Fischer         container::NoSuchElementException,
97b9e67834SAndre Fischer         lang::IllegalArgumentException,
98b9e67834SAndre Fischer         RuntimeException)
99b9e67834SAndre Fischer {
100b9e67834SAndre Fischer     Reference<ui::XUIElement> xElement;
101b9e67834SAndre Fischer     Reference<awt::XWindow> xParentWindow;
102b9e67834SAndre Fischer     Reference<frame::XFrame> xFrame;
103b9e67834SAndre Fischer     SfxBindings* pBindings = NULL;
104b9e67834SAndre Fischer 
105b9e67834SAndre Fischer     for (sal_Int32 nIndex(0),nCount(rArguments.getLength()); nIndex<nCount; ++nIndex)
106b9e67834SAndre Fischer     {
107b9e67834SAndre Fischer         const beans::PropertyValue& rValue (rArguments[nIndex]);
108b9e67834SAndre Fischer         if (rValue.Name.equalsAscii("ParentWindow"))
109b9e67834SAndre Fischer         {
110b9e67834SAndre Fischer             xParentWindow = Reference<awt::XWindow>(rValue.Value, UNO_QUERY);
111b9e67834SAndre Fischer         }
112b9e67834SAndre Fischer         else if (rValue.Name.equalsAscii("Frame"))
113b9e67834SAndre Fischer         {
114b9e67834SAndre Fischer             xFrame = Reference<frame::XFrame>(rValue.Value, UNO_QUERY);
115b9e67834SAndre Fischer         }
116b9e67834SAndre Fischer         else if (rValue.Name.equalsAscii("SfxBindings"))
117b9e67834SAndre Fischer         {
118b9e67834SAndre Fischer             sal_uInt64 nValue;
119b9e67834SAndre Fischer             if (rValue.Value >>= nValue)
120b9e67834SAndre Fischer                 pBindings = reinterpret_cast<SfxBindings*>(nValue);
121b9e67834SAndre Fischer         }
122b9e67834SAndre Fischer     }
123b9e67834SAndre Fischer 
124b9e67834SAndre Fischer     ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
125b9e67834SAndre Fischer     if ( ! xParentWindow.is() || pParentWindow==NULL)
126b9e67834SAndre Fischer         throw RuntimeException(
127b9e67834SAndre Fischer             A2S("PanelFactory::createUIElement called without ParentWindow"),
128b9e67834SAndre Fischer             NULL);
129b9e67834SAndre Fischer     if ( ! xFrame.is())
130b9e67834SAndre Fischer         throw RuntimeException(
131b9e67834SAndre Fischer             A2S("PanelFactory::createUIElement called without Frame"),
132b9e67834SAndre Fischer             NULL);
133b9e67834SAndre Fischer     if (pBindings == NULL)
134b9e67834SAndre Fischer         throw RuntimeException(
135b9e67834SAndre Fischer             A2S("PanelFactory::createUIElement called without SfxBindings"),
136b9e67834SAndre Fischer             NULL);
137b9e67834SAndre Fischer 
138b9e67834SAndre Fischer     if (rsResourceURL.endsWithAsciiL("/TextPropertyPanel", strlen("/TextPropertyPanel")))
13995a18594SAndre Fischer     {
14095a18594SAndre Fischer         TextPropertyPanel* pPanel = TextPropertyPanel::Create(pParentWindow, xFrame, pBindings);
14195a18594SAndre Fischer         xElement = sfx2::sidebar::SidebarPanelBase::Create(
14295a18594SAndre Fischer             rsResourceURL,
14395a18594SAndre Fischer             xFrame,
14495a18594SAndre Fischer             pPanel);
14595a18594SAndre Fischer     }
146b9e67834SAndre Fischer 
147*66c1fc23SArmin Le Grand     if (rsResourceURL.endsWithAsciiL("/AreaPropertyPanel", strlen("/AreaPropertyPanel")))
148*66c1fc23SArmin Le Grand     {
149*66c1fc23SArmin Le Grand         AreaPropertyPanel* pPanel = AreaPropertyPanel::Create(pParentWindow, xFrame, pBindings);
150*66c1fc23SArmin Le Grand         xElement = sfx2::sidebar::SidebarPanelBase::Create(
151*66c1fc23SArmin Le Grand             rsResourceURL,
152*66c1fc23SArmin Le Grand             xFrame,
153*66c1fc23SArmin Le Grand             pPanel);
154*66c1fc23SArmin Le Grand     }
155*66c1fc23SArmin Le Grand 
156b9e67834SAndre Fischer     return xElement;
157b9e67834SAndre Fischer }
158b9e67834SAndre Fischer 
159b9e67834SAndre Fischer 
160b9e67834SAndre Fischer 
161b9e67834SAndre Fischer } } // end of namespace svx::sidebar
162