Kaydet (Commit) fa8822c4 authored tarafından Caolán McNamara's avatar Caolán McNamara

weld SwTableWidthDlg

Change-Id: I272a783c9b7a8f725314e416fbd81217105ee5a6
Reviewed-on: https://gerrit.libreoffice.org/52266Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 5d5a7293
......@@ -20,6 +20,7 @@
#define INCLUDED_SVTOOLS_UNITCONV_HXX
#include <vcl/field.hxx>
#include <vcl/weld.hxx>
#include <svtools/svtdllapi.h>
#include <svl/poolitem.hxx>
......@@ -31,6 +32,7 @@ typedef long (*FUNC_CONVERT)(long);
// Functions -------------------------------------------------------------
SVT_DLLPUBLIC void SetFieldUnit(weld::MetricSpinButton& rCtrl, FieldUnit eUnit, bool bAll = false);
SVT_DLLPUBLIC void SetFieldUnit( MetricField& rCtrl, FieldUnit eUnit, bool bAll = false );
SVT_DLLPUBLIC void SetFieldUnit( MetricBox& rCtrl, FieldUnit eUnit );
......
......@@ -493,6 +493,20 @@ public:
max = ConvertValue(max, m_eSrcUnit, eDestUnit);
}
void set_min(int min, FieldUnit eValueUnit)
{
int dummy, max;
get_range(dummy, max, eValueUnit);
set_range(min, max, eValueUnit);
}
void set_max(int max, FieldUnit eValueUnit)
{
int min, dummy;
get_range(min, dummy, eValueUnit);
set_range(min, max, eValueUnit);
}
void set_increments(int step, int page, FieldUnit eValueUnit)
{
step = ConvertValue(step, eValueUnit, m_eSrcUnit);
......
......@@ -19,6 +19,60 @@
#include <svtools/unitconv.hxx>
void SetFieldUnit(weld::MetricSpinButton& rField, FieldUnit eUnit, bool bAll)
{
int nMin, nMax;
rField.get_range(nMin, nMax, FUNIT_TWIP);
nMin = rField.denormalize(nMin);
nMax = rField.denormalize(nMax);
if (!bAll)
{
switch (eUnit)
{
case FUNIT_M:
case FUNIT_KM:
eUnit = FUNIT_CM;
break;
case FUNIT_FOOT:
case FUNIT_MILE:
eUnit = FUNIT_INCH;
break;
default: //prevent warning
break;
}
}
rField.set_unit(eUnit);
if (FUNIT_POINT == eUnit && rField.get_digits() > 1)
rField.set_digits(1);
else
rField.set_digits(2);
switch (eUnit)
{
// _CHAR and _LINE sets the step of "char" and "line" unit, they are same as FUNIT_MM
case FUNIT_CHAR:
case FUNIT_LINE:
case FUNIT_MM:
rField.set_increments(50, 500, eUnit);
break;
case FUNIT_INCH:
rField.set_increments(2, 20, eUnit);
break;
default:
rField.set_increments(10, 100, eUnit);
break;
}
if (!bAll)
{
nMin = rField.normalize(nMin);
nMax = rField.normalize(nMax);
rField.set_range(nMin, nMax, FUNIT_TWIP);
}
}
void SetFieldUnit( MetricField& rField, FieldUnit eUnit, bool bAll )
{
......
......@@ -19,24 +19,22 @@
#ifndef INCLUDED_SW_INC_COLWD_HXX
#define INCLUDED_SW_INC_COLWD_HXX
#include <svx/stddlg.hxx>
#include <vcl/field.hxx>
#include <vcl/weld.hxx>
class SwTableFUNC;
class SwTableWidthDlg final : public SvxStandardDialog
class SwTableWidthDlg final : public weld::GenericDialogController
{
VclPtr<NumericField> m_pColNF;
VclPtr<MetricField> m_pWidthMF;
SwTableFUNC &rFnc;
SwTableFUNC &m_rFnc;
virtual void Apply() override;
DECL_LINK(LoseFocusHdl, Edit&, void);
std::unique_ptr<weld::SpinButton> m_xColNF;
std::unique_ptr<weld::MetricSpinButton> m_xWidthMF;
DECL_LINK(LoseFocusHdl, weld::SpinButton&, void);
public:
SwTableWidthDlg(vcl::Window *pParent, SwTableFUNC &rFnc );
virtual ~SwTableWidthDlg() override;
virtual void dispose() override;
SwTableWidthDlg(weld::Window *pParent, SwTableFUNC &rFnc);
short execute();
};
#endif
......
......@@ -435,7 +435,7 @@ public:
virtual VclPtr<SfxAbstractDialog> CreateSwBorderDlg ( vcl::Window* pParent, SfxItemSet& rSet, SwBorderModes nType ) = 0;
virtual VclPtr<SfxAbstractDialog> CreateSwWrapDlg ( vcl::Window* pParent, SfxItemSet& rSet, SwWrtShell* pSh ) = 0;
virtual VclPtr<VclAbstractDialog> CreateSwTableWidthDlg(vcl::Window *pParent, SwTableFUNC &rFnc) = 0;
virtual VclPtr<VclAbstractDialog> CreateSwTableWidthDlg(weld::Window *pParent, SwTableFUNC &rFnc) = 0;
virtual VclPtr<SfxAbstractTabDialog> CreateSwTableTabDlg(vcl::Window* pParent,
const SfxItemSet* pItemSet, SwWrtShell* pSh) = 0;
......
......@@ -32,6 +32,7 @@
#include <break.hxx>
#include <changedb.hxx>
#include <chrdlg.hxx>
#include <colwd.hxx>
#include <convert.hxx>
#include <cption.hxx>
#include <dbinsdlg.hxx>
......@@ -102,6 +103,10 @@ short AbstractSwBreakDlg_Impl::Execute()
{
return m_xDlg->execute();
}
short AbstractSwTableWidthDlg_Impl::Execute()
{
return m_xDlg->execute();
}
short AbstractSwSortDlg_Impl::Execute()
{
return m_xDlg->execute();
......@@ -841,10 +846,9 @@ VclPtr<SfxAbstractDialog> SwAbstractDialogFactory_Impl::CreateSwWrapDlg ( vcl::W
return VclPtr<SwAbstractSfxDialog_Impl>::Create( pDlg );
}
VclPtr<VclAbstractDialog> SwAbstractDialogFactory_Impl::CreateSwTableWidthDlg(vcl::Window *pParent, SwTableFUNC &rFnc)
VclPtr<VclAbstractDialog> SwAbstractDialogFactory_Impl::CreateSwTableWidthDlg(weld::Window *pParent, SwTableFUNC &rFnc)
{
VclPtr<Dialog> pDlg = VclPtr<SwTableWidthDlg>::Create(pParent, rFnc);
return VclPtr<VclAbstractDialog_Impl>::Create( pDlg );
return VclPtr<AbstractSwTableWidthDlg_Impl>::Create(new SwTableWidthDlg(pParent, rFnc));
}
VclPtr<SfxAbstractTabDialog> SwAbstractDialogFactory_Impl::CreateSwTableTabDlg(vcl::Window* pParent,
......
......@@ -26,6 +26,7 @@ class SwAsciiFilterDlg;
class Dialog;
class SwBreakDlg;
class SwSortDlg;
class SwTableWidthDlg;
class SignatureLineDialog;
class SfxTabDialog;
class SwConvertTableDlg;
......@@ -142,6 +143,18 @@ public:
virtual ::boost::optional<sal_uInt16> GetPageNumber() override;
};
class AbstractSwTableWidthDlg_Impl : public VclAbstractDialog
{
protected:
std::unique_ptr<SwTableWidthDlg> m_xDlg;
public:
explicit AbstractSwTableWidthDlg_Impl(SwTableWidthDlg* p)
: m_xDlg(p)
{
}
virtual short Execute() override;
};
class AbstractSplitTableDialog_Impl : public AbstractSplitTableDialog // add for
{
protected:
......@@ -487,7 +500,7 @@ public:
virtual VclPtr<SfxAbstractDialog> CreateSwBorderDlg (vcl::Window* pParent, SfxItemSet& rSet, SwBorderModes nType ) override;
virtual VclPtr<SfxAbstractDialog> CreateSwWrapDlg ( vcl::Window* pParent, SfxItemSet& rSet, SwWrtShell* pSh ) override;
virtual VclPtr<VclAbstractDialog> CreateSwTableWidthDlg(vcl::Window *pParent, SwTableFUNC &rFnc) override;
virtual VclPtr<VclAbstractDialog> CreateSwTableWidthDlg(weld::Window *pParent, SwTableFUNC &rFnc) override;
virtual VclPtr<SfxAbstractTabDialog> CreateSwTableTabDlg(vcl::Window* pParent,
const SfxItemSet* pItemSet, SwWrtShell* pSh) override;
virtual VclPtr<AbstractSwFieldDlg> CreateSwFieldDlg(SfxBindings* pB, SwChildWinWrapper* pCW, vcl::Window *pParent) override;
......
......@@ -22,6 +22,7 @@
#include <abstract.hxx>
#include <ascfldlg.hxx>
#include <break.hxx>
#include <colwd.hxx>
#include <convert.hxx>
#include <srtdlg.hxx>
#include <dbinsdlg.hxx>
......
......@@ -30,57 +30,48 @@
#include <cmdid.h>
IMPL_LINK_NOARG(SwTableWidthDlg, LoseFocusHdl, Edit&, void)
IMPL_LINK_NOARG(SwTableWidthDlg, LoseFocusHdl, weld::SpinButton&, void)
{
sal_uInt16 nId = static_cast<sal_uInt16>(m_pColNF->GetValue())-1;
const SwTwips lWidth = rFnc.GetColWidth(nId);
m_pWidthMF->SetMax(m_pWidthMF->Normalize(rFnc.GetMaxColWidth(nId)), FUNIT_TWIP);
m_pWidthMF->SetValue(m_pWidthMF->Normalize(lWidth), FUNIT_TWIP);
sal_uInt16 nId = static_cast<sal_uInt16>(m_xColNF->get_value()) - 1;
const SwTwips lWidth = m_rFnc.GetColWidth(nId);
m_xWidthMF->set_max(m_xWidthMF->normalize(m_rFnc.GetMaxColWidth(nId)), FUNIT_TWIP);
m_xWidthMF->set_value(m_xWidthMF->normalize(lWidth), FUNIT_TWIP);
}
SwTableWidthDlg::SwTableWidthDlg(vcl::Window *pParent, SwTableFUNC &rTableFnc )
: SvxStandardDialog( pParent, "ColumnWidthDialog", "modules/swriter/ui/columnwidth.ui" )
, rFnc(rTableFnc)
SwTableWidthDlg::SwTableWidthDlg(weld::Window *pParent, SwTableFUNC &rTableFnc)
: GenericDialogController(pParent, "modules/swriter/ui/columnwidth.ui", "ColumnWidthDialog")
, m_rFnc(rTableFnc)
, m_xColNF(m_xBuilder->weld_spin_button("column"))
, m_xWidthMF(m_xBuilder->weld_metric_spin_button("width"))
{
get(m_pColNF, "column");
get(m_pWidthMF, "width");
bool bIsWeb = rTableFnc.GetShell()
&& (dynamic_cast< const SwWebDocShell* >(
rTableFnc.GetShell()->GetView().GetDocShell()) != nullptr );
FieldUnit eFieldUnit = SW_MOD()->GetUsrPref( bIsWeb )->GetMetric();
::SetFieldUnit(*m_pWidthMF, eFieldUnit);
m_pColNF->SetValue( rFnc.GetCurColNum() +1 );
m_pWidthMF->SetMin(m_pWidthMF->Normalize(MINLAY), FUNIT_TWIP);
if(!m_pWidthMF->GetMin())
m_pWidthMF->SetMin(1);
::SetFieldUnit(*m_xWidthMF, eFieldUnit);
if(rFnc.GetColCount() == 0)
m_pWidthMF->SetMin(m_pWidthMF->Normalize(rFnc.GetColWidth(0)), FUNIT_TWIP);
m_pColNF->SetMax(rFnc.GetColCount() +1 );
m_pColNF->SetModifyHdl(LINK(this,SwTableWidthDlg, LoseFocusHdl));
LoseFocusHdl(*m_pColNF);
}
m_xColNF->set_max(m_rFnc.GetColCount() + 1);
m_xColNF->set_value(m_rFnc.GetCurColNum() + 1);
SwTableWidthDlg::~SwTableWidthDlg()
{
disposeOnce();
}
void SwTableWidthDlg::dispose()
{
m_pColNF.clear();
m_pWidthMF.clear();
SvxStandardDialog::dispose();
if (m_rFnc.GetColCount() == 0)
m_xWidthMF->set_min(m_xWidthMF->normalize(m_rFnc.GetColWidth(0)), FUNIT_TWIP);
else
m_xWidthMF->set_min(m_xWidthMF->normalize(MINLAY), FUNIT_TWIP);
m_xColNF->connect_value_changed(LINK(this, SwTableWidthDlg, LoseFocusHdl));
LoseFocusHdl(*m_xColNF);
}
void SwTableWidthDlg::Apply()
short SwTableWidthDlg::execute()
{
rFnc.InitTabCols();
rFnc.SetColWidth(
static_cast< sal_uInt16 >(m_pColNF->GetValue() - 1),
static_cast< sal_uInt16 >(m_pWidthMF->Denormalize(m_pWidthMF->GetValue(FUNIT_TWIP))));
short nRet = run();
if (nRet == RET_OK)
{
m_rFnc.InitTabCols();
m_rFnc.SetColWidth(
static_cast<sal_uInt16>(m_xColNF->get_value() - 1),
static_cast<sal_uInt16>(m_xWidthMF->denormalize(m_xWidthMF->get_value(FUNIT_TWIP))));
}
return nRet;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -53,7 +53,7 @@ public:
~SwTableFUNC();
void InitTabCols();
void ColWidthDlg(vcl::Window *pParent );
void ColWidthDlg(weld::Window *pParent);
SwTwips GetColWidth(sal_uInt16 nNum) const;
SwTwips GetMaxColWidth(sal_uInt16 nNum) const;
void SetColWidth(sal_uInt16 nNum, SwTwips nWidth );
......
......@@ -1158,7 +1158,7 @@ void SwTableShell::Execute(SfxRequest &rReq)
case FN_TABLE_SET_COL_WIDTH:
{
SwTableFUNC aMgr( &rSh );
aMgr.ColWidthDlg(GetView().GetWindow());
aMgr.ColWidthDlg(GetView().GetFrameWeld());
break;
}
case SID_TABLE_VERT_NONE:
......
......@@ -50,7 +50,7 @@
using namespace ::com::sun::star;
// Adjust line height (dialogue)
void SwTableFUNC::ColWidthDlg( vcl::Window *pParent )
void SwTableFUNC::ColWidthDlg(weld::Window *pParent)
{
InitTabCols();
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<!-- Generated with glade 3.20.4 -->
<interface domain="sw">
<requires lib="gtk+" version="3.18"/>
<object class="GtkAdjustment" id="adjustment1">
......@@ -14,6 +14,9 @@
<property name="border_width">6</property>
<property name="title" translatable="yes" context="columnwidth|ColumnWidthDialog">Column Width</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="default_width">0</property>
<property name="default_height">0</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
......@@ -29,6 +32,7 @@
<property name="label">gtk-ok</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
......@@ -98,10 +102,10 @@
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes" context="columnwidth|label2">Column:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">column</property>
<property name="xalign">1</property>
</object>
<packing>
<property name="left_attach">0</property>
......@@ -112,10 +116,10 @@
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes" context="columnwidth|label3">Width:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">width:0mm</property>
<property name="mnemonic_widget">width</property>
<property name="xalign">1</property>
</object>
<packing>
<property name="left_attach">0</property>
......@@ -126,6 +130,7 @@
<object class="GtkSpinButton" id="column">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activates_default">True</property>
<property name="adjustment">adjustment1</property>
</object>
<packing>
......@@ -134,9 +139,10 @@
</packing>
</child>
<child>
<object class="GtkSpinButton" id="width:0mm">
<object class="GtkSpinButton" id="width">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activates_default">True</property>
<property name="climb_rate">0.01</property>
<property name="digits">2</property>
</object>
......@@ -173,5 +179,8 @@
<action-widget response="-6">cancel</action-widget>
<action-widget response="-11">help</action-widget>
</action-widgets>
<child>
<placeholder/>
</child>
</object>
</interface>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment