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_sfx2.hxx" 23 24 #include "SidebarToolBox.hxx" 25 #include "ToolBoxBackground.hxx" 26 #include "sfx2/sidebar/Theme.hxx" 27 #include "Tools.hxx" 28 29 #include <vcl/gradient.hxx> 30 31 32 using namespace ::com::sun::star; 33 using namespace ::com::sun::star::uno; 34 35 36 namespace sfx2 { namespace sidebar { 37 38 39 SidebarToolBox::SidebarToolBox ( 40 Window* pParentWindow, 41 const ResId& rResId) 42 : ToolBox(pParentWindow, rResId), 43 mbParentIsBorder(false), 44 maItemSeparator(Theme::GetImage(Theme::Image_ToolBoxItemSeparator)) 45 { 46 SetBackground(Wallpaper()); 47 SetPaintTransparent(true); 48 #ifdef DEBUG 49 SetText(A2S("SidebarToolBox")); 50 #endif 51 } 52 53 54 55 56 SidebarToolBox::~SidebarToolBox (void) 57 { 58 } 59 60 61 62 63 void SidebarToolBox::SetBorderWindow (const Window* pBorderWindow) 64 { 65 if (pBorderWindow != GetParent()) 66 { 67 OSL_ASSERT("SetBorderWindow can only handle parent as border window"); 68 return; 69 } 70 71 if ( ! mbParentIsBorder) 72 { 73 mbParentIsBorder = true; 74 75 SetPosSizePixel ( 76 GetPosPixel().X(), 77 GetPosPixel().Y(), 78 GetSizePixel().Width(), 79 GetSizePixel().Height(), 80 WINDOW_POSSIZE_ALL); 81 } 82 } 83 84 85 86 87 void SidebarToolBox::Paint (const Rectangle& rRect) 88 { 89 ToolBox::Paint(rRect); 90 91 OSL_TRACE("paint ToolBox at %d,%d", 92 GetPosPixel().X(), 93 GetPosPixel().Y()); 94 95 if (Theme::GetBoolean(Theme::Bool_UseToolBoxItemSeparator)) 96 { 97 const sal_Int32 nSeparatorY ((GetSizePixel().Height() - maItemSeparator.GetSizePixel().Height())/2); 98 const sal_uInt16 nItemCount (GetItemCount()); 99 int nLastRight (-1); 100 for (sal_uInt16 nIndex=0; nIndex<nItemCount; ++nIndex) 101 { 102 const Rectangle aItemBoundingBox (GetItemPosRect(nIndex)); 103 if (nLastRight >= 0) 104 { 105 const int nSeparatorX ((nLastRight + aItemBoundingBox.Left() - 1) / 2); 106 DrawImage(Point(nSeparatorX,nSeparatorY), maItemSeparator); 107 } 108 109 nLastRight = aItemBoundingBox.Right(); 110 } 111 } 112 } 113 114 115 116 117 Point SidebarToolBox::GetPosPixel (void) const 118 { 119 if (mbParentIsBorder) 120 { 121 const Point aParentPoint (GetParent()->GetPosPixel()); 122 const Point aChildPoint (ToolBox::GetPosPixel()); 123 return Point( 124 aParentPoint.X() + aChildPoint.X(), 125 aParentPoint.Y() + aChildPoint.Y()); 126 } 127 else 128 return ToolBox::GetPosPixel(); 129 } 130 131 132 133 134 void SidebarToolBox::SetPosSizePixel ( 135 long nX, 136 long nY, 137 long nWidth, 138 long nHeight, 139 sal_uInt16 nFlags) 140 { 141 if (mbParentIsBorder) 142 { 143 const Point aRelativePosition (static_cast<ToolBoxBackground*>(GetParent())->SetToolBoxChild( 144 this, 145 nX, 146 nY, 147 nWidth, 148 nHeight, 149 nFlags)); 150 ToolBox::SetPosSizePixel( 151 aRelativePosition.X(), 152 aRelativePosition.Y(), 153 nWidth, 154 nHeight, 155 nFlags); 156 } 157 else 158 ToolBox::SetPosSizePixel(nX, nY, nWidth, nHeight, nFlags); 159 } 160 161 162 163 } } // end of namespace sfx2::sidebar 164