xref: /aoo41x/main/sfx2/source/sidebar/TitleBar.cxx (revision 54eaaa32)
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 
30 ToolbarValue::~ToolbarValue (void) {}
31 
32 
33 namespace sfx2 { namespace sidebar {
34 
35 TitleBar::TitleBar (
36     const ::rtl::OUString& rsTitle,
37     Window* pParentWindow,
38     const sidebar::Paint& rInitialBackgroundPaint)
39     : Window(pParentWindow),
40       maToolBox(this),
41       msTitle(rsTitle)
42 {
43     SetBackground(rInitialBackgroundPaint.GetWallpaper());
44 
45     maToolBox.SetSelectHdl(LINK(this, TitleBar, SelectionHandler));
46 }
47 
48 
49 
50 
51 TitleBar::~TitleBar (void)
52 {
53 }
54 
55 
56 
57 
58 void TitleBar::SetTitle (const ::rtl::OUString& rsTitle)
59 {
60     msTitle = rsTitle;
61     Invalidate();
62 }
63 
64 
65 
66 
67 void TitleBar::Paint (const Rectangle& rUpdateArea)
68 {
69     (void)rUpdateArea;
70 
71     // Paint title bar background.
72     Size aWindowSize( GetOutputSizePixel() );
73     Rectangle aTitleBarBox(
74         0,
75         0,
76         aWindowSize.Width(),
77         aWindowSize.Height()
78         );
79 
80     PaintDecoration(aTitleBarBox);
81     PaintTitle(GetTitleArea(aTitleBarBox));
82 }
83 
84 
85 
86 
87 void TitleBar::DataChanged (const DataChangedEvent& rEvent)
88 {
89     (void)rEvent;
90 
91     SetBackground(GetBackgroundPaint().GetWallpaper());
92 }
93 
94 
95 
96 
97 void TitleBar::SetPosSizePixel (
98     long nX,
99     long nY,
100     long nWidth,
101     long nHeight,
102     sal_uInt16 nFlags)
103 {
104     Window::SetPosSizePixel(nX,nY,nWidth,nHeight,nFlags);
105 
106     // Place the toolbox.
107     const sal_Int32 nToolBoxWidth (maToolBox.GetItemPosRect(0).GetWidth());
108     maToolBox.SetPosSizePixel(nWidth-nToolBoxWidth,0,nToolBoxWidth,nHeight);
109     maToolBox.Show();
110 }
111 
112 
113 
114 
115 void TitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
116 {
117     (void)nItemIndex;
118     // Any real processing has to be done in derived class.
119 }
120 
121 
122 
123 
124 void TitleBar::PaintTitle (const Rectangle& rTitleBox)
125 {
126     Push(PUSH_FONT | PUSH_TEXTCOLOR);
127 
128     // Use a bold font for the deck title.
129     Font aFont(GetFont());
130     aFont.SetWeight(WEIGHT_BOLD);
131     SetFont(aFont);
132 
133     // Paint title bar text.
134     SetTextColor(GetTextColor());
135     DrawText(
136         rTitleBox,
137         msTitle,
138         TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER);
139 
140     Pop();
141 }
142 
143 
144 
145 
146 IMPL_LINK(TitleBar, SelectionHandler, ToolBox*, pToolBox)
147 {
148     (void)pToolBox;
149     OSL_ASSERT(&maToolBox==pToolBox);
150     const sal_uInt16 nItemId (maToolBox.GetHighlightItemId());
151 
152     HandleToolBoxItemClick(nItemId);
153 
154     return sal_True;
155 }
156 
157 } } // end of namespace sfx2::sidebar
158