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 "DeckTitleBar.hxx"
25 #include "sfx2/sidebar/Theme.hxx"
26 
27 #include <vcl/image.hxx>
28 
29 #ifdef DEBUG
30 #include "sfx2/sidebar/Tools.hxx"
31 #endif
32 
33 
34 namespace sfx2 { namespace sidebar {
35 
36 static const sal_Int32 gaLeftGripPadding (3);
37 static const sal_Int32 gaRightGripPadding (3);
38 
39 
40 DeckTitleBar::DeckTitleBar (
41     const ::rtl::OUString& rsTitle,
42     Window* pParentWindow,
43     const ::boost::function<void(void)>& rCloserAction)
44     : TitleBar(rsTitle, pParentWindow, GetBackgroundPaint()),
45       mnCloserItemIndex(1),
46       maCloserAction(rCloserAction),
47       mbIsCloserVisible(rCloserAction)
48 {
49     OSL_ASSERT(pParentWindow != NULL);
50 
51     if (maCloserAction)
52     {
53         maToolBox.InsertItem(
54             mnCloserItemIndex,
55             Theme::GetImage(Theme::Image_Closer));
56     }
57 
58 #ifdef DEBUG
59     SetText(A2S("DeckTitleBar"));
60 #endif
61 }
62 
63 
64 
65 
66 DeckTitleBar::~DeckTitleBar (void)
67 {
68 }
69 
70 
71 
72 
73 void DeckTitleBar::SetCloserVisible (const bool bIsCloserVisible)
74 {
75     if (mbIsCloserVisible != bIsCloserVisible)
76     {
77         mbIsCloserVisible = bIsCloserVisible;
78 
79         if (mbIsCloserVisible)
80             maToolBox.InsertItem(
81                 mnCloserItemIndex,
82                 Theme::GetImage(Theme::Image_Closer));
83         else
84             maToolBox.RemoveItem(
85                 maToolBox.GetItemPos(mnCloserItemIndex));
86     }
87 }
88 
89 
90 
91 
92 Rectangle DeckTitleBar::GetTitleArea (const Rectangle& rTitleBarBox)
93 {
94     Image aGripImage (Theme::GetImage(Theme::Image_Grip));
95     return Rectangle(
96         aGripImage.GetSizePixel().Width() + gaLeftGripPadding + gaRightGripPadding,
97         rTitleBarBox.Top(),
98         rTitleBarBox.Right(),
99         rTitleBarBox.Bottom());
100 }
101 
102 
103 
104 
105 void DeckTitleBar::PaintDecoration (const Rectangle& rTitleBarBox)
106 {
107     (void)rTitleBarBox;
108 }
109 
110 
111 
112 
113 sidebar::Paint DeckTitleBar::GetBackgroundPaint (void)
114 {
115     return Theme::GetPaint(Theme::Paint_DeckTitleBarBackground);
116 }
117 
118 
119 
120 
121 Color DeckTitleBar::GetTextColor (void)
122 {
123     return Theme::GetColor(Theme::Color_DeckTitleFont);
124 }
125 
126 
127 
128 
129 void DeckTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
130 {
131     if (nItemIndex == mnCloserItemIndex)
132         if (maCloserAction)
133             maCloserAction();
134 }
135 
136 
137 
138 
139 void DeckTitleBar::DataChanged (const DataChangedEvent& rEvent)
140 {
141     maToolBox.SetItemImage(
142         mnCloserItemIndex,
143         Theme::GetImage(Theme::Image_Closer));
144     TitleBar::DataChanged(rEvent);
145 }
146 
147 
148 } } // end of namespace sfx2::sidebar
149