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 33*4e21436dSAndre Fischer namespace 34*4e21436dSAndre Fischer { 35*4e21436dSAndre Fischer const static sal_Int32 gnLeftIconSpace (3); 36*4e21436dSAndre Fischer const static sal_Int32 gnRightIconSpace (3); 37*4e21436dSAndre 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), 47*4e21436dSAndre Fischer msTitle(rsTitle), 48*4e21436dSAndre Fischer maIcon() 4922de8995SAndre Fischer { 507a32b0c8SAndre Fischer SetBackground(rInitialBackgroundPaint.GetWallpaper()); 51*4e21436dSAndre 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 74*4e21436dSAndre Fischer void TitleBar::SetIcon (const Image& rIcon) 75*4e21436dSAndre Fischer { 76*4e21436dSAndre Fischer maIcon = rIcon; 77*4e21436dSAndre Fischer Invalidate(); 78*4e21436dSAndre Fischer } 79*4e21436dSAndre Fischer 80*4e21436dSAndre Fischer 81*4e21436dSAndre Fischer 82*4e21436dSAndre Fischer 8322de8995SAndre Fischer void TitleBar::Paint (const Rectangle& rUpdateArea) 8422de8995SAndre Fischer { 8595a18594SAndre Fischer (void)rUpdateArea; 8695a18594SAndre Fischer 8722de8995SAndre Fischer // Paint title bar background. 8865908a7eSAndre 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) 1077a32b0c8SAndre Fischer { 1087a32b0c8SAndre Fischer (void)rEvent; 1097a32b0c8SAndre Fischer 1107a32b0c8SAndre Fischer SetBackground(GetBackgroundPaint().GetWallpaper()); 1117a32b0c8SAndre 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) 122ff12d537SAndre 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 1427a32b0c8SAndre Fischer void TitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex) 1437a32b0c8SAndre Fischer { 1447a32b0c8SAndre Fischer (void)nItemIndex; 1457a32b0c8SAndre Fischer // Any real processing has to be done in derived class. 146ff12d537SAndre Fischer } 147ff12d537SAndre Fischer 148ff12d537SAndre Fischer 149ff12d537SAndre Fischer 150ff12d537SAndre Fischer 151ff12d537SAndre Fischer void TitleBar::PaintTitle (const Rectangle& rTitleBox) 152ff12d537SAndre Fischer { 153ff12d537SAndre Fischer Push(PUSH_FONT | PUSH_TEXTCOLOR); 15422de8995SAndre Fischer 155*4e21436dSAndre Fischer Rectangle aTitleBox (rTitleBox); 156*4e21436dSAndre Fischer 157*4e21436dSAndre Fischer // When there is an icon then paint it at the left of the given 158*4e21436dSAndre Fischer // box. 159*4e21436dSAndre Fischer if ( !! maIcon) 160*4e21436dSAndre Fischer { 161*4e21436dSAndre Fischer DrawImage( 162*4e21436dSAndre Fischer Point( 163*4e21436dSAndre Fischer aTitleBox.Left() + gnLeftIconSpace, 164*4e21436dSAndre Fischer aTitleBox.Top() + (aTitleBox.GetHeight()-maIcon.GetSizePixel().Height())/2), 165*4e21436dSAndre Fischer maIcon); 166*4e21436dSAndre Fischer aTitleBox.Left() += gnLeftIconSpace + maIcon.GetSizePixel().Width() + gnRightIconSpace; 167*4e21436dSAndre Fischer } 168*4e21436dSAndre Fischer 16922de8995SAndre Fischer Font aFont(GetFont()); 170ba606a71SAndre Fischer aFont.SetWeight(WEIGHT_BOLD); 17122de8995SAndre Fischer SetFont(aFont); 17222de8995SAndre Fischer 17322de8995SAndre Fischer // Paint title bar text. 174ff12d537SAndre Fischer SetTextColor(GetTextColor()); 17522de8995SAndre Fischer DrawText( 176*4e21436dSAndre Fischer aTitleBox, 17722de8995SAndre Fischer msTitle, 17822de8995SAndre Fischer TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER); 17965908a7eSAndre Fischer 18065908a7eSAndre Fischer Pop(); 18165908a7eSAndre Fischer } 18265908a7eSAndre Fischer 18365908a7eSAndre Fischer 18465908a7eSAndre Fischer 18565908a7eSAndre Fischer 18665908a7eSAndre Fischer void TitleBar::PaintFocus (const Rectangle& rFocusBox) 18765908a7eSAndre Fischer { 18865908a7eSAndre Fischer Push(PUSH_FONT | PUSH_TEXTCOLOR | PUSH_LINECOLOR | PUSH_FILLCOLOR); 18965908a7eSAndre Fischer 19065908a7eSAndre Fischer const Rectangle aTextBox ( 19165908a7eSAndre Fischer GetTextRect( 19265908a7eSAndre Fischer rFocusBox, 19365908a7eSAndre Fischer msTitle, 19465908a7eSAndre Fischer TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER)); 19565908a7eSAndre Fischer const Rectangle aLargerTextBox ( 19665908a7eSAndre Fischer aTextBox.Left() - 2, 19765908a7eSAndre Fischer aTextBox.Top() - 2, 19865908a7eSAndre Fischer aTextBox.Right() + 2, 19965908a7eSAndre Fischer aTextBox.Bottom() + 2); 20065908a7eSAndre Fischer 20165908a7eSAndre Fischer LineInfo aDottedStyle (LINE_DASH); 20265908a7eSAndre Fischer aDottedStyle.SetDashCount(0); 20365908a7eSAndre Fischer aDottedStyle.SetDotCount(1); 20465908a7eSAndre Fischer aDottedStyle.SetDotLen(1); 20565908a7eSAndre Fischer aDottedStyle.SetDistance(1); 206ff12d537SAndre Fischer 20765908a7eSAndre Fischer SetFillColor(); 20865908a7eSAndre Fischer SetLineColor(COL_BLACK); 20965908a7eSAndre Fischer DrawPolyLine(Polygon(aLargerTextBox), aDottedStyle); 21065908a7eSAndre Fischer 21122de8995SAndre Fischer Pop(); 21222de8995SAndre Fischer } 21322de8995SAndre Fischer 21422de8995SAndre Fischer 2157a32b0c8SAndre Fischer 2167a32b0c8SAndre Fischer 2177a32b0c8SAndre Fischer IMPL_LINK(TitleBar, SelectionHandler, ToolBox*, pToolBox) 2187a32b0c8SAndre Fischer { 2197a32b0c8SAndre Fischer (void)pToolBox; 2207a32b0c8SAndre Fischer OSL_ASSERT(&maToolBox==pToolBox); 2217a32b0c8SAndre Fischer const sal_uInt16 nItemId (maToolBox.GetHighlightItemId()); 2227a32b0c8SAndre Fischer 2237a32b0c8SAndre Fischer HandleToolBoxItemClick(nItemId); 2247a32b0c8SAndre Fischer 2257a32b0c8SAndre Fischer return sal_True; 2267a32b0c8SAndre Fischer } 2277a32b0c8SAndre Fischer 228ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar 229