xref: /trunk/main/sfx2/source/sidebar/TitleBar.cxx (revision 65908a7e)
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 
34 namespace sfx2 { namespace sidebar {
35 
36 TitleBar::TitleBar (
37     const ::rtl::OUString& rsTitle,
38     Window* pParentWindow,
39     const sidebar::Paint& rInitialBackgroundPaint)
40     : Window(pParentWindow),
41       maToolBox(this),
42       msTitle(rsTitle)
43 {
44     SetBackground(rInitialBackgroundPaint.GetWallpaper());
45 
46     maToolBox.SetSelectHdl(LINK(this, TitleBar, SelectionHandler));
47 }
48 
49 
50 
51 
52 TitleBar::~TitleBar (void)
53 {
54 }
55 
56 
57 
58 
59 void TitleBar::SetTitle (const ::rtl::OUString& rsTitle)
60 {
61     msTitle = rsTitle;
62     Invalidate();
63 }
64 
65 
66 
67 
68 void TitleBar::Paint (const Rectangle& rUpdateArea)
69 {
70     (void)rUpdateArea;
71 
72     // Paint title bar background.
73     Size aWindowSize (GetOutputSizePixel());
74     Rectangle aTitleBarBox(
75         0,
76         0,
77         aWindowSize.Width(),
78         aWindowSize.Height()
79         );
80 
81     PaintDecoration(aTitleBarBox);
82     const Rectangle aTitleBox (GetTitleArea(aTitleBarBox));
83     PaintTitle(aTitleBox);
84     if (HasFocus())
85         PaintFocus(aTitleBox);
86 }
87 
88 
89 
90 
91 void TitleBar::DataChanged (const DataChangedEvent& rEvent)
92 {
93     (void)rEvent;
94 
95     SetBackground(GetBackgroundPaint().GetWallpaper());
96 }
97 
98 
99 
100 
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);
113     maToolBox.Show();
114 }
115 
116 
117 
118 
119 ToolBox& TitleBar::GetToolBox (void)
120 {
121     return maToolBox;
122 }
123 
124 
125 
126 
127 void TitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
128 {
129     (void)nItemIndex;
130     // Any real processing has to be done in derived class.
131 }
132 
133 
134 
135 
136 void TitleBar::PaintTitle (const Rectangle& rTitleBox)
137 {
138     Push(PUSH_FONT | PUSH_TEXTCOLOR);
139 
140     Font aFont(GetFont());
141     SetFont(aFont);
142 
143     // Paint title bar text.
144     SetTextColor(GetTextColor());
145     DrawText(
146         rTitleBox,
147         msTitle,
148         TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER);
149 
150     Pop();
151 }
152 
153 
154 
155 
156 void TitleBar::PaintFocus (const Rectangle& rFocusBox)
157 {
158     Push(PUSH_FONT | PUSH_TEXTCOLOR | PUSH_LINECOLOR | PUSH_FILLCOLOR);
159 
160     const Rectangle aTextBox (
161         GetTextRect(
162             rFocusBox,
163             msTitle,
164             TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER));
165     const Rectangle aLargerTextBox (
166         aTextBox.Left() - 2,
167         aTextBox.Top() - 2,
168         aTextBox.Right() + 2,
169         aTextBox.Bottom() + 2);
170 
171     LineInfo aDottedStyle (LINE_DASH);
172     aDottedStyle.SetDashCount(0);
173     aDottedStyle.SetDotCount(1);
174     aDottedStyle.SetDotLen(1);
175     aDottedStyle.SetDistance(1);
176 
177     SetFillColor();
178     SetLineColor(COL_BLACK);
179     DrawPolyLine(Polygon(aLargerTextBox), aDottedStyle);
180 
181     Pop();
182 }
183 
184 
185 
186 
187 IMPL_LINK(TitleBar, SelectionHandler, ToolBox*, pToolBox)
188 {
189     (void)pToolBox;
190     OSL_ASSERT(&maToolBox==pToolBox);
191     const sal_uInt16 nItemId (maToolBox.GetHighlightItemId());
192 
193     HandleToolBoxItemClick(nItemId);
194 
195     return sal_True;
196 }
197 
198 } } // end of namespace sfx2::sidebar
199