Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / sidebar / DeckTitleBar.cxx
blob41c8fcf785693983c43f6ff279f3d73c509c0905
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "DeckTitleBar.hxx"
21 #include <sfx2/sidebar/Theme.hxx>
22 #include <sfx2/sfxresid.hxx>
23 #include "Sidebar.hrc"
25 #include <vcl/image.hxx>
27 #ifdef DEBUG
28 #include <sfx2/sidebar/Tools.hxx>
29 #endif
31 namespace sfx2 { namespace sidebar {
33 namespace
35 static const sal_Int32 gaLeftGripPadding (3);
36 static const sal_Int32 gaRightGripPadding (3);
39 DeckTitleBar::DeckTitleBar (const OUString& rsTitle,
40 vcl::Window* pParentWindow,
41 const std::function<void()>& rCloserAction)
42 : TitleBar(rsTitle, pParentWindow, GetBackgroundPaint())
43 , mnCloserItemIndex(1)
44 , maCloserAction(rCloserAction)
45 , mbIsCloserVisible(false)
47 OSL_ASSERT(pParentWindow != NULL);
49 if (maCloserAction)
50 SetCloserVisible(true);
52 #ifdef DEBUG
53 SetText(OUString("DeckTitleBar"));
54 #endif
57 void DeckTitleBar::SetCloserVisible (const bool bIsCloserVisible)
59 if (mbIsCloserVisible != bIsCloserVisible)
61 mbIsCloserVisible = bIsCloserVisible;
63 if (mbIsCloserVisible)
65 maToolBox->InsertItem(mnCloserItemIndex,
66 Theme::GetImage(Theme::Image_Closer));
67 maToolBox->SetQuickHelpText(mnCloserItemIndex,
68 SFX2_RESSTR(SFX_STR_SIDEBAR_CLOSE_DECK));
70 else
71 maToolBox->RemoveItem(maToolBox->GetItemPos(mnCloserItemIndex));
75 Rectangle DeckTitleBar::GetTitleArea (const Rectangle& rTitleBarBox)
77 Image aGripImage (Theme::GetImage(Theme::Image_Grip));
78 return Rectangle(
79 aGripImage.GetSizePixel().Width() + gaLeftGripPadding + gaRightGripPadding,
80 rTitleBarBox.Top(),
81 rTitleBarBox.Right(),
82 rTitleBarBox.Bottom());
85 void DeckTitleBar::PaintDecoration(vcl::RenderContext& /*rRenderContext*/, const Rectangle& /*rTitleBarBox*/)
89 sidebar::Paint DeckTitleBar::GetBackgroundPaint()
91 return Theme::GetPaint(Theme::Paint_DeckTitleBarBackground);
94 Color DeckTitleBar::GetTextColor()
96 return Theme::GetColor(Theme::Color_DeckTitleFont);
99 void DeckTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
101 if (nItemIndex == mnCloserItemIndex && maCloserAction)
102 maCloserAction();
105 css::uno::Reference<css::accessibility::XAccessible> DeckTitleBar::CreateAccessible()
107 const OUString sAccessibleName(msTitle);
108 SetAccessibleName(sAccessibleName);
109 SetAccessibleDescription(sAccessibleName);
110 return TitleBar::CreateAccessible();
113 void DeckTitleBar::DataChanged (const DataChangedEvent& rEvent)
115 maToolBox->SetItemImage(
116 mnCloserItemIndex,
117 Theme::GetImage(Theme::Image_Closer));
118 TitleBar::DataChanged(rEvent);
121 } } // end of namespace sfx2::sidebar
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */