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 "ToolBoxBackground.hxx" 25 #include "Paint.hxx" 26 #include "DrawHelper.hxx" 27 #include "Tools.hxx" 28 #include "sfx2/sidebar/Theme.hxx" 29 30 #include <vcl/toolbox.hxx> 31 #include <vcl/gradient.hxx> 32 33 34 namespace sfx2 { namespace sidebar { 35 36 ToolBoxBackground::ToolBoxBackground (Window* pParentWindow) 37 : Window(pParentWindow), 38 maPadding(Tools::RectangleToSvBorder(Theme::GetRectangle(Theme::Rect_ToolBoxPadding))) 39 { 40 SetBackground(Theme::GetPaint(Theme::Paint_ToolBoxBackground).GetWallpaper()); 41 } 42 43 44 45 46 ToolBoxBackground::~ToolBoxBackground (void) 47 { 48 Link aEventListener (LINK(this, ToolBoxBackground, WindowEventHandler)); 49 if (GetChildCount() > 0) 50 GetChild(0)->RemoveEventListener(aEventListener); 51 } 52 53 54 55 56 Point ToolBoxBackground::SetToolBoxChild ( 57 ToolBox* pChild, 58 long nX, 59 long nY, 60 long nWidth, 61 long nHeight, 62 sal_uInt16 nFlags) 63 { 64 if (pChild == NULL) 65 { 66 OSL_ASSERT(pChild!=NULL); 67 return Point(nX, nY); 68 } 69 70 Link aEventListener (LINK(this, ToolBoxBackground, WindowEventHandler)); 71 pChild->AddEventListener(aEventListener); 72 73 SetPosSizePixel( 74 nX - maPadding.Left(), 75 nY - maPadding.Top(), 76 nWidth + maPadding.Left() + maPadding.Right(), 77 nHeight + maPadding.Top() + maPadding.Bottom(), 78 nFlags); 79 return Point( 80 maPadding.Left(), 81 maPadding.Top()); 82 } 83 84 85 86 87 void ToolBoxBackground::Paint (const Rectangle& rRect) 88 { 89 Window::Paint(rRect); 90 91 OSL_TRACE("paint ToolBoxBackground at %d,%d", 92 GetPosPixel().X(), 93 GetPosPixel().Y()); 94 Rectangle aBox (Point(0,0), GetSizePixel()); 95 96 const sidebar::Paint aTopLeftBorderPaint (Theme::GetPaint(Theme::Paint_ToolBoxBorderTopLeft)); 97 const sidebar::Paint aCenterBorderPaint (Theme::GetPaint(Theme::Paint_ToolBoxBorderCenterCorners)); 98 const sidebar::Paint aBottomRightBorderPaint (Theme::GetPaint(Theme::Paint_ToolBoxBorderBottomRight)); 99 const Rectangle aBorderSize (Theme::GetRectangle(Theme::Rect_ToolBoxBorder)); 100 DrawHelper::DrawBevelBorder ( 101 *this, 102 aBox, 103 Tools::RectangleToSvBorder(aBorderSize), 104 aTopLeftBorderPaint, 105 aCenterBorderPaint, 106 aBottomRightBorderPaint); 107 } 108 109 110 111 112 void ToolBoxBackground::DataChanged (const DataChangedEvent& rEvent) 113 { 114 (void)rEvent; 115 116 SetBackground(Theme::GetPaint(Theme::Paint_ToolBoxBackground).GetWallpaper()); 117 maPadding = Tools::RectangleToSvBorder(Theme::GetRectangle(Theme::Rect_ToolBoxPadding)); 118 } 119 120 121 122 123 IMPL_LINK(ToolBoxBackground, WindowEventHandler, VclWindowEvent*, pEvent) 124 { 125 if (pEvent != NULL) 126 { 127 switch (pEvent->GetId()) 128 { 129 case VCLEVENT_WINDOW_SHOW: 130 if (GetChild(0)->IsVisible()) 131 Show(); 132 break; 133 134 case VCLEVENT_WINDOW_HIDE: 135 if ( ! GetChild(0)->IsVisible()) 136 Hide(); 137 break; 138 139 default: 140 break; 141 } 142 } 143 144 return sal_True; 145 } 146 147 148 } } // end of namespace sfx2::sidebar 149