build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / vcl / source / control / notebookbar.cxx
blobfc9eb49f220d7291f1dde64132ee4db0f4ed300f
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/layout.hxx>
11 #include <vcl/tabctrl.hxx>
12 #include <vcl/notebookbar.hxx>
13 #include <cppuhelper/queryinterface.hxx>
14 #include <cppuhelper/implbase.hxx>
16 /**
17 * split from the main class since it needs different ref-counting mana
19 class NotebookBarContextChangeEventListener : public ::cppu::WeakImplHelper<css::ui::XContextChangeEventListener>
21 VclPtr<NotebookBar> mpParent;
22 public:
23 explicit NotebookBarContextChangeEventListener(NotebookBar *p) : mpParent(p) {}
25 // XContextChangeEventListener
26 virtual void SAL_CALL notifyContextChangeEvent(const css::ui::ContextChangeEventObject& rEvent)
27 throw (css::uno::RuntimeException, std::exception) override;
29 virtual void SAL_CALL disposing(const ::css::lang::EventObject&)
30 throw (::css::uno::RuntimeException, ::std::exception) override;
35 NotebookBar::NotebookBar(Window* pParent, const OString& rID, const OUString& rUIXMLDescription, const css::uno::Reference<css::frame::XFrame> &rFrame)
36 : Control(pParent), m_pEventListener(new NotebookBarContextChangeEventListener(this))
38 SetStyle(GetStyle() | WB_DIALOGCONTROL);
39 m_pUIBuilder.reset( new VclBuilder(this, getUIRootDir(), rUIXMLDescription, rID, rFrame) );
41 // In the Notebookbar's .ui file must exist control handling context
42 // - implementing NotebookbarContextControl interface with id "ContextContainer"
43 m_pContextContainer = dynamic_cast<NotebookbarContextControl*>(m_pUIBuilder->get<Window>("ContextContainer"));
46 NotebookBar::~NotebookBar()
48 disposeOnce();
51 void NotebookBar::dispose()
53 disposeBuilder();
54 m_pEventListener.clear();
55 Control::dispose();
58 Size NotebookBar::GetOptimalSize() const
60 if (isLayoutEnabled(this))
61 return VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild));
63 return Control::GetOptimalSize();
66 void NotebookBar::setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags)
68 bool bCanHandleSmallerWidth = false;
69 bool bCanHandleSmallerHeight = false;
71 bool bIsLayoutEnabled = isLayoutEnabled(this);
72 Window *pChild = GetWindow(GetWindowType::FirstChild);
74 if (bIsLayoutEnabled && pChild->GetType() == WINDOW_SCROLLWINDOW)
76 WinBits nStyle = pChild->GetStyle();
77 if (nStyle & (WB_AUTOHSCROLL | WB_HSCROLL))
78 bCanHandleSmallerWidth = true;
79 if (nStyle & (WB_AUTOVSCROLL | WB_VSCROLL))
80 bCanHandleSmallerHeight = true;
83 Size aSize(GetOptimalSize());
84 if (!bCanHandleSmallerWidth)
85 nWidth = std::max(nWidth, aSize.Width());
86 if (!bCanHandleSmallerHeight)
87 nHeight = std::max(nHeight, aSize.Height());
89 Control::setPosSizePixel(nX, nY, nWidth, nHeight, nFlags);
91 if (bIsLayoutEnabled && (nFlags & PosSizeFlags::Size))
92 VclContainer::setLayoutAllocation(*pChild, Point(0, 0), Size(nWidth, nHeight));
95 void NotebookBar::SetIconClickHdl(Link<NotebookBar*, void> aHdl)
97 if (m_pContextContainer)
98 m_pContextContainer->SetIconClickHdl(aHdl);
101 void SAL_CALL NotebookBarContextChangeEventListener::notifyContextChangeEvent(const css::ui::ContextChangeEventObject& rEvent)
102 throw (css::uno::RuntimeException, std::exception)
104 if (mpParent && mpParent->m_pContextContainer)
105 mpParent->m_pContextContainer->SetContext(vcl::EnumContext::GetContextEnum(rEvent.ContextName));
109 void SAL_CALL NotebookBarContextChangeEventListener::disposing(const ::css::lang::EventObject&)
110 throw (::css::uno::RuntimeException, ::std::exception)
112 mpParent.clear();
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */