weld OSelectLabelDialog

Change-Id: Icbf9f05e69667cb8161942dde84ded6b3fc61138
Reviewed-on: https://gerrit.libreoffice.org/67367
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
Caolán McNamara 2019-02-04 15:23:27 +00:00
parent ad5493c3fc
commit f69b5dd07a
6 changed files with 172 additions and 146 deletions

View file

@ -2855,11 +2855,12 @@ namespace pcr
bool FormComponentPropertyHandler::impl_dialogChooseLabelControl_nothrow( Any& _out_rNewValue, ::osl::ClearableMutexGuard& _rClearBeforeDialog ) const
{
ScopedVclPtrInstance< OSelectLabelDialog > dlgSelectLabel( impl_getDefaultDialogParent_nothrow(), m_xComponent );
vcl::Window* pParent = impl_getDefaultDialogParent_nothrow();
OSelectLabelDialog dlgSelectLabel(pParent ? pParent->GetFrameWeld() : nullptr, m_xComponent);
_rClearBeforeDialog.clear();
bool bSuccess = ( RET_OK == dlgSelectLabel->Execute() );
bool bSuccess = (RET_OK == dlgSelectLabel.run());
if ( bSuccess )
_out_rNewValue <<= dlgSelectLabel->GetSelected();
_out_rNewValue <<= dlgSelectLabel.GetSelected();
return bSuccess;
}

View file

@ -48,32 +48,20 @@ namespace pcr
// OSelectLabelDialog
OSelectLabelDialog::OSelectLabelDialog( vcl::Window* pParent, Reference< XPropertySet > const & _xControlModel )
:ModalDialog(pParent, "LabelSelectionDialog", "modules/spropctrlr/ui/labelselectiondialog.ui")
,m_xControlModel(_xControlModel)
,m_pInitialSelection(nullptr)
,m_pLastSelected(nullptr)
,m_bHaveAssignableControl(false)
OSelectLabelDialog::OSelectLabelDialog(weld::Window* pParent, Reference< XPropertySet > const & _xControlModel)
: GenericDialogController(pParent, "modules/spropctrlr/ui/labelselectiondialog.ui", "LabelSelectionDialog")
, m_xControlModel(_xControlModel)
, m_bLastSelected(false)
, m_bHaveAssignableControl(false)
, m_xMainDesc(m_xBuilder->weld_label("label"))
, m_xControlTree(m_xBuilder->weld_tree_view("control"))
, m_xNoAssignment(m_xBuilder->weld_check_button("noassignment"))
{
get(m_pMainDesc, "label");
get(m_pControlTree, "control");
get(m_pNoAssignment, "noassignment");
// initialize the TreeListBox
m_pControlTree->SetSelectionMode( SelectionMode::Single );
m_pControlTree->SetDragDropMode( DragDropMode::NONE );
m_pControlTree->EnableInplaceEditing( false );
m_pControlTree->SetStyle(m_pControlTree->GetStyle() | WB_BORDER | WB_HASLINES | WB_HASLINESATROOT | WB_HASBUTTONS | WB_HASBUTTONSATROOT | WB_HSCROLL);
m_pControlTree->SetNodeBitmaps(Image(StockImage::Yes, RID_EXTBMP_COLLAPSEDNODE),
Image(StockImage::Yes, RID_EXTBMP_EXPANDEDNODE));
m_pControlTree->SetSelectHdl(LINK(this, OSelectLabelDialog, OnEntrySelected));
m_pControlTree->SetDeselectHdl(LINK(this, OSelectLabelDialog, OnEntrySelected));
m_xControlTree->connect_changed(LINK(this, OSelectLabelDialog, OnEntrySelected));
m_xControlTree->set_size_request(-1, m_xControlTree->get_height_rows(8));
// fill the description
OUString sDescription = m_pMainDesc->GetText();
OUString sDescription = m_xMainDesc->get_label();
sal_Int16 nClassID = FormComponentType::CONTROL;
if (::comphelper::hasProperty(PROPERTY_CLASSID, m_xControlModel))
nClassID = ::comphelper::getINT16(m_xControlModel->getPropertyValue(PROPERTY_CLASSID));
@ -82,7 +70,7 @@ namespace pcr
GetUIHeadlineName(nClassID, makeAny(m_xControlModel)));
OUString sName = ::comphelper::getString(m_xControlModel->getPropertyValue(PROPERTY_NAME));
sDescription = sDescription.replaceAll("$controlname$", sName);
m_pMainDesc->SetText(sDescription);
m_xMainDesc->set_label(sDescription);
// search for the root of the form hierarchy
Reference< XChild > xCont(m_xControlModel, UNO_QUERY);
@ -102,9 +90,9 @@ namespace pcr
sal_Int16 nClassId = 0;
try { nClassId = ::comphelper::getINT16(m_xControlModel->getPropertyValue(PROPERTY_CLASSID)); } catch(...) { }
m_sRequiredService = (FormComponentType::RADIOBUTTON == nClassId) ? OUString(SERVICE_COMPONENT_GROUPBOX) : OUString(SERVICE_COMPONENT_FIXEDTEXT);
m_aRequiredControlImage = Image(StockImage::Yes, FormComponentType::RADIOBUTTON == nClassId ? OUStringLiteral(RID_EXTBMP_GROUPBOX) : OUStringLiteral(RID_EXTBMP_FIXEDTEXT));
m_aRequiredControlImage = (FormComponentType::RADIOBUTTON == nClassId) ? OUString(RID_EXTBMP_GROUPBOX) : OUString(RID_EXTBMP_FIXEDTEXT);
// calc the currently set label control (so InsertEntries can calc m_pInitialSelection)
// calc the currently set label control (so InsertEntries can calc m_xInitialSelection)
Any aCurrentLabelControl( m_xControlModel->getPropertyValue(PROPERTY_CONTROLLABEL) );
DBG_ASSERT((aCurrentLabelControl.getValueTypeClass() == TypeClass_INTERFACE) || !aCurrentLabelControl.hasValue(),
@ -113,62 +101,49 @@ namespace pcr
aCurrentLabelControl >>= m_xInitialLabelControl;
// insert the root
Image aRootImage(StockImage::Yes, RID_EXTBMP_FORMS);
SvTreeListEntry* pRoot = m_pControlTree->InsertEntry(PcrRes(RID_STR_FORMS), aRootImage, aRootImage);
OUString sRootName(PcrRes(RID_STR_FORMS));
OUString aFormImage(RID_EXTBMP_FORMS);
m_xControlTree->insert(nullptr, -1, &sRootName, nullptr,
nullptr, nullptr, &aFormImage, false);
// build the tree
m_pInitialSelection = nullptr;
m_xInitialSelection.reset();
m_bHaveAssignableControl = false;
InsertEntries(xSearch, pRoot);
m_pControlTree->Expand(pRoot);
std::unique_ptr<weld::TreeIter> xRoot = m_xControlTree->make_iterator();
m_xControlTree->get_iter_first(*xRoot);
InsertEntries(xSearch, *xRoot);
m_xControlTree->expand_row(*xRoot);
}
if (m_pInitialSelection)
if (m_xInitialSelection)
{
m_pControlTree->MakeVisible(m_pInitialSelection, true);
m_pControlTree->Select(m_pInitialSelection);
m_xControlTree->scroll_to_row(*m_xInitialSelection);
m_xControlTree->select(*m_xInitialSelection);
}
else
{
m_pControlTree->MakeVisible(m_pControlTree->First(), true);
if (m_pControlTree->FirstSelected())
m_pControlTree->Select(m_pControlTree->FirstSelected(), false);
m_pNoAssignment->Check();
m_xControlTree->scroll_to_row(0);
m_xControlTree->unselect_all();
m_xNoAssignment->set_active(true);
}
if (!m_bHaveAssignableControl)
{ // no controls which can be assigned
m_pNoAssignment->Check();
m_pNoAssignment->Enable(false);
m_xNoAssignment->set_active(true);
m_xNoAssignment->set_sensitive(false);
}
m_pNoAssignment->SetClickHdl(LINK(this, OSelectLabelDialog, OnNoAssignmentClicked));
m_pNoAssignment->GetClickHdl().Call(m_pNoAssignment);
m_xLastSelected = m_xControlTree->make_iterator(nullptr);
m_xNoAssignment->connect_toggled(LINK(this, OSelectLabelDialog, OnNoAssignmentClicked));
OnNoAssignmentClicked(*m_xNoAssignment);
}
OSelectLabelDialog::~OSelectLabelDialog()
{
disposeOnce();
}
void OSelectLabelDialog::dispose()
{
// delete the entry datas of the listbox entries
SvTreeListEntry* pLoop = m_pControlTree->First();
while (pLoop)
{
void* pData = pLoop->GetUserData();
if (pData)
delete static_cast<Reference< XPropertySet > *>(pData);
pLoop = m_pControlTree->Next(pLoop);
}
m_pMainDesc.clear();
m_pControlTree.clear();
m_pNoAssignment.clear();
ModalDialog::dispose();
}
sal_Int32 OSelectLabelDialog::InsertEntries(const Reference< XInterface > & _xContainer, SvTreeListEntry* pContainerEntry)
sal_Int32 OSelectLabelDialog::InsertEntries(const Reference< XInterface > & _xContainer, weld::TreeIter& rContainerEntry)
{
Reference< XIndexAccess > xContainer(_xContainer, UNO_QUERY);
if (!xContainer.is())
@ -201,19 +176,21 @@ namespace pcr
Reference< XIndexAccess > xCont(xAsSet, UNO_QUERY);
if (xCont.is() && xCont->getCount())
{ // yes -> step down
Image aFormImage(StockImage::Yes, RID_EXTBMP_FORM);
SvTreeListEntry* pCont = m_pControlTree->InsertEntry(sName, aFormImage, aFormImage, pContainerEntry);
sal_Int32 nContChildren = InsertEntries(xCont, pCont);
OUString aFormImage(RID_EXTBMP_FORM);
m_xControlTree->insert(&rContainerEntry, -1, &sName, nullptr,
nullptr, nullptr, &aFormImage, false);
auto xIter = m_xControlTree->make_iterator(&rContainerEntry);
m_xControlTree->iter_nth_child(*xIter, nChildren);
sal_Int32 nContChildren = InsertEntries(xCont, *xIter);
if (nContChildren)
{
m_pControlTree->Expand(pCont);
m_xControlTree->expand_row(*xIter);
++nChildren;
}
else
{ // oops, no valid children -> remove the entry
m_pControlTree->ModelIsRemoving(pCont);
m_pControlTree->GetModel()->Remove(pCont);
m_pControlTree->ModelHasRemoved(pCont);
m_xControlTree->remove(*xIter);
}
}
continue;
@ -229,71 +206,71 @@ namespace pcr
makeStringAndClear();
// all requirements met -> insert
SvTreeListEntry* pCurrent = m_pControlTree->InsertEntry(sDisplayName, m_aRequiredControlImage, m_aRequiredControlImage, pContainerEntry);
pCurrent->SetUserData(new Reference< XPropertySet > (xAsSet));
++nChildren;
m_xUserData.emplace_back(new Reference<XPropertySet>(xAsSet));
OUString sId(OUString::number(reinterpret_cast<sal_Int64>(m_xUserData.back().get())));
m_xControlTree->insert(&rContainerEntry, -1, &sDisplayName, &sId, nullptr, nullptr, &m_aRequiredControlImage, false);
if (m_xInitialLabelControl == xAsSet)
m_pInitialSelection = pCurrent;
{
m_xInitialSelection = m_xControlTree->make_iterator(&rContainerEntry);
m_xControlTree->iter_nth_child(*m_xInitialSelection, nChildren);
}
++nChildren;
m_bHaveAssignableControl = true;
}
return nChildren;
}
IMPL_LINK(OSelectLabelDialog, OnEntrySelected, SvTreeListBox*, pLB, void)
IMPL_LINK(OSelectLabelDialog, OnEntrySelected, weld::TreeView&, rLB, void)
{
DBG_ASSERT(pLB == m_pControlTree, "OSelectLabelDialog::OnEntrySelected : where did this come from ?");
SvTreeListEntry* pSelected = m_pControlTree->FirstSelected();
void* pData = pSelected ? pSelected->GetUserData() : nullptr;
if (pData)
m_xSelectedControl.set(*static_cast<Reference< XPropertySet > *>(pData));
m_pNoAssignment->SetClickHdl(Link<Button*,void>());
m_pNoAssignment->Check(pData == nullptr);
m_pNoAssignment->SetClickHdl(LINK(this, OSelectLabelDialog, OnNoAssignmentClicked));
DBG_ASSERT(&rLB == m_xControlTree.get(), "OSelectLabelDialog::OnEntrySelected : where did this come from ?");
std::unique_ptr<weld::TreeIter> xIter = m_xControlTree->make_iterator();
bool bSelected = m_xControlTree->get_selected(xIter.get());
OUString sData = bSelected ? m_xControlTree->get_id(*xIter) : OUString();
if (!sData.isEmpty())
m_xSelectedControl.set(*reinterpret_cast<Reference<XPropertySet>*>(sData.toInt64()));
m_xNoAssignment->set_active(sData.isEmpty());
}
IMPL_LINK(OSelectLabelDialog, OnNoAssignmentClicked, Button*, pButton, void)
IMPL_LINK(OSelectLabelDialog, OnNoAssignmentClicked, weld::ToggleButton&, rButton, void)
{
DBG_ASSERT(pButton == m_pNoAssignment, "OSelectLabelDialog::OnNoAssignmentClicked : where did this come from ?");
DBG_ASSERT(&rButton == m_xNoAssignment.get(), "OSelectLabelDialog::OnNoAssignmentClicked : where did this come from ?");
if (m_pNoAssignment->IsChecked())
m_pLastSelected = m_pControlTree->FirstSelected();
if (m_xNoAssignment->get_active())
{
m_bLastSelected = m_xControlTree->get_selected(m_xLastSelected.get());
}
else
{
DBG_ASSERT(m_bHaveAssignableControl, "OSelectLabelDialog::OnNoAssignmentClicked");
// search the first assignable entry
SvTreeListEntry* pSearch = m_pControlTree->First();
while (pSearch)
auto xSearch = m_xControlTree->make_iterator(nullptr);
bool bSearch = m_xControlTree->get_iter_first(*xSearch);
while (bSearch)
{
if (pSearch->GetUserData())
if (m_xControlTree->get_id(*xSearch).toInt64())
break;
pSearch = m_pControlTree->Next(pSearch);
bSearch = m_xControlTree->iter_next(*xSearch);
}
// and select it
if (pSearch)
if (bSearch)
{
m_pControlTree->Select(pSearch);
m_pLastSelected = pSearch;
m_xControlTree->copy_iterator(*xSearch, *m_xLastSelected);
m_xControlTree->select(*m_xLastSelected);
m_bLastSelected = true;
}
}
if (m_pLastSelected)
if (m_bLastSelected)
{
m_pControlTree->SetSelectHdl(Link<SvTreeListBox*,void>());
m_pControlTree->SetDeselectHdl(Link<SvTreeListBox*,void>());
m_pControlTree->Select(m_pLastSelected, !m_pNoAssignment->IsChecked());
m_pControlTree->SetSelectHdl(LINK(this, OSelectLabelDialog, OnEntrySelected));
m_pControlTree->SetDeselectHdl(LINK(this, OSelectLabelDialog, OnEntrySelected));
if (!m_xNoAssignment->get_active())
m_xControlTree->select(*m_xLastSelected);
else
m_xControlTree->unselect(*m_xLastSelected);
}
}
} // namespace pcr

View file

@ -20,56 +20,46 @@
#ifndef INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_SELECTLABELDIALOG_HXX
#define INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_SELECTLABELDIALOG_HXX
#include <vcl/fixed.hxx>
#include <vcl/treelistbox.hxx>
#include <vcl/button.hxx>
#include <vcl/image.hxx>
#include <vcl/dialog.hxx>
#include <vcl/weld.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include "modulepcr.hxx"
namespace pcr
{
// OSelectLabelDialog
class OSelectLabelDialog final
:public ModalDialog
class OSelectLabelDialog final : public weld::GenericDialogController
{
VclPtr<FixedText> m_pMainDesc;
VclPtr<SvTreeListBox> m_pControlTree;
VclPtr<CheckBox> m_pNoAssignment;
css::uno::Reference< css::beans::XPropertySet > m_xControlModel;
OUString m_sRequiredService;
Image m_aRequiredControlImage;
SvTreeListEntry* m_pInitialSelection;
OUString m_aRequiredControlImage;
std::unique_ptr<weld::TreeIter> m_xInitialSelection;
// the entry datas of the listbox entries
std::vector<std::unique_ptr<css::uno::Reference<css::beans::XPropertySet>>> m_xUserData;
css::uno::Reference< css::beans::XPropertySet > m_xInitialLabelControl;
css::uno::Reference< css::beans::XPropertySet > m_xSelectedControl;
SvTreeListEntry* m_pLastSelected;
bool m_bHaveAssignableControl;
std::unique_ptr<weld::TreeIter> m_xLastSelected;
bool m_bLastSelected;
bool m_bHaveAssignableControl;
std::unique_ptr<weld::Label> m_xMainDesc;
std::unique_ptr<weld::TreeView> m_xControlTree;
std::unique_ptr<weld::CheckButton> m_xNoAssignment;
public:
OSelectLabelDialog(vcl::Window* pParent, css::uno::Reference< css::beans::XPropertySet > const & _xControlModel);
OSelectLabelDialog(weld::Window* pParent, css::uno::Reference< css::beans::XPropertySet > const & _xControlModel);
virtual ~OSelectLabelDialog() override;
virtual void dispose() override;
css::uno::Reference< css::beans::XPropertySet > GetSelected() const { return m_pNoAssignment->IsChecked() ? css::uno::Reference< css::beans::XPropertySet > () : m_xSelectedControl; }
css::uno::Reference< css::beans::XPropertySet > GetSelected() const { return m_xNoAssignment->get_active() ? css::uno::Reference< css::beans::XPropertySet > () : m_xSelectedControl; }
private:
sal_Int32 InsertEntries(const css::uno::Reference< css::uno::XInterface >& _xContainer, SvTreeListEntry* pContainerEntry);
sal_Int32 InsertEntries(const css::uno::Reference< css::uno::XInterface >& _xContainer, weld::TreeIter& rContainerEntry);
DECL_LINK(OnEntrySelected, SvTreeListBox*, void);
DECL_LINK(OnNoAssignmentClicked, Button*, void);
DECL_LINK(OnEntrySelected, weld::TreeView&, void);
DECL_LINK(OnNoAssignmentClicked, weld::ToggleButton&, void);
};
} // namespace pcr
#endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_SELECTLABELDIALOG_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -1,16 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<!-- Generated with glade 3.22.1 -->
<interface domain="pcr">
<requires lib="gtk+" version="3.18"/>
<requires lib="LibreOffice" version="1.0"/>
<object class="GtkTreeStore" id="liststore1">
<columns>
<!-- column-name expander -->
<column type="GdkPixbuf"/>
<!-- column-name text -->
<column type="gchararray"/>
<!-- column-name id -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkDialog" id="LabelSelectionDialog">
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="title" translatable="yes" context="labelselectiondialog|LabelSelectionDialog">Label Field Selection</property>
<property name="modal">True</property>
<property name="default_width">0</property>
<property name="type_hint">dialog</property>
<child>
<placeholder/>
</child>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child internal-child="action_area">
@ -86,7 +102,8 @@
<property name="label" translatable="yes" context="labelselectiondialog|label">These are control fields that can be used as label fields for the $controlclass$ $controlname$.</property>
<property name="use_underline">True</property>
<property name="wrap">True</property>
<property name="mnemonic_widget">control:border</property>
<property name="mnemonic_widget">control</property>
<property name="width_chars">60</property>
<property name="max_width_chars">60</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
@ -98,15 +115,44 @@
</packing>
</child>
<child>
<object class="vcllo-SvTreeListBox" id="control:border">
<property name="width_request">200</property>
<property name="height_request">150</property>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection1"/>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="control">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="model">liststore1</property>
<property name="headers_visible">False</property>
<property name="search_column">1</property>
<property name="show_expanders">True</property>
<property name="enable_tree_lines">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="Macro Library List-selection1"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
<property name="spacing">6</property>
<child>
<object class="GtkCellRendererPixbuf" id="cellrenderertext4"/>
<attributes>
<attribute name="pixbuf">0</attribute>
</attributes>
</child>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>

View file

@ -463,7 +463,10 @@ protected:
void signal_changed() { m_aChangeHdl.Call(*this); }
void signal_row_activated() { m_aRowActivatedHdl.Call(*this); }
bool signal_expanding(TreeIter& rIter) { return m_aExpandingHdl.Call(rIter); }
bool signal_expanding(TreeIter& rIter)
{
return !m_aExpandingHdl.IsSet() || m_aExpandingHdl.Call(rIter);
}
// arg is pair<row,col>
void signal_toggled(const std::pair<int, int>& rRowCol) { m_aRadioToggleHdl.Call(rRowCol); }
@ -566,6 +569,15 @@ public:
// set iter to point to next node, depth first, then sibling
virtual bool iter_next(TreeIter& rIter) const = 0;
virtual bool iter_children(TreeIter& rIter) const = 0;
bool iter_nth_child(TreeIter& rIter, int nChild) const
{
if (!iter_children(rIter))
return false;
bool bRet = true;
for (int i = 0; i < nChild && bRet; ++i)
bRet = iter_next(rIter);
return bRet;
}
virtual bool iter_parent(TreeIter& rIter) const = 0;
virtual int get_iter_depth(const TreeIter& rIter) const = 0;
virtual bool iter_has_child(const TreeIter& rIter) const = 0;

View file

@ -5625,7 +5625,7 @@ public:
GtkTreeModel *pModel = GTK_TREE_MODEL(m_pTreeStore);
GtkTreePath* path = gtk_tree_model_get_path(pModel, &rGtkIter.iter);
if (!gtk_tree_view_row_expanded(m_pTreeView, path))
gtk_tree_view_expand_row(m_pTreeView, path, false);
gtk_tree_view_expand_to_path(m_pTreeView, path);
gtk_tree_path_free(path);
}