xref: /AOO41X/main/sfx2/source/sidebar/TitleBar.cxx (revision 52d13b840d5953d0e19a59e3804b0502534d8c83)
122de8995SAndre Fischer /**************************************************************
222de8995SAndre Fischer  *
322de8995SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
422de8995SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
522de8995SAndre Fischer  * distributed with this work for additional information
622de8995SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
722de8995SAndre Fischer  * to you under the Apache License, Version 2.0 (the
822de8995SAndre Fischer  * "License"); you may not use this file except in compliance
922de8995SAndre Fischer  * with the License.  You may obtain a copy of the License at
1022de8995SAndre Fischer  *
1122de8995SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
1222de8995SAndre Fischer  *
1322de8995SAndre Fischer  * Unless required by applicable law or agreed to in writing,
1422de8995SAndre Fischer  * software distributed under the License is distributed on an
1522de8995SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1622de8995SAndre Fischer  * KIND, either express or implied.  See the License for the
1722de8995SAndre Fischer  * specific language governing permissions and limitations
1822de8995SAndre Fischer  * under the License.
1922de8995SAndre Fischer  *
2022de8995SAndre Fischer  *************************************************************/
2122de8995SAndre Fischer 
2222de8995SAndre Fischer #include "precompiled_sfx2.hxx"
2322de8995SAndre Fischer 
2422de8995SAndre Fischer #include "TitleBar.hxx"
25ff12d537SAndre Fischer #include "Paint.hxx"
2622de8995SAndre Fischer 
2722de8995SAndre Fischer #include <tools/svborder.hxx>
2822de8995SAndre Fischer #include <vcl/gradient.hxx>
2965908a7eSAndre Fischer #include <vcl/lineinfo.hxx>
3022de8995SAndre Fischer 
31ff12d537SAndre Fischer ToolbarValue::~ToolbarValue (void) {}
3222de8995SAndre Fischer 
334e21436dSAndre Fischer namespace
344e21436dSAndre Fischer {
354e21436dSAndre Fischer     const static sal_Int32 gnLeftIconSpace (3);
364e21436dSAndre Fischer     const static sal_Int32 gnRightIconSpace (3);
374e21436dSAndre Fischer }
38ff12d537SAndre Fischer 
39ff12d537SAndre Fischer namespace sfx2 { namespace sidebar {
4022de8995SAndre Fischer 
4122de8995SAndre Fischer TitleBar::TitleBar (
4222de8995SAndre Fischer     const ::rtl::OUString& rsTitle,
437a32b0c8SAndre Fischer     Window* pParentWindow,
447a32b0c8SAndre Fischer     const sidebar::Paint& rInitialBackgroundPaint)
4522de8995SAndre Fischer     : Window(pParentWindow),
467a32b0c8SAndre Fischer       maToolBox(this),
474e21436dSAndre Fischer       msTitle(rsTitle),
484e21436dSAndre Fischer       maIcon()
4922de8995SAndre Fischer {
507a32b0c8SAndre Fischer     SetBackground(rInitialBackgroundPaint.GetWallpaper());
517a32b0c8SAndre Fischer 
527a32b0c8SAndre Fischer     maToolBox.SetSelectHdl(LINK(this, TitleBar, SelectionHandler));
5322de8995SAndre Fischer }
5422de8995SAndre Fischer 
5522de8995SAndre Fischer 
5622de8995SAndre Fischer 
5722de8995SAndre Fischer 
5822de8995SAndre Fischer TitleBar::~TitleBar (void)
5922de8995SAndre Fischer {
6022de8995SAndre Fischer }
6122de8995SAndre Fischer 
6222de8995SAndre Fischer 
6322de8995SAndre Fischer 
6422de8995SAndre Fischer 
6554eaaa32SAndre Fischer void TitleBar::SetTitle (const ::rtl::OUString& rsTitle)
6654eaaa32SAndre Fischer {
6754eaaa32SAndre Fischer     msTitle = rsTitle;
6854eaaa32SAndre Fischer     Invalidate();
6954eaaa32SAndre Fischer }
7054eaaa32SAndre Fischer 
7154eaaa32SAndre Fischer 
7254eaaa32SAndre Fischer 
7354eaaa32SAndre Fischer 
744e21436dSAndre Fischer void TitleBar::SetIcon (const Image& rIcon)
754e21436dSAndre Fischer {
764e21436dSAndre Fischer     maIcon = rIcon;
774e21436dSAndre Fischer     Invalidate();
784e21436dSAndre Fischer }
794e21436dSAndre Fischer 
804e21436dSAndre Fischer 
814e21436dSAndre Fischer 
824e21436dSAndre Fischer 
8322de8995SAndre Fischer void TitleBar::Paint (const Rectangle& rUpdateArea)
8422de8995SAndre Fischer {
8595a18594SAndre Fischer     (void)rUpdateArea;
8695a18594SAndre Fischer 
8722de8995SAndre Fischer     // Paint title bar background.
8822de8995SAndre Fischer     Size aWindowSize (GetOutputSizePixel());
89ff12d537SAndre Fischer     Rectangle aTitleBarBox(
90ff12d537SAndre Fischer         0,
91ff12d537SAndre Fischer         0,
92ff12d537SAndre Fischer         aWindowSize.Width(),
93ff12d537SAndre Fischer         aWindowSize.Height()
94ff12d537SAndre Fischer         );
95ff12d537SAndre Fischer 
96ff12d537SAndre Fischer     PaintDecoration(aTitleBarBox);
9765908a7eSAndre Fischer     const Rectangle aTitleBox (GetTitleArea(aTitleBarBox));
9865908a7eSAndre Fischer     PaintTitle(aTitleBox);
9965908a7eSAndre Fischer     if (HasFocus())
10065908a7eSAndre Fischer         PaintFocus(aTitleBox);
101ff12d537SAndre Fischer }
102ff12d537SAndre Fischer 
103ff12d537SAndre Fischer 
104ff12d537SAndre Fischer 
105b9e67834SAndre Fischer 
1067a32b0c8SAndre Fischer void TitleBar::DataChanged (const DataChangedEvent& rEvent)
107ff12d537SAndre Fischer {
1087a32b0c8SAndre Fischer     (void)rEvent;
109ff12d537SAndre Fischer 
1107a32b0c8SAndre Fischer     SetBackground(GetBackgroundPaint().GetWallpaper());
111ff12d537SAndre Fischer }
1127a32b0c8SAndre Fischer 
1137a32b0c8SAndre Fischer 
1147a32b0c8SAndre Fischer 
1157a32b0c8SAndre Fischer 
1167a32b0c8SAndre Fischer void TitleBar::SetPosSizePixel (
1177a32b0c8SAndre Fischer     long nX,
1187a32b0c8SAndre Fischer     long nY,
1197a32b0c8SAndre Fischer     long nWidth,
1207a32b0c8SAndre Fischer     long nHeight,
1217a32b0c8SAndre Fischer     sal_uInt16 nFlags)
1227a32b0c8SAndre Fischer {
1237a32b0c8SAndre Fischer     Window::SetPosSizePixel(nX,nY,nWidth,nHeight,nFlags);
1247a32b0c8SAndre Fischer 
1257a32b0c8SAndre Fischer     // Place the toolbox.
1267a32b0c8SAndre Fischer     const sal_Int32 nToolBoxWidth (maToolBox.GetItemPosRect(0).GetWidth());
1277a32b0c8SAndre Fischer     maToolBox.SetPosSizePixel(nWidth-nToolBoxWidth,0,nToolBoxWidth,nHeight);
1287a32b0c8SAndre Fischer     maToolBox.Show();
1297a32b0c8SAndre Fischer }
1307a32b0c8SAndre Fischer 
1317a32b0c8SAndre Fischer 
1327a32b0c8SAndre Fischer 
1337a32b0c8SAndre Fischer 
13465908a7eSAndre Fischer ToolBox& TitleBar::GetToolBox (void)
13565908a7eSAndre Fischer {
13665908a7eSAndre Fischer     return maToolBox;
13765908a7eSAndre Fischer }
13865908a7eSAndre Fischer 
13965908a7eSAndre Fischer 
14065908a7eSAndre Fischer 
14165908a7eSAndre Fischer 
142*52d13b84SAndre Fischer const ToolBox& TitleBar::GetToolBox (void) const
143*52d13b84SAndre Fischer {
144*52d13b84SAndre Fischer     return maToolBox;
145*52d13b84SAndre Fischer }
146*52d13b84SAndre Fischer 
147*52d13b84SAndre Fischer 
148*52d13b84SAndre Fischer 
149*52d13b84SAndre Fischer 
1507a32b0c8SAndre Fischer void TitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
1517a32b0c8SAndre Fischer {
1527a32b0c8SAndre Fischer     (void)nItemIndex;
1537a32b0c8SAndre Fischer     // Any real processing has to be done in derived class.
154ff12d537SAndre Fischer }
155ff12d537SAndre Fischer 
156ff12d537SAndre Fischer 
157ff12d537SAndre Fischer 
158ff12d537SAndre Fischer 
159ff12d537SAndre Fischer void TitleBar::PaintTitle (const Rectangle& rTitleBox)
160ff12d537SAndre Fischer {
161ff12d537SAndre Fischer     Push(PUSH_FONT | PUSH_TEXTCOLOR);
16222de8995SAndre Fischer 
1634e21436dSAndre Fischer     Rectangle aTitleBox (rTitleBox);
1644e21436dSAndre Fischer 
1654e21436dSAndre Fischer     // When there is an icon then paint it at the left of the given
1664e21436dSAndre Fischer     // box.
1674e21436dSAndre Fischer     if ( !! maIcon)
1684e21436dSAndre Fischer     {
1694e21436dSAndre Fischer         DrawImage(
1704e21436dSAndre Fischer             Point(
1714e21436dSAndre Fischer                 aTitleBox.Left() + gnLeftIconSpace,
1724e21436dSAndre Fischer                 aTitleBox.Top() + (aTitleBox.GetHeight()-maIcon.GetSizePixel().Height())/2),
1734e21436dSAndre Fischer             maIcon);
1744e21436dSAndre Fischer         aTitleBox.Left() += gnLeftIconSpace + maIcon.GetSizePixel().Width() + gnRightIconSpace;
1754e21436dSAndre Fischer     }
1764e21436dSAndre Fischer 
17722de8995SAndre Fischer     Font aFont(GetFont());
178ba606a71SAndre Fischer     aFont.SetWeight(WEIGHT_BOLD);
17922de8995SAndre Fischer     SetFont(aFont);
18022de8995SAndre Fischer 
18122de8995SAndre Fischer     // Paint title bar text.
182ff12d537SAndre Fischer     SetTextColor(GetTextColor());
18322de8995SAndre Fischer     DrawText(
1844e21436dSAndre Fischer         aTitleBox,
18522de8995SAndre Fischer         msTitle,
18622de8995SAndre Fischer         TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER);
18722de8995SAndre Fischer 
18822de8995SAndre Fischer     Pop();
18922de8995SAndre Fischer }
19022de8995SAndre Fischer 
19122de8995SAndre Fischer 
1927a32b0c8SAndre Fischer 
1937a32b0c8SAndre Fischer 
19465908a7eSAndre Fischer void TitleBar::PaintFocus (const Rectangle& rFocusBox)
19565908a7eSAndre Fischer {
19665908a7eSAndre Fischer     Push(PUSH_FONT | PUSH_TEXTCOLOR | PUSH_LINECOLOR | PUSH_FILLCOLOR);
19765908a7eSAndre Fischer 
198*52d13b84SAndre Fischer     Font aFont(GetFont());
199*52d13b84SAndre Fischer     aFont.SetWeight(WEIGHT_BOLD);
200*52d13b84SAndre Fischer     SetFont(aFont);
201*52d13b84SAndre Fischer 
20265908a7eSAndre Fischer     const Rectangle aTextBox (
20365908a7eSAndre Fischer         GetTextRect(
20465908a7eSAndre Fischer             rFocusBox,
20565908a7eSAndre Fischer             msTitle,
20665908a7eSAndre Fischer             TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER));
20765908a7eSAndre Fischer     const Rectangle aLargerTextBox (
20865908a7eSAndre Fischer         aTextBox.Left() - 2,
20965908a7eSAndre Fischer         aTextBox.Top() - 2,
21065908a7eSAndre Fischer         aTextBox.Right() + 2,
21165908a7eSAndre Fischer         aTextBox.Bottom() + 2);
21265908a7eSAndre Fischer 
21365908a7eSAndre Fischer     LineInfo aDottedStyle (LINE_DASH);
21465908a7eSAndre Fischer     aDottedStyle.SetDashCount(0);
21565908a7eSAndre Fischer     aDottedStyle.SetDotCount(1);
21665908a7eSAndre Fischer     aDottedStyle.SetDotLen(1);
21765908a7eSAndre Fischer     aDottedStyle.SetDistance(1);
21865908a7eSAndre Fischer 
21965908a7eSAndre Fischer     SetFillColor();
22065908a7eSAndre Fischer     SetLineColor(COL_BLACK);
22165908a7eSAndre Fischer     DrawPolyLine(Polygon(aLargerTextBox), aDottedStyle);
22265908a7eSAndre Fischer 
22365908a7eSAndre Fischer     Pop();
22465908a7eSAndre Fischer }
22565908a7eSAndre Fischer 
22665908a7eSAndre Fischer 
22765908a7eSAndre Fischer 
22865908a7eSAndre Fischer 
2297a32b0c8SAndre Fischer IMPL_LINK(TitleBar, SelectionHandler, ToolBox*, pToolBox)
2307a32b0c8SAndre Fischer {
2317a32b0c8SAndre Fischer     (void)pToolBox;
2327a32b0c8SAndre Fischer     OSL_ASSERT(&maToolBox==pToolBox);
2337a32b0c8SAndre Fischer     const sal_uInt16 nItemId (maToolBox.GetHighlightItemId());
2347a32b0c8SAndre Fischer 
2357a32b0c8SAndre Fischer     HandleToolBoxItemClick(nItemId);
2367a32b0c8SAndre Fischer 
2377a32b0c8SAndre Fischer     return sal_True;
2387a32b0c8SAndre Fischer }
2397a32b0c8SAndre Fischer 
240ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
241