/src/libreoffice/sfx2/source/sidebar/DeckTitleBar.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <sidebar/DeckTitleBar.hxx> |
21 | | #include <sfx2/sidebar/Theme.hxx> |
22 | | |
23 | | #include <utility> |
24 | | #include <vcl/bitmap.hxx> |
25 | | #include <vcl/outdev.hxx> |
26 | | #include <vcl/ptrstyle.hxx> |
27 | | #include <vcl/weld/customweld.hxx> |
28 | | |
29 | | #if OSL_DEBUG_LEVEL >= 2 |
30 | | #include <sidebar/Tools.hxx> |
31 | | #endif |
32 | | |
33 | | namespace sfx2::sidebar { |
34 | | |
35 | | class GripWidget : public weld::CustomWidgetController |
36 | | { |
37 | | private: |
38 | | Bitmap maGrip; |
39 | | public: |
40 | | virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override |
41 | 0 | { |
42 | 0 | weld::CustomWidgetController::SetDrawingArea(pDrawingArea); |
43 | 0 | StyleUpdated(); |
44 | 0 | } |
45 | | |
46 | | virtual void StyleUpdated() override |
47 | 0 | { |
48 | 0 | maGrip = Bitmap(u"sfx2/res/grip.png"_ustr); |
49 | 0 | Size aGripSize(maGrip.GetSizePixel()); |
50 | 0 | set_size_request(aGripSize.Width(), aGripSize.Height()); |
51 | 0 | weld::CustomWidgetController::StyleUpdated(); |
52 | 0 | } |
53 | | |
54 | | virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/) override |
55 | 0 | { |
56 | 0 | rRenderContext.SetBackground(Theme::GetColor(Theme::Color_DeckTitleBarBackground)); |
57 | 0 | rRenderContext.Erase(); |
58 | 0 | rRenderContext.DrawBitmap(Point(0, 0), maGrip); |
59 | 0 | } |
60 | | }; |
61 | | |
62 | | DeckTitleBar::DeckTitleBar (const OUString& rsTitle, |
63 | | weld::Builder& rBuilder, |
64 | | const OUString& rsHelpId, |
65 | | std::function<void()> aCloserAction) |
66 | 0 | : TitleBar(rBuilder, Theme::Color_DeckTitleBarBackground) |
67 | 0 | , mxGripWidget(new GripWidget) |
68 | 0 | , mxGripWeld(new weld::CustomWeld(rBuilder, u"grip"_ustr, *mxGripWidget)) |
69 | 0 | , mxLabel(rBuilder.weld_label(u"label"_ustr)) |
70 | 0 | , msHelpId(rsHelpId) |
71 | 0 | , maCloserAction(std::move(aCloserAction)) |
72 | 0 | , mbIsCloserVisible(false) |
73 | 0 | { |
74 | 0 | mxLabel->set_label(rsTitle); |
75 | 0 | mxGripWidget->SetPointer(PointerStyle::Move); |
76 | |
|
77 | 0 | if (maCloserAction) |
78 | 0 | SetCloserVisible(true); |
79 | 0 | } |
80 | | |
81 | | DeckTitleBar::~DeckTitleBar() |
82 | 0 | { |
83 | 0 | } |
84 | | |
85 | | tools::Rectangle DeckTitleBar::GetDragArea() const |
86 | 0 | { |
87 | 0 | int x, y, width, height; |
88 | 0 | if (mxGripWidget->GetDrawingArea()->get_extents_relative_to(*mxTitlebar, x, y, width, height)) |
89 | 0 | return tools::Rectangle(Point(x, y), Size(width, height)); |
90 | 0 | return tools::Rectangle(); |
91 | 0 | } |
92 | | |
93 | | void DeckTitleBar::SetTitle(const OUString& rsTitle) |
94 | 0 | { |
95 | 0 | mxLabel->set_label(rsTitle); |
96 | 0 | } |
97 | | |
98 | | OUString DeckTitleBar::GetTitle() const |
99 | 0 | { |
100 | 0 | return mxLabel->get_label(); |
101 | 0 | } |
102 | | |
103 | | void DeckTitleBar::SetCloserVisible (const bool bIsCloserVisible) |
104 | 0 | { |
105 | 0 | if (mbIsCloserVisible == bIsCloserVisible) |
106 | 0 | return; |
107 | | |
108 | 0 | mbIsCloserVisible = bIsCloserVisible; |
109 | |
|
110 | 0 | mxToolBox->set_visible(mbIsCloserVisible); |
111 | 0 | } |
112 | | |
113 | | void DeckTitleBar::HandleToolBoxItemClick() |
114 | 0 | { |
115 | 0 | if (msToolBoxRId == "btn_help") |
116 | 0 | { |
117 | | // Help toolbox button was clicked |
118 | 0 | DeckTitleBar::ShowHelp(msHelpId); |
119 | 0 | } |
120 | 0 | else if ((msToolBoxRId.isEmpty()) || (msToolBoxRId == "btn_close")) |
121 | 0 | { |
122 | 0 | if (maCloserAction) |
123 | 0 | maCloserAction(); |
124 | 0 | } |
125 | | // Reset the toolbox response id |
126 | 0 | msToolBoxRId = ""; |
127 | 0 | } |
128 | | |
129 | | void DeckTitleBar::DataChanged() |
130 | 0 | { |
131 | 0 | mxToolBox->set_item_icon_name(u"button"_ustr, u"sfx2/res/closedoc.png"_ustr); |
132 | 0 | TitleBar::DataChanged(); |
133 | 0 | } |
134 | | |
135 | | } // end of namespace sfx2::sidebar |
136 | | |
137 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |