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"
26*3b2c5b9dSAndre Fischer #include "Accessible.hxx"
27*3b2c5b9dSAndre 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
33*3b2c5b9dSAndre Fischer #include <com/sun/star/accessibility/AccessibleRole.hpp>
34*3b2c5b9dSAndre Fischer
35*3b2c5b9dSAndre Fischer
~ToolbarValue(void)36ff12d537SAndre Fischer ToolbarValue::~ToolbarValue (void) {}
3722de8995SAndre Fischer
384e21436dSAndre Fischer namespace
394e21436dSAndre Fischer {
404e21436dSAndre Fischer const static sal_Int32 gnLeftIconSpace (3);
414e21436dSAndre Fischer const static sal_Int32 gnRightIconSpace (3);
424e21436dSAndre Fischer }
43ff12d537SAndre Fischer
44ff12d537SAndre Fischer namespace sfx2 { namespace sidebar {
4522de8995SAndre Fischer
TitleBar(const::rtl::OUString & rsTitle,Window * pParentWindow,const sidebar::Paint & rInitialBackgroundPaint)4622de8995SAndre Fischer TitleBar::TitleBar (
4722de8995SAndre Fischer const ::rtl::OUString& rsTitle,
487a32b0c8SAndre Fischer Window* pParentWindow,
497a32b0c8SAndre Fischer const sidebar::Paint& rInitialBackgroundPaint)
5022de8995SAndre Fischer : Window(pParentWindow),
517a32b0c8SAndre Fischer maToolBox(this),
524e21436dSAndre Fischer msTitle(rsTitle),
534e21436dSAndre Fischer maIcon()
5422de8995SAndre Fischer {
557a32b0c8SAndre Fischer SetBackground(rInitialBackgroundPaint.GetWallpaper());
564e21436dSAndre Fischer
577a32b0c8SAndre Fischer maToolBox.SetSelectHdl(LINK(this, TitleBar, SelectionHandler));
5822de8995SAndre Fischer }
5922de8995SAndre Fischer
6022de8995SAndre Fischer
6122de8995SAndre Fischer
6222de8995SAndre Fischer
~TitleBar(void)6322de8995SAndre Fischer TitleBar::~TitleBar (void)
6422de8995SAndre Fischer {
6522de8995SAndre Fischer }
6622de8995SAndre Fischer
6722de8995SAndre Fischer
6822de8995SAndre Fischer
6922de8995SAndre Fischer
SetTitle(const::rtl::OUString & rsTitle)7054eaaa32SAndre Fischer void TitleBar::SetTitle (const ::rtl::OUString& rsTitle)
7154eaaa32SAndre Fischer {
7254eaaa32SAndre Fischer msTitle = rsTitle;
7354eaaa32SAndre Fischer Invalidate();
7454eaaa32SAndre Fischer }
7554eaaa32SAndre Fischer
7654eaaa32SAndre Fischer
7754eaaa32SAndre Fischer
7854eaaa32SAndre Fischer
SetIcon(const Image & rIcon)794e21436dSAndre Fischer void TitleBar::SetIcon (const Image& rIcon)
804e21436dSAndre Fischer {
814e21436dSAndre Fischer maIcon = rIcon;
824e21436dSAndre Fischer Invalidate();
834e21436dSAndre Fischer }
844e21436dSAndre Fischer
854e21436dSAndre Fischer
864e21436dSAndre Fischer
874e21436dSAndre Fischer
Paint(const Rectangle & rUpdateArea)8822de8995SAndre Fischer void TitleBar::Paint (const Rectangle& rUpdateArea)
8922de8995SAndre Fischer {
9095a18594SAndre Fischer (void)rUpdateArea;
9195a18594SAndre Fischer
9222de8995SAndre Fischer // Paint title bar background.
9365908a7eSAndre Fischer Size aWindowSize (GetOutputSizePixel());
94ff12d537SAndre Fischer Rectangle aTitleBarBox(
95ff12d537SAndre Fischer 0,
96ff12d537SAndre Fischer 0,
97ff12d537SAndre Fischer aWindowSize.Width(),
98ff12d537SAndre Fischer aWindowSize.Height()
99ff12d537SAndre Fischer );
100ff12d537SAndre Fischer
101ff12d537SAndre Fischer PaintDecoration(aTitleBarBox);
10265908a7eSAndre Fischer const Rectangle aTitleBox (GetTitleArea(aTitleBarBox));
10365908a7eSAndre Fischer PaintTitle(aTitleBox);
104*3b2c5b9dSAndre Fischer PaintFocus(aTitleBox);
105ff12d537SAndre Fischer }
106ff12d537SAndre Fischer
107ff12d537SAndre Fischer
108ff12d537SAndre Fischer
109b9e67834SAndre Fischer
DataChanged(const DataChangedEvent & rEvent)1107a32b0c8SAndre Fischer void TitleBar::DataChanged (const DataChangedEvent& rEvent)
1117a32b0c8SAndre Fischer {
1127a32b0c8SAndre Fischer (void)rEvent;
1137a32b0c8SAndre Fischer
1147a32b0c8SAndre Fischer SetBackground(GetBackgroundPaint().GetWallpaper());
1157a32b0c8SAndre Fischer }
1167a32b0c8SAndre Fischer
1177a32b0c8SAndre Fischer
1187a32b0c8SAndre Fischer
1197a32b0c8SAndre Fischer
SetPosSizePixel(long nX,long nY,long nWidth,long nHeight,sal_uInt16 nFlags)1207a32b0c8SAndre Fischer void TitleBar::SetPosSizePixel (
1217a32b0c8SAndre Fischer long nX,
1227a32b0c8SAndre Fischer long nY,
1237a32b0c8SAndre Fischer long nWidth,
1247a32b0c8SAndre Fischer long nHeight,
1257a32b0c8SAndre Fischer sal_uInt16 nFlags)
126ff12d537SAndre Fischer {
1277a32b0c8SAndre Fischer Window::SetPosSizePixel(nX,nY,nWidth,nHeight,nFlags);
1287a32b0c8SAndre Fischer
1297a32b0c8SAndre Fischer // Place the toolbox.
1307a32b0c8SAndre Fischer const sal_Int32 nToolBoxWidth (maToolBox.GetItemPosRect(0).GetWidth());
1318a1a651aSAndre Fischer maToolBox.SetPosSizePixel(nWidth-nToolBoxWidth,0, nToolBoxWidth,nHeight, WINDOW_POSSIZE_POSSIZE);
1327a32b0c8SAndre Fischer maToolBox.Show();
1337a32b0c8SAndre Fischer }
1347a32b0c8SAndre Fischer
1357a32b0c8SAndre Fischer
1367a32b0c8SAndre Fischer
1377a32b0c8SAndre Fischer
GetToolBox(void)13865908a7eSAndre Fischer ToolBox& TitleBar::GetToolBox (void)
13965908a7eSAndre Fischer {
14065908a7eSAndre Fischer return maToolBox;
14165908a7eSAndre Fischer }
14265908a7eSAndre Fischer
14365908a7eSAndre Fischer
14465908a7eSAndre Fischer
14565908a7eSAndre Fischer
GetToolBox(void) const14652d13b84SAndre Fischer const ToolBox& TitleBar::GetToolBox (void) const
14752d13b84SAndre Fischer {
14852d13b84SAndre Fischer return maToolBox;
14952d13b84SAndre Fischer }
15052d13b84SAndre Fischer
15152d13b84SAndre Fischer
15252d13b84SAndre Fischer
15352d13b84SAndre Fischer
HandleToolBoxItemClick(const sal_uInt16 nItemIndex)1547a32b0c8SAndre Fischer void TitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
1557a32b0c8SAndre Fischer {
1567a32b0c8SAndre Fischer (void)nItemIndex;
1577a32b0c8SAndre Fischer // Any real processing has to be done in derived class.
158ff12d537SAndre Fischer }
159ff12d537SAndre Fischer
160ff12d537SAndre Fischer
161ff12d537SAndre Fischer
162ff12d537SAndre Fischer
CreateAccessible(void)163*3b2c5b9dSAndre Fischer cssu::Reference<css::accessibility::XAccessible> TitleBar::CreateAccessible (void)
164*3b2c5b9dSAndre Fischer {
165*3b2c5b9dSAndre Fischer SetAccessibleRole(css::accessibility::AccessibleRole::PANEL);
166*3b2c5b9dSAndre Fischer return AccessibleTitleBar::Create(*this);
167*3b2c5b9dSAndre Fischer }
168*3b2c5b9dSAndre Fischer
169*3b2c5b9dSAndre Fischer
170*3b2c5b9dSAndre Fischer
171*3b2c5b9dSAndre Fischer
PaintTitle(const Rectangle & rTitleBox)172ff12d537SAndre Fischer void TitleBar::PaintTitle (const Rectangle& rTitleBox)
173ff12d537SAndre Fischer {
174ff12d537SAndre Fischer Push(PUSH_FONT | PUSH_TEXTCOLOR);
17522de8995SAndre Fischer
1764e21436dSAndre Fischer Rectangle aTitleBox (rTitleBox);
1774e21436dSAndre Fischer
1784e21436dSAndre Fischer // When there is an icon then paint it at the left of the given
1794e21436dSAndre Fischer // box.
1804e21436dSAndre Fischer if ( !! maIcon)
1814e21436dSAndre Fischer {
1824e21436dSAndre Fischer DrawImage(
1834e21436dSAndre Fischer Point(
1844e21436dSAndre Fischer aTitleBox.Left() + gnLeftIconSpace,
1854e21436dSAndre Fischer aTitleBox.Top() + (aTitleBox.GetHeight()-maIcon.GetSizePixel().Height())/2),
1864e21436dSAndre Fischer maIcon);
1874e21436dSAndre Fischer aTitleBox.Left() += gnLeftIconSpace + maIcon.GetSizePixel().Width() + gnRightIconSpace;
1884e21436dSAndre Fischer }
1894e21436dSAndre Fischer
19022de8995SAndre Fischer Font aFont(GetFont());
191ba606a71SAndre Fischer aFont.SetWeight(WEIGHT_BOLD);
19222de8995SAndre Fischer SetFont(aFont);
19322de8995SAndre Fischer
19422de8995SAndre Fischer // Paint title bar text.
195ff12d537SAndre Fischer SetTextColor(GetTextColor());
19622de8995SAndre Fischer DrawText(
1974e21436dSAndre Fischer aTitleBox,
19822de8995SAndre Fischer msTitle,
19922de8995SAndre Fischer TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER);
20065908a7eSAndre Fischer
20165908a7eSAndre Fischer Pop();
20265908a7eSAndre Fischer }
20365908a7eSAndre Fischer
20465908a7eSAndre Fischer
20565908a7eSAndre Fischer
20665908a7eSAndre Fischer
PaintFocus(const Rectangle & rFocusBox)20765908a7eSAndre Fischer void TitleBar::PaintFocus (const Rectangle& rFocusBox)
20865908a7eSAndre Fischer {
209*3b2c5b9dSAndre Fischer Push(PUSH_FONT | PUSH_TEXTCOLOR);
21065908a7eSAndre Fischer
21152d13b84SAndre Fischer Font aFont(GetFont());
21252d13b84SAndre Fischer aFont.SetWeight(WEIGHT_BOLD);
21352d13b84SAndre Fischer SetFont(aFont);
21452d13b84SAndre Fischer
21565908a7eSAndre Fischer const Rectangle aTextBox (
21665908a7eSAndre Fischer GetTextRect(
21765908a7eSAndre Fischer rFocusBox,
21865908a7eSAndre Fischer msTitle,
21965908a7eSAndre Fischer TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER));
22065908a7eSAndre Fischer const Rectangle aLargerTextBox (
22165908a7eSAndre Fischer aTextBox.Left() - 2,
22265908a7eSAndre Fischer aTextBox.Top() - 2,
22365908a7eSAndre Fischer aTextBox.Right() + 2,
22465908a7eSAndre Fischer aTextBox.Bottom() + 2);
22565908a7eSAndre Fischer
226*3b2c5b9dSAndre Fischer if (HasFocus())
227*3b2c5b9dSAndre Fischer Window::ShowFocus(aLargerTextBox);
228*3b2c5b9dSAndre Fischer else
229*3b2c5b9dSAndre Fischer Window::HideFocus();
23065908a7eSAndre Fischer
23122de8995SAndre Fischer Pop();
23222de8995SAndre Fischer }
23322de8995SAndre Fischer
23422de8995SAndre Fischer
2357a32b0c8SAndre Fischer
2367a32b0c8SAndre Fischer
IMPL_LINK(TitleBar,SelectionHandler,ToolBox *,pToolBox)2377a32b0c8SAndre Fischer IMPL_LINK(TitleBar, SelectionHandler, ToolBox*, pToolBox)
2387a32b0c8SAndre Fischer {
2397a32b0c8SAndre Fischer (void)pToolBox;
2407a32b0c8SAndre Fischer OSL_ASSERT(&maToolBox==pToolBox);
2417a32b0c8SAndre Fischer const sal_uInt16 nItemId (maToolBox.GetHighlightItemId());
2427a32b0c8SAndre Fischer
2437a32b0c8SAndre Fischer HandleToolBoxItemClick(nItemId);
2447a32b0c8SAndre Fischer
2457a32b0c8SAndre Fischer return sal_True;
2467a32b0c8SAndre Fischer }
2477a32b0c8SAndre Fischer
248ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
249