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 "precompiled_sd.hxx" 23 24 #include "SidebarFactory.hxx" 25 #include "framework/Pane.hxx" 26 #include "ViewShellBase.hxx" 27 #include "DrawController.hxx" 28 #include "LayoutMenu.hxx" 29 #include "CurrentMasterPagesSelector.hxx" 30 #include "RecentMasterPagesSelector.hxx" 31 #include "AllMasterPagesSelector.hxx" 32 #include "CustomAnimationPanel.hxx" 33 #include "TableDesignPanel.hxx" 34 #include "SlideTransitionPanel.hxx" 35 36 #include <sfx2/viewfrm.hxx> 37 #include <sfx2/sidebar/SidebarPanelBase.hxx> 38 #include <comphelper/namedvaluecollection.hxx> 39 #include <vcl/window.hxx> 40 #include <toolkit/helper/vclunohelper.hxx> 41 42 using namespace css; 43 using namespace cssu; 44 using namespace ::sd::framework; 45 using ::rtl::OUString; 46 47 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString))) 48 49 namespace sd { namespace sidebar { 50 51 namespace { 52 /** Note that these names have to be identical to (the tail of) 53 the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu 54 for the TaskPanelFactory. 55 */ 56 const static char* gsResourceNameCustomAnimations = "/CustomAnimations"; 57 const static char* gsResourceNameLayouts = "/Layouts"; 58 const static char* gsResourceNameAllMasterPages = "/AllMasterPages"; 59 const static char* gsResourceNameRecentMasterPages = "/RecentMasterPages"; 60 const static char* gsResourceNameUsedMasterPages = "/UsedMasterPages"; 61 const static char* gsResourceNameSlideTransitions = "/SlideTransitions"; 62 const static char* gsResourceNameTableDesign = "/TableDesign"; 63 } 64 65 Reference<lang::XEventListener> mxControllerDisposeListener; 66 67 68 69 // ----- Service functions ---------------------------------------------------- 70 71 Reference<XInterface> SAL_CALL SidebarFactory_createInstance ( 72 const Reference<XComponentContext>& rxContext) 73 { 74 return Reference<XInterface>(static_cast<XWeak*>(new SidebarFactory(rxContext))); 75 } 76 77 78 79 80 ::rtl::OUString SidebarFactory_getImplementationName (void) throw(RuntimeException) 81 { 82 return ::rtl::OUString( 83 RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.Draw.framework.SidebarFactory")); 84 } 85 86 87 88 89 Sequence<rtl::OUString> SAL_CALL SidebarFactory_getSupportedServiceNames (void) 90 throw (RuntimeException) 91 { 92 static const ::rtl::OUString sServiceName( 93 ::rtl::OUString::createFromAscii("com.sun.star.drawing.framework.SidebarFactory")); 94 return Sequence<rtl::OUString>(&sServiceName, 1); 95 } 96 97 98 99 100 //----- SidebarFactory -------------------------------------------------------- 101 102 SidebarFactory::SidebarFactory( 103 const css::uno::Reference<css::uno::XComponentContext>& rxContext) 104 : SidebarFactoryInterfaceBase(m_aMutex) 105 { 106 } 107 108 109 110 111 SidebarFactory::~SidebarFactory (void) 112 { 113 } 114 115 116 117 118 void SAL_CALL SidebarFactory::disposing (void) 119 { 120 } 121 122 123 124 125 // XInitialization 126 127 void SAL_CALL SidebarFactory::initialize (const Sequence<Any>& aArguments) 128 throw (Exception, RuntimeException) 129 { 130 } 131 132 133 134 135 // XUIElementFactory 136 137 Reference<ui::XUIElement> SAL_CALL SidebarFactory::createUIElement ( 138 const ::rtl::OUString& rsUIElementResourceURL, 139 const ::cssu::Sequence<css::beans::PropertyValue>& rArguments) 140 throw( 141 css::container::NoSuchElementException, 142 css::lang::IllegalArgumentException, 143 cssu::RuntimeException) 144 { 145 // Process arguments. 146 const ::comphelper::NamedValueCollection aArguments (rArguments); 147 Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>())); 148 Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>())); 149 Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>())); 150 151 // Throw exceptions when the arguments are not as expected. 152 ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); 153 if ( ! xParentWindow.is() || pParentWindow==NULL) 154 throw RuntimeException( 155 A2S("SidebarFactory::createUIElement called without ParentWindow"), 156 NULL); 157 if ( ! xFrame.is()) 158 throw RuntimeException( 159 A2S("SidebarFactory::createUIElement called without XFrame"), 160 NULL); 161 162 // Tunnel through the controller to obtain a ViewShellBase. 163 ViewShellBase* pBase = NULL; 164 Reference<lang::XUnoTunnel> xTunnel (xFrame->getController(), UNO_QUERY); 165 if (xTunnel.is()) 166 { 167 ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>( 168 xTunnel->getSomething(sd::DrawController::getUnoTunnelId())); 169 if (pController != NULL) 170 pBase = pController->GetViewShellBase(); 171 } 172 if (pBase == NULL) 173 throw RuntimeException(A2S("can not get ViewShellBase for frame"), NULL); 174 175 // Create a framework view. 176 ::Window* pControl = NULL; 177 178 #define EndsWith(s,t) s.endsWithAsciiL(t,strlen(t)) 179 if (EndsWith(rsUIElementResourceURL, gsResourceNameCustomAnimations)) 180 pControl = new CustomAnimationPanel(pParentWindow, *pBase); 181 else if (EndsWith(rsUIElementResourceURL, gsResourceNameLayouts)) 182 pControl = new LayoutMenu(pParentWindow, *pBase, xSidebar); 183 else if (EndsWith(rsUIElementResourceURL, gsResourceNameAllMasterPages)) 184 pControl = AllMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar); 185 else if (EndsWith(rsUIElementResourceURL, gsResourceNameRecentMasterPages)) 186 pControl = RecentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar); 187 else if (EndsWith(rsUIElementResourceURL, gsResourceNameUsedMasterPages)) 188 pControl = CurrentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar); 189 else if (EndsWith(rsUIElementResourceURL, gsResourceNameSlideTransitions)) 190 pControl = new SlideTransitionPanel(pParentWindow, *pBase); 191 else if (EndsWith(rsUIElementResourceURL, gsResourceNameTableDesign)) 192 pControl = new TableDesignPanel(pParentWindow, *pBase); 193 #undef EndsWith 194 195 if (pControl == NULL) 196 throw lang::IllegalArgumentException(); 197 198 // Create a wrapper around pane and view and return it as 199 // XUIElement. 200 Reference<ui::XUIElement> xUIElement; 201 try 202 { 203 xUIElement.set( 204 sfx2::sidebar::SidebarPanelBase::Create( 205 rsUIElementResourceURL, 206 xFrame, 207 pControl, 208 ::boost::function<void(void)>(), 209 ui::LayoutSize(-1,-1,-1))); 210 } 211 catch(Exception& rException) 212 { 213 // Creation of XUIElement failed. mxUIElement remains empty. 214 } 215 216 Reference<lang::XComponent> xComponent (xUIElement, UNO_QUERY); 217 if (xComponent.is()) 218 xComponent->addEventListener(this); 219 220 return xUIElement; 221 } 222 223 224 225 226 void SAL_CALL SidebarFactory::disposing (const ::css::lang::EventObject& rEvent) 227 throw(cssu::RuntimeException) 228 { 229 /* 230 if (mpImplementation 231 && rEvent.Source == mpImplementation->mxUIElement) 232 { 233 mpImplementation->mxUIElement.clear(); 234 } 235 */ 236 } 237 238 239 240 241 } } // end of namespace sd::sidebar 242