2014-09-11 14:10:21 +02:00
|
|
|
/* -*- 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 <vcl/layout.hxx>
|
2016-08-19 10:20:03 +02:00
|
|
|
#include <vcl/tabctrl.hxx>
|
2016-03-29 11:13:57 +02:00
|
|
|
#include <vcl/notebookbar.hxx>
|
2016-12-27 17:58:09 +01:00
|
|
|
#include <vcl/taskpanelist.hxx>
|
2016-06-17 23:54:00 +02:00
|
|
|
#include <cppuhelper/queryinterface.hxx>
|
2016-06-28 10:02:06 +02:00
|
|
|
#include <cppuhelper/implbase.hxx>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* split from the main class since it needs different ref-counting mana
|
|
|
|
*/
|
|
|
|
class NotebookBarContextChangeEventListener : public ::cppu::WeakImplHelper<css::ui::XContextChangeEventListener>
|
|
|
|
{
|
|
|
|
VclPtr<NotebookBar> mpParent;
|
|
|
|
public:
|
2016-07-25 10:27:49 +01:00
|
|
|
explicit NotebookBarContextChangeEventListener(NotebookBar *p) : mpParent(p) {}
|
2016-06-28 10:02:06 +02:00
|
|
|
|
|
|
|
// XContextChangeEventListener
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual void SAL_CALL notifyContextChangeEvent(const css::ui::ContextChangeEventObject& rEvent) override;
|
2016-06-28 10:02:06 +02:00
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual void SAL_CALL disposing(const ::css::lang::EventObject&) override;
|
2016-06-28 10:02:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-11 14:10:21 +02:00
|
|
|
|
2016-03-29 11:13:57 +02:00
|
|
|
NotebookBar::NotebookBar(Window* pParent, const OString& rID, const OUString& rUIXMLDescription, const css::uno::Reference<css::frame::XFrame> &rFrame)
|
2016-06-28 10:02:06 +02:00
|
|
|
: Control(pParent), m_pEventListener(new NotebookBarContextChangeEventListener(this))
|
2014-09-11 14:10:21 +02:00
|
|
|
{
|
|
|
|
SetStyle(GetStyle() | WB_DIALOGCONTROL);
|
2017-01-11 09:48:18 +02:00
|
|
|
m_pUIBuilder.reset( new VclBuilder(this, getUIRootDir(), rUIXMLDescription, rID, rFrame) );
|
2016-08-19 10:20:03 +02:00
|
|
|
|
|
|
|
// In the Notebookbar's .ui file must exist control handling context
|
|
|
|
// - implementing NotebookbarContextControl interface with id "ContextContainer"
|
|
|
|
m_pContextContainer = dynamic_cast<NotebookbarContextControl*>(m_pUIBuilder->get<Window>("ContextContainer"));
|
2014-09-11 14:10:21 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 11:13:57 +02:00
|
|
|
NotebookBar::~NotebookBar()
|
2014-09-11 14:10:21 +02:00
|
|
|
{
|
|
|
|
disposeOnce();
|
|
|
|
}
|
|
|
|
|
2016-03-29 11:13:57 +02:00
|
|
|
void NotebookBar::dispose()
|
2014-09-11 14:10:21 +02:00
|
|
|
{
|
2016-12-27 17:58:09 +01:00
|
|
|
if (m_pSystemWindow && m_pSystemWindow->ImplIsInTaskPaneList(this))
|
|
|
|
m_pSystemWindow->GetTaskPaneList()->RemoveWindow(this);
|
2017-01-05 11:27:23 +02:00
|
|
|
m_pSystemWindow.clear();
|
2014-09-11 14:10:21 +02:00
|
|
|
disposeBuilder();
|
2016-06-28 10:02:06 +02:00
|
|
|
m_pEventListener.clear();
|
2014-09-11 14:10:21 +02:00
|
|
|
Control::dispose();
|
|
|
|
}
|
|
|
|
|
2016-12-27 17:58:09 +01:00
|
|
|
bool NotebookBar::PreNotify(NotifyEvent& rNEvt)
|
|
|
|
{
|
|
|
|
// capture KeyEvents for taskpane cycling
|
|
|
|
if (rNEvt.GetType() == MouseNotifyEvent::KEYINPUT)
|
|
|
|
{
|
|
|
|
if (m_pSystemWindow)
|
|
|
|
return m_pSystemWindow->PreNotify(rNEvt);
|
|
|
|
}
|
|
|
|
return Window::PreNotify( rNEvt );
|
|
|
|
}
|
|
|
|
|
2016-03-29 11:13:57 +02:00
|
|
|
Size NotebookBar::GetOptimalSize() const
|
2014-09-11 14:10:21 +02:00
|
|
|
{
|
|
|
|
if (isLayoutEnabled(this))
|
|
|
|
return VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild));
|
|
|
|
|
|
|
|
return Control::GetOptimalSize();
|
|
|
|
}
|
|
|
|
|
2016-03-29 11:13:57 +02:00
|
|
|
void NotebookBar::setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags)
|
2014-09-11 14:10:21 +02:00
|
|
|
{
|
|
|
|
bool bCanHandleSmallerWidth = false;
|
|
|
|
bool bCanHandleSmallerHeight = false;
|
|
|
|
|
|
|
|
bool bIsLayoutEnabled = isLayoutEnabled(this);
|
|
|
|
Window *pChild = GetWindow(GetWindowType::FirstChild);
|
|
|
|
|
2017-02-13 19:08:14 +02:00
|
|
|
if (bIsLayoutEnabled && pChild->GetType() == WindowType::SCROLLWINDOW)
|
2014-09-11 14:10:21 +02:00
|
|
|
{
|
|
|
|
WinBits nStyle = pChild->GetStyle();
|
|
|
|
if (nStyle & (WB_AUTOHSCROLL | WB_HSCROLL))
|
|
|
|
bCanHandleSmallerWidth = true;
|
|
|
|
if (nStyle & (WB_AUTOVSCROLL | WB_VSCROLL))
|
|
|
|
bCanHandleSmallerHeight = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Size aSize(GetOptimalSize());
|
|
|
|
if (!bCanHandleSmallerWidth)
|
|
|
|
nWidth = std::max(nWidth, aSize.Width());
|
|
|
|
if (!bCanHandleSmallerHeight)
|
|
|
|
nHeight = std::max(nHeight, aSize.Height());
|
|
|
|
|
|
|
|
Control::setPosSizePixel(nX, nY, nWidth, nHeight, nFlags);
|
|
|
|
|
|
|
|
if (bIsLayoutEnabled && (nFlags & PosSizeFlags::Size))
|
|
|
|
VclContainer::setLayoutAllocation(*pChild, Point(0, 0), Size(nWidth, nHeight));
|
|
|
|
}
|
|
|
|
|
2017-02-14 12:08:03 +01:00
|
|
|
void NotebookBar::Resize()
|
|
|
|
{
|
|
|
|
if(m_pUIBuilder && m_pUIBuilder->get_widget_root())
|
|
|
|
{
|
|
|
|
vcl::Window* pWindow = m_pUIBuilder->get_widget_root()->GetChild(0);
|
|
|
|
if (pWindow)
|
|
|
|
{
|
|
|
|
Size aSize = pWindow->GetSizePixel();
|
|
|
|
aSize.Width() = GetSizePixel().Width();
|
|
|
|
pWindow->SetSizePixel(aSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Control::Resize();
|
|
|
|
}
|
|
|
|
|
2016-12-27 17:58:09 +01:00
|
|
|
void NotebookBar::SetSystemWindow(SystemWindow* pSystemWindow)
|
|
|
|
{
|
2017-01-05 11:27:23 +02:00
|
|
|
m_pSystemWindow = pSystemWindow;
|
2016-12-27 17:58:09 +01:00
|
|
|
if (!m_pSystemWindow->ImplIsInTaskPaneList(this))
|
|
|
|
m_pSystemWindow->GetTaskPaneList()->AddWindow(this);
|
|
|
|
}
|
|
|
|
|
2016-06-28 10:02:06 +02:00
|
|
|
void SAL_CALL NotebookBarContextChangeEventListener::notifyContextChangeEvent(const css::ui::ContextChangeEventObject& rEvent)
|
2016-06-17 23:54:00 +02:00
|
|
|
{
|
2016-08-19 10:20:03 +02:00
|
|
|
if (mpParent && mpParent->m_pContextContainer)
|
|
|
|
mpParent->m_pContextContainer->SetContext(vcl::EnumContext::GetContextEnum(rEvent.ContextName));
|
2016-06-17 23:54:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-28 10:02:06 +02:00
|
|
|
void SAL_CALL NotebookBarContextChangeEventListener::disposing(const ::css::lang::EventObject&)
|
2016-06-17 23:54:00 +02:00
|
|
|
{
|
2016-06-28 10:02:06 +02:00
|
|
|
mpParent.clear();
|
2016-06-17 23:54:00 +02:00
|
|
|
}
|
|
|
|
|
2014-09-11 14:10:21 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|