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