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