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 24*ae13266dSAndre Fischer #include "sfx2/sidebar/SidebarToolBox.hxx" 2595a18594SAndre Fischer #include "ToolBoxBackground.hxx" 26*ae13266dSAndre 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> 31b9e67834SAndre Fischer 3295a18594SAndre Fischer 33b9e67834SAndre Fischer using namespace ::com::sun::star; 34b9e67834SAndre Fischer using namespace ::com::sun::star::uno; 35*ae13266dSAndre Fischer using ::rtl::OUString; 36b9e67834SAndre Fischer 37b9e67834SAndre Fischer 38b9e67834SAndre Fischer namespace sfx2 { namespace sidebar { 39b9e67834SAndre Fischer 40b9e67834SAndre Fischer 41b9e67834SAndre Fischer SidebarToolBox::SidebarToolBox ( 42b9e67834SAndre Fischer Window* pParentWindow, 43*ae13266dSAndre Fischer const ResId& rResId, 44*ae13266dSAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame) 4595a18594SAndre Fischer : ToolBox(pParentWindow, rResId), 4695a18594SAndre Fischer mbParentIsBorder(false), 4795a18594SAndre Fischer maItemSeparator(Theme::GetImage(Theme::Image_ToolBoxItemSeparator)) 48b9e67834SAndre Fischer { 4995a18594SAndre Fischer SetBackground(Wallpaper()); 5095a18594SAndre Fischer SetPaintTransparent(true); 51*ae13266dSAndre Fischer 52*ae13266dSAndre Fischer if (rxFrame.is()) 53*ae13266dSAndre Fischer { 54*ae13266dSAndre Fischer const sal_uInt16 nItemCount (GetItemCount()); 55*ae13266dSAndre Fischer for (sal_uInt16 nItemIndex=0; nItemIndex<nItemCount; ++nItemIndex) 56*ae13266dSAndre Fischer CreateController(GetItemId(nItemIndex), rxFrame); 57*ae13266dSAndre Fischer UpdateIcons(rxFrame); 58*ae13266dSAndre Fischer 59*ae13266dSAndre Fischer SetSizePixel(CalcWindowSizePixel()); 60*ae13266dSAndre Fischer 61*ae13266dSAndre Fischer SetDropdownClickHdl(LINK(this, SidebarToolBox, DropDownClickHandler)); 62*ae13266dSAndre Fischer SetClickHdl(LINK(this, SidebarToolBox, ClickHandler)); 63*ae13266dSAndre Fischer SetDoubleClickHdl(LINK(this, SidebarToolBox, DoubleClickHandler)); 64*ae13266dSAndre Fischer SetSelectHdl(LINK(this, SidebarToolBox, SelectHandler)); 65*ae13266dSAndre Fischer SetActivateHdl(LINK(this, SidebarToolBox, Activate)); 66*ae13266dSAndre Fischer SetDeactivateHdl(LINK(this, SidebarToolBox, Deactivate)); 67*ae13266dSAndre Fischer } 68*ae13266dSAndre Fischer 697a32b0c8SAndre Fischer #ifdef DEBUG 707a32b0c8SAndre Fischer SetText(A2S("SidebarToolBox")); 717a32b0c8SAndre Fischer #endif 72b9e67834SAndre Fischer } 73b9e67834SAndre Fischer 74b9e67834SAndre Fischer 75b9e67834SAndre Fischer 76b9e67834SAndre Fischer 77b9e67834SAndre Fischer SidebarToolBox::~SidebarToolBox (void) 78b9e67834SAndre Fischer { 79*ae13266dSAndre Fischer ControllerContainer aControllers; 80*ae13266dSAndre Fischer aControllers.swap(maControllers); 81*ae13266dSAndre Fischer for (ControllerContainer::iterator iController(aControllers.begin()), iEnd(aControllers.end()); 82*ae13266dSAndre Fischer iController!=iEnd; 83*ae13266dSAndre Fischer ++iController) 84*ae13266dSAndre Fischer { 85*ae13266dSAndre Fischer Reference<lang::XComponent> xComponent (iController->second.mxController, UNO_QUERY); 86*ae13266dSAndre Fischer if (xComponent.is()) 87*ae13266dSAndre Fischer xComponent->dispose(); 88*ae13266dSAndre Fischer } 89*ae13266dSAndre Fischer 90*ae13266dSAndre Fischer SetDropdownClickHdl(Link()); 91*ae13266dSAndre Fischer SetClickHdl(Link()); 92*ae13266dSAndre Fischer SetDoubleClickHdl(Link()); 93*ae13266dSAndre Fischer SetSelectHdl(Link()); 94*ae13266dSAndre Fischer SetActivateHdl(Link()); 95*ae13266dSAndre Fischer SetDeactivateHdl(Link()); 96*ae13266dSAndre Fischer 97b9e67834SAndre Fischer } 98b9e67834SAndre Fischer 99b9e67834SAndre Fischer 100b9e67834SAndre Fischer 101b9e67834SAndre Fischer 10295a18594SAndre Fischer void SidebarToolBox::SetBorderWindow (const Window* pBorderWindow) 103b9e67834SAndre Fischer { 10495a18594SAndre Fischer if (pBorderWindow != GetParent()) 10595a18594SAndre Fischer { 10695a18594SAndre Fischer OSL_ASSERT("SetBorderWindow can only handle parent as border window"); 10795a18594SAndre Fischer return; 10895a18594SAndre Fischer } 109b9e67834SAndre Fischer 11095a18594SAndre Fischer if ( ! mbParentIsBorder) 111b9e67834SAndre Fischer { 11295a18594SAndre Fischer mbParentIsBorder = true; 11395a18594SAndre Fischer 11495a18594SAndre Fischer SetPosSizePixel ( 11595a18594SAndre Fischer GetPosPixel().X(), 11695a18594SAndre Fischer GetPosPixel().Y(), 11795a18594SAndre Fischer GetSizePixel().Width(), 11895a18594SAndre Fischer GetSizePixel().Height(), 11995a18594SAndre Fischer WINDOW_POSSIZE_ALL); 120b9e67834SAndre Fischer } 12195a18594SAndre Fischer } 12295a18594SAndre Fischer 12395a18594SAndre Fischer 12495a18594SAndre Fischer 125b9e67834SAndre Fischer 12695a18594SAndre Fischer void SidebarToolBox::Paint (const Rectangle& rRect) 12795a18594SAndre Fischer { 128b9e67834SAndre Fischer ToolBox::Paint(rRect); 12995a18594SAndre Fischer 13095a18594SAndre Fischer if (Theme::GetBoolean(Theme::Bool_UseToolBoxItemSeparator)) 13195a18594SAndre Fischer { 13295a18594SAndre Fischer const sal_Int32 nSeparatorY ((GetSizePixel().Height() - maItemSeparator.GetSizePixel().Height())/2); 13395a18594SAndre Fischer const sal_uInt16 nItemCount (GetItemCount()); 13495a18594SAndre Fischer int nLastRight (-1); 13595a18594SAndre Fischer for (sal_uInt16 nIndex=0; nIndex<nItemCount; ++nIndex) 13695a18594SAndre Fischer { 13795a18594SAndre Fischer const Rectangle aItemBoundingBox (GetItemPosRect(nIndex)); 13895a18594SAndre Fischer if (nLastRight >= 0) 13995a18594SAndre Fischer { 14095a18594SAndre Fischer const int nSeparatorX ((nLastRight + aItemBoundingBox.Left() - 1) / 2); 14195a18594SAndre Fischer DrawImage(Point(nSeparatorX,nSeparatorY), maItemSeparator); 14295a18594SAndre Fischer } 14395a18594SAndre Fischer 14495a18594SAndre Fischer nLastRight = aItemBoundingBox.Right(); 14595a18594SAndre Fischer } 14695a18594SAndre Fischer } 147b9e67834SAndre Fischer } 148b9e67834SAndre Fischer 14995a18594SAndre Fischer 15095a18594SAndre Fischer 15195a18594SAndre Fischer 15295a18594SAndre Fischer Point SidebarToolBox::GetPosPixel (void) const 15395a18594SAndre Fischer { 15495a18594SAndre Fischer if (mbParentIsBorder) 15595a18594SAndre Fischer { 15695a18594SAndre Fischer const Point aParentPoint (GetParent()->GetPosPixel()); 15795a18594SAndre Fischer const Point aChildPoint (ToolBox::GetPosPixel()); 15895a18594SAndre Fischer return Point( 15995a18594SAndre Fischer aParentPoint.X() + aChildPoint.X(), 16095a18594SAndre Fischer aParentPoint.Y() + aChildPoint.Y()); 16195a18594SAndre Fischer } 16295a18594SAndre Fischer else 16395a18594SAndre Fischer return ToolBox::GetPosPixel(); 16495a18594SAndre Fischer } 16595a18594SAndre Fischer 16695a18594SAndre Fischer 16795a18594SAndre Fischer 16895a18594SAndre Fischer 16995a18594SAndre Fischer void SidebarToolBox::SetPosSizePixel ( 17095a18594SAndre Fischer long nX, 17195a18594SAndre Fischer long nY, 17295a18594SAndre Fischer long nWidth, 17395a18594SAndre Fischer long nHeight, 17495a18594SAndre Fischer sal_uInt16 nFlags) 17595a18594SAndre Fischer { 17695a18594SAndre Fischer if (mbParentIsBorder) 17795a18594SAndre Fischer { 17895a18594SAndre Fischer const Point aRelativePosition (static_cast<ToolBoxBackground*>(GetParent())->SetToolBoxChild( 17995a18594SAndre Fischer this, 18095a18594SAndre Fischer nX, 18195a18594SAndre Fischer nY, 18295a18594SAndre Fischer nWidth, 18395a18594SAndre Fischer nHeight, 18495a18594SAndre Fischer nFlags)); 18595a18594SAndre Fischer ToolBox::SetPosSizePixel( 18695a18594SAndre Fischer aRelativePosition.X(), 18795a18594SAndre Fischer aRelativePosition.Y(), 18895a18594SAndre Fischer nWidth, 18995a18594SAndre Fischer nHeight, 19095a18594SAndre Fischer nFlags); 19195a18594SAndre Fischer } 19295a18594SAndre Fischer else 19395a18594SAndre Fischer ToolBox::SetPosSizePixel(nX, nY, nWidth, nHeight, nFlags); 19495a18594SAndre Fischer } 19595a18594SAndre Fischer 19695a18594SAndre Fischer 19795a18594SAndre Fischer 19852d13b84SAndre Fischer 19952d13b84SAndre Fischer long SidebarToolBox::Notify (NotifyEvent& rEvent) 20052d13b84SAndre Fischer { 20152d13b84SAndre Fischer if (rEvent.GetType() == EVENT_KEYINPUT) 20252d13b84SAndre Fischer { 20352d13b84SAndre Fischer if (rEvent.GetKeyEvent()->GetKeyCode().GetCode() == KEY_TAB) 20452d13b84SAndre Fischer { 20552d13b84SAndre Fischer // Special handling for transferring handling of KEY_TAB 20652d13b84SAndre Fischer // that becomes necessary because of our parent that is 20752d13b84SAndre Fischer // not the dialog but a background control. 20852d13b84SAndre Fischer return DockingWindow::Notify(rEvent); 20952d13b84SAndre Fischer } 21052d13b84SAndre Fischer } 21152d13b84SAndre Fischer return ToolBox::Notify(rEvent); 21252d13b84SAndre Fischer } 213*ae13266dSAndre Fischer 214*ae13266dSAndre Fischer 215*ae13266dSAndre Fischer 216*ae13266dSAndre Fischer 217*ae13266dSAndre Fischer void SidebarToolBox::CreateController ( 218*ae13266dSAndre Fischer const sal_uInt16 nItemId, 219*ae13266dSAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame) 220*ae13266dSAndre Fischer { 221*ae13266dSAndre Fischer ItemDescriptor aDescriptor; 222*ae13266dSAndre Fischer 223*ae13266dSAndre Fischer const OUString sCommandName (GetItemCommand(nItemId)); 224*ae13266dSAndre Fischer 225*ae13266dSAndre Fischer aDescriptor.mxController = sfx2::sidebar::ControllerFactory::CreateToolBoxController( 226*ae13266dSAndre Fischer this, 227*ae13266dSAndre Fischer nItemId, 228*ae13266dSAndre Fischer sCommandName, 229*ae13266dSAndre Fischer rxFrame); 230*ae13266dSAndre Fischer aDescriptor.maURL = sfx2::sidebar::Tools::GetURL(sCommandName); 231*ae13266dSAndre Fischer aDescriptor.msCurrentCommand = sCommandName; 232*ae13266dSAndre Fischer aDescriptor.mxDispatch = sfx2::sidebar::Tools::GetDispatch(rxFrame, aDescriptor.maURL); 233*ae13266dSAndre Fischer 234*ae13266dSAndre Fischer if (aDescriptor.mxController.is() && aDescriptor.mxDispatch.is()) 235*ae13266dSAndre Fischer maControllers.insert(::std::make_pair(nItemId, aDescriptor)); 236*ae13266dSAndre Fischer } 237*ae13266dSAndre Fischer 238*ae13266dSAndre Fischer 239*ae13266dSAndre Fischer 240*ae13266dSAndre Fischer 241*ae13266dSAndre Fischer Reference<frame::XToolbarController> SidebarToolBox::GetControllerForItemId (const sal_uInt16 nItemId) const 242*ae13266dSAndre Fischer { 243*ae13266dSAndre Fischer ControllerContainer::const_iterator iController (maControllers.find(nItemId)); 244*ae13266dSAndre Fischer if (iController != maControllers.end()) 245*ae13266dSAndre Fischer return iController->second.mxController; 246*ae13266dSAndre Fischer else 247*ae13266dSAndre Fischer return NULL; 248*ae13266dSAndre Fischer } 249*ae13266dSAndre Fischer 250*ae13266dSAndre Fischer 251*ae13266dSAndre Fischer 252*ae13266dSAndre Fischer 253*ae13266dSAndre Fischer void SidebarToolBox::UpdateIcons (const Reference<frame::XFrame>& rxFrame) 254*ae13266dSAndre Fischer { 255*ae13266dSAndre Fischer const sal_Bool bBigImages (SvtMiscOptions().AreCurrentSymbolsLarge()); 256*ae13266dSAndre Fischer const bool bIsHighContrastActive (sfx2::sidebar::Theme::IsHighContrastMode()); 257*ae13266dSAndre Fischer 258*ae13266dSAndre Fischer for (ControllerContainer::iterator iController(maControllers.begin()), iEnd(maControllers.end()); 259*ae13266dSAndre Fischer iController!=iEnd; 260*ae13266dSAndre Fischer ++iController) 261*ae13266dSAndre Fischer { 262*ae13266dSAndre Fischer const ::rtl::OUString sCommandURL (iController->second.msCurrentCommand); 263*ae13266dSAndre Fischer Image aImage (framework::GetImageFromURL(rxFrame, sCommandURL, bBigImages, bIsHighContrastActive)); 264*ae13266dSAndre Fischer SetItemImage(iController->first, aImage); 265*ae13266dSAndre Fischer } 266*ae13266dSAndre Fischer } 267*ae13266dSAndre Fischer 268*ae13266dSAndre Fischer 269*ae13266dSAndre Fischer 270*ae13266dSAndre Fischer 271*ae13266dSAndre Fischer sal_uInt16 SidebarToolBox::GetItemIdForSubToolbarName (const OUString& rsSubToolbarName) const 272*ae13266dSAndre Fischer { 273*ae13266dSAndre Fischer for (ControllerContainer::const_iterator iController(maControllers.begin()), iEnd(maControllers.end()); 274*ae13266dSAndre Fischer iController!=iEnd; 275*ae13266dSAndre Fischer ++iController) 276*ae13266dSAndre Fischer { 277*ae13266dSAndre Fischer Reference<frame::XToolbarController> xController (iController->second.mxController); 278*ae13266dSAndre Fischer Reference<frame::XSubToolbarController> xSubToolbarController (xController, UNO_QUERY); 279*ae13266dSAndre Fischer if (xSubToolbarController.is()) 280*ae13266dSAndre Fischer { 281*ae13266dSAndre Fischer const OUString sName (xSubToolbarController->getSubToolbarName()); 282*ae13266dSAndre Fischer if (sName.equals(rsSubToolbarName)) 283*ae13266dSAndre Fischer return iController->first; 284*ae13266dSAndre Fischer } 285*ae13266dSAndre Fischer } 286*ae13266dSAndre Fischer return 0; 287*ae13266dSAndre Fischer } 288*ae13266dSAndre Fischer 289*ae13266dSAndre Fischer 290*ae13266dSAndre Fischer 291*ae13266dSAndre Fischer IMPL_LINK(SidebarToolBox, DropDownClickHandler, ToolBox*, pToolBox) 292*ae13266dSAndre Fischer { 293*ae13266dSAndre Fischer if (pToolBox != NULL) 294*ae13266dSAndre Fischer { 295*ae13266dSAndre Fischer Reference<frame::XToolbarController> xController (GetControllerForItemId(pToolBox->GetCurItemId())); 296*ae13266dSAndre Fischer if (xController.is()) 297*ae13266dSAndre Fischer { 298*ae13266dSAndre Fischer Reference<awt::XWindow> xWindow = xController->createPopupWindow(); 299*ae13266dSAndre Fischer if (xWindow.is() ) 300*ae13266dSAndre Fischer xWindow->setFocus(); 301*ae13266dSAndre Fischer } 302*ae13266dSAndre Fischer } 303*ae13266dSAndre Fischer return 1; 304*ae13266dSAndre Fischer } 305*ae13266dSAndre Fischer 306*ae13266dSAndre Fischer 307*ae13266dSAndre Fischer 308*ae13266dSAndre Fischer 309*ae13266dSAndre Fischer IMPL_LINK(SidebarToolBox, ClickHandler, ToolBox*, pToolBox) 310*ae13266dSAndre Fischer { 311*ae13266dSAndre Fischer if (pToolBox == NULL) 312*ae13266dSAndre Fischer return 0; 313*ae13266dSAndre Fischer 314*ae13266dSAndre Fischer Reference<frame::XToolbarController> xController (GetControllerForItemId(pToolBox->GetCurItemId())); 315*ae13266dSAndre Fischer if (xController.is()) 316*ae13266dSAndre Fischer xController->click(); 317*ae13266dSAndre Fischer 318*ae13266dSAndre Fischer return 1; 319*ae13266dSAndre Fischer } 320*ae13266dSAndre Fischer 321*ae13266dSAndre Fischer 322*ae13266dSAndre Fischer 323*ae13266dSAndre Fischer 324*ae13266dSAndre Fischer IMPL_LINK(SidebarToolBox, DoubleClickHandler, ToolBox*, pToolBox) 325*ae13266dSAndre Fischer { 326*ae13266dSAndre Fischer if (pToolBox == NULL) 327*ae13266dSAndre Fischer return 0; 328*ae13266dSAndre Fischer 329*ae13266dSAndre Fischer Reference<frame::XToolbarController> xController (GetControllerForItemId(pToolBox->GetCurItemId())); 330*ae13266dSAndre Fischer if (xController.is()) 331*ae13266dSAndre Fischer xController->doubleClick(); 332*ae13266dSAndre Fischer 333*ae13266dSAndre Fischer return 1; 334*ae13266dSAndre Fischer } 335*ae13266dSAndre Fischer 336*ae13266dSAndre Fischer 337*ae13266dSAndre Fischer 338*ae13266dSAndre Fischer 339*ae13266dSAndre Fischer IMPL_LINK(SidebarToolBox, SelectHandler, ToolBox*, pToolBox) 340*ae13266dSAndre Fischer { 341*ae13266dSAndre Fischer if (pToolBox == NULL) 342*ae13266dSAndre Fischer return 0; 343*ae13266dSAndre Fischer 344*ae13266dSAndre Fischer Reference<frame::XToolbarController> xController (GetControllerForItemId(pToolBox->GetCurItemId())); 345*ae13266dSAndre Fischer if (xController.is()) 346*ae13266dSAndre Fischer xController->execute((sal_Int16)pToolBox->GetModifier()); 347*ae13266dSAndre Fischer 348*ae13266dSAndre Fischer return 1; 349*ae13266dSAndre Fischer } 350*ae13266dSAndre Fischer 351*ae13266dSAndre Fischer 352*ae13266dSAndre Fischer 353*ae13266dSAndre Fischer 354*ae13266dSAndre Fischer IMPL_LINK(SidebarToolBox, Activate, ToolBox*, EMPTYARG) 355*ae13266dSAndre Fischer { 356*ae13266dSAndre Fischer return 1; 357*ae13266dSAndre Fischer } 358*ae13266dSAndre Fischer 359*ae13266dSAndre Fischer 360*ae13266dSAndre Fischer 361*ae13266dSAndre Fischer 362*ae13266dSAndre Fischer IMPL_LINK(SidebarToolBox, Deactivate, ToolBox*, EMPTYARG) 363*ae13266dSAndre Fischer { 364*ae13266dSAndre Fischer return 1; 365*ae13266dSAndre Fischer } 366*ae13266dSAndre Fischer 367*ae13266dSAndre Fischer 36852d13b84SAndre Fischer 369b9e67834SAndre Fischer } } // end of namespace sfx2::sidebar 370