1b9e67834SAndre Fischer /************************************************************** 2b9e67834SAndre Fischer * 3b9e67834SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 4b9e67834SAndre Fischer * or more contributor license agreements. See the NOTICE file 5b9e67834SAndre Fischer * distributed with this work for additional information 6b9e67834SAndre Fischer * regarding copyright ownership. The ASF licenses this file 7b9e67834SAndre Fischer * to you under the Apache License, Version 2.0 (the 8b9e67834SAndre Fischer * "License"); you may not use this file except in compliance 9b9e67834SAndre Fischer * with the License. You may obtain a copy of the License at 10b9e67834SAndre Fischer * 11b9e67834SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 12b9e67834SAndre Fischer * 13b9e67834SAndre Fischer * Unless required by applicable law or agreed to in writing, 14b9e67834SAndre Fischer * software distributed under the License is distributed on an 15b9e67834SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16b9e67834SAndre Fischer * KIND, either express or implied. See the License for the 17b9e67834SAndre Fischer * specific language governing permissions and limitations 18b9e67834SAndre Fischer * under the License. 19b9e67834SAndre Fischer * 20b9e67834SAndre Fischer *************************************************************/ 21b9e67834SAndre Fischer 22b9e67834SAndre Fischer #include "precompiled_sfx2.hxx" 23b9e67834SAndre Fischer 24ae13266dSAndre Fischer #include "sfx2/sidebar/SidebarToolBox.hxx" 2595a18594SAndre Fischer #include "ToolBoxBackground.hxx" 26ae13266dSAndre Fischer #include "sfx2/sidebar/ControllerFactory.hxx" 2795a18594SAndre Fischer #include "sfx2/sidebar/Theme.hxx" 28f35c6d02SAndre Fischer #include "sfx2/sidebar/Tools.hxx" 29b9e67834SAndre Fischer 30b9e67834SAndre Fischer #include <vcl/gradient.hxx> 31*d46a1e42SAndre Fischer #include <toolkit/helper/vclunohelper.hxx> 32edc7f530SAndre Fischer #include <svtools/miscopt.hxx> 33edc7f530SAndre Fischer #include <framework/imageproducer.hxx> 34edc7f530SAndre Fischer #include <com/sun/star/frame/XSubToolbarController.hpp> 35b9e67834SAndre Fischer 3695a18594SAndre Fischer 37b9e67834SAndre Fischer using namespace ::com::sun::star; 38b9e67834SAndre Fischer using namespace ::com::sun::star::uno; 39ae13266dSAndre Fischer using ::rtl::OUString; 40b9e67834SAndre Fischer 41b9e67834SAndre Fischer 42b9e67834SAndre Fischer namespace sfx2 { namespace sidebar { 43b9e67834SAndre Fischer 44b9e67834SAndre Fischer 45b9e67834SAndre Fischer SidebarToolBox::SidebarToolBox ( 46b9e67834SAndre Fischer Window* pParentWindow, 47ae13266dSAndre Fischer const ResId& rResId, 48ae13266dSAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame) 4995a18594SAndre Fischer : ToolBox(pParentWindow, rResId), 5095a18594SAndre Fischer mbParentIsBorder(false), 5195a18594SAndre Fischer maItemSeparator(Theme::GetImage(Theme::Image_ToolBoxItemSeparator)) 52b9e67834SAndre Fischer { 5395a18594SAndre Fischer SetBackground(Wallpaper()); 5495a18594SAndre Fischer SetPaintTransparent(true); 55ae13266dSAndre Fischer 56ae13266dSAndre Fischer if (rxFrame.is()) 57ae13266dSAndre Fischer { 58ae13266dSAndre Fischer const sal_uInt16 nItemCount (GetItemCount()); 59*d46a1e42SAndre Fischer if (nItemCount == 1) 60*d46a1e42SAndre Fischer { 61*d46a1e42SAndre Fischer // When there is only one item then make that as wide as 62*d46a1e42SAndre Fischer // the tool box. 63*d46a1e42SAndre Fischer CreateController(GetItemId(0), rxFrame, GetSizePixel().Width()); 64*d46a1e42SAndre Fischer } 65*d46a1e42SAndre Fischer else 66*d46a1e42SAndre Fischer for (sal_uInt16 nItemIndex=0; nItemIndex<nItemCount; ++nItemIndex) 67*d46a1e42SAndre Fischer CreateController(GetItemId(nItemIndex), rxFrame, 0); 68ae13266dSAndre Fischer UpdateIcons(rxFrame); 69ae13266dSAndre Fischer 70ae13266dSAndre Fischer SetSizePixel(CalcWindowSizePixel()); 71ae13266dSAndre Fischer 72ae13266dSAndre Fischer SetDropdownClickHdl(LINK(this, SidebarToolBox, DropDownClickHandler)); 73ae13266dSAndre Fischer SetClickHdl(LINK(this, SidebarToolBox, ClickHandler)); 74ae13266dSAndre Fischer SetDoubleClickHdl(LINK(this, SidebarToolBox, DoubleClickHandler)); 75ae13266dSAndre Fischer SetSelectHdl(LINK(this, SidebarToolBox, SelectHandler)); 76ae13266dSAndre Fischer SetActivateHdl(LINK(this, SidebarToolBox, Activate)); 77ae13266dSAndre Fischer SetDeactivateHdl(LINK(this, SidebarToolBox, Deactivate)); 78ae13266dSAndre Fischer } 79ae13266dSAndre Fischer 807a32b0c8SAndre Fischer #ifdef DEBUG 817a32b0c8SAndre Fischer SetText(A2S("SidebarToolBox")); 827a32b0c8SAndre Fischer #endif 83b9e67834SAndre Fischer } 84b9e67834SAndre Fischer 85b9e67834SAndre Fischer 86b9e67834SAndre Fischer 87b9e67834SAndre Fischer 88b9e67834SAndre Fischer SidebarToolBox::~SidebarToolBox (void) 89b9e67834SAndre Fischer { 90ae13266dSAndre Fischer ControllerContainer aControllers; 91ae13266dSAndre Fischer aControllers.swap(maControllers); 92ae13266dSAndre Fischer for (ControllerContainer::iterator iController(aControllers.begin()), iEnd(aControllers.end()); 93ae13266dSAndre Fischer iController!=iEnd; 94ae13266dSAndre Fischer ++iController) 95ae13266dSAndre Fischer { 96ae13266dSAndre Fischer Reference<lang::XComponent> xComponent (iController->second.mxController, UNO_QUERY); 97ae13266dSAndre Fischer if (xComponent.is()) 98ae13266dSAndre Fischer xComponent->dispose(); 99ae13266dSAndre Fischer } 100ae13266dSAndre Fischer 101ae13266dSAndre Fischer SetDropdownClickHdl(Link()); 102ae13266dSAndre Fischer SetClickHdl(Link()); 103ae13266dSAndre Fischer SetDoubleClickHdl(Link()); 104ae13266dSAndre Fischer SetSelectHdl(Link()); 105ae13266dSAndre Fischer SetActivateHdl(Link()); 106ae13266dSAndre Fischer SetDeactivateHdl(Link()); 107ae13266dSAndre Fischer 108b9e67834SAndre Fischer } 109b9e67834SAndre Fischer 110b9e67834SAndre Fischer 111b9e67834SAndre Fischer 112b9e67834SAndre Fischer 11395a18594SAndre Fischer void SidebarToolBox::SetBorderWindow (const Window* pBorderWindow) 114b9e67834SAndre Fischer { 11595a18594SAndre Fischer if (pBorderWindow != GetParent()) 11695a18594SAndre Fischer { 11795a18594SAndre Fischer OSL_ASSERT("SetBorderWindow can only handle parent as border window"); 11895a18594SAndre Fischer return; 11995a18594SAndre Fischer } 120b9e67834SAndre Fischer 12195a18594SAndre Fischer if ( ! mbParentIsBorder) 122b9e67834SAndre Fischer { 12395a18594SAndre Fischer mbParentIsBorder = true; 12495a18594SAndre Fischer 12595a18594SAndre Fischer SetPosSizePixel ( 12695a18594SAndre Fischer GetPosPixel().X(), 12795a18594SAndre Fischer GetPosPixel().Y(), 12895a18594SAndre Fischer GetSizePixel().Width(), 12995a18594SAndre Fischer GetSizePixel().Height(), 13095a18594SAndre Fischer WINDOW_POSSIZE_ALL); 131b9e67834SAndre Fischer } 13295a18594SAndre Fischer } 13395a18594SAndre Fischer 13495a18594SAndre Fischer 13595a18594SAndre Fischer 136b9e67834SAndre Fischer 13795a18594SAndre Fischer void SidebarToolBox::Paint (const Rectangle& rRect) 13895a18594SAndre Fischer { 139b9e67834SAndre Fischer ToolBox::Paint(rRect); 14095a18594SAndre Fischer 14195a18594SAndre Fischer if (Theme::GetBoolean(Theme::Bool_UseToolBoxItemSeparator)) 14295a18594SAndre Fischer { 14395a18594SAndre Fischer const sal_Int32 nSeparatorY ((GetSizePixel().Height() - maItemSeparator.GetSizePixel().Height())/2); 14495a18594SAndre Fischer const sal_uInt16 nItemCount (GetItemCount()); 14595a18594SAndre Fischer int nLastRight (-1); 14695a18594SAndre Fischer for (sal_uInt16 nIndex=0; nIndex<nItemCount; ++nIndex) 14795a18594SAndre Fischer { 14895a18594SAndre Fischer const Rectangle aItemBoundingBox (GetItemPosRect(nIndex)); 14995a18594SAndre Fischer if (nLastRight >= 0) 15095a18594SAndre Fischer { 15195a18594SAndre Fischer const int nSeparatorX ((nLastRight + aItemBoundingBox.Left() - 1) / 2); 15295a18594SAndre Fischer DrawImage(Point(nSeparatorX,nSeparatorY), maItemSeparator); 15395a18594SAndre Fischer } 15495a18594SAndre Fischer 15595a18594SAndre Fischer nLastRight = aItemBoundingBox.Right(); 15695a18594SAndre Fischer } 15795a18594SAndre Fischer } 158b9e67834SAndre Fischer } 159b9e67834SAndre Fischer 16095a18594SAndre Fischer 16195a18594SAndre Fischer 16295a18594SAndre Fischer 16395a18594SAndre Fischer Point SidebarToolBox::GetPosPixel (void) const 16495a18594SAndre Fischer { 16595a18594SAndre Fischer if (mbParentIsBorder) 16695a18594SAndre Fischer { 16795a18594SAndre Fischer const Point aParentPoint (GetParent()->GetPosPixel()); 16895a18594SAndre Fischer const Point aChildPoint (ToolBox::GetPosPixel()); 16995a18594SAndre Fischer return Point( 17095a18594SAndre Fischer aParentPoint.X() + aChildPoint.X(), 17195a18594SAndre Fischer aParentPoint.Y() + aChildPoint.Y()); 17295a18594SAndre Fischer } 17395a18594SAndre Fischer else 17495a18594SAndre Fischer return ToolBox::GetPosPixel(); 17595a18594SAndre Fischer } 17695a18594SAndre Fischer 17795a18594SAndre Fischer 17895a18594SAndre Fischer 17995a18594SAndre Fischer 18095a18594SAndre Fischer void SidebarToolBox::SetPosSizePixel ( 18195a18594SAndre Fischer long nX, 18295a18594SAndre Fischer long nY, 18395a18594SAndre Fischer long nWidth, 18495a18594SAndre Fischer long nHeight, 18595a18594SAndre Fischer sal_uInt16 nFlags) 18695a18594SAndre Fischer { 18795a18594SAndre Fischer if (mbParentIsBorder) 18895a18594SAndre Fischer { 18995a18594SAndre Fischer const Point aRelativePosition (static_cast<ToolBoxBackground*>(GetParent())->SetToolBoxChild( 19095a18594SAndre Fischer this, 19195a18594SAndre Fischer nX, 19295a18594SAndre Fischer nY, 19395a18594SAndre Fischer nWidth, 19495a18594SAndre Fischer nHeight, 19595a18594SAndre Fischer nFlags)); 19695a18594SAndre Fischer ToolBox::SetPosSizePixel( 19795a18594SAndre Fischer aRelativePosition.X(), 19895a18594SAndre Fischer aRelativePosition.Y(), 19995a18594SAndre Fischer nWidth, 20095a18594SAndre Fischer nHeight, 20195a18594SAndre Fischer nFlags); 20295a18594SAndre Fischer } 20395a18594SAndre Fischer else 20495a18594SAndre Fischer ToolBox::SetPosSizePixel(nX, nY, nWidth, nHeight, nFlags); 20595a18594SAndre Fischer } 20695a18594SAndre Fischer 20795a18594SAndre Fischer 20895a18594SAndre Fischer 20952d13b84SAndre Fischer 21052d13b84SAndre Fischer long SidebarToolBox::Notify (NotifyEvent& rEvent) 21152d13b84SAndre Fischer { 21252d13b84SAndre Fischer if (rEvent.GetType() == EVENT_KEYINPUT) 21352d13b84SAndre Fischer { 21452d13b84SAndre Fischer if (rEvent.GetKeyEvent()->GetKeyCode().GetCode() == KEY_TAB) 21552d13b84SAndre Fischer { 21652d13b84SAndre Fischer // Special handling for transferring handling of KEY_TAB 21752d13b84SAndre Fischer // that becomes necessary because of our parent that is 21852d13b84SAndre Fischer // not the dialog but a background control. 21952d13b84SAndre Fischer return DockingWindow::Notify(rEvent); 22052d13b84SAndre Fischer } 22152d13b84SAndre Fischer } 22252d13b84SAndre Fischer return ToolBox::Notify(rEvent); 22352d13b84SAndre Fischer } 224ae13266dSAndre Fischer 225ae13266dSAndre Fischer 226ae13266dSAndre Fischer 227ae13266dSAndre Fischer 228ae13266dSAndre Fischer void SidebarToolBox::CreateController ( 229ae13266dSAndre Fischer const sal_uInt16 nItemId, 230*d46a1e42SAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame, 231*d46a1e42SAndre Fischer const sal_Int32 nItemWidth) 232ae13266dSAndre Fischer { 233ae13266dSAndre Fischer ItemDescriptor aDescriptor; 234ae13266dSAndre Fischer 235ae13266dSAndre Fischer const OUString sCommandName (GetItemCommand(nItemId)); 236ae13266dSAndre Fischer 237ae13266dSAndre Fischer aDescriptor.mxController = sfx2::sidebar::ControllerFactory::CreateToolBoxController( 238ae13266dSAndre Fischer this, 239ae13266dSAndre Fischer nItemId, 240ae13266dSAndre Fischer sCommandName, 241*d46a1e42SAndre Fischer rxFrame, 242*d46a1e42SAndre Fischer VCLUnoHelper::GetInterface(this), 243*d46a1e42SAndre Fischer nItemWidth); 244*d46a1e42SAndre Fischer if (aDescriptor.mxController.is()) 245*d46a1e42SAndre Fischer { 246*d46a1e42SAndre Fischer aDescriptor.maURL = sfx2::sidebar::Tools::GetURL(sCommandName); 247*d46a1e42SAndre Fischer aDescriptor.msCurrentCommand = sCommandName; 248ae13266dSAndre Fischer 249ae13266dSAndre Fischer maControllers.insert(::std::make_pair(nItemId, aDescriptor)); 250*d46a1e42SAndre Fischer } 251ae13266dSAndre Fischer } 252ae13266dSAndre Fischer 253ae13266dSAndre Fischer 254ae13266dSAndre Fischer 255ae13266dSAndre Fischer 256ae13266dSAndre Fischer Reference<frame::XToolbarController> SidebarToolBox::GetControllerForItemId (const sal_uInt16 nItemId) const 257ae13266dSAndre Fischer { 258ae13266dSAndre Fischer ControllerContainer::const_iterator iController (maControllers.find(nItemId)); 259ae13266dSAndre Fischer if (iController != maControllers.end()) 260ae13266dSAndre Fischer return iController->second.mxController; 261ae13266dSAndre Fischer else 262ae13266dSAndre Fischer return NULL; 263ae13266dSAndre Fischer } 264ae13266dSAndre Fischer 265ae13266dSAndre Fischer 266ae13266dSAndre Fischer 267ae13266dSAndre Fischer 268ae13266dSAndre Fischer void SidebarToolBox::UpdateIcons (const Reference<frame::XFrame>& rxFrame) 269ae13266dSAndre Fischer { 270ae13266dSAndre Fischer const sal_Bool bBigImages (SvtMiscOptions().AreCurrentSymbolsLarge()); 271ae13266dSAndre Fischer const bool bIsHighContrastActive (sfx2::sidebar::Theme::IsHighContrastMode()); 272ae13266dSAndre Fischer 273ae13266dSAndre Fischer for (ControllerContainer::iterator iController(maControllers.begin()), iEnd(maControllers.end()); 274ae13266dSAndre Fischer iController!=iEnd; 275ae13266dSAndre Fischer ++iController) 276ae13266dSAndre Fischer { 277ae13266dSAndre Fischer const ::rtl::OUString sCommandURL (iController->second.msCurrentCommand); 278ae13266dSAndre Fischer Image aImage (framework::GetImageFromURL(rxFrame, sCommandURL, bBigImages, bIsHighContrastActive)); 279ae13266dSAndre Fischer SetItemImage(iController->first, aImage); 280ae13266dSAndre Fischer } 281ae13266dSAndre Fischer } 282ae13266dSAndre Fischer 283ae13266dSAndre Fischer 284ae13266dSAndre Fischer 285ae13266dSAndre Fischer 286ae13266dSAndre Fischer sal_uInt16 SidebarToolBox::GetItemIdForSubToolbarName (const OUString& rsSubToolbarName) const 287ae13266dSAndre Fischer { 288ae13266dSAndre Fischer for (ControllerContainer::const_iterator iController(maControllers.begin()), iEnd(maControllers.end()); 289ae13266dSAndre Fischer iController!=iEnd; 290ae13266dSAndre Fischer ++iController) 291ae13266dSAndre Fischer { 292ae13266dSAndre Fischer Reference<frame::XToolbarController> xController (iController->second.mxController); 293ae13266dSAndre Fischer Reference<frame::XSubToolbarController> xSubToolbarController (xController, UNO_QUERY); 294ae13266dSAndre Fischer if (xSubToolbarController.is()) 295ae13266dSAndre Fischer { 296ae13266dSAndre Fischer const OUString sName (xSubToolbarController->getSubToolbarName()); 297ae13266dSAndre Fischer if (sName.equals(rsSubToolbarName)) 298ae13266dSAndre Fischer return iController->first; 299ae13266dSAndre Fischer } 300ae13266dSAndre Fischer } 301ae13266dSAndre Fischer return 0; 302ae13266dSAndre Fischer } 303ae13266dSAndre Fischer 304ae13266dSAndre Fischer 305ae13266dSAndre Fischer 306ae13266dSAndre Fischer IMPL_LINK(SidebarToolBox, DropDownClickHandler, ToolBox*, pToolBox) 307ae13266dSAndre Fischer { 308ae13266dSAndre Fischer if (pToolBox != NULL) 309ae13266dSAndre Fischer { 310ae13266dSAndre Fischer Reference<frame::XToolbarController> xController (GetControllerForItemId(pToolBox->GetCurItemId())); 311ae13266dSAndre Fischer if (xController.is()) 312ae13266dSAndre Fischer { 313ae13266dSAndre Fischer Reference<awt::XWindow> xWindow = xController->createPopupWindow(); 314ae13266dSAndre Fischer if (xWindow.is() ) 315ae13266dSAndre Fischer xWindow->setFocus(); 316ae13266dSAndre Fischer } 317ae13266dSAndre Fischer } 318ae13266dSAndre Fischer return 1; 319ae13266dSAndre Fischer } 320ae13266dSAndre Fischer 321ae13266dSAndre Fischer 322ae13266dSAndre Fischer 323ae13266dSAndre Fischer 324ae13266dSAndre Fischer IMPL_LINK(SidebarToolBox, ClickHandler, ToolBox*, pToolBox) 325ae13266dSAndre Fischer { 326ae13266dSAndre Fischer if (pToolBox == NULL) 327ae13266dSAndre Fischer return 0; 328ae13266dSAndre Fischer 329ae13266dSAndre Fischer Reference<frame::XToolbarController> xController (GetControllerForItemId(pToolBox->GetCurItemId())); 330ae13266dSAndre Fischer if (xController.is()) 331ae13266dSAndre Fischer xController->click(); 332ae13266dSAndre Fischer 333ae13266dSAndre Fischer return 1; 334ae13266dSAndre Fischer } 335ae13266dSAndre Fischer 336ae13266dSAndre Fischer 337ae13266dSAndre Fischer 338ae13266dSAndre Fischer 339ae13266dSAndre Fischer IMPL_LINK(SidebarToolBox, DoubleClickHandler, ToolBox*, pToolBox) 340ae13266dSAndre Fischer { 341ae13266dSAndre Fischer if (pToolBox == NULL) 342ae13266dSAndre Fischer return 0; 343ae13266dSAndre Fischer 344ae13266dSAndre Fischer Reference<frame::XToolbarController> xController (GetControllerForItemId(pToolBox->GetCurItemId())); 345ae13266dSAndre Fischer if (xController.is()) 346ae13266dSAndre Fischer xController->doubleClick(); 347ae13266dSAndre Fischer 348ae13266dSAndre Fischer return 1; 349ae13266dSAndre Fischer } 350ae13266dSAndre Fischer 351ae13266dSAndre Fischer 352ae13266dSAndre Fischer 353ae13266dSAndre Fischer 354ae13266dSAndre Fischer IMPL_LINK(SidebarToolBox, SelectHandler, ToolBox*, pToolBox) 355ae13266dSAndre Fischer { 356ae13266dSAndre Fischer if (pToolBox == NULL) 357ae13266dSAndre Fischer return 0; 358ae13266dSAndre Fischer 359ae13266dSAndre Fischer Reference<frame::XToolbarController> xController (GetControllerForItemId(pToolBox->GetCurItemId())); 360ae13266dSAndre Fischer if (xController.is()) 361ae13266dSAndre Fischer xController->execute((sal_Int16)pToolBox->GetModifier()); 362ae13266dSAndre Fischer 363ae13266dSAndre Fischer return 1; 364ae13266dSAndre Fischer } 365ae13266dSAndre Fischer 366ae13266dSAndre Fischer 367ae13266dSAndre Fischer 368ae13266dSAndre Fischer 369ae13266dSAndre Fischer IMPL_LINK(SidebarToolBox, Activate, ToolBox*, EMPTYARG) 370ae13266dSAndre Fischer { 371ae13266dSAndre Fischer return 1; 372ae13266dSAndre Fischer } 373ae13266dSAndre Fischer 374ae13266dSAndre Fischer 375ae13266dSAndre Fischer 376ae13266dSAndre Fischer 377ae13266dSAndre Fischer IMPL_LINK(SidebarToolBox, Deactivate, ToolBox*, EMPTYARG) 378ae13266dSAndre Fischer { 379ae13266dSAndre Fischer return 1; 380ae13266dSAndre Fischer } 381ae13266dSAndre Fischer 382ae13266dSAndre Fischer 38352d13b84SAndre Fischer 384b9e67834SAndre Fischer } } // end of namespace sfx2::sidebar 385