1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 #include <vcl/bitmapex.hxx>
25 #include <vcl/customweld.hxx>
26 #include <vcl/outdev.hxx>
27 #include <vcl/ptrstyle.hxx>
30 #include <sfx2/sidebar/Tools.hxx>
33 namespace sfx2::sidebar
{
35 class GripWidget
: public weld::CustomWidgetController
40 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
42 weld::CustomWidgetController::SetDrawingArea(pDrawingArea
);
46 virtual void StyleUpdated() override
48 maGrip
= BitmapEx("sfx2/res/grip.png");
49 Size
aGripSize(maGrip
.GetSizePixel());
50 set_size_request(aGripSize
.Width(), aGripSize
.Height());
51 weld::CustomWidgetController::StyleUpdated();
54 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& /*rRect*/) override
56 rRenderContext
.SetBackground(Theme::GetColor(Theme::Color_DeckTitleBarBackground
));
57 rRenderContext
.Erase();
58 rRenderContext
.DrawBitmapEx(Point(0, 0), maGrip
);
62 DeckTitleBar::DeckTitleBar (const OUString
& rsTitle
,
63 weld::Builder
& rBuilder
,
64 std::function
<void()> aCloserAction
)
65 : TitleBar(rBuilder
, Theme::Color_DeckTitleBarBackground
)
66 , mxGripWidget(new GripWidget
)
67 , mxGripWeld(new weld::CustomWeld(rBuilder
, "grip", *mxGripWidget
))
68 , mxLabel(rBuilder
.weld_label("label"))
69 , maCloserAction(std::move(aCloserAction
))
70 , mbIsCloserVisible(false)
72 mxLabel
->set_label(rsTitle
);
73 mxGripWidget
->SetPointer(PointerStyle::Move
);
76 SetCloserVisible(true);
79 DeckTitleBar::~DeckTitleBar()
83 tools::Rectangle
DeckTitleBar::GetDragArea() const
85 int x
, y
, width
, height
;
86 if (mxGripWidget
->GetDrawingArea()->get_extents_relative_to(*mxTitlebar
, x
, y
, width
, height
))
87 return tools::Rectangle(Point(x
, y
), Size(width
, height
));
88 return tools::Rectangle();
91 void DeckTitleBar::SetTitle(const OUString
& rsTitle
)
93 mxLabel
->set_label(rsTitle
);
96 OUString
DeckTitleBar::GetTitle() const
98 return mxLabel
->get_label();
101 void DeckTitleBar::SetCloserVisible (const bool bIsCloserVisible
)
103 if (mbIsCloserVisible
== bIsCloserVisible
)
106 mbIsCloserVisible
= bIsCloserVisible
;
108 mxToolBox
->set_visible(mbIsCloserVisible
);
111 void DeckTitleBar::HandleToolBoxItemClick()
117 void DeckTitleBar::DataChanged()
119 mxToolBox
->set_item_icon_name("button", "sfx2/res/closedoc.png");
120 TitleBar::DataChanged();
123 } // end of namespace sfx2::sidebar
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */