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 
26 #include <toolkit/helper/vclunohelper.hxx>
27 #include <vcl/window.hxx>
28 #include <sfx2/sfxbasecontroller.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     throw(uno::Exception)
55 {
56     (void)rxFactory;
57 
58     ::rtl::Reference<PanelFactory> pPanelFactory (new PanelFactory());
59     cssu::Reference<cssu::XInterface> xService (static_cast<XWeak*>(pPanelFactory.get()), cssu::UNO_QUERY);
60     return xService;
61 }
62 
63 
64 
65 
66 cssu::Sequence<OUString> SAL_CALL PanelFactory::getSupportedServiceNames (void)
67 {
68     cssu::Sequence<OUString> aServiceNames (1);
69     aServiceNames[0] = A2S(SERVICE_NAME);
70     return aServiceNames;
71 
72 }
73 
74 
75 
76 
77 PanelFactory::PanelFactory (void)
78     : PanelFactoryInterfaceBase(m_aMutex)
79 {
80 }
81 
82 
83 
84 
85 PanelFactory::~PanelFactory (void)
86 {
87 }
88 
89 
90 
91 
92 Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement (
93     const ::rtl::OUString& rsResourceURL,
94     const ::cssu::Sequence<css::beans::PropertyValue>& rArguments)
95     throw(
96         container::NoSuchElementException,
97         lang::IllegalArgumentException,
98         RuntimeException)
99 {
100     Reference<ui::XUIElement> xElement;
101     Reference<awt::XWindow> xParentWindow;
102     Reference<frame::XFrame> xFrame;
103     SfxBindings* pBindings = NULL;
104 
105     for (sal_Int32 nIndex(0),nCount(rArguments.getLength()); nIndex<nCount; ++nIndex)
106     {
107         const beans::PropertyValue& rValue (rArguments[nIndex]);
108         if (rValue.Name.equalsAscii("ParentWindow"))
109         {
110             xParentWindow = Reference<awt::XWindow>(rValue.Value, UNO_QUERY);
111         }
112         else if (rValue.Name.equalsAscii("Frame"))
113         {
114             xFrame = Reference<frame::XFrame>(rValue.Value, UNO_QUERY);
115         }
116         else if (rValue.Name.equalsAscii("SfxBindings"))
117         {
118             sal_uInt64 nValue;
119             if (rValue.Value >>= nValue)
120                 pBindings = reinterpret_cast<SfxBindings*>(nValue);
121         }
122     }
123 
124     ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
125     if ( ! xParentWindow.is() || pParentWindow==NULL)
126         throw RuntimeException(
127             A2S("PanelFactory::createUIElement called without ParentWindow"),
128             NULL);
129     if ( ! xFrame.is())
130         throw RuntimeException(
131             A2S("PanelFactory::createUIElement called without Frame"),
132             NULL);
133     if (pBindings == NULL)
134         throw RuntimeException(
135             A2S("PanelFactory::createUIElement called without SfxBindings"),
136             NULL);
137 
138     if (rsResourceURL.endsWithAsciiL("/TextPropertyPanel", strlen("/TextPropertyPanel")))
139         xElement = TextPropertyPanel::Create(rsResourceURL, pParentWindow, xFrame, pBindings);
140 
141     return xElement;
142 }
143 
144 
145 
146 } } // end of namespace svx::sidebar
147