Simplify using designated initializers
[LibreOffice.git] / vcl / source / control / NotebookbarPopup.cxx
blob0e36d2372636a03db09061f578d9da15e58d8fdf
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/.
8 */
10 #include <vcl/bitmapex.hxx>
11 #include <vcl/builder.hxx>
12 #include <vcl/layout.hxx>
13 #include <IPrioritable.hxx>
14 #include <NotebookbarPopup.hxx>
16 NotebookbarPopup::NotebookbarPopup(const VclPtr<VclHBox>& pParent)
17 : FloatingWindow(pParent, u"Popup"_ustr, u"sfx/ui/notebookbarpopup.ui"_ustr)
18 , m_pParent(pParent)
20 m_pBox = m_pUIBuilder->get<VclHBox>(u"box");
21 m_pBox->SetSizePixel(Size(100, 75));
22 m_pBox->SetBackground(GetSettings().GetStyleSettings().GetDialogColor());
25 NotebookbarPopup::~NotebookbarPopup() { disposeOnce(); }
27 VclHBox* NotebookbarPopup::getBox() { return m_pBox.get(); }
29 void NotebookbarPopup::PopupModeEnd()
31 hideSeparators(false);
32 while (m_pBox->GetChildCount())
34 vcl::IPrioritable* pChild = dynamic_cast<vcl::IPrioritable*>(GetChild(0));
35 if (pChild)
36 pChild->HideContent();
38 vcl::Window* pWindow = m_pBox->GetChild(0);
39 pWindow->SetParent(m_pParent);
41 // resize after all children of box are empty
42 if (m_pParent && !m_pBox->GetChildCount())
43 m_pParent->Resize();
46 FloatingWindow::PopupModeEnd();
49 void NotebookbarPopup::hideSeparators(bool bHide)
51 // separator on the beginning
52 vcl::Window* pWindow = m_pBox->GetChild(0);
53 while (pWindow && pWindow->GetType() == WindowType::CONTAINER)
55 pWindow = pWindow->GetChild(0);
57 if (pWindow && pWindow->GetType() == WindowType::FIXEDLINE)
59 if (bHide)
60 pWindow->Hide();
61 else
62 pWindow->Show();
65 // separator on the end
66 pWindow = m_pBox->GetChild(m_pBox->GetChildCount() - 1);
67 while (pWindow && pWindow->GetType() == WindowType::CONTAINER)
69 pWindow = pWindow->GetChild(pWindow->GetChildCount() - 1);
71 if (pWindow && pWindow->GetType() == WindowType::FIXEDLINE)
73 if (bHide)
74 pWindow->Hide();
75 else
76 pWindow->Show();
79 if (bHide)
81 sal_Int32 BoxId = 0;
82 while (BoxId <= m_pBox->GetChildCount() - 1)
84 if (m_pBox->GetChild(BoxId))
86 pWindow = m_pBox->GetChild(BoxId);
87 ApplyBackground(pWindow);
89 BoxId++;
92 else
94 sal_Int32 BoxId = m_pBox->GetChildCount() - 1;
95 while (BoxId >= 0)
97 if (m_pBox->GetChild(BoxId))
99 pWindow = m_pBox->GetChild(BoxId);
100 RemoveBackground(pWindow);
102 BoxId--;
107 void NotebookbarPopup::dispose()
109 PopupModeEnd();
110 m_pBox.disposeAndClear();
111 m_pParent.clear();
113 FloatingWindow::dispose();
116 void NotebookbarPopup::ApplyBackground(vcl::Window* pWindow)
118 pWindow->SetBackground(GetSettings().GetStyleSettings().GetDialogColor());
120 sal_Int32 nNext = 0;
121 VclPtr<vcl::Window> pChild = pWindow->GetChild(nNext);
122 while (pChild && pWindow->GetType() == WindowType::CONTAINER)
124 ApplyBackground(pChild);
125 nNext++;
126 if (pWindow->GetChild(nNext) && pWindow->GetType() == WindowType::CONTAINER)
127 pChild = pWindow->GetChild(nNext);
128 else
129 break;
133 void NotebookbarPopup::RemoveBackground(vcl::Window* pWindow)
135 pWindow->SetBackground(Wallpaper(COL_TRANSPARENT));
137 sal_Int32 nNext = 0;
138 VclPtr<vcl::Window> pChild = pWindow->GetChild(nNext);
139 while (pChild && pWindow->GetType() == WindowType::CONTAINER)
141 RemoveBackground(pChild);
142 nNext++;
143 if (pWindow->GetChild(nNext) && pWindow->GetType() == WindowType::CONTAINER)
144 pChild = pWindow->GetChild(nNext);
145 else
146 break;
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */