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 "PanelTitleBar.hxx"
25 
26 #include "Paint.hxx"
27 #include "Panel.hxx"
28 #include "sfx2/sidebar/Theme.hxx"
29 
30 #include <tools/svborder.hxx>
31 #include <vcl/gradient.hxx>
32 
33 namespace sfx2 { namespace sidebar {
34 
35 
36 static const sal_Int32 gaLeftIconPadding (5);
37 static const sal_Int32 gaRightIconPadding (5);
38 
39 
40 PanelTitleBar::PanelTitleBar (
41     const ::rtl::OUString& rsTitle,
42     Window* pParentWindow,
43     Panel* pPanel)
44     : TitleBar(rsTitle, pParentWindow),
45       mbIsLeftButtonDown(false),
46       mpPanel(pPanel)
47 {
48     OSL_ASSERT(mpPanel != NULL);
49 }
50 
51 
52 
53 
54 PanelTitleBar::~PanelTitleBar (void)
55 {
56 }
57 
58 
59 
60 
61 Rectangle PanelTitleBar::GetTitleArea (const Rectangle& rTitleBarBox)
62 {
63     if (mpPanel != NULL)
64     {
65         Image aImage (mpPanel->IsExpanded()
66             ? Theme::GetImage(Theme::Image_Expand)
67             : Theme::GetImage(Theme::Image_Collapse));
68         return Rectangle(
69             aImage.GetSizePixel().Width() + gaLeftIconPadding + gaRightIconPadding,
70             rTitleBarBox.Top(),
71             rTitleBarBox.Right(),
72             rTitleBarBox.Bottom());
73     }
74     else
75         return rTitleBarBox;
76 }
77 
78 
79 
80 
81 void PanelTitleBar::PaintDecoration (const Rectangle& rTitleBarBox)
82 {
83     if (mpPanel != NULL)
84     {
85         Image aImage (mpPanel->IsExpanded()
86             ? Theme::GetImage(Theme::Image_Expand)
87             : Theme::GetImage(Theme::Image_Collapse));
88         const Point aTopLeft (
89             gaLeftIconPadding,
90             (GetSizePixel().Height()-aImage.GetSizePixel().Height())/2);
91         DrawImage(aTopLeft, aImage);
92     }
93 }
94 
95 
96 
97 
98 Paint PanelTitleBar::GetBackgroundPaint (void)
99 {
100     return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground);
101 }
102 
103 
104 
105 
106 Color PanelTitleBar::GetTextColor (void)
107 {
108     return Theme::GetColor(Theme::Color_PanelTitleFont);
109 }
110 
111 
112 
113 
114 void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent)
115 {
116     if (rMouseEvent.IsLeft())
117     {
118         mbIsLeftButtonDown = true;
119         CaptureMouse();
120     }
121 }
122 
123 
124 
125 
126 void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent)
127 {
128     if (IsMouseCaptured())
129         ReleaseMouse();
130 
131     if (rMouseEvent.IsLeft())
132     {
133         if (mbIsLeftButtonDown)
134         {
135             if (mpPanel != NULL)
136             {
137                 mpPanel->SetExpanded( ! mpPanel->IsExpanded());
138                 Invalidate();
139             }
140         }
141     }
142     if (mbIsLeftButtonDown)
143         mbIsLeftButtonDown = false;
144 }
145 
146 
147 
148 } } // end of namespace sfx2::sidebar
149