xref: /aoo41x/main/sfx2/source/sidebar/TitleBar.cxx (revision ba606a71)
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     aFont.SetWeight(WEIGHT_BOLD);
142     SetFont(aFont);
143 
144     // Paint title bar text.
145     SetTextColor(GetTextColor());
146     DrawText(
147         rTitleBox,
148         msTitle,
149         TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER);
150 
151     Pop();
152 }
153 
154 
155 
156 
157 void TitleBar::PaintFocus (const Rectangle& rFocusBox)
158 {
159     Push(PUSH_FONT | PUSH_TEXTCOLOR | PUSH_LINECOLOR | PUSH_FILLCOLOR);
160 
161     const Rectangle aTextBox (
162         GetTextRect(
163             rFocusBox,
164             msTitle,
165             TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER));
166     const Rectangle aLargerTextBox (
167         aTextBox.Left() - 2,
168         aTextBox.Top() - 2,
169         aTextBox.Right() + 2,
170         aTextBox.Bottom() + 2);
171 
172     LineInfo aDottedStyle (LINE_DASH);
173     aDottedStyle.SetDashCount(0);
174     aDottedStyle.SetDotCount(1);
175     aDottedStyle.SetDotLen(1);
176     aDottedStyle.SetDistance(1);
177 
178     SetFillColor();
179     SetLineColor(COL_BLACK);
180     DrawPolyLine(Polygon(aLargerTextBox), aDottedStyle);
181 
182     Pop();
183 }
184 
185 
186 
187 
188 IMPL_LINK(TitleBar, SelectionHandler, ToolBox*, pToolBox)
189 {
190     (void)pToolBox;
191     OSL_ASSERT(&maToolBox==pToolBox);
192     const sal_uInt16 nItemId (maToolBox.GetHighlightItemId());
193 
194     HandleToolBoxItemClick(nItemId);
195 
196     return sal_True;
197 }
198 
199 } } // end of namespace sfx2::sidebar
200