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>
22 #include <sfx2/sfxresid.hxx>
23 #include <sfx2/strings.hrc>
25 #include <vcl/customweld.hxx>
26 #include <vcl/ptrstyle.hxx>
29 #include <sfx2/sidebar/Tools.hxx>
32 namespace sfx2::sidebar
{
34 class GripWidget
: public weld::CustomWidgetController
39 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
41 weld::CustomWidgetController::SetDrawingArea(pDrawingArea
);
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);
77 SetCloserVisible(true);
80 SetText(OUString("DeckTitleBar"));
84 DeckTitleBar::~DeckTitleBar()
89 void DeckTitleBar::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
)
120 mbIsCloserVisible
= bIsCloserVisible
;
122 if (mbIsCloserVisible
)
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
));
135 void DeckTitleBar::HandleToolBoxItemClick()
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: */