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 28 #include <vcl/gradient.hxx> 29 30 31 using namespace ::com::sun::star; 32 using namespace ::com::sun::star::uno; 33 34 35 namespace sfx2 { namespace sidebar { 36 37 38 SidebarToolBox::SidebarToolBox ( 39 Window* pParentWindow, 40 const ResId& rResId) 41 : ToolBox(pParentWindow, rResId), 42 mbParentIsBorder(false), 43 maItemSeparator(Theme::GetImage(Theme::Image_ToolBoxItemSeparator)) 44 { 45 SetBackground(Wallpaper()); 46 SetPaintTransparent(true); 47 } 48 49 50 51 52 SidebarToolBox::~SidebarToolBox (void) 53 { 54 } 55 56 57 58 59 void SidebarToolBox::SetBorderWindow (const Window* pBorderWindow) 60 { 61 if (pBorderWindow != GetParent()) 62 { 63 OSL_ASSERT("SetBorderWindow can only handle parent as border window"); 64 return; 65 } 66 67 if ( ! mbParentIsBorder) 68 { 69 mbParentIsBorder = true; 70 71 SetPosSizePixel ( 72 GetPosPixel().X(), 73 GetPosPixel().Y(), 74 GetSizePixel().Width(), 75 GetSizePixel().Height(), 76 WINDOW_POSSIZE_ALL); 77 } 78 } 79 80 81 82 83 void SidebarToolBox::Paint (const Rectangle& rRect) 84 { 85 ToolBox::Paint(rRect); 86 87 OSL_TRACE("paint ToolBox at %d,%d", 88 GetPosPixel().X(), 89 GetPosPixel().Y()); 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