summaryrefslogtreecommitdiff
path: root/sfx2/source/notebookbar/NotebookbarPopup.cxx
blob: 4c480af2c8d142e177f989d2e646fb3a9301580d (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
/* -*- 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/.
 */

#include "NotebookbarPopup.hxx"
#include <vcl/IPrioritable.hxx>
#include <vcl/layout.hxx>

NotebookbarPopup::NotebookbarPopup(const VclPtr<VclHBox>& pParent)
    : FloatingWindow(pParent, "Popup", "sfx/ui/notebookbarpopup.ui")
    , m_pParent(pParent)
{
    get(m_pBox, "box");
    m_pBox->SetSizePixel(Size(100, 75));
}

NotebookbarPopup::~NotebookbarPopup() { disposeOnce(); }

VclHBox* NotebookbarPopup::getBox() { return m_pBox.get(); }

void NotebookbarPopup::PopupModeEnd()
{
    hideSeparators(false);
    while (m_pBox->GetChildCount())
    {
        vcl::IPrioritable* pChild = dynamic_cast<vcl::IPrioritable*>(GetChild(0));
        if (pChild)
            pChild->HideContent();

        vcl::Window* pWindow = m_pBox->GetChild(0);
        pWindow->SetParent(m_pParent);

        if (m_pParent)
            m_pParent->Resize();
    }

    FloatingWindow::PopupModeEnd();
}

void NotebookbarPopup::hideSeparators(bool bHide)
{
    // separator on the beginning
    vcl::Window* pWindow = m_pBox->GetChild(0);
    while (pWindow && pWindow->GetType() == WindowType::CONTAINER)
    {
        pWindow = pWindow->GetChild(0);
    }
    if (pWindow && pWindow->GetType() == WindowType::FIXEDLINE)
    {
        if (bHide)
            pWindow->Hide();
        else
            pWindow->Show();
    }

    // separator on the end
    pWindow = m_pBox->GetChild(m_pBox->GetChildCount() - 1);
    while (pWindow && pWindow->GetType() == WindowType::CONTAINER)
    {
        pWindow = pWindow->GetChild(pWindow->GetChildCount() - 1);
    }
    if (pWindow && pWindow->GetType() == WindowType::FIXEDLINE)
    {
        if (bHide)
            pWindow->Hide();
        else
            pWindow->Show();
    }
}

void NotebookbarPopup::dispose()
{
    PopupModeEnd();
    m_pBox.disposeAndClear();
    m_pParent.clear();

    FloatingWindow::dispose();
}

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