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_svx.hxx" 23 24 #include "InsertPropertyPanel.hxx" 25 #include "InsertPropertyPanel.hrc" 26 #include "sfx2/sidebar/CommandInfoProvider.hxx" 27 28 #include <sfx2/sidebar/Theme.hxx> 29 #include <sfx2/sidebar/Tools.hxx> 30 #include <sfx2/sidebar/ControlFactory.hxx> 31 #include <sfx2/sidebar/ControllerFactory.hxx> 32 33 #include <svx/dialmgr.hxx> 34 #include <svtools/miscopt.hxx> 35 #include <svtools/generictoolboxcontroller.hxx> 36 #include <vcl/toolbox.hxx> 37 #include <sfx2/tbxctrl.hxx> 38 #include <framework/sfxhelperfunctions.hxx> 39 #include <framework/imageproducer.hxx> 40 #include <comphelper/processfactory.hxx> 41 #include <cppuhelper/compbase1.hxx> 42 #include <cppuhelper/basemutex.hxx> 43 44 #include <com/sun/star/frame/XStatusListener.hpp> 45 46 using namespace css; 47 using namespace cssu; 48 using ::rtl::OUString; 49 using ::sfx2::sidebar::SidebarToolBox; 50 51 namespace svx { namespace sidebar { 52 53 54 InsertPropertyPanel::InsertPropertyPanel ( 55 Window* pParent, 56 const cssu::Reference<css::frame::XFrame>& rxFrame) 57 : Control(pParent, SVX_RES(RID_SIDEBAR_INSERT_PANEL)), 58 mpStandardShapesBackground(sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this)), 59 mpStandardShapesToolBox(sfx2::sidebar::ControlFactory::CreateToolBox( 60 mpStandardShapesBackground.get(), 61 SVX_RES(TB_INSERT_STANDARD), 62 rxFrame)), 63 mpCustomShapesBackground(sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this)), 64 mpCustomShapesToolBox(sfx2::sidebar::ControlFactory::CreateToolBox( 65 mpCustomShapesBackground.get(), 66 SVX_RES(TB_INSERT_CUSTOM), 67 rxFrame)), 68 mxFrame(rxFrame) 69 { 70 FreeResource(); 71 72 mpStandardShapesToolBox->Show(); 73 mpCustomShapesToolBox->Show(); 74 75 // Listen to all tool box selection events. 76 Window* pTopWindow = pParent; 77 while (pTopWindow->GetParent() != NULL) 78 pTopWindow = pTopWindow->GetParent(); 79 pTopWindow->AddChildEventListener(LINK(this, InsertPropertyPanel, WindowEventListener)); 80 } 81 82 83 84 85 InsertPropertyPanel::~InsertPropertyPanel (void) 86 { 87 // Remove window child listener. 88 Window* pTopWindow = this; 89 while (pTopWindow->GetParent() != NULL) 90 pTopWindow = pTopWindow->GetParent(); 91 pTopWindow->RemoveChildEventListener(LINK(this, InsertPropertyPanel, WindowEventListener)); 92 93 mpStandardShapesToolBox.reset(); 94 mpCustomShapesToolBox.reset(); 95 mpStandardShapesBackground.reset(); 96 mpCustomShapesBackground.reset(); 97 } 98 99 100 101 102 IMPL_LINK(InsertPropertyPanel, WindowEventListener, VclSimpleEvent*, pEvent) 103 { 104 // We will be getting a lot of window events (well, basically all 105 // of them), so reject early everything that is not connected to 106 // toolbox selection. 107 if (pEvent == NULL) 108 return 1; 109 if ( ! pEvent->ISA(VclWindowEvent)) 110 return 1; 111 if (pEvent->GetId() != VCLEVENT_TOOLBOX_SELECT) 112 return 1; 113 114 Window* pWindow = dynamic_cast<VclWindowEvent*>(pEvent)->GetWindow(); 115 Window* pParent = pWindow->GetParent(); 116 ToolBox* pToolBox = dynamic_cast<ToolBox*>(pWindow); 117 if (pToolBox == NULL) 118 return 1; 119 120 // Extract name of (sub)toolbar from help id. 121 OUString sToolbarName (rtl::OStringToOUString(pToolBox->GetHelpId(), RTL_TEXTENCODING_UTF8)); 122 if (sToolbarName.getLength() == 0) 123 return 1; 124 const util::URL aURL (sfx2::sidebar::Tools::GetURL(sToolbarName)); 125 if (aURL.Path.getLength() == 0) 126 return 1; 127 128 // Get item id. 129 sal_uInt16 nId = pToolBox->GetCurItemId(); 130 if (nId == 0) 131 return 1; 132 133 SidebarToolBox* pSidebarToolBox = dynamic_cast<SidebarToolBox*>(mpStandardShapesToolBox.get()); 134 if (pSidebarToolBox == NULL) 135 return 1; 136 sal_uInt16 nItemId (pSidebarToolBox->GetItemIdForSubToolbarName(aURL.Path)); 137 if (nItemId == 0) 138 { 139 pSidebarToolBox = dynamic_cast<SidebarToolBox*>(mpCustomShapesToolBox.get()); 140 if (pSidebarToolBox == NULL) 141 return 1; 142 nItemId = pSidebarToolBox->GetItemIdForSubToolbarName(aURL.Path); 143 if (nItemId == 0) 144 return 1; 145 } 146 147 Reference<frame::XSubToolbarController> xController (pSidebarToolBox->GetControllerForItemId(nItemId), UNO_QUERY); 148 if ( ! xController.is()) 149 return 1; 150 151 const OUString sCommand (pToolBox->GetItemCommand(nId)); 152 xController->functionSelected(sCommand); 153 154 return 1; 155 } 156 157 158 } } // end of namespace svx::sidebar 159