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 if (Theme::GetBoolean(Theme::Bool_UseToolBoxItemSeparator)) 92 { 93 const sal_Int32 nSeparatorY ((GetSizePixel().Height() - maItemSeparator.GetSizePixel().Height())/2); 94 const sal_uInt16 nItemCount (GetItemCount()); 95 int nLastRight (-1); 96 for (sal_uInt16 nIndex=0; nIndex<nItemCount; ++nIndex) 97 { 98 const Rectangle aItemBoundingBox (GetItemPosRect(nIndex)); 99 if (nLastRight >= 0) 100 { 101 const int nSeparatorX ((nLastRight + aItemBoundingBox.Left() - 1) / 2); 102 DrawImage(Point(nSeparatorX,nSeparatorY), maItemSeparator); 103 } 104 105 nLastRight = aItemBoundingBox.Right(); 106 } 107 } 108 } 109 110 111 112 113 Point SidebarToolBox::GetPosPixel (void) const 114 { 115 if (mbParentIsBorder) 116 { 117 const Point aParentPoint (GetParent()->GetPosPixel()); 118 const Point aChildPoint (ToolBox::GetPosPixel()); 119 return Point( 120 aParentPoint.X() + aChildPoint.X(), 121 aParentPoint.Y() + aChildPoint.Y()); 122 } 123 else 124 return ToolBox::GetPosPixel(); 125 } 126 127 128 129 130 void SidebarToolBox::SetPosSizePixel ( 131 long nX, 132 long nY, 133 long nWidth, 134 long nHeight, 135 sal_uInt16 nFlags) 136 { 137 if (mbParentIsBorder) 138 { 139 const Point aRelativePosition (static_cast<ToolBoxBackground*>(GetParent())->SetToolBoxChild( 140 this, 141 nX, 142 nY, 143 nWidth, 144 nHeight, 145 nFlags)); 146 ToolBox::SetPosSizePixel( 147 aRelativePosition.X(), 148 aRelativePosition.Y(), 149 nWidth, 150 nHeight, 151 nFlags); 152 } 153 else 154 ToolBox::SetPosSizePixel(nX, nY, nWidth, nHeight, nFlags); 155 } 156 157 158 159 } } // end of namespace sfx2::sidebar 160