bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / chrdlg / numpara.cxx
blob81a8805d458296ccc6efd7f2d0c4f69d7d5e65ef
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 "cmdid.h"
21 #include "swtypes.hxx"
22 #include "hintids.hxx"
23 #include "globals.hrc"
24 #include "helpid.h"
25 #include <sfx2/objsh.hxx>
26 #include <sfx2/htmlmode.hxx>
27 #include <svx/svxids.hrc>
28 #include <svl/eitem.hxx>
29 #include <svl/stritem.hxx>
30 #include <svl/intitem.hxx>
31 #include <fmtline.hxx>
32 #include <numpara.hxx>
34 #include <app.hrc>
37 // Globals ******************************************************************
39 static sal_uInt16 aPageRg[] = {
40 FN_NUMBER_NEWSTART, FN_NUMBER_NEWSTART_AT,
44 SwParagraphNumTabPage::SwParagraphNumTabPage(Window* pParent, const SfxItemSet& rAttr ) :
45 SfxTabPage(pParent, "NumParaPage", "modules/swriter/ui/numparapage.ui", rAttr),
47 msOutlineNumbering( SW_RES( STR_OUTLINE_NUMBERING ) ),
48 bModified(sal_False),
49 bCurNumrule(sal_False)
51 get(m_pOutlineStartBX, "boxOUTLINE");
52 get(m_pOutlineLvLB, "comboLB_OUTLINE_LEVEL");
54 get(m_pNumberStyleBX, "boxNUMBER_STYLE");
55 get(m_pNumberStyleLB, "comboLB_NUMBER_STYLE");
57 get(m_pNewStartBX, "boxNEW_START");
58 get(m_pNewStartCB, "checkCB_NEW_START");
59 m_pNewStartCB->SetState(STATE_NOCHECK);
60 get(m_pNewStartNumberCB, "checkCB_NUMBER_NEW_START");
61 m_pNewStartNumberCB->SetState(STATE_NOCHECK);
62 get(m_pNewStartNF, "spinNF_NEW_START");
64 get(m_pCountParaFram, "frameFL_COUNT_PARA");
65 get(m_pCountParaCB, "checkCB_COUNT_PARA");
66 m_pCountParaCB->SetState(STATE_NOCHECK);
67 get(m_pRestartParaCountCB, "checkCB_RESTART_PARACOUNT");
68 m_pRestartParaCountCB->SetState(STATE_NOCHECK);
70 get(m_pRestartBX, "boxRESTART_NO");
71 get(m_pRestartNF, "spinNF_RESTART_PARA");
73 const SfxPoolItem* pItem;
74 SfxObjectShell* pObjSh;
75 if(SFX_ITEM_SET == rAttr.GetItemState(SID_HTML_MODE, sal_False, &pItem) ||
76 ( 0 != ( pObjSh = SfxObjectShell::Current()) &&
77 0 != (pItem = pObjSh->GetItem(SID_HTML_MODE))))
79 sal_uInt16 nHtmlMode = ((const SfxUInt16Item*)pItem)->GetValue();
81 if (HTMLMODE_ON & nHtmlMode)
82 m_pCountParaFram->Hide();
85 m_pNewStartCB->SetClickHdl(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
86 m_pNewStartNumberCB->SetClickHdl(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
87 m_pNumberStyleLB->SetSelectHdl(LINK(this, SwParagraphNumTabPage, StyleHdl_Impl));
88 m_pCountParaCB->SetClickHdl(LINK(this, SwParagraphNumTabPage, LineCountHdl_Impl));
89 m_pRestartParaCountCB->SetClickHdl( LINK(this, SwParagraphNumTabPage, LineCountHdl_Impl));
92 SwParagraphNumTabPage::~SwParagraphNumTabPage()
96 SfxTabPage* SwParagraphNumTabPage::Create( Window* pParent,
97 const SfxItemSet& rSet )
99 return new SwParagraphNumTabPage(pParent, rSet);
102 sal_uInt16* SwParagraphNumTabPage::GetRanges()
104 return aPageRg;
107 sal_Bool SwParagraphNumTabPage::FillItemSet( SfxItemSet& rSet )
109 if( m_pOutlineLvLB->GetSelectEntryPos() != m_pOutlineLvLB->GetSavedValue())
111 sal_uInt16 aOutlineLv = m_pOutlineLvLB->GetSelectEntryPos();
112 const SfxUInt16Item* pOldOutlineLv = (const SfxUInt16Item*)GetOldItem( rSet, SID_ATTR_PARA_OUTLINE_LEVEL);
113 SfxUInt16Item* pOutlineLv = (SfxUInt16Item*)pOldOutlineLv->Clone();
114 pOutlineLv->SetValue( aOutlineLv );
115 rSet.Put(*pOutlineLv);
116 delete pOutlineLv;
117 bModified = sal_True;
120 if( m_pNumberStyleLB->GetSelectEntryPos() != m_pNumberStyleLB->GetSavedValue())
122 OUString aStyle;
123 if(m_pNumberStyleLB->GetSelectEntryPos())
124 aStyle = m_pNumberStyleLB->GetSelectEntry();
125 const SfxStringItem* pOldRule = (const SfxStringItem*)GetOldItem( rSet, SID_ATTR_PARA_NUMRULE);
126 SfxStringItem* pRule = (SfxStringItem*)pOldRule->Clone();
127 pRule->SetValue(aStyle);
128 rSet.Put(*pRule);
129 delete pRule;
130 bModified = sal_True;
132 if(m_pNewStartCB->GetState() != m_pNewStartCB->GetSavedValue() ||
133 m_pNewStartNumberCB->GetState() != m_pNewStartNumberCB->GetSavedValue()||
134 m_pNewStartNF->GetText() != m_pNewStartNF->GetSavedValue())
136 bModified = sal_True;
137 bool bNewStartChecked = STATE_CHECK == m_pNewStartCB->GetState();
138 bool bNumberNewStartChecked = STATE_CHECK == m_pNewStartNumberCB->GetState();
139 rSet.Put(SfxBoolItem(FN_NUMBER_NEWSTART, bNewStartChecked));
140 rSet.Put(SfxUInt16Item(FN_NUMBER_NEWSTART_AT,
141 bNumberNewStartChecked && bNewStartChecked ? (sal_uInt16)m_pNewStartNF->GetValue() : USHRT_MAX));
144 if(m_pCountParaCB->GetSavedValue() != m_pCountParaCB->GetState() ||
145 m_pRestartParaCountCB->GetSavedValue() != m_pRestartParaCountCB->GetState() ||
146 m_pRestartNF->GetSavedValue() != m_pRestartNF->GetText() )
148 SwFmtLineNumber aFmt;
149 aFmt.SetStartValue( static_cast< sal_uLong >(m_pRestartParaCountCB->GetState() == STATE_CHECK ?
150 m_pRestartNF->GetValue() : 0 ));
151 aFmt.SetCountLines( m_pCountParaCB->IsChecked() );
152 rSet.Put(aFmt);
153 bModified = sal_True;
155 return bModified;
158 void SwParagraphNumTabPage::Reset( const SfxItemSet& rSet )
160 bool bHasNumberStyle = false;
162 SfxItemState eItemState = rSet.GetItemState( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) );
164 sal_Int16 nOutlineLv;
165 if( eItemState >= SFX_ITEM_AVAILABLE )
167 nOutlineLv = ((const SfxUInt16Item &)rSet.Get( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) )).GetValue();
168 m_pOutlineLvLB->SelectEntryPos( nOutlineLv ) ;
170 else
172 m_pOutlineLvLB->SetNoSelection();
174 m_pOutlineLvLB->SaveValue();
176 eItemState = rSet.GetItemState( GetWhich(SID_ATTR_PARA_NUMRULE) );
178 OUString aStyle;
179 if( eItemState >= SFX_ITEM_AVAILABLE )
181 aStyle = ((const SfxStringItem &)rSet.Get( GetWhich(SID_ATTR_PARA_NUMRULE) )).GetValue();
182 if(aStyle.isEmpty())
183 aStyle = m_pNumberStyleLB->GetEntry(0);
185 if( aStyle == "Outline")
187 m_pNumberStyleLB->InsertEntry( msOutlineNumbering );
188 m_pNumberStyleLB->SelectEntry( msOutlineNumbering );
189 m_pNumberStyleLB->RemoveEntry(msOutlineNumbering);
190 m_pNumberStyleLB->SaveValue();
192 else
193 m_pNumberStyleLB->SelectEntry( aStyle );
195 bHasNumberStyle = true;
197 else
199 m_pNumberStyleLB->SetNoSelection();
202 m_pNumberStyleLB->SaveValue();
204 eItemState = rSet.GetItemState( FN_NUMBER_NEWSTART );
205 if(eItemState > SFX_ITEM_AVAILABLE )
207 bCurNumrule = sal_True;
208 const SfxBoolItem& rStart = (const SfxBoolItem&)rSet.Get(FN_NUMBER_NEWSTART);
210 m_pNewStartCB->SetState(rStart.GetValue() ? STATE_CHECK : STATE_NOCHECK );
212 m_pNewStartCB->EnableTriState(sal_False);
214 else
215 m_pNewStartCB->SetState(bHasNumberStyle ? STATE_NOCHECK : STATE_DONTKNOW);
217 m_pNewStartCB->SaveValue();
219 eItemState = rSet.GetItemState( FN_NUMBER_NEWSTART_AT);
220 if( eItemState > SFX_ITEM_AVAILABLE )
222 sal_uInt16 nNewStart = ((const SfxUInt16Item&)rSet.Get(FN_NUMBER_NEWSTART_AT)).GetValue();
223 m_pNewStartNumberCB->Check(USHRT_MAX != nNewStart);
224 if(USHRT_MAX == nNewStart)
225 nNewStart = 1;
227 m_pNewStartNF->SetValue(nNewStart);
228 m_pNewStartNumberCB->EnableTriState(sal_False);
230 else
231 m_pNewStartCB->SetState(STATE_DONTKNOW);
232 NewStartHdl_Impl(m_pNewStartCB);
233 m_pNewStartNF->SaveValue();
234 m_pNewStartNumberCB->SaveValue();
235 StyleHdl_Impl(m_pNumberStyleLB);
236 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState(RES_LINENUMBER))
238 SwFmtLineNumber& rNum = (SwFmtLineNumber&)rSet.Get(RES_LINENUMBER);
239 sal_uLong nStartValue = rNum.GetStartValue();
240 bool bCount = rNum.IsCount();
241 m_pCountParaCB->SetState( bCount ? STATE_CHECK : STATE_NOCHECK );
242 m_pRestartParaCountCB->SetState( 0 != nStartValue ? STATE_CHECK : STATE_NOCHECK );
243 m_pRestartNF->SetValue(nStartValue == 0 ? 1 : nStartValue);
244 LineCountHdl_Impl(m_pCountParaCB);
245 m_pCountParaCB->EnableTriState(sal_False);
246 m_pRestartParaCountCB->EnableTriState(sal_False);
248 else
250 m_pCountParaCB->SetState(STATE_DONTKNOW);
251 m_pRestartParaCountCB->SetState(STATE_DONTKNOW);
253 m_pCountParaCB->SaveValue();
254 m_pRestartParaCountCB->SaveValue();
255 m_pRestartNF->SaveValue();
257 bModified = sal_False;
260 void SwParagraphNumTabPage::DisableOutline()
262 m_pOutlineStartBX->Disable();
265 void SwParagraphNumTabPage::DisableNumbering()
267 m_pNumberStyleBX->Disable();
270 void SwParagraphNumTabPage::EnableNewStart()
272 m_pNewStartCB->Show();
273 m_pNewStartBX->Show();
276 IMPL_LINK_NOARG(SwParagraphNumTabPage, NewStartHdl_Impl)
278 bool bEnable = m_pNewStartCB->IsChecked();
279 m_pNewStartNumberCB->Enable(bEnable);
280 m_pNewStartNF->Enable(bEnable && m_pNewStartNumberCB->IsChecked());
281 return 0;
284 IMPL_LINK_NOARG(SwParagraphNumTabPage, LineCountHdl_Impl)
286 m_pRestartParaCountCB->Enable(m_pCountParaCB->IsChecked());
288 bool bEnableRestartValue = m_pRestartParaCountCB->IsEnabled() &&
289 m_pRestartParaCountCB->IsChecked();
290 m_pRestartBX->Enable(bEnableRestartValue);
292 return 0;
295 IMPL_LINK( SwParagraphNumTabPage, StyleHdl_Impl, ListBox*, pBox )
297 bool bEnable = bCurNumrule || pBox->GetSelectEntryPos() > 0;
298 m_pNewStartCB->Enable(bEnable);
299 NewStartHdl_Impl(m_pNewStartCB);
301 return 0;
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */