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 122 ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); 123 if ( ! xParentWindow.is() || pParentWindow==NULL) 124 throw RuntimeException( 125 A2S("PanelFactory::createUIElement called without ParentWindow"), 126 NULL); 127 if ( ! xFrame.is()) 128 throw RuntimeException( 129 A2S("PanelFactory::createUIElement called without Frame"), 130 NULL); 131 if (pBindings == NULL) 132 throw RuntimeException( 133 A2S("PanelFactory::createUIElement called without SfxBindings"), 134 NULL); 135 136 Window* pControl = NULL; 137 ui::LayoutSize aLayoutSize (-1,-1,-1); 138 139 #define DoesResourceEndWith(s) rsResourceURL.endsWithAsciiL(s,strlen(s)) 140 if (DoesResourceEndWith("/TextPropertyPanel")) 141 { 142 pControl = TextPropertyPanel::Create(pParentWindow, xFrame, pBindings); 143 } 144 else if (DoesResourceEndWith("/ParaPropertyPanel")) 145 { 146 pControl = ParaPropertyPanel::Create(pParentWindow, xFrame, pBindings, xSidebar); 147 } 148 else if (DoesResourceEndWith("/AreaPropertyPanel")) 149 { 150 pControl = AreaPropertyPanel::Create(pParentWindow, xFrame, pBindings); 151 } 152 else if (DoesResourceEndWith("/GraphicPropertyPanel")) 153 { 154 pControl = GraphicPropertyPanel::Create(pParentWindow, xFrame, pBindings); 155 } 156 else if (DoesResourceEndWith("/LinePropertyPanel")) 157 { 158 pControl = LinePropertyPanel::Create(pParentWindow, xFrame, pBindings); 159 } 160 else if (DoesResourceEndWith("/PosSizePropertyPanel")) 161 { 162 pControl = PosSizePropertyPanel::Create(pParentWindow, xFrame, pBindings, xSidebar); 163 } 164 else if (DoesResourceEndWith("/InsertPropertyPanel")) 165 { 166 pControl = new InsertPropertyPanel(pParentWindow, xFrame); 167 } 168 else if (DoesResourceEndWith("/GalleryPanel")) 169 { 170 pControl = new GalleryControl(pBindings, pParentWindow); 171 aLayoutSize = ui::LayoutSize(300,-1,400); 172 } 173 else if (DoesResourceEndWith("/StyleListPanel")) 174 { 175 pControl = new SfxTemplatePanelControl(pBindings, pParentWindow); 176 aLayoutSize = ui::LayoutSize(0,-1,-1); 177 } 178 else if (DoesResourceEndWith("/Debug_ColorPanel")) 179 { 180 pControl = new ColorPanel(pParentWindow); 181 aLayoutSize = ui::LayoutSize(300,-1,400); 182 } 183 else if (DoesResourceEndWith("/Debug_ContextPanel")) 184 { 185 pControl = new ContextPanel(pParentWindow); 186 aLayoutSize = ui::LayoutSize(45,45,45); 187 } 188 else if (DoesResourceEndWith("/Debug_NotYetImplementedPanel")) 189 { 190 pControl = new NotYetImplementedPanel(pParentWindow); 191 aLayoutSize = ui::LayoutSize(20,25,25); 192 } 193 else if (DoesResourceEndWith("/EmptyPanel")) 194 { 195 pControl = new EmptyPanel(pParentWindow); 196 aLayoutSize = ui::LayoutSize(20,-1, 50); 197 } 198 #undef DoesResourceEndWith 199 200 if (pControl != NULL) 201 { 202 return sfx2::sidebar::SidebarPanelBase::Create( 203 rsResourceURL, 204 xFrame, 205 pControl, 206 aLayoutSize); 207 } 208 else 209 return Reference<ui::XUIElement>(); 210 } 211 212 } } // end of namespace svx::sidebar 213 214 // eof 215