xref: /AOO42X/main/sfx2/source/sidebar/TitleBar.cxx (revision 055746153e5cd78346b485d23b1c8e3408d513f1)
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 "TitleBar.hxx"
25 #include "Paint.hxx"
26 #include "Accessible.hxx"
27 #include "AccessibleTitleBar.hxx"
28 
29 #include <tools/svborder.hxx>
30 #include <vcl/gradient.hxx>
31 #include <vcl/lineinfo.hxx>
32 
33 #include <com/sun/star/accessibility/AccessibleRole.hpp>
34 
~ToolbarValue(void)35 ToolbarValue::~ToolbarValue (void) {}
36 
37 namespace
38 {
39     const static sal_Int32 gnLeftIconSpace (3);
40     const static sal_Int32 gnRightIconSpace (3);
41 }
42 
43 namespace sfx2 { namespace sidebar {
44 
TitleBar(const::rtl::OUString & rsTitle,Window * pParentWindow,const sidebar::Paint & rInitialBackgroundPaint)45 TitleBar::TitleBar (
46     const ::rtl::OUString& rsTitle,
47     Window* pParentWindow,
48     const sidebar::Paint& rInitialBackgroundPaint)
49     : Window(pParentWindow),
50       maToolBox(this),
51       msTitle(rsTitle),
52       maIcon()
53 {
54     SetBackground(rInitialBackgroundPaint.GetWallpaper());
55 
56     maToolBox.SetSelectHdl(LINK(this, TitleBar, SelectionHandler));
57 }
58 
~TitleBar(void)59 TitleBar::~TitleBar (void)
60 {
61 }
62 
SetTitle(const::rtl::OUString & rsTitle)63 void TitleBar::SetTitle (const ::rtl::OUString& rsTitle)
64 {
65     msTitle = rsTitle;
66     Invalidate();
67 }
68 
SetIcon(const Image & rIcon)69 void TitleBar::SetIcon (const Image& rIcon)
70 {
71     maIcon = rIcon;
72     Invalidate();
73 }
74 
Paint(const Rectangle & rUpdateArea)75 void TitleBar::Paint (const Rectangle& rUpdateArea)
76 {
77     (void)rUpdateArea;
78 
79     // Paint title bar background.
80     Size aWindowSize (GetOutputSizePixel());
81     Rectangle aTitleBarBox(
82         0,
83         0,
84         aWindowSize.Width(),
85         aWindowSize.Height()
86         );
87 
88     PaintDecoration(aTitleBarBox);
89     const Rectangle aTitleBox (GetTitleArea(aTitleBarBox));
90     PaintTitle(aTitleBox);
91     PaintFocus(aTitleBox);
92 }
93 
DataChanged(const DataChangedEvent & rEvent)94 void TitleBar::DataChanged (const DataChangedEvent& rEvent)
95 {
96     (void)rEvent;
97 
98     SetBackground(GetBackgroundPaint().GetWallpaper());
99 }
100 
SetPosSizePixel(long nX,long nY,long nWidth,long nHeight,sal_uInt16 nFlags)101 void TitleBar::SetPosSizePixel (
102     long nX,
103     long nY,
104     long nWidth,
105     long nHeight,
106     sal_uInt16 nFlags)
107 {
108     Window::SetPosSizePixel(nX,nY,nWidth,nHeight,nFlags);
109 
110     // Place the toolbox.
111     const sal_Int32 nToolBoxWidth (maToolBox.GetItemPosRect(0).GetWidth());
112     maToolBox.SetPosSizePixel(nWidth-nToolBoxWidth,0, nToolBoxWidth,nHeight, WINDOW_POSSIZE_POSSIZE);
113     maToolBox.Show();
114 }
115 
GetToolBox(void)116 ToolBox& TitleBar::GetToolBox (void)
117 {
118     return maToolBox;
119 }
120 
GetToolBox(void) const121 const ToolBox& TitleBar::GetToolBox (void) const
122 {
123     return maToolBox;
124 }
125 
HandleToolBoxItemClick(const sal_uInt16 nItemIndex)126 void TitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
127 {
128     (void)nItemIndex;
129     // Any real processing has to be done in derived class.
130 }
131 
CreateAccessible(void)132 cssu::Reference<css::accessibility::XAccessible> TitleBar::CreateAccessible (void)
133 {
134     SetAccessibleRole(css::accessibility::AccessibleRole::PANEL);
135     return AccessibleTitleBar::Create(*this);
136 }
137 
PaintTitle(const Rectangle & rTitleBox)138 void TitleBar::PaintTitle (const Rectangle& rTitleBox)
139 {
140     Push(PUSH_FONT | PUSH_TEXTCOLOR);
141 
142     Rectangle aTitleBox (rTitleBox);
143 
144     // When there is an icon then paint it at the left of the given box.
145     if ( !! maIcon)
146     {
147         DrawImage(
148             Point(
149                 aTitleBox.Left() + gnLeftIconSpace,
150                 aTitleBox.Top() + (aTitleBox.GetHeight()-maIcon.GetSizePixel().Height())/2),
151             maIcon);
152         aTitleBox.Left() += gnLeftIconSpace + maIcon.GetSizePixel().Width() + gnRightIconSpace;
153     }
154 
155     Font aFont(GetFont());
156     aFont.SetWeight(WEIGHT_BOLD);
157     SetFont(aFont);
158 
159     // Paint title bar text.
160     SetTextColor(GetTextColor());
161     DrawText(
162         aTitleBox,
163         msTitle,
164         TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER);
165 
166     Pop();
167 }
168 
PaintFocus(const Rectangle & rFocusBox)169 void TitleBar::PaintFocus (const Rectangle& rFocusBox)
170 {
171     Push(PUSH_FONT | PUSH_TEXTCOLOR);
172 
173     Font aFont(GetFont());
174     aFont.SetWeight(WEIGHT_BOLD);
175     SetFont(aFont);
176 
177     const Rectangle aTextBox (
178         GetTextRect(
179             rFocusBox,
180             msTitle,
181             TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER));
182     const Rectangle aLargerTextBox (
183         aTextBox.Left() - 2,
184         aTextBox.Top() - 2,
185         aTextBox.Right() + 2,
186         aTextBox.Bottom() + 2);
187 
188     if (HasFocus())
189         Window::ShowFocus(aLargerTextBox);
190     else
191         Window::HideFocus();
192 
193     Pop();
194 }
195 
IMPL_LINK(TitleBar,SelectionHandler,ToolBox *,pToolBox)196 IMPL_LINK(TitleBar, SelectionHandler, ToolBox*, pToolBox)
197 {
198     (void)pToolBox;
199     OSL_ASSERT(&maToolBox==pToolBox);
200     const sal_uInt16 nItemId (maToolBox.GetHighlightItemId());
201 
202     HandleToolBoxItemClick(nItemId);
203 
204     return sal_True;
205 }
206 
207 } } // end of namespace sfx2::sidebar
208 
209 /* vim: set noet sw=4 ts=4: */
210