weld ClassificationControl ToolboxWindow

Change-Id: Idda0b5187201aa77b5b6d682b740a8e55719742a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88129
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
Caolán McNamara 2020-02-06 17:15:41 +00:00
parent 2f86601db1
commit 57db1bb558
15 changed files with 215 additions and 153 deletions

View file

@ -9,11 +9,11 @@
#pragma once
#include <sfx2/dllapi.h>
#include <vcl/layout.hxx>
#include <vcl/weld.hxx>
#include <svx/svxdllapi.h>
class SVX_DLLPUBLIC InterimItemWindow : public Control
class SFX2_DLLPUBLIC InterimItemWindow : public Control
{
public:
virtual ~InterimItemWindow() override;

View file

@ -21,9 +21,9 @@
#include <vcl/field.hxx>
#include <vcl/lstbox.hxx>
#include <sfx2/InterimItemWindow.hxx>
#include <svtools/toolbarmenu.hxx>
#include <svx/dlgctrl.hxx>
#include <svx/InterimItemWindow.hxx>
#include <svx/svxdllapi.h>
class XLineWidthItem;
@ -66,6 +66,8 @@ private:
virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
virtual void GetFocus() override;
public:
SvxMetricField( vcl::Window* pParent,
const css::uno::Reference< css::frame::XFrame >& rFrame );

View file

@ -79,6 +79,11 @@ void SdPagesField::dispose()
InterimItemWindow::dispose();
}
void SdPagesField::GetFocus()
{
m_xWidget->grab_focus();
}
SdPagesField::~SdPagesField()
{
disposeOnce();

View file

@ -20,7 +20,7 @@
#ifndef INCLUDED_SD_SOURCE_UI_INC_DIACTRL_HXX
#define INCLUDED_SD_SOURCE_UI_INC_DIACTRL_HXX
#include <svx/InterimItemWindow.hxx>
#include <sfx2/InterimItemWindow.hxx>
#include <sfx2/tbxctrl.hxx>
namespace com { namespace sun { namespace star { namespace frame { class XFrame; } } } }
@ -45,6 +45,8 @@ public:
void set_sensitive(bool bSensitive);
virtual ~SdPagesField() override;
virtual void GetFocus() override;
void UpdatePagesField( const SfxUInt16Item* pItem );
};

View file

@ -127,6 +127,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
sfx2/source/bastyp/sfxhtml \
sfx2/source/bastyp/sfxresid \
sfx2/source/config/evntconf \
sfx2/source/control/InterimItemWindow \
sfx2/source/control/asyncfunc \
sfx2/source/control/bindings \
sfx2/source/control/ctrlitem \

View file

@ -20,6 +20,7 @@ $(eval $(call gb_UIConfig_add_uifiles,sfx,\
sfx2/uiconfig/ui/checkin \
sfx2/uiconfig/ui/cmisinfopage \
sfx2/uiconfig/ui/cmisline \
sfx2/uiconfig/ui/classificationbox \
sfx2/uiconfig/ui/custominfopage \
sfx2/uiconfig/ui/descriptioninfopage \
sfx2/uiconfig/ui/dockingwindow \

View file

@ -13,7 +13,7 @@
manual changes will be rewritten by the next run of update_pch.sh (which presumably
also fixes all possible problems, so it's usually better to use it).
Generated on 2020-02-03 10:51:07 using:
Generated on 2020-02-06 17:39:06 using:
./bin/update_pch sfx2 sfx --cutoff=3 --exclude:system --exclude:module --exclude:local
If after updating build fails, use the following command to locate conflicting headers:
@ -94,13 +94,11 @@
#include <vcl/button.hxx>
#include <vcl/commandevent.hxx>
#include <vcl/commandinfoprovider.hxx>
#include <vcl/ctrl.hxx>
#include <vcl/customweld.hxx>
#include <vcl/dibtools.hxx>
#include <vcl/dllapi.h>
#include <vcl/errcode.hxx>
#include <vcl/event.hxx>
#include <vcl/fixed.hxx>
#include <vcl/gdimtf.hxx>
#include <vcl/graph.hxx>
#include <vcl/graphicfilter.hxx>

View file

@ -0,0 +1,82 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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 <sfx2/InterimItemWindow.hxx>
InterimItemWindow::InterimItemWindow(vcl::Window* pParent, const OUString& rUIXMLDescription,
const OString& rID)
: Control(pParent, WB_TABSTOP)
{
m_xVclContentArea = VclPtr<VclVBox>::Create(this);
m_xVclContentArea->Show();
m_xBuilder.reset(Application::CreateInterimBuilder(m_xVclContentArea, rUIXMLDescription));
m_xContainer = m_xBuilder->weld_container(rID);
}
InterimItemWindow::~InterimItemWindow() { disposeOnce(); }
void InterimItemWindow::dispose()
{
m_xContainer.reset();
m_xBuilder.reset();
m_xVclContentArea.disposeAndClear();
Control::dispose();
}
void InterimItemWindow::Resize()
{
vcl::Window* pChild = GetWindow(GetWindowType::FirstChild);
assert(pChild);
VclContainer::setLayoutAllocation(*pChild, Point(0, 0), GetSizePixel());
Control::Resize();
}
Size InterimItemWindow::GetOptimalSize() const
{
return VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild));
}
bool InterimItemWindow::ChildKeyInput(const KeyEvent& rKEvt)
{
sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
if (nCode != KEY_TAB)
return false;
/* if the native widget has focus, then no vcl window has focus.
We want to grab focus to this vcl widget so that pressing tab will travese
to the next vcl widget.
But just using GrabFocus will, because no vcl widget has focus, trigger
bringing the toplevel to front with the expectation that a suitable widget
will be picked for focus when that happen, which is no use to us here.
SetFakeFocus avoids the problem, allowing GrabFocus to do the expected thing
then sending the Tab to our parent will do the right traversal
*/
SetFakeFocus(true);
GrabFocus();
/* let toolbox know we have focus so it updates its mnHighItemId to point
to this toolitem in case tab means to move to another toolitem within
the toolbox
*/
NotifyEvent aNEvt(MouseNotifyEvent::GETFOCUS, this);
vcl::Window* pToolBox = GetParent();
pToolBox->EventNotify(aNEvt);
/* now give focus to our toolbox parent and send it the tab */
pToolBox->GrabFocus();
pToolBox->KeyInput(rKEvt);
return true;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */

View file

@ -15,17 +15,18 @@
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/frame/XFrame.hpp>
#include <vcl/vclptr.hxx>
#include <vcl/lstbox.hxx>
#include <vcl/svapp.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/fixed.hxx>
#include <vcl/event.hxx>
#include <sfx2/InterimItemWindow.hxx>
#include <sfx2/classificationhelper.hxx>
#include <sfx2/objsh.hxx>
#include <sfx2/strings.hrc>
#include <sfx2/sfxresid.hxx>
#include <vcl/event.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/svapp.hxx>
#include <vcl/vclptr.hxx>
#include <vcl/weld.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <comphelper/propertysequence.hxx>
#include <comphelper/dispatchcommand.hxx>
@ -71,7 +72,7 @@ class ClassificationCategoriesController : public ClassificationCategoriesContro
rtl::Reference<comphelper::ConfigurationListener> m_xListener;
ClassificationPropertyListener m_aPropertyListener;
DECL_LINK(SelectHdl, ListBox&, void);
DECL_LINK(SelectHdl, weld::ComboBox&, void);
public:
explicit ClassificationCategoriesController(const uno::Reference<uno::XComponentContext>& rContext);
@ -94,21 +95,32 @@ public:
};
/// Classification control is the parent of all widgets that belongs to ClassificationCategoriesController.
class SAL_WARN_UNUSED ClassificationControl : public vcl::Window
class SAL_WARN_UNUSED ClassificationControl final : public InterimItemWindow
{
VclPtr<FixedText> m_pLabel;
VclPtr<ListBox> m_pCategory;
std::unique_ptr<weld::Label> m_xLabel;
std::unique_ptr<weld::ComboBox> m_xCategory;
DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
void SetOptimalSize();
void DataChanged(const DataChangedEvent& rEvent) override;
void GetFocus() override
{
m_xCategory->grab_focus();
}
public:
explicit ClassificationControl(vcl::Window* pParent);
~ClassificationControl() override;
void dispose() override;
void Resize() override;
const VclPtr<ListBox>& getCategory() const
weld::ComboBox& getCategory()
{
return m_pCategory;
return *m_xCategory;
}
void set_sensitive(bool bSensitive)
{
Enable(bSensitive);
m_xContainer->set_sensitive(bSensitive);
}
static sfx::ClassificationCreationOrigin getExistingClassificationOrigin();
void toggleInteractivityOnOrigin();
@ -175,13 +187,14 @@ uno::Reference<awt::XWindow> ClassificationCategoriesController::createItemWindo
if (pToolbar)
{
m_pClassification = VclPtr<ClassificationControl>::Create(pToolbar);
m_pClassification->getCategory()->SetSelectHdl(LINK(this, ClassificationCategoriesController, SelectHdl));
m_pClassification->getCategory().connect_changed(LINK(this, ClassificationCategoriesController, SelectHdl));
m_pClassification->Show();
}
return VCLUnoHelper::GetInterface(m_pClassification);
}
IMPL_LINK(ClassificationCategoriesController, SelectHdl, ListBox&, rCategory, void)
IMPL_LINK(ClassificationCategoriesController, SelectHdl, weld::ComboBox&, rCategory, void)
{
m_pClassification->toggleInteractivityOnOrigin();
@ -195,7 +208,7 @@ IMPL_LINK(ClassificationCategoriesController, SelectHdl, ListBox&, rCategory, vo
}
else
{
OUString aEntry = rCategory.GetSelectedEntry();
OUString aEntry = rCategory.get_active_text();
const OUString& aType = getCategoryType();
uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence({
@ -223,14 +236,12 @@ void ClassificationCategoriesController::statusChanged(const frame::FeatureState
// check if classification was set via the advanced dialog
if (ClassificationControl::getExistingClassificationOrigin() != sfx::ClassificationCreationOrigin::MANUAL)
{
VclPtr<ListBox> pCategories = m_pClassification->getCategory();
if (pCategories->GetEntryCount() == 0)
weld::ComboBox& rCategories = m_pClassification->getCategory();
if (rCategories.get_count() == 0)
{
std::vector<OUString> aNames = aHelper.GetBACNames();
for (const OUString& rName : aNames)
pCategories->InsertEntry(rName);
// Normally VclBuilder::makeObject() does this.
pCategories->EnableAutoSize(true);
rCategories.append_text(rName);
}
}
@ -241,16 +252,19 @@ void ClassificationCategoriesController::statusChanged(const frame::FeatureState
void ClassificationCategoriesController::removeEntries()
{
m_pClassification->getCategory()->Clear();
m_pClassification->getCategory().clear();
}
// WB_NOLABEL means here that the control won't be replaced with a label
// when it wouldn't fit the available space.
ClassificationControl::ClassificationControl(vcl::Window* pParent)
: Window(pParent, WB_DIALOGCONTROL | WB_NOLABEL)
: InterimItemWindow(pParent, "sfx/ui/classificationbox.ui", "ClassificationBox")
, m_xLabel(m_xBuilder->weld_label("label"))
, m_xCategory(m_xBuilder->weld_combo_box("combobox"))
{
m_pLabel = VclPtr<FixedText>::Create(this, WB_CENTER);
m_pCategory = VclPtr<ListBox>::Create(this, WB_CLIPCHILDREN|WB_LEFT|WB_VCENTER|WB_3DLOOK|WB_DROPDOWN|WB_SIMPLEMODE);
m_xCategory->connect_key_press(LINK(this, ClassificationControl, KeyInputHdl));
// WB_NOLABEL means here that the control won't be replaced with a label
// when it wouldn't fit the available space.
SetStyle(GetStyle() | WB_DIALOGCONTROL | WB_NOLABEL);
OUString aText;
switch (SfxClassificationHelper::getPolicyType())
@ -265,19 +279,22 @@ ClassificationControl::ClassificationControl(vcl::Window* pParent)
aText = SfxResId(STR_CLASSIFIED_EXPORT_CONTROL);
break;
}
Size aTextSize(m_pLabel->GetTextWidth(aText), m_pLabel->GetTextHeight());
// Padding.
aTextSize.AdjustWidth(12 );
m_pLabel->SetText(aText);
m_pLabel->SetSizePixel(aTextSize);
m_pLabel->Show();
m_xLabel->set_label(aText);
m_pCategory->Show();
// Same as SvxColorDockingWindow.
const Size aLogicalAttrSize(150, 0);
Size aSize(LogicToPixel(aLogicalAttrSize, MapMode(MapUnit::MapAppFont)));
m_xCategory->set_size_request(aSize.Width() - m_xLabel->get_preferred_size().Width(), -1);
SetOptimalSize();
}
IMPL_LINK(ClassificationControl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
{
return ChildKeyInput(rKEvt);
}
ClassificationControl::~ClassificationControl()
{
disposeOnce();
@ -285,43 +302,14 @@ ClassificationControl::~ClassificationControl()
void ClassificationControl::dispose()
{
m_pLabel.disposeAndClear();
m_pCategory.disposeAndClear();
vcl::Window::dispose();
}
void ClassificationControl::Resize()
{
// Give the label what it wants, and the remaining size to the listbox.
Size aSize(GetOutputSizePixel());
long nWLabel = m_pLabel->GetOutputSizePixel().Width();
long nW = aSize.Width();
long nH = aSize.Height();
long nPrefHeight = m_pLabel->get_preferred_size().Height();
long nOffset = (nH - nPrefHeight) / 2;
m_pLabel->SetPosSizePixel(Point(0, nOffset), Size(nWLabel, nPrefHeight));
nPrefHeight = m_pCategory->get_preferred_size().Height();
nOffset = (nH - nPrefHeight) / 2;
m_pCategory->SetPosSizePixel(Point(0 + nWLabel, nOffset), Size(nW - nWLabel, nPrefHeight));
m_xLabel.reset();
m_xCategory.reset();
InterimItemWindow::dispose();
}
void ClassificationControl::SetOptimalSize()
{
// Same as SvxColorDockingWindow.
const Size aLogicalAttrSize(150, 0);
Size aSize(LogicToPixel(aLogicalAttrSize, MapMode(MapUnit::MapAppFont)));
Point aPosition = m_pCategory->GetPosPixel();
aSize.setHeight( std::max(aSize.Height(), m_pLabel->get_preferred_size().Height()) );
aSize.setHeight( std::max(aSize.Height(), m_pCategory->get_preferred_size().Height()) );
aSize.setWidth( aPosition.X() + aSize.Width() );
SetSizePixel(aSize);
SetSizePixel(get_preferred_size());
}
void ClassificationControl::DataChanged(const DataChangedEvent& rEvent)
@ -331,7 +319,7 @@ void ClassificationControl::DataChanged(const DataChangedEvent& rEvent)
toggleInteractivityOnOrigin();
Window::DataChanged(rEvent);
InterimItemWindow::DataChanged(rEvent);
}
sfx::ClassificationCreationOrigin ClassificationControl::getExistingClassificationOrigin()
@ -351,11 +339,11 @@ void ClassificationControl::toggleInteractivityOnOrigin()
{
if (getExistingClassificationOrigin() == sfx::ClassificationCreationOrigin::MANUAL)
{
Disable();
set_sensitive(false);
}
else
{
Enable();
set_sensitive(true);
}
}
@ -364,7 +352,7 @@ void ClassificationControl::setCategoryStateFromPolicy(const SfxClassificationHe
const OUString& rCategoryName = rHelper.GetBACName(SfxClassificationHelper::getPolicyType());
if (!rCategoryName.isEmpty())
{
getCategory()->SelectEntry(rCategoryName);
getCategory().set_active_text(rCategoryName);
}
}

View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface domain="svx">
<requires lib="gtk+" version="3.18"/>
<object class="GtkBox" id="ClassificationBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">6</property>
<property name="margin_right">6</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">combobox</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="combobox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</interface>

View file

@ -13,7 +13,7 @@
manual changes will be rewritten by the next run of update_pch.sh (which presumably
also fixes all possible problems, so it's usually better to use it).
Generated on 2020-02-01 11:40:35 using:
Generated on 2020-02-06 17:42:27 using:
./bin/update_pch svx svxcore --cutoff=7 --exclude:system --include:module --exclude:local
If after updating build fails, use the following command to locate conflicting headers:
@ -95,6 +95,7 @@
#include <vcl/AccessibleBrowseBoxObjType.hxx>
#include <vcl/EnumContext.hxx>
#include <vcl/GraphicExternalLink.hxx>
#include <vcl/IContext.hxx>
#include <vcl/NotebookBarAddonsMerger.hxx>
#include <vcl/Scanline.hxx>
#include <vcl/accel.hxx>

View file

@ -34,78 +34,6 @@ using namespace svx;
#define MAX_SC_SD 116220200
#define NEGA_MAXVALUE -10000000
InterimItemWindow::InterimItemWindow(vcl::Window* pParent, const OUString& rUIXMLDescription, const OString& rID)
: Control(pParent, WB_TABSTOP)
{
m_xVclContentArea = VclPtr<VclVBox>::Create(this);
m_xVclContentArea->Show();
m_xBuilder.reset(Application::CreateInterimBuilder(m_xVclContentArea, rUIXMLDescription));
m_xContainer = m_xBuilder->weld_container(rID);
}
InterimItemWindow::~InterimItemWindow()
{
disposeOnce();
}
void InterimItemWindow::dispose()
{
m_xContainer.reset();
m_xBuilder.reset();
m_xVclContentArea.disposeAndClear();
Control::dispose();
}
void InterimItemWindow::Resize()
{
vcl::Window *pChild = GetWindow(GetWindowType::FirstChild);
assert(pChild);
VclContainer::setLayoutAllocation(*pChild, Point(0, 0), GetSizePixel());
Control::Resize();
}
Size InterimItemWindow::GetOptimalSize() const
{
return VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild));
}
bool InterimItemWindow::ChildKeyInput(const KeyEvent& rKEvt)
{
sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
if (nCode != KEY_TAB)
return false;
/* if the native widget has focus, then no vcl window has focus.
We want to grab focus to this vcl widget so that pressing tab will traverse
to the next vcl widget.
But just using GrabFocus will, because no vcl widget has focus, trigger
bringing the toplevel to front with the expectation that a suitable widget
will be picked for focus when that happen, which is no use to us here.
SetFakeFocus avoids the problem, allowing GrabFocus to do the expected thing
then sending the Tab to our parent will do the right traversal
*/
SetFakeFocus(true);
GrabFocus();
/* let toolbox know we have focus so it updates its mnHighItemId to point
to this toolitem in case tab means to move to another toolitem within
the toolbox
*/
NotifyEvent aNEvt(MouseNotifyEvent::GETFOCUS, this);
vcl::Window* pToolBox = GetParent();
pToolBox->EventNotify(aNEvt);
/* now give focus to our toolbox parent and send it the tab */
pToolBox->GrabFocus();
pToolBox->KeyInput(rKEvt);
return true;
}
// ParaULSpacingWindow
ParaULSpacingWindow::ParaULSpacingWindow(vcl::Window* pParent)

View file

@ -21,7 +21,7 @@
#include <editeng/ulspitem.hxx>
#include <vcl/EnumContext.hxx>
#include <svx/InterimItemWindow.hxx>
#include <sfx2/InterimItemWindow.hxx>
#include <svx/relfld.hxx>
using namespace com::sun::star;

View file

@ -178,6 +178,11 @@ void SvxMetricField::DataChanged( const DataChangedEvent& rDCEvt )
InterimItemWindow::DataChanged( rDCEvt );
}
void SvxMetricField::GetFocus()
{
m_xWidget->grab_focus();
}
SvxFillTypeBox::SvxFillTypeBox( vcl::Window* pParent ) :
ListBox( pParent, WB_BORDER | WB_DROPDOWN | WB_AUTOHSCROLL | WB_TABSTOP ),
nCurPos ( 0 ),

View file

@ -39,9 +39,9 @@
#include <memory>
#include <sfx2/InterimItemWindow.hxx>
#include <sfx2/sidebar/SidebarToolBox.hxx>
#include <boost/property_tree/ptree.hpp>
#include <svx/InterimItemWindow.hxx>
using namespace ::com::sun::star;