Update git submodules
[LibreOffice.git] / sd / source / ui / dlg / paragr.cxx
bloba41e3c99d56f0f115f34e168d6afdb8ddc115e35
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svl/cjkoptions.hxx>
21 #include <svl/eitem.hxx>
22 #include <svl/intitem.hxx>
24 #include <svx/dialogs.hrc>
25 #include <svx/svxids.hrc>
26 #include <svx/flagsdef.hxx>
27 #include <svx/xcolit.hxx>
29 #include <paragr.hxx>
30 #include <sdattr.hrc>
32 namespace {
34 class SdParagraphNumTabPage : public SfxTabPage
36 public:
37 SdParagraphNumTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet);
38 static std::unique_ptr<SfxTabPage> Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet );
40 static const WhichRangesContainer & GetRanges();
42 virtual bool FillItemSet( SfxItemSet* rSet ) override;
43 virtual void Reset( const SfxItemSet* rSet ) override;
45 private:
46 bool mbModified;
47 std::unique_ptr<weld::CheckButton> m_xNewStartCB;
48 std::unique_ptr<weld::CheckButton> m_xNewStartNumberCB;
49 std::unique_ptr<weld::SpinButton> m_xNewStartNF;
51 DECL_LINK( ImplNewStartHdl, weld::Toggleable&, void );
56 SdParagraphNumTabPage::SdParagraphNumTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rAttr)
57 : SfxTabPage(pPage, pController, u"modules/sdraw/ui/paranumberingtab.ui"_ustr, u"DrawParaNumbering"_ustr, &rAttr)
58 , mbModified(false)
59 , m_xNewStartCB(m_xBuilder->weld_check_button(u"checkbuttonCB_NEW_START"_ustr))
60 , m_xNewStartNumberCB(m_xBuilder->weld_check_button(u"checkbuttonCB_NUMBER_NEW_START"_ustr))
61 , m_xNewStartNF(m_xBuilder->weld_spin_button(u"spinbuttonNF_NEW_START"_ustr))
63 m_xNewStartCB->connect_toggled(LINK(this, SdParagraphNumTabPage, ImplNewStartHdl));
64 m_xNewStartNumberCB->connect_toggled(LINK(this, SdParagraphNumTabPage, ImplNewStartHdl));
67 std::unique_ptr<SfxTabPage> SdParagraphNumTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet * rAttrSet)
69 return std::make_unique<SdParagraphNumTabPage>(pPage, pController, *rAttrSet);
72 const WhichRangesContainer & SdParagraphNumTabPage::GetRanges()
74 static const auto gRanges = WhichRangesContainer(svl::Items<ATTR_PARANUMBERING_START, ATTR_PARANUMBERING_END>);
75 return gRanges;
78 bool SdParagraphNumTabPage::FillItemSet( SfxItemSet* rSet )
80 if (m_xNewStartCB->get_state_changed_from_saved() ||
81 m_xNewStartNumberCB->get_state_changed_from_saved()||
82 m_xNewStartNF->get_value_changed_from_saved())
84 mbModified = true;
85 bool bNewStartChecked = TRISTATE_TRUE == m_xNewStartCB->get_state();
86 bool bNumberNewStartChecked = TRISTATE_TRUE == m_xNewStartNumberCB->get_state();
87 rSet->Put(SfxBoolItem(ATTR_NUMBER_NEWSTART, bNewStartChecked));
89 const sal_Int16 nStartAt = static_cast<sal_Int16>(m_xNewStartNF->get_value());
90 rSet->Put(SfxInt16Item(ATTR_NUMBER_NEWSTART_AT, bNumberNewStartChecked && bNewStartChecked ? nStartAt : -1));
93 return mbModified;
96 void SdParagraphNumTabPage::Reset( const SfxItemSet* rSet )
98 SfxItemState eItemState = rSet->GetItemState( ATTR_NUMBER_NEWSTART );
99 if(eItemState > SfxItemState::DEFAULT )
101 const SfxBoolItem& rStart = rSet->Get(ATTR_NUMBER_NEWSTART);
102 m_xNewStartCB->set_state( rStart.GetValue() ? TRISTATE_TRUE : TRISTATE_FALSE );
104 else
106 m_xNewStartCB->set_state(TRISTATE_INDET);
107 m_xNewStartCB->set_sensitive(false);
109 m_xNewStartCB->save_state();
111 eItemState = rSet->GetItemState( ATTR_NUMBER_NEWSTART_AT);
112 if( eItemState > SfxItemState::DEFAULT )
114 sal_Int16 nNewStart = rSet->Get(ATTR_NUMBER_NEWSTART_AT).GetValue();
115 m_xNewStartNumberCB->set_active(-1 != nNewStart);
116 if(-1 == nNewStart)
117 nNewStart = 1;
119 m_xNewStartNF->set_value(nNewStart);
121 else
123 m_xNewStartCB->set_state(TRISTATE_INDET);
125 ImplNewStartHdl(*m_xNewStartCB);
126 m_xNewStartNF->save_value();
127 m_xNewStartNumberCB->save_state();
128 mbModified = false;
131 IMPL_LINK_NOARG(SdParagraphNumTabPage, ImplNewStartHdl, weld::Toggleable&, void)
133 bool bEnable = m_xNewStartCB->get_active();
134 m_xNewStartNumberCB->set_sensitive(bEnable);
135 m_xNewStartNF->set_sensitive(bEnable && m_xNewStartNumberCB->get_active());
138 SdParagraphDlg::SdParagraphDlg(weld::Window* pParent, const SfxItemSet* pAttr)
139 : SfxTabDialogController(pParent, u"modules/sdraw/ui/drawparadialog.ui"_ustr,
140 u"DrawParagraphPropertiesDialog"_ustr, pAttr)
142 AddTabPage( u"labelTP_PARA_STD"_ustr, RID_SVXPAGE_STD_PARAGRAPH);
144 if( SvtCJKOptions::IsAsianTypographyEnabled() )
145 AddTabPage( u"labelTP_PARA_ASIAN"_ustr, RID_SVXPAGE_PARA_ASIAN);
146 else
147 RemoveTabPage( u"labelTP_PARA_ASIAN"_ustr );
149 AddTabPage( u"labelTP_PARA_ALIGN"_ustr, RID_SVXPAGE_ALIGN_PARAGRAPH);
151 static const bool bShowParaNumbering = ( getenv( "SD_SHOW_NUMBERING_PAGE" ) != nullptr );
152 if( bShowParaNumbering )
153 AddTabPage( u"labelNUMBERING"_ustr, SdParagraphNumTabPage::Create, SdParagraphNumTabPage::GetRanges );
154 else
155 RemoveTabPage( u"labelNUMBERING"_ustr );
157 AddTabPage(u"labelTP_TABULATOR"_ustr, RID_SVXPAGE_TABULATOR);
160 void SdParagraphDlg::PageCreated(const OUString& rId, SfxTabPage &rPage)
162 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
163 if (rId == "labelTP_PARA_STD")
165 aSet.Put(SfxUInt32Item(SID_SVXSTDPARAGRAPHTABPAGE_ABSLINEDIST, MM50/2));
166 rPage.PageCreated(aSet);
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */