[Libreoffice-commits] core.git: include/svtools include/vcl svtools/source sw/inc sw/source sw/uiconfig

Caolán McNamara caolanm at redhat.com
Mon Apr 2 19:54:26 UTC 2018


 include/svtools/unitconv.hxx          |    2 +
 include/vcl/weld.hxx                  |   14 +++++++
 svtools/source/misc/unitconv.cxx      |   54 +++++++++++++++++++++++++++
 sw/inc/colwd.hxx                      |   20 ++++------
 sw/inc/swabstdlg.hxx                  |    2 -
 sw/source/ui/dialog/swdlgfact.cxx     |   10 +++--
 sw/source/ui/dialog/swdlgfact.hxx     |   15 +++++++
 sw/source/ui/dialog/swuiexp.cxx       |    1 
 sw/source/ui/table/colwd.cxx          |   67 ++++++++++++++--------------------
 sw/source/uibase/inc/tablemgr.hxx     |    2 -
 sw/source/uibase/shells/tabsh.cxx     |    2 -
 sw/source/uibase/table/tablemgr.cxx   |    2 -
 sw/uiconfig/swriter/ui/columnwidth.ui |   19 +++++++--
 13 files changed, 148 insertions(+), 62 deletions(-)

New commits:
commit fa8822c48e2a79589bebbd015b36d1da8b338cc2
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Apr 2 15:30:08 2018 +0100

    weld SwTableWidthDlg
    
    Change-Id: I272a783c9b7a8f725314e416fbd81217105ee5a6
    Reviewed-on: https://gerrit.libreoffice.org/52266
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/svtools/unitconv.hxx b/include/svtools/unitconv.hxx
index 756c4fdfe9ab..6d663df72b1c 100644
--- a/include/svtools/unitconv.hxx
+++ b/include/svtools/unitconv.hxx
@@ -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 );
 
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index e791724c0a43..a5a6d75035fb 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -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);
diff --git a/svtools/source/misc/unitconv.cxx b/svtools/source/misc/unitconv.cxx
index 88845fe9794b..f99b2806076c 100644
--- a/svtools/source/misc/unitconv.cxx
+++ b/svtools/source/misc/unitconv.cxx
@@ -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 )
 {
diff --git a/sw/inc/colwd.hxx b/sw/inc/colwd.hxx
index c6d13e159130..894ed19b2f5a 100644
--- a/sw/inc/colwd.hxx
+++ b/sw/inc/colwd.hxx
@@ -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
diff --git a/sw/inc/swabstdlg.hxx b/sw/inc/swabstdlg.hxx
index 9e604f66ce68..9c900e9d4b6f 100644
--- a/sw/inc/swabstdlg.hxx
+++ b/sw/inc/swabstdlg.hxx
@@ -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;
 
diff --git a/sw/source/ui/dialog/swdlgfact.cxx b/sw/source/ui/dialog/swdlgfact.cxx
index 2d1da118cd18..ca8b8c12fb44 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -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,
diff --git a/sw/source/ui/dialog/swdlgfact.hxx b/sw/source/ui/dialog/swdlgfact.hxx
index cf2343bb9e66..6635787db0fc 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -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;
diff --git a/sw/source/ui/dialog/swuiexp.cxx b/sw/source/ui/dialog/swuiexp.cxx
index 336a779100b8..1b681c9e8b52 100644
--- a/sw/source/ui/dialog/swuiexp.cxx
+++ b/sw/source/ui/dialog/swuiexp.cxx
@@ -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>
diff --git a/sw/source/ui/table/colwd.cxx b/sw/source/ui/table/colwd.cxx
index 8ad8aaf6be64..4ca22dda4b5e 100644
--- a/sw/source/ui/table/colwd.cxx
+++ b/sw/source/ui/table/colwd.cxx
@@ -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: */
diff --git a/sw/source/uibase/inc/tablemgr.hxx b/sw/source/uibase/inc/tablemgr.hxx
index 785862250fe9..3f6d3200a48f 100644
--- a/sw/source/uibase/inc/tablemgr.hxx
+++ b/sw/source/uibase/inc/tablemgr.hxx
@@ -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 );
diff --git a/sw/source/uibase/shells/tabsh.cxx b/sw/source/uibase/shells/tabsh.cxx
index 94b56435e1b9..f42d14e5a956 100644
--- a/sw/source/uibase/shells/tabsh.cxx
+++ b/sw/source/uibase/shells/tabsh.cxx
@@ -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:
diff --git a/sw/source/uibase/table/tablemgr.cxx b/sw/source/uibase/table/tablemgr.cxx
index 5f49fa04bf57..52b49a483e7d 100644
--- a/sw/source/uibase/table/tablemgr.cxx
+++ b/sw/source/uibase/table/tablemgr.cxx
@@ -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();
diff --git a/sw/uiconfig/swriter/ui/columnwidth.ui b/sw/uiconfig/swriter/ui/columnwidth.ui
index 1b9706059f38..593d0c1ee209 100644
--- a/sw/uiconfig/swriter/ui/columnwidth.ui
+++ b/sw/uiconfig/swriter/ui/columnwidth.ui
@@ -1,5 +1,5 @@
 <?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>


More information about the Libreoffice-commits mailing list