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"
27f35c6d02SAndre Fischer #include "sfx2/sidebar/Tools.hxx"
2895a18594SAndre Fischer #include "sfx2/sidebar/Theme.hxx"
2995a18594SAndre Fischer 
3095a18594SAndre Fischer #include <vcl/toolbox.hxx>
3195a18594SAndre Fischer #include <vcl/gradient.hxx>
327a32b0c8SAndre Fischer #include <svl/smplhint.hxx>
3395a18594SAndre Fischer 
3495a18594SAndre Fischer 
3595a18594SAndre Fischer namespace sfx2 { namespace sidebar {
3695a18594SAndre Fischer 
ToolBoxBackground(Window * pParentWindow,const bool bShowBorder)37*d46a1e42SAndre Fischer ToolBoxBackground::ToolBoxBackground (
38*d46a1e42SAndre Fischer     Window* pParentWindow,
39*d46a1e42SAndre Fischer     const bool bShowBorder)
4065908a7eSAndre Fischer     : Window(pParentWindow, WB_DIALOGCONTROL),
41*d46a1e42SAndre Fischer       maPadding(bShowBorder
42*d46a1e42SAndre Fischer           ? Tools::RectangleToSvBorder(Theme::GetRectangle(Theme::Rect_ToolBoxPadding))
43*d46a1e42SAndre Fischer           : SvBorder())
4495a18594SAndre Fischer {
45*d46a1e42SAndre Fischer     if (bShowBorder)
46*d46a1e42SAndre Fischer         SetBackground(Theme::GetPaint(Theme::Paint_ToolBoxBackground).GetWallpaper());
47*d46a1e42SAndre Fischer     else
48*d46a1e42SAndre Fischer         SetBackground(Wallpaper());
497a32b0c8SAndre Fischer 
507a32b0c8SAndre Fischer #ifdef DEBUG
517a32b0c8SAndre Fischer     SetText(A2S("ToolBoxBackground"));
527a32b0c8SAndre Fischer #endif
5395a18594SAndre Fischer }
5495a18594SAndre Fischer 
5595a18594SAndre Fischer 
5695a18594SAndre Fischer 
5795a18594SAndre Fischer 
~ToolBoxBackground(void)5895a18594SAndre Fischer ToolBoxBackground::~ToolBoxBackground (void)
5995a18594SAndre Fischer {
6095a18594SAndre Fischer     Link aEventListener (LINK(this, ToolBoxBackground, WindowEventHandler));
6195a18594SAndre Fischer     if (GetChildCount() > 0)
6295a18594SAndre Fischer         GetChild(0)->RemoveEventListener(aEventListener);
6395a18594SAndre Fischer }
6495a18594SAndre Fischer 
6595a18594SAndre Fischer 
6695a18594SAndre Fischer 
6795a18594SAndre Fischer 
SetToolBoxChild(ToolBox * pChild,long nX,long nY,long nWidth,long nHeight,sal_uInt16 nFlags)6895a18594SAndre Fischer Point ToolBoxBackground::SetToolBoxChild (
6995a18594SAndre Fischer     ToolBox* pChild,
7095a18594SAndre Fischer     long nX,
7195a18594SAndre Fischer     long nY,
7295a18594SAndre Fischer     long nWidth,
7395a18594SAndre Fischer     long nHeight,
7495a18594SAndre Fischer     sal_uInt16 nFlags)
7595a18594SAndre Fischer {
7695a18594SAndre Fischer     if (pChild == NULL)
7795a18594SAndre Fischer     {
7895a18594SAndre Fischer         OSL_ASSERT(pChild!=NULL);
7995a18594SAndre Fischer         return Point(nX, nY);
8095a18594SAndre Fischer     }
8195a18594SAndre Fischer 
8295a18594SAndre Fischer     Link aEventListener (LINK(this, ToolBoxBackground, WindowEventHandler));
8395a18594SAndre Fischer     pChild->AddEventListener(aEventListener);
8495a18594SAndre Fischer 
8595a18594SAndre Fischer     SetPosSizePixel(
8695a18594SAndre Fischer         nX - maPadding.Left(),
8795a18594SAndre Fischer         nY - maPadding.Top(),
8895a18594SAndre Fischer         nWidth + maPadding.Left() + maPadding.Right(),
8995a18594SAndre Fischer         nHeight + maPadding.Top() + maPadding.Bottom(),
9095a18594SAndre Fischer         nFlags);
9195a18594SAndre Fischer     return Point(
9295a18594SAndre Fischer         maPadding.Left(),
9395a18594SAndre Fischer         maPadding.Top());
9495a18594SAndre Fischer }
9595a18594SAndre Fischer 
9695a18594SAndre Fischer 
9795a18594SAndre Fischer 
9895a18594SAndre Fischer 
Paint(const Rectangle & rRect)9995a18594SAndre Fischer void ToolBoxBackground::Paint (const Rectangle& rRect)
10095a18594SAndre Fischer {
10195a18594SAndre Fischer     Window::Paint(rRect);
10295a18594SAndre Fischer 
10395a18594SAndre Fischer     Rectangle aBox (Point(0,0), GetSizePixel());
10495a18594SAndre Fischer 
10595a18594SAndre Fischer     const sidebar::Paint aTopLeftBorderPaint (Theme::GetPaint(Theme::Paint_ToolBoxBorderTopLeft));
10695a18594SAndre Fischer     const sidebar::Paint aCenterBorderPaint (Theme::GetPaint(Theme::Paint_ToolBoxBorderCenterCorners));
10795a18594SAndre Fischer     const sidebar::Paint aBottomRightBorderPaint (Theme::GetPaint(Theme::Paint_ToolBoxBorderBottomRight));
10895a18594SAndre Fischer     const Rectangle aBorderSize (Theme::GetRectangle(Theme::Rect_ToolBoxBorder));
10995a18594SAndre Fischer     DrawHelper::DrawBevelBorder (
11095a18594SAndre Fischer         *this,
11195a18594SAndre Fischer         aBox,
11295a18594SAndre Fischer         Tools::RectangleToSvBorder(aBorderSize),
11395a18594SAndre Fischer         aTopLeftBorderPaint,
11495a18594SAndre Fischer         aCenterBorderPaint,
11595a18594SAndre Fischer         aBottomRightBorderPaint);
11695a18594SAndre Fischer }
11795a18594SAndre Fischer 
11895a18594SAndre Fischer 
11995a18594SAndre Fischer 
12095a18594SAndre Fischer 
DataChanged(const DataChangedEvent & rEvent)12195a18594SAndre Fischer void ToolBoxBackground::DataChanged (const DataChangedEvent& rEvent)
12295a18594SAndre Fischer {
12395a18594SAndre Fischer     (void)rEvent;
12495a18594SAndre Fischer 
12595a18594SAndre Fischer     SetBackground(Theme::GetPaint(Theme::Paint_ToolBoxBackground).GetWallpaper());
12695a18594SAndre Fischer     maPadding = Tools::RectangleToSvBorder(Theme::GetRectangle(Theme::Rect_ToolBoxPadding));
12795a18594SAndre Fischer }
12895a18594SAndre Fischer 
12995a18594SAndre Fischer 
13095a18594SAndre Fischer 
13195a18594SAndre Fischer 
IMPL_LINK(ToolBoxBackground,WindowEventHandler,VclWindowEvent *,pEvent)13295a18594SAndre Fischer IMPL_LINK(ToolBoxBackground, WindowEventHandler, VclWindowEvent*, pEvent)
13395a18594SAndre Fischer {
13495a18594SAndre Fischer     if (pEvent != NULL)
13595a18594SAndre Fischer     {
13695a18594SAndre Fischer         switch (pEvent->GetId())
13795a18594SAndre Fischer         {
13895a18594SAndre Fischer             case VCLEVENT_WINDOW_SHOW:
13995a18594SAndre Fischer                 if (GetChild(0)->IsVisible())
14095a18594SAndre Fischer                     Show();
14195a18594SAndre Fischer                 break;
14295a18594SAndre Fischer 
14395a18594SAndre Fischer             case VCLEVENT_WINDOW_HIDE:
14495a18594SAndre Fischer                 if ( ! GetChild(0)->IsVisible())
14595a18594SAndre Fischer                     Hide();
14695a18594SAndre Fischer                 break;
14795a18594SAndre Fischer 
14895a18594SAndre Fischer             default:
14995a18594SAndre Fischer                 break;
15095a18594SAndre Fischer         }
15195a18594SAndre Fischer     }
15295a18594SAndre Fischer 
15395a18594SAndre Fischer     return sal_True;
15495a18594SAndre Fischer }
15595a18594SAndre Fischer 
15695a18594SAndre Fischer 
15795a18594SAndre Fischer } } // end of namespace sfx2::sidebar
158