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 #include "Accessible.hxx" 27 #include "AccessibleTitleBar.hxx" 28 29 #include <tools/svborder.hxx> 30 #include <vcl/gradient.hxx> 31 #include <vcl/lineinfo.hxx> 32 33 #include <com/sun/star/accessibility/AccessibleRole.hpp> 34 35 36 ToolbarValue::~ToolbarValue (void) {} 37 38 namespace 39 { 40 const static sal_Int32 gnLeftIconSpace (3); 41 const static sal_Int32 gnRightIconSpace (3); 42 } 43 44 namespace sfx2 { namespace sidebar { 45 46 TitleBar::TitleBar ( 47 const ::rtl::OUString& rsTitle, 48 Window* pParentWindow, 49 const sidebar::Paint& rInitialBackgroundPaint) 50 : Window(pParentWindow), 51 maToolBox(this), 52 msTitle(rsTitle), 53 maIcon() 54 { 55 SetBackground(rInitialBackgroundPaint.GetWallpaper()); 56 57 maToolBox.SetSelectHdl(LINK(this, TitleBar, SelectionHandler)); 58 } 59 60 61 62 63 TitleBar::~TitleBar (void) 64 { 65 } 66 67 68 69 70 void TitleBar::SetTitle (const ::rtl::OUString& rsTitle) 71 { 72 msTitle = rsTitle; 73 Invalidate(); 74 } 75 76 77 78 79 void TitleBar::SetIcon (const Image& rIcon) 80 { 81 maIcon = rIcon; 82 Invalidate(); 83 } 84 85 86 87 88 void TitleBar::Paint (const Rectangle& rUpdateArea) 89 { 90 (void)rUpdateArea; 91 92 // Paint title bar background. 93 Size aWindowSize (GetOutputSizePixel()); 94 Rectangle aTitleBarBox( 95 0, 96 0, 97 aWindowSize.Width(), 98 aWindowSize.Height() 99 ); 100 101 PaintDecoration(aTitleBarBox); 102 const Rectangle aTitleBox (GetTitleArea(aTitleBarBox)); 103 PaintTitle(aTitleBox); 104 PaintFocus(aTitleBox); 105 } 106 107 108 109 110 void TitleBar::DataChanged (const DataChangedEvent& rEvent) 111 { 112 (void)rEvent; 113 114 SetBackground(GetBackgroundPaint().GetWallpaper()); 115 } 116 117 118 119 120 void TitleBar::SetPosSizePixel ( 121 long nX, 122 long nY, 123 long nWidth, 124 long nHeight, 125 sal_uInt16 nFlags) 126 { 127 Window::SetPosSizePixel(nX,nY,nWidth,nHeight,nFlags); 128 129 // Place the toolbox. 130 const sal_Int32 nToolBoxWidth (maToolBox.GetItemPosRect(0).GetWidth()); 131 maToolBox.SetPosSizePixel(nWidth-nToolBoxWidth,0, nToolBoxWidth,nHeight, WINDOW_POSSIZE_POSSIZE); 132 maToolBox.Show(); 133 } 134 135 136 137 138 ToolBox& TitleBar::GetToolBox (void) 139 { 140 return maToolBox; 141 } 142 143 144 145 146 const ToolBox& TitleBar::GetToolBox (void) const 147 { 148 return maToolBox; 149 } 150 151 152 153 154 void TitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex) 155 { 156 (void)nItemIndex; 157 // Any real processing has to be done in derived class. 158 } 159 160 161 162 163 cssu::Reference<css::accessibility::XAccessible> TitleBar::CreateAccessible (void) 164 { 165 SetAccessibleRole(css::accessibility::AccessibleRole::PANEL); 166 return AccessibleTitleBar::Create(*this); 167 } 168 169 170 171 172 void TitleBar::PaintTitle (const Rectangle& rTitleBox) 173 { 174 Push(PUSH_FONT | PUSH_TEXTCOLOR); 175 176 Rectangle aTitleBox (rTitleBox); 177 178 // When there is an icon then paint it at the left of the given 179 // box. 180 if ( !! maIcon) 181 { 182 DrawImage( 183 Point( 184 aTitleBox.Left() + gnLeftIconSpace, 185 aTitleBox.Top() + (aTitleBox.GetHeight()-maIcon.GetSizePixel().Height())/2), 186 maIcon); 187 aTitleBox.Left() += gnLeftIconSpace + maIcon.GetSizePixel().Width() + gnRightIconSpace; 188 } 189 190 Font aFont(GetFont()); 191 aFont.SetWeight(WEIGHT_BOLD); 192 SetFont(aFont); 193 194 // Paint title bar text. 195 SetTextColor(GetTextColor()); 196 DrawText( 197 aTitleBox, 198 msTitle, 199 TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER); 200 201 Pop(); 202 } 203 204 205 206 207 void TitleBar::PaintFocus (const Rectangle& rFocusBox) 208 { 209 Push(PUSH_FONT | PUSH_TEXTCOLOR); 210 211 Font aFont(GetFont()); 212 aFont.SetWeight(WEIGHT_BOLD); 213 SetFont(aFont); 214 215 const Rectangle aTextBox ( 216 GetTextRect( 217 rFocusBox, 218 msTitle, 219 TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER)); 220 const Rectangle aLargerTextBox ( 221 aTextBox.Left() - 2, 222 aTextBox.Top() - 2, 223 aTextBox.Right() + 2, 224 aTextBox.Bottom() + 2); 225 226 if (HasFocus()) 227 Window::ShowFocus(aLargerTextBox); 228 else 229 Window::HideFocus(); 230 231 Pop(); 232 } 233 234 235 236 237 IMPL_LINK(TitleBar, SelectionHandler, ToolBox*, pToolBox) 238 { 239 (void)pToolBox; 240 OSL_ASSERT(&maToolBox==pToolBox); 241 const sal_uInt16 nItemId (maToolBox.GetHighlightItemId()); 242 243 HandleToolBoxItemClick(nItemId); 244 245 return sal_True; 246 } 247 248 } } // end of namespace sfx2::sidebar 249