Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / source / sidebar / DeckTitleBar.cxx
blobc797fc274f784f6c081670d22692a27d8bf0c0e1
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 <sidebar/DeckTitleBar.hxx>
21 #include <sfx2/sidebar/Theme.hxx>
22 #include <sfx2/sfxresid.hxx>
23 #include <sfx2/strings.hrc>
25 #include <vcl/customweld.hxx>
26 #include <vcl/ptrstyle.hxx>
28 #ifdef DEBUG
29 #include <sfx2/sidebar/Tools.hxx>
30 #endif
32 namespace sfx2::sidebar {
34 class GripWidget : public weld::CustomWidgetController
36 private:
37 BitmapEx maGrip;
38 public:
39 virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override
41 weld::CustomWidgetController::SetDrawingArea(pDrawingArea);
42 StyleUpdated();
45 virtual void StyleUpdated() override
47 maGrip = BitmapEx("sfx2/res/grip.png");
48 Size aGripSize(maGrip.GetSizePixel());
49 set_size_request(aGripSize.Width(), aGripSize.Height());
50 weld::CustomWidgetController::StyleUpdated();
53 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/) override
55 rRenderContext.SetBackground(Theme::GetColor(Theme::Color_DeckTitleBarBackground));
56 rRenderContext.DrawBitmapEx(Point(0, 0), maGrip);
60 DeckTitleBar::DeckTitleBar (const OUString& rsTitle,
61 vcl::Window* pParentWindow,
62 const std::function<void()>& rCloserAction)
63 : TitleBar(pParentWindow, "sfx/ui/decktitlebar.ui", "DeckTitleBar",
64 Theme::Color_DeckTitleBarBackground)
65 , mxGripWidget(new GripWidget)
66 , mxGripWeld(new weld::CustomWeld(*m_xBuilder, "grip", *mxGripWidget))
67 , mxLabel(m_xBuilder->weld_label("label"))
68 , maCloserAction(rCloserAction)
69 , mbIsCloserVisible(false)
71 mxLabel->set_label(rsTitle);
72 mxGripWidget->SetPointer(PointerStyle::Move);
74 OSL_ASSERT(pParentWindow != nullptr);
76 if (maCloserAction)
77 SetCloserVisible(true);
79 #ifdef DEBUG
80 SetText(OUString("DeckTitleBar"));
81 #endif
84 DeckTitleBar::~DeckTitleBar()
86 disposeOnce();
89 void DeckTitleBar::dispose()
91 mxLabel.reset();
92 mxGripWeld.reset();
93 mxGripWidget.reset();
94 TitleBar::dispose();
97 tools::Rectangle DeckTitleBar::GetDragArea()
99 int x, y, width, height;
100 if (mxGripWidget->GetDrawingArea()->get_extents_relative_to(*m_xContainer, x, y, width, height))
101 return tools::Rectangle(Point(x, y), Size(width, height));
102 return tools::Rectangle();
105 void DeckTitleBar::SetTitle(const OUString& rsTitle)
107 mxLabel->set_label(rsTitle);
110 OUString DeckTitleBar::GetTitle() const
112 return mxLabel->get_label();
115 void DeckTitleBar::SetCloserVisible (const bool bIsCloserVisible)
117 if (mbIsCloserVisible == bIsCloserVisible)
118 return;
120 mbIsCloserVisible = bIsCloserVisible;
122 if (mbIsCloserVisible)
124 mxToolBox->show();
125 mxToolBox->set_item_icon_name("button", "sfx2/res/closedoc.png");
126 mxToolBox->set_item_tooltip_text("button",
127 SfxResId(SFX_STR_SIDEBAR_CLOSE_DECK));
129 else
131 mxToolBox->hide();
135 void DeckTitleBar::HandleToolBoxItemClick()
137 if (maCloserAction)
138 maCloserAction();
141 void DeckTitleBar::DataChanged (const DataChangedEvent& rEvent)
143 mxToolBox->set_item_icon_name("button", "sfx2/res/closedoc.png");
144 TitleBar::DataChanged(rEvent);
147 } // end of namespace sfx2::sidebar
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */