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 "PanelFactory.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 "SlideTransitionPanel.hxx" 34 #include "NavigatorWrapper.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 { 50 extern ::Window * createTableDesignPanel (::Window* pParent, ViewShellBase& rBase); 51 } 52 53 namespace sd { namespace sidebar { 54 55 namespace { 56 /** Note that these names have to be identical to (the tail of) 57 the entries in officecfg/registry/data/org/openoffice/Office/Impress.xcu 58 for the TaskPanelFactory. 59 */ 60 const static char* gsResourceNameCustomAnimations = "/CustomAnimations"; 61 const static char* gsResourceNameLayouts = "/Layouts"; 62 const static char* gsResourceNameAllMasterPages = "/AllMasterPages"; 63 const static char* gsResourceNameRecentMasterPages = "/RecentMasterPages"; 64 const static char* gsResourceNameUsedMasterPages = "/UsedMasterPages"; 65 const static char* gsResourceNameSlideTransitions = "/SlideTransitions"; 66 const static char* gsResourceNameTableDesign = "/TableDesign"; 67 const static char* gsResourceNameNavigator = "/NavigatorPanel"; 68 } 69 70 Reference<lang::XEventListener> mxControllerDisposeListener; 71 72 73 74 // ----- Service functions ---------------------------------------------------- 75 76 Reference<XInterface> SAL_CALL PanelFactory_createInstance ( 77 const Reference<XComponentContext>& rxContext) 78 { 79 return Reference<XInterface>(static_cast<XWeak*>(new PanelFactory(rxContext))); 80 } 81 82 83 84 85 ::rtl::OUString PanelFactory_getImplementationName (void) 86 { 87 return ::rtl::OUString( 88 RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.Draw.framework.PanelFactory")); 89 } 90 91 92 93 94 Sequence<rtl::OUString> SAL_CALL PanelFactory_getSupportedServiceNames (void) 95 { 96 static const ::rtl::OUString sServiceName( 97 ::rtl::OUString::createFromAscii("com.sun.star.drawing.framework.PanelFactory")); 98 return Sequence<rtl::OUString>(&sServiceName, 1); 99 } 100 101 102 103 104 //----- PanelFactory -------------------------------------------------------- 105 106 PanelFactory::PanelFactory( 107 const css::uno::Reference<css::uno::XComponentContext>& rxContext) 108 : PanelFactoryInterfaceBase(m_aMutex) 109 { 110 } 111 112 113 114 115 PanelFactory::~PanelFactory (void) 116 { 117 } 118 119 120 121 122 void SAL_CALL PanelFactory::disposing (void) 123 { 124 } 125 126 127 128 129 // XUIElementFactory 130 131 Reference<ui::XUIElement> SAL_CALL PanelFactory::createUIElement ( 132 const ::rtl::OUString& rsUIElementResourceURL, 133 const ::cssu::Sequence<css::beans::PropertyValue>& rArguments) 134 { 135 // Process arguments. 136 const ::comphelper::NamedValueCollection aArguments (rArguments); 137 Reference<frame::XFrame> xFrame (aArguments.getOrDefault("Frame", Reference<frame::XFrame>())); 138 Reference<awt::XWindow> xParentWindow (aArguments.getOrDefault("ParentWindow", Reference<awt::XWindow>())); 139 Reference<ui::XSidebar> xSidebar (aArguments.getOrDefault("Sidebar", Reference<ui::XSidebar>())); 140 141 // Throw exceptions when the arguments are not as expected. 142 ::Window* pParentWindow = VCLUnoHelper::GetWindow(xParentWindow); 143 if ( ! xParentWindow.is() || pParentWindow==NULL) 144 throw RuntimeException( 145 A2S("PanelFactory::createUIElement called without ParentWindow"), 146 NULL); 147 if ( ! xFrame.is()) 148 throw RuntimeException( 149 A2S("PanelFactory::createUIElement called without XFrame"), 150 NULL); 151 152 // Tunnel through the controller to obtain a ViewShellBase. 153 ViewShellBase* pBase = NULL; 154 Reference<lang::XUnoTunnel> xTunnel (xFrame->getController(), UNO_QUERY); 155 if (xTunnel.is()) 156 { 157 ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>( 158 xTunnel->getSomething(sd::DrawController::getUnoTunnelId())); 159 if (pController != NULL) 160 pBase = pController->GetViewShellBase(); 161 } 162 if (pBase == NULL) 163 throw RuntimeException(A2S("can not get ViewShellBase for frame"), NULL); 164 165 // Get bindings from given arguments. 166 const sal_uInt64 nBindingsValue (aArguments.getOrDefault("SfxBindings", sal_uInt64(0))); 167 SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue); 168 169 // Create a framework view. 170 ::Window* pControl = NULL; 171 css::ui::LayoutSize aLayoutSize (-1,-1,-1); 172 173 #define EndsWith(s,t) s.endsWithAsciiL(t,strlen(t)) 174 if (EndsWith(rsUIElementResourceURL, gsResourceNameCustomAnimations)) 175 pControl = new CustomAnimationPanel(pParentWindow, *pBase); 176 else if (EndsWith(rsUIElementResourceURL, gsResourceNameLayouts)) 177 pControl = new LayoutMenu(pParentWindow, *pBase, xSidebar); 178 else if (EndsWith(rsUIElementResourceURL, gsResourceNameAllMasterPages)) 179 pControl = AllMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar); 180 else if (EndsWith(rsUIElementResourceURL, gsResourceNameRecentMasterPages)) 181 pControl = RecentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar); 182 else if (EndsWith(rsUIElementResourceURL, gsResourceNameUsedMasterPages)) 183 pControl = CurrentMasterPagesSelector::Create(pParentWindow, *pBase, xSidebar); 184 else if (EndsWith(rsUIElementResourceURL, gsResourceNameSlideTransitions)) 185 pControl = new SlideTransitionPanel(pParentWindow, *pBase); 186 else if (EndsWith(rsUIElementResourceURL, gsResourceNameTableDesign)) 187 pControl = createTableDesignPanel(pParentWindow, *pBase); 188 else if (EndsWith(rsUIElementResourceURL, gsResourceNameNavigator)) 189 pControl = new NavigatorWrapper(pParentWindow, *pBase, pBindings); 190 #undef EndsWith 191 192 if (pControl == NULL) 193 throw lang::IllegalArgumentException(); 194 195 // Create a wrapper around the control that implements the 196 // necessary UNO interfaces. 197 return sfx2::sidebar::SidebarPanelBase::Create( 198 rsUIElementResourceURL, 199 xFrame, 200 pControl, 201 aLayoutSize); 202 } 203 204 205 206 207 } } // end of namespace sd::sidebar 208