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 "paragraph/ParaPropertyPanel.hxx" 26 #include "area/AreaPropertyPanel.hxx" 27 #include "graphic/GraphicPropertyPanel.hxx" 28 #include "line/LinePropertyPanel.hxx" 29 #include "possize/PosSizePropertyPanel.hxx" 30 #include "insert/InsertPropertyPanel.hxx" 31 #include "GalleryControl.hxx" 32 #include "debug/ColorPanel.hxx" 33 #include "debug/ContextPanel.hxx" 34 #include "debug/NotYetImplementedPanel.hxx" 35 #include "EmptyPanel.hxx" 36 #include <sfx2/sidebar/SidebarPanelBase.hxx> 37 #include <sfx2/sfxbasecontroller.hxx> 38 #include <sfx2/templdlg.hxx> 39 #include <toolkit/helper/vclunohelper.hxx> 40 #include <vcl/window.hxx> 41 #include <rtl/ref.hxx> 42 #include <comphelper/namedvaluecollection.hxx> 43 #include <com/sun/star/ui/XSidebar.hpp> 44 45 #include <boost/bind.hpp> 46 47 48 using namespace css; 49 using namespace cssu; 50 using ::rtl::OUString; 51 52 53 namespace svx { namespace sidebar { 54 55 #define A2S(s) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)) 56 #define IMPLEMENTATION_NAME "org.apache.openoffice.comp.svx.sidebar.PanelFactory" 57 #define SERVICE_NAME "com.sun.star.ui.UIElementFactory" 58 59 60 ::rtl::OUString SAL_CALL PanelFactory::getImplementationName (void) 61 { 62 return A2S(IMPLEMENTATION_NAME); 63 } 64 65 66 67 68 cssu::Reference<cssu::XInterface> SAL_CALL PanelFactory::createInstance ( 69 const uno::Reference<lang::XMultiServiceFactory>& rxFactory) 70 { 71 (void)rxFactory; 72 73 ::rtl::Reference<PanelFactory> pPanelFactory (new PanelFactory()); 74 cssu::Reference<cssu::XInterface> xService (static_cast<XWeak*>(pPanelFactory.get()), cssu::UNO_QUERY); 75 return xService; 76 } 77 78 79 80 81 cssu::Sequence<OUString> SAL_CALL PanelFactory::getSupportedServiceNames (void) 82 { 83 cssu::Sequence<OUString> aServiceNames (1); 84 aServiceNames[0] = A2S(SERVICE_NAME); 85 return aServiceNames; 86 87 } 88 89 90 91 92 PanelFactory::PanelFactory (void) 93 : PanelFactoryInterfaceBase(m_aMutex) 94 { 95 } 96 97 98 99 100 PanelFactory::~PanelFactory (void) 101 { 102 } 103 104 105 106 107 Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement ( 108 const ::rtl::OUString& rsResourceURL, 109 const ::cssu::Sequence<css::beans::PropertyValue>& rArguments) 110 throw( 111 container::NoSuchElementException, 112 lang::IllegalArgumentException, 113 RuntimeException) 114 { 115 const ::comphelper::NamedValueCollection aArguments (rArguments); 116 Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>())); 117 Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>())); 118 Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>())); 119 const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0))); 120 SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue); 121 ::sfx2::sidebar::EnumContext aContext ( 122 aArguments.getOrDefault("ApplicationName", OUString()), 123 aArguments.getOrDefault("ContextName", OUString())); 124 125 ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); 126 if ( ! xParentWindow.is() || pParentWindow==NULL) 127 throw RuntimeException( 128 A2S("PanelFactory::createUIElement called without ParentWindow"), 129 NULL); 130 if ( ! xFrame.is()) 131 throw RuntimeException( 132 A2S("PanelFactory::createUIElement called without Frame"), 133 NULL); 134 if (pBindings == NULL) 135 throw RuntimeException( 136 A2S("PanelFactory::createUIElement called without SfxBindings"), 137 NULL); 138 139 Window* pControl = NULL; 140 ui::LayoutSize aLayoutSize (-1,-1,-1); 141 142 #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s)) 143 if (DoesResourceEndWith("/TextPropertyPanel")) 144 { 145 pControl = TextPropertyPanel::Create(pParentWindow, xFrame, pBindings, aContext); 146 } 147 else if (DoesResourceEndWith("/ParaPropertyPanel")) 148 { 149 pControl = ParaPropertyPanel::Create(pParentWindow, xFrame, pBindings, xSidebar); 150 } 151 else if (DoesResourceEndWith("/AreaPropertyPanel")) 152 { 153 pControl = AreaPropertyPanel::Create(pParentWindow, xFrame, pBindings); 154 } 155 else if (DoesResourceEndWith("/GraphicPropertyPanel")) 156 { 157 pControl = GraphicPropertyPanel::Create(pParentWindow, xFrame, pBindings); 158 } 159 else if (DoesResourceEndWith("/LinePropertyPanel")) 160 { 161 pControl = LinePropertyPanel::Create(pParentWindow, xFrame, pBindings); 162 } 163 else if (DoesResourceEndWith("/PosSizePropertyPanel")) 164 { 165 pControl = PosSizePropertyPanel::Create(pParentWindow, xFrame, pBindings, xSidebar); 166 } 167 else if (DoesResourceEndWith("/InsertPropertyPanel")) 168 { 169 pControl = new InsertPropertyPanel(pParentWindow, xFrame); 170 } 171 else if (DoesResourceEndWith("/GalleryPanel")) 172 { 173 pControl = new GalleryControl(pBindings, pParentWindow); 174 aLayoutSize = ui::LayoutSize(300,-1,400); 175 } 176 else if (DoesResourceEndWith("/StyleListPanel")) 177 { 178 pControl = new SfxTemplatePanelControl(pBindings, pParentWindow); 179 aLayoutSize = ui::LayoutSize(0,-1,-1); 180 } 181 else if (DoesResourceEndWith("/Debug_ColorPanel")) 182 { 183 pControl = new ColorPanel(pParentWindow); 184 aLayoutSize = ui::LayoutSize(300,-1,400); 185 } 186 else if (DoesResourceEndWith("/Debug_ContextPanel")) 187 { 188 pControl = new ContextPanel(pParentWindow); 189 aLayoutSize = ui::LayoutSize(45,45,45); 190 } 191 else if (DoesResourceEndWith("/Debug_NotYetImplementedPanel")) 192 { 193 pControl = new NotYetImplementedPanel(pParentWindow); 194 aLayoutSize = ui::LayoutSize(20,25,25); 195 } 196 else if (DoesResourceEndWith("/EmptyPanel")) 197 { 198 pControl = new EmptyPanel(pParentWindow); 199 aLayoutSize = ui::LayoutSize(20,-1, 50); 200 } 201 #undef DoesResourceEndWith 202 203 if (pControl != NULL) 204 { 205 return sfx2::sidebar::SidebarPanelBase::Create( 206 rsResourceURL, 207 xFrame, 208 pControl, 209 aLayoutSize); 210 } 211 else 212 return Reference<ui::XUIElement>(); 213 } 214 215 } } // end of namespace svx::sidebar 216 217 // eof 218