diff options
author | Szymon Kłos <eszkadev@gmail.com> | 2016-07-15 09:03:30 +0200 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2016-07-18 08:09:47 +0000 |
commit | e8fc80a0f03065ceb2c4f80facf08948d573b9af (patch) | |
tree | 0fe2f588a38bd7008c40c580fdd0a37f6d3dc9bd /sfx2 | |
parent | 54d8d7718b8ed3b3ddd47f3c2b993be689aeaab3 (diff) |
GSoC notebookbar: dropdown with hidden objects
+ added dropdown for hidden content
Change-Id: I86c9277d91b18fbe9e8505ccf170196fdb28638f
Reviewed-on: https://gerrit.libreoffice.org/27241
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/Library_sfx.mk | 1 | ||||
-rw-r--r-- | sfx2/UIConfig_sfx.mk | 1 | ||||
-rw-r--r-- | sfx2/source/notebookbar/DropdownBox.cxx | 166 | ||||
-rw-r--r-- | sfx2/source/notebookbar/DropdownBox.hxx | 54 | ||||
-rw-r--r-- | sfx2/source/notebookbar/PriorityHBox.cxx | 10 | ||||
-rw-r--r-- | sfx2/uiconfig/ui/notebookbarpopup.ui | 29 |
6 files changed, 257 insertions, 4 deletions
diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index fddb89b8af75..1a28afd63dee 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/DropdownBox \ sfx2/source/notebookbar/PriorityHBox \ sfx2/source/notebookbar/SfxNotebookBar \ sfx2/source/notify/eventsupplier \ diff --git a/sfx2/UIConfig_sfx.mk b/sfx2/UIConfig_sfx.mk index a7f532dce520..8482eca333e4 100644 --- a/sfx2/UIConfig_sfx.mk +++ b/sfx2/UIConfig_sfx.mk @@ -37,6 +37,7 @@ $(eval $(call gb_UIConfig_add_uifiles,sfx,\ sfx2/uiconfig/ui/notebookbar \ sfx2/uiconfig/ui/optprintpage \ sfx2/uiconfig/ui/password \ + sfx2/uiconfig/ui/notebookbarpopup \ sfx2/uiconfig/ui/printeroptionsdialog \ sfx2/uiconfig/ui/querysavedialog \ sfx2/uiconfig/ui/searchdialog \ diff --git a/sfx2/source/notebookbar/DropdownBox.cxx b/sfx2/source/notebookbar/DropdownBox.cxx new file mode 100644 index 000000000000..0058c89cfade --- /dev/null +++ b/sfx2/source/notebookbar/DropdownBox.cxx @@ -0,0 +1,166 @@ +/* -*- 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 "DropdownBox.hxx" + +#define NOTEBOOK_HEADER_HEIGHT 30 + +/* + * Popup - shows hidden content, controls are moved to this popup + * and after close moved to the original parent + */ + +class Popup : public FloatingWindow +{ +private: + VclPtr<VclHBox> m_pBox; + ScopedVclPtr<DropdownBox> m_pParent; + +public: + Popup(VclPtr<DropdownBox> pParent) + : FloatingWindow(pParent, "Popup", "sfx/ui/notebookbarpopup.ui") + , m_pParent(pParent) + { + get(m_pBox, "box"); + m_pBox->SetSizePixel(Size(100, 75)); + } + + virtual ~Popup() + { + disposeOnce(); + } + + VclHBox* getBox() + { + return m_pBox.get(); + } + + virtual void PopupModeEnd() override + { + for (int i = 0; i < m_pBox->GetChildCount(); i++) + { + m_pBox->GetChild(i)->Hide(); + m_pBox->GetChild(i)->SetParent(m_pParent); + } + FloatingWindow::PopupModeEnd(); + } + + void dispose() override + { + m_pBox.disposeAndClear(); + m_pParent.clear(); + + FloatingWindow::dispose(); + } +}; + +/* + * DropdownBox - shows content or moves it to the popup + * which can be opened by clicking on a button + */ + +DropdownBox::DropdownBox(vcl::Window *pParent) + : VclHBox(pParent) + , m_bInFullView(true) +{ + m_pButton = VclPtr<PushButton>::Create(this, WB_FLATBUTTON); + m_pButton->SetClickHdl(LINK(this, DropdownBox, PBClickHdl)); + m_pButton->SetSymbol(SymbolType::MENU); + m_pButton->set_width_request(15); + m_pButton->SetQuickHelpText(GetQuickHelpText()); + m_pButton->Resize(); +} + +DropdownBox::~DropdownBox() +{ + disposeOnce(); +} + +void DropdownBox::dispose() +{ + m_pButton.disposeAndClear(); + if (m_pPopup) + m_pPopup.disposeAndClear(); + + VclHBox::dispose(); +} + +void DropdownBox::HideContent() +{ + if (m_bInFullView) + { + m_bInFullView = false; + + for (int i = 0; i < GetChildCount(); i++) + GetChild(i)->Hide(); + + m_pButton->Show(); + SetOutputSizePixel(Size(m_pButton->GetSizePixel().Width(), GetSizePixel().Height())); + } +} + +void DropdownBox::ShowContent() +{ + if (!m_bInFullView) + { + m_bInFullView = true; + + for (int i = 0; i < GetChildCount(); i++) + GetChild(i)->Show(); + + m_pButton->Hide(); + } +} + +IMPL_LINK_TYPED(DropdownBox, PBClickHdl, Button*, /*pButton*/, void) +{ + if (m_pPopup) + m_pPopup.disposeAndClear(); + + m_pPopup = VclPtr<Popup>::Create(this); + + for (int i = 0; i < GetChildCount(); i++) + { + if (GetChild(i) != m_pButton) + { + Window* pChild = GetChild(i); + pChild->Show(); + + pChild->SetParent(m_pPopup->getBox()); + } + } + + m_pPopup->getBox()->set_height_request(GetSizePixel().Height()); + + long x = GetPosPixel().getX(); + long y = GetPosPixel().getY() + NOTEBOOK_HEADER_HEIGHT + GetSizePixel().Height(); + Rectangle aRect(x, y, x, y); + + m_pPopup->StartPopupMode(aRect, FloatWinPopupFlags::Down + |FloatWinPopupFlags::GrabFocus + |FloatWinPopupFlags::AllMouseButtonClose); +} + +VCL_BUILDER_FACTORY(DropdownBox) + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/notebookbar/DropdownBox.hxx b/sfx2/source/notebookbar/DropdownBox.hxx new file mode 100644 index 000000000000..a44d9708017d --- /dev/null +++ b/sfx2/source/notebookbar/DropdownBox.hxx @@ -0,0 +1,54 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_SFX2_NOTEBOOKBAR_DROPDOWNBOX_HXX +#define INCLUDED_SFX2_NOTEBOOKBAR_DROPDOWNBOX_HXX + +#include <vcl/builderfactory.hxx> +#include <vcl/layout.hxx> +#include <sfx2/dllapi.h> +#include <sfx2/viewfrm.hxx> +#include <vcl/floatwin.hxx> +#include <vcl/toolbox.hxx> +#include <sfx2/tbxctrl.hxx> + +class Popup; + +class SFX2_DLLPUBLIC DropdownBox : public VclHBox +{ +private: + bool m_bInFullView; + VclPtr<PushButton> m_pButton; + VclPtr<Popup> m_pPopup; + +public: + DropdownBox(vcl::Window *pParent); + virtual ~DropdownBox() override; + virtual void dispose() override; + + virtual void HideContent(); + virtual void ShowContent(); + +private: + DECL_LINK_TYPED(PBClickHdl, Button*, void); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/notebookbar/PriorityHBox.cxx b/sfx2/source/notebookbar/PriorityHBox.cxx index 88f91bc90518..52ce58aa9f16 100644 --- a/sfx2/source/notebookbar/PriorityHBox.cxx +++ b/sfx2/source/notebookbar/PriorityHBox.cxx @@ -21,6 +21,7 @@ #include <vcl/layout.hxx> #include <sfx2/dllapi.h> #include <sfx2/viewfrm.hxx> +#include "DropdownBox.hxx" #include <vector> @@ -75,16 +76,17 @@ public: auto pChild = m_aSortedChilds.begin(); while (nCurrentWidth > nWidth && pChild != m_aSortedChilds.end()) { - VclContainer* pContainer = static_cast<VclContainer*>(*pChild); + DropdownBox* pContainer = static_cast<DropdownBox*>(*pChild); nCurrentWidth -= pContainer->GetSizePixel().Width() + get_spacing(); - pContainer->Hide(); + pContainer->HideContent(); + nCurrentWidth += pContainer->GetSizePixel().Width() + get_spacing(); pChild++; } // Show higher priority controls if we already have enough space while (pChild != m_aSortedChilds.end()) { - static_cast<VclContainer*>(*pChild)->Show(); + static_cast<DropdownBox*>(*pChild)->ShowContent(); pChild++; } @@ -93,7 +95,7 @@ public: virtual void Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) override { - if (!m_bInitialized) + if (!m_bInitialized && SfxViewFrame::Current()) { m_bInitialized = true; diff --git a/sfx2/uiconfig/ui/notebookbarpopup.ui b/sfx2/uiconfig/ui/notebookbarpopup.ui new file mode 100644 index 000000000000..8400e481e66c --- /dev/null +++ b/sfx2/uiconfig/ui/notebookbarpopup.ui @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.18.3 --> +<interface> + <requires lib="gtk+" version="3.10"/> + <object class="GtkWindow" id="Popup"> + <property name="can_focus">False</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="border_width">4</property> + <property name="resizable">False</property> + <property name="destroy_with_parent">True</property> + <property name="type_hint">popup-menu</property> + <property name="skip_pager_hint">True</property> + <property name="deletable">False</property> + <child> + <object class="GtkBox" id="box"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_right">6</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="spacing">6</property> + <child> + <placeholder/> + </child> + </object> + </child> + </object> +</interface> |