/************************************************************** * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * *************************************************************/ #include "precompiled_svx.hxx" #include "InsertPropertyPanel.hxx" #include "InsertPropertyPanel.hrc" #include "sfx2/sidebar/CommandInfoProvider.hxx" #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace css; using namespace cssu; using ::rtl::OUString; namespace svx { namespace sidebar { InsertPropertyPanel::InsertPropertyPanel ( Window* pParent, const cssu::Reference& rxFrame) : Control(pParent, SVX_RES(RID_SIDEBAR_INSERT_PANEL)), mpStandardShapesBackground(sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this)), mpStandardShapesToolBox(sfx2::sidebar::ControlFactory::CreateToolBox( mpStandardShapesBackground.get(), SVX_RES(TB_INSERT_STANDARD))), mpCustomShapesBackground(sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this)), mpCustomShapesToolBox(sfx2::sidebar::ControlFactory::CreateToolBox( mpCustomShapesBackground.get(), SVX_RES(TB_INSERT_CUSTOM))), maControllers(), mxFrame(rxFrame) { SetupToolBox(*mpStandardShapesToolBox); SetupToolBox(*mpCustomShapesToolBox); FreeResource(); UpdateIcons(); mpStandardShapesToolBox->Show(); mpCustomShapesToolBox->Show(); // Listen to all tool box selection events. Window* pTopWindow = pParent; while (pTopWindow->GetParent() != NULL) pTopWindow = pTopWindow->GetParent(); pTopWindow->AddChildEventListener(LINK(this, InsertPropertyPanel, WindowEventListener)); } InsertPropertyPanel::~InsertPropertyPanel (void) { ControllerContainer aControllers; aControllers.swap(maControllers); for (ControllerContainer::iterator iController(aControllers.begin()), iEnd(aControllers.end()); iController!=iEnd; ++iController) { Reference xComponent (iController->second.mxController, UNO_QUERY); if (xComponent.is()) xComponent->dispose(); } // Remove window child listener. Window* pTopWindow = this; while (pTopWindow->GetParent() != NULL) pTopWindow = pTopWindow->GetParent(); pTopWindow->RemoveChildEventListener(LINK(this, InsertPropertyPanel, WindowEventListener)); mpStandardShapesToolBox.reset(); mpCustomShapesToolBox.reset(); mpStandardShapesBackground.reset(); mpCustomShapesBackground.reset(); } void InsertPropertyPanel::SetupToolBox (ToolBox& rToolBox) { const sal_uInt16 nItemCount (rToolBox.GetItemCount()); for (sal_uInt16 nItemIndex=0; nItemIndex xController (GetControllerForItemId(pToolBox->GetCurItemId())); if (xController.is()) { Reference xWindow = xController->createPopupWindow(); if (xWindow.is() ) xWindow->setFocus(); } } return 1; } IMPL_LINK(InsertPropertyPanel, ClickHandler, ToolBox*, pToolBox) { if (pToolBox == NULL) return 0; Reference xController (GetControllerForItemId(pToolBox->GetCurItemId())); if (xController.is()) xController->click(); return 1; } IMPL_LINK(InsertPropertyPanel, DoubleClickHandler, ToolBox*, pToolBox) { if (pToolBox == NULL) return 0; Reference xController (GetControllerForItemId(pToolBox->GetCurItemId())); if (xController.is()) xController->doubleClick(); return 1; } IMPL_LINK(InsertPropertyPanel, SelectHandler, ToolBox*, pToolBox) { if (pToolBox == NULL) return 0; Reference xController (GetControllerForItemId(pToolBox->GetCurItemId())); if (xController.is()) xController->execute((sal_Int16)pToolBox->GetModifier()); return 1; } IMPL_LINK(InsertPropertyPanel, WindowEventListener, VclSimpleEvent*, pEvent) { // We will be getting a lot of window events (well, basically all // of them), so reject early everything that is not connected to // toolbox selection. if (pEvent == NULL) return 1; if ( ! pEvent->ISA(VclWindowEvent)) return 1; if (pEvent->GetId() != VCLEVENT_TOOLBOX_SELECT) return 1; ToolBox* pToolBox = dynamic_cast(dynamic_cast(pEvent)->GetWindow()); if (pToolBox == NULL) return 1; // Extract name of (sub)toolbar from help id. OUString sToolbarName (rtl::OStringToOUString(pToolBox->GetHelpId(), RTL_TEXTENCODING_UTF8)); if (sToolbarName.getLength() == 0) return 1; const util::URL aURL (sfx2::sidebar::Tools::GetURL(sToolbarName)); if (aURL.Path.getLength() == 0) return 1; // Get item id. sal_uInt16 nId = pToolBox->GetCurItemId(); if (nId == 0) return 1; // Get toolbar controller. const sal_uInt16 nItemId (GetItemIdForSubToolbarName(aURL.Path)); Reference xController (GetControllerForItemId(nItemId), UNO_QUERY); if ( ! xController.is()) return 1; const OUString sCommand (pToolBox->GetItemCommand(nId)); ControllerContainer::iterator iController (maControllers.find(nItemId)); if (iController != maControllers.end()) iController->second.msCurrentCommand = sCommand; xController->functionSelected(sCommand); const sal_Bool bBigImages (SvtMiscOptions().AreCurrentSymbolsLarge()); const bool bIsHighContrastActive (sfx2::sidebar::Theme::IsHighContrastMode()); Image aImage (framework::GetImageFromURL(mxFrame, sCommand, bBigImages, bIsHighContrastActive)); pToolBox->SetItemImage(iController->first, aImage); return 1; } IMPL_LINK(InsertPropertyPanel, Activate, ToolBox*, EMPTYARG) { return 1; } IMPL_LINK(InsertPropertyPanel, Deactivate, ToolBox*, EMPTYARG) { return 1; } void InsertPropertyPanel::CreateController ( const sal_uInt16 nItemId) { ToolBox* pToolBox = GetToolBoxForItemId(nItemId); if (pToolBox != NULL) { ItemDescriptor aDescriptor; const OUString sCommandName (pToolBox->GetItemCommand(nItemId)); // Create a controller for the new item. aDescriptor.mxController.set( static_cast(::framework::CreateToolBoxController( mxFrame, pToolBox, nItemId, sCommandName)), UNO_QUERY); if ( ! aDescriptor.mxController.is()) aDescriptor.mxController.set( static_cast(new svt::GenericToolboxController( ::comphelper::getProcessServiceFactory(), mxFrame, pToolBox, nItemId, sCommandName)), UNO_QUERY); if ( ! aDescriptor.mxController.is()) return; // Get dispatch object for the command. aDescriptor.maURL = sfx2::sidebar::Tools::GetURL(sCommandName); aDescriptor.msCurrentCommand = sCommandName; aDescriptor.mxDispatch = sfx2::sidebar::Tools::GetDispatch(mxFrame, aDescriptor.maURL); if ( ! aDescriptor.mxDispatch.is()) return; // Initialize the controller with eg a service factory. Reference xInitialization (aDescriptor.mxController, UNO_QUERY); if (xInitialization.is()) { beans::PropertyValue aPropValue; std::vector aPropertyVector; aPropValue.Name = A2S("Frame"); aPropValue.Value <<= mxFrame; aPropertyVector.push_back(makeAny(aPropValue)); aPropValue.Name = A2S("ServiceManager"); aPropValue.Value <<= ::comphelper::getProcessServiceFactory(); aPropertyVector.push_back(makeAny(aPropValue)); aPropValue.Name = A2S("CommandURL"); aPropValue.Value <<= sCommandName; aPropertyVector.push_back(makeAny(aPropValue)); Sequence aArgs (comphelper::containerToSequence(aPropertyVector)); xInitialization->initialize(aArgs); } Reference xUpdatable (aDescriptor.mxController, UNO_QUERY); if (xUpdatable.is()) xUpdatable->update(); // Add label. const OUString sLabel (sfx2::sidebar::CommandInfoProvider::Instance().GetLabelForCommand( sCommandName, mxFrame)); pToolBox->SetQuickHelpText(nItemId, sLabel); // Add item to toolbox. pToolBox->EnableItem(nItemId); maControllers.insert(::std::make_pair(nItemId, aDescriptor)); } } ToolBox* InsertPropertyPanel::GetToolBoxForItemId (const sal_uInt16 nItemId) const { switch(nItemId) { case TBI_STANDARD_LINE: case TBI_STANDARD_ARROW: case TBI_STANDARD_RECTANGLE: case TBI_STANDARD_ELLIPSE: case TBI_STANDARD_TEXT: case TBI_STANDARD_LINES: case TBI_STANDARD_CONNECTORS: case TBI_STANDARD_ARROWS: return mpStandardShapesToolBox.get(); case TBI_CUSTOM_BASICS: case TBI_CUSTOM_SYMBOLS: case TBI_CUSTOM_ARROWS: case TBI_CUSTOM_FLOWCHARTS: case TBI_CUSTOM_CALLOUTS: case TBI_CUSTOM_STARS: return mpCustomShapesToolBox.get(); default: return NULL; } } Reference InsertPropertyPanel::GetControllerForItemId (const sal_uInt16 nItemId) const { ControllerContainer::const_iterator iController (maControllers.find(nItemId)); if (iController != maControllers.end()) return iController->second.mxController; else return NULL; } sal_uInt16 InsertPropertyPanel::GetItemIdForSubToolbarName (const OUString& rsSubToolbarName) const { for (ControllerContainer::const_iterator iController(maControllers.begin()), iEnd(maControllers.end()); iController!=iEnd; ++iController) { Reference xSubToolbarController (iController->second.mxController, UNO_QUERY); if (xSubToolbarController.is()) if (xSubToolbarController->getSubToolbarName().equals(rsSubToolbarName)) return iController->first; } return NULL; } void InsertPropertyPanel::UpdateIcons (void) { const sal_Bool bBigImages (SvtMiscOptions().AreCurrentSymbolsLarge()); const bool bIsHighContrastActive (sfx2::sidebar::Theme::IsHighContrastMode()); for (ControllerContainer::iterator iController(maControllers.begin()), iEnd(maControllers.end()); iController!=iEnd; ++iController) { const ::rtl::OUString sCommandURL (iController->second.msCurrentCommand); Image aImage (framework::GetImageFromURL(mxFrame, sCommandURL, bBigImages, bIsHighContrastActive)); ToolBox* pToolBox = GetToolBoxForItemId(iController->first); if (pToolBox != NULL) pToolBox->SetItemImage(iController->first, aImage); } } } } // end of namespace svx::sidebar