195a18594SAndre Fischer /**************************************************************
295a18594SAndre Fischer  *
395a18594SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
495a18594SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
595a18594SAndre Fischer  * distributed with this work for additional information
695a18594SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
795a18594SAndre Fischer  * to you under the Apache License, Version 2.0 (the
895a18594SAndre Fischer  * "License"); you may not use this file except in compliance
995a18594SAndre Fischer  * with the License.  You may obtain a copy of the License at
1095a18594SAndre Fischer  *
1195a18594SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
1295a18594SAndre Fischer  *
1395a18594SAndre Fischer  * Unless required by applicable law or agreed to in writing,
1495a18594SAndre Fischer  * software distributed under the License is distributed on an
1595a18594SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1695a18594SAndre Fischer  * KIND, either express or implied.  See the License for the
1795a18594SAndre Fischer  * specific language governing permissions and limitations
1895a18594SAndre Fischer  * under the License.
1995a18594SAndre Fischer  *
2095a18594SAndre Fischer  *************************************************************/
2195a18594SAndre Fischer 
2295a18594SAndre Fischer #include "precompiled_sfx2.hxx"
2395a18594SAndre Fischer 
2495a18594SAndre Fischer #include "ToolBoxBackground.hxx"
2595a18594SAndre Fischer #include "Paint.hxx"
2695a18594SAndre Fischer #include "DrawHelper.hxx"
2795a18594SAndre Fischer #include "Tools.hxx"
2895a18594SAndre Fischer #include "sfx2/sidebar/Theme.hxx"
2995a18594SAndre Fischer 
3095a18594SAndre Fischer #include <vcl/toolbox.hxx>
3195a18594SAndre Fischer #include <vcl/gradient.hxx>
32*7a32b0c8SAndre Fischer #include <svl/smplhint.hxx>
3395a18594SAndre Fischer 
3495a18594SAndre Fischer 
3595a18594SAndre Fischer namespace sfx2 { namespace sidebar {
3695a18594SAndre Fischer 
3795a18594SAndre Fischer ToolBoxBackground::ToolBoxBackground (Window* pParentWindow)
3895a18594SAndre Fischer     : Window(pParentWindow),
3995a18594SAndre Fischer       maPadding(Tools::RectangleToSvBorder(Theme::GetRectangle(Theme::Rect_ToolBoxPadding)))
4095a18594SAndre Fischer {
4195a18594SAndre Fischer     SetBackground(Theme::GetPaint(Theme::Paint_ToolBoxBackground).GetWallpaper());
42*7a32b0c8SAndre Fischer 
43*7a32b0c8SAndre Fischer #ifdef DEBUG
44*7a32b0c8SAndre Fischer     SetText(A2S("ToolBoxBackground"));
45*7a32b0c8SAndre Fischer #endif
4695a18594SAndre Fischer }
4795a18594SAndre Fischer 
4895a18594SAndre Fischer 
4995a18594SAndre Fischer 
5095a18594SAndre Fischer 
5195a18594SAndre Fischer ToolBoxBackground::~ToolBoxBackground (void)
5295a18594SAndre Fischer {
5395a18594SAndre Fischer     Link aEventListener (LINK(this, ToolBoxBackground, WindowEventHandler));
5495a18594SAndre Fischer     if (GetChildCount() > 0)
5595a18594SAndre Fischer         GetChild(0)->RemoveEventListener(aEventListener);
5695a18594SAndre Fischer }
5795a18594SAndre Fischer 
5895a18594SAndre Fischer 
5995a18594SAndre Fischer 
6095a18594SAndre Fischer 
6195a18594SAndre Fischer Point ToolBoxBackground::SetToolBoxChild (
6295a18594SAndre Fischer     ToolBox* pChild,
6395a18594SAndre Fischer     long nX,
6495a18594SAndre Fischer     long nY,
6595a18594SAndre Fischer     long nWidth,
6695a18594SAndre Fischer     long nHeight,
6795a18594SAndre Fischer     sal_uInt16 nFlags)
6895a18594SAndre Fischer {
6995a18594SAndre Fischer     if (pChild == NULL)
7095a18594SAndre Fischer     {
7195a18594SAndre Fischer         OSL_ASSERT(pChild!=NULL);
7295a18594SAndre Fischer         return Point(nX, nY);
7395a18594SAndre Fischer     }
7495a18594SAndre Fischer 
7595a18594SAndre Fischer     Link aEventListener (LINK(this, ToolBoxBackground, WindowEventHandler));
7695a18594SAndre Fischer     pChild->AddEventListener(aEventListener);
7795a18594SAndre Fischer 
7895a18594SAndre Fischer     SetPosSizePixel(
7995a18594SAndre Fischer         nX - maPadding.Left(),
8095a18594SAndre Fischer         nY - maPadding.Top(),
8195a18594SAndre Fischer         nWidth + maPadding.Left() + maPadding.Right(),
8295a18594SAndre Fischer         nHeight + maPadding.Top() + maPadding.Bottom(),
8395a18594SAndre Fischer         nFlags);
8495a18594SAndre Fischer     return Point(
8595a18594SAndre Fischer         maPadding.Left(),
8695a18594SAndre Fischer         maPadding.Top());
8795a18594SAndre Fischer }
8895a18594SAndre Fischer 
8995a18594SAndre Fischer 
9095a18594SAndre Fischer 
9195a18594SAndre Fischer 
9295a18594SAndre Fischer void ToolBoxBackground::Paint (const Rectangle& rRect)
9395a18594SAndre Fischer {
9495a18594SAndre Fischer     Window::Paint(rRect);
9595a18594SAndre Fischer 
9695a18594SAndre Fischer     Rectangle aBox (Point(0,0), GetSizePixel());
9795a18594SAndre Fischer 
9895a18594SAndre Fischer     const sidebar::Paint aTopLeftBorderPaint (Theme::GetPaint(Theme::Paint_ToolBoxBorderTopLeft));
9995a18594SAndre Fischer     const sidebar::Paint aCenterBorderPaint (Theme::GetPaint(Theme::Paint_ToolBoxBorderCenterCorners));
10095a18594SAndre Fischer     const sidebar::Paint aBottomRightBorderPaint (Theme::GetPaint(Theme::Paint_ToolBoxBorderBottomRight));
10195a18594SAndre Fischer     const Rectangle aBorderSize (Theme::GetRectangle(Theme::Rect_ToolBoxBorder));
10295a18594SAndre Fischer     DrawHelper::DrawBevelBorder (
10395a18594SAndre Fischer         *this,
10495a18594SAndre Fischer         aBox,
10595a18594SAndre Fischer         Tools::RectangleToSvBorder(aBorderSize),
10695a18594SAndre Fischer         aTopLeftBorderPaint,
10795a18594SAndre Fischer         aCenterBorderPaint,
10895a18594SAndre Fischer         aBottomRightBorderPaint);
10995a18594SAndre Fischer }
11095a18594SAndre Fischer 
11195a18594SAndre Fischer 
11295a18594SAndre Fischer 
11395a18594SAndre Fischer 
11495a18594SAndre Fischer void ToolBoxBackground::DataChanged (const DataChangedEvent& rEvent)
11595a18594SAndre Fischer {
11695a18594SAndre Fischer     (void)rEvent;
11795a18594SAndre Fischer 
11895a18594SAndre Fischer     SetBackground(Theme::GetPaint(Theme::Paint_ToolBoxBackground).GetWallpaper());
11995a18594SAndre Fischer     maPadding = Tools::RectangleToSvBorder(Theme::GetRectangle(Theme::Rect_ToolBoxPadding));
12095a18594SAndre Fischer }
12195a18594SAndre Fischer 
12295a18594SAndre Fischer 
12395a18594SAndre Fischer 
12495a18594SAndre Fischer 
12595a18594SAndre Fischer IMPL_LINK(ToolBoxBackground, WindowEventHandler, VclWindowEvent*, pEvent)
12695a18594SAndre Fischer {
12795a18594SAndre Fischer     if (pEvent != NULL)
12895a18594SAndre Fischer     {
12995a18594SAndre Fischer         switch (pEvent->GetId())
13095a18594SAndre Fischer         {
13195a18594SAndre Fischer             case VCLEVENT_WINDOW_SHOW:
13295a18594SAndre Fischer                 if (GetChild(0)->IsVisible())
13395a18594SAndre Fischer                     Show();
13495a18594SAndre Fischer                 break;
13595a18594SAndre Fischer 
13695a18594SAndre Fischer             case VCLEVENT_WINDOW_HIDE:
13795a18594SAndre Fischer                 if ( ! GetChild(0)->IsVisible())
13895a18594SAndre Fischer                     Hide();
13995a18594SAndre Fischer                 break;
14095a18594SAndre Fischer 
141*7a32b0c8SAndre Fischer             case SFX_HINT_DYING:
142*7a32b0c8SAndre Fischer                 doLazyDelete();
143*7a32b0c8SAndre Fischer                 break;
144*7a32b0c8SAndre Fischer 
14595a18594SAndre Fischer             default:
14695a18594SAndre Fischer                 break;
14795a18594SAndre Fischer         }
14895a18594SAndre Fischer     }
14995a18594SAndre Fischer 
15095a18594SAndre Fischer     return sal_True;
15195a18594SAndre Fischer }
15295a18594SAndre Fischer 
15395a18594SAndre Fischer 
15495a18594SAndre Fischer } } // end of namespace sfx2::sidebar
155