Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
33 :
34 : #include <app.hrc>
35 : #include <svl/stritem.hxx>
36 : #include <sfx2/app.hxx>
37 : #include <sfx2/dispatch.hxx>
38 : #include <sfx2/sfxhelp.hxx>
39 : #include <sfx2/viewsh.hxx>
40 :
41 : const sal_uInt16 SwParagraphNumTabPage::aPageRg[] = {
42 : FN_NUMBER_NEWSTART, FN_NUMBER_NEWSTART_AT,
43 : 0
44 : };
45 :
46 0 : SwParagraphNumTabPage::SwParagraphNumTabPage(vcl::Window* pParent, const SfxItemSet& rAttr ) :
47 : SfxTabPage(pParent, "NumParaPage", "modules/swriter/ui/numparapage.ui", &rAttr),
48 :
49 : msOutlineNumbering( SW_RES( STR_OUTLINE_NUMBERING ) ),
50 : bModified(false),
51 0 : bCurNumrule(false)
52 : {
53 0 : get(m_pOutlineStartBX, "boxOUTLINE");
54 0 : get(m_pOutlineLvLB, "comboLB_OUTLINE_LEVEL");
55 :
56 0 : get(m_pNumberStyleBX, "boxNUMBER_STYLE");
57 0 : get(m_pNumberStyleLB, "comboLB_NUMBER_STYLE");
58 0 : get(m_pEditNumStyleBtn, "editnumstyle");
59 0 : get(m_pNewStartBX, "boxNEW_START");
60 0 : get(m_pNewStartCB, "checkCB_NEW_START");
61 0 : m_pNewStartCB->SetState(TRISTATE_FALSE);
62 0 : get(m_pNewStartNumberCB, "checkCB_NUMBER_NEW_START");
63 0 : m_pNewStartNumberCB->SetState(TRISTATE_FALSE);
64 0 : get(m_pNewStartNF, "spinNF_NEW_START");
65 :
66 0 : get(m_pCountParaFram, "frameFL_COUNT_PARA");
67 0 : get(m_pCountParaCB, "checkCB_COUNT_PARA");
68 0 : m_pCountParaCB->SetState(TRISTATE_FALSE);
69 0 : get(m_pRestartParaCountCB, "checkCB_RESTART_PARACOUNT");
70 0 : m_pRestartParaCountCB->SetState(TRISTATE_FALSE);
71 :
72 0 : get(m_pRestartBX, "boxRESTART_NO");
73 0 : get(m_pRestartNF, "spinNF_RESTART_PARA");
74 :
75 0 : sal_Int32 numSelectPos = m_pNumberStyleLB->GetSelectEntryPos();
76 0 : if ( numSelectPos == 0 )
77 0 : m_pEditNumStyleBtn->Disable();
78 : else
79 0 : m_pEditNumStyleBtn->Enable();
80 :
81 : const SfxPoolItem* pItem;
82 : SfxObjectShell* pObjSh;
83 0 : if(SfxItemState::SET == rAttr.GetItemState(SID_HTML_MODE, false, &pItem) ||
84 0 : ( 0 != ( pObjSh = SfxObjectShell::Current()) &&
85 0 : 0 != (pItem = pObjSh->GetItem(SID_HTML_MODE))))
86 : {
87 0 : const sal_uInt16 nHtmlMode = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
88 :
89 0 : if (HTMLMODE_ON & nHtmlMode)
90 0 : m_pCountParaFram->Hide();
91 : }
92 :
93 0 : m_pNewStartCB->SetClickHdl(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
94 0 : m_pNewStartNumberCB->SetClickHdl(LINK(this, SwParagraphNumTabPage, NewStartHdl_Impl));
95 0 : m_pNumberStyleLB->SetSelectHdl(LINK(this, SwParagraphNumTabPage, StyleHdl_Impl));
96 0 : m_pCountParaCB->SetClickHdl(LINK(this, SwParagraphNumTabPage, LineCountHdl_Impl));
97 0 : m_pRestartParaCountCB->SetClickHdl( LINK(this, SwParagraphNumTabPage, LineCountHdl_Impl));
98 0 : m_pNumberStyleLB->SetSelectHdl( LINK( this, SwParagraphNumTabPage, EditNumStyleSelectHdl_Impl ) );
99 0 : m_pEditNumStyleBtn->SetClickHdl( LINK(this, SwParagraphNumTabPage, EditNumStyleHdl_Impl));
100 0 : }
101 :
102 0 : SwParagraphNumTabPage::~SwParagraphNumTabPage()
103 : {
104 0 : disposeOnce();
105 0 : }
106 :
107 0 : void SwParagraphNumTabPage::dispose()
108 : {
109 0 : m_pOutlineStartBX.clear();
110 0 : m_pOutlineLvLB.clear();
111 0 : m_pNumberStyleBX.clear();
112 0 : m_pNumberStyleLB.clear();
113 0 : m_pEditNumStyleBtn.clear();
114 0 : m_pNewStartCB.clear();
115 0 : m_pNewStartBX.clear();
116 0 : m_pNewStartNumberCB.clear();
117 0 : m_pNewStartNF.clear();
118 0 : m_pCountParaFram.clear();
119 0 : m_pCountParaCB.clear();
120 0 : m_pRestartParaCountCB.clear();
121 0 : m_pRestartBX.clear();
122 0 : m_pRestartNF.clear();
123 0 : SfxTabPage::dispose();
124 0 : }
125 :
126 0 : VclPtr<SfxTabPage> SwParagraphNumTabPage::Create( vcl::Window* pParent,
127 : const SfxItemSet* rSet )
128 : {
129 0 : return VclPtr<SwParagraphNumTabPage>::Create(pParent, *rSet);
130 : }
131 :
132 0 : bool SwParagraphNumTabPage::FillItemSet( SfxItemSet* rSet )
133 : {
134 0 : if( m_pOutlineLvLB->IsValueChangedFromSaved())
135 : {
136 0 : const sal_uInt16 aOutlineLv = m_pOutlineLvLB->GetSelectEntryPos();
137 0 : const SfxUInt16Item* pOldOutlineLv = static_cast<const SfxUInt16Item*>(GetOldItem( *rSet, SID_ATTR_PARA_OUTLINE_LEVEL));
138 0 : if (pOldOutlineLv)
139 : {
140 0 : SfxUInt16Item* pOutlineLv = static_cast<SfxUInt16Item*>(pOldOutlineLv->Clone());
141 0 : pOutlineLv->SetValue( aOutlineLv );
142 0 : rSet->Put(*pOutlineLv);
143 0 : delete pOutlineLv;
144 0 : bModified = true;
145 : }
146 : }
147 :
148 0 : if( m_pNumberStyleLB->IsValueChangedFromSaved())
149 : {
150 0 : OUString aStyle;
151 0 : if(m_pNumberStyleLB->GetSelectEntryPos())
152 0 : aStyle = m_pNumberStyleLB->GetSelectEntry();
153 0 : const SfxStringItem* pOldRule = static_cast<const SfxStringItem*>(GetOldItem( *rSet, SID_ATTR_PARA_NUMRULE));
154 0 : SfxStringItem* pRule = pOldRule ? static_cast<SfxStringItem*>(pOldRule->Clone()) : NULL;
155 0 : if (pRule)
156 : {
157 0 : pRule->SetValue(aStyle);
158 0 : rSet->Put(*pRule);
159 0 : delete pRule;
160 0 : bModified = true;
161 0 : }
162 : }
163 0 : if(m_pNewStartCB->IsValueChangedFromSaved() ||
164 0 : m_pNewStartNumberCB->IsValueChangedFromSaved()||
165 0 : m_pNewStartNF->IsValueChangedFromSaved())
166 : {
167 0 : bModified = true;
168 0 : bool bNewStartChecked = TRISTATE_TRUE == m_pNewStartCB->GetState();
169 0 : bool bNumberNewStartChecked = TRISTATE_TRUE == m_pNewStartNumberCB->GetState();
170 0 : rSet->Put(SfxBoolItem(FN_NUMBER_NEWSTART, bNewStartChecked));
171 : rSet->Put(SfxUInt16Item(FN_NUMBER_NEWSTART_AT,
172 0 : bNumberNewStartChecked && bNewStartChecked ? (sal_uInt16)m_pNewStartNF->GetValue() : USHRT_MAX));
173 : }
174 :
175 0 : if(m_pCountParaCB->IsValueChangedFromSaved()||
176 0 : m_pRestartParaCountCB->IsValueChangedFromSaved() ||
177 0 : m_pRestartNF->IsValueChangedFromSaved() )
178 : {
179 0 : SwFormatLineNumber aFormat;
180 0 : aFormat.SetStartValue( static_cast< sal_uLong >(m_pRestartParaCountCB->GetState() == TRISTATE_TRUE ?
181 0 : m_pRestartNF->GetValue() : 0 ));
182 0 : aFormat.SetCountLines( m_pCountParaCB->IsChecked() );
183 0 : rSet->Put(aFormat);
184 0 : bModified = true;
185 : }
186 0 : return bModified;
187 : }
188 :
189 0 : void SwParagraphNumTabPage::Reset( const SfxItemSet* rSet )
190 : {
191 0 : bool bHasNumberStyle = false;
192 :
193 0 : SfxItemState eItemState = rSet->GetItemState( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) );
194 :
195 : sal_Int16 nOutlineLv;
196 0 : if( eItemState >= SfxItemState::DEFAULT )
197 : {
198 0 : nOutlineLv = static_cast<const SfxUInt16Item &>(rSet->Get( GetWhich(SID_ATTR_PARA_OUTLINE_LEVEL) )).GetValue();
199 0 : m_pOutlineLvLB->SelectEntryPos( nOutlineLv ) ;
200 : }
201 : else
202 : {
203 0 : m_pOutlineLvLB->SetNoSelection();
204 : }
205 0 : m_pOutlineLvLB->SaveValue();
206 :
207 0 : eItemState = rSet->GetItemState( GetWhich(SID_ATTR_PARA_NUMRULE) );
208 :
209 0 : if( eItemState >= SfxItemState::DEFAULT )
210 : {
211 0 : OUString aStyle = static_cast<const SfxStringItem &>(rSet->Get( GetWhich(SID_ATTR_PARA_NUMRULE) )).GetValue();
212 0 : if(aStyle.isEmpty())
213 0 : aStyle = m_pNumberStyleLB->GetEntry(0);
214 :
215 0 : if( aStyle == "Outline")
216 : {
217 0 : m_pNumberStyleLB->InsertEntry( msOutlineNumbering );
218 0 : m_pNumberStyleLB->SelectEntry( msOutlineNumbering );
219 0 : m_pNumberStyleLB->RemoveEntry(msOutlineNumbering);
220 0 : m_pNumberStyleLB->SaveValue();
221 : }
222 : else
223 0 : m_pNumberStyleLB->SelectEntry( aStyle );
224 :
225 0 : bHasNumberStyle = true;
226 : }
227 : else
228 : {
229 0 : m_pNumberStyleLB->SetNoSelection();
230 : }
231 :
232 0 : m_pNumberStyleLB->SaveValue();
233 :
234 0 : eItemState = rSet->GetItemState( FN_NUMBER_NEWSTART );
235 0 : if(eItemState > SfxItemState::DEFAULT )
236 : {
237 0 : bCurNumrule = true;
238 0 : const SfxBoolItem& rStart = static_cast<const SfxBoolItem&>(rSet->Get(FN_NUMBER_NEWSTART));
239 :
240 0 : m_pNewStartCB->SetState(rStart.GetValue() ? TRISTATE_TRUE : TRISTATE_FALSE );
241 :
242 0 : m_pNewStartCB->EnableTriState(false);
243 : }
244 : else
245 0 : m_pNewStartCB->SetState(bHasNumberStyle ? TRISTATE_FALSE : TRISTATE_INDET);
246 :
247 0 : m_pNewStartCB->SaveValue();
248 :
249 0 : eItemState = rSet->GetItemState( FN_NUMBER_NEWSTART_AT);
250 0 : if( eItemState > SfxItemState::DEFAULT )
251 : {
252 0 : const sal_uInt16 nNewStart = static_cast<const SfxUInt16Item&>(rSet->Get(FN_NUMBER_NEWSTART_AT)).GetValue();
253 0 : const bool bNotMax = USHRT_MAX != nNewStart;
254 0 : m_pNewStartNumberCB->Check(bNotMax);
255 0 : m_pNewStartNF->SetValue(bNotMax ? nNewStart : 1);
256 0 : m_pNewStartNumberCB->EnableTriState(false);
257 : }
258 : else
259 0 : m_pNewStartCB->SetState(TRISTATE_INDET);
260 0 : NewStartHdl_Impl(m_pNewStartCB);
261 0 : m_pNewStartNF->SaveValue();
262 0 : m_pNewStartNumberCB->SaveValue();
263 0 : StyleHdl_Impl(m_pNumberStyleLB);
264 0 : if( SfxItemState::DEFAULT <= rSet->GetItemState(RES_LINENUMBER))
265 : {
266 0 : const SwFormatLineNumber& rNum = static_cast<const SwFormatLineNumber&>(rSet->Get(RES_LINENUMBER));
267 0 : sal_uLong nStartValue = rNum.GetStartValue();
268 0 : bool bCount = rNum.IsCount();
269 0 : m_pCountParaCB->SetState( bCount ? TRISTATE_TRUE : TRISTATE_FALSE );
270 0 : m_pRestartParaCountCB->SetState( 0 != nStartValue ? TRISTATE_TRUE : TRISTATE_FALSE );
271 0 : m_pRestartNF->SetValue(nStartValue == 0 ? 1 : nStartValue);
272 0 : LineCountHdl_Impl(m_pCountParaCB);
273 0 : m_pCountParaCB->EnableTriState(false);
274 0 : m_pRestartParaCountCB->EnableTriState(false);
275 : }
276 : else
277 : {
278 0 : m_pCountParaCB->SetState(TRISTATE_INDET);
279 0 : m_pRestartParaCountCB->SetState(TRISTATE_INDET);
280 : }
281 0 : m_pCountParaCB->SaveValue();
282 0 : m_pRestartParaCountCB->SaveValue();
283 0 : m_pRestartNF->SaveValue();
284 :
285 0 : bModified = false;
286 0 : }
287 :
288 0 : void SwParagraphNumTabPage::DisableOutline()
289 : {
290 0 : m_pOutlineStartBX->Disable();
291 0 : }
292 :
293 0 : void SwParagraphNumTabPage::DisableNumbering()
294 : {
295 0 : m_pNumberStyleBX->Disable();
296 0 : }
297 :
298 0 : void SwParagraphNumTabPage::EnableNewStart()
299 : {
300 0 : m_pNewStartCB->Show();
301 0 : m_pNewStartBX->Show();
302 0 : }
303 :
304 0 : IMPL_LINK_NOARG(SwParagraphNumTabPage, NewStartHdl_Impl)
305 : {
306 0 : bool bEnable = m_pNewStartCB->IsChecked();
307 0 : m_pNewStartNumberCB->Enable(bEnable);
308 0 : m_pNewStartNF->Enable(bEnable && m_pNewStartNumberCB->IsChecked());
309 0 : return 0;
310 : }
311 :
312 :
313 0 : IMPL_LINK_NOARG(SwParagraphNumTabPage, LineCountHdl_Impl)
314 : {
315 0 : m_pRestartParaCountCB->Enable(m_pCountParaCB->IsChecked());
316 :
317 0 : bool bEnableRestartValue = m_pRestartParaCountCB->IsEnabled() &&
318 0 : m_pRestartParaCountCB->IsChecked();
319 0 : m_pRestartBX->Enable(bEnableRestartValue);
320 :
321 0 : return 0;
322 : }
323 :
324 0 : IMPL_LINK_NOARG( SwParagraphNumTabPage, EditNumStyleSelectHdl_Impl )
325 : {
326 0 : sal_Int32 numSelectPos = m_pNumberStyleLB->GetSelectEntryPos();
327 0 : if ( numSelectPos == 0 )
328 0 : m_pEditNumStyleBtn->Disable();
329 : else
330 0 : m_pEditNumStyleBtn->Enable();
331 :
332 0 : return 0;
333 : }
334 :
335 0 : IMPL_LINK_NOARG(SwParagraphNumTabPage, EditNumStyleHdl_Impl)
336 : {
337 0 : OUString aTemplName(m_pNumberStyleLB->GetSelectEntry());
338 0 : ExecuteEditNumStyle_Impl( SID_STYLE_EDIT, aTemplName, OUString(),SFX_STYLE_FAMILY_PARA, 0 );
339 0 : return 0;
340 : }
341 :
342 : // Internal: Perform functions through the Dispatcher
343 0 : bool SwParagraphNumTabPage::ExecuteEditNumStyle_Impl(
344 : sal_uInt16 nId, const OUString &rStr, const OUString& rRefStr, sal_uInt16 nFamily,
345 : sal_uInt16 nMask, const sal_uInt16* pModifier)
346 : {
347 :
348 0 : SfxDispatcher &rDispatcher = *SfxViewShell::Current()->GetDispatcher();
349 0 : SfxStringItem aItem(nId, rStr);
350 0 : SfxUInt16Item aFamily(SID_STYLE_FAMILY, nFamily);
351 0 : SfxUInt16Item aMask( SID_STYLE_MASK, nMask );
352 0 : SfxStringItem aUpdName(SID_STYLE_UPD_BY_EX_NAME, rStr);
353 0 : SfxStringItem aRefName( SID_STYLE_REFERENCE, rRefStr );
354 : const SfxPoolItem* pItems[ 6 ];
355 0 : sal_uInt16 nCount = 0;
356 0 : if( !rStr.isEmpty() )
357 0 : pItems[ nCount++ ] = &aItem;
358 0 : pItems[ nCount++ ] = &aFamily;
359 0 : if( nMask )
360 0 : pItems[ nCount++ ] = &aMask;
361 0 : if( !rRefStr.isEmpty() )
362 0 : pItems[ nCount++ ] = &aRefName;
363 :
364 0 : pItems[ nCount++ ] = 0;
365 :
366 0 : sal_uInt16 nModi = pModifier ? *pModifier : 0;
367 : const SfxPoolItem* mpItem = rDispatcher.Execute(
368 : nId, SfxCallMode::SYNCHRON | SfxCallMode::RECORD | SfxCallMode::MODAL,
369 0 : pItems, nModi );
370 :
371 0 : if ( !mpItem )
372 0 : return false;
373 :
374 0 : return true;
375 :
376 : }
377 :
378 0 : IMPL_LINK( SwParagraphNumTabPage, StyleHdl_Impl, ListBox*, pBox )
379 : {
380 0 : bool bEnable = bCurNumrule || pBox->GetSelectEntryPos() > 0;
381 0 : m_pNewStartCB->Enable(bEnable);
382 0 : NewStartHdl_Impl(m_pNewStartCB);
383 :
384 0 : return 0;
385 0 : }
386 :
387 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|