LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / source / sidebar / DeckTitleBar.cxx
blob42379e5354f3034a8a6363377950a6c0e069558e
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.Erase();
57 rRenderContext.DrawBitmapEx(Point(0, 0), maGrip);
61 DeckTitleBar::DeckTitleBar (const OUString& rsTitle,
62 weld::Builder& rBuilder,
63 const std::function<void()>& rCloserAction)
64 : TitleBar(rBuilder, Theme::Color_DeckTitleBarBackground)
65 , mxGripWidget(new GripWidget)
66 , mxGripWeld(new weld::CustomWeld(rBuilder, "grip", *mxGripWidget))
67 , mxLabel(rBuilder.weld_label("label"))
68 , maCloserAction(rCloserAction)
69 , mbIsCloserVisible(false)
71 mxLabel->set_label(rsTitle);
72 mxGripWidget->SetPointer(PointerStyle::Move);
74 if (maCloserAction)
75 SetCloserVisible(true);
78 DeckTitleBar::~DeckTitleBar()
82 tools::Rectangle DeckTitleBar::GetDragArea() const
84 int x, y, width, height;
85 if (mxGripWidget->GetDrawingArea()->get_extents_relative_to(*mxTitlebar, x, y, width, height))
86 return tools::Rectangle(Point(x, y), Size(width, height));
87 return tools::Rectangle();
90 void DeckTitleBar::SetTitle(const OUString& rsTitle)
92 mxLabel->set_label(rsTitle);
95 OUString DeckTitleBar::GetTitle() const
97 return mxLabel->get_label();
100 void DeckTitleBar::SetCloserVisible (const bool bIsCloserVisible)
102 if (mbIsCloserVisible == bIsCloserVisible)
103 return;
105 mbIsCloserVisible = bIsCloserVisible;
107 mxToolBox->set_visible(mbIsCloserVisible);
110 void DeckTitleBar::HandleToolBoxItemClick()
112 if (maCloserAction)
113 maCloserAction();
116 void DeckTitleBar::DataChanged()
118 mxToolBox->set_item_icon_name("button", "sfx2/res/closedoc.png");
119 TitleBar::DataChanged();
122 } // end of namespace sfx2::sidebar
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */