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 
35 namespace sfx2 { namespace sidebar {
36 
37 ToolBoxBackground::ToolBoxBackground (Window* pParentWindow)
38     : Window(pParentWindow, WB_DIALOGCONTROL),
39       maPadding(Tools::RectangleToSvBorder(Theme::GetRectangle(Theme::Rect_ToolBoxPadding)))
40 {
41     SetBackground(Theme::GetPaint(Theme::Paint_ToolBoxBackground).GetWallpaper());
42 
43 #ifdef DEBUG
44     SetText(A2S("ToolBoxBackground"));
45 #endif
46 }
47 
48 
49 
50 
51 ToolBoxBackground::~ToolBoxBackground (void)
52 {
53     Link aEventListener (LINK(this, ToolBoxBackground, WindowEventHandler));
54     if (GetChildCount() > 0)
55         GetChild(0)->RemoveEventListener(aEventListener);
56 }
57 
58 
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 
90 
91 
92 void ToolBoxBackground::Paint (const Rectangle& rRect)
93 {
94     Window::Paint(rRect);
95 
96     Rectangle aBox (Point(0,0), GetSizePixel());
97 
98     const sidebar::Paint aTopLeftBorderPaint (Theme::GetPaint(Theme::Paint_ToolBoxBorderTopLeft));
99     const sidebar::Paint aCenterBorderPaint (Theme::GetPaint(Theme::Paint_ToolBoxBorderCenterCorners));
100     const sidebar::Paint aBottomRightBorderPaint (Theme::GetPaint(Theme::Paint_ToolBoxBorderBottomRight));
101     const Rectangle aBorderSize (Theme::GetRectangle(Theme::Rect_ToolBoxBorder));
102     DrawHelper::DrawBevelBorder (
103         *this,
104         aBox,
105         Tools::RectangleToSvBorder(aBorderSize),
106         aTopLeftBorderPaint,
107         aCenterBorderPaint,
108         aBottomRightBorderPaint);
109 }
110 
111 
112 
113 
114 void ToolBoxBackground::DataChanged (const DataChangedEvent& rEvent)
115 {
116     (void)rEvent;
117 
118     SetBackground(Theme::GetPaint(Theme::Paint_ToolBoxBackground).GetWallpaper());
119     maPadding = Tools::RectangleToSvBorder(Theme::GetRectangle(Theme::Rect_ToolBoxPadding));
120 }
121 
122 
123 
124 
125 IMPL_LINK(ToolBoxBackground, WindowEventHandler, VclWindowEvent*, pEvent)
126 {
127     if (pEvent != NULL)
128     {
129         switch (pEvent->GetId())
130         {
131             case VCLEVENT_WINDOW_SHOW:
132                 if (GetChild(0)->IsVisible())
133                     Show();
134                 break;
135 
136             case VCLEVENT_WINDOW_HIDE:
137                 if ( ! GetChild(0)->IsVisible())
138                     Hide();
139                 break;
140 
141             default:
142                 break;
143         }
144     }
145 
146     return sal_True;
147 }
148 
149 
150 } } // end of namespace sfx2::sidebar
151