cui/source/inc/paragrph.hxx       |    3 -
 cui/source/tabpages/paragrph.cxx  |   85 ++++++++++++++++++++++++++++----------
 cui/uiconfig/ui/textflowpage.ui   |   10 +++-
 sw/source/uibase/utlui/uitool.cxx |   21 ++++++++-
 4 files changed, 90 insertions(+), 29 deletions(-)

New commits:
commit c43cc2d70a8083c70e615335d19780bd59f40fd8
Author: Michael Stahl <mst...@redhat.com>
Date:   Wed Mar 1 12:39:54 2017 +0100

    tdf#77111 cui,sw: fix page number offset on paragraph dialog "Text Flow"
    
    Commit c2ccd20c0fd92bddfff76447754541705e3eb8f3 introduced 0 as a valid
    value for page number offset in sw core.
    
    Unfortunately the paragraph dialog was not changed then; previously
    page number 0 would do automatic numbering, but since then 0 was set as
    the offset, and once you have a 0 offset there's no easy way to remove
    it, you have to remove the whole page break.
    
    * change the label before the text number edit widget to a checkbox
      that disables the edit widget
    
    * keep the id "labelPageNum" so that translations still work
    
    * adapt SfxToSwPageDescAttr so it can not just set but also clear the
      page number
    
    * set initial value to 1; 0 is a really bad default since we can't
      export it to ODF (see tdf#91306)
    
    (cherry picked from commit d36fa0589ab822dc617c65b4d0d3bf68c092ad37)
    Reviewed-on: https://gerrit.libreoffice.org/34745
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>
    (cherry picked from commit a5104f575a5acf8aea957cb79aa0fd67bc74f141)
    
    Change-Id: Ic4ca9e2562bb65ac359b305a2202f782e8598307
    Reviewed-on: https://gerrit.libreoffice.org/34810
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>

diff --git a/cui/source/inc/paragrph.hxx b/cui/source/inc/paragrph.hxx
index 6397f82..1e79a0c 100644
--- a/cui/source/inc/paragrph.hxx
+++ b/cui/source/inc/paragrph.hxx
@@ -236,7 +236,7 @@ private:
     VclPtr<ListBox>            m_pBreakPositionLB;
     VclPtr<TriStateBox>        m_pApplyCollBtn;
     VclPtr<ListBox>            m_pApplyCollBox;
-    VclPtr<FixedText>          m_pPagenumText;
+    VclPtr<TriStateBox>        m_pPageNumBox;
     VclPtr<NumericField>       m_pPagenumEdit;
 
     // paragraph division
@@ -264,6 +264,7 @@ private:
     DECL_LINK_TYPED(ApplyCollClickHdl_Impl, Button*, void);
     DECL_LINK_TYPED( PageBreakPosHdl_Impl, ListBox&, void );
     DECL_LINK_TYPED( PageBreakTypeHdl_Impl, ListBox&, void );
+    DECL_LINK_TYPED(PageNumBoxClickHdl_Impl, Button*, void);
 
     virtual void            PageCreated(const SfxAllItemSet& aSet) override;
 };
diff --git a/cui/source/tabpages/paragrph.cxx b/cui/source/tabpages/paragrph.cxx
index 4b9e7da..5fdc153 100644
--- a/cui/source/tabpages/paragrph.cxx
+++ b/cui/source/tabpages/paragrph.cxx
@@ -1392,18 +1392,27 @@ bool SvxExtParagraphTabPage::FillItemSet( SfxItemSet* 
rOutSet )
         }
     }
 
-    if (m_pPagenumEdit->IsEnabled() && m_pPagenumEdit->IsValueModified())
+    if (m_pPageNumBox->IsEnabled()
+        && (m_pPageNumBox->IsValueChangedFromSaved() || 
m_pPagenumEdit->IsValueModified()))
     {
-        SfxUInt16Item aPageNum( SID_ATTR_PARA_PAGENUM,
-                                (sal_uInt16)m_pPagenumEdit->GetValue() );
-
         pOld = GetOldItem( *rOutSet, SID_ATTR_PARA_PAGENUM );
 
-        if ( !pOld || static_cast<const SfxUInt16Item*>(pOld)->GetValue() != 
aPageNum.GetValue() )
+        if (TRISTATE_TRUE == m_pPageNumBox->GetState()
+            && (!pOld || IsInvalidItem(pOld)
+                || static_cast<const SfxUInt16Item*>(pOld)->GetValue() != 
m_pPagenumEdit->GetValue()))
         {
+            SfxUInt16Item aPageNum(SID_ATTR_PARA_PAGENUM,
+                    static_cast<sal_uInt16>(m_pPagenumEdit->GetValue()));
             rOutSet->Put( aPageNum );
             bModified = true;
         }
+        else if (TRISTATE_FALSE == m_pPageNumBox->GetState()
+                && (pOld || IsInvalidItem(pOld)))
+        {
+            // need to tell sw to remove the item
+            rOutSet->DisableItem(SID_ATTR_PARA_PAGENUM);
+            bModified = true;
+        }
     }
 
     // pagebreak
@@ -1595,11 +1604,34 @@ void SvxExtParagraphTabPage::Reset( const SfxItemSet* 
rSet )
 
     _nWhich = GetWhich( SID_ATTR_PARA_PAGENUM );
 
-    if (rSet->GetItemState(_nWhich) >= SfxItemState::SET)
+    switch (rSet->GetItemState(_nWhich))
     {
-        const sal_uInt16 nPageNum =
-            static_cast<const SfxUInt16Item&>(rSet->Get( _nWhich ) 
).GetValue();
-        m_pPagenumEdit->SetValue( nPageNum );
+        case SfxItemState::SET:
+        {
+            m_pPageNumBox->EnableTriState(false);
+            m_pPageNumBox->SetState(TRISTATE_TRUE);
+            SfxUInt16Item const*const pItem(static_cast<const 
SfxUInt16Item*>(rSet->GetItem(_nWhich)));
+            const sal_uInt16 nPageNum(pItem->GetValue());
+            m_pPagenumEdit->SetValue( nPageNum );
+            break;
+        }
+        case SfxItemState::DONTCARE:
+        {
+            m_pPageNumBox->EnableTriState();
+            m_pPageNumBox->SetState(TRISTATE_INDET);
+            break;
+        }
+        case SfxItemState::UNKNOWN:
+        case SfxItemState::DEFAULT:
+        case SfxItemState::DISABLED:
+        {
+            m_pPageNumBox->EnableTriState(false);
+            m_pPageNumBox->SetState(TRISTATE_FALSE);
+            break;
+        }
+        default:
+            assert(false); // unexpected
+            break;
     }
 
     if ( bPageBreak )
@@ -1655,7 +1687,7 @@ void SvxExtParagraphTabPage::Reset( const SfxItemSet* 
rSet )
             m_pApplyCollBtn->Enable(false);
             m_pApplyCollBox->Enable(false);
             m_pPagenumEdit->Enable(false);
-            m_pPagenumText->Enable(false);
+            m_pPageNumBox->Enable(false);
         }
 
         if ( !bIsPageModel )
@@ -1688,6 +1720,7 @@ void SvxExtParagraphTabPage::Reset( const SfxItemSet* 
rSet )
                 if(!_bEnable)
                 {
                     m_pApplyCollBox->Enable(_bEnable);
+                    m_pPageNumBox->Enable(false);
                     m_pPagenumEdit->Enable(_bEnable);
                 }
 
@@ -1835,6 +1868,7 @@ void SvxExtParagraphTabPage::ChangesApplied()
     m_pBreakTypeLB->SaveValue();
     m_pApplyCollBtn->SaveValue();
     m_pApplyCollBox->SaveValue();
+    m_pPageNumBox->SaveValue();
     m_pPagenumEdit->SaveValue();
     m_pKeepTogetherBox->SaveValue();
     m_pKeepParaBox->SaveValue();
@@ -1860,6 +1894,7 @@ void SvxExtParagraphTabPage::DisablePageBreak()
     m_pBreakPositionLB->Enable(false);
     m_pApplyCollBtn->Enable(false);
     m_pApplyCollBox->Enable(false);
+    m_pPageNumBox->Enable(false);
     m_pPagenumEdit->Enable(false);
 }
 
@@ -1888,7 +1923,7 @@ SvxExtParagraphTabPage::SvxExtParagraphTabPage( 
vcl::Window* pParent, const SfxI
     get(m_pPagenumEdit,"spinPageNumber");
     get(m_pBreakTypeFT,"labelType");
     get(m_pBreakPositionFT,"labelPosition");
-    get(m_pPagenumText,"labelPageNum");
+    get(m_pPageNumBox,"labelPageNum");
 
     // Options
     get(m_pKeepTogetherBox,"checkSplitPara");
@@ -1919,6 +1954,7 @@ SvxExtParagraphTabPage::SvxExtParagraphTabPage( 
vcl::Window* pParent, const SfxI
     m_pApplyCollBtn->SetClickHdl(      LINK( this, SvxExtParagraphTabPage, 
ApplyCollClickHdl_Impl ) );
     m_pBreakTypeLB->SetSelectHdl(      LINK( this, SvxExtParagraphTabPage, 
PageBreakTypeHdl_Impl ) );
     m_pBreakPositionLB->SetSelectHdl(  LINK( this, SvxExtParagraphTabPage, 
PageBreakPosHdl_Impl ) );
+    m_pPageNumBox->SetClickHdl(        LINK( this, SvxExtParagraphTabPage, 
PageNumBoxClickHdl_Impl ) );
 
     SfxObjectShell* pSh = SfxObjectShell::Current();
     if ( pSh )
@@ -1950,7 +1986,7 @@ SvxExtParagraphTabPage::SvxExtParagraphTabPage( 
vcl::Window* pParent, const SfxI
         m_pExtHyphenAfterBox   ->Enable(false);
         m_pMaxHyphenLabel      ->Enable(false);
         m_pMaxHyphenEdit       ->Enable(false);
-        m_pPagenumText         ->Enable(false);
+        m_pPageNumBox          ->Enable(false);
         m_pPagenumEdit         ->Enable(false);
         // no column break in HTML
         m_pBreakTypeLB->RemoveEntry(1);
@@ -1978,7 +2014,7 @@ void SvxExtParagraphTabPage::dispose()
     m_pBreakPositionLB.clear();
     m_pApplyCollBtn.clear();
     m_pApplyCollBox.clear();
-    m_pPagenumText.clear();
+    m_pPageNumBox.clear();
     m_pPagenumEdit.clear();
     m_pKeepTogetherBox.clear();
     m_pKeepParaBox.clear();
@@ -2011,8 +2047,8 @@ IMPL_LINK_NOARG_TYPED(SvxExtParagraphTabPage, 
PageBreakHdl_Impl, Button*, void)
                 m_pApplyCollBox->Enable(bEnable);
                 if(!bHtmlMode)
                 {
-                    m_pPagenumText->Enable(bEnable);
-                    m_pPagenumEdit->Enable(bEnable);
+                    m_pPageNumBox->Enable(bEnable);
+                    m_pPagenumEdit->Enable(bEnable && 
m_pPageNumBox->GetState() == TRISTATE_TRUE);
                 }
             }
             break;
@@ -2022,7 +2058,7 @@ IMPL_LINK_NOARG_TYPED(SvxExtParagraphTabPage, 
PageBreakHdl_Impl, Button*, void)
             m_pApplyCollBtn->SetState( TRISTATE_FALSE );
             m_pApplyCollBtn->Enable(false);
             m_pApplyCollBox->Enable(false);
-            m_pPagenumText->Enable(false);
+            m_pPageNumBox->Enable(false);
             m_pPagenumEdit->Enable(false);
             m_pBreakTypeFT->Enable(false);
             m_pBreakTypeLB->Enable(false);
@@ -2112,8 +2148,8 @@ IMPL_LINK_NOARG_TYPED(SvxExtParagraphTabPage, 
ApplyCollClickHdl_Impl, Button*, v
     m_pApplyCollBox->Enable(bEnable);
     if(!bHtmlMode)
     {
-        m_pPagenumText->Enable(bEnable);
-        m_pPagenumEdit->Enable(bEnable);
+        m_pPageNumBox->Enable(bEnable);
+        m_pPagenumEdit->Enable(bEnable && m_pPageNumBox->GetState() == 
TRISTATE_TRUE);
     }
 }
 
@@ -2129,8 +2165,8 @@ IMPL_LINK_TYPED( SvxExtParagraphTabPage, 
PageBreakPosHdl_Impl, ListBox&, rListBo
         m_pApplyCollBox->Enable(bEnable);
         if(!bHtmlMode)
         {
-            m_pPagenumText->Enable(bEnable);
-            m_pPagenumEdit->Enable(bEnable);
+            m_pPageNumBox->Enable(bEnable);
+            m_pPagenumEdit->Enable(bEnable && m_pPageNumBox->GetState() == 
TRISTATE_TRUE);
         }
     }
     else if ( 1 == rListBox.GetSelectEntryPos() )
@@ -2138,7 +2174,7 @@ IMPL_LINK_TYPED( SvxExtParagraphTabPage, 
PageBreakPosHdl_Impl, ListBox&, rListBo
         m_pApplyCollBtn->SetState( TRISTATE_FALSE );
         m_pApplyCollBtn->Enable(false);
         m_pApplyCollBox->Enable(false);
-        m_pPagenumText->Enable(false);
+        m_pPageNumBox->Enable(false);
         m_pPagenumEdit->Enable(false);
     }
 }
@@ -2152,13 +2188,18 @@ IMPL_LINK_TYPED( SvxExtParagraphTabPage, 
PageBreakTypeHdl_Impl, ListBox&, rListB
         m_pApplyCollBtn->SetState( TRISTATE_FALSE );
         m_pApplyCollBtn->Enable(false);
         m_pApplyCollBox->Enable(false);
-        m_pPagenumText->Enable(false);
+        m_pPageNumBox->Enable(false);
         m_pPagenumEdit->Enable(false);
     }
     else
         PageBreakPosHdl_Impl( *m_pBreakPositionLB );
 }
 
+IMPL_LINK_NOARG_TYPED(SvxExtParagraphTabPage, PageNumBoxClickHdl_Impl, 
Button*, void)
+{
+    m_pPagenumEdit->Enable(m_pPageNumBox->GetState() == TRISTATE_TRUE);
+}
+
 void SvxExtParagraphTabPage::PageCreated(const SfxAllItemSet& aSet)
 {
     const SfxBoolItem* pDisablePageBreakItem = 
aSet.GetItem<SfxBoolItem>(SID_DISABLE_SVXEXTPARAGRAPHTABPAGE_PAGEBREAK, false);
diff --git a/cui/uiconfig/ui/textflowpage.ui b/cui/uiconfig/ui/textflowpage.ui
index 0674dbc..a5c3ed8 100644
--- a/cui/uiconfig/ui/textflowpage.ui
+++ b/cui/uiconfig/ui/textflowpage.ui
@@ -18,6 +18,7 @@
     <property name="upper">9999</property>
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
+    <property name="value">1</property>
   </object>
   <object class="GtkGrid" id="TextFlowPage">
     <property name="visible">True</property>
@@ -243,6 +244,9 @@
                     <property name="can_focus">True</property>
                     <property name="invisible_char">•</property>
                     <property name="adjustment">adjustment3</property>
+                    <accessibility>
+                      <relation type="labelled-by" target="labelPageNum"/>
+                    </accessibility>
                   </object>
                   <packing>
                     <property name="left_attach">4</property>
@@ -250,14 +254,14 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="labelPageNum">
+                  <object class="GtkCheckButton" id="labelPageNum">
                     <property name="visible">True</property>
-                    <property name="can_focus">False</property>
+                    <property name="can_focus">True</property>
                     <property name="xalign">1</property>
                     <property name="label" translatable="yes">Page 
_number:</property>
                     <property name="use_underline">True</property>
+                    <property name="inconsistent">True</property>
                     <property name="justify">right</property>
-                    <property name="mnemonic_widget">spinPageNumber</property>
                   </object>
                   <packing>
                     <property name="left_attach">3</property>
diff --git a/sw/source/uibase/utlui/uitool.cxx 
b/sw/source/uibase/utlui/uitool.cxx
index f566769..09123a3 100644
--- a/sw/source/uibase/utlui/uitool.cxx
+++ b/sw/source/uibase/utlui/uitool.cxx
@@ -600,10 +600,25 @@ void SfxToSwPageDescAttr( const SwWrtShell& rShell, 
SfxItemSet& rSet )
 
     bool bChanged = false;
     // Page number
-    if(SfxItemState::SET == rSet.GetItemState(SID_ATTR_PARA_PAGENUM, false, 
&pItem))
+    switch (rSet.GetItemState(SID_ATTR_PARA_PAGENUM, false, &pItem))
     {
-        aPgDesc.SetNumOffset(static_cast<const 
SfxUInt16Item*>(pItem)->GetValue());
-        bChanged = true;
+        case SfxItemState::SET:
+        {
+            aPgDesc.SetNumOffset(static_cast<const 
SfxUInt16Item*>(pItem)->GetValue());
+            bChanged = true;
+            break;
+        }
+        case SfxItemState::DISABLED:
+        {
+            bChanged = true; // default initialised aPgDesc clears the number
+            break;
+        }
+        case SfxItemState::UNKNOWN:
+        case SfxItemState::DEFAULT:
+            break;
+        default:
+            assert(false); // unexpected
+            break;
     }
     if( SfxItemState::SET == rSet.GetItemState( SID_ATTR_PARA_MODEL, false, 
&pItem ))
     {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to