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