summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorSzymon Kłos <eszkadev@gmail.com>2016-07-01 15:53:46 +0200
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2016-07-08 13:23:24 +0000
commitd3dd6b5c41cbd16620bf53189b9c08ad5600fdc8 (patch)
treed0a38e7bd742d0fc670dab52cfaf3b5a3a9ddb1d /sfx2
parentb39596b109e05e6b49687e072bcb1e0b39b21dcc (diff)
GSoC notebookbar: container with priority
+ extended vcl builder to parse priority + IPrioritable interface for controls with priorities + added IPrioritable as a base for VclContainer + Added PriorityHBox - box which shows controls if we have enough space PriorityHBox listen vcl events from SystemWindow to detect Resize Change-Id: I74ac1a80e7d0a061f5e7a8584dbb2abf956053c7 Reviewed-on: https://gerrit.libreoffice.org/26983 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/Library_sfx.mk1
-rw-r--r--sfx2/source/doc/objxtor.cxx3
-rw-r--r--sfx2/source/notebookbar/PriorityHBox.cxx152
3 files changed, 156 insertions, 0 deletions
diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk
index 0b77f45d62b7..fddb89b8af75 100644
--- a/sfx2/Library_sfx.mk
+++ b/sfx2/Library_sfx.mk
@@ -234,6 +234,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
sfx2/source/doc/saveastemplatedlg \
sfx2/source/explorer/nochaos \
sfx2/source/inet/inettbc \
+ sfx2/source/notebookbar/PriorityHBox \
sfx2/source/notebookbar/SfxNotebookBar \
sfx2/source/notify/eventsupplier \
sfx2/source/notify/globalevents \
diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx
index 8f7a814bdce6..f3cc4f2d716a 100644
--- a/sfx2/source/doc/objxtor.cxx
+++ b/sfx2/source/doc/objxtor.cxx
@@ -97,6 +97,7 @@
#include "appbaslib.hxx"
#include <sfx2/sfxbasemodel.hxx>
#include <shellimpl.hxx>
+#include <sfx2/notebookbar/SfxNotebookBar.hxx>
#include <basic/basicmanagerrepository.hxx>
@@ -622,6 +623,8 @@ bool SfxObjectShell::PrepareClose
return false;
}
+ if ( pFrame )
+ sfx2::SfxNotebookBar::CloseMethod(pFrame->GetBindings());
pImpl->bPreparedForClose = true;
return true;
}
diff --git a/sfx2/source/notebookbar/PriorityHBox.cxx b/sfx2/source/notebookbar/PriorityHBox.cxx
new file mode 100644
index 000000000000..88f91bc90518
--- /dev/null
+++ b/sfx2/source/notebookbar/PriorityHBox.cxx
@@ -0,0 +1,152 @@
+/* -*- 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 <vcl/builderfactory.hxx>
+#include <vcl/layout.hxx>
+#include <sfx2/dllapi.h>
+#include <sfx2/viewfrm.hxx>
+
+#include <vector>
+
+bool lcl_comparePriority(const vcl::IPrioritable* a, const vcl::IPrioritable* b)
+{
+ return a->GetPriority() < b->GetPriority();
+}
+
+/*
+ * PriorityHBox is a VclHBox which hides own childs if there is no sufficient space.
+ * Hiding order can be modified using child's priorities. If a control have default
+ * priority assigned (VCL_PRIORITY_DEFAULT), it is always shown.
+ */
+
+class SFX2_DLLPUBLIC PriorityHBox : public VclHBox
+{
+private:
+ bool m_bInitialized;
+ long m_nNeededWidth;
+
+ std::vector<IPrioritable*> m_aSortedChilds;
+
+public:
+ PriorityHBox(vcl::Window *pParent)
+ : VclHBox(pParent)
+ , m_bInitialized(false)
+ , m_nNeededWidth(0)
+ {
+ }
+
+ virtual ~PriorityHBox() override
+ {
+ disposeOnce();
+ }
+
+ virtual void dispose() override
+ {
+ if (m_bInitialized && SfxViewFrame::Current())
+ {
+ SystemWindow* pSystemWindow = SfxViewFrame::Current()->GetFrame().GetSystemWindow();
+ pSystemWindow->RemoveEventListener(LINK(this, PriorityHBox, WindowEventListener));
+ }
+ VclHBox::dispose();
+ }
+
+ virtual void Resize() override
+ {
+ long nWidth = GetSizePixel().Width();
+ long nCurrentWidth = m_nNeededWidth;
+
+ // Hide lower priority controls
+ auto pChild = m_aSortedChilds.begin();
+ while (nCurrentWidth > nWidth && pChild != m_aSortedChilds.end())
+ {
+ VclContainer* pContainer = static_cast<VclContainer*>(*pChild);
+ nCurrentWidth -= pContainer->GetSizePixel().Width() + get_spacing();
+ pContainer->Hide();
+ pChild++;
+ }
+
+ // Show higher priority controls if we already have enough space
+ while (pChild != m_aSortedChilds.end())
+ {
+ static_cast<VclContainer*>(*pChild)->Show();
+ pChild++;
+ }
+
+ VclHBox::Resize();
+ }
+
+ virtual void Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) override
+ {
+ if (!m_bInitialized)
+ {
+ m_bInitialized = true;
+
+ SystemWindow* pSystemWindow = SfxViewFrame::Current()->GetFrame().GetSystemWindow();
+ pSystemWindow->AddEventListener(LINK(this, PriorityHBox, WindowEventListener));
+
+ CalcNeededWidth();
+
+ long nWidth = pSystemWindow->GetSizePixel().Width();
+ SetSizePixel(Size(nWidth, GetSizePixel().Height()));
+ }
+
+ VclHBox::Paint(rRenderContext, rRect);
+ }
+
+ void CalcNeededWidth()
+ {
+ int spacing = get_spacing();
+
+ for (sal_uInt16 i = 0; i < GetChildCount(); ++i)
+ {
+ vcl::Window* pChild = GetChild(i);
+ m_nNeededWidth += pChild->GetSizePixel().Width() + spacing;
+
+ // Add only containers which have explicitly assigned priority.
+ if (pChild->GetType() == WINDOW_CONTAINER)
+ {
+ IPrioritable* pPrioritable = dynamic_cast<IPrioritable*>(pChild);
+ if (pPrioritable->GetPriority() != VCL_PRIORITY_DEFAULT)
+ m_aSortedChilds.push_back(pPrioritable);
+ }
+ }
+
+ std::sort(m_aSortedChilds.begin(), m_aSortedChilds.end(), lcl_comparePriority);
+ }
+
+private:
+ DECL_LINK_TYPED( WindowEventListener, VclWindowEvent&, void );
+};
+
+IMPL_LINK_TYPED( PriorityHBox, WindowEventListener, VclWindowEvent&, rEvent, void )
+{
+ if (rEvent.GetId() == VCLEVENT_WINDOW_RESIZE)
+ {
+ vcl::Window* pEventWindow = rEvent.GetWindow();
+
+ OSL_ENSURE(pEventWindow, "PriorityHBox::WindowEventListener: no window!");
+
+ long nWidth = pEventWindow->GetSizePixel().Width();
+ SetSizePixel(Size(nWidth, GetSizePixel().Height()));
+ }
+}
+
+VCL_BUILDER_FACTORY(PriorityHBox)
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */