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