summaryrefslogtreecommitdiff
path: root/sfx2/source/sidebar/DeckTitleBar.cxx
blob: 6700014e82a4da6868dc6399bceb3740cfb5d13f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <sidebar/DeckTitleBar.hxx>
#include <sfx2/sidebar/Theme.hxx>
#include <sfx2/sfxresid.hxx>
#include <sfx2/strings.hrc>

#include <vcl/customweld.hxx>
#include <vcl/ptrstyle.hxx>

#ifdef DEBUG
#include <sfx2/sidebar/Tools.hxx>
#endif

namespace sfx2::sidebar {

class GripWidget : public weld::CustomWidgetController
{
private:
    BitmapEx maGrip;
public:
    virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override
    {
        weld::CustomWidgetController::SetDrawingArea(pDrawingArea);
        StyleUpdated();
    }

    virtual void StyleUpdated() override
    {
        maGrip = BitmapEx("sfx2/res/grip.png");
        Size aGripSize(maGrip.GetSizePixel());
        set_size_request(aGripSize.Width(), aGripSize.Height());
        weld::CustomWidgetController::StyleUpdated();
    }

    virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/) override
    {
        rRenderContext.SetBackground(Theme::GetColor(Theme::Color_DeckTitleBarBackground));
        rRenderContext.DrawBitmapEx(Point(0, 0), maGrip);
    }
};

DeckTitleBar::DeckTitleBar (const OUString& rsTitle,
                            weld::Builder& rBuilder,
                            const std::function<void()>& rCloserAction)
    : TitleBar(rBuilder, Theme::Color_DeckTitleBarBackground)
    , mxGripWidget(new GripWidget)
    , mxGripWeld(new weld::CustomWeld(rBuilder, "grip", *mxGripWidget))
    , mxLabel(rBuilder.weld_label("label"))
    , maCloserAction(rCloserAction)
    , mbIsCloserVisible(false)
{
    mxLabel->set_label(rsTitle);
    mxGripWidget->SetPointer(PointerStyle::Move);

    if (maCloserAction)
        SetCloserVisible(true);
}

DeckTitleBar::~DeckTitleBar()
{
}

tools::Rectangle DeckTitleBar::GetDragArea() const
{
    int x, y, width, height;
    if (mxGripWidget->GetDrawingArea()->get_extents_relative_to(*mxTitlebar, x, y, width, height))
        return tools::Rectangle(Point(x, y), Size(width, height));
    return tools::Rectangle();
}

void DeckTitleBar::SetTitle(const OUString& rsTitle)
{
    mxLabel->set_label(rsTitle);
}

OUString DeckTitleBar::GetTitle() const
{
    return mxLabel->get_label();
}

void DeckTitleBar::SetCloserVisible (const bool bIsCloserVisible)
{
    if (mbIsCloserVisible == bIsCloserVisible)
        return;

    mbIsCloserVisible = bIsCloserVisible;

    mxToolBox->set_visible(mbIsCloserVisible);
}

void DeckTitleBar::HandleToolBoxItemClick()
{
    if (maCloserAction)
        maCloserAction();
}

void DeckTitleBar::DataChanged()
{
    mxToolBox->set_item_icon_name("button", "sfx2/res/closedoc.png");
    TitleBar::DataChanged();
}

} // end of namespace sfx2::sidebar

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */