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