xref: /aoo41x/main/sfx2/source/sidebar/TitleBar.cxx (revision 8a1a651a)
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, WINDOW_POSSIZE_POSSIZE);
128     maToolBox.Show();
129 }
130 
131 
132 
133 
134 ToolBox& TitleBar::GetToolBox (void)
135 {
136     return maToolBox;
137 }
138 
139 
140 
141 
142 const ToolBox& TitleBar::GetToolBox (void) const
143 {
144     return maToolBox;
145 }
146 
147 
148 
149 
150 void TitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
151 {
152     (void)nItemIndex;
153     // Any real processing has to be done in derived class.
154 }
155 
156 
157 
158 
159 void TitleBar::PaintTitle (const Rectangle& rTitleBox)
160 {
161     Push(PUSH_FONT | PUSH_TEXTCOLOR);
162 
163     Rectangle aTitleBox (rTitleBox);
164 
165     // When there is an icon then paint it at the left of the given
166     // box.
167     if ( !! maIcon)
168     {
169         DrawImage(
170             Point(
171                 aTitleBox.Left() + gnLeftIconSpace,
172                 aTitleBox.Top() + (aTitleBox.GetHeight()-maIcon.GetSizePixel().Height())/2),
173             maIcon);
174         aTitleBox.Left() += gnLeftIconSpace + maIcon.GetSizePixel().Width() + gnRightIconSpace;
175     }
176 
177     Font aFont(GetFont());
178     aFont.SetWeight(WEIGHT_BOLD);
179     SetFont(aFont);
180 
181     // Paint title bar text.
182     SetTextColor(GetTextColor());
183     DrawText(
184         aTitleBox,
185         msTitle,
186         TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER);
187 
188     Pop();
189 }
190 
191 
192 
193 
194 void TitleBar::PaintFocus (const Rectangle& rFocusBox)
195 {
196     Push(PUSH_FONT | PUSH_TEXTCOLOR | PUSH_LINECOLOR | PUSH_FILLCOLOR);
197 
198     Font aFont(GetFont());
199     aFont.SetWeight(WEIGHT_BOLD);
200     SetFont(aFont);
201 
202     const Rectangle aTextBox (
203         GetTextRect(
204             rFocusBox,
205             msTitle,
206             TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER));
207     const Rectangle aLargerTextBox (
208         aTextBox.Left() - 2,
209         aTextBox.Top() - 2,
210         aTextBox.Right() + 2,
211         aTextBox.Bottom() + 2);
212 
213     LineInfo aDottedStyle (LINE_DASH);
214     aDottedStyle.SetDashCount(0);
215     aDottedStyle.SetDotCount(1);
216     aDottedStyle.SetDotLen(1);
217     aDottedStyle.SetDistance(1);
218 
219     SetFillColor();
220     SetLineColor(COL_BLACK);
221     DrawPolyLine(Polygon(aLargerTextBox), aDottedStyle);
222 
223     Pop();
224 }
225 
226 
227 
228 
229 IMPL_LINK(TitleBar, SelectionHandler, ToolBox*, pToolBox)
230 {
231     (void)pToolBox;
232     OSL_ASSERT(&maToolBox==pToolBox);
233     const sal_uInt16 nItemId (maToolBox.GetHighlightItemId());
234 
235     HandleToolBoxItemClick(nItemId);
236 
237     return sal_True;
238 }
239 
240 } } // end of namespace sfx2::sidebar
241