xref: /trunk/main/sfx2/source/sidebar/TitleBar.cxx (revision 549760eabef7046a021eb562805aa3542b2e9b62)
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"
263b2c5b9dSAndre Fischer #include "Accessible.hxx"
273b2c5b9dSAndre Fischer #include "AccessibleTitleBar.hxx"
2822de8995SAndre Fischer 
2922de8995SAndre Fischer #include <tools/svborder.hxx>
3022de8995SAndre Fischer #include <vcl/gradient.hxx>
3165908a7eSAndre Fischer #include <vcl/lineinfo.hxx>
3222de8995SAndre Fischer 
333b2c5b9dSAndre Fischer #include <com/sun/star/accessibility/AccessibleRole.hpp>
343b2c5b9dSAndre Fischer 
~ToolbarValue(void)35ff12d537SAndre Fischer ToolbarValue::~ToolbarValue (void) {}
3622de8995SAndre Fischer 
374e21436dSAndre Fischer namespace
384e21436dSAndre Fischer {
394e21436dSAndre Fischer     const static sal_Int32 gnLeftIconSpace (3);
404e21436dSAndre Fischer     const static sal_Int32 gnRightIconSpace (3);
414e21436dSAndre Fischer }
42ff12d537SAndre Fischer 
43ff12d537SAndre Fischer namespace sfx2 { namespace sidebar {
4422de8995SAndre Fischer 
TitleBar(const::rtl::OUString & rsTitle,Window * pParentWindow,const sidebar::Paint & rInitialBackgroundPaint)4522de8995SAndre Fischer TitleBar::TitleBar (
4622de8995SAndre Fischer     const ::rtl::OUString& rsTitle,
477a32b0c8SAndre Fischer     Window* pParentWindow,
487a32b0c8SAndre Fischer     const sidebar::Paint& rInitialBackgroundPaint)
4922de8995SAndre Fischer     : Window(pParentWindow),
507a32b0c8SAndre Fischer       maToolBox(this),
514e21436dSAndre Fischer       msTitle(rsTitle),
524e21436dSAndre Fischer       maIcon()
5322de8995SAndre Fischer {
547a32b0c8SAndre Fischer     SetBackground(rInitialBackgroundPaint.GetWallpaper());
557a32b0c8SAndre Fischer 
567a32b0c8SAndre Fischer     maToolBox.SetSelectHdl(LINK(this, TitleBar, SelectionHandler));
5722de8995SAndre Fischer }
5822de8995SAndre Fischer 
~TitleBar(void)5922de8995SAndre Fischer TitleBar::~TitleBar (void)
6022de8995SAndre Fischer {
6122de8995SAndre Fischer }
6222de8995SAndre Fischer 
SetTitle(const::rtl::OUString & rsTitle)6354eaaa32SAndre Fischer void TitleBar::SetTitle (const ::rtl::OUString& rsTitle)
6454eaaa32SAndre Fischer {
6554eaaa32SAndre Fischer     msTitle = rsTitle;
6654eaaa32SAndre Fischer     Invalidate();
6754eaaa32SAndre Fischer }
6854eaaa32SAndre Fischer 
SetIcon(const Image & rIcon)694e21436dSAndre Fischer void TitleBar::SetIcon (const Image& rIcon)
704e21436dSAndre Fischer {
714e21436dSAndre Fischer     maIcon = rIcon;
724e21436dSAndre Fischer     Invalidate();
734e21436dSAndre Fischer }
744e21436dSAndre Fischer 
Paint(const Rectangle & rUpdateArea)7522de8995SAndre Fischer void TitleBar::Paint (const Rectangle& rUpdateArea)
7622de8995SAndre Fischer {
7795a18594SAndre Fischer     (void)rUpdateArea;
7895a18594SAndre Fischer 
7922de8995SAndre Fischer     // Paint title bar background.
8022de8995SAndre Fischer     Size aWindowSize (GetOutputSizePixel());
81ff12d537SAndre Fischer     Rectangle aTitleBarBox(
82ff12d537SAndre Fischer         0,
83ff12d537SAndre Fischer         0,
84ff12d537SAndre Fischer         aWindowSize.Width(),
85ff12d537SAndre Fischer         aWindowSize.Height()
86ff12d537SAndre Fischer         );
87ff12d537SAndre Fischer 
88ff12d537SAndre Fischer     PaintDecoration(aTitleBarBox);
8965908a7eSAndre Fischer     const Rectangle aTitleBox (GetTitleArea(aTitleBarBox));
9065908a7eSAndre Fischer     PaintTitle(aTitleBox);
9165908a7eSAndre Fischer     PaintFocus(aTitleBox);
92ff12d537SAndre Fischer }
93ff12d537SAndre Fischer 
DataChanged(const DataChangedEvent & rEvent)947a32b0c8SAndre Fischer void TitleBar::DataChanged (const DataChangedEvent& rEvent)
95ff12d537SAndre Fischer {
967a32b0c8SAndre Fischer     (void)rEvent;
97ff12d537SAndre Fischer 
987a32b0c8SAndre Fischer     SetBackground(GetBackgroundPaint().GetWallpaper());
99ff12d537SAndre Fischer }
1007a32b0c8SAndre Fischer 
SetPosSizePixel(long nX,long nY,long nWidth,long nHeight,sal_uInt16 nFlags)1017a32b0c8SAndre Fischer void TitleBar::SetPosSizePixel (
1027a32b0c8SAndre Fischer     long nX,
1037a32b0c8SAndre Fischer     long nY,
1047a32b0c8SAndre Fischer     long nWidth,
1057a32b0c8SAndre Fischer     long nHeight,
1067a32b0c8SAndre Fischer     sal_uInt16 nFlags)
1077a32b0c8SAndre Fischer {
1087a32b0c8SAndre Fischer     Window::SetPosSizePixel(nX,nY,nWidth,nHeight,nFlags);
1097a32b0c8SAndre Fischer 
1107a32b0c8SAndre Fischer     // Place the toolbox.
1117a32b0c8SAndre Fischer     const sal_Int32 nToolBoxWidth (maToolBox.GetItemPosRect(0).GetWidth());
1128a1a651aSAndre Fischer     maToolBox.SetPosSizePixel(nWidth-nToolBoxWidth,0, nToolBoxWidth,nHeight, WINDOW_POSSIZE_POSSIZE);
1137a32b0c8SAndre Fischer     maToolBox.Show();
1147a32b0c8SAndre Fischer }
1157a32b0c8SAndre Fischer 
GetToolBox(void)11665908a7eSAndre Fischer ToolBox& TitleBar::GetToolBox (void)
11765908a7eSAndre Fischer {
11865908a7eSAndre Fischer     return maToolBox;
11965908a7eSAndre Fischer }
12065908a7eSAndre Fischer 
GetToolBox(void) const12152d13b84SAndre Fischer const ToolBox& TitleBar::GetToolBox (void) const
12252d13b84SAndre Fischer {
12352d13b84SAndre Fischer     return maToolBox;
12452d13b84SAndre Fischer }
12552d13b84SAndre Fischer 
HandleToolBoxItemClick(const sal_uInt16 nItemIndex)1267a32b0c8SAndre Fischer void TitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
1277a32b0c8SAndre Fischer {
1287a32b0c8SAndre Fischer     (void)nItemIndex;
1297a32b0c8SAndre Fischer     // Any real processing has to be done in derived class.
130ff12d537SAndre Fischer }
131ff12d537SAndre Fischer 
CreateAccessible(void)1323b2c5b9dSAndre Fischer cssu::Reference<css::accessibility::XAccessible> TitleBar::CreateAccessible (void)
1333b2c5b9dSAndre Fischer {
1343b2c5b9dSAndre Fischer     SetAccessibleRole(css::accessibility::AccessibleRole::PANEL);
1353b2c5b9dSAndre Fischer     return AccessibleTitleBar::Create(*this);
1363b2c5b9dSAndre Fischer }
1373b2c5b9dSAndre Fischer 
PaintTitle(const Rectangle & rTitleBox)138ff12d537SAndre Fischer void TitleBar::PaintTitle (const Rectangle& rTitleBox)
139ff12d537SAndre Fischer {
140ff12d537SAndre Fischer     Push(PUSH_FONT | PUSH_TEXTCOLOR);
14122de8995SAndre Fischer 
1424e21436dSAndre Fischer     Rectangle aTitleBox (rTitleBox);
1434e21436dSAndre Fischer 
144*549760eaSmseidel     // When there is an icon then paint it at the left of the given box.
1454e21436dSAndre Fischer     if ( !! maIcon)
1464e21436dSAndre Fischer     {
1474e21436dSAndre Fischer         DrawImage(
1484e21436dSAndre Fischer             Point(
1494e21436dSAndre Fischer                 aTitleBox.Left() + gnLeftIconSpace,
1504e21436dSAndre Fischer                 aTitleBox.Top() + (aTitleBox.GetHeight()-maIcon.GetSizePixel().Height())/2),
1514e21436dSAndre Fischer             maIcon);
1524e21436dSAndre Fischer         aTitleBox.Left() += gnLeftIconSpace + maIcon.GetSizePixel().Width() + gnRightIconSpace;
1534e21436dSAndre Fischer     }
1544e21436dSAndre Fischer 
15522de8995SAndre Fischer     Font aFont(GetFont());
156ba606a71SAndre Fischer     aFont.SetWeight(WEIGHT_BOLD);
15722de8995SAndre Fischer     SetFont(aFont);
15822de8995SAndre Fischer 
15922de8995SAndre Fischer     // Paint title bar text.
160ff12d537SAndre Fischer     SetTextColor(GetTextColor());
16122de8995SAndre Fischer     DrawText(
1624e21436dSAndre Fischer         aTitleBox,
16322de8995SAndre Fischer         msTitle,
16422de8995SAndre Fischer         TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER);
16522de8995SAndre Fischer 
16622de8995SAndre Fischer     Pop();
16722de8995SAndre Fischer }
16822de8995SAndre Fischer 
PaintFocus(const Rectangle & rFocusBox)16965908a7eSAndre Fischer void TitleBar::PaintFocus (const Rectangle& rFocusBox)
17065908a7eSAndre Fischer {
1713b2c5b9dSAndre Fischer     Push(PUSH_FONT | PUSH_TEXTCOLOR);
17265908a7eSAndre Fischer 
17352d13b84SAndre Fischer     Font aFont(GetFont());
17452d13b84SAndre Fischer     aFont.SetWeight(WEIGHT_BOLD);
17552d13b84SAndre Fischer     SetFont(aFont);
17652d13b84SAndre Fischer 
17765908a7eSAndre Fischer     const Rectangle aTextBox (
17865908a7eSAndre Fischer         GetTextRect(
17965908a7eSAndre Fischer             rFocusBox,
18065908a7eSAndre Fischer             msTitle,
18165908a7eSAndre Fischer             TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER));
18265908a7eSAndre Fischer     const Rectangle aLargerTextBox (
18365908a7eSAndre Fischer         aTextBox.Left() - 2,
18465908a7eSAndre Fischer         aTextBox.Top() - 2,
18565908a7eSAndre Fischer         aTextBox.Right() + 2,
18665908a7eSAndre Fischer         aTextBox.Bottom() + 2);
18765908a7eSAndre Fischer 
1883b2c5b9dSAndre Fischer     if (HasFocus())
1893b2c5b9dSAndre Fischer         Window::ShowFocus(aLargerTextBox);
1903b2c5b9dSAndre Fischer     else
1913b2c5b9dSAndre Fischer         Window::HideFocus();
19265908a7eSAndre Fischer 
19365908a7eSAndre Fischer     Pop();
19465908a7eSAndre Fischer }
19565908a7eSAndre Fischer 
IMPL_LINK(TitleBar,SelectionHandler,ToolBox *,pToolBox)1967a32b0c8SAndre Fischer IMPL_LINK(TitleBar, SelectionHandler, ToolBox*, pToolBox)
1977a32b0c8SAndre Fischer {
1987a32b0c8SAndre Fischer     (void)pToolBox;
1997a32b0c8SAndre Fischer     OSL_ASSERT(&maToolBox==pToolBox);
2007a32b0c8SAndre Fischer     const sal_uInt16 nItemId (maToolBox.GetHighlightItemId());
2017a32b0c8SAndre Fischer 
2027a32b0c8SAndre Fischer     HandleToolBoxItemClick(nItemId);
2037a32b0c8SAndre Fischer 
2047a32b0c8SAndre Fischer     return sal_True;
2057a32b0c8SAndre Fischer }
2067a32b0c8SAndre Fischer 
207ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
208*549760eaSmseidel 
209*549760eaSmseidel /* vim: set noet sw=4 ts=4: */
210