1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include "sidebar/PanelFactory.hxx"
23 
24 #include "text/TextPropertyPanel.hxx"
25 #include <sfx2/sidebar/SidebarPanelBase.hxx>
26 #include <sfx2/sfxbasecontroller.hxx>
27 #include <toolkit/helper/vclunohelper.hxx>
28 #include <vcl/window.hxx>
29 #include <rtl/ref.hxx>
30 
31 
32 using namespace css;
33 using namespace cssu;
34 using ::rtl::OUString;
35 
36 
37 namespace svx { namespace sidebar {
38 
39 #define A2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
40 #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.svx.sidebar.PanelFactory"
41 #define SERVICE_NAME "com.sun.star.ui.UIElementFactory"
42 
43 
44 ::rtl::OUString SAL_CALL PanelFactory::getImplementationName (void)
45 {
46     return A2S(IMPLEMENTATION_NAME);
47 }
48 
49 
50 
51 
52 cssu::Reference<cssu::XInterface> SAL_CALL PanelFactory::createInstance (
53     const uno::Reference<lang::XMultiServiceFactory>& rxFactory)
54 {
55     (void)rxFactory;
56 
57     ::rtl::Reference<PanelFactory> pPanelFactory (new PanelFactory());
58     cssu::Reference<cssu::XInterface> xService (static_cast<XWeak*>(pPanelFactory.get()), cssu::UNO_QUERY);
59     return xService;
60 }
61 
62 
63 
64 
65 cssu::Sequence<OUString> SAL_CALL PanelFactory::getSupportedServiceNames (void)
66 {
67     cssu::Sequence<OUString> aServiceNames (1);
68     aServiceNames[0] = A2S(SERVICE_NAME);
69     return aServiceNames;
70 
71 }
72 
73 
74 
75 
76 PanelFactory::PanelFactory (void)
77     : PanelFactoryInterfaceBase(m_aMutex)
78 {
79 }
80 
81 
82 
83 
84 PanelFactory::~PanelFactory (void)
85 {
86 }
87 
88 
89 
90 
91 Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
92     const ::rtl::OUString& rsResourceURL,
93     const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
94     throw(
95         container::NoSuchElementException,
96         lang::IllegalArgumentException,
97         RuntimeException)
98 {
99     Reference<ui::XUIElement> xElement;
100     Reference<awt::XWindow> xParentWindow;
101     Reference<frame::XFrame> xFrame;
102     SfxBindings* pBindings = NULL;
103 
104     for (sal_Int32 nIndex(0),nCount(rArguments.getLength()); nIndex<nCount; ++nIndex)
105     {
106         const beans::PropertyValue& rValue (rArguments[nIndex]);
107         if (rValue.Name.equalsAscii("ParentWindow"))
108         {
109             xParentWindow = Reference<awt::XWindow>(rValue.Value, UNO_QUERY);
110         }
111         else if (rValue.Name.equalsAscii("Frame"))
112         {
113             xFrame = Reference<frame::XFrame>(rValue.Value, UNO_QUERY);
114         }
115         else if (rValue.Name.equalsAscii("SfxBindings"))
116         {
117             sal_uInt64 nValue;
118             if (rValue.Value >>= nValue)
119                 pBindings = reinterpret_cast<SfxBindings*>(nValue);
120         }
121     }
122 
123     ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
124     if ( ! xParentWindow.is() || pParentWindow==NULL)
125         throw RuntimeException(
126             A2S("PanelFactory::createUIElement called without ParentWindow"),
127             NULL);
128     if ( ! xFrame.is())
129         throw RuntimeException(
130             A2S("PanelFactory::createUIElement called without Frame"),
131             NULL);
132     if (pBindings == NULL)
133         throw RuntimeException(
134             A2S("PanelFactory::createUIElement called without SfxBindings"),
135             NULL);
136 
137     if (rsResourceURL.endsWithAsciiL("/TextPropertyPanel", strlen("/TextPropertyPanel")))
138     {
139         TextPropertyPanel* pPanel = TextPropertyPanel::Create(pParentWindow, xFrame, pBindings);
140         xElement = sfx2::sidebar::SidebarPanelBase::Create(
141             rsResourceURL,
142             xFrame,
143             pPanel);
144     }
145 
146     return xElement;
147 }
148 
149 
150 
151 } } // end of namespace svx::sidebar
152